Created
December 19, 2012 08:13
-
-
Save 0xc010d/4335229 to your computer and use it in GitHub Desktop.
Hopper's 'Insert ASM instruction' script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires yasm to be at /usr/local/bin | |
from subprocess import call | |
asmFile = "/tmp/tmp.s" | |
binFile = "/tmp/tmp.o" | |
doc = Document.getCurrentDocument() | |
seg = doc.getCurrentSegment() | |
addr = doc.getCurrentAddress() | |
asm = Document.ask("Enter instruction:") | |
if asm != None: | |
f = open(asmFile, "w") | |
f.write("[BITS 64]\n") | |
f.write(asm) | |
f.close() | |
res = call(["/usr/local/bin/yasm", "-o", binFile, asmFile]) | |
if res == 0: | |
bytes = bytearray(open(binFile, "rb").read()) | |
for i in range(len(bytes)): | |
byte = bytes[i] | |
seg.writeByte(addr, byte) | |
addr = addr + 1 | |
seg.markAsCode(doc.getCurrentAddress()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Thanks so much sharing this code snippet. I added it to the hopper sample scripts library on github.
When I try to insert this code
add rax, qword [ss:rbp+0x563ee8a7]
it appears correctly in hopper but when I build new binary and open file - I see this it being mis-interpreted as var.
I hardcoded script to a /tmp/tmp.s file but couldn't succeed.
[BITS 64]
add rax, qword [ss:rbp+0x563ee8a7]
[BITS 64]
add rax, qword [ss:rbp+1446963367]
[BITS 64]
add rax, qword [ss:rbp+'1446963367']
any ideas?