Updated WEEK09

This commit is contained in:
Kevin Thomas
2026-06-14 10:49:32 -04:00
parent db64f419ac
commit 93aa5d6cef
13 changed files with 948 additions and 52 deletions
+62 -44
View File
@@ -175,8 +175,8 @@ bool result = (x > y) && (y > x); // false AND true = false
Bitwise operators work on the binary representation of numbers:
```c
int x = 6; // Binary: 0b00000110
int result = x << 1; // Shift left by 1: 0b00001100 = 12
int x = 6; // Binary: 0b00000110
int result = x << 1; // Shift left by 1: 0b00001100 = 12
```
```
@@ -436,14 +436,14 @@ Let's trace through what happens to `x`:
| Variable x Through the Program |
| |
| Line | x value | Result |
| ------------------+---------+--------------------------------- |
| ------------------+---------+--------------------------------- |
| int x = 5; | 5 | x initialized to 5 |
| x * y | 5 | arithmetic = 5 * 10 = 50 |
| x++ | 5->6 | increment = 5 (then x becomes 6) |
| x++ | 5->6 | increment = 5 (then x becomes 6)|
| x > y | 6 | relational = (6 > 10) = false |
| (x>y) && (y>x) | 6 | logical = false && true = false |
| x << 1 | 6 | bitwise = 6 << 1 = 12 |
| x += 5 | 6->11 | assignment = 6 + 5 = 11 |
| x += 5 | 6->11 | assignment = 6 + 5 = 11 |
| |
+-----------------------------------------------------------------+
```
@@ -534,11 +534,11 @@ x/60i 0x10000234
You should see the operator calculations and function calls:
```
0x10000234: push {r4, r5, r6, r7, lr}
0x10000236: sub sp, #20
0x10000238: bl 0x10003014 ; stdio_init_all
0x1000023c: movs r0, #4 ; GPIO 4 for DHT11
0x1000023e: bl 0x100003b4 ; dht11_init
0x10000234 <main>: push {r4, r5, r6, r7, lr}
0x10000236 <main+2>: sub sp, #20
0x10000238 <main+4>: bl 0x10003384 <stdio_init_all>
0x1000023c <main+8>: movs r0, #4
0x1000023e <main+10>: bl 0x100002d4 <dht11_init>
...
```
@@ -549,20 +549,12 @@ b *0x10000234
c
```
GDB responds:
```
Breakpoint 1 at 0x10000234
Continuing.
Breakpoint 1, 0x10000234 in ?? ()
```
### Step 11: Find the Operator Calculations
The compiler likely optimized many of these calculations at compile time. Look for immediate values:
```
x/30i 0x10000240
x/32i 0x10000240
```
You may see values like:
@@ -576,7 +568,7 @@ You may see values like:
Set a breakpoint before the first printf and examine registers:
```
```gdb
b *0x10000262
c
i r r0 r1
@@ -584,18 +576,22 @@ i r r0 r1
You should see:
- `r0` = address of format string
- `r1` = value to print (50 for arithmetic_operator)
- `r1` = value to print
### Step 13: Examine the Format Strings
```
x/s 0x10003xxx
```gdb
x/s 0x10003978
```
Find the format strings like:
```
"arithmetic_operator: %d\r\n"
"increment_operator: %d\r\n"
Find the format strings and value for print:
```gdb
(gdb) x/s 0x10003978
0x10003978: "Humidity: %.1f%%, Temperature: %.1fA°C\r\n"
(gdb) x/x 0x4037cccc
0x4037cccc: 0x00
(gdb) x/x $r1
0x4037cccc: 0x00
...
```
@@ -603,23 +599,24 @@ Find the format strings like:
Find where dht11_read is called:
```
x/10i 0x100002a0
```gdb
(gdb) x/3i 0x1000029f
```
You'll see stack addresses being passed as arguments:
```
add r0, sp, #0x8 ; Address of hum variable
add r1, sp, #0xc ; Address of temp variable
bl dht11_read
0x1000029f <main+106>: add r1, sp, #12
0x100002a1 <main+108>: add r0, sp, #8
0x100002a3 <main+110>: bl 0x100002f4 <dht11_read>
```
### Step 15: Watch the Float Values
After dht11_read returns, examine the float values on the stack:
```
x/2fw $sp+8
```gdb
(gdb) x/2fw $sp+8
0x20081fe0: 62 23.7999992
```
This shows the humidity and temperature as floats.
@@ -628,7 +625,7 @@ This shows the humidity and temperature as floats.
Continue execution and watch the values:
```
```gdb
c
```
@@ -826,8 +823,8 @@ bl FUN_xxxxx ; sleep_ms
This is trickier! Look for a function call with TWO address arguments:
```assembly
add r0, sp, #0x8 ; Address of hum on stack
add r1, sp, #0xc ; Address of temp on stack
add r0, sp, #0x8 ; Address of hum on stack
bl FUN_xxxxx ; dht11_read
```
@@ -931,11 +928,11 @@ Navigate to the `dht11_read` function you identified earlier.
### Step 35: Find the Scaling Constant
At the end of the `dht11_read` function, look for floating-point instructions. You'll find instructions like:
At the end of the `dht11_read` function, and around `0x10000410`, look for floating-point instructions. You'll find instructions like:
```assembly
vfma.f32 s14, s12, s11 ; Fused multiply-add for humidity
vfma.f32 s15, s13, s11 ; Fused multiply-add for temperature
vfma.f32 s14, s12, s11 ; Fused multiply-add for humidity
vfma.f32 s15, s13, s11 ; Fused multiply-add for temperature
```
The constant `0.1` (at address `0x1000042c`) is loaded into register `s11` and used to scale the raw sensor readings.
@@ -1005,6 +1002,20 @@ new = struct.unpack('<f', bytes.fromhex('0000a040'))[0]
print(f"New: {new}") # 5.0
```
```python
>>> import struct
>>>
>>> # Original value
>>> original = struct.unpack('<f', bytes.fromhex('cdcccc3d'))[0]
>>> print(f"Original: {original}") # 0.1
Original: 0.10000000149011612
>>>
>>> # New value
>>> new = struct.unpack('<f', bytes.fromhex('0000a040'))[0]
>>> print(f"New: {new}") # 5.0
New: 5.0
```
---
## Part 19: Exporting and Testing
@@ -1012,7 +1023,7 @@ print(f"New: {new}") # 5.0
### Step 41: Export the Patched Binary
1. Click **File** -> **Export Program**
2. Set **Format** to **Binary**
2. Set **Format** to **Raw Bytes**
3. Navigate to your build directory
4. Name the file `0x001a_operators-h.bin`
5. Click **OK**
@@ -1034,6 +1045,16 @@ python ..\uf2conv.py build\0x001a_operators-h.bin --base 0x10000000 --family 0xe
You should see dramatically increased temperature readings!
```
Humidity: 60.0%, Temperature: 63.0°C
arithmetic_operator: 50
increment_operator: 5
relational_operator: 0
logical_operator: 0
bitwise_operator: 12
assignment_operator: 11
```
---
## Part 20: Summary and Review
@@ -1181,7 +1202,4 @@ By manipulating sensor readings, an attacker could:
**Remember:** The techniques you learned today can be used for good (security research, debugging) or bad (sabotage, fraud). Always use your skills ethically and legally. Understanding how attacks work helps us build more secure systems!
Happy hacking! ?
Happy hacking!
+79
View File
@@ -0,0 +1,79 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<!-- Background grid decoration -->
<g opacity="0.06">
<line x1="0" y1="100" x2="1200" y2="100" stroke="#00ff41" stroke-width="1"/>
<line x1="0" y1="200" x2="1200" y2="200" stroke="#00ff41" stroke-width="1"/>
<line x1="0" y1="300" x2="1200" y2="300" stroke="#00ff41" stroke-width="1"/>
<line x1="0" y1="400" x2="1200" y2="400" stroke="#00ff41" stroke-width="1"/>
<line x1="0" y1="500" x2="1200" y2="500" stroke="#00ff41" stroke-width="1"/>
<line x1="0" y1="600" x2="1200" y2="600" stroke="#00ff41" stroke-width="1"/>
<line x1="0" y1="700" x2="1200" y2="700" stroke="#00ff41" stroke-width="1"/>
<line x1="200" y1="0" x2="200" y2="800" stroke="#00ff41" stroke-width="1"/>
<line x1="400" y1="0" x2="400" y2="800" stroke="#00ff41" stroke-width="1"/>
<line x1="600" y1="0" x2="600" y2="800" stroke="#00ff41" stroke-width="1"/>
<line x1="800" y1="0" x2="800" y2="800" stroke="#00ff41" stroke-width="1"/>
<line x1="1000" y1="0" x2="1000" y2="800" stroke="#00ff41" stroke-width="1"/>
</g>
<!-- Hex rain decoration -->
<g opacity="0.04" font-family="'Courier New',monospace" font-size="14" fill="#00ff41">
<text x="50" y="80">4F 70 65 6E 4F 43 44</text>
<text x="900" y="120">10 00 02 34 08 B5 01</text>
<text x="150" y="180">47 44 42 20 52 45 56</text>
<text x="800" y="240">20 08 20 00 FF AA 00</text>
<text x="80" y="350">52 50 32 33 35 30 00</text>
<text x="950" y="380">0A 0A 0F 12 12 1A 1A</text>
<text x="100" y="520">41 52 4D 76 38 2D 4D</text>
<text x="870" y="560">00 FF 41 00 D4 FF 88</text>
<text x="60" y="680">47 48 49 44 52 41 00</text>
<text x="920" y="720">FF 00 40 C0 C0 C0 00</text>
</g>
<!-- Corner accents -->
<polyline points="30,30 30,80 80,80" fill="none" stroke="#00ff41" stroke-width="2" opacity="0.3"/>
<polyline points="1170,30 1170,80 1120,80" fill="none" stroke="#00ff41" stroke-width="2" opacity="0.3"/>
<polyline points="30,770 30,720 80,720" fill="none" stroke="#00ff41" stroke-width="2" opacity="0.3"/>
<polyline points="1170,770 1170,720 1120,720" fill="none" stroke="#00ff41" stroke-width="2" opacity="0.3"/>
<!-- Top accent line -->
<rect x="100" y="140" width="1000" height="2" fill="#00ff41" opacity="0.4"/>
<!-- Course Title -->
<text x="600" y="210" text-anchor="middle" font-family="'Courier New',monospace" font-size="56" font-weight="bold" fill="#00ff41">Embedded Systems</text>
<text x="600" y="278" text-anchor="middle" font-family="'Courier New',monospace" font-size="56" font-weight="bold" fill="#00ff41">Reverse Engineering</text>
<!-- Divider -->
<rect x="300" y="310" width="600" height="2" fill="#00d4ff" opacity="0.6"/>
<!-- Week Number -->
<text x="600" y="380" text-anchor="middle" font-family="'Courier New',monospace" font-size="42" font-weight="bold" fill="#00d4ff">// WEEK 09</text>
<!-- Week Topic -->
<text x="600" y="440" text-anchor="middle" font-family="'Courier New',monospace" font-size="28" fill="#c0c0c0">Operators in Embedded Systems:</text>
<text x="600" y="478" text-anchor="middle" font-family="'Courier New',monospace" font-size="28" fill="#c0c0c0">Debugging and Hacking Operators</text>
<text x="600" y="516" text-anchor="middle" font-family="'Courier New',monospace" font-size="28" fill="#c0c0c0">w/ DHT11 Sensor Single-Wire Protocol</text>
<!-- Bottom accent line -->
<rect x="100" y="570" width="1000" height="2" fill="#00ff41" opacity="0.4"/>
<!-- University -->
<text x="600" y="635" text-anchor="middle" font-family="'Courier New',monospace" font-size="36" font-weight="bold" fill="#ffaa00">George Mason University</text>
<!-- Bottom badge -->
<rect x="400" y="670" width="400" height="40" rx="20" fill="none" stroke="#00ff41" stroke-width="1.5" opacity="0.5"/>
<text x="600" y="697" text-anchor="middle" font-family="'Courier New',monospace" font-size="20" fill="#00ff41" opacity="0.7">RP2350 // ARM Cortex-M33</text>
</svg>

After

Width:  |  Height:  |  Size: 4.4 KiB

+74
View File
@@ -0,0 +1,74 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<rect class="hdr" x="0" y="0" width="1200" height="100" rx="0"/>
<text class="title" x="600" y="52" text-anchor="middle">C Operators Overview</text>
<text class="dim" x="600" y="88" text-anchor="middle">Six Types of Operators in C</text>
<!-- Top Row -->
<rect class="pnl" x="30" y="110" width="370" height="195" rx="8"/>
<text class="amb" x="50" y="145">Arithmetic</text>
<rect x="50" y="160" width="330" height="120" rx="4" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="txt" x="70" y="190">+ - * / %</text>
<text class="dim" x="70" y="220">Math operations</text>
<text class="grn" x="70" y="250">5 * 10 = 50</text>
<rect class="pnl" x="415" y="110" width="370" height="195" rx="8"/>
<text class="amb" x="435" y="145">Increment</text>
<rect x="435" y="160" width="330" height="120" rx="4" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="txt" x="455" y="190">x++ ++x x--</text>
<text class="dim" x="455" y="220">Add/subtract by 1</text>
<text class="grn" x="455" y="250">x++ returns old val</text>
<rect class="pnl" x="800" y="110" width="370" height="195" rx="8"/>
<text class="amb" x="820" y="145">Relational</text>
<rect x="820" y="160" width="330" height="120" rx="4" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="txt" x="840" y="190">&gt; &lt; &gt;= &lt;= == !=</text>
<text class="dim" x="840" y="220">Compare values</text>
<text class="grn" x="840" y="250">(6 &gt; 10) = false</text>
<!-- Bottom Row -->
<rect class="pnl" x="30" y="320" width="370" height="195" rx="8"/>
<text class="amb" x="50" y="355">Logical</text>
<rect x="50" y="370" width="330" height="120" rx="4" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="txt" x="70" y="400">&amp;&amp; || !</text>
<text class="dim" x="70" y="430">Combine conditions</text>
<text class="grn" x="70" y="460">AND, OR, NOT</text>
<rect class="pnl" x="415" y="320" width="370" height="195" rx="8"/>
<text class="amb" x="435" y="355">Bitwise</text>
<rect x="435" y="370" width="330" height="120" rx="4" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="txt" x="455" y="400">&lt;&lt; &gt;&gt; &amp; | ^ ~</text>
<text class="dim" x="455" y="430">Manipulate bits</text>
<text class="grn" x="455" y="460">6 &lt;&lt; 1 = 12</text>
<rect class="pnl" x="800" y="320" width="370" height="195" rx="8"/>
<text class="amb" x="820" y="355">Assignment</text>
<rect x="820" y="370" width="330" height="120" rx="4" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="txt" x="840" y="400">+= -= *= /=</text>
<text class="dim" x="840" y="430">Assign and modify</text>
<text class="grn" x="840" y="460">x += 5 (x=x+5)</text>
<!-- Bottom: Context -->
<rect class="pnl" x="30" y="530" width="1140" height="120" rx="8"/>
<text class="sub" x="50" y="565">This Week's Program</text>
<text class="txt" x="50" y="600">0x001a_operators.c demonstrates all 6 types</text>
<text class="dim" x="50" y="630">DHT11 temperature/humidity sensor + operator calculations</text>
<!-- Key insight -->
<rect class="pnl" x="30" y="665" width="1140" height="80" rx="8"/>
<text class="red" x="50" y="700">KEY:</text>
<text class="txt" x="130" y="700">Compiler pre-computes constant expressions</text>
<text class="dim" x="50" y="725">In the binary, most operators become immediate values</text>
</svg>

After

Width:  |  Height:  |  Size: 3.8 KiB

+75
View File
@@ -0,0 +1,75 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<rect class="hdr" x="0" y="0" width="1200" height="100" rx="0"/>
<text class="title" x="600" y="52" text-anchor="middle">Arithmetic &amp; Increment</text>
<text class="dim" x="600" y="88" text-anchor="middle">Math Operations and Post/Pre Increment</text>
<!-- Arithmetic Panel -->
<rect class="pnl" x="30" y="110" width="555" height="290" rx="8"/>
<text class="sub" x="50" y="145">Arithmetic Operators</text>
<rect x="50" y="160" width="515" height="220" rx="6" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="amb" x="70" y="195">+</text>
<text class="dim" x="130" y="195">5 + 10 = 15</text>
<text class="dim" x="360" y="195">Addition</text>
<text class="amb" x="70" y="230">-</text>
<text class="dim" x="130" y="230">10 - 5 = 5</text>
<text class="dim" x="360" y="230">Subtraction</text>
<text class="amb" x="70" y="265">*</text>
<text class="dim" x="130" y="265">5 * 10 = 50</text>
<text class="dim" x="360" y="265">Multiplication</text>
<text class="amb" x="70" y="300">/</text>
<text class="dim" x="130" y="300">10 / 5 = 2</text>
<text class="dim" x="360" y="300">Division</text>
<text class="amb" x="70" y="335">%</text>
<text class="dim" x="130" y="335">10 % 3 = 1</text>
<text class="dim" x="360" y="335">Modulus</text>
<!-- Increment Panel -->
<rect class="pnl" x="615" y="110" width="555" height="290" rx="8"/>
<text class="sub" x="635" y="145">Post vs Pre Increment</text>
<rect x="635" y="165" width="515" height="100" rx="6" fill="#00ff41" fill-opacity="0.08" stroke="#00ff41"/>
<text class="grn" x="655" y="195">Post: x++</text>
<text class="txt" x="655" y="225">Use value THEN increment</text>
<text class="dim" x="655" y="250">a = x++ --> a=5, x=6</text>
<rect x="635" y="275" width="515" height="100" rx="6" fill="#00d4ff" fill-opacity="0.08" stroke="#00d4ff"/>
<text class="cyn" x="655" y="305">Pre: ++x</text>
<text class="txt" x="655" y="335">Increment THEN use value</text>
<text class="dim" x="655" y="360">b = ++x --> x=7, b=7</text>
<!-- Trace Example -->
<rect class="pnl" x="30" y="415" width="1140" height="225" rx="8"/>
<text class="sub" x="50" y="450">Post-Increment Step by Step</text>
<rect x="50" y="465" width="1100" height="155" rx="6" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="cyn" x="70" y="495">int x = 5;</text>
<text class="cyn" x="70" y="530">int result = x++;</text>
<text class="dim" x="470" y="495">Step 1: result = x</text>
<text class="grn" x="750" y="495">result gets 5</text>
<text class="dim" x="470" y="530">Step 2: x = x + 1</text>
<text class="grn" x="750" y="530">x becomes 6</text>
<text class="amb" x="70" y="575">Final: result = 5</text>
<text class="amb" x="400" y="575">x = 6</text>
<text class="dim" x="560" y="575">"Use first, THEN increment"</text>
<!-- Key -->
<rect class="pnl" x="30" y="655" width="1140" height="80" rx="8"/>
<text class="red" x="50" y="690">In our code:</text>
<text class="txt" x="250" y="690">int increment_operator = x++;</text>
<text class="dim" x="50" y="718">x was 5, so increment_operator = 5, then x becomes 6</text>
</svg>

After

Width:  |  Height:  |  Size: 3.6 KiB

+95
View File
@@ -0,0 +1,95 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<rect class="hdr" x="0" y="0" width="1200" height="100" rx="0"/>
<text class="title" x="600" y="52" text-anchor="middle">Relational &amp; Logical</text>
<text class="dim" x="600" y="88" text-anchor="middle">Comparing Values and Combining Conditions</text>
<!-- Relational Panel -->
<rect class="pnl" x="30" y="110" width="555" height="340" rx="8"/>
<text class="sub" x="50" y="145">Relational Operators</text>
<text class="dim" x="50" y="175">Compare two values --> true (1) or false (0)</text>
<rect x="50" y="190" width="515" height="240" rx="6" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="amb" x="70" y="220">&gt;</text>
<text class="dim" x="130" y="220">6 &gt; 10</text>
<text class="red" x="310" y="220">false</text>
<text class="dim" x="400" y="220">Greater than</text>
<text class="amb" x="70" y="255">&lt;</text>
<text class="dim" x="130" y="255">6 &lt; 10</text>
<text class="grn" x="310" y="255">true</text>
<text class="dim" x="400" y="255">Less than</text>
<text class="amb" x="70" y="290">&gt;=</text>
<text class="dim" x="130" y="290">6 &gt;= 6</text>
<text class="grn" x="310" y="290">true</text>
<text class="dim" x="400" y="290">Greater/equal</text>
<text class="amb" x="70" y="325">&lt;=</text>
<text class="dim" x="130" y="325">6 &lt;= 10</text>
<text class="grn" x="310" y="325">true</text>
<text class="dim" x="400" y="325">Less or equal</text>
<text class="amb" x="70" y="360">==</text>
<text class="dim" x="130" y="360">6 == 10</text>
<text class="red" x="310" y="360">false</text>
<text class="dim" x="400" y="360">Equal to</text>
<text class="amb" x="70" y="395">!=</text>
<text class="dim" x="130" y="395">6 != 10</text>
<text class="grn" x="310" y="395">true</text>
<text class="dim" x="400" y="395">Not equal</text>
<!-- Logical Panel -->
<rect class="pnl" x="615" y="110" width="555" height="340" rx="8"/>
<text class="sub" x="635" y="145">Logical Operators</text>
<text class="dim" x="635" y="175">Combine conditions into one result</text>
<rect x="635" y="190" width="515" height="105" rx="6" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="amb" x="655" y="220">&amp;&amp;</text>
<text class="dim" x="720" y="220">AND -- both must be true</text>
<text class="amb" x="655" y="255">||</text>
<text class="dim" x="720" y="255">OR -- at least one true</text>
<text class="amb" x="655" y="290">!</text>
<text class="dim" x="720" y="290">NOT -- inverts result</text>
<!-- Truth table for AND -->
<text class="dim" x="635" y="320">AND Truth Table</text>
<rect x="635" y="330" width="515" height="165" rx="6" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="dim" x="655" y="355">A</text>
<text class="dim" x="755" y="355">B</text>
<text class="dim" x="855" y="355">A &amp;&amp; B</text>
<text class="red" x="655" y="385">false</text>
<text class="red" x="755" y="385">false</text>
<text class="red" x="855" y="385">false</text>
<text class="red" x="655" y="415">false</text>
<text class="grn" x="755" y="415">true</text>
<text class="red" x="855" y="415">false</text>
<text class="grn" x="655" y="445">true</text>
<text class="red" x="755" y="445">false</text>
<text class="red" x="855" y="445">false</text>
<text class="grn" x="655" y="475">true</text>
<text class="grn" x="755" y="475">true</text>
<text class="grn" x="855" y="475">true</text>
<!-- Bottom: Code Example -->
<rect class="pnl" x="30" y="465" width="1140" height="155" rx="8"/>
<text class="sub" x="50" y="500">In Our Code (x=6, y=10)</text>
<rect x="50" y="515" width="1100" height="85" rx="6" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="cyn" x="70" y="545">bool relational = (x &gt; y);</text>
<text class="dim" x="560" y="545">(6 &gt; 10) = false = 0</text>
<text class="cyn" x="70" y="580">bool logical = (x&gt;y) &amp;&amp; (y&gt;x);</text>
<text class="dim" x="560" y="580">false &amp;&amp; true = false = 0</text>
<!-- Key -->
<rect class="pnl" x="30" y="635" width="1140" height="100" rx="8"/>
<text class="red" x="50" y="670">In the binary:</text>
<text class="txt" x="290" y="670">Both compile to immediate #0</text>
<text class="dim" x="50" y="700">Compiler pre-computes: constants are known at compile time</text>
<text class="dim" x="50" y="720">Result 0 = false, Result 1 = true</text>
</svg>

After

Width:  |  Height:  |  Size: 4.8 KiB

+89
View File
@@ -0,0 +1,89 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<rect class="hdr" x="0" y="0" width="1200" height="100" rx="0"/>
<text class="title" x="600" y="52" text-anchor="middle">Bitwise &amp; Assignment</text>
<text class="dim" x="600" y="88" text-anchor="middle">Bit Manipulation and Compound Assignment</text>
<!-- Bitwise Panel -->
<rect class="pnl" x="30" y="110" width="555" height="370" rx="8"/>
<text class="sub" x="50" y="145">Bitwise Operators</text>
<rect x="50" y="160" width="515" height="200" rx="6" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="amb" x="70" y="190">&lt;&lt;</text>
<text class="dim" x="140" y="190">6 &lt;&lt; 1 = 12</text>
<text class="dim" x="360" y="190">Left shift</text>
<text class="amb" x="70" y="220">&gt;&gt;</text>
<text class="dim" x="140" y="220">6 &gt;&gt; 1 = 3</text>
<text class="dim" x="360" y="220">Right shift</text>
<text class="amb" x="70" y="250">&amp;</text>
<text class="dim" x="140" y="250">6 &amp; 3 = 2</text>
<text class="dim" x="360" y="250">AND</text>
<text class="amb" x="70" y="280">|</text>
<text class="dim" x="140" y="280">6 | 3 = 7</text>
<text class="dim" x="360" y="280">OR</text>
<text class="amb" x="70" y="310">^</text>
<text class="dim" x="140" y="310">6 ^ 3 = 5</text>
<text class="dim" x="360" y="310">XOR</text>
<text class="amb" x="70" y="340">~</text>
<text class="dim" x="140" y="340">~6</text>
<text class="dim" x="360" y="340">NOT (invert)</text>
<!-- Left shift diagram -->
<text class="dim" x="50" y="390">Left shift = multiply by 2</text>
<rect x="50" y="400" width="515" height="60" rx="4" fill="#0a0a0f" stroke="#00ff41" stroke-width="1"/>
<text class="grn" x="70" y="425">0 0 0 0 0 1 1 0</text>
<text class="dim" x="370" y="425">= 6</text>
<text class="grn" x="70" y="448">0 0 0 0 1 1 0 0</text>
<text class="dim" x="370" y="448">= 12</text>
<!-- Assignment Panel -->
<rect class="pnl" x="615" y="110" width="555" height="370" rx="8"/>
<text class="sub" x="635" y="145">Assignment Operators</text>
<text class="dim" x="635" y="175">Shorthand for math + assign</text>
<rect x="635" y="190" width="515" height="200" rx="6" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="amb" x="655" y="220">+=</text>
<text class="dim" x="720" y="220">x += 5</text>
<text class="dim" x="905" y="220">x = x + 5</text>
<text class="amb" x="655" y="255">-=</text>
<text class="dim" x="720" y="255">x -= 2</text>
<text class="dim" x="905" y="255">x = x - 2</text>
<text class="amb" x="655" y="290">*=</text>
<text class="dim" x="720" y="290">x *= 3</text>
<text class="dim" x="905" y="290">x = x * 3</text>
<text class="amb" x="655" y="325">/=</text>
<text class="dim" x="720" y="325">x /= 2</text>
<text class="dim" x="905" y="325">x = x / 2</text>
<text class="amb" x="655" y="360">%=</text>
<text class="dim" x="720" y="360">x %= 4</text>
<text class="dim" x="905" y="360">x = x % 4</text>
<!-- Code example -->
<text class="dim" x="635" y="415">In our code (x=6 after x++):</text>
<rect x="635" y="425" width="515" height="45" rx="4" fill="#0a0a0f" stroke="#ffaa00" stroke-width="1"/>
<text class="amb" x="655" y="453">x += 5 --> 6 + 5 = 11</text>
<!-- Bottom -->
<rect class="pnl" x="30" y="495" width="1140" height="120" rx="8"/>
<text class="sub" x="50" y="530">In Our Code (x=6, y=10)</text>
<rect x="50" y="545" width="1100" height="50" rx="6" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="cyn" x="70" y="575">int bitwise = (x&lt;&lt;1);</text>
<text class="dim" x="500" y="575">6 &lt;&lt; 1 = 12 (0b0110 --> 0b1100)</text>
<!-- Binary output preview -->
<rect class="pnl" x="30" y="630" width="1140" height="110" rx="8"/>
<text class="sub" x="50" y="665">Expected Output</text>
<text class="txt" x="50" y="700">bitwise_operator: 12</text>
<text class="txt" x="470" y="700">assignment_operator: 11</text>
<text class="dim" x="50" y="725">Both pre-computed by compiler as immediates</text>
</svg>

After

Width:  |  Height:  |  Size: 4.4 KiB

+72
View File
@@ -0,0 +1,72 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<rect class="hdr" x="0" y="0" width="1200" height="100" rx="0"/>
<text class="title" x="600" y="52" text-anchor="middle">DHT11 Sensor</text>
<text class="dim" x="600" y="88" text-anchor="middle">Single-Wire Temperature and Humidity</text>
<!-- Left: Pinout and Specs -->
<rect class="pnl" x="30" y="110" width="555" height="260" rx="8"/>
<text class="sub" x="50" y="145">DHT11 Pinout</text>
<rect x="180" y="165" width="120" height="80" rx="4" fill="#0a0a0f" stroke="#00ff41" stroke-width="2"/>
<text class="grn" x="205" y="212">DHT11</text>
<text class="dim" x="180" y="265">1:VCC 2:DATA 3:NC 4:GND</text>
<text class="dim" x="50" y="300">Humidity: 20-90% RH (+/-5%)</text>
<text class="dim" x="50" y="325">Temp: 0-50C (+/-2C)</text>
<text class="dim" x="50" y="350">Protocol: custom one-wire</text>
<!-- Right: Wiring -->
<rect class="pnl" x="615" y="110" width="555" height="260" rx="8"/>
<text class="sub" x="635" y="145">Wiring to Pico 2</text>
<rect x="635" y="165" width="100" height="45" rx="4" fill="#0a0a0f" stroke="#00d4ff" stroke-width="1"/>
<text class="cyn" x="655" y="194">Pico</text>
<rect x="1040" y="165" width="100" height="45" rx="4" fill="#0a0a0f" stroke="#00ff41" stroke-width="1"/>
<text class="grn" x="1055" y="194">DHT11</text>
<line x1="735" y1="178" x2="1040" y2="178" stroke="#ffaa00" stroke-width="2"/>
<line x1="735" y1="198" x2="1040" y2="198" stroke="#888" stroke-width="2"/>
<text class="dim" x="635" y="230">GPIO 4 = DATA</text>
<text class="dim" x="635" y="255">3.3V = VCC</text>
<text class="dim" x="635" y="280">GND = GND</text>
<!-- Communication Protocol -->
<rect class="pnl" x="635" y="295" width="555" height="75" rx="6"/>
<text class="dim" x="655" y="320">1. Host pulls LOW 18ms</text>
<text class="dim" x="655" y="345">2. DHT11 responds, sends 40 bits</text>
<!-- Source Code -->
<rect class="pnl" x="30" y="385" width="1140" height="380" rx="8"/>
<text class="sub" x="50" y="420">Source Code: 0x001a_operators.c</text>
<rect x="50" y="435" width="1100" height="310" rx="6" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="cyn" x="70" y="465">int x = 5, y = 10;</text>
<text class="txt" x="70" y="495">int arithmetic = (x * y);</text>
<text class="dim" x="530" y="495">// 50</text>
<text class="txt" x="70" y="525">int increment = x++;</text>
<text class="dim" x="530" y="525">// 5 (post)</text>
<text class="txt" x="70" y="555">bool relational = (x &gt; y);</text>
<text class="dim" x="530" y="555">// false</text>
<text class="txt" x="70" y="585">bool logical = (x&gt;y)&amp;&amp;(y&gt;x);</text>
<text class="dim" x="530" y="585">// false</text>
<text class="txt" x="70" y="615">int bitwise = (x&lt;&lt;1);</text>
<text class="dim" x="530" y="615">// 12</text>
<text class="txt" x="70" y="645">int assignment = (x += 5);</text>
<text class="dim" x="530" y="645">// 11</text>
<text class="cyn" x="70" y="680">float hum, temp;</text>
<text class="txt" x="70" y="710">dht11_read(&amp;hum, &amp;temp);</text>
</svg>

After

Width:  |  Height:  |  Size: 3.6 KiB

+75
View File
@@ -0,0 +1,75 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<rect class="hdr" x="0" y="0" width="1200" height="100" rx="0"/>
<text class="title" x="600" y="52" text-anchor="middle">Variable Flow</text>
<text class="dim" x="600" y="88" text-anchor="middle">Tracing x Through Every Operator</text>
<!-- Variable trace table -->
<rect class="pnl" x="30" y="110" width="1140" height="650" rx="8"/>
<text class="sub" x="50" y="150">Tracing x Step-by-Step</text>
<!-- Header row -->
<text class="amb" x="50" y="195">Line</text>
<text class="amb" x="520" y="195">x</text>
<text class="amb" x="640" y="195">Result</text>
<line x1="50" y1="205" x2="1140" y2="205" stroke="#1a1a2e" stroke-width="1"/>
<!-- Row 1: init -->
<text class="cyn" x="50" y="240">int x = 5, y = 10;</text>
<text class="grn" x="520" y="240">5</text>
<text class="dim" x="640" y="240">x initialized to 5</text>
<!-- Row 2: arithmetic -->
<text class="txt" x="50" y="280">int arithmetic = (x * y);</text>
<text class="grn" x="520" y="280">5</text>
<text class="txt" x="640" y="280">arithmetic = 50</text>
<!-- Row 3: post-increment -->
<text class="txt" x="50" y="320">int increment = x++;</text>
<text class="red" x="520" y="320">5-->6</text>
<text class="txt" x="640" y="320">increment = 5</text>
<text class="dim" x="640" y="345">use THEN increment</text>
<!-- Row 4: relational -->
<text class="txt" x="50" y="385">bool relational = (x &gt; y);</text>
<text class="grn" x="520" y="385">6</text>
<text class="txt" x="640" y="385">relational = false</text>
<text class="dim" x="640" y="410">6 &gt; 10 is false</text>
<!-- Row 5: logical -->
<text class="txt" x="50" y="450">bool logical = (x&gt;y)&amp;&amp;(y&gt;x);</text>
<text class="grn" x="520" y="450">6</text>
<text class="txt" x="640" y="450">logical = false</text>
<text class="dim" x="640" y="475">false AND true = false</text>
<!-- Row 6: bitwise -->
<text class="txt" x="50" y="515">int bitwise = (x&lt;&lt;1);</text>
<text class="grn" x="520" y="515">6</text>
<text class="txt" x="640" y="515">bitwise = 12</text>
<text class="dim" x="640" y="540">0b0110 &lt;&lt; 1 = 0b1100</text>
<!-- Row 7: assignment -->
<text class="txt" x="50" y="580">int assignment = (x += 5);</text>
<text class="red" x="520" y="580">6-->11</text>
<text class="txt" x="640" y="580">assignment = 11</text>
<text class="dim" x="640" y="605">6 + 5 = 11</text>
<!-- DHT11 output -->
<line x1="50" y1="635" x2="1140" y2="635" stroke="#1a1a2e" stroke-width="1"/>
<text class="sub" x="50" y="670">DHT11 Output</text>
<text class="grn" x="50" y="705">Humidity: 51.0%</text>
<text class="grn" x="400" y="705">Temperature: 23.8C</text>
<text class="dim" x="50" y="735">dht11_read(&amp;hum, &amp;temp) -- passes addresses so function can write values</text>
</svg>

After

Width:  |  Height:  |  Size: 3.3 KiB

+77
View File
@@ -0,0 +1,77 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<rect class="hdr" x="0" y="0" width="1200" height="100" rx="0"/>
<text class="title" x="600" y="52" text-anchor="middle">Vector Table</text>
<text class="dim" x="600" y="88" text-anchor="middle">Finding Reset_Handler and main()</text>
<!-- Vector Table Structure -->
<rect class="pnl" x="30" y="110" width="555" height="280" rx="8"/>
<text class="sub" x="50" y="150">ARM Vector Table</text>
<text class="dim" x="50" y="178">Base address: 0x10000000</text>
<text class="amb" x="50" y="215">Offset</text>
<text class="amb" x="180" y="215">Contents</text>
<text class="amb" x="400" y="215">Purpose</text>
<line x1="50" y1="225" x2="565" y2="225" stroke="#1a1a2e" stroke-width="1"/>
<text class="grn" x="50" y="255">0x00</text>
<text class="txt" x="180" y="255">Initial SP</text>
<text class="dim" x="400" y="255">Stack ptr</text>
<text class="grn" x="50" y="290">0x04</text>
<text class="cyn" x="180" y="290">Reset_Handler</text>
<text class="dim" x="400" y="290">Entry point</text>
<text class="grn" x="50" y="325">0x08</text>
<text class="txt" x="180" y="325">NMI_Handler</text>
<text class="dim" x="400" y="325">NMI</text>
<text class="grn" x="50" y="360">0x0C</text>
<text class="txt" x="180" y="360">HardFault</text>
<text class="dim" x="400" y="360">Fault</text>
<!-- Little-Endian + Thumb Bit -->
<rect class="pnl" x="615" y="110" width="555" height="280" rx="8"/>
<text class="sub" x="635" y="150">Decoding the Address</text>
<text class="txt" x="635" y="190">At 0x10000004:</text>
<text class="grn" x="635" y="225">Bytes: 5d 01 00 10</text>
<text class="amb" x="635" y="265">Step 1: Reverse (little-endian)</text>
<text class="txt" x="635" y="295">10 00 01 5d = 0x1000015d</text>
<text class="amb" x="635" y="330">Step 2: Remove Thumb bit</text>
<text class="txt" x="635" y="360">0x1000015d - 1 = 0x1000015c</text>
<!-- Reset_Handler Flow -->
<rect class="pnl" x="30" y="410" width="1140" height="350" rx="8"/>
<text class="sub" x="50" y="450">Reset_Handler --> main()</text>
<text class="dim" x="50" y="485">Reset_Handler at 0x1000015c calls 3 functions:</text>
<rect x="50" y="505" width="1100" height="230" rx="6" fill="#0a0a0f" stroke="#1a1a2e"/>
<text class="txt" x="70" y="540">Call 1: some_init()</text>
<text class="dim" x="450" y="540">Hardware initialization</text>
<text class="cyn" x="70" y="580">Call 2: main()</text>
<text class="amb" x="450" y="580">THIS IS WHAT WE WANT</text>
<text class="dim" x="450" y="605">Address: 0x10000234</text>
<text class="txt" x="70" y="645">Call 3: exit()</text>
<text class="dim" x="450" y="645">Never returns</text>
<text class="dim" x="70" y="685">The MIDDLE function call is always main()</text>
<text class="dim" x="70" y="710">Navigate to 0x10000234 in Ghidra to find it</text>
</svg>

After

Width:  |  Height:  |  Size: 3.4 KiB

+81
View File
@@ -0,0 +1,81 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<rect class="hdr" x="0" y="0" width="1200" height="100" rx="0"/>
<text class="title" x="600" y="52" text-anchor="middle">IEEE-754 Floats</text>
<text class="dim" x="600" y="88" text-anchor="middle">How Computers Store Decimal Numbers</text>
<!-- Float Layout Diagram -->
<rect class="pnl" x="30" y="110" width="1140" height="190" rx="8"/>
<text class="sub" x="50" y="150">32-bit Float Structure</text>
<!-- Bit field boxes -->
<rect x="50" y="170" width="80" height="50" rx="4" fill="#ff0040" fill-opacity="0.2" stroke="#ff0040"/>
<text class="red" x="70" y="202">S</text>
<text class="dim" x="55" y="240">1 bit</text>
<rect x="150" y="170" width="320" height="50" rx="4" fill="#ffaa00" fill-opacity="0.2" stroke="#ffaa00"/>
<text class="amb" x="260" y="202">Exponent</text>
<text class="dim" x="270" y="240">8 bits</text>
<rect x="490" y="170" width="660" height="50" rx="4" fill="#00d4ff" fill-opacity="0.2" stroke="#00d4ff"/>
<text class="cyn" x="740" y="202">Mantissa (Fraction)</text>
<text class="dim" x="760" y="240">23 bits</text>
<text class="dim" x="50" y="280">Value = (-1)^S x (1 + Mantissa) x 2^(Exponent - 127)</text>
<!-- Example: Decoding 0.1f -->
<rect class="pnl" x="30" y="320" width="1140" height="220" rx="8"/>
<text class="sub" x="50" y="360">Example: Decoding 0.1f</text>
<text class="txt" x="50" y="400">Little-endian bytes:</text>
<text class="grn" x="380" y="400">cd cc cc 3d</text>
<text class="txt" x="50" y="435">Reversed (big-endian):</text>
<text class="grn" x="380" y="435">0x3dcccccd</text>
<text class="amb" x="50" y="475">Sign: 0</text>
<text class="amb" x="250" y="475">Exp: 01111011 = 123</text>
<text class="amb" x="580" y="475">Mantissa: 1001100...</text>
<text class="txt" x="50" y="510">Exp - 127 = -4, so value = 1.6 x 2^(-4)</text>
<text class="grn" x="680" y="510">= 0.1</text>
<!-- Float Reference Table -->
<rect class="pnl" x="30" y="560" width="1140" height="200" rx="8"/>
<text class="sub" x="50" y="600">IEEE-754 Quick Reference</text>
<text class="amb" x="50" y="635">Value</text>
<text class="amb" x="200" y="635">Hex</text>
<text class="amb" x="430" y="635">Bytes (LE)</text>
<line x1="50" y1="645" x2="1140" y2="645" stroke="#1a1a2e" stroke-width="1"/>
<text class="txt" x="50" y="675">0.1</text>
<text class="grn" x="200" y="675">0x3dcccccd</text>
<text class="dim" x="430" y="675">cd cc cc 3d</text>
<text class="txt" x="700" y="675">1.0</text>
<text class="grn" x="820" y="675">0x3f800000</text>
<text class="dim" x="1020" y="675">00 00 80 3f</text>
<text class="txt" x="50" y="710">5.0</text>
<text class="grn" x="200" y="710">0x40a00000</text>
<text class="dim" x="430" y="710">00 00 a0 40</text>
<text class="txt" x="700" y="710">10.0</text>
<text class="grn" x="820" y="710">0x41200000</text>
<text class="dim" x="1020" y="710">00 00 20 41</text>
<text class="txt" x="50" y="740">-1.0</text>
<text class="grn" x="200" y="740">0xbf800000</text>
<text class="dim" x="430" y="740">00 00 80 bf</text>
</svg>

After

Width:  |  Height:  |  Size: 3.6 KiB

+64
View File
@@ -0,0 +1,64 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<rect class="hdr" x="0" y="0" width="1200" height="100" rx="0"/>
<text class="title" x="600" y="52" text-anchor="middle">Hacking the Float</text>
<text class="dim" x="600" y="88" text-anchor="middle">Changing the DHT11 Scaling Constant</text>
<!-- DHT11 Scaling Formula -->
<rect class="pnl" x="30" y="110" width="1140" height="150" rx="8"/>
<text class="sub" x="50" y="150">DHT11 Scaling Calculation</text>
<text class="txt" x="50" y="190">result = integer + (decimal x 0.1)</text>
<text class="dim" x="50" y="218">Example: temp = 23 + (8 x 0.1) = 23.8C</text>
<text class="amb" x="700" y="190">0.1f is our target!</text>
<!-- Key Offsets -->
<rect class="pnl" x="30" y="280" width="1140" height="200" rx="8"/>
<text class="sub" x="50" y="320">Key Offsets in Binary</text>
<text class="amb" x="50" y="360">Offset</text>
<text class="amb" x="200" y="360">Bytes</text>
<text class="amb" x="480" y="360">Meaning</text>
<line x1="50" y1="370" x2="1140" y2="370" stroke="#1a1a2e" stroke-width="1"/>
<text class="grn" x="50" y="400">0x410</text>
<text class="txt" x="200" y="400">a6 ee 25 7a</text>
<text class="dim" x="480" y="400">vfma.f32 s14,s12,s11 (humidity)</text>
<text class="grn" x="50" y="435">0x414</text>
<text class="txt" x="200" y="435">e6 ee a5 7a</text>
<text class="dim" x="480" y="435">vfma.f32 s15,s13,s11 (temp)</text>
<text class="red" x="50" y="470">0x42C</text>
<text class="cyn" x="200" y="470">cd cc cc 3d</text>
<text class="amb" x="480" y="470">0.1f -- the scaling constant</text>
<!-- The Hack -->
<rect class="pnl" x="30" y="500" width="1140" height="260" rx="8"/>
<text class="sub" x="50" y="540">The Hack: 0.1f --> 5.0f</text>
<text class="txt" x="50" y="580">At offset 0x42C, change:</text>
<rect x="50" y="600" width="500" height="50" rx="6" fill="#0a0a0f" stroke="#ff0040"/>
<text class="red" x="70" y="632">Original: cd cc cc 3d</text>
<text class="dim" x="380" y="632">(0.1f)</text>
<rect x="600" y="600" width="500" height="50" rx="6" fill="#0a0a0f" stroke="#00ff41"/>
<text class="grn" x="620" y="632">Patched: 00 00 a0 40</text>
<text class="dim" x="930" y="632">(5.0f)</text>
<text class="txt" x="50" y="685">New result: 23 + (8 x 5.0) = 63.0C</text>
<text class="dim" x="50" y="715">Decimal part is now multiplied by 5.0 instead of 0.1</text>
<text class="dim" x="50" y="740">Export .bin from Ghidra, convert to UF2, flash to Pico</text>
</svg>

After

Width:  |  Height:  |  Size: 3.0 KiB

+97
View File
@@ -0,0 +1,97 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<rect class="hdr" x="0" y="0" width="1200" height="100" rx="0"/>
<text class="title" x="600" y="52" text-anchor="middle">Operators &amp; DHT11 Hacking</text>
<text class="dim" x="600" y="88" text-anchor="middle">Operators, DHT11, IEEE-754, and Hacking</text>
<!-- Left: 6 Operator Types -->
<rect class="pnl" x="30" y="110" width="555" height="280" rx="8"/>
<text class="sub" x="50" y="150">6 Operator Types</text>
<text class="grn" x="50" y="185">Arithmetic</text>
<text class="dim" x="260" y="185">x * y = 50</text>
<text class="grn" x="50" y="215">Increment</text>
<text class="dim" x="260" y="215">x++ returns 5, x becomes 6</text>
<text class="grn" x="50" y="245">Relational</text>
<text class="dim" x="260" y="245">(6 &gt; 10) = false</text>
<text class="grn" x="50" y="275">Logical</text>
<text class="dim" x="260" y="275">false &amp;&amp; true = false</text>
<text class="grn" x="50" y="305">Bitwise</text>
<text class="dim" x="260" y="305">6 &lt;&lt; 1 = 12</text>
<text class="grn" x="50" y="335">Assignment</text>
<text class="dim" x="260" y="335">x += 5 = 11</text>
<text class="dim" x="50" y="370">Post-increment: use THEN increment</text>
<!-- Right: Key Addresses -->
<rect class="pnl" x="615" y="110" width="555" height="280" rx="8"/>
<text class="sub" x="635" y="150">Key Addresses</text>
<text class="cyn" x="635" y="190">0x10000000</text>
<text class="dim" x="870" y="190">Vector table</text>
<text class="cyn" x="635" y="225">0x10000004</text>
<text class="dim" x="870" y="225">Reset_Handler addr</text>
<text class="cyn" x="635" y="260">0x10000234</text>
<text class="dim" x="870" y="260">main()</text>
<text class="cyn" x="635" y="295">0x10000410</text>
<text class="dim" x="870" y="295">Humidity vfma</text>
<text class="cyn" x="635" y="330">0x10000414</text>
<text class="dim" x="870" y="330">Temp vfma</text>
<text class="red" x="635" y="365">0x1000042C</text>
<text class="dim" x="870" y="365">0.1f constant (hack)</text>
<!-- IEEE-754 -->
<rect class="pnl" x="30" y="410" width="555" height="160" rx="8"/>
<text class="sub" x="50" y="450">IEEE-754 Format</text>
<text class="txt" x="50" y="485">S(1) + Exp(8) + Mantissa(23)</text>
<text class="dim" x="50" y="515">(-1)^S x (1+M) x 2^(E-127)</text>
<text class="dim" x="50" y="545">0.1f = 0x3dcccccd = cd cc cc 3d</text>
<!-- Hack Workflow -->
<rect class="pnl" x="615" y="410" width="555" height="160" rx="8"/>
<text class="sub" x="635" y="450">Hack Workflow</text>
<text class="txt" x="635" y="485">1. Analyze in Ghidra</text>
<text class="txt" x="635" y="515">2. Find float at 0x42C</text>
<text class="txt" x="635" y="545">3. Patch cd cc cc 3d</text>
<!-- Bottom: Steps -->
<rect class="pnl" x="30" y="590" width="1140" height="170" rx="8"/>
<text class="sub" x="50" y="630">Binary Hacking Steps</text>
<text class="amb" x="50" y="665">Analyze</text>
<text class="txt" x="200" y="665">--></text>
<text class="amb" x="260" y="665">Identify</text>
<text class="txt" x="410" y="665">--></text>
<text class="amb" x="470" y="665">Offset</text>
<text class="txt" x="600" y="665">--></text>
<text class="amb" x="660" y="665">Patch</text>
<text class="txt" x="790" y="665">--></text>
<text class="amb" x="850" y="665">Export</text>
<text class="txt" x="990" y="665">--></text>
<text class="amb" x="1050" y="665">Test</text>
<text class="dim" x="50" y="700">Project: 0x001a_operators</text>
<text class="dim" x="50" y="730">Source: 0x001a_operators.c with DHT11 sensor on GPIO 4</text>
</svg>

After

Width:  |  Height:  |  Size: 4.1 KiB

+8 -8
View File
@@ -875,17 +875,17 @@ Create a mental (or written) map:
+-----------------------------------------------------------------+
| Struct Member Mapping |
| |
| Assembly Value -> Struct Member -> Physical LED |
| Assembly Value -> Struct Member -> Physical LED |
| ------------------------------------------------------------- |
| 0x10 (16) -> led1_pin -> Red LED |
| 0x11 (17) -> led2_pin -> Green LED |
| 0x12 (18) -> led3_pin -> Yellow LED |
| 0x10 (16) -> led1_pin -> Red LED |
| 0x11 (17) -> led2_pin -> Green LED |
| 0x12 (18) -> led3_pin -> Yellow LED |
| |
| NEC Code -> State Member -> Action |
| NEC Code -> State Member -> Action |
| ------------------------------------------------------------- |
| 0x0C -> led1_state=true -> Red LED ON |
| 0x18 -> led2_state=true -> Green LED ON |
| 0x5E -> led3_state=true -> Yellow LED ON |
| 0x0C -> led1_state=true -> Red LED ON |
| 0x18 -> led2_state=true -> Green LED ON |
| 0x5E -> led3_state=true -> Yellow LED ON |
| |
+-----------------------------------------------------------------+
```