How To Remove Watermark By Programing

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 时间: 下午1:00   |    

7 评论:

時間 说... 2010年1月8日 上午1:32  

美女交友artdab美女交友cys pm美女交友djgift美女交友ggo美女交友ggoo美女交友locarno美女交友sfr美女交友thcmt美女寫真mat情色a片flashxyz美女交友artdab美女交友cys pm美女交友djgift美女交友ggo美女交友ggoo美女交友locarno美女交友sfr美女交友thcmt美女寫真mat情色a片flashxyz美女交友artdab美女交友cys pm美女交友djgift美女交友ggo美女交友ggoo美女交友locarno美女交友sfr美女交友thcmt美女寫真mat情色a片flashxyz美女交友artdab美女交友cys pm美女交友djgift美女交友ggo美女交友ggoo美女交友locarno美女交友sfr美女交友thcmt美女寫真mat情色a片flashxyz

zenegra online 说... 2011年7月11日 下午1:21  

You have done excellent work. Generic Viagra Online,Kamagra,Lovegra Online I am regular reader of your blog and expecting new and great things. Good Luck.

Fikri Ferdiansyah 说... 2015年5月13日 下午3:02  

This paragraph is truly a fastidious one it
assists new internet people, who are wishing in favor of
blogging.

Look into my web page Obat Multiple Sclerosis | Obat Kelenjar Getah Bening Di Leher | Obat Herbal Kista Ovarium | Obat Asam Lambung | Obat Tumor Lambung

lolyta 说... 2015年10月23日 上午6:27  

I came across the serach engine and find your website, you have great and nice blog, Thanks for sharing, God

bless you
Pingback : HARGA VIMAX IZON
HARGA VIMAX IZON ASLI
OBAT VIMAX HERBAL
VIMAX IZON ASLI
AGEN VIMAX


http://vimaxizoncanada.com/

vimax izon asli
jual vimax izon
harga vimax izon
vimax izon canada
vimax izon Original
khasiat vimax canada
vimax izon
vimax izon


RAHASIADEWASA.NET

PERANGSANG WANITA
opium spray
opium spray asli
jual opium spray
OBAT PERANGSANG WANITA
MAXMAN CAPSULE
PRO

EXTENDER

selaput dara buatan
selaput dara keperawanan


ALATSEXIMPORT.COM

ALAT BANTU SEX
JUAL ALAT SEX IMPORT
TOKO ALAT BANTU SEX IMPORT
PENGHILANG DAN PENGHAPUS TATTO PERMANEN
ALAT SEX UNTUK BDSM
BONEKA SEX KOREA FULL BODI
ALAT ONANI PRIA

OPIUM SPRAY

Vmenplus Herbal
Vmenplus
Vmenplus import
Vmenplus Asli
Vmenplus herbal
Obat Vmenplus

Dian Ardi 说... 2016年3月23日 下午3:57  

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

M. Umar Firmansyah 说... 2016年11月17日 下午3:38  

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

Acep Suherman Herbal 说... 2017年12月7日 下午3:26  

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

发表评论

previous home
 
Copyright 2009 deepxw | 闲人小作