Lesson 17-Cross-Platform Reverse Engineering

This tutorial will comprehensively cover program reverse engineering techniques and methods for Windows, Linux, Android, and iOS platforms, providing a complete knowledge system from basic to advanced levels to help readers master the core skills of cross-platform reverse analysis.

Windows Program Reverse Engineering

Windows Program Basic Analysis

PE File Structure Parsing:

import pefile

def analyze_pe(file_path):
    pe = pefile.PE(file_path)
    
    print(f"PE File Header Information:")
    print(f"  Machine Type: {pe.FILE_HEADER.Machine}")
    print(f"  Number of Sections: {pe.FILE_HEADER.NumberOfSections}")
    print(f"  Timestamp: {pe.FILE_HEADER.TimeDateStamp}")
    
    print("\nImport Table Information:")
    for entry in pe.DIRECTORY_ENTRY_IMPORT:
        print(f"  DLL: {entry.dll}")
        for imp in entry.imports:
            if imp.name:
                print(f"    Function: {imp.name.decode('utf-8')}")
    
    pe.close()

# Usage Example
analyze_pe("example.exe")

Common Windows API Analysis:

  • CreateProcess – Process creation
  • LoadLibrary – Dynamic library loading
  • GetProcAddress – Function address acquisition
  • VirtualAlloc – Memory allocation
  • WriteProcessMemory – Memory writing
  • CreateRemoteThread – Remote thread creation

Windows Reverse Engineering Toolchain

  1. Static Analysis Tools:
    • IDA Pro (Windows-specific version)
    • Ghidra (supports Windows)
    • PEiD (packer detection)
    • CFF Explorer (PE editor)
  2. Dynamic Analysis Tools:
    • x64dbg (modern debugger)
    • OllyDbg (classic debugger)
    • Process Monitor (system monitoring)
    • API Monitor (API call monitoring)
  3. Auxiliary Tools:
    • Dependency Walker (dependency analysis)
    • strings (string extraction)
    • dumpbin (Microsoft toolchain)

Windows Reverse Engineering Key Techniques

  1. Packing and Unpacking:
    • Common packers: UPX, ASPack, VMProtect
    • Unpacking techniques: Memory dump, IAT repair, code restoration
  2. Anti-Debugging Technique Analysis:
    • IsDebuggerPresent – Direct detection
    • CheckRemoteDebuggerPresent – Remote detection
    • NtQueryInformationProcess – Advanced detection
    • Exception handling bypass
  3. API Hooking Analysis:
    • IAT Hook
    • Inline Hook
    • EAT Hook
    • Detection and bypass methods

Linux Program Reverse Engineering

Linux Binary File Analysis

ELF File Structure Parsing:

from elftools.elf.elffile import ELFFile

def analyze_elf(file_path):
    with open(file_path, 'rb') as f:
        elf = ELFFile(f)
        
        print(f"ELF File Header Information:")
        print(f"  Type: {elf.header['e_type']}")
        print(f"  Machine Type: {elf.header['e_machine']}")
        print(f"  Entry Point: {hex(elf.header['e_entry'])}")
        
        print("\nProgram Header Information:")
        for segment in elf.iter_segments():
            print(f"  Type: {segment['p_type']}")
            print(f"  Offset: {hex(segment['p_offset'])}")
            print(f"  Virtual Address: {hex(segment['p_vaddr'])}")
            print(f"  File Size: {segment['p_filesz']}")
            print(f"  Memory Size: {segment['p_memsz']}")
        
        print("\nSection Information:")
        for section in elf.iter_sections():
            print(f"  Name: {section.name}")
            print(f"  Type: {section['sh_type']}")
            print(f"  Address: {hex(section['sh_addr'])}")
            print(f"  Size: {section['sh_size']}")

# Usage Example
analyze_elf("example")

Common Linux System Call Analysis:

  • execve – Program execution
  • fork – Process creation
  • open – File opening
  • read/write – File read/write
  • socket – Network communication

Linux Reverse Engineering Toolchain

  1. Static Analysis Tools:
    • IDA Pro (Linux support)
    • Ghidra (supports Linux)
    • Radare2 (command-line reverse engineering framework)
    • Binary Ninja (cross-platform)
  2. Dynamic Analysis Tools:
    • GDB (GNU debugger)
    • strace (system call tracing)
    • ltrace (library call tracing)
    • Valgrind (memory analysis)
  3. Auxiliary Tools:
    • strings (string extraction)
    • objdump (disassembly)
    • readelf (ELF analysis)
    • nm (symbol table viewing)

Linux Reverse Engineering Key Techniques

  1. Dynamic Link Library Analysis:
    • .so file analysis
    • Symbol resolution process
    • Dynamic linking mechanism
  2. Anti-Debugging Technique Analysis:
    • ptrace call detection
    • fork trap detection
    • Exception handling bypass
  3. Kernel Module Analysis:
    • Kernel module loading mechanism
    • Kernel symbol table analysis
    • Kernel hook detection

Android Application Reverse Engineering

Android Application Structure Analysis

APK File Structure Parsing:

import zipfile

def analyze_apk(file_path):
    with zipfile.ZipFile(file_path, 'r') as apk:
        print("APK File Contents:")
        for name in apk.namelist():
            print(f"  {name}")
        
        # Extract AndroidManifest.xml
        with apk.open('AndroidManifest.xml') as f:
            manifest = f.read()
            print("\nAndroidManifest.xml Content (first 100 bytes):")
            print(manifest[:100].decode('utf-8', errors='ignore'))

# Usage Example
analyze_apk("example.apk")

Common Android Component Analysis:

  • Activity – User interface component
  • Service – Background service
  • BroadcastReceiver – Broadcast receiver
  • ContentProvider – Content provider

Android Reverse Engineering Toolchain

  1. Static Analysis Tools:
    • JADX (APK decompiler)
    • Apktool (APK decompilation and repackaging)
    • Bytecode Viewer (multi-engine analysis)
    • JADX Online (online decompilation)
  2. Dynamic Analysis Tools:
    • Frida (dynamic instrumentation framework)
    • Xposed (modular framework)
    • Objection (Frida extension)
    • MobSF (mobile security framework)
  3. Auxiliary Tools:
    • strings (string extraction)
    • dex2jar (DEX to JAR conversion)
    • jadx (JAR decompilation)
    • jadx-gui (graphical interface)

Android Reverse Engineering Key Techniques

  1. DEX Decompilation and Recompilation:
    • DEX to Java conversion
    • Code obfuscation analysis
    • Resource file extraction
  2. Native Code Analysis:
    • JNI call analysis
    • Native library decompilation
    • Dynamic link library analysis
  3. Android Security Mechanism Analysis:
    • Android permission system
    • SELinux policy analysis
    • Encryption and signature verification

iOS Application Reverse Engineering

iOS Application Structure Analysis

IPA File Structure Parsing:

import zipfile

def analyze_ipa(file_path):
    with zipfile.ZipFile(file_path, 'r') as ipa:
        print("IPA File Contents:")
        for name in ipa.namelist():
            print(f"  {name}")
        
        # Extract Info.plist
        with ipa.open('Payload/*.app/Info.plist') as f:
            plist = f.read()
            print("\nInfo.plist Content (first 100 bytes):")
            print(plist[:100].decode('utf-8', errors='ignore'))

# Usage Example
analyze_ipa("example.ipa")

Common iOS Component Analysis:

  • UIViewController – View controller
  • UIView – View
  • NSCoder – Encoding/decoding
  • NSUserDefaults – User preferences

iOS Reverse Engineering Toolchain

  1. Static Analysis Tools:
    • Hopper Disassembler (supports iOS)
    • IDA Pro (supports iOS)
    • Ghidra (supports iOS)
    • class-dump (header file extraction)
  2. Dynamic Analysis Tools:
    • Frida (supports iOS)
    • Cycript (Objective-C runtime interaction)
    • lldb (LLVM debugger)
    • otool (Mach-O analysis)
  3. Auxiliary Tools:
    • strings (string extraction)
    • otool (Mach-O analysis)
    • lipo (universal binary tool)
    • codesign (signature tool)

iOS Reverse Engineering Key Techniques

  1. Mach-O File Analysis:
    • Mach-O file structure
    • Dynamic library loading mechanism
    • Symbol table analysis
  2. Objective-C Runtime Analysis:
    • Method call tracing
    • Class structure analysis
    • Message sending mechanism
  3. iOS Security Mechanism Analysis:
    • Code signing verification
    • Sandbox mechanism
    • App Transport Security (ATS)
    • Keychain access control

Cross-Platform Reverse Engineering Advanced Techniques

Cross-Platform Reverse Engineering General Techniques

  1. Deobfuscation Techniques:
    • Control flow flattening analysis
    • String encryption analysis
    • Virtual machine protection analysis
  2. Vulnerability Mining Techniques:
    • Memory corruption vulnerabilities
    • Logic vulnerabilities
    • Privilege escalation vulnerabilities
  3. Automated Reverse Engineering Techniques:
    • Fuzzing frameworks
    • Symbolic execution tools
    • Binary difference analysis

Cross-Platform Reverse Engineering Challenges and Solutions

  1. Different Architecture Handling:
    • x86/x64/ARM architecture differences
    • Instruction set conversion and analysis
  2. Different Operating System Differences:
    • Windows/Linux/Android/iOS system call differences
    • Memory management mechanism differences
  3. Different Application Type Differences:
    • Desktop vs. mobile application differences
    • Native vs. Web application differences

Learning Path Suggestions

  1. Basic Stage:
    • Learn assembly language (x86/x64/ARM)
    • Master PE/ELF/Mach-O file formats
    • Learn basic reverse engineering tool usage
  2. Intermediate Stage:
    • Deeply study Windows/Linux/Android/iOS platform characteristics
    • Research common reverse engineering techniques (anti-debugging, API hooking, etc.)
    • Practice vulnerability mining and exploitation
  3. Advanced Stage:
    • Research advanced reverse engineering techniques (virtual machine protection, control flow flattening, etc.)
    • Develop automated reverse engineering tools
    • Research cross-platform reverse engineering techniques

Through systematic learning and practice, you will master the core techniques of cross-platform program reverse engineering, contributing to software security research and reverse engineering. Remember, reverse engineering should only be used for legitimate security research and defense purposes.

Share your love