core.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:cemu 作者: hugsy 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号