diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-06-20 14:34:02 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-06-20 14:34:02 +0200 |
| commit | 46145fe7d5b1d9f0921121a088a3d61f968cc473 (patch) | |
| tree | 3bb8d13e1d9138456d03253051c24580f46690cb | |
| parent | 307c4669d787d25df04d990b3a0e47a1617b078f (diff) | |
| download | openwar-46145fe7d5b1d9f0921121a088a3d61f968cc473.tar.gz openwar-46145fe7d5b1d9f0921121a088a3d61f968cc473.tar.bz2 openwar-46145fe7d5b1d9f0921121a088a3d61f968cc473.zip | |
Adds a disasm program that decodes the first DOS instruction in a LE exe.
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | disasm/CMakeLists.txt | 16 | ||||
| -rw-r--r-- | disasm/disasm.cpp | 68 |
3 files changed, 85 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c618557..36ad668 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,4 +6,5 @@ add_subdirectory(fusion-utils) add_subdirectory(binparse) add_subdirectory(mz) add_subdirectory(le) +add_subdirectory(disasm) diff --git a/disasm/CMakeLists.txt b/disasm/CMakeLists.txt new file mode 100644 index 0000000..e433d10 --- /dev/null +++ b/disasm/CMakeLists.txt @@ -0,0 +1,16 @@ + +add_executable(disasm + disasm.cpp +) + +find_package(Boost COMPONENTS filesystem program_options system REQUIRED) + +target_link_libraries(disasm + PRIVATE le + PRIVATE ${Boost_LIBRARIES} + PRIVATE distorm3 +) + +target_include_directories(disasm + PRIVATE ${Boost_INCLUDE_DIRS} +)
\ No newline at end of file diff --git a/disasm/disasm.cpp b/disasm/disasm.cpp new file mode 100644 index 0000000..609794e --- /dev/null +++ b/disasm/disasm.cpp @@ -0,0 +1,68 @@ + +#include "le_file.hpp" + +#include <distorm.h> + +#include <boost/filesystem.hpp> +#include <boost/program_options.hpp> + +#include <iostream> +#include <istream> + +int main(int argc, char* argv[]) { + boost::program_options::options_description description; + description.add_options() + ("help,h", "produces this help message") + ("exe,e", boost::program_options::value<std::string>(), "The LE executable to parse the header for.") + ; + + boost::program_options::variables_map vm; + boost::program_options::store(boost::program_options::parse_command_line(argc, argv, description), vm); + boost::program_options::notify(vm); + + if(vm.count("help")) { + std::cout << description << std::endl; + return 0; + } + + boost::filesystem::path file_path; + if(vm.count("exe")) { + std::string exe_file = vm["exe"].as<std::string>(); + + if(boost::filesystem::exists(exe_file)) { + if(!boost::filesystem::is_directory(exe_file)) { + file_path = exe_file; + } else { + std::cerr << exe_file << " is a folder" << std::endl; + std::cerr << std::endl; + std::cerr << description << std::endl; + return -1; + } + } else { + std::cerr << "file: " << exe_file << " does not exist" << std::endl; + std::cerr << std::endl; + std::cerr << description << std::endl; + return -1; + } + } else { + std::cerr << "Option \"exe_file\" is required"; + std::cerr << std::endl; + std::cerr << description << std::endl; + return -1; + } + + std::ifstream file(file_path.string()); + auto x = le::parse_file(file); + file.close(); + + std::basic_ifstream<char> code_file(file_path.string()); + std::vector<uint8_t> code(std::istreambuf_iterator<char>(code_file), {}); + + _DecodedInst inst; + unsigned int read_inst; + + auto result = distorm_decode64(x.mz_header.ip, code.data(), 1, Decode16Bits, &inst, 1, &read_inst); + + std::cout << inst.mnemonic.p << " " << inst.operands.p << std::endl; + +} |
