binsync / libbs

A library for writing plugins in any decompiler: includes API lifting, common data formatting, and GUI abstraction!
BSD 2-Clause "Simplified" License
71 stars 6 forks source link

Support scope names in Structs and Enums #97

Open mahaloz opened 3 months ago

mahaloz commented 3 months ago

In Ghidra, structs can look like this:

dict_items([('ELF/Elf64_Ehdr', <Struct: ELF/Elf64_Ehdr membs=21 (0x40)>), ('ELF/Elf64_Phdr', <Struct: ELF/Elf64_Phdr membs=8 (0x38)>), ('ELF/Elf64_Shdr', <Struct: ELF/Elf64_Shdr membs=10 (0x40)>), ('ELF/Elf64_Dyn', <Struct: ELF/Elf64_Dyn membs=2 (0x10)>), ('ELF/Elf64_Sym', <Struct: ELF/Elf64_Sym membs=6 (0x18)>), ('ELF/Elf64_Rela', <Struct: ELF/Elf64_Rela membs=3 (0x18)>), ('ELF/NoteAbiTag', <Struct: ELF/NoteAbiTag membs=6 (0x20)>), ('ELF/GnuBuildId', <Struct: ELF/GnuBuildId membs=5 (0x24)>), ('eh_frame_hdr', <Struct: eh_frame_hdr membs=4 (0x4)>), ('fde_table_entry', <Struct: fde_table_entry membs=2 (0x8)>), ('ossl_typ.h/evp_pkey_ctx_st', <Struct: ossl_typ.h/evp_pkey_ctx_st membs=0 (0x1)>), ('stdio.h/_IO_FILE', <Struct: stdio.h/_IO_FILE membs=29 (0xd8)>), ('libio.h/_IO_marker', <Struct: libio.h/_IO_marker membs=3 (0x18)>)])

The name is like libio.h/_IO_marker, which is a problem, since we often try to lookup structs by their name in other plugins. This needs to be normalized by adding a scope property to both enums and struct, which normally will be None. For Ghidra, we will put everything before the name as the scope.

This can also be useful for future Class support.