MiApplyDriverHotPatch

NTSTATUS __stdcall MiApplyDriverHotPatch(
        const _GUID *ApplicationId,
        UINT64 BlockId,
        VOID *Context,
        UINT64 a4,
        INT64 a5){
  int v5; 
  UINT64 *v8; 
  NTSTATUS result; 
  UINT64 *v10; 
  UINT64 *v11; 
  unsigned int v12; 
  void *Pool; 
  int v14; 
  unsigned int Data1; 
  int SectionStrongImageReference; 
  VOID *v17; 
  __int64 v18; 
  _MI_IMAGE_SECURITY_REFERENCE *SeImageStub; 
  NTSTATUS v20; 
  int v21; 
  INT8 v22; 
  INT64 v23; 
  INT64 v24; 
  INT64 v25; 
  INT64 v26; 
  INT64 v27; 
  INT64 v28; 
  INT64 v29[2]; 
  unsigned int v30; 
  __int64 v31; 
  int v32; 
  __int64 v33; 
  __int64 v34; 
  __int64 v35; 
  __int64 v36; 
  INT64 v37[2]; 
  int v38; 
  __int64 v39; 
  int v40; 
  __int64 v41; 
  __int64 v42; 
  __int64 v43; 
  __int64 v44; 
  INT64 v45[10]; 
  UINT64 v46; 
  CHAR *HotPatchBase; 

  v5 = *(_DWORD *)(BlockId + 196);
  v39 = 0i64;
  v40 = 0;
  v42 = 0i64;
  v8 = 0i64;
  v44 = 0i64;
  v31 = 0i64;
  v32 = 0;
  v34 = 0i64;
  v36 = 0i64;
  LODWORD(v46) = 0;
  if( (v5 & 0x20) != 0 )
    return -1073741800;
  LODWORD(v10) = RtlFindHotPatchInformation(*(VOID **)&ApplicationId[3].Data1);
  v11 = v10;
  HotPatchBase = RtlFindHotPatchBase(v10);
  if( !HotPatchBase )
    return -1073741701;
  v12 = *(_DWORD *)(BlockId + 64);
  v37[0] = BlockId;
  v41 = 0i64;
  v43 = 0i64;
  Pool = 0i64;
  v14 = (v12 >> 12) + ((v12 & 0xFFF) != 0);
  v37[1] = (INT64)HotPatchBase;
  Data1 = ApplicationId[4].Data1;
  v38 = v14;
  v29[0] = (INT64)ApplicationId;
  v29[1] = 0i64;
  v30 = (Data1 >> 12) + ((Data1 & 0xFFF) != 0);
  v33 = 0i64;
  v35 = 0i64;
  if( !*(_QWORD *)(BlockId + 280) )
    goto LABEL_11;
  result = VslDetermineHotPatchUndoTableSize(*(_QWORD *)(BlockId + 48), &v46);
  if( result < 0 )
    return result;
  if( !(_DWORD)v46 )
    goto LABEL_11;
  Pool = MiAllocatePool(256i64, (unsigned int)v46, 0x54555048ui64);
  if( !Pool )
    return -1073741670;
  SectionStrongImageReference = VslObtainHotPatchUndoTable(*(PVOID *)(BlockId + 48));
  if( SectionStrongImageReference >= 0 )
  {
LABEL_11:
    v17 = *(VOID **)(BlockId + 136);
    if( (*(_DWORD *)&ApplicationId[12].Data2 & 0x20) != 0
      || v17 == (VOID *)1
      || (v8 = MiAddEntryToImportList(*(INT64 **)(BlockId + 136), (UINT64)ApplicationId)) != 0i64 )
    {
      SectionStrongImageReference = MiPrepareDriverPatchState((INT64)v37);
      if( SectionStrongImageReference >= 0 )
      {
        SectionStrongImageReference = MiPrepareDriverPatchState((INT64)v29);
        if( SectionStrongImageReference >= 0 )
        {
          SectionStrongImageReference = MiIdentifyPatchImageWritablePages((INT64)v29);
          if( SectionStrongImageReference >= 0 )
          {
            if( (*(_DWORD *)&ApplicationId[12].Data2 & 0x20) != 0
              || (v45[1] = 0i64,
                  v18 = *((unsigned int *)HotPatchBase + 6),
                  v45[0] = (INT64)MiCheckHotPatchApplicable,
                  v45[2] = (INT64)v29,
                  LODWORD(v25) = 2,
                  LODWORD(v24) = 0,
                  SectionStrongImageReference = RtlApplyHotPatch(
                                                  *(_QWORD *)(v37[0] + 48),
                                                  *(_QWORD *)(v37[0] + 48),
                                                  0i64,
                                                  0i64,
                                                  0i64,
                                                  v22,
                                                  v23,
                                                  *(_QWORD *)(v29[0] + 48),
                                                  *(_QWORD *)(v29[0] + 48),
                                                  0i64,
                                                  v24,
                                                  0i64,
                                                  (INT64)v11,
                                                  (INT64)v11 + v18,
                                                  v25,
                                                  0i64,
                                                  0i64,
                                                  (INT64)v45,
                                                  v26,
                                                  v27,
                                                  v28),
                  SectionStrongImageReference >= 0) )
            {
              SectionStrongImageReference = MiPrepareDriverForHotPatch(v37, v29, v11, (INT64)Pool);
              if( SectionStrongImageReference >= 0 )
              {
                SeImageStub = MiSectionControlArea(*(_SECTION **)&ApplicationId[7].Data1)->u2.SeImageStub;
                SectionStrongImageReference = MiGetSectionStrongImageReference((INT64)SeImageStub);
                if( SectionStrongImageReference >= 0 )
                {
                  v20 = VslApplyHotPatch(
                          SeImageStub->StrongImageReference,
                          *(_QWORD *)&ApplicationId[7].Data1,
                          *(_QWORD *)(BlockId + 48),
                          BlockId,
                          *(_QWORD *)&ApplicationId[3].Data1,
                          (__int64)ApplicationId,
                          0i64);
                  SectionStrongImageReference = v20;
                  if( v20 >= 0 )
                  {
                    if( v8 )
                    {
                      *(_QWORD *)(BlockId + 136) = v8;
                      MiFreeLoadedImportList(v17);
                      v8 = 0i64;
                    }
                    *(_QWORD *)(BlockId + 280) = ApplicationId;
                    v21 = *(_DWORD *)&ApplicationId[12].Data2;
                    if( (v21 & 0x20) == 0 )
                    {
                      *(_QWORD *)ApplicationId[17].Data4 = BlockId;
                      *(_DWORD *)&ApplicationId[12].Data2 = v21 | 0x20;
                    }
                  }
                  else if( v20 == -1073740628 )
                  {
                    KeBugCheckEx(
                      0x1Au,
                      (PVOID)0x485018,
                      *(PVOID *)(BlockId + 48),
                      *(PVOID *)&ApplicationId[3].Data1,
                      0i64);
                  }
                }
              }
            }
          }
        }
      }
    }
    else
    {
      SectionStrongImageReference = -1073741670;
    }
  }
  MiUnlockDriverPages((UINT64 *)v37);
  MiUnlockDriverPages((UINT64 *)v29);
  if( Pool )
    ExFreePoolWithTag(Pool, 0);
  if( v8 )
    MiFreeLoadedImportList(v8);
  return SectionStrongImageReference;
}

Referenced by:

MiApplyHotPatchToLoadedDriver