Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: courgette/disassembler_win32_x64_unittest.cc

Issue 2055343002: Courgette: Add static method QuickDetect() to optimize program detection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « courgette/disassembler_win32_x64.cc ('k') | courgette/disassembler_win32_x86.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <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 DisassemblerWin32X64Test : public BaseTest { 16 class DisassemblerWin32X64Test : public BaseTest {
17 public: 17 public:
18 void TestExe() const; 18 void TestExe() const;
19 void TestExe32ShouldFail() const; 19 void TestExe32ShouldFail() const;
20 void TestResourceDll() const; 20 void TestResourceDll() const;
21 }; 21 };
22 22
23 void DisassemblerWin32X64Test::TestExe() const { 23 void DisassemblerWin32X64Test::TestExe() const {
24 std::string file1 = FileContents("chrome64_1.exe"); 24 std::string file1 = FileContents("chrome64_1.exe");
25 25
26 std::unique_ptr<courgette::DisassemblerWin32X64> disassembler( 26 std::unique_ptr<courgette::DisassemblerWin32X64> disassembler(
27 new courgette::DisassemblerWin32X64(file1.c_str(), file1.length())); 27 new courgette::DisassemblerWin32X64(
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(488448U, disassembler->size_of_code()); 38 EXPECT_EQ(488448U, disassembler->size_of_code());
(...skipping 20 matching lines...) Expand all
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 DisassemblerWin32X64Test::TestExe32ShouldFail() const { 65 void DisassemblerWin32X64Test::TestExe32ShouldFail() const {
65 std::string file1 = FileContents("setup1.exe"); 66 std::string file1 = FileContents("setup1.exe");
66 67
67 std::unique_ptr<courgette::DisassemblerWin32X64> disassembler( 68 std::unique_ptr<courgette::DisassemblerWin32X64> disassembler(
68 new courgette::DisassemblerWin32X64(file1.c_str(), file1.length())); 69 new courgette::DisassemblerWin32X64(
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 DisassemblerWin32X64Test::TestResourceDll() const { 81 void DisassemblerWin32X64Test::TestResourceDll() const {
80 std::string file1 = FileContents("en-US-64.dll"); 82 std::string file1 = FileContents("en-US-64.dll");
81 83
82 std::unique_ptr<courgette::DisassemblerWin32X64> disassembler( 84 std::unique_ptr<courgette::DisassemblerWin32X64> disassembler(
83 new courgette::DisassemblerWin32X64(file1.c_str(), file1.length())); 85 new courgette::DisassemblerWin32X64(
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(DisassemblerWin32X64Test, All) { 97 TEST_F(DisassemblerWin32X64Test, All) {
95 TestExe(); 98 TestExe();
96 TestExe32ShouldFail(); 99 TestExe32ShouldFail();
97 TestResourceDll(); 100 TestResourceDll();
98 } 101 }
OLDNEW
« no previous file with comments | « courgette/disassembler_win32_x64.cc ('k') | courgette/disassembler_win32_x86.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698