mirror of
https://github.com/mytechnotalent/Embedded-Hacking.git
synced 2026-08-22 19:07:49 +02:00
Updated WEEK01
This commit is contained in:
+18
-21
@@ -8,26 +8,23 @@ Introduction and Overview of Embedded Reverse Engineering: Ethics, Scoping, and
|
||||
|
||||
#### Answers
|
||||
|
||||
##### Question 1: GDB Connection
|
||||
- **Was GDB able to connect to OpenOCD?** Yes, via `target extended-remote localhost:3333`
|
||||
- **Did program stop at breakpoint?** Yes, at `Breakpoint 1, main () at ../0x0001_hello-world.c:4`
|
||||
##### Step 1-2 Verification
|
||||
|
||||
##### Question 2: Memory Address of main
|
||||
- **Address of main's first instruction:** `0x10000234`
|
||||
- **Flash or RAM?** **Flash memory** - the address starts with `0x10000...` (XIP region starting at `0x10000000`)
|
||||
- **Was GDB able to connect to OpenOCD?** Yes, via `target extended-remote localhost:3333`.
|
||||
- **Did the program stop at the `main` breakpoint?** Yes, at `Breakpoint 1, main () at ../0x0001_hello-world.c:4`.
|
||||
|
||||
##### Question 3: Stack Pointer Value
|
||||
- **SP value at main:** `0x20082000`
|
||||
- **Flash or RAM?** **RAM** - the address starts with `0x20000...` (SRAM starts at `0x20000000`)
|
||||
##### Step 3: Answer Exactly
|
||||
|
||||
##### Question 4: First Instruction
|
||||
- **First instruction in main:** `push {r3, lr}`
|
||||
- **What does it do?** Saves register `r3` and the Link Register (`lr`) onto the stack. This preserves the return address so `main()` can call other functions (like `stdio_init_all()` and `__wrap_puts`) and they can properly use `lr` themselves.
|
||||
- **What is the address of `main`'s first instruction, and is it Flash or RAM?**
|
||||
- `0x10000234`, and it is in **Flash** (`0x100...` XIP region).
|
||||
- **What is the `sp` value at `main`, and is it Flash or RAM?**
|
||||
- `x/s $sp`, the value is, `0x20082000`, and it is in **RAM** (`0x200...` SRAM region).
|
||||
- **What is the first instruction in `main`, and what does it do?**
|
||||
- `push {r3, lr}`; it saves `r3` and `lr` on the stack and keeps 8-byte stack alignment for ABI-compliant calls.
|
||||
- **Does GDB match what Ghidra shows?**
|
||||
- Yes. The disassembly and flow match the Ghidra listing.
|
||||
|
||||
##### Question 5: Comparison to Ghidra
|
||||
**Yes, they match.** The GDB disassembly output is identical to what Ghidra shows in the Listing View. Both static analysis (Ghidra) and dynamic analysis (GDB) reveal the same instructions.
|
||||
|
||||
##### Register Values at Breakpoint
|
||||
##### Step 4: Capture Register Values (`pc`, `sp`, `lr`, `r0-r3`, by using `x/x $XX`)
|
||||
|
||||
| Register | Value | Description |
|
||||
|----------|-------|-------------|
|
||||
@@ -39,12 +36,12 @@ Introduction and Overview of Embedded Reverse Engineering: Ethics, Scoping, and
|
||||
| **r2** | `0x80808080` | General Purpose |
|
||||
| **r3** | `0xe000ed08` | General Purpose |
|
||||
|
||||
##### Full Disassembly of main
|
||||
##### Reference Disassembly (for verification)
|
||||
|
||||
```
|
||||
0x10000234 <+0>: push {r3, lr} # Save registers to stack
|
||||
0x10000234 <+0>: push {r3, lr} # Save registers to stack
|
||||
0x10000236 <+2>: bl 0x1000156c <stdio_init_all> # Initialize I/O
|
||||
0x1000023a <+6>: ldr r0, [pc, #8] # Load string pointer
|
||||
0x1000023a <+6>: ldr r0, [pc, #8] # Load string pointer
|
||||
0x1000023c <+8>: bl 0x100015fc <__wrap_puts> # Print string
|
||||
0x10000240 <+12>: b.n 0x1000023a <main+6> # Infinite loop
|
||||
0x10000242 <+14>: nop
|
||||
@@ -60,11 +57,11 @@ Terminal 2: arm-none-eabi-gdb build/0x0001_hello-world.elf
|
||||
(gdb) monitor reset halt
|
||||
(gdb) b main
|
||||
(gdb) c
|
||||
(gdb) disassemble main
|
||||
(gdb) disas main
|
||||
(gdb) i r
|
||||
```
|
||||
|
||||
#### Reflection Answers
|
||||
#### Step 5: Reflection Answers
|
||||
|
||||
1. **Why does the stack pointer start at `0x20082000`?**
|
||||
The initial stack pointer value comes from the first entry in the vector table at `0x10000000`. The linker script sets `__StackTop` to `0x20082000`, which is the top of the SCRATCH_Y region in SRAM. The stack grows downward from this address.
|
||||
|
||||
Reference in New Issue
Block a user