Skip to content

Commit ec4a6ec

Browse files
committed
Implemented the Mach-O version of the function info getter
1 parent b251e29 commit ec4a6ec

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/parser/file/macho/machoFile.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ void machoFile_create(struct machoFile* self) {
5454
self->_.type = MACHO_FILE;
5555
self->_.concrete = self;
5656

57-
self->_.addr2String = &machoFile_addr2String;
58-
self->_.destroy = &machoFile_destroy;
59-
self->_.deleter = &machoFile_delete;
57+
self->_.getFunctionInfo = &machoFile_getFunctionInfo;
58+
self->_.addr2String = &machoFile_addr2String;
59+
self->_.destroy = &machoFile_destroy;
60+
self->_.deleter = &machoFile_delete;
6061

6162
self->addressOffset = 0;
6263
self->linkedit_fileoff = 0;
@@ -375,6 +376,26 @@ static inline bool machoFile_loadFile(struct machoFile* self) {
375376
return success;
376377
}
377378

379+
bool machoFile_getFunctionInfo(struct binaryFile* me, const char* functionName, struct functionInfo* info) {
380+
struct machoFile* self = machoFileOrNull(me);
381+
if (self == NULL) {
382+
return false;
383+
}
384+
if (!self->_.parsed &&
385+
!(self->_.parsed = machoFile_loadFile(self))) {
386+
return false;
387+
}
388+
389+
vector_iterate(pair_funcFile_t, &self->functions, {
390+
if (strcmp(element->first.linkedName, functionName) == 0) {
391+
info->begin = (uintptr_t) element->first.startAddress;
392+
info->length = element->first.length;
393+
return true;
394+
}
395+
})
396+
return false;
397+
}
398+
378399
bool machoFile_addr2String(struct binaryFile* me, void* address, struct callstack_frame* frame) {
379400
struct machoFile * self = machoFileOrNull(me);
380401
if (self == NULL) {

src/parser/file/macho/machoFile.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ struct machoFile {
6464
/**
6565
* Allocates and initializes a Mach-O file structure.
6666
*
67-
* @param fileName the name of the file
6867
* @return the allocated Mach-O file structure or `NULL` on error
6968
*/
7069
struct machoFile* machoFile_new(void);
@@ -98,6 +97,8 @@ static inline struct machoFile* machoFileOrNull(struct binaryFile * self) {
9897
*/
9998
bool machoFile_addr2String(struct binaryFile* self, void* address, struct callstack_frame* frame);
10099

100+
bool machoFile_getFunctionInfo(struct binaryFile* self, const char* functionName, struct functionInfo* info);
101+
101102
/**
102103
* Deinitializes the given binary file structure if it is a Mach-O file structure.
103104
*

0 commit comments

Comments
 (0)