remove old backstage injection and remove all legacy code
This commit is contained in:
@@ -31,23 +31,19 @@ fn main() {
|
||||
}
|
||||
|
||||
fn generate_loader_entry() {
|
||||
let name = match std::env::var("BACKSTAGE_LOADER_EXPORT").ok().as_deref() {
|
||||
Some("ReflectiveLoader") => "ReflectiveLoader".to_string(),
|
||||
Some(value) => panic!("unsupported BACKSTAGE_LOADER_EXPORT value: {value}"),
|
||||
None => {
|
||||
let seed = std::env::var("BACKSTAGE_LOADER_SEED")
|
||||
.ok()
|
||||
.and_then(|value| value.parse::<u64>().ok())
|
||||
.unwrap_or_else(|| {
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos() as u64
|
||||
^ (std::process::id() as u64).wrapping_mul(0x9E37_79B9_7F4A_7C15)
|
||||
});
|
||||
format!("x{:06x}", seed & 0xFFFF_FF)
|
||||
}
|
||||
};
|
||||
// The loader export is always a per-build randomized `x<hex>` name. The
|
||||
// legacy fixed `ReflectiveLoader` export is no longer supported.
|
||||
let seed = std::env::var("BACKSTAGE_LOADER_SEED")
|
||||
.ok()
|
||||
.and_then(|value| value.parse::<u64>().ok())
|
||||
.unwrap_or_else(|| {
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos() as u64
|
||||
^ (std::process::id() as u64).wrapping_mul(0x9E37_79B9_7F4A_7C15)
|
||||
});
|
||||
let name = format!("x{:06x}", seed & 0xFFFF_FF);
|
||||
|
||||
let src = format!(
|
||||
"// Generated by build.rs — do not edit.\n\
|
||||
@@ -63,6 +59,5 @@ fn generate_loader_entry() {
|
||||
let out_dir = std::env::var("OUT_DIR").unwrap();
|
||||
std::fs::write(std::path::Path::new(&out_dir).join("loader_entry.rs"), src)
|
||||
.expect("failed to write loader_entry.rs");
|
||||
println!("cargo:rerun-if-env-changed=BACKSTAGE_LOADER_EXPORT");
|
||||
println!("cargo:rerun-if-env-changed=BACKSTAGE_LOADER_SEED");
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
//! Position-independent reflective loader, pure Rust (no C).
|
||||
//!
|
||||
//! This is a direct port of the Harmony Security `ReflectiveLoader` that was
|
||||
//! previously compiled from `reflective/ReflectiveLoader.c`. The injection
|
||||
//! stubs (`inject_reflective`) copy this DLL's raw bytes into a remote process
|
||||
//! and start a thread on our exported `ReflectiveLoader`. When that thread
|
||||
//! begins, the copied image is *not* relocated and its imports are *not*
|
||||
//! resolved, so this function must be position independent end to end:
|
||||
//! This is a direct port of the Harmony Security `ReflectiveLoader` approach.
|
||||
//! The injection stubs (`inject_reflective`) copy this DLL's raw bytes into a
|
||||
//! remote process and start a thread on our exported loader entry, whose name
|
||||
//! is randomized per build (see build.rs) rather than a fixed string. When
|
||||
//! that thread begins, the copied image is *not* relocated and its imports
|
||||
//! are *not* resolved, so this function must be position independent end to
|
||||
//! end:
|
||||
//!
|
||||
//! - It never reads relocatable data. All image structures are reached by
|
||||
//! computing addresses at runtime and reading with volatile scalar loads.
|
||||
|
||||
Reference in New Issue
Block a user