summaryrefslogtreecommitdiff
path: root/src/registers.rs
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2023-10-15 21:25:49 +0200
committerSanto Cariotti <santo@dcariotti.me>2023-10-15 21:27:17 +0200
commitd3095900b941d7b08d579f9dc5e9dac45690228b (patch)
treec28e5f89b46eeacc4e95c7cabbaa4cf1863e4c3c /src/registers.rs
parent2779d956c4ad2e3be7fa814708c11c13ea1365d7 (diff)
Use `registers` mod
Diffstat (limited to 'src/registers.rs')
-rw-r--r--src/registers.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/registers.rs b/src/registers.rs
new file mode 100644
index 0000000..80b4a9b
--- /dev/null
+++ b/src/registers.rs
@@ -0,0 +1,31 @@
+use nix::libc::user_regs_struct;
+
+/// Struct used to manipulate registers data from https://docs.rs/libc/0.2.147/libc/struct.user_regs_struct.html
+pub struct RegistersData {
+ orig_rax: u64,
+ rdi: u64,
+ rsi: u64,
+ rdx: u64,
+ rax: u64,
+}
+
+impl RegistersData {
+ /// Create new `RegistersData` from an `user_regs_struct`'C structure
+ pub fn new(registers: user_regs_struct) -> RegistersData {
+ RegistersData {
+ orig_rax: registers.orig_rax,
+ rdi: registers.rdi,
+ rsi: registers.rsi,
+ rdx: registers.rdx,
+ rax: registers.rax,
+ }
+ }
+
+ /// Returns a good string which shows the output for a line
+ pub fn output(&self) -> String {
+ format!(
+ "{}({:x}, {:x}, {:x}, ...) = {:x}",
+ self.orig_rax, self.rdi, self.rsi, self.rdx, self.rax
+ )
+ }
+}