#!/usr/bin/python from keystone import * from capstone import * def maketest(cmd, ksarch, ksmode, csarch, csmode): ks = Ks(ksarch, ksmode) cs = Cs(csarch, csmode) op = ''.join(chr(i) for i in ks.asm(cmd, 0x1000)[0]) insns = cs.disasm(op, 0x1000) insn = insns.next() print 'Expected:\t{}\nGot:\t\t{} {}'.format(cmd, insn.mnemonic, insn.op_str) print "ARM:" maketest("b #0x1010", KS_ARCH_ARM, KS_MODE_ARM, CS_ARCH_ARM, CS_MODE_ARM) maketest("bl #0x1010", KS_ARCH_ARM, KS_MODE_ARM, CS_ARCH_ARM, CS_MODE_ARM) print "ARM64:" maketest("b #0x1010", KS_ARCH_ARM64, 0, CS_ARCH_ARM64, 0) maketest("bl #0x1010", KS_ARCH_ARM64, 0, CS_ARCH_ARM64, 0) print "SPARC:" maketest("b 0x1010", KS_ARCH_SPARC, KS_MODE_BIG_ENDIAN + KS_MODE_SPARC32, CS_ARCH_SPARC, CS_MODE_BIG_ENDIAN) print "MIPS:" maketest("b 0x1010", KS_ARCH_MIPS, KS_MODE_MIPS32, CS_ARCH_MIPS, CS_MODE_MIPS32) print "PPC:" maketest("b 0x1010", KS_ARCH_PPC, KS_MODE_PPC32 + KS_MODE_BIG_ENDIAN, CS_ARCH_PPC, CS_MODE_BIG_ENDIAN) print "SystemZ:" maketest("j 0x1010", KS_ARCH_SYSTEMZ, KS_MODE_BIG_ENDIAN, CS_ARCH_SYSZ, CS_MODE_BIG_ENDIAN)