Browse Source

Add DynamoRIO cover script and update README

master
ben 2 years ago
parent
commit
42794fec76
  1. 27
      README.md
  2. 80
      dynrio_cover.py

27
README.md

@ -1,4 +1,4 @@
Various [scripts](https://git.hackade.org/ghidra-scripts.git/) to extend [Gidhra](https://ghidra-sre.org/) features.
Various [scripts](https://git.hackade.org/ghidra-scripts.git/) for [Gidhra](https://ghidra-sre.org/) reverse engineering (SRE) suite.
## Installation
@ -9,9 +9,9 @@ git clone https://git.hackade.org/ghidra-scripts.git/
In the Ghidra Script Manager click the "Script Directories" icon in the toolbar and add the path where scripts are saved.
Scripts from this collection will appear in the "Hackade scripts" category.
### Qemu cover script
### Qemu code coverage script
[qemu_cover.py](https://git.hackade.org/ghidra-scripts.git/tree/qemu_cover.py) is code coverage plugin that visualize Qemu logged instructions.
[qemu_cover.py](https://git.hackade.org/ghidra-scripts.git/tree/qemu_cover.py) is a plugin to visualize traces from Qemu logged instructions.
#### How to use
@ -28,3 +28,24 @@ Then execute qemu_cover.py script, select the generated trace file (file.trace i
<div>
<video controls src="https://ghidra.hackade.org/qemu_cover_demo.webm">Demo</video>
</div>
### DynamoRIO code covererage script
[dynrio_cover.py](https://git.hackade.org/ghidra-scripts.git/tree/dynrio_cover.py) is a plugin to visualize traces from DynamoRIO code coverage tool.
#### How to use
First you need to generate log file (in text format) from DynamoRIO code coverage tool:
```
bin64\drrun.exe -t drcov -dump_text -- target.exe
```
The execute dynrio_cover.py script, select the generated trace file and choose a color.
#### Demo
<div>
<video controls src="https://ghidra.hackade.org/dynrio_cover_demo.webm">Demo</video>
</div>

80
dynrio_cover.py

@ -0,0 +1,80 @@
# DynamoRIO coverage visualization script
#@author hackade <ben@hackade.org>
#@category Hackade Scripts
from os.path import basename
from os import linesep
from ghidra.app.plugin.core.colorizer import ColorizingService
from ghidra.app.script 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 "DynamoRIO coverage visualization"
# Get executables addresses ranges
executable_addr_range = []
image_base = currentProgram.getImageBase().getOffset()
print "Image base is 0x%x" % int(image_base)
filename = basename(currentProgram.getExecutablePath())
print filename
blocks = currentProgram.getMemory().getBlocks()
for block in blocks:
if block.isExecute():
start = block.getStart().getOffset() - image_base
end = block.getEnd().getOffset() - image_base
executable_addr_range.append((start, end))
# Select the trace file
try:
trace_file = askFile("FILE", "Choose a file")
except IllegalArgumentException as error:
Msg.warn(self, "Error during headless processing: " + error.toString())
addresses = AddressSet()
Module_Table_Found = False
Target_Module_Found = False
with open(str(trace_file), "r") as f:
for line in f.readlines():
if not Module_Table_Found:
if line.startswith("Module Table"):
Module_Table_Found = True
print "Module table found"
continue
if Module_Table_Found and not Target_Module_Found:
if line.endswith(filename + linesep):
Target_Module_Found = True
target_module = int(line.split(",")[0])
print "Target module ID is %d" % target_module
if Target_Module_Found:
module_str = ("module[%3d]:" % target_module)
if line.startswith(module_str):
iaddr = int(line.split(':')[1].split(',')[0],16)
size = int(line.split(',')[1])
for block in executable_addr_range:
if iaddr >= block[0] and iaddr <= block[1]:
saddr = ("0x%x" % (iaddr+int(image_base)))
addr_start = currentProgram.parseAddress(saddr)[0]
addr_end = addr_start.add(size)
addr = addr_start
while addr != addr_end:
addresses.add(addr)
addr = addr.next()
# 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)
Loading…
Cancel
Save