| 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_win32_x86.h" | 5 #include "courgette/disassembler_win32_x86.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 9 #include "courgette/base_test_unittest.h" | 11 #include "courgette/base_test_unittest.h" |
| 10 | 12 |
| 11 class DisassemblerWin32X86Test : public BaseTest { | 13 class DisassemblerWin32X86Test : public BaseTest { |
| 12 public: | 14 public: |
| 13 void TestExe() const; | 15 void TestExe() const; |
| 14 void TestExe64() const; | 16 void TestExe64() const; |
| 15 void TestResourceDll() const; | 17 void TestResourceDll() const; |
| 16 }; | 18 }; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 37 | 39 |
| 38 EXPECT_EQ(0, disassembler->RVAToFileOffset(0)); | 40 EXPECT_EQ(0, disassembler->RVAToFileOffset(0)); |
| 39 EXPECT_EQ(1024, disassembler->RVAToFileOffset(4096)); | 41 EXPECT_EQ(1024, disassembler->RVAToFileOffset(4096)); |
| 40 EXPECT_EQ(46928, disassembler->RVAToFileOffset(50000)); | 42 EXPECT_EQ(46928, disassembler->RVAToFileOffset(50000)); |
| 41 | 43 |
| 42 std::vector<courgette::RVA> relocs; | 44 std::vector<courgette::RVA> relocs; |
| 43 bool can_parse_relocs = disassembler->ParseRelocs(&relocs); | 45 bool can_parse_relocs = disassembler->ParseRelocs(&relocs); |
| 44 EXPECT_TRUE(can_parse_relocs); | 46 EXPECT_TRUE(can_parse_relocs); |
| 45 EXPECT_TRUE(base::STLIsSorted(relocs)); | 47 EXPECT_TRUE(base::STLIsSorted(relocs)); |
| 46 | 48 |
| 47 const uint8* offset_p = disassembler->OffsetToPointer(0); | 49 const uint8_t* offset_p = disassembler->OffsetToPointer(0); |
| 48 EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()), | 50 EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()), |
| 49 reinterpret_cast<const void*>(offset_p)); | 51 reinterpret_cast<const void*>(offset_p)); |
| 50 EXPECT_EQ('M', offset_p[0]); | 52 EXPECT_EQ('M', offset_p[0]); |
| 51 EXPECT_EQ('Z', offset_p[1]); | 53 EXPECT_EQ('Z', offset_p[1]); |
| 52 | 54 |
| 53 const uint8* rva_p = disassembler->RVAToPointer(0); | 55 const uint8_t* rva_p = disassembler->RVAToPointer(0); |
| 54 EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()), | 56 EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()), |
| 55 reinterpret_cast<const void*>(rva_p)); | 57 reinterpret_cast<const void*>(rva_p)); |
| 56 EXPECT_EQ('M', rva_p[0]); | 58 EXPECT_EQ('M', rva_p[0]); |
| 57 EXPECT_EQ('Z', rva_p[1]); | 59 EXPECT_EQ('Z', rva_p[1]); |
| 58 } | 60 } |
| 59 | 61 |
| 60 void DisassemblerWin32X86Test::TestExe64() const { | 62 void DisassemblerWin32X86Test::TestExe64() const { |
| 61 std::string file1 = FileContents("pe-64.exe"); | 63 std::string file1 = FileContents("pe-64.exe"); |
| 62 | 64 |
| 63 scoped_ptr<courgette::DisassemblerWin32X86> disassembler( | 65 scoped_ptr<courgette::DisassemblerWin32X86> disassembler( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 91 EXPECT_FALSE(disassembler->has_text_section()); | 93 EXPECT_FALSE(disassembler->has_text_section()); |
| 92 EXPECT_EQ(0U, disassembler->size_of_code()); | 94 EXPECT_EQ(0U, disassembler->size_of_code()); |
| 93 EXPECT_TRUE(disassembler->is_32bit()); | 95 EXPECT_TRUE(disassembler->is_32bit()); |
| 94 } | 96 } |
| 95 | 97 |
| 96 TEST_F(DisassemblerWin32X86Test, All) { | 98 TEST_F(DisassemblerWin32X86Test, All) { |
| 97 TestExe(); | 99 TestExe(); |
| 98 TestExe64(); | 100 TestExe64(); |
| 99 TestResourceDll(); | 101 TestResourceDll(); |
| 100 } | 102 } |
| OLD | NEW |