mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-17 11:11:10 +02:00
Validate save imports by main-data checksum, not raw file size
The SAVE FILES card only accepted saves of exactly 32768 bytes and refused anything else. importToSlot now classifies a non-32768 file by the integrity of its main-data checksum instead: - Oversize + valid checksum -> an emulator RTC footer, so the launcher asks for confirmation, then truncates to 32768 on force. - Oversize + invalid checksum -> rejected. - Undersize + valid checksum -> imports zero-padded; otherwise refused. Adds the "Oversized save file" confirm modal, a new vendor-oracle test built by gen1lib (PKHeX-derived) run as its own Lua 5.4 tier, oversize/ truncated policy tests, and the LUA54 wiring in test.sh. # Conflicts: # src/import/LauncherView.lua
This commit is contained in:
@@ -190,6 +190,18 @@ local function checksum(bytes, from, to)
|
||||
return bit.band(bit.bnot(sum), 0xFF)
|
||||
end
|
||||
|
||||
-- Main-data checksum gate used before an import policy is decided. Returns
|
||||
-- nil when the buffer is too short to even carry the stored checksum byte
|
||||
-- (offset O.mainChecksum, the last byte of wMainData), false on a mismatch,
|
||||
-- true when it matches. Works on any length >= O.mainChecksum + 1, so a
|
||||
-- caller can classify a truncated or footer-padded file without a full
|
||||
-- decode -- the checksummed region (0x2598..0x3522) always sits entirely
|
||||
-- inside the first 0x3524 bytes of a save.
|
||||
function GenSave.mainChecksumValid(bytes)
|
||||
if #bytes < O.mainChecksum + 1 then return nil end
|
||||
return checksum(bytes, O.checksumStart, O.checksumEnd) == u8(bytes, O.mainChecksum)
|
||||
end
|
||||
|
||||
-- flag_array packs LSB-first within each byte (bit 0 of byte 0 = index 0).
|
||||
-- This is pokered's runtime FlagAction convention (home/predef macros): it
|
||||
-- takes flag number N, addresses byte N/8, and builds the mask by rotating
|
||||
|
||||
@@ -25,6 +25,7 @@ local GenSave = require("src.save_convert.GenSave")
|
||||
local SaveConvert = {}
|
||||
|
||||
SaveConvert.SAVE_SIZE = GenSave.SAVE_SIZE
|
||||
SaveConvert.mainChecksumValid = GenSave.mainChecksumValid
|
||||
|
||||
-- ------------------------------------------------------------------
|
||||
-- Crosswalk data loading (cached). Mirrors src/core/Data.lua: prefer
|
||||
|
||||
Reference in New Issue
Block a user