反彙編代碼中的數組聲明 (Declaration of an array in disassembled code)


問題描述

反彙編代碼中的數組聲明 (Declaration of an array in disassembled code)

我嘗試拆卸 ropasaurusrex。這是 CTF 的問題。您可以從以下鏈接下載可執行文件。我使用 Hopper 進行拆卸。這裡

enter image description here

上圖是本程序的主程序

請看上圖紅線。

p>

數組的聲明好像在這裡。

lea eax, dword [ss: ebp+var_88] =====> char buffer[128];

為什麼?128bytes看不懂?


參考解法

方法 1:

In general, there is no direct correspondence between individual assembly instructions and C constructs. A single instruction may be just a single "brick" from a larger construct. If optimisations are turned on, tracing things this way becomes even harder.

Considering the first routine, here is an instruction‑by‑instruction walkthrough:

  • push ebp saves the old "stack base pointer" on the stack, so that it can restored after leaving the function and the caller can be confident that it hasn't changed;

  • mov ebp, esp loads the value of the "base pointer" with the current value of the "stack pointer". Any further references to variables within the stack frame of that function can be made relative to this newly assigned base pointer;

  • sub esp, 0x98 subtracts the value 152 from the stack pointer. This effectively "allocates" space on the stack. Any variables with automatic storage can be now accommodated between the addresses pointed to by ebp and esp. This probably includes your buffer array.

  • mov dword[ss:esp + 8], 0x100 puts the value 256 at the address pointed to by esp + 8. That might correspond to an assignment to an automatic variable/array.

  • lea eax, dword[ss:ebp + var_88] computes an address that is the result of the base pointer plus some constant offset, and stores it into eax. This probably corresponds to a pointer to the beginning of the automatic array.

  • eax is then moved to the stack as an argument to the following call to j_read. 0 is also passed as the first argument. The function is then called, the leave instruction restores the old base pointer and the control is returned to the caller via the ret instruction.

(by stackosieteBlagovest Buyukliev)

參考文件

  1. Declaration of an array in disassembled code (CC BY‑SA 2.5/3.0/4.0)

#32-bit #assembly #reverse-engineering #C #x86






相關問題

內聯彙編 - cdecl 和準備堆棧 (Inline assembly - cdecl and preparing the stack)

來自 32 位用戶代碼的 64 位系統中的 ioctl 命令錯誤 (ioctl command wrong in 64 bit system from 32 bit user code)

Baiklah, PR: Bagaimana mungkin X[i] diinterpretasikan sama dengan i[X] di C? (Alright, homework: How can X[i] possibly be interpretted the same as i[X] in C?)

x32 ABI - гэта інструмент, як ім карыстацца (x32 ABI is this a tool ,how to use this)

Biên dịch Visual Studio 2012 32bit trên hệ thống 64bit (Visual Studio 2012 32bit compilation on 64bit system)

如何讓 Netbeans 7.2 使用 32 位 JVM (How get Netbeans 7.2 to use 32 Bit JVM)

反彙編代碼中的數組聲明 (Declaration of an array in disassembled code)

用C編寫跨平台應用程序 (Writing cross-platform apps in C)

為什麼 BinaryReader.ReadUInt32() 反轉位模式? (Why does BinaryReader.ReadUInt32() reverse the bit pattern?)

32 位 RHEL 機器上的內存使用 (Memory use on 32 bit RHEL machine)

將 32 位應用程序安裝到 C:\Program Files\ 而不是 C:\Program Files(x86)\ 會有什麼負面影響? (What would be the negative effects of installing a 32bit app into the C:\Program Files\ instead of the C:\Program Files(x86)\?)

Arduino 將浮點數轉換為十六進制 IEEE754 單精度 32 位 (Arduino convert float to hex IEEE754 Single precision 32-bit)







留言討論