@@ -335,7 +335,6 @@ PIMAGE_SECTION_HEADER PhMappedImageRvaToSection(
335
335
return NULL ;
336
336
}
337
337
338
- _Success_ (return != NULL )
339
338
PVOID PhMappedImageRvaToVa (
340
339
_In_ PPH_MAPPED_IMAGE MappedImage ,
341
340
_In_ ULONG Rva ,
@@ -358,7 +357,6 @@ PVOID PhMappedImageRvaToVa(
358
357
));
359
358
}
360
359
361
- _Success_ (return != NULL )
362
360
PVOID PhMappedImageVaToVa (
363
361
_In_ PPH_MAPPED_IMAGE MappedImage ,
364
362
_In_ ULONG Va ,
@@ -2343,7 +2341,8 @@ NTSTATUS PhGetMappedImageProdIdHeader(
2343
2341
2344
2342
if (richStartSignature == ProdIdTagStart && richEndSignature == ProdIdTagEnd )
2345
2343
{
2346
- PPH_STRING hashString = NULL ;
2344
+ PPH_STRING hashRawContentString = NULL ;
2345
+ PPH_STRING hashContentString = NULL ;
2347
2346
ULONG currentCount = 0 ;
2348
2347
PBYTE currentAddress ;
2349
2348
PBYTE currentEnd ;
@@ -2362,17 +2361,69 @@ NTSTATUS PhGetMappedImageProdIdHeader(
2362
2361
2363
2362
if (PhFinalHash (& hashContext , hash , 16 , NULL ))
2364
2363
{
2365
- hashString = PhBufferToHexString (hash , 16 );
2364
+ hashRawContentString = PhBufferToHexString (hash , 16 );
2366
2365
}
2367
2366
}
2368
2367
__except (EXCEPTION_EXECUTE_HANDLER )
2369
2368
{
2370
2369
return GetExceptionCode ();
2371
2370
}
2372
2371
2373
- if (PhIsNullOrEmptyString (hashString ))
2372
+ if (PhIsNullOrEmptyString (hashRawContentString ))
2374
2373
return STATUS_FAIL_CHECK ;
2375
-
2374
+
2375
+ // VT creates a different hash based on the decrypted header while other tools
2376
+ // (including this one) create the hash based on the raw header. So create a second hash
2377
+ // from the decrypted header so we can show and search both hashes (dmex)
2378
+ {
2379
+ PVOID richHeaderContentEnd ;
2380
+ ULONG richHeaderContentLength ;
2381
+ PULONG richHeaderContentBuffer ;
2382
+ PULONG richHeaderContentOffset ;
2383
+ PH_HASH_CONTEXT hashContext ;
2384
+ UCHAR hash [32 ];
2385
+
2386
+ // Recalculate the length needed for the hash since VT doesn't include the remaining entry.
2387
+ richHeaderContentEnd = PTR_ADD_OFFSET (MappedImage -> ViewBase , richHeaderEndOffset );
2388
+ richHeaderContentLength = PtrToUlong (PTR_SUB_OFFSET (richHeaderContentEnd , richHeaderStart ));
2389
+
2390
+ // We already probed above so this isn't really needed but probe again just to be sure.
2391
+ __try
2392
+ {
2393
+ PhpMappedImageProbe (MappedImage , richHeaderStart , richHeaderContentLength );
2394
+ }
2395
+ __except (EXCEPTION_EXECUTE_HANDLER )
2396
+ {
2397
+ return GetExceptionCode ();
2398
+ }
2399
+
2400
+ richHeaderContentBuffer = PhAllocateZero (richHeaderContentLength );
2401
+ memcpy (richHeaderContentBuffer , richHeaderStart , richHeaderContentLength );
2402
+
2403
+ // Walk the buffer and decrypt the entire thing.
2404
+ for (
2405
+ richHeaderContentOffset = richHeaderContentBuffer ;
2406
+ richHeaderContentOffset < (PULONG )PTR_ADD_OFFSET (richHeaderContentBuffer , richHeaderContentLength );
2407
+ richHeaderContentOffset ++
2408
+ )
2409
+ {
2410
+ * richHeaderContentOffset ^= richHeaderKey ;
2411
+ }
2412
+
2413
+ PhInitializeHash (& hashContext , Md5HashAlgorithm );
2414
+ PhUpdateHash (& hashContext , richHeaderContentBuffer , richHeaderContentLength );
2415
+
2416
+ if (PhFinalHash (& hashContext , hash , 16 , NULL ))
2417
+ {
2418
+ hashContentString = PhBufferToHexString (hash , 16 );
2419
+ }
2420
+
2421
+ PhFree (richHeaderContentBuffer );
2422
+ }
2423
+
2424
+ if (PhIsNullOrEmptyString (hashContentString ))
2425
+ return STATUS_FAIL_CHECK ;
2426
+
2376
2427
// Do a scan to determine how many entries there are.
2377
2428
for (offset = currentAddress ; offset < currentEnd ; offset += sizeof (PRODITEM ))
2378
2429
{
@@ -2466,7 +2517,8 @@ NTSTATUS PhGetMappedImageProdIdHeader(
2466
2517
//PhPrintPointer(ProdIdHeader->Key, UlongToPtr(richHeaderKey));
2467
2518
ProdIdHeader -> Valid = richHeaderKey == richHeaderValue ;
2468
2519
ProdIdHeader -> Key = PhFormatString (L"%lx" , richHeaderKey );
2469
- ProdIdHeader -> Hash = hashString ;
2520
+ ProdIdHeader -> RawHash = hashRawContentString ;
2521
+ ProdIdHeader -> Hash = hashContentString ;
2470
2522
ProdIdHeader -> NumberOfEntries = currentCount ;
2471
2523
ProdIdHeader -> ProdIdEntries = PhFinalArrayItems (& richHeaderEntryArray );
2472
2524
0 commit comments