mirror of
https://github.com/mytechnotalent/Embedded-Hacking.git
synced 2026-07-20 19:00:52 +02:00
Fixed WEEK06
This commit is contained in:
+14
-12
@@ -50,28 +50,29 @@ arm-none-eabi-gdb build/0x0014_static-variables.elf
|
||||
|
||||
##### Step 2: Locate the Increment Instruction
|
||||
|
||||
From the tutorial, we know the static variable operations are around address `0x10000260`. Disassemble the loop body:
|
||||
From the tutorial, we know the static variable operations are in the loop body starting at `0x10000274`. Disassemble the loop body:
|
||||
|
||||
```gdb
|
||||
(gdb) x/20i 0x10000260
|
||||
(gdb) x/20i 0x10000274
|
||||
```
|
||||
|
||||
Look for this sequence:
|
||||
|
||||
```
|
||||
ldrb r3, [r4, #0x0] ; Load static_fav_num from RAM
|
||||
adds r3, #0x1 ; Increment by 1 ← THIS IS OUR TARGET
|
||||
strb r3, [r4, #0x0] ; Store back to RAM
|
||||
0x10000278: ldrb r3, [r4, #0] ; Load static_fav_num from RAM
|
||||
0x1000027a: movs r2, #16 ; LED GPIO pin number
|
||||
0x1000027c: adds r3, #1 ; Increment by 1 ← THIS IS OUR TARGET
|
||||
0x1000027e: strb r3, [r4, #0] ; Store back to RAM
|
||||
```
|
||||
|
||||
Note the exact address of the `adds r3, #0x1` instruction.
|
||||
The `adds r3, #1` instruction is at address `0x1000027c`.
|
||||
|
||||
##### Step 3: Examine the Instruction Encoding
|
||||
|
||||
Look at the raw bytes of the instruction:
|
||||
|
||||
```gdb
|
||||
(gdb) x/2bx <address_of_adds>
|
||||
(gdb) x/2bx 0x1000027c
|
||||
```
|
||||
|
||||
You should see:
|
||||
@@ -89,7 +90,7 @@ You should see:
|
||||
Before making a permanent patch, test the change in RAM:
|
||||
|
||||
```gdb
|
||||
(gdb) b *<address_of_adds>
|
||||
(gdb) b *0x1000027c
|
||||
(gdb) c
|
||||
```
|
||||
|
||||
@@ -111,19 +112,20 @@ For the `adds r3, #0x1` instruction at its address, calculate the offset.
|
||||
|
||||
##### Step 6: Patch with the Hex Editor
|
||||
|
||||
1. Open `0x0014_static-variables.bin` in HxD
|
||||
1. In HxD, open `C:\Users\flare-vm\Desktop\Embedded-Hacking-main\0x0014_static-variables\build\0x0014_static-variables.bin`
|
||||
2. Press **Ctrl+G** (Go to offset) and enter the calculated offset
|
||||
3. You should see the byte `01` followed by `33`
|
||||
4. Change `01` to `0A` (10 in decimal)
|
||||
5. Verify: the bytes should now read `0A 33` — encoding `adds r3, #0xa`
|
||||
6. Click **File** → **Save As** → `0x0014_static-variables-h.bin`
|
||||
6. Click **File** → **Save As** → `0x0014_static-variables-h.bin` (in the same `build` directory)
|
||||
|
||||
> 🔍 **Why this works:** In Thumb `adds rD, #imm8` encoding, the immediate value is stored in the first byte. The `#imm8` field accepts values 0-255, so changing 1 to 10 is safe.
|
||||
|
||||
##### Step 7: Convert to UF2 and Flash
|
||||
|
||||
```bash
|
||||
python ../uf2conv.py build/0x0014_static-variables-h.bin --base 0x10000000 --family 0xe48bff59 --output build/hacked.uf2
|
||||
```powershell
|
||||
cd C:\Users\flare-vm\Desktop\Embedded-Hacking-main\0x0014_static-variables
|
||||
python ..\uf2conv.py build\0x0014_static-variables-h.bin --base 0x10000000 --family 0xe48bff59 --output build\hacked.uf2
|
||||
```
|
||||
|
||||
1. Hold BOOTSEL and plug in your Pico 2
|
||||
|
||||
Reference in New Issue
Block a user