From 2e6e1899bd8aa7907a37c279a028792f7f22d8af Mon Sep 17 00:00:00 2001 From: John Pope Date: Fri, 27 Nov 2015 18:19:46 +1100 Subject: [PATCH] insert instruction --- Insert instruction.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Insert instruction.py diff --git a/Insert instruction.py b/Insert instruction.py new file mode 100644 index 0000000..d111272 --- /dev/null +++ b/Insert instruction.py @@ -0,0 +1,25 @@ +#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())