├── .gitignore ├── LICENSE ├── README.md ├── btparser.sln └── btparser ├── .gitignore ├── ast.h ├── btparser.vcxproj ├── btparser.vcxproj.filters ├── btparser.vcxproj.user ├── helpers.h ├── keywords.h ├── lexer.cpp ├── lexer.h ├── main.cpp ├── operators.h ├── parser.cpp ├── parser.h ├── testfiles.h └── tests ├── AVITemplate.bt ├── AndroidManifestTemplate.bt ├── BMPTemplate.bt ├── CABTemplate.bt ├── CAPTemplate.bt ├── CDATemplate.bt ├── CLASSTemplate.bt ├── CLASSTemplate2.bt ├── CLASSTemplate3.bt ├── CRXTemplate.bt ├── DBFTemplate.bt ├── DEXTemplate.bt ├── DEXTemplate.new.bt ├── DMPTemplate.bt ├── EDIDTemplate.bt ├── ELFTemplate.bt ├── ELFTemplate.new.bt ├── EMFTemplate.bt ├── EOTTemplate.bt ├── EVSBTemplate.bt ├── EXETemplate.bt ├── EXETemplate2.bt ├── ElTorito.bt ├── FAT16Template.bt ├── FLVTemplate.bt ├── GIFTemplate.bt ├── GPTTemplate.bt ├── GZipTemplate.bt ├── GeoTIFTemplate.bt ├── GocleverTemplate.bt ├── ICOTemplate.bt ├── ISOBMFTemplate.bt ├── ISOTemplate.bt ├── InspectorDates.bt ├── InspectorWithMP4DateTime.bt ├── JPGTemplate.bt ├── LNKTemplate.bt ├── LUKSTemplate.bt ├── MBRTemplate.bt ├── MBRTemplateFAT.bt ├── MFTRecord.bt ├── MIDITemplate.bt ├── MOBITemplate.bt ├── MP3Template.bt ├── MP4Template.bt ├── MachOTemplate.bt ├── Mifare1kTemplate.bt ├── Mifare4kTemplate.bt ├── NetflowVersion5.bt ├── OGGTemplate.bt ├── OrCAD3.20a_LIB.bt ├── OrCad3.20a_SCH.bt ├── OscarItemTemplate.bt ├── PALTemplate.bt ├── PCAPTemplate.bt ├── PCXTemplate.bt ├── PDFTemplate.bt ├── PETemplate.bt ├── PNG12Template.bt ├── PNGTemplate.bt ├── PSFTemplate.bt ├── PYCTemplate.bt ├── RARTemplate.bt ├── RDBTemplate.bt ├── RESTemplate.bt ├── RIFFTemplate.bt ├── ROMFS.bt ├── RegistryHive.bt ├── RegistryPolicyFileTemplate.bt ├── SF2Template.bt ├── SHPTemplate.bt ├── SHXTemplate.bt ├── SRecTemplate.bt ├── SSPTemplate.bt ├── STLTemplate.bt ├── SWFTemplate.bt ├── SinclairMicrodriveImage.bt ├── TGATemplate.bt ├── TIFTemplate.bt ├── TOCTemplate.bt ├── TTFTemplate.bt ├── TacxTemplate.bt ├── UTMPTemplate.bt ├── VHDTemplate.bt ├── WAVTemplate.bt ├── WAVTemplateAdv.bt ├── WMFTemplate.bt ├── WinhexPosTemplate.bt ├── ZIPTemplate.bt ├── ZIPTemplateAdv.bt ├── comment.bt ├── comment_error.bt ├── exFATTemplate.bt ├── exp_lex ├── AVITemplate.bt ├── AndroidManifestTemplate.bt ├── BMPTemplate.bt ├── CABTemplate.bt ├── CAPTemplate.bt ├── CDATemplate.bt ├── CLASSTemplate.bt ├── CLASSTemplate2.bt ├── CLASSTemplate3.bt ├── CRXTemplate.bt ├── DBFTemplate.bt ├── DMPTemplate.bt ├── EDIDTemplate.bt ├── ELFTemplate.bt ├── ELFTemplate.new.bt ├── EMFTemplate.bt ├── EOTTemplate.bt ├── EVSBTemplate.bt ├── EXETemplate.bt ├── EXETemplate2.bt ├── FAT16Template.bt ├── FLVTemplate.bt ├── GIFTemplate.bt ├── GPTTemplate.bt ├── GZipTemplate.bt ├── GeoTIFTemplate.bt ├── GocleverTemplate.bt ├── ICOTemplate.bt ├── ISOBMFTemplate.bt ├── InspectorDates.bt ├── InspectorWithMP4DateTime.bt ├── JPGTemplate.bt ├── LNKTemplate.bt ├── MBRTemplate.bt ├── MBRTemplateFAT.bt ├── MFTRecord.bt ├── MIDITemplate.bt ├── MOBITemplate.bt ├── MP3Template.bt ├── MP4Template.bt ├── Mifare1kTemplate.bt ├── Mifare4kTemplate.bt ├── NetflowVersion5.bt ├── OGGTemplate.bt ├── OrCAD3.20a_LIB.bt ├── OrCad3.20a_SCH.bt ├── OscarItemTemplate.bt ├── PALTemplate.bt ├── PCAPTemplate.bt ├── PCXTemplate.bt ├── PDFTemplate.bt ├── PETemplate.bt ├── PNG12Template.bt ├── PNGTemplate.bt ├── PSFTemplate.bt ├── PYCTemplate.bt ├── RARTemplate.bt ├── RDBTemplate.bt ├── RESTemplate.bt ├── RIFFTemplate.bt ├── RegistryHive.bt ├── RegistryPolicyFileTemplate.bt ├── SF2Template.bt ├── SHPTemplate.bt ├── SHXTemplate.bt ├── SRecTemplate.bt ├── SSPTemplate.bt ├── STLTemplate.bt ├── SWFTemplate.bt ├── SinclairMicrodriveImage.bt ├── TGATemplate.bt ├── TIFTemplate.bt ├── TOCTemplate.bt ├── TTFTemplate.bt ├── TacxTemplate.bt ├── VHDTemplate.bt ├── WAVTemplate.bt ├── WAVTemplateAdv.bt ├── WMFTemplate.bt ├── WinhexPosTemplate.bt ├── ZIPTemplate.bt ├── ZIPTemplateAdv.bt ├── comment.bt ├── comment_error.bt ├── exFATTemplate.bt ├── stringlit.bt ├── stringlit_error.bt └── test.bt ├── simple.bt ├── stringlit.bt ├── stringlit_error.bt └── test.bt /.gitignore: -------------------------------------------------------------------------------- 1 | *.sdf 2 | *.opensdf 3 | *.suo 4 | Release/ 5 | Debug/ 6 | My Amplifier XE Results */ 7 | actual.out 8 | expected.out 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # btparser 2 | 3 | Lexer/Parser for 010 Editor's Binary Templates. Currently not very far developed, but lexing appears to be working. 4 | 5 | **Licensed under GPLv3, make sure to take this into consideration.** 6 | -------------------------------------------------------------------------------- /btparser.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.40629.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "btparser", "btparser\btparser.vcxproj", "{B0411C78-2F06-49E0-8DE9-5C52A466F5DE}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release|Win32 = Release|Win32 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {B0411C78-2F06-49E0-8DE9-5C52A466F5DE}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {B0411C78-2F06-49E0-8DE9-5C52A466F5DE}.Debug|Win32.Build.0 = Debug|Win32 18 | {B0411C78-2F06-49E0-8DE9-5C52A466F5DE}.Debug|x64.ActiveCfg = Debug|x64 19 | {B0411C78-2F06-49E0-8DE9-5C52A466F5DE}.Debug|x64.Build.0 = Debug|x64 20 | {B0411C78-2F06-49E0-8DE9-5C52A466F5DE}.Release|Win32.ActiveCfg = Release|Win32 21 | {B0411C78-2F06-49E0-8DE9-5C52A466F5DE}.Release|Win32.Build.0 = Release|Win32 22 | {B0411C78-2F06-49E0-8DE9-5C52A466F5DE}.Release|x64.ActiveCfg = Release|x64 23 | {B0411C78-2F06-49E0-8DE9-5C52A466F5DE}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /btparser/.gitignore: -------------------------------------------------------------------------------- 1 | Debug/ 2 | Release/ 3 | -------------------------------------------------------------------------------- /btparser/ast.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "lexer.h" 4 | #include 5 | 6 | namespace AST 7 | { 8 | using namespace std; 9 | 10 | template 11 | using uptr = unique_ptr; 12 | 13 | template 14 | static typename enable_if < !is_array::value, unique_ptr>::type make_uptr(Args && ... args) 15 | { 16 | return uptr(new T(std::forward(args)...)); 17 | } 18 | 19 | using Operator = Lexer::Token; //TODO 20 | using Type = Lexer::Token; //TODO 21 | 22 | /* 23 | (2.1) - const can be combined with any type specifier except itself. 24 | (2.2) - volatile can be combined with any type specifier except itself. 25 | (2.3) - signed or unsigned can be combined with char, long, short, or int. 26 | (2.4) - short or long can be combined with int. 27 | (2.5) - long can be combined with double. 28 | (2.6) - long can be combined with long. 29 | "The signed specifier forces char objects to be signed; it is redundant in other contexts." 30 | */ 31 | 32 | class StatDecl //base class for every node 33 | { 34 | public: 35 | virtual ~StatDecl() {} 36 | }; 37 | 38 | class Stat : public StatDecl //statement (expressions, control, block) 39 | { 40 | }; 41 | 42 | class Block : public Stat //block 43 | { 44 | vector> mStatDecls; 45 | public: 46 | explicit Block(vector> statDecls) 47 | : mStatDecls(move(statDecls)) {} 48 | }; 49 | 50 | class Expr : public Stat //expression 51 | { 52 | public: 53 | virtual ~Expr() {} 54 | }; 55 | 56 | class Return : public Stat 57 | { 58 | uptr mExpr; 59 | public: 60 | explicit Return(uptr expr) 61 | : mExpr(move(expr)) {} 62 | }; 63 | 64 | class Decl : public StatDecl //declaration (variables/types) 65 | { 66 | }; 67 | 68 | class BuiltinVar : public Decl //built-in variable declaration (int x;) 69 | { 70 | Type mType; 71 | string mName; 72 | public: 73 | explicit BuiltinVar(Type type, const string & id) 74 | : mType(type), mName(id) {} 75 | }; 76 | 77 | class Struct : public Decl //struct declaration (can contain code, not just declarations) 78 | { 79 | string mName; 80 | uptr mBlock; 81 | public: 82 | explicit Struct(const string & id, uptr block) 83 | : mName(id), mBlock(move(block)) {} 84 | }; 85 | 86 | class StructVar : public Decl //struct variable declaration: (struct {...} x;) 87 | { 88 | string mVarName; //name of the variable 89 | string mStructName; //name of the struct 90 | public: 91 | explicit StructVar(const string & varName, const string & structName) 92 | : mVarName(varName), mStructName(structName) {} 93 | }; 94 | }; -------------------------------------------------------------------------------- /btparser/btparser.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | 29 | 30 | Header Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | Header Files 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | 49 | 50 | Header Files 51 | 52 | 53 | -------------------------------------------------------------------------------- /btparser/btparser.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /btparser/keywords.h: -------------------------------------------------------------------------------- 1 | #ifndef DEF_KEYWORD 2 | // Don't create errors if someone uses this by mistake 3 | #define DEF_KEYWORD(x) 4 | #endif 5 | 6 | DEF_KEYWORD(if) 7 | DEF_KEYWORD(do) 8 | DEF_KEYWORD(for) 9 | DEF_KEYWORD(else) 10 | DEF_KEYWORD(while) 11 | 12 | DEF_KEYWORD(case) 13 | DEF_KEYWORD(switch) 14 | DEF_KEYWORD(default) 15 | 16 | DEF_KEYWORD(break) 17 | DEF_KEYWORD(return) 18 | DEF_KEYWORD(continue) 19 | 20 | DEF_KEYWORD(enum) 21 | DEF_KEYWORD(struct) 22 | DEF_KEYWORD(typedef) 23 | DEF_KEYWORD(sizeof) 24 | DEF_KEYWORD(void) 25 | DEF_KEYWORD(union) 26 | DEF_KEYWORD(local) 27 | 28 | DEF_KEYWORD(signed) 29 | DEF_KEYWORD(unsigned) 30 | 31 | DEF_KEYWORD(bool) 32 | DEF_KEYWORD(char) 33 | DEF_KEYWORD(uchar) 34 | DEF_KEYWORD(wchar_t) 35 | DEF_KEYWORD(char16_t) 36 | DEF_KEYWORD(char32_t) 37 | 38 | DEF_KEYWORD(byte) 39 | DEF_KEYWORD(ubyte) 40 | DEF_KEYWORD(short) 41 | DEF_KEYWORD(ushort) 42 | DEF_KEYWORD(int) 43 | DEF_KEYWORD(uint) 44 | DEF_KEYWORD(long) 45 | DEF_KEYWORD(ulong) 46 | 47 | DEF_KEYWORD(int8) 48 | DEF_KEYWORD(uint8) 49 | DEF_KEYWORD(int16) 50 | DEF_KEYWORD(uint16) 51 | DEF_KEYWORD(int32) 52 | DEF_KEYWORD(uint32) 53 | DEF_KEYWORD(int64) 54 | DEF_KEYWORD(uint64) 55 | 56 | DEF_KEYWORD(BOOL) 57 | DEF_KEYWORD(CHAR) 58 | DEF_KEYWORD(BYTE) 59 | DEF_KEYWORD(WORD) 60 | DEF_KEYWORD(DWORD) 61 | DEF_KEYWORD(QWORD) 62 | 63 | DEF_KEYWORD(float) 64 | DEF_KEYWORD(double) 65 | DEF_KEYWORD(string) 66 | DEF_KEYWORD(time_t) 67 | DEF_KEYWORD(quad) 68 | 69 | DEF_KEYWORD(DOSDATE) 70 | DEF_KEYWORD(DOSTIME) 71 | DEF_KEYWORD(FILETIME) 72 | DEF_KEYWORD(OLETIME) 73 | DEF_KEYWORD(UQUAD) 74 | DEF_KEYWORD(LONGLONG) 75 | DEF_KEYWORD(ULONG_PTR) 76 | DEF_KEYWORD(VQUAD) 77 | DEF_KEYWORD(UINT32) 78 | 79 | DEF_KEYWORD(true) 80 | DEF_KEYWORD(false) 81 | DEF_KEYWORD(nullptr) 82 | DEF_KEYWORD(NULL) -------------------------------------------------------------------------------- /btparser/lexer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class Lexer 10 | { 11 | public: 12 | enum Token 13 | { 14 | //status tokens 15 | tok_eof, 16 | tok_error, 17 | 18 | //keywords 19 | #define DEF_KEYWORD(keyword) tok_##keyword, 20 | #include "keywords.h" 21 | #undef DEF_KEYWORD 22 | 23 | //others 24 | tok_identifier, //[a-zA-Z_][a-zA-Z0-9_] 25 | tok_number, //(0x[0-9a-fA-F]+)|([0-9]+) 26 | tok_stringlit, //"([^\\"]|\\([\\"'?abfnrtv0]|x[0-9a-fA-f]{2}))*" 27 | tok_charlit, //'([^\\]|\\([\\"'?abfnrtv0]|x[0-9a-fA-f]{2}))' 28 | 29 | //operators 30 | #define DEF_OP_TRIPLE(enumval, ch1, ch2, ch3) tok_##enumval, 31 | #define DEF_OP_DOUBLE(enumval, ch1, ch2) tok_##enumval, 32 | #define DEF_OP_SINGLE(enumval, ch1) tok_##enumval, 33 | #include "operators.h" 34 | #undef DEF_OP_TRIPLE 35 | #undef DEF_OP_DOUBLE 36 | #undef DEF_OP_SINGLE 37 | }; 38 | 39 | struct TokenState 40 | { 41 | Token Token = tok_eof; 42 | std::string IdentifierStr; //tok_identifier 43 | uint64_t NumberVal = 0; //tok_number 44 | std::string StringLit; //tok_stringlit 45 | char CharLit = '\0'; //tok_charlit 46 | 47 | size_t CurLine = 0; 48 | size_t LineIndex = 0; 49 | 50 | bool IsType() const 51 | { 52 | return Token >= tok_signed && Token <= tok_UINT32; 53 | } 54 | }; 55 | 56 | explicit Lexer(); 57 | bool ReadInputFile(const std::string & filename); 58 | void SetInputData(const std::string & data); 59 | bool DoLexing(std::vector & tokens, std::string & error); 60 | bool Test(const std::function & lexEnum, bool output = true); 61 | std::string TokString(Token tok); 62 | std::string TokString(const TokenState & ts); 63 | 64 | private: 65 | TokenState mState; 66 | std::vector mWarnings; 67 | std::string mError; 68 | std::vector mInput; 69 | size_t mIndex = 0; 70 | bool mIsHexNumberVal = false; 71 | std::string mNumStr; 72 | int mLastChar = ' '; 73 | std::unordered_map mKeywordMap; 74 | std::unordered_map mReverseTokenMap; 75 | std::unordered_map mOpTripleMap; 76 | std::unordered_map mOpDoubleMap; 77 | std::unordered_map mOpSingleMap; 78 | 79 | void resetLexerState(); 80 | void setupTokenMaps(); 81 | Token reportError(const std::string & error); 82 | void reportWarning(const std::string & warning); 83 | int peekChar(size_t distance = 0); 84 | int readChar(); 85 | bool checkString(const std::string & expected); 86 | int nextChar(); 87 | void signalNewLine(); 88 | Token getToken(); 89 | }; -------------------------------------------------------------------------------- /btparser/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "testfiles.h" 4 | #include "lexer.h" 5 | #include "parser.h" 6 | #include "helpers.h" 7 | 8 | bool TestLexer(Lexer & lexer, const std::string & filename) 9 | { 10 | if(!lexer.ReadInputFile("tests\\" + filename)) 11 | { 12 | printf("failed to read \"%s\"\n", filename.c_str()); 13 | return false; 14 | } 15 | std::string actual; 16 | actual.reserve(65536); 17 | auto success = lexer.Test([&](const std::string & line) 18 | { 19 | actual.append(line); 20 | }); 21 | std::string expected; 22 | if(FileHelper::ReadAllText("tests\\exp_lex\\" + filename, expected) && expected == actual) 23 | { 24 | printf("lexer test for \"%s\" success!\n", filename.c_str()); 25 | return true; 26 | } 27 | if(success) 28 | return true; 29 | printf("lexer test for \"%s\" failed...\n", filename.c_str()); 30 | FileHelper::WriteAllText("expected.out", expected); 31 | FileHelper::WriteAllText("actual.out", actual); 32 | return false; 33 | } 34 | 35 | bool DebugLexer(Lexer & lexer, const std::string & filename, bool output) 36 | { 37 | if(!lexer.ReadInputFile("tests\\" + filename)) 38 | { 39 | printf("failed to read \"%s\"\n", filename.c_str()); 40 | return false; 41 | } 42 | auto success = lexer.Test([](const std::string & line) 43 | { 44 | printf("%s", line.c_str()); 45 | }, output); 46 | if(output) 47 | puts(""); 48 | return success; 49 | } 50 | 51 | void GenerateExpected(Lexer & lexer, const std::string & filename) 52 | { 53 | if(!lexer.ReadInputFile("tests\\" + filename)) 54 | { 55 | printf("failed to read \"%s\"\n", filename.c_str()); 56 | return; 57 | } 58 | std::string actual; 59 | actual.reserve(65536); 60 | lexer.Test([&](const std::string & line) 61 | { 62 | actual.append(line); 63 | }); 64 | FileHelper::WriteAllText("tests\\exp_lex\\" + filename, actual); 65 | } 66 | 67 | void GenerateExpectedTests() 68 | { 69 | Lexer lexer; 70 | for(auto file : testFiles) 71 | GenerateExpected(lexer, file); 72 | } 73 | 74 | void RunLexerTests() 75 | { 76 | Lexer lexer; 77 | for(auto file : testFiles) 78 | TestLexer(lexer, file); 79 | } 80 | 81 | void DebugLexerTests(bool output = true) 82 | { 83 | Lexer lexer; 84 | for(auto file : testFiles) 85 | DebugLexer(lexer, file, output); 86 | } 87 | 88 | bool DebugParser(const std::string & filename) 89 | { 90 | Parser parser; 91 | std::string error; 92 | if(!parser.ParseFile("tests\\" + filename, error)) 93 | { 94 | printf("ParseFile failed: %s\n", error.c_str()); 95 | return false; 96 | } 97 | puts("ParseFile success!"); 98 | return true; 99 | } 100 | 101 | int main() 102 | { 103 | //GenerateExpectedTests(); 104 | auto ticks = GetTickCount(); 105 | DebugParser("simple.bt"); 106 | //Lexer lexer; 107 | //DebugLexer(lexer, "AndroidManifestTemplate.bt", false); 108 | //RunLexerTests(); 109 | printf("finished in %ums\n", GetTickCount() - ticks); 110 | system("pause"); 111 | return 0; 112 | } -------------------------------------------------------------------------------- /btparser/operators.h: -------------------------------------------------------------------------------- 1 | #ifndef DEF_OP_TRIPLE 2 | #define DEF_OP_TRIPLE(enumval, ch1, ch2, ch3) 3 | #endif //DEF_OP_TRIPLE 4 | #ifndef DEF_OP_DOUBLE 5 | #define DEF_OP_DOUBLE(enumval, ch1, ch2) 6 | #endif //DEF_OP_DOUBLE 7 | #ifndef DEF_OP_SINGLE 8 | #define DEF_OP_SINGLE(enumval, ch1) 9 | #endif //DEF_OP_SINGLE 10 | 11 | DEF_OP_TRIPLE(ass_shl, '<', '<', '=') 12 | DEF_OP_TRIPLE(ass_shr, '>', '>', '=') 13 | 14 | DEF_OP_DOUBLE(op_inc, '+', '+') 15 | DEF_OP_DOUBLE(op_dec, '-', '-') 16 | DEF_OP_DOUBLE(op_shl, '<', '<') 17 | DEF_OP_DOUBLE(op_shr, '>', '>') 18 | 19 | DEF_OP_DOUBLE(lop_le_eq, '<', '=') 20 | DEF_OP_DOUBLE(lop_gr_eq, '>', '=') 21 | DEF_OP_DOUBLE(lop_eq, '=', '=') 22 | DEF_OP_DOUBLE(lop_not_eq, '!', '=') 23 | DEF_OP_DOUBLE(lop_and, '&', '&') 24 | DEF_OP_DOUBLE(lop_or, '|', '|') 25 | 26 | DEF_OP_DOUBLE(ass_plus, '+', '=') 27 | DEF_OP_DOUBLE(ass_min, '-', '=') 28 | DEF_OP_DOUBLE(ass_mul, '*', '=') 29 | DEF_OP_DOUBLE(ass_div, '/', '=') 30 | DEF_OP_DOUBLE(ass_mod, '%', '=') 31 | DEF_OP_DOUBLE(ass_and, '&', '=') 32 | DEF_OP_DOUBLE(ass_xor, '^', '=') 33 | DEF_OP_DOUBLE(ass_or, '|', '=') 34 | 35 | DEF_OP_SINGLE(paropen, '(') 36 | DEF_OP_SINGLE(parclose, ')') 37 | DEF_OP_SINGLE(bropen, '{') 38 | DEF_OP_SINGLE(brclose, '}') 39 | DEF_OP_SINGLE(subopen, '[') 40 | DEF_OP_SINGLE(subclose, ']') 41 | DEF_OP_SINGLE(member, '.') 42 | DEF_OP_SINGLE(comma, ',') 43 | DEF_OP_SINGLE(tenary, '?') 44 | DEF_OP_SINGLE(colon, ':') 45 | DEF_OP_SINGLE(assign, '=') 46 | DEF_OP_SINGLE(semic, ';') 47 | 48 | DEF_OP_SINGLE(op_mul, '*') 49 | DEF_OP_SINGLE(op_div, '/') 50 | DEF_OP_SINGLE(op_mod, '%') 51 | DEF_OP_SINGLE(op_plus, '+') 52 | DEF_OP_SINGLE(op_min, '-') 53 | DEF_OP_SINGLE(op_neg, '~') 54 | DEF_OP_SINGLE(op_xor, '^') 55 | DEF_OP_SINGLE(op_and, '&') 56 | DEF_OP_SINGLE(op_or, '|') 57 | 58 | DEF_OP_SINGLE(lop_le, '<') 59 | DEF_OP_SINGLE(lop_gr, '>') 60 | DEF_OP_SINGLE(lop_not, '!') -------------------------------------------------------------------------------- /btparser/parser.cpp: -------------------------------------------------------------------------------- 1 | #include "parser.h" 2 | 3 | using namespace AST; 4 | 5 | Parser::Parser() 6 | : CurToken(Lexer::TokenState()) 7 | { 8 | } 9 | 10 | bool Parser::ParseFile(const string & filename, string & error) 11 | { 12 | if(!mLexer.ReadInputFile(filename)) 13 | { 14 | error = "failed to read input file"; 15 | return false; 16 | } 17 | if(!mLexer.DoLexing(mTokens, error)) 18 | return false; 19 | CurToken = mTokens[0]; 20 | mBinaryTemplate = ParseBinaryTemplate(); 21 | return !!mBinaryTemplate; 22 | } 23 | 24 | void Parser::NextToken() 25 | { 26 | if(mIndex < mTokens.size() - 1) 27 | { 28 | mIndex++; 29 | CurToken = mTokens[mIndex]; 30 | } 31 | } 32 | 33 | void Parser::ReportError(const std::string & error) 34 | { 35 | mErrors.push_back(Error(error)); 36 | } 37 | 38 | uptr Parser::ParseBinaryTemplate() 39 | { 40 | vector> statDecls; 41 | while(true) 42 | { 43 | auto statDecl = ParseStatDecl(); 44 | if(!statDecl) 45 | break; 46 | statDecls.push_back(move(statDecl)); 47 | } 48 | auto binaryTemplate = make_uptr(move(statDecls)); 49 | if(CurToken.Token != Lexer::tok_eof) 50 | { 51 | ReportError("last token is not EOF"); 52 | return nullptr; 53 | } 54 | return move(binaryTemplate); 55 | } 56 | 57 | uptr Parser::ParseStatDecl() 58 | { 59 | auto decl = ParseDecl(); 60 | if(decl) 61 | return move(decl); 62 | 63 | auto stat = ParseStat(); 64 | if(stat) 65 | return move(stat); 66 | 67 | ReportError("failed to parse StatDecl"); 68 | return nullptr; 69 | } 70 | 71 | uptr Parser::ParseStat() 72 | { 73 | auto block = ParseBlock(); 74 | if(block) 75 | return move(block); 76 | 77 | auto expr = ParseExpr(); 78 | if(expr) 79 | return move(expr); 80 | 81 | auto ret = ParseReturn(); 82 | if(ret) 83 | return move(ret); 84 | 85 | ReportError("failed to parse Stat"); 86 | return nullptr; 87 | } 88 | 89 | uptr Parser::ParseBlock() 90 | { 91 | if(CurToken.Token != Lexer::tok_bropen) //'{' 92 | return nullptr; 93 | NextToken(); 94 | 95 | vector> statDecls; 96 | 97 | if(CurToken.Token == Lexer::tok_brclose) //'}' 98 | { 99 | NextToken(); 100 | return make_uptr(move(statDecls)); 101 | } 102 | 103 | ReportError("failed to parse Block"); 104 | return nullptr; 105 | } 106 | 107 | uptr Parser::ParseExpr() 108 | { 109 | return nullptr; 110 | } 111 | 112 | uptr Parser::ParseReturn() 113 | { 114 | if(CurToken.Token == Lexer::tok_return) 115 | { 116 | NextToken(); 117 | auto expr = ParseExpr(); 118 | if(!expr) 119 | { 120 | ReportError("failed to parse Return (ParseExpr failed)"); 121 | return nullptr; 122 | } 123 | return make_uptr(move(expr)); 124 | } 125 | return nullptr; 126 | } 127 | 128 | uptr Parser::ParseDecl() 129 | { 130 | auto builtin = ParseBuiltinVar(); 131 | if(builtin) 132 | return move(builtin); 133 | auto stru = ParseStruct(); 134 | if(stru) 135 | return move(stru); 136 | return nullptr; 137 | } 138 | 139 | uptr Parser::ParseBuiltinVar() 140 | { 141 | if(CurToken.Token == Lexer::tok_uint) //TODO: properly handle types 142 | { 143 | auto type = CurToken.Token; 144 | NextToken(); 145 | if(CurToken.Token != Lexer::tok_identifier) 146 | { 147 | ReportError("failed to parse BuiltinVar (no identifier)"); 148 | return nullptr; 149 | } 150 | auto id = CurToken.IdentifierStr; 151 | NextToken(); 152 | if(CurToken.Token != Lexer::tok_semic) 153 | { 154 | ReportError("failed to parse BuiltinVar (no semicolon)"); 155 | return nullptr; 156 | } 157 | NextToken(); 158 | return make_uptr(type, id); 159 | } 160 | return nullptr; 161 | } 162 | 163 | uptr Parser::ParseStruct() 164 | { 165 | if(CurToken.Token == Lexer::tok_struct) 166 | { 167 | NextToken(); 168 | string id; 169 | if(CurToken.Token == Lexer::tok_identifier) 170 | { 171 | id = CurToken.IdentifierStr; 172 | NextToken(); 173 | } 174 | auto block = ParseBlock(); 175 | if(!block) 176 | { 177 | ReportError("failed to parse Struct (ParseBlock)"); 178 | return nullptr; 179 | } 180 | return make_uptr(id, move(block)); 181 | } 182 | return nullptr; 183 | } 184 | 185 | AST::uptr Parser::ParseStructVar() 186 | { 187 | return nullptr; 188 | } 189 | -------------------------------------------------------------------------------- /btparser/parser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "lexer.h" 4 | #include "ast.h" 5 | 6 | class Parser 7 | { 8 | public: 9 | struct Error 10 | { 11 | explicit Error(const std::string & text) 12 | : text(text) {} 13 | 14 | std::string text; 15 | }; 16 | 17 | explicit Parser(); 18 | bool ParseFile(const std::string & filename, std::string & error); 19 | 20 | private: 21 | Lexer mLexer; 22 | std::vector mTokens; 23 | size_t mIndex = 0; 24 | AST::uptr mBinaryTemplate = nullptr; 25 | std::vector mErrors; 26 | 27 | Lexer::TokenState CurToken; 28 | void NextToken(); 29 | void ReportError(const std::string & error); 30 | 31 | AST::uptr ParseBinaryTemplate(); 32 | AST::uptr ParseStatDecl(); 33 | 34 | AST::uptr ParseStat(); 35 | AST::uptr ParseBlock(); 36 | AST::uptr ParseExpr(); 37 | AST::uptr ParseReturn(); 38 | 39 | AST::uptr ParseDecl(); 40 | AST::uptr ParseBuiltinVar(); 41 | AST::uptr ParseStruct(); 42 | AST::uptr ParseStructVar(); 43 | }; -------------------------------------------------------------------------------- /btparser/testfiles.h: -------------------------------------------------------------------------------- 1 | static const char* testFiles[] = 2 | { 3 | "test.bt", 4 | "comment.bt", 5 | "comment_error.bt", 6 | "stringlit.bt", 7 | "stringlit_error.bt", 8 | "CDATemplate.bt", 9 | "NetflowVersion5.bt", 10 | "SHXTemplate.bt", 11 | "WinhexPosTemplate.bt", 12 | "Mifare1kTemplate.bt", 13 | "PALTemplate.bt", 14 | "GocleverTemplate.bt", 15 | "OGGTemplate.bt", 16 | "STLTemplate.bt", 17 | "SinclairMicrodriveImage.bt", 18 | "RDBTemplate.bt", 19 | "DBFTemplate.bt", 20 | "Mifare4kTemplate.bt", 21 | "GPTTemplate.bt", 22 | "SSPTemplate.bt", 23 | "SHPTemplate.bt", 24 | "SRecTemplate.bt", 25 | "FLVTemplate.bt", 26 | "LUKSTemplate.bt", 27 | "PCXTemplate.bt", 28 | "UTMPTemplate.bt", 29 | "ElTorito.bt", 30 | "DMPTemplate.bt", 31 | "OscarItemTemplate.bt", 32 | "EOTTemplate.bt", 33 | "ISOTemplate.bt", 34 | "CLASSTemplate2.bt", 35 | "EVSBTemplate.bt", 36 | "BMPTemplate.bt", 37 | "TGATemplate.bt", 38 | "TOCTemplate.bt", 39 | "CABTemplate.bt", 40 | "RIFFTemplate.bt", 41 | "AndroidManifestTemplate.bt", 42 | "InspectorWithMP4DateTime.bt", 43 | "FAT16Template.bt", 44 | "PNGTemplate.bt", 45 | "ICOTemplate.bt", 46 | "RegistryPolicyFileTemplate.bt", 47 | "VHDTemplate.bt", 48 | "ISOBMFTemplate.bt", 49 | "PCAPTemplate.bt", 50 | "AVITemplate.bt", 51 | "ZIPTemplate.bt", 52 | "CRXTemplate.bt", 53 | "MIDITemplate.bt", 54 | "GZipTemplate.bt", 55 | "GIFTemplate.bt", 56 | "InspectorDates.bt", 57 | "WAVTemplate.bt", 58 | "RegistryHive.bt", 59 | "EMFTemplate.bt", 60 | "ROMFS.bt", 61 | "OrCad3.20a_SCH.bt", 62 | "MP4Template.bt", 63 | "CLASSTemplate.bt", 64 | "WMFTemplate.bt", 65 | "LNKTemplate.bt", 66 | "OrCAD3.20a_LIB.bt", 67 | "PSFTemplate.bt", 68 | "RARTemplate.bt", 69 | "PYCTemplate.bt", 70 | "EXETemplate.bt", 71 | "PNG12Template.bt", 72 | "TacxTemplate.bt", 73 | "MFTRecord.bt", 74 | "MP3Template.bt", 75 | "MBRTemplate.bt", 76 | "WAVTemplateAdv.bt", 77 | "PDFTemplate.bt", 78 | "EXETemplate2.bt", 79 | "RESTemplate.bt", 80 | "ZIPTemplateAdv.bt", 81 | "SF2Template.bt", 82 | "MOBITemplate.bt", 83 | "MBRTemplateFAT.bt", 84 | "exFATTemplate.bt", 85 | "ELFTemplate.new.bt", 86 | "ELFTemplate.bt", 87 | "MachOTemplate.bt", 88 | "PETemplate.bt", 89 | "EDIDTemplate.bt", 90 | "GeoTIFTemplate.bt", 91 | "CLASSTemplate3.bt", 92 | "CAPTemplate.bt", 93 | "TIFTemplate.bt", 94 | "TTFTemplate.bt", 95 | "JPGTemplate.bt", 96 | "DEXTemplate.bt", 97 | "DEXTemplate.new.bt", 98 | "SWFTemplate.bt", 99 | }; -------------------------------------------------------------------------------- /btparser/tests/AndroidManifestTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v5.0.2 Binary Template 3 | // 4 | // File: AndroidManifestTemplate.bt 5 | // Author: dongmu 6 | // Revision: 1.0 7 | // Purpose: Define a template for parsing 8 | // AndroidManifest.xml binary files. 9 | //-------------------------------------- 10 | 11 | // Define the structures used in a 12 | // AndroidManifest.xml binary file 13 | 14 | // Define Header 15 | typedef struct { 16 | uint magicnumber; 17 | uint filesize; 18 | } HEADER; 19 | 20 | // Define the string format 21 | typedef struct { 22 | ushort sfSize; 23 | if (sfSize > 0) 24 | { 25 | struct { 26 | char c1; 27 | char c2; 28 | } ONECHAR[ sfSize ]; 29 | } 30 | ushort sfEnd; 31 | } STRING_ITEM; 32 | 33 | 34 | // Define the string chunk 35 | typedef struct { 36 | uint scSignature; 37 | uint scSize; 38 | uint scStringCount; 39 | uint scStyleCount; 40 | uint scUNKNOWN; 41 | uint scStringPoolOffset; 42 | uint scStylePoolOffset; 43 | uint scStringOffsets[ scStringCount ] ; 44 | 45 | if (scStyleCount > 0) 46 | uint scStyleOffset[ scStylePoolOffset ]; 47 | 48 | // The Strings 49 | local int i; 50 | for (i = 0; i < scStringCount; i++) 51 | { 52 | if ((0x8+scStringPoolOffset + scStringOffsets[ i ]) < (0x8+scSize)) 53 | { 54 | FSeek(0x8+scStringPoolOffset + scStringOffsets[ i ]); 55 | STRING_ITEM strItem; 56 | } 57 | } 58 | 59 | } STRINGCHUNK; 60 | 61 | // Define the Resource chunk 62 | typedef struct { 63 | 64 | local int pos = FTell(); 65 | 66 | uint rcSignature; 67 | uint rcSize; 68 | uint rcItem[ rcSize/4 - 2 ]; 69 | 70 | } RESOURCEIDCHUNK; 71 | 72 | // Define the Start Namespace Chunk 73 | typedef struct { 74 | uint sncSignature; 75 | uint sncSize; 76 | uint sncLineNumber; 77 | uint sncUNKNOWN; 78 | uint sncPrefix; 79 | uint sncUri; 80 | } SNCHUNK; 81 | 82 | // Define the End Namespace Chunk 83 | typedef struct { 84 | uint encSignature; 85 | uint encSize; 86 | uint encLineNumber; 87 | uint encUNKNOWN; 88 | uint encPrefix; 89 | uint encUri; 90 | } ENCHUNK; 91 | 92 | // Define the Attribute Chunk 93 | typedef struct { 94 | uint acNamespaceUri; 95 | uint acName; 96 | uint acValueStr; 97 | uint acType ; 98 | uint acData; 99 | } ATTRIBUTECHUNK; 100 | 101 | 102 | // Define the Start Tag Chunk 103 | typedef struct { 104 | local int pos = FTell(); 105 | uint stcSignature; 106 | uint stcSize; 107 | uint stcLineNumber; 108 | uint stcUNKNOWN; 109 | uint stcNamespaceUri; 110 | uint stcName; 111 | uint stcFlags; 112 | uint stcAttributeCount; 113 | uint stcClassAttribute; 114 | 115 | while (FTell() != pos + stcSize) 116 | ATTRIBUTECHUNK attributeChunk; 117 | } STCHUNK; 118 | 119 | // Define the End Tag Chunk 120 | typedef struct { 121 | uint etcSignature; 122 | uint etcSize; 123 | uint etcLineNumber; 124 | uint etcUNKNOWN; 125 | uint etcNamespaceUri; 126 | uint etcName; 127 | } ETCHUNK; 128 | 129 | // Define the Text Chunk 130 | typedef struct { 131 | uint tcSignature; 132 | uint tcSize; 133 | uint tcLineNumber; 134 | uint tcUNKNOWN; 135 | uint tcName; 136 | uint tcUNKNOWN; 137 | uint tcUNNNOWN; 138 | } TEXTCHUNK; 139 | 140 | //-------------------------------------- 141 | // Define the file 142 | 143 | local uint tag; 144 | 145 | LittleEndian(); 146 | HEADER header; 147 | 148 | SetBackColor( cLtGreen ); 149 | STRINGCHUNK stringChunk; 150 | // Sometimes there are some zeros padding after the string chunk 151 | FSeek(0x8+stringChunk.scSize); 152 | 153 | SetBackColor( cLtBlue ); 154 | RESOURCEIDCHUNK resourceChunk; 155 | FSeek(resourceChunk.pos+resourceChunk.rcSize); 156 | 157 | while( !FEof() ) 158 | { 159 | // Read a tag 160 | tag = ReadUInt( FTell() ); 161 | 162 | // Read data depending upon tag 163 | if (tag == 0x00100100) 164 | { 165 | SetBackColor( cLtPurple ); 166 | SNCHUNK startNamespaceChunk; 167 | } 168 | else if (tag == 0x00100101) 169 | { 170 | SetBackColor( cLtPurple ); 171 | ENCHUNK endNamespaceChunk; 172 | } 173 | else if (tag == 0x00100102) 174 | { 175 | SetBackColor( cLtGreen ); 176 | STCHUNK startTagChunk; 177 | } 178 | else if (tag == 0x00100103) 179 | { 180 | SetBackColor( cLtGreen ); 181 | ETCHUNK endTagChunk; 182 | } 183 | else if (tag == 0x00100104) 184 | { 185 | SetBackColor( cLtBlue ); 186 | TEXTCHUNK TextChunk; 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /btparser/tests/BMPTemplate.bt: -------------------------------------------------------------------------------- 1 | //----------------------------------- 2 | //--- 010 Editor v2.0 Binary Template 3 | // 4 | // File: BMPTemplate.bt 5 | // Author: SweetScape Software 6 | // Revision: 2.2 7 | // Purpose: Defines a template for 8 | // parsing BMP image files. 9 | //----------------------------------- 10 | 11 | // Define structures used in BMP files 12 | 13 | typedef struct { // bmfh 14 | CHAR bfType[2]; 15 | DWORD bfSize; 16 | WORD bfReserved1; 17 | WORD bfReserved2; 18 | DWORD bfOffBits; 19 | } BITMAPFILEHEADER; 20 | 21 | typedef struct { // bmih 22 | DWORD biSize; 23 | LONG biWidth; 24 | LONG biHeight; 25 | WORD biPlanes; 26 | WORD biBitCount; 27 | DWORD biCompression; 28 | DWORD biSizeImage; 29 | LONG biXPelsPerMeter; 30 | LONG biYPelsPerMeter; 31 | DWORD biClrUsed; 32 | DWORD biClrImportant; 33 | } BITMAPINFOHEADER; 34 | 35 | typedef struct { // rgbq 36 | UBYTE rgbBlue; 37 | UBYTE rgbGreen; 38 | UBYTE rgbRed; 39 | UBYTE rgbReserved; 40 | } RGBQUAD ; 41 | 42 | typedef struct { // rgbt 43 | UBYTE rgbBlue; 44 | UBYTE rgbGreen; 45 | UBYTE rgbRed; 46 | } RGBTRIPLE ; 47 | 48 | //--------------------------------------------- 49 | // Custom read functions for color types - this allows the 50 | // color to be displayed without having to open up the structure. 51 | 52 | string ReadRGBQUAD( RGBQUAD &a ) 53 | { 54 | string s; 55 | SPrintf( s, "#%02X%02X%02X%02X", (int)a.rgbReserved, (int)a.rgbRed, (int)a.rgbGreen, (int)a.rgbBlue ); 56 | return s; 57 | } 58 | 59 | string ReadRGBTRIPLE( RGBTRIPLE &a ) 60 | { 61 | string s; 62 | SPrintf( s, "#%02X%02X%02X", (int)a.rgbRed, (int)a.rgbGreen, (int)a.rgbBlue ); 63 | return s; 64 | } 65 | 66 | //--------------------------------------------- 67 | 68 | // Define the headers 69 | LittleEndian(); 70 | SetBackColor( cLtGray ); 71 | BITMAPFILEHEADER bmfh; 72 | BITMAPINFOHEADER bmih; 73 | 74 | // Check for header 75 | if( bmfh.bfType != "BM" ) 76 | { 77 | Warning( "File is not a bitmap. Template stopped." ); 78 | return -1; 79 | } 80 | 81 | // Define the color table 82 | if( (bmih.biBitCount != 24) && (bmih.biBitCount != 32) ) 83 | { 84 | SetBackColor( cLtAqua ); 85 | if( bmih.biClrUsed > 0 ) 86 | RGBQUAD aColors[ bmih.biClrUsed ]; 87 | else 88 | RGBQUAD aColors[ 1 << bmih.biBitCount ]; 89 | } 90 | 91 | // Define the bytes of the data 92 | SetBackColor( cNone ); 93 | if( bmih.biCompression > 0 ) 94 | { 95 | // Bytes are compressed 96 | if( bmih.biSizeImage > 0 ) 97 | UBYTE rleData[ bmih.biSizeImage ]; 98 | else 99 | UBYTE rleData[ bmfh.bfSize - FTell() ]; 100 | } 101 | else 102 | { 103 | // Calculate bytes per line and padding required 104 | local int bytesPerLine = (int)Ceil( bmih.biWidth * bmih.biBitCount / 8.0 ); 105 | local int padding = 4 - (bytesPerLine % 4); 106 | if( padding == 4 ) 107 | padding = 0; 108 | 109 | // Define each line of the image 110 | struct BITMAPLINE { 111 | 112 | // Define color data 113 | if( bmih.biBitCount < 8 ) 114 | UBYTE imageData[ bytesPerLine ]; 115 | else if( bmih.biBitCount == 8 ) 116 | UBYTE colorIndex[ bmih.biWidth ]; 117 | else if( bmih.biBitCount == 24 ) 118 | RGBTRIPLE colors[ bmih.biWidth ]; 119 | else if( bmih.biBitCount == 32 ) 120 | RGBQUAD colors[ bmih.biWidth ]; 121 | 122 | // Pad if necessary 123 | if( padding != 0 ) 124 | UBYTE padBytes[ padding ]; 125 | 126 | } lines[ bmih.biHeight ] ; 127 | } -------------------------------------------------------------------------------- /btparser/tests/CABTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v3.2.2 Binary Template 3 | // 4 | // File: cabtemplate.bt 5 | // Author: Alex McDonnell 6 | // Revision: 0.1 7 | // Purpose: Parse Microsoft CAB files 8 | // Changes: 9 | // 0.2 (SweetScape): 10 | // - Allow for multiple flags to be set at the same time 11 | //-------------------------------------- 12 | 13 | // Define structures used in CAB files 14 | 15 | typedef struct { 16 | //header 17 | char signature[4]; /* 'MSCF' */ 18 | uint reserved1; /* 0x00000000 */ 19 | uint cbCabinet; /* size of this cabinet file in bytes */ 20 | uint reserved2; /* 0x00000000 */ 21 | uint coffFiles; /* offset of the first CFFILE entry */ 22 | uint reserved3; /* 0x00000000 */ 23 | ubyte versionMinor; /* cabinet file format version, minor 0x03 */ 24 | ubyte versionMajor; /* cabinet file format version, major 0x01 */ 25 | ushort cFolders; /* number of CFFOLDER entries in this cabinet */ 26 | ushort cFiles; /* number of CFFILE entries in this cabinet */ 27 | ushort flags; /* cabinet file option indicators 0x0001 0x0002 0x0004 only*/ 28 | ushort setID; /* must be the same for all cabinets in a set */ 29 | ushort iCabinet; /* number of this cabinet file in a set */ 30 | 31 | if(flags & 4){ 32 | 33 | ushort cbCFHeader; /* (optional) size of per-cabinet reserved area */ 34 | ubyte cbCFFolder; /* (optional) size of per-folder reserved area */ 35 | ubyte cbCFData; /* (optional) size of per-datablock reserved area */ 36 | 37 | if(cbCFHeader > 0) 38 | char abReserve[cbCFHeader]; /* (optional) per-cabinet reserved area */ 39 | 40 | } 41 | if(flags & 1){ 42 | 43 | char szCabinetPrev[];/* (optional) name of previous cabinet file */ 44 | char szDiskPrev[]; /* (optional) name of previous disk */ 45 | 46 | } 47 | if(flags & 2){ 48 | 49 | char szCabinetNext[]; /* (optional) name of next cabinet file */ 50 | char szDiskNext[]; /* (optional) name of next disk */ 51 | 52 | } 53 | 54 | } CFHEADER; 55 | 56 | LittleEndian(); 57 | CFHEADER header; 58 | local uint counter = 0; 59 | 60 | typedef struct { 61 | //folder 62 | uint coffCabStart; /* offset of the first CFDATA block in this folder */ 63 | ushort cCFData; /* number of CFDATA blocks in this folder */ 64 | ushort typeCompress; /* compression type indicator */ 65 | 66 | if( exists(header.cbCFFolder)) 67 | char abReserve[header.cbCFFolder]; /* (optional) per-folder reserved area */ 68 | 69 | } CFFOLDER; 70 | 71 | typedef struct { 72 | //file 73 | uint cbFile; /* uncompressed size of this file in bytes */ 74 | uint uoffFolderStart; /* uncompressed offset of this file in the folder */ 75 | ushort iFolder; /* index into the CFFOLDER area */ 76 | DOSDATE date; /* date stamp for this file */ 77 | DOSTIME time; /* time stamp for this file */ 78 | ushort attribs; /* attribute flags for this file */ 79 | char szName[]; /* name of this file */ 80 | } CFFILE; 81 | 82 | typedef struct { 83 | //data 84 | uint csum; /* checksum of this CFDATA entry */ 85 | ushort cbData; /* number of compressed bytes in this block */ 86 | ushort cbUncomp; /* number of uncompressed bytes in this block */ 87 | 88 | if( exists(header.cbCFData)) 89 | char abReserve[header.cbCFData]; /* (optional) per-datablock reserved area */ 90 | 91 | char ab[cbData]; /* compressed data bytes */ 92 | } CFDATA; 93 | 94 | while(header.cFolders > counter){ 95 | 96 | counter++; 97 | CFFOLDER folder; 98 | 99 | } 100 | 101 | counter = 0; 102 | 103 | while(header.cFiles > counter){ 104 | 105 | counter++; 106 | CFFILE file; 107 | 108 | } 109 | 110 | counter = 0; 111 | 112 | while(folder.cCFData > counter){ 113 | 114 | counter++; 115 | CFDATA data; 116 | 117 | } -------------------------------------------------------------------------------- /btparser/tests/CDATemplate.bt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/x64dbg/btparser/200221b4151b614017c9564709452e795b3c6c82/btparser/tests/CDATemplate.bt -------------------------------------------------------------------------------- /btparser/tests/CLASSTemplate2.bt: -------------------------------------------------------------------------------- 1 | BigEndian(); 2 | 3 | typedef struct { 4 | enum { 5 | CONSTANT_Class = 7, 6 | CONSTANT_Fieldref = 9, 7 | CONSTANT_Methodref = 10, 8 | CONSTANT_InterfaceMethodref = 11, 9 | CONSTANT_String = 8, 10 | CONSTANT_Integer = 3, 11 | CONSTANT_Float = 4, 12 | CONSTANT_Long = 5, 13 | CONSTANT_Double = 6, 14 | CONSTANT_NameAndType = 12, 15 | CONSTANT_Utf8 = 1 16 | } tag; 17 | switch (tag) { 18 | case 7: 19 | uint16 name_index; 20 | break; 21 | case 9: 22 | uint16 class_index; 23 | uint16 name_and_type_index; 24 | break; 25 | case 10: 26 | uint16 class_index; 27 | uint16 name_and_type_index; 28 | break; 29 | case 11: 30 | uint16 class_index; 31 | uint16 name_and_type_index; 32 | break; 33 | case 8: 34 | uint16 string_index; 35 | break; 36 | case 3: 37 | int32 int_value; 38 | break; 39 | case 4: 40 | float float_value; 41 | break; 42 | case 5: 43 | int64 long_value; 44 | break; 45 | case 6: 46 | double double_value; 47 | break; 48 | case 12: 49 | uint16 name_index; 50 | uint16 descriptor_index; 51 | break; 52 | case 1: 53 | uint16 length; 54 | char utf8_value[length]; 55 | break; 56 | } 57 | } cp_info; 58 | 59 | typedef struct { 60 | uint16 attribute_name_index; 61 | uint32 attribute_length; 62 | char info[attribute_length]; 63 | } attribute_info; 64 | 65 | typedef struct { 66 | uint16 access_flags ; 67 | uint16 name_index; 68 | uint16 descriptor_index; 69 | uint16 attributes_count; 70 | local int i_att2 = 0; 71 | for ( i_att2 = 0; i_att2 < attributes_count; i_att2++) { 72 | attribute_info attributes; 73 | }; 74 | } field_info, method_info; 75 | 76 | typedef struct { 77 | uint32 magic ; 78 | if (magic != 0xCAFEBABE) { 79 | Warning ("Invalid Class File."); 80 | return -1; 81 | } 82 | uint16 minor_version; 83 | uint16 major_version; 84 | uint16 constant_pool_count; 85 | local int i_cp = 0; 86 | for ( i_cp = 1; i_cp < constant_pool_count; i_cp++) { 87 | cp_info constant_pool; 88 | if ( constant_pool.tag == 5 || constant_pool.tag == 6 ){ 89 | i_cp++; 90 | } 91 | }; 92 | uint16 access_flags ; 93 | uint16 this_class; 94 | uint16 super_class; 95 | uint16 interfaces_count; 96 | local int i_if = 0; 97 | for ( i_if = 0; i_if < interfaces_count; i_if++) { 98 | uint16 interfaces; 99 | }; 100 | uint16 fields_count; 101 | local int i_fld = 0; 102 | for ( i_fld = 0; i_fld < fields_count; i_fld++) { 103 | field_info fields; 104 | }; 105 | uint16 methods_count; 106 | local int i_m = 0; 107 | for ( i_m = 0; i_m < methods_count; i_m++) { 108 | method_info methods; 109 | }; 110 | uint16 attributes_count; 111 | local int i_att = 0; 112 | for ( i_att = 0; i_att < attributes_count; i_att++) { 113 | attribute_info attributes; 114 | }; 115 | } class_file; 116 | 117 | class_file file; 118 | 119 | if (!FEof()) { 120 | Warning("File is not properly ended."); 121 | }; 122 | -------------------------------------------------------------------------------- /btparser/tests/DBFTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v2.1.3 Binary Template 3 | // 4 | // File: 5 | // Author: 6 | // Revision: 7 | // Purpose: 8 | //-------------------------------------- 9 | 10 | string yearFrom1900 (char yy) 11 | { 12 | string s; 13 | SPrintf(s, "%d", 1900 + yy); 14 | return s; 15 | } 16 | 17 | struct DBF { 18 | struct HEADER { 19 | char version; 20 | struct DATE_OF_LAST_UPDATE { 21 | char yy ; 22 | char mm ; 23 | char dd ; 24 | } DateOfLastUpdate; 25 | int numberOfRecords; 26 | short lengthOfHeaderStructure; 27 | short lengthOfEachRecord; 28 | char reserved[2]; 29 | char incompleteTrasaction ; 30 | char encryptionFlag ; 31 | int freeRecordThread; 32 | int reserved1[2]; 33 | char mdxFlag ; 34 | char languageDriver ; 35 | short reserved2; 36 | } header; 37 | struct FIELD { 38 | char fieldName[11]; 39 | char fieldType; 40 | int fieldDataAddress; 41 | char fieldLength ; 42 | char decimalCount ; 43 | short reserved; 44 | char workAreaId ; 45 | short reserved1; 46 | char flags ; 47 | char reserved2[7]; 48 | char indexFieldFlag ; 49 | } field[(header.lengthOfHeaderStructure-33)/sizeof(struct FIELD)]; 50 | char Terminator ; 51 | struct RECORD { 52 | char deletedFlag; 53 | char fields[header.lengthOfEachRecord-1]; 54 | } record [ header.numberOfRecords ] ; 55 | } dbf ; 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /btparser/tests/DMPTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v2.0.2 Binary Template 3 | // 4 | // File: DMPTemplate.bt 5 | // Author: 6 | // Revision: 1.0 - 20060320 7 | // Purpose: This template merely serves as documentation of the 8 | // memory dump format used by Microsoft's debuggers and 9 | // the NT kernel crashdump facility. Detailed and 10 | // authorative information about a DMP file can be 11 | // obtained by processing the file with the "dumpchk" 12 | // utility which ships whith Microsoft's free debugging 13 | // tools package. 14 | //-------------------------------------- 15 | 16 | 17 | typedef enum { 18 | FULL = 1, 19 | KERNEL, 20 | SMALL 21 | } e_DumpType; 22 | 23 | 24 | typedef struct { 25 | uint32 BasePage ; 26 | uint32 PageCount ; 27 | } _PHYSICAL_MEMORY_RUN32; 28 | 29 | 30 | typedef struct { 31 | uint32 NumberOfRuns; 32 | uint32 NumberOfPages ; 33 | _PHYSICAL_MEMORY_RUN32 Run[NumberOfRuns]; 34 | } _PHYSICAL_MEMORY_DESCRIPTOR32; 35 | 36 | 37 | typedef struct { 38 | int32 ExceptionCode ; 39 | uint32 ExceptionFlags; 40 | uint32 ExceptionRecord; 41 | uint32 ExceptionAddress ; 42 | uint32 NumberParameters; 43 | uint32 ExceptionInformation[15] ; 44 | } _EXCEPTION_RECORD32; 45 | 46 | 47 | FSeek(0); 48 | 49 | char Signature[4]; 50 | char ValidDump[4]; 51 | uint32 MajorVersion; 52 | uint32 MinorVersion; 53 | uint32 DirectoryTableBase ; 54 | uint32 PfnDataBase ; 55 | uint32 PsLoadedModuleList ; 56 | uint32 PsActiveProcessHead ; 57 | uint32 MachineImageType ; 58 | uint32 NumberProcessors; 59 | uint32 BugCheckCode ; 60 | uint32 BugCheckParameter[4] ; 61 | char VersionUser[32]; 62 | uchar PaeEnabled; 63 | uchar KdSecondaryVersion; 64 | uchar Spare3[2]; 65 | uint32 KdDebuggerDataBlock ; 66 | _PHYSICAL_MEMORY_DESCRIPTOR32 PhysicalMemoryBlock; 67 | FSeek(800); 68 | uchar ContextRecord[1200]; 69 | _EXCEPTION_RECORD32 Exception; 70 | char Comment[128]; 71 | uchar _reserved0[1768]; 72 | e_DumpType DumpType; 73 | uint32 MiniDumpFields; 74 | uint32 SecondaryDataState; 75 | uint32 ProductType; 76 | uint32 SuiteMask; 77 | uint32 WriterStatus; 78 | int64 RequiredDumpSpace; 79 | uchar _reserved2[16]; 80 | FILETIME SystemUpTime; 81 | FILETIME SystemTime; 82 | uchar _reserved3[56]; 83 | -------------------------------------------------------------------------------- /btparser/tests/EOTTemplate.bt: -------------------------------------------------------------------------------- 1 | //------------------------------------ 2 | //--- 010 Editor v2.01 Binary Template 3 | // 4 | // Name: EOTTemplate.bt 5 | // Author: Neo (Jiepeng) Tan 6 | // Revision: 1.0 7 | // Purpose: Parse an Embedded OpenType (EOT) File Format for Version: 0x00020002 8 | // Reference: http://www.w3.org/Submission/EOT/ 9 | //------------------------------------ 10 | 11 | LittleEndian(); 12 | 13 | 14 | typedef enum {TTEMBED_SUBSET = 0x1, 15 | TTEMBED_TTCOMPRESSED = 0x4, 16 | TTEMBED_FAILIFVARIATIONSIMULATED = 0x10, 17 | TTMBED_EMBEDEUDC = 0x00000020, 18 | TTEMBED_VALIDATIONTESTS = 0x00000040, 19 | TTEMBED_WEBOBJECT = 0x00000080, 20 | TTEMBED_XORENCRYPTDATA = 0x10000000 21 | } TTEMBED; 22 | 23 | typedef struct embedded_opentype_file { 24 | unsigned long EOTSize; 25 | unsigned long FontDataSize; 26 | unsigned long Version; 27 | TTEMBED Flags;//processing flags #define TTEMBED_TTCOMPRESSED 0x00000004 28 | byte FontPANOSE[10]; 29 | byte Charset; 30 | byte Italic; 31 | unsigned long Weight; 32 | unsigned short fsType; 33 | unsigned short MagicNumber;//Magic number for EOT file - 0x504C 34 | unsigned long UnicodeRange1; 35 | unsigned long UnicodeRange2; 36 | unsigned long UnicodeRange3; 37 | unsigned long UnicodeRange4; 38 | unsigned long CodePageRange1; 39 | unsigned long CodePageRange2; 40 | unsigned long CheckSumAdjustment; 41 | unsigned long Reserved1;//must be 0 42 | unsigned long Reserved2;//must be 0 43 | unsigned long Reserved3;//must be 0 44 | unsigned long Reserved4;//must be 0 45 | unsigned short Padding1;//always 0x0000 46 | unsigned short FamilyNameSize; 47 | byte FamilyName[FamilyNameSize]; 48 | 49 | unsigned short Padding2;//always 0x0000 50 | unsigned short StyleNameSize; 51 | byte StyleName[StyleNameSize]; 52 | 53 | unsigned short Padding3;//always 0x0000 54 | unsigned short VersionNameSize; 55 | byte VersionName[VersionNameSize]; 56 | 57 | unsigned short Padding4;//always 0x0000 58 | unsigned short FullNameSize; 59 | byte FullName[FullNameSize]; 60 | 61 | unsigned short Padding5;//always 0x0000 62 | unsigned short RootStringSize; 63 | byte RootString[RootStringSize]; 64 | unsigned long RootStringCheckSum; 65 | unsigned long EUDCCodePage; 66 | unsigned short Padding6; 67 | unsigned short SignatureSize; 68 | byte Signature[SignatureSize]; 69 | unsigned long EUDCFlags; 70 | unsigned long EUDCFontSize; 71 | byte EUDCFontData[EUDCFontSize]; 72 | byte FontData[FontDataSize]; 73 | }; 74 | 75 | LittleEndian(); 76 | 77 | FSeek(0); 78 | embedded_opentype_file EOT; -------------------------------------------------------------------------------- /btparser/tests/EVSBTemplate.bt: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | //--- 010 Editor v2.0.2 Binary Template 3 | // 4 | // File: EVSB_Symbol_Display 5 | // Author: Kip Leitner, Panasonic, PSDC NJ, USA, kleitner@pavcal.com 6 | // Revision: 1.0 21 January, 2006 7 | // 8 | // Purpose: Decompose EVSB Over-the-Air (OTA) symbols for DTV Transmission 9 | // 10 | // Ref: ATSC Digital Television standard (A/53), Revision D 11 | // Including Ammendment 1 12 | // 19 July 2005 13 | // Data Organization (Sect 5.3) 14 | //---------------------------------------------------------------------------- 15 | // Setups for 010 View --> Width --> custom (832) to see segment synks 16 | // View --> Width --> custom (64) to Field sync details 17 | // 18 | // modify template for your own frame length 19 | const int Frame_Count = 951; 20 | 21 | 22 | //---------------------------------------------------------------------------- 23 | typedef struct SYNC_SEGMENT_EVEN 24 | { 25 | SetBackColor(cRed); 26 | char Sync[4]; 27 | SetBackColor(cPurple); 28 | char PN511[511]; 29 | SetBackColor(cLtBlue); 30 | char PN63_a[63]; 31 | SetBackColor(cBlue); 32 | char PN63_b[63]; 33 | SetBackColor(cLtBlue); 34 | char PN63_c[63]; 35 | SetBackColor(cLtGreen); 36 | char VSB_Mode[24]; 37 | SetBackColor(cAqua); 38 | char Kerdock[64]; 39 | SetBackColor(cNone); 40 | char Reserved_a[28]; 41 | SetBackColor(cSilver); 42 | char Reserved_b[12]; 43 | } Sync_Segment_Even; 44 | 45 | typedef struct SYNC_SEGMENT_ODD 46 | { 47 | SetBackColor(cLtRed); 48 | char Sync[4]; 49 | SetBackColor(cPurple); 50 | char PN511[511]; 51 | SetBackColor(cLtBlue); 52 | char PN63_a[63]; 53 | SetBackColor(cBlue); 54 | char PN63_b[63]; 55 | SetBackColor(cLtBlue); 56 | char PN63_c[63]; 57 | SetBackColor(cLtGreen); 58 | char VSB_Mode[24]; 59 | SetBackColor(cAqua); 60 | char Kerdock[64]; 61 | SetBackColor(cNone); 62 | char Reserved_a[28]; 63 | SetBackColor(cSilver); 64 | char Reserved_b[12]; 65 | } Sync_Segment_Odd; 66 | 67 | typedef struct DATA_SEGMENT_EVEN 68 | { 69 | SetBackColor(cRed); 70 | char Data_Segment_Sync[4]; 71 | SetBackColor(cNone); 72 | char Payload_Even[828]; 73 | } Data_Segment_Even; 74 | 75 | typedef struct DATA_SEGMENT_ODD 76 | { 77 | SetBackColor(cLtRed); 78 | char Data_Segment_Sync[4]; 79 | SetBackColor(cNone); 80 | char Payload_Odd[828]; 81 | } Data_Segment_Odd; 82 | 83 | typedef struct FIELD_EVEN 84 | { 85 | Sync_Segment_Even Sync_Seg_Even[1]; 86 | Data_Segment_Even Data_Seg_Even[312]; 87 | } Field_Even; 88 | 89 | typedef struct FIELD_ODD 90 | { 91 | Sync_Segment_Odd Sync_Seg_Odd[1]; 92 | Data_Segment_Odd Data_Seg_Odd[312]; 93 | } Field_Odd; 94 | 95 | typedef struct FRAME 96 | { 97 | Field_Even F_Even; 98 | Field_Odd F_Odd; 99 | } Frame; 100 | 101 | struct FILE 102 | { 103 | Frame Frames[Frame_Count]; 104 | } File; -------------------------------------------------------------------------------- /btparser/tests/ElTorito.bt: -------------------------------------------------------------------------------- 1 | BitfieldRightToLeft(); 2 | BitfieldDisablePadding(); 3 | 4 | #define BLOCK_SIZE 2048 5 | #define BOOT_RECORD_OFFSET 2048 * 16 6 | #define ELTORITO_OFFSET 2048 * 17 7 | 8 | typedef struct { 9 | ubyte BootIndicator; 10 | char IsoId[5]; 11 | ubyte Version; 12 | char Identifier[32]; 13 | ubyte Unused[32]; 14 | uint32 BootCatalog; 15 | ubyte Unused2[5]; 16 | uint32 VolSpaceSize[2]; 17 | } BOOT_RECORD_DESC; 18 | 19 | typedef union { 20 | struct { 21 | ubyte HeaderId; 22 | ubyte PlatformId; 23 | uint16 Res0; 24 | char Id[24]; 25 | uint16 Checksum ; 26 | uint16 Sig ; // 0xaa55 27 | } ValEntry; 28 | 29 | struct { 30 | enum { BOOTABLE=0x88, NOT_BOOTABLE=0x0 } BootId ; 31 | enum { NO_EMULATION=0x0, DISKETTE_1_2=0x1, DISKETTE_1_44=0x2, DISKETTE_2_88=0x3, HARDDISK=0x4 } MediaType ; 32 | uint16 LoadSegment ; 33 | ubyte SystemType; 34 | ubyte Unused; 35 | uint16 SectorCount; 36 | uint32 LoadLba; 37 | } DefaultEntry; 38 | 39 | struct { 40 | enum { NOT_LAST_HEADER=0x90, LAST_HEADER=0x91 } HeaderId ; 41 | enum { PC_80x86=0x0, POWERPC=0x1, MAC=0x2 } PlatformId ; 42 | uint16 NumSectionEntries; 43 | char IdString[28]; 44 | } SecHeader; 45 | 46 | struct { 47 | enum { SECTION_BOOTABLE=0x88, SECTION_NOT_BOOTABLE=0x0 } BootId ; 48 | enum { SEC_NO_EMULATION=0x0, SEC_DISKETTE_1_2=0x1, SEC_DISKETTE_1_44=0x2, SEC_DISKETTE_2_88=0x3, SEC_HARDDISK=0x4 } MediaType ; 49 | uint16 LoadSegment ; 50 | ubyte SystemType; 51 | ubyte Unused; 52 | uint16 SectorCount; 53 | uint32 LoadLba; 54 | enum { NO_SELECTION_CRITERIA=0x0, LANGUAGE_AND_VERSION=0x1 } SelectionType; 55 | ubyte Criteria[19]; 56 | } SecEntry; 57 | 58 | } EL_TORITO_ENTRIES; 59 | 60 | LittleEndian(); 61 | 62 | FSeek(ELTORITO_OFFSET); 63 | BOOT_RECORD_DESC boot_record; 64 | 65 | FSeek(boot_record.BootCatalog * BLOCK_SIZE); 66 | EL_TORITO_ENTRIES el_torito[BLOCK_SIZE / sizeof(EL_TORITO_ENTRIES) - 1]; 67 | -------------------------------------------------------------------------------- /btparser/tests/FAT16Template.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v3.1.2 Binary Template 3 | // 4 | // File: FAT16Template.bt 5 | // Author: 6 | // Revision: 7 | // Purpose: This template can find the 8 | // partitions and display the FAT16 9 | // partitions on the disk. 10 | //-------------------------------------- 11 | 12 | //-------------------------------------- 13 | //Master Boot record 14 | //-------------------------------------- 15 | typedef struct _CHS 16 | { 17 | BYTE Head; 18 | BYTE Sector; 19 | BYTE Cylinder; 20 | }CHS; 21 | //-------------------------------------- 22 | typedef union _CHSAddr 23 | { 24 | CHS chs; 25 | BYTE Address[3]; 26 | }CHSAddr; 27 | //-------------------------------------- 28 | typedef struct _Partion_Table_Entry{ 29 | BYTE Status; 30 | CHSAddr StartCHSAddress; 31 | BYTE PartitionType; 32 | CHSAddr EndCHSAddress; 33 | DWORD FirstLBA; 34 | DWORD TotalSectors; 35 | }Partion_Table_Entry; 36 | //-------------------------------------- 37 | typedef struct { 38 | BYTE Code[446]; 39 | Partion_Table_Entry ptable[4]; 40 | WORD Signature55AA ; 41 | if ( Signature55AA != 0xAA55 ) 42 | { 43 | Warning("Invalid MBR"); 44 | return 1; 45 | } 46 | }MBR; 47 | //-------------------------------------- 48 | //FAT Boot sector FAT12,FAT16 49 | //-------------------------------------- 50 | typedef struct _FAT16BootSector 51 | { 52 | BYTE JumpCode[3]; 53 | BYTE OEM_Name[8]; 54 | WORD BytesPerSector; 55 | BYTE SectorsPerCluster; 56 | WORD ReservedSectorCount; //Number of sectors before the first FAT, including the boot sector 57 | BYTE NumberOfFAT; 58 | WORD MAX_RootDirEntry; 59 | WORD TotalSectors; //If Less than 65535 else see offset 0x20 60 | BYTE MediaDescriptor; 61 | WORD SectorsPerFAT; //For FAT12/16 62 | WORD SectorsPerTrack; 63 | WORD NumberOfHeads; 64 | DWORD HiddenSectorsBeforePartition; 65 | DWORD TotalSectors; 66 | BYTE PhysicalDriveNumber; 67 | BYTE Reserved; //Current Head 68 | BYTE ExtendedBootSignature; 69 | BYTE SerialNumber[4]; 70 | BYTE VolumeLable[11]; 71 | BYTE FAT_Type[8]; 72 | BYTE BootCode[448]; 73 | WORD BootSectorSignature; //0x55 0xAA 74 | }FAT16BootSector; 75 | //-------------------------------------- 76 | //FAT16 77 | //-------------------------------------- 78 | local unsigned int FATEntryCount=0; 79 | typedef struct _FAT16 80 | { 81 | WORD Table[FATEntryCount]; 82 | }FAT16; 83 | //-------------------------------------- 84 | //FAT root dir entry FAT12,FAT16 85 | //-------------------------------------- 86 | typedef struct _RootDirEntry 87 | { 88 | BYTE name[8]; 89 | BYTE extn[3]; 90 | BYTE attributes; 91 | BYTE reserved[10]; 92 | WORD time; 93 | WORD date; 94 | WORD firstDataBlock; 95 | DWORD size; 96 | }RootDirEntry; 97 | //-------------------------------------- 98 | LittleEndian(); 99 | FSeek(0); 100 | //-------------------------------------- 101 | //MBR Object 102 | MBR MasterBootRecord; 103 | //-------------------------------------- 104 | //Partition Info 105 | //-------------------------------------- 106 | local unsigned int partition_index=0; 107 | typedef struct _Fat16Partition 108 | { 109 | 110 | local unsigned int startBYTE = (MasterBootRecord.ptable[partition_index].FirstLBA*512); 111 | FSeek( startBYTE); 112 | FAT16BootSector BtSector; 113 | 114 | //-------------------------------------- 115 | //Find the FATs 116 | //-------------------------------------- 117 | //Skip the reserved sectors (-1 for accounting the bootrecord) 118 | FSkip((BtSector.ReservedSectorCount-1)*512); 119 | 120 | local unsigned int FATsize = (BtSector.SectorsPerFAT * 512)/2; 121 | local unsigned int FATcnt = 0; 122 | for(FATcnt = 0;FATcnt < BtSector.NumberOfFAT;++FATcnt) 123 | { 124 | FATEntryCount=FATsize; 125 | FAT16 FAT; 126 | } 127 | 128 | //-------------------------------------- 129 | //Find the Root Dir Entries 130 | //-------------------------------------- 131 | RootDirEntry rootDir[BtSector.MAX_RootDirEntry]; 132 | //-------------------------------------- 133 | 134 | }Fat16Partition; 135 | //-------------------------------------- 136 | //disk Info 137 | //-------------------------------------- 138 | typedef struct _Disk 139 | { 140 | //find all the partitions 141 | local int part; 142 | for(part=0;part<4;++part) 143 | { 144 | if(MasterBootRecord.ptable[part].FirstLBA) 145 | { 146 | partition_index=part; 147 | Fat16Partition FAT16partition; 148 | } 149 | } 150 | }Disk; 151 | //-------------------------------------- 152 | Disk dsk; 153 | //-------------------------------------- 154 | 155 | -------------------------------------------------------------------------------- /btparser/tests/FLVTemplate.bt: -------------------------------------------------------------------------------- 1 | //----------------------------------- 2 | //--- 010 Editor v3.0 Binary Template 3 | // 4 | // File: FLVTemplate.bt 5 | // Author: lafei(indep@263.net) 6 | // Revision: 2.1 7 | // Purpose: Defines a template for 8 | // parsing FLV files. 9 | //----------------------------------- 10 | 11 | // Define structures used in FLV files 12 | 13 | typedef struct { 14 | CHAR signature[3]; //"FLV" 15 | UBYTE version; 16 | UBYTE dummy : 5; 17 | UBYTE audio : 1; //1 if audio present 18 | UBYTE dummy2 : 1; 19 | UBYTE video : 1; //1 if video present 20 | DWORD dataoffset; //in abs. file offset 21 | DWORD zero; //previous tag size 22 | } HEADER; 23 | 24 | local UINT taglen; 25 | 26 | typedef struct { 27 | UINT type : 8; 28 | UINT datasize : 24; 29 | UINT timestamp : 24; 30 | UINT timestamphi : 8; 31 | UINT streamid : 24; 32 | taglen = datasize - 1; 33 | Printf("tag length: %x\n",taglen); 34 | if(type==8) //audio 35 | { 36 | UINT fmt : 4; 37 | UINT sr : 2; 38 | UINT bits : 1; 39 | UINT channels : 1; 40 | if(fmt==10) 41 | { 42 | --taglen; 43 | UBYTE frmtype; 44 | } 45 | } 46 | else if(type==9)//video 47 | { 48 | UINT frmtype : 4; 49 | UINT codecid : 4; 50 | if(codecid==7) 51 | { 52 | taglen -= 4; 53 | UINT pkttype : 8; 54 | UINT compotime : 24; 55 | } 56 | } 57 | else if(type==18)//script 58 | { 59 | UINT fristbyte : 8; 60 | } 61 | UBYTE data[taglen]; 62 | UINT lastsize; //last tag size 63 | 64 | //for debugging 65 | //Printf("lastsize: %x\n",lastsize); 66 | //Printf("Pos: %x\n",FTell()); 67 | } Tag; 68 | 69 | BigEndian(); 70 | SetBackColor( cLtGray ); 71 | HEADER hdr; 72 | 73 | // Check for header 74 | if( hdr.signature != "FLV" ) 75 | { 76 | Warning( "File is not a FLV. Template stopped." ); 77 | return -1; 78 | } 79 | 80 | if( hdr.version != 1 ) 81 | { 82 | Warning( "Unsupported FLV version. Template stopped." ); 83 | return -1; 84 | } 85 | 86 | // Define the bytes of the data 87 | SetBackColor( cNone ); 88 | 89 | while( !FEof() ) 90 | { 91 | Tag tag; 92 | } 93 | -------------------------------------------------------------------------------- /btparser/tests/GPTTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v5.0 Binary Template 3 | // 4 | // File: GPTTemplate 5 | // Author: lurker0ster@gmail.com 6 | // Revision: V1.0 7 | // Purpose: Guid Partition Table 8 | //-------------------------------------- 9 | typedef struct { 10 | BYTE BootIndicator; 11 | BYTE StartHead; 12 | WORD StartSector:6; 13 | WORD StartCylinder:10; 14 | BYTE PartitionType; 15 | BYTE EndHead; 16 | WORD EndSector:6; 17 | WORD EndCylider:10; 18 | DWORD SectorsPrecedingPartion; 19 | DWORD SectorsInPartition; 20 | }MBRPARTITIONTABLE; 21 | 22 | 23 | typedef struct{ 24 | char SIGNATURE[8]; 25 | DWORD Revision; 26 | DWORD Headersize; 27 | DWORD CRC32OfHeader; 28 | DWORD Reserved; 29 | uint64 CurrentLBA; 30 | uint64 BackupLBA; //location of the other head copy 31 | uint64 FirstUsableLBA; //primary partition table last LBA+1 32 | uint64 LastUsableLBA; //secondary parition table first LBA-1 33 | BYTE DiskGUID[16]; 34 | uint64 PartitionEntries; 35 | DWORD NumOfPartitions; 36 | DWORD SizeOfPartitionEntry; 37 | DWORD CRC32ofPartitionArray; 38 | BYTE reserved[420]; 39 | }GPT; 40 | 41 | typedef struct { 42 | BYTE PartitionTypeGUID[16]; 43 | BYTE PartitionGUID[16]; 44 | uint64 PartitionStartLBA; 45 | uint64 PartitionEndLBA; 46 | uint64 PartitionProperty; 47 | wchar_t PartitionName[36]; //Unicode 48 | }GPTPAPTITIONTABLE ; 49 | 50 | LittleEndian(); 51 | struct { 52 | BYTE bootcode[446]; 53 | MBRPARTITIONTABLE partitionTable[4]; 54 | WORD signature; 55 | }MBR ; 56 | 57 | 58 | 59 | 60 | if ((MBR.partitionTable[0].PartitionType & 0xFF) == 0xEE) { 61 | Printf("Protected MBR. GPT reserved"); 62 | GPT gptheader; 63 | GPTPAPTITIONTABLE table[128]; 64 | FSeek(FileSize()-sizeof(GPT)-sizeof(GPTPAPTITIONTABLE)*128); 65 | GPTPAPTITIONTABLE BackupTable[128]; 66 | FSeek(FileSize()-sizeof(GPT)); 67 | GPT Backupgptheader; 68 | } -------------------------------------------------------------------------------- /btparser/tests/GocleverTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v3.2.1 Binary Template 3 | // 4 | // File:GocleverTemplate.bt 5 | // Author:Artur Babecki 6 | // Revision: 21.02.2012 7 | // Purpose: template for GOCLEVER Navigation log format 8 | // GPSLogYYYY-MM-DD_xx-xx-xx.bin 9 | // (Model GC-4335 and others) 10 | // Generates raport in the human readable form: 11 | // Date, Longitude, Latitude, Geoid, Altitude, Direction. 12 | // 13 | //-------------------------------------- 14 | 15 | 16 | local uint number_of_records; 17 | local int i; 18 | local string s; 19 | 20 | number_of_records=FileSize()/48; 21 | struct gps 22 | { 23 | double longitude ; 24 | double latitude ; 25 | time_t date; 26 | int direction; 27 | int speed; 28 | uchar unknown_data [12]; 29 | int geoid; 30 | int altitude ; 31 | } goclever[number_of_records]; 32 | OutputPaneClear(); 33 | 34 | Printf("GOCLEVER Navigation log: %s \n\n",GetFileName()); 35 | Printf(" Date\t\tLongitude Latitude Geoid Altitude Direction Speed\n"); 36 | Printf("mm/dd/yyyy hh:mm:ss\n"); 37 | for (i=0;i=8bpp) 19 | BYTE bReserved; // Reserved ( must be 0) 20 | WORD wPlanes; // Color Planes 21 | WORD wBitCount; // Bits per pixel 22 | DWORD dwBytesInRes; // How many bytes in this resource? 23 | DWORD dwImageOffset; // Where in the file is this image? 24 | } ICONDIRENTRY ; 25 | 26 | typedef struct 27 | { 28 | WORD idReserved; // Reserved (must be 0) 29 | WORD idType; // Resource Type (1 for icons) 30 | WORD idCount; // How many images? 31 | ICONDIRENTRY idEntries[idCount]; // An entry for each image (idCount of 'em) 32 | } ICONDIR; 33 | 34 | typedef struct { // rgbq 35 | UBYTE rgbBlue; 36 | UBYTE rgbGreen; 37 | UBYTE rgbRed; 38 | UBYTE rgbReserved; 39 | } RGBQUAD ; 40 | 41 | typedef struct { // rgbt 42 | UBYTE rgbBlue; 43 | UBYTE rgbGreen; 44 | UBYTE rgbRed; 45 | } RGBTRIPLE ; 46 | 47 | typedef struct { // bmih 48 | DWORD biSize; 49 | LONG biWidth; 50 | LONG biHeight; 51 | WORD biPlanes; 52 | WORD biBitCount; 53 | DWORD biCompression; 54 | DWORD biSizeImage; 55 | LONG biXPelsPerMeter; 56 | LONG biYPelsPerMeter; 57 | DWORD biClrUsed; 58 | DWORD biClrImportant; 59 | } BITMAPINFOHEADER; 60 | 61 | typedef struct { 62 | // Define the color table 63 | if( (bmiHeader.biBitCount != 24) && (bmiHeader.biBitCount != 32) ) 64 | { 65 | if( bmiHeader.biClrUsed > 0 ) 66 | RGBQUAD aColors[ bmiHeader.biClrUsed ]; 67 | else 68 | RGBQUAD aColors[ 1 << bmiHeader.biBitCount ]; 69 | } 70 | 71 | // Calculate bytes per line and padding required 72 | local int bytesPerLine = (int)Ceil( bmiHeader.biWidth * bmiHeader.biBitCount / 8.0 ); 73 | local int padding = 4 - (bytesPerLine % 4); 74 | if( padding == 4 ) 75 | padding = 0; 76 | 77 | // Define each line of the image 78 | struct BITMAPLINE { 79 | 80 | // Define color data 81 | if( bmiHeader.biBitCount < 8 ) 82 | UBYTE imageData[ bytesPerLine ]; 83 | else if( bmiHeader.biBitCount == 8 ) 84 | UBYTE colorIndex[ bmiHeader.biWidth ]; 85 | else if( bmiHeader.biBitCount == 24 ) 86 | RGBTRIPLE colors[ bmiHeader.biWidth ]; 87 | else if( bmiHeader.biBitCount == 32 ) 88 | RGBQUAD colors[ bmiHeader.biWidth ]; 89 | 90 | // Pad if necessary 91 | if( padding != 0 ) 92 | UBYTE padBytes[ padding ]; 93 | 94 | } lines[ bmiHeader.biHeight/2 ]; 95 | 96 | // Define each line of the mask 97 | struct MASKLINE { 98 | UBYTE line[((bmiHeader.biWidth + 31)/32)*4]; 99 | }mask[bmiHeader.biHeight/2]; 100 | 101 | }IMAGEDATA; 102 | 103 | typedef struct { 104 | SetBackColor( cLtAqua ); 105 | BITMAPINFOHEADER bmiHeader; 106 | SetBackColor( cLtGray ); 107 | IMAGEDATA data; 108 | }ICONIMAGE ; 109 | 110 | //--------------------------------------------- 111 | // Custom read functions - this allows the data to be displayed without having to open up the structure. 112 | 113 | 114 | string ReadIconDirEntry( ICONDIRENTRY &dirEntry ) 115 | { 116 | string s; 117 | SPrintf( s, "%dx%d %dbit %d colors", dirEntry.bWidth, dirEntry.bHeight, dirEntry.wBitCount, dirEntry.bColorCount ); 118 | return s; 119 | } 120 | 121 | string ReadDIBHeader( ICONIMAGE &image ) 122 | { 123 | string s; 124 | SPrintf( s, "%dx%d %dbit", image.bmiHeader.biWidth, image.bmiHeader.biHeight, image.bmiHeader.biBitCount ); 125 | return s; 126 | } 127 | 128 | string ReadRGBQUAD( RGBQUAD &a ) 129 | { 130 | string s; 131 | SPrintf( s, "#%02X%02X%02X%02X", a.rgbReserved, a.rgbRed, a.rgbGreen, a.rgbBlue ); 132 | return s; 133 | } 134 | 135 | string ReadRGBTRIPLE( RGBTRIPLE &a ) 136 | { 137 | string s; 138 | SPrintf( s, "#%02X%02X%02X", a.rgbRed, a.rgbGreen, a.rgbBlue ); 139 | return s; 140 | } 141 | 142 | //--------------------------------------------- 143 | 144 | // Define the headers 145 | LittleEndian(); 146 | 147 | local short res = ReadShort( FTell() ); 148 | local short type = ReadShort(FTell() +2 ); 149 | 150 | //Check icon dir 151 | if( res != 0 || type != 1) 152 | { 153 | Warning( "File is not an Icon. Template stopped." ); 154 | return -1; 155 | } 156 | 157 | SetBackColor( cNone ); 158 | ICONDIR icondir; 159 | ICONIMAGE images[icondir.idCount] ; -------------------------------------------------------------------------------- /btparser/tests/ISOTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v5.0 Binary Template 3 | // 4 | // File: ISOTemplate.bt 5 | // Author: Anton Kochkov 6 | // Revision: 0.1 7 | // Purpose: Show contents of the ISO headers 8 | //-------------------------------------- 9 | 10 | BitfieldRightToLeft(); 11 | BitfieldDisablePadding(); 12 | 13 | #define BLOCK_SIZE 2048 14 | #define BOOT_RECORD_OFFSET 2048 * 16 15 | 16 | typedef struct _BOOT_RECORD 17 | { 18 | ubyte BootIndicator; 19 | char IsoId[5]; 20 | ubyte Version; 21 | char Identifier[32]; 22 | ubyte Unused[32]; 23 | uint32 BootCatalog; 24 | ubyte Unused2[5]; 25 | uint32 VolSpaceSize[2]; 26 | } BOOT_RECORD_DESC; 27 | 28 | typedef struct { 29 | ubyte VolDescType; 30 | byte StdId[5]; 31 | ubyte VolDescVer; 32 | } VOLUME_DESCRIPTOR_HEADER; 33 | 34 | typedef struct { 35 | uint32 Year; 36 | uint16 Month; 37 | uint16 Day; 38 | uint16 Hour; 39 | uint16 Minute; 40 | uint16 Second; 41 | uint16 HSecond; 42 | byte Offset; 43 | } CD_DATE_TIME; 44 | 45 | typedef struct { 46 | ubyte Year; 47 | ubyte Month; 48 | ubyte Day; 49 | ubyte Hour; 50 | ubyte Minute; 51 | ubyte Second; 52 | byte Offset; 53 | } FILE_DATE_TIME; 54 | 55 | typedef struct { 56 | ubyte RecordLength; 57 | ubyte ExtAttrRecLength; 58 | uint64 StartLba; 59 | uint64 DataLength; 60 | FILE_DATE_TIME RecTime; 61 | ubyte Flags; 62 | ubyte FileUnitSize; 63 | ubyte InterleaveGap; 64 | uint32 VolSeqNum; 65 | ubyte FileIdLength; 66 | ubyte FileId[1]; 67 | } ROOT_DIR_HEADER; 68 | 69 | typedef struct { 70 | VOLUME_DESCRIPTOR_HEADER Header; 71 | ubyte Flags; 72 | byte SysId[32]; 73 | byte VolId[32]; 74 | uint64 Unused; 75 | uint64 VolSpaceSize; 76 | byte EscSeq[32]; 77 | uint32 VolSetSize; 78 | uint32 VolSeqNum; 79 | uint32 LBlockSize; 80 | uint64 PathTblSize; 81 | uint32 LPathTbl1; 82 | uint32 LPathTbl2; 83 | uint32 MPathTbl1; 84 | uint32 MPathTbl2; 85 | ROOT_DIR_HEADER Root; 86 | byte VolSetId[128]; 87 | byte PublisherId[128]; 88 | byte DataPrepId[128]; 89 | byte ApplicationId[128]; 90 | byte CopyrightFileId[37]; 91 | byte AbstractFileId[37]; 92 | byte BiblioFileId[37]; 93 | CD_DATE_TIME CreationTime; 94 | CD_DATE_TIME ModifyTime; 95 | CD_DATE_TIME ExpireTime; 96 | CD_DATE_TIME EffectiveTime; 97 | ubyte FileStrucVer; 98 | ubyte Unused1; 99 | } PRIMARY_VOLUME_DESC_HEADER; 100 | 101 | LittleEndian(); 102 | FSeek(BOOT_RECORD_OFFSET); 103 | 104 | union { 105 | BOOT_RECORD_DESC boot_record; 106 | PRIMARY_VOLUME_DESC_HEADER primary_volume; 107 | } disk_header; 108 | 109 | -------------------------------------------------------------------------------- /btparser/tests/InspectorWithMP4DateTime.bt: -------------------------------------------------------------------------------- 1 | //----------------------------------- 2 | //--- 010 Editor v4.0 Binary Template 3 | // 4 | // File: InspectorMoje.bt 5 | // Author: SweetScape Software 6 | // Revision: 1.1 7 | // Purpose: This template may be used 8 | // to customize the auto tab of the 9 | // Inspector with your own variables. 10 | // See the Inspector section of the 11 | // Options dialog for more information. 12 | // Changes: 13 | // 1.1 (SweetScape): 14 | // - Added hfloat data type. 15 | // 1.2 (Marian Denes): 16 | // - Added MP4_Time data type 17 | //----------------------------------- 18 | RequiresVersion( 4.0 ); 19 | 20 | // Calculate the position for each variable, 21 | // either at the beginning of the selection 22 | // or at the current cursor position. 23 | local int64 position; 24 | if( GetSelSize() > 0 ) 25 | position = GetSelStart(); 26 | else 27 | position = GetCursorPos(); 28 | 29 | 30 | int leap(int year) 31 | { 32 | return year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 ); 33 | } 34 | 35 | int daysInYear(int year) {return 365 + leap(year);} 36 | 37 | 38 | typedef uint MP4_Time ; 39 | 40 | string MP4_TimeRead( MP4_Time secs ) 41 | { 42 | // secs - seconds since midnight, January 1, 1904 43 | 44 | int days = secs / 86400; 45 | secs = secs % 86400; 46 | 47 | int year = 1904; 48 | int month = 1; 49 | 50 | int daysInMonth[13] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 51 | int extraDay [13] = {-1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 52 | 53 | while (days > daysInYear(year)) 54 | { 55 | days -= daysInYear(year); 56 | year++; 57 | } 58 | 59 | while (days > daysInMonth[month] + leap(year) * extraDay[month]) 60 | { 61 | days -= daysInMonth[month] + leap(year) * extraDay[month]; 62 | month++; 63 | } 64 | 65 | int day = ++days; // 0 (full) days remaining means the 1st day of the monht, and so on 66 | 67 | int hours = secs / 3600; 68 | secs = secs % 3600; 69 | int mins = secs / 60; 70 | secs = secs % 60; 71 | 72 | string s; 73 | SPrintf( s, "%02d.%02d.%4d %02d:%02d:%02d", day, month, year, hours, mins, secs ); 74 | return s; 75 | } 76 | 77 | void MP4_TimeWrite( MP4_Time &secs, string dateTime ) 78 | { 79 | int daysInMonth[13] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 80 | int extraDay [13] = {-1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 81 | 82 | int day, month, year, hour, min, sec; //secs = 0x1122; 83 | SScanf(dateTime, "%d.%d.%d %d:%d:%d", day, month, year, hour, min, sec); 84 | 85 | int days = day - 1; // January 1, 1994 is 0 days after this date, and so on 86 | int months, hours, mins, y, m; 87 | 88 | for (y = 1904; y < year; ++y) 89 | days += daysInYear(y); 90 | 91 | for (m = 1; m < month; ++m) 92 | days += daysInMonth[m] + leap(year) * extraDay[m]; 93 | 94 | secs = days * 86400 + hour * 3600 + min * 60 + sec; 95 | } 96 | 97 | // Define variables for the inspector 98 | FSeek( position ); MP4_Time _mp4t ; 99 | FSeek( position ); byte _si8 ; 100 | FSeek( position ); ubyte _ui8 ; 101 | FSeek( position ); short _si16 ; 102 | FSeek( position ); ushort _ui16 ; 103 | FSeek( position ); int _si32 ; 104 | FSeek( position ); uint _ui32 ; 105 | FSeek( position ); int64 _si64 ; 106 | FSeek( position ); uint64 _ui64 ; 107 | FSeek( position ); float _f ; 108 | FSeek( position ); double _d ; 109 | FSeek( position ); hfloat _hf ; 110 | FSeek( position ); char _s [ReadStringLength(position,256)] ; // limit to 256 characters 111 | FSeek( position ); wchar_t _ws[ReadWStringLength(position,256)] ; // limit to 256 characters 112 | FSeek( position ); DOSDATE _dd ; 113 | FSeek( position ); DOSTIME _dt ; 114 | FSeek( position ); FILETIME _ft ; 115 | FSeek( position ); OLETIME _ot ; 116 | FSeek( position ); time_t _tt ; 117 | -------------------------------------------------------------------------------- /btparser/tests/LUKSTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v4.0.1 Binary Template 3 | // 4 | // File: LUKS.bt 5 | // Author: Daniel Correa 6 | // URL: http://www.sinfocol.org/ 7 | // Revision: 1.0 8 | // Purpose: Template for LUKS 9 | //-------------------------------------- 10 | 11 | #define LUKS_CIPHERNAME_L 32 12 | #define LUKS_CIPHERMODE_L 32 13 | #define LUKS_HASHSPEC_L 32 14 | #define LUKS_DIGESTSIZE 20 15 | #define LUKS_HMACSIZE 32 16 | #define LUKS_SALTSIZE 32 17 | #define LUKS_NUMKEYS 8 18 | 19 | #define LUKS_MKD_ITERATIONS_MIN 1000 20 | #define LUKS_SLOT_ITERATIONS_MIN 1000 21 | 22 | #define LUKS_KEY_DISABLED_OLD 0 23 | #define LUKS_KEY_ENABLED_OLD 0xCAFE 24 | 25 | #define LUKS_KEY_DISABLED 0x0000DEAD 26 | #define LUKS_KEY_ENABLED 0x00AC71F3 27 | 28 | #define LUKS_STRIPES 4000 29 | 30 | #define LUKS_MAGIC "LUKS\xBA\xBE" 31 | #define LUKS_MAGIC_L 6 32 | 33 | #define LUKS_PHDR_SIZE (sizeof(struct luks_phdr)/SECTOR_SIZE+1) 34 | 35 | #define UUID_STRING_L 40 36 | 37 | #define LUKS_ALIGN_KEYSLOTS 4096 38 | 39 | 40 | typedef struct luks_phdr { 41 | char magic[LUKS_MAGIC_L] ; 42 | 43 | if (magic != LUKS_MAGIC) { 44 | SetBackColor(0x0000ff); 45 | Warning("File is not a LUKS disk. Bad signature."); 46 | return -1; 47 | } 48 | 49 | uint16 version ; 50 | char cipherName[LUKS_CIPHERNAME_L] ; 51 | char cipherMode[LUKS_CIPHERMODE_L] ; 52 | char hashSpec[LUKS_HASHSPEC_L] ; 53 | uint32 payloadOffset ; 54 | uint32 keyBytes ; 55 | char mkDigest[LUKS_DIGESTSIZE] ; 56 | char mkDigestSalt[LUKS_SALTSIZE] ; 57 | uint32 mkDigestIterations ; 58 | char uuid[UUID_STRING_L] ; 59 | 60 | struct { 61 | uint32 active ; 62 | 63 | uint32 passwordIterations ; 64 | char passwordSalt[LUKS_SALTSIZE] ; 65 | 66 | uint32 keyMaterialOffset ; 67 | uint32 stripes ; 68 | } keyblock[LUKS_NUMKEYS]; 69 | 70 | char _padding[432]; 71 | }; 72 | 73 | FSeek(0); 74 | BigEndian(); 75 | luks_phdr LUKS; -------------------------------------------------------------------------------- /btparser/tests/MBRTemplateFAT.bt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/x64dbg/btparser/200221b4151b614017c9564709452e795b3c6c82/btparser/tests/MBRTemplateFAT.bt -------------------------------------------------------------------------------- /btparser/tests/Mifare1kTemplate.bt: -------------------------------------------------------------------------------- 1 | //----------------------------------- 2 | // File: Mifare Classic 1k 3 | // Author: Ruben Boonen (b33f) 4 | // http://www.fuzzysecurity.com/ 5 | // Purpose: Basic Structure 6 | //----------------------------------- 7 | 8 | struct FILE { 9 | struct Manufacturer_block { 10 | char Card_UID[4] ; 11 | char LRC[1] ; 12 | char Internal[11] ; 13 | char Data[32]; 14 | char Key_A[6] ; 15 | char Access_Bits[3] ; 16 | char GPB[1] ; 17 | char Key_B[6] ; 18 | } manufacturer_block; 19 | 20 | struct Sec_4blk { 21 | char Data[48]; 22 | char Key_A[6] ; 23 | char Access_Bits[3] ; 24 | char GPB[1] ; 25 | char Key_B[6] ; 26 | } sec_4blk[ 15 ]; 27 | 28 | } file ; -------------------------------------------------------------------------------- /btparser/tests/Mifare4kTemplate.bt: -------------------------------------------------------------------------------- 1 | //----------------------------------- 2 | // File: Mifare Classic 4k 3 | // Author: Ruben Boonen (b33f) 4 | // http://www.fuzzysecurity.com/ 5 | // Purpose: Basic Structure 6 | //----------------------------------- 7 | 8 | struct FILE { 9 | struct Manufacturer_block { 10 | char Card_UID[4] ; 11 | char LRC[1] ; 12 | char Internal[11] ; 13 | char Data[32]; 14 | char Key_A[6] ; 15 | char Access_Bits[3] ; 16 | char GPB[1] ; 17 | char Key_B[6] ; 18 | } manufacturer_block; 19 | 20 | struct Sec_4blk { 21 | char Data[48]; 22 | char Key_A[6] ; 23 | char Access_Bits[3] ; 24 | char GPB[1] ; 25 | char Key_B[6] ; 26 | } sec_4blk[ 31 ]; 27 | 28 | struct Sec_16blk { 29 | char Data[240]; 30 | char Key_A[6] ; 31 | char Access_Bits[3] ; 32 | char GPB[1] ; 33 | char Key_B[6] ; 34 | } sec_16blk[ 8 ]; 35 | 36 | } file ; -------------------------------------------------------------------------------- /btparser/tests/NetflowVersion5.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v2.1.3 Binary Template 3 | // 4 | // File: Netflow Version 5 5 | // 6 | // Author: Andrew Faust 7 | // Revision: 8 | // Purpose: Parses a Netflow Version 5 record 9 | //-------------------------------------- 10 | 11 | BigEndian(); 12 | 13 | struct FLOW { 14 | struct HEADER { 15 | ushort Version; 16 | ushort Count; 17 | uint SysUptime; 18 | uint EopochSeconds; 19 | uint NanoSeconds; 20 | uint FlowsSeen; 21 | byte EngineType; 22 | byte EngineID; 23 | char filler[2]; 24 | } header; 25 | 26 | struct DATA { 27 | char SourceIP[4]; 28 | char DestIP[4]; 29 | char NextHopIP[4]; 30 | ushort InSNMP; 31 | ushort OutSNMP; 32 | uint PacketCount; 33 | uint ByteCount; 34 | uint StartFlowTime; 35 | uint EndFlowTime; 36 | ushort SourcePort; 37 | ushort DestPort; 38 | char filler[1]; 39 | byte TCPFlags; 40 | byte Protocol; 41 | byte TypeOfService; 42 | ushort SourceSysID; 43 | ushort DestSysID; 44 | byte SourceMaskBitsCount; 45 | byte DestMaskBitsCount; 46 | char filler2[2]; 47 | } data [ flow.header.Count ]; 48 | } flow; -------------------------------------------------------------------------------- /btparser/tests/OGGTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v4.0.4 Binary Template 3 | // 4 | // File: OGGTemplate.bt 5 | // Author: George Woods 6 | // Revision: 7 | // Purpose: Parses the ogg container format. 8 | //-------------------------------------- 9 | 10 | // ogg files can be quite large. Don't read more the 1000 pages. 11 | local uint MAXPAGES = 1000; 12 | 13 | typedef struct { // bmfh 14 | CHAR CapturePattern[4]; 15 | BYTE Version; 16 | BYTE HeaderType; 17 | QUAD GranulePosition; 18 | DWORD BitstreamSerial; 19 | DWORD PageSequenceNumber; 20 | DWORD Checksum; 21 | UBYTE PageSegments; 22 | 23 | // the lengths of the segments that follow 24 | UBYTE SegmentLen[PageSegments]; 25 | 26 | // the segments themselves 27 | local uint i; 28 | for (i = 0; i < PageSegments; i++) { 29 | struct { 30 | BYTE Data[SegmentLen[i]] ; 31 | } Segment; 32 | } 33 | } PAGE; 34 | 35 | 36 | LittleEndian(); 37 | 38 | local uint currpage = 0; 39 | while( !FEof() ) 40 | { 41 | currpage++; 42 | if (MAXPAGES < currpage) 43 | { 44 | Printf("Max Pages of %d reached!\n", maxpages); 45 | return 0; 46 | } 47 | 48 | PAGE page ; 49 | 50 | // Check for valid header 51 | if( page.CapturePattern != "OggS" ) 52 | { 53 | Warning( "File is not a valid ogg file. Template stopped." ); 54 | return -1; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /btparser/tests/OscarItemTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v5.0.2 Binary Template 3 | // 4 | // File: OscarItemTemplate.bt 5 | // Author: 6 | // Revision:1.0 7 | // Purpose: Template for binary journal 8 | // file used in AppleOne POS. 9 | //-------------------------------------- 10 | while( !FEof() ){ 11 | struct RECORD { 12 | char type; 13 | if (r.type == 'A'){ 14 | char unused ; 15 | short empNum; 16 | int ssn; 17 | short checkNum; 18 | short tableNum; 19 | short calcGuestCt; 20 | short openTime; 21 | short flagDeleted; 22 | short unused2; 23 | short pullBack; 24 | short itemCt; 25 | short guestCt; 26 | short takeoutTicket; 27 | int csiNumber; 28 | char junk[22]; 29 | } else { if (r.type == 'B'){ 30 | char unused ; 31 | short empNum; 32 | int ssn; 33 | short itemNum; 34 | short deptCat; 35 | short priceGrp; 36 | int price; 37 | int tax1Amt; 38 | int tax2Amt; 39 | short quantity; 40 | short taxStatusAcct; 41 | short specUserId; 42 | int plu; 43 | int managerSsn; 44 | short orderTime; 45 | byte seatNum; 46 | byte priceCode; 47 | byte xxExpansion; 48 | byte itemType; 49 | int reductionCode; 50 | int postPrice; 51 | } else { if (r.type == 'C' || r.type == 'D'){ 52 | char unused ; 53 | short empNum; 54 | int ssn; 55 | short itemNum; 56 | short deptCat; 57 | short priceGrp; 58 | int price; 59 | int tax1Amt; 60 | int tax2Amt; 61 | short quantity; 62 | short dupVoidCat; 63 | short managerNum; 64 | int plu; 65 | int managerSsn; 66 | short tranTime; 67 | byte seatNum; 68 | char unused2[3]; 69 | short voidCatId; 70 | char junk[6]; 71 | } else { if (r.type == 'E'){ 72 | char unused ; 73 | short empNum; 74 | int ssn; 75 | char unused2[6]; 76 | int discAmt; 77 | int tax1Amt; 78 | int tax2Amt; 79 | short quantity; 80 | short altDiscCat; 81 | short managerNum; 82 | char unused3[4]; 83 | int managerSsn; 84 | short discTime; 85 | byte seatNum; 86 | char unused4[3]; 87 | short discCatId; 88 | char junk[6]; 89 | } else { if (r.type == 'F'){ 90 | char unused ; 91 | short empNum; 92 | int ssn; 93 | short payCatId; 94 | int payAmt; 95 | int gratuity; 96 | int externalId; 97 | short status; 98 | int acctNum; 99 | int acctExHigh; 100 | int cashBack; 101 | char junk[18]; 102 | } else { if (r.type == 'K'){ 103 | char unused ; 104 | short empNum; 105 | int ssn; 106 | int amount; 107 | short closedTime; 108 | short origClsTime; 109 | int unused2; 110 | short dupEmpNum; 111 | int unused3; 112 | short origCheckNum; 113 | char junk[26]; 114 | } else { 115 | char junk[53] ; 116 | }}}}}} 117 | } r; 118 | } 119 | -------------------------------------------------------------------------------- /btparser/tests/PALTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v2.0.2 Template File 3 | // 4 | // File: PALTemplate.bt 5 | // Author: SweetScape Software 6 | // Revision: 1.1 7 | // Purpose: Parses a Microsoft PAL 8 | // palette file. 9 | // SweetScape: Changed display order 10 | // in ReadRGBQUAD to match the BMP 11 | // template (Oct 24th, 2007). 12 | //-------------------------------------- 13 | 14 | // Declare a structure for holding a color 15 | typedef struct 16 | { 17 | uchar red; 18 | uchar green; 19 | uchar blue; 20 | uchar alpha; 21 | } RGBQUAD ; 22 | 23 | // Custom read functions for color types - this allows the 24 | // color to be displayed without having to open up the structure. 25 | string ReadRGBQUAD( RGBQUAD &a ) 26 | { 27 | string s; 28 | SPrintf( s, "#%02X%02X%02X%02X", a.alpha, a.red, a.green, a.blue ); 29 | return s; 30 | } 31 | 32 | //--------------------------------------------- 33 | 34 | // Declare the file header 35 | char file_signature[4]; 36 | int file_length; 37 | char tag_type[4]; 38 | 39 | // Declare the RIFF chunk with color data 40 | char chunk_signature[4]; 41 | int chunk_size; 42 | ushort version ; //should be 300h 43 | ushort num_colors; 44 | RGBQUAD colors[ num_colors ]; 45 | -------------------------------------------------------------------------------- /btparser/tests/PCXTemplate.bt: -------------------------------------------------------------------------------- 1 | //------------------------------------ 2 | //--- 010 Editor v1.2 Binary Template 3 | // 4 | // Name: PCXTemplate.bt 5 | // Author: James Newton 6 | // Purpose: Sample template for PCX 7 | // header information. 8 | //------------------------------------ 9 | 10 | enum PCX_TYPE { 11 | v25 =0, //Version 2.5 of PC Paintbrush 12 | v28Pal =2, //Version 2.8 w/palette information 13 | v28 =3, //Version 2.8 w/o palette information 14 | v5Win =4, //PC Paintbrush for Windows(Plus for Windows uses Ver 5) 15 | v3up =5 //Version 3.0 and > of PC Paintbrush and PC Paintbrush +, includes Publisher's Paintbrush. Includes 24-bit .PCX files. 16 | } ; 17 | 18 | struct PCX { 19 | ubyte Manufacturer; //Constant Flag, 10 = ZSoft .pcx 20 | PCX_TYPE version; //Version information 21 | ubyte encoding; //1 = .PCX run length encoding 22 | ubyte BitsPerPixel; //Number of bits to represent a pixel (per Plane) - 1, 2, 4, or 8 23 | ushort Xmin; //Window. Image Dimensions: Xmin,Ymin,Xmax,Ymax 24 | ushort Ymin; // 25 | ushort Xmax; // 26 | ushort Ymax; // 27 | ushort HDpi; //Horizontal Resolution of image in DPI* 28 | ushort VDpi; //Vertical Resolution of image in DPI* 29 | ubyte Colormap[48]; //Color palette setting, see text 30 | ubyte Reserved; //Should be set to 0. 31 | ubyte NPlanes; //Number of color planes 32 | ushort BytesPerLine; //Number of bytes to allocate for a scanline plane. MUST be an EVEN number. Do NOT calculate from Xmax-Xmin. 33 | ushort PaletteInfo; //How to interpret palette- 1 = Color/BW, 2 = Grayscale (ignored in PB IV/ IV +) 34 | ushort HscreenSize; //Horizontal screen size in pixels. New field found only in PB IV/IV Plus 35 | ushort VscreenSize; //Vertical screen size in pixels. New field found only in PB IV/IV Plus 36 | ubyte Filler[54]; //Blank to fill out 128 byte header. Set all bytes to 0 37 | }; 38 | 39 | PCX file; 40 | -------------------------------------------------------------------------------- /btparser/tests/PNGTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v2.0.1 Binary Template 3 | // 4 | // File: PNGTemplate.bt 5 | // Author: Kevin O. Grover 6 | // Purpose: A template for parsing PNG (Portable Network Graphics) files. 7 | // Version: 1.1 2009-02-25 8 | // History: 9 | // 2005-05-11 KOG Initial version 10 | // 2005-06-29 KOG Fixed typos in comments 11 | // 2009-02-23 KOG Decode IHDR and tEXt chunks 12 | // 13 | // This template was written to the PNG 1.2 Specification. 14 | // Note however, that it does not check nor parse chunk subdata, so it 15 | // should work with all future PNG specifications. 16 | // 17 | // Also, a possible caveat: PNG encourages the type of chunks to be 18 | // mapped to strings of the form "[a-zA-Z]{4}". However, it's not a requirement. 19 | // 20 | // Summary of PNG Format: 21 | // A PNG file consists of an 8 byte ID followed by a series of chunks. 22 | // Each Chunk is 23 | // length (4 bytes), chunk_type (4 bytes), data (length bytes), crc (4 bytes) 24 | // CRC Does NOT include the length bytes. 25 | //-------------------------------------- 26 | 27 | BigEndian(); // PNG files are in Network Byte order 28 | 29 | const uint64 PNGMAGIC = 0x89504E470D0A1A0AL; 30 | 31 | // Chunk Type 32 | typedef union { 33 | uint32 ctype ; // Chunk Type 34 | char cname[4]; // character representation 35 | } CTYPE ; 36 | 37 | string readCTYPE(local CTYPE &t) { 38 | return t.cname; 39 | } 40 | 41 | // -- Specific Chunks 42 | 43 | // IHDR - Image Header 44 | 45 | typedef struct { 46 | uint32 width; 47 | uint32 height; 48 | ubyte bits; 49 | ubyte color_type; 50 | ubyte compression; 51 | ubyte filter; 52 | ubyte interlace; 53 | } IHDR ; 54 | 55 | string readIHDR(local IHDR &ihdr) { 56 | local string s; 57 | SPrintf(s, "%i x %i (x%i)", ihdr.width, ihdr.height, ihdr.bits); 58 | return s; 59 | } 60 | 61 | // tEXt - Text Data 62 | 63 | typedef struct { 64 | string label; // to the first NULL (including) 65 | char data[length - Strlen(label) - 1]; // rest of the data 66 | } tEXt ; 67 | 68 | string readtEXt(local tEXt &text) { 69 | local string s; 70 | SPrintf(s, "%s = %s", text.label, text.data); 71 | return s; 72 | } 73 | 74 | // -- End: Specific Chunks 75 | 76 | local uint32 CHUNK_CNT = 0; 77 | 78 | // Generic Chunks 79 | typedef struct { 80 | uint32 length; // Number of data bytes (not including length,type, or crc) 81 | local quad pos_start = FTell(); 82 | CTYPE type; // Type of chunk 83 | if (type.cname == "IHDR") { 84 | IHDR ihdr; 85 | } else if (type.cname == "tEXt") { 86 | tEXt text; 87 | } else { 88 | ubyte data[length]; // Data (or not present) 89 | } 90 | local quad data_size = FTell() - pos_start; 91 | uint32 crc ; // CRC type and data (not including length or crc) 92 | local uint32 crc_calc = Checksum(CHECKSUM_CRC32, pos_start, data_size); 93 | if (crc != crc_calc) { 94 | local string msg; 95 | SPrintf(msg, "*WARNING CRC Mismatch @ chunk[%d] (%08x != %08x)\n", CHUNK_CNT, crc, crc_calc); 96 | Warning(msg); 97 | Printf(msg); 98 | } 99 | CHUNK_CNT++; 100 | } CHUNK ; 101 | 102 | 103 | // Chunks can be in any order: HOWEVER, IHDR must be first, IEND must be last 104 | // Bit 5s in chunk type bytes are used to flag some things: 105 | // Ancillary bit: bit 5 of 1st byte: 0=Critical, 1=Ancillary 106 | // Private bit: bit 5 of 2nd byte: 0=Public, 1=Private 107 | // Reserved bit: bit 5 of 3rd byte: MUST be 0 108 | // Safe to Copy bit: bit 5 of 4th byte: 0=Unsafe to Copy, 1=Safe to Copy 109 | string readCHUNK(local CHUNK &c) { 110 | local string s; 111 | s=readCTYPE(c.type)+" ("; 112 | s += (c.type.cname[0] & 0x20) ? "Ancillary, " : "Critical, "; 113 | s += (c.type.cname[1] & 0x20) ? "Private, " : "Public, "; 114 | s += (c.type.cname[2] & 0x20) ? "ERROR_RESERVED, " : ""; 115 | s += (c.type.cname[3] & 0x20) ? "Safe to Copy)" : "Unsafe to Copy)"; 116 | return s; 117 | } 118 | 119 | // --------------------------------------------------------------------------- 120 | // MAIN -- Here's where we really allocate the data 121 | // --------------------------------------------------------------------------- 122 | 123 | uint64 pngid ; 124 | if (pngid != PNGMAGIC) { 125 | Warning("Invalid PNG File: Bad Magic Number"); 126 | return -1; 127 | } 128 | while(!FEof()) { 129 | CHUNK chunk; 130 | } 131 | if (CHUNK_CNT > 1) { 132 | if ((chunk[0].type.cname != "IHDR") || (chunk[CHUNK_CNT-1].type.cname != "IEND")) { 133 | local string msg; 134 | SPrintf(msg, "*WARNING: Chunk IHDR must be first and chunk IEND must be last!\n"); 135 | Warning(msg); 136 | Printf(msg); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /btparser/tests/RDBTemplate.bt: -------------------------------------------------------------------------------- 1 | //----------------------------------- 2 | //--- 010 Editor v2.0 Binary Template 3 | // 4 | // File: RDBTemplate.bt 5 | // Author: AnTler 6 | // Revision: 1.0 7 | // Purpose: Defines a template for parsing RDB files. 8 | // Changes: 9 | 10 | //----------------------------------- 11 | 12 | // Define structures used in RDB files 13 | 14 | // Defines a file header 15 | typedef struct { 16 | CHAR reserved[16]; 17 | DWORD fhFileTotalCount; 18 | INT64 fhFileNameOffBits ; 19 | INT64 fhFileDataOffBits ; 20 | } RDBFILEHEADER ; 21 | 22 | // Defines a file record 23 | typedef struct { 24 | local INT fileNameLength = 0; 25 | local USHORT value = 0; 26 | do 27 | { 28 | value = ReadUShort( FTell() + fileNameLength) ; 29 | fileNameLength += sizeof(value); 30 | } while(value != 0x0000); 31 | 32 | CHAR frCurFileName[fileNameLength]; 33 | INT64 frCurFileDataOffBits ; 34 | INT64 frCurFileDataSize; 35 | } RDBFILERECORD ; 36 | 37 | string ReadRDBFILERECORD( RDBFILERECORD &r ) 38 | { 39 | string s; 40 | SPrintf( s, "%s", r.frCurFileName); 41 | return s; 42 | } 43 | 44 | //-------------------------------------------- 45 | 46 | // Define the file 47 | LittleEndian(); 48 | 49 | RDBFILEHEADER rdbFileHeader; 50 | 51 | FSeek(rdbFileHeader.fhFileNameOffBits); 52 | 53 | local int i; 54 | for( i = 0; i < rdbFileHeader.fhFileTotalCount; i++ ) 55 | RDBFILERECORD rdbFileRecord; 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /btparser/tests/RIFFTemplate.bt: -------------------------------------------------------------------------------- 1 | //----------------------------------- 2 | //--- 010 Editor v2.0 Binary Template 3 | // 4 | // File: RIFFTemplate.bt 5 | // Author: gocha 6 | // Revision: 1.0 7 | // Purpose: Defines a template for 8 | // parsing generic RIFF files. 9 | //----------------------------------- 10 | 11 | typedef CHAR ID[4]; 12 | 13 | local int cOverTheRainbowIndex = 0; 14 | local int cOverTheRainbow[12] = { 15 | 0xbfbfef, 16 | 0xbfcfef, 17 | 0xbfefef, 18 | 0xbfefcf, 19 | 0xbfefbf, 20 | 0xcfefbf, 21 | 0xefefbf, 22 | 0xefcfbf, 23 | 0xefbfbf, 24 | 0xefbfcf, 25 | 0xefbfef, 26 | 0xcfbfef 27 | }; 28 | local int cGrayZone = 0xd9dadc; 29 | local int COLOR_LUT_LENGTH = sizeof(cOverTheRainbow) / sizeof(cOverTheRainbow[0]); 30 | 31 | //----------------------------------- 32 | // Define structures used in RIFF files 33 | 34 | typedef struct { 35 | ID chunkID; 36 | DWORD chunkSize; 37 | UCHAR data[chunkSize]; 38 | 39 | // Padding so the next chunk starts on an even byte 40 | if( (chunkSize & 1) && (FTell() < FileSize()) ) 41 | UCHAR padding; 42 | } CHUNK ; 43 | 44 | string ReadCHUNK( struct CHUNK &s ) 45 | { 46 | return s.chunkID; 47 | } 48 | 49 | //typedef struct LISTCHUNK LISTCHUNK; 50 | struct LISTCHUNK { 51 | ID chunkID; 52 | DWORD chunkSize; 53 | local quad pos = FTell(); 54 | ID chunkType; 55 | 56 | // Read the subchunks 57 | local char tag[5]; 58 | local DWORD size; 59 | while( FTell() - pos < chunkSize ) 60 | { 61 | // Read the chunk tag 62 | ReadBytes( tag, FTell(), 4 ); 63 | tag[4] = 0; 64 | 65 | // Read the chunk size 66 | size = ReadUInt( FTell() + 4 ); 67 | if( FTell() - pos + size > chunkSize ){ 68 | Printf( "Chunk '%s' of size %d at position 0x%LX exceeds the parent chunk size boundary.\n", tag, size, FTell() ); 69 | return -1; 70 | } 71 | 72 | // See which chunk this is 73 | switch( tag ) 74 | { 75 | case "LIST": 76 | SetBackColor( cGrayZone ); 77 | struct LISTCHUNK list; 78 | break; 79 | default: 80 | SetBackColor( cOverTheRainbow[cOverTheRainbowIndex] ); 81 | cOverTheRainbowIndex = (cOverTheRainbowIndex + 1) % COLOR_LUT_LENGTH; 82 | CHUNK subchunk; 83 | break; 84 | } 85 | } 86 | 87 | // Padding so the next chunk starts on an even byte 88 | if( (chunkSize & 1) && (FTell() < FileSize()) ) 89 | UCHAR padding; 90 | }; 91 | 92 | typedef struct 93 | { 94 | ID groupID; 95 | DWORD size; 96 | ID riffType; 97 | } RIFFHEADER; 98 | 99 | 100 | 101 | //--------------------------------------------- 102 | 103 | // Define the headers 104 | local quad riff_pos = FTell(); 105 | LittleEndian(); 106 | SetBackColor( cGrayZone ); 107 | RIFFHEADER header; 108 | 109 | // Check for valid header 110 | if( header.groupID != "RIFF" ) 111 | { 112 | Warning( "File is not a valid RIFF file. Template stopped." ); 113 | return -1; 114 | } 115 | 116 | // Read the file as a set of chunks 117 | local char tag[5]; 118 | local DWORD size; 119 | while( FTell() + 8 <= FileSize() && FTell() - riff_pos != header.size + 8 ) 120 | { 121 | // Read the chunk tag 122 | ReadBytes( tag, FTell(), 4 ); 123 | tag[4] = 0; 124 | 125 | // Read the chunk size 126 | size = ReadUInt( FTell() + 4 ); 127 | 128 | // See which chunk this is 129 | switch( tag ) 130 | { 131 | case "LIST": 132 | SetBackColor( cGrayZone ); 133 | LISTCHUNK list; 134 | break; 135 | default: 136 | SetBackColor( cOverTheRainbow[cOverTheRainbowIndex] ); 137 | cOverTheRainbowIndex = (cOverTheRainbowIndex + 1) % COLOR_LUT_LENGTH; 138 | CHUNK chunk; 139 | break; 140 | } 141 | } 142 | 143 | // Verify the whole file size 144 | local quad actual_size = FTell() - riff_pos; 145 | if( actual_size != 8 + header.size ) 146 | { 147 | Printf( "RIFF file size mismatch (header value %Ld, actual size %Ld).\n", header.size, actual_size - 8 ); 148 | return -1; 149 | } 150 | -------------------------------------------------------------------------------- /btparser/tests/RegistryPolicyFileTemplate.bt: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // 010 Editor v4.0.3d Binary Template 4 | // 5 | // File: RegistryPolicyFileTemplate.bt 6 | // Author: Blake Frantz (blakefrantz at gmail dot com) 7 | // Revision: 1.0, Last Updated on 6 Mar 2013. 8 | // Purpose: Parse registry.pol files. 9 | // See http://msdn.microsoft.com/en-us/library/windows/desktop/aa374407(v=vs.85).aspx 10 | // 11 | 12 | const DWORD REG_SZ = 1; 13 | const DWORD REG_EXPAND_SZ = 2; 14 | const DWORD REG_BINARY = 3; 15 | const DWORD REG_DWORD = 4; 16 | const DWORD REG_MULTI_SZ = 7; 17 | 18 | typedef struct 19 | { 20 | CHAR LBRACKET[2] ; 21 | wstring Key; 22 | SHORT seperator0 ; 23 | wstring ValueName; 24 | SHORT seperator1 ; 25 | DWORD Type ; 26 | SHORT seperator2 ; 27 | DWORD DataSize; 28 | SHORT seperator3 ; 29 | union { 30 | UBYTE Raw[DataSize]; 31 | DWORD Int; 32 | wstring String; 33 | } Data; 34 | 35 | CHAR RBRACKET[2] ; 36 | 37 | } REGISTRY_RECORD ; 38 | 39 | string DataValueTypeComment( DWORD type ) 40 | { 41 | string comment = ""; 42 | 43 | switch ( type ) 44 | { 45 | case REG_SZ : comment = "REG_SZ"; break; 46 | case REG_EXPAND_SZ: comment = "REG_EXPAND_SZ"; break; 47 | case REG_BINARY : comment = "REG_BINARY"; break; 48 | case REG_DWORD : comment = "REG_DWORD"; break; 49 | case REG_MULTI_SZ : comment = "REG_MULTI_SZ"; break; 50 | default : comment = "UNKNOWN_TYPE"; break; 51 | } 52 | 53 | return comment; 54 | } 55 | 56 | string RegistryRecordComment( REGISTRY_RECORD &record ) 57 | { 58 | string comment; 59 | 60 | uchar tempBuffer[ sizeof(record) ]; 61 | ReadBytes( tempBuffer, startof(record), sizeof(record) ); 62 | 63 | string result; 64 | ChecksumAlgArrayStr( CHECKSUM_CRC32, result, tempBuffer, sizeof(record)); 65 | 66 | if(WStrnicmp(record.ValueName, "**Del.", 6) == 0 ) 67 | { 68 | SPrintf(comment, "ValueName '%s' will be deleted from '%s'. CRC=%s", SubStr(record.ValueName, 6), record.Key, result); 69 | } 70 | else if(WStrnicmp(record.ValueName, "**DeleteValues", 14) == 0 ) 71 | { 72 | SPrintf(comment, "ValueNames '%s' will be deleted from '%s'. CRC=%s", SubStr(record.ValueName, 14), record.Key, result); 73 | } 74 | else if(WStrnicmp(record.ValueName, "**DelVals", 9) == 0 ) 75 | { 76 | SPrintf(comment, "All ValueNames under '%s' will be deleted. CRC=%s", record.Key, result); 77 | } 78 | else if(WStrnicmp(record.ValueName, "**DeleteKeys", 12) == 0 ) 79 | { 80 | SPrintf(comment, "Keys '%s' under '%s' will be deleted. CRC=%s", SubStr(record.ValueName, 12), record.Key, result); 81 | } 82 | else if(WStrnicmp(record.ValueName, "**SecureKey=0", 13) == 0 ) 83 | { 84 | SPrintf(comment, "The DACL on '%s' will be reset to align with the root's DACL. CRC=%s", record.Key, result); 85 | } 86 | else if(WStrnicmp(record.ValueName, "**SecureKey=1", 13) == 0 ) 87 | { 88 | SPrintf(comment, "The DACL on '%s' will be set as follows: Administrators, SYSTEM = Full; Users = Read Only. CRC=%s", record.Key, result); 89 | } 90 | else if(record.Type == REG_DWORD) 91 | { 92 | SPrintf(comment, "%s:%s = (REG_DWORD) %d. CRC=%s", record.Key, record.ValueName, record.Data.Int, result); 93 | } 94 | else if(record.Type == REG_SZ) 95 | { 96 | SPrintf(comment, "%s:%s = (REG_SZ) '%s'. CRC=%s", record.Key, record.ValueName, record.Data.String, result); 97 | } 98 | else if(record.Type == REG_EXPAND_SZ) 99 | { 100 | SPrintf(comment, "%s:%s = (REG_EXPAND_SZ) ... CRC=%s", record.Key, record.ValueName, result); 101 | } 102 | else if(record.Type == REG_BINARY) 103 | { 104 | SPrintf(comment, "%s:%s = (REG_BINARY) ... CRC=%s", record.Key, record.ValueName, result); 105 | } 106 | else if(record.Type == REG_MULTI_SZ) 107 | { 108 | SPrintf(comment, "%s:%s = (REG_MULTI_SZ) ... CRC=%s", record.Key, record.ValueName, result); 109 | } 110 | else 111 | { 112 | SPrintf(comment, "%s:%s (%s)", record.Key, record.ValueName, result); 113 | } 114 | 115 | return comment; 116 | } 117 | 118 | BigEndian(); 119 | 120 | DWORD REGFILE_SIGNATURE; 121 | 122 | LittleEndian(); 123 | 124 | DWORD REGISTRY_FILE_VERSION; 125 | 126 | if (REGFILE_SIGNATURE !=0x50526567 || REGISTRY_FILE_VERSION != 0x01 ) 127 | { 128 | Warning( "File is not Registry Policy File Format Version 1. Template stopped." ); 129 | return -1; 130 | } 131 | 132 | local int records = 0; 133 | 134 | while( !FEof() ) 135 | { 136 | REGISTRY_RECORD record; 137 | records++; 138 | } 139 | 140 | local int i; 141 | 142 | for (i=0; i < records; i++) 143 | { 144 | Printf("%s\\%s\n", record[i].Key, record[i].ValueName); 145 | } -------------------------------------------------------------------------------- /btparser/tests/SHPTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v2.1.3 Binary Template 3 | // 4 | // File: 5 | // Author: 6 | // Revision: 7 | // Purpose: 8 | //-------------------------------------- 9 | typedef struct point_s {double X; double Y;} POINT; 10 | 11 | string GetByteSize(int wordSize) 12 | { 13 | string s; 14 | SPrintf(s, "%d", 2*wordSize); 15 | return s; 16 | } 17 | 18 | struct ESRI_SHAPE { 19 | SetBackColor(cLtGreen); 20 | struct HEADER { 21 | BigEndian(); 22 | int fileCode; 23 | int unused[5]; 24 | int fileLength ; 25 | LittleEndian(); 26 | int version; 27 | enum ShapeEnum { 28 | NullShape, 29 | Point, 30 | PolyLine=3, 31 | Polygon=5, 32 | MultiPoint=5, 33 | PointZ=11, 34 | PolyLineZ=13, 35 | PolygonZ=15} shapeType; 36 | double Xmin; 37 | double Ymin; 38 | double Xmax; 39 | double Ymax; 40 | double Zmin; 41 | double Zmax; 42 | double Mmin; 43 | double Mmax; 44 | } header; 45 | SetBackColor(cLtGray); 46 | struct RECORD { 47 | BigEndian(); 48 | int recordNumber; 49 | int contentLength ; 50 | LittleEndian(); 51 | enum ShapeTypeEnum { 52 | NullShapeType, 53 | PointType, 54 | PolyLineType=3, 55 | PolygonType=5, 56 | MultiPointType=8, 57 | PointZType=11, 58 | PolyLineZType=13, 59 | PolygonZType=15, 60 | MultiPointZType=18, 61 | PointMType=21, 62 | PolyLineMType=23, 63 | PolygonMType=25, 64 | MultiPointMType=28, 65 | MultiPatchType=31} shapeType; 66 | if (shapeType == 1) 67 | { 68 | POINT location; 69 | } 70 | else if (shapeType == 3) 71 | { 72 | double box[4]; 73 | int numParts; 74 | int numPoints; 75 | int parts[numParts]; 76 | POINT points[numPoints]; 77 | } 78 | else if (shapeType == 5) 79 | { 80 | double box[4]; 81 | int numParts; 82 | int numPoints; 83 | int parts[numParts]; 84 | POINT points[numPoints]; 85 | } 86 | } record [10000] ; 87 | } esri_shape; -------------------------------------------------------------------------------- /btparser/tests/SHXTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v2.1.3 Binary Template 3 | // 4 | // File: 5 | // Author: 6 | // Revision: 7 | // Purpose: 8 | //-------------------------------------- 9 | typedef struct point_s {double X; double Y;} POINT; 10 | 11 | string GetByteSize(int wordSize) 12 | { 13 | string s; 14 | SPrintf(s, "%d", 2*wordSize); 15 | return s; 16 | } 17 | 18 | struct ESRI_INDEX { 19 | SetBackColor(cLtGreen); 20 | struct HEADER { 21 | BigEndian(); 22 | int fileCode; 23 | int unused[5]; 24 | int fileLength ; 25 | LittleEndian(); 26 | int version; 27 | enum ShapeEnum { 28 | NullShape, 29 | Point, 30 | PolyLine=3, 31 | Polygon=5, 32 | MultiPoint=5, 33 | PointZ=11, 34 | PolyLineZ=13, 35 | PolygonZ=15} shapeType; 36 | double Xmin; 37 | double Ymin; 38 | double Xmax; 39 | double Ymax; 40 | double Zmin; 41 | double Zmax; 42 | double Mmin; 43 | double Mmax; 44 | } header; 45 | SetBackColor(cLtGray); 46 | struct INDEX_RECORD { 47 | BigEndian(); 48 | int offset ; 49 | int contentLength ; 50 | } record [(FileSize() - 100)/8]; 51 | 52 | } esri_index; -------------------------------------------------------------------------------- /btparser/tests/SRecTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v5.0 Binary Template 3 | // 4 | // File: SRecTemplate.bt 5 | // Author: Mario Ghecea 6 | // Revision: 1A 7 | // Purpose: Parses Motorola S-REC 8 | //-------------------------------------- 9 | typedef char RECORDTYPE [2]; 10 | typedef char COUNT [2]; 11 | typedef char ADDRESS16 [4]; 12 | typedef char ADDRESS24 [6]; 13 | typedef char ADDRESS32 [8]; 14 | typedef char CHECKSUM [2]; 15 | 16 | local char hexval [10]; 17 | local uint addrwidth; 18 | local uint rec = 1; 19 | 20 | typedef struct 21 | { 22 | RECORDTYPE recordType; 23 | COUNT count; 24 | switch(recordType) 25 | { 26 | case "S0": // header 27 | case "S1": // 16-bit address record 28 | case "S5": // total record count 29 | case "S9": // termination 16-bit 30 | ADDRESS16 address16; 31 | addrwidth = 4; 32 | break; 33 | case "S2": // 24-bit address record 34 | case "S8": // termination 24-bit 35 | ADDRESS24 address24; 36 | addrwidth = 6; 37 | break; 38 | case "S3": // 32-bit address record 39 | case "S7": // termination 32-bit 40 | ADDRESS32 adress32; 41 | addrwidth = 8; 42 | break; 43 | //case "S4": 44 | //case "S6": 45 | default: 46 | break; 47 | } 48 | 49 | local int i; 50 | local int intval = 0; 51 | local uint pow = 0; 52 | local uint hexlen = 2; 53 | local uint digit = 0; 54 | for (i = 0; i < hexlen; i ++) 55 | { 56 | digit = (count[i] - '0' > 9) ? count[i] - '7' : count[i] - '0'; 57 | intval += ((uint32) digit * (1 << 4 * ((hexlen - 1) - i))); 58 | } 59 | local uint bytesPerLine = (uint32) ((intval - 1) * 2) - addrwidth; 60 | if (bytesPerLine != 0) 61 | char data [(bytesPerLine)]; 62 | //Printf("rec# %d bpl: %d %X count : %s\n\r", rec++, bytesPerLine, intval, count); 63 | char checksum [2]; 64 | char crlf[2]; 65 | }SREC; 66 | 67 | while( !FEof() ) 68 | { 69 | SREC srec; 70 | } -------------------------------------------------------------------------------- /btparser/tests/SSPTemplate.bt: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------- 2 | //--- 010 Editor v3.2 Binary Template 3 | // 4 | // File: SSPTemplate.bt 5 | // Author: ThangCuAnh (TQN) - HVA 6 | // Revision: 0.1, prototypes 7 | // Date: 2010/10/09 8 | // Purpose: Define a template for parsing SmartSniff Packet file 9 | // References: http://www.nirsoft.net/utils/smsniff.html 10 | //--------------------------------------------------------------- 11 | 12 | typedef BYTE IP_ADDRESS[4] ; 13 | typedef BYTE MAC_ADDRESS[6] ; 14 | 15 | string IP2Str(IP_ADDRESS ip) 16 | { 17 | string strReturn; 18 | 19 | SPrintf(strReturn, "IP: %02d.%02d.%02d.%02d", ip[0], ip[1], ip[2], ip[3]); 20 | return strReturn; 21 | } 22 | 23 | typedef struct { 24 | char signature[8]; // SMSNF200 25 | WORD numberOfBytesInHeader; 26 | IP_ADDRESS IP; 27 | 28 | if ((Strcmp(signature, "SMSNF200") != 0) || (numberOfBytesInHeader != 4)) 29 | { 30 | Warning("Not a valid SmartSniff Packet file"); 31 | return -1; 32 | } 33 | } SSP_HEADER; 34 | 35 | typedef struct { 36 | WORD packetHeaderSize; 37 | if (packetHeaderSize != 0x18) 38 | { 39 | Waring("Invalid packetHeaderSize"); 40 | return -1; 41 | } 42 | DWORD numberOfReceivedBytes; 43 | FILETIME fileTime; 44 | MAC_ADDRESS sourceMAC; 45 | MAC_ADDRESS destMAC; 46 | BYTE packet[numberOfReceivedBytes] ; 47 | } SSP_PACKET; 48 | 49 | string MAC2Str(MAC_ADDRESS mac) 50 | { 51 | string strReturn; 52 | SPrintf(strReturn, "%02X-%02X-%02X-%02X-%02X-%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 53 | 54 | return strReturn; 55 | } 56 | 57 | // Define the headers 58 | LittleEndian(); 59 | SSP_HEADER header; 60 | 61 | while (!FEof()) 62 | { 63 | SSP_PACKET record; 64 | } 65 | 66 | return 1; 67 | -------------------------------------------------------------------------------- /btparser/tests/STLTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v3.0.5 Binary Template 3 | // 4 | // File: STLTemplate.bt 5 | // Author: ZiZi 6 | // E-mail: zefars@rambler.ru 7 | // Revision: 1.2 8 | // Purpose: Defines a template for 9 | // parsing STL 3D-data files. 10 | //----------------------------------- 11 | 12 | typedef struct { 13 | CHAR Caption[80]; 14 | DWORD trCount; 15 | } STLFILEHEADER ; 16 | 17 | string STLFILEHEADERRead(STLFILEHEADER &x) 18 | { 19 | return x.Caption; 20 | }; 21 | 22 | typedef struct { 23 | FLOAT x; 24 | FLOAT y; 25 | FLOAT z; 26 | } tVector3f ; 27 | string tVector3fRead( tVector3f &v ) { 28 | string s; 29 | SPrintf( s, "(%6.2f %6.2f %6.2f)", v.x, v.y, v.z ); 30 | return s; 31 | }; 32 | 33 | typedef struct { 34 | tVector3f Normal; 35 | tVector3f Point0; 36 | tVector3f Point1; 37 | tVector3f Point2; 38 | WORD Flags ; 39 | } STLTRIANGLE; 40 | 41 | //--------------------------------------------- 42 | 43 | LittleEndian(); 44 | SetBackColor( cLtAqua ); 45 | 46 | local CHAR text_sign[5]; 47 | ReadBytes( text_sign, FTell(), 5); 48 | if (text_sign=="solid") 49 | { 50 | Warning("Is ASCII STL"); 51 | return; 52 | } 53 | STLFILEHEADER stlh; 54 | SetBackColor( cNone ); 55 | local int64 n=(FileSize()-84)/50; 56 | if (stlh.trCount!=n) Warning("File corrupted: stlh.trCount must be equal %Ld", n); 57 | STLTRIANGLE Data[n]; 58 | -------------------------------------------------------------------------------- /btparser/tests/SinclairMicrodriveImage.bt: -------------------------------------------------------------------------------- 1 | //----------------------------------- 2 | //--- 010 Editor v2.0 Binary Template 3 | // 4 | // File: SinclairMicrodriveImage.bt 5 | // Author: 6 | // Revision: 1.0 7 | // Purpose: Defines a template for parsing 8 | // images of emulated Sinclair Microdrive 9 | // cartridges. 10 | //----------------------------------- 11 | 12 | struct { 13 | ubyte HDFLAG[1]; // Value 1, to indicate header block *See note. 14 | // char HDNUMB[1]; // sector number (values 254 down to 1) 15 | ubyte HDNUMB[1]; 16 | ubyte UNUSED[2]; // not used (and of undetermined value) 17 | ubyte HDNAME[10]; // microdrive cartridge name (blank padded) 18 | ubyte HDCHK[1]; //header checksum (of first 14 bytes) 19 | 20 | ubyte RECFLG[1]; // - bit 0: always 0 to indicate record block 21 | // - bit 1: set for the EOF block 22 | // - bit 2: reset for a PRINT file 23 | // - bits 3-7: not used (value 0) 24 | 25 | ubyte RECNUM[1]; // data block sequence number (value starts at 0) 26 | ubyte RECLEN[2]; // data block length (<=512, LSB first) 27 | ubyte RECNAM[10]; // filename (blank padded) 28 | ubyte DESCHK[1]; // record descriptor checksum (of previous 14 bytes) 29 | ubyte CHDATA[512]; // data block 30 | ubyte DCHK[1]; // data block checksum (of all 512 bytes of data 31 | // block, even when not all bytes are used) 32 | } MicrodriveSector[254] ; 33 | ubyte WriteProtectionFlag[1]; 34 | -------------------------------------------------------------------------------- /btparser/tests/TGATemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v2.0.2 Binary Template 3 | // 4 | // File: TGATemplate.bt 5 | // Author: Chiuta Adrian Marius 6 | // E-mail: camsoftwarero@yahoo.com 7 | // Revision: 1.0 8 | // Purpose: Shows the fields of a TGA image. 9 | //-------------------------------------- 10 | 11 | //Definim structurile folosite de TGA 12 | typedef struct{ 13 | WORD FirstIndexEntry; 14 | WORD ColorMapLength; 15 | UBYTE ColorMapEntrySize; 16 | }COLORMAPSPECIFICATION; 17 | 18 | typedef struct{ 19 | WORD XOrigin; 20 | WORD YOrigin; 21 | WORD Width; 22 | WORD Height; 23 | UBYTE PixelDepth; 24 | UBYTE ImageDescriptor; 25 | }IMAGESPECIFICATION ; 26 | 27 | typedef struct{ 28 | UBYTE IDLength; 29 | UBYTE ColorMapType; 30 | UBYTE ImageType; 31 | COLORMAPSPECIFICATION CMSpecification; 32 | IMAGESPECIFICATION ISpecification; 33 | }TGAFILEHEADER ; 34 | 35 | typedef struct{ 36 | DWORD B:5; 37 | DWORD G:5; 38 | DWORD R:5; 39 | }RGB555 ; 40 | 41 | typedef struct{ 42 | DWORD B:5; 43 | DWORD G:5; 44 | DWORD R:5; 45 | DWORD X:1; 46 | }XRGB1555 ; 47 | 48 | typedef struct{ 49 | UBYTE B; 50 | UBYTE G; 51 | UBYTE R; 52 | }RGB888 ; 53 | 54 | typedef struct{ 55 | UBYTE B; 56 | UBYTE G; 57 | UBYTE R; 58 | UBYTE A; 59 | }ARGB8888 ; 60 | 61 | string ReadTGAHeader(TGAFILEHEADER &a) 62 | { 63 | switch( a.ImageType ) 64 | { 65 | case 0: 66 | return "No Image Data Included"; 67 | case 1: 68 | return "Uncompressed, Color-mapped Image"; 69 | case 2: 70 | return "Uncompressed, True-color Image"; 71 | case 3: 72 | return "Uncompressed, Black-and-white Image"; 73 | case 9: 74 | return "Run-length encoded, Color-mapped Image"; 75 | case 10: 76 | return "Run-length encoded, True-color Image"; 77 | case 11: 78 | return "Run-length encoded, Black-and-white Image"; 79 | } 80 | } 81 | string ReadImageSpecification(IMAGESPECIFICATION &a) 82 | { 83 | string s; 84 | SPrintf( s, "Res: %dx%d^%d", a.Width, a.Height, a.PixelDepth ); 85 | return s; 86 | } 87 | string ReadRGB555( RGB555 &a ) 88 | { 89 | string s; 90 | SPrintf( s, "B=%03d G=%03d R=%03d", a.B, a.G, a.R ); 91 | return s; 92 | } 93 | string ReadXRGB1555( XRGB1555 &a ) 94 | { 95 | string s; 96 | SPrintf( s, "X=%1d B=%03d G=%03d R=%03d",a.X, a.B, a.G, a.R ); 97 | return s; 98 | } 99 | 100 | string ReadRGB888( RGB888 &a ) 101 | { 102 | string s; 103 | SPrintf( s, "B=%03d G=%03d R=%03d", a.B, a.G, a.R ); 104 | return s; 105 | } 106 | 107 | string ReadARGB8888( ARGB8888 &a ) 108 | { 109 | string s; 110 | SPrintf( s, "A=%03d B=%03d G=%03d R=%03d",a.A, a.B, a.G, a.R ); 111 | return s; 112 | } 113 | 114 | LittleEndian(); 115 | SetBackColor( cLtGray ); 116 | //Definim headerului fisierului TGA 117 | TGAFILEHEADER TGAfh; 118 | 119 | 120 | if( TGAfh.IDLength!=0 )//Definim ID-ul imaginii TGA 121 | UBYTE ImageID[ TGAfh.IDLength ]; 122 | 123 | SetBackColor( cSilver ); 124 | //Definim culorile indexate asociate TGA-ului 125 | if( TGAfh.ColorMapType!=0 ) 126 | switch( TGAfh.CMSpecification.ColorMapEntrySize) 127 | { 128 | case 15: 129 | RGB555 ColorMap[ TGAfh.CMSpecification.ColorMapLength ]; 130 | break; 131 | case 16: 132 | XRGB1555 ColorMap[ TGAfh.CMSpecification.ColorMapLength ]; 133 | break; 134 | case 24: 135 | RGB888 ColorMap[ TGAfh.CMSpecification.ColorMapLength ]; 136 | break; 137 | case 32: 138 | ARGB8888 ColorMap[ TGAfh.CMSpecification.ColorMapLength ]; 139 | break; 140 | } 141 | SetBackColor( cLtAqua ); 142 | struct TGALine { 143 | switch( TGAfh.ISpecification.PixelDepth ) 144 | { 145 | case 8: 146 | UBYTE ColorIndex[TGAfh.ISpecification.Height]; 147 | break; 148 | case 16: 149 | XRGB1555 Pixel[TGAfh.ISpecification.Height]; 150 | break; 151 | case 24: 152 | RGB888 Pixel[TGAfh.ISpecification.Height]; 153 | break; 154 | case 32: 155 | ARGB8888 Pixel[TGAfh.ISpecification.Height]; 156 | break; 157 | } 158 | }TGALines [ TGAfh.ISpecification.Width ] ; 159 | -------------------------------------------------------------------------------- /btparser/tests/TOCTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v2.1.4 Binary Template 3 | // 4 | // File: TOCTemplate.bt 5 | // Author: L. Potjewijd 6 | // Revision: 1.22 7 | // Purpose: Eudora 7.1.0.9 mailbox .TOC files 8 | //-------------------------------------- 9 | enum type {In,Out,Junk,Trash,User,IMAP=8}; 10 | enum class {user,system}; 11 | enum stat {unread,read,replied,forwarded,redirected,rebuilt,sendable,queued,sent,unsent,timed,sending,recovered}; 12 | 13 | typedef struct 14 | { char EudoraVersion[8]; // might contain something else, too 15 | char MailboxName[32]; // this name is used in the window title 16 | type MailboxType; 17 | short Unknown0; 18 | class MailboxClass; 19 | struct 20 | { short TopLeftX; // default = 80 21 | short TopLeftY; // default = 80 22 | short BottomRightX; // default = 565 23 | short BottomRightY; // default = 415 24 | } WindowPosition; 25 | // -1 = default size and location. 26 | // For non-maximized and non-minimized windows only, 27 | // relative to the main window upper left corner. 28 | // All values are clipped to main window boundaries 29 | // on next opening, minimum window size is 112*27 (X*Y) 30 | // and takes precedence over clipping. 31 | 32 | struct 33 | { short StatusColumnWidth; // default = 2 34 | short JunkScoreColumnWidth; // default = 4 35 | short PriorityColumnWidth; // default = 2 36 | short AttachmentColumnWidth; // default = 2 37 | short LabelColumnWidth; // default = 8 38 | short WhoColumnWidth; // default = 16 39 | short DateColumnWidth; // default = 16 40 | short SizeColumnWidth; // default = 2 41 | } ColumnWidths; 42 | // Measurement unit is unknown (not pixels); pica's? 43 | // Window size takes precedence over column width. 44 | // The server and mood status columns are always 45 | // displayed with a width of 2 when the window is 46 | // opened, the subject column gets whatever is left. 47 | // -1 means default width. 48 | short Unknown1; 49 | long HighestMsgSeqNumber; 50 | short Unknown2[4]; 51 | short PreviewPaneDivider; 52 | short Unknown3[5]; 53 | long NewMessageOffsetMBXfile; // = FileSize ( .mbx file ) + 1 54 | short Unknown4; 55 | short MessagesInMailbox; // number of active messages in mailbox 56 | } TOChdr; // 104 bytes in total 57 | 58 | typedef struct 59 | { long OffsetMBXfile ; 60 | long Length; 61 | time_t GMTtimestamp; 62 | stat Status; 63 | SetForeColor(cGreen); 64 | ubyte Flags1 :8 ; 65 | // LSB SignatureUsed was: alternate signature 66 | // . obsolete was: signature used 67 | // . WordwrapON 68 | // . TabsInBody 69 | // . KeepCopyOfSentMessage 70 | // . InlineTextAttachment 71 | // . ReturnReceiptTo 72 | // MSB QuotedPrintable 73 | ubyte Flags2 :8 ; 74 | // LSB MIMEencoded 75 | // . UUencoded neither means BINHEX encoded 76 | // . obsolete was: ShowAllHeaders 77 | // . 78 | // . 79 | // . Text/HTML/Enriched 80 | // . ReceiptRequestPending 81 | // MSB Attachments 82 | SetForeColor(cNone); 83 | short Priority; 84 | char LocalDateTime[32]; 85 | char Who[64]; 86 | char Subject[64]; 87 | struct 88 | { short TopLeftX; 89 | short TopLeftY; 90 | short BottomRightX; 91 | short BottomRightY; 92 | } WindowPosition; 93 | 94 | short Label; 95 | long OffsetLMOSfile ; 96 | long MsgSeqNumber; 97 | SetForeColor(cPurple); 98 | ubyte Flags3 :8 ; 99 | // LSB 100 | // . 101 | // . 102 | // . 103 | // . 104 | // . 105 | // . 106 | // MSB looks like 'Return Receipt To:' header flag 107 | ubyte Flags4 :8 ; 108 | // LSB 109 | // . 110 | // . 111 | // . 112 | // . 113 | // . 114 | // . 115 | // MSB 116 | SetForeColor(cNone); 117 | short Unknown[10]; 118 | } TOCmsg; // 218 bytes in total 119 | 120 | //==================================================================== 121 | 122 | LittleEndian(); 123 | TOChdr hdr; 124 | while( !FEof() ) 125 | { TOCmsg msg; 126 | } 127 | -------------------------------------------------------------------------------- /btparser/tests/UTMPTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v5.0beta1 Binary Template 3 | // 4 | // File: UTMPTemplate.bt 5 | // Author: Matthew Geiger 6 | // Revision: 0.1 7 | // Purpose: Parsing entries in wtmp and utmp files on *nix hosts 8 | //-------------------------------------- 9 | 10 | #define UT_LINESIZE 32 11 | #define UT_NAMESIZE 32 12 | #define UT_HOSTSIZE 256 13 | 14 | LittleEndian(); 15 | 16 | typedef enum { /* Should be a short(?), but not on Linux systems I have seen */ 17 | EMPTY = 0, /* Record does not contain valid info 18 | (formerly known as UT_UNKNOWN on Linux) */ 19 | RUN_LVL = 1, /* Change in system run-level (see 20 | init(8)) */ 21 | BOOT_TIME = 2, /* Time of system boot (in ut_tv) */ 22 | NEW_TIME = 3, /* Time after system clock change 23 | (in ut_tv) */ 24 | OLD_TIME = 4, /* Time before system clock change 25 | (in ut_tv) */ 26 | INIT_PROCESS = 5, /* Process spawned by init(8) */ 27 | LOGIN_PROCESS = 6, /* Session leader process for user login */ 28 | USER_PROCESS = 7, /* Normal process */ 29 | DEAD_PROCESS = 8, /* Terminated process */ 30 | ACCOUNTING = 9 /* Not implemented */ 31 | } LOGIN_TYPE; 32 | 33 | 34 | struct exit_status 35 | { 36 | short e_termination; /* Process termination status. */ 37 | short e_exit; /* Process exit status. */ 38 | }; 39 | 40 | 41 | struct utmp 42 | { 43 | LOGIN_TYPE ut_type; /* Type of login. */ 44 | int ut_pid; /* Process ID of login process. */ 45 | char ut_line[UT_LINESIZE]; /* Devicename. */ 46 | char ut_id[4]; /* Inittab ID. */ 47 | char ut_user[UT_NAMESIZE]; /* Username. */ 48 | char ut_host[UT_HOSTSIZE]; /* Hostname for remote login. */ 49 | struct exit_status ut_exit; /* Exit status of a process marked 50 | as DEAD_PROCESS. */ 51 | long ut_session; /* Session ID, used for windowing. */ 52 | time_t high_timeval; /* Time entry was made. */ 53 | int low_timeval; 54 | int ut_addr_v6[4]; /* Internet address of remote host. */ 55 | char __unused[20]; /* Reserved for future use. */ 56 | }; 57 | 58 | 59 | FSeek(0); 60 | while( !FEof() ) 61 | { 62 | utmp UTMP_entry; 63 | } -------------------------------------------------------------------------------- /btparser/tests/WinhexPosTemplate.bt: -------------------------------------------------------------------------------- 1 | //-------------------------------------- 2 | //--- 010 Editor v3.2.2f Binary Template 3 | // 4 | // File: WinhexPosTemplate 5 | // Author: Artur Babecki 6 | // Revision: 21.02.2012 7 | // Purpose: the WinHex (editor by X-Ways Software Technology AG ) 8 | // stores the find results in the winhex.pos file. 9 | // This template parses its structure and allows to 10 | // build the script to convert WinHex results into set 11 | // of bookmarks of 010Editor 12 | //-------------------------------------- 13 | string Wh_WinhexID ; 14 | uint32 Wh_Flags ; 15 | uint32 Wh_n_ch ; 16 | struct chunk { 17 | uint16 Chsize ; 18 | uint16 Chflags ; 19 | uint64 Offset; 20 | uint64 Time; 21 | FILETIME date; 22 | uchar RGB[3]; 23 | uchar Padding; 24 | uint16 DescrLen; 25 | string Descr; 26 | if(Chflags&0x100) { 27 | uint64 Relative_Offset; 28 | uint64 FileId; 29 | uint16 PathLen; 30 | string Path; 31 | } 32 | //Printf("%X\n",chflags); 33 | } wh_pos[Wh_n_ch] ; 34 | -------------------------------------------------------------------------------- /btparser/tests/comment.bt: -------------------------------------------------------------------------------- 1 | //this is a single line comment string x = "3"; 2 | int x = 5; 3 | /* 4 | 5 | this 6 | 7 | is a 8 | 9 | multline comment*/int y = 4; -------------------------------------------------------------------------------- /btparser/tests/comment_error.bt: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | this is an unterminated comment -------------------------------------------------------------------------------- /btparser/tests/exp_lex/AndroidManifestTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: 13 | 13: 14 | 14: 15 | 15: typedef struct { 16 | 16: uint magicnumber ; 17 | 17: uint filesize ; 18 | 18: } HEADER ; 19 | 19: 20 | 20: 21 | 21: typedef struct { 22 | 22: ushort sfSize ; 23 | 23: if ( sfSize > 0 ) 24 | 24: { 25 | 25: struct { 26 | 26: char c1 ; 27 | 27: char c2 ; 28 | 28: } ONECHAR [ sfSize ] ; 29 | 29: } 30 | 30: ushort sfEnd ; 31 | 31: } STRING_ITEM ; 32 | 32: 33 | 33: 34 | 34: 35 | 35: typedef struct { 36 | 36: uint scSignature ; 37 | 37: uint scSize ; 38 | 38: uint scStringCount ; 39 | 39: uint scStyleCount ; 40 | 40: uint scUNKNOWN ; 41 | 41: uint scStringPoolOffset ; 42 | 42: uint scStylePoolOffset ; 43 | 43: uint scStringOffsets [ scStringCount ] < comment = "Relative to the 0x8+scStringPoolOffset" > ; 44 | 44: 45 | 45: if ( scStyleCount > 0 ) 46 | 46: uint scStyleOffset [ scStylePoolOffset ] ; 47 | 47: 48 | 48: 49 | 49: local int i ; 50 | 50: for ( i = 0 ; i < scStringCount ; i ++ ) 51 | 51: { 52 | 52: if ( ( 0x8 + scStringPoolOffset + scStringOffsets [ i ] ) < ( 0x8 + scSize ) ) 53 | 53: { 54 | 54: FSeek ( 0x8 + scStringPoolOffset + scStringOffsets [ i ] ) ; 55 | 55: STRING_ITEM strItem ; 56 | 56: } 57 | 57: } 58 | 58: 59 | 59: } STRINGCHUNK ; 60 | 60: 61 | 61: 62 | 62: typedef struct { 63 | 63: 64 | 64: local int pos = FTell ( ) ; 65 | 65: 66 | 66: uint rcSignature ; 67 | 67: uint rcSize ; 68 | 68: uint rcItem [ rcSize / 4 - 2 ] ; 69 | 69: 70 | 70: } RESOURCEIDCHUNK ; 71 | 71: 72 | 72: 73 | 73: typedef struct { 74 | 74: uint sncSignature ; 75 | 75: uint sncSize ; 76 | 76: uint sncLineNumber ; 77 | 77: uint sncUNKNOWN ; 78 | 78: uint sncPrefix ; 79 | 79: uint sncUri ; 80 | 80: } SNCHUNK ; 81 | 81: 82 | 82: 83 | 83: typedef struct { 84 | 84: uint encSignature ; 85 | 85: uint encSize ; 86 | 86: uint encLineNumber ; 87 | 87: uint encUNKNOWN ; 88 | 88: uint encPrefix ; 89 | 89: uint encUri ; 90 | 90: } ENCHUNK ; 91 | 91: 92 | 92: 93 | 93: typedef struct { 94 | 94: uint acNamespaceUri ; 95 | 95: uint acName ; 96 | 96: uint acValueStr ; 97 | 97: uint acType < comment = "right shift 24bit" > ; 98 | 98: uint acData ; 99 | 99: } ATTRIBUTECHUNK ; 100 | 100: 101 | 101: 102 | 102: 103 | 103: typedef struct { 104 | 104: local int pos = FTell ( ) ; 105 | 105: uint stcSignature ; 106 | 106: uint stcSize ; 107 | 107: uint stcLineNumber ; 108 | 108: uint stcUNKNOWN ; 109 | 109: uint stcNamespaceUri ; 110 | 110: uint stcName ; 111 | 111: uint stcFlags ; 112 | 112: uint stcAttributeCount ; 113 | 113: uint stcClassAttribute ; 114 | 114: 115 | 115: while ( FTell ( ) != pos + stcSize ) 116 | 116: ATTRIBUTECHUNK attributeChunk ; 117 | 117: } STCHUNK ; 118 | 118: 119 | 119: 120 | 120: typedef struct { 121 | 121: uint etcSignature ; 122 | 122: uint etcSize ; 123 | 123: uint etcLineNumber ; 124 | 124: uint etcUNKNOWN ; 125 | 125: uint etcNamespaceUri ; 126 | 126: uint etcName ; 127 | 127: } ETCHUNK ; 128 | 128: 129 | 129: 130 | 130: typedef struct { 131 | 131: uint tcSignature ; 132 | 132: uint tcSize ; 133 | 133: uint tcLineNumber ; 134 | 134: uint tcUNKNOWN ; 135 | 135: uint tcName ; 136 | 136: uint tcUNKNOWN ; 137 | 137: uint tcUNNNOWN ; 138 | 138: } TEXTCHUNK ; 139 | 139: 140 | 140: 141 | 141: 142 | 142: 143 | 143: local uint tag ; 144 | 144: 145 | 145: LittleEndian ( ) ; 146 | 146: HEADER header ; 147 | 147: 148 | 148: SetBackColor ( cLtGreen ) ; 149 | 149: STRINGCHUNK stringChunk ; 150 | 150: 151 | 151: FSeek ( 0x8 + stringChunk . scSize ) ; 152 | 152: 153 | 153: SetBackColor ( cLtBlue ) ; 154 | 154: RESOURCEIDCHUNK resourceChunk ; 155 | 155: FSeek ( resourceChunk . pos + resourceChunk . rcSize ) ; 156 | 156: 157 | 157: while ( ! FEof ( ) ) 158 | 158: { 159 | 159: 160 | 160: tag = ReadUInt ( FTell ( ) ) ; 161 | 161: 162 | 162: 163 | 163: if ( tag == 0x100100 ) 164 | 164: { 165 | 165: SetBackColor ( cLtPurple ) ; 166 | 166: SNCHUNK startNamespaceChunk ; 167 | 167: } 168 | 168: else if ( tag == 0x100101 ) 169 | 169: { 170 | 170: SetBackColor ( cLtPurple ) ; 171 | 171: ENCHUNK endNamespaceChunk ; 172 | 172: } 173 | 173: else if ( tag == 0x100102 ) 174 | 174: { 175 | 175: SetBackColor ( cLtGreen ) ; 176 | 176: STCHUNK startTagChunk ; 177 | 177: } 178 | 178: else if ( tag == 0x100103 ) 179 | 179: { 180 | 180: SetBackColor ( cLtGreen ) ; 181 | 181: ETCHUNK endTagChunk ; 182 | 182: } 183 | 183: else if ( tag == 0x100104 ) 184 | 184: { 185 | 185: SetBackColor ( cLtBlue ) ; 186 | 186: TEXTCHUNK TextChunk ; 187 | 187: } 188 | 188: } 189 | 189: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/BMPTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: 13 | 13: typedef struct { 14 | 14: CHAR bfType [ 2 ] ; 15 | 15: DWORD bfSize ; 16 | 16: WORD bfReserved1 ; 17 | 17: WORD bfReserved2 ; 18 | 18: DWORD bfOffBits ; 19 | 19: } BITMAPFILEHEADER ; 20 | 20: 21 | 21: typedef struct { 22 | 22: DWORD biSize ; 23 | 23: LONG biWidth ; 24 | 24: LONG biHeight ; 25 | 25: WORD biPlanes ; 26 | 26: WORD biBitCount ; 27 | 27: DWORD biCompression ; 28 | 28: DWORD biSizeImage ; 29 | 29: LONG biXPelsPerMeter ; 30 | 30: LONG biYPelsPerMeter ; 31 | 31: DWORD biClrUsed ; 32 | 32: DWORD biClrImportant ; 33 | 33: } BITMAPINFOHEADER ; 34 | 34: 35 | 35: typedef struct { 36 | 36: UBYTE rgbBlue ; 37 | 37: UBYTE rgbGreen ; 38 | 38: UBYTE rgbRed ; 39 | 39: UBYTE rgbReserved ; 40 | 40: } RGBQUAD < read = ReadRGBQUAD > ; 41 | 41: 42 | 42: typedef struct { 43 | 43: UBYTE rgbBlue ; 44 | 44: UBYTE rgbGreen ; 45 | 45: UBYTE rgbRed ; 46 | 46: } RGBTRIPLE < read = ReadRGBTRIPLE > ; 47 | 47: 48 | 48: 49 | 49: 50 | 50: 51 | 51: 52 | 52: string ReadRGBQUAD ( RGBQUAD & a ) 53 | 53: { 54 | 54: string s ; 55 | 55: SPrintf ( s , "#%02X%02X%02X%02X" , ( int ) a . rgbReserved , ( int ) a . rgbRed , ( int ) a . rgbGreen , ( int ) a . rgbBlue ) ; 56 | 56: return s ; 57 | 57: } 58 | 58: 59 | 59: string ReadRGBTRIPLE ( RGBTRIPLE & a ) 60 | 60: { 61 | 61: string s ; 62 | 62: SPrintf ( s , "#%02X%02X%02X" , ( int ) a . rgbRed , ( int ) a . rgbGreen , ( int ) a . rgbBlue ) ; 63 | 63: return s ; 64 | 64: } 65 | 65: 66 | 66: 67 | 67: 68 | 68: 69 | 69: LittleEndian ( ) ; 70 | 70: SetBackColor ( cLtGray ) ; 71 | 71: BITMAPFILEHEADER bmfh ; 72 | 72: BITMAPINFOHEADER bmih ; 73 | 73: 74 | 74: 75 | 75: if ( bmfh . bfType != "BM" ) 76 | 76: { 77 | 77: Warning ( "File is not a bitmap. Template stopped." ) ; 78 | 78: return - 1 ; 79 | 79: } 80 | 80: 81 | 81: 82 | 82: if ( ( bmih . biBitCount != 24 ) && ( bmih . biBitCount != 32 ) ) 83 | 83: { 84 | 84: SetBackColor ( cLtAqua ) ; 85 | 85: if ( bmih . biClrUsed > 0 ) 86 | 86: RGBQUAD aColors [ bmih . biClrUsed ] ; 87 | 87: else 88 | 88: RGBQUAD aColors [ 1 << bmih . biBitCount ] ; 89 | 89: } 90 | 90: 91 | 91: 92 | 92: SetBackColor ( cNone ) ; 93 | 93: if ( bmih . biCompression > 0 ) 94 | 94: { 95 | 95: 96 | 96: if ( bmih . biSizeImage > 0 ) 97 | 97: UBYTE rleData [ bmih . biSizeImage ] ; 98 | 98: else 99 | 99: UBYTE rleData [ bmfh . bfSize - FTell ( ) ] ; 100 | 100: } 101 | 101: else 102 | 102: { 103 | 103: 104 | 104: local int bytesPerLine = ( int ) Ceil ( bmih . biWidth * bmih . biBitCount / 8 . 0 ) ; 105 | 105: local int padding = 4 - ( bytesPerLine % 4 ) ; 106 | 106: if ( padding == 4 ) 107 | 107: padding = 0 ; 108 | 108: 109 | 109: 110 | 110: struct BITMAPLINE { 111 | 111: 112 | 112: 113 | 113: if ( bmih . biBitCount < 8 ) 114 | 114: UBYTE imageData [ bytesPerLine ] ; 115 | 115: else if ( bmih . biBitCount == 8 ) 116 | 116: UBYTE colorIndex [ bmih . biWidth ] ; 117 | 117: else if ( bmih . biBitCount == 24 ) 118 | 118: RGBTRIPLE colors [ bmih . biWidth ] ; 119 | 119: else if ( bmih . biBitCount == 32 ) 120 | 120: RGBQUAD colors [ bmih . biWidth ] ; 121 | 121: 122 | 122: 123 | 123: if ( padding != 0 ) 124 | 124: UBYTE padBytes [ padding ] ; 125 | 125: 126 | 126: } lines [ bmih . biHeight ] < optimize = true > ; 127 | 127: } tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/CABTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: 13 | 13: 14 | 14: 15 | 15: typedef struct { 16 | 16: 17 | 17: char signature [ 4 ] ; 18 | 18: uint reserved1 ; 19 | 19: uint cbCabinet ; 20 | 20: uint reserved2 ; 21 | 21: uint coffFiles ; 22 | 22: uint reserved3 ; 23 | 23: ubyte versionMinor ; 24 | 24: ubyte versionMajor ; 25 | 25: ushort cFolders ; 26 | 26: ushort cFiles ; 27 | 27: ushort flags ; 28 | 28: ushort setID ; 29 | 29: ushort iCabinet ; 30 | 30: 31 | 31: if ( flags & 4 ) { 32 | 32: 33 | 33: ushort cbCFHeader ; 34 | 34: ubyte cbCFFolder ; 35 | 35: ubyte cbCFData ; 36 | 36: 37 | 37: if ( cbCFHeader > 0 ) 38 | 38: char abReserve [ cbCFHeader ] ; 39 | 39: 40 | 40: } 41 | 41: if ( flags & 1 ) { 42 | 42: 43 | 43: char szCabinetPrev [ ] ; 44 | 44: char szDiskPrev [ ] ; 45 | 45: 46 | 46: } 47 | 47: if ( flags & 2 ) { 48 | 48: 49 | 49: char szCabinetNext [ ] ; 50 | 50: char szDiskNext [ ] ; 51 | 51: 52 | 52: } 53 | 53: 54 | 54: } CFHEADER ; 55 | 55: 56 | 56: LittleEndian ( ) ; 57 | 57: CFHEADER header ; 58 | 58: local uint counter = 0 ; 59 | 59: 60 | 60: typedef struct { 61 | 61: 62 | 62: uint coffCabStart ; 63 | 63: ushort cCFData ; 64 | 64: ushort typeCompress ; 65 | 65: 66 | 66: if ( exists ( header . cbCFFolder ) ) 67 | 67: char abReserve [ header . cbCFFolder ] ; 68 | 68: 69 | 69: } CFFOLDER ; 70 | 70: 71 | 71: typedef struct { 72 | 72: 73 | 73: uint cbFile ; 74 | 74: uint uoffFolderStart ; 75 | 75: ushort iFolder ; 76 | 76: DOSDATE date ; 77 | 77: DOSTIME time ; 78 | 78: ushort attribs ; 79 | 79: char szName [ ] ; 80 | 80: } CFFILE ; 81 | 81: 82 | 82: typedef struct { 83 | 83: 84 | 84: uint csum ; 85 | 85: ushort cbData ; 86 | 86: ushort cbUncomp ; 87 | 87: 88 | 88: if ( exists ( header . cbCFData ) ) 89 | 89: char abReserve [ header . cbCFData ] ; 90 | 90: 91 | 91: char ab [ cbData ] ; 92 | 92: } CFDATA ; 93 | 93: 94 | 94: while ( header . cFolders > counter ) { 95 | 95: 96 | 96: counter ++ ; 97 | 97: CFFOLDER folder ; 98 | 98: 99 | 99: } 100 | 100: 101 | 101: counter = 0 ; 102 | 102: 103 | 103: while ( header . cFiles > counter ) { 104 | 104: 105 | 105: counter ++ ; 106 | 106: CFFILE file ; 107 | 107: 108 | 108: } 109 | 109: 110 | 110: counter = 0 ; 111 | 111: 112 | 112: while ( folder . cCFData > counter ) { 113 | 113: 114 | 114: counter ++ ; 115 | 115: CFDATA data ; 116 | 116: 117 | 117: } tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/CDATemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: typedef struct 10 | 10: { 11 | 11: char szHeader [ 8 ] ; 12 | 12: char szFormat [ 8 ] ; 13 | 13: DWORD dwEOLn ; 14 | 14: } CDAFILEHEADER ; 15 | 15: 16 | 16: typedef struct 17 | 17: { 18 | 18: WORD wTrackFirst ; 19 | 19: WORD wTrackCount ; 20 | 20: DWORD dwVolumeSerialNumber ; 21 | 21: DWORD dwStartFrame ; 22 | 22: DWORD dwLengthFrame ; 23 | 23: DWORD dwStartMS ; 24 | 24: DWORD dwLengthMS ; 25 | 25: } CDAINFORMATION ; 26 | 26: 27 | 27: LittleEndian ( ) ; 28 | 28: CDAFILEHEADER Header ; 29 | 29: CDAINFORMATION Information ; 30 | 30: 31 | 31: 32 | 32: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/CLASSTemplate2.bt: -------------------------------------------------------------------------------- 1 | 1: BigEndian ( ) ; 2 | 2: 3 | 3: typedef struct { 4 | 4: enum < ubyte > { 5 | 5: CONSTANT_Class = 7 , 6 | 6: CONSTANT_Fieldref = 9 , 7 | 7: CONSTANT_Methodref = 10 , 8 | 8: CONSTANT_InterfaceMethodref = 11 , 9 | 9: CONSTANT_String = 8 , 10 | 10: CONSTANT_Integer = 3 , 11 | 11: CONSTANT_Float = 4 , 12 | 12: CONSTANT_Long = 5 , 13 | 13: CONSTANT_Double = 6 , 14 | 14: CONSTANT_NameAndType = 12 , 15 | 15: CONSTANT_Utf8 = 1 16 | 16: } tag ; 17 | 17: switch ( tag ) { 18 | 18: case 7 : 19 | 19: uint16 name_index ; 20 | 20: break ; 21 | 21: case 9 : 22 | 22: uint16 class_index ; 23 | 23: uint16 name_and_type_index ; 24 | 24: break ; 25 | 25: case 10 : 26 | 26: uint16 class_index ; 27 | 27: uint16 name_and_type_index ; 28 | 28: break ; 29 | 29: case 11 : 30 | 30: uint16 class_index ; 31 | 31: uint16 name_and_type_index ; 32 | 32: break ; 33 | 33: case 8 : 34 | 34: uint16 string_index ; 35 | 35: break ; 36 | 36: case 3 : 37 | 37: int32 int_value ; 38 | 38: break ; 39 | 39: case 4 : 40 | 40: float float_value ; 41 | 41: break ; 42 | 42: case 5 : 43 | 43: int64 long_value ; 44 | 44: break ; 45 | 45: case 6 : 46 | 46: double double_value ; 47 | 47: break ; 48 | 48: case 12 : 49 | 49: uint16 name_index ; 50 | 50: uint16 descriptor_index ; 51 | 51: break ; 52 | 52: case 1 : 53 | 53: uint16 length ; 54 | 54: char utf8_value [ length ] ; 55 | 55: break ; 56 | 56: } 57 | 57: } cp_info ; 58 | 58: 59 | 59: typedef struct { 60 | 60: uint16 attribute_name_index ; 61 | 61: uint32 attribute_length ; 62 | 62: char info [ attribute_length ] ; 63 | 63: } attribute_info ; 64 | 64: 65 | 65: typedef struct { 66 | 66: uint16 access_flags < format = binary > ; 67 | 67: uint16 name_index ; 68 | 68: uint16 descriptor_index ; 69 | 69: uint16 attributes_count ; 70 | 70: local int i_att2 = 0 ; 71 | 71: for ( i_att2 = 0 ; i_att2 < attributes_count ; i_att2 ++ ) { 72 | 72: attribute_info attributes ; 73 | 73: } ; 74 | 74: } field_info , method_info ; 75 | 75: 76 | 76: typedef struct { 77 | 77: uint32 magic < format = hex > ; 78 | 78: if ( magic != 0xCAFEBABE ) { 79 | 79: Warning ( "Invalid Class File." ) ; 80 | 80: return - 1 ; 81 | 81: } 82 | 82: uint16 minor_version ; 83 | 83: uint16 major_version ; 84 | 84: uint16 constant_pool_count ; 85 | 85: local int i_cp = 0 ; 86 | 86: for ( i_cp = 1 ; i_cp < constant_pool_count ; i_cp ++ ) { 87 | 87: cp_info constant_pool ; 88 | 88: if ( constant_pool . tag == 5 || constant_pool . tag == 6 ) { 89 | 89: i_cp ++ ; 90 | 90: } 91 | 91: } ; 92 | 92: uint16 access_flags < format = binary > ; 93 | 93: uint16 this_class ; 94 | 94: uint16 super_class ; 95 | 95: uint16 interfaces_count ; 96 | 96: local int i_if = 0 ; 97 | 97: for ( i_if = 0 ; i_if < interfaces_count ; i_if ++ ) { 98 | 98: uint16 interfaces ; 99 | 99: } ; 100 | 100: uint16 fields_count ; 101 | 101: local int i_fld = 0 ; 102 | 102: for ( i_fld = 0 ; i_fld < fields_count ; i_fld ++ ) { 103 | 103: field_info fields ; 104 | 104: } ; 105 | 105: uint16 methods_count ; 106 | 106: local int i_m = 0 ; 107 | 107: for ( i_m = 0 ; i_m < methods_count ; i_m ++ ) { 108 | 108: method_info methods ; 109 | 109: } ; 110 | 110: uint16 attributes_count ; 111 | 111: local int i_att = 0 ; 112 | 112: for ( i_att = 0 ; i_att < attributes_count ; i_att ++ ) { 113 | 113: attribute_info attributes ; 114 | 114: } ; 115 | 115: } class_file ; 116 | 116: 117 | 117: class_file file ; 118 | 118: 119 | 119: if ( ! FEof ( ) ) { 120 | 120: Warning ( "File is not properly ended." ) ; 121 | 121: } ; 122 | 122: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/DBFTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: string yearFrom1900 ( char yy ) 11 | 11: { 12 | 12: string s ; 13 | 13: SPrintf ( s , "%d" , 1900 + yy ) ; 14 | 14: return s ; 15 | 15: } 16 | 16: 17 | 17: struct DBF { 18 | 18: struct HEADER { 19 | 19: char version ; 20 | 20: struct DATE_OF_LAST_UPDATE { 21 | 21: char yy < read = yearFrom1900 , format = decimal > ; 22 | 22: char mm < format = decimal > ; 23 | 23: char dd < format = decimal > ; 24 | 24: } DateOfLastUpdate ; 25 | 25: int numberOfRecords ; 26 | 26: short lengthOfHeaderStructure ; 27 | 27: short lengthOfEachRecord ; 28 | 28: char reserved [ 2 ] ; 29 | 29: char incompleteTrasaction < format = decimal > ; 30 | 30: char encryptionFlag < format = decimal > ; 31 | 31: int freeRecordThread ; 32 | 32: int reserved1 [ 2 ] ; 33 | 33: char mdxFlag < format = decimal > ; 34 | 34: char languageDriver < format = decimal > ; 35 | 35: short reserved2 ; 36 | 36: } header ; 37 | 37: struct FIELD { 38 | 38: char fieldName [ 11 ] ; 39 | 39: char fieldType ; 40 | 40: int fieldDataAddress ; 41 | 41: char fieldLength < format = decimal > ; 42 | 42: char decimalCount < format = decimal > ; 43 | 43: short reserved ; 44 | 44: char workAreaId < format = decimal > ; 45 | 45: short reserved1 ; 46 | 46: char flags < format = hex > ; 47 | 47: char reserved2 [ 7 ] ; 48 | 48: char indexFieldFlag < format = decimal > ; 49 | 49: } field [ ( header . lengthOfHeaderStructure - 33 ) / sizeof ( struct FIELD ) ] ; 50 | 50: char Terminator < format = hex > ; 51 | 51: struct RECORD { 52 | 52: char deletedFlag ; 53 | 53: char fields [ header . lengthOfEachRecord - 1 ] ; 54 | 54: } record [ header . numberOfRecords ] < optimize = false > ; 55 | 55: } dbf < optimize = false > ; 56 | 56: 57 | 57: 58 | 58: 59 | 59: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/DMPTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: 13 | 13: 14 | 14: 15 | 15: 16 | 16: 17 | 17: typedef enum < uint32 > { 18 | 18: FULL = 1 , 19 | 19: KERNEL , 20 | 20: SMALL 21 | 21: } e_DumpType ; 22 | 22: 23 | 23: 24 | 24: typedef struct { 25 | 25: uint32 BasePage < format = hex > ; 26 | 26: uint32 PageCount < format = hex > ; 27 | 27: } _PHYSICAL_MEMORY_RUN32 ; 28 | 28: 29 | 29: 30 | 30: typedef struct { 31 | 31: uint32 NumberOfRuns ; 32 | 32: uint32 NumberOfPages < format = hex > ; 33 | 33: _PHYSICAL_MEMORY_RUN32 Run [ NumberOfRuns ] ; 34 | 34: } _PHYSICAL_MEMORY_DESCRIPTOR32 ; 35 | 35: 36 | 36: 37 | 37: typedef struct { 38 | 38: int32 ExceptionCode < format = hex > ; 39 | 39: uint32 ExceptionFlags ; 40 | 40: uint32 ExceptionRecord ; 41 | 41: uint32 ExceptionAddress < format = hex > ; 42 | 42: uint32 NumberParameters ; 43 | 43: uint32 ExceptionInformation [ 15 ] < format = hex > ; 44 | 44: } _EXCEPTION_RECORD32 ; 45 | 45: 46 | 46: 47 | 47: FSeek ( 0 ) ; 48 | 48: 49 | 49: char Signature [ 4 ] ; 50 | 50: char ValidDump [ 4 ] ; 51 | 51: uint32 MajorVersion ; 52 | 52: uint32 MinorVersion ; 53 | 53: uint32 DirectoryTableBase < format = hex > ; 54 | 54: uint32 PfnDataBase < format = hex > ; 55 | 55: uint32 PsLoadedModuleList < format = hex > ; 56 | 56: uint32 PsActiveProcessHead < format = hex > ; 57 | 57: uint32 MachineImageType < format = hex > ; 58 | 58: uint32 NumberProcessors ; 59 | 59: uint32 BugCheckCode < format = hex > ; 60 | 60: uint32 BugCheckParameter [ 4 ] < format = hex > ; 61 | 61: char VersionUser [ 32 ] ; 62 | 62: uchar PaeEnabled ; 63 | 63: uchar KdSecondaryVersion ; 64 | 64: uchar Spare3 [ 2 ] ; 65 | 65: uint32 KdDebuggerDataBlock < format = hex > ; 66 | 66: _PHYSICAL_MEMORY_DESCRIPTOR32 PhysicalMemoryBlock ; 67 | 67: FSeek ( 800 ) ; 68 | 68: uchar ContextRecord [ 1200 ] ; 69 | 69: _EXCEPTION_RECORD32 Exception ; 70 | 70: char Comment [ 128 ] ; 71 | 71: uchar _reserved0 [ 1768 ] ; 72 | 72: e_DumpType DumpType ; 73 | 73: uint32 MiniDumpFields ; 74 | 74: uint32 SecondaryDataState ; 75 | 75: uint32 ProductType ; 76 | 76: uint32 SuiteMask ; 77 | 77: uint32 WriterStatus ; 78 | 78: int64 RequiredDumpSpace ; 79 | 79: uchar _reserved2 [ 16 ] ; 80 | 80: FILETIME SystemUpTime ; 81 | 81: FILETIME SystemTime ; 82 | 82: uchar _reserved3 [ 56 ] ; 83 | 83: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/EOTTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: LittleEndian ( ) ; 12 | 12: 13 | 13: 14 | 14: typedef enum < DWORD > { TTEMBED_SUBSET = 0x1 , 15 | 15: TTEMBED_TTCOMPRESSED = 0x4 , 16 | 16: TTEMBED_FAILIFVARIATIONSIMULATED = 0x10 , 17 | 17: TTMBED_EMBEDEUDC = 0x20 , 18 | 18: TTEMBED_VALIDATIONTESTS = 0x40 , 19 | 19: TTEMBED_WEBOBJECT = 0x80 , 20 | 20: TTEMBED_XORENCRYPTDATA = 0x10000000 21 | 21: } TTEMBED ; 22 | 22: 23 | 23: typedef struct embedded_opentype_file { 24 | 24: unsigned long EOTSize ; 25 | 25: unsigned long FontDataSize ; 26 | 26: unsigned long Version ; 27 | 27: TTEMBED Flags ; 28 | 28: byte FontPANOSE [ 10 ] ; 29 | 29: byte Charset ; 30 | 30: byte Italic ; 31 | 31: unsigned long Weight ; 32 | 32: unsigned short fsType ; 33 | 33: unsigned short MagicNumber < bgcolor = cLtRed > ; 34 | 34: unsigned long UnicodeRange1 ; 35 | 35: unsigned long UnicodeRange2 ; 36 | 36: unsigned long UnicodeRange3 ; 37 | 37: unsigned long UnicodeRange4 ; 38 | 38: unsigned long CodePageRange1 ; 39 | 39: unsigned long CodePageRange2 ; 40 | 40: unsigned long CheckSumAdjustment ; 41 | 41: unsigned long Reserved1 ; 42 | 42: unsigned long Reserved2 ; 43 | 43: unsigned long Reserved3 ; 44 | 44: unsigned long Reserved4 ; 45 | 45: unsigned short Padding1 ; 46 | 46: unsigned short FamilyNameSize ; 47 | 47: byte FamilyName [ FamilyNameSize ] ; 48 | 48: 49 | 49: unsigned short Padding2 ; 50 | 50: unsigned short StyleNameSize ; 51 | 51: byte StyleName [ StyleNameSize ] ; 52 | 52: 53 | 53: unsigned short Padding3 ; 54 | 54: unsigned short VersionNameSize ; 55 | 55: byte VersionName [ VersionNameSize ] ; 56 | 56: 57 | 57: unsigned short Padding4 ; 58 | 58: unsigned short FullNameSize ; 59 | 59: byte FullName [ FullNameSize ] ; 60 | 60: 61 | 61: unsigned short Padding5 ; 62 | 62: unsigned short RootStringSize ; 63 | 63: byte RootString [ RootStringSize ] ; 64 | 64: unsigned long RootStringCheckSum ; 65 | 65: unsigned long EUDCCodePage ; 66 | 66: unsigned short Padding6 ; 67 | 67: unsigned short SignatureSize ; 68 | 68: byte Signature [ SignatureSize ] ; 69 | 69: unsigned long EUDCFlags ; 70 | 70: unsigned long EUDCFontSize ; 71 | 71: byte EUDCFontData [ EUDCFontSize ] ; 72 | 72: byte FontData [ FontDataSize ] < bgcolor = cLtAqua > ; 73 | 73: } ; 74 | 74: 75 | 75: LittleEndian ( ) ; 76 | 76: 77 | 77: FSeek ( 0 ) ; 78 | 78: embedded_opentype_file EOT ; tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/EVSBTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: 13 | 13: 14 | 14: 15 | 15: 16 | 16: 17 | 17: 18 | 18: 19 | 19: const int Frame_Count = 951 ; 20 | 20: 21 | 21: 22 | 22: 23 | 23: typedef struct SYNC_SEGMENT_EVEN 24 | 24: { 25 | 25: SetBackColor ( cRed ) ; 26 | 26: char Sync [ 4 ] ; 27 | 27: SetBackColor ( cPurple ) ; 28 | 28: char PN511 [ 511 ] ; 29 | 29: SetBackColor ( cLtBlue ) ; 30 | 30: char PN63_a [ 63 ] ; 31 | 31: SetBackColor ( cBlue ) ; 32 | 32: char PN63_b [ 63 ] ; 33 | 33: SetBackColor ( cLtBlue ) ; 34 | 34: char PN63_c [ 63 ] ; 35 | 35: SetBackColor ( cLtGreen ) ; 36 | 36: char VSB_Mode [ 24 ] ; 37 | 37: SetBackColor ( cAqua ) ; 38 | 38: char Kerdock [ 64 ] ; 39 | 39: SetBackColor ( cNone ) ; 40 | 40: char Reserved_a [ 28 ] ; 41 | 41: SetBackColor ( cSilver ) ; 42 | 42: char Reserved_b [ 12 ] ; 43 | 43: } Sync_Segment_Even ; 44 | 44: 45 | 45: typedef struct SYNC_SEGMENT_ODD 46 | 46: { 47 | 47: SetBackColor ( cLtRed ) ; 48 | 48: char Sync [ 4 ] ; 49 | 49: SetBackColor ( cPurple ) ; 50 | 50: char PN511 [ 511 ] ; 51 | 51: SetBackColor ( cLtBlue ) ; 52 | 52: char PN63_a [ 63 ] ; 53 | 53: SetBackColor ( cBlue ) ; 54 | 54: char PN63_b [ 63 ] ; 55 | 55: SetBackColor ( cLtBlue ) ; 56 | 56: char PN63_c [ 63 ] ; 57 | 57: SetBackColor ( cLtGreen ) ; 58 | 58: char VSB_Mode [ 24 ] ; 59 | 59: SetBackColor ( cAqua ) ; 60 | 60: char Kerdock [ 64 ] ; 61 | 61: SetBackColor ( cNone ) ; 62 | 62: char Reserved_a [ 28 ] ; 63 | 63: SetBackColor ( cSilver ) ; 64 | 64: char Reserved_b [ 12 ] ; 65 | 65: } Sync_Segment_Odd ; 66 | 66: 67 | 67: typedef struct DATA_SEGMENT_EVEN 68 | 68: { 69 | 69: SetBackColor ( cRed ) ; 70 | 70: char Data_Segment_Sync [ 4 ] ; 71 | 71: SetBackColor ( cNone ) ; 72 | 72: char Payload_Even [ 828 ] ; 73 | 73: } Data_Segment_Even ; 74 | 74: 75 | 75: typedef struct DATA_SEGMENT_ODD 76 | 76: { 77 | 77: SetBackColor ( cLtRed ) ; 78 | 78: char Data_Segment_Sync [ 4 ] ; 79 | 79: SetBackColor ( cNone ) ; 80 | 80: char Payload_Odd [ 828 ] ; 81 | 81: } Data_Segment_Odd ; 82 | 82: 83 | 83: typedef struct FIELD_EVEN 84 | 84: { 85 | 85: Sync_Segment_Even Sync_Seg_Even [ 1 ] ; 86 | 86: Data_Segment_Even Data_Seg_Even [ 312 ] ; 87 | 87: } Field_Even ; 88 | 88: 89 | 89: typedef struct FIELD_ODD 90 | 90: { 91 | 91: Sync_Segment_Odd Sync_Seg_Odd [ 1 ] ; 92 | 92: Data_Segment_Odd Data_Seg_Odd [ 312 ] ; 93 | 93: } Field_Odd ; 94 | 94: 95 | 95: typedef struct FRAME 96 | 96: { 97 | 97: Field_Even F_Even ; 98 | 98: Field_Odd F_Odd ; 99 | 99: } Frame ; 100 | 100: 101 | 101: struct FILE 102 | 102: { 103 | 103: Frame Frames [ Frame_Count ] ; 104 | 104: } File ; tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/FAT16Template.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: 13 | 13: 14 | 14: 15 | 15: typedef struct _CHS 16 | 16: { 17 | 17: BYTE Head ; 18 | 18: BYTE Sector ; 19 | 19: BYTE Cylinder ; 20 | 20: } CHS ; 21 | 21: 22 | 22: typedef union _CHSAddr 23 | 23: { 24 | 24: CHS chs ; 25 | 25: BYTE Address [ 3 ] ; 26 | 26: } CHSAddr ; 27 | 27: 28 | 28: typedef struct _Partion_Table_Entry { 29 | 29: BYTE Status ; 30 | 30: CHSAddr StartCHSAddress ; 31 | 31: BYTE PartitionType ; 32 | 32: CHSAddr EndCHSAddress ; 33 | 33: DWORD FirstLBA ; 34 | 34: DWORD TotalSectors ; 35 | 35: } Partion_Table_Entry ; 36 | 36: 37 | 37: typedef struct { 38 | 38: BYTE Code [ 446 ] ; 39 | 39: Partion_Table_Entry ptable [ 4 ] ; 40 | 40: WORD Signature55AA < format = hex > ; 41 | 41: if ( Signature55AA != 0xAA55 ) 42 | 42: { 43 | 43: Warning ( "Invalid MBR" ) ; 44 | 44: return 1 ; 45 | 45: } 46 | 46: } MBR ; 47 | 47: 48 | 48: 49 | 49: 50 | 50: typedef struct _FAT16BootSector 51 | 51: { 52 | 52: BYTE JumpCode [ 3 ] ; 53 | 53: BYTE OEM_Name [ 8 ] ; 54 | 54: WORD BytesPerSector ; 55 | 55: BYTE SectorsPerCluster ; 56 | 56: WORD ReservedSectorCount ; 57 | 57: BYTE NumberOfFAT ; 58 | 58: WORD MAX_RootDirEntry ; 59 | 59: WORD TotalSectors ; 60 | 60: BYTE MediaDescriptor ; 61 | 61: WORD SectorsPerFAT ; 62 | 62: WORD SectorsPerTrack ; 63 | 63: WORD NumberOfHeads ; 64 | 64: DWORD HiddenSectorsBeforePartition ; 65 | 65: DWORD TotalSectors ; 66 | 66: BYTE PhysicalDriveNumber ; 67 | 67: BYTE Reserved ; 68 | 68: BYTE ExtendedBootSignature ; 69 | 69: BYTE SerialNumber [ 4 ] ; 70 | 70: BYTE VolumeLable [ 11 ] ; 71 | 71: BYTE FAT_Type [ 8 ] ; 72 | 72: BYTE BootCode [ 448 ] ; 73 | 73: WORD BootSectorSignature ; 74 | 74: } FAT16BootSector ; 75 | 75: 76 | 76: 77 | 77: 78 | 78: local unsigned int FATEntryCount = 0 ; 79 | 79: typedef struct _FAT16 80 | 80: { 81 | 81: WORD Table [ FATEntryCount ] ; 82 | 82: } FAT16 ; 83 | 83: 84 | 84: 85 | 85: 86 | 86: typedef struct _RootDirEntry 87 | 87: { 88 | 88: BYTE name [ 8 ] ; 89 | 89: BYTE extn [ 3 ] ; 90 | 90: BYTE attributes ; 91 | 91: BYTE reserved [ 10 ] ; 92 | 92: WORD time ; 93 | 93: WORD date ; 94 | 94: WORD firstDataBlock ; 95 | 95: DWORD size ; 96 | 96: } RootDirEntry ; 97 | 97: 98 | 98: LittleEndian ( ) ; 99 | 99: FSeek ( 0 ) ; 100 | 100: 101 | 101: 102 | 102: MBR MasterBootRecord ; 103 | 103: 104 | 104: 105 | 105: 106 | 106: local unsigned int partition_index = 0 ; 107 | 107: typedef struct _Fat16Partition 108 | 108: { 109 | 109: 110 | 110: local unsigned int startBYTE = ( MasterBootRecord . ptable [ partition_index ] . FirstLBA * 512 ) ; 111 | 111: FSeek ( startBYTE ) ; 112 | 112: FAT16BootSector BtSector ; 113 | 113: 114 | 114: 115 | 115: 116 | 116: 117 | 117: 118 | 118: FSkip ( ( BtSector . ReservedSectorCount - 1 ) * 512 ) ; 119 | 119: 120 | 120: local unsigned int FATsize = ( BtSector . SectorsPerFAT * 512 ) / 2 ; 121 | 121: local unsigned int FATcnt = 0 ; 122 | 122: for ( FATcnt = 0 ; FATcnt < BtSector . NumberOfFAT ; ++ FATcnt ) 123 | 123: { 124 | 124: FATEntryCount = FATsize ; 125 | 125: FAT16 FAT ; 126 | 126: } 127 | 127: 128 | 128: 129 | 129: 130 | 130: 131 | 131: RootDirEntry rootDir [ BtSector . MAX_RootDirEntry ] ; 132 | 132: 133 | 133: 134 | 134: } Fat16Partition ; 135 | 135: 136 | 136: 137 | 137: 138 | 138: typedef struct _Disk 139 | 139: { 140 | 140: 141 | 141: local int part ; 142 | 142: for ( part = 0 ; part < 4 ; ++ part ) 143 | 143: { 144 | 144: if ( MasterBootRecord . ptable [ part ] . FirstLBA ) 145 | 145: { 146 | 146: partition_index = part ; 147 | 147: Fat16Partition FAT16partition ; 148 | 148: } 149 | 149: } 150 | 150: } Disk ; 151 | 151: 152 | 152: Disk dsk ; 153 | 153: 154 | 154: 155 | 155: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/FLVTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: 13 | 13: typedef struct { 14 | 14: CHAR signature [ 3 ] ; 15 | 15: UBYTE version ; 16 | 16: UBYTE dummy : 5 ; 17 | 17: UBYTE audio : 1 ; 18 | 18: UBYTE dummy2 : 1 ; 19 | 19: UBYTE video : 1 ; 20 | 20: DWORD dataoffset ; 21 | 21: DWORD zero ; 22 | 22: } HEADER ; 23 | 23: 24 | 24: local UINT taglen ; 25 | 25: 26 | 26: typedef struct { 27 | 27: UINT type : 8 ; 28 | 28: UINT datasize : 24 ; 29 | 29: UINT timestamp : 24 ; 30 | 30: UINT timestamphi : 8 ; 31 | 31: UINT streamid : 24 ; 32 | 32: taglen = datasize - 1 ; 33 | 33: Printf ( "tag length: %x\n" , taglen ) ; 34 | 34: if ( type == 8 ) 35 | 35: { 36 | 36: UINT fmt : 4 ; 37 | 37: UINT sr : 2 ; 38 | 38: UINT bits : 1 ; 39 | 39: UINT channels : 1 ; 40 | 40: if ( fmt == 10 ) 41 | 41: { 42 | 42: -- taglen ; 43 | 43: UBYTE frmtype ; 44 | 44: } 45 | 45: } 46 | 46: else if ( type == 9 ) 47 | 47: { 48 | 48: UINT frmtype : 4 ; 49 | 49: UINT codecid : 4 ; 50 | 50: if ( codecid == 7 ) 51 | 51: { 52 | 52: taglen -= 4 ; 53 | 53: UINT pkttype : 8 ; 54 | 54: UINT compotime : 24 ; 55 | 55: } 56 | 56: } 57 | 57: else if ( type == 18 ) 58 | 58: { 59 | 59: UINT fristbyte : 8 ; 60 | 60: } 61 | 61: UBYTE data [ taglen ] ; 62 | 62: UINT lastsize ; 63 | 63: 64 | 64: 65 | 65: 66 | 66: 67 | 67: } Tag ; 68 | 68: 69 | 69: BigEndian ( ) ; 70 | 70: SetBackColor ( cLtGray ) ; 71 | 71: HEADER hdr ; 72 | 72: 73 | 73: 74 | 74: if ( hdr . signature != "FLV" ) 75 | 75: { 76 | 76: Warning ( "File is not a FLV. Template stopped." ) ; 77 | 77: return - 1 ; 78 | 78: } 79 | 79: 80 | 80: if ( hdr . version != 1 ) 81 | 81: { 82 | 82: Warning ( "Unsupported FLV version. Template stopped." ) ; 83 | 83: return - 1 ; 84 | 84: } 85 | 85: 86 | 86: 87 | 87: SetBackColor ( cNone ) ; 88 | 88: 89 | 89: while ( ! FEof ( ) ) 90 | 90: { 91 | 91: Tag tag ; 92 | 92: } 93 | 93: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/GPTTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: typedef struct { 10 | 10: BYTE BootIndicator ; 11 | 11: BYTE StartHead ; 12 | 12: WORD StartSector : 6 ; 13 | 13: WORD StartCylinder : 10 ; 14 | 14: BYTE PartitionType ; 15 | 15: BYTE EndHead ; 16 | 16: WORD EndSector : 6 ; 17 | 17: WORD EndCylider : 10 ; 18 | 18: DWORD SectorsPrecedingPartion ; 19 | 19: DWORD SectorsInPartition ; 20 | 20: } MBRPARTITIONTABLE ; 21 | 21: 22 | 22: 23 | 23: typedef struct { 24 | 24: char SIGNATURE [ 8 ] ; 25 | 25: DWORD Revision ; 26 | 26: DWORD Headersize ; 27 | 27: DWORD CRC32OfHeader ; 28 | 28: DWORD Reserved ; 29 | 29: uint64 CurrentLBA ; 30 | 30: uint64 BackupLBA ; 31 | 31: uint64 FirstUsableLBA ; 32 | 32: uint64 LastUsableLBA ; 33 | 33: BYTE DiskGUID [ 16 ] ; 34 | 34: uint64 PartitionEntries ; 35 | 35: DWORD NumOfPartitions ; 36 | 36: DWORD SizeOfPartitionEntry ; 37 | 37: DWORD CRC32ofPartitionArray ; 38 | 38: BYTE reserved [ 420 ] ; 39 | 39: } GPT ; 40 | 40: 41 | 41: typedef struct { 42 | 42: BYTE PartitionTypeGUID [ 16 ] ; 43 | 43: BYTE PartitionGUID [ 16 ] ; 44 | 44: uint64 PartitionStartLBA ; 45 | 45: uint64 PartitionEndLBA ; 46 | 46: uint64 PartitionProperty ; 47 | 47: wchar_t PartitionName [ 36 ] ; 48 | 48: } GPTPAPTITIONTABLE < size = 128 > ; 49 | 49: 50 | 50: LittleEndian ( ) ; 51 | 51: struct { 52 | 52: BYTE bootcode [ 446 ] ; 53 | 53: MBRPARTITIONTABLE partitionTable [ 4 ] ; 54 | 54: WORD signature ; 55 | 55: } MBR < size = 512 > ; 56 | 56: 57 | 57: 58 | 58: 59 | 59: 60 | 60: if ( ( MBR . partitionTable [ 0 ] . PartitionType & 0xFF ) == 0xEE ) { 61 | 61: Printf ( "Protected MBR. GPT reserved" ) ; 62 | 62: GPT gptheader ; 63 | 63: GPTPAPTITIONTABLE table [ 128 ] ; 64 | 64: FSeek ( FileSize ( ) - sizeof ( GPT ) - sizeof ( GPTPAPTITIONTABLE ) * 128 ) ; 65 | 65: GPTPAPTITIONTABLE BackupTable [ 128 ] ; 66 | 66: FSeek ( FileSize ( ) - sizeof ( GPT ) ) ; 67 | 67: GPT Backupgptheader ; 68 | 68: } tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/GZipTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: 13 | 13: 14 | 14: 15 | 15: 16 | 16: 17 | 17: 18 | 18: 19 | 19: 20 | 20: 21 | 21: 22 | 22: 23 | 23: 24 | 24: 25 | 25: 26 | 26: 27 | 27: 28 | 28: 29 | 29: LittleEndian ( ) ; 30 | 30: 31 | 31: 32 | 32: typedef ubyte MAGIC [ 2 ] < read = MAGICRead , format = hex > ; 33 | 33: 34 | 34: string MAGICRead ( MAGIC magic ) { 35 | 35: string ret ; 36 | 36: string tmp ; 37 | 37: int i ; 38 | 38: 39 | 39: for ( i = 0 ; i < 2 ; i ++ ) { 40 | 40: SPrintf ( tmp , "%.2X" , magic [ i ] ) ; 41 | 41: ret += tmp ; 42 | 42: } 43 | 43: 44 | 44: return ret ; 45 | 45: } 46 | 46: 47 | 47: typedef enum < ubyte > { 48 | 48: 49 | 49: STORED = 0 , 50 | 50: COMPRESSED = 1 , 51 | 51: PACKED = 2 , 52 | 52: LZHED = 3 , 53 | 53: RESERVED_4 = 4 , 54 | 54: RESERVED_5 = 5 , 55 | 55: RESERVED_6 = 6 , 56 | 56: RESERVED_7 = 7 , 57 | 57: 58 | 58: DEFLATE = 8 59 | 59: } COMPRESSION ; 60 | 60: 61 | 61: 62 | 62: 63 | 63: typedef struct { 64 | 64: 65 | 65: byte FLAG_ASCII_TEXT : 1 ; 66 | 66: 67 | 67: 68 | 68: byte FLAG_CONTINUATION : 1 ; 69 | 69: 70 | 70: 71 | 71: byte FLAG_EXTRA : 1 ; 72 | 72: 73 | 73: 74 | 74: byte FLAG_NAME : 1 ; 75 | 75: 76 | 76: 77 | 77: byte FLAG_COMMENT : 1 ; 78 | 78: 79 | 79: 80 | 80: byte FLAG_ENCRYPTED : 1 ; 81 | 81: 82 | 82: 83 | 83: byte FLAG_RESERVED : 1 ; 84 | 84: byte FLAG_RESERVED : 1 ; 85 | 85: } FLAGS ; 86 | 86: 87 | 87: typedef enum < byte > { 88 | 88: FAT_FILESYSTEM = 0 , 89 | 89: AMIGA = 1 , 90 | 90: VMS = 2 , 91 | 91: UNIX = 3 , 92 | 92: VM_CMS = 4 , 93 | 93: ATARI_TOS = 5 , 94 | 94: HPFS_FILESYSTEM = 6 , 95 | 95: MACINTOSH = 7 , 96 | 96: Z_SYSTEM = 8 , 97 | 97: CPM = 9 , 98 | 98: TOPS_20 = 10 , 99 | 99: NTFS_FILESYSTEM = 11 , 100 | 100: QDOS = 12 , 101 | 101: ACORN_RISCOS = 13 , 102 | 102: UNKNOWN = 255 103 | 103: } OS ; 104 | 104: 105 | 105: typedef struct { 106 | 106: MAGIC magic_bytes < format = hex , comment = "Magic bytes for the file" > ; 107 | 107: 108 | 108: 109 | 109: if ( magic_bytes [ 0 ] == 0x1F ) { 110 | 110: if ( magic_bytes [ 1 ] == 0x8B ) { 111 | 111: 112 | 112: Printf ( "Appears to be a valid GZIP compressed file, attempting to parse.\n" ) ; 113 | 113: } else if ( magic_bytes [ 1 ] == 0x1E ) { 114 | 114: 115 | 115: Printf ( "Appears to be a generic compressed file, attempting to parse - don't expect much though.\n" ) ; 116 | 116: } else if ( magic_bytes [ 1 ] == 0x9E ) { 117 | 117: 118 | 118: Printf ( "Appears to be an old GZip compressed file, attempting to parse - don't expect much though.\n" ) ; 119 | 119: } else if ( magic_bytes [ 1 ] == 0xA0 ) { 120 | 120: 121 | 121: Printf ( "Appears to be a LZH compressed file, attempting to parse - don't expect much though.\n" ) ; 122 | 122: } 123 | 123: } else if ( magic_bytes [ 0 ] == 0x50 && magic_bytes [ 1 ] == 0x4B ) { 124 | 124: Warning ( "Appears to be a possible ZIP file - unable to parse with this template!" ) ; 125 | 125: Exit ( - 1 ) ; 126 | 126: } else { 127 | 127: Warning ( "Does not appear to be a GZip file!" ) ; 128 | 128: Exit ( - 1 ) ; 129 | 129: } 130 | 130: 131 | 131: COMPRESSION compression_method < comment = "Compression method used by engine" > ; 132 | 132: FLAGS flags < comment = "Optional flags for compressed section" > ; 133 | 133: 134 | 134: 135 | 135: uint modification_time < comment = "Unix timestamp of the file modification time" > ; 136 | 136: 137 | 137: 138 | 138: ubyte extra_flags < comment = "Extra flags, dependant on compression method" > ; 139 | 139: 140 | 140: 141 | 141: OS operating_system < comment = "Operating system compression took place on" > ; 142 | 142: 143 | 143: 144 | 144: if ( flags . FLAG_CONTINUATION == 1 ) { 145 | 145: ushort part < comment = "Part number of the continuation" > ; 146 | 146: } 147 | 147: 148 | 148: 149 | 149: if ( flags . FLAG_EXTRA == 1 ) { 150 | 150: ushort extra_length < comment = "Length of extra field" > ; 151 | 151: byte extra_bytes [ extra_length ] < comment = "Data for extra field" > ; 152 | 152: } 153 | 153: 154 | 154: if ( flags . FLAG_NAME == 1 ) { 155 | 155: string original_file_name < comment = "Original file name" > ; 156 | 156: } 157 | 157: 158 | 158: if ( flags . FLAG_COMMENT == 1 ) { 159 | 159: string file_comment < comment = "File comment" > ; 160 | 160: } 161 | 161: 162 | 162: 163 | 163: 164 | 164: 165 | 165: 166 | 166: 167 | 167: if ( flags . FLAG_ENCRYPTED == 1 ) { 168 | 168: 169 | 169: } 170 | 170: } gzip_header ; 171 | 171: 172 | 172: 173 | 173: struct { 174 | 174: 175 | 175: gzip_header header < comment = "GZip header information" > ; 176 | 176: 177 | 177: 178 | 178: 179 | 179: byte compressed [ FileSize ( ) - FTell ( ) - 8 ] < comment = "compressed data section" > ; 180 | 180: 181 | 181: uint CRC32 < format = hex , comment = "CRC of the data section" > ; 182 | 182: 183 | 183: 184 | 184: uint uncompressed_sized < comment = "Size of the uncompressed input" > ; 185 | 185: } gzip_file ; tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/GocleverTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: 13 | 13: 14 | 14: 15 | 15: 16 | 16: local uint number_of_records ; 17 | 17: local int i ; 18 | 18: local string s ; 19 | 19: 20 | 20: number_of_records = FileSize ( ) / 48 ; 21 | 21: struct gps 22 | 22: { 23 | 23: double longitude ; 24 | 24: double latitude ; 25 | 25: time_t date ; 26 | 26: int direction ; 27 | 27: int speed ; 28 | 28: uchar unknown_data [ 12 ] ; 29 | 29: int geoid ; 30 | 30: int altitude ; 31 | 31: } goclever [ number_of_records ] ; 32 | 32: OutputPaneClear ( ) ; 33 | 33: 34 | 34: Printf ( "GOCLEVER Navigation log: %s \n\n" , GetFileName ( ) ) ; 35 | 35: Printf ( " Date\t\tLongitude Latitude Geoid Altitude Direction Speed\n" ) ; 36 | 36: Printf ( "mm/dd/yyyy hh:mm:ss\n" ) ; 37 | 37: for ( i = 0 ; i < number_of_records ; i ++ ) 38 | 38: { 39 | 39: s = TimeTToString ( goclever [ i ] . date ) ; 40 | 40: Printf ( "%s\t%Lf\t%Lf\t%d\t%d\t%d\t%d\n" , s , goclever [ i ] . longitude , goclever [ i ] . latitude , goclever [ i ] . geoid , goclever [ i ] . altitude , goclever [ i ] . direction , goclever [ i ] . speed ) ; 41 | 41: } ; 42 | 42: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/ICOTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: 13 | 13: 14 | 14: typedef struct 15 | 15: { 16 | 16: BYTE bWidth ; 17 | 17: BYTE bHeight ; 18 | 18: BYTE bColorCount ; 19 | 19: BYTE bReserved ; 20 | 20: WORD wPlanes ; 21 | 21: WORD wBitCount ; 22 | 22: DWORD dwBytesInRes ; 23 | 23: DWORD dwImageOffset ; 24 | 24: } ICONDIRENTRY < read = ReadIconDirEntry > ; 25 | 25: 26 | 26: typedef struct 27 | 27: { 28 | 28: WORD idReserved ; 29 | 29: WORD idType ; 30 | 30: WORD idCount ; 31 | 31: ICONDIRENTRY idEntries [ idCount ] ; 32 | 32: } ICONDIR ; 33 | 33: 34 | 34: typedef struct { 35 | 35: UBYTE rgbBlue ; 36 | 36: UBYTE rgbGreen ; 37 | 37: UBYTE rgbRed ; 38 | 38: UBYTE rgbReserved ; 39 | 39: } RGBQUAD < read = ReadRGBQUAD > ; 40 | 40: 41 | 41: typedef struct { 42 | 42: UBYTE rgbBlue ; 43 | 43: UBYTE rgbGreen ; 44 | 44: UBYTE rgbRed ; 45 | 45: } RGBTRIPLE < read = ReadRGBTRIPLE > ; 46 | 46: 47 | 47: typedef struct { 48 | 48: DWORD biSize ; 49 | 49: LONG biWidth ; 50 | 50: LONG biHeight ; 51 | 51: WORD biPlanes ; 52 | 52: WORD biBitCount ; 53 | 53: DWORD biCompression ; 54 | 54: DWORD biSizeImage ; 55 | 55: LONG biXPelsPerMeter ; 56 | 56: LONG biYPelsPerMeter ; 57 | 57: DWORD biClrUsed ; 58 | 58: DWORD biClrImportant ; 59 | 59: } BITMAPINFOHEADER ; 60 | 60: 61 | 61: typedef struct { 62 | 62: 63 | 63: if ( ( bmiHeader . biBitCount != 24 ) && ( bmiHeader . biBitCount != 32 ) ) 64 | 64: { 65 | 65: if ( bmiHeader . biClrUsed > 0 ) 66 | 66: RGBQUAD aColors [ bmiHeader . biClrUsed ] ; 67 | 67: else 68 | 68: RGBQUAD aColors [ 1 << bmiHeader . biBitCount ] ; 69 | 69: } 70 | 70: 71 | 71: 72 | 72: local int bytesPerLine = ( int ) Ceil ( bmiHeader . biWidth * bmiHeader . biBitCount / 8 . 0 ) ; 73 | 73: local int padding = 4 - ( bytesPerLine % 4 ) ; 74 | 74: if ( padding == 4 ) 75 | 75: padding = 0 ; 76 | 76: 77 | 77: 78 | 78: struct BITMAPLINE { 79 | 79: 80 | 80: 81 | 81: if ( bmiHeader . biBitCount < 8 ) 82 | 82: UBYTE imageData [ bytesPerLine ] ; 83 | 83: else if ( bmiHeader . biBitCount == 8 ) 84 | 84: UBYTE colorIndex [ bmiHeader . biWidth ] ; 85 | 85: else if ( bmiHeader . biBitCount == 24 ) 86 | 86: RGBTRIPLE colors [ bmiHeader . biWidth ] ; 87 | 87: else if ( bmiHeader . biBitCount == 32 ) 88 | 88: RGBQUAD colors [ bmiHeader . biWidth ] ; 89 | 89: 90 | 90: 91 | 91: if ( padding != 0 ) 92 | 92: UBYTE padBytes [ padding ] ; 93 | 93: 94 | 94: } lines [ bmiHeader . biHeight / 2 ] < optimize = false > ; 95 | 95: 96 | 96: 97 | 97: struct MASKLINE { 98 | 98: UBYTE line [ ( ( bmiHeader . biWidth + 31 ) / 32 ) * 4 ] < format = hex > ; 99 | 99: } mask [ bmiHeader . biHeight / 2 ] < optimize = false > ; 100 | 100: 101 | 101: } IMAGEDATA ; 102 | 102: 103 | 103: typedef struct { 104 | 104: SetBackColor ( cLtAqua ) ; 105 | 105: BITMAPINFOHEADER bmiHeader ; 106 | 106: SetBackColor ( cLtGray ) ; 107 | 107: IMAGEDATA data ; 108 | 108: } ICONIMAGE < read = ReadDIBHeader > ; 109 | 109: 110 | 110: 111 | 111: 112 | 112: 113 | 113: 114 | 114: string ReadIconDirEntry ( ICONDIRENTRY & dirEntry ) 115 | 115: { 116 | 116: string s ; 117 | 117: SPrintf ( s , "%dx%d %dbit %d colors" , dirEntry . bWidth , dirEntry . bHeight , dirEntry . wBitCount , dirEntry . bColorCount ) ; 118 | 118: return s ; 119 | 119: } 120 | 120: 121 | 121: string ReadDIBHeader ( ICONIMAGE & image ) 122 | 122: { 123 | 123: string s ; 124 | 124: SPrintf ( s , "%dx%d %dbit" , image . bmiHeader . biWidth , image . bmiHeader . biHeight , image . bmiHeader . biBitCount ) ; 125 | 125: return s ; 126 | 126: } 127 | 127: 128 | 128: string ReadRGBQUAD ( RGBQUAD & a ) 129 | 129: { 130 | 130: string s ; 131 | 131: SPrintf ( s , "#%02X%02X%02X%02X" , a . rgbReserved , a . rgbRed , a . rgbGreen , a . rgbBlue ) ; 132 | 132: return s ; 133 | 133: } 134 | 134: 135 | 135: string ReadRGBTRIPLE ( RGBTRIPLE & a ) 136 | 136: { 137 | 137: string s ; 138 | 138: SPrintf ( s , "#%02X%02X%02X" , a . rgbRed , a . rgbGreen , a . rgbBlue ) ; 139 | 139: return s ; 140 | 140: } 141 | 141: 142 | 142: 143 | 143: 144 | 144: 145 | 145: LittleEndian ( ) ; 146 | 146: 147 | 147: local short res = ReadShort ( FTell ( ) ) ; 148 | 148: local short type = ReadShort ( FTell ( ) + 2 ) ; 149 | 149: 150 | 150: 151 | 151: if ( res != 0 || type != 1 ) 152 | 152: { 153 | 153: Warning ( "File is not an Icon. Template stopped." ) ; 154 | 154: return - 1 ; 155 | 155: } 156 | 156: 157 | 157: SetBackColor ( cNone ) ; 158 | 158: ICONDIR icondir ; 159 | 159: ICONIMAGE images [ icondir . idCount ] < optimize = false > ; tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/InspectorWithMP4DateTime.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: 13 | 13: 14 | 14: 15 | 15: 16 | 16: 17 | 17: 18 | 18: RequiresVersion ( 4 . 0 ) ; 19 | 19: 20 | 20: 21 | 21: 22 | 22: 23 | 23: local int64 position ; 24 | 24: if ( GetSelSize ( ) > 0 ) 25 | 25: position = GetSelStart ( ) ; 26 | 26: else 27 | 27: position = GetCursorPos ( ) ; 28 | 28: 29 | 29: 30 | 30: int leap ( int year ) 31 | 31: { 32 | 32: return year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 ) ; 33 | 33: } 34 | 34: 35 | 35: int daysInYear ( int year ) { return 365 + leap ( year ) ; } 36 | 36: 37 | 37: 38 | 38: typedef uint MP4_Time < read = MP4_TimeRead , write = MP4_TimeWrite > ; 39 | 39: 40 | 40: string MP4_TimeRead ( MP4_Time secs ) 41 | 41: { 42 | 42: 43 | 43: 44 | 44: int days = secs / 86400 ; 45 | 45: secs = secs % 86400 ; 46 | 46: 47 | 47: int year = 1904 ; 48 | 48: int month = 1 ; 49 | 49: 50 | 50: int daysInMonth [ 13 ] = { - 1 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ; 51 | 51: int extraDay [ 13 ] = { - 1 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ; 52 | 52: 53 | 53: while ( days > daysInYear ( year ) ) 54 | 54: { 55 | 55: days -= daysInYear ( year ) ; 56 | 56: year ++ ; 57 | 57: } 58 | 58: 59 | 59: while ( days > daysInMonth [ month ] + leap ( year ) * extraDay [ month ] ) 60 | 60: { 61 | 61: days -= daysInMonth [ month ] + leap ( year ) * extraDay [ month ] ; 62 | 62: month ++ ; 63 | 63: } 64 | 64: 65 | 65: int day = ++ days ; 66 | 66: 67 | 67: int hours = secs / 3600 ; 68 | 68: secs = secs % 3600 ; 69 | 69: int mins = secs / 60 ; 70 | 70: secs = secs % 60 ; 71 | 71: 72 | 72: string s ; 73 | 73: SPrintf ( s , "%02d.%02d.%4d %02d:%02d:%02d" , day , month , year , hours , mins , secs ) ; 74 | 74: return s ; 75 | 75: } 76 | 76: 77 | 77: void MP4_TimeWrite ( MP4_Time & secs , string dateTime ) 78 | 78: { 79 | 79: int daysInMonth [ 13 ] = { - 1 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ; 80 | 80: int extraDay [ 13 ] = { - 1 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ; 81 | 81: 82 | 82: int day , month , year , hour , min , sec ; 83 | 83: SScanf ( dateTime , "%d.%d.%d %d:%d:%d" , day , month , year , hour , min , sec ) ; 84 | 84: 85 | 85: int days = day - 1 ; 86 | 86: int months , hours , mins , y , m ; 87 | 87: 88 | 88: for ( y = 1904 ; y < year ; ++ y ) 89 | 89: days += daysInYear ( y ) ; 90 | 90: 91 | 91: for ( m = 1 ; m < month ; ++ m ) 92 | 92: days += daysInMonth [ m ] + leap ( year ) * extraDay [ m ] ; 93 | 93: 94 | 94: secs = days * 86400 + hour * 3600 + min * 60 + sec ; 95 | 95: } 96 | 96: 97 | 97: 98 | 98: FSeek ( position ) ; MP4_Time _mp4t < name = "MP4 time" > ; 99 | 99: FSeek ( position ) ; byte _si8 < name = "Signed Byte" > ; 100 | 100: FSeek ( position ) ; ubyte _ui8 < name = "Unsigned Byte" > ; 101 | 101: FSeek ( position ) ; short _si16 < name = "Signed Short" > ; 102 | 102: FSeek ( position ) ; ushort _ui16 < name = "Unsigned Short" > ; 103 | 103: FSeek ( position ) ; int _si32 < name = "Signed Int" > ; 104 | 104: FSeek ( position ) ; uint _ui32 < name = "Unsigned Int" > ; 105 | 105: FSeek ( position ) ; int64 _si64 < name = "Signed Int64" > ; 106 | 106: FSeek ( position ) ; uint64 _ui64 < name = "Unsigned Int64" > ; 107 | 107: FSeek ( position ) ; float _f < name = "Float" > ; 108 | 108: FSeek ( position ) ; double _d < name = "Double" > ; 109 | 109: FSeek ( position ) ; hfloat _hf < name = "Half Float" > ; 110 | 110: FSeek ( position ) ; char _s [ ReadStringLength ( position , 256 ) ] < name = "String" > ; 111 | 111: FSeek ( position ) ; wchar_t _ws [ ReadWStringLength ( position , 256 ) ] < name = "Unicode" > ; 112 | 112: FSeek ( position ) ; DOSDATE _dd < name = "DOS Date" > ; 113 | 113: FSeek ( position ) ; DOSTIME _dt < name = "DOS Time" > ; 114 | 114: FSeek ( position ) ; FILETIME _ft < name = "FILETIME" > ; 115 | 115: FSeek ( position ) ; OLETIME _ot < name = "OLETIME" > ; 116 | 116: FSeek ( position ) ; time_t _tt < name = "time_t" > ; 117 | 117: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/Mifare1kTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: struct FILE { 9 | 9: struct Manufacturer_block { 10 | 10: char Card_UID [ 4 ] < fgcolor = cDkGreen > ; 11 | 11: char LRC [ 1 ] < fgcolor = cDkRed > ; 12 | 12: char Internal [ 11 ] < fgcolor = cWhite > ; 13 | 13: char Data [ 32 ] ; 14 | 14: char Key_A [ 6 ] < bgcolor = cDkGray , fgcolor = cLtRed > ; 15 | 15: char Access_Bits [ 3 ] < bgcolor = cDkGray , fgcolor = cWhite > ; 16 | 16: char GPB [ 1 ] < bgcolor = cDkGray , fgcolor = cLtBlue > ; 17 | 17: char Key_B [ 6 ] < bgcolor = cDkGray , fgcolor = cYellow > ; 18 | 18: } manufacturer_block ; 19 | 19: 20 | 20: struct Sec_4blk { 21 | 21: char Data [ 48 ] ; 22 | 22: char Key_A [ 6 ] < bgcolor = cDkGray , fgcolor = cLtRed > ; 23 | 23: char Access_Bits [ 3 ] < bgcolor = cDkGray , fgcolor = cWhite > ; 24 | 24: char GPB [ 1 ] < bgcolor = cDkGray , fgcolor = cLtBlue > ; 25 | 25: char Key_B [ 6 ] < bgcolor = cDkGray , fgcolor = cYellow > ; 26 | 26: } sec_4blk [ 15 ] ; 27 | 27: 28 | 28: } file < bgcolor = cSilver > ; tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/Mifare4kTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: struct FILE { 9 | 9: struct Manufacturer_block { 10 | 10: char Card_UID [ 4 ] < fgcolor = cDkGreen > ; 11 | 11: char LRC [ 1 ] < fgcolor = cDkRed > ; 12 | 12: char Internal [ 11 ] < fgcolor = cWhite > ; 13 | 13: char Data [ 32 ] ; 14 | 14: char Key_A [ 6 ] < bgcolor = cDkGray , fgcolor = cLtRed > ; 15 | 15: char Access_Bits [ 3 ] < bgcolor = cDkGray , fgcolor = cWhite > ; 16 | 16: char GPB [ 1 ] < bgcolor = cDkGray , fgcolor = cLtBlue > ; 17 | 17: char Key_B [ 6 ] < bgcolor = cDkGray , fgcolor = cYellow > ; 18 | 18: } manufacturer_block ; 19 | 19: 20 | 20: struct Sec_4blk { 21 | 21: char Data [ 48 ] ; 22 | 22: char Key_A [ 6 ] < bgcolor = cDkGray , fgcolor = cLtRed > ; 23 | 23: char Access_Bits [ 3 ] < bgcolor = cDkGray , fgcolor = cWhite > ; 24 | 24: char GPB [ 1 ] < bgcolor = cDkGray , fgcolor = cLtBlue > ; 25 | 25: char Key_B [ 6 ] < bgcolor = cDkGray , fgcolor = cYellow > ; 26 | 26: } sec_4blk [ 31 ] ; 27 | 27: 28 | 28: struct Sec_16blk { 29 | 29: char Data [ 240 ] ; 30 | 30: char Key_A [ 6 ] < bgcolor = cDkGray , fgcolor = cLtRed > ; 31 | 31: char Access_Bits [ 3 ] < bgcolor = cDkGray , fgcolor = cWhite > ; 32 | 32: char GPB [ 1 ] < bgcolor = cDkGray , fgcolor = cLtBlue > ; 33 | 33: char Key_B [ 6 ] < bgcolor = cDkGray , fgcolor = cYellow > ; 34 | 34: } sec_16blk [ 8 ] ; 35 | 35: 36 | 36: } file < bgcolor = cSilver > ; tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/NetflowVersion5.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: BigEndian ( ) ; 12 | 12: 13 | 13: struct FLOW { 14 | 14: struct HEADER { 15 | 15: ushort Version ; 16 | 16: ushort Count ; 17 | 17: uint SysUptime ; 18 | 18: uint EopochSeconds ; 19 | 19: uint NanoSeconds ; 20 | 20: uint FlowsSeen ; 21 | 21: byte EngineType ; 22 | 22: byte EngineID ; 23 | 23: char filler [ 2 ] ; 24 | 24: } header ; 25 | 25: 26 | 26: struct DATA { 27 | 27: char SourceIP [ 4 ] ; 28 | 28: char DestIP [ 4 ] ; 29 | 29: char NextHopIP [ 4 ] ; 30 | 30: ushort InSNMP ; 31 | 31: ushort OutSNMP ; 32 | 32: uint PacketCount ; 33 | 33: uint ByteCount ; 34 | 34: uint StartFlowTime ; 35 | 35: uint EndFlowTime ; 36 | 36: ushort SourcePort ; 37 | 37: ushort DestPort ; 38 | 38: char filler [ 1 ] ; 39 | 39: byte TCPFlags ; 40 | 40: byte Protocol ; 41 | 41: byte TypeOfService ; 42 | 42: ushort SourceSysID ; 43 | 43: ushort DestSysID ; 44 | 44: byte SourceMaskBitsCount ; 45 | 45: byte DestMaskBitsCount ; 46 | 46: char filler2 [ 2 ] ; 47 | 47: } data [ flow . header . Count ] ; 48 | 48: } flow ; tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/OGGTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: local uint MAXPAGES = 1000 ; 12 | 12: 13 | 13: typedef struct { 14 | 14: CHAR CapturePattern [ 4 ] ; 15 | 15: BYTE Version ; 16 | 16: BYTE HeaderType ; 17 | 17: QUAD GranulePosition ; 18 | 18: DWORD BitstreamSerial ; 19 | 19: DWORD PageSequenceNumber ; 20 | 20: DWORD Checksum ; 21 | 21: UBYTE PageSegments ; 22 | 22: 23 | 23: 24 | 24: UBYTE SegmentLen [ PageSegments ] ; 25 | 25: 26 | 26: 27 | 27: local uint i ; 28 | 28: for ( i = 0 ; i < PageSegments ; i ++ ) { 29 | 29: struct { 30 | 30: BYTE Data [ SegmentLen [ i ] ] < bgcolor = cLtGray > ; 31 | 31: } Segment ; 32 | 32: } 33 | 33: } PAGE ; 34 | 34: 35 | 35: 36 | 36: LittleEndian ( ) ; 37 | 37: 38 | 38: local uint currpage = 0 ; 39 | 39: while ( ! FEof ( ) ) 40 | 40: { 41 | 41: currpage ++ ; 42 | 42: if ( MAXPAGES < currpage ) 43 | 43: { 44 | 44: Printf ( "Max Pages of %d reached!\n" , maxpages ) ; 45 | 45: return 0 ; 46 | 46: } 47 | 47: 48 | 48: PAGE page < bgcolor = cLtBlue > ; 49 | 49: 50 | 50: 51 | 51: if ( page . CapturePattern != "OggS" ) 52 | 52: { 53 | 53: Warning ( "File is not a valid ogg file. Template stopped." ) ; 54 | 54: return - 1 ; 55 | 55: } 56 | 56: } 57 | 57: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/OscarItemTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: while ( ! FEof ( ) ) { 11 | 11: struct RECORD { 12 | 12: char type ; 13 | 13: if ( r . type == 'A' ) { 14 | 14: char unused < bgcolor = 0xFF0000 > ; 15 | 15: short empNum ; 16 | 16: int ssn ; 17 | 17: short checkNum ; 18 | 18: short tableNum ; 19 | 19: short calcGuestCt ; 20 | 20: short openTime ; 21 | 21: short flagDeleted ; 22 | 22: short unused2 ; 23 | 23: short pullBack ; 24 | 24: short itemCt ; 25 | 25: short guestCt ; 26 | 26: short takeoutTicket ; 27 | 27: int csiNumber ; 28 | 28: char junk [ 22 ] ; 29 | 29: } else { if ( r . type == 'B' ) { 30 | 30: char unused < bgcolor = 0xDDDD00 > ; 31 | 31: short empNum ; 32 | 32: int ssn ; 33 | 33: short itemNum ; 34 | 34: short deptCat ; 35 | 35: short priceGrp ; 36 | 36: int price ; 37 | 37: int tax1Amt ; 38 | 38: int tax2Amt ; 39 | 39: short quantity ; 40 | 40: short taxStatusAcct ; 41 | 41: short specUserId ; 42 | 42: int plu ; 43 | 43: int managerSsn ; 44 | 44: short orderTime ; 45 | 45: byte seatNum ; 46 | 46: byte priceCode ; 47 | 47: byte xxExpansion ; 48 | 48: byte itemType ; 49 | 49: int reductionCode ; 50 | 50: int postPrice ; 51 | 51: } else { if ( r . type == 'C' || r . type == 'D' ) { 52 | 52: char unused < bgcolor = 0xFF > ; 53 | 53: short empNum ; 54 | 54: int ssn ; 55 | 55: short itemNum ; 56 | 56: short deptCat ; 57 | 57: short priceGrp ; 58 | 58: int price ; 59 | 59: int tax1Amt ; 60 | 60: int tax2Amt ; 61 | 61: short quantity ; 62 | 62: short dupVoidCat ; 63 | 63: short managerNum ; 64 | 64: int plu ; 65 | 65: int managerSsn ; 66 | 66: short tranTime ; 67 | 67: byte seatNum ; 68 | 68: char unused2 [ 3 ] ; 69 | 69: short voidCatId ; 70 | 70: char junk [ 6 ] ; 71 | 71: } else { if ( r . type == 'E' ) { 72 | 72: char unused < bgcolor = 0xDDDD > ; 73 | 73: short empNum ; 74 | 74: int ssn ; 75 | 75: char unused2 [ 6 ] ; 76 | 76: int discAmt ; 77 | 77: int tax1Amt ; 78 | 78: int tax2Amt ; 79 | 79: short quantity ; 80 | 80: short altDiscCat ; 81 | 81: short managerNum ; 82 | 82: char unused3 [ 4 ] ; 83 | 83: int managerSsn ; 84 | 84: short discTime ; 85 | 85: byte seatNum ; 86 | 86: char unused4 [ 3 ] ; 87 | 87: short discCatId ; 88 | 88: char junk [ 6 ] ; 89 | 89: } else { if ( r . type == 'F' ) { 90 | 90: char unused < bgcolor = 0x551A8B > ; 91 | 91: short empNum ; 92 | 92: int ssn ; 93 | 93: short payCatId ; 94 | 94: int payAmt ; 95 | 95: int gratuity ; 96 | 96: int externalId ; 97 | 97: short status ; 98 | 98: int acctNum ; 99 | 99: int acctExHigh ; 100 | 100: int cashBack ; 101 | 101: char junk [ 18 ] ; 102 | 102: } else { if ( r . type == 'K' ) { 103 | 103: char unused < bgcolor = 0xFF00 > ; 104 | 104: short empNum ; 105 | 105: int ssn ; 106 | 106: int amount ; 107 | 107: short closedTime ; 108 | 108: short origClsTime ; 109 | 109: int unused2 ; 110 | 110: short dupEmpNum ; 111 | 111: int unused3 ; 112 | 112: short origCheckNum ; 113 | 113: char junk [ 26 ] ; 114 | 114: } else { 115 | 115: char junk [ 53 ] < bgcolor = 0xAAAAAA > ; 116 | 116: } } } } } } 117 | 117: } r ; 118 | 118: } 119 | 119: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/PALTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: 13 | 13: 14 | 14: 15 | 15: typedef struct 16 | 16: { 17 | 17: uchar red ; 18 | 18: uchar green ; 19 | 19: uchar blue ; 20 | 20: uchar alpha ; 21 | 21: } RGBQUAD < read = ReadRGBQUAD > ; 22 | 22: 23 | 23: 24 | 24: 25 | 25: string ReadRGBQUAD ( RGBQUAD & a ) 26 | 26: { 27 | 27: string s ; 28 | 28: SPrintf ( s , "#%02X%02X%02X%02X" , a . alpha , a . red , a . green , a . blue ) ; 29 | 29: return s ; 30 | 30: } 31 | 31: 32 | 32: 33 | 33: 34 | 34: 35 | 35: char file_signature [ 4 ] ; 36 | 36: int file_length ; 37 | 37: char tag_type [ 4 ] ; 38 | 38: 39 | 39: 40 | 40: char chunk_signature [ 4 ] ; 41 | 41: int chunk_size ; 42 | 42: ushort version < format = hex > ; 43 | 43: ushort num_colors ; 44 | 44: RGBQUAD colors [ num_colors ] ; 45 | 45: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/PCXTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: enum < ubyte > PCX_TYPE { 11 | 11: v25 = 0 , 12 | 12: v28Pal = 2 , 13 | 13: v28 = 3 , 14 | 14: v5Win = 4 , 15 | 15: v3up = 5 16 | 16: } ; 17 | 17: 18 | 18: struct PCX { 19 | 19: ubyte Manufacturer ; 20 | 20: PCX_TYPE version ; 21 | 21: ubyte encoding ; 22 | 22: ubyte BitsPerPixel ; 23 | 23: ushort Xmin ; 24 | 24: ushort Ymin ; 25 | 25: ushort Xmax ; 26 | 26: ushort Ymax ; 27 | 27: ushort HDpi ; 28 | 28: ushort VDpi ; 29 | 29: ubyte Colormap [ 48 ] ; 30 | 30: ubyte Reserved ; 31 | 31: ubyte NPlanes ; 32 | 32: ushort BytesPerLine ; 33 | 33: ushort PaletteInfo ; 34 | 34: ushort HscreenSize ; 35 | 35: ushort VscreenSize ; 36 | 36: ubyte Filler [ 54 ] ; 37 | 37: } ; 38 | 38: 39 | 39: PCX file ; 40 | 40: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/PNGTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: 13 | 13: 14 | 14: 15 | 15: 16 | 16: 17 | 17: 18 | 18: 19 | 19: 20 | 20: 21 | 21: 22 | 22: 23 | 23: 24 | 24: 25 | 25: 26 | 26: 27 | 27: BigEndian ( ) ; 28 | 28: 29 | 29: const uint64 PNGMAGIC = 0x89504E470D0A1A0A L ; 30 | 30: 31 | 31: 32 | 32: typedef union { 33 | 33: uint32 ctype < format = hex > ; 34 | 34: char cname [ 4 ] ; 35 | 35: } CTYPE < read = readCTYPE > ; 36 | 36: 37 | 37: string readCTYPE ( local CTYPE & t ) { 38 | 38: return t . cname ; 39 | 39: } 40 | 40: 41 | 41: 42 | 42: 43 | 43: 44 | 44: 45 | 45: typedef struct { 46 | 46: uint32 width ; 47 | 47: uint32 height ; 48 | 48: ubyte bits ; 49 | 49: ubyte color_type ; 50 | 50: ubyte compression ; 51 | 51: ubyte filter ; 52 | 52: ubyte interlace ; 53 | 53: } IHDR < read = readIHDR > ; 54 | 54: 55 | 55: string readIHDR ( local IHDR & ihdr ) { 56 | 56: local string s ; 57 | 57: SPrintf ( s , "%i x %i (x%i)" , ihdr . width , ihdr . height , ihdr . bits ) ; 58 | 58: return s ; 59 | 59: } 60 | 60: 61 | 61: 62 | 62: 63 | 63: typedef struct { 64 | 64: string label ; 65 | 65: char data [ length - Strlen ( label ) - 1 ] ; 66 | 66: } tEXt < read = readtEXt > ; 67 | 67: 68 | 68: string readtEXt ( local tEXt & text ) { 69 | 69: local string s ; 70 | 70: SPrintf ( s , "%s = %s" , text . label , text . data ) ; 71 | 71: return s ; 72 | 72: } 73 | 73: 74 | 74: 75 | 75: 76 | 76: local uint32 CHUNK_CNT = 0 ; 77 | 77: 78 | 78: 79 | 79: typedef struct { 80 | 80: uint32 length ; 81 | 81: local quad pos_start = FTell ( ) ; 82 | 82: CTYPE type ; 83 | 83: if ( type . cname == "IHDR" ) { 84 | 84: IHDR ihdr ; 85 | 85: } else if ( type . cname == "tEXt" ) { 86 | 86: tEXt text ; 87 | 87: } else { 88 | 88: ubyte data [ length ] ; 89 | 89: } 90 | 90: local quad data_size = FTell ( ) - pos_start ; 91 | 91: uint32 crc < format = hex > ; 92 | 92: local uint32 crc_calc = Checksum ( CHECKSUM_CRC32 , pos_start , data_size ) ; 93 | 93: if ( crc != crc_calc ) { 94 | 94: local string msg ; 95 | 95: SPrintf ( msg , "*WARNING CRC Mismatch @ chunk[%d] (%08x != %08x)\n" , CHUNK_CNT , crc , crc_calc ) ; 96 | 96: Warning ( msg ) ; 97 | 97: Printf ( msg ) ; 98 | 98: } 99 | 99: CHUNK_CNT ++ ; 100 | 100: } CHUNK < read = readCHUNK > ; 101 | 101: 102 | 102: 103 | 103: 104 | 104: 105 | 105: 106 | 106: 107 | 107: 108 | 108: 109 | 109: string readCHUNK ( local CHUNK & c ) { 110 | 110: local string s ; 111 | 111: s = readCTYPE ( c . type ) + " (" ; 112 | 112: s += ( c . type . cname [ 0 ] & 0x20 ) ? "Ancillary, " : "Critical, " ; 113 | 113: s += ( c . type . cname [ 1 ] & 0x20 ) ? "Private, " : "Public, " ; 114 | 114: s += ( c . type . cname [ 2 ] & 0x20 ) ? "ERROR_RESERVED, " : "" ; 115 | 115: s += ( c . type . cname [ 3 ] & 0x20 ) ? "Safe to Copy)" : "Unsafe to Copy)" ; 116 | 116: return s ; 117 | 117: } 118 | 118: 119 | 119: 120 | 120: 121 | 121: 122 | 122: 123 | 123: uint64 pngid < format = hex > ; 124 | 124: if ( pngid != PNGMAGIC ) { 125 | 125: Warning ( "Invalid PNG File: Bad Magic Number" ) ; 126 | 126: return - 1 ; 127 | 127: } 128 | 128: while ( ! FEof ( ) ) { 129 | 129: CHUNK chunk ; 130 | 130: } 131 | 131: if ( CHUNK_CNT > 1 ) { 132 | 132: if ( ( chunk [ 0 ] . type . cname != "IHDR" ) || ( chunk [ CHUNK_CNT - 1 ] . type . cname != "IEND" ) ) { 133 | 133: local string msg ; 134 | 134: SPrintf ( msg , "*WARNING: Chunk IHDR must be first and chunk IEND must be last!\n" ) ; 135 | 135: Warning ( msg ) ; 136 | 136: Printf ( msg ) ; 137 | 137: } 138 | 138: } 139 | 139: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/RDBTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: 13 | 13: 14 | 14: 15 | 15: typedef struct { 16 | 16: CHAR reserved [ 16 ] ; 17 | 17: DWORD fhFileTotalCount ; 18 | 18: INT64 fhFileNameOffBits < format = hex > ; 19 | 19: INT64 fhFileDataOffBits < format = hex > ; 20 | 20: } RDBFILEHEADER ; 21 | 21: 22 | 22: 23 | 23: typedef struct { 24 | 24: local INT fileNameLength = 0 ; 25 | 25: local USHORT value = 0 ; 26 | 26: do 27 | 27: { 28 | 28: value = ReadUShort ( FTell ( ) + fileNameLength ) ; 29 | 29: fileNameLength += sizeof ( value ) ; 30 | 30: } while ( value != 0x0 ) ; 31 | 31: 32 | 32: CHAR frCurFileName [ fileNameLength ] ; 33 | 33: INT64 frCurFileDataOffBits < format = hex > ; 34 | 34: INT64 frCurFileDataSize ; 35 | 35: } RDBFILERECORD < read = ReadRDBFILERECORD > ; 36 | 36: 37 | 37: string ReadRDBFILERECORD ( RDBFILERECORD & r ) 38 | 38: { 39 | 39: string s ; 40 | 40: SPrintf ( s , "%s" , r . frCurFileName ) ; 41 | 41: return s ; 42 | 42: } 43 | 43: 44 | 44: 45 | 45: 46 | 46: 47 | 47: LittleEndian ( ) ; 48 | 48: 49 | 49: RDBFILEHEADER rdbFileHeader ; 50 | 50: 51 | 51: FSeek ( rdbFileHeader . fhFileNameOffBits ) ; 52 | 52: 53 | 53: local int i ; 54 | 54: for ( i = 0 ; i < rdbFileHeader . fhFileTotalCount ; i ++ ) 55 | 55: RDBFILERECORD rdbFileRecord ; 56 | 56: 57 | 57: 58 | 58: 59 | 59: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/RIFFTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: typedef CHAR ID [ 4 ] ; 12 | 12: 13 | 13: local int cOverTheRainbowIndex = 0 ; 14 | 14: local int cOverTheRainbow [ 12 ] = { 15 | 15: 0xBFBFEF , 16 | 16: 0xBFCFEF , 17 | 17: 0xBFEFEF , 18 | 18: 0xBFEFCF , 19 | 19: 0xBFEFBF , 20 | 20: 0xCFEFBF , 21 | 21: 0xEFEFBF , 22 | 22: 0xEFCFBF , 23 | 23: 0xEFBFBF , 24 | 24: 0xEFBFCF , 25 | 25: 0xEFBFEF , 26 | 26: 0xCFBFEF 27 | 27: } ; 28 | 28: local int cGrayZone = 0xD9DADC ; 29 | 29: local int COLOR_LUT_LENGTH = sizeof ( cOverTheRainbow ) / sizeof ( cOverTheRainbow [ 0 ] ) ; 30 | 30: 31 | 31: 32 | 32: 33 | 33: 34 | 34: typedef struct { 35 | 35: ID chunkID ; 36 | 36: DWORD chunkSize ; 37 | 37: UCHAR data [ chunkSize ] ; 38 | 38: 39 | 39: 40 | 40: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) 41 | 41: UCHAR padding ; 42 | 42: } CHUNK < read = ReadCHUNK > ; 43 | 43: 44 | 44: string ReadCHUNK ( struct CHUNK & s ) 45 | 45: { 46 | 46: return s . chunkID ; 47 | 47: } 48 | 48: 49 | 49: 50 | 50: struct LISTCHUNK { 51 | 51: ID chunkID ; 52 | 52: DWORD chunkSize ; 53 | 53: local quad pos = FTell ( ) ; 54 | 54: ID chunkType ; 55 | 55: 56 | 56: 57 | 57: local char tag [ 5 ] ; 58 | 58: local DWORD size ; 59 | 59: while ( FTell ( ) - pos < chunkSize ) 60 | 60: { 61 | 61: 62 | 62: ReadBytes ( tag , FTell ( ) , 4 ) ; 63 | 63: tag [ 4 ] = 0 ; 64 | 64: 65 | 65: 66 | 66: size = ReadUInt ( FTell ( ) + 4 ) ; 67 | 67: if ( FTell ( ) - pos + size > chunkSize ) { 68 | 68: Printf ( "Chunk '%s' of size %d at position 0x%LX exceeds the parent chunk size boundary.\n" , tag , size , FTell ( ) ) ; 69 | 69: return - 1 ; 70 | 70: } 71 | 71: 72 | 72: 73 | 73: switch ( tag ) 74 | 74: { 75 | 75: case "LIST" : 76 | 76: SetBackColor ( cGrayZone ) ; 77 | 77: struct LISTCHUNK list ; 78 | 78: break ; 79 | 79: default : 80 | 80: SetBackColor ( cOverTheRainbow [ cOverTheRainbowIndex ] ) ; 81 | 81: cOverTheRainbowIndex = ( cOverTheRainbowIndex + 1 ) % COLOR_LUT_LENGTH ; 82 | 82: CHUNK subchunk ; 83 | 83: break ; 84 | 84: } 85 | 85: } 86 | 86: 87 | 87: 88 | 88: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) 89 | 89: UCHAR padding ; 90 | 90: } ; 91 | 91: 92 | 92: typedef struct 93 | 93: { 94 | 94: ID groupID ; 95 | 95: DWORD size ; 96 | 96: ID riffType ; 97 | 97: } RIFFHEADER ; 98 | 98: 99 | 99: 100 | 100: 101 | 101: 102 | 102: 103 | 103: 104 | 104: local quad riff_pos = FTell ( ) ; 105 | 105: LittleEndian ( ) ; 106 | 106: SetBackColor ( cGrayZone ) ; 107 | 107: RIFFHEADER header ; 108 | 108: 109 | 109: 110 | 110: if ( header . groupID != "RIFF" ) 111 | 111: { 112 | 112: Warning ( "File is not a valid RIFF file. Template stopped." ) ; 113 | 113: return - 1 ; 114 | 114: } 115 | 115: 116 | 116: 117 | 117: local char tag [ 5 ] ; 118 | 118: local DWORD size ; 119 | 119: while ( FTell ( ) + 8 <= FileSize ( ) && FTell ( ) - riff_pos != header . size + 8 ) 120 | 120: { 121 | 121: 122 | 122: ReadBytes ( tag , FTell ( ) , 4 ) ; 123 | 123: tag [ 4 ] = 0 ; 124 | 124: 125 | 125: 126 | 126: size = ReadUInt ( FTell ( ) + 4 ) ; 127 | 127: 128 | 128: 129 | 129: switch ( tag ) 130 | 130: { 131 | 131: case "LIST" : 132 | 132: SetBackColor ( cGrayZone ) ; 133 | 133: LISTCHUNK list ; 134 | 134: break ; 135 | 135: default : 136 | 136: SetBackColor ( cOverTheRainbow [ cOverTheRainbowIndex ] ) ; 137 | 137: cOverTheRainbowIndex = ( cOverTheRainbowIndex + 1 ) % COLOR_LUT_LENGTH ; 138 | 138: CHUNK chunk ; 139 | 139: break ; 140 | 140: } 141 | 141: } 142 | 142: 143 | 143: 144 | 144: local quad actual_size = FTell ( ) - riff_pos ; 145 | 145: if ( actual_size != 8 + header . size ) 146 | 146: { 147 | 147: Printf ( "RIFF file size mismatch (header value %Ld, actual size %Ld).\n" , header . size , actual_size - 8 ) ; 148 | 148: return - 1 ; 149 | 149: } 150 | 150: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/SHPTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: typedef struct point_s { double X ; double Y ; } POINT ; 10 | 10: 11 | 11: string GetByteSize ( int wordSize ) 12 | 12: { 13 | 13: string s ; 14 | 14: SPrintf ( s , "%d" , 2 * wordSize ) ; 15 | 15: return s ; 16 | 16: } 17 | 17: 18 | 18: struct ESRI_SHAPE { 19 | 19: SetBackColor ( cLtGreen ) ; 20 | 20: struct HEADER { 21 | 21: BigEndian ( ) ; 22 | 22: int fileCode ; 23 | 23: int unused [ 5 ] ; 24 | 24: int fileLength < read = GetByteSize > ; 25 | 25: LittleEndian ( ) ; 26 | 26: int version ; 27 | 27: enum ShapeEnum { 28 | 28: NullShape , 29 | 29: Point , 30 | 30: PolyLine = 3 , 31 | 31: Polygon = 5 , 32 | 32: MultiPoint = 5 , 33 | 33: PointZ = 11 , 34 | 34: PolyLineZ = 13 , 35 | 35: PolygonZ = 15 } shapeType ; 36 | 36: double Xmin ; 37 | 37: double Ymin ; 38 | 38: double Xmax ; 39 | 39: double Ymax ; 40 | 40: double Zmin ; 41 | 41: double Zmax ; 42 | 42: double Mmin ; 43 | 43: double Mmax ; 44 | 44: } header ; 45 | 45: SetBackColor ( cLtGray ) ; 46 | 46: struct RECORD { 47 | 47: BigEndian ( ) ; 48 | 48: int recordNumber ; 49 | 49: int contentLength < read = GetByteSize > ; 50 | 50: LittleEndian ( ) ; 51 | 51: enum ShapeTypeEnum { 52 | 52: NullShapeType , 53 | 53: PointType , 54 | 54: PolyLineType = 3 , 55 | 55: PolygonType = 5 , 56 | 56: MultiPointType = 8 , 57 | 57: PointZType = 11 , 58 | 58: PolyLineZType = 13 , 59 | 59: PolygonZType = 15 , 60 | 60: MultiPointZType = 18 , 61 | 61: PointMType = 21 , 62 | 62: PolyLineMType = 23 , 63 | 63: PolygonMType = 25 , 64 | 64: MultiPointMType = 28 , 65 | 65: MultiPatchType = 31 } shapeType ; 66 | 66: if ( shapeType == 1 ) 67 | 67: { 68 | 68: POINT location ; 69 | 69: } 70 | 70: else if ( shapeType == 3 ) 71 | 71: { 72 | 72: double box [ 4 ] ; 73 | 73: int numParts ; 74 | 74: int numPoints ; 75 | 75: int parts [ numParts ] ; 76 | 76: POINT points [ numPoints ] ; 77 | 77: } 78 | 78: else if ( shapeType == 5 ) 79 | 79: { 80 | 80: double box [ 4 ] ; 81 | 81: int numParts ; 82 | 82: int numPoints ; 83 | 83: int parts [ numParts ] ; 84 | 84: POINT points [ numPoints ] ; 85 | 85: } 86 | 86: } record [ 10000 ] < optimize = false > ; 87 | 87: } esri_shape ; tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/SHXTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: typedef struct point_s { double X ; double Y ; } POINT ; 10 | 10: 11 | 11: string GetByteSize ( int wordSize ) 12 | 12: { 13 | 13: string s ; 14 | 14: SPrintf ( s , "%d" , 2 * wordSize ) ; 15 | 15: return s ; 16 | 16: } 17 | 17: 18 | 18: struct ESRI_INDEX { 19 | 19: SetBackColor ( cLtGreen ) ; 20 | 20: struct HEADER { 21 | 21: BigEndian ( ) ; 22 | 22: int fileCode ; 23 | 23: int unused [ 5 ] ; 24 | 24: int fileLength < read = GetByteSize > ; 25 | 25: LittleEndian ( ) ; 26 | 26: int version ; 27 | 27: enum ShapeEnum { 28 | 28: NullShape , 29 | 29: Point , 30 | 30: PolyLine = 3 , 31 | 31: Polygon = 5 , 32 | 32: MultiPoint = 5 , 33 | 33: PointZ = 11 , 34 | 34: PolyLineZ = 13 , 35 | 35: PolygonZ = 15 } shapeType ; 36 | 36: double Xmin ; 37 | 37: double Ymin ; 38 | 38: double Xmax ; 39 | 39: double Ymax ; 40 | 40: double Zmin ; 41 | 41: double Zmax ; 42 | 42: double Mmin ; 43 | 43: double Mmax ; 44 | 44: } header ; 45 | 45: SetBackColor ( cLtGray ) ; 46 | 46: struct INDEX_RECORD { 47 | 47: BigEndian ( ) ; 48 | 48: int offset < read = GetByteSize > ; 49 | 49: int contentLength < read = GetByteSize > ; 50 | 50: } record [ ( FileSize ( ) - 100 ) / 8 ] ; 51 | 51: 52 | 52: } esri_index ; tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/SRecTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: typedef char RECORDTYPE [ 2 ] ; 10 | 10: typedef char COUNT [ 2 ] ; 11 | 11: typedef char ADDRESS16 [ 4 ] ; 12 | 12: typedef char ADDRESS24 [ 6 ] ; 13 | 13: typedef char ADDRESS32 [ 8 ] ; 14 | 14: typedef char CHECKSUM [ 2 ] ; 15 | 15: 16 | 16: local char hexval [ 10 ] ; 17 | 17: local uint addrwidth ; 18 | 18: local uint rec = 1 ; 19 | 19: 20 | 20: typedef struct 21 | 21: { 22 | 22: RECORDTYPE recordType ; 23 | 23: COUNT count ; 24 | 24: switch ( recordType ) 25 | 25: { 26 | 26: case "S0" : 27 | 27: case "S1" : 28 | 28: case "S5" : 29 | 29: case "S9" : 30 | 30: ADDRESS16 address16 ; 31 | 31: addrwidth = 4 ; 32 | 32: break ; 33 | 33: case "S2" : 34 | 34: case "S8" : 35 | 35: ADDRESS24 address24 ; 36 | 36: addrwidth = 6 ; 37 | 37: break ; 38 | 38: case "S3" : 39 | 39: case "S7" : 40 | 40: ADDRESS32 adress32 ; 41 | 41: addrwidth = 8 ; 42 | 42: break ; 43 | 43: 44 | 44: 45 | 45: default : 46 | 46: break ; 47 | 47: } 48 | 48: 49 | 49: local int i ; 50 | 50: local int intval = 0 ; 51 | 51: local uint pow = 0 ; 52 | 52: local uint hexlen = 2 ; 53 | 53: local uint digit = 0 ; 54 | 54: for ( i = 0 ; i < hexlen ; i ++ ) 55 | 55: { 56 | 56: digit = ( count [ i ] - '0' > 9 ) ? count [ i ] - '7' : count [ i ] - '0' ; 57 | 57: intval += ( ( uint32 ) digit * ( 1 << 4 * ( ( hexlen - 1 ) - i ) ) ) ; 58 | 58: } 59 | 59: local uint bytesPerLine = ( uint32 ) ( ( intval - 1 ) * 2 ) - addrwidth ; 60 | 60: if ( bytesPerLine != 0 ) 61 | 61: char data [ ( bytesPerLine ) ] ; 62 | 62: 63 | 63: char checksum [ 2 ] ; 64 | 64: char crlf [ 2 ] ; 65 | 65: } SREC ; 66 | 66: 67 | 67: while ( ! FEof ( ) ) 68 | 68: { 69 | 69: SREC srec ; 70 | 70: } tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/SSPTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: typedef BYTE IP_ADDRESS [ 4 ] < read = IP2Str > ; 13 | 13: typedef BYTE MAC_ADDRESS [ 6 ] < read = MAC2Str > ; 14 | 14: 15 | 15: string IP2Str ( IP_ADDRESS ip ) 16 | 16: { 17 | 17: string strReturn ; 18 | 18: 19 | 19: SPrintf ( strReturn , "IP: %02d.%02d.%02d.%02d" , ip [ 0 ] , ip [ 1 ] , ip [ 2 ] , ip [ 3 ] ) ; 20 | 20: return strReturn ; 21 | 21: } 22 | 22: 23 | 23: typedef struct { 24 | 24: char signature [ 8 ] ; 25 | 25: WORD numberOfBytesInHeader ; 26 | 26: IP_ADDRESS IP ; 27 | 27: 28 | 28: if ( ( Strcmp ( signature , "SMSNF200" ) != 0 ) || ( numberOfBytesInHeader != 4 ) ) 29 | 29: { 30 | 30: Warning ( "Not a valid SmartSniff Packet file" ) ; 31 | 31: return - 1 ; 32 | 32: } 33 | 33: } SSP_HEADER ; 34 | 34: 35 | 35: typedef struct { 36 | 36: WORD packetHeaderSize ; 37 | 37: if ( packetHeaderSize != 0x18 ) 38 | 38: { 39 | 39: Waring ( "Invalid packetHeaderSize" ) ; 40 | 40: return - 1 ; 41 | 41: } 42 | 42: DWORD numberOfReceivedBytes ; 43 | 43: FILETIME fileTime ; 44 | 44: MAC_ADDRESS sourceMAC ; 45 | 45: MAC_ADDRESS destMAC ; 46 | 46: BYTE packet [ numberOfReceivedBytes ] < fgcolor = cRed , bgcolor = cYellow > ; 47 | 47: } SSP_PACKET ; 48 | 48: 49 | 49: string MAC2Str ( MAC_ADDRESS mac ) 50 | 50: { 51 | 51: string strReturn ; 52 | 52: SPrintf ( strReturn , "%02X-%02X-%02X-%02X-%02X-%02X" , mac [ 0 ] , mac [ 1 ] , mac [ 2 ] , mac [ 3 ] , mac [ 4 ] , mac [ 5 ] ) ; 53 | 53: 54 | 54: return strReturn ; 55 | 55: } 56 | 56: 57 | 57: 58 | 58: LittleEndian ( ) ; 59 | 59: SSP_HEADER header ; 60 | 60: 61 | 61: while ( ! FEof ( ) ) 62 | 62: { 63 | 63: SSP_PACKET record ; 64 | 64: } 65 | 65: 66 | 66: return 1 ; 67 | 67: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/STLTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: typedef struct { 13 | 13: CHAR Caption [ 80 ] ; 14 | 14: DWORD trCount ; 15 | 15: } STLFILEHEADER < read = STLFILEHEADERRead > ; 16 | 16: 17 | 17: string STLFILEHEADERRead ( STLFILEHEADER & x ) 18 | 18: { 19 | 19: return x . Caption ; 20 | 20: } ; 21 | 21: 22 | 22: typedef struct { 23 | 23: FLOAT x ; 24 | 24: FLOAT y ; 25 | 25: FLOAT z ; 26 | 26: } tVector3f < read = tVector3fRead > ; 27 | 27: string tVector3fRead ( tVector3f & v ) { 28 | 28: string s ; 29 | 29: SPrintf ( s , "(%6.2f %6.2f %6.2f)" , v . x , v . y , v . z ) ; 30 | 30: return s ; 31 | 31: } ; 32 | 32: 33 | 33: typedef struct { 34 | 34: tVector3f Normal ; 35 | 35: tVector3f Point0 ; 36 | 36: tVector3f Point1 ; 37 | 37: tVector3f Point2 ; 38 | 38: WORD Flags < format = hex > ; 39 | 39: } STLTRIANGLE ; 40 | 40: 41 | 41: 42 | 42: 43 | 43: LittleEndian ( ) ; 44 | 44: SetBackColor ( cLtAqua ) ; 45 | 45: 46 | 46: local CHAR text_sign [ 5 ] ; 47 | 47: ReadBytes ( text_sign , FTell ( ) , 5 ) ; 48 | 48: if ( text_sign == "solid" ) 49 | 49: { 50 | 50: Warning ( "Is ASCII STL" ) ; 51 | 51: return ; 52 | 52: } 53 | 53: STLFILEHEADER stlh ; 54 | 54: SetBackColor ( cNone ) ; 55 | 55: local int64 n = ( FileSize ( ) - 84 ) / 50 ; 56 | 56: if ( stlh . trCount != n ) Warning ( "File corrupted: stlh.trCount must be equal %Ld" , n ) ; 57 | 57: STLTRIANGLE Data [ n ] ; 58 | 58: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/SinclairMicrodriveImage.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: struct { 13 | 13: ubyte HDFLAG [ 1 ] ; 14 | 14: 15 | 15: ubyte HDNUMB [ 1 ] ; 16 | 16: ubyte UNUSED [ 2 ] ; 17 | 17: ubyte HDNAME [ 10 ] ; 18 | 18: ubyte HDCHK [ 1 ] ; 19 | 19: 20 | 20: ubyte RECFLG [ 1 ] ; 21 | 21: 22 | 22: 23 | 23: 24 | 24: 25 | 25: ubyte RECNUM [ 1 ] ; 26 | 26: ubyte RECLEN [ 2 ] ; 27 | 27: ubyte RECNAM [ 10 ] ; 28 | 28: ubyte DESCHK [ 1 ] ; 29 | 29: ubyte CHDATA [ 512 ] ; 30 | 30: ubyte DCHK [ 1 ] ; 31 | 31: 32 | 32: } MicrodriveSector [ 254 ] ; 33 | 33: ubyte WriteProtectionFlag [ 1 ] ; 34 | 34: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/TGATemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: typedef struct { 13 | 13: WORD FirstIndexEntry ; 14 | 14: WORD ColorMapLength ; 15 | 15: UBYTE ColorMapEntrySize ; 16 | 16: } COLORMAPSPECIFICATION ; 17 | 17: 18 | 18: typedef struct { 19 | 19: WORD XOrigin ; 20 | 20: WORD YOrigin ; 21 | 21: WORD Width ; 22 | 22: WORD Height ; 23 | 23: UBYTE PixelDepth ; 24 | 24: UBYTE ImageDescriptor ; 25 | 25: } IMAGESPECIFICATION < read = ReadImageSpecification > ; 26 | 26: 27 | 27: typedef struct { 28 | 28: UBYTE IDLength ; 29 | 29: UBYTE ColorMapType ; 30 | 30: UBYTE ImageType ; 31 | 31: COLORMAPSPECIFICATION CMSpecification ; 32 | 32: IMAGESPECIFICATION ISpecification ; 33 | 33: } TGAFILEHEADER < read = ReadTGAHeader > ; 34 | 34: 35 | 35: typedef struct { 36 | 36: DWORD B : 5 ; 37 | 37: DWORD G : 5 ; 38 | 38: DWORD R : 5 ; 39 | 39: } RGB555 < read = ReadRGB555 > ; 40 | 40: 41 | 41: typedef struct { 42 | 42: DWORD B : 5 ; 43 | 43: DWORD G : 5 ; 44 | 44: DWORD R : 5 ; 45 | 45: DWORD X : 1 ; 46 | 46: } XRGB1555 < read = ReadXRGB1555 > ; 47 | 47: 48 | 48: typedef struct { 49 | 49: UBYTE B ; 50 | 50: UBYTE G ; 51 | 51: UBYTE R ; 52 | 52: } RGB888 < read = ReadRGB888 > ; 53 | 53: 54 | 54: typedef struct { 55 | 55: UBYTE B ; 56 | 56: UBYTE G ; 57 | 57: UBYTE R ; 58 | 58: UBYTE A ; 59 | 59: } ARGB8888 < read = ReadARGB8888 > ; 60 | 60: 61 | 61: string ReadTGAHeader ( TGAFILEHEADER & a ) 62 | 62: { 63 | 63: switch ( a . ImageType ) 64 | 64: { 65 | 65: case 0 : 66 | 66: return "No Image Data Included" ; 67 | 67: case 1 : 68 | 68: return "Uncompressed, Color-mapped Image" ; 69 | 69: case 2 : 70 | 70: return "Uncompressed, True-color Image" ; 71 | 71: case 3 : 72 | 72: return "Uncompressed, Black-and-white Image" ; 73 | 73: case 9 : 74 | 74: return "Run-length encoded, Color-mapped Image" ; 75 | 75: case 10 : 76 | 76: return "Run-length encoded, True-color Image" ; 77 | 77: case 11 : 78 | 78: return "Run-length encoded, Black-and-white Image" ; 79 | 79: } 80 | 80: } 81 | 81: string ReadImageSpecification ( IMAGESPECIFICATION & a ) 82 | 82: { 83 | 83: string s ; 84 | 84: SPrintf ( s , "Res: %dx%d^%d" , a . Width , a . Height , a . PixelDepth ) ; 85 | 85: return s ; 86 | 86: } 87 | 87: string ReadRGB555 ( RGB555 & a ) 88 | 88: { 89 | 89: string s ; 90 | 90: SPrintf ( s , "B=%03d G=%03d R=%03d" , a . B , a . G , a . R ) ; 91 | 91: return s ; 92 | 92: } 93 | 93: string ReadXRGB1555 ( XRGB1555 & a ) 94 | 94: { 95 | 95: string s ; 96 | 96: SPrintf ( s , "X=%1d B=%03d G=%03d R=%03d" , a . X , a . B , a . G , a . R ) ; 97 | 97: return s ; 98 | 98: } 99 | 99: 100 | 100: string ReadRGB888 ( RGB888 & a ) 101 | 101: { 102 | 102: string s ; 103 | 103: SPrintf ( s , "B=%03d G=%03d R=%03d" , a . B , a . G , a . R ) ; 104 | 104: return s ; 105 | 105: } 106 | 106: 107 | 107: string ReadARGB8888 ( ARGB8888 & a ) 108 | 108: { 109 | 109: string s ; 110 | 110: SPrintf ( s , "A=%03d B=%03d G=%03d R=%03d" , a . A , a . B , a . G , a . R ) ; 111 | 111: return s ; 112 | 112: } 113 | 113: 114 | 114: LittleEndian ( ) ; 115 | 115: SetBackColor ( cLtGray ) ; 116 | 116: 117 | 117: TGAFILEHEADER TGAfh ; 118 | 118: 119 | 119: 120 | 120: if ( TGAfh . IDLength != 0 ) 121 | 121: UBYTE ImageID [ TGAfh . IDLength ] ; 122 | 122: 123 | 123: SetBackColor ( cSilver ) ; 124 | 124: 125 | 125: if ( TGAfh . ColorMapType != 0 ) 126 | 126: switch ( TGAfh . CMSpecification . ColorMapEntrySize ) 127 | 127: { 128 | 128: case 15 : 129 | 129: RGB555 ColorMap [ TGAfh . CMSpecification . ColorMapLength ] ; 130 | 130: break ; 131 | 131: case 16 : 132 | 132: XRGB1555 ColorMap [ TGAfh . CMSpecification . ColorMapLength ] ; 133 | 133: break ; 134 | 134: case 24 : 135 | 135: RGB888 ColorMap [ TGAfh . CMSpecification . ColorMapLength ] ; 136 | 136: break ; 137 | 137: case 32 : 138 | 138: ARGB8888 ColorMap [ TGAfh . CMSpecification . ColorMapLength ] ; 139 | 139: break ; 140 | 140: } 141 | 141: SetBackColor ( cLtAqua ) ; 142 | 142: struct TGALine { 143 | 143: switch ( TGAfh . ISpecification . PixelDepth ) 144 | 144: { 145 | 145: case 8 : 146 | 146: UBYTE ColorIndex [ TGAfh . ISpecification . Height ] ; 147 | 147: break ; 148 | 148: case 16 : 149 | 149: XRGB1555 Pixel [ TGAfh . ISpecification . Height ] ; 150 | 150: break ; 151 | 151: case 24 : 152 | 152: RGB888 Pixel [ TGAfh . ISpecification . Height ] ; 153 | 153: break ; 154 | 154: case 32 : 155 | 155: ARGB8888 Pixel [ TGAfh . ISpecification . Height ] ; 156 | 156: break ; 157 | 157: } 158 | 158: } TGALines [ TGAfh . ISpecification . Width ] < optimize = true > ; 159 | 159: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/TOCTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: enum < WORD > type { In , Out , Junk , Trash , User , IMAP = 8 } ; 10 | 10: enum < WORD > class { user , system } ; 11 | 11: enum < WORD > stat { unread , read , replied , forwarded , redirected , rebuilt , sendable , queued , sent , unsent , timed , sending , recovered } ; 12 | 12: 13 | 13: typedef struct 14 | 14: { char EudoraVersion [ 8 ] ; 15 | 15: char MailboxName [ 32 ] ; 16 | 16: type MailboxType ; 17 | 17: short Unknown0 ; 18 | 18: class MailboxClass ; 19 | 19: struct 20 | 20: { short TopLeftX ; 21 | 21: short TopLeftY ; 22 | 22: short BottomRightX ; 23 | 23: short BottomRightY ; 24 | 24: } WindowPosition ; 25 | 25: 26 | 26: 27 | 27: 28 | 28: 29 | 29: 30 | 30: 31 | 31: 32 | 32: struct 33 | 33: { short StatusColumnWidth ; 34 | 34: short JunkScoreColumnWidth ; 35 | 35: short PriorityColumnWidth ; 36 | 36: short AttachmentColumnWidth ; 37 | 37: short LabelColumnWidth ; 38 | 38: short WhoColumnWidth ; 39 | 39: short DateColumnWidth ; 40 | 40: short SizeColumnWidth ; 41 | 41: } ColumnWidths ; 42 | 42: 43 | 43: 44 | 44: 45 | 45: 46 | 46: 47 | 47: 48 | 48: short Unknown1 ; 49 | 49: long HighestMsgSeqNumber ; 50 | 50: short Unknown2 [ 4 ] ; 51 | 51: short PreviewPaneDivider ; 52 | 52: short Unknown3 [ 5 ] ; 53 | 53: long NewMessageOffsetMBXfile ; 54 | 54: short Unknown4 ; 55 | 55: short MessagesInMailbox ; 56 | 56: } TOChdr ; 57 | 57: 58 | 58: typedef struct 59 | 59: { long OffsetMBXfile < format = hex > ; 60 | 60: long Length ; 61 | 61: time_t GMTtimestamp ; 62 | 62: stat Status ; 63 | 63: SetForeColor ( cGreen ) ; 64 | 64: ubyte Flags1 : 8 < format = binary > ; 65 | 65: 66 | 66: 67 | 67: 68 | 68: 69 | 69: 70 | 70: 71 | 71: 72 | 72: 73 | 73: ubyte Flags2 : 8 < format = binary > ; 74 | 74: 75 | 75: 76 | 76: 77 | 77: 78 | 78: 79 | 79: 80 | 80: 81 | 81: 82 | 82: SetForeColor ( cNone ) ; 83 | 83: short Priority ; 84 | 84: char LocalDateTime [ 32 ] ; 85 | 85: char Who [ 64 ] ; 86 | 86: char Subject [ 64 ] ; 87 | 87: struct 88 | 88: { short TopLeftX ; 89 | 89: short TopLeftY ; 90 | 90: short BottomRightX ; 91 | 91: short BottomRightY ; 92 | 92: } WindowPosition ; 93 | 93: 94 | 94: short Label ; 95 | 95: long OffsetLMOSfile < format = hex > ; 96 | 96: long MsgSeqNumber ; 97 | 97: SetForeColor ( cPurple ) ; 98 | 98: ubyte Flags3 : 8 < format = binary > ; 99 | 99: 100 | 100: 101 | 101: 102 | 102: 103 | 103: 104 | 104: 105 | 105: 106 | 106: 107 | 107: ubyte Flags4 : 8 < format = binary > ; 108 | 108: 109 | 109: 110 | 110: 111 | 111: 112 | 112: 113 | 113: 114 | 114: 115 | 115: 116 | 116: SetForeColor ( cNone ) ; 117 | 117: short Unknown [ 10 ] ; 118 | 118: } TOCmsg ; 119 | 119: 120 | 120: 121 | 121: 122 | 122: LittleEndian ( ) ; 123 | 123: TOChdr hdr ; 124 | 124: while ( ! FEof ( ) ) 125 | 125: { TOCmsg msg ; 126 | 126: } 127 | 127: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/WinhexPosTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: 13 | 13: string Wh_WinhexID < comment = "file signature" > ; 14 | 14: uint32 Wh_Flags < comment = "currently - 0x00, 0X01 - Unicode" > ; 15 | 15: uint32 Wh_n_ch < comment = "number of chunks" > ; 16 | 16: struct chunk { 17 | 17: uint16 Chsize < comment = "chunk size" > ; 18 | 18: uint16 Chflags ; 19 | 19: uint64 Offset ; 20 | 20: uint64 Time ; 21 | 21: FILETIME date ; 22 | 22: uchar RGB [ 3 ] ; 23 | 23: uchar Padding ; 24 | 24: uint16 DescrLen ; 25 | 25: string Descr ; 26 | 26: if ( Chflags & 0x100 ) { 27 | 27: uint64 Relative_Offset ; 28 | 28: uint64 FileId ; 29 | 29: uint16 PathLen ; 30 | 30: string Path ; 31 | 31: } 32 | 32: 33 | 33: } wh_pos [ Wh_n_ch ] < optimize = false > ; 34 | 34: tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/ZIPTemplate.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: 10 | 10: 11 | 11: 12 | 12: 13 | 13: 14 | 14: 15 | 15: 16 | 16: 17 | 17: 18 | 18: 19 | 19: 20 | 20: typedef enum < short > { 21 | 21: COMP_STORED = 0 , 22 | 22: COMP_SHRUNK = 1 , 23 | 23: COMP_REDUCED1 = 2 , 24 | 24: COMP_REDUCED2 = 3 , 25 | 25: COMP_REDUCED3 = 4 , 26 | 26: COMP_REDUCED4 = 5 , 27 | 27: COMP_IMPLODED = 6 , 28 | 28: COMP_TOKEN = 7 , 29 | 29: COMP_DEFLATE = 8 , 30 | 30: COMP_DEFLATE64 = 9 31 | 31: } COMPTYPE ; 32 | 32: 33 | 33: 34 | 34: typedef struct { 35 | 35: 36 | 36: char frSignature [ 4 ] ; 37 | 37: ushort frVersion ; 38 | 38: ushort frFlags ; 39 | 39: COMPTYPE frCompression ; 40 | 40: DOSTIME frFileTime ; 41 | 41: DOSDATE frFileDate ; 42 | 42: uint frCrc < format = hex > ; 43 | 43: uint frCompressedSize ; 44 | 44: uint frUncompressedSize ; 45 | 45: ushort frFileNameLength ; 46 | 46: ushort frExtraFieldLength ; 47 | 47: if ( frFileNameLength > 0 ) 48 | 48: char frFileName [ frFileNameLength ] ; 49 | 49: if ( frExtraFieldLength > 0 ) 50 | 50: uchar frExtraField [ frExtraFieldLength ] ; 51 | 51: 52 | 52: 53 | 53: SetBackColor ( cNone ) ; 54 | 54: if ( frCompressedSize > 0 ) 55 | 55: uchar frData [ frCompressedSize ] ; 56 | 56: 57 | 57: } ZIPFILERECORD < read = ReadZIPFILERECORD , write = WriteZIPFILERECORD > ; 58 | 58: 59 | 59: 60 | 60: typedef struct { 61 | 61: char deSignature [ 4 ] ; 62 | 62: ushort deVersionMadeBy ; 63 | 63: ushort deVersionToExtract ; 64 | 64: ushort deFlags ; 65 | 65: COMPTYPE deCompression ; 66 | 66: DOSTIME deFileTime ; 67 | 67: DOSDATE deFileDate ; 68 | 68: uint deCrc < format = hex > ; 69 | 69: uint deCompressedSize ; 70 | 70: uint deUncompressedSize ; 71 | 71: ushort deFileNameLength ; 72 | 72: ushort deExtraFieldLength ; 73 | 73: ushort deFileCommentLength ; 74 | 74: ushort deDiskNumberStart ; 75 | 75: ushort deInternalAttributes ; 76 | 76: uint deExternalAttributes ; 77 | 77: uint deHeaderOffset ; 78 | 78: if ( deFileNameLength > 0 ) 79 | 79: char deFileName [ deFileNameLength ] ; 80 | 80: if ( deExtraFieldLength > 0 ) 81 | 81: uchar deExtraField [ deExtraFieldLength ] ; 82 | 82: if ( deFileCommentLength > 0 ) 83 | 83: uchar deFileComment [ deFileCommentLength ] ; 84 | 84: } ZIPDIRENTRY < read = ReadZIPDIRENTRY > ; 85 | 85: 86 | 86: 87 | 87: typedef struct { 88 | 88: char dsSignature [ 4 ] ; 89 | 89: ushort dsDataLength ; 90 | 90: if ( dsDataLength > 0 ) 91 | 91: uchar dsData [ dsDataLength ] ; 92 | 92: } ZIPDIGITALSIG ; 93 | 93: 94 | 94: 95 | 95: typedef struct { 96 | 96: char ddSignature [ 4 ] ; 97 | 97: uint ddCRC < format = hex > ; 98 | 98: uint ddCompressedSize ; 99 | 99: uint ddUncompressedSize ; 100 | 100: } ZIPDATADESCR ; 101 | 101: 102 | 102: 103 | 103: typedef struct { 104 | 104: char elSignature [ 4 ] ; 105 | 105: ushort elDiskNumber ; 106 | 106: ushort elStartDiskNumber ; 107 | 107: ushort elEntriesOnDisk ; 108 | 108: ushort elEntriesInDirectory ; 109 | 109: uint elDirectorySize ; 110 | 110: uint elDirectoryOffset ; 111 | 111: ushort elCommentLength ; 112 | 112: if ( elCommentLength > 0 ) 113 | 113: char elComment [ elCommentLength ] ; 114 | 114: } ZIPENDLOCATOR ; 115 | 115: 116 | 116: 117 | 117: 118 | 118: 119 | 119: 120 | 120: 121 | 121: string ReadZIPFILERECORD ( ZIPFILERECORD & file ) 122 | 122: { 123 | 123: if ( exists ( file . frFileName ) ) 124 | 124: return file . frFileName ; 125 | 125: else 126 | 126: return "" ; 127 | 127: } 128 | 128: 129 | 129: string ReadZIPDIRENTRY ( ZIPDIRENTRY & entry ) 130 | 130: { 131 | 131: if ( exists ( entry . deFileName ) ) 132 | 132: return entry . deFileName ; 133 | 133: else 134 | 134: return "" ; 135 | 135: } 136 | 136: 137 | 137: 138 | 138: 139 | 139: 140 | 140: 141 | 141: void WriteZIPFILERECORD ( ZIPFILERECORD & file , string s ) 142 | 142: { 143 | 143: local int len = Strlen ( s ) ; 144 | 144: if ( exists ( file . frFileName ) ) 145 | 145: { 146 | 146: Strncpy ( file . frFileName , s , file . frFileNameLength ) ; 147 | 147: if ( len < file . frFileNameLength ) 148 | 148: file . frFileName [ len ] = 0 ; 149 | 149: } 150 | 150: } 151 | 151: 152 | 152: 153 | 153: 154 | 154: 155 | 155: local uint tag ; 156 | 156: LittleEndian ( ) ; 157 | 157: while ( ! FEof ( ) ) 158 | 158: { 159 | 159: 160 | 160: tag = ReadUInt ( FTell ( ) ) ; 161 | 161: 162 | 162: 163 | 163: 164 | 164: 165 | 165: 166 | 166: if ( tag == 0x4034B50 ) 167 | 167: { 168 | 168: SetBackColor ( cLtGray ) ; 169 | 169: ZIPFILERECORD record ; 170 | 170: } 171 | 171: else if ( tag == 0x8074B50 ) 172 | 172: { 173 | 173: SetBackColor ( cLtGreen ) ; 174 | 174: ZIPDATADESCR dataDescr ; 175 | 175: } 176 | 176: else if ( tag == 0x2014B50 ) 177 | 177: { 178 | 178: SetBackColor ( cLtPurple ) ; 179 | 179: ZIPDIRENTRY dirEntry ; 180 | 180: } 181 | 181: else if ( tag == 0x5054B50 ) 182 | 182: { 183 | 183: SetBackColor ( cLtBlue ) ; 184 | 184: ZIPDIGITALSIG digitalSig ; 185 | 185: } 186 | 186: else if ( tag == 0x6054B50 ) 187 | 187: { 188 | 188: SetBackColor ( cLtYellow ) ; 189 | 189: ZIPENDLOCATOR endLocator ; 190 | 190: } 191 | 191: else 192 | 192: { 193 | 193: Warning ( "Unknown ZIP tag encountered. Template stopped." ) ; 194 | 194: return - 1 ; 195 | 195: } 196 | 196: } tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/comment.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: int x = 5 ; 3 | 3: 4 | 4: 5 | 5: 6 | 6: 7 | 7: 8 | 8: 9 | 9: int y = 4 ; tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/comment_error.bt: -------------------------------------------------------------------------------- 1 | 1: 2 | 2: 3 | 3: error(line 3, col 32, "unexpected end of file in block comment") -------------------------------------------------------------------------------- /btparser/tests/exp_lex/stringlit.bt: -------------------------------------------------------------------------------- 1 | 1: string test = "this is a test\nwith a \0zero terminat and \x1B" ; tok_eof -------------------------------------------------------------------------------- /btparser/tests/exp_lex/stringlit_error.bt: -------------------------------------------------------------------------------- 1 | 1: string test = error(line 1, col 30, "unexpected newline in string literal (1)") -------------------------------------------------------------------------------- /btparser/tests/exp_lex/test.bt: -------------------------------------------------------------------------------- 1 | 1: struct DBZ { 2 | 2: struct HEADER { 3 | 3: char magic [ 4 ] ; 4 | 4: unsigned int size ; 5 | 5: unsigned int dataStart ; 6 | 6: unsigned int numEntries ; 7 | 7: } header ; 8 | 8: char empty [ header . size - sizeof ( HEADER ) ] ; 9 | 9: unsigned int entryOffsets [ header . numEntries ] ; 10 | 10: } dbz ; tok_eof -------------------------------------------------------------------------------- /btparser/tests/simple.bt: -------------------------------------------------------------------------------- 1 | uint x; -------------------------------------------------------------------------------- /btparser/tests/stringlit.bt: -------------------------------------------------------------------------------- 1 | string test = "this is a test\nwith a \0zero terminat and \x1B"; -------------------------------------------------------------------------------- /btparser/tests/stringlit_error.bt: -------------------------------------------------------------------------------- 1 | string test = "this is a test 2 | -------------------------------------------------------------------------------- /btparser/tests/test.bt: -------------------------------------------------------------------------------- 1 | struct DBZ { 2 | struct HEADER { 3 | char magic[4]; 4 | unsigned int size; 5 | unsigned int dataStart; 6 | unsigned int numEntries; 7 | } header; 8 | char empty[header.size - sizeof(HEADER)]; 9 | unsigned int entryOffsets[header.numEntries]; 10 | } dbz; --------------------------------------------------------------------------------