Skip to content

Commit

Permalink
changed list_exports return value and updated the example
Browse files Browse the repository at this point in the history
  • Loading branch information
Xoffio committed Sep 5, 2024
1 parent ee52266 commit 909792e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 30 deletions.
7 changes: 3 additions & 4 deletions examples/core/list_exports/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ Once ran you should expect an output similar to the next one:
```
[*] Frida version: 16.4.8
[*] Device name: Local System
[*] Attached to PID 7581
- 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.
Some(["increment", "getvalue"])
Some(["increment", "getvalue"])
Some(["increment", "getvalue"])
["increment", "getvalue"]
["increment", "getvalue"]
["increment", "getvalue"]
[*] Script unloaded
[*] Session detached
Exiting...
Expand Down
20 changes: 2 additions & 18 deletions examples/core/list_exports/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,21 @@ lazy_static! {
}

fn main() {
let args: Vec<String> = std::env::args().collect();

if args.len() < 2 {
println!("Usage: {} <PID>", args[0]);
return;
}

let device_manager = frida::DeviceManager::obtain(&FRIDA);
let local_device = device_manager.get_device_by_type(frida::DeviceType::Local);
let pid: u32 = args[1].parse().unwrap();
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 = match device.attach(pid) {
Ok(s) => s,
Err(_) => {
println!("Error attaching to process {}", pid);
return;
}
};
let session = device.attach(0).unwrap();

if session.is_detached() {
println!("Session is detached");
return;
}

println!("[*] Attached to PID {}", pid);

let script_source = r#"
var globalVar = 0;
console.log("Logging message from JS");
Expand Down
12 changes: 4 additions & 8 deletions frida/src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl<'a> Script<'a> {
}

/// List all the exported attributes from the script's rpc
pub fn list_exports(&mut self) -> Result<Option<Vec<String>>> {
pub fn list_exports(&mut self) -> Result<Vec<String>> {
let json_req = {
let name = "frida:rpc".into();
let id = self.inc_id().into();
Expand All @@ -263,7 +263,7 @@ impl<'a> Script<'a> {
let (_, rx) = &self.callback_handler.channel;
let rpc_result = rx.recv().unwrap();

let func_list: Option<Vec<String>> = match rpc_result {
let func_list: Vec<String> = match rpc_result {
Message::Send(r) => {
let tmp_list: Vec<String> = r
.payload
Expand All @@ -274,13 +274,9 @@ impl<'a> Script<'a> {
.map(|i| i.as_str().unwrap_or("").to_string())
.collect();

if !tmp_list.is_empty() {
Some(tmp_list)
} else {
None
}
tmp_list
}
_ => None,
_ => Vec::new(),
};

Ok(func_list)
Expand Down

0 comments on commit 909792e

Please sign in to comment.