0Pricing
Reverse Engineering & Binary Analysis Basics · Урок

Исследование памяти и регистров

Потренируйтесь исследовать области памяти, просматривать значения регистров и изменять состояние программы во время выполнения.

«Исследование памяти и регистров» — бесплатный урок Reverse Engineering & Binary Analysis Basics на CoddyKit. Это урок 3 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Reverse Engineering & Binary Analysis Basics, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Reverse Engineering & Binary Analysis Basics содержит 4 уроков всего.

Части этого урока еще не переведены и отображаются на английском.

Debugging's Core: Memory & Registers

When analyzing programs, especially during dynamic analysis, understanding what's happening inside the CPU is key. This means looking at registers and memory.

These are the CPU's direct workspaces, holding data and instructions that are actively being processed.

CPU's Scratchpad: Registers

Registers are tiny, super-fast storage locations directly within the CPU itself. Think of them as the CPU's "scratchpad" where it keeps data it needs immediately.

  • They hold temporary values, addresses, and control information.
  • Accessing data in registers is much faster than accessing RAM.
  • Different architectures (like x86, ARM) have different sets of registers.

Common x86/x64 Registers

While there are many registers, some are crucial for reverse engineering:

  • General-Purpose: RAX/EAX, RBX/EBX, RCX/ECX, RDX/EDX (used for data, function arguments, return values).
  • Stack Pointer: RSP/ESP (points to the top of the stack).
  • Base Pointer: RBP/EBP (points to the base of the current stack frame).
  • Instruction Pointer: RIP/EIP (points to the next instruction to execute).

Viewing Registers in GDB

Let's see how to inspect registers using a debugger like GDB. We'll use a simple C program.

First, compile with debug info (-g): gcc -g -o myprog myprog.c

After compiling and starting GDB (e.g., gdb -q ./myprog), you can set a breakpoint (break main), run (run), and then use info registers.

    #include <stdio.h>

    int main() {
        int a = 10;
        int b = 20;
        int sum = a + b;
        printf("Sum: %d\n", sum);
        return 0;
    }

Program's Workspace: Memory

Memory (RAM) is where your program stores larger amounts of data that aren't actively being processed by the CPU. This includes variables, program code, and other resources.

Every byte in memory has a unique address. When a program runs, it gets its own dedicated "virtual" memory space.

Simplified Memory Layout

A program's memory is typically divided into sections:

  • Text/Code Segment: Contains the executable instructions.
  • Data Segment: Stores global and static variables.
  • Heap: Used for dynamically allocated memory (e.g., with malloc).
  • Stack: Used for local variables, function arguments, and return addresses.

Viewing Memory in GDB

To inspect memory in GDB, we use the x command (examine memory). It has a flexible syntax:

  • x /NFS ADDRESS
  • N: Number of units to display (optional).
  • F: Format (e.g., x for hex, d for decimal, s for string, i for instruction).
  • S: Size (e.g., b for byte, h for halfword (2 bytes), w for word (4 bytes), g for giant (8 bytes)).

Example: Viewing a Stack Variable

Let's use our previous program. Compile it and set a breakpoint before printf. Then, we can find the address of sum and examine its content.

Run this code, then attach GDB (gdb -q ./myprog), set a breakpoint at line 7 (break main.c:7), and run (run).

In GDB: p &sum to get its address. Finally, x /w ADDRESS_OF_SUM to view its 4-byte value.

    #include <stdio.h>

    int main() {
        int a = 10;
        int b = 20;
        int sum = a + b; // Breakpoint here
        printf("Sum: %d\n", sum);
        return 0;
    }

Changing Register Values

A powerful debugging technique is to modify register values on the fly. This can change how a program behaves without altering its code.

In GDB, you can use the set command:

  • set $rax = 0x1234
  • set $rip = *0x400500 (jump to a new address)

This is useful for bypassing checks or redirecting execution flow.

Altering Memory Content

Just like registers, you can also modify memory content while debugging. This allows you to change variable values, strings, or even instructions in memory.

Using GDB's set command:

  • set var_name = new_value (if the variable is in scope)
  • set {int}0x400000 = 123 (change 4 bytes at address 0x400000 to 123)

Be careful, incorrect modifications can crash the program!

Debugger Challenge

You're debugging a program. You want to see the value of a 4-byte integer variable named counter located at memory address 0x7fffffff0000. What GDB command would you use?

Recap: Debugging's Core

Today, we explored how to examine and modify the core components of a running program: registers and memory.

  • Registers are CPU's fast storage, viewed with info registers.
  • Memory holds larger data, viewed with x /NFS ADDRESS.
  • Both can be modified with set to alter program state dynamically.

These skills are fundamental for understanding program execution and reverse engineering!

Часто задаваемые вопросы

Урок «Исследование памяти и регистров» бесплатный?

Да — полный текст урока «Исследование памяти и регистров» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Reverse Engineering & Binary Analysis Basics, подпишись на CoddyKit PRO. Курс Reverse Engineering & Binary Analysis Basics содержит 4 уроков всего.

Чему я научусь в уроке «Исследование памяти и регистров»?

Потренируйтесь исследовать области памяти, просматривать значения регистров и изменять состояние программы во время выполнения. Ты практикуешь Reverse Engineering & Binary Analysis Basics с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать Reverse Engineering & Binary Analysis Basics?

Предыдущий опыт не требуется. Reverse Engineering & Binary Analysis Basics на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 3 из 4.

Сколько времени занимает урок «Исследование памяти и регистров»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке Reverse Engineering & Binary Analysis Basics?

Да. Каждый урок Reverse Engineering & Binary Analysis Basics включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Основы отладки (GDB, WinDbg)
  2. Точки останова и пошаговое выполнение
  3. Исследование памяти и регистров
  4. Трассировка API и системных вызовов во время выполнения
← Назад к Reverse Engineering & Binary Analysis Basics