Newer
Older
AMI-Aptio-BIOS-Reversed / PurleyPlatPkg / BootGuard / ExtendBtGSupportToDxe / Pei / BootGuardPei / BootGuardPeiEntry.c
@Ajax Dong Ajax Dong 2 days ago 4 KB Restructure the repo
int __cdecl BootGuardPeiEntry(int a1)
{
  int PeiServices; // eax
  int v2; // esi
  int v4; // eax
  int v5; // esi
  int BootGuardHashKey; // ebp
  int v7; // eax
  int v8; // eax
  int v9; // eax
  int *ZeroPool_1; // esi
  unsigned int n0x20; // edi
  unsigned int i; // ebx
  unsigned int j; // ebx
  unsigned int k; // ebx
  int v15; // eax
  int PcdPei; // eax
  int v17; // eax
  int v18; // [esp+4h] [ebp-50h] BYREF
  int ZeroPool; // [esp+8h] [ebp-4Ch] BYREF
  int n17; // [esp+Ch] [ebp-48h] BYREF
  _BYTE v21[32]; // [esp+14h] [ebp-40h] BYREF
  _BYTE v22[32]; // [esp+34h] [ebp-20h] BYREF

  PeiServices = GetPeiServices(); /*0xffde31c3*/
  v2 = (*(int (__cdecl **)(int, int *))(*(_DWORD *)PeiServices + 40))(PeiServices, &n17); /*0xffde31d3*/
  if ( v2 < 0 ) /*0xffde31d9*/
  {
    DebugPrint(0x80000000, "[BootGuardPei.c] Get Boot Mode is fail\n"); /*0xffde31e5*/
    return v2; /*0xffde31ee*/
  }
  if ( n17 == 17 ) /*0xffde31f8*/
  {
    DebugPrint(64, "[BootGuardPei.c] In the BOOT_ON_S3_RESUME\n"); /*0xffde3201*/
    return v2; /*0xffde3201*/
  }
  v4 = Sha256ContextSize(); /*0xffde3204*/
  v5 = (*(int (__cdecl **)(int, int, int *))(*(_DWORD *)a1 + 76))(a1, v4, &v18); /*0xffde3219*/
  if ( v5 < 0 ) /*0xffde3220*/
  {
    DebugPrint(0x80000000, "[BootGuardPei.c] AllocatePool is fail for BootGuardSha256Context\n"); /*0xffde3227*/
    return v5; /*0xffde3249*/
  }
  ZeroPool = AllocateZeroPool(); /*0xffde322e*/
  if ( !ZeroPool ) /*0xffde3234*/
  {
    DebugPrint(0x80000000, "[BootGuardPei.c] AllocateZeroPool is fail for RESERVE_BOOT_GUARD_FV_MAIN_HASH_KEY\n"); /*0xffde3240*/
    return v5; /*0xffde3240*/
  }
  BootGuardHashKey = LocateBootGuardHashKey((int)&ZeroPool); /*0xffde325b*/
  if ( BootGuardHashKey >= 0 ) /*0xffde3260*/
  {
    ZeroPool_1 = (int *)ZeroPool; /*0xffde32a9*/
    n0x20 = 0; /*0xffde32ad*/
    for ( i = 0; i < 0x20; ++i ) /*0xffde32b0*/
      DebugPrint(64, "[BootGuardPei.c] BootGuardFvMainHashKey0[%x]= %x.\n", i, *((unsigned __int8 *)ZeroPool_1 + i)); /*0xffde32bf*/
    DebugPrint(64, "\n[BootGuardPei.c] BootGuardFvMainSegmentBase0= %x.\n", ZeroPool_1[8]); /*0xffde32d7*/
    DebugPrint(64, "\n[BootGuardPei.c] BootGuardFvMainSegmentSize0= %x.\n", ZeroPool_1[9]); /*0xffde32e6*/
    Sha256InitWrapper(v18); /*0xffde32ef*/
    Sha256UpdateWrapper(v18, ZeroPool_1[8], ZeroPool_1[9]); /*0xffde32fe*/
    Sha256FinalWrapper(v18, (int)v21); /*0xffde330c*/
    for ( j = 0; j < 0x20; ++j ) /*0xffde3314*/
      DebugPrint(64, "[BootGuardPei.c] CurrentBootGuardFvMainHash256Val[%x]= %x.\n", j, (unsigned __int8)v21[j]); /*0xffde3324*/
    if ( CompareMem((int)ZeroPool_1, (int)v21, 32) ) /*0xffde333a*/
    {
      DebugPrint(64, "[BootGuardPei.c] FvMainHashKey0 Verify Fail.\n"); /*0xffde334d*/
    }
    else
    {
      if ( !ZeroPool_1[18] ) /*0xffde3352*/
        return BootGuardHashKey; /*0xffde3352*/
      if ( !ZeroPool_1[19] ) /*0xffde335b*/
        return BootGuardHashKey; /*0xffde335b*/
      for ( k = 0; k < 0x20; ++k ) /*0xffde3364*/
        DebugPrint( /*0xffde3374*/
          64,
          "[BootGuardPei.c] BootGuardFvMainHashKey1[%x]= %x.\n",
          k,
          *((unsigned __int8 *)ZeroPool_1 + k + 40));
      DebugPrint(64, "\n[BootGuardPei.c] BootGuardFvMainSegmentBase1= %x.\n", ZeroPool_1[18]); /*0xffde338e*/
      DebugPrint(64, "\n[BootGuardPei.c] BootGuardFvMainSegmentSize1= %x.\n", ZeroPool_1[19]); /*0xffde339c*/
      Sha256InitWrapper(v18); /*0xffde33a5*/
      Sha256UpdateWrapper(v18, ZeroPool_1[18], ZeroPool_1[19]); /*0xffde33b4*/
      Sha256FinalWrapper(v18, (int)v22); /*0xffde33c2*/
      do /*0xffde33e3*/
      {
        DebugPrint( /*0xffde33d7*/
          64,
          "[BootGuardPei.c] CurrentBootGuardFvMainHash256Val2[%x]= %x.\n",
          n0x20,
          (unsigned __int8)v22[n0x20]);
        ++n0x20; /*0xffde33df*/
      }
      while ( n0x20 < 0x20 ); /*0xffde33e3*/
      if ( !CompareMem((int)(ZeroPool_1 + 10), (int)v22, 32) ) /*0xffde33f0*/
        return BootGuardHashKey; /*0xffde343c*/
      DebugPrint(64, "[BootGuardPei.c] FvMainHashKey1 Verify Fail.\n"); /*0xffde3402*/
    }
    v15 = GetPeiServices(); /*0xffde3407*/
    (*(void (__cdecl **)(int, int))(*(_DWORD *)v15 + 44))(v15, 32); /*0xffde3411*/
    DebugClear(); /*0xffde3414*/
    PcdPei = GetPcdPei(); /*0xffde3419*/
    if ( !(*(unsigned __int8 (__cdecl **)(int))(PcdPei + 24))(9) ) /*0xffde3420*/
    {
      v17 = GetPcdPei(); /*0xffde342a*/
      (*(void (__cdecl **)(int, int))(v17 + 80))(9, 1); /*0xffde3433*/
    }
    return 0; /*0xffde3438*/
  }
  else
  {
    DebugPrint(0x80000000, "[BootGuardPei.c] LocateBootGuardHashKey is fail\n"); /*0xffde326c*/
    v7 = GetPeiServices(); /*0xffde3271*/
    (*(void (__cdecl **)(int, int))(*(_DWORD *)v7 + 44))(v7, 32); /*0xffde327b*/
    DebugClear(); /*0xffde327e*/
    v8 = GetPcdPei(); /*0xffde3283*/
    if ( !(*(unsigned __int8 (__cdecl **)(int))(v8 + 24))(9) ) /*0xffde328a*/
    {
      v9 = GetPcdPei(); /*0xffde3294*/
      (*(void (__cdecl **)(int, int))(v9 + 80))(9, 1); /*0xffde329d*/
    }
    return BootGuardHashKey; /*0xffde32a2*/
  }
}