Attempt to track allocations that doesn't actually work cuz I can't get it loaded

This commit is contained in:
IQuant 2025-11-17 22:14:31 +03:00
parent 70af6cfdef
commit 487a334e5d
6 changed files with 65 additions and 0 deletions

View file

@ -19,5 +19,6 @@
"rust-analyzer.linkedProjects": [
"ewext/Cargo.toml",
"noita-proxy/Cargo.toml",
"extra/malloc_probe/Cargo.toml",
]
}

View file

@ -0,0 +1,2 @@
[build]
target = "i686-pc-windows-gnu"

7
extra/malloc_probe/Cargo.lock generated Normal file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "malloc_probe"
version = "0.1.0"

View file

@ -0,0 +1,20 @@
[package]
name = "malloc_probe"
version = "0.1.0"
edition = "2024"
[lib]
crate-type = ["cdylib"]
[profile.dev]
panic = "abort"
[profile.release]
lto = true
panic = "abort"
split-debuginfo = "packed"
incremental=true
codegen-units=1
opt-level = 3
[dependencies]

View file

@ -0,0 +1,3 @@
fn main() {
println!("cargo:rustc-link-arg=-Wl,-eDllMain");
}

View file

@ -0,0 +1,32 @@
use std::{
alloc::{self, Layout},
ffi::c_void,
};
unsafe extern "cdecl" fn operator_new(size: usize) -> *mut c_void {
let buffer =
unsafe { alloc::alloc(Layout::from_size_align_unchecked(size + 4, 4)).cast::<usize>() };
unsafe { buffer.write(size) };
unsafe { buffer.offset(1).cast() }
}
unsafe extern "cdecl" fn operator_delete(pointer: *mut c_void) {
let ptr = unsafe { pointer.cast::<usize>().offset(-1) };
let size = unsafe { ptr.read() };
unsafe {
alloc::dealloc(
pointer.cast(),
Layout::from_size_align_unchecked(size + 4, 4),
);
}
}
#[unsafe(no_mangle)]
unsafe extern "C" fn dummy() {}
#[unsafe(no_mangle)]
pub extern "stdcall" fn DllMain(_: *const u8, _: u32, _: *const u8) -> u32 {
// unsafe { ((0x00f07500) as *mut *const usize).write(operator_new as *const usize) };
// unsafe { ((0x00f07504) as *mut *const usize).write(operator_delete as *const usize) };
1
}