ReverseEngineering – Telegram
ReverseEngineering
1.24K subscribers
40 photos
10 videos
55 files
666 links
Download Telegram
Calling Convention

توضیح:
قانونیه که میگه آرگومان‌ ها چطور به تابع داده میشن و نتیجه چطور برمیگرده

وقتی دارید مهندسی معکوس میکنی اگه Convention رو نشناسید اصلا نمیفهمید تابع چی از کجا ورودی میگیره و چی رو تغییر میده



سه Convention مهم برای مهندسی معکوس

فقط همین سه‌تا رو باید مسلط باشید بقیه‌ شون یا قدیمین یا کم‌ استفاده


System V AMD64 برای لینوکس و مک

شش آرگومان اول داخل رجیسترها:

RDI, RSI, RDX, RCX, R8, R9


بقیه آرگومان‌ها روی استک

return value → RAX



اگه کد لینوکسه نگاهتون اول باید بره سراغ RDI و RSI %90 آرگومان‌ ها اونجاست




Windows x64 Convention

چهار آرگومان اول در رجیستر ها:

RCX, RDX, R8, R9

بقیه آرگومان‌ها روی استک

return RAX



ویندوز فقط چهار تا رجیستر میده بهتون بقیش میره رو استک


Stack-based (cdecl / stdcall / fastcall قدیمی‌ تر

اینا تو x86 زیاد بودن تو x64 کمتر
ولی هنوز هستت

همه آرگومان‌ ها روی استک

return
در RAX یا EAX

Caller یا Callee
استک رو تمیز میکنه بسته به نوع



اگر دیدید قبل از call کلی push push push انجام شد تقریبا یعنی Convention قدیمیه



چطور توی دیس‌اسمبلی Convention رو تشخیص بدیم (Detect)


رجیستر هایی که قبل از call مقدار میگیرن

RDI/RSI
قطعا System V

RCX/RDX
تقریبا همیشه Windows x64


push
پشت هم احتمالا stack-based

prologue


بعضی compilerها قبل از شروع تابع shadow space میذارن فقط تو ویندوز

sub rsp, 0x20


یعنی:

اینجا ویندوزه Convention: Windows x64



Calling Convention

Explanation:
A rule that says how arguments are given to a function and how the result is returned

When you are reverse engineering, if you do not know the Convention, you will not understand at all what the function takes input from, where it comes from, and what it changes

Three important conventions for reverse engineering

You only need to master these three, the rest are either old or rarely used

System V AMD64 for Linux and Mac

The first six arguments are in the registers:

RDI, RSI, RDX, RCX, R8, R9


The rest of the arguments are on the stack

return value → RAX

If it is Linux code, your first look should be at RDI and RSI, 90% of the arguments are there

Windows x64 Convention

The first four arguments are in the registers:

RCX, RDX, R8, R9


The rest of the arguments are on the stack

return RAX

Windows only provides four registers The rest goes to the stack

Stack-based (older cdecl / stdcall / fastcall

This was more in x86, less in x64

But it's still there

All arguments on the stack

return
in RAX or EAX

Caller or Callee
Cleans the stack depending on the type

If you see a whole push push push done before the call, it almost means the Convention is old

How to detect the Convention in disassembly

Registers that get values ​​before the call

RDI/RSI
Definitely System V

RCX/RDX
Almost always Windows x64

push
Back to back probably stack-based

prologue


Some compilers put a shadow space before the function starts, only in Windows

sub rsp, 0x20


Meaning:

Here is Windows Convention: Windows x64

@reverseengine
1
ReverseEngineering
Calling Convention توضیح: قانونیه که میگه آرگومان‌ ها چطور به تابع داده میشن و نتیجه چطور برمیگرده وقتی دارید مهندسی معکوس میکنی اگه Convention رو نشناسید اصلا نمیفهمید تابع چی از کجا ورودی میگیره و چی رو تغییر میده سه Convention مهم برای مهندسی معکوس…
مثال تشخیص Calling Convention

دیس‌اسمبلی:

mov rdi, rax
mov rsi, rbx
call func


این خط داریم دو آرگومان به func میدیم چون RDI/RSI هست پس کد لینوکسه و
Convention = System V


Example of Calling Convention Detection

Disassembly:

mov rdi, rax
mov rsi, rbx
call func


In this line, we are giving two arguments to func because it is RDI/RSI, so it is Linux code and Convention = System V

@reverseengine
1
vmp-3.5.1.zip
20.2 MB
VMProtect Source Code (Leaked 07.12.2023)

intel.cc and processors.cc included


mirror:
https://github.com/jmpoep/vmprotect-3.5.1

@reverseengine
1
Dirty Vanity: A New Approach to Code Injection & EDR Bypass
Clone the shellcode

https://www.deepinstinct.com/blog/dirty-vanity-a-new-approach-to-code-injection-edr-bypass

@reverseengine
2