Skip to content

Commit

Permalink
code style: Format elf.py for the black linter
Browse files Browse the repository at this point in the history
  • Loading branch information
yelhamer committed Apr 23, 2023
1 parent b32a8ca commit 5a4ca9c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions capa/features/extractors/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ def from_viv(cls, section, buf: bytes):
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')),
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:
Expand Down
12 changes: 6 additions & 6 deletions capa/features/extractors/viv/insn.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,18 @@ def extract_insn_api_features(fh: FunctionHandle, bb, ih: InsnHandle) -> Iterato
yield API(name[1:]), ih.address
return

if f.vw.metadata['Format'] == 'elf':
if not hasattr(extract_insn_api_features, 'symtab'):
if f.vw.metadata["Format"] == "elf":
if not hasattr(extract_insn_api_features, "symtab"):
# the symbol table gets stored as a function's attribute in order to avoid running
# this code everytime the call is made, thus preventing the computational overhead.
elf = f.vw.parsedbin
endian = '<' if elf.getEndian() == 0 else '>'
endian = "<" if elf.getEndian() == 0 else ">"
bitness = elf.bits

SHT_SYMTAB = 0x2
for section in elf.sections:
if section.vsGetField('sh_info') & SHT_SYMTAB != 0:
strtab = elf.sections[section.vsGetField('sh_link')]
if section.vsGetField("sh_info") & SHT_SYMTAB != 0:
strtab = elf.sections[section.vsGetField("sh_link")]
sh_symtab = Shdr.from_viv(section, elf.getSectionBytes(section.name))
sh_strtab = Shdr.from_viv(strtab, elf.getSectionBytes(strtab.name))

Expand All @@ -145,7 +145,7 @@ def extract_insn_api_features(fh: FunctionHandle, bb, ih: InsnHandle) -> Iterato
sym_name = symtab.get_name(symbol)
sym_value = symbol.value
sym_info = symbol.info

STT_FUNC = 0x2
if sym_value == target and sym_info & STT_FUNC != 0:
yield API(sym_name), ih.address
Expand Down

0 comments on commit 5a4ca9c

Please sign in to comment.