From 8dcd30d2cecfbd6a159dd654e8382de10d86bc98 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Wed, 1 Apr 2015 16:53:50 +0200 Subject: [PATCH] Add armel testcase This one doesn't do thumb so it's easy --- CMakeLists.txt | 1 + .../llvm/tests/armelLinuxDisassemblerTest.cxx | 72 ++++++++++++++++++ .../binaries/crypt.clang.O2.armel.elf | Bin 0 -> 6856 bytes .../binaries/crypt.clang.O2.armel.elf.frida | Bin 0 -> 6185 bytes 4 files changed, 73 insertions(+) create mode 100644 src/disassembler/llvm/tests/armelLinuxDisassemblerTest.cxx create mode 100755 testdata/disassembler/binaries/crypt.clang.O2.armel.elf create mode 100644 testdata/disassembler/binaries/crypt.clang.O2.armel.elf.frida diff --git a/CMakeLists.txt b/CMakeLists.txt index c3ff63f..c0abdf5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,6 +131,7 @@ set(fridatest_SOURCES src/core/tests/CommentTest.cxx src/disassembler/llvm/tests/amd64LinuxDisassemblerTest.cxx src/disassembler/llvm/tests/mipselLinuxDisassemblerTest.cxx + src/disassembler/llvm/tests/armelLinuxDisassemblerTest.cxx src/disassembler/llvm/tests/amd64MachODisassemblerTest.cxx ${frida_SOURCES} ) diff --git a/src/disassembler/llvm/tests/armelLinuxDisassemblerTest.cxx b/src/disassembler/llvm/tests/armelLinuxDisassemblerTest.cxx new file mode 100644 index 0000000..4e79972 --- /dev/null +++ b/src/disassembler/llvm/tests/armelLinuxDisassemblerTest.cxx @@ -0,0 +1,72 @@ +#include +#include + +#include "core/InformationManager.hxx" +#include "core/Function.hxx" +#include "core/BasicBlock.hxx" +#include "disassembler/llvm/LLVMDisassembler.hxx" + +extern char * TEST_DATA_DIRECTORY; + +static void testMainFunction(Function* main) { + ASSERT_NE(nullptr, main); + EXPECT_STREQ("main", main->getName().c_str()); + + auto blocks = main->blocks(); + auto block = blocks.begin()->second; + EXPECT_EQ(4, blocks.size()); + EXPECT_EQ(22, block->getInstructions().size()); + EXPECT_EQ(0x1068c, block->getNextBlock(0)); + EXPECT_EQ(0x10684, block->getNextBlock(1)); + + EXPECT_TRUE(blocks.find(0x1068c) != blocks.end()); + EXPECT_TRUE(blocks.find(0x10684) != blocks.end()); +} + +static void testCheckFunction(Function* check) { + ASSERT_NE(nullptr, check); + EXPECT_STREQ("check", check->getName().c_str()); + + auto blocks = check->blocks(); + auto block = blocks.begin()->second; + EXPECT_EQ(1, blocks.size()); + EXPECT_EQ(18, block->getInstructions().size()); + EXPECT_EQ(0x0, block->getNextBlock(0)); + EXPECT_EQ(0x0, block->getNextBlock(1)); +} + +TEST(llvmDisassemblerTest, armelLinuxOpenBinaryBasicStructure) { + SCOPED_TRACE("opening cryptsample.clang.armel.elf"); + InformationManager manager; + + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmParsers(); + llvm::InitializeAllDisassemblers(); + + manager.reset(std::string(TEST_DATA_DIRECTORY) + + "/disassembler/binaries/crypt.clang.O2.armel.elf"); + + ASSERT_NE(nullptr, manager.getDisassembler()); + EXPECT_EQ(0x104a8, manager.getDisassembler()->entryAddress()); + testCheckFunction(manager.getFunction(0x105d8)); + testMainFunction(manager.getFunction(0x1062c)); +} + +TEST(llvmDisassemblerTest, armelLinuxLoadBinaryBasicStructure) { + SCOPED_TRACE("loading cryptsample.clang.armel.elf"); + InformationManager manager; + + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmParsers(); + llvm::InitializeAllDisassemblers(); + + manager.load(std::string(TEST_DATA_DIRECTORY) + + "/disassembler/binaries/crypt.clang.O2.armel.elf.frida"); + + ASSERT_NE(nullptr, manager.getDisassembler()); + EXPECT_EQ(0x104a8, manager.getDisassembler()->entryAddress()); + testCheckFunction(manager.getFunction(0x105d8)); + testMainFunction(manager.getFunction(0x1062c)); +} diff --git a/testdata/disassembler/binaries/crypt.clang.O2.armel.elf b/testdata/disassembler/binaries/crypt.clang.O2.armel.el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