mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-27 23:37:04 -05:00
patterns: put author and description inside each pattern (#155)
This commit is contained in:
2277
patterns/3ds.hexpat
2277
patterns/3ds.hexpat
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,5 @@
|
||||
#pragma description 7z File Format
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <std/math.pat>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description Crash Bandicoot - Back in Time (fan game) User created flashback tapes level format
|
||||
|
||||
#include <type/magic.pat>
|
||||
#include <std/string.pat>
|
||||
#include <std/array.pat>
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Nintendo Switch Atmosphère CFW Fatal Error log
|
||||
|
||||
#pragma endian little
|
||||
|
||||
#include <std/io.pat>
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Static library archive files
|
||||
|
||||
#pragma MIME application/x-archive
|
||||
|
||||
#include <std/string.pat>
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description ARM Cortex M Vector Table Layout
|
||||
|
||||
#pragma endian little
|
||||
|
||||
#include <std/io.pat>
|
||||
|
||||
@@ -1,73 +1,76 @@
|
||||
#pragma MIME application/x-bittorrent
|
||||
|
||||
#include <std/ctype.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <std/string.pat>
|
||||
|
||||
namespace bencode {
|
||||
|
||||
struct ASCIIDecimal {
|
||||
char value[while(std::ctype::isdigit(std::mem::read_unsigned($, 1)))];
|
||||
} [[sealed, format("bencode::format_ascii_decimal"), transform("bencode::format_ascii_decimal")]];
|
||||
|
||||
fn format_ascii_decimal(ASCIIDecimal adsasd) {
|
||||
return std::string::parse_int(adsasd.value, 10);
|
||||
};
|
||||
|
||||
enum Type : u8 {
|
||||
Integer = 'i',
|
||||
Dictionary = 'd',
|
||||
List = 'l',
|
||||
|
||||
String0 = '0',
|
||||
String1 = '1',
|
||||
String2 = '2',
|
||||
String3 = '3',
|
||||
String4 = '4',
|
||||
String5 = '5',
|
||||
String6 = '6',
|
||||
String7 = '7',
|
||||
String8 = '8',
|
||||
String9 = '9'
|
||||
};
|
||||
|
||||
struct String {
|
||||
ASCIIDecimal length;
|
||||
char separator [[hidden]];
|
||||
char value[length];
|
||||
} [[sealed, format("bencode::format_string"), transform("bencode::format_string")]];
|
||||
|
||||
fn format_string(String string) {
|
||||
return string.value;
|
||||
};
|
||||
|
||||
using Bencode;
|
||||
using Value;
|
||||
|
||||
struct DictionaryEntry {
|
||||
String key;
|
||||
Value value;
|
||||
};
|
||||
|
||||
struct Value {
|
||||
Type type;
|
||||
|
||||
if (type == Type::Dictionary) {
|
||||
DictionaryEntry entry[while(std::mem::read_unsigned($, 1) != 'e')];
|
||||
} else if (type == Type::Integer) {
|
||||
ASCIIDecimal value;
|
||||
char end;
|
||||
} else {
|
||||
$ -= 1;
|
||||
String value;
|
||||
}
|
||||
};
|
||||
|
||||
struct Bencode {
|
||||
Value value[while(!std::mem::eof())] [[inline]];
|
||||
char end;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
bencode::Bencode bencode @ 0x00;
|
||||
#pragma author WerWolv
|
||||
#pragma description Bencode encoding, used by Torrent files
|
||||
|
||||
#pragma MIME application/x-bittorrent
|
||||
|
||||
#include <std/ctype.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <std/string.pat>
|
||||
|
||||
namespace bencode {
|
||||
|
||||
struct ASCIIDecimal {
|
||||
char value[while(std::ctype::isdigit(std::mem::read_unsigned($, 1)))];
|
||||
} [[sealed, format("bencode::format_ascii_decimal"), transform("bencode::format_ascii_decimal")]];
|
||||
|
||||
fn format_ascii_decimal(ASCIIDecimal adsasd) {
|
||||
return std::string::parse_int(adsasd.value, 10);
|
||||
};
|
||||
|
||||
enum Type : u8 {
|
||||
Integer = 'i',
|
||||
Dictionary = 'd',
|
||||
List = 'l',
|
||||
|
||||
String0 = '0',
|
||||
String1 = '1',
|
||||
String2 = '2',
|
||||
String3 = '3',
|
||||
String4 = '4',
|
||||
String5 = '5',
|
||||
String6 = '6',
|
||||
String7 = '7',
|
||||
String8 = '8',
|
||||
String9 = '9'
|
||||
};
|
||||
|
||||
struct String {
|
||||
ASCIIDecimal length;
|
||||
char separator [[hidden]];
|
||||
char value[length];
|
||||
} [[sealed, format("bencode::format_string"), transform("bencode::format_string")]];
|
||||
|
||||
fn format_string(String string) {
|
||||
return string.value;
|
||||
};
|
||||
|
||||
using Bencode;
|
||||
using Value;
|
||||
|
||||
struct DictionaryEntry {
|
||||
String key;
|
||||
Value value;
|
||||
};
|
||||
|
||||
struct Value {
|
||||
Type type;
|
||||
|
||||
if (type == Type::Dictionary) {
|
||||
DictionaryEntry entry[while(std::mem::read_unsigned($, 1) != 'e')];
|
||||
} else if (type == Type::Integer) {
|
||||
ASCIIDecimal value;
|
||||
char end;
|
||||
} else {
|
||||
$ -= 1;
|
||||
String value;
|
||||
}
|
||||
};
|
||||
|
||||
struct Bencode {
|
||||
Value value[while(!std::mem::eof())] [[inline]];
|
||||
char end;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
bencode::Bencode bencode @ 0x00;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description OS2/Windows Bitmap files
|
||||
|
||||
#pragma MIME image/bmp
|
||||
#pragma endian little
|
||||
#include <std/mem.pat>
|
||||
|
||||
@@ -1,128 +1,131 @@
|
||||
#pragma MIME application/bson
|
||||
|
||||
#include <type/time.pat>
|
||||
|
||||
enum Type : u8 {
|
||||
Double = 0x01,
|
||||
String = 0x02,
|
||||
EmbeddedDocument = 0x03,
|
||||
Array = 0x04,
|
||||
Binary = 0x05,
|
||||
Undefined = 0x06,
|
||||
ObjectId = 0x07,
|
||||
Boolean = 0x08,
|
||||
UTCDatetime = 0x09,
|
||||
Null = 0x0A,
|
||||
Regex = 0x0B,
|
||||
DBPointer = 0x0C,
|
||||
JavaScript = 0x0D,
|
||||
Symbol = 0x0E,
|
||||
JavaScriptWithScope = 0x0F,
|
||||
Int32 = 0x10,
|
||||
Timestamp = 0x11,
|
||||
Int64 = 0x12,
|
||||
Decimal128 = 0x13,
|
||||
|
||||
MinKey = 0xFF,
|
||||
MaxKey = 0x7F
|
||||
};
|
||||
|
||||
enum Subtype : u8 {
|
||||
GenericBinarySubtype = 0x00,
|
||||
Function = 0x01,
|
||||
BinaryOld = 0x02,
|
||||
UUIDOld = 0x03,
|
||||
UUID = 0x04,
|
||||
MD5 = 0x05,
|
||||
EncryptedBSONValue = 0x06,
|
||||
CompressedBSONColumn = 0x07,
|
||||
UserDefined = 0x80
|
||||
};
|
||||
|
||||
struct Binary {
|
||||
s32 length;
|
||||
Subtype subtype;
|
||||
u8 data[length];
|
||||
};
|
||||
|
||||
struct String {
|
||||
u32 length [[hidden]];
|
||||
char value[length];
|
||||
} [[sealed, format("format_string")]];
|
||||
|
||||
struct CString {
|
||||
char value[];
|
||||
} [[sealed, format("format_string")]];
|
||||
|
||||
fn format_string(auto string) {
|
||||
return string.value;
|
||||
};
|
||||
|
||||
struct ObjectId {
|
||||
type::time32_t timestamp;
|
||||
u8 randomValue[5];
|
||||
u24 counter;
|
||||
};
|
||||
|
||||
struct DBPointer {
|
||||
String name;
|
||||
ObjectId value;
|
||||
};
|
||||
|
||||
|
||||
using Document;
|
||||
|
||||
struct Element {
|
||||
Type type;
|
||||
|
||||
CString name;
|
||||
|
||||
if (type == Type::Double) {
|
||||
double value;
|
||||
} else if (type == Type::String) {
|
||||
String value;
|
||||
} else if (type == Type::EmbeddedDocument) {
|
||||
Document value;
|
||||
} else if (type == Type::Array) {
|
||||
Document value;
|
||||
} else if (type == Type::Binary) {
|
||||
Binary value;
|
||||
} else if (type == Type::Undefined) {
|
||||
/* undefined */
|
||||
} else if (type == Type::ObjectId) {
|
||||
ObjectId value;
|
||||
} else if (type == Type::Boolean) {
|
||||
bool value;
|
||||
} else if (type == Type::UTCDatetime) {
|
||||
type::time64_t value;
|
||||
} else if (type == Type::Null) {
|
||||
/* null */
|
||||
} else if (type == Type::Regex) {
|
||||
CString regexPattern;
|
||||
CString regexOptions;
|
||||
} else if (type == Type::DBPointer) {
|
||||
DBPointer value;
|
||||
} else if (type == Type::JavaScript) {
|
||||
String value;
|
||||
} else if (type == Type::Symbol) {
|
||||
String value;
|
||||
} else if (type == Type::JavaScriptWithScope) {
|
||||
String value;
|
||||
} else if (type == Type::Int32) {
|
||||
s32 value;
|
||||
} else if (type == Type::Timestamp) {
|
||||
u64 value;
|
||||
} else if (type == Type::Int64) {
|
||||
s64 value;
|
||||
} else if (type == Type::Decimal128) {
|
||||
u128 value;
|
||||
}
|
||||
};
|
||||
|
||||
struct Document {
|
||||
s32 listLength;
|
||||
Element elements[while($ < ((addressof(this) + listLength) - 1))];
|
||||
padding[1];
|
||||
};
|
||||
|
||||
#pragma author WerWolv
|
||||
#pragma description BSON (Binary JSON) format
|
||||
|
||||
#pragma MIME application/bson
|
||||
|
||||
#include <type/time.pat>
|
||||
|
||||
enum Type : u8 {
|
||||
Double = 0x01,
|
||||
String = 0x02,
|
||||
EmbeddedDocument = 0x03,
|
||||
Array = 0x04,
|
||||
Binary = 0x05,
|
||||
Undefined = 0x06,
|
||||
ObjectId = 0x07,
|
||||
Boolean = 0x08,
|
||||
UTCDatetime = 0x09,
|
||||
Null = 0x0A,
|
||||
Regex = 0x0B,
|
||||
DBPointer = 0x0C,
|
||||
JavaScript = 0x0D,
|
||||
Symbol = 0x0E,
|
||||
JavaScriptWithScope = 0x0F,
|
||||
Int32 = 0x10,
|
||||
Timestamp = 0x11,
|
||||
Int64 = 0x12,
|
||||
Decimal128 = 0x13,
|
||||
|
||||
MinKey = 0xFF,
|
||||
MaxKey = 0x7F
|
||||
};
|
||||
|
||||
enum Subtype : u8 {
|
||||
GenericBinarySubtype = 0x00,
|
||||
Function = 0x01,
|
||||
BinaryOld = 0x02,
|
||||
UUIDOld = 0x03,
|
||||
UUID = 0x04,
|
||||
MD5 = 0x05,
|
||||
EncryptedBSONValue = 0x06,
|
||||
CompressedBSONColumn = 0x07,
|
||||
UserDefined = 0x80
|
||||
};
|
||||
|
||||
struct Binary {
|
||||
s32 length;
|
||||
Subtype subtype;
|
||||
u8 data[length];
|
||||
};
|
||||
|
||||
struct String {
|
||||
u32 length [[hidden]];
|
||||
char value[length];
|
||||
} [[sealed, format("format_string")]];
|
||||
|
||||
struct CString {
|
||||
char value[];
|
||||
} [[sealed, format("format_string")]];
|
||||
|
||||
fn format_string(auto string) {
|
||||
return string.value;
|
||||
};
|
||||
|
||||
struct ObjectId {
|
||||
type::time32_t timestamp;
|
||||
u8 randomValue[5];
|
||||
u24 counter;
|
||||
};
|
||||
|
||||
struct DBPointer {
|
||||
String name;
|
||||
ObjectId value;
|
||||
};
|
||||
|
||||
|
||||
using Document;
|
||||
|
||||
struct Element {
|
||||
Type type;
|
||||
|
||||
CString name;
|
||||
|
||||
if (type == Type::Double) {
|
||||
double value;
|
||||
} else if (type == Type::String) {
|
||||
String value;
|
||||
} else if (type == Type::EmbeddedDocument) {
|
||||
Document value;
|
||||
} else if (type == Type::Array) {
|
||||
Document value;
|
||||
} else if (type == Type::Binary) {
|
||||
Binary value;
|
||||
} else if (type == Type::Undefined) {
|
||||
/* undefined */
|
||||
} else if (type == Type::ObjectId) {
|
||||
ObjectId value;
|
||||
} else if (type == Type::Boolean) {
|
||||
bool value;
|
||||
} else if (type == Type::UTCDatetime) {
|
||||
type::time64_t value;
|
||||
} else if (type == Type::Null) {
|
||||
/* null */
|
||||
} else if (type == Type::Regex) {
|
||||
CString regexPattern;
|
||||
CString regexOptions;
|
||||
} else if (type == Type::DBPointer) {
|
||||
DBPointer value;
|
||||
} else if (type == Type::JavaScript) {
|
||||
String value;
|
||||
} else if (type == Type::Symbol) {
|
||||
String value;
|
||||
} else if (type == Type::JavaScriptWithScope) {
|
||||
String value;
|
||||
} else if (type == Type::Int32) {
|
||||
s32 value;
|
||||
} else if (type == Type::Timestamp) {
|
||||
u64 value;
|
||||
} else if (type == Type::Int64) {
|
||||
s64 value;
|
||||
} else if (type == Type::Decimal128) {
|
||||
u128 value;
|
||||
}
|
||||
};
|
||||
|
||||
struct Document {
|
||||
s32 listLength;
|
||||
Element elements[while($ < ((addressof(this) + listLength) - 1))];
|
||||
padding[1];
|
||||
};
|
||||
|
||||
Document document @ 0x00;
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description GoldSrc engine maps format (used in Half-Life 1)
|
||||
|
||||
#include <std/ptr.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <std/sys.pat>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description Command and Conquer Voxel Animation
|
||||
|
||||
// Command and conquer voxel animation format
|
||||
|
||||
struct vec4_s {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description Command and Conquer Voxel Palette
|
||||
|
||||
// Command and conquer palette format
|
||||
|
||||
struct Color {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description Command and Conquer Voxel Model
|
||||
|
||||
// Command and Conquer voxel model format
|
||||
|
||||
struct vec4_s {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description Compact Disc Audio track
|
||||
|
||||
struct Header {
|
||||
u32 RIFF;
|
||||
s32 size;
|
||||
|
||||
@@ -1,395 +1,398 @@
|
||||
#include <type/magic.pat>
|
||||
#include <type/size.pat>
|
||||
#include <type/guid.pat>
|
||||
#include <type/leb128.pat>
|
||||
#include <std/sys.pat>
|
||||
|
||||
enum WindowsLanguageId : u32 {
|
||||
Arabic_SaudiArabia = 0x401,
|
||||
Arabic_Iraq = 0x801,
|
||||
Arabic_Egypt = 0xc01,
|
||||
Arabic_Libya = 0x1001,
|
||||
Arabic_Algeria = 0x1401,
|
||||
Arabic_Morocco = 0x1801,
|
||||
Arabic_Tunisia = 0x1c01,
|
||||
Arabic_Oman = 0x2001,
|
||||
Arabic_Yemen = 0x2401,
|
||||
Arabic_Syria = 0x2801,
|
||||
Arabic_Jordan = 0x2c01,
|
||||
Arabic_Lebanon = 0x3001,
|
||||
Arabic_Kuwait = 0x3401,
|
||||
Arabic_UAE = 0x3801,
|
||||
Arabic_Bahrain = 0x3c01,
|
||||
Arabic_Qatar = 0x4001,
|
||||
Bulgarian = 0x402,
|
||||
Catalan = 0x403,
|
||||
Valencian = 0x803,
|
||||
Chinese_Taiwan = 0x404,
|
||||
Chinese_PRC = 0x804,
|
||||
Chinese_HongKongSAR = 0xc04,
|
||||
Chinese_Singapore = 0x1004,
|
||||
Chinese_MacaoSAR = 0x1404,
|
||||
Czech = 0x405,
|
||||
Danish = 0x406,
|
||||
German_Germany = 0x407,
|
||||
German_Switzerland = 0x807,
|
||||
German_Austria = 0xc07,
|
||||
German_Luxembourg = 0x1007,
|
||||
German_Liechtenstein = 0x1407,
|
||||
Greek = 0x408,
|
||||
English_UnitedStates = 0x409,
|
||||
English_UnitedKingdom = 0x809,
|
||||
English_Australia = 0xc09,
|
||||
English_Canada = 0x1009,
|
||||
English_NewZealand = 0x1409,
|
||||
English_Ireland = 0x1809,
|
||||
English_SouthAfrica = 0x1c09,
|
||||
English_Jamaica = 0x2009,
|
||||
English_Caribbean = 0x2409,
|
||||
English_Belize = 0x2809,
|
||||
English_TrinidadandTobago = 0x2c09,
|
||||
English_Zimbabwe = 0x3009,
|
||||
English_Philippines = 0x3409,
|
||||
English_Indonesia = 0x3809,
|
||||
English_HongKongSAR = 0x3c09,
|
||||
English_India = 0x4009,
|
||||
English_Malaysia = 0x4409,
|
||||
English_Singapore = 0x4809,
|
||||
Spanish_SpainTraditionalSort = 0x40a,
|
||||
Spanish_Mexico = 0x80a,
|
||||
Spanish_Spain = 0xc0a,
|
||||
Spanish_Guatemala = 0x100a,
|
||||
Spanish_CostaRica = 0x140a,
|
||||
Spanish_Panama = 0x180a,
|
||||
Spanish_DominicanRepublic = 0x1c0a,
|
||||
Spanish_Venezuela = 0x200a,
|
||||
Spanish_Colombia = 0x240a,
|
||||
Spanish_Peru = 0x280a,
|
||||
Spanish_Argentina = 0x2c0a,
|
||||
Spanish_Ecuador = 0x300a,
|
||||
Spanish_Chile = 0x340a,
|
||||
Spanish_Uruguay = 0x380a,
|
||||
Spanish_Paraguay = 0x3c0a,
|
||||
Spanish_Bolivia = 0x400a,
|
||||
Spanish_ElSalvador = 0x440a,
|
||||
Spanish_Honduras = 0x480a,
|
||||
Spanish_Nicaragua = 0x4c0a,
|
||||
Spanish_PuertoRico = 0x500a,
|
||||
Spanish_UnitedStates = 0x540a,
|
||||
Spanish_LatinAmerica = 0x580a,
|
||||
Finnish = 0x40b,
|
||||
French_France = 0x40c,
|
||||
French_Belgium = 0x80c,
|
||||
French_Canada = 0xc0c,
|
||||
French_Switzerland = 0x100c,
|
||||
French_Luxembourg = 0x140c,
|
||||
French_Monaco = 0x180c,
|
||||
French_Caribbean = 0x1c0c,
|
||||
French_Reunion = 0x200c,
|
||||
French_CongoDRC = 0x240c,
|
||||
French_Senegal = 0x280c,
|
||||
French_Cameroon = 0x2c0c,
|
||||
French_CoteDIvoire = 0x300c,
|
||||
French_Mali = 0x340c,
|
||||
French_Morocco = 0x380c,
|
||||
French_Haiti = 0x3c0c,
|
||||
Hebrew = 0x40d,
|
||||
Hungarian = 0x40e,
|
||||
Icelandic = 0x40f,
|
||||
Italian_Italy = 0x410,
|
||||
Italian_Switzerland = 0x810,
|
||||
Japanese = 0x411,
|
||||
Korean = 0x412,
|
||||
Dutch_Netherlands = 0x413,
|
||||
Dutch_Belgium = 0x813,
|
||||
Norwegian_Bokmal = 0x414,
|
||||
Norwegian_Nynorsk = 0x814,
|
||||
Polish = 0x415,
|
||||
Portuguese_Brazil = 0x416,
|
||||
Portuguese_Portugal = 0x816,
|
||||
Romansh = 0x417,
|
||||
Romanian = 0x418,
|
||||
Romanian_Moldova = 0x818,
|
||||
Russian = 0x419,
|
||||
Russian_Moldova = 0x819,
|
||||
Croatian_Croatia = 0x41a,
|
||||
Serbian_LatinSerbiaandMontenegroFormer = 0x81a,
|
||||
Serbian_CyrillicSerbiaAndMontenegroFormer = 0xc1a,
|
||||
Croatian_BosniaAndHerzegovina = 0x101a,
|
||||
Bosnian_Latin = 0x141a,
|
||||
Serbian_LatinBosniaAndHerzegovina = 0x181a,
|
||||
Serbian_CyrillicBosniaAndHerzegovina = 0x1c1a,
|
||||
Bosnian_Cyrillic = 0x201a,
|
||||
Serbian_LatinSerbia = 0x241a,
|
||||
Serbian_CyrillicSerbia = 0x281a,
|
||||
Serbian_LatinMontenegro = 0x2c1a,
|
||||
Serbian_CyrillicMontenegro = 0x301a,
|
||||
Slovak = 0x41b,
|
||||
Albanian = 0x41c,
|
||||
Swedish_Sweden = 0x41d,
|
||||
Swedish_Finland = 0x81d,
|
||||
Thai = 0x41e,
|
||||
Turkish = 0x41f,
|
||||
Urdu_Pakistan = 0x420,
|
||||
Urdu_India = 0x820,
|
||||
Indonesian = 0x421,
|
||||
Ukrainian = 0x422,
|
||||
Belarusian = 0x423,
|
||||
Slovenian = 0x424,
|
||||
Estonian = 0x425,
|
||||
Latvian = 0x426,
|
||||
Lithuanian = 0x427,
|
||||
Tajik = 0x428,
|
||||
Persian = 0x429,
|
||||
Vietnamese = 0x42a,
|
||||
Armenian = 0x42b,
|
||||
Azerbaijani_Latin = 0x42c,
|
||||
Azerbaijani_Cyrillic = 0x82c,
|
||||
Basque = 0x42d,
|
||||
UpperSorbian = 0x42e,
|
||||
LowerSorbian = 0x82e,
|
||||
Macedonian = 0x42f,
|
||||
Sesotho_SouthAfrica = 0x430,
|
||||
Xitsonga = 0x431,
|
||||
Setswana_SouthAfrica = 0x432,
|
||||
Setswana_Botswana = 0x832,
|
||||
Venda = 0x433,
|
||||
isiXhosa = 0x434,
|
||||
isiZulu = 0x435,
|
||||
Afrikaans = 0x436,
|
||||
Georgian = 0x437,
|
||||
Faroese = 0x438,
|
||||
Hindi = 0x439,
|
||||
Maltese = 0x43a,
|
||||
NorthernSami_Norway = 0x43b,
|
||||
NorthernSami_Sweden = 0x83b,
|
||||
NorthernSami_Finland = 0xc3b,
|
||||
LuleSami_Norway = 0x103b,
|
||||
LuleSami_Sweden = 0x143b,
|
||||
SouthernSami_Norway = 0x183b,
|
||||
SouthernSami_Sweden = 0x1c3b,
|
||||
SkoltSami_Finland = 0x203b,
|
||||
InariSami_Finland = 0x243b,
|
||||
Irish = 0x83c,
|
||||
Yiddish = 0x43d,
|
||||
Malay_Malaysia = 0x43e,
|
||||
Malay_BruneiDarussalam = 0x83e,
|
||||
Kazakh = 0x43f,
|
||||
Kyrgyz = 0x440,
|
||||
Kiswahili = 0x441,
|
||||
Turkmen = 0x442,
|
||||
Uzbek_Latin = 0x443,
|
||||
Uzbek_Cyrillic = 0x843,
|
||||
Tatar = 0x444,
|
||||
Bangla_India = 0x445,
|
||||
Bangla_Bangladesh = 0x845,
|
||||
Punjabi_India = 0x446,
|
||||
Punjabi_Pakistan = 0x846,
|
||||
Gujarati = 0x447,
|
||||
Odia = 0x448,
|
||||
Tamil_India = 0x449,
|
||||
Tamil_SriLanka = 0x849,
|
||||
Telugu = 0x44a,
|
||||
Kannada = 0x44b,
|
||||
Malayalam = 0x44c,
|
||||
Assamese = 0x44d,
|
||||
Marathi = 0x44e,
|
||||
Sanskrit = 0x44f,
|
||||
Mongolian_Cyrillic = 0x450,
|
||||
Mongolian_TraditionalMongolianPRC = 0x850,
|
||||
Mongolian_TraditionalMongolianMongolia = 0xc50,
|
||||
Tibetan_PRC = 0x451,
|
||||
Welsh = 0x452,
|
||||
Khmer = 0x453,
|
||||
Lao = 0x454,
|
||||
Burmese = 0x455,
|
||||
Galician = 0x456,
|
||||
Konkani = 0x457,
|
||||
Manipuri = 0x458,
|
||||
Sindhi_Devanagari = 0x459,
|
||||
Sindhi_Arabic = 0x859,
|
||||
Syriac = 0x45a,
|
||||
Sinhala = 0x45b,
|
||||
Cherokee_Cherokee = 0x45c,
|
||||
Inuktitut_Syllabics = 0x45d,
|
||||
Inuktitut_Latin = 0x85d,
|
||||
Amharic = 0x45e,
|
||||
Tamazight_ArabicMorocco = 0x45f,
|
||||
Tamazight_LatinAlgeria = 0x85f,
|
||||
Tamazight_TifinaghMorocco = 0x105f,
|
||||
Kashmiri_Arabic = 0x460,
|
||||
Kashmiri = 0x860,
|
||||
Nepali = 0x461,
|
||||
Nepali_India = 0x861,
|
||||
Frisian = 0x462,
|
||||
Pashto = 0x463,
|
||||
Filipino = 0x464,
|
||||
Divehi = 0x465,
|
||||
Edo = 0x466,
|
||||
Fulah_Nigeria = 0x467,
|
||||
Fulah_LatinSenegal = 0x867,
|
||||
Hausa = 0x468,
|
||||
Ibibio_Nigeria = 0x469,
|
||||
Yoruba = 0x46a,
|
||||
Quechua_Bolivia = 0x46b,
|
||||
Quechua_Ecuador = 0x86b,
|
||||
Quechua_Peru = 0xc6b,
|
||||
SesothoSaLeboa = 0x46c,
|
||||
Bashkir = 0x46d,
|
||||
Luxembourgish = 0x46e,
|
||||
Greenlandic = 0x46f,
|
||||
Igbo = 0x470,
|
||||
Kanuri = 0x471,
|
||||
Oromo = 0x472,
|
||||
Tigrinya_Ethiopia = 0x473,
|
||||
Tigrinya_Eritrea = 0x873,
|
||||
Guarani = 0x474,
|
||||
Hawaiian = 0x475,
|
||||
Latin = 0x476,
|
||||
Somali = 0x477,
|
||||
Yi_PRC = 0x478,
|
||||
Papiamentu = 0x479,
|
||||
Mapudungun = 0x47a,
|
||||
Mohawk = 0x47c,
|
||||
Breton = 0x47e,
|
||||
Uyghur_PRC = 0x480,
|
||||
Maori = 0x481,
|
||||
Occitan = 0x482,
|
||||
Corsican = 0x483,
|
||||
Alsatian = 0x484,
|
||||
Sakha = 0x485,
|
||||
Kiche = 0x486,
|
||||
Kinyarwanda = 0x487,
|
||||
Wolof = 0x488,
|
||||
Dari = 0x48c,
|
||||
ScottishGaelic_UnitedKingdom = 0x491,
|
||||
CentralKurdish_Iraq = 0x492
|
||||
};
|
||||
|
||||
struct DirectoryListingEntry {
|
||||
type::LEB128 nameLength;
|
||||
char name[nameLength];
|
||||
type::LEB128 contentSection;
|
||||
type::LEB128 offset;
|
||||
type::LEB128 length;
|
||||
};
|
||||
|
||||
struct DirectoryIndexEntry {
|
||||
type::LEB128 nameLength;
|
||||
char name[nameLength];
|
||||
type::LEB128 directoryListingChunk;
|
||||
};
|
||||
|
||||
struct ListingChunk {
|
||||
char magic[4];
|
||||
|
||||
if (magic == "PMGL") {
|
||||
type::Size<u32> freeSpaceLength;
|
||||
u32;
|
||||
u32 prevChunkNumber, nextChunkNumber;
|
||||
|
||||
u16 directoryListingEntryCount @ addressof(this) + parent.directoryChunkSize - 2;
|
||||
u16 offsets[(freeSpaceLength - 2) / 2] @ addressof(directoryListingEntryCount) - (freeSpaceLength - 2);
|
||||
|
||||
DirectoryListingEntry directories[directoryListingEntryCount];
|
||||
|
||||
$ = addressof(directoryListingEntryCount) + sizeof(directoryListingEntryCount);
|
||||
} else if (magic == "PMGI") {
|
||||
type::Size<u32> freeSpaceLength;
|
||||
|
||||
u16 directoryIndexEntryCount @ addressof(this) + parent.directoryChunkSize - 2;
|
||||
u16 offsets[(freeSpaceLength - 2) / 2] @ addressof(directoryIndexEntryCount) - (freeSpaceLength - 2);
|
||||
|
||||
DirectoryIndexEntry indexes[directoryIndexEntryCount];
|
||||
|
||||
$ = addressof(directoryIndexEntryCount) + sizeof(directoryIndexEntryCount);
|
||||
} else {
|
||||
std::error("Invalid chunk magic!");
|
||||
}
|
||||
};
|
||||
|
||||
struct HeaderSection {
|
||||
char magic[4];
|
||||
|
||||
if (magic == "\xFE\x01\x00\x00") {
|
||||
u32;
|
||||
type::Size<u64> fileSize;
|
||||
u32;
|
||||
u32;
|
||||
} else if (magic == "ITSP") {
|
||||
u32 version;
|
||||
type::Size<u32> directoryHeaderLength1;
|
||||
u32;
|
||||
u32 directoryChunkSize;
|
||||
u32 quickRefSectionDensity;
|
||||
u32 indexTreeDepth;
|
||||
u32 rootIndexChunkNumber;
|
||||
u32 firstPMGLChunkNumber;
|
||||
u32 lastPMGLChunkNumber;
|
||||
u32;
|
||||
u32 directoryChunkCount;
|
||||
WindowsLanguageId languageId;
|
||||
type::GUID guid;
|
||||
type::Size<u32> directoryHeaderLength2;
|
||||
u32;
|
||||
u32;
|
||||
u32;
|
||||
|
||||
ListingChunk chunk[directoryChunkCount];
|
||||
} else {
|
||||
std::error("Invalid header section magic!");
|
||||
}
|
||||
};
|
||||
|
||||
struct HeaderSectionTableEntry {
|
||||
u64 offset;
|
||||
type::Size<u64> size;
|
||||
|
||||
HeaderSection headerSection @ offset;
|
||||
};
|
||||
|
||||
struct NameListEntry {
|
||||
type::Size<u16> nameLength;
|
||||
char16 name[nameLength];
|
||||
padding[2];
|
||||
};
|
||||
|
||||
struct NameListFile {
|
||||
u16 fileLengthWords;
|
||||
u16 entriesInFile;
|
||||
|
||||
NameListEntry nameList[entriesInFile];
|
||||
|
||||
padding[0x2E];
|
||||
};
|
||||
|
||||
struct SectionData {
|
||||
u32 fileLengthWords;
|
||||
type::Magic<"LZXC"> magic;
|
||||
u32 version;
|
||||
u32 lzxResetInterval;
|
||||
type::Size<u32> windowSize;
|
||||
type::Size<u32> cacheSize;
|
||||
u32;
|
||||
};
|
||||
|
||||
struct Content {
|
||||
NameListFile nameListFile;
|
||||
SectionData sectionData;
|
||||
};
|
||||
|
||||
struct CHM {
|
||||
type::Magic<"ITSF"> magic;
|
||||
u32 version;
|
||||
type::Size<u32> headerSize;
|
||||
u32;
|
||||
be u32 timeStamp;
|
||||
WindowsLanguageId languageId;
|
||||
type::GUID guids[2];
|
||||
|
||||
HeaderSectionTableEntry headerSectionTable[2];
|
||||
|
||||
Content *dataOffset : u64;
|
||||
};
|
||||
|
||||
CHM chm @ 0x00;
|
||||
#pragma author WerWolv
|
||||
#pragma description Windows HtmlHelp Data (ITSF / CHM)
|
||||
|
||||
#include <type/magic.pat>
|
||||
#include <type/size.pat>
|
||||
#include <type/guid.pat>
|
||||
#include <type/leb128.pat>
|
||||
#include <std/sys.pat>
|
||||
|
||||
enum WindowsLanguageId : u32 {
|
||||
Arabic_SaudiArabia = 0x401,
|
||||
Arabic_Iraq = 0x801,
|
||||
Arabic_Egypt = 0xc01,
|
||||
Arabic_Libya = 0x1001,
|
||||
Arabic_Algeria = 0x1401,
|
||||
Arabic_Morocco = 0x1801,
|
||||
Arabic_Tunisia = 0x1c01,
|
||||
Arabic_Oman = 0x2001,
|
||||
Arabic_Yemen = 0x2401,
|
||||
Arabic_Syria = 0x2801,
|
||||
Arabic_Jordan = 0x2c01,
|
||||
Arabic_Lebanon = 0x3001,
|
||||
Arabic_Kuwait = 0x3401,
|
||||
Arabic_UAE = 0x3801,
|
||||
Arabic_Bahrain = 0x3c01,
|
||||
Arabic_Qatar = 0x4001,
|
||||
Bulgarian = 0x402,
|
||||
Catalan = 0x403,
|
||||
Valencian = 0x803,
|
||||
Chinese_Taiwan = 0x404,
|
||||
Chinese_PRC = 0x804,
|
||||
Chinese_HongKongSAR = 0xc04,
|
||||
Chinese_Singapore = 0x1004,
|
||||
Chinese_MacaoSAR = 0x1404,
|
||||
Czech = 0x405,
|
||||
Danish = 0x406,
|
||||
German_Germany = 0x407,
|
||||
German_Switzerland = 0x807,
|
||||
German_Austria = 0xc07,
|
||||
German_Luxembourg = 0x1007,
|
||||
German_Liechtenstein = 0x1407,
|
||||
Greek = 0x408,
|
||||
English_UnitedStates = 0x409,
|
||||
English_UnitedKingdom = 0x809,
|
||||
English_Australia = 0xc09,
|
||||
English_Canada = 0x1009,
|
||||
English_NewZealand = 0x1409,
|
||||
English_Ireland = 0x1809,
|
||||
English_SouthAfrica = 0x1c09,
|
||||
English_Jamaica = 0x2009,
|
||||
English_Caribbean = 0x2409,
|
||||
English_Belize = 0x2809,
|
||||
English_TrinidadandTobago = 0x2c09,
|
||||
English_Zimbabwe = 0x3009,
|
||||
English_Philippines = 0x3409,
|
||||
English_Indonesia = 0x3809,
|
||||
English_HongKongSAR = 0x3c09,
|
||||
English_India = 0x4009,
|
||||
English_Malaysia = 0x4409,
|
||||
English_Singapore = 0x4809,
|
||||
Spanish_SpainTraditionalSort = 0x40a,
|
||||
Spanish_Mexico = 0x80a,
|
||||
Spanish_Spain = 0xc0a,
|
||||
Spanish_Guatemala = 0x100a,
|
||||
Spanish_CostaRica = 0x140a,
|
||||
Spanish_Panama = 0x180a,
|
||||
Spanish_DominicanRepublic = 0x1c0a,
|
||||
Spanish_Venezuela = 0x200a,
|
||||
Spanish_Colombia = 0x240a,
|
||||
Spanish_Peru = 0x280a,
|
||||
Spanish_Argentina = 0x2c0a,
|
||||
Spanish_Ecuador = 0x300a,
|
||||
Spanish_Chile = 0x340a,
|
||||
Spanish_Uruguay = 0x380a,
|
||||
Spanish_Paraguay = 0x3c0a,
|
||||
Spanish_Bolivia = 0x400a,
|
||||
Spanish_ElSalvador = 0x440a,
|
||||
Spanish_Honduras = 0x480a,
|
||||
Spanish_Nicaragua = 0x4c0a,
|
||||
Spanish_PuertoRico = 0x500a,
|
||||
Spanish_UnitedStates = 0x540a,
|
||||
Spanish_LatinAmerica = 0x580a,
|
||||
Finnish = 0x40b,
|
||||
French_France = 0x40c,
|
||||
French_Belgium = 0x80c,
|
||||
French_Canada = 0xc0c,
|
||||
French_Switzerland = 0x100c,
|
||||
French_Luxembourg = 0x140c,
|
||||
French_Monaco = 0x180c,
|
||||
French_Caribbean = 0x1c0c,
|
||||
French_Reunion = 0x200c,
|
||||
French_CongoDRC = 0x240c,
|
||||
French_Senegal = 0x280c,
|
||||
French_Cameroon = 0x2c0c,
|
||||
French_CoteDIvoire = 0x300c,
|
||||
French_Mali = 0x340c,
|
||||
French_Morocco = 0x380c,
|
||||
French_Haiti = 0x3c0c,
|
||||
Hebrew = 0x40d,
|
||||
Hungarian = 0x40e,
|
||||
Icelandic = 0x40f,
|
||||
Italian_Italy = 0x410,
|
||||
Italian_Switzerland = 0x810,
|
||||
Japanese = 0x411,
|
||||
Korean = 0x412,
|
||||
Dutch_Netherlands = 0x413,
|
||||
Dutch_Belgium = 0x813,
|
||||
Norwegian_Bokmal = 0x414,
|
||||
Norwegian_Nynorsk = 0x814,
|
||||
Polish = 0x415,
|
||||
Portuguese_Brazil = 0x416,
|
||||
Portuguese_Portugal = 0x816,
|
||||
Romansh = 0x417,
|
||||
Romanian = 0x418,
|
||||
Romanian_Moldova = 0x818,
|
||||
Russian = 0x419,
|
||||
Russian_Moldova = 0x819,
|
||||
Croatian_Croatia = 0x41a,
|
||||
Serbian_LatinSerbiaandMontenegroFormer = 0x81a,
|
||||
Serbian_CyrillicSerbiaAndMontenegroFormer = 0xc1a,
|
||||
Croatian_BosniaAndHerzegovina = 0x101a,
|
||||
Bosnian_Latin = 0x141a,
|
||||
Serbian_LatinBosniaAndHerzegovina = 0x181a,
|
||||
Serbian_CyrillicBosniaAndHerzegovina = 0x1c1a,
|
||||
Bosnian_Cyrillic = 0x201a,
|
||||
Serbian_LatinSerbia = 0x241a,
|
||||
Serbian_CyrillicSerbia = 0x281a,
|
||||
Serbian_LatinMontenegro = 0x2c1a,
|
||||
Serbian_CyrillicMontenegro = 0x301a,
|
||||
Slovak = 0x41b,
|
||||
Albanian = 0x41c,
|
||||
Swedish_Sweden = 0x41d,
|
||||
Swedish_Finland = 0x81d,
|
||||
Thai = 0x41e,
|
||||
Turkish = 0x41f,
|
||||
Urdu_Pakistan = 0x420,
|
||||
Urdu_India = 0x820,
|
||||
Indonesian = 0x421,
|
||||
Ukrainian = 0x422,
|
||||
Belarusian = 0x423,
|
||||
Slovenian = 0x424,
|
||||
Estonian = 0x425,
|
||||
Latvian = 0x426,
|
||||
Lithuanian = 0x427,
|
||||
Tajik = 0x428,
|
||||
Persian = 0x429,
|
||||
Vietnamese = 0x42a,
|
||||
Armenian = 0x42b,
|
||||
Azerbaijani_Latin = 0x42c,
|
||||
Azerbaijani_Cyrillic = 0x82c,
|
||||
Basque = 0x42d,
|
||||
UpperSorbian = 0x42e,
|
||||
LowerSorbian = 0x82e,
|
||||
Macedonian = 0x42f,
|
||||
Sesotho_SouthAfrica = 0x430,
|
||||
Xitsonga = 0x431,
|
||||
Setswana_SouthAfrica = 0x432,
|
||||
Setswana_Botswana = 0x832,
|
||||
Venda = 0x433,
|
||||
isiXhosa = 0x434,
|
||||
isiZulu = 0x435,
|
||||
Afrikaans = 0x436,
|
||||
Georgian = 0x437,
|
||||
Faroese = 0x438,
|
||||
Hindi = 0x439,
|
||||
Maltese = 0x43a,
|
||||
NorthernSami_Norway = 0x43b,
|
||||
NorthernSami_Sweden = 0x83b,
|
||||
NorthernSami_Finland = 0xc3b,
|
||||
LuleSami_Norway = 0x103b,
|
||||
LuleSami_Sweden = 0x143b,
|
||||
SouthernSami_Norway = 0x183b,
|
||||
SouthernSami_Sweden = 0x1c3b,
|
||||
SkoltSami_Finland = 0x203b,
|
||||
InariSami_Finland = 0x243b,
|
||||
Irish = 0x83c,
|
||||
Yiddish = 0x43d,
|
||||
Malay_Malaysia = 0x43e,
|
||||
Malay_BruneiDarussalam = 0x83e,
|
||||
Kazakh = 0x43f,
|
||||
Kyrgyz = 0x440,
|
||||
Kiswahili = 0x441,
|
||||
Turkmen = 0x442,
|
||||
Uzbek_Latin = 0x443,
|
||||
Uzbek_Cyrillic = 0x843,
|
||||
Tatar = 0x444,
|
||||
Bangla_India = 0x445,
|
||||
Bangla_Bangladesh = 0x845,
|
||||
Punjabi_India = 0x446,
|
||||
Punjabi_Pakistan = 0x846,
|
||||
Gujarati = 0x447,
|
||||
Odia = 0x448,
|
||||
Tamil_India = 0x449,
|
||||
Tamil_SriLanka = 0x849,
|
||||
Telugu = 0x44a,
|
||||
Kannada = 0x44b,
|
||||
Malayalam = 0x44c,
|
||||
Assamese = 0x44d,
|
||||
Marathi = 0x44e,
|
||||
Sanskrit = 0x44f,
|
||||
Mongolian_Cyrillic = 0x450,
|
||||
Mongolian_TraditionalMongolianPRC = 0x850,
|
||||
Mongolian_TraditionalMongolianMongolia = 0xc50,
|
||||
Tibetan_PRC = 0x451,
|
||||
Welsh = 0x452,
|
||||
Khmer = 0x453,
|
||||
Lao = 0x454,
|
||||
Burmese = 0x455,
|
||||
Galician = 0x456,
|
||||
Konkani = 0x457,
|
||||
Manipuri = 0x458,
|
||||
Sindhi_Devanagari = 0x459,
|
||||
Sindhi_Arabic = 0x859,
|
||||
Syriac = 0x45a,
|
||||
Sinhala = 0x45b,
|
||||
Cherokee_Cherokee = 0x45c,
|
||||
Inuktitut_Syllabics = 0x45d,
|
||||
Inuktitut_Latin = 0x85d,
|
||||
Amharic = 0x45e,
|
||||
Tamazight_ArabicMorocco = 0x45f,
|
||||
Tamazight_LatinAlgeria = 0x85f,
|
||||
Tamazight_TifinaghMorocco = 0x105f,
|
||||
Kashmiri_Arabic = 0x460,
|
||||
Kashmiri = 0x860,
|
||||
Nepali = 0x461,
|
||||
Nepali_India = 0x861,
|
||||
Frisian = 0x462,
|
||||
Pashto = 0x463,
|
||||
Filipino = 0x464,
|
||||
Divehi = 0x465,
|
||||
Edo = 0x466,
|
||||
Fulah_Nigeria = 0x467,
|
||||
Fulah_LatinSenegal = 0x867,
|
||||
Hausa = 0x468,
|
||||
Ibibio_Nigeria = 0x469,
|
||||
Yoruba = 0x46a,
|
||||
Quechua_Bolivia = 0x46b,
|
||||
Quechua_Ecuador = 0x86b,
|
||||
Quechua_Peru = 0xc6b,
|
||||
SesothoSaLeboa = 0x46c,
|
||||
Bashkir = 0x46d,
|
||||
Luxembourgish = 0x46e,
|
||||
Greenlandic = 0x46f,
|
||||
Igbo = 0x470,
|
||||
Kanuri = 0x471,
|
||||
Oromo = 0x472,
|
||||
Tigrinya_Ethiopia = 0x473,
|
||||
Tigrinya_Eritrea = 0x873,
|
||||
Guarani = 0x474,
|
||||
Hawaiian = 0x475,
|
||||
Latin = 0x476,
|
||||
Somali = 0x477,
|
||||
Yi_PRC = 0x478,
|
||||
Papiamentu = 0x479,
|
||||
Mapudungun = 0x47a,
|
||||
Mohawk = 0x47c,
|
||||
Breton = 0x47e,
|
||||
Uyghur_PRC = 0x480,
|
||||
Maori = 0x481,
|
||||
Occitan = 0x482,
|
||||
Corsican = 0x483,
|
||||
Alsatian = 0x484,
|
||||
Sakha = 0x485,
|
||||
Kiche = 0x486,
|
||||
Kinyarwanda = 0x487,
|
||||
Wolof = 0x488,
|
||||
Dari = 0x48c,
|
||||
ScottishGaelic_UnitedKingdom = 0x491,
|
||||
CentralKurdish_Iraq = 0x492
|
||||
};
|
||||
|
||||
struct DirectoryListingEntry {
|
||||
type::LEB128 nameLength;
|
||||
char name[nameLength];
|
||||
type::LEB128 contentSection;
|
||||
type::LEB128 offset;
|
||||
type::LEB128 length;
|
||||
};
|
||||
|
||||
struct DirectoryIndexEntry {
|
||||
type::LEB128 nameLength;
|
||||
char name[nameLength];
|
||||
type::LEB128 directoryListingChunk;
|
||||
};
|
||||
|
||||
struct ListingChunk {
|
||||
char magic[4];
|
||||
|
||||
if (magic == "PMGL") {
|
||||
type::Size<u32> freeSpaceLength;
|
||||
u32;
|
||||
u32 prevChunkNumber, nextChunkNumber;
|
||||
|
||||
u16 directoryListingEntryCount @ addressof(this) + parent.directoryChunkSize - 2;
|
||||
u16 offsets[(freeSpaceLength - 2) / 2] @ addressof(directoryListingEntryCount) - (freeSpaceLength - 2);
|
||||
|
||||
DirectoryListingEntry directories[directoryListingEntryCount];
|
||||
|
||||
$ = addressof(directoryListingEntryCount) + sizeof(directoryListingEntryCount);
|
||||
} else if (magic == "PMGI") {
|
||||
type::Size<u32> freeSpaceLength;
|
||||
|
||||
u16 directoryIndexEntryCount @ addressof(this) + parent.directoryChunkSize - 2;
|
||||
u16 offsets[(freeSpaceLength - 2) / 2] @ addressof(directoryIndexEntryCount) - (freeSpaceLength - 2);
|
||||
|
||||
DirectoryIndexEntry indexes[directoryIndexEntryCount];
|
||||
|
||||
$ = addressof(directoryIndexEntryCount) + sizeof(directoryIndexEntryCount);
|
||||
} else {
|
||||
std::error("Invalid chunk magic!");
|
||||
}
|
||||
};
|
||||
|
||||
struct HeaderSection {
|
||||
char magic[4];
|
||||
|
||||
if (magic == "\xFE\x01\x00\x00") {
|
||||
u32;
|
||||
type::Size<u64> fileSize;
|
||||
u32;
|
||||
u32;
|
||||
} else if (magic == "ITSP") {
|
||||
u32 version;
|
||||
type::Size<u32> directoryHeaderLength1;
|
||||
u32;
|
||||
u32 directoryChunkSize;
|
||||
u32 quickRefSectionDensity;
|
||||
u32 indexTreeDepth;
|
||||
u32 rootIndexChunkNumber;
|
||||
u32 firstPMGLChunkNumber;
|
||||
u32 lastPMGLChunkNumber;
|
||||
u32;
|
||||
u32 directoryChunkCount;
|
||||
WindowsLanguageId languageId;
|
||||
type::GUID guid;
|
||||
type::Size<u32> directoryHeaderLength2;
|
||||
u32;
|
||||
u32;
|
||||
u32;
|
||||
|
||||
ListingChunk chunk[directoryChunkCount];
|
||||
} else {
|
||||
std::error("Invalid header section magic!");
|
||||
}
|
||||
};
|
||||
|
||||
struct HeaderSectionTableEntry {
|
||||
u64 offset;
|
||||
type::Size<u64> size;
|
||||
|
||||
HeaderSection headerSection @ offset;
|
||||
};
|
||||
|
||||
struct NameListEntry {
|
||||
type::Size<u16> nameLength;
|
||||
char16 name[nameLength];
|
||||
padding[2];
|
||||
};
|
||||
|
||||
struct NameListFile {
|
||||
u16 fileLengthWords;
|
||||
u16 entriesInFile;
|
||||
|
||||
NameListEntry nameList[entriesInFile];
|
||||
|
||||
padding[0x2E];
|
||||
};
|
||||
|
||||
struct SectionData {
|
||||
u32 fileLengthWords;
|
||||
type::Magic<"LZXC"> magic;
|
||||
u32 version;
|
||||
u32 lzxResetInterval;
|
||||
type::Size<u32> windowSize;
|
||||
type::Size<u32> cacheSize;
|
||||
u32;
|
||||
};
|
||||
|
||||
struct Content {
|
||||
NameListFile nameListFile;
|
||||
SectionData sectionData;
|
||||
};
|
||||
|
||||
struct CHM {
|
||||
type::Magic<"ITSF"> magic;
|
||||
u32 version;
|
||||
type::Size<u32> headerSize;
|
||||
u32;
|
||||
be u32 timeStamp;
|
||||
WindowsLanguageId languageId;
|
||||
type::GUID guids[2];
|
||||
|
||||
HeaderSectionTableEntry headerSectionTable[2];
|
||||
|
||||
Content *dataOffset : u64;
|
||||
};
|
||||
|
||||
CHM chm @ 0x00;
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Common Object File Format (COFF) executable
|
||||
|
||||
#pragma MIME application/x-coff
|
||||
|
||||
#include <type/time.pat>
|
||||
|
||||
@@ -1,66 +1,69 @@
|
||||
#include <type/base.pat>
|
||||
|
||||
#include <std/time.pat>
|
||||
#include <std/core.pat>
|
||||
#include <std/sys.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
#pragma MIME application/x-cpio
|
||||
|
||||
namespace old_binary {
|
||||
|
||||
using Time = u32 [[format("old_binary::format_time")]];
|
||||
|
||||
fn swap_32bit(u32 value) {
|
||||
return ((value >> 16) & 0xFFFF) | ((value & 0xFFFF) << 16);
|
||||
};
|
||||
|
||||
fn format_time(u32 value) {
|
||||
return std::time::format(std::time::to_utc(swap_32bit(value)));
|
||||
};
|
||||
|
||||
using SwappedU32 = u32 [[transform("old_binary::swap_32bit"), format("old_binary::swap_32bit")]];
|
||||
|
||||
bitfield Mode {
|
||||
x : 3;
|
||||
w : 3;
|
||||
r : 3;
|
||||
sticky : 1;
|
||||
sgid : 1;
|
||||
suid : 1;
|
||||
file_type : 4;
|
||||
};
|
||||
|
||||
struct CpioHeader {
|
||||
type::Oct<u16> magic;
|
||||
if (magic == be u16(0o070707))
|
||||
std::core::set_endian(std::mem::Endian::Big);
|
||||
else if (magic == le u16(0o070707))
|
||||
std::core::set_endian(std::mem::Endian::Little);
|
||||
else
|
||||
std::error("Invalid CPIO Magic!");
|
||||
|
||||
u16 dev;
|
||||
u16 ino;
|
||||
Mode mode;
|
||||
u16 uid;
|
||||
u16 gid;
|
||||
u16 nlink;
|
||||
u16 rdev;
|
||||
Time mtime;
|
||||
u16 namesize;
|
||||
SwappedU32 filesize;
|
||||
};
|
||||
|
||||
struct Cpio {
|
||||
CpioHeader header;
|
||||
char pathname[header.namesize % 2 == 0 ? header.namesize : header.namesize + 1];
|
||||
u8 data[header.filesize % 2 == 0 ? header.filesize : header.filesize + 1];
|
||||
|
||||
if (pathname == "TRAILER!!!\x00\x00")
|
||||
break;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
old_binary::Cpio cpio[while(true)] @ 0x00;
|
||||
#pragma author WerWolv
|
||||
#pragma description Old Binary CPIO Format
|
||||
|
||||
#include <type/base.pat>
|
||||
|
||||
#include <std/time.pat>
|
||||
#include <std/core.pat>
|
||||
#include <std/sys.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
#pragma MIME application/x-cpio
|
||||
|
||||
namespace old_binary {
|
||||
|
||||
using Time = u32 [[format("old_binary::format_time")]];
|
||||
|
||||
fn swap_32bit(u32 value) {
|
||||
return ((value >> 16) & 0xFFFF) | ((value & 0xFFFF) << 16);
|
||||
};
|
||||
|
||||
fn format_time(u32 value) {
|
||||
return std::time::format(std::time::to_utc(swap_32bit(value)));
|
||||
};
|
||||
|
||||
using SwappedU32 = u32 [[transform("old_binary::swap_32bit"), format("old_binary::swap_32bit")]];
|
||||
|
||||
bitfield Mode {
|
||||
x : 3;
|
||||
w : 3;
|
||||
r : 3;
|
||||
sticky : 1;
|
||||
sgid : 1;
|
||||
suid : 1;
|
||||
file_type : 4;
|
||||
};
|
||||
|
||||
struct CpioHeader {
|
||||
type::Oct<u16> magic;
|
||||
if (magic == be u16(0o070707))
|
||||
std::core::set_endian(std::mem::Endian::Big);
|
||||
else if (magic == le u16(0o070707))
|
||||
std::core::set_endian(std::mem::Endian::Little);
|
||||
else
|
||||
std::error("Invalid CPIO Magic!");
|
||||
|
||||
u16 dev;
|
||||
u16 ino;
|
||||
Mode mode;
|
||||
u16 uid;
|
||||
u16 gid;
|
||||
u16 nlink;
|
||||
u16 rdev;
|
||||
Time mtime;
|
||||
u16 namesize;
|
||||
SwappedU32 filesize;
|
||||
};
|
||||
|
||||
struct Cpio {
|
||||
CpioHeader header;
|
||||
char pathname[header.namesize % 2 == 0 ? header.namesize : header.namesize + 1];
|
||||
u8 data[header.filesize % 2 == 0 ? header.filesize : header.filesize + 1];
|
||||
|
||||
if (pathname == "TRAILER!!!\x00\x00")
|
||||
break;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
old_binary::Cpio cpio[while(true)] @ 0x00;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description DirectDraw Surface
|
||||
|
||||
#pragma MIME image/vnd-ms.dds
|
||||
#pragma endian little
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description Dalvik EXecutable Format
|
||||
|
||||
#include <type/leb128.pat>
|
||||
|
||||
struct header_item {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description Apple Disk Image Trailer (DMG)
|
||||
|
||||
#pragma endian big
|
||||
|
||||
#include <type/magic.pat>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description .DS_Store file format
|
||||
|
||||
// Apple macOS .DS_Store format
|
||||
#pragma endian big
|
||||
#include <std/io.pat>
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description ELF header in elf binaries
|
||||
|
||||
#pragma MIME application/x-executable
|
||||
#pragma MIME application/x-elf
|
||||
#pragma MIME application/x-coredump
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description MS Windows Vista Event Log
|
||||
|
||||
#pragma endian little
|
||||
|
||||
struct Header {
|
||||
|
||||
@@ -1,122 +1,125 @@
|
||||
#pragma endian big
|
||||
|
||||
#include <std/sys.pat>
|
||||
#include <std/io.pat>
|
||||
#include <std/core.pat>
|
||||
|
||||
#include <type/magic.pat>
|
||||
#include <type/size.pat>
|
||||
|
||||
// These are used in order for the children to be able to find strings
|
||||
u64 fdt_addr;
|
||||
u64 str_offset;
|
||||
|
||||
|
||||
struct FDTHeader {
|
||||
type::Magic<"\xD0\x0D\xFE\xED"> magic;
|
||||
u32 totalsize;
|
||||
u32 off_dt_struct;
|
||||
u32 off_dt_strings;
|
||||
u32 off_mem_rsvmap;
|
||||
u32 version;
|
||||
u32 last_comp_version;
|
||||
u32 boot_cpuid_phys;
|
||||
u32 size_dt_strings;
|
||||
u32 size_dt_struct;
|
||||
};
|
||||
|
||||
struct AlignTo<auto Alignment> {
|
||||
padding[Alignment- ((($ - 1) % Alignment) + 1)];
|
||||
} [[hidden]];
|
||||
|
||||
struct FDTReserveEntry {
|
||||
u64 address;
|
||||
type::Size<u64> size;
|
||||
|
||||
if (address == 0x00 && size == 0x00)
|
||||
break;
|
||||
};
|
||||
|
||||
enum FDTToken : u32 {
|
||||
FDT_BEGIN_NODE = 0x00000001,
|
||||
FDT_END_NODE = 0x00000002,
|
||||
FDT_PROP = 0x00000003,
|
||||
FDT_NOP = 0x00000004,
|
||||
FDT_END = 0x00000009
|
||||
};
|
||||
|
||||
union FDTPropValue<auto len> {
|
||||
u32 prop_array[len / sizeof(u32)];
|
||||
char string[len];
|
||||
};
|
||||
|
||||
struct FDTProp {
|
||||
FDTToken tok[[hidden]];
|
||||
u32 len [[hidden]];
|
||||
u32 nameoff [[hidden]];
|
||||
if (len > 0) {
|
||||
// if len is zero, value is absent and no need to include it
|
||||
FDTPropValue<len> value;
|
||||
}
|
||||
AlignTo<4>;
|
||||
char name[] @ fdt_addr + str_offset + nameoff;
|
||||
|
||||
std::core::set_display_name(this, name);
|
||||
std::print(std::format("{:x} token {} len {} {}",
|
||||
$, tok, len,nameoff));
|
||||
FDTToken token = std::mem::read_unsigned($, 4, std::mem::Endian::Big);
|
||||
if (token != FDTToken::FDT_PROP) {
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
struct FDTNode {
|
||||
FDTToken token = std::mem::read_unsigned($, 4, std::mem::Endian::Big);
|
||||
|
||||
if (token == FDTToken::FDT_BEGIN_NODE) {
|
||||
FDTToken tok[[hidden]];
|
||||
char name[];
|
||||
AlignTo<4>;
|
||||
std::core::set_display_name(this, name[0] ? name : "/");
|
||||
token = std::mem::read_unsigned($, 4, std::mem::Endian::Big);
|
||||
|
||||
if(token == FDTToken::FDT_PROP) {
|
||||
FDTProp props[while(true)];
|
||||
}
|
||||
|
||||
token = std::mem::read_unsigned($, 4, std::mem::Endian::Big);
|
||||
if(token == FDTToken::FDT_END_NODE) {
|
||||
FDTToken[[hidden]];
|
||||
break;
|
||||
}
|
||||
|
||||
FDTNode children[while(true)][[inline]];
|
||||
} else if(token == FDTToken::FDT_NOP) {
|
||||
// TODO this may break the pattern, I've so far not encountered it
|
||||
}
|
||||
|
||||
// ew duplication
|
||||
token = std::mem::read_unsigned($, 4, std::mem::Endian::Big);
|
||||
if(token == FDTToken::FDT_END_NODE) {
|
||||
FDTToken[[hidden]];
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
struct FDTStructureBlock {
|
||||
FDTNode;
|
||||
};
|
||||
|
||||
|
||||
struct FDT {
|
||||
FDTHeader header;
|
||||
std::assert(header.version == 17, "Unsupported format version");
|
||||
fdt_addr = addressof(this);
|
||||
str_offset = header.off_dt_strings;
|
||||
|
||||
FDTStructureBlock structureBlocks @ fdt_addr + header.off_dt_struct;
|
||||
FDTReserveEntry reserveEntries[while(true)] @ fdt_addr + header.off_mem_rsvmap;
|
||||
};
|
||||
|
||||
std::mem::MagicSearch<"\xD0\x0D\xFE\xED", FDT> fdt @ std::mem::base_address();
|
||||
|
||||
#pragma author WerWolv
|
||||
#pragma description Flat Linux Device Tree blob
|
||||
|
||||
#pragma endian big
|
||||
|
||||
#include <std/sys.pat>
|
||||
#include <std/io.pat>
|
||||
#include <std/core.pat>
|
||||
|
||||
#include <type/magic.pat>
|
||||
#include <type/size.pat>
|
||||
|
||||
// These are used in order for the children to be able to find strings
|
||||
u64 fdt_addr;
|
||||
u64 str_offset;
|
||||
|
||||
|
||||
struct FDTHeader {
|
||||
type::Magic<"\xD0\x0D\xFE\xED"> magic;
|
||||
u32 totalsize;
|
||||
u32 off_dt_struct;
|
||||
u32 off_dt_strings;
|
||||
u32 off_mem_rsvmap;
|
||||
u32 version;
|
||||
u32 last_comp_version;
|
||||
u32 boot_cpuid_phys;
|
||||
u32 size_dt_strings;
|
||||
u32 size_dt_struct;
|
||||
};
|
||||
|
||||
struct AlignTo<auto Alignment> {
|
||||
padding[Alignment- ((($ - 1) % Alignment) + 1)];
|
||||
} [[hidden]];
|
||||
|
||||
struct FDTReserveEntry {
|
||||
u64 address;
|
||||
type::Size<u64> size;
|
||||
|
||||
if (address == 0x00 && size == 0x00)
|
||||
break;
|
||||
};
|
||||
|
||||
enum FDTToken : u32 {
|
||||
FDT_BEGIN_NODE = 0x00000001,
|
||||
FDT_END_NODE = 0x00000002,
|
||||
FDT_PROP = 0x00000003,
|
||||
FDT_NOP = 0x00000004,
|
||||
FDT_END = 0x00000009
|
||||
};
|
||||
|
||||
union FDTPropValue<auto len> {
|
||||
u32 prop_array[len / sizeof(u32)];
|
||||
char string[len];
|
||||
};
|
||||
|
||||
struct FDTProp {
|
||||
FDTToken tok[[hidden]];
|
||||
u32 len [[hidden]];
|
||||
u32 nameoff [[hidden]];
|
||||
if (len > 0) {
|
||||
// if len is zero, value is absent and no need to include it
|
||||
FDTPropValue<len> value;
|
||||
}
|
||||
AlignTo<4>;
|
||||
char name[] @ fdt_addr + str_offset + nameoff;
|
||||
|
||||
std::core::set_display_name(this, name);
|
||||
std::print(std::format("{:x} token {} len {} {}",
|
||||
$, tok, len,nameoff));
|
||||
FDTToken token = std::mem::read_unsigned($, 4, std::mem::Endian::Big);
|
||||
if (token != FDTToken::FDT_PROP) {
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
struct FDTNode {
|
||||
FDTToken token = std::mem::read_unsigned($, 4, std::mem::Endian::Big);
|
||||
|
||||
if (token == FDTToken::FDT_BEGIN_NODE) {
|
||||
FDTToken tok[[hidden]];
|
||||
char name[];
|
||||
AlignTo<4>;
|
||||
std::core::set_display_name(this, name[0] ? name : "/");
|
||||
token = std::mem::read_unsigned($, 4, std::mem::Endian::Big);
|
||||
|
||||
if(token == FDTToken::FDT_PROP) {
|
||||
FDTProp props[while(true)];
|
||||
}
|
||||
|
||||
token = std::mem::read_unsigned($, 4, std::mem::Endian::Big);
|
||||
if(token == FDTToken::FDT_END_NODE) {
|
||||
FDTToken[[hidden]];
|
||||
break;
|
||||
}
|
||||
|
||||
FDTNode children[while(true)][[inline]];
|
||||
} else if(token == FDTToken::FDT_NOP) {
|
||||
// TODO this may break the pattern, I've so far not encountered it
|
||||
}
|
||||
|
||||
// ew duplication
|
||||
token = std::mem::read_unsigned($, 4, std::mem::Endian::Big);
|
||||
if(token == FDTToken::FDT_END_NODE) {
|
||||
FDTToken[[hidden]];
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
struct FDTStructureBlock {
|
||||
FDTNode;
|
||||
};
|
||||
|
||||
|
||||
struct FDT {
|
||||
FDTHeader header;
|
||||
std::assert(header.version == 17, "Unsupported format version");
|
||||
fdt_addr = addressof(this);
|
||||
str_offset = header.off_dt_strings;
|
||||
|
||||
FDTStructureBlock structureBlocks @ fdt_addr + header.off_dt_struct;
|
||||
FDTReserveEntry reserveEntries[while(true)] @ fdt_addr + header.off_mem_rsvmap;
|
||||
};
|
||||
|
||||
std::mem::MagicSearch<"\xD0\x0D\xFE\xED", FDT> fdt @ std::mem::base_address();
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Free Lossless Audio Codec, FLAC Audio Format
|
||||
|
||||
#include <std/sys.pat>
|
||||
#include <std/core.pat>
|
||||
#include <std/io.pat>
|
||||
|
||||
@@ -1,168 +1,171 @@
|
||||
#include <std/io.pat>
|
||||
|
||||
struct DiskTimeStamp {
|
||||
u8 seconds, minutes, hours;
|
||||
};
|
||||
|
||||
enum DiskProtection : u16 {
|
||||
None = 0x0000,
|
||||
CopyProtected = 0x5A5A
|
||||
};
|
||||
|
||||
bitfield CHS {
|
||||
h : 8;
|
||||
s : 6;
|
||||
c : 10;
|
||||
} [[format("chs_formatter")]];
|
||||
|
||||
fn chs_formatter(CHS chs) {
|
||||
return std::format("({:X}, {:X}, {:X}) | 0x{:X}", chs.c, chs.h, chs.s, (chs.c * 16 + chs.h) * 63 + (chs.s - 1));
|
||||
};
|
||||
|
||||
enum PartitionStatus : u8 {
|
||||
None = 0x00,
|
||||
Active = 0x80
|
||||
};
|
||||
|
||||
enum PartitionType : u8 {
|
||||
EmptyPartitionEntry = 0x00,
|
||||
FAT32_CHS = 0x0B,
|
||||
FAT32_LBA = 0x0C
|
||||
};
|
||||
|
||||
namespace fat32 {
|
||||
|
||||
u64 bytesPerCluster;
|
||||
|
||||
struct FSInfo {
|
||||
u32 leadSignature;
|
||||
padding[480];
|
||||
u32 structSignature;
|
||||
u32 freeClusterCount;
|
||||
u32 nextFreeCluster;
|
||||
padding[12];
|
||||
u32 trailSignature;
|
||||
};
|
||||
|
||||
bitfield SequenceNumber {
|
||||
padding : 1;
|
||||
lastLogical : 1;
|
||||
padding : 1;
|
||||
number : 5;
|
||||
} [[left_to_right]];
|
||||
|
||||
enum EntryStatus : u8 {
|
||||
Regular = 0x00,
|
||||
DotEntry = 0x2E,
|
||||
DeletedEntry = 0xE5
|
||||
};
|
||||
|
||||
union EntryStatusOrSequenceNumber {
|
||||
EntryStatus entryStatus;
|
||||
SequenceNumber sequenceNumber;
|
||||
};
|
||||
|
||||
bitfield Attributes {
|
||||
readOnly : 1;
|
||||
hidden : 1;
|
||||
systemFile : 1;
|
||||
volumeLabel : 1;
|
||||
subdirectory : 1;
|
||||
archive : 1;
|
||||
padding : 2;
|
||||
} [[right_to_left]];
|
||||
|
||||
struct DirEntry {
|
||||
char fileName[8];
|
||||
char extension[3];
|
||||
Attributes attributes;
|
||||
u8 reserved[10];
|
||||
u16 time, date;
|
||||
u16 startingCluster;
|
||||
u32 fileSize;
|
||||
|
||||
u8 data[fileSize] @ startingCluster * bytesPerCluster;
|
||||
};
|
||||
|
||||
struct VFATDirEntry {
|
||||
EntryStatusOrSequenceNumber entryStatusOrSequenceNumber;
|
||||
char16 name1[5];
|
||||
Attributes attributes;
|
||||
u8 type;
|
||||
u8 nameChecksum;
|
||||
char16 name2[6];
|
||||
u16 startingCluster;
|
||||
char16 name3[2];
|
||||
|
||||
if (entryStatusOrSequenceNumber.sequenceNumber.number > 1)
|
||||
VFATDirEntry nextLogicalEntry;
|
||||
else
|
||||
DirEntry physicalEntry;
|
||||
};
|
||||
|
||||
struct Partition {
|
||||
u8 jmpCode[3];
|
||||
char oemName[8];
|
||||
u16 bytesPerSector;
|
||||
u8 sectorsPerCluster;
|
||||
u16 reservedAreaSize;
|
||||
u8 numFats;
|
||||
u16 rootEntryCount;
|
||||
u16 numSectors;
|
||||
u8 mediaType;
|
||||
u16 fatSize;
|
||||
u16 sectorsPerTrack;
|
||||
u16 numHeads;
|
||||
u32 numHiddenSectors;
|
||||
u32 numFsSectors;
|
||||
u32 numFatSectors;
|
||||
u16 extFlags;
|
||||
u16 fsVersion;
|
||||
u32 rootCluster;
|
||||
u16 fsInfoSector;
|
||||
u16 backupBootSector;
|
||||
padding[12];
|
||||
u8 driveNumber;
|
||||
padding[1];
|
||||
u8 bootSignature;
|
||||
u32 volumeID;
|
||||
char volumeLabel[11];
|
||||
char fsType[8];
|
||||
u8 bootstrapCode[420];
|
||||
u16 signature;
|
||||
|
||||
bytesPerCluster = (sectorsPerCluster * 1024) * bytesPerSector;
|
||||
|
||||
FSInfo fsInfo @ addressof(this) + fsInfoSector * bytesPerSector;
|
||||
VFATDirEntry rootDirEntry @ addressof(this) + rootCluster * bytesPerCluster;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
struct PartitionEntry {
|
||||
PartitionStatus status;
|
||||
CHS chsFirstSectorAddress;
|
||||
PartitionType type;
|
||||
CHS chsLastSectorAddress;
|
||||
u32 lbaFirstSectorAddress;
|
||||
u32 numSectors;
|
||||
|
||||
if (type == PartitionType::EmptyPartitionEntry)
|
||||
continue;
|
||||
else if (type == PartitionType::FAT32_CHS || type == PartitionType::FAT32_LBA)
|
||||
fat32::Partition partition @ lbaFirstSectorAddress * 512;
|
||||
};
|
||||
|
||||
struct MasterBootRecord {
|
||||
u8 bootstrapCodeArea1[218];
|
||||
padding[2];
|
||||
u8 originalPhysicalDrive;
|
||||
DiskTimeStamp diskTimeStamp;
|
||||
u8 bootstrapCodeArea2[216];
|
||||
u32 diskSignature;
|
||||
DiskProtection diskProtection;
|
||||
PartitionEntry partitionEntries[4];
|
||||
u16 bootSignature;
|
||||
};
|
||||
|
||||
#pragma author WerWolv
|
||||
#pragma description Drive File System
|
||||
|
||||
#include <std/io.pat>
|
||||
|
||||
struct DiskTimeStamp {
|
||||
u8 seconds, minutes, hours;
|
||||
};
|
||||
|
||||
enum DiskProtection : u16 {
|
||||
None = 0x0000,
|
||||
CopyProtected = 0x5A5A
|
||||
};
|
||||
|
||||
bitfield CHS {
|
||||
h : 8;
|
||||
s : 6;
|
||||
c : 10;
|
||||
} [[format("chs_formatter")]];
|
||||
|
||||
fn chs_formatter(CHS chs) {
|
||||
return std::format("({:X}, {:X}, {:X}) | 0x{:X}", chs.c, chs.h, chs.s, (chs.c * 16 + chs.h) * 63 + (chs.s - 1));
|
||||
};
|
||||
|
||||
enum PartitionStatus : u8 {
|
||||
None = 0x00,
|
||||
Active = 0x80
|
||||
};
|
||||
|
||||
enum PartitionType : u8 {
|
||||
EmptyPartitionEntry = 0x00,
|
||||
FAT32_CHS = 0x0B,
|
||||
FAT32_LBA = 0x0C
|
||||
};
|
||||
|
||||
namespace fat32 {
|
||||
|
||||
u64 bytesPerCluster;
|
||||
|
||||
struct FSInfo {
|
||||
u32 leadSignature;
|
||||
padding[480];
|
||||
u32 structSignature;
|
||||
u32 freeClusterCount;
|
||||
u32 nextFreeCluster;
|
||||
padding[12];
|
||||
u32 trailSignature;
|
||||
};
|
||||
|
||||
bitfield SequenceNumber {
|
||||
padding : 1;
|
||||
lastLogical : 1;
|
||||
padding : 1;
|
||||
number : 5;
|
||||
} [[left_to_right]];
|
||||
|
||||
enum EntryStatus : u8 {
|
||||
Regular = 0x00,
|
||||
DotEntry = 0x2E,
|
||||
DeletedEntry = 0xE5
|
||||
};
|
||||
|
||||
union EntryStatusOrSequenceNumber {
|
||||
EntryStatus entryStatus;
|
||||
SequenceNumber sequenceNumber;
|
||||
};
|
||||
|
||||
bitfield Attributes {
|
||||
readOnly : 1;
|
||||
hidden : 1;
|
||||
systemFile : 1;
|
||||
volumeLabel : 1;
|
||||
subdirectory : 1;
|
||||
archive : 1;
|
||||
padding : 2;
|
||||
} [[right_to_left]];
|
||||
|
||||
struct DirEntry {
|
||||
char fileName[8];
|
||||
char extension[3];
|
||||
Attributes attributes;
|
||||
u8 reserved[10];
|
||||
u16 time, date;
|
||||
u16 startingCluster;
|
||||
u32 fileSize;
|
||||
|
||||
u8 data[fileSize] @ startingCluster * bytesPerCluster;
|
||||
};
|
||||
|
||||
struct VFATDirEntry {
|
||||
EntryStatusOrSequenceNumber entryStatusOrSequenceNumber;
|
||||
char16 name1[5];
|
||||
Attributes attributes;
|
||||
u8 type;
|
||||
u8 nameChecksum;
|
||||
char16 name2[6];
|
||||
u16 startingCluster;
|
||||
char16 name3[2];
|
||||
|
||||
if (entryStatusOrSequenceNumber.sequenceNumber.number > 1)
|
||||
VFATDirEntry nextLogicalEntry;
|
||||
else
|
||||
DirEntry physicalEntry;
|
||||
};
|
||||
|
||||
struct Partition {
|
||||
u8 jmpCode[3];
|
||||
char oemName[8];
|
||||
u16 bytesPerSector;
|
||||
u8 sectorsPerCluster;
|
||||
u16 reservedAreaSize;
|
||||
u8 numFats;
|
||||
u16 rootEntryCount;
|
||||
u16 numSectors;
|
||||
u8 mediaType;
|
||||
u16 fatSize;
|
||||
u16 sectorsPerTrack;
|
||||
u16 numHeads;
|
||||
u32 numHiddenSectors;
|
||||
u32 numFsSectors;
|
||||
u32 numFatSectors;
|
||||
u16 extFlags;
|
||||
u16 fsVersion;
|
||||
u32 rootCluster;
|
||||
u16 fsInfoSector;
|
||||
u16 backupBootSector;
|
||||
padding[12];
|
||||
u8 driveNumber;
|
||||
padding[1];
|
||||
u8 bootSignature;
|
||||
u32 volumeID;
|
||||
char volumeLabel[11];
|
||||
char fsType[8];
|
||||
u8 bootstrapCode[420];
|
||||
u16 signature;
|
||||
|
||||
bytesPerCluster = (sectorsPerCluster * 1024) * bytesPerSector;
|
||||
|
||||
FSInfo fsInfo @ addressof(this) + fsInfoSector * bytesPerSector;
|
||||
VFATDirEntry rootDirEntry @ addressof(this) + rootCluster * bytesPerCluster;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
struct PartitionEntry {
|
||||
PartitionStatus status;
|
||||
CHS chsFirstSectorAddress;
|
||||
PartitionType type;
|
||||
CHS chsLastSectorAddress;
|
||||
u32 lbaFirstSectorAddress;
|
||||
u32 numSectors;
|
||||
|
||||
if (type == PartitionType::EmptyPartitionEntry)
|
||||
continue;
|
||||
else if (type == PartitionType::FAT32_CHS || type == PartitionType::FAT32_LBA)
|
||||
fat32::Partition partition @ lbaFirstSectorAddress * 512;
|
||||
};
|
||||
|
||||
struct MasterBootRecord {
|
||||
u8 bootstrapCodeArea1[218];
|
||||
padding[2];
|
||||
u8 originalPhysicalDrive;
|
||||
DiskTimeStamp diskTimeStamp;
|
||||
u8 bootstrapCodeArea2[216];
|
||||
u32 diskSignature;
|
||||
DiskProtection diskProtection;
|
||||
PartitionEntry partitionEntries[4];
|
||||
u16 bootSignature;
|
||||
};
|
||||
|
||||
MasterBootRecord mbr @ 0x00;
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Gameboy ROM
|
||||
|
||||
#include <type/size.pat>
|
||||
#include <std/io.pat>
|
||||
#include <std/string.pat>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description GIF image files
|
||||
|
||||
#pragma MIME image/gif
|
||||
|
||||
// Extension Labels
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description GZip compressed data format
|
||||
|
||||
#pragma MIME application/gzip
|
||||
|
||||
#include <type/time.pat>
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Icon (.ico) or Cursor (.cur) files
|
||||
|
||||
#pragma endian little
|
||||
|
||||
#include <std/sys.pat>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description ID3 tags in MP3 files
|
||||
|
||||
#pragma MIME audio/mpeg
|
||||
|
||||
#include <std/mem.pat>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description [Intel hexadecimal object file format definition]("https://en.wikipedia.org/wiki/Intel_HEX")
|
||||
|
||||
/* If you have no delimiters between data records then remove
|
||||
* the null_bytes field in the data_packet struct.
|
||||
* Set the array at the bottom to the highest index + 1 in the Pattern Data view
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Ethernet II Frames (IP Packets)
|
||||
|
||||
#pragma endian big
|
||||
|
||||
#include <std/sys.pat>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description IPS (International Patching System) files
|
||||
|
||||
#include <std/mem.pat>
|
||||
#include <std/string.pat>
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description ISO 9660 file system
|
||||
|
||||
#pragma endian little
|
||||
|
||||
#include <std/io.pat>
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Java Class files
|
||||
|
||||
#pragma endian big
|
||||
#pragma pattern_limit 100000000
|
||||
#pragma MIME application/x-java-applet
|
||||
|
||||
@@ -1,122 +1,125 @@
|
||||
#include <std/mem.pat>
|
||||
#pragma endian big
|
||||
|
||||
#pragma MIME image/jpeg
|
||||
|
||||
enum Marker : u8 {
|
||||
TEM = 0x01,
|
||||
SOF0 = 0xC0,
|
||||
SOF1 = 0xC1,
|
||||
SOF2 = 0xC2,
|
||||
SOF3 = 0xC3,
|
||||
DHT = 0xC4,
|
||||
SOF5 = 0xC5,
|
||||
SOF6 = 0xC6,
|
||||
SOF7 = 0xC7,
|
||||
SOI = 0xD8,
|
||||
EOI = 0xD9,
|
||||
SOS = 0xDA,
|
||||
DQT = 0xDB,
|
||||
DNL = 0xDC,
|
||||
DRI = 0xDD,
|
||||
DHP = 0xDE,
|
||||
APP0 = 0xE0,
|
||||
APP1 = 0xE1,
|
||||
APP2 = 0xE2,
|
||||
APP3 = 0xE3,
|
||||
APP4 = 0xE4,
|
||||
APP5 = 0xE5,
|
||||
APP6 = 0xE6,
|
||||
APP7 = 0xE7,
|
||||
APP8 = 0xE8,
|
||||
APP9 = 0xE9,
|
||||
APP10 = 0xEA,
|
||||
APP11 = 0xEB,
|
||||
APP12 = 0xEC,
|
||||
APP13 = 0xED,
|
||||
APP14 = 0xEE,
|
||||
APP15 = 0xEF,
|
||||
COM = 0xFE
|
||||
};
|
||||
|
||||
enum DensityUnit : u8 {
|
||||
NoUnit = 0x00,
|
||||
PixelsPerInch = 0x01,
|
||||
PixelsPerCm = 0x02
|
||||
};
|
||||
|
||||
struct Pixel {
|
||||
u8 r, g, b;
|
||||
} [[sealed, transform("transform_pixel")]];
|
||||
|
||||
fn transform_pixel(Pixel pixel) {
|
||||
return (0xFF << 24) | (pixel.b << 16) | (pixel.g << 8) | (pixel.r << 0);
|
||||
};
|
||||
|
||||
|
||||
struct APP0 {
|
||||
char magic[5];
|
||||
u8 versionMajor, versionMinor;
|
||||
DensityUnit densityUnit;
|
||||
u16 densityX, densityY;
|
||||
u8 thumbnailX, thumbnailY;
|
||||
Pixel thumbnail[thumbnailX * thumbnailY] [[sealed]];
|
||||
};
|
||||
|
||||
enum ComponentId : u8 {
|
||||
Y = 1,
|
||||
CB = 2,
|
||||
CR = 3,
|
||||
I = 4,
|
||||
Q = 5
|
||||
};
|
||||
|
||||
struct SOF0Component {
|
||||
ComponentId componentId;
|
||||
u8 samplingFactors;
|
||||
u8 quantizationTableId;
|
||||
};
|
||||
|
||||
struct SOF0 {
|
||||
u8 bitsPerSample;
|
||||
u16 imageHeight, imageWidth;
|
||||
u8 numComponents;
|
||||
SOF0Component components[numComponents];
|
||||
};
|
||||
|
||||
struct SOSComponent {
|
||||
ComponentId componentId;
|
||||
u8 huffmanTable;
|
||||
};
|
||||
|
||||
struct SOS {
|
||||
u8 numComponents;
|
||||
SOSComponent components[numComponents];
|
||||
u8 startSpectralSelection;
|
||||
u8 endSpectral;
|
||||
u8 apprBitPos;
|
||||
|
||||
u8 image_data[while(!std::mem::eof())] [[sealed]];
|
||||
};
|
||||
|
||||
struct Segment {
|
||||
u8 magic;
|
||||
Marker marker;
|
||||
|
||||
if (marker == Marker::SOI || marker == Marker::EOI) {
|
||||
|
||||
} else {
|
||||
u16 length;
|
||||
if (marker == Marker::APP0) {
|
||||
APP0 data;
|
||||
} else if (marker == Marker::SOF0) {
|
||||
SOF0 data;
|
||||
} else if (marker == Marker::SOS) {
|
||||
SOS data;
|
||||
} else {
|
||||
u8 data[length - sizeof(length)] [[sealed]];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#pragma author WerWolv
|
||||
#pragma description JPEG Image Format
|
||||
|
||||
#include <std/mem.pat>
|
||||
#pragma endian big
|
||||
|
||||
#pragma MIME image/jpeg
|
||||
|
||||
enum Marker : u8 {
|
||||
TEM = 0x01,
|
||||
SOF0 = 0xC0,
|
||||
SOF1 = 0xC1,
|
||||
SOF2 = 0xC2,
|
||||
SOF3 = 0xC3,
|
||||
DHT = 0xC4,
|
||||
SOF5 = 0xC5,
|
||||
SOF6 = 0xC6,
|
||||
SOF7 = 0xC7,
|
||||
SOI = 0xD8,
|
||||
EOI = 0xD9,
|
||||
SOS = 0xDA,
|
||||
DQT = 0xDB,
|
||||
DNL = 0xDC,
|
||||
DRI = 0xDD,
|
||||
DHP = 0xDE,
|
||||
APP0 = 0xE0,
|
||||
APP1 = 0xE1,
|
||||
APP2 = 0xE2,
|
||||
APP3 = 0xE3,
|
||||
APP4 = 0xE4,
|
||||
APP5 = 0xE5,
|
||||
APP6 = 0xE6,
|
||||
APP7 = 0xE7,
|
||||
APP8 = 0xE8,
|
||||
APP9 = 0xE9,
|
||||
APP10 = 0xEA,
|
||||
APP11 = 0xEB,
|
||||
APP12 = 0xEC,
|
||||
APP13 = 0xED,
|
||||
APP14 = 0xEE,
|
||||
APP15 = 0xEF,
|
||||
COM = 0xFE
|
||||
};
|
||||
|
||||
enum DensityUnit : u8 {
|
||||
NoUnit = 0x00,
|
||||
PixelsPerInch = 0x01,
|
||||
PixelsPerCm = 0x02
|
||||
};
|
||||
|
||||
struct Pixel {
|
||||
u8 r, g, b;
|
||||
} [[sealed, transform("transform_pixel")]];
|
||||
|
||||
fn transform_pixel(Pixel pixel) {
|
||||
return (0xFF << 24) | (pixel.b << 16) | (pixel.g << 8) | (pixel.r << 0);
|
||||
};
|
||||
|
||||
|
||||
struct APP0 {
|
||||
char magic[5];
|
||||
u8 versionMajor, versionMinor;
|
||||
DensityUnit densityUnit;
|
||||
u16 densityX, densityY;
|
||||
u8 thumbnailX, thumbnailY;
|
||||
Pixel thumbnail[thumbnailX * thumbnailY] [[sealed]];
|
||||
};
|
||||
|
||||
enum ComponentId : u8 {
|
||||
Y = 1,
|
||||
CB = 2,
|
||||
CR = 3,
|
||||
I = 4,
|
||||
Q = 5
|
||||
};
|
||||
|
||||
struct SOF0Component {
|
||||
ComponentId componentId;
|
||||
u8 samplingFactors;
|
||||
u8 quantizationTableId;
|
||||
};
|
||||
|
||||
struct SOF0 {
|
||||
u8 bitsPerSample;
|
||||
u16 imageHeight, imageWidth;
|
||||
u8 numComponents;
|
||||
SOF0Component components[numComponents];
|
||||
};
|
||||
|
||||
struct SOSComponent {
|
||||
ComponentId componentId;
|
||||
u8 huffmanTable;
|
||||
};
|
||||
|
||||
struct SOS {
|
||||
u8 numComponents;
|
||||
SOSComponent components[numComponents];
|
||||
u8 startSpectralSelection;
|
||||
u8 endSpectral;
|
||||
u8 apprBitPos;
|
||||
|
||||
u8 image_data[while(!std::mem::eof())] [[sealed]];
|
||||
};
|
||||
|
||||
struct Segment {
|
||||
u8 magic;
|
||||
Marker marker;
|
||||
|
||||
if (marker == Marker::SOI || marker == Marker::EOI) {
|
||||
|
||||
} else {
|
||||
u16 length;
|
||||
if (marker == Marker::APP0) {
|
||||
APP0 data;
|
||||
} else if (marker == Marker::SOF0) {
|
||||
SOF0 data;
|
||||
} else if (marker == Marker::SOS) {
|
||||
SOS data;
|
||||
} else {
|
||||
u8 data[length - sizeof(length)] [[sealed]];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Segment segments[while(!std::mem::eof())] @ 0x00 [[hex::visualize("image", this)]];
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Windows Shell Link file format
|
||||
|
||||
#pragma MIME application/x-ms-shortcut
|
||||
|
||||
#include <std/core.pat>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description Lua 5.4 bytecode
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Mach-O executable
|
||||
|
||||
#pragma MIME application/x-mach-binary
|
||||
|
||||
#include <type/size.pat>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description Mechanized Assault and Exploration v1.04 (strategy game) save file format
|
||||
|
||||
#include <std/sys.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description MIDI header, event fields provided
|
||||
|
||||
#include <std/core.pat>
|
||||
|
||||
#pragma MIME audio/midi
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Windows MiniDump files
|
||||
|
||||
#pragma MIME application/x-dmp
|
||||
|
||||
#include <type/time.pat>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description MPEG-4 Part 14 digital multimedia container format
|
||||
|
||||
#pragma endian big
|
||||
|
||||
#pragma MIME audio/mp4
|
||||
|
||||
@@ -1,154 +1,157 @@
|
||||
#pragma MIME application/x-msgpack
|
||||
|
||||
enum Type : u8 {
|
||||
PositiveFixInt = 0x00 ... 0x7F,
|
||||
FixMap = 0x80 ... 0x8F,
|
||||
FixArray = 0x90 ... 0x9F,
|
||||
FixStr = 0xA0 ... 0xBF,
|
||||
Nil = 0xC0,
|
||||
Unused = 0xC1,
|
||||
False = 0xC2,
|
||||
True = 0xC3,
|
||||
Bin8 = 0xC4,
|
||||
Bin16 = 0xC5,
|
||||
Bin32 = 0xC6,
|
||||
Ext8 = 0xC7,
|
||||
Ext16 = 0xC8,
|
||||
Ext32 = 0xC9,
|
||||
Float32 = 0xCA,
|
||||
Float64 = 0xCB,
|
||||
Uint8 = 0xCC,
|
||||
Uint16 = 0xCD,
|
||||
Uint32 = 0xCE,
|
||||
Uint64 = 0xCF,
|
||||
Int8 = 0xD0,
|
||||
Int16 = 0xD1,
|
||||
Int32 = 0xD2,
|
||||
Int64 = 0xD3,
|
||||
FixExt1 = 0xD4,
|
||||
FixExt2 = 0xD5,
|
||||
FixExt4 = 0xD6,
|
||||
FixExt8 = 0xD7,
|
||||
FixExt16 = 0xD8,
|
||||
Str8 = 0xD9,
|
||||
Str16 = 0xDA,
|
||||
Str32 = 0xDB,
|
||||
Array16 = 0xDC,
|
||||
Array32 = 0xDD,
|
||||
Map16 = 0xDE,
|
||||
Map32 = 0xDF,
|
||||
NegativeFixInt = 0xE0 ... 0xFF
|
||||
};
|
||||
|
||||
fn format_positive_fixint(u8 value) {
|
||||
return value & 0b0111'1111;
|
||||
};
|
||||
|
||||
fn format_negative_fixint(u8 value) {
|
||||
return -(value & 0b0001'1111);
|
||||
};
|
||||
|
||||
using MessagePack;
|
||||
|
||||
struct MapEntry {
|
||||
MessagePack key, value;
|
||||
};
|
||||
|
||||
struct MessagePack {
|
||||
Type type;
|
||||
|
||||
if (u8(type) <= 0x7F) {
|
||||
$ -= 1;
|
||||
u8 value [[format("format_positive_fixint")]];
|
||||
} else if (u8(type) >= Type::NegativeFixInt) {
|
||||
$ -= 1;
|
||||
u8 value [[format("format_negative_fixint")]];
|
||||
} else if (type == Type::Uint8)
|
||||
be u8 value;
|
||||
else if (type == Type::Uint16)
|
||||
be u16 value;
|
||||
else if (type == Type::Uint32)
|
||||
be u32 value;
|
||||
else if (type == Type::Uint64)
|
||||
be u64 value;
|
||||
else if (type == Type::Int8)
|
||||
be s8 value;
|
||||
else if (type == Type::Int16)
|
||||
be s16 value;
|
||||
else if (type == Type::Int32)
|
||||
be s32 value;
|
||||
else if (type == Type::Int64)
|
||||
be s64 value;
|
||||
else if (type == Type::Float32)
|
||||
be float value;
|
||||
else if (type == Type::Float64)
|
||||
be double value;
|
||||
else if ((u8(type) & 0b1110'0000) == Type::FixStr)
|
||||
char value[u8(type) & 0b0001'1111];
|
||||
else if (type == Type::Str8) {
|
||||
be u8 length;
|
||||
char value[length];
|
||||
} else if (type == Type::Str16) {
|
||||
be u16 length;
|
||||
char value[length];
|
||||
} else if (type == Type::Str32) {
|
||||
be u32 length;
|
||||
char value[length];
|
||||
} else if (type == Type::Bin8) {
|
||||
be u8 length;
|
||||
u8 value[length];
|
||||
} else if (type == Type::Bin16) {
|
||||
be u16 length;
|
||||
u8 value[length];
|
||||
} else if (type == Type::Bin32) {
|
||||
be u32 length;
|
||||
u8 value[length];
|
||||
} else if ((u8(type) & 0b1111'0000) == Type::FixArray)
|
||||
MessagePack value[u8(type) & 0b0000'1111];
|
||||
else if (type == Type::Array16) {
|
||||
be u16 length;
|
||||
MessagePack value[length];
|
||||
} else if (type == Type::Array32) {
|
||||
be u32 length;
|
||||
MessagePack value[length];
|
||||
} else if ((u8(type) & 0b1111'0000) == Type::FixMap)
|
||||
MapEntry value[u8(type) & 0b0000'1111];
|
||||
else if (type == Type::Map16) {
|
||||
be u16 length;
|
||||
MapEntry value[length];
|
||||
} else if (type == Type::Map32) {
|
||||
be u32 length;
|
||||
MapEntry value[length];
|
||||
} else if (type == Type::FixExt1) {
|
||||
s8 type;
|
||||
u8 data;
|
||||
} else if (type == Type::FixExt2) {
|
||||
s8 type;
|
||||
u16 data;
|
||||
} else if (type == Type::FixExt4) {
|
||||
s8 type;
|
||||
u32 data;
|
||||
} else if (type == Type::FixExt8) {
|
||||
s8 type;
|
||||
u64 data;
|
||||
} else if (type == Type::FixExt16) {
|
||||
s8 type;
|
||||
u128 data;
|
||||
} else if (type == Type::Ext8) {
|
||||
u8 length;
|
||||
s8 type;
|
||||
u8 data[length];
|
||||
} else if (type == Type::Ext16) {
|
||||
u16 length;
|
||||
s8 type;
|
||||
u8 data[length];
|
||||
} else if (type == Type::Ext32) {
|
||||
u32 length;
|
||||
s8 type;
|
||||
u8 data[length];
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#pragma author WerWolv
|
||||
#pragma description MessagePack binary serialization format
|
||||
|
||||
#pragma MIME application/x-msgpack
|
||||
|
||||
enum Type : u8 {
|
||||
PositiveFixInt = 0x00 ... 0x7F,
|
||||
FixMap = 0x80 ... 0x8F,
|
||||
FixArray = 0x90 ... 0x9F,
|
||||
FixStr = 0xA0 ... 0xBF,
|
||||
Nil = 0xC0,
|
||||
Unused = 0xC1,
|
||||
False = 0xC2,
|
||||
True = 0xC3,
|
||||
Bin8 = 0xC4,
|
||||
Bin16 = 0xC5,
|
||||
Bin32 = 0xC6,
|
||||
Ext8 = 0xC7,
|
||||
Ext16 = 0xC8,
|
||||
Ext32 = 0xC9,
|
||||
Float32 = 0xCA,
|
||||
Float64 = 0xCB,
|
||||
Uint8 = 0xCC,
|
||||
Uint16 = 0xCD,
|
||||
Uint32 = 0xCE,
|
||||
Uint64 = 0xCF,
|
||||
Int8 = 0xD0,
|
||||
Int16 = 0xD1,
|
||||
Int32 = 0xD2,
|
||||
Int64 = 0xD3,
|
||||
FixExt1 = 0xD4,
|
||||
FixExt2 = 0xD5,
|
||||
FixExt4 = 0xD6,
|
||||
FixExt8 = 0xD7,
|
||||
FixExt16 = 0xD8,
|
||||
Str8 = 0xD9,
|
||||
Str16 = 0xDA,
|
||||
Str32 = 0xDB,
|
||||
Array16 = 0xDC,
|
||||
Array32 = 0xDD,
|
||||
Map16 = 0xDE,
|
||||
Map32 = 0xDF,
|
||||
NegativeFixInt = 0xE0 ... 0xFF
|
||||
};
|
||||
|
||||
fn format_positive_fixint(u8 value) {
|
||||
return value & 0b0111'1111;
|
||||
};
|
||||
|
||||
fn format_negative_fixint(u8 value) {
|
||||
return -(value & 0b0001'1111);
|
||||
};
|
||||
|
||||
using MessagePack;
|
||||
|
||||
struct MapEntry {
|
||||
MessagePack key, value;
|
||||
};
|
||||
|
||||
struct MessagePack {
|
||||
Type type;
|
||||
|
||||
if (u8(type) <= 0x7F) {
|
||||
$ -= 1;
|
||||
u8 value [[format("format_positive_fixint")]];
|
||||
} else if (u8(type) >= Type::NegativeFixInt) {
|
||||
$ -= 1;
|
||||
u8 value [[format("format_negative_fixint")]];
|
||||
} else if (type == Type::Uint8)
|
||||
be u8 value;
|
||||
else if (type == Type::Uint16)
|
||||
be u16 value;
|
||||
else if (type == Type::Uint32)
|
||||
be u32 value;
|
||||
else if (type == Type::Uint64)
|
||||
be u64 value;
|
||||
else if (type == Type::Int8)
|
||||
be s8 value;
|
||||
else if (type == Type::Int16)
|
||||
be s16 value;
|
||||
else if (type == Type::Int32)
|
||||
be s32 value;
|
||||
else if (type == Type::Int64)
|
||||
be s64 value;
|
||||
else if (type == Type::Float32)
|
||||
be float value;
|
||||
else if (type == Type::Float64)
|
||||
be double value;
|
||||
else if ((u8(type) & 0b1110'0000) == Type::FixStr)
|
||||
char value[u8(type) & 0b0001'1111];
|
||||
else if (type == Type::Str8) {
|
||||
be u8 length;
|
||||
char value[length];
|
||||
} else if (type == Type::Str16) {
|
||||
be u16 length;
|
||||
char value[length];
|
||||
} else if (type == Type::Str32) {
|
||||
be u32 length;
|
||||
char value[length];
|
||||
} else if (type == Type::Bin8) {
|
||||
be u8 length;
|
||||
u8 value[length];
|
||||
} else if (type == Type::Bin16) {
|
||||
be u16 length;
|
||||
u8 value[length];
|
||||
} else if (type == Type::Bin32) {
|
||||
be u32 length;
|
||||
u8 value[length];
|
||||
} else if ((u8(type) & 0b1111'0000) == Type::FixArray)
|
||||
MessagePack value[u8(type) & 0b0000'1111];
|
||||
else if (type == Type::Array16) {
|
||||
be u16 length;
|
||||
MessagePack value[length];
|
||||
} else if (type == Type::Array32) {
|
||||
be u32 length;
|
||||
MessagePack value[length];
|
||||
} else if ((u8(type) & 0b1111'0000) == Type::FixMap)
|
||||
MapEntry value[u8(type) & 0b0000'1111];
|
||||
else if (type == Type::Map16) {
|
||||
be u16 length;
|
||||
MapEntry value[length];
|
||||
} else if (type == Type::Map32) {
|
||||
be u32 length;
|
||||
MapEntry value[length];
|
||||
} else if (type == Type::FixExt1) {
|
||||
s8 type;
|
||||
u8 data;
|
||||
} else if (type == Type::FixExt2) {
|
||||
s8 type;
|
||||
u16 data;
|
||||
} else if (type == Type::FixExt4) {
|
||||
s8 type;
|
||||
u32 data;
|
||||
} else if (type == Type::FixExt8) {
|
||||
s8 type;
|
||||
u64 data;
|
||||
} else if (type == Type::FixExt16) {
|
||||
s8 type;
|
||||
u128 data;
|
||||
} else if (type == Type::Ext8) {
|
||||
u8 length;
|
||||
s8 type;
|
||||
u8 data[length];
|
||||
} else if (type == Type::Ext16) {
|
||||
u16 length;
|
||||
s8 type;
|
||||
u8 data[length];
|
||||
} else if (type == Type::Ext32) {
|
||||
u32 length;
|
||||
s8 type;
|
||||
u8 data[length];
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
MessagePack pack @ 0x00;
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Nintendo Switch NACP files
|
||||
|
||||
#pragma endian little
|
||||
|
||||
#include <std/sys.pat>
|
||||
|
||||
@@ -1,76 +1,79 @@
|
||||
#include <std/sys.pat>
|
||||
|
||||
#pragma endian big
|
||||
|
||||
enum Tag : u8 {
|
||||
End = 0,
|
||||
Byte = 1,
|
||||
Short = 2,
|
||||
Int = 3,
|
||||
Long = 4,
|
||||
Float = 5,
|
||||
Double = 6,
|
||||
ByteArray = 7,
|
||||
String = 8,
|
||||
List = 9,
|
||||
Compound = 10,
|
||||
IntArray = 11,
|
||||
LongArray = 12
|
||||
};
|
||||
|
||||
using Element;
|
||||
|
||||
struct Value {
|
||||
if (parent.tag == Tag::Byte)
|
||||
s8 value;
|
||||
else if (parent.tag == Tag::Short)
|
||||
s16 value;
|
||||
else if (parent.tag == Tag::Int)
|
||||
s32 value;
|
||||
else if (parent.tag == Tag::Long)
|
||||
s64 value;
|
||||
else if (parent.tag == Tag::Float)
|
||||
float value;
|
||||
else if (parent.tag == Tag::Double)
|
||||
double value;
|
||||
else if (parent.tag == Tag::ByteArray) {
|
||||
s32 arrayLength;
|
||||
s8 value[arrayLength] [[sealed]];
|
||||
} else if (parent.tag == Tag::String) {
|
||||
u16 stringLength;
|
||||
char value[stringLength];
|
||||
} else if (parent.tag == Tag::List) {
|
||||
Tag tag;
|
||||
s32 listLength;
|
||||
Value values[listLength] [[static]];
|
||||
} else if (parent.tag == Tag::Compound) {
|
||||
Element values[while(true)];
|
||||
} else if (parent.tag == Tag::IntArray){
|
||||
s32 arrayLength;
|
||||
s32 value[arrayLength] [[sealed]];
|
||||
} else if (parent.tag == Tag::LongArray) {
|
||||
s32 arrayLength;
|
||||
s64 value[arrayLength] [[sealed]];
|
||||
} else {
|
||||
std::error(std::format("Invalid tag {:02X}", TypeTag));
|
||||
}
|
||||
} [[inline]];
|
||||
|
||||
struct Element {
|
||||
Tag tag;
|
||||
if (tag == Tag::End)
|
||||
break;
|
||||
else {
|
||||
|
||||
u16 nameLength;
|
||||
char name[nameLength];
|
||||
|
||||
Value value;
|
||||
}
|
||||
};
|
||||
|
||||
struct NBT {
|
||||
Element element[while(true)] [[inline]];
|
||||
};
|
||||
|
||||
NBT nbt @ 0x00;
|
||||
#pragma author WerWolv
|
||||
#pragma description Minecraft NBT format
|
||||
|
||||
#include <std/sys.pat>
|
||||
|
||||
#pragma endian big
|
||||
|
||||
enum Tag : u8 {
|
||||
End = 0,
|
||||
Byte = 1,
|
||||
Short = 2,
|
||||
Int = 3,
|
||||
Long = 4,
|
||||
Float = 5,
|
||||
Double = 6,
|
||||
ByteArray = 7,
|
||||
String = 8,
|
||||
List = 9,
|
||||
Compound = 10,
|
||||
IntArray = 11,
|
||||
LongArray = 12
|
||||
};
|
||||
|
||||
using Element;
|
||||
|
||||
struct Value {
|
||||
if (parent.tag == Tag::Byte)
|
||||
s8 value;
|
||||
else if (parent.tag == Tag::Short)
|
||||
s16 value;
|
||||
else if (parent.tag == Tag::Int)
|
||||
s32 value;
|
||||
else if (parent.tag == Tag::Long)
|
||||
s64 value;
|
||||
else if (parent.tag == Tag::Float)
|
||||
float value;
|
||||
else if (parent.tag == Tag::Double)
|
||||
double value;
|
||||
else if (parent.tag == Tag::ByteArray) {
|
||||
s32 arrayLength;
|
||||
s8 value[arrayLength] [[sealed]];
|
||||
} else if (parent.tag == Tag::String) {
|
||||
u16 stringLength;
|
||||
char value[stringLength];
|
||||
} else if (parent.tag == Tag::List) {
|
||||
Tag tag;
|
||||
s32 listLength;
|
||||
Value values[listLength] [[static]];
|
||||
} else if (parent.tag == Tag::Compound) {
|
||||
Element values[while(true)];
|
||||
} else if (parent.tag == Tag::IntArray){
|
||||
s32 arrayLength;
|
||||
s32 value[arrayLength] [[sealed]];
|
||||
} else if (parent.tag == Tag::LongArray) {
|
||||
s32 arrayLength;
|
||||
s64 value[arrayLength] [[sealed]];
|
||||
} else {
|
||||
std::error(std::format("Invalid tag {:02X}", TypeTag));
|
||||
}
|
||||
} [[inline]];
|
||||
|
||||
struct Element {
|
||||
Tag tag;
|
||||
if (tag == Tag::End)
|
||||
break;
|
||||
else {
|
||||
|
||||
u16 nameLength;
|
||||
char name[nameLength];
|
||||
|
||||
Value value;
|
||||
}
|
||||
};
|
||||
|
||||
struct NBT {
|
||||
Element element[while(true)] [[inline]];
|
||||
};
|
||||
|
||||
NBT nbt @ 0x00;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description NE header and Standard NE fields
|
||||
|
||||
#include <std/mem.pat>
|
||||
|
||||
struct DOSHeader {
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Nintendo Switch NRO files
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/sys.pat>
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description NTAG213/NTAG215/NTAG216, NFC Forum Type 2 Tag compliant IC
|
||||
|
||||
#include <std/core.pat>
|
||||
|
||||
using BitfieldOrder = std::core::BitfieldOrder;
|
||||
|
||||
@@ -1,29 +1,32 @@
|
||||
#pragma MIME audio/ogg
|
||||
|
||||
#include <std/core.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
bitfield HeaderType {
|
||||
Continuation : 1;
|
||||
BeginOfStream : 1;
|
||||
EndOfStream : 1;
|
||||
};
|
||||
|
||||
struct SegmentData {
|
||||
u8 data[parent.segmentTable[std::core::array_index()]];
|
||||
};
|
||||
|
||||
struct Ogg {
|
||||
char capturePattern[4];
|
||||
u8 version;
|
||||
HeaderType headerType;
|
||||
u64 granulePosition;
|
||||
u32 bitstreamSerialNumber;
|
||||
u32 pageSequenceNumber;
|
||||
u32 checksum;
|
||||
u8 pageSegments;
|
||||
u8 segmentTable[pageSegments];
|
||||
SegmentData data[pageSegments];
|
||||
};
|
||||
|
||||
#pragma author WerWolv
|
||||
#pragma description OGG Audio format
|
||||
|
||||
#pragma MIME audio/ogg
|
||||
|
||||
#include <std/core.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
bitfield HeaderType {
|
||||
Continuation : 1;
|
||||
BeginOfStream : 1;
|
||||
EndOfStream : 1;
|
||||
};
|
||||
|
||||
struct SegmentData {
|
||||
u8 data[parent.segmentTable[std::core::array_index()]];
|
||||
};
|
||||
|
||||
struct Ogg {
|
||||
char capturePattern[4];
|
||||
u8 version;
|
||||
HeaderType headerType;
|
||||
u64 granulePosition;
|
||||
u32 bitstreamSerialNumber;
|
||||
u32 pageSequenceNumber;
|
||||
u32 checksum;
|
||||
u8 pageSegments;
|
||||
u8 segmentTable[pageSegments];
|
||||
SegmentData data[pageSegments];
|
||||
};
|
||||
|
||||
Ogg ogg[while(!std::mem::eof())] @ 0x00;
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description pcap header and packets
|
||||
|
||||
#include <std/mem.pat>
|
||||
#pragma MIME application/vnd.tcpdump.pcap
|
||||
|
||||
|
||||
@@ -1,52 +1,55 @@
|
||||
#pragma MIME application/x-pcx
|
||||
|
||||
#include <std/io.pat>
|
||||
|
||||
enum Encoding : u8 {
|
||||
NoEncoding = 0x00,
|
||||
RunLengthEncoding = 0x01
|
||||
};
|
||||
|
||||
enum PaletteType : u16 {
|
||||
MonochromeOrColorInformation = 0x01,
|
||||
GrayscaleInformation = 0x02
|
||||
};
|
||||
|
||||
enum Version : u8 {
|
||||
V2_5 = 0x00,
|
||||
V2_8WithPalette = 0x02,
|
||||
V2_8_WithoutPalette = 0x03,
|
||||
PaintbrushForWindows = 0x04,
|
||||
V3_0 = 0x05
|
||||
};
|
||||
|
||||
struct Header {
|
||||
u8 magic;
|
||||
Version version;
|
||||
Encoding encoding;
|
||||
u8 bitsPerPixel;
|
||||
u16 xMin, yMin;
|
||||
u16 xMax, yMax;
|
||||
u16 hdpi, vdpi;
|
||||
};
|
||||
|
||||
struct RGB8 {
|
||||
u8 r, g, b;
|
||||
} [[sealed, color(std::format("{:02X}{:02X}{:02X}", this.r, this.g, this.b))]];
|
||||
|
||||
struct Palette {
|
||||
RGB8 color[16];
|
||||
};
|
||||
|
||||
struct PCX {
|
||||
Header header;
|
||||
Palette palette;
|
||||
padding[1];
|
||||
u8 numPlanes;
|
||||
u16 bytesPerLine;
|
||||
PaletteType paletteType;
|
||||
u16 hres, vres;
|
||||
padding[54];
|
||||
};
|
||||
|
||||
#pragma author WerWolv
|
||||
#pragma description PCX Image format
|
||||
|
||||
#pragma MIME application/x-pcx
|
||||
|
||||
#include <std/io.pat>
|
||||
|
||||
enum Encoding : u8 {
|
||||
NoEncoding = 0x00,
|
||||
RunLengthEncoding = 0x01
|
||||
};
|
||||
|
||||
enum PaletteType : u16 {
|
||||
MonochromeOrColorInformation = 0x01,
|
||||
GrayscaleInformation = 0x02
|
||||
};
|
||||
|
||||
enum Version : u8 {
|
||||
V2_5 = 0x00,
|
||||
V2_8WithPalette = 0x02,
|
||||
V2_8_WithoutPalette = 0x03,
|
||||
PaintbrushForWindows = 0x04,
|
||||
V3_0 = 0x05
|
||||
};
|
||||
|
||||
struct Header {
|
||||
u8 magic;
|
||||
Version version;
|
||||
Encoding encoding;
|
||||
u8 bitsPerPixel;
|
||||
u16 xMin, yMin;
|
||||
u16 xMax, yMax;
|
||||
u16 hdpi, vdpi;
|
||||
};
|
||||
|
||||
struct RGB8 {
|
||||
u8 r, g, b;
|
||||
} [[sealed, color(std::format("{:02X}{:02X}{:02X}", this.r, this.g, this.b))]];
|
||||
|
||||
struct Palette {
|
||||
RGB8 color[16];
|
||||
};
|
||||
|
||||
struct PCX {
|
||||
Header header;
|
||||
Palette palette;
|
||||
padding[1];
|
||||
u8 numPlanes;
|
||||
u16 bytesPerLine;
|
||||
PaletteType paletteType;
|
||||
u16 hres, vres;
|
||||
padding[54];
|
||||
};
|
||||
|
||||
PCX pcx @ 0x00;
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description PE header, COFF header, Standard COFF fields and Windows Specific fields
|
||||
|
||||
#pragma MIME application/x-dosexec
|
||||
#pragma MIME application/x-msdownload
|
||||
|
||||
|
||||
@@ -1,38 +1,41 @@
|
||||
#include <type/magic.pat>
|
||||
#include <type/size.pat>
|
||||
|
||||
#include <std/core.pat>
|
||||
|
||||
struct FileEntry {
|
||||
u64 dataOffset;
|
||||
type::Size<u64> dataSize;
|
||||
u32 nameOffset;
|
||||
padding[4];
|
||||
};
|
||||
|
||||
struct String {
|
||||
char value[];
|
||||
};
|
||||
|
||||
struct Header {
|
||||
type::Magic<"PFS0"> magic;
|
||||
u32 numFiles;
|
||||
type::Size<u32> stringTableSize;
|
||||
padding[4];
|
||||
|
||||
FileEntry fileEntryTable[numFiles];
|
||||
String strings[numFiles];
|
||||
};
|
||||
|
||||
struct File {
|
||||
char name[] @ addressof(parent.header.strings) + parent.header.fileEntryTable[std::core::array_index()].nameOffset;
|
||||
u8 data[parent.header.fileEntryTable[std::core::array_index()].dataSize] @ parent.header.fileEntryTable[std::core::array_index()].dataOffset [[sealed]];
|
||||
};
|
||||
|
||||
struct PFS0 {
|
||||
Header header;
|
||||
|
||||
File files[header.numFiles];
|
||||
};
|
||||
|
||||
#pragma author WerWolv
|
||||
#pragma description Nintendo Switch PFS0 archive (NSP files)
|
||||
|
||||
#include <type/magic.pat>
|
||||
#include <type/size.pat>
|
||||
|
||||
#include <std/core.pat>
|
||||
|
||||
struct FileEntry {
|
||||
u64 dataOffset;
|
||||
type::Size<u64> dataSize;
|
||||
u32 nameOffset;
|
||||
padding[4];
|
||||
};
|
||||
|
||||
struct String {
|
||||
char value[];
|
||||
};
|
||||
|
||||
struct Header {
|
||||
type::Magic<"PFS0"> magic;
|
||||
u32 numFiles;
|
||||
type::Size<u32> stringTableSize;
|
||||
padding[4];
|
||||
|
||||
FileEntry fileEntryTable[numFiles];
|
||||
String strings[numFiles];
|
||||
};
|
||||
|
||||
struct File {
|
||||
char name[] @ addressof(parent.header.strings) + parent.header.fileEntryTable[std::core::array_index()].nameOffset;
|
||||
u8 data[parent.header.fileEntryTable[std::core::array_index()].dataSize] @ parent.header.fileEntryTable[std::core::array_index()].dataOffset [[sealed]];
|
||||
};
|
||||
|
||||
struct PFS0 {
|
||||
Header header;
|
||||
|
||||
File files[header.numFiles];
|
||||
};
|
||||
|
||||
PFS0 pfs0 @ 0x00;
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description PIF Image Format
|
||||
|
||||
/* PIF - Portable Image Format
|
||||
*
|
||||
* Basic decoder for the PIF file structure
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description PNG image files
|
||||
|
||||
#pragma MIME image/png
|
||||
#pragma endian big
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Nintendo Switch PRODINFO
|
||||
|
||||
enum Model : u16 {
|
||||
NX = 1
|
||||
};
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Google Protobuf encoding
|
||||
|
||||
#include <std/core.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description Python bytecode files
|
||||
|
||||
#include <type/time.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description PyInstaller binray files
|
||||
|
||||
#pragma endian big
|
||||
|
||||
#include <std/mem.pat>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description Qubicle voxel scene project file
|
||||
|
||||
// Qubicle QBCL format
|
||||
|
||||
struct String {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description QOI image files
|
||||
|
||||
#pragma MIME image/qoi
|
||||
#pragma endian big
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description SE Linux modules
|
||||
|
||||
#include <std/sys.pat>
|
||||
#pragma pattern_limit 13107200
|
||||
#pragma endian little
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description SE Linux package
|
||||
|
||||
// SE Linux Policy Package
|
||||
// Extension: PP
|
||||
// https://github.com/SELinuxProject/selinux/blob/master/libsepol/src/module.c
|
||||
|
||||
@@ -1,115 +1,118 @@
|
||||
// Based on https://github.com/mietek/theunarchiver/wiki/StuffIt5Format and https://github.com/ParksProjets/Maconv/blob/master/docs/stuffit/Stuffit_v5.md
|
||||
|
||||
#pragma endian big
|
||||
#pragma MIME application/x-stuffit
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/time.pat>
|
||||
|
||||
namespace v5 {
|
||||
|
||||
bitfield Flags1 {
|
||||
padding : 1;
|
||||
folder : 1;
|
||||
encrypted : 1;
|
||||
padding : 5;
|
||||
};
|
||||
|
||||
bitfield Flags2 {
|
||||
padding : 7;
|
||||
resource_fork : 1;
|
||||
padding : 8;
|
||||
};
|
||||
|
||||
using MacOSHFSPlusDate = u32 [[format("v5::format_macos_date")]];
|
||||
|
||||
fn format_macos_date(MacOSHFSPlusDate date) {
|
||||
return std::time::format(std::time::to_utc(date - 2082844800));
|
||||
};
|
||||
|
||||
struct Header {
|
||||
char magic[0x50];
|
||||
u32 unknown1;
|
||||
u32 archiveSize;
|
||||
u32 entriesOffset;
|
||||
u32 unknown2;
|
||||
};
|
||||
|
||||
struct EntryHeader {
|
||||
u32 magic;
|
||||
u8 version;
|
||||
u8 unknown1;
|
||||
u16 headerSize;
|
||||
u8 unknown2;
|
||||
Flags1 flags;
|
||||
MacOSHFSPlusDate creationDate, modificationDate;
|
||||
u32 prevEntryOffset, nextEntryOffset, parentEntryOffset;
|
||||
u16 nameSize;
|
||||
u16 headerChecksum;
|
||||
|
||||
u32 dataForkUncompressedLength, dataForkCompressedLength;
|
||||
u16 dataForkChecksum;
|
||||
u16 unknown3;
|
||||
};
|
||||
|
||||
enum CompressionMethod : u8 {
|
||||
None = 0x00, // No compression
|
||||
Rle90 = 0x01, // Run length encoding
|
||||
Compress = 0x02, // Compress LZW algorithm, 14 bit max code length, block mode
|
||||
StuffIt3 = 0x03, // Simple Huffman encoding for individual bytes
|
||||
StuffIt5 = 0x05, // LZAH
|
||||
StuffIt8 = 0x08, // Miller-Wegman
|
||||
StuffIt13 = 0x0D, // LZSS and Huffman
|
||||
Stuffit14 = 0x0E, // Unknown
|
||||
StuffItArsenic = 0x0F // BWT and arithmetic coding
|
||||
};
|
||||
|
||||
struct Entry {
|
||||
EntryHeader header;
|
||||
if (header.flags.folder) {
|
||||
u16 numFiles;
|
||||
|
||||
if (header.dataForkUncompressedLength)
|
||||
std::print("Folder entry {} is special!", std::core::array_index());
|
||||
} else {
|
||||
CompressionMethod compressionMethod;
|
||||
}
|
||||
|
||||
u8 passwordDataLength;
|
||||
u8 passwordInformation[passwordDataLength];
|
||||
char fileName[header.nameSize];
|
||||
u16 commentSize;
|
||||
u16 unknown2;
|
||||
char comment[commentSize];
|
||||
|
||||
if (!header.flags.folder) {
|
||||
Flags2 flags;
|
||||
u16 unknown3;
|
||||
char fileType[4];
|
||||
u32 fileCreator;
|
||||
u16 macOSFinderFlags;
|
||||
u32 unknown4;
|
||||
u32 unknown5;
|
||||
u8 unknown6[6];
|
||||
|
||||
if (header.version == 1)
|
||||
u32 unknown7;
|
||||
|
||||
u8 compressedData[header.dataForkCompressedLength] [[sealed]];
|
||||
|
||||
if (header.nextEntryOffset == 0x00)
|
||||
break;
|
||||
else
|
||||
$ = header.nextEntryOffset;
|
||||
}
|
||||
};
|
||||
|
||||
struct StuffIt {
|
||||
Header header;
|
||||
|
||||
Entry entries[while(true)] @ header.entriesOffset;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#pragma author WerWolv
|
||||
#pragma description StuffIt V5 archive
|
||||
|
||||
// Based on https://github.com/mietek/theunarchiver/wiki/StuffIt5Format and https://github.com/ParksProjets/Maconv/blob/master/docs/stuffit/Stuffit_v5.md
|
||||
|
||||
#pragma endian big
|
||||
#pragma MIME application/x-stuffit
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/time.pat>
|
||||
|
||||
namespace v5 {
|
||||
|
||||
bitfield Flags1 {
|
||||
padding : 1;
|
||||
folder : 1;
|
||||
encrypted : 1;
|
||||
padding : 5;
|
||||
};
|
||||
|
||||
bitfield Flags2 {
|
||||
padding : 7;
|
||||
resource_fork : 1;
|
||||
padding : 8;
|
||||
};
|
||||
|
||||
using MacOSHFSPlusDate = u32 [[format("v5::format_macos_date")]];
|
||||
|
||||
fn format_macos_date(MacOSHFSPlusDate date) {
|
||||
return std::time::format(std::time::to_utc(date - 2082844800));
|
||||
};
|
||||
|
||||
struct Header {
|
||||
char magic[0x50];
|
||||
u32 unknown1;
|
||||
u32 archiveSize;
|
||||
u32 entriesOffset;
|
||||
u32 unknown2;
|
||||
};
|
||||
|
||||
struct EntryHeader {
|
||||
u32 magic;
|
||||
u8 version;
|
||||
u8 unknown1;
|
||||
u16 headerSize;
|
||||
u8 unknown2;
|
||||
Flags1 flags;
|
||||
MacOSHFSPlusDate creationDate, modificationDate;
|
||||
u32 prevEntryOffset, nextEntryOffset, parentEntryOffset;
|
||||
u16 nameSize;
|
||||
u16 headerChecksum;
|
||||
|
||||
u32 dataForkUncompressedLength, dataForkCompressedLength;
|
||||
u16 dataForkChecksum;
|
||||
u16 unknown3;
|
||||
};
|
||||
|
||||
enum CompressionMethod : u8 {
|
||||
None = 0x00, // No compression
|
||||
Rle90 = 0x01, // Run length encoding
|
||||
Compress = 0x02, // Compress LZW algorithm, 14 bit max code length, block mode
|
||||
StuffIt3 = 0x03, // Simple Huffman encoding for individual bytes
|
||||
StuffIt5 = 0x05, // LZAH
|
||||
StuffIt8 = 0x08, // Miller-Wegman
|
||||
StuffIt13 = 0x0D, // LZSS and Huffman
|
||||
Stuffit14 = 0x0E, // Unknown
|
||||
StuffItArsenic = 0x0F // BWT and arithmetic coding
|
||||
};
|
||||
|
||||
struct Entry {
|
||||
EntryHeader header;
|
||||
if (header.flags.folder) {
|
||||
u16 numFiles;
|
||||
|
||||
if (header.dataForkUncompressedLength)
|
||||
std::print("Folder entry {} is special!", std::core::array_index());
|
||||
} else {
|
||||
CompressionMethod compressionMethod;
|
||||
}
|
||||
|
||||
u8 passwordDataLength;
|
||||
u8 passwordInformation[passwordDataLength];
|
||||
char fileName[header.nameSize];
|
||||
u16 commentSize;
|
||||
u16 unknown2;
|
||||
char comment[commentSize];
|
||||
|
||||
if (!header.flags.folder) {
|
||||
Flags2 flags;
|
||||
u16 unknown3;
|
||||
char fileType[4];
|
||||
u32 fileCreator;
|
||||
u16 macOSFinderFlags;
|
||||
u32 unknown4;
|
||||
u32 unknown5;
|
||||
u8 unknown6[6];
|
||||
|
||||
if (header.version == 1)
|
||||
u32 unknown7;
|
||||
|
||||
u8 compressedData[header.dataForkCompressedLength] [[sealed]];
|
||||
|
||||
if (header.nextEntryOffset == 0x00)
|
||||
break;
|
||||
else
|
||||
$ = header.nextEntryOffset;
|
||||
}
|
||||
};
|
||||
|
||||
struct StuffIt {
|
||||
Header header;
|
||||
|
||||
Entry entries[while(true)] @ header.entriesOffset;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
v5::StuffIt stuffIt @ 0x00;
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description SPIR-V header and instructions
|
||||
|
||||
#include <std/mem.pat>
|
||||
|
||||
enum GeneratorID : u16 {
|
||||
|
||||
@@ -1,51 +1,54 @@
|
||||
#pragma MIME model/stl
|
||||
#pragma MIME model/x.stl-binary
|
||||
#pragma MIME model/x.stl-ascii
|
||||
#pragma MIME application/sla
|
||||
|
||||
#include <std/sys.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <std/core.pat>
|
||||
|
||||
struct Vector3f {
|
||||
float x, y, z;
|
||||
} [[static, format("format_vector3f")]];
|
||||
|
||||
fn format_vector3f(Vector3f vec) {
|
||||
return std::format("[ {}, {}, {} ]", vec.x, vec.y, vec.z);
|
||||
};
|
||||
|
||||
struct Triangle {
|
||||
Vector3f normal;
|
||||
Vector3f points[3];
|
||||
u16 flags;
|
||||
} [[static]];
|
||||
|
||||
struct BinarySTLHeader {
|
||||
char caption[while($[$] != 0x00 && $ - addressof(this) < 80)];
|
||||
padding[80 - sizeof(caption)];
|
||||
u32 triangleCount;
|
||||
};
|
||||
|
||||
struct STL {
|
||||
if (std::mem::read_string(0, 6) == "solid ")
|
||||
std::warning("ASCII STL file!");
|
||||
else {
|
||||
BinarySTLHeader header;
|
||||
Triangle triangles[header.triangleCount];
|
||||
}
|
||||
};
|
||||
|
||||
STL stl @ 0x00;
|
||||
|
||||
/* Visualize the 3D Model */
|
||||
|
||||
struct Vertex {
|
||||
Vector3f points[3] @ addressof(stl.triangles[std::core::array_index()].points);
|
||||
};
|
||||
|
||||
struct Model {
|
||||
Vertex vertices[stl.header.triangleCount];
|
||||
} [[highlight_hidden, sealed, hex::visualize("3d", vertices, null)]];
|
||||
|
||||
Model model @ 0x00;
|
||||
#pragma author WerWolv
|
||||
#pragma description STL 3D Model format
|
||||
|
||||
#pragma MIME model/stl
|
||||
#pragma MIME model/x.stl-binary
|
||||
#pragma MIME model/x.stl-ascii
|
||||
#pragma MIME application/sla
|
||||
|
||||
#include <std/sys.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <std/core.pat>
|
||||
|
||||
struct Vector3f {
|
||||
float x, y, z;
|
||||
} [[static, format("format_vector3f")]];
|
||||
|
||||
fn format_vector3f(Vector3f vec) {
|
||||
return std::format("[ {}, {}, {} ]", vec.x, vec.y, vec.z);
|
||||
};
|
||||
|
||||
struct Triangle {
|
||||
Vector3f normal;
|
||||
Vector3f points[3];
|
||||
u16 flags;
|
||||
} [[static]];
|
||||
|
||||
struct BinarySTLHeader {
|
||||
char caption[while($[$] != 0x00 && $ - addressof(this) < 80)];
|
||||
padding[80 - sizeof(caption)];
|
||||
u32 triangleCount;
|
||||
};
|
||||
|
||||
struct STL {
|
||||
if (std::mem::read_string(0, 6) == "solid ")
|
||||
std::warning("ASCII STL file!");
|
||||
else {
|
||||
BinarySTLHeader header;
|
||||
Triangle triangles[header.triangleCount];
|
||||
}
|
||||
};
|
||||
|
||||
STL stl @ 0x00;
|
||||
|
||||
/* Visualize the 3D Model */
|
||||
|
||||
struct Vertex {
|
||||
Vector3f points[3] @ addressof(stl.triangles[std::core::array_index()].points);
|
||||
};
|
||||
|
||||
struct Model {
|
||||
Vertex vertices[stl.header.triangleCount];
|
||||
} [[highlight_hidden, sealed, hex::visualize("3d", vertices, null)]];
|
||||
|
||||
Model model @ 0x00;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description Tar file format
|
||||
|
||||
#pragma MIME application/tar
|
||||
#pragma MIME application/x-tar
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description Truevision TGA/TARGA image
|
||||
|
||||
#pragma MIME image/tga
|
||||
#pragma endian little
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description Tag Image File Format
|
||||
|
||||
#pragma MIME image/tiff
|
||||
|
||||
#pragma eval_depth 100
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description Ubiquiti Firmware (update) image
|
||||
|
||||
#pragma endian big
|
||||
|
||||
#include <std/mem.pat>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description UEFI structs for parsing efivars
|
||||
|
||||
#pragma MIME data
|
||||
|
||||
#define WIN_CERT_TYPE_PKCS_SIGNED_DATA 0x0002
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description [USB Flashing Format](https://github.com/microsoft/uf2)
|
||||
|
||||
#include <std/sys.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma author WerWolv
|
||||
#pragma description Binary Value Data Format (.vdf) files
|
||||
|
||||
#pragma eval_depth 0x10000
|
||||
|
||||
#include <std/mem.pat>
|
||||
|
||||
@@ -1,193 +1,196 @@
|
||||
#include <std/io.pat>
|
||||
#include <std/ptr.pat>
|
||||
#include <std/core.pat>
|
||||
|
||||
#include <type/guid.pat>
|
||||
#include <type/size.pat>
|
||||
|
||||
struct FileTypeIdentifier {
|
||||
char signature[8];
|
||||
char16 creator[256];
|
||||
padding[0x1'0000 - sizeof(signature) - sizeof(creator)];
|
||||
};
|
||||
|
||||
struct DataSector {
|
||||
u32 sequenceHigh;
|
||||
u8 data[4084];
|
||||
u32 sequenceLow;
|
||||
} [[static]];
|
||||
|
||||
struct ZeroDescriptor {
|
||||
padding[4];
|
||||
u64 zeroLength;
|
||||
DataSector *dataSector : u64;
|
||||
u64 sequenceNumber;
|
||||
} [[static]];
|
||||
|
||||
struct DataDescriptor {
|
||||
u32 trailingBytes;
|
||||
u64 leadingBytes;
|
||||
DataSector *dataSector : u64;
|
||||
u64 sequenceNumber;
|
||||
} [[static]];
|
||||
|
||||
struct LogDescriptor {
|
||||
char signature[4];
|
||||
|
||||
if (signature == "zero")
|
||||
ZeroDescriptor descriptor [[inline]];
|
||||
else if (signature == "desc")
|
||||
DataDescriptor descriptor [[inline]];
|
||||
};
|
||||
|
||||
struct LogEntry {
|
||||
char signature[4];
|
||||
u32 checksum;
|
||||
type::Size32 entryLength;
|
||||
u32 tail;
|
||||
u64 sequenceNumber;
|
||||
u32 descriptorCount;
|
||||
padding[4];
|
||||
type::GUID logGuid;
|
||||
u64 flushedFileOffset;
|
||||
u64 lastFileOffset;
|
||||
} [[static]];
|
||||
|
||||
bitfield BAT {
|
||||
State : 3;
|
||||
padding : 17;
|
||||
FileOffsetMB : 44;
|
||||
} [[right_to_left]];
|
||||
|
||||
bitfield MetadataEntryFlags {
|
||||
IsUser : 1;
|
||||
IsVirtualDisk : 1;
|
||||
IsRequired : 1;
|
||||
padding : 29;
|
||||
};
|
||||
|
||||
bitfield FileParameterFlags {
|
||||
LeaveBlockAllocated : 1;
|
||||
HasParent : 1;
|
||||
padding : 30;
|
||||
};
|
||||
|
||||
struct MetadataFileParameters {
|
||||
type::Size32 blockSize;
|
||||
FileParameterFlags flags;
|
||||
};
|
||||
|
||||
struct MetadataVirtualDiskSize {
|
||||
type::Size64 virtualDiskSize;
|
||||
};
|
||||
|
||||
struct MetadataVirtualDiskID {
|
||||
type::GUID virtualDiskID;
|
||||
};
|
||||
|
||||
struct MetadataLogicalSectorSize {
|
||||
type::Size32 logicalSectorSize;
|
||||
};
|
||||
|
||||
struct MetadataPhysicalSectorSize {
|
||||
type::Size32 physicalSectorSize;
|
||||
};
|
||||
|
||||
struct ParentLocatorEntry {
|
||||
u32 keyOffset;
|
||||
u32 valueOffset;
|
||||
u16 keyLength;
|
||||
u16 valueLength;
|
||||
|
||||
char key[keyLength] @ addressof(parent) + keyOffset;
|
||||
char value[valueLength] @ addressof(parent) + valueOffset;
|
||||
};
|
||||
|
||||
struct MetadataParentLocator {
|
||||
type::GUID locatorType;
|
||||
padding[2];
|
||||
u16 keyValueCount;
|
||||
ParentLocatorEntry entries[keyValueCount];
|
||||
};
|
||||
|
||||
fn metadata_relative(u128 offset) {
|
||||
return addressof(parent.parent);
|
||||
};
|
||||
|
||||
struct MetadataTableEntry {
|
||||
type::GUID itemID;
|
||||
|
||||
if (std::core::formatted_value(itemID) == "{CAA16737-FA36-4D43-B3B6-33F0AA44E76B}")
|
||||
MetadataFileParameters *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{2FA54224-CD1B-4876-B211-5DBED83BF4B8}")
|
||||
MetadataVirtualDiskSize *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{BECA12AB-B2E6-4523-93EF-C309E000C746}")
|
||||
MetadataVirtualDiskID *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{8141BF1D-A96F-4709-BA47-F233A8FAAB5F}")
|
||||
MetadataLogicalSectorSize *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{CDA348C7-445D-4471-9CC9-E9885251C556}")
|
||||
MetadataPhysicalSectorSize *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{A8D35F2D-B30B-454D-ABF7-D3D84834AB0C}")
|
||||
MetadataParentLocator *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else
|
||||
u32 dataOffset;
|
||||
|
||||
type::Size32 length;
|
||||
MetadataEntryFlags flags;
|
||||
padding[4];
|
||||
};
|
||||
|
||||
struct MetadataRegion {
|
||||
char signature[8];
|
||||
padding[2];
|
||||
u16 entryCount;
|
||||
padding[20];
|
||||
MetadataTableEntry entries[entryCount];
|
||||
};
|
||||
|
||||
struct RegionTableEntry {
|
||||
type::GUID guid;
|
||||
|
||||
if (std::core::formatted_value(guid) == "{2DC27766-F623-4200-9D64-115E9BFD4A08}")
|
||||
BAT *bat : u64;
|
||||
else if (std::core::formatted_value(guid) == "{8B7CA206-4790-4B9A-B8FE-575F050F886E}")
|
||||
MetadataRegion *metadata : u64;
|
||||
else
|
||||
u64 fileOffset;
|
||||
|
||||
type::Size32 length;
|
||||
u32 required;
|
||||
};
|
||||
|
||||
struct RegionTable {
|
||||
char signature[4];
|
||||
u32 checksum;
|
||||
u32 entryCount;
|
||||
padding[4];
|
||||
|
||||
RegionTableEntry entries[entryCount];
|
||||
};
|
||||
|
||||
struct Header {
|
||||
char signature[4];
|
||||
u32 checksum;
|
||||
u64 sequenceNumber;
|
||||
type::GUID fileWriteGuid, dataWriteGuid, logGuid;
|
||||
u16 logVersion;
|
||||
u16 version;
|
||||
type::Size32 logLength;
|
||||
LogEntry *log : u64;
|
||||
padding[4016];
|
||||
};
|
||||
|
||||
struct VHDX {
|
||||
FileTypeIdentifier fileTypeIdentifier;
|
||||
|
||||
Header header @ 0x1'0000;
|
||||
Header headerBackup @ 0x2'0000;
|
||||
|
||||
RegionTable regionTable @ 0x3'0000;
|
||||
RegionTable regionTableBackup @ 0x4'0000;
|
||||
};
|
||||
|
||||
#pragma author WerWolv
|
||||
#pragma description Microsoft Hyper-V Virtual Hard Disk format
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/ptr.pat>
|
||||
#include <std/core.pat>
|
||||
|
||||
#include <type/guid.pat>
|
||||
#include <type/size.pat>
|
||||
|
||||
struct FileTypeIdentifier {
|
||||
char signature[8];
|
||||
char16 creator[256];
|
||||
padding[0x1'0000 - sizeof(signature) - sizeof(creator)];
|
||||
};
|
||||
|
||||
struct DataSector {
|
||||
u32 sequenceHigh;
|
||||
u8 data[4084];
|
||||
u32 sequenceLow;
|
||||
} [[static]];
|
||||
|
||||
struct ZeroDescriptor {
|
||||
padding[4];
|
||||
u64 zeroLength;
|
||||
DataSector *dataSector : u64;
|
||||
u64 sequenceNumber;
|
||||
} [[static]];
|
||||
|
||||
struct DataDescriptor {
|
||||
u32 trailingBytes;
|
||||
u64 leadingBytes;
|
||||
DataSector *dataSector : u64;
|
||||
u64 sequenceNumber;
|
||||
} [[static]];
|
||||
|
||||
struct LogDescriptor {
|
||||
char signature[4];
|
||||
|
||||
if (signature == "zero")
|
||||
ZeroDescriptor descriptor [[inline]];
|
||||
else if (signature == "desc")
|
||||
DataDescriptor descriptor [[inline]];
|
||||
};
|
||||
|
||||
struct LogEntry {
|
||||
char signature[4];
|
||||
u32 checksum;
|
||||
type::Size32 entryLength;
|
||||
u32 tail;
|
||||
u64 sequenceNumber;
|
||||
u32 descriptorCount;
|
||||
padding[4];
|
||||
type::GUID logGuid;
|
||||
u64 flushedFileOffset;
|
||||
u64 lastFileOffset;
|
||||
} [[static]];
|
||||
|
||||
bitfield BAT {
|
||||
State : 3;
|
||||
padding : 17;
|
||||
FileOffsetMB : 44;
|
||||
} [[right_to_left]];
|
||||
|
||||
bitfield MetadataEntryFlags {
|
||||
IsUser : 1;
|
||||
IsVirtualDisk : 1;
|
||||
IsRequired : 1;
|
||||
padding : 29;
|
||||
};
|
||||
|
||||
bitfield FileParameterFlags {
|
||||
LeaveBlockAllocated : 1;
|
||||
HasParent : 1;
|
||||
padding : 30;
|
||||
};
|
||||
|
||||
struct MetadataFileParameters {
|
||||
type::Size32 blockSize;
|
||||
FileParameterFlags flags;
|
||||
};
|
||||
|
||||
struct MetadataVirtualDiskSize {
|
||||
type::Size64 virtualDiskSize;
|
||||
};
|
||||
|
||||
struct MetadataVirtualDiskID {
|
||||
type::GUID virtualDiskID;
|
||||
};
|
||||
|
||||
struct MetadataLogicalSectorSize {
|
||||
type::Size32 logicalSectorSize;
|
||||
};
|
||||
|
||||
struct MetadataPhysicalSectorSize {
|
||||
type::Size32 physicalSectorSize;
|
||||
};
|
||||
|
||||
struct ParentLocatorEntry {
|
||||
u32 keyOffset;
|
||||
u32 valueOffset;
|
||||
u16 keyLength;
|
||||
u16 valueLength;
|
||||
|
||||
char key[keyLength] @ addressof(parent) + keyOffset;
|
||||
char value[valueLength] @ addressof(parent) + valueOffset;
|
||||
};
|
||||
|
||||
struct MetadataParentLocator {
|
||||
type::GUID locatorType;
|
||||
padding[2];
|
||||
u16 keyValueCount;
|
||||
ParentLocatorEntry entries[keyValueCount];
|
||||
};
|
||||
|
||||
fn metadata_relative(u128 offset) {
|
||||
return addressof(parent.parent);
|
||||
};
|
||||
|
||||
struct MetadataTableEntry {
|
||||
type::GUID itemID;
|
||||
|
||||
if (std::core::formatted_value(itemID) == "{CAA16737-FA36-4D43-B3B6-33F0AA44E76B}")
|
||||
MetadataFileParameters *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{2FA54224-CD1B-4876-B211-5DBED83BF4B8}")
|
||||
MetadataVirtualDiskSize *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{BECA12AB-B2E6-4523-93EF-C309E000C746}")
|
||||
MetadataVirtualDiskID *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{8141BF1D-A96F-4709-BA47-F233A8FAAB5F}")
|
||||
MetadataLogicalSectorSize *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{CDA348C7-445D-4471-9CC9-E9885251C556}")
|
||||
MetadataPhysicalSectorSize *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{A8D35F2D-B30B-454D-ABF7-D3D84834AB0C}")
|
||||
MetadataParentLocator *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else
|
||||
u32 dataOffset;
|
||||
|
||||
type::Size32 length;
|
||||
MetadataEntryFlags flags;
|
||||
padding[4];
|
||||
};
|
||||
|
||||
struct MetadataRegion {
|
||||
char signature[8];
|
||||
padding[2];
|
||||
u16 entryCount;
|
||||
padding[20];
|
||||
MetadataTableEntry entries[entryCount];
|
||||
};
|
||||
|
||||
struct RegionTableEntry {
|
||||
type::GUID guid;
|
||||
|
||||
if (std::core::formatted_value(guid) == "{2DC27766-F623-4200-9D64-115E9BFD4A08}")
|
||||
BAT *bat : u64;
|
||||
else if (std::core::formatted_value(guid) == "{8B7CA206-4790-4B9A-B8FE-575F050F886E}")
|
||||
MetadataRegion *metadata : u64;
|
||||
else
|
||||
u64 fileOffset;
|
||||
|
||||
type::Size32 length;
|
||||
u32 required;
|
||||
};
|
||||
|
||||
struct RegionTable {
|
||||
char signature[4];
|
||||
u32 checksum;
|
||||
u32 entryCount;
|
||||
padding[4];
|
||||
|
||||
RegionTableEntry entries[entryCount];
|
||||
};
|
||||
|
||||
struct Header {
|
||||
char signature[4];
|
||||
u32 checksum;
|
||||
u64 sequenceNumber;
|
||||
type::GUID fileWriteGuid, dataWriteGuid, logGuid;
|
||||
u16 logVersion;
|
||||
u16 version;
|
||||
type::Size32 logLength;
|
||||
LogEntry *log : u64;
|
||||
padding[4016];
|
||||
};
|
||||
|
||||
struct VHDX {
|
||||
FileTypeIdentifier fileTypeIdentifier;
|
||||
|
||||
Header header @ 0x1'0000;
|
||||
Header headerBackup @ 0x2'0000;
|
||||
|
||||
RegionTable regionTable @ 0x3'0000;
|
||||
RegionTable regionTableBackup @ 0x4'0000;
|
||||
};
|
||||
|
||||
VHDX vhdx @ 0x00;
|
||||
@@ -1,24 +1,27 @@
|
||||
#include <type/magic.pat>
|
||||
#include <type/size.pat>
|
||||
|
||||
enum WADType : char {
|
||||
Internal = 'I',
|
||||
Patch = 'P'
|
||||
};
|
||||
|
||||
struct FileLump {
|
||||
u32 filePos;
|
||||
type::Size<u32> size;
|
||||
char name[8];
|
||||
|
||||
u8 data[size] @ filePos [[sealed]];
|
||||
};
|
||||
|
||||
struct WAD {
|
||||
WADType type;
|
||||
type::Magic<"WAD"> identification;
|
||||
u32 numLumps;
|
||||
FileLump *infoTable[numLumps] : u32;
|
||||
};
|
||||
|
||||
#pragma author WerWolv
|
||||
#pragma description DOOM WAD Archive
|
||||
|
||||
#include <type/magic.pat>
|
||||
#include <type/size.pat>
|
||||
|
||||
enum WADType : char {
|
||||
Internal = 'I',
|
||||
Patch = 'P'
|
||||
};
|
||||
|
||||
struct FileLump {
|
||||
u32 filePos;
|
||||
type::Size<u32> size;
|
||||
char name[8];
|
||||
|
||||
u8 data[size] @ filePos [[sealed]];
|
||||
};
|
||||
|
||||
struct WAD {
|
||||
WADType type;
|
||||
type::Magic<"WAD"> identification;
|
||||
u32 numLumps;
|
||||
FileLump *infoTable[numLumps] : u32;
|
||||
};
|
||||
|
||||
WAD wad @ 0x00;
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description RIFF header, WAVE header, PCM header
|
||||
|
||||
#pragma MIME audio/x-wav
|
||||
#pragma MIME audio/wav
|
||||
|
||||
|
||||
@@ -1,403 +1,406 @@
|
||||
#pragma MIME audio/x-xbox-executable
|
||||
|
||||
#include <type/magic.pat>
|
||||
#include <type/size.pat>
|
||||
#include <type/time.pat>
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
|
||||
bitfield AllowedMedia {
|
||||
HardDisk : 1;
|
||||
DVD_X2 : 1;
|
||||
DVD_CD : 1;
|
||||
CD : 1;
|
||||
DVD_5_RO : 1;
|
||||
DVD_9_RO : 1;
|
||||
DVD_5_RW : 1;
|
||||
DVD_9_RW : 1;
|
||||
Dongle : 1;
|
||||
MediaBoard : 1;
|
||||
padding : 20;
|
||||
NonSecureHardDisk : 1;
|
||||
NonSecureMode : 1;
|
||||
};
|
||||
|
||||
bitfield GameRegion {
|
||||
NorthAmerica : 1;
|
||||
Japan : 1;
|
||||
RestOfTheWorld : 1;
|
||||
padding : 28;
|
||||
Manufacturing : 1;
|
||||
};
|
||||
|
||||
struct Certificate {
|
||||
type::Size<u32> certificateSize;
|
||||
type::time32_t timeDate;
|
||||
u32 titleId;
|
||||
char16 titleName[0x50 / 2];
|
||||
u32 alternateTitleIds[16];
|
||||
AllowedMedia allowedMedia;
|
||||
GameRegion gameRegion;
|
||||
u32 gameRatings;
|
||||
u128 lanKey;
|
||||
u128 signatureKey;
|
||||
u128 alternateSignatureKeys[16];
|
||||
};
|
||||
|
||||
bitfield InitializationFlags {
|
||||
MountUtilityDrive : 1;
|
||||
FormatUtilityDrive : 1;
|
||||
Limit64Megabytes : 1;
|
||||
DontSetuptHarddisk : 1;
|
||||
padding : 28;
|
||||
};
|
||||
|
||||
union EntryPoint {
|
||||
u32 betaAddress [[format("format_beta_entrypoint")]];
|
||||
u32 debugAddress [[format("format_debug_entrypoint")]];
|
||||
u32 retailAddress [[format("format_retail_entrypoint")]];
|
||||
|
||||
if ((betaAddress ^ 0xE682F45B) - parent.baseAddress < std::mem::size())
|
||||
u8 beta @ (betaAddress ^ 0xE682F45B) - parent.baseAddress;;
|
||||
if ((debugAddress ^ 0x94859D4B) - parent.baseAddress < std::mem::size())
|
||||
u8 debug @ (debugAddress ^ 0x94859D4B) - parent.baseAddress;;
|
||||
if ((retailAddress ^ 0xA8FC57AB) - parent.baseAddress < std::mem::size())
|
||||
u8 retail @ (retailAddress ^ 0xA8FC57AB) - parent.baseAddress;
|
||||
};
|
||||
|
||||
fn format_beta_entrypoint(u32 value) {
|
||||
return std::format("0x{:08X}", value ^ 0xE682F45B);
|
||||
};
|
||||
|
||||
fn format_debug_entrypoint(u32 value) {
|
||||
return std::format("0x{:08X}", value ^ 0x94859D4B);
|
||||
};
|
||||
|
||||
fn format_retail_entrypoint(u32 value) {
|
||||
return std::format("0x{:08X}", value ^ 0xA8FC57AB);
|
||||
};
|
||||
|
||||
#define KERNEL_BASE 0x8000'0000
|
||||
enum KernelImageFunction : u32 {
|
||||
AvGetSavedDataAddress = 1 + KERNEL_BASE,
|
||||
AvSendTVEncoderOption = 2 + KERNEL_BASE,
|
||||
AvSetDisplayMode = 3 + KERNEL_BASE,
|
||||
AvSetSavedDataAddress = 4 + KERNEL_BASE,
|
||||
DbgBreakPoint = 5 + KERNEL_BASE,
|
||||
DbgBreakPointWithStatus = 6 + KERNEL_BASE,
|
||||
DbgLoadImageSymbols = 7 + KERNEL_BASE,
|
||||
DbgPrint = 8 + KERNEL_BASE,
|
||||
HalReadSMCTrayState = 9 + KERNEL_BASE,
|
||||
DbgPrompt = 10 + KERNEL_BASE,
|
||||
DbgUnLoadImageSymbols = 11 + KERNEL_BASE,
|
||||
ExAcquireReadWriteLockExclusive = 12 + KERNEL_BASE,
|
||||
ExAcquireReadWriteLockShared = 13 + KERNEL_BASE,
|
||||
ExAllocatePool = 14 + KERNEL_BASE,
|
||||
ExAllocatePoolWithTag = 15 + KERNEL_BASE,
|
||||
ExEventObjectType = 16 + KERNEL_BASE,
|
||||
ExFreePool = 17 + KERNEL_BASE,
|
||||
ExInitializeReadWriteLock = 18 + KERNEL_BASE,
|
||||
ExInterlockedAddLargeInteger = 19 + KERNEL_BASE,
|
||||
ExInterlockedAddLargeStatistic = 20 + KERNEL_BASE,
|
||||
ExInterlockedCompareExchange64 = 21 + KERNEL_BASE,
|
||||
ExMutantObjectType = 22 + KERNEL_BASE,
|
||||
ExQueryPoolBlockSize = 23 + KERNEL_BASE,
|
||||
ExQueryNonVolatileSetting = 24 + KERNEL_BASE,
|
||||
ExReadWriteRefurbInfo = 25 + KERNEL_BASE,
|
||||
ExRaiseException = 26 + KERNEL_BASE,
|
||||
ExRaiseStatus = 27 + KERNEL_BASE,
|
||||
ExReleaseReadWriteLock = 28 + KERNEL_BASE,
|
||||
ExSaveNonVolatileSetting = 29 + KERNEL_BASE,
|
||||
ExSemaphoreObjectType = 30 + KERNEL_BASE,
|
||||
ExTimerObjectType = 31 + KERNEL_BASE,
|
||||
ExfInterlockedInsertHeadList = 32 + KERNEL_BASE,
|
||||
ExfInterlockedInsertTailList = 33 + KERNEL_BASE,
|
||||
ExfInterlockedRemoveHeadList = 34 + KERNEL_BASE,
|
||||
FscGetCacheSize = 35 + KERNEL_BASE,
|
||||
FscInvalidateIdleBlocks = 36 + KERNEL_BASE,
|
||||
FscSetCacheSize = 37 + KERNEL_BASE,
|
||||
HalClearSoftwareInterrupt = 38 + KERNEL_BASE,
|
||||
HalDisableSystemInterrupt = 39 + KERNEL_BASE,
|
||||
HalDiskCachePartitionCount = 40 + KERNEL_BASE,
|
||||
HalDiskModelNumber = 41 + KERNEL_BASE,
|
||||
HalDiskSerialNumber = 42 + KERNEL_BASE,
|
||||
HalEnableSystemInterrupt = 43 + KERNEL_BASE,
|
||||
HalGetInterruptVector = 44 + KERNEL_BASE,
|
||||
HalReadSMBusValue = 45 + KERNEL_BASE,
|
||||
HalReadWritePCISpace = 46 + KERNEL_BASE,
|
||||
HalRegisterShutdownNotification = 47 + KERNEL_BASE,
|
||||
HalRequestSoftwareInterrupt = 48 + KERNEL_BASE,
|
||||
HalReturnToFirmware = 49 + KERNEL_BASE,
|
||||
HalWriteSMBusValue = 50 + KERNEL_BASE,
|
||||
InterlockedCompareExchange = 51 + KERNEL_BASE,
|
||||
InterlockedDecrement = 52 + KERNEL_BASE,
|
||||
InterlockedIncrement = 53 + KERNEL_BASE,
|
||||
InterlockedExchange = 54 + KERNEL_BASE,
|
||||
InterlockedExchangeAdd = 55 + KERNEL_BASE,
|
||||
InterlockedFlushSList = 56 + KERNEL_BASE,
|
||||
InterlockedPopEntrySList = 57 + KERNEL_BASE,
|
||||
InterlockedPushEntrySList = 58 + KERNEL_BASE,
|
||||
IoAllocateIrp = 59 + KERNEL_BASE,
|
||||
IoBuildAsynchronousFsdRequest = 60 + KERNEL_BASE,
|
||||
IoBuildDeviceIoControlRequest = 61 + KERNEL_BASE,
|
||||
IoBuildSynchronousFsdRequest = 62 + KERNEL_BASE,
|
||||
IoCheckShareAccess = 63 + KERNEL_BASE,
|
||||
IoCompletionObjectType = 64 + KERNEL_BASE,
|
||||
IoCreateDevice = 65 + KERNEL_BASE,
|
||||
IoCreateFile = 66 + KERNEL_BASE,
|
||||
IoCreateSymbolicLink = 67 + KERNEL_BASE,
|
||||
IoDeleteDevice = 68 + KERNEL_BASE,
|
||||
IoDeleteSymbolicLink = 69 + KERNEL_BASE,
|
||||
IoDeviceObjectType = 70 + KERNEL_BASE,
|
||||
IoFileObjectType = 71 + KERNEL_BASE,
|
||||
IoFreeIrp = 72 + KERNEL_BASE,
|
||||
IoInitializeIrp = 73 + KERNEL_BASE,
|
||||
IoInvalidDeviceRequest = 74 + KERNEL_BASE,
|
||||
IoQueryFileInformation = 75 + KERNEL_BASE,
|
||||
IoQueryVolumeInformation = 76 + KERNEL_BASE,
|
||||
IoQueueThreadIrp = 77 + KERNEL_BASE,
|
||||
IoRemoveShareAccess = 78 + KERNEL_BASE,
|
||||
IoSetIoCompletion = 79 + KERNEL_BASE,
|
||||
IoSetShareAccess = 80 + KERNEL_BASE,
|
||||
IoStartNextPacket = 81 + KERNEL_BASE,
|
||||
IoStartNextPacketByKey = 82 + KERNEL_BASE,
|
||||
IoStartPacket = 83 + KERNEL_BASE,
|
||||
IoSynchronousDeviceIoControlRequest = 84 + KERNEL_BASE,
|
||||
IoSynchronousFsdRequest = 85 + KERNEL_BASE,
|
||||
IofCallDriver = 86 + KERNEL_BASE,
|
||||
IofCompleteRequest = 87 + KERNEL_BASE,
|
||||
KdDebuggerEnabled = 88 + KERNEL_BASE,
|
||||
KdDebuggerNotPresent = 89 + KERNEL_BASE,
|
||||
IoDismountVolume = 90 + KERNEL_BASE,
|
||||
IoDismountVolumeByName = 91 + KERNEL_BASE,
|
||||
KeAlertResumeThread = 92 + KERNEL_BASE,
|
||||
KeAlertThread = 93 + KERNEL_BASE,
|
||||
KeBoostPriorityThread = 94 + KERNEL_BASE,
|
||||
KeBugCheck = 95 + KERNEL_BASE,
|
||||
KeBugCheckEx = 96 + KERNEL_BASE,
|
||||
KeCancelTimer = 97 + KERNEL_BASE,
|
||||
KeConnectInterrupt = 98 + KERNEL_BASE,
|
||||
KeDelayExecutionThread = 99 + KERNEL_BASE,
|
||||
KeDisconnectInterrupt = 100 + KERNEL_BASE,
|
||||
KeEnterCriticalRegion = 101 + KERNEL_BASE,
|
||||
MmGlobalData = 102 + KERNEL_BASE,
|
||||
KeGetCurrentIrql = 103 + KERNEL_BASE,
|
||||
KeGetCurrentThread = 104 + KERNEL_BASE,
|
||||
KeInitializeApc = 105 + KERNEL_BASE,
|
||||
KeInitializeDeviceQueue = 106 + KERNEL_BASE,
|
||||
KeInitializeDpc = 107 + KERNEL_BASE,
|
||||
KeInitializeEvent = 108 + KERNEL_BASE,
|
||||
KeInitializeInterrupt = 109 + KERNEL_BASE,
|
||||
KeInitializeMutant = 110 + KERNEL_BASE,
|
||||
KeInitializeQueue = 111 + KERNEL_BASE,
|
||||
KeInitializeSemaphore = 112 + KERNEL_BASE,
|
||||
KeInitializeTimerEx = 113 + KERNEL_BASE,
|
||||
KeInsertByKeyDeviceQueue = 114 + KERNEL_BASE,
|
||||
KeInsertDeviceQueue = 115 + KERNEL_BASE,
|
||||
KeInsertHeadQueue = 116 + KERNEL_BASE,
|
||||
KeInsertQueue = 117 + KERNEL_BASE,
|
||||
KeInsertQueueApc = 118 + KERNEL_BASE,
|
||||
KeInsertQueueDpc = 119 + KERNEL_BASE,
|
||||
KeInterruptTime = 120 + KERNEL_BASE,
|
||||
KeIsExecutingDpc = 121 + KERNEL_BASE,
|
||||
KeLeaveCriticalRegion = 122 + KERNEL_BASE,
|
||||
KePulseEvent = 123 + KERNEL_BASE,
|
||||
KeQueryBasePriorityThread = 124 + KERNEL_BASE,
|
||||
KeQueryInterruptTime = 125 + KERNEL_BASE,
|
||||
KeQueryPerformanceCounter = 126 + KERNEL_BASE,
|
||||
KeQueryPerformanceFrequency = 127 + KERNEL_BASE,
|
||||
KeQuerySystemTime = 128 + KERNEL_BASE,
|
||||
KeRaiseIrqlToDpcLevel = 129 + KERNEL_BASE,
|
||||
KeRaiseIrqlToSynchLevel = 130 + KERNEL_BASE,
|
||||
KeReleaseMutant = 131 + KERNEL_BASE,
|
||||
KeReleaseSemaphore = 132 + KERNEL_BASE,
|
||||
KeRemoveByKeyDeviceQueue = 133 + KERNEL_BASE,
|
||||
KeRemoveDeviceQueue = 134 + KERNEL_BASE,
|
||||
KeRemoveEntryDeviceQueue = 135 + KERNEL_BASE,
|
||||
KeRemoveQueue = 136 + KERNEL_BASE,
|
||||
KeRemoveQueueDpc = 137 + KERNEL_BASE,
|
||||
KeResetEvent = 138 + KERNEL_BASE,
|
||||
KeRestoreFloatingPointState = 139 + KERNEL_BASE,
|
||||
KeResumeThread = 140 + KERNEL_BASE,
|
||||
KeRundownQueue = 141 + KERNEL_BASE,
|
||||
KeSaveFloatingPointState = 142 + KERNEL_BASE,
|
||||
KeSetBasePriorityThread = 143 + KERNEL_BASE,
|
||||
KeSetDisableBoostThread = 144 + KERNEL_BASE,
|
||||
KeSetEvent = 145 + KERNEL_BASE,
|
||||
KeSetEventBoostPriority = 146 + KERNEL_BASE,
|
||||
KeSetPriorityProcess = 147 + KERNEL_BASE,
|
||||
KeSetPriorityThread = 148 + KERNEL_BASE,
|
||||
KeSetTimer = 149 + KERNEL_BASE,
|
||||
KeSetTimerEx = 150 + KERNEL_BASE,
|
||||
KeStallExecutionProcessor = 151 + KERNEL_BASE,
|
||||
KeSuspendThread = 152 + KERNEL_BASE,
|
||||
KeSynchronizeExecution = 153 + KERNEL_BASE,
|
||||
KeSystemTime = 154 + KERNEL_BASE,
|
||||
KeTestAlertThread = 155 + KERNEL_BASE,
|
||||
KeTickCount = 156 + KERNEL_BASE,
|
||||
KeTimeIncrement = 157 + KERNEL_BASE,
|
||||
KeWaitForMultipleObjects = 158 + KERNEL_BASE,
|
||||
KeWaitForSingleObject = 159 + KERNEL_BASE,
|
||||
KfRaiseIrql = 160 + KERNEL_BASE,
|
||||
KfLowerIrql = 161 + KERNEL_BASE,
|
||||
KiBugCheckData = 162 + KERNEL_BASE,
|
||||
KiUnlockDispatcherDatabase = 163 + KERNEL_BASE,
|
||||
LaunchDataPage = 164 + KERNEL_BASE,
|
||||
MmAllocateContiguousMemory = 165 + KERNEL_BASE,
|
||||
MmAllocateContiguousMemoryEx = 166 + KERNEL_BASE,
|
||||
MmAllocateSystemMemory = 167 + KERNEL_BASE,
|
||||
MmClaimGpuInstanceMemory = 168 + KERNEL_BASE,
|
||||
MmCreateKernelStack = 169 + KERNEL_BASE,
|
||||
MmDeleteKernelStack = 170 + KERNEL_BASE,
|
||||
MmFreeContiguousMemory = 171 + KERNEL_BASE,
|
||||
MmFreeSystemMemory = 172 + KERNEL_BASE,
|
||||
MmGetPhysicalAddress = 173 + KERNEL_BASE,
|
||||
MmIsAddressValid = 174 + KERNEL_BASE,
|
||||
MmLockUnlockBufferPages = 175 + KERNEL_BASE,
|
||||
MmLockUnlockPhysicalPage = 176 + KERNEL_BASE,
|
||||
MmMapIoSpace = 177 + KERNEL_BASE,
|
||||
MmPersistContiguousMemory = 178 + KERNEL_BASE,
|
||||
MmQueryAddressProtect = 179 + KERNEL_BASE,
|
||||
MmQueryAllocationSize = 180 + KERNEL_BASE,
|
||||
MmQueryStatistics = 181 + KERNEL_BASE,
|
||||
MmSetAddressProtect = 182 + KERNEL_BASE,
|
||||
MmUnmapIoSpace = 183 + KERNEL_BASE,
|
||||
NtAllocateVirtualMemory = 184 + KERNEL_BASE,
|
||||
NtCancelTimer = 185 + KERNEL_BASE,
|
||||
NtClearEvent = 186 + KERNEL_BASE,
|
||||
NtClose = 187 + KERNEL_BASE,
|
||||
NtCreateDirectoryObject = 188 + KERNEL_BASE,
|
||||
NtCreateEvent = 189 + KERNEL_BASE,
|
||||
NtCreateFile = 190 + KERNEL_BASE,
|
||||
NtCreateIoCompletion = 191 + KERNEL_BASE,
|
||||
NtCreateMutant = 192 + KERNEL_BASE,
|
||||
NtCreateSemaphore = 193 + KERNEL_BASE,
|
||||
NtCreateTimer = 194 + KERNEL_BASE,
|
||||
NtDeleteFile = 195 + KERNEL_BASE,
|
||||
NtDeviceIoControlFile = 196 + KERNEL_BASE,
|
||||
NtDuplicateObject = 197 + KERNEL_BASE,
|
||||
NtFlushBuffersFile = 198 + KERNEL_BASE,
|
||||
NtFreeVirtualMemory = 199 + KERNEL_BASE,
|
||||
NtFsControlFile = 200 + KERNEL_BASE,
|
||||
NtOpenDirectoryObject = 201 + KERNEL_BASE,
|
||||
NtOpenFile = 202 + KERNEL_BASE,
|
||||
NtOpenSymbolicLinkObject = 203 + KERNEL_BASE,
|
||||
NtProtectVirtualMemory = 204 + KERNEL_BASE,
|
||||
NtPulseEvent = 205 + KERNEL_BASE,
|
||||
NtQueueApcThread = 206 + KERNEL_BASE,
|
||||
NtQueryDirectoryFile = 207 + KERNEL_BASE
|
||||
};
|
||||
|
||||
struct KernelImageThunk {
|
||||
KernelImageFunction addresses[while(std::mem::read_unsigned($, 4) != 0x00)];
|
||||
padding[4];
|
||||
};
|
||||
|
||||
union KernelImageThunkAddress {
|
||||
u32 debugAddress [[format("format_debug_kernel_image_thunk_address")]];
|
||||
u32 retailAddress [[format("format_retail_kernel_image_thunk_address")]];
|
||||
|
||||
if ((debugAddress ^ 0xEFB1F152) - parent.baseAddress < std::mem::size())
|
||||
KernelImageThunk debug @ (debugAddress ^ 0xEFB1F152) - parent.baseAddress;;
|
||||
if ((retailAddress ^ 0x5B6D40B6) - parent.baseAddress < std::mem::size())
|
||||
KernelImageThunk retail @ (retailAddress ^ 0x5B6D40B6) - parent.baseAddress;
|
||||
};
|
||||
|
||||
fn format_debug_kernel_image_thunk_address(u32 value) {
|
||||
return std::format("0x{:08X}", value ^ 0xEFB1F152);
|
||||
};
|
||||
|
||||
fn format_retail_kernel_image_thunk_address(u32 value) {
|
||||
return std::format("0x{:08X}", value ^ 0x5B6D40B6);
|
||||
};
|
||||
|
||||
struct TLS {
|
||||
u32 rawDataStart, rawDataEnd;
|
||||
u32 indexAddress;
|
||||
u32 callbacksAddress;
|
||||
type::Size<u32> zeroFillSize;
|
||||
u32 characteristics;
|
||||
};
|
||||
|
||||
fn relative_to_base(auto pointer) {
|
||||
return -parent.baseAddress;
|
||||
};
|
||||
|
||||
fn relative_to_base_section(auto pointer) {
|
||||
return -parent.parent.baseAddress;
|
||||
};
|
||||
|
||||
bitfield LibraryFlags {
|
||||
QFEVersion : 13;
|
||||
Approved : 2;
|
||||
DebugBuild : 1;
|
||||
};
|
||||
|
||||
struct LibraryVersion {
|
||||
char libraryName[8];
|
||||
u16 major, minor, build;
|
||||
LibraryFlags flags;
|
||||
};
|
||||
|
||||
bitfield SectionFlags {
|
||||
Writable : 1;
|
||||
Preload : 1;
|
||||
Executable : 1;
|
||||
InsertedFile : 1;
|
||||
HeadPageReadOnly : 1;
|
||||
TailPageReadOnly : 1;
|
||||
padding : 26;
|
||||
};
|
||||
|
||||
struct SectionHeader {
|
||||
SectionFlags sectionFlags;
|
||||
u32 virtualAddress;
|
||||
type::Size<u32> virtualSize;
|
||||
u32 rawAddress;
|
||||
type::Size<u32> rawSize;
|
||||
char *sectionName[] : u32 [[pointer_base("relative_to_base_section")]];
|
||||
u32 *sectionNameRefrenceCount : u32 [[pointer_base("relative_to_base_section")]];
|
||||
u16 *headSharedPageReferenceCount : u32 [[pointer_base("relative_to_base_section")]];
|
||||
u16 *tailSharedPageReferenceCount : u32 [[pointer_base("relative_to_base_section")]];
|
||||
u8 sectionDigest[20];
|
||||
|
||||
u8 data[rawSize] @ rawAddress [[sealed]];
|
||||
};
|
||||
|
||||
struct XBEH {
|
||||
type::Magic<"XBEH"> magic;
|
||||
u8 signature[0x100] [[sealed]];
|
||||
u32 baseAddress;
|
||||
type::Size<u32> headerSize, imageSize, imageHeaderSize;
|
||||
type::time32_t timeDate;
|
||||
Certificate *certificate : u32 [[pointer_base("relative_to_base")]];
|
||||
u32 numSections;
|
||||
SectionHeader *sectionHeader[numSections] : u32 [[pointer_base("relative_to_base")]];
|
||||
InitializationFlags initializationFlags;
|
||||
EntryPoint entrypoint;
|
||||
TLS *tls : u32 [[pointer_base("relative_to_base")]];
|
||||
|
||||
type::Size<u32> stackSize;
|
||||
u32 peHeapReserve, peHeapCommit, peBaseAddress;
|
||||
type::Size<u32> peImageSize;
|
||||
u32 peChecksum;
|
||||
type::time32_t peTimeDate;
|
||||
char *debugPathNameAddress[] : u32 [[pointer_base("relative_to_base")]];
|
||||
char *debugFileNameAddress[] : u32 [[pointer_base("relative_to_base")]];
|
||||
char16 *utf16DebugFileNameAddress[] : u32 [[pointer_base("relative_to_base")]];
|
||||
KernelImageThunkAddress kernelImageThunkAddress;
|
||||
u32 nonKernelImportDirectoryAddress;
|
||||
u32 numLibraryVersions;
|
||||
LibraryVersion *libraryVersonTable[numLibraryVersions] : u32 [[pointer_base("relative_to_base")]];
|
||||
LibraryVersion *kernelLibraryVersion : u32 [[pointer_base("relative_to_base")]];
|
||||
LibraryVersion *xapiLibraryVersion : u32 [[pointer_base("relative_to_base")]];
|
||||
u32 logoBitMapAddress, logoBitmapSize;
|
||||
u64 unknown1;
|
||||
u32 unknown2;
|
||||
|
||||
u8 logoBitmap[logoBitmapSize] @ logoBitMapAddress - baseAddress;
|
||||
};
|
||||
|
||||
#pragma author WerWolv
|
||||
#pragma description Xbox executable
|
||||
|
||||
#pragma MIME audio/x-xbox-executable
|
||||
|
||||
#include <type/magic.pat>
|
||||
#include <type/size.pat>
|
||||
#include <type/time.pat>
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
|
||||
bitfield AllowedMedia {
|
||||
HardDisk : 1;
|
||||
DVD_X2 : 1;
|
||||
DVD_CD : 1;
|
||||
CD : 1;
|
||||
DVD_5_RO : 1;
|
||||
DVD_9_RO : 1;
|
||||
DVD_5_RW : 1;
|
||||
DVD_9_RW : 1;
|
||||
Dongle : 1;
|
||||
MediaBoard : 1;
|
||||
padding : 20;
|
||||
NonSecureHardDisk : 1;
|
||||
NonSecureMode : 1;
|
||||
};
|
||||
|
||||
bitfield GameRegion {
|
||||
NorthAmerica : 1;
|
||||
Japan : 1;
|
||||
RestOfTheWorld : 1;
|
||||
padding : 28;
|
||||
Manufacturing : 1;
|
||||
};
|
||||
|
||||
struct Certificate {
|
||||
type::Size<u32> certificateSize;
|
||||
type::time32_t timeDate;
|
||||
u32 titleId;
|
||||
char16 titleName[0x50 / 2];
|
||||
u32 alternateTitleIds[16];
|
||||
AllowedMedia allowedMedia;
|
||||
GameRegion gameRegion;
|
||||
u32 gameRatings;
|
||||
u128 lanKey;
|
||||
u128 signatureKey;
|
||||
u128 alternateSignatureKeys[16];
|
||||
};
|
||||
|
||||
bitfield InitializationFlags {
|
||||
MountUtilityDrive : 1;
|
||||
FormatUtilityDrive : 1;
|
||||
Limit64Megabytes : 1;
|
||||
DontSetuptHarddisk : 1;
|
||||
padding : 28;
|
||||
};
|
||||
|
||||
union EntryPoint {
|
||||
u32 betaAddress [[format("format_beta_entrypoint")]];
|
||||
u32 debugAddress [[format("format_debug_entrypoint")]];
|
||||
u32 retailAddress [[format("format_retail_entrypoint")]];
|
||||
|
||||
if ((betaAddress ^ 0xE682F45B) - parent.baseAddress < std::mem::size())
|
||||
u8 beta @ (betaAddress ^ 0xE682F45B) - parent.baseAddress;;
|
||||
if ((debugAddress ^ 0x94859D4B) - parent.baseAddress < std::mem::size())
|
||||
u8 debug @ (debugAddress ^ 0x94859D4B) - parent.baseAddress;;
|
||||
if ((retailAddress ^ 0xA8FC57AB) - parent.baseAddress < std::mem::size())
|
||||
u8 retail @ (retailAddress ^ 0xA8FC57AB) - parent.baseAddress;
|
||||
};
|
||||
|
||||
fn format_beta_entrypoint(u32 value) {
|
||||
return std::format("0x{:08X}", value ^ 0xE682F45B);
|
||||
};
|
||||
|
||||
fn format_debug_entrypoint(u32 value) {
|
||||
return std::format("0x{:08X}", value ^ 0x94859D4B);
|
||||
};
|
||||
|
||||
fn format_retail_entrypoint(u32 value) {
|
||||
return std::format("0x{:08X}", value ^ 0xA8FC57AB);
|
||||
};
|
||||
|
||||
#define KERNEL_BASE 0x8000'0000
|
||||
enum KernelImageFunction : u32 {
|
||||
AvGetSavedDataAddress = 1 + KERNEL_BASE,
|
||||
AvSendTVEncoderOption = 2 + KERNEL_BASE,
|
||||
AvSetDisplayMode = 3 + KERNEL_BASE,
|
||||
AvSetSavedDataAddress = 4 + KERNEL_BASE,
|
||||
DbgBreakPoint = 5 + KERNEL_BASE,
|
||||
DbgBreakPointWithStatus = 6 + KERNEL_BASE,
|
||||
DbgLoadImageSymbols = 7 + KERNEL_BASE,
|
||||
DbgPrint = 8 + KERNEL_BASE,
|
||||
HalReadSMCTrayState = 9 + KERNEL_BASE,
|
||||
DbgPrompt = 10 + KERNEL_BASE,
|
||||
DbgUnLoadImageSymbols = 11 + KERNEL_BASE,
|
||||
ExAcquireReadWriteLockExclusive = 12 + KERNEL_BASE,
|
||||
ExAcquireReadWriteLockShared = 13 + KERNEL_BASE,
|
||||
ExAllocatePool = 14 + KERNEL_BASE,
|
||||
ExAllocatePoolWithTag = 15 + KERNEL_BASE,
|
||||
ExEventObjectType = 16 + KERNEL_BASE,
|
||||
ExFreePool = 17 + KERNEL_BASE,
|
||||
ExInitializeReadWriteLock = 18 + KERNEL_BASE,
|
||||
ExInterlockedAddLargeInteger = 19 + KERNEL_BASE,
|
||||
ExInterlockedAddLargeStatistic = 20 + KERNEL_BASE,
|
||||
ExInterlockedCompareExchange64 = 21 + KERNEL_BASE,
|
||||
ExMutantObjectType = 22 + KERNEL_BASE,
|
||||
ExQueryPoolBlockSize = 23 + KERNEL_BASE,
|
||||
ExQueryNonVolatileSetting = 24 + KERNEL_BASE,
|
||||
ExReadWriteRefurbInfo = 25 + KERNEL_BASE,
|
||||
ExRaiseException = 26 + KERNEL_BASE,
|
||||
ExRaiseStatus = 27 + KERNEL_BASE,
|
||||
ExReleaseReadWriteLock = 28 + KERNEL_BASE,
|
||||
ExSaveNonVolatileSetting = 29 + KERNEL_BASE,
|
||||
ExSemaphoreObjectType = 30 + KERNEL_BASE,
|
||||
ExTimerObjectType = 31 + KERNEL_BASE,
|
||||
ExfInterlockedInsertHeadList = 32 + KERNEL_BASE,
|
||||
ExfInterlockedInsertTailList = 33 + KERNEL_BASE,
|
||||
ExfInterlockedRemoveHeadList = 34 + KERNEL_BASE,
|
||||
FscGetCacheSize = 35 + KERNEL_BASE,
|
||||
FscInvalidateIdleBlocks = 36 + KERNEL_BASE,
|
||||
FscSetCacheSize = 37 + KERNEL_BASE,
|
||||
HalClearSoftwareInterrupt = 38 + KERNEL_BASE,
|
||||
HalDisableSystemInterrupt = 39 + KERNEL_BASE,
|
||||
HalDiskCachePartitionCount = 40 + KERNEL_BASE,
|
||||
HalDiskModelNumber = 41 + KERNEL_BASE,
|
||||
HalDiskSerialNumber = 42 + KERNEL_BASE,
|
||||
HalEnableSystemInterrupt = 43 + KERNEL_BASE,
|
||||
HalGetInterruptVector = 44 + KERNEL_BASE,
|
||||
HalReadSMBusValue = 45 + KERNEL_BASE,
|
||||
HalReadWritePCISpace = 46 + KERNEL_BASE,
|
||||
HalRegisterShutdownNotification = 47 + KERNEL_BASE,
|
||||
HalRequestSoftwareInterrupt = 48 + KERNEL_BASE,
|
||||
HalReturnToFirmware = 49 + KERNEL_BASE,
|
||||
HalWriteSMBusValue = 50 + KERNEL_BASE,
|
||||
InterlockedCompareExchange = 51 + KERNEL_BASE,
|
||||
InterlockedDecrement = 52 + KERNEL_BASE,
|
||||
InterlockedIncrement = 53 + KERNEL_BASE,
|
||||
InterlockedExchange = 54 + KERNEL_BASE,
|
||||
InterlockedExchangeAdd = 55 + KERNEL_BASE,
|
||||
InterlockedFlushSList = 56 + KERNEL_BASE,
|
||||
InterlockedPopEntrySList = 57 + KERNEL_BASE,
|
||||
InterlockedPushEntrySList = 58 + KERNEL_BASE,
|
||||
IoAllocateIrp = 59 + KERNEL_BASE,
|
||||
IoBuildAsynchronousFsdRequest = 60 + KERNEL_BASE,
|
||||
IoBuildDeviceIoControlRequest = 61 + KERNEL_BASE,
|
||||
IoBuildSynchronousFsdRequest = 62 + KERNEL_BASE,
|
||||
IoCheckShareAccess = 63 + KERNEL_BASE,
|
||||
IoCompletionObjectType = 64 + KERNEL_BASE,
|
||||
IoCreateDevice = 65 + KERNEL_BASE,
|
||||
IoCreateFile = 66 + KERNEL_BASE,
|
||||
IoCreateSymbolicLink = 67 + KERNEL_BASE,
|
||||
IoDeleteDevice = 68 + KERNEL_BASE,
|
||||
IoDeleteSymbolicLink = 69 + KERNEL_BASE,
|
||||
IoDeviceObjectType = 70 + KERNEL_BASE,
|
||||
IoFileObjectType = 71 + KERNEL_BASE,
|
||||
IoFreeIrp = 72 + KERNEL_BASE,
|
||||
IoInitializeIrp = 73 + KERNEL_BASE,
|
||||
IoInvalidDeviceRequest = 74 + KERNEL_BASE,
|
||||
IoQueryFileInformation = 75 + KERNEL_BASE,
|
||||
IoQueryVolumeInformation = 76 + KERNEL_BASE,
|
||||
IoQueueThreadIrp = 77 + KERNEL_BASE,
|
||||
IoRemoveShareAccess = 78 + KERNEL_BASE,
|
||||
IoSetIoCompletion = 79 + KERNEL_BASE,
|
||||
IoSetShareAccess = 80 + KERNEL_BASE,
|
||||
IoStartNextPacket = 81 + KERNEL_BASE,
|
||||
IoStartNextPacketByKey = 82 + KERNEL_BASE,
|
||||
IoStartPacket = 83 + KERNEL_BASE,
|
||||
IoSynchronousDeviceIoControlRequest = 84 + KERNEL_BASE,
|
||||
IoSynchronousFsdRequest = 85 + KERNEL_BASE,
|
||||
IofCallDriver = 86 + KERNEL_BASE,
|
||||
IofCompleteRequest = 87 + KERNEL_BASE,
|
||||
KdDebuggerEnabled = 88 + KERNEL_BASE,
|
||||
KdDebuggerNotPresent = 89 + KERNEL_BASE,
|
||||
IoDismountVolume = 90 + KERNEL_BASE,
|
||||
IoDismountVolumeByName = 91 + KERNEL_BASE,
|
||||
KeAlertResumeThread = 92 + KERNEL_BASE,
|
||||
KeAlertThread = 93 + KERNEL_BASE,
|
||||
KeBoostPriorityThread = 94 + KERNEL_BASE,
|
||||
KeBugCheck = 95 + KERNEL_BASE,
|
||||
KeBugCheckEx = 96 + KERNEL_BASE,
|
||||
KeCancelTimer = 97 + KERNEL_BASE,
|
||||
KeConnectInterrupt = 98 + KERNEL_BASE,
|
||||
KeDelayExecutionThread = 99 + KERNEL_BASE,
|
||||
KeDisconnectInterrupt = 100 + KERNEL_BASE,
|
||||
KeEnterCriticalRegion = 101 + KERNEL_BASE,
|
||||
MmGlobalData = 102 + KERNEL_BASE,
|
||||
KeGetCurrentIrql = 103 + KERNEL_BASE,
|
||||
KeGetCurrentThread = 104 + KERNEL_BASE,
|
||||
KeInitializeApc = 105 + KERNEL_BASE,
|
||||
KeInitializeDeviceQueue = 106 + KERNEL_BASE,
|
||||
KeInitializeDpc = 107 + KERNEL_BASE,
|
||||
KeInitializeEvent = 108 + KERNEL_BASE,
|
||||
KeInitializeInterrupt = 109 + KERNEL_BASE,
|
||||
KeInitializeMutant = 110 + KERNEL_BASE,
|
||||
KeInitializeQueue = 111 + KERNEL_BASE,
|
||||
KeInitializeSemaphore = 112 + KERNEL_BASE,
|
||||
KeInitializeTimerEx = 113 + KERNEL_BASE,
|
||||
KeInsertByKeyDeviceQueue = 114 + KERNEL_BASE,
|
||||
KeInsertDeviceQueue = 115 + KERNEL_BASE,
|
||||
KeInsertHeadQueue = 116 + KERNEL_BASE,
|
||||
KeInsertQueue = 117 + KERNEL_BASE,
|
||||
KeInsertQueueApc = 118 + KERNEL_BASE,
|
||||
KeInsertQueueDpc = 119 + KERNEL_BASE,
|
||||
KeInterruptTime = 120 + KERNEL_BASE,
|
||||
KeIsExecutingDpc = 121 + KERNEL_BASE,
|
||||
KeLeaveCriticalRegion = 122 + KERNEL_BASE,
|
||||
KePulseEvent = 123 + KERNEL_BASE,
|
||||
KeQueryBasePriorityThread = 124 + KERNEL_BASE,
|
||||
KeQueryInterruptTime = 125 + KERNEL_BASE,
|
||||
KeQueryPerformanceCounter = 126 + KERNEL_BASE,
|
||||
KeQueryPerformanceFrequency = 127 + KERNEL_BASE,
|
||||
KeQuerySystemTime = 128 + KERNEL_BASE,
|
||||
KeRaiseIrqlToDpcLevel = 129 + KERNEL_BASE,
|
||||
KeRaiseIrqlToSynchLevel = 130 + KERNEL_BASE,
|
||||
KeReleaseMutant = 131 + KERNEL_BASE,
|
||||
KeReleaseSemaphore = 132 + KERNEL_BASE,
|
||||
KeRemoveByKeyDeviceQueue = 133 + KERNEL_BASE,
|
||||
KeRemoveDeviceQueue = 134 + KERNEL_BASE,
|
||||
KeRemoveEntryDeviceQueue = 135 + KERNEL_BASE,
|
||||
KeRemoveQueue = 136 + KERNEL_BASE,
|
||||
KeRemoveQueueDpc = 137 + KERNEL_BASE,
|
||||
KeResetEvent = 138 + KERNEL_BASE,
|
||||
KeRestoreFloatingPointState = 139 + KERNEL_BASE,
|
||||
KeResumeThread = 140 + KERNEL_BASE,
|
||||
KeRundownQueue = 141 + KERNEL_BASE,
|
||||
KeSaveFloatingPointState = 142 + KERNEL_BASE,
|
||||
KeSetBasePriorityThread = 143 + KERNEL_BASE,
|
||||
KeSetDisableBoostThread = 144 + KERNEL_BASE,
|
||||
KeSetEvent = 145 + KERNEL_BASE,
|
||||
KeSetEventBoostPriority = 146 + KERNEL_BASE,
|
||||
KeSetPriorityProcess = 147 + KERNEL_BASE,
|
||||
KeSetPriorityThread = 148 + KERNEL_BASE,
|
||||
KeSetTimer = 149 + KERNEL_BASE,
|
||||
KeSetTimerEx = 150 + KERNEL_BASE,
|
||||
KeStallExecutionProcessor = 151 + KERNEL_BASE,
|
||||
KeSuspendThread = 152 + KERNEL_BASE,
|
||||
KeSynchronizeExecution = 153 + KERNEL_BASE,
|
||||
KeSystemTime = 154 + KERNEL_BASE,
|
||||
KeTestAlertThread = 155 + KERNEL_BASE,
|
||||
KeTickCount = 156 + KERNEL_BASE,
|
||||
KeTimeIncrement = 157 + KERNEL_BASE,
|
||||
KeWaitForMultipleObjects = 158 + KERNEL_BASE,
|
||||
KeWaitForSingleObject = 159 + KERNEL_BASE,
|
||||
KfRaiseIrql = 160 + KERNEL_BASE,
|
||||
KfLowerIrql = 161 + KERNEL_BASE,
|
||||
KiBugCheckData = 162 + KERNEL_BASE,
|
||||
KiUnlockDispatcherDatabase = 163 + KERNEL_BASE,
|
||||
LaunchDataPage = 164 + KERNEL_BASE,
|
||||
MmAllocateContiguousMemory = 165 + KERNEL_BASE,
|
||||
MmAllocateContiguousMemoryEx = 166 + KERNEL_BASE,
|
||||
MmAllocateSystemMemory = 167 + KERNEL_BASE,
|
||||
MmClaimGpuInstanceMemory = 168 + KERNEL_BASE,
|
||||
MmCreateKernelStack = 169 + KERNEL_BASE,
|
||||
MmDeleteKernelStack = 170 + KERNEL_BASE,
|
||||
MmFreeContiguousMemory = 171 + KERNEL_BASE,
|
||||
MmFreeSystemMemory = 172 + KERNEL_BASE,
|
||||
MmGetPhysicalAddress = 173 + KERNEL_BASE,
|
||||
MmIsAddressValid = 174 + KERNEL_BASE,
|
||||
MmLockUnlockBufferPages = 175 + KERNEL_BASE,
|
||||
MmLockUnlockPhysicalPage = 176 + KERNEL_BASE,
|
||||
MmMapIoSpace = 177 + KERNEL_BASE,
|
||||
MmPersistContiguousMemory = 178 + KERNEL_BASE,
|
||||
MmQueryAddressProtect = 179 + KERNEL_BASE,
|
||||
MmQueryAllocationSize = 180 + KERNEL_BASE,
|
||||
MmQueryStatistics = 181 + KERNEL_BASE,
|
||||
MmSetAddressProtect = 182 + KERNEL_BASE,
|
||||
MmUnmapIoSpace = 183 + KERNEL_BASE,
|
||||
NtAllocateVirtualMemory = 184 + KERNEL_BASE,
|
||||
NtCancelTimer = 185 + KERNEL_BASE,
|
||||
NtClearEvent = 186 + KERNEL_BASE,
|
||||
NtClose = 187 + KERNEL_BASE,
|
||||
NtCreateDirectoryObject = 188 + KERNEL_BASE,
|
||||
NtCreateEvent = 189 + KERNEL_BASE,
|
||||
NtCreateFile = 190 + KERNEL_BASE,
|
||||
NtCreateIoCompletion = 191 + KERNEL_BASE,
|
||||
NtCreateMutant = 192 + KERNEL_BASE,
|
||||
NtCreateSemaphore = 193 + KERNEL_BASE,
|
||||
NtCreateTimer = 194 + KERNEL_BASE,
|
||||
NtDeleteFile = 195 + KERNEL_BASE,
|
||||
NtDeviceIoControlFile = 196 + KERNEL_BASE,
|
||||
NtDuplicateObject = 197 + KERNEL_BASE,
|
||||
NtFlushBuffersFile = 198 + KERNEL_BASE,
|
||||
NtFreeVirtualMemory = 199 + KERNEL_BASE,
|
||||
NtFsControlFile = 200 + KERNEL_BASE,
|
||||
NtOpenDirectoryObject = 201 + KERNEL_BASE,
|
||||
NtOpenFile = 202 + KERNEL_BASE,
|
||||
NtOpenSymbolicLinkObject = 203 + KERNEL_BASE,
|
||||
NtProtectVirtualMemory = 204 + KERNEL_BASE,
|
||||
NtPulseEvent = 205 + KERNEL_BASE,
|
||||
NtQueueApcThread = 206 + KERNEL_BASE,
|
||||
NtQueryDirectoryFile = 207 + KERNEL_BASE
|
||||
};
|
||||
|
||||
struct KernelImageThunk {
|
||||
KernelImageFunction addresses[while(std::mem::read_unsigned($, 4) != 0x00)];
|
||||
padding[4];
|
||||
};
|
||||
|
||||
union KernelImageThunkAddress {
|
||||
u32 debugAddress [[format("format_debug_kernel_image_thunk_address")]];
|
||||
u32 retailAddress [[format("format_retail_kernel_image_thunk_address")]];
|
||||
|
||||
if ((debugAddress ^ 0xEFB1F152) - parent.baseAddress < std::mem::size())
|
||||
KernelImageThunk debug @ (debugAddress ^ 0xEFB1F152) - parent.baseAddress;;
|
||||
if ((retailAddress ^ 0x5B6D40B6) - parent.baseAddress < std::mem::size())
|
||||
KernelImageThunk retail @ (retailAddress ^ 0x5B6D40B6) - parent.baseAddress;
|
||||
};
|
||||
|
||||
fn format_debug_kernel_image_thunk_address(u32 value) {
|
||||
return std::format("0x{:08X}", value ^ 0xEFB1F152);
|
||||
};
|
||||
|
||||
fn format_retail_kernel_image_thunk_address(u32 value) {
|
||||
return std::format("0x{:08X}", value ^ 0x5B6D40B6);
|
||||
};
|
||||
|
||||
struct TLS {
|
||||
u32 rawDataStart, rawDataEnd;
|
||||
u32 indexAddress;
|
||||
u32 callbacksAddress;
|
||||
type::Size<u32> zeroFillSize;
|
||||
u32 characteristics;
|
||||
};
|
||||
|
||||
fn relative_to_base(auto pointer) {
|
||||
return -parent.baseAddress;
|
||||
};
|
||||
|
||||
fn relative_to_base_section(auto pointer) {
|
||||
return -parent.parent.baseAddress;
|
||||
};
|
||||
|
||||
bitfield LibraryFlags {
|
||||
QFEVersion : 13;
|
||||
Approved : 2;
|
||||
DebugBuild : 1;
|
||||
};
|
||||
|
||||
struct LibraryVersion {
|
||||
char libraryName[8];
|
||||
u16 major, minor, build;
|
||||
LibraryFlags flags;
|
||||
};
|
||||
|
||||
bitfield SectionFlags {
|
||||
Writable : 1;
|
||||
Preload : 1;
|
||||
Executable : 1;
|
||||
InsertedFile : 1;
|
||||
HeadPageReadOnly : 1;
|
||||
TailPageReadOnly : 1;
|
||||
padding : 26;
|
||||
};
|
||||
|
||||
struct SectionHeader {
|
||||
SectionFlags sectionFlags;
|
||||
u32 virtualAddress;
|
||||
type::Size<u32> virtualSize;
|
||||
u32 rawAddress;
|
||||
type::Size<u32> rawSize;
|
||||
char *sectionName[] : u32 [[pointer_base("relative_to_base_section")]];
|
||||
u32 *sectionNameRefrenceCount : u32 [[pointer_base("relative_to_base_section")]];
|
||||
u16 *headSharedPageReferenceCount : u32 [[pointer_base("relative_to_base_section")]];
|
||||
u16 *tailSharedPageReferenceCount : u32 [[pointer_base("relative_to_base_section")]];
|
||||
u8 sectionDigest[20];
|
||||
|
||||
u8 data[rawSize] @ rawAddress [[sealed]];
|
||||
};
|
||||
|
||||
struct XBEH {
|
||||
type::Magic<"XBEH"> magic;
|
||||
u8 signature[0x100] [[sealed]];
|
||||
u32 baseAddress;
|
||||
type::Size<u32> headerSize, imageSize, imageHeaderSize;
|
||||
type::time32_t timeDate;
|
||||
Certificate *certificate : u32 [[pointer_base("relative_to_base")]];
|
||||
u32 numSections;
|
||||
SectionHeader *sectionHeader[numSections] : u32 [[pointer_base("relative_to_base")]];
|
||||
InitializationFlags initializationFlags;
|
||||
EntryPoint entrypoint;
|
||||
TLS *tls : u32 [[pointer_base("relative_to_base")]];
|
||||
|
||||
type::Size<u32> stackSize;
|
||||
u32 peHeapReserve, peHeapCommit, peBaseAddress;
|
||||
type::Size<u32> peImageSize;
|
||||
u32 peChecksum;
|
||||
type::time32_t peTimeDate;
|
||||
char *debugPathNameAddress[] : u32 [[pointer_base("relative_to_base")]];
|
||||
char *debugFileNameAddress[] : u32 [[pointer_base("relative_to_base")]];
|
||||
char16 *utf16DebugFileNameAddress[] : u32 [[pointer_base("relative_to_base")]];
|
||||
KernelImageThunkAddress kernelImageThunkAddress;
|
||||
u32 nonKernelImportDirectoryAddress;
|
||||
u32 numLibraryVersions;
|
||||
LibraryVersion *libraryVersonTable[numLibraryVersions] : u32 [[pointer_base("relative_to_base")]];
|
||||
LibraryVersion *kernelLibraryVersion : u32 [[pointer_base("relative_to_base")]];
|
||||
LibraryVersion *xapiLibraryVersion : u32 [[pointer_base("relative_to_base")]];
|
||||
u32 logoBitMapAddress, logoBitmapSize;
|
||||
u64 unknown1;
|
||||
u32 unknown2;
|
||||
|
||||
u8 logoBitmap[logoBitmapSize] @ logoBitMapAddress - baseAddress;
|
||||
};
|
||||
|
||||
XBEH xbeh @ 0x00;
|
||||
@@ -1,97 +1,100 @@
|
||||
#include <std/core.pat>
|
||||
|
||||
#include <type/magic.pat>
|
||||
#include <type/size.pat>
|
||||
|
||||
#define PAGE_SIZE 0x200
|
||||
|
||||
enum RomSize : u8 {
|
||||
_1GB = 0xFA,
|
||||
_2GB = 0xF8,
|
||||
_4GB = 0xF0,
|
||||
_8GB = 0xE0,
|
||||
_16GB = 0xE1,
|
||||
_32GB = 0xE2
|
||||
};
|
||||
|
||||
bitfield Index {
|
||||
titleKeyDecIndex : 4;
|
||||
kekIndex : 4;
|
||||
};
|
||||
|
||||
bitfield Flags {
|
||||
autoBoot : 1;
|
||||
historyErase : 1;
|
||||
repairTool : 1;
|
||||
differentRegionCupToTerraDevice : 1;
|
||||
differentRegionCupToGlobalDevice : 1;
|
||||
padding : 2;
|
||||
hasNewCardHeader : 1;
|
||||
};
|
||||
|
||||
struct SelSec {
|
||||
u16 t1, t2;
|
||||
};
|
||||
|
||||
struct CardHeader {
|
||||
u8 headerSignature[0x100];
|
||||
type::Magic<"HEAD"> magic;
|
||||
u32 romAreaStartPageAddress;
|
||||
u32 backupAreaStartPageAddress;
|
||||
Index index [[inline]];
|
||||
RomSize romSize;
|
||||
u8 cardHeaderVersion;
|
||||
Flags flags;
|
||||
u64 packageId;
|
||||
u32 validDataEndAddress;
|
||||
padding[4];
|
||||
u8 iv[0x10];
|
||||
u64 partitionFsHeaderAddress;
|
||||
type::Size<u64> partitionFsHeaderSize;
|
||||
u8 partitionFsHeaderHash[0x20];
|
||||
u8 initialDataHash[0x20];
|
||||
SelSec selSec;
|
||||
u32 selT1Key;
|
||||
u32 selKey;
|
||||
u32 limArea;
|
||||
|
||||
u8 cardHeaderEncryptedData[0x70];
|
||||
};
|
||||
|
||||
struct FileEntry {
|
||||
u64 dataOffset;
|
||||
type::Size<u64> dataSize;
|
||||
u32 fileNameOffset;
|
||||
type::Size<u32> hashedRegionSize;
|
||||
padding[8];
|
||||
u8 hash[0x20];
|
||||
};
|
||||
|
||||
struct String {
|
||||
char string[];
|
||||
};
|
||||
|
||||
struct File {
|
||||
String fileName @ addressof(parent.stringTable) + parent.fileEntryTable[std::core::array_index()].fileNameOffset;
|
||||
u8 data[parent.fileEntryTable[std::core::array_index()].dataSize] @ addressof(parent.stringTable) + sizeof(parent.stringTable) + parent.fileEntryTable[std::core::array_index()].dataOffset [[sealed]];
|
||||
};
|
||||
|
||||
struct PartitionFs {
|
||||
type::Magic<"HFS0"> magic;
|
||||
u32 fileCount;
|
||||
type::Size<u32> stringTableSize;
|
||||
padding[4];
|
||||
FileEntry fileEntryTable[fileCount];
|
||||
String stringTable[while($ < (addressof(fileEntryTable) + sizeof(fileEntryTable) + stringTableSize))];
|
||||
|
||||
File files[fileCount];
|
||||
};
|
||||
|
||||
struct XCI {
|
||||
CardHeader header;
|
||||
|
||||
PartitionFs x @ header.romAreaStartPageAddress * PAGE_SIZE;
|
||||
|
||||
};
|
||||
|
||||
#pragma author WerWolv
|
||||
#pragma description Nintendo Switch XCI cardridge ROM
|
||||
|
||||
#include <std/core.pat>
|
||||
|
||||
#include <type/magic.pat>
|
||||
#include <type/size.pat>
|
||||
|
||||
#define PAGE_SIZE 0x200
|
||||
|
||||
enum RomSize : u8 {
|
||||
_1GB = 0xFA,
|
||||
_2GB = 0xF8,
|
||||
_4GB = 0xF0,
|
||||
_8GB = 0xE0,
|
||||
_16GB = 0xE1,
|
||||
_32GB = 0xE2
|
||||
};
|
||||
|
||||
bitfield Index {
|
||||
titleKeyDecIndex : 4;
|
||||
kekIndex : 4;
|
||||
};
|
||||
|
||||
bitfield Flags {
|
||||
autoBoot : 1;
|
||||
historyErase : 1;
|
||||
repairTool : 1;
|
||||
differentRegionCupToTerraDevice : 1;
|
||||
differentRegionCupToGlobalDevice : 1;
|
||||
padding : 2;
|
||||
hasNewCardHeader : 1;
|
||||
};
|
||||
|
||||
struct SelSec {
|
||||
u16 t1, t2;
|
||||
};
|
||||
|
||||
struct CardHeader {
|
||||
u8 headerSignature[0x100];
|
||||
type::Magic<"HEAD"> magic;
|
||||
u32 romAreaStartPageAddress;
|
||||
u32 backupAreaStartPageAddress;
|
||||
Index index [[inline]];
|
||||
RomSize romSize;
|
||||
u8 cardHeaderVersion;
|
||||
Flags flags;
|
||||
u64 packageId;
|
||||
u32 validDataEndAddress;
|
||||
padding[4];
|
||||
u8 iv[0x10];
|
||||
u64 partitionFsHeaderAddress;
|
||||
type::Size<u64> partitionFsHeaderSize;
|
||||
u8 partitionFsHeaderHash[0x20];
|
||||
u8 initialDataHash[0x20];
|
||||
SelSec selSec;
|
||||
u32 selT1Key;
|
||||
u32 selKey;
|
||||
u32 limArea;
|
||||
|
||||
u8 cardHeaderEncryptedData[0x70];
|
||||
};
|
||||
|
||||
struct FileEntry {
|
||||
u64 dataOffset;
|
||||
type::Size<u64> dataSize;
|
||||
u32 fileNameOffset;
|
||||
type::Size<u32> hashedRegionSize;
|
||||
padding[8];
|
||||
u8 hash[0x20];
|
||||
};
|
||||
|
||||
struct String {
|
||||
char string[];
|
||||
};
|
||||
|
||||
struct File {
|
||||
String fileName @ addressof(parent.stringTable) + parent.fileEntryTable[std::core::array_index()].fileNameOffset;
|
||||
u8 data[parent.fileEntryTable[std::core::array_index()].dataSize] @ addressof(parent.stringTable) + sizeof(parent.stringTable) + parent.fileEntryTable[std::core::array_index()].dataOffset [[sealed]];
|
||||
};
|
||||
|
||||
struct PartitionFs {
|
||||
type::Magic<"HFS0"> magic;
|
||||
u32 fileCount;
|
||||
type::Size<u32> stringTableSize;
|
||||
padding[4];
|
||||
FileEntry fileEntryTable[fileCount];
|
||||
String stringTable[while($ < (addressof(fileEntryTable) + sizeof(fileEntryTable) + stringTableSize))];
|
||||
|
||||
File files[fileCount];
|
||||
};
|
||||
|
||||
struct XCI {
|
||||
CardHeader header;
|
||||
|
||||
PartitionFs x @ header.romAreaStartPageAddress * PAGE_SIZE;
|
||||
|
||||
};
|
||||
|
||||
XCI xci @ 0x00;
|
||||
@@ -1,52 +1,55 @@
|
||||
#include <std/mem.pat>
|
||||
#include <std/io.pat>
|
||||
|
||||
struct Flags {
|
||||
be u16 length;
|
||||
u8 value[length];
|
||||
};
|
||||
|
||||
struct TLV {
|
||||
char tag[parent.keySize];
|
||||
be u16 length;
|
||||
char value[length];
|
||||
};
|
||||
|
||||
struct Command {
|
||||
be u32 value;
|
||||
} [[static, sealed, format("format_command")]];
|
||||
|
||||
fn format_command(Command command) {
|
||||
u32 x = command.value;
|
||||
|
||||
if (x == 0x20000000) return "NOP";
|
||||
if (x == 0xAA995566) return "SYNC";
|
||||
if (x == 0x000000BB) return "Bus Width Sync";
|
||||
if (x == 0x11220044) return "Bus Width Detect";
|
||||
if (x == 0x30002001) return "Write to FAR";
|
||||
if (x == 0x28006000) return "Write to FDRO";
|
||||
if (x == 0x30000001) return "Write to CRC";
|
||||
if (x == 0x30018001) return "Write to IDCODE";
|
||||
if (x == 0x30004000) return "Write to FDRI";
|
||||
if (x == 0x30008001) return "Write to CMD";
|
||||
|
||||
if ((x & 0xF0000000) == 0x30000000)
|
||||
return std::format("Write to Register {}", (x & 0x0003E000) >> 13);
|
||||
|
||||
return std::format("0x{:08X}", x);
|
||||
};
|
||||
|
||||
struct Commands {
|
||||
char tag[parent.keySize];
|
||||
be u32 length;
|
||||
Command commands[length / 4];
|
||||
};
|
||||
|
||||
struct Header {
|
||||
Flags flags;
|
||||
be u16 keySize;
|
||||
TLV tlv[4];
|
||||
Commands data;
|
||||
};
|
||||
|
||||
#pragma author WerWolv
|
||||
#pragma description Xilinx FPGA Bitstreams
|
||||
|
||||
#include <std/mem.pat>
|
||||
#include <std/io.pat>
|
||||
|
||||
struct Flags {
|
||||
be u16 length;
|
||||
u8 value[length];
|
||||
};
|
||||
|
||||
struct TLV {
|
||||
char tag[parent.keySize];
|
||||
be u16 length;
|
||||
char value[length];
|
||||
};
|
||||
|
||||
struct Command {
|
||||
be u32 value;
|
||||
} [[static, sealed, format("format_command")]];
|
||||
|
||||
fn format_command(Command command) {
|
||||
u32 x = command.value;
|
||||
|
||||
if (x == 0x20000000) return "NOP";
|
||||
if (x == 0xAA995566) return "SYNC";
|
||||
if (x == 0x000000BB) return "Bus Width Sync";
|
||||
if (x == 0x11220044) return "Bus Width Detect";
|
||||
if (x == 0x30002001) return "Write to FAR";
|
||||
if (x == 0x28006000) return "Write to FDRO";
|
||||
if (x == 0x30000001) return "Write to CRC";
|
||||
if (x == 0x30018001) return "Write to IDCODE";
|
||||
if (x == 0x30004000) return "Write to FDRI";
|
||||
if (x == 0x30008001) return "Write to CMD";
|
||||
|
||||
if ((x & 0xF0000000) == 0x30000000)
|
||||
return std::format("Write to Register {}", (x & 0x0003E000) >> 13);
|
||||
|
||||
return std::format("0x{:08X}", x);
|
||||
};
|
||||
|
||||
struct Commands {
|
||||
char tag[parent.keySize];
|
||||
be u32 length;
|
||||
Command commands[length / 4];
|
||||
};
|
||||
|
||||
struct Header {
|
||||
Flags flags;
|
||||
be u16 keySize;
|
||||
TLV tlv[4];
|
||||
Commands data;
|
||||
};
|
||||
|
||||
Header header @ 0x00;
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description End of Central Directory Header, Central Directory File Headers
|
||||
|
||||
#pragma MIME application/zip
|
||||
|
||||
#include <std/mem.pat>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description ZLIB compressed data format
|
||||
|
||||
#pragma MIME application/zlib
|
||||
|
||||
#include <std/core.pat>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma description Zstandard compressed data format
|
||||
|
||||
// https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md
|
||||
|
||||
#pragma MIME application/zstd
|
||||
|
||||
Reference in New Issue
Block a user