diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index b435419..cf90146 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -17,7 +17,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-latest, macos-latest, windows-2019] steps: - uses: actions/checkout@v2 - run: | @@ -28,7 +28,7 @@ jobs: - run: brew install capstone nasm mingw-w64 glfw glm if: matrix.os == 'macOS-latest' - run: choco install python3 nasm - if: matrix.os == 'windows-latest' + if: matrix.os == 'windows-2019' - name: Create Build Environment # Some projects don't allow in-source building, so create a separate build directory # We'll use this as our working directory for all subsequent commands @@ -48,7 +48,7 @@ jobs: run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE - name: Configure CMake (Linux\Windows) - if: matrix.os == 'ubuntu-latest' || matrix.os == 'windows-latest' + if: matrix.os == 'ubuntu-latest' || matrix.os == 'windows-2019' # Use a bash shell so we can use the same syntax for environment variable # access regardless of the host operating system shell: bash @@ -73,7 +73,7 @@ jobs: run: ./src/test/Disassembler_TEST - name: Test Windows - if: matrix.os == 'windows-latest' + if: matrix.os == 'windows-2019' working-directory: ${{github.workspace}}/build shell: bash # Execute tests defined by the CMake configuration. diff --git a/int-tests/mac/CMakeLists.txt b/int-tests/mac/CMakeLists.txt index ee4859e..a7c6ef9 100644 --- a/int-tests/mac/CMakeLists.txt +++ b/int-tests/mac/CMakeLists.txt @@ -1,6 +1,12 @@ # Project "mac-tests" project(mac-tests ASM_NASM) set(CMAKE_ASM_NASM_LINK_FLAGS "-macosx_version_min 10.13 -lSystem") +if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" + AND CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER_EQUAL 20 + AND CMAKE_HOST_SYSTEM_VERSION VERSION_LESS 21) + set(CMAKE_ASM_NASM_LINK_FLAGS "${CMAKE_ASM_NASM_LINK_FLAGS} -L /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib") + message(STATUS "Running on Big Sur") +endif () # Specify ASM linker set(CMAKE_ASM_NASM_LINK_EXECUTABLE "ld -o ") diff --git a/src/cli/binaryfilecli.cpp b/src/cli/binaryfilecli.cpp index be9939d..7376bb9 100644 --- a/src/cli/binaryfilecli.cpp +++ b/src/cli/binaryfilecli.cpp @@ -17,6 +17,7 @@ BinaryFileCLI::BinaryFileCLI(int argc, char **argv) : BaseCLI(argc, argv) { // its only in BaseCLI this->filename = parser.get("f"); this->dynamicLibs = parser.get("d"); + this->shouldPrintFileNames = parser.get("F"); } BinaryFileCLI::~BinaryFileCLI() {} @@ -28,9 +29,11 @@ void BinaryFileCLI::configure_parser() { parser.set_required(name, altName, description); parser.set_optional("d", "dynamic", "", "input to the dynamic lib we want to load."); + parser.set_optional("F", "function", 0, "print out function names."); } void BinaryFileCLI::executeAction() { this->BaseCLI::executeAction(); - BinaryDisassemble::action(this->filename, this->dynamicLibs); + BinaryDisassemble::action(this->filename, this->dynamicLibs, + this->shouldPrintFileNames); } \ No newline at end of file diff --git a/src/cli/binaryfilecli.h b/src/cli/binaryfilecli.h index 614f148..90e1abd 100644 --- a/src/cli/binaryfilecli.h +++ b/src/cli/binaryfilecli.h @@ -26,6 +26,7 @@ class BinaryFileCLI : public BaseCLI { private: std::string filename; std::string dynamicLibs; + bool shouldPrintFileNames; }; #endif // __binary_file_cli_h__ \ No newline at end of file diff --git a/src/runtime/binaryDisassemble.cpp b/src/runtime/binaryDisassemble.cpp index 0e10ccd..4df3600 100644 --- a/src/runtime/binaryDisassemble.cpp +++ b/src/runtime/binaryDisassemble.cpp @@ -35,12 +35,16 @@ BinaryDisassemble::disassemble(const std::string &filename, bool BinaryDisassemble::action(const std::string &filename, const std::string &dynamicLibPaths, - std::ostream &out) { + bool shouldPrintFileNames, std::ostream &out) { std::unique_ptr binary = ASMParser::Parser(filename); auto disasm = disassemble(filename, dynamicLibPaths); out << *(binary.get()) << std::endl; - out << *(disasm.get()) << std::endl; + if (shouldPrintFileNames) { + out << binary->functionNames() << std::endl; + } else { + out << *(disasm.get()) << std::endl; + } return true; } \ No newline at end of file diff --git a/src/runtime/binaryDisassemble.h b/src/runtime/binaryDisassemble.h index f84d22e..4979761 100644 --- a/src/runtime/binaryDisassemble.h +++ b/src/runtime/binaryDisassemble.h @@ -27,6 +27,7 @@ class BinaryDisassemble { disassemble(const std::string &filename, const std::string &dynamicLibPaths); static bool action(const std::string &filename, const std::string &dynamicLibPaths, + bool shouldPrintFileNames = false, std::ostream &out = std::cout); }; diff --git a/src/runtime/internalData.h b/src/runtime/internalData.h index c37b864..052b874 100644 --- a/src/runtime/internalData.h +++ b/src/runtime/internalData.h @@ -22,6 +22,7 @@ struct BinaryTypes { struct BinaryInternal { BinaryInternal() {} BinaryTypes binary; + std::vector funcNames; void setElf(std::unique_ptr &elf) { binary.elf = std::move(elf); } @@ -34,6 +35,26 @@ struct BinaryInternal { void setMachO(LIEF::MachO::Binary *machO) { binary.machO = std::unique_ptr(machO); } + LIEF::Binary::functions_t functions() { + if (binary.elf) { + return binary.elf->functions(); + } + if (binary.pe) { + return binary.pe->functions(); + } + if (binary.machO) { + return binary.machO->functions(); + } + } + std::vector &functionNames() { + auto funcs = functions(); + if (funcNames.empty()) { + auto getFuncName = [](LIEF::Function &func) { return func.name(); }; + std::transform(funcs.begin(), funcs.end(), std::back_inserter(funcNames), + getFuncName); + } + return funcNames; + } }; #endif //__internal_data_h__ \ No newline at end of file diff --git a/src/runtime/runtime.cpp b/src/runtime/runtime.cpp index 61a9eba..c9202f0 100644 --- a/src/runtime/runtime.cpp +++ b/src/runtime/runtime.cpp @@ -16,4 +16,8 @@ Binary::Binary(std::string path) : mPath(path) { mBinaryInternal = std::make_unique(); } +std::vector &Binary::functionNames() { + return mBinaryInternal->functionNames(); +} + Binary::~Binary() {} \ No newline at end of file diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index 4c84941..4677494 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -44,6 +44,7 @@ class Binary { OStype OS() const { return os; } const std::vector &Instructions() const; + std::vector &functionNames(); friend class ASMParser; };