1 #include <gtest/gtest.h>
4 #include "core/InformationManager.hxx"
5 #include "core/Function.hxx"
6 #include "core/BasicBlock.hxx"
7 #include "disassembler/llvm/LLVMDisassembler.hxx"
9 extern char * TEST_DATA_DIRECTORY
;
11 static void testMainFunction(Function
* main
) {
12 ASSERT_NE(nullptr, main
);
13 EXPECT_STREQ("main", main
->getName().c_str());
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));
22 EXPECT_TRUE(blocks
.find(0x1068c) != blocks
.end());
23 EXPECT_TRUE(blocks
.find(0x10684) != blocks
.end());
26 static void testCheckFunction(Function
* check
) {
27 ASSERT_NE(nullptr, check
);
28 EXPECT_STREQ("check", check
->getName().c_str());
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));
38 TEST(llvmDisassemblerTest
, armelLinuxOpenBinaryBasicStructure
) {
39 SCOPED_TRACE("opening cryptsample armelLinux");
40 InformationManager manager
;
42 llvm::InitializeAllTargetInfos();
43 llvm::InitializeAllTargetMCs();
44 llvm::InitializeAllAsmParsers();
45 llvm::InitializeAllDisassemblers();
47 manager
.reset(std::string(TEST_DATA_DIRECTORY
)
48 + "/disassembler/binaries/crypt.clang.O2.armel.elf");
50 ASSERT_NE(nullptr, manager
.getDisassembler());
51 EXPECT_EQ(0x104a8, manager
.getDisassembler()->entryAddress());
52 testCheckFunction(manager
.getFunction(0x105d8));
53 testMainFunction(manager
.getFunction(0x1062c));
56 TEST(llvmDisassemblerTest
, armelLinuxLoadBinaryBasicStructure
) {
57 SCOPED_TRACE("loading cryptsample armelLinux");
58 InformationManager manager
;
60 llvm::InitializeAllTargetInfos();
61 llvm::InitializeAllTargetMCs();
62 llvm::InitializeAllAsmParsers();
63 llvm::InitializeAllDisassemblers();
65 manager
.load(std::string(TEST_DATA_DIRECTORY
)
66 + "/disassembler/binaries/crypt.clang.O2.armel.elf.frida");
68 ASSERT_NE(nullptr, manager
.getDisassembler());
69 EXPECT_EQ(0x104a8, manager
.getDisassembler()->entryAddress());
70 testCheckFunction(manager
.getFunction(0x105d8));
71 testMainFunction(manager
.getFunction(0x1062c));