| 1091 | } |
| 1092 | |
| 1093 | static bool FlatStream_LoadBitmap(TBlockStream * pStream) |
| 1094 | { |
| 1095 | FILE_BITMAP_FOOTER Footer; |
| 1096 | ULONGLONG ByteOffset; |
| 1097 | LPBYTE FileBitmap; |
| 1098 | DWORD BlockCount; |
| 1099 | DWORD BitmapSize; |
| 1100 | |
| 1101 | // Do not load the bitmap if we should not have to |
| 1102 | if(!(pStream->dwFlags & STREAM_FLAG_USE_BITMAP)) |
| 1103 | return false; |
| 1104 | |
| 1105 | // Only if the size is greater than size of bitmap footer |
| 1106 | if(pStream->Base.File.FileSize > sizeof(FILE_BITMAP_FOOTER)) |
| 1107 | { |
| 1108 | // Load the bitmap footer |
| 1109 | ByteOffset = pStream->Base.File.FileSize - sizeof(FILE_BITMAP_FOOTER); |
| 1110 | if(pStream->BaseRead(pStream, &ByteOffset, &Footer, sizeof(FILE_BITMAP_FOOTER))) |
| 1111 | { |
| 1112 | // Make sure that the array is properly BSWAP-ed |
| 1113 | BSWAP_ARRAY32_UNSIGNED((LPDWORD)(&Footer), sizeof(FILE_BITMAP_FOOTER)); |
| 1114 | |
| 1115 | // Verify if there is actually a footer |
| 1116 | if(Footer.Signature == ID_FILE_BITMAP_FOOTER && Footer.Version == 0x03) |
| 1117 | { |
| 1118 | // Get the offset of the bitmap, number of blocks and size of the bitmap |
| 1119 | ByteOffset = MAKE_OFFSET64(Footer.MapOffsetHi, Footer.MapOffsetLo); |
| 1120 | BlockCount = (DWORD)(((ByteOffset - 1) / Footer.BlockSize) + 1); |
| 1121 | BitmapSize = ((BlockCount + 7) / 8); |
| 1122 | |
| 1123 | // Check if the sizes match |
| 1124 | if(ByteOffset + BitmapSize + sizeof(FILE_BITMAP_FOOTER) == pStream->Base.File.FileSize) |
| 1125 | { |
| 1126 | // Allocate space for the bitmap |
| 1127 | FileBitmap = STORM_ALLOC(BYTE, BitmapSize); |
| 1128 | if(FileBitmap != NULL) |
| 1129 | { |
| 1130 | // Load the bitmap bits |
| 1131 | if(!pStream->BaseRead(pStream, &ByteOffset, FileBitmap, BitmapSize)) |
| 1132 | { |
| 1133 | STORM_FREE(FileBitmap); |
| 1134 | return false; |
| 1135 | } |
| 1136 | |
| 1137 | // Update the stream size |
| 1138 | pStream->BuildNumber = Footer.BuildNumber; |
| 1139 | pStream->StreamSize = ByteOffset; |
| 1140 | |
| 1141 | // Fill the bitmap information |
| 1142 | pStream->FileBitmap = FileBitmap; |
| 1143 | pStream->BitmapSize = BitmapSize; |
| 1144 | pStream->BlockSize = Footer.BlockSize; |
| 1145 | pStream->BlockCount = BlockCount; |
| 1146 | pStream->IsComplete = FlatStream_CheckFile(pStream); |
| 1147 | return true; |
| 1148 | } |
| 1149 | } |
| 1150 | } |
no test coverage detected