Add dll proxying test

This commit is contained in:
Dimitris Zervas 2023-06-03 18:13:37 +03:00
parent 141bf26048
commit 1f6e15e288
No known key found for this signature in database
GPG Key ID: 5C27D7C9D1901A30

View File

@ -84,20 +84,39 @@ mod tests {
.expect("Failed to build mybin"); .expect("Failed to build mybin");
assert_eq!(bin_status.code().unwrap(), 40, "Failed to replace foo()"); assert_eq!(bin_status.code().unwrap(), 40, "Failed to replace foo()");
// assert_eq!(40, unsafe { mylib_foo() }); }
// escargot::CargoBuild::new() #[test]
// .current_release() #[cfg(all(windows, feature = "frida"))]
// .current_target() fn test_frida_on_load() {
// .env("FRIDA_CODE", r#" let bin_exec = Command::new("cargo")
// const foo = Module.getExportByName(null, "mylib_foo"); .arg("build")
// Interceptor.replace(foo, new NativeCallback(function () { .arg("--manifest-path")
// console.log("replaced foo() called"); .arg("tests/mybin/Cargo.toml")
// return 20; .arg("--target-dir")
// }, "uint8", [])); .arg("target/test_frida_on_load");
// "#)
// .manifest_path("../../Cargo.toml") let lib_status = Command::new("cargo")
// .run() .arg("build")
// .unwrap(); .arg("--lib")
.arg("--target-dir")
.arg("target/test_frida_on_load")
.env("DLL_PROXY", "target/test_frida_on_load/debug/deps/mylib.dll")
.env("FRIDA_CODE", r#"
const foo = Module.getExportByName(null, "mylib_foo");
Interceptor.replace(foo, new NativeCallback(function () {
console.log("replaced foo() called");
return 40;
}, "uint8", []));
"#)
.status()
.expect("Failed to build dynamic library");
assert!(lib_status.success(), "Failed to build dynamic library");
fs::rename("target/test_frida_on_load/debug/deps/mylib.dll", "target/test_frida_on_load/debug/mylib-orig.dll").expect("Failed to rename original DLL");
fs::rename("target/test_frida_on_load/debug/frida_deepfreeze_rs.dll", "target/test_frida_on_load/debug/mylib.dll").expect("Failed to rename deepfreeze DLL");
let bin_status = bin_exec.status().expect("Failed to build mybin");
assert_eq!(bin_status.code().unwrap(), 40, "Failed to replace foo()");
} }
} }