-
-
[原创]趁手的Hooker,代码还原之前的准备
-
2023-1-25 22:20 6326
-
一个趁手的Hook于逆向代码还原工作而言,犹如一个趁手的兵器于战场上的战士。通过搜罗不同的Hook库,找到了一份适合个人的Hook模块。因为原模块是针对一个游戏的,所以Hook库本身有较多游戏元素的代码片段。于是为了便于日后的使用,本人经过了一些裁剪,以满足自己目前的需求。该模块目前只支持x86,但于个人而言,够用。后续如果有X64需求,再寻求改动。
下面写了一些测试代码,记录和说明模块的用途和用法。测试结果先出:
接下来是代码说明:
完整测试代码如下:
1 2 3 4 5 6 7 8 9 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 | #include <Windows.h> #include<stdio.h> #include "./Plugin/Hooker/Hooker.h" class MathMethod { public: __declspec(noinline) int add( int a, int b) { int nResult = a + b; printf( "methold add, result: %d\n" , nResult); return nResult; } __declspec(noinline) int mul( int a, int b) { int nResult = a * b; printf( "methold mul, result: %d\n" , nResult); return nResult; } __declspec(noinline) int algorithm( int a, int b) { int nResult = mul(add(a, b), 10 ); printf( "algorithm result: %d\n" , nResult); return nResult; } }; class MathMethodFake { public: __declspec(noinline) int add( int a, int b) { printf( "LINE %d : a=%d, b=%d\n" , __LINE__, a, b); return a + b; } __declspec(noinline) int mul( int a, int b) { return plugin::CallMethodAndReturn< int , 0x0401280 , MathMethodFake * , int , int >(this, a, b); } __declspec(noinline) int algorithm( int a, int b) { int nResult = mul(add(a, b), 20 ); printf( "algorithm result: %d\n" , nResult); return nResult; } }; int main( int argc, char * argv[]) { int nResult = 0 ; volatile int a( 2 ), b( 3 ); MathMethod mathMethod; nResult = mathMethod.algorithm(a, b); printf( "LINE %d : nResult=%d\n" , __LINE__, nResult); printf( "LINE %d :\n &MathMethod::mul->%p,\t&MathMethod::algorithm->%p,\t&MathMethod::add->%p\n" , __LINE__ , &MathMethod::mul, &MathMethod::algorithm, &MathMethod::add); printf( "\n-----------Hook start...\n" ); ReversibleHooks::Install( "MathMethodFake" , "add" , 0x0401260 , &MathMethodFake::add); ReversibleHooks::Install( "MathMethodFake" , "algorithm" , 0x04012A0 , &MathMethodFake::algorithm); nResult = mathMethod.algorithm(a, b); printf( "LINE %d : nResult=%d\n" , __LINE__, nResult); system( "pause" ); return 0 ; } |
Hooker模块如下附件。
最后于 2023-1-25 22:43
被_THINCT编辑
,原因:
赞赏
他的文章
[转帖]WinDbg使用笔记
1972
看原图