iptr-decoder
iptr-decoder is a crate of iptr project, providing idiomatic Rust-style low-level Intel PT trace handling APIs.
To use this crate, add this crate to your Cargo.toml:
= "0.1"
Basic usage
The core functionalities are designed within the trait HandlePacket. A typical usage example is like the following code snippet.
use ;
;
// Use the defined `MyPtHandler` to decode Intel PT traces
The HandlePacket trait has a lot of provided methods, each of which is corresponding to a type of PT packet. When a PT packet is decoded, the right method will be invoked with extracted values. The default implementation for each packet handlers is an NOP, and you can override each implementation like the code snippet above.
Supported PT packet types
- Short TNT
- Long TNT
- TIP
- TIP.PGE
- TIP.PGD
- FUP
- PIP
- MODE
- TraceStop
- CBR
- TSC
- MTC
- TMA
- CYC
- VMCS
- OVF
- PSB
- PSBEND
- MNT
- PAD
- PTW
- EXSTOP
- MWAIT
- PWRE
- RWRX
- BBP
- BIP
- BEP
- CFE
- EVD
Advanced Usage
Apart from customized HandlePacket implementors, this crate also provides some common packet handlers, which are organized in the iptr_decoder::packet_handler module.
For example, the PacketHandlerRawLogger logs all packet's information, and PacketCounter can tell us how many PT packets are decoded in total.
Moreover, we provide a powerful CombinedPacketHandler. With this structure, you can use the provided common packet handlers alongwith your own customized HandlePacket implementors:
use ;
;
When running the handle_pt_trace, both the log_handler and my_packet_handler will be invoked, which is very useful when debugging your own packet handler.
If you want to get the branch and basic block information, you can refer to the iptr-edge-analyzer crate, which provides a more comprehensive, complex and efficient solution.
Features
This crate has the following features:
-
log_handlerEnable
iptr_decoder::packet_handler::log, which includes handler for logging low level packets.This feature is not enabled by default.
-
allocEnable the alloc dependency. Used only for
log_handlerfeature for now.This feature is not enabled by default.