def test_block_alignment_via_array_section_fallback_x64(self): # This tests the changes in MR 362. ir, m = create_test_module(file_format=gtirb.Module.FileFormat.ELF, isa=gtirb.Module.ISA.X64) _, bi = add_section(m, ".init_array") add_data_block(bi, b"\x00\x00\x00\x00\x00\x00\x00\x00") asm = run_asm_pprinter(ir, ["--policy=dynamic"]) self.assertContains(asm_lines(asm), [".align 8", ".zero 8"])
def test_ldlinux_dep(self): # Check that a binary with a known dependence on ld-linux.so does # not try to explicity link with it, as the link should be implicit. ir, m = create_test_module( gtirb.Module.FileFormat.ELF, gtirb.Module.ISA.X64, ["DYN"] ) add_section(m, ".dynamic") _, bi = add_text_section(m) main = add_code_block(bi, b"\xC3") add_function(m, "main", main) m.aux_data["libraries"].data.append("ld-linux-x86-64.so.2") output = run_binary_pprinter_mock_out( ir, [], check_output=True ).stdout.decode(sys.stdout.encoding) self.assertIn("Compiler arguments:", output) self.assertNotIn("ld-linux", output)
def test_keep_function(self): ir, m = create_test_module( file_format=gtirb.Module.FileFormat.ELF, isa=gtirb.Module.ISA.X64, binary_type=["DYN"], ) _, _ = add_section(m, ".dynamic") _, bi = add_text_section(m) add_function(m, "_start", add_code_block(bi, b"\xC3")) asm = run_asm_pprinter(ir) self.assertNotContains(asm_lines(asm), ["_start:", "ret"]) asm = run_asm_pprinter(ir, ["--keep-function", "_start"]) self.assertContains(asm_lines(asm), ["_start:", "ret"])
def make_pe_resource_data(self) -> gtirb.IR: ir, m = create_test_module( file_format=gtirb.Module.FileFormat.PE, isa=gtirb.Module.ISA.X64, binary_type=["EXEC", "EXE", "WINDOWS_GUI"], ) _, bi = add_section(m, ".text") entry = add_code_block(bi, b"\xC3") m.entry_point = entry resource_data = b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\ \x00\x00\x00\x00\x00\x02\x00\x06\x00\x00\x00 \x00\x00\x80\ \x18\x00\x00\x008\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\ \x00\x00\x00\x00\x00\x00\x00\x01\x00\x07\x00\x00\x00P\x00\ \x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ \x00\x00\x01\x00\x01\x00\x00\x00h\x00\x00\x80\x00\x00\x00\ \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\t\x04\ \x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ \x00\x00\x00\x00\x00\x01\x00\t\x04\x00\x00\x90\x00\x00\x00\ \xa0`\x00\x00H\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ \xe8`\x00\x00}\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x00T\x00e\x00s\ \x00t\x00 \x00r\x00e\x00s\x00o\x00u\x00r\x00c\x00e\x00 \x00s\ \x00t\x00r\x00i\x00n\x00g\x00\x00\x00\x00\x00\x00\x00\x00\ \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ <?xml version='1.0' encoding='UTF-8' standalone='yes'?>\ \r\n<assembly xmlns='urn:schemas-microsoft-com:asm.v1\ ' manifestVersion='1.0'>\r\n \ <trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v3\">\r\n\ <security>\r\n <requestedPrivileges>\r\n \ <requestedExecutionLevel level='asInvoker' uiAccess='false' />\r\n\ </requestedPrivileges>\r\n </security>\r\n </trustInfo>\ \r\n</assembly>\r\n\x00\x00\x00')" _, bi = add_section(m, ".rsrc") _ = add_byte_block(bi, gtirb.block.DataBlock, resource_data) off1 = gtirb.Offset(bi, 0) off2 = gtirb.Offset(bi, 72) entry1 = ( [ 72, 0, 0, 0, 32, 0, 0, 0, 255, 255, 6, 0, 255, 255, 7, 0, 0, 0, 0, 0, 48, 16, 9, 4, 0, 0, 0, 0, 0, 0, 0, 0, ], off1, 72, ) entry2 = ( [ 125, 1, 0, 0, 32, 0, 0, 0, 255, 255, 24, 0, 255, 255, 1, 0, 0, 0, 0, 0, 48, 16, 9, 4, 0, 0, 0, 0, 0, 0, 0, 0, ], off2, 381, ) m.aux_data["peResources"] = gtirb.AuxData( [entry1, entry2], "sequence<tuple<sequence<uint8_t>,Offset,uint64_t>>", ) return ir