OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "courgette/disassembler_elf_32_x86.h" | 5 #include "courgette/disassembler_elf_32_x86.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 class DisassemblerElf32X86Test : public BaseTest { | 60 class DisassemblerElf32X86Test : public BaseTest { |
61 public: | 61 public: |
62 void TestExe(const char* file_name, | 62 void TestExe(const char* file_name, |
63 size_t expected_abs_count, | 63 size_t expected_abs_count, |
64 size_t expected_rel_count) const; | 64 size_t expected_rel_count) const; |
65 }; | 65 }; |
66 | 66 |
67 void DisassemblerElf32X86Test::TestExe(const char* file_name, | 67 void DisassemblerElf32X86Test::TestExe(const char* file_name, |
68 size_t expected_abs_count, | 68 size_t expected_abs_count, |
69 size_t expected_rel_count) const { | 69 size_t expected_rel_count) const { |
70 using TypedRVA = DisassemblerElf32::TypedRVA; | |
71 std::string file1 = FileContents(file_name); | 70 std::string file1 = FileContents(file_name); |
72 | 71 |
73 std::unique_ptr<TestDisassemblerElf32X86> disassembler( | 72 std::unique_ptr<TestDisassemblerElf32X86> disassembler( |
74 new TestDisassemblerElf32X86(file1.c_str(), file1.length())); | 73 new TestDisassemblerElf32X86(file1.c_str(), file1.length())); |
75 | 74 |
76 bool can_parse_header = disassembler->ParseHeader(); | 75 bool can_parse_header = disassembler->ParseHeader(); |
77 EXPECT_TRUE(can_parse_header); | 76 EXPECT_TRUE(can_parse_header); |
78 EXPECT_TRUE(disassembler->ok()); | 77 EXPECT_TRUE(disassembler->ok()); |
79 | 78 |
80 // The length of the disassembled value will be slightly smaller than the | 79 // The length of the disassembled value will be slightly smaller than the |
(...skipping 10 matching lines...) Expand all Loading... |
91 | 90 |
92 std::unique_ptr<AssemblyProgram> program(new AssemblyProgram(EXE_ELF_32_X86)); | 91 std::unique_ptr<AssemblyProgram> program(new AssemblyProgram(EXE_ELF_32_X86)); |
93 | 92 |
94 EXPECT_TRUE(disassembler->Disassemble(program.get())); | 93 EXPECT_TRUE(disassembler->Disassemble(program.get())); |
95 | 94 |
96 const std::vector<RVA>& abs32_list = disassembler->Abs32Locations(); | 95 const std::vector<RVA>& abs32_list = disassembler->Abs32Locations(); |
97 | 96 |
98 // Flatten the list typed rel32 to a list of rel32 RVAs. | 97 // Flatten the list typed rel32 to a list of rel32 RVAs. |
99 std::vector<RVA> rel32_list; | 98 std::vector<RVA> rel32_list; |
100 rel32_list.reserve(disassembler->Rel32Locations().size()); | 99 rel32_list.reserve(disassembler->Rel32Locations().size()); |
101 for (TypedRVA* typed_rel32 : disassembler->Rel32Locations()) | 100 for (auto& typed_rel32 : disassembler->Rel32Locations()) |
102 rel32_list.push_back(typed_rel32->rva()); | 101 rel32_list.push_back(typed_rel32->rva()); |
103 | 102 |
104 EXPECT_EQ(expected_abs_count, abs32_list.size()); | 103 EXPECT_EQ(expected_abs_count, abs32_list.size()); |
105 EXPECT_EQ(expected_rel_count, rel32_list.size()); | 104 EXPECT_EQ(expected_rel_count, rel32_list.size()); |
106 | 105 |
107 EXPECT_TRUE(std::is_sorted(abs32_list.begin(), abs32_list.end())); | 106 EXPECT_TRUE(std::is_sorted(abs32_list.begin(), abs32_list.end())); |
108 EXPECT_TRUE(std::is_sorted(rel32_list.begin(), rel32_list.end())); | 107 EXPECT_TRUE(std::is_sorted(rel32_list.begin(), rel32_list.end())); |
109 | 108 |
110 // Verify that rel32 RVAs do not overlap with abs32 RVAs. | 109 // Verify that rel32 RVAs do not overlap with abs32 RVAs. |
111 // TODO(huangs): Fix this to account for RVA's 4-byte width. | 110 // TODO(huangs): Fix this to account for RVA's 4-byte width. |
(...skipping 17 matching lines...) Expand all Loading... |
129 } | 128 } |
130 | 129 |
131 } // namespace | 130 } // namespace |
132 | 131 |
133 TEST_F(DisassemblerElf32X86Test, All) { | 132 TEST_F(DisassemblerElf32X86Test, All) { |
134 TestExe("elf-32-1", 200, 3337); | 133 TestExe("elf-32-1", 200, 3337); |
135 TestExe("elf-32-high-bss", 0, 4); | 134 TestExe("elf-32-high-bss", 0, 4); |
136 } | 135 } |
137 | 136 |
138 } // namespace courgette | 137 } // namespace courgette |
OLD | NEW |