From e7ccea44e7e462968e34d4daeadec4b4a89bb61b Mon Sep 17 00:00:00 2001 From: Yacine Elhamer Date: Sat, 22 Apr 2023 01:33:00 +0100 Subject: [PATCH] Shdr: add a constructor for vivisect's shdr representation --- capa/features/extractors/elf.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/capa/features/extractors/elf.py b/capa/features/extractors/elf.py index e0dc596c..7c2f2d7a 100644 --- a/capa/features/extractors/elf.py +++ b/capa/features/extractors/elf.py @@ -90,6 +90,24 @@ class Shdr: link: int entsize: int buf: bytes + + @classmethod + def from_viv(cls, section, buf: bytes): + """ + construct a Shdr object from vivisect's representation of + section headers (Elf.Elf32Section or Elf.Elf64Section) + """ + return cls( + int(section.vsGetField('sh_name')), + int(section.vsGetField('sh_type')), + int(section.vsGetField('sh_flags')), + int(section.vsGetField('sh_addr')), + int(section.vsGetField('sh_offset')), + int(section.vsGetField('sh_size')), + int(section.vsGetField('sh_link')), + int(section.vsGetField('sh_entsize')), + buf, + ) class ELF: