-
Notifications
You must be signed in to change notification settings - Fork 0
/
jumpover.py
29 lines (20 loc) · 1.09 KB
/
jumpover.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
# This is a simple script that will basically nop out the current assembly selection by jumping from the start to the end.
# Simple but useful if certain blocks can be skipped entirely.
# @r3ck0_
# @category MyScripts
# @menupath MyScripts.JumpOver
# @toolbar python.png
from ghidra.app.plugin.assembler import Assemblers
from ghidra.program.disassemble import Disassembler
#TODO Add User Code Here
minAddr = currentSelection.getMinAddress()
maxAddr = currentSelection.getMaxAddress()
delta = maxAddr.getOffset() - minAddr.getOffset()
assembler = Assemblers.getAssembler(currentProgram)
new_bytes = assembler.assembleLine(minAddr, "JMP " + str(maxAddr.getOffset() + 1))
listing = currentProgram.getListing()
address_set = currentProgram.getAddressFactory().getAddressSet(minAddr, maxAddr)
for instruction in listing.getInstructions(address_set, True):
listing.clearCodeUnits(instruction.getAddress(), instruction.getAddress().add(instruction.getLength() - 1), True)
currentProgram.getMemory().setBytes(minAddr, new_bytes)
Disassembler.getDisassembler(currentProgram, monitor, None).disassemble(minAddr, None)