| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_x64.h" | 5 #include "courgette/disassembler_win32_x64.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 14 #include "courgette/base_test_unittest.h" | 11 #include "courgette/base_test_unittest.h" |
| 15 | 12 |
| 16 class DisassemblerWin32X64Test : public BaseTest { | 13 class DisassemblerWin32X64Test : public BaseTest { |
| 17 public: | 14 public: |
| 18 void TestExe() const; | 15 void TestExe() const; |
| 19 void TestExe32() const; | 16 void TestExe32() const; |
| 20 void TestResourceDll() const; | 17 void TestResourceDll() const; |
| 21 }; | 18 }; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 33 EXPECT_EQ(file1.length(), disassembler->length()); | 30 EXPECT_EQ(file1.length(), disassembler->length()); |
| 34 | 31 |
| 35 EXPECT_TRUE(disassembler->ok()); | 32 EXPECT_TRUE(disassembler->ok()); |
| 36 EXPECT_TRUE(disassembler->has_text_section()); | 33 EXPECT_TRUE(disassembler->has_text_section()); |
| 37 EXPECT_EQ(488448U, disassembler->size_of_code()); | 34 EXPECT_EQ(488448U, disassembler->size_of_code()); |
| 38 EXPECT_FALSE(disassembler->is_32bit()); | 35 EXPECT_FALSE(disassembler->is_32bit()); |
| 39 EXPECT_EQ(courgette::DisassemblerWin32X64::SectionName( | 36 EXPECT_EQ(courgette::DisassemblerWin32X64::SectionName( |
| 40 disassembler->RVAToSection(0x00401234 - 0x00400000)), | 37 disassembler->RVAToSection(0x00401234 - 0x00400000)), |
| 41 std::string(".text")); | 38 std::string(".text")); |
| 42 | 39 |
| 43 EXPECT_EQ(0U, disassembler->RVAToFileOffset(0)); | 40 EXPECT_EQ(0, disassembler->RVAToFileOffset(0)); |
| 44 EXPECT_EQ(1024U, disassembler->RVAToFileOffset(4096)); | 41 EXPECT_EQ(1024, disassembler->RVAToFileOffset(4096)); |
| 45 EXPECT_EQ(46928U, disassembler->RVAToFileOffset(50000)); | 42 EXPECT_EQ(46928, disassembler->RVAToFileOffset(50000)); |
| 46 | 43 |
| 47 std::vector<courgette::RVA> relocs; | 44 std::vector<courgette::RVA> relocs; |
| 48 bool can_parse_relocs = disassembler->ParseRelocs(&relocs); | 45 bool can_parse_relocs = disassembler->ParseRelocs(&relocs); |
| 49 EXPECT_TRUE(can_parse_relocs); | 46 EXPECT_TRUE(can_parse_relocs); |
| 50 EXPECT_TRUE(base::STLIsSorted(relocs)); | 47 EXPECT_TRUE(base::STLIsSorted(relocs)); |
| 51 | 48 |
| 52 const uint8_t* offset_p = disassembler->FileOffsetToPointer(0); | 49 const uint8_t* offset_p = disassembler->OffsetToPointer(0); |
| 53 EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()), | 50 EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()), |
| 54 reinterpret_cast<const void*>(offset_p)); | 51 reinterpret_cast<const void*>(offset_p)); |
| 55 EXPECT_EQ('M', offset_p[0]); | 52 EXPECT_EQ('M', offset_p[0]); |
| 56 EXPECT_EQ('Z', offset_p[1]); | 53 EXPECT_EQ('Z', offset_p[1]); |
| 57 | 54 |
| 58 const uint8_t* rva_p = disassembler->RVAToPointer(0); | 55 const uint8_t* rva_p = disassembler->RVAToPointer(0); |
| 59 EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()), | 56 EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()), |
| 60 reinterpret_cast<const void*>(rva_p)); | 57 reinterpret_cast<const void*>(rva_p)); |
| 61 EXPECT_EQ('M', rva_p[0]); | 58 EXPECT_EQ('M', rva_p[0]); |
| 62 EXPECT_EQ('Z', rva_p[1]); | 59 EXPECT_EQ('Z', rva_p[1]); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 EXPECT_FALSE(disassembler->has_text_section()); | 93 EXPECT_FALSE(disassembler->has_text_section()); |
| 97 EXPECT_EQ(0U, disassembler->size_of_code()); | 94 EXPECT_EQ(0U, disassembler->size_of_code()); |
| 98 EXPECT_FALSE(disassembler->is_32bit()); | 95 EXPECT_FALSE(disassembler->is_32bit()); |
| 99 } | 96 } |
| 100 | 97 |
| 101 TEST_F(DisassemblerWin32X64Test, All) { | 98 TEST_F(DisassemblerWin32X64Test, All) { |
| 102 TestExe(); | 99 TestExe(); |
| 103 TestExe32(); | 100 TestExe32(); |
| 104 TestResourceDll(); | 101 TestResourceDll(); |
| 105 } | 102 } |
| OLD | NEW |