How To Remove Watermark By Programing
2009年5月10日星期日
Some friends asked me how to remove the watermark by programming, now, I have post a demo to google code. You can found the source code at http://code.google.com/p/removewatermark/
Main steps:
Load the user32.dll.mui into memory by API LoadLibraryEx().
Find the string table by FindResourceEx(), and load it by LoadResource(), LockResource().
Look up the watermark string in string table, we can get the string virtual address and length, then calculate the string offset base the module address, and we get the file offset.
Map the file to memory, just simple zero the watermark string.
In order to make the procedure simple, so use the simplest method.
Finally, re-check sum the file.
OK, all done.
//
// Load mui file to memory
//
HINSTANCE hInstLib = NULL;
hInstLib = LoadLibraryEx(pszFile, NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
if( NULL == hInstLib )
{
_tcprintf(_T("Fail to open file user32.dll.mui!\n"));
return FALSE;
}
//
// Get file type
//
PIMAGE_DOS_HEADER pDOSHeader = (PIMAGE_DOS_HEADER)((DWORD_PTR)hInstLib - 1);
PIMAGE_NT_HEADERS pNTHeader = (PIMAGE_NT_HEADERS) (pDOSHeader->e_lfanew + (DWORD_PTR)pDOSHeader);
_tcprintf(_T("File type:\t"));
switch (pNTHeader->FileHeader.Machine)
{
case IMAGE_FILE_MACHINE_I386:
_tcprintf(_T("x86"));
break;
case IMAGE_FILE_MACHINE_AMD64:
_tcprintf(_T("x64"));
break;
case IMAGE_FILE_MACHINE_IA64:
_tcprintf(_T("ia64"));
break;
default:
_tcprintf(_T("Unknown\nThis is not a valid file.\n"));
FreeLibrary(hInstLib);
return FALSE;
}
// Load string from resource with special langID
//
BOOL LoadStringExx(
HINSTANCE hInst, // Hinstance of lib
WORD wLangID, // Language ID of resource
PRES_STRING_INFO pInfo // Pointer to the string info
)
{
HRSRC hFindRes; // Handle of the resources has been found
HGLOBAL hLoadRes; // Handle of the resources has been loaded
LPVOID pRes; // Pointer to the resources
UINT nBlockID; // String block ID
pInfo->dwFileOffset = 0; // String offset in the file
pInfo->dwBytes = 0; // String length, in bytes
pInfo->pszText = NULL;
nBlockID = pInfo->uStringID / 16 + 1;
__try
{
// find the string block
hFindRes = FindResourceEx(hInst, RT_STRING, MAKEINTRESOURCE(nBlockID), wLangID);
if(!hFindRes )
{
__leave;
}
hLoadRes = LoadResource(hInst, hFindRes);
if(!hLoadRes )
{
__leave;
}
pRes = LockResource(hLoadRes);
if(!pRes )
{
__leave;
}
WCHAR* pParse = (WCHAR *)pRes; // Pointer to the String block
UINT nIndex = pInfo->uStringID % 16; // Calculate the string index
int nLen;
UINT i;
// 16 strings per block
for( i = 0; i < (nIndex & 15); i++ )
{
pParse += 1 + (int)*pParse;
}
// OK, we get it
nLen = (UINT)*pParse; // The length of the target string.
pParse += 1; // Pointer to the target string
// Main point, calculate the string offset
pInfo->dwFileOffset = (DWORD) ( (DWORD_PTR)pParse - (DWORD_PTR)hInst ) + 1;
pInfo->dwBytes = nLen * sizeof(WCHAR);
// allocate memory
pInfo->pszText = (LPWSTR)MALLOC((nLen + 1) * sizeof(WCHAR));
if (!pInfo->pszText)
__leave;
// copy string for return
CopyMemory((LPVOID)pInfo->pszText, (LPVOID)pParse, pInfo->dwBytes);
*(PWCHAR)((DWORD_PTR)pInfo->pszText + pInfo->dwBytes) = 0;
}
__finally
{
// Clean up, free memory
if (pRes)
UnlockResource(pRes);
if (hFindRes)
FreeResource(hFindRes);
}
// if pointer is null, we return a NULL string
if (!pInfo->pszText)
{
pInfo->pszText = (LPWSTR)MALLOC(sizeof(WCHAR));
pInfo->pszText[0] = 0;
}
return TRUE;
} // LoadStringExx()
发帖者 deepxw 时间: 13:00 |
Besides it looks very beautiful, the contents of its news was very nice Obat Penyakit Jantung Lemah Herbal
kept constantly updated useful information like this Manfaat Jamur Ganoderma
I will always visit your blog Penyebab Asma
Thank you, nice to meet you and always success Penyakit Kulit
Obat Herbal Kanker Vagina
The information you have to say this is very nice, Cara Mengobati Kaki Bengkak Obat Herbal Benjolan Di Kepala I am very happy because it can get infomrasi that I had been looking Obat Sakit Kepala Obat Krusta Thank you for sharing information that is unusually good to us all
Obat Benjolan Di Leher Cara Menyembuhkan Gastritis I hope you continue to renew other tarubaru news, which certainly can be beneficial for many people Obat Infeksi Kulit Herbal yang Ampuh Obat Vaginosis Bakterialis Herbal Maybe I'll come back to your site, as I am sure there will be lots of information other extraordinary time when that will come Obat Benjolan Di Kaki Herbal Cara Membeli QnC Jelly Gamat
This is the most interesting information and fit into our topic.
obat amandel
obat amandel
obat amandel
obat amandel
obat amandel
obat amandel
obat amandel
obat amandel
obat amandel
Can I just say what a relief to find someone who actually knows what theyre talking about on the internet. You definitely know how to bring an issue to light and make it important. More people need to read this and understand this side of the story. I cant believe youre not more popular because you definitely have the gift.
Website
Information
Click Here
หนังออนไลน์ หนังต่อสู้ดูไม่เบื่อ Donnybrook ต่อย...เป็น หยุด...ตาย (2018) ไปดูกับที่เว็บหนังออนไลน์เว็บนี้เลย
Donnybrook ต่อย...เป็น หยุด...ตาย (2018)