int Test(HWND hwnd, LPCTSTR str1, LPCTSTR str2, UINT nType);
2: PROC* pfnNew = (PROC*)Test;
3: PROC* ppfn = NULL;
4:
5:
int Test(HWND hwnd, LPCTSTR str1, LPCTSTR str2, UINT nType)
7: {
, MB_OK);
);
return 0;
11: }
12:
13:
int argc, _TCHAR* argv[])
15: {
16: HMODULE hMd = GetModuleHandleA(NULL);
18:
if (!hMd)
20: {
return 0;
22: }
23:
24: PROC pfnOrig = GetProcAddress(
),
27: );
28:
29: ULONG ulSize;
30:
31: PIMAGE_IMPORT_DESCRIPTOR pImportDesc = (PIMAGE_IMPORT_DESCRIPTOR)
32: ImageDirectoryEntryToData(
33: hMd,
TRUE,
35: IMAGE_DIRECTORY_ENTRY_IMPORT,
36: &ulSize
37: );
38:
if (pImportDesc == NULL)
40: {
return 0;
42: }
43:
for (; pImportDesc->Name; pImportDesc++)
45: {
46: PSTR pszName = (PSTR) ((PBYTE)hMd + pImportDesc->Name);
) == 0)
48: {
break;
50: }
51: }
52:
if (pImportDesc->Name == NULL)
54: {
return 0;
56: }
57:
58: PIMAGE_THUNK_DATA pThunk = (PIMAGE_THUNK_DATA)
59: ((PBYTE)hMd + pImportDesc->FirstThunk);
60:
for (; pThunk->u1.Function; pThunk++)
62: {
63: ppfn = (PROC*) &pThunk->u1.Function;
64: BOOL bFound = (*ppfn == pfnOrig);
65:
if (bFound)
67: {
if (WriteProcessMemory(
69: GetCurrentProcess(),
70: ppfn,
71: &pfnNew,
sizeof(pfnNew),
73: NULL
74: ))
75: {
break;
77: }
else
79: {
80: DWORD dwoldProtect;
sizeof(pfnNew), PAGE_WRITECOPY, &dwoldProtect);
sizeof(pfnNew), NULL);
sizeof(pfnNew), dwoldProtect, &dwoldProtect);
84: }
85: }
86: }
87:
, MB_OK);
89:
, MB_OK);
91:
93:
return 0;
95: }