-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample_pyhidra.py
34 lines (27 loc) · 1.12 KB
/
sample_pyhidra.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import pyhidra
#### Section to make autocomplete work
try:
import ghidra
from ghidra_builtins import *
except:
pass
####
PROJECT_NAME = os.getenv('PROJECT_NAME')
PROJECT_LOCATION = os.path.join(os.getenv('GHIDRA_PROJECTS_PATH'),PROJECT_NAME)
pyhidra.start(True) # setting Verbose output
with pyhidra.open_program("/bin/ls", project_name=PROJECT_NAME, project_location=PROJECT_LOCATION) as flat_api:
prog = flat_api.getCurrentProgram()
print("Program Info:")
program_name = prog.getName()
creation_date = prog.getCreationDate()
language_id = prog.getLanguageID()
compiler_spec_id = prog.getCompilerSpec().getCompilerSpecID()
print("Program: {}: {}_{} ({})\n".format(program_name, language_id, compiler_spec_id, creation_date))
# Get info about the current program's memory layout
print("Memory layout:")
print("Imagebase: " + hex(prog.getImageBase().getOffset()))
for block in prog.getMemory().getBlocks():
start = block.getStart().getOffset()
end = block.getEnd().getOffset()
print("{} [start: 0x{}, end: 0x{}]".format(block.getName(), start, end))