Weird problem with port of nLaunch CX to the CM boot2

I tried to port nLaunch CX to the CM boot2 (the original version by nLaunch CX guy, because the code is simpler)
The firstloader works, and the preloader seems to work, but there is a strange problem where the main binary, nlaunch.tns, has lots of 00 00 00 00 in the middle of it in random places (like some kind of memory corruption). I can't figure out if it is corrupted when the preloader copies it to /phoenix/install, or if it is corrupted when being loaded.
Can anyone help me? The code is attached (it's a git repo so you can see what I was trying)
The firstloader works, and the preloader seems to work, but there is a strange problem where the main binary, nlaunch.tns, has lots of 00 00 00 00 in the middle of it in random places (like some kind of memory corruption). I can't figure out if it is corrupted when the preloader copies it to /phoenix/install, or if it is corrupted when being loaded.
Can anyone help me? The code is attached (it's a git repo so you can see what I was trying)