Newer
Older
AMI-Aptio-BIOS-Reversed / Platform / ConstructConfigHdr.c
@Ajax Dong Ajax Dong 2 days ago 3 KB Init
// ConstructConfigHdr - decompiled from Platform.efi
CHAR16 *__fastcall ConstructConfigHdr(unsigned __int8 *SourceBuffer, __int16 *IntelSetup, __int64 a3)
{
  __int16 *IntelSetup_1; // rsi
  unsigned __int64 v6; // rbp
  unsigned __int8 *Node; // rdi
  UINTN j_1; // r12
  __int64 v9; // rax
  UINTN n0xF4240; // r14
  __int64 v12; // rbp
  CHAR16 *ZeroPool; // rax
  CHAR16 *ZeroPool_1; // rbx
  CHAR16 *Source; // r15
  unsigned __int64 i; // r13
  CHAR16 *Source_1; // r15
  CHAR16 *Source_2; // rsi
  UINTN j; // r15
  CHAR16 *ZeroPool_2; // rdx
  char k; // r8
  CHAR16 n38; // ax
  unsigned __int8 *Node_1; // [rsp+80h] [rbp+18h] BYREF

  IntelSetup_1 = IntelSetup; /*0x9830*/
  v6 = 0; /*0x9836*/
  if ( IntelSetup ) /*0x983c*/
    v6 = SetupOptionQuery(IntelSetup); /*0x9846*/
  Node = 0; /*0x9849*/
  j_1 = 0; /*0x984c*/
  if ( a3 ) /*0x9852*/
  {
    v9 = (*(__int64 (__fastcall **)(__int64, void *, unsigned __int8 **))(BootServices + 152))(a3, &unk_FA90, &Node_1); /*0x986d*/
    Node = Node_1; /*0x9874*/
    if ( v9 < 0 ) /*0x987f*/
      Node = 0; /*0x987f*/
    Node_1 = Node; /*0x9883*/
    if ( !Node ) /*0x988e*/
      return 0; /*0x988e*/
    j_1 = DevicePathAppend(Node); /*0x989f*/
  }
  n0xF4240 = 2 * (j_1 + 2 * v6) + 50; /*0x98a6*/
  v12 = 2 * n0xF4240; /*0x98ae*/
  ZeroPool = (CHAR16 *)AllocateZeroPool(2 * n0xF4240); /*0x98b5*/
  ZeroPool_1 = ZeroPool; /*0x98ba*/
  if ( !ZeroPool ) /*0x98c0*/
    return 0; /*0x9892*/
  HiiStringPacker(ZeroPool, n0xF4240, (const CHAR16 *)L"GUID="); /*0x98cf*/
  Source = &ZeroPool_1[SetupOptionQuery(ZeroPool_1)]; /*0x98dc*/
  if ( SourceBuffer ) /*0x98e3*/
  {
    for ( i = 0; i < 0x10; ++i ) /*0x98ea*/
    {
      Uint64ToStr(Source, (unsigned __int64)ZeroPool_1 + v12 - (_QWORD)Source, 160, SourceBuffer[i], 2u); /*0x990d*/
      Source += StrLen(Source); /*0x992c*/
    }
    IntelSetup_1 = IntelSetup; /*0x9936*/
  }
  StrCatS(ZeroPool_1, n0xF4240, (const CHAR16 *)L"&NAME="); /*0x9948*/
  Source_1 = &Source[SetupOptionQuery(Source)]; /*0x9958*/
  if ( IntelSetup_1 ) /*0x995f*/
  {
    while ( *IntelSetup_1 ) /*0x99ac*/
    {
      Uint64ToStr( /*0x9982*/
        Source_1,
        (unsigned __int64)ZeroPool_1 + v12 - (_QWORD)Source_1,
        160,
        (unsigned __int16)*IntelSetup_1++,
        4u);
      Source_1 += StrLen(Source_1); /*0x99a2*/
    }
  }
  StrCatS(ZeroPool_1, n0xF4240, (const CHAR16 *)L"&PATH="); /*0x99bb*/
  Source_2 = &Source_1[SetupOptionQuery(Source_1)]; /*0x99c8*/
  for ( j = 0; j < j_1; Source_2 += StrLen(Source_2) ) /*0x99d2*/
    Uint64ToStr(Source_2, (unsigned __int64)ZeroPool_1 + v12 - (_QWORD)Source_2, 160, Node[j++], 2u); /*0x99f4*/
  *Source_2 = 0; /*0x9a1c*/
  if ( !ZeroPool_1 ) /*0x9a23*/
    Assert((__int64)"e:\\hs\\MdeModulePkg\\Library\\UefiHiiLib\\HiiLib.c", 525, (__int64)"ConfigString != ((void *) 0)"); /*0x9a38*/
  ZeroPool_2 = ZeroPool_1; /*0x9a3d*/
  for ( k = 0; *ZeroPool_2; ++ZeroPool_2 ) /*0x9a43*/
  {
    n38 = *ZeroPool_2; /*0x9a49*/
    if ( *ZeroPool_2 == 61 ) /*0x9a50*/
    {
      k = 1; /*0x9a52*/
    }
    else if ( n38 == 38 ) /*0x9a5b*/
    {
      k = 0; /*0x9a5d*/
    }
    else if ( k ) /*0x9a65*/
    {
      if ( (unsigned __int16)(n38 - 65) <= 5u ) /*0x9a6e*/
        *ZeroPool_2 = n38 + 32; /*0x9a74*/
    }
  }
  return ZeroPool_1; /*0x9a8c*/
}