]> git.siccegge.de Git - frida/frida.git/blob - src/disassembler/llvm/tests/amd64MachODisassemblerTest.cxx
Color logmessages according to severity
[frida/frida.git] / src / disassembler / llvm / tests / amd64MachODisassemblerTest.cxx
1 #include <gtest/gtest.h>
2 #include <string>
3
4 #include "core/InformationManager.hxx"
5 #include "core/Function.hxx"
6 #include "core/BasicBlock.hxx"
7 #include "disassembler/llvm/LLVMDisassembler.hxx"
8
9 extern char * TEST_DATA_DIRECTORY;
10
11 static void testMainFunction(Function* main) {
12 ASSERT_NE(nullptr, main);
13 EXPECT_STREQ("_main", main->getName().c_str());
14
15 auto blocks = main->blocks();
16 auto block = blocks.begin()->second;
17 EXPECT_EQ(6, blocks.size());
18 EXPECT_EQ(20, block->getInstructions().size());
19 EXPECT_EQ(0x100000EB2, block->getNextBlock(0));
20 EXPECT_EQ(0x100000E99, block->getNextBlock(1));
21
22 EXPECT_TRUE(blocks.find(0x100000EB2) != blocks.end());
23 EXPECT_TRUE(blocks.find(0x100000E99) != blocks.end());
24 }
25
26 static void testCheckFunction(Function* check) {
27 ASSERT_NE(nullptr, check);
28 EXPECT_STREQ("_check", check->getName().c_str());
29
30 auto blocks = check->blocks();
31 auto block = blocks.begin()->second;
32 EXPECT_EQ(1, blocks.size());
33 EXPECT_EQ(29, block->getInstructions().size());
34 EXPECT_EQ(0x0, block->getNextBlock(0));
35 EXPECT_EQ(0x0, block->getNextBlock(1));
36 }
37
38 TEST(llvmDisassemblerTest, amd64MachOOpenBinaryBasicStructure) {
39 SCOPED_TRACE("opening cryptsample amd64MachO");
40 InformationManager manager;
41
42 llvm::InitializeAllTargetInfos();
43 llvm::InitializeAllTargetMCs();
44 llvm::InitializeAllAsmParsers();
45 llvm::InitializeAllDisassemblers();
46
47 manager.reset(std::string(TEST_DATA_DIRECTORY)
48 + "/disassembler/binaries/crypt.clang.O2.amd64.macho");
49
50 ASSERT_NE(nullptr, manager.getDisassembler());
51 EXPECT_EQ(0x0, manager.getDisassembler()->entryAddress());
52 testCheckFunction(manager.getFunction(0x100000db0));
53 testMainFunction(manager.getFunction(0x100000e30));
54 }
55
56 TEST(llvmDisassemblerTest, amd64MachOLoadBinaryBasicStructure) {
57 SCOPED_TRACE("loading cryptsample amd64MachO");
58 InformationManager manager;
59
60 llvm::InitializeAllTargetInfos();
61 llvm::InitializeAllTargetMCs();
62 llvm::InitializeAllAsmParsers();
63 llvm::InitializeAllDisassemblers();
64
65 manager.load(std::string(TEST_DATA_DIRECTORY)
66 + "/disassembler/binaries/crypt.clang.O2.amd64.macho.frida");
67
68 ASSERT_NE(nullptr, manager.getDisassembler());
69 EXPECT_EQ(0x0, manager.getDisassembler()->entryAddress());
70 testCheckFunction(manager.getFunction(0x100000db0));
71 testMainFunction(manager.getFunction(0x100000e30));
72 }