changed everything to use pyGhidra

This commit is contained in:
Vivian M
2025-09-18 16:00:39 -04:00
parent b657cf2782
commit bbc19924e3
21 changed files with 452 additions and 351 deletions

View File

@@ -1,3 +1,6 @@
#@category CodeCut
#@runtime PyGhidra
#
## Copyright 2022 The Johns Hopkins University Applied Physics Laboratory LLC
## (JHU/APL). All Rights Reserved.
#

View File

@@ -35,11 +35,11 @@ def decompile_user_functions_in_range(
current_program.getAddressFactory().getAddress(end_address_str)
if start_address is None or end_address is None:
print 'Invalid address range specified.'
print('Invalid address range specified.')
return
if start_address >= end_address:
print 'Invalid address range: start address should be less than end address.'
print('Invalid address range: start address should be less than end address.')
return
decompiler = DecompInterface()

View File

@@ -1,3 +1,4 @@
# @category CodeCut
from ghidra.program.model.listing import Function
from ghidra.program.model.symbol import SourceType
@@ -39,6 +40,7 @@ def get_referenced_function_signatures_base(function, monitor):
return signatures
def getFunctionReferences(function, monitor):
refs = set()
instructions = \
@@ -47,9 +49,10 @@ def getFunctionReferences(function, monitor):
for instr in instructions:
flowType = instr.getFlowType()
if flowType.isCall():
target = instr.getOperandReferences(0)[0].getToAddress()
func = \
function.getProgram().getFunctionManager().getFunctionAt(target)
oprefs = instr.getOperandReferences(0)
if not oprefs: continue
target = oprefs[0].getToAddress()
func = function.getProgram().getFunctionManager().getFunctionAt(target)
if func is not None:
refs.add(func)
return refs

View File

@@ -17,7 +17,7 @@ def get_global_variables(program, start_addr, end_addr):
#set.addRange(start_addr, end_addr)
print(start_address, end_address)
print(addrset)
#for symbol in symbol_table.getAllSymbols(False):
for symbol in symbol_table.getSymbols(addrset,SymbolType.LABEL,True):
print(symbol)
@@ -27,30 +27,30 @@ def get_global_variables(program, start_addr, end_addr):
if (program.getListing().getDataAt(symbol.getAddress())):
global_vars.append(symbol)
'''
'''
def is_user_defined(var):
var_name = var.getName()
var_addr = var.getAddress()
if var_name.startswith('__') or var_name.startswith('_'):
return False
if var_name.startswith('imp_') or var_name.startswith('thunk_'):
return False
if var_name.startswith('fde_') or var_name.startswith('cie_'):
return False
if var_name.startswith('completed.0') \
or var_name.startswith('data_start'):
return False
if var_addr.toString().startswith('EXTERNAL:'):
return False
section_name = program.getMemory().getBlock(var_addr).getName()
#if section_name not in ['.data', '.bss']:
# return False
return True
'''

View File

@@ -21,6 +21,8 @@
# under Contract Number N66001-20-C-4024.
#
import sys
print(sys.executable)
import sys
import math

View File

@@ -1,4 +1,6 @@
#@category AMP-Improved
#@category CodeCut
#@runtime PyGhidra
from generate_c import generate_recompilable_c_code
import os
from ghidra.util.task import TaskMonitor