@@ -22,6 +22,54 @@ static int (*org_UnloadModule)(int id);
22
22
static int (* org_SearchModuleByName )(const char * modname );
23
23
static int (* org_ReferModuleStatus )(int mid , ModuleStatus * status );
24
24
25
+ #if 0 //def DEBUG // Too much text output, enable when needed
26
+ //--------------------------------------------------------------
27
+ static void print_libs ()
28
+ {
29
+ ModuleInfo_t * m = GetLoadcoreInternalData ()-> image_info ;
30
+ M_DEBUG ("Module list:\n" );
31
+ M_DEBUG (" name | start | text | data | bss\n" );
32
+ while (m != NULL ) {
33
+ M_DEBUG (" %-22s | 0x%6x | %6d | %5d | %5d\n" , m -> name , m -> text_start , m -> text_size , m -> data_size , m -> bss_size );
34
+ m = m -> next ;
35
+ }
36
+ }
37
+ #else
38
+ static inline void print_libs () {}
39
+ #endif
40
+
41
+ #ifdef DEBUG
42
+ //--------------------------------------------------------------
43
+ static void print_args (int arg_len , char * args )
44
+ {
45
+ // Multiple null terminated strings together
46
+ int args_idx = 0 ;
47
+ int was_null = 1 ;
48
+
49
+ if (arg_len == 0 )
50
+ return ;
51
+
52
+ M_DEBUG ("Module arguments (arg_len=%d):\n" , arg_len );
53
+
54
+ // Search strings
55
+ while (args_idx < arg_len ) {
56
+ if (args [args_idx ] == 0 ) {
57
+ if (was_null == 1 ) {
58
+ M_DEBUG ("- args[%d]=0\n" , args_idx );
59
+ }
60
+ was_null = 1 ;
61
+ }
62
+ else if (was_null == 1 ) {
63
+ M_DEBUG ("- args[%d]='%s'\n" , args_idx , & args [args_idx ]);
64
+ was_null = 0 ;
65
+ }
66
+ args_idx ++ ;
67
+ }
68
+ }
69
+ #else
70
+ static inline void print_args (int arg_len , char * args ) {}
71
+ #endif
72
+
25
73
//--------------------------------------------------------------
26
74
static struct FakeModule * checkFakemodByFile (const char * path , struct FakeModule * fakemod_list )
27
75
{
@@ -64,45 +112,14 @@ static struct FakeModule *checkFakemodById(int id, struct FakeModule *fakemod_li
64
112
return NULL ;
65
113
}
66
114
67
- #ifdef DEBUG
68
- //--------------------------------------------------------------
69
- static void print_args (int arg_len , char * args )
70
- {
71
- // Multiple null terminated strings together
72
- int args_idx = 0 ;
73
- int was_null = 1 ;
74
-
75
- if (arg_len == 0 )
76
- return ;
77
-
78
- M_DEBUG ("Module arguments (arg_len=%d):\n" , arg_len );
79
-
80
- // Search strings
81
- while (args_idx < arg_len ) {
82
- if (args [args_idx ] == 0 ) {
83
- if (was_null == 1 ) {
84
- M_DEBUG ("- args[%d]=0\n" , args_idx );
85
- }
86
- was_null = 1 ;
87
- }
88
- else if (was_null == 1 ) {
89
- M_DEBUG ("- args[%d]='%s'\n" , args_idx , & args [args_idx ]);
90
- was_null = 0 ;
91
- }
92
- args_idx ++ ;
93
- }
94
- }
95
- #endif
96
-
97
115
//--------------------------------------------------------------
98
116
static int Hook_LoadStartModule (char * modpath , int arg_len , char * args , int * modres )
99
117
{
100
118
struct FakeModule * mod ;
101
119
120
+ print_libs ();
102
121
M_DEBUG ("%s(%s, %d, ...)\n" , __FUNCTION__ , modpath , arg_len );
103
- #ifdef DEBUG
104
122
print_args (arg_len , args );
105
- #endif
106
123
107
124
mod = checkFakemodByFile (modpath , fmd .fake );
108
125
if (mod != NULL ) {
@@ -131,9 +148,7 @@ static int Hook_StartModule(int id, char *modname, int arg_len, char *args, int
131
148
struct FakeModule * mod ;
132
149
133
150
M_DEBUG ("%s(0x%x, %s, %d, ...)\n" , __FUNCTION__ , id , modname , arg_len );
134
- #ifdef DEBUG
135
151
print_args (arg_len , args );
136
- #endif
137
152
138
153
mod = checkFakemodById (id , fmd .fake );
139
154
if (mod != NULL ) {
@@ -164,7 +179,8 @@ static int Hook_LoadModuleBuffer(void *ptr)
164
179
elf_pheader_t * eph = (elf_pheader_t * )(ptr + eh -> phoff );
165
180
const char * modname = (const char * )ptr + eph -> offset + 0x1a ;
166
181
167
- M_DEBUG ("%s() modname = '%s'\n" , __FUNCTION__ , modname );
182
+ print_libs ();
183
+ M_DEBUG ("%s(0x%x) modname = '%s'\n" , __FUNCTION__ , ptr , modname );
168
184
169
185
mod = checkFakemodByName (modname , fmd .fake );
170
186
if (mod != NULL ) {
@@ -192,9 +208,7 @@ static int Hook_StopModule(int id, int arg_len, char *args, int *modres)
192
208
struct FakeModule * mod ;
193
209
194
210
M_DEBUG ("%s(0x%x, %d, ...)\n" , __FUNCTION__ , id , arg_len );
195
- #ifdef DEBUG
196
211
print_args (arg_len , args );
197
- #endif
198
212
199
213
mod = checkFakemodById (id , fmd .fake );
200
214
if (mod != NULL ) {
@@ -255,11 +269,11 @@ static int Hook_ReferModuleStatus(int id, ModuleStatus *status)
255
269
{
256
270
struct FakeModule * mod ;
257
271
258
- M_DEBUG ("%s(0x%x, ...)\n" , __FUNCTION__ , id );
272
+ // M_DEBUG("%s(0x%x, ...)\n", __FUNCTION__, id);
259
273
260
274
mod = checkFakemodById (id , fmd .fake );
261
275
if (mod != NULL && mod -> returnLoad == 0 ) {
262
- M_DEBUG ("- FAKING! id=0x%x\n" , mod -> id );
276
+ // M_DEBUG("- FAKING! id=0x%x\n", mod->id);
263
277
memset (status , 0 , sizeof (ModuleStatus ));
264
278
strcpy (status -> name , mod -> name );
265
279
status -> version = mod -> version ;
@@ -275,8 +289,11 @@ int _start(int argc, char **argv)
275
289
{
276
290
int i ;
277
291
292
+ print_libs ();
293
+
278
294
// Change string index to string pointers
279
295
M_DEBUG ("Fake module list:\n" );
296
+ M_DEBUG (" fname | name | vers. | rl | rs | prop\n" );
280
297
for (i = 0 ; i < MODULE_SETTINGS_MAX_FAKE_COUNT ; i ++ ) {
281
298
struct FakeModule * fm = & fmd .fake [i ];
282
299
@@ -293,7 +310,7 @@ int _start(int argc, char **argv)
293
310
}
294
311
295
312
if (fm -> fname != NULL ) {
296
- M_DEBUG (" %d: % 12s | %-14s | 0x%3x | %3d | %d | 0x%x\n" , i , fm -> fname , fm -> name , fm -> version , fm -> returnLoad , fm -> returnStart , fm -> prop );
313
+ M_DEBUG (" %12s | %-14s | 0x%3x | %3d | %2d | 0x%x\n" , fm -> fname , fm -> name , fm -> version , fm -> returnLoad , fm -> returnStart , fm -> prop );
297
314
}
298
315
}
299
316
0 commit comments