Skip to content

Commit

Permalink
Update address/size information for Surface Duo 2 UEFI changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gus33000 committed Oct 14, 2023
1 parent fb6dc05 commit 44168ad
Showing 1 changed file with 52 additions and 21 deletions.
73 changes: 52 additions & 21 deletions SurfaceDuoDualBootKernelImagePatcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,58 @@ static byte[] PatchKernel(byte[] kernelBuffer, SurfaceDuoProduct surfaceDuoProdu
patchedKernelBuffer[2] = 0;
patchedKernelBuffer[3] = 0x14;

// Now we need to fill in the stack base of our firmware
// Stack Base: 0x00000000 9FC00000 (64 bit!)
patchedKernelBuffer[0x20] = 0;
patchedKernelBuffer[0x21] = 0;
patchedKernelBuffer[0x22] = 0xC0;
patchedKernelBuffer[0x23] = 0x9F;
patchedKernelBuffer[0x24] = 0;
patchedKernelBuffer[0x25] = 0;
patchedKernelBuffer[0x26] = 0;
patchedKernelBuffer[0x27] = 0;

// Then we need to fill in the stack size of our firmware
// Stack Base: 0x00000000 00300000 (64 bit!)
patchedKernelBuffer[0x28] = 0;
patchedKernelBuffer[0x29] = 0;
patchedKernelBuffer[0x2A] = 0x30;
patchedKernelBuffer[0x2B] = 0;
patchedKernelBuffer[0x2C] = 0;
patchedKernelBuffer[0x2D] = 0;
patchedKernelBuffer[0x2E] = 0;
patchedKernelBuffer[0x2F] = 0;
if (surfaceDuoProduct == SurfaceDuoProduct.Epsilon)
{
// Now we need to fill in the stack base of our firmware
// Stack Base: 0x00000000 9FC00000 (64 bit!)
patchedKernelBuffer[0x20] = 0;
patchedKernelBuffer[0x21] = 0;
patchedKernelBuffer[0x22] = 0xC0;
patchedKernelBuffer[0x23] = 0x9F;
patchedKernelBuffer[0x24] = 0;
patchedKernelBuffer[0x25] = 0;
patchedKernelBuffer[0x26] = 0;
patchedKernelBuffer[0x27] = 0;

// Then we need to fill in the stack size of our firmware
// Stack Base: 0x00000000 00300000 (64 bit!)
patchedKernelBuffer[0x28] = 0;
patchedKernelBuffer[0x29] = 0;
patchedKernelBuffer[0x2A] = 0x30;
patchedKernelBuffer[0x2B] = 0;
patchedKernelBuffer[0x2C] = 0;
patchedKernelBuffer[0x2D] = 0;
patchedKernelBuffer[0x2E] = 0;
patchedKernelBuffer[0x2F] = 0;
}
else if (surfaceDuoProduct == SurfaceDuoProduct.Zeta)
{
// Now we need to fill in the stack base of our firmware
// Stack Base: 0x00000000 9FC41000 (64 bit!)
patchedKernelBuffer[0x20] = 0;
patchedKernelBuffer[0x21] = 0x10;
patchedKernelBuffer[0x22] = 0xC4;
patchedKernelBuffer[0x23] = 0x9F;
patchedKernelBuffer[0x24] = 0;
patchedKernelBuffer[0x25] = 0;
patchedKernelBuffer[0x26] = 0;
patchedKernelBuffer[0x27] = 0;

// Then we need to fill in the stack size of our firmware
// Stack Base: 0x00000000 002BF000 (64 bit!)
patchedKernelBuffer[0x28] = 0;
patchedKernelBuffer[0x29] = 0xF0;
patchedKernelBuffer[0x2A] = 0x2B;
patchedKernelBuffer[0x2B] = 0;
patchedKernelBuffer[0x2C] = 0;
patchedKernelBuffer[0x2D] = 0;
patchedKernelBuffer[0x2E] = 0;
patchedKernelBuffer[0x2F] = 0;
}
else
{
throw new Exception("Unknown Surface Duo Product specified!");
}

// Finally, we add in the total kernel image size because we need to jump over!
uint kernelSize = (uint)patchedKernelBuffer.Length;
Expand Down

0 comments on commit 44168ad

Please sign in to comment.