Clean up libelfin_wrap functions api

This commit is contained in:
kamkow1
2025-03-13 14:03:04 +01:00
parent a9f555d916
commit 4f60dfcd4d
3 changed files with 63 additions and 56 deletions

View File

@@ -19,7 +19,7 @@ class LibelfinBinding
uintptr_t loadoffset;
};
DEBUGUS_EXTERNC void libelfin_wrap_get_syms(PLibelfinBinding *pbind, Symbols *syms)
DEBUGUS_EXTERNC void libelfin_wrap_get_funcs(PLibelfinBinding pbind, Funcs *funcs)
{
LibelfinBinding *bind = (LibelfinBinding *)pbind;
for (auto &section : bind->elf.sections()) {
@@ -27,18 +27,24 @@ DEBUGUS_EXTERNC void libelfin_wrap_get_syms(PLibelfinBinding *pbind, Symbols *sy
for (auto sym : section.as_symtab()) {
auto &d = sym.get_data();
if (d.type() == elf::stt::func) {
Symbol s = {
Func f = {
.name = (const char *)malloc(strlen(sym.get_name().c_str())+1),
.addr = bind->loadoffset + (uintptr_t)d.value,
.ai = libelfin_wrap_info_from_rip(pbind, (uintptr_t)d.value),
};
strcpy((char*)s.name, sym.get_name().c_str());
da_append(syms, s);
strcpy((char*)f.name, sym.get_name().c_str());
da_append(funcs, f);
}
}
}
}
}
DEBUGUS_EXTERNC uintptr_t libelfin_wrap_func_addr(PLibelfinBinding pbind, Func *f)
{
LibelfinBinding *bind = (LibelfinBinding *)pbind;
return bind->loadoffset + f->ai->addr;
}
DEBUGUS_EXTERNC PLibelfinBinding libelfin_wrap_get_binding(int fd, uintptr_t loadoffset)
{
return (PLibelfinBinding)new LibelfinBinding(fd, loadoffset);