64,663
社区成员
发帖
与我相关
我的任务
分享
// 111
void _declspec(naked) Hook111Result()
{
__asm {
pushad
pushfd
push edi
call gHook111.disposeCall
popfd
popad
call gHook111.originCall
jmp gHook111.nextOrderAddress
}
}
// 222
void _declspec(naked) Hook222Notify()
{
__asm {
pushad
pushfd
push esi
call gHook222.disposeCall
popfd
popad
call gHook222.originCall
jmp gHook222.nextOrderAddress
}
}
// 定义
template<DWORD MSG_TYPE, DWORD ORIGIN_CALL, DWORD NEXT_ARRRESS, void(*FUNC_PTR)(DWORD type, ...)>
void __declspec(naked) HookTest() {
__asm {
pushad
pushfd
mov eax, MSG_TYPE
push eax
mov eax, esp
push eax
call FUNC_PTR
popfd
popad
call ORIGIN_CALL
jmp NEXT_ARRRESS
}
}
// 测试调用
void main()
{
auto test_block = [](DWORD t, ...) {
std::cout << "dd";
};
// 这里只是测试调用,实际情况是需要注入到软件的某个模块,使用HOOK技术替换相关代码的
// 另外实际项目中肯定是使用全局函数代替lambda的
HookTest<0x0, 0x1, 0x2, test_block >();
}
//codegen.c
// 输入一组字符串,比如
// aa ss ddd dd 33 dd
// 然后自动生成一个函数 int A(const char*);
// 实现A("aa")返回0 A("ss")返回1 依次类推
#include <stdio.h>
int main(int argc,char **argv) {
int i;
if (argc<2) {
printf("%s p1 [p2 ...] [>result.c]\nGenerate code int A(const char *a); 0==A(\"p1\") 1==A(\"p2\") ...",argv[0]);
return 1;
}
//printf("#include <string.h>\n");
printf("int A(const char *a) {\n");
for (i=0;i<argc-1;i++) {
printf(" if (0==strcmp(a,\"%s\")) return %d;\n",argv[i+1],i);
}
printf(" return -1;\n");
printf("}\n");
return 0;
}
//C:\test\Debug>codegen.exe
//codegen.exe p1 [p2 ...] [>result.c]
//Generate code int A(const char *a); 0==A("p1") 1==A("p2") ...
//C:\test\Debug>codegen.exe aa ss ddd dd 33 dd
//int A(const char *a) {
// if (0==strcmp(a,"aa")) return 0;
// if (0==strcmp(a,"ss")) return 1;
// if (0==strcmp(a,"ddd")) return 2;
// if (0==strcmp(a,"dd")) return 3;
// if (0==strcmp(a,"33")) return 4;
// if (0==strcmp(a,"dd")) return 5;
// return -1;
//}
//
//c:\test\Debug>codegen.exe aa ss ddd dd 33 dd >result.c
//
//c:\test\Debug>type result.c
//int A(const char *a) {
// if (0==strcmp(a,"aa")) return 0;
// if (0==strcmp(a,"ss")) return 1;
// if (0==strcmp(a,"ddd")) return 2;
// if (0==strcmp(a,"dd")) return 3;
// if (0==strcmp(a,"33")) return 4;
// if (0==strcmp(a,"dd")) return 5;
// return -1;
//}
//