메모리 및 레지스터 검사
실행 중 메모리 영역을 검사하고 레지스터 값을 확인하며 프로그램 상태를 수정하는 연습을 합니다.
메모리 및 레지스터 검사은(는) CoddyKit의 무료 Reverse Engineering & Binary Analysis Basics 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 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.,
xfor hex,dfor decimal,sfor string,ifor instruction). - S: Size (e.g.,
bfor byte,hfor halfword (2 bytes),wfor word (4 bytes),gfor 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 = 0x1234set $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
setto alter program state dynamically.
These skills are fundamental for understanding program execution and reverse engineering!
자주 묻는 질문
“메모리 및 레지스터 검사” 강의는 무료인가요?
네 — “메모리 및 레지스터 검사” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Reverse Engineering & Binary Analysis Basics 강의 전체를 잠금 해제할 수 있습니다. Reverse Engineering & Binary Analysis Basics 강의에는 총 4개의 강의가 포함되어 있습니다.
“메모리 및 레지스터 검사”에서 뭘 배우나요?
실행 중 메모리 영역을 검사하고 레지스터 값을 확인하며 프로그램 상태를 수정하는 연습을 합니다. 브라우저에서 직접 실행하는 실습 코드로 Reverse Engineering & Binary Analysis Basics을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Reverse Engineering & Binary Analysis Basics을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Reverse Engineering & Binary Analysis Basics은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.
“메모리 및 레지스터 검사” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Reverse Engineering & Binary Analysis Basics 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Reverse Engineering & Binary Analysis Basics 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.