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"
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"
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"
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"
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] ) ), )
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
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"