Add various scripts and JSON plans for Ghidra project
- Introduced `seg043_boundary_repair.json` to manage function boundaries in segment 043. - Created `read_file.py` for reading and printing file content size. - Added `resolve_bb4f.py` to resolve specific function call targets. - Implemented `resolve_top_targets.py` to find resolved NE targets for top-called wrapper functions. - Added `script_contents.txt` to summarize NE relocation far calls. - Updated `tier4_ghidra.txt`, `tier4_ghidra_check.txt`, `tier4_output.txt`, and `tier4_result.txt` with function call statistics. - Created `tier5_errors.txt` for error logging and `tier5_output.txt` for additional function call statistics. - Established `tools` directory with helper scripts for the Ghidra project, including CLI and common functionalities. - Implemented command-line interface in `cli.py` for various project operations. - Added `common.py` for shared functions and configurations across tools. - Introduced `validate_fixups.py` to validate NE relocation fixups against known addresses.
This commit is contained in:
parent
6b9eb205d4
commit
24d4416003
36 changed files with 145712 additions and 14 deletions
41
disasm_helper.py
Normal file
41
disasm_helper.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import struct, os, sys
|
||||
|
||||
BIN_PATH = r'k:\ghidra\Crusader_Decomp\NE_segments\seg001_code_off_37600_len_8400.bin'
|
||||
TARGET = 0x265B
|
||||
|
||||
with open(BIN_PATH, 'rb') as f:
|
||||
f.seek(TARGET - 0x200)
|
||||
data = f.read(0x280)
|
||||
|
||||
try:
|
||||
import capstone
|
||||
md = capstone.Cs(capstone.CS_ARCH_X86, capstone.CS_MODE_16)
|
||||
for ins in md.disasm(data, TARGET - 0x200):
|
||||
print(' 0x%04x: %s %s' % (ins.address, ins.mnemonic, ins.op_str))
|
||||
if ins.address > TARGET + 0x40:
|
||||
break
|
||||
except ImportError:
|
||||
print('capstone not available, trying ndisasm...')
|
||||
import subprocess, tempfile
|
||||
tmp = os.path.join(os.environ.get('TEMP', '.'), 'seg001_chunk.bin')
|
||||
with open(tmp, 'wb') as f2:
|
||||
f2.write(data)
|
||||
result = subprocess.run(
|
||||
['ndisasm', '-b', '16', '-o', '0x%x' % (TARGET - 0x200), tmp],
|
||||
capture_output=True, text=True, timeout=15
|
||||
)
|
||||
if result.returncode == 0:
|
||||
for line in result.stdout.split('\n'):
|
||||
try:
|
||||
addr = int(line.split()[0], 16)
|
||||
if TARGET - 0x200 <= addr <= TARGET + 0x40:
|
||||
print(line)
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
print('ndisasm failed:', result.stderr)
|
||||
# Fallback: hex dump
|
||||
offset = TARGET - 0x200
|
||||
for i in range(0, len(data), 16):
|
||||
hexb = ' '.join('%02x' % b for b in data[i:i+16])
|
||||
print('0x%04x: %s' % (offset+i, hexb))
|
||||
Loading…
Add table
Add a link
Reference in a new issue