Various scripts for Gidhra reverse engineering suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.8 KiB

# Qemu coverage visualization script
#@author hackade <>
#@category Hackade scripts
from import ColorizingService
from import GhidraScript
from docking.options.editor import GhidraColorChooser
from ghidra.program.model.listing import Program
from ghidra.program.model.mem import Memory, MemoryBlock
from ghidra.program.model.address import Address
from ghidra.program.model.address import AddressSet
from ghidra.util import Msg
from java.awt import Color
from java.lang import IllegalArgumentException
print "Qemu coverage visualization"
# Get executables addresses ranges
executable_addr_range = []
blocks = currentProgram.getMemory().getBlocks()
for block in blocks:
if block.isExecute():
executable_addr_range.append((block.getStart().getOffset(), block.getEnd().getOffset()))
# Select the trace file
trace_file = askFile("FILE", "Choose a file")
except IllegalArgumentException as error:
Msg.warn(self, "Error during headless processing: " + error.toString())
# Parse addresses in traces and check if executables ranges
addresses = AddressSet()
with open(str(trace_file), "r") as f:
for line in f.readlines():
if not line.startswith("0x"):
iaddr = int(line.split(":")[0],16)
for block in executable_addr_range:
if iaddr >= block[0] and iaddr <= block[1]:
addr = currentProgram.parseAddress(hex(iaddr))
# Choose a color
colorchooser = GhidraColorChooser()
color = colorchooser.showDialog(None)
# Taints addrresses
service = state.getTool().getService(ColorizingService)
if service is None:
print "Can't find ColorizingService service"
service.setBackgroundColor(addresses, color)