diff --git a/Cargo.lock b/Cargo.lock index edf6abe..bc713a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -227,6 +227,7 @@ dependencies = [ "frida", "goblin", "lazy_static", + "mylib", "pretty_assertions", "serde", "serde_json", @@ -568,6 +569,10 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "mylib" +version = "0.1.0" + [[package]] name = "nom" version = "7.1.3" diff --git a/Cargo.toml b/Cargo.toml index 4afba94..7c670e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,3 +33,4 @@ build-target = "0.4" [dev-dependencies] pretty_assertions = "1.4.0" +mylib = { path = "tests/mylib" } diff --git a/src/frida_handler.rs b/src/frida_handler.rs index a4a3f7d..561c361 100644 --- a/src/frida_handler.rs +++ b/src/frida_handler.rs @@ -88,29 +88,29 @@ impl ScriptHandler for Handler { } } -// #[cfg(test)] -// mod tests { -// use super::*; -// use pretty_assertions::assert_eq; +#[cfg(test)] +mod tests { + use super::*; + use pretty_assertions::assert_eq; -// #[link(name = "mylib", kind = "dylib")] -// extern { -// fn mylib_foo() -> u8; -// } + #[link(name = "mylib", kind = "dylib")] + extern { + fn mylib_foo() -> u8; + } -// #[test] -// fn test_attach_pid() { -// assert_eq!(10, unsafe { mylib_foo() }); + #[test] + fn test_attach_pid() { + assert_eq!(10, unsafe { mylib_foo() }); -// let frida_script = r#" -// const foo = Module.getExportByName(null, "mylib_foo"); -// Interceptor.replace(foo, new NativeCallback(function () { -// console.log("replaced foo() called"); -// return 20; -// }, "uint8", [])); -// "#; + let frida_script = r#" + const foo = Module.getExportByName(null, "mylib_foo"); + Interceptor.replace(foo, new NativeCallback(function () { + console.log("replaced foo() called"); + return 20; + }, "uint8", [])); + "#; -// attach_pid(frida_script, 0); -// assert_eq!(20, unsafe { mylib_foo() }); -// } -// } + attach_pid(frida_script, 0); + assert_eq!(20, unsafe { mylib_foo() }); + } +}