Skip to content

Commit

Permalink
add device image extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
msartore committed May 14, 2024
1 parent 18a260e commit 021c07a
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 58 deletions.
4 changes: 2 additions & 2 deletions ATA-GUI/Classes/AppData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ public class AppData
{
public AppData(string name, string package)
{
this.Name = name;
this.Package = package;
Name = name;
Package = package;
}

public string Name { get; set; }
Expand Down
67 changes: 54 additions & 13 deletions ATA-GUI/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions ATA-GUI/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ private async void buttonSyncApp_Click(object sender, EventArgs e)
panelRecovery.Enabled = true;
groupBoxFlash.Enabled = ATA.CurrentDeviceSelected.Mode == DeviceMode.SIDELOAD;
groupBoxRecoveryRM.Enabled = ATA.CurrentDeviceSelected.Mode != DeviceMode.SIDELOAD;
groupBoxImageExtraction.Enabled = groupBoxRecoveryRM.Enabled;
}
else
{
Expand Down Expand Up @@ -594,6 +595,8 @@ public void ToolTipGenerator(Control button, string title, string message)
private void MainForm_Load(object sender, EventArgs e)
{
comboBoxImg.SelectedIndex = 0;
comboBoxImgExtraction.SelectedIndex = 0;

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
ToolTipGenerator(buttonConnectToIP, "Connect device", "Connect to your device with this IP");
ToolTipGenerator(buttonDisconnectIP, "Disconnect device", "Disconnect from your device with this IP");
Expand Down Expand Up @@ -2199,5 +2202,46 @@ private void setWantedRows()
}
}
}

private void buttonImgExtraction_Click(object sender, EventArgs e)
{
bool opResult = false;

LogWriteLine("Generating image...", LogType.INFO);

string creationResult = ConsoleProcess.adbProcess(commandAssemblerF(String.Format("shell dd if=/dev/block/bootdevice/by-name/{0} of=/sdcard/{0}.img", comboBoxImgExtraction.Text)));

if (!creationResult.Contains("No such file or directory") && creationResult.Contains("copied"))
{
if (!Directory.Exists("IMG"))
{
Directory.CreateDirectory("IMG");
}

LogWriteLine("image generated, pulling it from the device...", LogType.INFO);

string pullResult = ConsoleProcess.adbProcess(String.Format("pull /sdcard/{0}.img IMG/{0}.img", comboBoxImgExtraction.Text));

if (pullResult.Contains("file pulled"))
{
ConsoleProcess.adbProcess(String.Format("shell rm /sdcard/{0}.img", comboBoxImgExtraction.Text));
opResult = true;
LogWriteLine("image pulled successfully!", LogType.OK);
}
else
{
LogWriteLine("Failed to pull the image, \nError result:\n" + pullResult, LogType.ERROR);
}
}
else
{
LogWriteLine("Failed to generate the image. \nError result:" + creationResult, LogType.ERROR);
}

MessageShowBox(
opResult ? "image extracted, it can be found in this directory: " + Directory.GetCurrentDirectory() + "\\IMG" : "Failed to extract the img",
opResult ? 2 : 0
);
}
}
}
3 changes: 0 additions & 3 deletions ATA-GUI/Forms/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>853, 19</value>
</metadata>
<metadata name="name.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
Expand Down
72 changes: 32 additions & 40 deletions ATA-GUI/Utils/ConsoleProcess.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand All @@ -25,55 +26,46 @@ public static string adbFastbootCommandR(string command, int type)
public static string adbFastbootCommandR(string[] args, int type)
{
StringBuilder ret = new();
string line;
Cursor.Current = Cursors.WaitCursor;
Process process = new();

string executable = type switch
{
0 => "adb.exe",
1 => "fastboot.exe",
_ => throw new ArgumentOutOfRangeException(nameof(type), "Invalid type specified.")
};

ProcessStartInfo startInfo = new()
{
FileName = executable,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true
};
switch (type)

foreach (string arg in args)
{
case 0:
startInfo.FileName = "adb.exe";
process.StartInfo = startInfo;

foreach (string s in args)
{
startInfo.Arguments = s;
_ = process.Start();
line = process.StandardOutput.ReadToEnd();
if (line.Length > 0)
{
_ = ret.Append(line);
}
}
break;
case 1:
startInfo.FileName = "fastboot.exe";
process.StartInfo = startInfo;

foreach (string s in args)
{
startInfo.Arguments = s;
_ = process.Start();
line = process.StandardError.ReadToEnd();
if (line.Length > 0) { _ = ret.Append(line); }

line = process.StandardOutput.ReadToEnd();
if (line.Length > 0)
{
_ = ret.Append(line);
}
}
break;
default:
break;
startInfo.Arguments = arg;
using Process process = new() { StartInfo = startInfo };
process.Start();

string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();

if (!string.IsNullOrEmpty(output))
{
ret.AppendLine(output);
}
if (!string.IsNullOrEmpty(error))
{
ret.AppendLine(error);
}

process.WaitForExit();
}
process.Close();

Cursor.Current = Cursors.Default;
return ret.ToString().Trim();
}

Expand Down

0 comments on commit 021c07a

Please sign in to comment.