[C] 纯文本查看 复制代码
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <malloc.h>
int WINAPI MyMessageBox(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType);
void GetHookData();
void HookOn();
void HookOff();
DWORD OldProtect, RETAddr;
FARPROC OldAddr;
BYTE OldCode[5], NewCode[5];
HANDLE hProcess;
char str1[100], str2[100];
void *pp;
int main()
{
char ch;
pp = malloc(150);
GetHookData();
printf("Please Input Name:");
scanf("%99s", str1);
while ((ch = getchar()) != '\n');
printf("Please Input Password:");
scanf("%99s", str2);
while ((ch = getchar()) != '\n');
HookOn();
MessageBoxW(0, L"Faild!", L"O(∩_∩)O哈哈~", 0);
return 0;
}
int WINAPI MyMessageBox(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
{
int ret;
int len1 = strlen(str1);
int len2 = strlen(str2);
char * suc = "SUCCESS!";
char * fai = "Faild!";
int i, j;
int sum1 = 0, sum2 = 0;
HookOff();
for (i = 1; i < len1; i++)
sum1 += str1[i] - str1[i - 1];
for (j = 0; j < len2 - 1; j++)
sum2 += str1[i] - str2[i + 1];
if (sum1 == sum2)
ret = MessageBoxW(hWnd, L"SUCCESS!", L"O(∩_∩)O哈哈~", uType);
else
ret = MessageBoxW(hWnd, L"Faild!", L"O(∩_∩)O哈哈~", uType);
HookOn();
return ret;
}
void GetHookData()
{
hProcess = GetCurrentProcess();
OldAddr = GetProcAddress(LoadLibraryA((LPCSTR)"user32.dll"), (LPCSTR)"MessageBoxW");
if (OldAddr)
{
memcpy(OldCode, OldAddr, 5);
memcpy(pp, MyMessageBox, 150);
NewCode[0] = 0xe9;
DWORD JmpAddr = (DWORD)pp - (DWORD)OldAddr - 5;
memcpy(&NewCode[1], &JmpAddr, 5);
}
else
{
exit(0);
}
}
void HookOn()
{
VirtualProtectEx(hProcess, OldAddr, 5, PAGE_EXECUTE_READWRITE, &OldProtect);
WriteProcessMemory(hProcess, OldAddr, NewCode, 5, 0);
VirtualProtectEx(hProcess, OldAddr, 5, OldProtect, &OldProtect);
VirtualProtectEx(hProcess, pp, 150, PAGE_EXECUTE_READWRITE, &OldProtect);
}
void HookOff()
{
VirtualProtectEx(hProcess, OldAddr, 5, PAGE_EXECUTE_READWRITE, &OldProtect);
WriteProcessMemory(hProcess, OldAddr, OldCode, 5, 0);
VirtualProtectEx(hProcess, OldAddr, 5, OldProtect, &OldProtect);
VirtualProtectEx(hProcess, pp, 150, PAGE_READWRITE, &OldProtect);
}