Skip to content

Commit

Permalink
Add a parameter for UEFI FD to do the concat (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
MollySophia authored Oct 14, 2023
1 parent 44168ad commit fe138c0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions SurfaceDuoDualBootKernelImagePatcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ internal class Program
{
static void Main(string[] args)
{
if (args.Length != 3)
if (args.Length != 4)
{
Console.WriteLine("Usage: <Kernel Image to Patch> <Patched Kernel Image Destination> <0: Epsilon, 1: Zeta>");
Console.WriteLine("Usage: <Kernel Image to Patch> <Patched Kernel Image Destination> <0: Epsilon, 1: Zeta> <UEFI FD Image>");
return;
}

File.WriteAllBytes(args[1], PatchKernel(File.ReadAllBytes(args[0]), (SurfaceDuoProduct)uint.Parse(args[2])));
File.WriteAllBytes(args[1], PatchKernel(File.ReadAllBytes(args[0]), File.ReadAllBytes(args[3]), (SurfaceDuoProduct)uint.Parse(args[2])));
}

static byte[] PatchKernel(byte[] kernelBuffer, SurfaceDuoProduct surfaceDuoProduct)
static byte[] PatchKernel(byte[] kernelBuffer, byte[] uefiBuffer, SurfaceDuoProduct surfaceDuoProduct)
{
byte[] patchedKernelBuffer = new byte[kernelBuffer.Length];
byte[] patchedKernelBuffer = new byte[kernelBuffer.Length + uefiBuffer.Length];

// Copy the original kernel first into the patched buffer
Array.Copy(kernelBuffer, patchedKernelBuffer, kernelBuffer.Length);
Array.Copy(uefiBuffer, 0, patchedKernelBuffer, kernelBuffer.Length, uefiBuffer.Length);

// Determine the loading offset of the kernel first,
// we are either going to find a b instruction on the
Expand Down Expand Up @@ -123,7 +124,7 @@ static byte[] PatchKernel(byte[] kernelBuffer, SurfaceDuoProduct surfaceDuoProdu
}

// Finally, we add in the total kernel image size because we need to jump over!
uint kernelSize = (uint)patchedKernelBuffer.Length;
uint kernelSize = (uint)kernelBuffer.Length;
byte[] kernelSizeBuffer = BitConverter.GetBytes(kernelSize);
patchedKernelBuffer[0x30] = kernelSizeBuffer[0];
patchedKernelBuffer[0x31] = kernelSizeBuffer[1];
Expand Down

0 comments on commit fe138c0

Please sign in to comment.