Devirtualization مجازی سازی زدایی
بعضی محافظ ها مثل VMProtect کد اصلی برنامه رو به بایت کد تبدیل میکنن و یک ماشین مجازی داخل برنامه قرار میدن تا اون بایت کد رو اجرا کنه مشکل از جایی شروع میشه که دیگه با یک تابع معمولی طرف نیستیم به جای چند دستور اسمبلی ساده با صدها یا هزار دستور مربوط به ماشین مجازی طرف میشیم
اینجاست که Devirtualization به دردمون میخوره
Devirtualization
یعنی تلاش برای تبدیل منطق مخفی شده داخل ماشین مجازی به شکلی که دوباره قابل فهم باشه
هدف Devirtualization این نیست که محافظ رو حذف کنیم
هدف اینه که بفهمیم برنامه واقعا چه کاری انجام میده
فرض کنید کد اصلی این بوده:
C
if(password == "1234") { success(); }
بعد از Virtualization ممکنه این منطق به صد ها دستور بایت کد تبدیل بشه
در ظاهر دیگر هیچ strcmp یا if مشخصی وجود نداره فقط یک Dispatcher و تعداد زیادی Handler دیده میشه
کاری که تحلیلگر انجام میده اینه که به تدریج معنی هر Opcode رو کشف کنه
مثلا متوجه میشه:
Opcode 0x01 دادهای رو داخل رجیستر مجازی اپلود میکنه
Opcode 0x02 دو مقدار رو مقایسه میکنه
Opcode 0x03 یک پرش شرطی انجام میده
بعد از شناسایی Opcode ها میتونیم رفتار ماشین مجازی رو روی کاغذ بازسازی کنیم
به این فرایند ساختن نقشه Opcode ها
معمولا فرایند تحلیل به این شکل پیش میره:
اول Dispatcher پیدا میشه
بعد Handler های مختلف شناسایی میشن
بعد Opcode ها دسته بندی میشن
در نهایت منطق اصلی برنامه بازسازی میشه
یکی از اشتباهات رایج افراد تازهکار اینه که مستقیم سراغ Handler ها میرن
در حالی که اول باید ساختار کلی ماشین مجازی رو بفهمید
اگر Dispatcher رو نفهمید Handler ها تقریبا بی معنی هستن
یک قانون مهم در تحلیل ماشین های مجازی:
اول جریان اجرای بایت کد رو درک کنید
بعد سراغ معنی دستور ها برید
تمرین
یک ماشین مجازی ساده طراحی کنید که فقط سه تا Opcode داشته باشه:
LOAD
ADD
PRINT
بعد سعی کنید فقط با نگاه کردن به اجرای برنامه بفهمید هر Opcode چه کاری انجام میده
Devirtualization
Some protectors, such as VMProtect, convert the original program code into bytecode and place a virtual machine inside the program to execute that bytecode. The problem starts when we are no longer dealing with a normal function, but instead of a few simple assembly instructions, we are dealing with hundreds or thousands of instructions related to the virtual machine.
This is where Devirtualization comes in.
Devirtualization
is an attempt to convert the hidden logic inside the virtual machine into a form that is understandable again.
The goal of Devirtualization is not to remove the protector. The goal is to understand what the program is actually doing.
Suppose the original code was:
C
if(password == "1234") { success(); }
After Virtualization, this logic may be converted into hundreds of bytecode instructions. On the surface, there is no specific strcmp or if, only a Dispatcher and a large number of Handlers. What the analyzer does is to gradually discover the meaning of each Opcode.
For example, it finds:
Opcode 0x01 uploads data into a virtual register
Opcode 0x02 compares two values
Opcode 0x03 performs a conditional jump
After identifying the Opcodes, we can reconstruct the behavior of the virtual machine on paper. This process is called creating an Opcode map.
Usually, the analysis process goes like this:
First, the Dispatcher is found.
Then the different Handlers are identified.
Then the Opcodes are categorized.
Finally, the main logic of the program is reconstructed.
One of the common mistakes of beginners is to go straight to the Handlers.
While you should first understand the overall structure of the virtual machine.
If you don't understand the Dispatcher, the Handler are almost meaningless
An important rule in analyzing virtual machines:
First understand the flow of bytecode execution
Then move on to the meaning of the instructions
Exercise
Design a simple virtual machine that has only three Opcodes:
LOAD
ADD
PRINT
Then try to figure out what each Opcode does just by looking at the program execution
@reverseengine