Skip to content

Instantly share code, notes, and snippets.

View zsennenga's full-sized avatar

Zachary Ennenga zsennenga

  • San Francisco, CA
View GitHub Profile
Struct(
"signature" / Const(b"MT\xbe\xef"),
"unknown_const_256" / Const(256, Int16ul) * "Probably part of the signature",
"width" / Int16ul,
"minimum_bytes_per_row" / Int16ul * "Likely used to aid resizing",
"height" / Int16ul * "Seems to be decreased by 1 when using the standard builder. Bug?",
"color_count" / Const(16, Int16ul),
"palette_and_image_size" / Int16ul * "This seems to be unused - and it bugs out with larger images. You can easily exceed a short, even with the default generator",
"sky_palette_index" / Int16ul * "This is the palette index referring to what the sky was",
"unknowns_16" / Struct(
Struct(
"signature" / Const(b"MT\xbe\xef"),
"unknown_const_256" / Const(256, Int16ul) * "Probably part of the signature",
"width" / Int16ul,
"unknown_1" / Int16ul,
"height" / Int16ul * "Seems to be decreased by 1 when using the standard builder. Bug?",
"color_count" / Const(16, Int16ul),
"palette_and_image_size" / Int16ul * "This seems to be unused - and it bugs out with larger images. You can easily exceed a short, even with the default generator",
"unknown_2" / Int16ul,
"unknown_3" / Int16ul,
Struct(
"signature" / Const(b"MT\xbe\xef"),
"unknown_const_256" / Const(256, Int16ul) * "Probably part of the signature",
"width" / Int16ul,
"unknown_1" / Int16ul,
"height" / Int16ul * "Seems to be decreased by 1 when using the standard builder. Bug?",
"color_count" / Const(16, Int16ul),
"palette_and_image_size" / Int16ul * "This seems to be unused - and it bugs out with larger images. You can easily exceed a short, even with the default generator",
"unknown_2" / Int16ul,
"unknown_3" / Int16ul,
Struct(
"signature" / Const(b"MT\xbe\xef"),
"unknown_const_256" / Const(256, Int16ul) * "Probably part of the signature",
"header" / Int16ul[18]
"palette" / Array(
16,
Struct(
"R" / Int8ul,
"G" / Int8ul,
"B" / Int8ul,
Struct(
"signature" / Const(b"BM"),
"file_size" / Rebuild(Int32ul, lambda ctx: 14 + 40 + int((ctx.height * ctx.width * ctx.bpp) / 8)),
Padding(4),
"data_offset" / Rebuild(Int32ul, 14 + 40 + ((2 ** this.bpp if this.bpp <= 8 else 0) * 4)),
"header_size" / Const(40, Int32ul),
"width" / Int32sl,
"height" / Int32sl,
"planes" / Int16ul,
"bpp" / Const(4, Int16ul), # bits per pixel