Skip to content

Commit

Permalink
console version support
Browse files Browse the repository at this point in the history
  • Loading branch information
ucorpor committed Mar 31, 2024
1 parent 19268c1 commit 5055292
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 44 deletions.
75 changes: 46 additions & 29 deletions ibf-unpack/IbfUnpack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public static void Unpack(string archivePath)
Directory.CreateDirectory(systemDir);

Stream stream = File.OpenRead(archivePath);
int filenameLength = stream.ReadByte() * 2;
int filenameLength = stream.ReadByte();
while (filenameLength > 0)
{
string filename = ReadString(stream, filenameLength).Replace("\0", string.Empty);
string filename = ReadString(stream, filenameLength * 2).Replace("\0", string.Empty);
string filepath = Path.Combine(systemDir, filename);
File.WriteAllText(filepath, string.Empty);

Expand All @@ -31,64 +31,81 @@ public static void Unpack(string archivePath)
int remained = fileLength - fileLength / chunkSize * chunkSize;
ReadAndWriteBytes(stream, remained, filepath);

filenameLength = stream.ReadByte() * 2;
filenameLength = stream.ReadByte();
}
stream.Close();
}

public static void UnpackV2(string archivePath)
public static void Unpack2(string archivePath, bool isBigEndian = false)
{
string systemDir = Path.Combine(Path.GetDirectoryName(archivePath), "System");
Directory.CreateDirectory(systemDir);

Stream stream = File.OpenRead(archivePath);
int filenameLength = stream.ReadByte() * 2;
while (filenameLength > 0)
int filenameLength = stream.ReadByte();
while (stream.Position < stream.Length)
{
string filename = ReadString(stream, filenameLength).Replace("\0", string.Empty);
string filepath = Path.Combine(systemDir, filename);
File.WriteAllText(filepath, string.Empty);

List<byte> file = new List<byte>();
byte prevB = byte.MaxValue;
while (true)
if (filenameLength > 0)
{
byte b = ReadBytes(stream, 1)[0];
if ((prevB == 0x0D || prevB == 0x5B) && b == 0x0)
string filename = ReadString(stream, filenameLength * 2, isBigEndian).Replace("\0", string.Empty);
string filepath = Path.Combine(systemDir, filename);
File.WriteAllText(filepath, string.Empty);

List<byte> file = new List<byte>();
byte prevB = byte.MaxValue;
while (stream.Position < stream.Length)
{
file.Add(prevB);
file.Add(b);
break;
byte b = ReadByte(stream);
if ((isBigEndian == false && prevB != 0x0 && b == 0x0)
|| (isBigEndian == true && prevB == 0x0 && b != 0x0))
{
file.Add(prevB);
file.Add(b);
break;
}
prevB = b;
}
prevB = b;
}

while (true)
{
byte[] symbol = ReadBytes(stream, 2);
if (symbol[0] == 0x0 && symbol[1] == 0x0)
while (stream.Position < stream.Length)
{
WriteBytes(file.ToArray(), filepath);
break;
byte[] symbol = ReadBytes(stream, 2);
if (symbol[0] == 0x0 && symbol[1] == 0x0)
{
WriteBytes(file.ToArray(), filepath);
break;
}
file.AddRange(symbol);
}
file.AddRange(symbol);
}

filenameLength = stream.ReadByte() * 2;
filenameLength = stream.ReadByte();
}
stream.Close();
}

private static byte ReadByte(Stream stream)
{
byte[] bytes = new byte[1];
stream.Read(bytes, 0, 1);
return bytes[0];
}

private static byte[] ReadBytes(Stream stream, int length)
{
byte[] bytes = new byte[length];
stream.Read(bytes, 0, length);
return bytes;
}

private static string ReadString(Stream stream, int length)
private static string ReadString(Stream stream, int length, bool isBigEndian = false)
{
byte[] bytes = ReadBytes(stream, length);

if (isBigEndian)
{
return Encoding.BigEndianUnicode.GetString(bytes);
}

return Encoding.Unicode.GetString(bytes);
}

Expand Down
66 changes: 54 additions & 12 deletions ibf-unpack/MainForm.Designer.cs

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

14 changes: 13 additions & 1 deletion ibf-unpack/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@ private void unpackBtn_Click(object sender, EventArgs e)
try
{
string path = pathTxt.Text.Trim();
IbfUnpack.Unpack(path);
if (consoleRb.Checked)
{
IbfUnpack.Unpack2(path, true);
}
else if (b2Rb.Checked)
{
IbfUnpack.Unpack2(path);
}
else
{
IbfUnpack.Unpack(path);
}

if (renameCb.Checked) File.Move(path, $"{path}.backup");

Expand Down Expand Up @@ -110,5 +121,6 @@ private void makeBtn_Click(object sender, EventArgs e)
Cursor = Cursors.Default;
}
}

}
}
4 changes: 2 additions & 2 deletions ibf-unpack/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]

0 comments on commit 5055292

Please sign in to comment.