Skip to content

Commit 269f0c6

Browse files
expose frida-gum underlying writer object to allow users to use funct… (#198)
* expose frida-gum underlying writer object to allow users to use functions that are not exposed in * add function for writers * add and
1 parent 14881d4 commit 269f0c6

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

frida-gum/src/instruction_writer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ pub trait InstructionWriter {
5858
/// Add a branch to an immediate address
5959
fn put_branch_address(&self, address: u64) -> bool;
6060

61+
/// Add a nop instruction
62+
fn put_nop(&self);
63+
6164
/// Flush the writer, outputing any pending ldr-immediates
6265
fn flush(&self) -> bool;
6366
}

frida-gum/src/instruction_writer/aarch64/writer.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ impl InstructionWriter for Aarch64InstructionWriter {
6161
unsafe { gum_sys::gum_arm64_writer_put_b_imm(self.writer, address) != 0 }
6262
}
6363

64+
fn put_nop(&self) {
65+
unsafe { gum_sys::gum_arm64_writer_put_nop(self.writer) }
66+
}
67+
6468
fn flush(&self) -> bool {
6569
unsafe { gum_sys::gum_arm64_writer_flush(self.writer) != 0 }
6670
}
@@ -74,6 +78,11 @@ impl Aarch64InstructionWriter {
7478
}
7579
}
7680

81+
/// Get the underlying frida gum writer object
82+
pub fn raw_writer(&self) -> *mut gum_sys::_GumArm64Writer {
83+
self.writer
84+
}
85+
7786
/// Insert a `b` to a label. The label is specified by `id`.
7887
pub fn put_b_label(&self, id: u64) {
7988
unsafe { gum_sys::gum_arm64_writer_put_b_label(self.writer, id as *const c_void) }

frida-gum/src/instruction_writer/arm/writer.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ impl InstructionWriter for ArmInstructionWriter {
4545
unsafe { gum_sys::gum_arm_writer_put_b_imm(self.writer, address) != 0 }
4646
}
4747

48+
fn put_nop(&self) {
49+
unsafe { gum_sys::gum_arm_writer_put_nop(self.writer) }
50+
}
51+
4852
fn flush(&self) -> bool {
4953
unsafe { gum_sys::gum_arm_writer_flush(self.writer) != 0 }
5054
}
@@ -57,6 +61,11 @@ impl ArmInstructionWriter {
5761
is_from_new: false,
5862
}
5963
}
64+
65+
/// Get the underlying frida gum writer object
66+
pub fn raw_writer(&self) -> *mut gum_sys::_GumArmWriter {
67+
self.writer
68+
}
6069
}
6170

6271
impl Drop for ArmInstructionWriter {

frida-gum/src/instruction_writer/x86_64/writer.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ impl InstructionWriter for X86InstructionWriter {
5858
unsafe { gum_sys::gum_x86_writer_put_jmp_address(self.writer, address) != 0 }
5959
}
6060

61+
fn put_nop(&self) {
62+
unsafe { gum_sys::gum_x86_writer_put_nop(self.writer) }
63+
}
64+
6165
fn flush(&self) -> bool {
6266
unsafe { gum_sys::gum_x86_writer_flush(self.writer) != 0 }
6367
}
@@ -71,6 +75,11 @@ impl X86InstructionWriter {
7175
}
7276
}
7377

78+
/// Get the underlying frida gum writer object
79+
pub fn raw_writer(&self) -> *mut gum_sys::_GumX86Writer {
80+
self.writer
81+
}
82+
7483
pub fn put_leave(&self) -> bool {
7584
unsafe {
7685
gum_sys::gum_x86_writer_put_leave(self.writer);

frida-gum/src/stalker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ impl Stalker {
153153
}
154154
}
155155

156+
/// Get the underlying frida stalker object
157+
pub fn raw_stalker(&self) -> *mut frida_gum_sys::GumStalker {
158+
self.stalker
159+
}
160+
156161
/// Exclude a range of address from the Stalker engine.
157162
///
158163
/// This exclusion will prevent the Stalker from tracing into the memory range,

0 commit comments

Comments
 (0)