From 517f692fc827fe404ba1f18073565a9c9e60ec02 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Thu, 26 Mar 2015 17:59:46 +0100 Subject: [PATCH] Add (failing) mipsel test --- CMakeLists.txt | 1 + .../tests/mipselLinuxDisassemblerTest.cxx | 72 ++++++++++++++++++ .../binaries/crypt.clang.O2.mipsel.elf | Bin 0 -> 7188 bytes 3 files changed, 73 insertions(+) create mode 100644 src/disassembler/llvm/tests/mipselLinuxDisassemblerTest.cxx create mode 100755 testdata/disassembler/binaries/crypt.clang.O2.mipsel.elf diff --git a/CMakeLists.txt b/CMakeLists.txt index fabb0d9..c3ff63f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,6 +130,7 @@ set(fridatest_SOURCES src/core/tests/FunctionTest.cxx src/core/tests/CommentTest.cxx src/disassembler/llvm/tests/amd64LinuxDisassemblerTest.cxx + src/disassembler/llvm/tests/mipselLinuxDisassemblerTest.cxx src/disassembler/llvm/tests/amd64MachODisassemblerTest.cxx ${frida_SOURCES} ) diff --git a/src/disassembler/llvm/tests/mipselLinuxDisassemblerTest.cxx b/src/disassembler/llvm/tests/mipselLinuxDisassemblerTest.cxx new file mode 100644 index 0000000..70511b4 --- /dev/null +++ b/src/disassembler/llvm/tests/mipselLinuxDisassemblerTest.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(27, block->getInstructions().size()); + 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()); +} + +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(24, block->getInstructions().size()); + EXPECT_EQ(0x0, block->getNextBlock(0)); + EXPECT_EQ(0x0, block->getNextBlock(1)); +} + +TEST(llvmDisassemblerTest, mipselLinuxOpenBinaryBasicStructure) { + SCOPED_TRACE("opening cryptsample.clang.mipsel.elf"); + InformationManager manager; + + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmParsers(); + llvm::InitializeAllDisassemblers(); + + manager.reset(std::string(TEST_DATA_DIRECTORY) + + "/disassembler/binaries/crypt.clang.O2.mipsel.elf"); + + ASSERT_NE(nullptr, manager.getDisassembler()); + EXPECT_EQ(0x4005F0, manager.getDisassembler()->entryAddress()); + testCheckFunction(manager.getFunction(0x400810)); + testMainFunction(manager.getFunction(0x400870)); +} + +TEST(llvmDisassemblerTest, mipselLinuxLoadBinaryBasicStructure) { + SCOPED_TRACE("loading cryptsample.clang.mipsel.elf"); + InformationManager manager; + + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmParsers(); + llvm::InitializeAllDisassemblers(); + + manager.load(std::string(TEST_DATA_DIRECTORY) + + "/disassembler/binaries/crypt.clang.O2.mipsel.elf.frida"); + + ASSERT_NE(nullptr, manager.getDisassembler()); + EXPECT_EQ(0x4005F0, manager.getDisassembler()->entryAddress()); + testCheckFunction(manager.getFunction(0x400810)); + testMainFunction(manager.getFunction(0x400870)); +} diff --git a/testdata/disassembler/binaries/crypt.clang.O2.mipsel.elf b/testdata/disassembler/binaries/crypt.clang.O2.mipsel.elf new file mode 100755 index 0000000000000000000000000000000000000000..492011aba8ebb6ad494b302a9691bf84b8857741 GIT binary patch literal 7188 zcmb7Ie{5UT6+X6;Hccr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