diff --git a/src/lazy_importer.rs b/src/lazy_importer.rs index c212388..677df07 100644 --- a/src/lazy_importer.rs +++ b/src/lazy_importer.rs @@ -128,22 +128,20 @@ pub unsafe fn import< // get the ldr data table entries let module_link: *const usize; core::arch::asm!( - "mov {x}, gs:[60h]", // TEB->PEB - "mov {x}, [{x} + 18h]", // PEB->LDR - "mov {x}, [{x} + 10h]", // LDR->InLoadOrderModuleList - x = out(reg) module_link, - ); + "mov {x}, gs:[60h]", // TEB->PEB + "mov {x}, [{x} + 18h]", // PEB->LDR + "lea {x}, [{x} + 10h]", // LDR->InLoadOrderModuleList + x = out(reg) module_link); // 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 end = (cursor as *const usize).add(offsets ^ 1).read(); 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 - if cursor == module_link as usize { break; } + while cursor != end { + cursor = (cursor as *const usize).add(offsets).read(); // extract the appropriate fields let name_len = ((cursor + 0x58) as *const u16).read(); @@ -164,7 +162,7 @@ pub unsafe fn import< match module.exports() { None => { debug_assert!(false, "Module has no exports"); - core::arch::asm!("int 3", options(noreturn)); + core::arch::asm!("", options(noreturn)); } Some(exports) => { for export in exports { @@ -175,7 +173,7 @@ pub unsafe fn import< } } debug_assert!(false, "failed to find export"); - core::arch::asm!("int 3", options(noreturn)) + core::arch::asm!("", options(noreturn)) } }