summaryrefslogtreecommitdiff
path: root/other/Kermit/test/test_patch.cpp
diff options
context:
space:
mode:
authorRoot THC2026-02-24 12:42:47 +0000
committerRoot THC2026-02-24 12:42:47 +0000
commitc9cbeced5b3f2bdd7407e29c0811e65954132540 (patch)
treeaefc355416b561111819de159ccbd86c3004cf88 /other/Kermit/test/test_patch.cpp
parent073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff)
initial
Diffstat (limited to 'other/Kermit/test/test_patch.cpp')
-rw-r--r--other/Kermit/test/test_patch.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/other/Kermit/test/test_patch.cpp b/other/Kermit/test/test_patch.cpp
new file mode 100644
index 0000000..c5bbd94
--- /dev/null
+++ b/other/Kermit/test/test_patch.cpp
@@ -0,0 +1,67 @@
1#include <Patch.hpp>
2#include <SymbolTable.hpp>
3#include <rwKernel.hpp>
4#include <string>
5
6void bla_foo (char *n, bool a)
7{
8 if (a == false)
9 {
10 cout << n << " Failed" << endl;
11 abort ();
12 }
13}
14
15
16int main ()
17{
18 bool foo = false;
19 Patch *mall = NULL;
20 SymbolTable *tab = NULL;
21 Addr2AddrList *x = NULL;
22 rwKernel *y = NULL;
23 unsigned char *tmp = NULL;
24 int w = 0;
25
26 unsigned char sys_malloc[] =
27 "\x55\x89\xe5\x83\xec\x14\x53\xc7\x45\xfc\xee\xee"
28 "\xf8\xf8\xc7\x45\xf8\x00\x00\x00\x00\x83\xc4\xf8"
29 "\x6a\x15\x8b\x45\x08\x50\x8b\x5d\xfc\xff\xd3\x83"
30 "\xc4\x10\x89\xc0\x89\x45\xf8\x8b\x55\xf8\x89\xd0"
31 "\xeb\x06\x8d\xb6\x00\x00\x00\x00\x8b\x5d\xe8\x89"
32 "\xec\x5d\xc3\x90";
33
34 y = new rwKernel ();
35 genDummyValMap ();
36 tab = new SymbolTable (y);
37
38
39/* look up all needed symbols */
40 foo = tab->findSymbol (string ("init"));
41 bla_foo ("init", foo);
42 foo = tab->findSymbol (string ("kmalloc"));
43 bla_foo ("kmalloc", foo);
44
45
46 cout << "Found all needed symbols, proceeding .." << endl;
47 x = genReplaceValMap (tab);
48 if (x == NULL)
49 {
50 cout << "Foo!" << endl;
51 abort ();
52 }
53
54/* insert malloc function [overwritting init] */
55 cout << "Creating patch" << endl;
56 mall = new Patch (sys_malloc, 72, tab->getSymbol ("init"));
57
58 cout << "linking" << endl;
59 mall->link (x);
60 foo = mall->wasChanged ();
61 bla_foo ("link", foo);
62 cout << "appling now ..." << endl;
63 mall->apply (y);
64 cout << "done." << endl;
65 return 0;
66}
67