From 84febaee29f31ecd7149f26878e581954a18b761 Mon Sep 17 00:00:00 2001 From: bob Date: Fri, 28 Oct 2022 11:12:19 +0800 Subject: [PATCH] Copy from private repository --- .gitignore | 11 +++++++++ AssemblyInfo.cs | 14 +++++++++++ Program.cs | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ adb2tgz.csproj | 51 ++++++++++++++++++++++++++++++++++++++ adb2tgz.sln | 25 +++++++++++++++++++ 5 files changed, 166 insertions(+) create mode 100644 .gitignore create mode 100644 AssemblyInfo.cs create mode 100644 Program.cs create mode 100644 adb2tgz.csproj create mode 100644 adb2tgz.sln diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..83a5e21 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +bin +obj +*.exe +*.suo +*.user +*.dll +*.pdb +.git +.vs +*.log +*.log.doc diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs new file mode 100644 index 0000000..b8049e7 --- /dev/null +++ b/AssemblyInfo.cs @@ -0,0 +1,14 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("adb2tgz")] +[assembly: AssemblyDescription("Converts Android ADB backup to TGZ archive type")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("JGhost")] +[assembly: AssemblyProduct("adb2tgz")] +[assembly: AssemblyCopyright("© 2015-2022 JGHost")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..ca36aea --- /dev/null +++ b/Program.cs @@ -0,0 +1,65 @@ +using System; +using System.IO; + +static class Program { + + static int Main(string[] args) { + try { + + Console.WriteLine("Converts Android adb backup file to tgz archive type"); + if (args.Length > 0) { + if (File.Exists(args[0])) { + Console.WriteLine("using file " + args[0]); + + FileStream fs = new FileStream(args[0], FileMode.Open, FileAccess.ReadWrite); + byte[] buffer = new byte[8] { 0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 }; + byte[] buffer1 = new byte[1024 * 1024 * 10]; + fs.Read(buffer1, 0, 8); + //Avoid corrupting a file that is already converted + if (Compare(buffer, buffer1)) { + Console.WriteLine("Selected file is already a tgz type. it might have been converted before"); + return 1; + } + + + fs.Position = 0; + fs.Write(buffer, 0, 8); + long size = fs.Length; + fs.Position = 24; + int notification = 10; + while (fs.Position < fs.Length) { + fs.Read(buffer1, 0, buffer1.Length); + fs.Position = fs.Position - buffer1.Length - 16; + fs.Write(buffer1, 0, buffer1.Length); + fs.Position = fs.Position + 16; + notification--; + if (notification < 1) { + Console.WriteLine(" " + ((fs.Position / (decimal) size) * 100).ToString("0") + "%"); + } + } + + fs.Flush(); + fs.Close(); + Console.WriteLine(" Renaming adb file to tgz"); + File.Move(args[0], args[0].Replace(Path.GetExtension(args[0]), ".tgz")); + } + } else { + Console.WriteLine("No backup file selected, drag your backup file on executable to convert it to tar file"); + } + } catch (Exception ex) { + Console.WriteLine(ex.ToString()); + } + + Console.WriteLine("Complete. Press a key to exit"); + Console.ReadKey(); + return 0; + } + + private static bool Compare(byte[] buffer, byte[] buffer1) { + for (int i = 0;i < buffer.Length;i++) { + if (buffer[i] != buffer1[i]) + return false; + } + return true; + } +} \ No newline at end of file diff --git a/adb2tgz.csproj b/adb2tgz.csproj new file mode 100644 index 0000000..98ddb3e --- /dev/null +++ b/adb2tgz.csproj @@ -0,0 +1,51 @@ + + + + + Debug + AnyCPU + {60BAFF0C-D983-4F68-9593-3CEC58D18DCC} + Exe + adb2tgz + adb2tgz + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + .\ + DEBUG;TRACE + prompt + 4 + false + + + AnyCPU + pdbonly + true + .\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/adb2tgz.sln b/adb2tgz.sln new file mode 100644 index 0000000..8d083f5 --- /dev/null +++ b/adb2tgz.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30523.141 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "adb2tgz", "adb2tgz.csproj", "{60BAFF0C-D983-4F68-9593-3CEC58D18DCC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {60BAFF0C-D983-4F68-9593-3CEC58D18DCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {60BAFF0C-D983-4F68-9593-3CEC58D18DCC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {60BAFF0C-D983-4F68-9593-3CEC58D18DCC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {60BAFF0C-D983-4F68-9593-3CEC58D18DCC}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FA8907BD-5A91-45B5-A80F-E57D9D09E599} + EndGlobalSection +EndGlobal