Integrity Checking


uint FUN_00401863(void)

{
  HMODULE pHVar1;
  int *piVar2;
 
  pHVar1 = GetModuleHandleW((LPCWSTR)0x0);
  if ((((pHVar1 != (HMODULE)0x0) && ((short)pHVar1->unused == 0x5a4d)) &&
      (piVar2 = (int *)((int)&pHVar1->unused + pHVar1[0xf].unused), *piVar2 == 0x4550)) &&
     ((pHVar1 = (HMODULE)0x10b, (short)piVar2[6] == 0x10b && (0xe < (uint)piVar2[0x1d])))) {
    return CONCAT31(1,piVar2[0x3a] != 0);
  }
  return (uint)pHVar1 & 0xffffff00;
}



You're looking at another low-level helper function — FUN_00401863() — and this one's a stealthy check on the PE header of the current module (i.e. the executable itself). Let's unpack it.


🔍 What Does FUN_00401863() Do?

It appears to:

  • Access the current process module (your EXE) via GetModuleHandleW(NULL)

  • Verify it's a valid PE (Portable Executable) file

  • Check if a certain field in the PE Optional Header is non-zero

  • Return a uint indicating the result


🧠 Let's Break It Down

1. Get Handle to Current Module

pHVar1 = GetModuleHandleW(NULL);  
  • Returns a handle to the base address of the current executable image.

  • Essentially: pHVar1 == (HMODULE) base address of EXE


2. Verify MZ Header

(short)pHVar1->unused == 0x5a4d  
  • 0x5A4D = 'MZ' signature (DOS stub header at start of PE file)


3. Locate PE Header

piVar2 = (int *)((int)&pHVar1->unused + pHVar1[0xf].unused);  *piVar2 == 0x4550  
  • Accesses the offset stored in the DOS header (e_lfanew)

  • Verifies the PE signature: 0x00004550 = 'PE\0\0'


4. Validate PE32 (Not PE32+)

(short)piVar2[6] == 0x10b  
  • Optional header magic value:

    • 0x10B → PE32

    • 0x20B → PE32+


5. Check if Field Exists and Is Non-Zero

(0xe < (uint)piVar2[0x1d]) && piVar2[0x3a] != 0  

This is checking:

  • If the Optional Header is large enough (SizeOfOptionalHeader > 0xe)

  • Then accessing and evaluating piVar2[0x3a] → unknown field in context

Note:

  • piVar2[0x3a] = field at offset 0xE8 from PE header (assuming piVar2 points to PE header)

This could be:

  • A custom field inserted by a packer, protector, or malware stub

  • Or maybe it's reading LoaderFlags, Win32VersionValue, or another optional header value


✅ Return Value

return CONCAT31(1, piVar2[0x3a] != 0);  
  • If the field is non-zero, returns something like 0x00000001

  • Otherwise returns 0x00000000

If any checks fail, it falls through to:

return (uint)pHVar1 & 0xffffff00;  
  • Returns a high-byte-only value (e.g., 0x100, 0x200), likely representing failure


💡 So What's the Purpose?

This function is:

  • Validating its own PE structure

  • Checking a custom or rare PE header field

  • Returning a status flag


🛠️ Use Cases

Possible Intent Description
Legit integrity check Making sure the executable hasn't been tampered with
🧪 Packer stub Checking if it's been unpacked or altered
🧼 Clean start check Verifies certain state before cleanup/init
🔐 Malware evasion Some malware checks for field changes or injectors

🔎 Want to Dig Deeper?

If you can provide a memory dump, or tell me what value is in piVar2[0x3a], I can help you identify exactly what field this is and why it matters.

Also, if you're analyzing a suspicious binary or unpacking something, this kind of function is a classic anti-analysis trick.


Comments

Popular posts from this blog

Avoiding detection when injecting a DLL into a game process

Some global variable set, mystery function

FULL REFLECTIVE INJECTION PACK