1 730
🧠 Devirtualization (شکستن Virtual Machine Protection)
وقتی یه نرمافزار با VMProtect / Themida / Custom VM محافظت شده باشه مهندسی معکوس میره سمت Devirtualization
اینجاست که تحلیلگر باید VM رو مهندسی معکوس کنه
1️⃣ شناسایی VM Entry Points
اولین قدم اینه که بفهمیم برنامه از کجا وارد ماشین مجازی میشه
📌 معمولاً یک سری Prologue ثابت وجود داره:
Push کردن یه سری مقادیر روی استک
پرش به یک Interpreter مرکزی
2️⃣ پیدا کردن VM Handlers
هر دستور VM توسط یه Handler اجرا میشه
این Handlerها مثل opcodeهای CPU واقعی هستن
مثال:
VM_OP_01 → ADD VM_OP_02 → MOV VM_OP_03 → JMPاینجا باید همه Handlerها شناسایی بشن معمولا صدها تا هستن 3️⃣ ساخت Mapping بین VM و CPU واقعی وقتی Handlerها رو شناسایی کردی باید یک جدول معادلسازی درست کنی مثلا: VM Opcode Real Instruction توضیح
0x12 MOV EAX, EBX کپی مقدار رجیستر 0x34 ADD ECX, 5 جمع ثابت با رجیستر 0x56 JMP addr پرش به آدرس4️⃣ ابزارها و روشها برای Devirtualization Dynamic Tracing → اجرای VM و لاگ گرفتن از دستورها Static Analysis → پیدا کردن Handlerها در دیساسمبلر Plugins → مثل [IDA Hex-Rays Devirtualizer Plugins] Custom Tools → نوشتن Decompiler اختصاصی برای بازسازی کد اصلی 5️⃣ چالشها Obfuscation روی VM Handlerها استفاده از چند VM مختلف در یک برنامه درهمریختگی عمدی Junk Code, Fake Opcodes Self-Modifying Code داخل خود VM 🧠 Devirtualization (Breaking VM-Based Protections) When a binary is protected by VMProtect / Themida / custom VM, reverse engineering becomes about understanding and emulating a fake CPU inside the program 1️⃣ Identify VM Entry Points The first step is to locate where the real code switches into virtualized code execution 🔍 Typical signs: A prologue pattern: pushing multiple values/contexts on the stack A jump or call into a central interpreter function Execution stops making sense in x86 and looks like dispatcher loops 2️⃣ Locate VM Handlers Each VM opcode is processed by a handler just like x86 instructions are decoded by the CPU Example mapping idea:
VM_OP_01 → ADD VM_OP_02 → MOV VM_OP_03 → JMP👉 In practice, there may be hundreds of handlers, sometimes with junk code or mixed execution 3️⃣ Build an Opcode → Real Instruction Mapping Once you identify handlers you need to build a translation table between VM opcodes and real CPU instructions 📖 Example mapping table: VM Opcode Real Instruction Meaning
0x12 MOV EAX, EBX copy register 0x34 ADD ECX, 5 add immediate constant 0x56 JMP addr unconditional jumpThis mapping becomes the foundation of your decompiler/devirtualizer 4️⃣ Methods & Tools for Devirtualization Dynamic Tracing → Run the VM, log executed opcodes + their effects Static Analysis → Identify handler functions inside the disassembler Plugins → Tools like IDA/Ghidra devirtualizer plugins research versions exist Custom Tools → Write your own script/decompiler to rebuild the original logic from VM bytecode 5️⃣ Key Challenges Obfuscated Handlers → Each handler may have junk code, opaque predicates Multiple VMs → Some binaries use different VM engines for different functions Fake Opcodes → Inserted to confuse analysis no-ops, misleading behavior Self-Modifying Code → The VM engine may rewrite itself in memory at runtime 🔹 Realistic Workflow for an Analyst 1 Find VM entry → identify the dispatcher loop 2 Extract VM bytecode stream 3 Reverse engineer handler functions → document them 4 Build mapping table (opcode → real instruction) 5 Automate devirtualization with a script/decompiler 6 Reconstruct original program logic ⚡ In practice: Analysts often combine dynamic tracing + static reversing Full automation is rare—usually a mix of scripting and manual work VMProtect / Themida add anti-debugging and obfuscation layers on top making this even harder
04 sep 2025, 17:14

