示例#1
0
文件: chain.py 项目: kedenk/pychains
 def __init__(self, myarg):
     if isinstance(myarg, str):
         self.my_arg = tainted.tstr(str(myarg))
     elif isinstance(myarg, int):
         self.my_arg = taintint.tint(int(myarg))
     elif isinstance(myarg, bytes):
         self.my_arg = taintbytes.tbytes(bytes(myarg))
示例#2
0
def main(inputCode) -> None:

    # create simulator for VM
    sim = Simulator()
    # convert cli string input to tbytes input
    inputAsBytes = tbytes(decode_hex(inputCode))

    if VERBOSE:
        print("Code: " + inputCode)

    # execute raw bytecode
    computation = sim.executeCode(1000000000000, b'', inputAsBytes)

    # check, if error during execution occured
    if computation.is_error:
        origin = computation._error
        exc = VMExecutionError(str(origin), origin)
        raise exc

    if VERBOSE:
        print("Gas used: " + str(computation.get_gas_used()))
        print("Remaining gas: " + str(computation.get_gas_remaining()))

        print(computation.get_log_entries())
        print("Stack: " + str(computation._stack.values))
def test_equality():

    currentComparisonCount = len(taintbytes.Comparisons)

    # test equality
    a = taintbytes.tbytes(b"6010")
    b = taintbytes.tbytes(b"6010")

    assertTBytes(a)
    assertTBytes(b)
    assert a == b

    # test not equal
    b = taintbytes.tbytes(b"Hello")
    assertTBytes(b)
    assert a != b

    #assert len(taintbytes.Comparisons) == (currentComparisonCount + 2)

    b = taintbytes.tbytes(b"10")
    assert b in a
def test_byte_to_int():

    b = taintbytes.tbytes(b"600160024a")
    assert b.has_taint()
    bTaints = [t for t in b._taint]

    i = taintint.tint.from_bytes(b, 'big')
    iTaints = [t for t in i._taint]
    assert i.has_taint()

    b = b[0:2]
    bTaints = [t for t in b._taint]

    i = taintint.tint.from_bytes(b, 'big')
    iTaints = [t for t in i._taint]
    assert i.has_taint()

    b = taintbytes.tbytes(codecs.decode("600160024a", 'hex'))
    for value in b:
        assert value.has_taint()
        valueTaint = [t for t in value._taint]
        vt = value.x()
        assert isinstance(value, taintint.tint)
def test_getitem():

    b = taintbytes.tbytes(b"60106002")
    assert isinstance(b, taintbytes.tbytes)
    assert b.has_taint()

    # test if index access result is tint
    # and if taints are copied
    idx = 0
    b1 = b[idx]
    assert isinstance(b1, taintint.tint)
    assert b.x(idx) == b1.x(0)  # index of tint is always 0

    idx = 2
    b1 = b[idx]
    assert b.x(idx) == b1.x()
示例#6
0
文件: chain.py 项目: kedenk/pychains
    def parsing_state(self, h, arg_prefix):
        # every iteration we add a hexadecimal (2 digits)
        if isinstance(arg_prefix, int):
            arg_prefix = tstr(arg_prefix)
        _, _, hex_part = arg_prefix.rpartition('x')
        last_char_added = taintbytes.tbytes(codecs.decode(hex_part, 'hex'))[-1]
        o = h.op

        if o in CmpSet and h.op_A.x() == last_char_added.x():
            # last added byte was wrong -> fix it
            return (1, EState.Byte, h)
        if o in CmpSet and h.op_A.x() != last_char_added.x():
            # some early byte was wrong. trim to that position
            return (1, EState.Trim, h)
        elif h.op_A.x() == len(last_char_added):
            return (1, EState.EOF, h)
        else:
            return (-1, EState.Unknown, (h, last_char_added))
def test_iterator_and_loop():

    tbytesValue = taintbytes.tbytes(b"601020304010Hello")

    assertTBytes(tbytesValue)

    idx = 0
    for value in tbytesValue:
        # check if iterator result is tint
        # documentation says that the result of index access is an int, not bytes
        assert isinstance(value, taintint.tint)
        # check if result has taint
        assert value.has_taint()
        # check, if taints match
        assert value.x() == tbytesValue.x(idx)
        # check if 'in' operator works
        assert value in tbytesValue

        idx += 1
示例#8
0
    def to_bytes(self, length, byteorder, *args, **kwargs) -> bytes:
        import datatypes.taintedbytes as taintbytes

        res = super().to_bytes(length, byteorder, *args, **kwargs)
        return taintbytes.tbytes(res)
示例#9
0
import taintedstr
import datatypes.taintedbytes as tb
import string
ascii_letters = taintedstr.tstr(string.ascii_letters).untaint()
digits = taintedstr.tstr(string.digits).untaint()

hexdigits = tb.tbytes(string.hexdigits).untaint()