From a4e55a328c38e5339f42e3ff915285aa8419a0d5 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sat, 5 Nov 2022 23:47:50 -0700 Subject: [PATCH] Add boilerplate for NE, LE, PE builders --- BurnOutSharp.Builder/LinearExecutable.cs | 28 ++++++++++++++++++++++ BurnOutSharp.Builder/NewExecutable.cs | 28 ++++++++++++++++++++++ BurnOutSharp.Builder/PortableExecutable.cs | 28 ++++++++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/BurnOutSharp.Builder/LinearExecutable.cs b/BurnOutSharp.Builder/LinearExecutable.cs index 43cd6242..caa74684 100644 --- a/BurnOutSharp.Builder/LinearExecutable.cs +++ b/BurnOutSharp.Builder/LinearExecutable.cs @@ -16,6 +16,20 @@ namespace BurnOutSharp.Builder /// Filled executable on success, null on error public static Executable ParseExecutable(byte[] data, int offset) { + // If the data is invalid + if (data == null) + return null; + + // If the offset is out of bounds + if (offset < 0 || offset >= data.Length) + return null; + + // Cache the current offset + int initialOffset = offset; + + // Create a new executable to fill + var executable = new Executable(); + // TODO: Implement LE/LX parsing return null; } @@ -31,6 +45,20 @@ namespace BurnOutSharp.Builder /// Filled executable on success, null on error public static Executable ParseExecutable(Stream data) { + // If the data is invalid + if (data == null) + return null; + + // If the offset is out of bounds + if (data.Position < 0 || data.Position >= data.Length) + return null; + + // Cache the current offset + int initialOffset = (int)data.Position; + + // Create a new executable to fill + var executable = new Executable(); + // TODO: Implement LE/LX parsing return null; } diff --git a/BurnOutSharp.Builder/NewExecutable.cs b/BurnOutSharp.Builder/NewExecutable.cs index 333fcdd8..9b03c52c 100644 --- a/BurnOutSharp.Builder/NewExecutable.cs +++ b/BurnOutSharp.Builder/NewExecutable.cs @@ -16,6 +16,20 @@ namespace BurnOutSharp.Builder /// Filled executable on success, null on error public static Executable ParseExecutable(byte[] data, int offset) { + // If the data is invalid + if (data == null) + return null; + + // If the offset is out of bounds + if (offset < 0 || offset >= data.Length) + return null; + + // Cache the current offset + int initialOffset = offset; + + // Create a new executable to fill + var executable = new Executable(); + // TODO: Implement NE parsing return null; } @@ -31,6 +45,20 @@ namespace BurnOutSharp.Builder /// Filled executable on success, null on error public static Executable ParseExecutable(Stream data) { + // If the data is invalid + if (data == null) + return null; + + // If the offset is out of bounds + if (data.Position < 0 || data.Position >= data.Length) + return null; + + // Cache the current offset + int initialOffset = (int)data.Position; + + // Create a new executable to fill + var executable = new Executable(); + // TODO: Implement NE parsing return null; } diff --git a/BurnOutSharp.Builder/PortableExecutable.cs b/BurnOutSharp.Builder/PortableExecutable.cs index e05663fc..ecce394b 100644 --- a/BurnOutSharp.Builder/PortableExecutable.cs +++ b/BurnOutSharp.Builder/PortableExecutable.cs @@ -16,6 +16,20 @@ namespace BurnOutSharp.Builder /// Filled executable on success, null on error public static Executable ParseExecutable(byte[] data, int offset) { + // If the data is invalid + if (data == null) + return null; + + // If the offset is out of bounds + if (offset < 0 || offset >= data.Length) + return null; + + // Cache the current offset + int initialOffset = offset; + + // Create a new executable to fill + var executable = new Executable(); + // TODO: Implement PE parsing return null; } @@ -31,6 +45,20 @@ namespace BurnOutSharp.Builder /// Filled executable on success, null on error public static Executable ParseExecutable(Stream data) { + // If the data is invalid + if (data == null) + return null; + + // If the offset is out of bounds + if (data.Position < 0 || data.Position >= data.Length) + return null; + + // Cache the current offset + int initialOffset = (int)data.Position; + + // Create a new executable to fill + var executable = new Executable(); + // TODO: Implement PE parsing return null; }