[Tool] Samloader (SamFirm / Frija replacement)

Search This thread

nn000

New member
May 27, 2020
1
16
Hello,
I recently wanted to download some firmware for my Samsung device, but I realized that there is no 100% open source program to do so. In fact, all the tools that claim to do so require a library that is packed by Themida (so it is difficult to check what this might be doing), in order to authenticate to the server. This is a native DLL, meaning that it is only compatible with Windows x86. Additionally, many of these tools are actually using stolen decompiled code from SamFirm, which, apart from being possibly illegal, means they would be difficult to maintain and run slowly.
So, I decided to reverse engineer Smart Switch to figure out exactly how the download is taking place, and wrote a cross-platform tool that does this without using the Windows DLL that the other tools have, making it compatible with Linux and MacOS. I also realized that the newer versions are actually using a new version of the authentication algorithm, meaning possibly at some point the old tools might stop working as Samsung drops support for it.
You can find it at:
Code:
https://github.com/nlscc/samloader
To install, go to the downloaded repository and run:
Code:
pip3 install .
See the README or look at the code for usage. You might want to know that my old github account, nm111, was unfortunately deleted, and I lost access to my old XDA account. You can see the verified email is the same however.
Feel free to use the algorithms I figured out in your own code, so long as you don't use it in proprietary programs. It is licensed under GNU GPLv3 or later.
This works for all phones, not just S10+, but I couldn't find a better forum and this is where Frija posted.
 

phhusson

Recognized Developer
Jul 23, 2009
2,448
4,692
Paris
This is going to be super useful for me (ATM I'm using SamFirm with wine/proton and my setup breaks often, and GUI gets in my way) since I need to download many firmwares for my reverse-engineering, so thanks!
 
  • Like
Reactions: xdagee

goofwear

Senior Member
Apr 10, 2010
390
230
www.goofwear.com
@nn000 Glad this made the front page. I have used this for a little wile now and it works great
@phhusson
This will work on windows if you use the WSL and install Ubuntu. You could probably get this working under Cygwin too.
 

Attachments

  • Samloader.png
    Samloader.png
    21.8 KB · Views: 1,194

kazim.asghar

Senior Member
Oct 9, 2012
213
89
Melbourne
Samsung Galaxy S10+
Hi, thanks for this great tool as samfirm and frija are slow to download firmwares. I am trying to download firmware for galaxy watch. I can only search the firmware version but when trying to download it there is error:
filename = root.find("./FUSBody/Put/BINARY_NAME/Data").text
AttributeError: 'NoneType' object has no attribute 'text'
is there any way to modify this tool to download watch firmware too?
 

ianmacd

Senior Member
Jan 5, 2016
2,331
3,726
Amsterdam
localhost
Feel free to use the algorithms I figured out in your own code, so long as you don't use it in proprietary programs. It is licensed under GNU GPLv3 or later.
This works for all phones, not just S10+, but I couldn't find a better forum and this is where Frija posted.

Brilliant work!

Thank you very much for developing this tool and removing our dependency on Windows for such basic functionality as checking for and downloading firmware updates. Thank you also for having the foresight and generosity to publish this under the GPL.

This tool will receive a huge amount of use on my machines.
 
Last edited:
  • Like
Reactions: LiOnDubSeleKta

4929york

Senior Member
Oct 30, 2013
58
10
I tried installing with the command found in the readme file
Code:
pip3 install git+https://github.com/nlscc/samloader.git
But when I type
Code:
$ samloader --help
It says "samloader: command not found"
 
Last edited:

Rosli59564

Senior Member
Mar 10, 2013
1,821
849
How to set download location(out) in the command line
samloader download [firmware version] [phone model] [region] [out]
I tried to put \Download but it's not in the folder.
 

Viper780

Senior Member
Feb 4, 2010
95
5
Vienna
I installed python39 and git on Win10 but sill get errors

Code:
pip3 install git+https://github.com/nlscc/samloader.git
Collecting git+https://github.com/nlscc/samloader.git
  Cloning https://github.com/nlscc/samloader.git to c:\users\danie\appdata\local\temp\pip-req-build-s8l3kwc6
Collecting clint
  Using cached clint-0.5.1.tar.gz (29 kB)
Collecting pycryptodomex
  Using cached pycryptodomex-3.9.8.tar.gz (15.6 MB)
    ERROR: Command errored out with exit status 1:
     command: 'c:\program files\python39\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\danie\\AppData\\Local\\Temp\\pip-install-vvk574_e\\pycryptodomex\\setup.py'"'"'; __file__='"'"'C:\\Users\\danie\\AppData\\Local\\Temp\\pip-install-vvk574_e\\pycryptodomex\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\danie\AppData\Local\Temp\pip-pip-egg-info-3i7fsfut'
         cwd: C:\Users\danie\AppData\Local\Temp\pip-install-vvk574_e\pycryptodomex\
    Complete output (20 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\danie\AppData\Local\Temp\pip-install-vvk574_e\pycryptodomex\setup.py", line 457, in <module>
        set_compiler_options(package_root, ext_modules)
      File "C:\Users\danie\AppData\Local\Temp\pip-install-vvk574_e\pycryptodomex\compiler_opt.py", line 341, in set_compiler_options
        clang = compiler_is_clang()
      File "C:\Users\danie\AppData\Local\Temp\pip-install-vvk574_e\pycryptodomex\compiler_opt.py", line 251, in compiler_is_clang
        return test_compilation(source, msg="clang")
      File "C:\Users\danie\AppData\Local\Temp\pip-install-vvk574_e\pycryptodomex\compiler_opt.py", line 82, in test_compilation
        objects = compiler.compile([fname], extra_postargs=extra_cc_options)
      File "c:\program files\python39\lib\distutils\_msvccompiler.py", line 323, in compile
        self.initialize()
      File "c:\program files\python39\lib\distutils\_msvccompiler.py", line 220, in initialize
        vc_env = _get_vc_env(plat_spec)
      File "c:\program files\python39\lib\site-packages\setuptools\msvc.py", line 314, in msvc14_get_vc_env
        return _msvc14_get_vc_env(plat_spec)
      File "c:\program files\python39\lib\site-packages\setuptools\msvc.py", line 268, in _msvc14_get_vc_env
        raise distutils.errors.DistutilsPlatformError(
    distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
    Testing support for clang
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
 

ianmacd

Senior Member
Jan 5, 2016
2,331
3,726
Amsterdam
localhost
I installed python39 and git on Win10 but sill get errors

Code:
    distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/

The problem is right there in front of you: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
 
  • Like
Reactions: jamieh081

Viper780

Senior Member
Feb 4, 2010
95
5
Vienna
It's pretty annoying when there are requirements and you find out about them afterwards.

Would be good to write them to the install instructions
- python3
- git
- Buildtools for MS C++
 
  • Like
Reactions: aIecxs

hinxnz

Senior Member
Jul 21, 2009
2,849
2,458
Thanks for this, it works well! Cheers..
:highfive:

Example:
Install
Code:
pip3 install git+https://github.com/nlscc/samloader.git
Check update
Code:
samloader -m SM-G975F -r NZC checkupdate
Download
Code:
samloader -m SM-G975F -r NZC download -v G975FXXS9DTI8/G975FOXM9DTI8/G975FXXS9DTI8/G975FXXS9DTI8 -O /home/hinxnz/Downloads
Decrypt
Code:
samloader -m SM-G975F -r NZC decrypt -v G975FXXS9DTI8/G975FOXM9DTI8/G975FXXS9DTI8/G975FXXS9DTI8 -V 4 -i SM-G975F_1_20200921075534_uii8oafhih_fac.zip.enc4 -o SM-G975F_1_20200921075534_uii8oafhih_fac.zip

---------- Post added at 10:52 PM ---------- Previous post was at 10:41 PM ----------

I installed python39 and git on Win10 but sill get errors

Code:
pip3 install git+https://github.com/nlscc/samloader.git
Collecting git+https://github.com/nlscc/samloader.git
  Cloning https://github.com/nlscc/samloader.git to c:\users\danie\appdata\local\temp\pip-req-build-s8l3kwc6
Collecting clint
  Using cached clint-0.5.1.tar.gz (29 kB)
Collecting pycryptodomex
  Using cached pycryptodomex-3.9.8.tar.gz (15.6 MB)
    ERROR: Command errored out with exit status 1:
     command: 'c:\program files\python39\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\danie\\AppData\\Local\\Temp\\pip-install-vvk574_e\\pycryptodomex\\setup.py'"'"'; __file__='"'"'C:\\Users\\danie\\AppData\\Local\\Temp\\pip-install-vvk574_e\\pycryptodomex\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\danie\AppData\Local\Temp\pip-pip-egg-info-3i7fsfut'
         cwd: C:\Users\danie\AppData\Local\Temp\pip-install-vvk574_e\pycryptodomex\
    Complete output (20 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\danie\AppData\Local\Temp\pip-install-vvk574_e\pycryptodomex\setup.py", line 457, in <module>
        set_compiler_options(package_root, ext_modules)
      File "C:\Users\danie\AppData\Local\Temp\pip-install-vvk574_e\pycryptodomex\compiler_opt.py", line 341, in set_compiler_options
        clang = compiler_is_clang()
      File "C:\Users\danie\AppData\Local\Temp\pip-install-vvk574_e\pycryptodomex\compiler_opt.py", line 251, in compiler_is_clang
        return test_compilation(source, msg="clang")
      File "C:\Users\danie\AppData\Local\Temp\pip-install-vvk574_e\pycryptodomex\compiler_opt.py", line 82, in test_compilation
        objects = compiler.compile([fname], extra_postargs=extra_cc_options)
      File "c:\program files\python39\lib\distutils\_msvccompiler.py", line 323, in compile
        self.initialize()
      File "c:\program files\python39\lib\distutils\_msvccompiler.py", line 220, in initialize
        vc_env = _get_vc_env(plat_spec)
      File "c:\program files\python39\lib\site-packages\setuptools\msvc.py", line 314, in msvc14_get_vc_env
        return _msvc14_get_vc_env(plat_spec)
      File "c:\program files\python39\lib\site-packages\setuptools\msvc.py", line 268, in _msvc14_get_vc_env
        raise distutils.errors.DistutilsPlatformError(
    distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
    Testing support for clang
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Now install linux :p
 
Last edited:
  • Haha
Reactions: LiOnDubSeleKta

Top Liked Posts

  • There are no posts matching your filters.
  • 16
    Hello,
    I recently wanted to download some firmware for my Samsung device, but I realized that there is no 100% open source program to do so. In fact, all the tools that claim to do so require a library that is packed by Themida (so it is difficult to check what this might be doing), in order to authenticate to the server. This is a native DLL, meaning that it is only compatible with Windows x86. Additionally, many of these tools are actually using stolen decompiled code from SamFirm, which, apart from being possibly illegal, means they would be difficult to maintain and run slowly.
    So, I decided to reverse engineer Smart Switch to figure out exactly how the download is taking place, and wrote a cross-platform tool that does this without using the Windows DLL that the other tools have, making it compatible with Linux and MacOS. I also realized that the newer versions are actually using a new version of the authentication algorithm, meaning possibly at some point the old tools might stop working as Samsung drops support for it.
    You can find it at:
    Code:
    https://github.com/nlscc/samloader
    To install, go to the downloaded repository and run:
    Code:
    pip3 install .
    See the README or look at the code for usage. You might want to know that my old github account, nm111, was unfortunately deleted, and I lost access to my old XDA account. You can see the verified email is the same however.
    Feel free to use the algorithms I figured out in your own code, so long as you don't use it in proprietary programs. It is licensed under GNU GPLv3 or later.
    This works for all phones, not just S10+, but I couldn't find a better forum and this is where Frija posted.
    2
    I made a bash script to use with Termux which automates everything directly on your device.

    It even offers to install samloader and its dependencies if they are not already installed.

    You can check it out here:
    https://github.com/lekron42/samloader_termux
    2
    Also works with Termux!

    How to:
    First enable the storage permission for Termux in "Settings > Apps > Termux > Permissions > Storage".
    Now set up Termux to install Samloader with commands below.
    Code:
    pkg upgrade
    pkg install git
    pkg install python
    pip install --upgrade pip
    Now you can install Samloader
    Code:
    pip3 install git+https://github.com/nlscc/samloader.git
    To update Samloader
    Code:
    pip3 install --upgrade git+https://github.com/nlscc/samloader.git

    Example:
    Check update
    Code:
    samloader -m SM-G975F -r NZC checkupdate
    Download
    Code:
    samloader -m SM-G975F -r NZC download -v G975FXXS9DTI8/G975FOXM9DTI8/G975FXXS9DTI8/G975FXXS9DTI8 -O /storage/emulated/0/Download/
    Decrypt
    Code:
    samloader -m SM-G975F -r NZC decrypt -v G975FXXS9DTI8/G975FOXM9DTI8/G975FXXS9DTI8/G975FXXS9DTI8 -V 4 -i /storage/emulated/0/Download/SM-G975F_1_20200921075534_uii8oafhih_fac.zip.enc4 -o /storage/emulated/0/Download/SM-G975F_1_20200921075534_uii8oafhih_fac.zip
    1
    Thank you. This is pretty cool. I downloaded it now and will check it out later tonight.
    1
    FKN AWESOMEEEEE :cool: :cool: :cool: working on mint GENIUS WORK!!!!!
    Captura de pantalla de 2021-02-09 19-59-26.png
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone