Skip to content

Commit

Permalink
Add dumper target for a dump-only build
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTheMan827 committed Dec 12, 2022
1 parent 643d35d commit d3e03dd
Show file tree
Hide file tree
Showing 13 changed files with 379 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
branch = notracesource
[submodule "Libraries/ProgressODoom"]
path = Libraries/ProgressODoom
url = https://github.com/daPhie79/ProgressODoom.git
url = https://github.com/TeamShinkansen/ProgressODoom.git
[submodule "Libraries/tiny7z"]
path = Libraries/tiny7z
url = https://github.com/daPhie79/tiny7z.git
Expand Down
2 changes: 1 addition & 1 deletion Libraries/ProgressODoom
2 changes: 1 addition & 1 deletion Libraries/SSH.NET
102 changes: 102 additions & 0 deletions hakchi_gui.sln

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions hakchi_gui/DumperForm.Designer.cs

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

23 changes: 23 additions & 0 deletions hakchi_gui/DumperForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using com.clusterrr.hakchi_gui.Properties;
using System;
using System.Windows.Forms;

namespace com.clusterrr.hakchi_gui
{
public partial class DumperForm : Form
{
public DumperForm()
{
InitializeComponent();
hakchi.Initialize();
}

private void DumperForm_Load(object sender, EventArgs e)
{
#if DUMPER
MainForm.DoNand(Tasks.MembootTasks.NandTasks.DumpNand, Resources.DumpingNand, this);
#endif
Close();
}
}
}
120 changes: 120 additions & 0 deletions hakchi_gui/DumperForm.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
15 changes: 13 additions & 2 deletions hakchi_gui/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1950,8 +1950,15 @@ bool UploadGames(bool exportGames = false)
}
}

#if DUMPER
internal static
#endif
bool DumpDialog(FileAccess type, string FileName, string FileExt, out string DumpFileName, string DialogFilter = null)
{
#if DUMPER
var openDumpFileDialog = new OpenFileDialog();
var saveDumpFileDialog = new SaveFileDialog();
#endif
DumpFileName = null;
string currentFilter;
switch (type)
Expand Down Expand Up @@ -1997,9 +2004,13 @@ bool DumpDialog(FileAccess type, string FileName, string FileExt, out string Dum
}
}

bool DoNand(MembootTasks.NandTasks task, string title)
bool DoNand(MembootTasks.NandTasks task, string title) => DoNand(task, title, this);
#if DUMPER
internal static
#endif
bool DoNand(MembootTasks.NandTasks task, string title, Form owner)
{
using (Tasker tasker = new Tasker(this))
using (Tasker tasker = new Tasker(owner))
{
tasker.AttachViews(new Tasks.TaskerTaskbar(), new Tasks.TaskerForm());
tasker.SetStatusImage(Resources.sign_cogs);
Expand Down
10 changes: 10 additions & 0 deletions hakchi_gui/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ static void Main(string[] args)

Trace.Listeners.Add(new TextWriterTraceListener(stdout));

#if !DUMPER
if (Debugger.IsAttached || Array.IndexOf(args, "/debug") != -1)
#endif
{
try
{
Expand Down Expand Up @@ -173,6 +175,7 @@ static void Main(string[] args)
{
if (createdNew)
{
#if !DUMPER
if (!isPortable)
{
BaseDirectoryExternal = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "hakchi2");
Expand Down Expand Up @@ -258,6 +261,9 @@ static void Main(string[] args)
}

SetupScrapers();
#else
BaseDirectoryExternal = BaseDirectoryInternal;
#endif

Trace.WriteLine("Starting, version: " + Shared.AppDisplayVersion);

Expand All @@ -267,7 +273,11 @@ static void Main(string[] args)

FormContext.AllFormsClosed += Process.GetCurrentProcess().Kill; // Suicide! Just easy and dirty way to kill all threads.

#if !DUMPER
FormContext.AddForm(new MainForm());
#else
FormContext.AddForm(new DumperForm());
#endif
Application.Run(FormContext);
Trace.WriteLine("Done.");
}
Expand Down
11 changes: 9 additions & 2 deletions hakchi_gui/Sunxi/NandInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal PartitionInfo(string device, string label, long blocks)

public static PartitionInfo GetByLabel(IEnumerable<PartitionInfo> info, params string[] labels)
{
return info.Where(e => labels.Contains(e.Label)).First();
return info.Where(e => labels.Contains(e.Label)).FirstOrDefault();
}
}

Expand All @@ -46,7 +46,14 @@ private NandInfo(PartitionInfo[] partitions, long pageSize, long pagesPerBlock,
public static NandInfo GetNandInfo(string partCommand = "sunxi-part")
{
string partInfo = hakchi.Shell.ExecuteSimple(partCommand);
string[] nandInfo = hakchi.Shell.ExecuteSimple("sunxi-flash nandinfo").Split(' ');
string commandOutput = hakchi.Shell.ExecuteSimple("sunxi-flash nandinfo");

if (string.IsNullOrWhiteSpace(commandOutput))
{
return new NandInfo(new PartitionInfo[] { }, 0, 0, 0);
}

string[] nandInfo = commandOutput.Split(' ');

var partitions = new List<PartitionInfo>();

Expand Down
27 changes: 22 additions & 5 deletions hakchi_gui/Tasks/MembootTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -853,13 +853,15 @@ public static TaskFunc ProcessNand(string nandDump, NandTasks task)
throw new Exception(Properties.Resources.InvalidUserDataBackup);
}
var hasNand = hakchi.Shell.ExecuteSimple("ls -lah /dev/nanda &> /dev/null && echo 1 || echo 0") == "1";
var hasMmc = hakchi.Shell.ExecuteSimple("ls -lah /dev/mmcblk0 &> /dev/null && echo 1 || echo 0") == "1";
var nandInfo = Sunxi.NandInfo.GetNandInfo();
long partitionSize = 300 * 1024 * 1024;
var splitStream = new SplitterStream(Program.debugStreams);
string rootfsDevice = $"/dev/{nandInfo.GetRootfsPartition().Device}";
string rootfsDevice = $"/dev/{nandInfo.GetRootfsPartition()?.Device}";
string osDecryptedDevice = rootfsDevice;
string userDataDevice = $"/dev/{nandInfo.GetDataPartition().Device}";
string userDataDevice = $"/dev/{nandInfo.GetDataPartition()?.Device}";
bool hasKeyfile = hakchi.Shell.Execute("[ -f /key-file ]") == 0;
if (hasKeyfile)
Expand Down Expand Up @@ -901,7 +903,14 @@ public static TaskFunc ProcessNand(string nandDump, NandTasks task)
break;
case NandTasks.DumpNand:
partitionSize = 536870912;
if (hasNand)
{
partitionSize = 536870912;
}
if (!hasNand && hasMmc)
{
partitionSize = long.Parse(hakchi.Shell.ExecuteSimple($"blockdev --getsize64 /dev/mmcblk0", throwOnNonZero: true));
}
break;
}
Expand Down Expand Up @@ -1050,8 +1059,16 @@ public static TaskFunc ProcessNand(string nandDump, NandTasks task)
break;
case NandTasks.DumpNand:
hakchi.Shell.Execute("hakchi umount_base", null, splitStream, splitStream, 0, true);
Shared.ShellPipe("sntool sunxi_flash phy_read 0", null, file, throwOnNonZero: true);
if (hasNand)
{
hakchi.Shell.Execute("hakchi umount_base", null, splitStream, splitStream, 0, true);
Shared.ShellPipe("sntool sunxi_flash phy_read 0", null, file, throwOnNonZero: true);
}
if (!hasNand && hasMmc)
{
Shared.ShellPipe("dd if=/dev/mmcblk0 bs=1M", null, file, throwOnNonZero: true);
}
break;
}
file.Close();
Expand Down
Loading

0 comments on commit d3e03dd

Please sign in to comment.