--- /dev/null
+#include <gtest/gtest.h>
+#include <string>
+
+#include "core/InformationManager.hxx"
+#include "core/Function.hxx"
+#include "core/BasicBlock.hxx"
+#include "disassembler/llvm/LLVMDisassembler.hxx"
+define(GEN_NAME, $1$2)dnl
+
+extern char * TEST_DATA_DIRECTORY;
+
+static void testMainFunction(Function* main) {
+ ASSERT_NE(nullptr, main);
+ EXPECT_STREQ("MAIN_NAME", main->getName().c_str());
+
+ auto blocks = main->blocks();
+ auto block = blocks.begin()->second;
+ EXPECT_EQ(MAIN_BLOCKS, blocks.size());
+ EXPECT_EQ(MAIN_SIZE, block->getInstructions().size());
+ EXPECT_EQ(MAIN_CHILD_0, block->getNextBlock(0));
+ EXPECT_EQ(MAIN_CHILD_1, block->getNextBlock(1));
+
+ EXPECT_TRUE(blocks.find(MAIN_CHILD_0) != blocks.end());
+ EXPECT_TRUE(blocks.find(MAIN_CHILD_1) != blocks.end());
+}
+
+static void testCheckFunction(Function* check) {
+ ASSERT_NE(nullptr, check);
+ EXPECT_STREQ("TEST_NAME", check->getName().c_str());
+
+ auto blocks = check->blocks();
+ auto block = blocks.begin()->second;
+ EXPECT_EQ(1, blocks.size());
+ EXPECT_EQ(TEST_SIZE, block->getInstructions().size());
+ EXPECT_EQ(0x0, block->getNextBlock(0));
+ EXPECT_EQ(0x0, block->getNextBlock(1));
+}
+
+TEST(llvmDisassemblerTest, GEN_NAME(NAME, OpenBinaryBasicStructure)) {
+ SCOPED_TRACE("opening cryptsample NAME");
+ InformationManager manager;
+
+ llvm::InitializeAllTargetInfos();
+ llvm::InitializeAllTargetMCs();
+ llvm::InitializeAllAsmParsers();
+ llvm::InitializeAllDisassemblers();
+
+ manager.reset(std::string(TEST_DATA_DIRECTORY)
+ + "FILENAME");
+
+ ASSERT_NE(nullptr, manager.getDisassembler());
+ EXPECT_EQ(ENTRY, manager.getDisassembler()->entryAddress());
+ testCheckFunction(manager.getFunction(TEST_ENTRY));
+ testMainFunction(manager.getFunction(MAIN_ENTRY));
+}
+
+TEST(llvmDisassemblerTest, GEN_NAME(NAME, LoadBinaryBasicStructure)) {
+ SCOPED_TRACE("loading cryptsample NAME");
+ InformationManager manager;
+
+ llvm::InitializeAllTargetInfos();
+ llvm::InitializeAllTargetMCs();
+ llvm::InitializeAllAsmParsers();
+ llvm::InitializeAllDisassemblers();
+
+ manager.load(std::string(TEST_DATA_DIRECTORY)
+ + "FILENAME.frida");
+
+ ASSERT_NE(nullptr, manager.getDisassembler());
+ EXPECT_EQ(ENTRY, manager.getDisassembler()->entryAddress());
+ testCheckFunction(manager.getFunction(TEST_ENTRY));
+ testMainFunction(manager.getFunction(MAIN_ENTRY));
+}
--- /dev/null
+#!/usr/bin/make -f
+
+all: amd64LinuxDisassemblerTest.cxx armelLinuxDisassemblerTest.cxx mipselLinuxDisassemblerTest.cxx amd64MachODisassemblerTest.cxx
+
+amd64LinuxDisassemblerTest.cxx: DisassemblerTest.cxx.m4
+ m4 -DNAME=amd64Linux \
+ -DFILENAME=/disassembler/binaries/crypt.clang.O2.amd64.elf \
+ -DENTRY=0x4005F0 \
+ -DMAIN_ENTRY=0x400770 \
+ -DMAIN_NAME=main \
+ -DMAIN_SIZE=17 \
+ -DMAIN_BLOCKS=4 \
+ -DMAIN_CHILD_0=0x4007ea \
+ -DMAIN_CHILD_1=0x4007ce \
+ -DTEST_ENTRY=0x4006f0 \
+ -DTEST_NAME=check \
+ -DTEST_SIZE=29 \
+ < $^ > $@
+
+armelLinuxDisassemblerTest.cxx: DisassemblerTest.cxx.m4
+ m4 -DNAME=armelLinux \
+ -DFILENAME=/disassembler/binaries/crypt.clang.O2.armel.elf \
+ -DENTRY=0x104a8 \
+ -DMAIN_ENTRY=0x1062c \
+ -DMAIN_NAME=main \
+ -DMAIN_SIZE=22 \
+ -DMAIN_BLOCKS=4 \
+ -DMAIN_CHILD_0=0x1068c \
+ -DMAIN_CHILD_1=0x10684 \
+ -DTEST_ENTRY=0x105d8 \
+ -DTEST_NAME=check \
+ -DTEST_SIZE=18 \
+ < $^ > $@
+
+mipselLinuxDisassemblerTest.cxx: DisassemblerTest.cxx.m4
+ m4 -DNAME=DISABLED_mipselLinux \
+ -DFILENAME=/disassembler/binaries/crypt.clang.O2.mipsel.elf \
+ -DENTRY=0x4005F0 \
+ -DMAIN_ENTRY=0x400870 \
+ -DMAIN_NAME=main \
+ -DMAIN_SIZE=27 \
+ -DMAIN_BLOCKS=4 \
+ -DMAIN_CHILD_0=0x4008f4 \
+ -DMAIN_CHILD_1=0x4008dc \
+ -DTEST_ENTRY=0x400810 \
+ -DTEST_NAME=check \
+ -DTEST_SIZE=24 \
+ < $^ > $@
+
+amd64MachODisassemblerTest.cxx: DisassemblerTest.cxx.m4
+ m4 -DNAME=amd64MachO \
+ -DFILENAME=/disassembler/binaries/crypt.clang.O2.amd64.macho \
+ -DENTRY=0x0 \
+ -DMAIN_ENTRY=0x100000e30 \
+ -DMAIN_NAME=_main \
+ -DMAIN_SIZE=20 \
+ -DMAIN_BLOCKS=6 \
+ -DMAIN_CHILD_0=0x100000EB2 \
+ -DMAIN_CHILD_1=0x100000E99 \
+ -DTEST_ENTRY=0x100000db0 \
+ -DTEST_NAME=_check \
+ -DTEST_SIZE=29 \
+ < $^ > $@
}
TEST(llvmDisassemblerTest, amd64LinuxOpenBinaryBasicStructure) {
- SCOPED_TRACE("opening cryptsample.clang.amd64.elf");
+ SCOPED_TRACE("opening cryptsample amd64Linux");
InformationManager manager;
llvm::InitializeAllTargetInfos();
}
TEST(llvmDisassemblerTest, amd64LinuxLoadBinaryBasicStructure) {
- SCOPED_TRACE("loading cryptsample.clang.amd64.elf");
+ SCOPED_TRACE("loading cryptsample amd64Linux");
InformationManager manager;
llvm::InitializeAllTargetInfos();
extern char * TEST_DATA_DIRECTORY;
static void testMainFunction(Function* main) {
- SCOPED_TRACE("main");
ASSERT_NE(nullptr, main);
EXPECT_STREQ("_main", main->getName().c_str());
}
static void testCheckFunction(Function* check) {
- SCOPED_TRACE("check");
ASSERT_NE(nullptr, check);
EXPECT_STREQ("_check", check->getName().c_str());
}
TEST(llvmDisassemblerTest, amd64MachOOpenBinaryBasicStructure) {
- SCOPED_TRACE("opening cryptsample.clang.amd64.macho");
+ SCOPED_TRACE("opening cryptsample amd64MachO");
InformationManager manager;
llvm::InitializeAllTargetInfos();
+ "/disassembler/binaries/crypt.clang.O2.amd64.macho");
ASSERT_NE(nullptr, manager.getDisassembler());
+ EXPECT_EQ(0x0, manager.getDisassembler()->entryAddress());
testCheckFunction(manager.getFunction(0x100000db0));
testMainFunction(manager.getFunction(0x100000e30));
}
TEST(llvmDisassemblerTest, amd64MachOLoadBinaryBasicStructure) {
- SCOPED_TRACE("loading cryptsample.clang.amd64.macho");
+ SCOPED_TRACE("loading cryptsample amd64MachO");
InformationManager manager;
llvm::InitializeAllTargetInfos();
+ "/disassembler/binaries/crypt.clang.O2.amd64.macho.frida");
ASSERT_NE(nullptr, manager.getDisassembler());
+ EXPECT_EQ(0x0, manager.getDisassembler()->entryAddress());
testCheckFunction(manager.getFunction(0x100000db0));
testMainFunction(manager.getFunction(0x100000e30));
}
}
TEST(llvmDisassemblerTest, armelLinuxOpenBinaryBasicStructure) {
- SCOPED_TRACE("opening cryptsample.clang.armel.elf");
+ SCOPED_TRACE("opening cryptsample armelLinux");
InformationManager manager;
llvm::InitializeAllTargetInfos();
}
TEST(llvmDisassemblerTest, armelLinuxLoadBinaryBasicStructure) {
- SCOPED_TRACE("loading cryptsample.clang.armel.elf");
+ SCOPED_TRACE("loading cryptsample armelLinux");
InformationManager manager;
llvm::InitializeAllTargetInfos();
EXPECT_EQ(0x4008f4, block->getNextBlock(0));
EXPECT_EQ(0x4008dc, block->getNextBlock(1));
- EXPECT_TRUE(blocks.find(0x4007ea) != blocks.end());
- EXPECT_TRUE(blocks.find(0x4007ce) != blocks.end());
+ EXPECT_TRUE(blocks.find(0x4008f4) != blocks.end());
+ EXPECT_TRUE(blocks.find(0x4008dc) != blocks.end());
}
static void testCheckFunction(Function* check) {
EXPECT_EQ(0x0, block->getNextBlock(1));
}
-TEST(llvmDisassemblerTest, mipselLinuxOpenBinaryBasicStructure) {
- SCOPED_TRACE("opening cryptsample.clang.mipsel.elf");
+TEST(llvmDisassemblerTest, DISABLED_mipselLinuxOpenBinaryBasicStructure) {
+ SCOPED_TRACE("opening cryptsample DISABLED_mipselLinux");
InformationManager manager;
llvm::InitializeAllTargetInfos();
testMainFunction(manager.getFunction(0x400870));
}
-TEST(llvmDisassemblerTest, mipselLinuxLoadBinaryBasicStructure) {
- SCOPED_TRACE("loading cryptsample.clang.mipsel.elf");
+TEST(llvmDisassemblerTest, DISABLED_mipselLinuxLoadBinaryBasicStructure) {
+ SCOPED_TRACE("loading cryptsample DISABLED_mipselLinux");
InformationManager manager;
llvm::InitializeAllTargetInfos();