-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
list_exports func added and initial RPC code. (#147)
* list_exports func added. example showing how to use it. initial rpc code. * s1341's notes have been addressed. * intentional js error removed. pid gets pass by parameter. * trying to fix CI * fix no_std ci issues * changed list_exports return value and updated the example * deleted extra spaces
- Loading branch information
Showing
11 changed files
with
299 additions
and
26 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,10 @@ | ||
[package] | ||
name = "list_exports" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["Ricardo J Marques Montilla / Xoffio"] | ||
|
||
[dependencies] | ||
frida = { path = "../../../frida" } | ||
frida-sys = { path = "../../../frida-sys" } | ||
lazy_static = "1.5.0" |
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,18 @@ | ||
Example to showing how to use `script.list_exports()`. | ||
Once ran you should expect an output similar to the next one: | ||
|
||
``` | ||
[*] Frida version: 16.4.8 | ||
[*] Device name: Local System | ||
- Log(MessageLog { level: Info, payload: "Logging message from JS" }) | ||
- Log(MessageLog { level: Warning, payload: "Warning message from JS" }) | ||
- Log(MessageLog { level: Debug, payload: "Debug message from JS" }) | ||
- Log(MessageLog { level: Error, payload: "Error message from JS" }) | ||
[*] Script loaded. | ||
["increment", "getvalue"] | ||
["increment", "getvalue"] | ||
["increment", "getvalue"] | ||
[*] Script unloaded | ||
[*] Session detached | ||
Exiting... | ||
``` |
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,82 @@ | ||
use frida::{Frida, Message}; | ||
use lazy_static::lazy_static; | ||
use std::{thread, time::Duration}; | ||
|
||
lazy_static! { | ||
static ref FRIDA: Frida = unsafe { Frida::obtain() }; | ||
} | ||
|
||
fn main() { | ||
let device_manager = frida::DeviceManager::obtain(&FRIDA); | ||
let local_device = device_manager.get_local_device(); | ||
|
||
if let Ok(device) = local_device { | ||
println!("[*] Frida version: {}", frida::Frida::version()); | ||
println!("[*] Device name: {}", device.get_name()); | ||
|
||
// Attach to the program | ||
let session = device.attach(0).unwrap(); | ||
|
||
if session.is_detached() { | ||
println!("Session is detached"); | ||
return; | ||
} | ||
|
||
let script_source = r#" | ||
var globalVar = 0; | ||
console.log("Logging message from JS"); | ||
console.warn("Warning message from JS"); | ||
console.debug("Debug message from JS"); | ||
console.error("Error message from JS"); | ||
rpc.exports = { | ||
increment: function() { | ||
globalVar += 1; | ||
return globalVar; | ||
}, | ||
getvalue: function() { | ||
return globalVar; | ||
} | ||
}; | ||
"#; | ||
let mut script_option = frida::ScriptOption::default(); | ||
let mut script = match session.create_script(script_source, &mut script_option) { | ||
Ok(s) => s, | ||
Err(err) => { | ||
println!("{}", err); | ||
return; | ||
} | ||
}; | ||
|
||
let msg_handler = script.handle_message(Handler); | ||
if let Err(err) = msg_handler { | ||
panic!("{:?}", err); | ||
} | ||
|
||
script.load().unwrap(); | ||
println!("[*] Script loaded."); | ||
|
||
println!("{:?}", script.list_exports().unwrap()); | ||
|
||
for _ in 0..2 { | ||
thread::sleep(Duration::from_secs(1)); | ||
println!("{:?}", script.list_exports().unwrap()); | ||
} | ||
|
||
script.unload().unwrap(); | ||
println!("[*] Script unloaded"); | ||
|
||
session.detach().unwrap(); | ||
println!("[*] Session detached"); | ||
} | ||
|
||
println!("Exiting..."); | ||
} | ||
|
||
struct Handler; | ||
|
||
impl frida::ScriptHandler for Handler { | ||
fn on_message(&mut self, message: &Message) { | ||
println!("- {:?}", message); | ||
} | ||
} |
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.