Changeset 107375 in vbox
- Timestamp:
- Dec 19, 2024 1:21:50 AM (6 weeks ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/formats/bmp.h
r106061 r107375 56 56 #define BMP_HDR_SIZE_OS22 64 57 57 #define BMP_HDR_SIZE_WIN3X 40 58 #define BMP_HDR_SIZE_NT4 108 59 #define BMP_HDR_SIZE_W2K 124 58 60 /** @} */ 59 61 … … 178 180 typedef BMPWIN3XINFOHDR *PBMPWIN3XINFOHDR; 179 181 182 typedef struct BMPWINCIEXYZ 183 { 184 int32_t x, y, z; 185 } BMPWINCIEXYZ; 186 AssertCompileSize(BMPWINCIEXYZ, 12); 187 188 typedef struct BMPWINCIEXYZTRIPLE 189 { 190 BMPWINCIEXYZ Red, Green, Blue; 191 } BMPWINCIEXYZTRIPLE; 192 AssertCompileSize(BMPWINCIEXYZTRIPLE, 36); 193 194 typedef struct BMPWINV4INFOHDR 195 { 196 uint32_t cbSize; 197 int32_t cx; 198 int32_t cy; 199 uint16_t cPlanes; 200 uint16_t cBits; 201 uint32_t enmCompression; /**< Differs from BMPWIN3XINFOHDR::enmCompression? */ 202 uint32_t cbImage; 203 int32_t cXPelsPerMeter; 204 int32_t cYPelsPerMeter; 205 uint32_t cColorsUsed; 206 uint32_t cColorsImportant; 207 /* New v4 fields: */ 208 uint32_t fRedMask; 209 uint32_t fGreenMask; 210 uint32_t fBlueMask; 211 uint32_t fAlphaMask; 212 uint32_t enmCSType; 213 BMPWINCIEXYZTRIPLE Endpoints; 214 uint32_t uGammaRed; 215 uint32_t uGammaGreen; 216 uint32_t uGammaBlue; 217 } BMPWINV4INFOHDR; 218 AssertCompileSize(BMPWINV4INFOHDR, BMP_HDR_SIZE_NT4); 219 220 typedef struct BMPWINV5INFOHDR 221 { 222 uint32_t cbSize; 223 int32_t cx; 224 int32_t cy; 225 uint16_t cPlanes; 226 uint16_t cBits; 227 uint32_t enmCompression; /**< Differs from BMPWIN3XINFOHDR::enmCompression? */ 228 uint32_t cbImage; 229 int32_t cXPelsPerMeter; 230 int32_t cYPelsPerMeter; 231 uint32_t cColorsUsed; 232 uint32_t cColorsImportant; 233 /* New v4 fields: */ 234 uint32_t fRedMask; 235 uint32_t fGreenMask; 236 uint32_t fBlueMask; 237 uint32_t fAlphaMask; 238 uint32_t enmCSType; 239 BMPWINCIEXYZTRIPLE Endpoints; 240 uint32_t uGammaRed; 241 uint32_t uGammaGreen; 242 uint32_t uGammaBlue; 243 /* New v5 fields: */ 244 uint32_t fIntent; 245 uint32_t offProfileData; 246 uint32_t cbProfileData; 247 uint32_t uReserved; 248 } BMPWINV5INFOHDR; 249 AssertCompileSize(BMPWINV5INFOHDR, BMP_HDR_SIZE_W2K); 250 180 251 181 252 182 253 /** @name BMP compression types. 183 254 * @{ */ 184 #define BMP_COMPRESSION_TYPE_NONE 0 185 #define BMP_COMPRESSION_TYPE_RLE8 1 186 #define BMP_COMPRESSION_TYPE_RLE4 2 255 #define BMP_COMPRESSION_TYPE_NONE 0 256 #define BMP_COMPRESSION_TYPE_RLE8 1 257 #define BMP_COMPRESSION_TYPE_RLE4 2 258 #define BMP_COMPRESSION_TYPE_BITFIELDS 3 259 #define BMP_COMPRESSION_TYPE_JPEG 4 260 #define BMP_COMPRESSION_TYPE_PNG 5 261 #define BMP_COMPRESSION_TYPE_ALPHABITFIELDS 6 262 #define BMP_COMPRESSION_TYPE_CMYK 11 263 #define BMP_COMPRESSION_TYPE_CMYKRLE8 12 264 #define BMP_COMPRESSION_TYPE_CMYKRLE4 13 187 265 /** @} */ 188 266 -
trunk/src/VBox/Debugger/DBGCDumpImage.cpp
r106073 r107375 56 56 # include <iprt/vfs.h> 57 57 #endif 58 #include <iprt/formats/bmp.h> 58 59 #include <iprt/formats/mz.h> 59 60 #include <iprt/formats/pecoff.h> … … 91 92 #define FLENT(a_Define) { a_Define, #a_Define } 92 93 94 95 /** @todo move to some formats header */ 96 typedef struct WIN_ICON_DIR_T 97 { 98 /** Must be zero. */ 99 uint16_t uZero; 100 /** 1 or 2. */ 101 uint16_t idType; 102 /** Number of icons. */ 103 uint16_t cEntries; 104 } WIN_ICON_DIR_T; 105 106 /** @todo move to some formats header */ 107 typedef struct WIN_ICON_ENTRY_T 108 { 109 uint8_t cx; 110 uint8_t cy; 111 uint8_t cColors; 112 uint8_t bReserved; 113 uint16_t cPlanes; 114 uint16_t cBits; 115 uint32_t cbData; 116 uint32_t offData; 117 } WIN_ICON_ENTRY_T; 93 118 94 119 … … 194 219 /** What to dump (DUMPIMAGE_SELECT_XXX). */ 195 220 uint64_t m_fSelection; 221 enum { kType_ExeImage = 0, kType_Icon } 222 m_enmType; 196 223 197 224 private: … … 212 239 #endif 213 240 , m_fSelection(DUMPIMAGE_SELECT_DEFAULT) 241 , m_enmType(kType_ExeImage) 214 242 { 215 243 } … … 428 456 return rc; 429 457 458 } 459 460 int optType(const char *pszImageType) RT_NOEXCEPT 461 { 462 if ( strcmp(pszImageType, "icon") == 0 463 || strcmp(pszImageType, "ico") == 0 464 || strcmp(pszImageType, "cursor") == 0 465 || strcmp(pszImageType, "cur") == 0) 466 m_enmType = kType_Icon; 467 else if ( strcmp(pszImageType, "exe") == 0 468 || strcmp(pszImageType, "dll") == 0 469 || strcmp(pszImageType, "sys") == 0 470 || strcmp(pszImageType, "image") == 0) 471 m_enmType = kType_ExeImage; 472 else 473 { 474 mySyntax("Unknown image type '%s'", pszImageType); 475 return VERR_INVALID_PARAMETER; 476 } 477 return VINF_SUCCESS; 430 478 } 431 479 … … 1946 1994 1947 1995 1996 static int dbgcDumpImageIcon(DumpImageCmd *pCmd, WIN_ICON_DIR_T const *pIconDir) 1997 { 1998 RT_NOREF_PV(pCmd); 1999 2000 /* 2001 * The directory. 2002 */ 2003 pCmd->myPrintf("%s: %s with %#x entries\n", 2004 pCmd->m_pszName, pIconDir->idType == 1 ? "Icon" : pIconDir->idType == 2 ? "Cursor" : "!unknown!", 2005 pIconDir->cEntries); 2006 2007 /* Read the directory. */ 2008 uint32_t const cbEntries = pIconDir->cEntries * sizeof(WIN_ICON_ENTRY_T); 2009 WIN_ICON_ENTRY_T *paEntries = (WIN_ICON_ENTRY_T *)RTMemTmpAllocZ(cbEntries); 2010 if (!paEntries) 2011 return VERR_NO_TMP_MEMORY; 2012 int rc = pCmd->readAt(sizeof(*pIconDir), paEntries, cbEntries, NULL); 2013 if (RT_SUCCESS(rc)) 2014 { 2015 /* Go thru the entries. */ 2016 for (uint32_t i = 0; i < pIconDir->cEntries; i++) 2017 { 2018 pCmd->myPrintf("%s: #%#x: %#08RX32 LB %#08RX32 - %ux%u, %u bbp, %u planes, %u colors\n", pCmd->m_pszName, i, 2019 paEntries[i].offData, paEntries[i].cbData, 2020 paEntries[i].cx ? paEntries[i].cx : 256, 2021 paEntries[i].cy ? paEntries[i].cy : 256, 2022 paEntries[i].cBits, paEntries[i].cPlanes, paEntries[i].cPlanes); 2023 union 2024 { 2025 uint8_t ab[_1K]; 2026 BMPWIN3XINFOHDR v3; 2027 BMPWINV4INFOHDR v4; 2028 BMPWINV5INFOHDR v5; 2029 } Data = {{0}}; 2030 uint32_t const cbData = RT_MIN(sizeof(Data), paEntries[i].cbData); 2031 int rc2 = pCmd->readAt(paEntries[i].offData, &Data, cbData, NULL); 2032 if (RT_SUCCESS(rc2)) 2033 { 2034 if ( Data.v3.cbSize == sizeof(Data.v3) 2035 || Data.v3.cbSize == sizeof(Data.v4) 2036 || Data.v3.cbSize == sizeof(Data.v5)) 2037 { 2038 pCmd->myPrintf("BMP%s - %dx%d, %u bbp, %u planes, %u colors used, %u important, %dx%d ppm, compression %u\n", 2039 Data.v3.cbSize == sizeof(Data.v3) ? "v3" 2040 : Data.v3.cbSize == sizeof(Data.v4) ? "v4" : "v5", 2041 Data.v4.cx, 2042 Data.v4.cy, 2043 Data.v4.cBits, 2044 Data.v4.cPlanes, 2045 Data.v4.cColorsUsed, 2046 Data.v4.cColorsImportant, 2047 Data.v4.cXPelsPerMeter, 2048 Data.v4.cYPelsPerMeter, 2049 Data.v4.enmCompression); 2050 } 2051 else if ( Data.ab[0] == 0x89 2052 || Data.ab[1] == 'P' 2053 || Data.ab[2] == 'N' 2054 || Data.ab[3] == 'G' 2055 || Data.ab[4] == '\r' 2056 || Data.ab[5] == '\n') 2057 { 2058 pCmd->myPrintf("PNG!\n"); 2059 } 2060 else 2061 pCmd->myPrintf("Unknown!\n"); 2062 2063 2064 pCmd->myPrintf("%#.*Rhxd\n", RT_MIN(cbData, 128), &Data); 2065 } 2066 else 2067 { 2068 pCmd->myPrintf("%s: #%#x: Error reading data: %Rrc\n", 2069 pCmd->m_pszName, i, paEntries[i].offData, paEntries[i].cbData, rc2); 2070 rc = rc2; 2071 } 2072 } 2073 } 2074 RTMemTmpFree(paEntries); 2075 return rc; 2076 } 2077 2078 1948 2079 /** 1949 2080 * Common worker for the dumpimage command and the VBoxDumpImage tool. … … 1958 2089 { 1959 2090 uint8_t ab[0x10]; 2091 uint16_t au16[8]; 1960 2092 IMAGE_DOS_HEADER DosHdr; 1961 2093 struct … … 1965 2097 } Nt; 1966 2098 mach_header_64_t MachO64; 2099 WIN_ICON_DIR_T IconDir; 1967 2100 } uBuf; 1968 2101 int rc = readAt(0, &uBuf.DosHdr, sizeof(uBuf.DosHdr), NULL); … … 2003 2136 rc = dbgcDumpImageMachO(this, &uBuf.MachO64); 2004 2137 /* 2005 * Dunno. 2138 * Use the type. 2139 */ 2140 else if ( m_enmType == kType_Icon 2141 && uBuf.IconDir.uZero == 0 2142 && ( uBuf.IconDir.idType == 1 /*icon*/ 2143 || uBuf.IconDir.idType == 2 /*cursor*/) 2144 && uBuf.IconDir.cEntries > 0 2145 && uBuf.IconDir.cEntries < 4096 /* thin-air-sanity */) 2146 rc = dbgcDumpImageIcon(this, &uBuf.IconDir); 2147 /* 2148 * Unknown. 2006 2149 */ 2007 2150 else … … 2062 2205 { "--skip", 's', RTGETOPT_REQ_STRING }, 2063 2206 { "--skip", 'S', RTGETOPT_REQ_STRING }, 2207 { "--type", 't', RTGETOPT_REQ_STRING }, 2064 2208 }; 2065 2209 … … 2097 2241 case 'S': 2098 2242 rc = Cmd.optSelectionSkip(ValueUnion.psz); 2243 if (RT_FAILURE(rc)) 2244 return RTEXITCODE_SYNTAX; 2245 break; 2246 2247 case 't': 2248 rc = Cmd.optType(ValueUnion.psz); 2099 2249 if (RT_FAILURE(rc)) 2100 2250 return RTEXITCODE_SYNTAX;
Note:
See TracChangeset
for help on using the changeset viewer.