Home > Net >  Is there a big help on CRT initialization failure
Is there a big help on CRT initialization failure

Time:09-24

CRT (c + + runtime) initialization has a problem, I hand my DLL dynamic database (driver + white list) is mapped to another DLL in memory, I will be a IAT hook to the "of" the CloseHandle function, so the game will call my mainCRTStartup (c + + initialization function, this is the program's entry point, then I will call my main () function), if you disable the CRT, the entry point will jump straight to the main () function, compiled, when injection is good, but once the CRT initialization target process will collapse (see below), here I parse the DLL import, hooks, no problem, but the CRT initialization, collapse directly, and occasionally even cannot execute
I need to hook code: (all run in the kernel)
` ` ` c
Constexpr would s_RustClientModule []=L "uplay_r164. DLL";
UNICODE_STRING u_RustClientModule={0};
Funcs: : RtlInitUnicodeString (& amp; U_RustClientModule s_RustClientModule);
Const auto rust_client_exe=game. Get_module (& amp; U_RustClientModule nullptr);

if ( ! Rust_client_exe)
{
Game. Detach ();
Return STATUS_UNSUCCESSFUL;
}

Funcs: : DbgPrint (" rust_client_exe: % p \ n ", rust_client_exe);
Utils: : sleep (2000);

Auto import_address=utils: : get_imported_function (rust_client_exe, "CloseHandle");

if ( ! Import_address)
{
Game. Detach ();
Return STATUS_UNSUCCESSFUL;
}

Funcs: : DbgPrint (" import_address: % p \ n ", import_address);
Utils: : sleep (2000);

Auto import_ptr_protect=reinterpret_cast & lt; PVOID & gt; (import_address);

Auto import_ptr=reinterpret_cast & lt; Uintptr_t * & gt; (import_address);

Const auto original_import_ptr=* import_ptr;

Funcs: : DbgPrint (" import_ptr: % p \ n ", import_ptr);
Funcs: : DbgPrint (" import_ptr deref: % p \ n ", * import_ptr);
Funcs: : DbgPrint (" import_ptr address of: % p \ n ", & amp; Import_ptr);
Utils: : sleep (2000);

SIZE_T size=sizeof (uintptr_t);
ULONG old_access;
ULONG old_access2;

if ( ! NT_SUCCESS (funcs: : ZwProtectVirtualMemory (NtCurrentProcess (), & amp; Import_ptr_protect, & amp; The size, PAGE_READWRITE, & amp; Old_access)))
{
Funcs: : DbgPrint (" failed protect 1 ");
Utils: : sleep (2000);
Game. Detach ();
Return STATUS_UNSUCCESSFUL;
}

RtlCopyMemory (import_ptr, & amp; Entry_point, sizeof (entry_point));

Utils: : sleep (50);

if ( ! NT_SUCCESS (funcs: : ZwProtectVirtualMemory (NtCurrentProcess (), & amp; Import_ptr_protect, & amp; The size, old_access, & amp; Old_access2)))
{
Funcs: : DbgPrint (" failed protect 2 ");
Utils: : sleep (2000);
Game. Detach ();
Return STATUS_UNSUCCESSFUL;
}

Funcs: : DbgPrint (" finished hook ");
Utils: : sleep (2000); ` ` `
What is wrong?
  • Related