DbgkpWerCleanupContext

VOID __stdcall DbgkpWerCleanupContext(_DBGKWER_CONTEXT *Context){
  void *v2; 
  UINT64 v3; 
  INT64 v4; 
  UINT64 v5; 
  void *v6; 
  _QWORD *v7; 
  _ADAPTER_OBJECT *v8; 
  __int64 v9; 
  _QWORD *v10; 
  void *v11; 
  _QWORD *v12; 
  void *v13; 
  void *v14; 
  int v15; 
  int v16; 

  DbgPrintEx(5u, 3u, "DBGK: DbgkpWerCleanupContext: Context 0x%p\n", Context);
  if( Context )
  {
    v2 = (void *)*((_QWORD *)Context + 17);
    if( v2 )
    {
      IopLiveDumpTraceInterfaceStart(2ui64);
      IopLiveDumpTraceInterfaceEnd(v3, 2i64, 0i64);
      IopLiveDumpReleaseResources((INT64)v2, v4, v5);
      ExFreePoolWithTag(v2, 0x706D644Cu);
      *((_QWORD *)Context + 17) = 0i64;
    }
    v6 = (void *)*((_QWORD *)Context + 15);
    if( v6 )
    {
      ExFreePoolWithTag(v6, 0x57676244u);
      *((_QWORD *)Context + 15) = 0i64;
    }
    v7 = (_QWORD *)*((_QWORD *)Context + 16);
    if( v7 )
    {
      v8 = (_ADAPTER_OBJECT *)v7[2];
      if( v8 )
      {
        HalPutDmaAdapter(v8);
        *(_QWORD *)(*((_QWORD *)Context + 16) + 16i64) = 0i64;
        v7 = (_QWORD *)*((_QWORD *)Context + 16);
      }
      v9 = v7[1];
      if( v9 )
      {
        ZwClose(v9);
        *(_QWORD *)(*((_QWORD *)Context + 16) + 8i64) = 0i64;
        v7 = (_QWORD *)*((_QWORD *)Context + 16);
      }
      v10 = (_QWORD *)v7[5];
      v7[5] = 0i64;
      if( v10 )
      {
        do
        {
          v11 = (void *)v10[2];
          v12 = (_QWORD *)v10[4];
          if( v11 )
            ExFreePoolWithTag(v11, 0x57676244u);
          ExFreePoolWithTag(v10, 0x57676244u);
          v10 = v12;
        }
        while( v12 );
      }
      v13 = (void *)*((_QWORD *)Context + 16);
      if( v13 )
        ExFreePoolWithTag(v13, 0x57676244u);
      *((_QWORD *)Context + 16) = 0i64;
    }
    v14 = (void *)*((_QWORD *)Context + 18);
    if( v14 )
    {
      ExFreePoolWithTag(v14, 0x57676244u);
      *((_QWORD *)Context + 18) = 0i64;
    }
    if( *((_QWORD *)Context + 13) )
    {
      if( (Context[28] & 1) == 0 )
      {
        v15 = WerLiveKernelCancelReport();
        if( v15 < 0 )
          DbgPrintEx(
            5u,
            1u,
            "DBGK: DbgkpWerCleanupContext: WerLiveKernelCancelReport failed, 0x%X\n",
            (unsigned int)v15);
      }
      v16 = WerLiveKernelCloseHandle(*((_QWORD *)Context + 13));
      if( v16 < 0 )
        DbgPrintEx(5u, 1u, "DBGK: DbgkpWerCleanupContext: WerLiveKernelCloseHandle failed, 0x%X\n", (unsigned int)v16);
      *((_QWORD *)Context + 13) = 0i64;
    }
  }
}

Referenced by:

DbgkWerCaptureLiveKernelDump
DbgkpWerDeferredWriteRoutine