Пример #1
0
def test_image_relocation_backward():
    base_address = 0xCA00
    offsets = {"eggs": 0x00FE, "spam": 0x00CA}

    reloc = symbol.Relocation("eggs", -2).bind("spam")
    assert reloc.compute_value(base_address, offsets) == 0xCAFC
    assert reloc.compute_bin(base_address, offsets) == b"\xfc\xca"
Пример #2
0
def test_image_relocation_hi():
    base_address = 0xCA00
    offsets = {"eggs": 0x00FE, "spam": 0x00CA}

    reloc = symbol.Relocation("eggs", byte=symbol.Relocation.hi).bind("spam")
    assert reloc.compute_value(base_address, offsets) == 0xCA
    assert reloc.compute_bin(base_address, offsets) == b"\xca"
Пример #3
0
def test_image_relocation_simple():
    base_address = 0xCA00
    offsets = {"eggs": 0x00FE, "spam": 0x00CA}

    reloc = symbol.Relocation("eggs").bind("spam")
    assert reloc.compute_value(base_address, offsets) == 0xCAFE
    assert reloc.compute_bin(base_address, offsets) == b"\xfe\xca"
Пример #4
0
def test_image_relocation_complex():
    base_address = 0xCA00
    offsets = {"eggs": 0x00FE, "spam": 0x00CA}

    reloc = symbol.Relocation("eggs", -2, symbol.Relocation.lo).bind("spam")
    assert reloc.compute_value(base_address, offsets) == 0xFC
    assert reloc.compute_bin(base_address, offsets) == b"\xfc"
Пример #5
0
def relocations(draw):
    return symbol.Relocation(
        draw(hs.text(max_size=symbol.MAX_STRING_SIZE)),
        draw(hs.integers(min_value=-(1 << 15), max_value=(1 << 15) - 1)),
        draw(
            hs.sampled_from(
                [symbol.Relocation.full, symbol.Relocation.hi, symbol.Relocation.lo]
            )
        ),
    )
Пример #6
0
def test_pack_archive():
    archive = symbol.Archive()
    archive.symbols["eggs"] = symbol.Symbol(
        section="text",
        data=b"spam",
        type_info=types.u32,
        relocations={0xCAFE: symbol.Relocation("beans", 7)},
    )
    with io.BytesIO() as f:
        archive.dump(f)
        assert f.getvalue() == simple_archive
Пример #7
0
def test_pack_relocation():
    reloc = symbol.Relocation("spam", 0x42)
    packed = pack_by_type(Fmt.struct(symbol.Relocation), reloc)
    assert packed == b"\x03\x00sy\x04\x00\x00\x00spamic\x42\x00byw"