Skip to content

Commit

Permalink
Utilities: Use more clever hash failure simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed Feb 5, 2022
1 parent a29e2db commit 81eedb5
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions Utilities/TestPeCoff/PeCoff.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
#include <UserFile.h>
#include <UserMemory.h>

STATIC UINT8 PcdValidHashes = MAX_UINT8;
UINTN HashDependency;
STATIC UINT64 mHashesMask = MAX_UINT64;
STATIC UINTN mHashIndex = 0;
STATIC UINTN mHashDependency;

BOOLEAN
HashUpdate (
Expand All @@ -31,15 +32,21 @@ HashUpdate (

(VOID) HashContext;

BOOLEAN p;

for (UINTN i = 0; i < DataLength; i++)
HashDependency += D[i];
mHashDependency += D[i];

if (PcdValidHashes > 0) {
PcdValidHashes--;
return TRUE;
if ((mHashesMask & (1ULL << mHashIndex)) != 0) {
p = TRUE;
} else {
p = FALSE;
}

return FALSE;
++mHashIndex;
mHashIndex &= 63U;

return p;
}

STATIC
Expand Down Expand Up @@ -116,7 +123,8 @@ PeCoffTestLoad (
}

static void loadConfig(const uint8_t *data, size_t size) {
HashDependency = 0;
mHashDependency = 0;
mHashIndex = 0;
UINT32 Off = sizeof(UINT8);
UINT32 LastByte = data[size - Off];
PcdGetBool(PcdImageLoaderRtRelocAllowTargetMismatch) = (LastByte & 1U) != 0;
Expand All @@ -136,11 +144,11 @@ static void loadConfig(const uint8_t *data, size_t size) {
memcpy(&mPageAllocationMask, &data[size - Off], sizeof(UINT64));
else
mPageAllocationMask = MAX_UINT64;
Off += sizeof(UINT8);
Off += sizeof(UINT64);
if (size >= Off)
PcdValidHashes = data[size - Off];
memcpy(&mHashesMask, &data[size - Off], sizeof(UINT64));
else
PcdValidHashes = MAX_UINT8;
mHashesMask = MAX_UINT64;
}

RETURN_STATUS
Expand Down

0 comments on commit 81eedb5

Please sign in to comment.