Newer
Older
AMI-Aptio-BIOS-Reversed / NvdimmSmbusCommon / NvdimmSmbusCommon.c
@Ajax Dong Ajax Dong 2 days ago 11 KB Init
#include "NvdimmSmbusCommon.h"

// NvdimmSmbusCommon - UEFI Module (Regenerated from IDA)
// Total functions: 14

// Function: InternalMemZeroMem @ 0x1000 (0x20 bytes)
// Index: 1/14

char *__fastcall InternalMemZeroMem(char *buf, unsigned __int64 n0xF)
{
  memset(buf, 0, 8 * (n0xF >> 3)); /*0x1016*/
  memset(&buf[8 * (n0xF >> 3)], 0, n0xF & 7); /*0x101b*/
  return buf; /*0x101e*/
}

// Function: _ModuleEntryPoint @ 0x10c4 (0x49 bytes)
// Index: 2/14

EFI_STATUS ModuleEntryPoint(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
  signed __int64 v3; // rbx

  UefiBootServicesTableLibConstructor((__int64)ImageHandle, SystemTable); /*0x10cd*/
  v3 = NvdimmSmbusCommonEntryPoint(ImageHandle); /*0x10da*/
  if ( v3 < 0 ) /*0x10e0*/
  {
    (*(void (__fastcall **)(__int64))(BootServices_0 + 112))(qword_3070); /*0x10f0*/
    (*(void (__fastcall **)(__int64))(BootServices_0 + 112))(qword_3078); /*0x1101*/
  }
  return v3; /*0x1107*/
}

// Function: UefiBootServicesTableLibConstructor @ 0x1110 (0x1a4 bytes)
// Index: 3/14

__int64 __fastcall UefiBootServicesTableLibConstructor(__int64 ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
  EFI_BOOT_SERVICES *BootServices; // r10
  __int64 result; // rax
  __int64 v5; // rbx

  ::ImageHandle = ImageHandle; /*0x111a*/
  if ( !ImageHandle ) /*0x112e*/
    sub_1544( /*0x113d*/
      (__int64)"e:\\hs\\MdePkg\\Library\\UefiBootServicesTableLib\\UefiBootServicesTableLib.c",
      51,
      (__int64)"gImageHandle != ((void *) 0)");
  ::SystemTable = (__int64)SystemTable; /*0x1142*/
  if ( !SystemTable ) /*0x114c*/
    sub_1544( /*0x115b*/
      (__int64)"e:\\hs\\MdePkg\\Library\\UefiBootServicesTableLib\\UefiBootServicesTableLib.c",
      57,
      (__int64)"gST != ((void *) 0)");
  ::BootServices = (__int64)SystemTable->BootServices; /*0x1164*/
  if ( !::BootServices ) /*0x116e*/
    sub_1544( /*0x117d*/
      (__int64)"e:\\hs\\MdePkg\\Library\\UefiBootServicesTableLib\\UefiBootServicesTableLib.c",
      63,
      (__int64)"gBS != ((void *) 0)");
  RuntimeServices = (__int64)SystemTable->RuntimeServices; /*0x1186*/
  if ( !RuntimeServices ) /*0x1190*/
    sub_1544( /*0x11a3*/
      (__int64)"e:\\hs\\MdePkg\\Library\\UefiRuntimeServicesTableLib\\UefiRuntimeServicesTableLib.c",
      47,
      (__int64)"gRT != ((void *) 0)");
  BootServices = SystemTable->BootServices; /*0x11b3*/
  RuntimeServices_0 = (__int64)SystemTable->RuntimeServices; /*0x11ba*/
  BootServices_0 = (__int64)BootServices; /*0x11cd*/
  ((void (__fastcall *)(__int64, __int64, void (*)()))BootServices->CreateEvent)(513, 8, sub_1584); /*0x11df*/
  (*(void (__fastcall **)(__int64, __int64, __int64 (__fastcall *)(), _QWORD, __int64 *))(BootServices_0 + 80))( /*0x1207*/
    1610613250,
    8,
    sub_1590,
    0,
    &qword_3078);
  sub_167C(); /*0x120a*/
  result = sub_15B8((__int64)&unk_3030, &qword_3098); /*0x121d*/
  v5 = result; /*0x1222*/
  if ( result < 0 ) /*0x122d*/
  {
    sub_14C4(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", result); /*0x123b*/
    result = sub_1544( /*0x1253*/
               (__int64)"e:\\hs\\MdePkg\\Library\\DxeServicesTableLib\\DxeServicesTableLib.c",
               64,
               (__int64)"!EFI_ERROR (Status)");
  }
  if ( !qword_3098 ) /*0x1260*/
    result = sub_1544( /*0x1275*/
               (__int64)"e:\\hs\\MdePkg\\Library\\DxeServicesTableLib\\DxeServicesTableLib.c",
               65,
               (__int64)"gDS != ((void *) 0)");
  if ( v5 < 0 ) /*0x127d*/
  {
    sub_14C4(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", v5); /*0x128c*/
    return sub_1544( /*0x12a4*/
             (__int64)"e:\\hs\\Build\\HR6N0XMLK\\DEBUG_VS2015\\X64\\PurleySktPkg\\Dxe\\NvdimmCommon\\NvdimmSmbusCommon\\DEBUG\\AutoGen.c",
             265,
             (__int64)"!EFI_ERROR (Status)");
  }
  return result; /*0x12ae*/
}

// Function: NvdimmSmbusCommonEntryPoint @ 0x12b4 (0x124 bytes)
// Index: 4/14

unsigned __int64 __fastcall NvdimmSmbusCommonEntryPoint(EFI_HANDLE ImageHandle)
{
  __int64 v1; // rax
  __int64 v2; // rbx
  const char *[NGN]_ERROR:_SMBUS_NONSMM___SMM_memory_allocation_failed_with_s; // rdx
  EFI_HANDLE ImageHandle_1; // [rsp+30h] [rbp+8h] BYREF
  char *buf; // [rsp+38h] [rbp+10h] BYREF

  ImageHandle_1 = ImageHandle; /*0x12c9*/
  buf = (char *)0xFFFFFFFFLL; /*0x12d6*/
  v1 = (*(__int64 (__fastcall **)(__int64, __int64, __int64, char **))(BootServices + 40))(1, 10, 1, &buf); /*0x12e9*/
  v2 = v1; /*0x12ec*/
  if ( v1 < 0 )
  {
    [NGN]_ERROR:_SMBUS_NONSMM___SMM_memory_allocation_failed_with_s = "[NGN] ERROR: SMBUS NONSMM<->SMM memory allocation "
                                                                      "failed with status (%r)\n";
LABEL_5:
    sub_14C4(0x80000000LL, [NGN]_ERROR:_SMBUS_NONSMM___SMM_memory_allocation_failed_with_s, v1); /*0x1384*/
    sub_14C4(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", v2); /*0x139f*/
    sub_1544( /*0x13b7*/
      (__int64)"e:\\hs\\PurleySktPkg\\Dxe\\NvdimmCommon\\NvdimmSmbusCommon.c",
      60,
      (__int64)"!EFI_ERROR (Status)");
    return (v2 >> 63) & 0x8000000000000001uLL; /*0x13b7*/
  }
  sub_14C4(64, "[NGN] SMBUS NONSMM<->SMM interface address: 0x%llx\n", buf);
  ::buf = (__int64)buf; /*0x1320*/
  sub_13D8(buf, 0xFu); /*0x1327*/
  sub_13D8(&buf_, 0x10u); /*0x1338*/
  buf_0 = ::buf; /*0x134b*/
  buf_ = 1; /*0x1368*/
  v1 = (*(__int64 (__fastcall **)(EFI_HANDLE *, void *, _QWORD, char *))(BootServices + 128))( /*0x136f*/
         &ImageHandle_1,
         &unk_3010,
         0,
         &buf_);
  v2 = v1; /*0x1375*/
  if ( v1 < 0 )
  {
    [NGN]_ERROR:_SMBUS_NONSMM___SMM_memory_allocation_failed_with_s = "[NGN] ERROR: SMBUS NONSMM<->SMM interface protocol"
                                                                      " installation failed with status (%r)\n";
    goto LABEL_5; /*0x137d*/
  }
  return (v2 >> 63) & 0x8000000000000001uLL; /*0x13d2*/
}

// Function: ZeroMemWrapper @ 0x13d8 (0x63 bytes)
// Index: 5/14

char *__fastcall ZeroMemWrapper(char *buf, unsigned __int64 n0xF)
{
  if ( !buf ) /*0x13eb*/
    sub_1544( /*0x13fe*/
      (__int64)"e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\ZeroMemWrapper.c",
      53,
      (__int64)"Buffer != ((void *) 0)");
  if ( n0xF > -(__int64)buf ) /*0x140c*/
    sub_1544( /*0x1421*/
      (__int64)"e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\ZeroMemWrapper.c",
      54,
      (__int64)"Length <= (0xFFFFFFFFFFFFFFFFULL - (UINTN)Buffer + 1)");
  return sub_1000(buf, n0xF); /*0x1431*/
}

// Function: GetSmbusProtocol @ 0x143c (0x86 bytes)
// Index: 6/14

__int64 GetSmbusProtocol()
{
  __int64 result; // rax
  unsigned __int64 n0x10; // rbx
  __int64 v2; // rax
  __int64 v3; // rcx

  result = qword_3088; /*0x1446*/
  if ( !qword_3088 ) /*0x1452*/
  {
    if ( BootServices_0 /*0x1480*/
      && (n0x10 = (*(__int64 (__fastcall **)(__int64))(BootServices_0 + 24))(31),
          (*(void (__fastcall **)(unsigned __int64))(BootServices_0 + 32))(n0x10),
          n0x10 <= 0x10) )
    {
      v2 = (*(__int64 (__fastcall **)(void *, _QWORD, __int64 *))(BootServices_0 + 320))(&unk_3000, 0, &qword_3088); /*0x1499*/
      v3 = qword_3088; /*0x149f*/
      if ( v2 < 0 ) /*0x14a9*/
        v3 = 0; /*0x14a9*/
      qword_3088 = v3; /*0x14ad*/
      return v3; /*0x14b4*/
    }
    else
    {
      return 0; /*0x1460*/
    }
  }
  return result; /*0x14bc*/
}

// Function: DebugLogPrint @ 0x14c4 (0x80 bytes)
// Index: 7/14

__int64 DebugLogPrint(__int64 a1, const char *a2, ...)
{
  __int64 result; // rax
  __int64 v4; // r8
  __int64 (__fastcall **v5)(__int64, const char *, __int64 *); // r9
  unsigned __int8 v6; // al
  unsigned __int8 n3; // al
  int n113; // edx
  va_list va; // [rsp+40h] [rbp+18h] BYREF

  va_start(va, a2);
  result = GetSmbusProtocol(); /*0x14db*/
  v4 = 0; /*0x14e0*/
  v5 = (__int64 (__fastcall **)(__int64, const char *, __int64 *))result; /*0x14e3*/
  if ( result ) /*0x14e9*/
  {
    v6 = __inbyte(0x70u); /*0x14ef*/
    __outbyte(0x70u, v6 & 0x80 | 0x4B); /*0x14f4*/
    n113 = 113; /*0x14f5*/
    n3 = __inbyte(0x71u); /*0x14f9*/
    LOBYTE(n113) = n3; /*0x14fa*/
    if ( n3 > 3u ) /*0x14fe*/
    {
      n113 = 3; /*0x1507*/
      if ( n113 ) /*0x150d*/
        n113 = (unsigned __int8)n113; /*0x150d*/
    }
    result = (unsigned int)(n113 - 1); /*0x1510*/
    if ( (unsigned __int8)(n113 - 1) <= 0xFDu ) /*0x1515*/
    {
      result = 2147483652LL; /*0x151a*/
      v4 = 2147483718LL; /*0x151f*/
      if ( (_BYTE)n113 == 1 ) /*0x1525*/
        v4 = 2147483652LL; /*0x1525*/
    }
    if ( (v4 & a1) != 0 ) /*0x152c*/
      return (*v5)(a1, a2, (__int64 *)va); /*0x153b*/
  }
  return result; /*0x153e*/
}

// Function: AssertCpuDeadLoop @ 0x1544 (0x3e bytes)
// Index: 8/14

__int64 __fastcall AssertCpuDeadLoop(__int64 a1, __int64 a2, __int64 a3)
{
  __int64 result; // rax

  result = GetSmbusProtocol(); /*0x155c*/
  if ( result ) /*0x1564*/
    return (*(__int64 (__fastcall **)(__int64, __int64, __int64))(result + 8))(a1, a2, a3); /*0x156f*/
  return result; /*0x157c*/
}

// Function: CleanupEventNotify1 @ 0x1584 (0x9 bytes)
// Index: 9/14

// (too small: 9 bytes)

// Function: CleanupEventNotify2 @ 0x1590 (0x26 bytes)
// Index: 10/14

__int64 CleanupEventNotify2()
{
  __int64 result; // rax

  if ( qword_3088 ) /*0x159c*/
    return (*(__int64 (__fastcall **)(_QWORD, __int64 *))(RuntimeServices_0 + 64))(0, &qword_3088); /*0x15ae*/
  return result; /*0x15b1*/
}

// Function: EfiGetSystemConfigurationTable @ 0x15b8 (0xc4 bytes)
// Index: 11/14

EFI_STATUS __cdecl EfiGetSystemConfigurationTable(EFI_GUID *TableGuid, void **Table)
{
  __int64 SystemTable; // rdi
  __int64 v5; // rbx
  __int64 i; // r14

  if ( !TableGuid ) /*0x15da*/
    AssertCpuDeadLoop((__int64)"e:\\hs\\MdePkg\\Library\\UefiLib\\UefiLib.c", 97, (__int64)"TableGuid != ((void *) 0)"); /*0x15ed*/
  if ( !Table ) /*0x15f5*/
    AssertCpuDeadLoop((__int64)"e:\\hs\\MdePkg\\Library\\UefiLib\\UefiLib.c", 98, (__int64)"Table != ((void *) 0)"); /*0x1608*/
  SystemTable = SystemTable; /*0x160d*/
  v5 = 0; /*0x1614*/
  *Table = 0; /*0x1616*/
  if ( !*(_QWORD *)(SystemTable + 104) ) /*0x161a*/
    return 0x800000000000000EuLL; /*0x1643*/
  for ( i = 0; !sub_1700((__int64)TableGuid, i + *(_QWORD *)(SystemTable + 112)); i += 24 ) /*0x1620*/
  {
    if ( (unsigned __int64)++v5 >= *(_QWORD *)(SystemTable + 104) ) /*0x1641*/
      return 0x800000000000000EuLL; /*0x1641*/
  }
  *Table = *(void **)(*(_QWORD *)(SystemTable + 112) + 24 * v5 + 16); /*0x1677*/
  return 0; /*0x1661*/
}

// Function: GetHobList @ 0x167c (0x82 bytes)
// Index: 12/14

void *__cdecl GetHobList()
{
  void *Table_; // rax
  signed __int64 SystemConfigurationTable; // rax

  Table_ = (void *)Table_; /*0x1680*/
  if ( !Table_ ) /*0x168a*/
  {
    SystemConfigurationTable = EfiGetSystemConfigurationTable(&TableGuid_, (void **)&Table_); /*0x169a*/
    if ( SystemConfigurationTable < 0 ) /*0x16a2*/
    {
      DebugLogPrint(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", SystemConfigurationTable); /*0x16b3*/
      AssertCpuDeadLoop((__int64)"e:\\hs\\MdePkg\\Library\\DxeHobLib\\HobLib.c", 54, (__int64)"!EFI_ERROR (Status)"); /*0x16cb*/
    }
    Table_ = (void *)Table_; /*0x16d0*/
    if ( !Table_ ) /*0x16da*/
    {
      AssertCpuDeadLoop( /*0x16ed*/
        (__int64)"e:\\hs\\MdePkg\\Library\\DxeHobLib\\HobLib.c",
        55,
        (__int64)"mHobList != ((void *) 0)");
      return (void *)Table_; /*0x16f2*/
    }
  }
  return Table_; /*0x16f9*/
}

// Function: GuidEqual @ 0x1700 (0x67 bytes)
// Index: 13/14

bool __fastcall GuidEqual(EFI_GUID *TableGuid, __int64 TableGuid_1)
{
  __int128 v4; // rdi
  __int64 v5; // rbx

  *((_QWORD *)&v4 + 1) = sub_1768((__int64)TableGuid); /*0x1722*/
  v5 = sub_1768(TableGuid_1); /*0x172e*/
  *(_QWORD *)&v4 = sub_1768((__int64)TableGuid->Data4); /*0x173a*/
  return v4 == __PAIR128__(v5, sub_1768(TableGuid_1 + 8)); /*0x1761*/
}

// Function: Crc32GuidHash @ 0x1768 (0x2f bytes)
// Index: 14/14

__int64 __fastcall Crc32GuidHash(EFI_GUID *TableGuid)
{
  if ( !TableGuid ) /*0x1774*/
    AssertCpuDeadLoop((__int64)"e:\\hs\\MdePkg\\Library\\BaseLib\\Unaligned.c", 192, (__int64)"Buffer != ((void *) 0)"); /*0x1789*/
  return *(_QWORD *)&TableGuid->Data1; /*0x1791*/
}