Skip to content

Fixed a bug when calculating USB size - #199

Open
Ricca665 wants to merge 293 commits into
nullmoth:mainfrom
Ricca665:main
Open

Ricca665 wants to merge 293 commits into
nullmoth:mainfrom
Ricca665:main

Conversation

@Ricca665

@Ricca665 Ricca665 commented Nov 22, 2026 •

Copy link
Copy Markdown
  • fixed a bug that incorrectly calculated USB size
  • fixed an old unit test that used the old formula

What was wrong
When doing the 32GB Flash drive calculation, Windows uses GiB when calculating size, however reports the size in GB
When the program checked for the size it assumed it was using GB instead of GiB
So for example 1TB gets read by windows as 931GB
This bug therefore prevented real 32GB flash drives from working

What this changes
Corrects the expression
So instead of it doing:
32 * 1024 * 1024 * 1024
it does
31 * 1000 * 1000 * 1000
As windows sees a 32GB flash drive as around 28.9 "GB" (stupid i know)

How I tested it (your PC, the stick, what you ran or did)
MSI Cyborg 15 A13V
32GB Flash drive (Kingston DataTraveler G4)
Ran the project in visual studio, went through and used said 32GB flash drive

Fixes

  • Fixed the bug so now it can use 32GB flash drives.
  • I wrote this change and this description myself (not an AI tool), and I can explain every line.

NullMoth Systems added 30 commits October 31, 2026 17:21
1401: do not erase the stick before Apple will serve the download; finish the Windows hardware map

Measured over the raw write logs users sent on 2026-10-31..11-02 (780 write logs of 16,620
uploads), not over the summarised digest, which truncates each line before its status code:

  HTTP 406 from oscdn        328 logs   323 of them AFTER "OK erased the stick"
  HTTP 405 from osrecovery    11 logs
  HTTP 503 / 502              16 logs   (already retried)
  HTTP 403                     5 logs   (already has a fresh-token path)
  HTTP 400                     2 logs
  HTTP 408                     1 log
  HTTP 416 on a resume         1 log    20 resumes over 15 minutes that could not succeed

333 of the 339 406/405 stops fell inside ONE UTC hour (2026-11-01 09:00-09:59), across six app
versions back to 1.10.0, with zero in the other 61 hours of the window. That is Apple's side
failing for an hour, not a per-network and not a per-version fault. What was ours:

- The chunklist was the download's first request and the download ran after the erase, so 323
  users lost whatever was on their stick to learn that Apple would not serve them. apple.preflight()
  now fetches and verifies the signed chunklist and samples 64 KiB of the image BEFORE the erase,
  and download() reuses those verified bytes instead of asking oscdn a second time. A refusal there
  stops with "your USB stick was not touched".
- 406, 405, 408, 425 and 429 were outside _transient, so each got one request with no back-off and
  no reroute. They are now retried like a 5xx; 406 also tries another edge through DNS-over-HTTPS,
  and 405/406 on osrecovery now take the existing HTTPS route that 400 and 403 already took.
- The stop for those statuses was a bare status and a raw CDN URL. It now says Apple answered that
  way to every try, that waiting is the thing to do, and that nothing was changed - and no longer
  claims the network "keeps cutting the connection", which a 406 is not.
- A 416 on a resume means the server's object ends before the byte we need while Apple's signed
  chunklist says the image is longer, so no retry can satisfy it. It refuses at once and says so.
- The readback stop now names the stick by model and claimed size (never its serial), and tells the
  two faults apart: of 32 readback stops, 16 had 1-19 of 85-92 parts different (a failing write,
  rewritten once, still wrong -> try another port) and 16 had 37-82 different (a stick reporting a
  size it does not have -> use a different stick). 27 of the 32 named a generic controller.
- The read-only refusal says what to do about a lock switch and what it means when there is none.

Windows hardware map, the counterpart of the Mac app's Sources/HardwareMap.swift, finished:

- HardwareMap.cs is wired into the check step as one call site, off the UI thread, writing
  hardware-map.txt beside Report.json so the identifiers travel with every report.
- Added the fields Windows can actually state and the map needed: pci_class (from the CC_ compatible
  ID - the field that says "this is an HD-audio controller"), audio_codec_vendor_device and
  audio_codec_revision (from HDAUDIO ids, the only place Windows names the codec itself),
  usb_class/subclass/protocol, usb_interface_number and hid_usage_page/hid_usage. Every one is a
  fixed-width hex capture from an anchored pattern, so the strict allow-list is unchanged.
- Each WMI object is now disposed, the enumeration is bounded by devices examined and not only by
  devices listed, a damaged WMI repository is reported as a devices_status line rather than thrown,
  and each device line is field-name sorted so two maps of one PC are the same text and can be diffed.
- hardware_map_parse_check.py: 9 arms -> 20, including two negative controls that must fire and two
  arms calibrated on identifiers from real reports. Its fixtures no longer carry a personal name or
  a private LAN address; they use RFC 5737 and IANA documentation values.

HardwareMap.cs is UNBUILT: there is no .NET toolchain on the machine it was written on. It was
reviewed line by line against net48 and C# 7.3 and its parse rules are proven by the Python mirror,
but it has never been compiled and never run against WMI.

Tests: 878 pass (859 before, plus 19 new in tests/test_apple_preflight_status.py), 5 skipped.
usbwriter --selftest 20/20. hardware_map_parse_check 20/20, and it fails when an anchor is removed.
1401: the resume give-up says what was observed instead of blaming the network, and stops being silent

The resume and readback paths already existed, so nothing was added on top of them. This answers the
narrower question: given that resume already runs, what do the give-up reports actually show? Read from
the RAW write logs of 10-31..11-02 (100 resume give-ups among 780 write logs), because the digest
truncates each stop line before the trail that carries the evidence.

  stalled-in-a-row at give-up        20 on ALL 100 (the RESUMES_WINDOWED cap)
  total resumes at give-up           20 on 87, then 21..60 (RESUMES_TOTAL is 400 and was never near)
  never printed a PROGRESS line      83 of 100
  span of the recorded connections   min 968 s, median 1084 s, max 3935 s
  the first full connection gave     exactly 1048576 B on 89 of 100
  the empty answers                  343 of them, EVERY one a well-formed HTTP 206 with
                                     Content-Length 524288 - the window 1401 asked for - and no body
  who answered                       Server nginx on 48 machines, dlb/1.0.2 on 1, Via absent on all 343
  versions                           2.6.6 x54, 2.6.5 x30, 2.6.4 x8, 2.6.2 x3, 2.5.4 x2, 2.0.4 x2, 2.5.5 x1

Three changes, each named by the number that drove it:

- The stop said "Something on this network cuts Apple's download: turn off web/HTTP scanning in your
  antivirus". The 343 empty answers were not cut: the server accepted the range, promised the exact
  length and sent nothing, and no proxy announced itself in a Via header. A scanner cutting a stream
  does not answer 206 and state a Content-Length first. The stop now reports what happened - how many
  connections, how many delivered nothing, how many minutes, what percent - offers the two possible
  causes without claiming which, and orders the three remedies cheapest first (antivirus, then hotspot
  or VPN, then wait an hour because Apple may be busy). Driven by: 343 empty answers, all 206 with
  Content-Length 524288, Via absent on all of them.

- Nothing was printed while this was happening. 83 of 100 give-ups never printed a PROGRESS line, and
  the recorded connections spanned a median of 1084 s, so for 16 to 65 minutes the window showed a bar
  at zero and no text. Each stalled connection now prints one line saying how many in a row have
  delivered nothing, at what percent, and how many are left before it stops. A healthy windowed
  download never reaches that path, so a working write cannot be spammed by it. Driven by: 83 of 100,
  median span 1084 s.

- No log, failed or successful, has ever recorded who answers a download that WORKS, which is the only
  reason "nginx" cannot be told from Apple's own edge. The first connection's Server, Via, X-Cache and
  X-Responding-Server are now logged once, deliberately without calling them Apple's. Driven by: 51 of
  the 100 recorded no headers at all, and the 49 that did had no baseline to be compared against.

Thresholds NOT changed, and this is the restraint the numbers demand: all 100 give-ups stopped at
exactly 20 stalled connections, but every one of those logs is a FAILURE, so they cannot show how often
20 would have recovered. The code's own history records a write that reached 8 MiB after 19 resumes,
which is why the limit is 20 and not 8. A negative-control arm now pins RESUMES, RESUMES_WINDOWED,
RESUMES_TOTAL and WINDOW_MAX_DELAY so a later change has to be argued for rather than drifted into.

Whether "nginx" is Apple's edge or an interposer is UNKNOWN and is left labelled as such in the code
and in the user-facing text.

Tests: 885 pass (878 before, plus 7 arms), 5 skipped. usbwriter --selftest 20/20. The give-up wording
had no test at all before this, which is why it could assert a cause for weeks without being noticed.
Turning it on installs NullMoth's arm64-to-x86 translator package under
/Library/NullMoth/arm: signed manifest, SHA-256 and release signature on the
download, then root copies it into a root-only folder, checks the SHA-256 again
on that copy, unpacks it and runs its installer. Translation runs as the user
with streamed progress and a Cancel that ends the whole process tree; the
translated copy goes to ~/Applications/NullMoth ARM and the original is never
changed. Turning it off runs the package's uninstaller only when root owns it.
Send logs now includes ~/Library/Logs/NullMoth/arm, redacted like every file.
Nothing else in the app changes.
A stick prepared by 1401 for Windows can carry "opt_in": {"arm_apps": true}
in its system profile. After a successful driver install, or at the first
launch after one, 1401 turns ARM apps on through the same verified path as
the button, but only when no decision is recorded yet. Decisions are kept in
Application Support/NullMoth/arm.json with their source; a user who turned
ARM apps off stays off, and a request that fails (CPU, network, signature,
password prompt) installs nothing, shows the reason in the card and is
recorded so it never fires again. The automatic path checks the CPU (x86-64-v2
plus AES) before downloading anything.
1401 Mac: ARM apps request becomes a banner; package checked on one buffer

Nothing installs on its own any more. At the first launch after a driver
install, a 1401 for Windows request with no recorded decision opens Tools
with the ARM card first and a banner: "1401 for Windows set up ARM apps for
this Mac. Press Turn on to finish (your password is needed once)." Turn on
runs the normal signed install; Turn on, Turn off and Not now each record a
decision, so the banner shows once. The CPU is checked first (AES,
PCLMULQDQ, SSE4.2, POPCNT, by features only); a CPU that cannot run
translated apps gets the reason instead of the button.

The package is read into memory once; its SHA-256 and release signature are
checked on that buffer, which is then written atomically, and its digest is
what root re-checks on its private copy. The manifest's name and link must be
nullmoth-arm-<its own version>.tar.gz.
1401 Mac: ARM apps test names the request outcome as an offer, not an install
nm-arm list is read in its object form ({"apps": [...]}), with "output" standing
in for "path" on older builds; a refused remove shows nm-arm's own reason;
the installer's exit codes become plain reasons. The CPU pre-check accepts
PCLMUL in either spelling and leaves an empty sysctl answer to nm-arm check,
which reads CPUID itself.
nm-arm check now carries a "note" when the system seems to hide CPU features
(a virtual machine, for example); the card shows it. The CPU pre-check steps
aside when any of the three sysctl feature lists is blank, since the package
reads CPUID itself then.
A write-page checkbox, off by default and offered only on a stick that carries
the NVIDIA driver. Ticked, the stick's NullMoth/system-profile.json gains
"opt_in": {"arm_apps": true, "from": "1401-windows", "schema": 1}; unticked,
the file is byte-identical to before. The Mac app honours it once after the
driver is set up, through its own signed install and CPU check.
Windows: ARM apps text says the Mac app offers a one-click finish, not an automatic install
The ARM installer ran under the private copy's umask 077 and left /Library/NullMoth root-only, hiding nm-arm from its user. A Mac started with -nvoff now gets the Turn the driver on button even with no install record, and its first-login report names the park instead of filing it as a failed install.
NullMoth Systems and others added 28 commits November 9, 2026 17:00
Mac app: the last two Swift warnings fixed (an unread list, a constant declared variable); every Swift compile in build.sh now stops on a warning
Experimental drivers: the builder places NullMoth's own EFI drivers that fit a PC (keyboard backlight on laptops, NVIDIA display sound with volume on macOS 15) in the EFI switched off; the Mac app switches each on or off there, copies one into an older EFI from the installed driver, and has Select all and Deselect all
Experimental drivers: a driver is copied into the EFI only from the installed package's root-owned folder (no link, nothing another user can write), with no environment override of that folder
Send logs: the reader of fixed-name system logs refuses a link (some of those names are in folders any account can write, and it runs as root)
Recovery targets for 10.7 to 10.12 (board ids and serials from OpenCore's macrecovery list). Releases below 10.13 are built as 10.13 and converted, each change with its source; hardware that cannot run a release is refused with what would work. The stick carries that release's driver kit; the display driver starts and the accelerator stays off until asked for.
Each is marked experimental and passes the opt-in to the engine; Apple's full installer stays for macOS 15 and 26. Messages name the older releases.
Community graphics: every iGPU project claiming Tahoe, and linked downloads

The 2026-11-13 census adds 27 projects (Intel and AMD integrated GPUs) to the
catalogue. A new verdict, linked-download, gives the author's own release file
pinned by URL, size and SHA-256 in the build notice, only on the hardware it
targets, so the user's machine fetches it from its author; nothing is hosted,
bundled or merged. Linked: nullarc 0.4.0-alpha (Phoenix / Hawk Point, never
beside an NVIDIA card because it replaces the Metal plugin path), the Latitude
5350 Meteor Lake package 0.3.21, the X1 Carbon Gen 11 Iris Xe EFI V0.4 and
MyIntelGPU 4.4.121. New notices: RembrandtGfx for an iGPU-only Radeon 680M,
mothbridge-630 for UHD 630 MUX-less laptops.
…tes, sign-off

DEVELOPING.md covers what each part needs, the repository map, the unit tests, the hardware corpus and self-tests,
building the Windows and Mac apps, testing on real hardware, the rules for changes, and where to start.
The new Tests workflow runs the unit tests on every pull request and on main. Issue templates ask for the report
ID and the machine. CONTRIBUTING.md asks for signed-off commits (Developer Certificate of Origin).

The Mac app did not build with Swift 6.4: an unowned capture of self inside a closure that captured self implicitly
is now an error under -warnings-as-errors. The outer closure now captures self explicitly, which keeps the same
ownership as before.
Signed-off-by: Ricca665 <riccy10210@gmail.com>
Signed-off-by: Ricca665 <riccy10210@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant