Skip to content

Commit

Permalink
Initial imei/serial support
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmeler committed Dec 26, 2023
1 parent 35a81c3 commit 3746e73
Show file tree
Hide file tree
Showing 6 changed files with 502 additions and 438 deletions.
2 changes: 1 addition & 1 deletion AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SamFirm Reborn")]
[assembly: AssemblyFileVersion("0.3.6.7")]
[assembly: AssemblyFileVersion("0.3.6.8")]
[assembly: AssemblyDescription("BornAgain Edition")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCopyright("Copyright zxz0O0 © 2015 / Ivan Meler 2021-2023 / KSmith 2023 / corsicanu 2024")]
Expand Down
20 changes: 12 additions & 8 deletions CmdLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal class CmdLine
private static string file = string.Empty;
private static string model = string.Empty;
private static string region = string.Empty;
private static string imei = string.Empty;
private static string logicValue = string.Empty;
private static string folder = string.Empty;
private static bool binary = false;
Expand All @@ -35,12 +36,12 @@ private static int ProcessAction()
int num = -1;
if (!string.IsNullOrEmpty(CmdLine.file))
{
if (!string.IsNullOrEmpty(CmdLine.region) && !string.IsNullOrEmpty(CmdLine.model) && !string.IsNullOrEmpty(CmdLine.version))
if (!string.IsNullOrEmpty(CmdLine.region) && !string.IsNullOrEmpty(CmdLine.imei) && !string.IsNullOrEmpty(CmdLine.model) && !string.IsNullOrEmpty(CmdLine.version))
num = CmdLine.DoDecrypt();
else if (!string.IsNullOrEmpty(CmdLine.logicValue) && !string.IsNullOrEmpty(CmdLine.version))
num = CmdLine.DoDecrypt();
}
else if (!string.IsNullOrEmpty(CmdLine.model) && !string.IsNullOrEmpty(CmdLine.region))
else if (!string.IsNullOrEmpty(CmdLine.model) && !string.IsNullOrEmpty(CmdLine.imei) && !string.IsNullOrEmpty(CmdLine.region))
num = !CmdLine.checkonly ? CmdLine.DoDownload() : CmdLine.DoCheck();
if (num == -1)
{
Expand Down Expand Up @@ -97,12 +98,12 @@ private static int DoCheck()
Command.Firmware firmware;
if (string.IsNullOrEmpty(CmdLine.version))
{
firmware = Command.UpdateCheckAuto(CmdLine.model, CmdLine.region, CmdLine.binary);
firmware = Command.UpdateCheckAuto(CmdLine.model, CmdLine.region, CmdLine.imei, CmdLine.binary);
if (firmware.FetchAttempts == 0)
return 5;
}
else
firmware = Command.UpdateCheck(CmdLine.model, CmdLine.region, CmdLine.version, CmdLine.binary, false);
firmware = Command.UpdateCheck(CmdLine.model, CmdLine.region, CmdLine.imei, CmdLine.version, CmdLine.binary, false);
return firmware.Version == null ? 2 : 0;
}

Expand All @@ -112,12 +113,12 @@ private static int DoDownload()
Command.Firmware fw;
if (string.IsNullOrEmpty(CmdLine.version))
{
fw = Command.UpdateCheckAuto(CmdLine.model, CmdLine.region, CmdLine.binary);
fw = Command.UpdateCheckAuto(CmdLine.model, CmdLine.region, CmdLine.imei, CmdLine.binary);
if (fw.FetchAttempts == 0)
return 5;
}
else
fw = Command.UpdateCheck(CmdLine.model, CmdLine.region, CmdLine.version, CmdLine.binary, false);
fw = Command.UpdateCheck(CmdLine.model, CmdLine.region, CmdLine.imei, CmdLine.version, CmdLine.binary, false);
if (fw.Version == null)
return 2;
dfw = fw;
Expand Down Expand Up @@ -214,12 +215,12 @@ private static void DisplayUsage()
{
Logger.WriteLog("Usage:\n", false);
Logger.WriteLog("Update check:", false);
Logger.WriteLog(" SamFirm.exe -c -model [device model] -region [region code]\n [-version [pda/csc/phone/data]] [-binary]", false);
Logger.WriteLog(" SamFirm.exe -c -model [device model] -region [region code] -imei [imei or serial number]\n [-version [pda/csc/phone/data]] [-binary]", false);
Logger.WriteLog("\nDecrypting:", false);
Logger.WriteLog(" SamFirm.exe -file [path-to-file.zip.enc2] -version [pda/csc/phone/data] [-meta metafile]", false);
Logger.WriteLog(" SamFirm.exe -file [path-to-file.zip.enc4] -version [pda/csc/phone/data] -logicValue [logicValue] [-meta metafile]", false);
Logger.WriteLog("\nDownloading:", false);
Logger.WriteLog(" SamFirm.exe -model [device model] -region [region code]\n [-version [pda/csc/phone/data]] [-folder [output folder]]\n [-binary] [-autodecrypt] [-nozip] [-meta metafile]", false);
Logger.WriteLog(" SamFirm.exe -model [device model] -region [region code] -imei [imei or serial number]\n [-version [pda/csc/phone/data]] [-folder [output folder]]\n [-binary] [-autodecrypt] [-nozip] [-meta metafile]", false);
}

public static void SaveMeta(Command.Firmware fw, string metafile)
Expand Down Expand Up @@ -292,6 +293,9 @@ private static bool ParseArgs(string[] args)
case "-region":
CmdLine.region = args[index1].ToUpper();
break;
case "-imei":
CmdLine.imei = args[index1].ToUpper();
break;
case "-model":
CmdLine.model = args[index1];
break;
Expand Down
9 changes: 6 additions & 3 deletions Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ internal class Command
public static Command.Firmware UpdateCheckAuto(
string model,
string region,
string imei,
bool BinaryNature)
{
int num = 0;
Expand All @@ -19,7 +20,7 @@ public static Command.Firmware UpdateCheckAuto(
if (!string.IsNullOrEmpty(info))
{
++num;
firmware = Command.UpdateCheck(model, region, info, BinaryNature, true);
firmware = Command.UpdateCheck(model, region, imei, info, BinaryNature, true);
if (firmware.Version == null)
{
if (firmware.ConnectionError)
Expand All @@ -38,6 +39,7 @@ public static Command.Firmware UpdateCheckAuto(
public static Command.Firmware UpdateCheck(
string model,
string region,
string imei,
string info,
bool BinaryNature,
bool AutoFetch = false)
Expand All @@ -50,12 +52,13 @@ public static Command.Firmware UpdateCheck(
string csc = Utility.InfoExtract(info, "csc");
string phone = Utility.InfoExtract(info, "phone");
string data = Utility.InfoExtract(info, "data");
return Command.UpdateCheck(model, region, pda, csc, phone, data, BinaryNature, AutoFetch);
return Command.UpdateCheck(model, region, imei, pda, csc, phone, data, BinaryNature, AutoFetch);
}

public static Command.Firmware UpdateCheck(
string model,
string region,
string imei,
string pda,
string csc,
string phone,
Expand All @@ -78,7 +81,7 @@ public static Command.Firmware UpdateCheck(
//Logger.WriteLog($"Auth signature: {Web.AuthHeaderNoNonce}");

string xmlresponse;
int htmlstatus = Web.DownloadBinaryInform(Xml.GetXmlBinaryInform(model, region, pda, csc, phone, data, BinaryNature), out xmlresponse);
int htmlstatus = Web.DownloadBinaryInform(Xml.GetXmlBinaryInform(model, region, imei, pda, csc, phone, data, BinaryNature), out xmlresponse);
if (htmlstatus != 200 || Utility.GetXMLStatusCode(xmlresponse) != 200)
{
Logger.WriteLog("Error: Could not send BinaryInform. Status code " + (object) htmlstatus + "/" + (object) Utility.GetXMLStatusCode(xmlresponse), false);
Expand Down
Loading

0 comments on commit 3746e73

Please sign in to comment.