#include "le_file.hpp" #include #include #include #include #include #include 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(), "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(); 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 code_file(file_path.string()); std::vector code(std::istreambuf_iterator(code_file), {}); std::vector<_DecodedInst> instructions; instructions.resize(100000); unsigned int read_inst; auto eip_object = x.object_table.entries[x.le_header.EIP_object]; auto index = eip_object.page_table_index; auto page = x.object_page_table.entries[index]; binparse::Offset32 offset = x.le_header.data_page_offset; auto result = distorm_decode64(0x00010000, code.data() + offset, x.object_table.entries[1].nr_page_table_entries * x.le_header.page_size, Decode32Bits, instructions.data(), instructions.size(), &read_inst); instructions.resize(read_inst); instructions.shrink_to_fit(); if(result) { } for(auto&& inst : instructions) { std::cout << std::hex << std::setw(8) << std::setfill('0') << inst.offset << ":\t" << inst.mnemonic.p << " " << inst.operands.p << std::endl; } return 0; }