]> git.siccegge.de Git - frida/frida.git/blob - src/disassembler/llvm/tests/armelLinuxDisassemblerTest.cxx
Color logmessages according to severity
[frida/frida.git] / src / disassembler / llvm / tests / armelLinuxDisassemblerTest.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(4, blocks.size());
18 EXPECT_EQ(22, block->getInstructions().size());
19 EXPECT_EQ(0x1068c, block->getNextBlock(0));
20 EXPECT_EQ(0x10684, block->getNextBlock(1));
21
22 EXPECT_TRUE(blocks.find(0x1068c) != blocks.end());
23 EXPECT_TRUE(blocks.find(0x10684) != 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(18, block->getInstructions().size());
34 EXPECT_EQ(0x0, block->getNextBlock(0));
35 EXPECT_EQ(0x0, block->getNextBlock(1));
36 }
37
38 TEST(llvmDisassemblerTest, armelLinuxOpenBinaryBasicStructure) {
39 SCOPED_TRACE("opening cryptsample armelLinux");
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.armel.elf");
49
50 ASSERT_NE(nullptr, manager.getDisassembler());
51 EXPECT_EQ(0x104a8, manager.getDisassembler()->entryAddress());
52 testCheckFunction(manager.getFunction(0x105d8));
53 testMainFunction(manager.getFunction(0x1062c));
54 }
55
56 TEST(llvmDisassemblerTest, armelLinuxLoadBinaryBasicStructure) {
57 SCOPED_TRACE("loading cryptsample armelLinux");
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.armel.elf.frida");
67
68 ASSERT_NE(nullptr, manager.getDisassembler());
69 EXPECT_EQ(0x104a8, manager.getDisassembler()->entryAddress());
70 testCheckFunction(manager.getFunction(0x105d8));
71 testMainFunction(manager.getFunction(0x1062c));
72 }