01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
|
BOOL
WINAPI my_Process32NextW(
HANDLE
hSnapshot, LPPROCESSENTRY32W lppe)
{
CAdAutoHookApi autoHook(&gHooks, my_Process32NextW);
BOOL
ret = Process32Next(hSnapshot, lppe);
if
(ret)
{
// logOutput(formatString("Process32Next(0x%08X, Exe:%S)\r\n", (int)hSnapshot, lppe->szExeFile));
if
(_wcsicmp(lppe->szExeFile, L
"devenv.exe"
) == 0)
{
wcscpy(lppe->szExeFile, L
"crack.exe"
);
logOutput(
"Process32Next, Rename \"devenv.exe\" to \"crack.exe\"\r\n"
);
}
}
return
ret;
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
hasp_status_t HASP_CALLCONV my_hasp_login(hasp_feature_t feature_id,
hasp_vendor_code_t vendor_code,
hasp_handle_t *handle)
{
logOutput(formatString(
"HASP API : Call hasp_login(%d)\r\n"
, (
int
)feature_id));
*handle = 0x88888888;
return
HASP_STATUS_OK;
}
hasp_status_t HASP_CALLCONV my_hasp_login_scope(hasp_feature_t feature_id,
const
char
*scope,
hasp_vendor_code_t vendor_code,
hasp_handle_t *handle)
{
logOutput(formatString(
"HASP API : Call hasp_login_scope(%d)\r\n"
, (
int
)feature_id));
*handle = 0x88888888;
return
HASP_STATUS_OK;
}
hasp_status_t HASP_CALLCONV my_hasp_encrypt(hasp_handle_t handle,
void
*buffer,
hasp_size_t length)
{
logOutput(formatString(
"HASP API : Call hasp_encrypt(0x%08X, 0x%08X, %d)\r\n"
,
(
int
)handle, (
int
)buffer, (
int
)length));
return
HASP_STATUS_OK;
}
hasp_status_t HASP_CALLCONV my_hasp_decrypt(hasp_handle_t handle,
void
*buffer,
hasp_size_t length)
{
logOutput(formatString(
"HASP API : Call hasp_decrypt(0x%08X, 0x%08X, %d)\r\n"
,
(
int
)handle, (
int
)buffer, (
int
)length));
这部分代码后面再说。。。
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
int
HookHaspAPI_Begin()
{
if
(!g_is_hasp_login_scope)
{
void
*pOldAddr = (
void
*)0x0053FCE0;
const
BYTE
verifyData[] = { 0x81, 0xEC, 0x00, 0x04, 0x00, 0x00, 0x56 };
HANDLE
hHook = gHooks.Add(pOldAddr, my_hasp_login_scope, verifyData,
sizeof
(verifyData));
if
(hHook != NULL)
{
gHooks.Begin(hHook);
logOutput(formatString(
"HASP API : hasp_login_scope hooked\r\n"
));
g_is_hasp_login_scope =
true
;
}
}
if
(!g_is_hasp_encrypt)
{
void
*pOldAddr = (
void
*)0x0053EF60;
const
BYTE
verifyData[] = { 0x56, 0x8B, 0x74, 0x24, 0x10, 0x83, 0xFE, 0x08 };
HANDLE
hHook = gHooks.Add(pOldAddr, my_hasp_encrypt, verifyData,
sizeof
(verifyData));
if
(hHook != NULL)
{
gHooks.Begin(hHook);
logOutput(formatString(
"HASP API : my_hasp_encrypt hooked\r\n"
));
g_is_hasp_encrypt =
true
;
}
}
if
(!g_is_hasp_decrypt)
{
void
*pOldAddr = (
void
*)0x0053F000;
const
BYTE
verifyData[] = { 0x56, 0x8B, 0x74, 0x24, 0x10, 0x83, 0xFE, 0x08 };
HANDLE
hHook = gHooks.Add(pOldAddr, my_hasp_decrypt, verifyData,
sizeof
(verifyData));
if
(hHook != NULL)
{
gHooks.Begin(hHook);
logOutput(formatString(
"HASP API : my_hasp_decrypt hooked\r\n"
));
g_is_hasp_decrypt =
true
;
}
}
if
(!g_is_hasp_get_info)
{
void
*pOldAddr = (
void
*)0x0053FDE0;
const
BYTE
verifyData[] = { 0x81, 0xEC, 0xB8, 0x09, 0x00, 0x00, 0x8B, 0x84 };
HANDLE
hHook = gHooks.Add(pOldAddr, my_hasp_get_info, verifyData,
sizeof
(verifyData));
if
(hHook != NULL)
{
gHooks.Begin(hHook);
logOutput(formatString(
"HASP API : my_hasp_get_info hooked\r\n"
));
g_is_hasp_get_info =
true
;
}
}
if
(!g_is_hasp_logout)
{
void
*pOldAddr = (
void
*)0x0053EED0;
const
BYTE
verifyData[] = { 0x56, 0x8B, 0x74, 0x24, 0x08, 0x6A, 0x00 };
HANDLE
hHook = gHooks.Add(pOldAddr, my_hasp_logout, verifyData,
sizeof
(verifyData));
if
(hHook != NULL)
{
gHooks.Begin(hHook);
logOutput(formatString(
"HASP API : my_hasp_logout hooked\r\n"
));
g_is_hasp_logout =
true
;
}
}
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
FARPROC WINAPI my_GetProcAddress(
HMODULE
hModule,
LPCSTR
lpProcName)
{
CAdAutoHookApi autoHook(&gHooks, my_GetProcAddress);
FARPROC ret = GetProcAddress(hModule, lpProcName);
string moduleName = getFileName(getModuleNameA(hModule));
if
(IsBadStringPtrA(lpProcName, 255))
{
// logOutput(formatString("GetProcAddress(0x%08X(%s), 0x%08X) : 0x%08X\r\n",
// (int)hModule, moduleName.c_str(), (int)lpProcName, (int)ret));
}
else
{
// logOutput(formatString("GetProcAddress(0x%08X(%s), %s) : 0x%08X\r\n",
// (int)hModule, moduleName.c_str(), (lpProcName != NULL) ? lpProcName : "NULL", (int)ret));
/*
if(strcmp(lpProcName, "LoadLibraryA") == 0)
{
MessageBoxW(::GetDesktopWindow(), L"GetProcAddress(LoadLibraryA)", L"ApiDebugger", MB_OK);
}
*/
}
HookHaspAPI_Begin();
return
ret;
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
|
007040FB 8A5429 F0
MOV
DL
,
BYTE
PTR
DS
:[
ECX
+
EBP
-10]
007040FF 3BC2
CMP
EAX
,
EDX
// 这里是判断,这是壳程序的检查
00704101 68 3D457000
PUSH
AAA
.0070453D
00704106 C3
RETN
00704107 D840 E9
FADD
DWORD
PTR
DS
:[
EAX
-17]
0070410A FFF9 ???
; Unknown command
0070410C FFFF ???
; Unknown command
0052B45B 8A5429 F0
MOV
DL
,
BYTE
PTR
DS
:[
ECX
+
EBP
-10]
0052B45F 3BC2
CMP
EAX
,
EDX
// 同样的代码,也是判断,这是主程序运行后的检查
0052B461 68 9DB85200
PUSH
AAA
.0052B89D
0052B466 C3
RETN
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
|
PUSH
EAX
MOV
EAX
,
DWORD
PTR
DS
:[
EDX
+52C4E4+0]
MOV
DWORD
PTR
DS
:[
EBP
-10+0],
EAX
MOV
EAX
,
DWORD
PTR
DS
:[
EDX
+52C4E4+4]
MOV
DWORD
PTR
DS
:[
EBP
-10+4],
EAX
MOV
EAX
,
DWORD
PTR
DS
:[
EDX
+52C4E4+8]
MOV
DWORD
PTR
DS
:[
EBP
-10+8],
EAX
MOV
EAX
,
DWORD
PTR
DS
:[
EDX
+52C4E4+0C]
MOV
DWORD
PTR
DS
:[
EBP
-10+0C],
EAX
POP
EAX
MOV
DL
,
AL
CMP
EAX
,
EDX
JMP
0052B461
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
hasp_status_t HASP_CALLCONV my_hasp_decrypt(hasp_handle_t handle,
void
*buffer,
hasp_size_t length)
{
logOutput(formatString(
"HASP API : Call hasp_decrypt(0x%08X, 0x%08X, %d)\r\n"
,
(
int
)handle, (
int
)buffer, (
int
)length));
if
(length == 0x8000)
{
const
BYTE
data1[] = { 0x41, 0xC9, 0x2A, 0x77, 0x12, 0xA5, 0xB3, 0x6B };
const
BYTE
data2[] = { 0x08, 0xB3, 0xC4, 0x2E, 0xC8, 0xAF, 0x78, 0x6E };
if
(
memcmp
(buffer, data1,
sizeof
(data1)) == 0)
{
// writeDataToFile("data.dec1.bin", buffer, length);
if
(readDataFromFile(
"data.enc1.bin"
, buffer, length) == length)
{
logOutput(formatString(
"HASP API : Read data from \"data.enc1.bin\"\r\n"
));
}
}
if
(
memcmp
(buffer, data2,
sizeof
(data2)) == 0)
{
// writeDataToFile("data.dec2.bin", buffer, length);
if
(readDataFromFile(
"data.enc2.bin"
, buffer, length) == length)
{
logOutput(formatString(
"HASP API : Read data from \"data.enc2.bin\"\r\n"
));
}
}
}
else
if
((length == 16) && (
memcmp
(buffer, gZeroInput,
sizeof
(gZeroInput)) == 0))
{
memcpy
(buffer, gZeroOutput, length);
logOutput(formatString(
"HASP API : Decrypt Zero Buffer.\r\n"
));
string hexData = string(
"E : "
) + toHexString((
const
char
*)buffer, length) +
"\r\n"
;
logOutput(hexData);
}
else
{
writeDataToFile(
"enc.bin"
, buffer, length);
string hexData = string(
"D : "
) + toHexString((
const
char
*)buffer, length) +
"\r\n"
;
logOutput(hexData);
memset
(buffer, 0, length);
if
(!g_is_patch_code1)
{
// 0052B45B
const
BYTE
verifyData[] = { 0x8A, 0x54, 0x29, 0xF0, 0x3B, 0xC2, 0x68 };
const
BYTE
patchCode[] = { 0x3B, 0xC0 };
void
*pVerifyAddr = (
void
*)0x0052B45B;
void
*pPatchAddr = (
void
*)0x0052B45F;
if
(CAdHookApi::VerifyAddress(pVerifyAddr, verifyData,
sizeof
(verifyData)))
{
if
(CAdHookApi::PatchCode(pPatchAddr, patchCode,
sizeof
(patchCode)))
{
logOutput(formatString(
"HASP API : Patch Address 0x0052B45F, (CMP EAX, EAX)\r\n"
));
g_is_patch_code1 =
true
;
}
}
}
if
(!g_is_patch_code2)
{
// 007040FB
const
BYTE
verifyData[] = { 0x8A, 0x54, 0x29, 0xF0, 0x3B, 0xC2, 0x68 };
const
BYTE
patchCode[] = { 0x3B, 0xC0 };
void
*pVerifyAddr = (
void
*)0x007040FB;
void
*pPatchAddr = (
void
*)0x007040FF;
if
(CAdHookApi::VerifyAddress(pVerifyAddr, verifyData,
sizeof
(verifyData)))
{
if
(CAdHookApi::PatchCode(pPatchAddr, patchCode,
sizeof
(patchCode)))
{
logOutput(formatString(
"HASP API : Patch Address 0x007040FF, (CMP EAX, EAX)\r\n"
));
g_is_patch_code2 =
true
;
ApiDebugferShutdown();
}
}
}
}
return
HASP_STATUS_OK;
}
|