KsepApplyShimsToDriver
__int64 __fastcall KsepApplyShimsToDriver(__int64 a1, __int64 a2, __int64 a3, unsigned int a4){
unsigned int v7;
__int64 v8;
__int64(__fastcall *v9)(__int64, _QWORD, _QWORD, _QWORD, _DWORD);
int v10;
unsigned int v11;
void *v12;
__int64 v13;
__int64 v14;
__int64 v16;
__int64 v17;
if( !a1 || !a2 || !a3 )
return 3221225485i64;
v7 = 0;
if( !a4 )
{
LABEL_16:
v14 = ((unsigned __int8)_InterlockedExchangeAdd(&KsepHistoryMessagesIndex, 1u) + 1) & 0x3F;
HIDWORD(KsepHistoryMessages[v14]) = 0;
LODWORD(KsepHistoryMessages[v14]) = 459438;
if( (KsepDebugFlag & 1) != 0 )
KsepDebugPrint(8i64, "KSE: Successfully applied shims to driver [%ws]\n", *(_QWORD *)(a2 + 8));
KsepLogInfo(8, "KSE: Successfully applied shims to driver [%ws]\n", *(_QWORD *)(a2 + 8));
return 0;
}
v8 = a3 + 72;
while( 1 )
{
if( (*(_DWORD *)(*(_QWORD *)v8 + 28i64) & 4) != 0 )
goto LABEL_15;
v9 = *(__int64(__fastcall **)(__int64, _QWORD, _QWORD, _QWORD, _DWORD))(*(_QWORD *)(*(_QWORD *)v8 + 16i64) + 40i64);
if( v9 )
{
v10 = v9(a2, *(_QWORD *)(a1 + 48), *(unsigned int *)(a1 + 64), *(unsigned int *)(a1 + 156), *(_DWORD *)(a1 + 120));
if( v10 < 0 )
break;
}
v11 = KsepPatchDriverImportsTable(a1, *(_QWORD *)(*(_QWORD *)v8 + 16i64));
if( (v11 & 0x80000000) != 0 )
{
v17 = ((unsigned __int8)_InterlockedExchangeAdd(&KsepHistoryErrorsIndex, 1u) + 1) & 0x3F;
dword_140C2A864[2 * v17] = v11;
KsepHistoryErrors[2 * v17] = 459415;
if( (KsepDebugFlag & 2) != 0 )
KsepDebugPrint(8i64, "KSE: Failed to patch driver [%ws]: 0x%x\n", *(_QWORD *)(a2 + 8), v11);
KsepLogError(8, "KSE: Failed to patch driver [%ws]: 0x%x\n", *(_QWORD *)(a2 + 8), v11);
return v11;
}
v12 = *(void **)(*(_QWORD *)v8 + 32i64);
if( v12 )
ObfReferenceObject(v12);
v13 = ((unsigned __int8)_InterlockedExchangeAdd(&KsepHistoryMessagesIndex, 1u) + 1) & 0x3F;
HIDWORD(KsepHistoryMessages[v13]) = 0;
LODWORD(KsepHistoryMessages[v13]) = 459434;
if( (KsepDebugFlag & 1) != 0 )
KsepDebugPrint(
8i64,
"KSE: Applied shim [0x%08X] to driver [%ws]\n",
**(unsigned int **)(*(_QWORD *)(*(_QWORD *)v8 + 16i64) + 8i64),
*(_QWORD *)(a2 + 8));
KsepLogInfo(
8,
"KSE: Applied shim [0x%08X] to driver [%ws]\n",
**(unsigned int **)(*(_QWORD *)(*(_QWORD *)v8 + 16i64) + 8i64),
*(_QWORD *)(a2 + 8));
LABEL_15:
++v7;
v8 += 80i64;
if( v7 >= a4 )
goto LABEL_16;
}
v16 = ((unsigned __int8)_InterlockedExchangeAdd(&KsepHistoryErrorsIndex, 1u) + 1) & 0x3F;
dword_140C2A864[2 * v16] = v10;
KsepHistoryErrors[2 * v16] = 459396;
if( (KsepDebugFlag & 2) != 0 )
KsepDebugPrint(8i64, "KSE: Driver blocked with [%ws]: 0x%x\n", *(_QWORD *)(a2 + 8), (unsigned int)v10);
KsepLogError(8, "KSE: Driver blocked with [%ws]: 0x%x\n", *(_QWORD *)(a2 + 8), (unsigned int)v10);
return(unsigned int)-1073740948;
}Referenced by:
KseDriverLoadImage