Exemplo n.º 1
0
    def test_compile_decompile(self):
        def check(s):
            b1 = compile(s)
            s1 = disassemble(b1)
            b2 = compile(s1)
            self.assertEqual(s, s1)
            self.assertEqual(b1, b2)

        def build_hex(size, a, b):
            "build some random-looking hex"
            return "[%s]" % "".join("%02x" % (((i + a) * b) & 0xff)
                                    for i in range(size))

        scripts = []
        check("[ff]")
        check("[ff03]")
        check("[ff030102]")
        check("[55aabbccddeeff112131]")
        long_hex_260 = build_hex(260, 13, 93)
        long_hex_270 = build_hex(270, 11, 47)
        check("%s %s" % (long_hex_260, long_hex_270))
        s = set(INT_TO_OPCODE.values())
        for opcode, code in OPCODE_LIST:
            # skip reassigned NOPs
            if opcode not in s:
                continue
            if opcode.startswith("OP_PUSHDATA"):
                # these disassemble differently
                continue
            check(opcode)
Exemplo n.º 2
0
 def test_compile_decompile(self):
     def check(s):
         b1 = compile(s)
         s1 = disassemble(b1)
         b2 = compile(s1)
         self.assertEqual(s, s1)
         self.assertEqual(b1, b2)
     def build_hex(size, a, b):
         "build some random-looking hex"
         return "[%s]" % "".join("%02x" % (((i+a)*b) & 0xff) for i in range(size))
     scripts = []
     check("[ff]")
     check("[ff03]")
     check("[ff030102]")
     check("[55aabbccddeeff112131]")
     long_hex_260 = build_hex(260, 13, 93)
     long_hex_270 = build_hex(270, 11, 47)
     check("%s %s" % (long_hex_260, long_hex_270))
     s = set(INT_TO_OPCODE.values())
     for opcode, code in OPCODE_LIST:
         # skip reassigned NOPs
         if opcode not in s:
             continue
         if opcode.startswith("OP_PUSHDATA"):
             # these disassemble differently
             continue
         check(opcode)
Exemplo n.º 3
0
def instruction_for_opcode(opcode, data):
    if data is None or len(data) == 0:
        return INT_TO_OPCODE.get(opcode, "(UNKNOWN OPCODE)")
    return "[PUSH_%d] %s" % (opcode, b2h(data))
Exemplo n.º 4
0
def instruction_for_opcode(opcode, data):
    if data is None or len(data) == 0:
        return INT_TO_OPCODE.get(opcode, "(UNKNOWN OPCODE)")
    return "[PUSH_%d] %s" % (opcode, binascii.hexlify(data))
Exemplo n.º 5
0
def instruction_for_opcode(opcode, data):
    if len(data) == 0:
        return INT_TO_OPCODE.get(opcode, "(UNKNOWN OPCODE)")
    return "[PUSH_%d] %s" % (opcode, binascii.hexlify(data))