Samsung-Loki / Syndical

An alternative to SamLoader - cleaner code, easier to understand and tamper with.
Mozilla Public License 2.0
47 stars 10 forks source link

Decryption fails? #15

Open user8547 opened 8 months ago

user8547 commented 8 months ago

Using latest source code as of 2024-01-05, it is not possible to unzip the downloaded and decrypted firmware:

$ ./TheAirBlow.Syndical.Application -m DownloadDecrypt -v G970FXXSGHWC1/G970FOXMGHWA3/G970FXXSGHWB3 -M SM-G970F -r SEB -I RF8M81TZ4VB -f
Device: SM-G970F/SEB
Firmware: G970FXXSGHWC1/G970FOXMGHWA3/G970FXXSGHWB3/G970FXXSGHWC1
Connecting to FUS server...
Verifying firmware version...
Fetching firmware information...
Initializing download...
Destination: SM-G970F_5_20230303113410_3xhglg47s4_fac.zip
WANRING: No hash check will be performed.
Firmware download & decryption done!                                                                                   

Downloading & Decrypting firmware ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 5.9 GB 43.2 MB/s 00:00:00 00:03:42     

$ unzip SM-G970F_5_20230303113410_3xhglg47s4_fac.zip
Archive:  SM-G970F_5_20230303113410_3xhglg47s4_fac.zip
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of SM-G970F_5_20230303113410_3xhglg47s4_fac.zip or
        SM-G970F_5_20230303113410_3xhglg47s4_fac.zip.zip, and cannot find SM-G970F_5_20230303113410_3xhglg47s4_fac.zip.ZIP, period.
user8547 commented 8 months ago
$ md5sum SM-G970F_5_20230303113410_3xhglg47s4_fac.zip
c4b1969e8b18e89369e2c4985ade54b3  SM-G970F_5_20230303113410_3xhglg47s4_fac.zip
TheRealMrWicked commented 8 months ago

Hey so I am not sure if the problem is with the decryption of the file, but it appears that the header of the zip file has an error in it.

I usually extract these files using 7-Zip on windows and the program has not issue with extracting it, however on Linux using the most common programs (unzip, tar, 7z) all fail to extract it.

But I have found a solution to the issue, you need to fix the archive using the zip program.

Firstly download the program from your repo using the respective package manager:

sudo apt install zip or sudo pacman install zip

Then run the fix command (this may take up to 10 minutes):

zip -FF inputarchive --out outputarchive

Example Usage:

zip -FF SM-G970F_5_20230303113410_3xhglg47s4_fac.zip --out Firmware.zip

Then you can decompress the newly created archive as usual using unzip:

unzip Firmware.zip

Hope this helps you solve the problem.

TheAirBlow commented 8 months ago
$ md5sum SM-G970F_5_20230303113410_3xhglg47s4_fac.zip
c4b1969e8b18e89369e2c4985ade54b3  SM-G970F_5_20230303113410_3xhglg47s4_fac.zip

Check if you get the same corrupted zip when using Bifrost.

This project is basically in maintenance only for now (two new libraries soon), so I'm piggybanking off them.

user8547 commented 8 months ago

Bitfrost after decryption produced a different zip file which unzips fine:

$ md5sum SM-G970F_5_20230303113410_3xhglg47s4_fac_G970FXXSGHWC1_G970FOXMGHWA3_G970FXXSGHWB3_G970FXXSGHWC1_SEB.zip
abe8b002c6394eefd9d2fab4927e5983  SM-G970F_5_20230303113410_3xhglg47s4_fac_G970FXXSGHWC1_G970FOXMGHWA3_G970FXXSGHWB3_G970FXXSGHWC1_SEB.zip

$ unzip SM-G970F_5_20230303113410_3xhglg47s4_fac_G970FXXSGHWC1_G970FOXMGHWA3_G970FXXSGHWB3_G970FXXSGHWC1_SEB.zip 
Archive:  SM-G970F_5_20230303113410_3xhglg47s4_fac_G970FXXSGHWC1_G970FOXMGHWA3_G970FXXSGHWB3_G970FXXSGHWC1_SEB.zip
  inflating: BL_G970FXXSGHWC1_CL25257816_QB62768393_REV01_user_low_ship.tar.md5  
  inflating: AP_G970FXXSGHWC1_CL25257816_QB62768393_REV01_user_low_ship_meta_OS12.tar.md5

TheRealMrWicked: Thank you for looking into it! zip -FF was not able to fix the zip file, but you are correct that 7z on windows is able to decompress that corrupted zip just fine!