1
1
diff -r bbefb8b8e74c dynload/dynload_syms_mach-o.c
2
2
--- a/dynload/dynload_syms_mach-o.c Thu Nov 24 23:47:31 2016 +0000
3
- +++ b/dynload/dynload_syms_mach-o.c Sun Dec 25 20 :36:56 2016 +0100
3
+ +++ b/dynload/dynload_syms_mach-o.c Thu Jan 05 09 :36:39 2017 +0000
4
4
@@ -29,6 +29,7 @@
5
5
dynamic symbol resolver for Mach-O
6
6
@@ -27,7 +27,7 @@ diff -r bbefb8b8e74c dynload/dynload_syms_mach-o.c
27
27
struct DLLib_
28
28
{
29
29
char* libPath;
30
- @@ -58,11 +60,139 @@
30
+ @@ -58,11 +60,143 @@
31
31
32
32
struct DLSyms_
33
33
{
@@ -37,6 +37,10 @@ diff -r bbefb8b8e74c dynload/dynload_syms_mach-o.c
37
37
uint32_t symbolCount;
38
38
};
39
39
40
+ + const struct load_command* get_next_command(const struct load_command* cmd) {
41
+ + return (const struct load_command*)(((char*)cmd) + cmd->cmdsize);
42
+ + }
43
+ +
40
44
+ int isSameMacImageName(const char* libPath, const char* systemLibPath) {
41
45
+ if (!libPath || !systemLibPath)
42
46
+ return 0;
@@ -167,7 +171,7 @@ diff -r bbefb8b8e74c dynload/dynload_syms_mach-o.c
167
171
168
172
DLSyms* dlSymsInit(const char* libPath)
169
173
{
170
- @@ -71,27 +201,61 @@
174
+ @@ -71,37 +205,71 @@
171
175
for (iImage = 0, nImages = _dyld_image_count(); iImage < nImages; iImage++)
172
176
{
173
177
const char* name = _dyld_get_image_name(iImage);
@@ -193,57 +197,70 @@ diff -r bbefb8b8e74c dynload/dynload_syms_mach-o.c
193
197
uint32_t iCmd, nCmds = pHeader->ncmds;
194
198
const struct load_command* cmd = (const struct load_command*)(pBase + sizeof(struct MACH_HEADER_TYPE));
195
199
200
+ + // First, try and find a LC_SYMTAB
201
+ + for (iCmd = 0; iCmd < nCmds; iCmd++)
202
+ + {
203
+ + if (cmd->cmd == LC_SYMTAB)
204
+ + {
205
+ + const struct symtab_command* scmd = (const struct symtab_command*)cmd;
206
+ +
207
+ + pSyms = (DLSyms*)( dlAllocMem(sizeof(DLSyms)) );
208
+ + //memset(pSyms, sizeof(DLSyms), 0);
209
+ + pSyms->decompressedSymbols = NULL;
210
+ + pSyms->symbolCount = scmd->nsyms;
211
+ + pSyms->pStringTable = pBase + scmd->stroff;
212
+ + pSyms->pSymbolTable = (struct NLIST_TYPE*)(pBase + scmd->symoff);
213
+ +
214
+ + return pSyms;
215
+ + }
216
+ + cmd = get_next_command(cmd);
217
+ + }
218
+ +
219
+ + // Then, try and use LC_DYLD_INFO_ONLY or LC_DYLD_INFO and parse their trie.
196
220
for (iCmd = 0; iCmd < nCmds; iCmd++)
197
221
{
198
222
- if (cmd->cmd == LC_SYMTAB)
199
223
- {
200
- + if (!cmd) continue;
201
- +
224
+ - const struct symtab_command* scmd = (const struct symtab_command*)cmd;
225
+ -
226
+ - pSyms = (DLSyms*)( dlAllocMem(sizeof(DLSyms)) );
227
+ - pSyms->symbolCount = scmd->nsyms;
228
+ - pSyms->pStringTable = pBase + scmd->stroff;
229
+ - pSyms->pSymbolTable = (struct NLIST_TYPE*)(pBase + scmd->symoff);
230
+ -
231
+ - return pSyms;
232
+ - }
233
+ - cmd = (const struct load_command*)(((char*)cmd) + cmd->cmdsize);
202
234
+ if (cmd->cmd == LC_DYLD_INFO_ONLY || cmd->cmd == LC_DYLD_INFO) {
203
- + const struct dyld_info_command* dcmd = (const struct dyld_info_command*)cmd;
204
- + const unsigned char* trie = (pBase + dcmd->export_off);
205
- +
206
- + pSyms = (DLSyms*)( dlAllocMem(sizeof(DLSyms)) );
207
- +
208
- + // First, get the number of symbols
209
- + pSyms->symbolCount = visitTrie(trie, trie, trie + dcmd->export_size, NULL, NULL, 0, NULL, 0);
210
- +
211
- + if (pSyms->symbolCount) {
212
- + // Now revisit and copy symbols to their destination
213
- + DCString s;
214
- + size_t decompSize = pSyms->symbolCount * sizeof(char*) * 2;
215
- + pSyms->decompressedSymbols = dlAllocMem(decompSize);
216
- + memset(pSyms->decompressedSymbols, decompSize, 0);
217
- + initString(&s, 1024);
218
- + visitTrie(trie, trie, trie + dcmd->export_size, &s, CopyToNthString, 0, pSyms->decompressedSymbols, 0);
219
- + freeString(&s);
220
- + }
221
- +
222
- + return pSyms;
223
- + }
224
- +
225
- + if (cmd->cmd & LC_REQ_DYLD) {
226
- + return NULL; // "unknown load command required for execution";
227
- + }
228
- + if (cmd->cmd == LC_SYMTAB)
229
- + {
230
- const struct symtab_command* scmd = (const struct symtab_command*)cmd;
231
-
232
- pSyms = (DLSyms*)( dlAllocMem(sizeof(DLSyms)) );
233
- + //memset(pSyms, sizeof(DLSyms), 0);
234
- + pSyms->decompressedSymbols = NULL;
235
- pSyms->symbolCount = scmd->nsyms;
236
- pSyms->pStringTable = pBase + scmd->stroff;
237
- pSyms->pSymbolTable = (struct NLIST_TYPE*)(pBase + scmd->symoff);
238
- @@ -101,7 +265,6 @@
239
- cmd = (const struct load_command*)(((char*)cmd) + cmd->cmdsize);
235
+ + const struct dyld_info_command* dcmd = (const struct dyld_info_command*)cmd;
236
+ + const unsigned char* trie = (pBase + dcmd->export_off);
237
+ +
238
+ + pSyms = (DLSyms*)( dlAllocMem(sizeof(DLSyms)) );
239
+ +
240
+ + // First, get the number of symbols
241
+ + pSyms->symbolCount = visitTrie(trie, trie, trie + dcmd->export_size, NULL, NULL, 0, NULL, 0);
242
+ +
243
+ + if (pSyms->symbolCount) {
244
+ + // Now revisit and copy symbols to their destination
245
+ + DCString s;
246
+ + size_t decompSize = pSyms->symbolCount * sizeof(char*) * 2;
247
+ + pSyms->decompressedSymbols = dlAllocMem(decompSize);
248
+ + memset(pSyms->decompressedSymbols, decompSize, 0);
249
+ + initString(&s, 1024);
250
+ + visitTrie(trie, trie, trie + dcmd->export_size, &s, CopyToNthString, 0, pSyms->decompressedSymbols, 0);
251
+ + freeString(&s);
252
+ + }
253
+ +
254
+ + return pSyms;
255
+ + }
256
+ + cmd = get_next_command(cmd);
240
257
}
241
258
}
242
259
- break;
243
260
}
244
261
}
245
262
return NULL;
246
- @@ -113,6 +276 ,18 @@
263
+ @@ -113,6 +281 ,18 @@
247
264
if (!pSyms)
248
265
return;
249
266
@@ -262,7 +279,7 @@ diff -r bbefb8b8e74c dynload/dynload_syms_mach-o.c
262
279
dlFreeMem(pSyms);
263
280
}
264
281
265
- @@ -133,6 +308 ,11 @@
282
+ @@ -133,6 +313 ,11 @@
266
283
if (nl->n_un.n_strx <= 1)
267
284
return NULL; // would be empty string anyway
268
285
@@ -274,7 +291,7 @@ diff -r bbefb8b8e74c dynload/dynload_syms_mach-o.c
274
291
//TODO skip more symbols based on nl->n_desc and nl->n_type ?
275
292
return nl;
276
293
}
277
- @@ -140,6 +320 ,12 @@
294
+ @@ -140,6 +325 ,12 @@
278
295
279
296
const char* dlSymsName(DLSyms* pSyms, int index)
280
297
{
@@ -287,7 +304,7 @@ diff -r bbefb8b8e74c dynload/dynload_syms_mach-o.c
287
304
const struct NLIST_TYPE* nl = get_nlist(pSyms, index);
288
305
if (!nl)
289
306
return NULL;
290
- @@ -150,6 +336 ,12 @@
307
+ @@ -150,6 +341 ,12 @@
291
308
292
309
void* dlSymsValue(DLSyms* pSyms, int index)
293
310
{
@@ -302,7 +319,7 @@ diff -r bbefb8b8e74c dynload/dynload_syms_mach-o.c
302
319
return NULL;
303
320
diff -r bbefb8b8e74c dynload/dynload_unix.c
304
321
--- a/dynload/dynload_unix.c Thu Nov 24 23:47:31 2016 +0000
305
- +++ b/dynload/dynload_unix.c Sun Dec 25 20 :36:56 2016 +0100
322
+ +++ b/dynload/dynload_unix.c Thu Jan 05 09 :36:39 2017 +0000
306
323
@@ -41,7 +41,7 @@
307
324
308
325
DLLib* dlLoadLibrary(const char* libPath)
@@ -314,7 +331,7 @@ diff -r bbefb8b8e74c dynload/dynload_unix.c
314
331
315
332
diff -r bbefb8b8e74c dynload/dynload_windows.c
316
333
--- a/dynload/dynload_windows.c Thu Nov 24 23:47:31 2016 +0000
317
- +++ b/dynload/dynload_windows.c Sun Dec 25 20 :36:56 2016 +0100
334
+ +++ b/dynload/dynload_windows.c Thu Jan 05 09 :36:39 2017 +0000
318
335
@@ -41,7 +41,9 @@
319
336
DLLib* dlLoadLibrary(const char* libPath)
320
337
{
0 commit comments