Example #1
0
def test_s390x_lochi():
    arch = archinfo.ArchS390X()
    irsb = pyvex.lift(b"\xec\x18\xab\xcd\x00\x42", 0x400400,
                      arch)  # lochi %r1,0xabcd,8
    irsb_str = str(irsb)

    assert "s390_calculate_cond(0x0000000000000008" in irsb_str
    assert "PUT(r1_32) = 0xffffabcd" in irsb_str
    assert irsb.jumpkind in "Ijk_Boring"
Example #2
0
def test_s390x_lochi():
    arch = archinfo.ArchS390X()
    irsb = pyvex.lift(
        b'\xec\x18\xab\xcd\x00\x42',  # lochi %r1,0xabcd,8
        0x400400,
        arch)
    irsb_str = str(irsb)

    nose.tools.assert_in('s390_calculate_cond(0x0000000000000008', irsb_str)
    nose.tools.assert_in('PUT(r1_32) = 0xffffabcd', irsb_str)
    nose.tools.assert_equal(irsb.jumpkind, 'Ijk_Boring')
Example #3
0
def test_s390x_vl():
    arch = archinfo.ArchS390X()
    irsb = pyvex.lift(b"\xe7\x40\x90\xa8\x00\x06", 0x11C6C9E,
                      arch)  # vl %v4, 0xa8(%r9)
    irsb_str = str(irsb)

    assert "GET:I64(r9)" in irsb_str
    assert "Add64(0x00000000000000a8" in irsb_str
    assert "LDbe:V128" in irsb_str
    assert "PUT(v4) =" in irsb_str
    assert irsb.jumpkind == "Ijk_Boring"
def get_hardware_mode():
    (arch, mode) = (None, None)
    info = idaapi.get_inf_structure()
    # heuristically detect hardware setup
    info = idaapi.get_inf_structure()

    try:
        cpuname = info.procname.lower()
    except:
        cpuname = info.procName.lower()

    try:
        # since IDA7 beta 3 (170724) renamed inf.mf -> is_be()/set_be()
        is_be = idaapi.cvar.inf.is_be()
    except:
        # older IDA versions
        is_be = idaapi.cvar.inf.mf
    # print("Keypatch BIG_ENDIAN = %s" %is_be)

    if cpuname == "metapc":
        if info.is_64bit():
            arch = archinfo.ArchAMD64()
            mode = KS_MODE_64
        elif info.is_32bit():
            arch = archinfo.ArchX86()
            mode = KS_MODE_32
        else:
            arch = archinfo.ArchNotFound()
            mode = KS_MODE_16

    elif cpuname.startswith("ppc"):
        if info.is_64bit():
            arch = archinfo.ArchPPC64()
            mode = KS_MODE_PPC64
        else:
            arch = archinfo.ArchPPC32()
            mode = KS_MODE_PPC32
        if cpuname == "ppc":
            # do not support Little Endian mode for PPC
            mode += KS_MODE_BIG_ENDIAN

    elif cpuname.startswith("mips"):
        if info.is_64bit():
            arch = archinfo.ArchMIPS64()
            mode = KS_MODE_MIPS64
        else:
            arch = archinfo.ArchMIPS32()
            mode = KS_MODE_MIPS32
    elif cpuname.startswith("systemz") or cpuname.startswith("s390x"):
        arch = archinfo.ArchS390X()
        mode = KS_MODE_BIG_ENDIAN

    return (arch, mode)
Example #5
0
def test_s390x_vl():
    arch = archinfo.ArchS390X()
    irsb = pyvex.lift(
        b'\xe7\x40\x90\xa8\x00\x06',  # vl %v4, 0xa8(%r9)
        0x11c6c9e,
        arch)
    irsb_str = str(irsb)

    nose.tools.assert_in('GET:I64(r9)', irsb_str)
    nose.tools.assert_in('Add64(0x00000000000000a8', irsb_str)
    nose.tools.assert_in('LDbe:V128', irsb_str)
    nose.tools.assert_in('PUT(v4) =', irsb_str)
    nose.tools.assert_equal(irsb.jumpkind, 'Ijk_Boring')
Example #6
0
def test_s390x_exrl():
    arch = archinfo.ArchS390X()
    irsb = pyvex.lift(
        b'\xc6\x10\x00\x00\x00\x04'  # exrl %r1,0x400408
        b'\x07\xfe'  # br %r14
        b'\xd7\x00\x20\x00\x30\x00'  # xc 0(0,%r2),0(%r3)
        b'\x7d\xa7',  # padding
        0x400400,
        arch)
    irsb_str = str(irsb)

    nose.tools.assert_in('0xd700200030007da7', irsb_str)
    nose.tools.assert_in('s390x_dirtyhelper_EX', irsb_str)
    nose.tools.assert_in('{ PUT(ia) = 0x400400; Ijk_Boring }', irsb_str)
    nose.tools.assert_in('------ IMark(0x400406, 2, 0) ------', irsb_str)
    nose.tools.assert_equal(irsb.jumpkind, 'Ijk_Ret')
Example #7
0
def test_s390x_exrl():
    arch = archinfo.ArchS390X()
    irsb = pyvex.lift(
        b"\xc6\x10\x00\x00\x00\x04"  # exrl %r1,0x400408
        b"\x07\xfe"  # br %r14
        b"\xd7\x00\x20\x00\x30\x00"  # xc 0(0,%r2),0(%r3)
        b"\x7d\xa7",  # padding
        0x400400,
        arch,
    )
    irsb_str = str(irsb)

    # check last_execute_target, only top 6 bytes are relevant
    assert "0xd700200030000000" in irsb_str
    assert "s390x_dirtyhelper_EX" in irsb_str
    assert "{ PUT(ia) = 0x400400; Ijk_Boring }" in irsb_str
    assert "------ IMark(0x400406, 2, 0) ------" in irsb_str
    assert irsb.jumpkind == "Ijk_Ret"