mirror of
https://github.com/LBPUnion/UnionPatcher.git
synced 2025-08-01 21:58:40 +00:00
Reflow tabs
This commit is contained in:
parent
4a68509d2b
commit
8e267a9cd2
3 changed files with 71 additions and 71 deletions
|
@ -71,20 +71,20 @@ namespace LBPUnion.UnionPatcher.Gui {
|
||||||
|
|
||||||
ElfFile eboot = new(this.filePicker.FilePath);
|
ElfFile eboot = new(this.filePicker.FilePath);
|
||||||
|
|
||||||
if(eboot.IsValid == false) {
|
if(eboot.IsValid == false) {
|
||||||
this.CreateOkDialog("Eboot Error", $"{eboot.Name} is not a valid ELF file (magic number mismatch)").ShowModal();
|
this.CreateOkDialog("Eboot Error", $"{eboot.Name} is not a valid ELF file (magic number mismatch)").ShowModal();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(eboot.Is64Bit == null) {
|
if(eboot.Is64Bit == null) {
|
||||||
this.CreateOkDialog("Eboot Error", $"{eboot.Name} does not target a valid system").ShowModal();
|
this.CreateOkDialog("Eboot Error", $"{eboot.Name} does not target a valid system").ShowModal();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(string.IsNullOrWhiteSpace(eboot.Architecture)) {
|
if(string.IsNullOrWhiteSpace(eboot.Architecture)) {
|
||||||
this.CreateOkDialog("Eboot Error", $"{eboot.Name} does not target a valid architecture (PowerPC or ARM)").ShowModal();
|
this.CreateOkDialog("Eboot Error", $"{eboot.Name} does not target a valid architecture (PowerPC or ARM)").ShowModal();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Patcher.PatchFile(this.filePicker.FilePath, this.serverUrl.Text, this.outputFileName.FilePath);
|
Patcher.PatchFile(this.filePicker.FilePath, this.serverUrl.Text, this.outputFileName.FilePath);
|
||||||
|
|
|
@ -9,66 +9,66 @@ Wikipedia entry on ELF: https://en.wikipedia.org/wiki/Executable_and_Linkable_Fo
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace LBPUnion.UnionPatcher {
|
namespace LBPUnion.UnionPatcher {
|
||||||
public class ElfFile {
|
public class ElfFile {
|
||||||
private enum WordSize : byte {
|
private enum WordSize : byte {
|
||||||
ThirtyTwoBits = 0x01,
|
ThirtyTwoBits = 0x01,
|
||||||
SixtyFourBits = 0x02
|
SixtyFourBits = 0x02
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum Endianness : byte {
|
private enum Endianness : byte {
|
||||||
Little = 0x01,
|
Little = 0x01,
|
||||||
Big = 0x02
|
Big = 0x02
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum InstructionSetArchitecture : UInt16 {
|
private enum InstructionSetArchitecture : UInt16 {
|
||||||
PowerPC = 0x15, //64-bit PowerPC (PS3)
|
PowerPC = 0x15, //64-bit PowerPC (PS3)
|
||||||
ARM = 0x28 //32-bit ARM (Vita)
|
ARM = 0x28 //32-bit ARM (Vita)
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name { get; } = "Binary Blob";
|
public string Name { get; } = "Binary Blob";
|
||||||
|
|
||||||
public bool IsValid { get; }
|
public bool IsValid { get; }
|
||||||
public bool? Is64Bit { get; } = null;
|
public bool? Is64Bit { get; } = null;
|
||||||
public bool? IsBigEndian { get; } = null;
|
public bool? IsBigEndian { get; } = null;
|
||||||
public string Architecture { get; } = null;
|
public string Architecture { get; } = null;
|
||||||
|
|
||||||
public byte[] Contents { get; } = null;
|
public byte[] Contents { get; } = null;
|
||||||
|
|
||||||
public ElfFile(byte[] fileContents) {
|
public ElfFile(byte[] fileContents) {
|
||||||
IsValid = fileContents[0x00..0x04].SequenceEqual(new byte[] {0x7F, (byte)'E', (byte)'L', (byte)'F'});
|
IsValid = fileContents[0x00..0x04].SequenceEqual(new byte[] {0x7F, (byte)'E', (byte)'L', (byte)'F'});
|
||||||
if(IsValid == false) return;
|
if(IsValid == false) return;
|
||||||
|
|
||||||
byte identClassValue = fileContents[0x04];
|
byte identClassValue = fileContents[0x04];
|
||||||
byte identDataValue = fileContents[0x05];
|
byte identDataValue = fileContents[0x05];
|
||||||
|
|
||||||
if(identClassValue == (byte)WordSize.ThirtyTwoBits || identClassValue == (byte)WordSize.SixtyFourBits)
|
if(identClassValue == (byte)WordSize.ThirtyTwoBits || identClassValue == (byte)WordSize.SixtyFourBits)
|
||||||
Is64Bit = identClassValue == (byte)WordSize.SixtyFourBits;
|
Is64Bit = identClassValue == (byte)WordSize.SixtyFourBits;
|
||||||
|
|
||||||
if(identDataValue == (byte)Endianness.Little || identDataValue == (byte)Endianness.Big)
|
if(identDataValue == (byte)Endianness.Little || identDataValue == (byte)Endianness.Big)
|
||||||
IsBigEndian = identDataValue == (byte)Endianness.Big;
|
IsBigEndian = identDataValue == (byte)Endianness.Big;
|
||||||
|
|
||||||
Architecture = GetFileArchitecture(fileContents, IsBigEndian == true);
|
Architecture = GetFileArchitecture(fileContents, IsBigEndian == true);
|
||||||
|
|
||||||
Contents = fileContents;
|
Contents = fileContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ElfFile(FileInfo file) : this(File.ReadAllBytes(file.FullName)) {
|
public ElfFile(FileInfo file) : this(File.ReadAllBytes(file.FullName)) {
|
||||||
Name = file.Name;
|
Name = file.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ElfFile(string fileName) : this(new FileInfo(fileName)) {}
|
public ElfFile(string fileName) : this(new FileInfo(fileName)) {}
|
||||||
|
|
||||||
private string GetFileArchitecture(byte[] elfHeader, bool isBigEndian) {
|
private string GetFileArchitecture(byte[] elfHeader, bool isBigEndian) {
|
||||||
byte[] architectureBytes = elfHeader[0x12..0x14];
|
byte[] architectureBytes = elfHeader[0x12..0x14];
|
||||||
UInt16 fileArch = (isBigEndian) ?
|
UInt16 fileArch = (isBigEndian) ?
|
||||||
BinaryPrimitives.ReadUInt16BigEndian(architectureBytes) :
|
BinaryPrimitives.ReadUInt16BigEndian(architectureBytes) :
|
||||||
BinaryPrimitives.ReadUInt16LittleEndian(architectureBytes);
|
BinaryPrimitives.ReadUInt16LittleEndian(architectureBytes);
|
||||||
|
|
||||||
foreach(InstructionSetArchitecture arch in Enum.GetValues(typeof(InstructionSetArchitecture))) {
|
foreach(InstructionSetArchitecture arch in Enum.GetValues(typeof(InstructionSetArchitecture))) {
|
||||||
if(fileArch == (UInt16)arch)
|
if(fileArch == (UInt16)arch)
|
||||||
return arch.ToString();
|
return arch.ToString();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,21 +25,21 @@ namespace LBPUnion.UnionPatcher {
|
||||||
ElfFile eboot = new(new FileInfo(args[0]));
|
ElfFile eboot = new(new FileInfo(args[0]));
|
||||||
|
|
||||||
if(eboot.IsValid == false) {
|
if(eboot.IsValid == false) {
|
||||||
Console.WriteLine($"{eboot.Name} is not a valid ELF file (magic number mismatch)");
|
Console.WriteLine($"{eboot.Name} is not a valid ELF file (magic number mismatch)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(eboot.Is64Bit == null) {
|
if(eboot.Is64Bit == null) {
|
||||||
Console.WriteLine($"{eboot.Name} does not target a valid system");
|
Console.WriteLine($"{eboot.Name} does not target a valid system");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(string.IsNullOrWhiteSpace(eboot.Architecture)) {
|
if(string.IsNullOrWhiteSpace(eboot.Architecture)) {
|
||||||
Console.WriteLine($"{eboot.Name} does not target a valid architecture (PowerPC or ARM)");
|
Console.WriteLine($"{eboot.Name} does not target a valid architecture (PowerPC or ARM)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine($"{eboot.Name} targets {eboot.Architecture}");
|
Console.WriteLine($"{eboot.Name} targets {eboot.Architecture}");
|
||||||
|
|
||||||
Patcher.PatchFile(args[0], args[1], args[2]);
|
Patcher.PatchFile(args[0], args[1], args[2]);
|
||||||
Console.WriteLine($"Successfully patched Server URL to {args[1]}.");
|
Console.WriteLine($"Successfully patched Server URL to {args[1]}.");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue