mirror of
https://github.com/mytechnotalent/Embedded-Hacking.git
synced 2026-08-28 05:40:36 +02:00
Refactor E and S
This commit is contained in:
+7
-7
@@ -1,10 +1,10 @@
|
||||
# Embedded Systems Reverse Engineering
|
||||
# Embedded Systems Reverse Engineering
|
||||
[Repository](https://github.com/mytechnotalent/Embedded-Hacking)
|
||||
|
||||
## Week 6
|
||||
Static Variables in Embedded Systems: Debugging and Hacking Static Variables w/ GPIO Input Basics
|
||||
|
||||
### Exercise 1: Change the Static Variable Initial Value from 42 to 100
|
||||
### Non-Credit Practice Exercise 1: Change the Static Variable Initial Value from 42 to 100
|
||||
|
||||
#### Objective
|
||||
Use GDB to locate the static variable `static_fav_num` in the `.data` section of the `0x0014_static-variables` binary, calculate the corresponding file offset, patch the initial value from `42` (`0x2A`) to `100` (`0x64`) using a hex editor, convert the patched binary to UF2 format, and flash it to the Pico 2 to verify the change.
|
||||
@@ -68,7 +68,7 @@ Examine the disassembly to find data copy references. The initial value `42` (`0
|
||||
(gdb) find /b 0x10000000, 0x10010000, 0x2a
|
||||
```
|
||||
|
||||
This searches the flash region for the byte `0x2A`. You may get multiple hits — look for one that is in the data initialization area (typically near the end of the code section).
|
||||
This searches the flash region for the byte `0x2A`. You may get multiple hits — look for one that is in the data initialization area (typically near the end of the code section).
|
||||
|
||||
##### Step 4: Confirm the Address
|
||||
|
||||
@@ -98,7 +98,7 @@ For example, if the initial value is at `0x10004xxx`:
|
||||
3. Enter the calculated offset
|
||||
4. You should see the byte `2A` at this position
|
||||
5. Change `2A` to `64` (100 in decimal)
|
||||
6. Click **File** → **Save As** → `0x0014_static-variables-h.bin` (in the same `build` directory)
|
||||
6. Click **File** ? **Save As** ? `0x0014_static-variables-h.bin` (in the same `build` directory)
|
||||
|
||||
##### Step 7: Convert to UF2 and Flash
|
||||
|
||||
@@ -116,7 +116,7 @@ python ..\uf2conv.py build\0x0014_static-variables-h.bin --base 0x10000000 --fam
|
||||
**Expected serial output:**
|
||||
```
|
||||
regular_fav_num: 42
|
||||
static_fav_num: 100 ← Starts at 100 now!
|
||||
static_fav_num: 100 ? Starts at 100 now!
|
||||
regular_fav_num: 42
|
||||
static_fav_num: 101
|
||||
regular_fav_num: 42
|
||||
@@ -143,13 +143,13 @@ After completing this exercise, you should be able to:
|
||||
|
||||
###### Question 3: If you also wanted to change the `regular_fav_num` constant from 42, would you patch the same area of the binary? Why or why not?
|
||||
|
||||
###### Question 4: What would happen if the `.data` section had TWO static variables — would their initial values be adjacent in flash?
|
||||
###### Question 4: What would happen if the `.data` section had TWO static variables — would their initial values be adjacent in flash?
|
||||
|
||||
#### Tips and Hints
|
||||
- The `find` command in GDB can search for bytes, halfwords, or words in any memory range
|
||||
- Static variables with initial values are in `.data`; without initial values they're in `.bss`
|
||||
- The startup code (`crt0`) copies the entire `.data` section from flash to RAM before calling `main()`
|
||||
- HxD shows both hex and ASCII — the value `0x2A` is the ASCII character `*`
|
||||
- HxD shows both hex and ASCII — the value `0x2A` is the ASCII character `*`
|
||||
|
||||
#### Next Steps
|
||||
- Proceed to Exercise 2 to try a more complex hack (reversing GPIO logic)
|
||||
|
||||
Reference in New Issue
Block a user