From 3da233dcad430d2af14b40e7651d997690a7336d Mon Sep 17 00:00:00 2001 From: colton-gabertan Date: Wed, 7 Jun 2023 13:04:49 -0700 Subject: [PATCH] colton: removed redundant imports & object, locally tested --- capa/features/extractors/ghidra/global_.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/capa/features/extractors/ghidra/global_.py b/capa/features/extractors/ghidra/global_.py index b0fad5cf..2409bf0c 100644 --- a/capa/features/extractors/ghidra/global_.py +++ b/capa/features/extractors/ghidra/global_.py @@ -3,13 +3,6 @@ import contextlib from io import BytesIO from typing import Tuple, Iterator -# imports for clarity -# note: currentProgram is a static variable accessible in -# the specific ghidra runtime environment -import ghidra.program.database.mem -import ghidra.program.flatapi as flatapi -ghidraapi = flatapi.FlatProgramAPI(currentProgram) # Ghidrathon hacks :) - import capa.features.extractors.elf from capa.features.common import OS, ARCH_I386, ARCH_AMD64, OS_WINDOWS, Arch, Feature from capa.features.address import NO_ADDRESS, Address @@ -17,14 +10,13 @@ from capa.features.address import NO_ADDRESS, Address logger = logging.getLogger(__name__) def extract_os() -> Iterator[Tuple[Feature, Address]]: - current_program = ghidraapi.getCurrentProgram() - format_name: str = current_program.getExecutableFormat() + format_name: str = currentProgram.getExecutableFormat() if "PE" in format_name: yield OS(OS_WINDOWS), NO_ADDRESS elif "ELF" in format_name: - program_memory = current_program.getMemory() # ghidra.program.database.mem.MemoryMapDB + program_memory = currentProgram.getMemory() # ghidra.program.database.mem.MemoryMapDB fbytes_list = program_memory.getAllFileBytes() # java.util.List fbytes = fbytes_list[0] # ghidra.program.database.mem.FileBytes @@ -57,8 +49,7 @@ def extract_os() -> Iterator[Tuple[Feature, Address]]: def extract_arch() -> Iterator[Tuple[Feature, Address]]: - current_program = ghidraapi.getCurrentProgram() - lang_id = current_program.getMetadata().get('Language ID') + lang_id = currentProgram.getMetadata().get('Language ID') if 'x86' in lang_id and '64' in lang_id: yield Arch(ARCH_AMD64), NO_ADDRESS