From 58c418362bf12bf18acfd54a730a990acca9a739 Mon Sep 17 00:00:00 2001 From: Jake <505e06b2@gmail.com> Date: Sun, 20 Feb 2022 19:05:05 +0000 Subject: [PATCH] Added filesize check; fixed formatting --- UnionPatcher.Gui/MainForm.cs | 2 +- UnionPatcher/ElfFile.cs | 7 ++++++- UnionPatcher/Program.cs | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/UnionPatcher.Gui/MainForm.cs b/UnionPatcher.Gui/MainForm.cs index f77d7db..cd650c0 100644 --- a/UnionPatcher.Gui/MainForm.cs +++ b/UnionPatcher.Gui/MainForm.cs @@ -72,7 +72,7 @@ namespace LBPUnion.UnionPatcher.Gui { ElfFile eboot = new(this.filePicker.FilePath); 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)\nThe EBOOT must be decrypted before using this tool").ShowModal(); return; } diff --git a/UnionPatcher/ElfFile.cs b/UnionPatcher/ElfFile.cs index a7a12bb..6a24bfc 100644 --- a/UnionPatcher/ElfFile.cs +++ b/UnionPatcher/ElfFile.cs @@ -35,8 +35,13 @@ namespace LBPUnion.UnionPatcher { public byte[] Contents { get; } = null; public ElfFile(byte[] fileContents) { + if(fileContents.length < 52) { + IsValid = false; + return; + } + IsValid = fileContents[0x00..0x04].SequenceEqual(new byte[] {0x7F, (byte)'E', (byte)'L', (byte)'F'}); - if(IsValid == false) return; + if(!IsValid) return; byte identClassValue = fileContents[0x04]; byte identDataValue = fileContents[0x05]; diff --git a/UnionPatcher/Program.cs b/UnionPatcher/Program.cs index 3e50c76..6cd7fb4 100644 --- a/UnionPatcher/Program.cs +++ b/UnionPatcher/Program.cs @@ -24,8 +24,9 @@ namespace LBPUnion.UnionPatcher { ElfFile eboot = new(new FileInfo(args[0])); - if(eboot.IsValid == false) { + if(!eboot.IsValid) { Console.WriteLine($"{eboot.Name} is not a valid ELF file (magic number mismatch)"); + Console.WriteLine("The EBOOT must be decrypted before using this tool"); return; }