Skip to content

Commit

Permalink
Fix python binding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danghvu committed Sep 27, 2014
1 parent ef92cdb commit 2412069
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
6 changes: 3 additions & 3 deletions bindings/python/test_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def print_insn_detail(insn):
print("\t\toperands[%u].type: SYSREG = %u" % (c, i.reg))
if i.type == ARM_OP_SETEND:
if i.setend == ARM_SETEND_BE:
print("\t\toperands[%u].type: SETEND = be")
print("\t\toperands[%u].type: SETEND = be" % c)
else:
print("\t\toperands[%u].type: SETEND = le")
print("\t\toperands[%u].type: SETEND = le" % c)
if i.type == ARM_OP_MEM:
print("\t\toperands[%u].type: MEM" % c)
if i.mem.base != 0:
Expand All @@ -66,7 +66,7 @@ def print_insn_detail(insn):
% (c, to_x_32(i.mem.disp)))

if i.shift.type != ARM_SFT_INVALID and i.shift.value:
print("\t\t\tShift: type = %u, value = %u\n" \
print("\t\t\tShift: %u = %u" \
% (i.shift.type, i.shift.value))
if i.vector_index != -1:
print("\t\t\toperands[%u].vector_index = %u" %(c, i.vector_index))
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/test_arm64.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def print_insn_detail(insn):
if insn.writeback:
print("\tWrite-back: True")
if not insn.cc in [ARM64_CC_AL, ARM64_CC_INVALID]:
print("\tCode condition: %u" % insn.cc)
print("\tCode-condition: %u" % insn.cc)
if insn.update_flags:
print("\tUpdate-flags: True")

Expand Down
2 changes: 1 addition & 1 deletion bindings/python/test_ppc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from capstone import *
from capstone.ppc import *
from xprint import to_x, to_hex, to_x_32
PPC_CODE = b"\x80\x20\x00\x00\x80\x3f\x00\x00\x10\x43\x23\x0e\xd0\x44\x00\x80\x4c\x43\x22\x02\x2d\x03\x00\x80\x7c\x43\x20\x14\x7c\x43\x20\x93\x4f\x20\x00\x21\x4c\xc8\x00\x21"
PPC_CODE = b"\x80\x20\x00\x00\x80\x3f\x00\x00\x10\x43\x23\x0e\xd0\x44\x00\x80\x4c\x43\x22\x02\x2d\x03\x00\x80\x7c\x43\x20\x14\x7c\x43\x20\x93\x4f\x20\x00\x21\x4c\xc8\x00\x21\x40\x82\x00\x14"

all_tests = (
(CS_ARCH_PPC, CS_MODE_BIG_ENDIAN, PPC_CODE, "PPC-64"),
Expand Down
5 changes: 4 additions & 1 deletion bindings/python/test_sparc.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def print_insn_detail(insn):
if i.mem.base != 0:
print("\t\t\toperands[%u].mem.base: REG = %s" \
% (c, insn.reg_name(i.mem.base)))
if i.mem.index != 0:
print("\t\t\toperands[%u].mem.index: REG = %s" \
% (c, insn.reg_name(i.mem.index)))
if i.mem.disp != 0:
print("\t\t\toperands[%u].mem.disp: 0x%s" \
% (c, to_x_32(i.mem.disp)))
Expand All @@ -46,7 +49,7 @@ def print_insn_detail(insn):
if insn.cc:
print("\tCode condition: %u" % insn.cc)
if insn.hint:
print("\tBranch hint: %u" % insn.hint)
print("\tHint code: %u" % insn.hint)


# ## Test class Cs
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/test_xcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def print_insn_detail(insn):
print("\t\t\toperands[%u].mem.disp: 0x%s" \
% (c, to_x(i.mem.disp)))
if i.mem.direct != 1:
print("\t\t\toperands[%u].mem.direct: -1")
print("\t\t\toperands[%u].mem.direct: -1" % c)
c += 1


Expand Down
18 changes: 9 additions & 9 deletions bindings/python/xprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ def to_hex(s):
else:
return " ".join("0x{0:02x}".format(ord(c)) for c in s)

def to_hex2(s):
if _python3:
r = "".join("{0:02x}".format(c) for c in s) # <-- Python 3 is OK
else:
r = "".join("{0:02x}".format(ord(c)) for c in s)
while r[0] == '0': r = r[1:]
return r

def to_x(s):
from struct import pack
if not s: return '0'
x = pack(">q", s)
while x[0] in ('\0', 0): x = x[1:]
if _python3:
return "".join("{0:02x}".format(c) for c in x) # <-- Python 3 is OK
else:
return "".join("{0:02x}".format(ord(c)) for c in x)

return to_hex2(x)

def to_x_32(s):
from struct import pack
if not s: return '0'
x = pack(">i", s)
while x[0] in ('\0', 0): x = x[1:]
if _python3:
return "".join("{0:02x}".format(c) for c in x) # <-- Python 3 is OK
else:
return "".join("{0:02x}".format(ord(c)) for c in x)
return to_hex2(x)

0 comments on commit 2412069

Please sign in to comment.