Support only for windows DLLs for DLL proxying - unix does not seem to support such functionality
This commit is contained in:
parent
5894967a27
commit
5902d9bf40
43
build.rs
43
build.rs
@ -3,7 +3,7 @@ use std::env;
|
|||||||
fn main() {
|
fn main() {
|
||||||
println!("cargo:rerun-if-env-changed=FRIDA_CODE");
|
println!("cargo:rerun-if-env-changed=FRIDA_CODE");
|
||||||
println!("cargo:rerun-if-env-changed=FRIDA_CODE_FILE");
|
println!("cargo:rerun-if-env-changed=FRIDA_CODE_FILE");
|
||||||
println!("cargo:rerun-if-env-changed=LIB_PROXY");
|
println!("cargo:rerun-if-env-changed=DLL_PROXY");
|
||||||
|
|
||||||
if let Ok(code_file) = env::var("FRIDA_CODE_FILE") {
|
if let Ok(code_file) = env::var("FRIDA_CODE_FILE") {
|
||||||
env::set_var("FRIDA_CODE", &std::fs::read_to_string(&code_file).unwrap());
|
env::set_var("FRIDA_CODE", &std::fs::read_to_string(&code_file).unwrap());
|
||||||
@ -15,46 +15,33 @@ fn main() {
|
|||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(lib_path) = env::var("LIB_PROXY") {
|
if let Ok(lib_path) = env::var("DLL_PROXY") {
|
||||||
use goblin::Object::{self, Elf, PE, Mach, Archive, Unknown};
|
use goblin::Object::{self, PE};
|
||||||
// use goblin::mach::{MultiArch, MachO};
|
|
||||||
|
|
||||||
let path = std::path::Path::new(&lib_path);
|
let path = std::path::Path::new(&lib_path);
|
||||||
let lib_name = path.file_name().unwrap().to_str().unwrap();
|
let lib_filename = path.file_name().unwrap().to_str().unwrap();
|
||||||
|
|
||||||
let lib_bytes = std::fs::read(path).expect(format!("Failed to open given library file {}", &lib_name).as_str());
|
let lib_bytes = std::fs::read(path).expect(format!("Failed to open given library file {}", &lib_filename).as_str());
|
||||||
let object = Object::parse(&lib_bytes).expect(format!("Failed to parse given libary file {}", &lib_name).as_str());
|
let object = Object::parse(&lib_bytes).expect(format!("Failed to parse given libary file {}", &lib_filename).as_str());
|
||||||
|
|
||||||
let exports: Vec<&str> = match object {
|
let (exports, lib_name): (Vec<&str>, String) = match object {
|
||||||
Elf(o) =>
|
|
||||||
o.dynsyms
|
|
||||||
.iter()
|
|
||||||
.filter(|e| !e.is_import())
|
|
||||||
.map(|e| o.dynstrtab.get_at(e.st_name).unwrap())
|
|
||||||
.collect(),
|
|
||||||
PE(o) =>
|
PE(o) =>
|
||||||
o.exports
|
(o.exports
|
||||||
.iter()
|
.iter()
|
||||||
.map(|e| e.name.unwrap().clone())
|
.map(|e| e.name.unwrap().clone())
|
||||||
.collect(),
|
.collect(),
|
||||||
Mach(_o) => {
|
o.name.unwrap().replace(".dll", "")),
|
||||||
println!("Mach binaries are not supported yet");
|
_ => {
|
||||||
std::process::exit(1);
|
println!("Only DLL files are supported");
|
||||||
},
|
|
||||||
Archive(_o) => {
|
|
||||||
println!("Archive files are not supported");
|
|
||||||
std::process::exit(1);
|
|
||||||
},
|
|
||||||
Unknown(_o) => {
|
|
||||||
println!("The file you provided is of unknown format");
|
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
for e in exports.iter() {
|
for e in exports.iter() {
|
||||||
println!("cargo:warning=Exported function: {}", e);
|
println!("cargo:warning=Exported function: {}", e);
|
||||||
// println!("cargo:rustc-link-lib=dylib=orig.{}", lib_name);
|
// println!("cargo:rustc-link-lib=dylib={}-orig", lib_name);
|
||||||
println!("cargo:rustc-link-arg=/export:{}=orig.{}.{}", e, lib_name, e);
|
println!("cargo:rustc-link-arg=/export:{}={}-orig.{}", e, lib_name, e);
|
||||||
}
|
}
|
||||||
|
println!("cargo:warning=Expected library name: {}-orig.dll", lib_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user