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