11#include <Library/MemoryAllocationLib.h>
12#include <Library/DebugLib.h>
26 BOOLEAN DmgContextValid;
45 DEBUG ((DEBUG_ERROR,
"Please provide a valid Disk Image path\n"));
49 if ((argc % 2) != 1) {
50 DEBUG ((DEBUG_ERROR,
"Please provide a chunklist file for each DMG, enter \'n\' to skip\n"));
53 for (Index = 1; Index < (argc - 1); Index += 2) {
54 DmgContextValid = FALSE;
59 if ((Dmg =
UserReadFile (argv[Index], &DmgSize)) == NULL) {
60 DEBUG ((DEBUG_ERROR,
"Read fail\n"));
70 for (Index2 = 0; Index2 <
ExtentTable.ExtentCount; ++Index2) {
81 DEBUG ((DEBUG_ERROR,
"DMG Context initialization error\n"));
85 DmgContextValid = TRUE;
87 if (AsciiStrCmp (argv[Index + 1],
"n") != 0) {
88 if ((Chunklist =
UserReadFile (argv[Index + 1], &ChunklistSize)) == NULL) {
89 DEBUG ((DEBUG_ERROR,
"Read fail\n"));
95 DEBUG ((DEBUG_ERROR,
"Chunklist Context initialization error\n"));
101 DEBUG ((DEBUG_ERROR,
"Chunklist signature verification error\n"));
102 goto ContinueDmgLoop;
107 DEBUG ((DEBUG_ERROR,
"Chunklist chunk verification error\n"));
108 goto ContinueDmgLoop;
113 UncompDmg = AllocatePool (UncompSize);
114 if (UncompDmg == NULL) {
115 DEBUG ((DEBUG_ERROR,
"DMG data allocation failed\n"));
116 goto ContinueDmgLoop;
121 DEBUG ((DEBUG_ERROR,
"DMG read error\n"));
122 goto ContinueDmgLoop;
125 DEBUG ((DEBUG_ERROR,
"Decompressed the entire DMG...\n"));
132 UINT8 Digest[CC_MD5_DIGEST_LENGTH];
136 CC_MD5_Init (&Context);
137 CC_MD5_Update (&Context, UncompDmg, UncompSize);
138 CC_MD5_Final (Digest, &Context);
139 for (Index3 = 0; Index3 < CC_MD5_DIGEST_LENGTH; ++Index3) {
140 DEBUG ((DEBUG_ERROR,
"%02x", (UINT32)Digest[Index3]));
143 DEBUG ((DEBUG_ERROR,
"\n"));
146 DEBUG ((DEBUG_ERROR,
"Success...\n"));
149 if (DmgContextValid) {
157 if (Chunklist != NULL) {
158 FreePool (Chunklist);
161 if (UncompDmg != NULL) {
162 FreePool (UncompDmg);
175 #define MAX_INPUT 256
176 #define MAX_OUTPUT 4096
180 UINT32 CurrentLength;
191 for (Index = 0; Index < 4096; ++Index) {
200 ASSERT (CurrentLength <= Index);
#define ARRAY_SIZE(Array)
#define APPLE_RAM_DISK_EXTENT_SIGNATURE
APPLE_RAM_DISK_EXTENT_TABLE ExtentTable
#define APPLE_RAM_DISK_EXTENT_VERSION
PACKED struct @54 APPLE_RAM_DISK_EXTENT_TABLE
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
#define APPLE_DISK_IMAGE_SECTOR_SIZE
BOOLEAN OcAppleChunklistVerifySignature(IN OUT OC_APPLE_CHUNKLIST_CONTEXT *Context, IN CONST OC_RSA_PUBLIC_KEY *PublicKey)
BOOLEAN OcAppleChunklistInitializeContext(OUT OC_APPLE_CHUNKLIST_CONTEXT *Context, IN OUT VOID *Buffer, IN UINT32 BufferSize)
DMG_SIZE_DEVICE_PATH Size
BOOLEAN OcAppleDiskImageRead(IN OC_APPLE_DISK_IMAGE_CONTEXT *Context, IN UINTN Lba, IN UINTN BufferSize, OUT VOID *Buffer)
BOOLEAN OcAppleDiskImageVerifyData(IN OUT OC_APPLE_DISK_IMAGE_CONTEXT *Context, IN OUT OC_APPLE_CHUNKLIST_CONTEXT *ChunklistContext)
BOOLEAN OcAppleDiskImageInitializeContext(OUT OC_APPLE_DISK_IMAGE_CONTEXT *Context, IN CONST APPLE_RAM_DISK_EXTENT_TABLE *ExtentTable, IN UINTN FileSize)
VOID OcAppleDiskImageFreeContext(IN OC_APPLE_DISK_IMAGE_CONTEXT *Context)
CONST APPLE_PK_ENTRY PkDataBase[NUM_OF_PK]
UINTN DecompressZLIB(OUT UINT8 *Dst, IN UINTN DstLen, IN CONST UINT8 *Src, IN UINTN SrcLen)
UINT8 * UserReadFile(IN CONST CHAR8 *FileName, OUT UINT32 *Size)
VOID UserWriteFile(IN CONST CHAR8 *FileName, IN CONST VOID *Data, IN UINT32 Size)
#define ASAN_POISON_MEMORY_REGION(addr, size)
#define ASAN_UNPOISON_MEMORY_REGION(addr, size)
VOID SetPoolAllocationSizeLimit(UINTN AllocationSize)