SdbGetDatabaseMatch

NTSTATUS __fastcall SdbGetDatabaseMatch(
        VOID *hSDB,
        const WCHAR *szPath,
        VOID *FileHandle,
        VOID *pImageBase,
        UINT64 cbImageSize){
  int v8; 
  const WCHAR *v9; 
  const WCHAR *v10; 
  tagSEARCHDBCONTEXT *v11; 
  unsigned int v12; 
  int v14; 
  __int64 v15; 
  INT8 *v16; 
  UINT64 v17; 
  INT8 *v18; 
  UINT64 v19; 
  _RTL_ARRAY *v20; 
  UINT64 ptrWhich; 
  WCHAR **FileMappingHandleOut; 
  _BYTE pContext[96]; 
  int tiWhich[32]; 

  memset(&pContext[4], 0i64, 0x5Cu);
  memset(tiWhich, 0i64, sizeof(tiWhich));
  FileMappingHandleOut = 0i64;
  v8 = 10;
  LODWORD(ptrWhich) = 0;
  if( pImageBase )
    v8 = 26;
  *(_DWORD *)pContext = v8;
  if( AslFileMappingCreate(&FileMappingHandleOut, szPath, (VOID *)0xFFFFFFFFFFFFFFFFi64, 0i64, 0i64) >= 0 )
    goto LABEL_4;
  if( !pImageBase )
  {
    v16 = (INT8 *)"Failed to create initialize file mapping [%x]";
    v17 = 4452i64;
    goto LABEL_18;
  }
  if( AslFileMappingCreateFromImageView(&FileMappingHandleOut, szPath, pImageBase, (WCHAR *)cbImageSize) < 0 )
  {
    v16 = "Failed to initialize file mapping from image view [%x]";
    v17 = 4444i64;
LABEL_18:
    AslLogCallPrintf(1ui64, (INT8 *)"SdbGetDatabaseMatch", v17, v16);
    goto LABEL_8;
  }
LABEL_4:
  if( !SdbpCreateSearchDBContext((tagSEARCHDBCONTEXT *)pContext, FileMappingHandleOut, v9, v10, v20) )
  {
    v18 = "Failed to create search DB context";
    v19 = 4461i64;
LABEL_21:
    AslLogCallPrintf(1ui64, (INT8 *)"SdbGetDatabaseMatch", v19, v18);
    goto LABEL_8;
  }
  v12 = SdbpSearchDB(hSDB, *((_DB **)hSDB + 1), v11, (tagEXE_ENTRY_INFO *)pContext);
  if( v12 > 0x10 )
  {
    AslLogCallPrintf(
      1ui64,
      (INT8 *)"SdbGetDatabaseMatch",
      0x117Cui64,
      (INT8 *)"The database has more matches than SDB_MAX_EXES");
    v12 = 16;
  }
  if( v12 )
  {
    v14 = v12 - 1;
    v15 = v14;
    if( v14 >= 0 )
    {
      while( (tiWhich[2 * v15 + 1] & 2) != 0
           || SdbTagIDToTagRef(hSDB, *((_DB **)hSDB + 1), (unsigned int)tiWhich[2 * v15], &ptrWhich) )
      {
        if( --v15 < 0 )
          goto LABEL_8;
      }
      v18 = (INT8 *)"Failed to convert tagid to tagref";
      v19 = 4495i64;
      goto LABEL_21;
    }
  }
LABEL_8:
  SdbpReleaseSearchDBContext((tagSEARCHDBCONTEXT *)pContext);
  AslFileMappingDelete((UINT64)FileMappingHandleOut);
  return ptrWhich;
}

Referenced by:

PiIsDriverBlocked