Arion 1.0.2-alpha
A high-performance C++ framework for emulating executable binaries.
 
Loading...
Searching...
No Matches
code_tracer.hpp
Go to the documentation of this file.
1#ifndef ARION_CODE_TRACER_HPP
2#define ARION_CODE_TRACER_HPP
3
7#include <fstream>
8#include <iosfwd>
9#include <memory>
10#include <string>
11
13#define ARION_MAX_LIGHT_HITS 1024
15#define ARION_MAX_HEAVY_HITS 64
16
17namespace arion
18{
19
20class Arion;
21
23const char TRACER_FILE_MAGIC[] = "ARIONTRC";
25const float TRACER_FILE_VERSION = 1.0;
27const uint16_t TRACER_FILE_HEADER_SIZE = 0x28;
28
31{
32 // Arion specific files
36
37 // Non-Arion files
39
40 // Used to mark end of enum
41 UNKNOWN
42};
43
47{
49 uint32_t off;
51 uint16_t sz;
53 uint16_t mod_id;
55 std::unique_ptr<std::map<REG, RVAL>> regs;
56
69 CODE_HIT(uint32_t off, size_t sz, uint16_t mod_id) : off(off), sz(sz), mod_id(mod_id) {};
70};
71
74{
80 std::string name;
81
82 /*
83 * Builder for TRACER_MAPPING instances.
84 * @param[in] start Start address of the memory mapping.
85 * @param[in] end End address of the memory mapping.
86 * @param[in] name Name associated with the memory mapping.
87 */
89};
90
93{
94 private:
96 std::weak_ptr<Arion> arion;
98 bool enabled = false;
105 std::string out_f_path;
107 std::ofstream out_f;
115 std::vector<std::unique_ptr<CODE_HIT>> hits;
117 std::vector<std::unique_ptr<TRACER_MAPPING>> mappings;
125 static void instr_hook(std::shared_ptr<Arion> arion, ADDR addr, size_t sz, void *user_data);
133 static void block_hook(std::shared_ptr<Arion> arion, ADDR addr, size_t sz, void *user_data);
149 void process_hit(ADDR addr, size_t sz);
154
155 public:
161 static std::unique_ptr<CodeTracer> initialize(std::weak_ptr<Arion> arion);
166 CodeTracer(std::weak_ptr<Arion> arion) : arion(arion) {};
176 void ARION_EXPORT start(std::string out_f_path, TRACE_MODE mode);
186 void process_new_mapping(std::shared_ptr<ARION_MAPPING> mapping);
197};
198
199}; // namespace arion
200
201#endif // ARION_CODE_TRACER_HPP
This class is used to perform tracing operations over an Arion emulation and store the result in a de...
Definition code_tracer.hpp:93
void process_new_mapping(std::shared_ptr< ARION_MAPPING > mapping)
std::vector< std::unique_ptr< TRACER_MAPPING > > mappings
List of general data concerning memory mappings.
Definition code_tracer.hpp:117
CodeTracer(std::weak_ptr< Arion > arion)
Definition code_tracer.hpp:166
TRACE_MODE get_mode()
std::string out_f_path
Path to the output trace file.
Definition code_tracer.hpp:105
HOOK_ID curr_hook_id
Definition code_tracer.hpp:103
std::weak_ptr< Arion > arion
The Arion instance which emulation should be traced.
Definition code_tracer.hpp:96
std::vector< std::unique_ptr< CODE_HIT > > hits
List of code hits (instructions or basic blocks) which have not yet been flushed in the output trace ...
Definition code_tracer.hpp:115
void start(std::string out_f_path, TRACE_MODE mode)
static void instr_hook(std::shared_ptr< Arion > arion, ADDR addr, size_t sz, void *user_data)
std::ofstream out_f
Output stream of the output trace file.
Definition code_tracer.hpp:107
void process_hit(ADDR addr, size_t sz)
static std::unique_ptr< CodeTracer > initialize(std::weak_ptr< Arion > arion)
off_t mod_sec_off
Offset in the output trace file to the modules section.
Definition code_tracer.hpp:113
off_t total_hits_off
Offset in the output trace file to the total amount of hits.
Definition code_tracer.hpp:111
TRACE_MODE mode
Trace mode, conditions the output file.
Definition code_tracer.hpp:100
static void block_hook(std::shared_ptr< Arion > arion, ADDR addr, size_t sz, void *user_data)
size_t total_hits
Total amount of hits to be stored in the output trace file.
Definition code_tracer.hpp:109
#define ARION_EXPORT
Defines which symbols should be exported from the library.
Definition global_defs.hpp:13
Definition arch_x86-64.hpp:11
const float TRACER_FILE_VERSION
Version number of Arion tracer file format.
Definition code_tracer.hpp:25
const char TRACER_FILE_MAGIC[]
Magic string for headers of Arion tracer files.
Definition code_tracer.hpp:23
uint64_t ADDR
Identifies a memory address.
Definition global_defs.hpp:36
const uint16_t TRACER_FILE_HEADER_SIZE
Header size of Arion tracer files.
Definition code_tracer.hpp:27
uint64_t HOOK_ID
ID associated with a hook when created.
Definition hooks_manager.hpp:19
TRACE_MODE
These modes are used to configure the output file format.
Definition code_tracer.hpp:31
@ BLOCK
Arion tracer file which stores the address of every executed basic block (in control flow).
Definition code_tracer.hpp:35
@ INSTR
Arion tracer file which stores the address of every executed instruction.
Definition code_tracer.hpp:33
@ UNKNOWN
Unknown file format, should not be used.
Definition code_tracer.hpp:41
@ CTXT
Arion tracer file which stores the CPU context of every executed instruction.
Definition code_tracer.hpp:34
@ DRCOV
DrCov file format. Useful for compatibility with disassembler plugins.
Definition code_tracer.hpp:38
Definition code_tracer.hpp:47
std::unique_ptr< std::map< REG, RVAL > > regs
CPU context as a map of register values. Only used in TRACE_MODE::CTXT.
Definition code_tracer.hpp:55
CODE_HIT()
Definition code_tracer.hpp:60
uint16_t sz
Size of the hit. It can either be the instruction size or the basic block size depending on the used ...
Definition code_tracer.hpp:51
CODE_HIT(uint32_t off, size_t sz, uint16_t mod_id)
Definition code_tracer.hpp:69
uint16_t mod_id
ID of the hit module.
Definition code_tracer.hpp:53
uint32_t off
Offset of the hit relative to the start address of its module.
Definition code_tracer.hpp:49
Stores general data over a memory mapping to be stored in the output trace file.
Definition code_tracer.hpp:74
TRACER_MAPPING(ADDR start, ADDR end, std::string name)
Definition code_tracer.hpp:88
std::string name
Name associated with the memory mapping.
Definition code_tracer.hpp:80
ADDR start
Start address of the memory mapping.
Definition code_tracer.hpp:76
ADDR end
End address of the memory mapping.
Definition code_tracer.hpp:78