Skip to content

Commit

Permalink
focus on data references only
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-hunhoff committed Dec 1, 2023
1 parent f868a75 commit 1374570
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions capa/features/extractors/ghidra/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ def dereference_ptr(insn: ghidra.program.database.code.InstructionDB):
return to_deref


def find_memory_references_from_insn(insn, max_depth: int = 10):
"""yield memory references from given instruction"""
def find_data_references_from_insn(insn, max_depth: int = 10):
"""yield data references from given instruction"""
for reference in insn.getReferencesFrom():
if not reference.isMemoryReference():
# only care about memory references
if not reference.getReferenceType().isData():
# only care about data references
continue

to_addr = reference.getToAddress()
Expand Down
4 changes: 2 additions & 2 deletions capa/features/extractors/ghidra/insn.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def extract_insn_bytes_features(fh: FunctionHandle, bb: BBHandle, ih: InsnHandle
example:
push offset iid_004118d4_IShellLinkA ; riid
"""
for addr in capa.features.extractors.ghidra.helpers.find_memory_references_from_insn(ih.inner):
for addr in capa.features.extractors.ghidra.helpers.find_data_references_from_insn(ih.inner):
data = getDataAt(addr) # type: ignore [name-defined] # noqa: F821
if data and not data.hasStringValue():
extracted_bytes = capa.features.extractors.ghidra.helpers.get_bytes(addr, MAX_BYTES_FEATURE_SIZE)
Expand All @@ -236,7 +236,7 @@ def extract_insn_string_features(fh: FunctionHandle, bb: BBHandle, ih: InsnHandl
example:
push offset aAcr ; "ACR > "
"""
for addr in capa.features.extractors.ghidra.helpers.find_memory_references_from_insn(ih.inner):
for addr in capa.features.extractors.ghidra.helpers.find_data_references_from_insn(ih.inner):
data = getDataAt(addr) # type: ignore [name-defined] # noqa: F821
if data and data.hasStringValue():
yield String(data.getValue()), ih.address
Expand Down

0 comments on commit 1374570

Please sign in to comment.