/*
*IsSecRecoveryPEI.c
*IsSecRecoveryPEI PEI module decompiled from IDA
*/
#include "IsSecRecoveryPEI.h"
// SecRecoveryMemset @ 0xffe058bc void *SecRecoveryMemset(void *buf, unsigned int count, char value)
{
memset(buf, value, count); /*0xffe058c9*/
return buf; /*0xffe058cf*/
}
// SecRecoveryMemmove @ 0xffe058dc char *SecRecoveryMemmove(char *dst, char *src, unsigned int count)
{
unsigned int count_1; // edx char *dst_1; // edi char *src_1; // esi count_1 = count; /*0xffe058e6*/
if ( src < dst && &src[count - 1] >= dst ) /*0xffe058f4*/
{
src_1 = &src[count - 1]; /*0xffe05908*/
dst_1 = &dst[count - 1]; /*0xffe0590a*/
}
else
{
count_1 = count & 3; /*0xffe058f8*/
qmemcpy(dst, src, 4 * (count >> 2)); /*0xffe05901*/
src_1 = &src[4 * (count >> 2)]; /*0xffe05901*/
dst_1 = &dst[4 * (count >> 2)]; /*0xffe05901*/
}
qmemcpy(dst_1, src_1, count_1); /*0xffe05911*/
return dst; /*0xffe05918*/
}
// SecRecoveryMemset32Pairs @ 0xffe0593c int SecRecoveryMemset32Pairs(int a1, int a2, int a3, int a4)
{
do /*0xffe05955*/
{
*(_DWORD *)(a1 + 8 *a2 - 8) = a3; /*0xffe0594d*/
*(_DWORD *)(a1 + 8 *a2-- - 4) = a4; /*0xffe05951*/
}
while ( a2 ); /*0xffe05955*/
return a1; /*0xffe05959*/
}
// SecRecoveryMemset32 @ 0xffe0595c void *SecRecoveryMemset32(void *buf, unsigned int count, int value)
{
memset32(buf, value, count); /*0xffe05969*/
return buf; /*0xffe0596f*/
}
// _ModuleEntryPoint @ 0xffe05971 EFI_STATUS ModuleEntryPoint(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
int Ppi; // eax if ( *(_DWORD *)(LODWORD(SystemTable->Hdr.Signature) + 8) < 0x1000Au ) /*0xffe0597f*/
{
Ppi = SecRecoveryLocatePpi(); /*0xffe05981*/
if ( Ppi ) /*0xffe05988*/
(*(void ( **)(const char *, int, const char *))(Ppi + 4))( /*0xffe05996*/
"e:\\hs\\MdePkg\\Library\\PeimEntryPoint\\PeimEntryPoint.c",
46,
"(*PeiServices)->Hdr.Revision >= _gPeimRevision");
}
(*(void ( **)(EFI_SYSTEM_TABLE *, void *))(LODWORD(SystemTable->Hdr.Signature) + 36))( /*0xffe059a4*/
SystemTable,
&unk_FFE05F30);
return (*(EFI_STATUS ( **)(EFI_SYSTEM_TABLE *, void *))(LODWORD(SystemTable->Hdr.Signature) + 36))( /*0xffe059b5*/
SystemTable,
&unk_FFE05F24);
}
// SecRecoveryGetNvramVariable @ 0xffe059b7 char SecRecoveryGetNvramVariable(int n32, int a2, _DWORD *a3)
{
int ( **v5)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD); // [esp+8h] [ebp-8h] BYREF int n29; // [esp+Ch] [ebp-4h] BYREF if ( (*(int ( **)(int, void *, _DWORD, _DWORD, int ( ***)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD)))(*(_DWORD *)n32 + 32))( /*0xffe059d8*/
n32,
&unk_FFE05E9C,
0,
0,
&v5) < 0 )
return 0; /*0xffe059d8*/
n29 = 29; /*0xffe059de*/
if ( (*v5)(v5, L"AmiFlashUpd", &unk_FFE05F08, 0, &n29, a2) < 0 ) /*0xffe059fc*/
return 0; /*0xffe05a34*/
n29 = 4; /*0xffe05a16*/
if ( (*v5)(v5, L"MonotonicCounter", &unk_FFE05EEC, 0, &n29, a3) < 0 || *(_DWORD *)(a2 + 25) == -1 ) /*0xffe05a2a*/
*a3 = -1; /*0xffe05a2c*/
return 1; /*0xffe05a36*/
}
// SecRecoveryCheckRecoveryMode @ 0xffe05a3c char SecRecoveryCheckRecoveryMode(int n32, _DWORD *p_n32)
{
int v4[6]; // [esp+4h] [ebp-24h] BYREF int v5; // [esp+1Dh] [ebp-Bh]
int v6; // [esp+24h] [ebp-4h] BYREF v6 = 0; /*0xffe05a44*/
v5 = 0; /*0xffe05a47*/
LOBYTE(v4[0]) = 0; /*0xffe05a4a*/
if ( SecRecoveryGetNvramVariable(n32, (int)v4, &v6) && v6 == v5 ) /*0xffe05a67*/
{
if ( LOBYTE(v4[0]) == 1 ) /*0xffe05a6e*/
{
*p_n32 = 32; /*0xffe05a70*/
return 1; /*0xffe05a78*/
}
if ( LOBYTE(v4[0]) == 2 ) /*0xffe05a7c*/
{
*p_n32 = 18; /*0xffe05a7e*/
return 1; /*0xffe05a84*/
}
}
return 0; /*0xffe05a88*/
}
// SecRecoverySetBootMode32 @ 0xffe05a8d int SecRecoverySetBootMode32(int n32)
{
int n32_1; // esi n32_1 = n32; /*0xffe05a91*/
if ( (*(int ( **)(int, int *))(*(_DWORD *)n32 + 40))(n32, &n32) >= 0 /*0xffe05abc*/
&& n32 != 32
&& SecRecoveryCheckRecoveryMode(n32_1, &n32)
&& n32 == 32 )
{
(*(void ( **)(int, void *))(*(_DWORD *)n32_1 + 24))(n32_1, &unk_FFE05F18); /*0xffe05ac6*/
(*(void ( **)(int, int))(*(_DWORD *)n32_1 + 44))(n32_1, n32); /*0xffe05acf*/
}
return 0; /*0xffe05ad7*/
}
// SecRecoverySetBootMode18 @ 0xffe05ada int SecRecoverySetBootMode18(int n18)
{
int n18_1; // esi n18_1 = n18; /*0xffe05ade*/
if ( (*(int ( **)(int, int *))(*(_DWORD *)n18 + 40))(n18, &n18) >= 0 /*0xffe05afc*/
&& n18 == 17
&& SecRecoveryCheckRecoveryMode(n18_1, &n18) )
{
if ( n18 != 18 ) /*0xffe05b09*/
return 0; /*0xffe05b09*/
(*(void ( **)(int, int))(*(_DWORD *)n18_1 + 44))(n18_1, 18); /*0xffe05b10*/
}
if ( n18 == 18 ) /*0xffe05b19*/
(*(void ( **)(int, void *))(*(_DWORD *)n18_1 + 24))(n18_1, &unk_FFE05EFC); /*0xffe05b23*/
return 0; /*0xffe05b2a*/
}
// SecRecoveryLocatePpi @ 0xffe05b2d int SecRecoveryLocatePpi()
{
int PeiServices; // eax int v2; // [esp+0h] [ebp-8h] BYREF int Result; // [esp+4h] [ebp-4h] BYREF PeiServices = SecRecoveryGetPeiServices(); /*0xffe05b32*/
if ( (*(int ( **)(int, void *, _DWORD, int *, int *))(*(_DWORD *)PeiServices + 32))( /*0xffe05b51*/
PeiServices,
&unk_FFE05EAC,
0,
&v2,
&Result) >= 0 )
return Result; /*0xffe05b57*/
else return 0; /*0xffe05b53*/
}
// SecRecoveryPpiAssert @ 0xffe05b5e int SecRecoveryPpiAssert(
int e:__hs__MdePkg__Library__PeiServicesTablePointerLibIdt__PeiServ,
int n48,
int PeiServices____((void__)_0))
{
int result; // eax result = SecRecoveryLocatePpi(); /*0xffe05b64*/
if ( result ) /*0xffe05b6b*/
return (*(int ( **)(int, int, int))(result + 4))( /*0xffe05b73*/
e:__hs__MdePkg__Library__PeiServicesTablePointerLibIdt__PeiServ,
n48,
PeiServices____((void__)_0));
return result; /*0xffe05b79*/
}
// SecRecoveryGetPeiServices @ 0xffe05b7c int SecRecoveryGetPeiServices()
{
int Result; // esi _BYTE v2[8]; // [esp+4h] [ebp-8h] BYREF SecRecoveryReadIdtr(v2); /*0xffe05b85*/
Result = *(_DWORD *)(*(_DWORD *)&v2[2] - 4); /*0xffe05b8d*/
if ( !Result ) /*0xffe05b92*/
SecRecoveryPpiAssert( /*0xffe05ba1*/
(int)"e:\\hs\\MdePkg\\Library\\PeiServicesTablePointerLibIdt\\PeiServicesTablePointer.c",
48,
(int)"PeiServices != ((void *) 0)");
return Result; /*0xffe05ba9*/
}
// SecRecoveryReadIdtr @ 0xffe05bae void *__thiscall SecRecoveryReadIdtr(void *this)
{
void *this_1; // eax if ( !this ) /*0xffe05bb4*/
SecRecoveryPpiAssert((int)"e:\\hs\\MdePkg\\Library\\BaseLib\\X86ReadIdtr.c", 37, (int)"Idtr != ((void *) 0)"); /*0xffe05bc3*/
this_1 = this; /*0xffe05bc9*/
__sidt(this); /*0xffe05bcc*/
return this_1; /*0xffe05bd0*/
}