def saveAsCFile(self):
template = open(TEMPLATES_PATH+"/template.c", "rb").read()
insns = self.canvas.codeWidget.parser.getCleanCodeAsByte(as_string=False)
if sys.version_info.major == 2:
title = bytes(self.arch.name)
else:
title = bytes(self.arch.name, encoding="utf-8")
sc = b'""\n'
i = 0
for insn in insns:
txt, cnt = assemble(insn, self.arch)
if cnt < 0:
self.canvas.logWidget.editor.append("Failed to compile code")
return
c = b'"' + b''.join([ b'\\x%.2x'%txt[i] for i in range(len(txt)) ]) + b'"'
c = c.ljust(60, b' ')
c+= b'// ' + insn + b'\n'
sc += b'\t' + c
i += len(txt)
sc += b'\t""'
body = template % (title, i, sc)
fd, fpath = tempfile.mkstemp(suffix=".c")
os.write(fd, body)
os.close(fd)
self.canvas.logWidget.editor.append("Saved as '%s'" % fpath)
return
评论列表
文章目录