fix imports that randomly got the backwards iterator from crashing
This commit is contained in:
@@ -130,20 +130,18 @@ pub unsafe fn import<
|
|||||||
core::arch::asm!(
|
core::arch::asm!(
|
||||||
"mov {x}, gs:[60h]", // TEB->PEB
|
"mov {x}, gs:[60h]", // TEB->PEB
|
||||||
"mov {x}, [{x} + 18h]", // PEB->LDR
|
"mov {x}, [{x} + 18h]", // PEB->LDR
|
||||||
"mov {x}, [{x} + 10h]", // LDR->InLoadOrderModuleList
|
"lea {x}, [{x} + 10h]", // LDR->InLoadOrderModuleList
|
||||||
x = out(reg) module_link,
|
x = out(reg) module_link);
|
||||||
);
|
|
||||||
|
|
||||||
// 0x0 = next, 0x8 = prev, use the xor seed to flip the direction of the iterator
|
// 0x0 = next, 0x8 = prev, use the xor seed to flip the direction of the iterator
|
||||||
let offsets = 1; // const { XorSeed & 1 };
|
let offsets = const { XorSeed & 1 } as usize;
|
||||||
|
|
||||||
let mut cursor = module_link as usize;
|
let mut cursor = module_link as usize;
|
||||||
|
let end = (cursor as *const usize).add(offsets ^ 1).read();
|
||||||
let mut module: usize = 0usize;
|
let mut module: usize = 0usize;
|
||||||
loop {
|
|
||||||
cursor = (cursor as *const usize).add(offsets).read();
|
|
||||||
|
|
||||||
// if we have gone all the way around and ended up at our module again, abort
|
while cursor != end {
|
||||||
if cursor == module_link as usize { break; }
|
cursor = (cursor as *const usize).add(offsets).read();
|
||||||
|
|
||||||
// extract the appropriate fields
|
// extract the appropriate fields
|
||||||
let name_len = ((cursor + 0x58) as *const u16).read();
|
let name_len = ((cursor + 0x58) as *const u16).read();
|
||||||
@@ -164,7 +162,7 @@ pub unsafe fn import<
|
|||||||
match module.exports() {
|
match module.exports() {
|
||||||
None => {
|
None => {
|
||||||
debug_assert!(false, "Module has no exports");
|
debug_assert!(false, "Module has no exports");
|
||||||
core::arch::asm!("int 3", options(noreturn));
|
core::arch::asm!("", options(noreturn));
|
||||||
}
|
}
|
||||||
Some(exports) => {
|
Some(exports) => {
|
||||||
for export in exports {
|
for export in exports {
|
||||||
@@ -175,7 +173,7 @@ pub unsafe fn import<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug_assert!(false, "failed to find export");
|
debug_assert!(false, "failed to find export");
|
||||||
core::arch::asm!("int 3", options(noreturn))
|
core::arch::asm!("", options(noreturn))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user