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(17, block
->getInstructions().size());
19 EXPECT_EQ(0x4007ea, block
->getNextBlock(0));
20 EXPECT_EQ(0x4007ce, block
->getNextBlock(1));
22 EXPECT_TRUE(blocks
.find(0x4007ea) != blocks
.end());
23 EXPECT_TRUE(blocks
.find(0x4007ce) != 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(29, block
->getInstructions().size());
34 EXPECT_EQ(0x0, block
->getNextBlock(0));
35 EXPECT_EQ(0x0, block
->getNextBlock(1));
38 TEST(llvmDisassemblerTest
, amd64LinuxOpenBinaryBasicStructure
) {
39 SCOPED_TRACE("opening cryptsample.clang.amd64.elf");
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.amd64.elf");
50 ASSERT_NE(nullptr, manager
.getDisassembler());
51 EXPECT_EQ(0x4005F0, manager
.getDisassembler()->entryAddress());
52 testCheckFunction(manager
.getFunction(0x4006f0));
53 testMainFunction(manager
.getFunction(0x400770));
56 TEST(llvmDisassemblerTest
, amd64LinuxLoadBinaryBasicStructure
) {
57 SCOPED_TRACE("loading cryptsample.clang.amd64.elf");
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.amd64.elf.frida");
68 ASSERT_NE(nullptr, manager
.getDisassembler());
69 EXPECT_EQ(0x4005F0, manager
.getDisassembler()->entryAddress());
70 testCheckFunction(manager
.getFunction(0x4006f0));
71 testMainFunction(manager
.getFunction(0x400770));