Skip to content

Commit 333191c

Browse files
committed
SamFirm.NET: .NET 5 implementation of SamFirm
1 parent c987b0f commit 333191c

17 files changed

+1335
-16
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ bin
22
dist
33
obj
44

5+
SM-*
6+
57
## Ignore Visual Studio temporary files, build results, and
68
## files generated by popular Visual Studio add-ons.
79
##

.vscode/launch.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": ".NET Core Launch (console)",
6+
"type": "coreclr",
7+
"request": "launch",
8+
"preLaunchTask": "build",
9+
"program": "${workspaceFolder}/SamFirm/bin/Debug/net5.0/SamFirm.dll",
10+
"args": ["--model", "SM-F916N", "--region", "KOO"],
11+
"cwd": "${workspaceFolder}/SamFirm",
12+
"console": "internalConsole",
13+
"stopAtEntry": false
14+
},
15+
{
16+
"name": ".NET Core Attach",
17+
"type": "coreclr",
18+
"request": "attach",
19+
"processId": "${command:pickProcess}"
20+
}
21+
]
22+
}

.vscode/tasks.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/SamFirm/SamFirm.csproj",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/SamFirm/SamFirm.csproj",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"${workspaceFolder}/SamFirm/SamFirm.csproj",
36+
"/property:GenerateFullPaths=true",
37+
"/consoleloggerparameters:NoSummary"
38+
],
39+
"problemMatcher": "$msCompile"
40+
}
41+
]
42+
}

LICENSE

+674
Large diffs are not rendered by default.

README.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# SamFirm.NET
2+
3+
A streaming downloader, decryptor and extractor of Samsung firmware.
4+
5+
## Getting started
6+
7+
### Run
8+
9+
1. Download the executable from [Release](https://github.com/jesec/samfirm.net/releases).
10+
1. Run it with `--region` and `--model` arguments.
11+
12+
Windows users may choose the smaller but not-self-contained variant if .NET runtime is present.
13+
14+
### Build
15+
16+
1. Get [Visual Studio 2019](https://visualstudio.microsoft.com/vs/)
17+
1. Open the repository with VS 2019
18+
1. Install dependencies as prompted
19+
1. Build solution
20+
21+
## Example
22+
23+
```
24+
> ./SamFirm -m SM-F916N -r KOO
25+
26+
Model: SM-F916N
27+
Region: KOO
28+
29+
Latest version:
30+
PDA: F916NTBU1ATJC
31+
CSC: F916NOKT1ATJC
32+
MODEM: F916NKSU1ATJ7
33+
34+
OS: Q(Android 10)
35+
Filename: SM-F916N_10_20201028094404_saezf08xjk_fac.zip.enc4
36+
Size: 5669940496 bytes
37+
Logic Value: 611oq0u820f7uv34
38+
Description:
39+
• SIM Tray 제거시 가이드 팝업 적용
40+
• 충전 동작 관련 안정화 코드 적용
41+
• 단말 동작 관련 안정화 코드 적용
42+
• 단말 보안 관련 안정화 코드 적용
43+
44+
https://doc.samsungmobile.com/SM-F916N/KOO/doc.html
45+
46+
/mnt/c/Users/jc/source/repos/SamFirm.NET/SamFirm/dist/linux-x64/SM-F916N_KOO
47+
BL_F916NTBU1ATJC_CL19952515_QB35429635_REV00_user_low_ship_MULTI_CERT.tar.md5
48+
```
49+
50+
## License
51+
52+
```
53+
Copyright (C) 2020 Jesse Chan <[email protected]>
54+
55+
This program is free software: you can redistribute it and/or modify
56+
it under the terms of the GNU General Public License as published by
57+
the Free Software Foundation, either version 3 of the License, or
58+
(at your option) any later version.
59+
60+
This program is distributed in the hope that it will be useful,
61+
but WITHOUT ANY WARRANTY; without even the implied warranty of
62+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63+
GNU General Public License for more details.
64+
65+
You should have received a copy of the GNU General Public License
66+
along with this program. If not, see <https://www.gnu.org/licenses/>.
67+
```

SamFirm.NET.sln

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
21
Microsoft Visual Studio Solution File, Format Version 12.00
32
# Visual Studio Version 16
43
VisualStudioVersion = 16.0.30709.64
54
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamFirm.NET", "SamFirm.NET\SamFirm.NET.csproj", "{2642C974-0B2C-4B7F-9308-36DBFBCB434A}"
5+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SamFirm", "SamFirm\SamFirm.csproj", "{2642C974-0B2C-4B7F-9308-36DBFBCB434A}"
76
EndProject
87
Global
98
GlobalSection(SolutionConfigurationPlatforms) = preSolution

SamFirm.NET/Program.cs

-12
This file was deleted.

SamFirm/Program.cs

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System;
2+
using System.IO;
3+
using System.Net;
4+
using System.Text;
5+
using System.Xml.Linq;
6+
using System.Xml.XPath;
7+
using CommandLine;
8+
9+
namespace SamFirm
10+
{
11+
class Program
12+
{
13+
public class Options
14+
{
15+
[Option('m', "model", Required = true)]
16+
public string Model { get; set; }
17+
18+
[Option('r', "region", Required = true)]
19+
public string Region { get; set; }
20+
}
21+
22+
private static string GetLatestVersion(string region, string model)
23+
{
24+
using (WebClient client = new WebClient())
25+
{
26+
string XMLString = client.DownloadString("http://fota-cloud-dn.ospserver.net/firmware/" + region + "/" + model + "/version.xml");
27+
return XDocument.Parse(XMLString).XPathSelectElement("./versioninfo/firmware/version/latest").Value;
28+
}
29+
}
30+
31+
static void Main(string[] args)
32+
{
33+
string model = "";
34+
string region = "";
35+
Parser.Default.ParseArguments<Options>(args)
36+
.WithParsed(o =>
37+
{
38+
model = o.Model;
39+
region = o.Region;
40+
});
41+
42+
if (model.Length == 0 || region.Length == 0)
43+
{
44+
return;
45+
}
46+
47+
Console.OutputEncoding = Encoding.UTF8;
48+
49+
Console.WriteLine($@"
50+
Model: {model}
51+
Region: {region}");
52+
53+
string[] versions = GetLatestVersion(region, model).Split('/');
54+
string versionPDA = versions[0];
55+
string versionCSC = versions[1];
56+
string versionMODEM = versions[2];
57+
string version = $"{versionPDA}/{versionCSC}/{(versionMODEM.Length > 0 ? versionMODEM : versionPDA)}/{versionPDA}";
58+
59+
Console.WriteLine($@"
60+
Latest version:
61+
PDA: {versionPDA}
62+
CSC: {versionCSC}
63+
MODEM: {(versionMODEM.Length > 0 ? versionMODEM : "N/A")}");
64+
65+
int responseStatus;
66+
responseStatus = Utils.FUSClient.GenerateNonce();
67+
68+
string binaryInfoXMLString;
69+
responseStatus = Utils.FUSClient.DownloadBinaryInform(
70+
Utils.Msg.GetBinaryInformMsg(version, region, model, Utils.FUSClient.NonceDecrypted), out binaryInfoXMLString);
71+
72+
XDocument binaryInfo = XDocument.Parse(binaryInfoXMLString);
73+
long binaryByteSize = long.Parse(binaryInfo.XPathSelectElement("./FUSMsg/FUSBody/Put/BINARY_BYTE_SIZE/Data").Value);
74+
string binaryDescription = binaryInfo.XPathSelectElement("./FUSMsg/FUSBody/Put/DESCRIPTION/Data").Value;
75+
string binaryFilename = binaryInfo.XPathSelectElement("./FUSMsg/FUSBody/Put/BINARY_NAME/Data").Value;
76+
string binaryLogicValue = binaryInfo.XPathSelectElement("./FUSMsg/FUSBody/Put/LOGIC_VALUE_FACTORY/Data").Value;
77+
string binaryModelPath = binaryInfo.XPathSelectElement("./FUSMsg/FUSBody/Put/MODEL_PATH/Data").Value;
78+
string binaryOSVersion = binaryInfo.XPathSelectElement("./FUSMsg/FUSBody/Put/CURRENT_OS_VERSION/Data").Value;
79+
string binaryVersion = binaryInfo.XPathSelectElement("./FUSMsg/FUSBody/Results/LATEST_FW_VERSION/Data").Value;
80+
81+
Console.WriteLine($@"
82+
OS: {binaryOSVersion}
83+
Filename: {binaryFilename}
84+
Size: {binaryByteSize} bytes
85+
Logic Value: {binaryLogicValue}
86+
Description:
87+
{string.Join("\n ", binaryDescription.TrimStart().Split('\n'))}");
88+
89+
string binaryInitXMLString;
90+
responseStatus = Utils.FUSClient.DownloadBinaryInit(Utils.Msg.GetBinaryInitMsg(binaryFilename, Utils.FUSClient.NonceDecrypted), out binaryInitXMLString);
91+
92+
Utils.File.FileSize = binaryByteSize;
93+
Utils.File.SetDecryptKey(binaryVersion, binaryLogicValue);
94+
95+
string savePath = Path.GetFullPath($"./{model}_{region}");
96+
97+
Console.WriteLine($@"
98+
{savePath}");
99+
100+
Utils.FUSClient.DownloadBinary(binaryModelPath, binaryFilename, savePath);
101+
}
102+
}
103+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"SamFirm.NET": {
4+
"commandName": "Project",
5+
"commandLineArgs": "--model SM-F916N --region KOO"
6+
}
7+
}
8+
}

SamFirm.NET/SamFirm.NET.csproj renamed to SamFirm/SamFirm.csproj

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net5.0</TargetFramework>
6-
<StartupObject>SamFirm.NET.Program</StartupObject>
6+
<StartupObject>SamFirm.Program</StartupObject>
77
<Platforms>x64</Platforms>
8+
<Authors>Jesse Chan &lt;[email protected]&gt;</Authors>
89
</PropertyGroup>
910

1011
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
1112
<PlatformTarget>x64</PlatformTarget>
1213
</PropertyGroup>
1314

1415
<ItemGroup>
16+
<PackageReference Include="CommandLineParser" Version="2.8.0" />
1517
<PackageReference Include="SharpZipLib" Version="1.3.0" />
1618
</ItemGroup>
1719

0 commit comments

Comments
 (0)