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> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "courgette/base_test_unittest.h" | 14 #include "courgette/base_test_unittest.h" |
15 | 15 |
16 class DisassemblerWin32X86Test : public BaseTest { | 16 class DisassemblerWin32X86Test : public BaseTest { |
17 public: | 17 public: |
18 void TestExe() const; | 18 void TestExe() const; |
19 void TestExe64ShouldFail() const; | 19 void TestExe64ShouldFail() const; |
20 void TestResourceDll() const; | 20 void TestResourceDll() const; |
21 }; | 21 }; |
22 | 22 |
23 void DisassemblerWin32X86Test::TestExe() const { | 23 void DisassemblerWin32X86Test::TestExe() const { |
24 std::string file1 = FileContents("setup1.exe"); | 24 std::string file1 = FileContents("setup1.exe"); |
25 | 25 |
26 std::unique_ptr<courgette::DisassemblerWin32X86> disassembler( | 26 std::unique_ptr<courgette::DisassemblerWin32X86> disassembler( |
27 new courgette::DisassemblerWin32X86(file1.c_str(), file1.length())); | 27 new courgette::DisassemblerWin32X86( |
| 28 reinterpret_cast<const uint8_t*>(file1.c_str()), file1.length())); |
28 | 29 |
29 bool can_parse_header = disassembler->ParseHeader(); | 30 bool can_parse_header = disassembler->ParseHeader(); |
30 EXPECT_TRUE(can_parse_header); | 31 EXPECT_TRUE(can_parse_header); |
31 | 32 |
32 // The executable is the whole file, not 'embedded' with the file | 33 // The executable is the whole file, not 'embedded' with the file |
33 EXPECT_EQ(file1.length(), disassembler->length()); | 34 EXPECT_EQ(file1.length(), disassembler->length()); |
34 | 35 |
35 EXPECT_TRUE(disassembler->ok()); | 36 EXPECT_TRUE(disassembler->ok()); |
36 EXPECT_TRUE(disassembler->has_text_section()); | 37 EXPECT_TRUE(disassembler->has_text_section()); |
37 EXPECT_EQ(449536U, disassembler->size_of_code()); | 38 EXPECT_EQ(449536U, disassembler->size_of_code()); |
(...skipping 20 matching lines...) Expand all Loading... |
58 EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()), | 59 EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()), |
59 reinterpret_cast<const void*>(rva_p)); | 60 reinterpret_cast<const void*>(rva_p)); |
60 EXPECT_EQ('M', rva_p[0]); | 61 EXPECT_EQ('M', rva_p[0]); |
61 EXPECT_EQ('Z', rva_p[1]); | 62 EXPECT_EQ('Z', rva_p[1]); |
62 } | 63 } |
63 | 64 |
64 void DisassemblerWin32X86Test::TestExe64ShouldFail() const { | 65 void DisassemblerWin32X86Test::TestExe64ShouldFail() const { |
65 std::string file1 = FileContents("pe-64.exe"); | 66 std::string file1 = FileContents("pe-64.exe"); |
66 | 67 |
67 std::unique_ptr<courgette::DisassemblerWin32X86> disassembler( | 68 std::unique_ptr<courgette::DisassemblerWin32X86> disassembler( |
68 new courgette::DisassemblerWin32X86(file1.c_str(), file1.length())); | 69 new courgette::DisassemblerWin32X86( |
| 70 reinterpret_cast<const uint8_t*>(file1.c_str()), file1.length())); |
69 | 71 |
70 bool can_parse_header = disassembler->ParseHeader(); | 72 bool can_parse_header = disassembler->ParseHeader(); |
71 EXPECT_FALSE(can_parse_header); | 73 EXPECT_FALSE(can_parse_header); |
72 | 74 |
73 // The executable is the whole file, not 'embedded' with the file | 75 // The executable is the whole file, not 'embedded' with the file |
74 EXPECT_EQ(file1.length(), disassembler->length()); | 76 EXPECT_EQ(file1.length(), disassembler->length()); |
75 | 77 |
76 EXPECT_FALSE(disassembler->ok()); | 78 EXPECT_FALSE(disassembler->ok()); |
77 } | 79 } |
78 | 80 |
79 void DisassemblerWin32X86Test::TestResourceDll() const { | 81 void DisassemblerWin32X86Test::TestResourceDll() const { |
80 std::string file1 = FileContents("en-US.dll"); | 82 std::string file1 = FileContents("en-US.dll"); |
81 | 83 |
82 std::unique_ptr<courgette::DisassemblerWin32X86> disassembler( | 84 std::unique_ptr<courgette::DisassemblerWin32X86> disassembler( |
83 new courgette::DisassemblerWin32X86(file1.c_str(), file1.length())); | 85 new courgette::DisassemblerWin32X86( |
| 86 reinterpret_cast<const uint8_t*>(file1.c_str()), file1.length())); |
84 | 87 |
85 bool can_parse_header = disassembler->ParseHeader(); | 88 bool can_parse_header = disassembler->ParseHeader(); |
86 EXPECT_FALSE(can_parse_header); | 89 EXPECT_FALSE(can_parse_header); |
87 | 90 |
88 // The executable is the whole file, not 'embedded' with the file | 91 // The executable is the whole file, not 'embedded' with the file |
89 EXPECT_EQ(file1.length(), disassembler->length()); | 92 EXPECT_EQ(file1.length(), disassembler->length()); |
90 | 93 |
91 EXPECT_FALSE(disassembler->ok()); | 94 EXPECT_FALSE(disassembler->ok()); |
92 } | 95 } |
93 | 96 |
94 TEST_F(DisassemblerWin32X86Test, All) { | 97 TEST_F(DisassemblerWin32X86Test, All) { |
95 TestExe(); | 98 TestExe(); |
96 TestExe64ShouldFail(); | 99 TestExe64ShouldFail(); |
97 TestResourceDll(); | 100 TestResourceDll(); |
98 } | 101 } |
OLD | NEW |