diff options
| -rw-r--r-- | emulate/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | emulate/emulator.cpp | 15 |
2 files changed, 15 insertions, 3 deletions
diff --git a/emulate/CMakeLists.txt b/emulate/CMakeLists.txt index df4a04e..19d2879 100644 --- a/emulate/CMakeLists.txt +++ b/emulate/CMakeLists.txt @@ -5,7 +5,7 @@ add_executable(emulate emulator.hpp emulator.cpp ) -find_package(Boost COMPONENTS filesystem program_options system REQUIRED) +find_package(Boost COMPONENTS filesystem program_options timer system REQUIRED) find_package(distorm3 REQUIRED CONFIG) @@ -13,6 +13,7 @@ target_link_libraries(emulate PRIVATE Boost::program_options PRIVATE Boost::system PRIVATE Boost::filesystem + PRIVATE Boost::timer PRIVATE distorm3 PRIVATE le )
\ No newline at end of file diff --git a/emulate/emulator.cpp b/emulate/emulator.cpp index 2e30fd8..669684f 100644 --- a/emulate/emulator.cpp +++ b/emulate/emulator.cpp @@ -1,6 +1,8 @@ #include "emulator.hpp" +#include <boost/timer/timer.hpp> + template <> struct SignedCounterpart<uint32_t> { typedef int32_t type; @@ -417,8 +419,13 @@ void emulate(std::string file_path) { emulator.set_data_segment(file.object_table.entries.at(2).reloc_base_address); unsigned int decodedInstructionsCount; + unsigned int emulated_instructions = 0; bool run = true; + + boost::timer::cpu_timer timer; + timer.start(); + while(run) { ci.code = binary.data() + emulator.cpu.eip(); ci.nextOffset = emulator.cpu.eip(); @@ -428,17 +435,21 @@ void emulate(std::string file_path) { ci.features = DF_NONE; _DInst decinst; - distorm_decompose(&ci, &decinst, 1, &decodedInstructionsCount); + distorm_decompose(&ci, &decinst, 1, &decodedInstructionsCount); _DecodedInst inst; distorm_format64(&ci, &decinst, &inst); std::cout << emulator.cpu << std::endl; - std::cout << "CurrentInstruction: " << std::hex << std::setw(8) << std::setfill('0') << inst.offset << ":\t" << inst.mnemonic.p << " " << inst.operands.p << std::endl; + std::cout << "CurrentInstruction: " << std::hex << std::setw(8) << std::setfill('0') << inst.offset << ":\t" << inst.mnemonic.p << " " << inst.operands.p << std::dec << std::endl; std::cout << std::endl << std::endl; emulator.cpu.eip() += decinst.size; run = emulator.handle_instruction(decinst); + emulated_instructions++; } + + timer.stop(); + std::cout << "Serviced: " << emulated_instructions << " Instructions in: " << timer.elapsed().user << "ns" << std::endl; } |
