tft: all four checksums solved (three header CRCs, trailer for any length)

0x44 = CRC of the resource area, 0xC4 = CRC of header [0,0xC4), 0x18C = CRC of
[0xC8,0x18C); trailer = CRC of the whole file ^ (len & 0xFF) ^ 0x56. tft.seal()
recomputes all of them. Verified against 24 Editor-made files of 8 lengths.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Fable 5.2 committed 2026-11-16 16:54:59 +01:00
1 parent 6b2835334a
commit 7337e693a5
6 files changed
+124 -22

No files matched your search

+1 -1
View File
@@ -18,7 +18,7 @@ src/nxhmi/
pictures.py N.i / N.is pictures.py N.i / N.is
fonts.py .zi v6 fonts, generation from TrueType fonts.py .zi v6 fonts, generation from TrueType
render.py page renderer matching the Editor canvas render.py page renderer matching the Editor canvas
tft.py .tft research helpers (layout table, same-length trailer patch) tft.py .tft research helpers (layout table, header checksums, trailer, seal)
cli.py python -m nxhmi ... cli.py python -m nxhmi ...
mcp_server.py MCP server (stdio JSON-RPC, no deps) -- tools for Claude incl. render_page images mcp_server.py MCP server (stdio JSON-RPC, no deps) -- tools for Claude incl. render_page images
examples/make_demo.py builds demo/ (demo.HMI, decoded/, render/) examples/make_demo.py builds demo/ (demo.HMI, decoded/, render/)
+1 -1
View File
@@ -32,7 +32,7 @@ Every percentage is a count with a stated basis, so it can be checked (details i
| Readable attribute names in JSON | **100 %** (31/31 types) | every value list the Editor documents, incl. the Intelligent-only types and load effects | | Readable attribute names in JSON | **100 %** (31/31 types) | every value list the Editor documents, incl. the Intelligent-only types and load effects |
| Rendering, Basic components | **100 %** (20/20 pixel-exact) | incl. gauges and QR codes (own encoder, no dependencies) | | Rendering, Basic components | **100 %** (20/20 pixel-exact) | incl. gauges and QR codes (own encoder, no dependencies) |
| Rendering, all components | **94 %** (29/31 pixel-exact) | Intelligent ComboBox and Switch are drawn, but their anti-aliased edges are approximate (~99 % / ~92 % of pixels exact) | | Rendering, all components | **94 %** (29/31 pixel-exact) | Intelligent ComboBox and Switch are drawn, but their anti-aliased edges are approximate (~99 % / ~92 % of pixels exact) |
| `.tft` compilation | **31 %** (2.5/8 milestones) | layout mapped, layout table decoded, trailer checksum (same-length edits only); not usable yet | | `.tft` compilation | **50 %** (4/8 milestones) | layout mapped, layout table decoded, all four checksums solved (any length); page format not yet, so not usable |
## Compatibility ## Compatibility
+4 -4
View File
@@ -29,7 +29,7 @@ byte for byte, or a file written by nxhmi was opened in the Editor and showed th
- **Rendering**: a component type counts as covered when every test case of it is pixel-identical - **Rendering**: a component type counts as covered when every test case of it is pixel-identical
to the Editor canvas (name tags and selection outline excluded). Invisible types (timer, to the Editor canvas (name tags and selection outline excluded). Invisible types (timer,
variable, hotspot, touch cap) count when they draw nothing, like the Editor. variable, hotspot, touch cap) count when they draw nothing, like the Editor.
- **`.tft` milestones** (8): layout map; layout table; trailer checksum (half: same-length only); - **`.tft` milestones** (8): layout map; layout table; trailer checksum;
the three header checksums; compiled page/component format; event-code tokens; pictures and fonts the three header checksums; compiled page/component format; event-code tokens; pictures and fonts
in the TFT; a builder that produces a file the display accepts. in the TFT; a builder that produces a file the display accepts.
@@ -110,13 +110,13 @@ byte for byte, or a file written by nxhmi was opened in the Editor and showed th
|---|---| |---|---|
| File layout | mapped (header, embedded Nextion files, project section, trailer) | | File layout | mapped (header, embedded Nextion files, project section, trailer) |
| Layout table | decoded (fixed XOR key) | | Layout table | decoded (fixed XOR key) |
| Trailer checksum | works for same-length edits; **unknown for different lengths** (stuck) | | Trailer checksum | solved for any length (`tft.trailer`); one model measured |
| 3 header checksums (0x44, 0xC4, 0x18C) | not analysed | | 3 header checksums (0x44, 0xC4, 0x18C) | solved (`tft.header_checksums`, `tft.seal`) |
| Compiled page format, event-code tokens | first look only | | Compiled page format, event-code tokens | first look only |
| Pictures and fonts inside the TFT | not analysed | | Pictures and fonts inside the TFT | not analysed |
| Licensing | every `.tft` embeds Nextion's firmware files; the repo must never ship them -- a builder would read them from the user's own Editor installation | | Licensing | every `.tft` embeds Nextion's firmware files; the repo must never ship them -- a builder would read them from the user's own Editor installation |
## Suggested next steps ## Suggested next steps
1. `.tft`: try the remaining trailer-checksum ideas listed in NOTES.md; then the compiled page format. 1. `.tft`: the compiled page/component format and the event-code token table (see NOTES.md).
2. The anti-aliasing routine of Intelligent rounded shapes (switch knob/track, ComboBox). 2. The anti-aliasing routine of Intelligent rounded shapes (switch knob/track, ComboBox).
3. The premultiplied-alpha colour step for transparent JPEG pictures (a few levels off). 3. The premultiplied-alpha colour step for transparent JPEG pictures (a few levels off).
+25 -10
View File
@@ -104,14 +104,29 @@ ending right before the trailer -- proved on two independent one-change pairs. C
**same-length edits can be re-checksummed** (`nxhmi.tft.patch_trailer`, reproduces the Editor's **same-length edits can be re-checksummed** (`nxhmi.tft.patch_trailer`, reproduces the Editor's
output byte for byte for a colour change and for `dim=50` -> `dim=51`). output byte for byte for a colour change and for `dim=50` -> `dim=51`).
**STUCK (2026-11-15):** start offset / seed of the trailer CRC across files of different lengths. ### All four checksums solved (2026-11-16)
Tried, all without a fit (three minimal files of different lengths + the 6-page project):
every start offset 0..end with a constant seed (solved exactly by GF(2) linear algebra); seeds
taken from header fields 0x44/0xC4/0x18C (raw, inverted, LE/BE); the header checksum fields
zeroed or 0xFF in every combination; the layout table de-obfuscated before checksumming.
Ideas not yet tried: the stream skipping a region whose size varies (e.g. FF padding after the
page data); a seed derived from file size or layout words; the trailer covering only the
project section in a different order (e.g. pages then the zero area).
Not started: the 3 header checksums, the compiled page format (component records, the token All are the word-per-byte CRC with seed 0xFFFFFFFF (`nxhmi.tft.header_checksums`, `trailer`,
table for event code), pictures/fonts inside the TFT. `seal`); verified on every sample (two layouts, 0x40000 and 0x90000 resource areas):
| Where | Covers |
|---|---|
| 0x44 | the resource area `[0x10000, 0x10000 + u32@0x40)` -- firmware files, pictures, fonts. Constant for all picture-less projects of one model, which is why it looked "layout only" |
| 0xC4 | header `[0x00, 0xC4)` (includes 0x44) |
| 0x18C | `[0xC8, 0x18C)`: the layout table as stored (XORed) and the FF padding after it |
| last 4 bytes | the whole file before the trailer, then XOR `(file length & 0xFF) ^ 0x56` |
Why the trailer resisted: the stream and seed were the obvious ones all along, but the result
is XORed with a byte that depends on the file length, so every "constant seed" search failed.
What cracked it: compute, per file, the seed that a from-offset-0 CRC would need (run the CRC
backwards from the trailer). Files of equal length needed the same seed even with different
headers -> the header is in the stream as-is and only the length matters; then
`trailer ^ CRC(file)` turned out to be a single byte, `len & 0xFF ^ 0x56`, on all eight lengths
seen (low bytes D8 E0 E4 E8 EC F0 00 C0). **OPEN:** whether 0x56 is model-specific (only
NX4832T035 measured), and whether more than the low length byte takes part.
The file length is always a multiple of 4 (the page section is padded with zeros).
Other dead ends, for the record: seeds from header fields; header checksum fields zeroed/0xFF in
every combination; the layout table de-obfuscated before checksumming; prefixes built from
length/layout words; runs of 00/FF bytes before the file.
+62 -6
View File
@@ -3,17 +3,17 @@
Only what is verified is implemented here: Only what is verified is implemented here:
* the obfuscated layout table at 0xC8..0x113 is XOR 0xEBAB2932 per 32-bit word; * the obfuscated layout table at 0xC8..0x113 is XOR 0xEBAB2932 per 32-bit word;
* the trailer (last 4 bytes, LE) is a word-per-byte CRC whose stream ends at the trailer -- so * the three header checksums (:func:`header_checksums`) and the trailer (:func:`trailer`) are
for edits that keep the file length, the trailer can be updated by linearity word-per-byte CRCs; :func:`seal` recomputes all four.
(:func:`patch_trailer`). Building a .tft from scratch is not possible yet: the trailer's start
offset / seed are unknown, and every .tft embeds Nextion's own firmware files, which this Every .tft embeds Nextion's own firmware files, which this project does not and must not
project does not and must not distribute. distribute.
""" """
from __future__ import annotations from __future__ import annotations
import struct import struct
from .checksum import _feed_byte_as_word, _feed_word from .checksum import _feed_byte_as_word, _feed_word, word_per_byte_crc
LAYOUT_KEY = 0xEBAB2932 LAYOUT_KEY = 0xEBAB2932
LAYOUT_START, LAYOUT_END = 0xC8, 0x114 LAYOUT_START, LAYOUT_END = 0xC8, 0x114
@@ -34,6 +34,62 @@ def header_info(tft: bytes) -> dict:
} }
RES_START = 0x10000 # resource area: firmware files, pictures, fonts
OFF_RES_SIZE, OFF_RES_CRC, OFF_HEAD1_CRC, OFF_HEAD2_CRC = 0x40, 0x44, 0xC4, 0x18C
def header_checksums(tft: bytes) -> dict:
"""The three header checksums as they should be (all word-per-byte CRCs, seed 0xFFFFFFFF):
* 0x44 -- over the resource area ``[0x10000, 0x10000 + u32@0x40)``;
* 0xC4 -- over header bytes ``[0x00, 0xC4)`` (so it includes the value at 0x44);
* 0x18C -- over ``[0xC8, 0x18C)``, the layout table as stored (still XORed) plus its padding.
"""
res_size = struct.unpack_from("<I", tft, OFF_RES_SIZE)[0]
res = word_per_byte_crc(tft[RES_START:RES_START + res_size])
head1 = bytearray(tft[:OFF_HEAD1_CRC])
struct.pack_into("<I", head1, OFF_RES_CRC, res)
return {
OFF_RES_CRC: res,
OFF_HEAD1_CRC: word_per_byte_crc(bytes(head1)),
OFF_HEAD2_CRC: word_per_byte_crc(tft[LAYOUT_START:OFF_HEAD2_CRC]),
}
def verify_header(tft: bytes) -> bool:
return all(struct.unpack_from("<I", tft, o)[0] == v for o, v in header_checksums(tft).items())
def fix_header(tft: bytes) -> bytes:
"""Return ``tft`` with the three header checksums recomputed (the trailer is left alone)."""
out = bytearray(tft)
for o, v in header_checksums(tft).items():
struct.pack_into("<I", out, o, v)
return bytes(out)
TRAILER_XOR = 0x56
def trailer(tft: bytes) -> int:
"""The file checksum that belongs in the last 4 bytes (LE) of ``tft`` (whose last 4 bytes are
ignored): the word-per-byte CRC (seed 0xFFFFFFFF) of everything before the trailer, XORed with
``(file length & 0xFF) ^ 0x56``. Measured on files of eight different lengths, one display model
(NX4832T035); whether 0x56 depends on the model is not known."""
n = len(tft)
return word_per_byte_crc(tft[:n - 4]) ^ (n & 0xFF) ^ TRAILER_XOR
def verify_trailer(tft: bytes) -> bool:
return struct.unpack_from("<I", tft, len(tft) - 4)[0] == trailer(tft)
def seal(tft: bytes) -> bytes:
"""Recompute every checksum of a .tft image: the three header checksums, then the trailer."""
out = fix_header(tft)
return out[:-4] + struct.pack("<I", trailer(out))
def _zero_words(n: int, c: int) -> int: def _zero_words(n: int, c: int) -> int:
for _ in range(n): for _ in range(n):
c = _feed_word(c, 0) c = _feed_word(c, 0)
+31
View File
@@ -23,6 +23,21 @@ def fake_tft(payload: bytes) -> bytes:
return body + struct.pack("<I", bitwise_word_crc(body, 0x12345678)) return body + struct.pack("<I", bitwise_word_crc(body, 0x12345678))
def sealed_tft(resources: bytes, pages: bytes) -> bytes:
"""A synthetic image with all four checksums computed by the independent bitwise CRC."""
head = bytearray(b"\xff" * tft.RES_START)
head[:0x200] = bytes(0x200)
struct.pack_into("<I", head, tft.OFF_RES_SIZE, len(resources))
for i, o in enumerate(range(tft.LAYOUT_START, tft.LAYOUT_END, 4)):
struct.pack_into("<I", head, o, (i * 7) ^ tft.LAYOUT_KEY)
struct.pack_into("<I", head, tft.OFF_RES_CRC, bitwise_word_crc(resources, 0xFFFFFFFF))
struct.pack_into("<I", head, tft.OFF_HEAD1_CRC, bitwise_word_crc(bytes(head[:0xC4]), 0xFFFFFFFF))
struct.pack_into("<I", head, tft.OFF_HEAD2_CRC, bitwise_word_crc(bytes(head[0xC8:0x18C]), 0xFFFFFFFF))
body = bytes(head) + resources + pages
n = len(body) + 4
return body + struct.pack("<I", bitwise_word_crc(body, 0xFFFFFFFF) ^ (n & 0xFF) ^ 0x56)
class Tft(unittest.TestCase): class Tft(unittest.TestCase):
def test_layout_table(self): def test_layout_table(self):
t = fake_tft(b"x" * 10) t = fake_tft(b"x" * 10)
@@ -35,6 +50,22 @@ class Tft(unittest.TestCase):
expect = fake_tft(b"page data: colour 00 f8") expect = fake_tft(b"page data: colour 00 f8")
self.assertEqual(tft.patch_trailer(old, new_body + b"\0\0\0\0"), expect) self.assertEqual(tft.patch_trailer(old, new_body + b"\0\0\0\0"), expect)
def test_checksums_and_seal(self):
# rules measured on Editor output: 0x44 = CRC of the resource area, 0xC4 = CRC of
# [0, 0xC4), 0x18C = CRC of [0xC8, 0x18C), trailer = CRC of the file ^ (len & 0xFF) ^ 0x56
good = sealed_tft(b"firmware and pictures", b"page data, any length!")
self.assertTrue(tft.verify_header(good))
self.assertTrue(tft.verify_trailer(good))
broken = bytearray(good)
for o in (tft.OFF_RES_CRC, tft.OFF_HEAD1_CRC, tft.OFF_HEAD2_CRC, len(good) - 4):
broken[o] ^= 0x5A
self.assertFalse(tft.verify_header(bytes(broken)))
self.assertFalse(tft.verify_trailer(bytes(broken)))
self.assertEqual(tft.seal(bytes(broken)), good)
# a different length changes the trailer's XOR byte
longer = sealed_tft(b"firmware and pictures", b"page data, any length!!!")
self.assertEqual(tft.seal(longer[:-4] + b"\0\0\0\0"), longer)
def test_patch_trailer_rejects_length_change(self): def test_patch_trailer_rejects_length_change(self):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
tft.patch_trailer(b"\0" * 20, b"\0" * 24) tft.patch_trailer(b"\0" * 20, b"\0" * 24)