Self Scan

Bypassing APK Integrity Scans via Memory Mapping

When you run a native library (.so) inside an emulator, it often tries to scan its own process memory layout by reading /proc/self/maps. It’s sniffing around to see where it was loaded from and what the environment looks like.

Anti-cheat and anti-tamper protections usually fall into two categories here: The Dumb Checker: It just parses the text strings in maps looking for anything weird or out of place. If it smells an emulation path, it triggers The Smart Checker: It doesn't trust strings. It grabs the actual path to the APK from the memory map, tries to physically open that file, and scans its contents for integrity, signatures, or hooked modifications

If you are dealing with a smart checker that goes out of its way to read the APK file, your emulator will either crash or get flagged. However, there is a slick way to shut the library up with one simple step before initialization. The Fix: Pre-mapping a Virtual File

We can simulate the expected Android file structure and map the original (pretty much a clean) APK directly into the emulator’s memory space exactly where the library expects to find it.

How it looks like? This example i take out when i'm test my env.

# Mount file to memory
vf = emulator.vfs.mount_file(
    "/data/app/io.github.vvb2060.mahoshojo/base.apk", 
    "vfs/data/app/io.github.vvb2060.mahoshojo/base.apk", 
    uid=1000
)

apk_size = vf.get_size()
emulator.memory.map( # Map it for /proc/self/maps
    0,
    size=apk_size,
    prot=UC_PROT_READ,
    node=vf,
    offset=0
)

Why this works? When the native library wakes up, checks /proc/self/maps, extracts the APK path, and attempts to open it. The emulator seamlessly serves the virtual_file. The library thinks it’s running on a real device, reads the valid bytes, and chills out. Clean bypass before the .so even gets a chance to complain.