Skip to content

Commit 3ac0f07

Browse files
committed
Implemented ELF version of the function info getter
1 parent ec4a6ec commit 3ac0f07

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/parser/file/elf/elfFile.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ void elfFile_create(struct elfFile* self) {
4949
self->_.type = ELF_FILE;
5050
self->_.concrete = self;
5151

52-
self->_.addr2String = &elfFile_addr2String;
53-
self->_.destroy = &elfFile_destroy;
54-
self->_.deleter = &elfFile_delete;
52+
self->_.getFunctionInfo = &elfFile_getFunctionInfo;
53+
self->_.addr2String = &elfFile_addr2String;
54+
self->_.destroy = &elfFile_destroy;
55+
self->_.deleter = &elfFile_delete;
56+
5557
lcs_section_create(&self->debugLine);
5658
lcs_section_create(&self->debugLineStr);
5759
lcs_section_create(&self->debugStr);
@@ -363,6 +365,25 @@ static inline optional_debugInfo_t elfFile_getDebugInfo(struct elfFile* self, vo
363365
return toReturn;
364366
}
365367

368+
bool elfFile_getFunctionInfo(struct binaryFile* me, const char* functionName, struct functionInfo* info) {
369+
struct elfFile* self = elfFileOrNull(me);
370+
if (self == NULL) return false;
371+
372+
if (!me->parsed &&
373+
!(me->parsed = elfFile_loadFile(self))) {
374+
return false;
375+
}
376+
377+
vector_iterate(struct function, &self->functions, {
378+
if (strcmp(element->linkedName, functionName) == 0) {
379+
info->begin = (uintptr_t) element->startAddress;
380+
info->length = element->length;
381+
return true;
382+
}
383+
})
384+
return false;
385+
}
386+
366387
bool elfFile_addr2String(struct binaryFile* me, void* address, struct callstack_frame* frame) {
367388
struct elfFile* self = elfFileOrNull(me);
368389
if (self == NULL) return false;

src/parser/file/elf/elfFile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ static inline struct elfFile* elfFileOrNull(struct binaryFile * self) {
9292
*/
9393
bool elfFile_addr2String(struct binaryFile* self, void* address, struct callstack_frame* frame);
9494

95+
bool elfFile_getFunctionInfo(struct binaryFile* self, const char* functionName, struct functionInfo* info);
96+
9597
/**
9698
* Deinitializes the given binary file structure, if it is an ELF file structure.
9799
*

0 commit comments

Comments
 (0)