-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c93bd23
commit 6d287d1
Showing
20 changed files
with
335 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "stalker-observer" | ||
version = "0.1.0" | ||
authors = ["meme <meme@users.noreply.github.com>"] | ||
edition = "2018" | ||
license = "wxWindows" | ||
publish = false | ||
|
||
[dependencies] | ||
frida-gum = { path = "../../../frida-gum", features = ["event-sink", "invocation-listener", "stalker-observer"] } | ||
frida-gum-sys = { path = "../../../frida-gum-sys" } | ||
lazy_static = "1.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* This example is in the public domain */ | ||
|
||
use frida_gum as gum; | ||
use frida_gum::stalker::{Event, EventMask, EventSink, Stalker, StalkerObserver, Transformer}; | ||
use frida_gum_sys as gum_sys; | ||
use lazy_static::lazy_static; | ||
|
||
lazy_static! { | ||
static ref GUM: gum::Gum = unsafe { gum::Gum::obtain() }; | ||
} | ||
|
||
struct SampleEventSink; | ||
|
||
impl EventSink for SampleEventSink { | ||
fn query_mask(&mut self) -> EventMask { | ||
EventMask::Exec | ||
} | ||
|
||
fn start(&mut self) { | ||
println!("start"); | ||
} | ||
|
||
fn process(&mut self, _event: &Event) { | ||
println!("process"); | ||
} | ||
|
||
fn flush(&mut self) { | ||
println!("flush"); | ||
} | ||
|
||
fn stop(&mut self) { | ||
println!("stop"); | ||
} | ||
} | ||
|
||
struct SampleStalkerObserver; | ||
|
||
impl StalkerObserver for SampleStalkerObserver { | ||
fn switch_callback( | ||
&mut self, | ||
from_address: gum_sys::gpointer, | ||
start_address: gum_sys::gpointer, | ||
from_insn: gum_sys::gpointer, | ||
target: &mut gum_sys::gpointer, | ||
) { | ||
println!( | ||
"from_address: {:p}, start_address: {:p}, from_insn: {:p}, target: {:p}", | ||
from_address, start_address, from_insn, *target | ||
); | ||
} | ||
|
||
fn notify_backpatch( | ||
&mut self, | ||
_backpatch: *const gum_sys::GumBackpatch, | ||
_size: gum_sys::gsize, | ||
) { | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut stalker = Stalker::new(&GUM); | ||
let transformer = Transformer::from_callback(&GUM, |basic_block, _output| { | ||
for instr in basic_block { | ||
instr.put_callout(|_cpu_context| {}); | ||
instr.keep(); | ||
} | ||
}); | ||
|
||
let mut event_sink = SampleEventSink; | ||
stalker.follow_me(&transformer, Some(&mut event_sink)); | ||
stalker.set_observer(&mut SampleStalkerObserver); | ||
stalker.unfollow_me(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright © 2020-2021 Keegan Saunders | ||
* | ||
* Licence: wxWindows Library Licence, Version 3.1 | ||
*/ | ||
|
||
#include "stalker_observer.h" | ||
|
||
static void gum_rust_stalker_observer_iface_init(gpointer g_iface, gpointer iface_data); | ||
|
||
G_DEFINE_TYPE_EXTENDED(GumRustStalkerObserver, | ||
gum_rust_stalker_observer, | ||
G_TYPE_OBJECT, | ||
0, | ||
G_IMPLEMENT_INTERFACE(GUM_TYPE_STALKER_OBSERVER, | ||
gum_rust_stalker_observer_iface_init)) | ||
|
||
static void | ||
gum_rust_stalker_observer_finalize(GObject *obj) | ||
{ | ||
G_OBJECT_CLASS(gum_rust_stalker_observer_parent_class)->finalize(obj); | ||
} | ||
|
||
static void | ||
gum_rust_stalker_observer_class_init (GumRustStalkerObserverClass *klass) | ||
{ | ||
GObjectClass *object_class = G_OBJECT_CLASS(klass); | ||
object_class->finalize = gum_rust_stalker_observer_finalize; | ||
} | ||
|
||
static void | ||
gum_rust_stalker_observer_notify_backpatch(GumStalkerObserver *sink, | ||
const GumBackpatch * backpatch, gsize size) | ||
{ | ||
GumRustStalkerObserver *self = GUM_RUST_STALKER_OBSERVER(sink); | ||
return self->rust.notify_backpatch(self->rust.user_data, backpatch, size); | ||
} | ||
|
||
static void | ||
gum_rust_stalker_observer_switch_callback(GumStalkerObserver *sink, | ||
gpointer from_address, gpointer start_address, gpointer from_insn, | ||
gpointer * target) | ||
{ | ||
GumRustStalkerObserver *self = GUM_RUST_STALKER_OBSERVER(sink); | ||
return self->rust.switch_callback(self->rust.user_data, from_address, | ||
start_address, from_insn, target); | ||
} | ||
|
||
static void | ||
gum_rust_stalker_observer_iface_init(gpointer g_iface, gpointer iface_data) | ||
{ | ||
(void) iface_data; | ||
|
||
GumStalkerObserverInterface *iface = g_iface; | ||
iface->notify_backpatch = gum_rust_stalker_observer_notify_backpatch; | ||
iface->switch_callback = gum_rust_stalker_observer_switch_callback; | ||
} | ||
|
||
static void | ||
gum_rust_stalker_observer_init(GumRustStalkerObserver *self) | ||
{ | ||
(void) self; | ||
} | ||
|
||
GumStalkerObserver* | ||
gum_rust_stalker_observer_new (RustStalkerObserverVTable rust) | ||
{ | ||
GumRustStalkerObserver *sink; | ||
sink = g_object_new(GUM_TYPE_RUST_STALKER_OBSERVER, NULL); | ||
memcpy(&sink->rust, &rust, sizeof(sink->rust)); | ||
return GUM_STALKER_OBSERVER(sink); | ||
} | ||
|
||
void | ||
gum_rust_stalker_observer_reset(GumRustStalkerObserver *self) | ||
{ | ||
(void) self; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright © 2020-2021 Keegan Saunders | ||
* | ||
* Licence: wxWindows Library Licence, Version 3.1 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "frida-gum.h" | ||
|
||
G_BEGIN_DECLS | ||
|
||
#define GUM_TYPE_RUST_STALKER_OBSERVER (gum_rust_stalker_observer_get_type()) | ||
G_DECLARE_FINAL_TYPE(GumRustStalkerObserver, gum_rust_stalker_observer, GUM, | ||
RUST_STALKER_OBSERVER, GObject) | ||
|
||
typedef struct { | ||
void *user_data; | ||
|
||
void (*notify_backpatch)(void *user_data, const GumBackpatch * backpatch, | ||
gsize size); | ||
void (*switch_callback)(void *user_data, gpointer from_address, | ||
gpointer start_address, gpointer from_insn, gpointer * target); | ||
} RustStalkerObserverVTable; | ||
|
||
struct _GumRustStalkerObserver { | ||
GObject parent; | ||
RustStalkerObserverVTable rust; | ||
}; | ||
|
||
GumStalkerObserver *gum_rust_stalker_observer_new(RustStalkerObserverVTable rust); | ||
void gum_rust_stalker_observer_reset(GumRustStalkerObserver *self); | ||
|
||
G_END_DECLS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.