diff --git a/cparser/tests/exp_lex/AVITemplate.bt b/cparser/tests/exp_lex/AVITemplate.bt new file mode 100644 index 0000000..4153111 --- /dev/null +++ b/cparser/tests/exp_lex/AVITemplate.bt @@ -0,0 +1,307 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: typedef struct +21: { +22: WORD wFormatTag ; +23: WORD nChannels ; +24: DWORD nSamplesPerSec ; +25: DWORD nAvgBytesPerSec ; +26: WORD nBlockAlign ; +27: WORD wBitsPerSample ; +28: WORD cbSize ; +29: } WAVEFORMATEX ; +30: +31: +32: typedef struct +33: { +34: DWORD dwMicroSecPerFrame ; +35: DWORD dwMaxBytesPerSec ; +36: DWORD dwReserved1 ; +37: DWORD dwFlags ; +38: DWORD dwTotalFrames ; +39: DWORD dwInitialFrames ; +40: DWORD dwStreams ; +41: DWORD dwSuggestedBufferSize ; +42: DWORD dwWidth ; +43: DWORD dwHeight ; +44: DWORD dwScale ; +45: DWORD dwRate ; +46: DWORD dwStart ; +47: DWORD dwLength ; +48: } MainAVIHeader ; +49: +50: typedef struct +51: { +52: uint32 biSize ; +53: uint32 biWidth ; +54: uint32 biHeight ; +55: uint16 biPlanes ; +56: uint16 biBitCount ; +57: uint32 biCompression ; +58: uint32 biSizeImage ; +59: uint32 biXPelsPerMeter ; +60: uint32 biYPelsPerMeter ; +61: uint32 biClrUsed ; +62: uint32 biClrImportant ; +63: } BITMAPINFOHEADER ; +64: +65: typedef struct +66: { +67: unsigned char rgbBlue ; +68: unsigned char rgbGreen ; +69: unsigned char rgbRed ; +70: unsigned char rgbReserved ; +71: } RGBQUAD ; +72: +73: typedef struct +74: { +75: BITMAPINFOHEADER bmiHeader ; +76: RGBQUAD bmiColors ; +77: } BITMAPINFO ; +78: +79: typedef struct +80: { +81: char id [ 4 ] ; +82: uint32 datalen ; +83: MainAVIHeader data ; +84: } avihHEADER ; +85: +86: +87: +88: typedef struct +89: { +90: char fccType [ 4 ] ; +91: char fccHandler [ 4 ] ; +92: DWORD dwFlags ; +93: DWORD dwReserved1 ; +94: DWORD dwInitialFrames ; +95: DWORD dwScale ; +96: DWORD dwRate ; +97: DWORD dwStart ; +98: DWORD dwLength ; +99: DWORD dwSuggestedBufferSize ; +100: DWORD dwQuality ; +101: DWORD dwSampleSize ; +102: DWORD xdwQuality ; +103: DWORD xdwSampleSize ; +104: } AVIStreamHeader ; +105: +106: typedef struct +107: { +108: char id [ 4 ] ; +109: uint32 datalen ; +110: AVIStreamHeader data ; +111: } strhHEADER ; +112: +113: +114: +115: typedef struct +116: { +117: char id [ 4 ] ; +118: uint32 datalen ; +119: if ( datalen % 2 ) +120: char data [ datalen + 1 ] ; +121: else +122: char data [ datalen ] ; +123: } strfHEADER ; +124: +125: +126: typedef struct +127: { +128: char id [ 4 ] ; +129: uint32 datalen ; +130: BITMAPINFOHEADER bmiHeader ; +131: local int sz = sizeof ( bmiHeader ) ; +132: if ( datalen == ( sizeof ( BITMAPINFOHEADER ) + sizeof ( RGBQUAD ) ) ) +133: { +134: RGBQUAD bmiColors ; +135: sz += sizeof ( RGBQUAD ) ; +136: } +137: Printf ( "left: %d\n" , sz ) ; +138: char exData [ datalen - sz ] ; +139: } strfHEADER_BIH ; +140: +141: +142: +143: typedef struct +144: { +145: char id [ 4 ] ; +146: uint32 datalen ; +147: WAVEFORMATEX wave ; +148: char exData [ datalen - sizeof ( WAVEFORMATEX ) ] ; +149: } strfHEADER_WAVE ; +150: +151: +152: typedef struct +153: { +154: char id [ 4 ] ; +155: uint32 datalen ; +156: if ( datalen % 2 ) +157: char data [ datalen + 1 ] ; +158: else +159: char data [ datalen ] ; +160: } strnHEADER ; +161: +162: +163: typedef struct +164: { +165: char id [ 4 ] ; +166: uint32 datalen ; +167: if ( datalen % 2 ) +168: char data [ datalen + 1 ] ; +169: else +170: char data [ datalen ] ; +171: } genericblock ; +172: +173: +174: +175: typedef struct +176: { +177: char id [ 4 ] ; +178: uint32 datalen ; +179: char type [ 4 ] ; +180: +181: if ( ! Memcmp ( type , "hdrl" , 4 ) ) +182: { +183: avihHEADER avhi ; +184: } +185: else if ( ! Memcmp ( type , "strl" , 4 ) ) +186: { +187: strhHEADER strh ; +188: +189: +190: if ( Memcmp ( strh . data . fccType , "vids" , 4 ) == 0 ) +191: { +192: strfHEADER_BIH strf ; +193: } +194: else if ( Memcmp ( strh . data . fccType , "auds" , 4 ) == 0 ) +195: { +196: strfHEADER_WAVE strf ; +197: } +198: else +199: { +200: strfHEADER strf ; +201: } +202: strnHEADER strn ; +203: } +204: else if ( Memcmp ( type , "movi" , 4 ) == 0 ) +205: { +206: local int32 pointer = 0 ; +207: local int32 stop = datalen - 4 ; +208: +209: +210: +211: do +212: { +213: genericblock gb ; +214: pointer += sizeof ( gb ) ; +215: +216: } while ( pointer != stop ) ; +217: } +218: else +219: { +220: char data [ datalen - 4 ] ; +221: } +222: } LISTHEADER ; +223: +224: +225: +226: typedef struct +227: { +228: char id [ 4 ] ; +229: uint32 datalen ; +230: if ( datalen % 2 ) +231: char data [ datalen + 1 ] ; +232: else +233: char data [ datalen ] ; +234: } JUNKHEADER ; +235: +236: +237: +238: typedef struct +239: { +240: DWORD ckid ; +241: DWORD dwFlags ; +242: DWORD dwChunkOffset ; +243: DWORD dwChunkLength ; +244: } AVIINDEXENTRY ; +245: +246: const DWORD AVIINDEXENTRYLEN = 16 ; +247: +248: typedef struct +249: { +250: char id [ 4 ] ; +251: uint32 datalen ; +252: AVIINDEXENTRY data [ datalen / AVIINDEXENTRYLEN ] ; +253: } idx1HEADER ; +254: +255: +256: typedef struct xroot +257: { +258: char id [ 4 ] ; +259: if ( root . id [ 3 ] == 'X' ) +260: { +261: Printf ( "Motorola format\n" ) ; +262: BigEndian ( ) ; +263: } +264: else +265: { +266: Printf ( "Intel format\n" ) ; +267: LittleEndian ( ) ; +268: } +269: +270: uint32 datalen ; +271: char form [ 4 ] ; +272: +273: if ( Strcmp ( form , "AVI " ) ) +274: { +275: Warning ( "Not a valid AVI file" ) ; +276: return - 1 ; +277: } +278: } ROOT ; +279: +280: local char nheader [ 4 ] ; +281: +282: ROOT root ; +283: +284: while ( ! FEof ( ) ) +285: { +286: ReadBytes ( nheader , FTell ( ) , 4 ) ; +287: +288: if ( Memcmp ( nheader , "LIST" , 4 ) == 0 ) +289: { +290: LISTHEADER list ; +291: } +292: else if ( Memcmp ( nheader , "JUNK" , 4 ) == 0 ) +293: { +294: JUNKHEADER junk ; +295: } +296: else if ( Memcmp ( nheader , "idx1" , 4 ) == 0 ) +297: { +298: idx1HEADER idx1 ; +299: } +300: else +301: { +302: if ( ! FEof ( ) ) +303: Printf ( "unknown chunk: %c%c%c%c" , nheader [ 0 ] , nheader [ 1 ] , nheader [ 2 ] , nheader [ 3 ] ) ; +304: return - 1 ; +305: } +306: } +307: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/AndroidManifestTemplate.bt b/cparser/tests/exp_lex/AndroidManifestTemplate.bt new file mode 100644 index 0000000..2063932 --- /dev/null +++ b/cparser/tests/exp_lex/AndroidManifestTemplate.bt @@ -0,0 +1,189 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: typedef struct { +16: uint magicnumber ; +17: uint filesize ; +18: } HEADER ; +19: +20: +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: +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 ] < comment = "Relative to the 0x8+scStringPoolOffset" > ; +44: +45: if ( scStyleCount > 0 ) +46: uint scStyleOffset [ scStylePoolOffset ] ; +47: +48: +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: +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: +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: +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: +93: typedef struct { +94: uint acNamespaceUri ; +95: uint acName ; +96: uint acValueStr ; +97: uint acType < comment = "right shift 24bit" > ; +98: uint acData ; +99: } ATTRIBUTECHUNK ; +100: +101: +102: +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: +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: +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: +142: +143: local uint tag ; +144: +145: LittleEndian ( ) ; +146: HEADER header ; +147: +148: SetBackColor ( cLtGreen ) ; +149: STRINGCHUNK stringChunk ; +150: +151: FSeek ( 0x8 + stringChunk . scSize ) ; +152: +153: SetBackColor ( cLtBlue ) ; +154: RESOURCEIDCHUNK resourceChunk ; +155: FSeek ( resourceChunk . pos + resourceChunk . rcSize ) ; +156: +157: while ( ! FEof ( ) ) +158: { +159: +160: tag = ReadUInt ( FTell ( ) ) ; +161: +162: +163: if ( tag == 0x100100 ) +164: { +165: SetBackColor ( cLtPurple ) ; +166: SNCHUNK startNamespaceChunk ; +167: } +168: else if ( tag == 0x100101 ) +169: { +170: SetBackColor ( cLtPurple ) ; +171: ENCHUNK endNamespaceChunk ; +172: } +173: else if ( tag == 0x100102 ) +174: { +175: SetBackColor ( cLtGreen ) ; +176: STCHUNK startTagChunk ; +177: } +178: else if ( tag == 0x100103 ) +179: { +180: SetBackColor ( cLtGreen ) ; +181: ETCHUNK endTagChunk ; +182: } +183: else if ( tag == 0x100104 ) +184: { +185: SetBackColor ( cLtBlue ) ; +186: TEXTCHUNK TextChunk ; +187: } +188: } +189: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/BMPTemplate.bt b/cparser/tests/exp_lex/BMPTemplate.bt new file mode 100644 index 0000000..092f4b4 --- /dev/null +++ b/cparser/tests/exp_lex/BMPTemplate.bt @@ -0,0 +1,127 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: typedef struct { +14: CHAR bfType [ 2 ] ; +15: DWORD bfSize ; +16: WORD bfReserved1 ; +17: WORD bfReserved2 ; +18: DWORD bfOffBits ; +19: } BITMAPFILEHEADER ; +20: +21: typedef struct { +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 { +36: UBYTE rgbBlue ; +37: UBYTE rgbGreen ; +38: UBYTE rgbRed ; +39: UBYTE rgbReserved ; +40: } RGBQUAD < read = ReadRGBQUAD > ; +41: +42: typedef struct { +43: UBYTE rgbBlue ; +44: UBYTE rgbGreen ; +45: UBYTE rgbRed ; +46: } RGBTRIPLE < read = ReadRGBTRIPLE > ; +47: +48: +49: +50: +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: +69: LittleEndian ( ) ; +70: SetBackColor ( cLtGray ) ; +71: BITMAPFILEHEADER bmfh ; +72: BITMAPINFOHEADER bmih ; +73: +74: +75: if ( bmfh . bfType != "BM" ) +76: { +77: Warning ( "File is not a bitmap. Template stopped." ) ; +78: return - 1 ; +79: } +80: +81: +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: +92: SetBackColor ( cNone ) ; +93: if ( bmih . biCompression > 0 ) +94: { +95: +96: if ( bmih . biSizeImage > 0 ) +97: UBYTE rleData [ bmih . biSizeImage ] ; +98: else +99: UBYTE rleData [ bmfh . bfSize - FTell ( ) ] ; +100: } +101: else +102: { +103: +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: +110: struct BITMAPLINE { +111: +112: +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: +123: if ( padding != 0 ) +124: UBYTE padBytes [ padding ] ; +125: +126: } lines [ bmih . biHeight ] < optimize = true > ; +127: } tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/CABTemplate.bt b/cparser/tests/exp_lex/CABTemplate.bt new file mode 100644 index 0000000..2e6aa9d --- /dev/null +++ b/cparser/tests/exp_lex/CABTemplate.bt @@ -0,0 +1,117 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: typedef struct { +16: +17: char signature [ 4 ] ; +18: uint reserved1 ; +19: uint cbCabinet ; +20: uint reserved2 ; +21: uint coffFiles ; +22: uint reserved3 ; +23: ubyte versionMinor ; +24: ubyte versionMajor ; +25: ushort cFolders ; +26: ushort cFiles ; +27: ushort flags ; +28: ushort setID ; +29: ushort iCabinet ; +30: +31: if ( flags & 4 ) { +32: +33: ushort cbCFHeader ; +34: ubyte cbCFFolder ; +35: ubyte cbCFData ; +36: +37: if ( cbCFHeader > 0 ) +38: char abReserve [ cbCFHeader ] ; +39: +40: } +41: if ( flags & 1 ) { +42: +43: char szCabinetPrev [ ] ; +44: char szDiskPrev [ ] ; +45: +46: } +47: if ( flags & 2 ) { +48: +49: char szCabinetNext [ ] ; +50: char szDiskNext [ ] ; +51: +52: } +53: +54: } CFHEADER ; +55: +56: LittleEndian ( ) ; +57: CFHEADER header ; +58: local uint counter = 0 ; +59: +60: typedef struct { +61: +62: uint coffCabStart ; +63: ushort cCFData ; +64: ushort typeCompress ; +65: +66: if ( exists ( header . cbCFFolder ) ) +67: char abReserve [ header . cbCFFolder ] ; +68: +69: } CFFOLDER ; +70: +71: typedef struct { +72: +73: uint cbFile ; +74: uint uoffFolderStart ; +75: ushort iFolder ; +76: DOSDATE date ; +77: DOSTIME time ; +78: ushort attribs ; +79: char szName [ ] ; +80: } CFFILE ; +81: +82: typedef struct { +83: +84: uint csum ; +85: ushort cbData ; +86: ushort cbUncomp ; +87: +88: if ( exists ( header . cbCFData ) ) +89: char abReserve [ header . cbCFData ] ; +90: +91: char ab [ cbData ] ; +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: } tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/CAPTemplate.bt b/cparser/tests/exp_lex/CAPTemplate.bt new file mode 100644 index 0000000..b236ce6 --- /dev/null +++ b/cparser/tests/exp_lex/CAPTemplate.bt @@ -0,0 +1,1292 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: local ushort method_offsets [ 256 ] ; +13: local ushort method_codesize [ 256 ] ; +14: local uint64 tail_index = 0 ; +15: local uint64 head_index = 0 ; +16: +17: void queue_push_method ( ushort offset , ushort codesize ) { +18: method_offsets [ tail_index ] = offset ; +19: method_codesize [ tail_index ] = codesize ; +20: tail_index ++ ; +21: } +22: +23: uint queue_pop_method ( ) { +24: if ( head_index != tail_index ) { +25: head_index ++ ; +26: return 1 ; +27: } else { +28: return 0 ; +29: } +30: } +31: +32: uint queue_peek_method ( ) { +33: if ( head_index != tail_index ) { +34: return 1 ; +35: } else { +36: return 0 ; +37: } +38: } +39: +40: typedef enum < short > { +41: COMP_STORED = 0 , +42: COMP_SHRUNK = 1 , +43: COMP_REDUCED1 = 2 , +44: COMP_REDUCED2 = 3 , +45: COMP_REDUCED3 = 4 , +46: COMP_REDUCED4 = 5 , +47: COMP_IMPLODED = 6 , +48: COMP_TOKEN = 7 , +49: COMP_DEFLATE = 8 , +50: COMP_DEFLATE64 = 9 +51: } COMPTYPE ; +52: +53: typedef enum < uchar > { +54: aaload = 0x24 , +55: aastore = 0x37 , +56: aconst_null = 0x1 , +57: aload = 0x15 , +58: aload_0 = 0x18 , +59: aload_1 = 0x19 , +60: aload_2 = 0x1A , +61: aload_3 = 0x1B , +62: anewarray = 0x91 , +63: areturn = 0x77 , +64: arraylength = 0x92 , +65: astore = 0x28 , +66: astore_0 = 0x2B , +67: astore_1 = 0x2C , +68: astore_2 = 0x2D , +69: astore_3 = 0x2E , +70: athrow = 0x93 , +71: baload = 0x25 , +72: bastore = 0x38 , +73: bipush = 0x12 , +74: bspush = 0x10 , +75: checkcast = 0x94 , +76: dup = 0x3D , +77: dup_x = 0x3F , +78: dup2 = 0x3E , +79: getfield_a = 0x83 , +80: getfield_b = 0x84 , +81: getfield_s = 0x85 , +82: getfield_i = 0x86 , +83: getfield_a_this = 0xAD , +84: getfield_b_this = 0xAE , +85: getfield_s_this = 0xAF , +86: getfield_i_this = 0xB0 , +87: getfield_a_w = 0xA9 , +88: getfield_b_w = 0xAA , +89: getfield_s_w = 0xAB , +90: getfield_i_w = 0xAC , +91: getstatic_a = 0x7B , +92: getstatic_b = 0x7C , +93: getstatic_s = 0x7D , +94: getstatic_i = 0x7E , +95: goto = 0x70 , +96: goto_w = 0xA8 , +97: i2b = 0x5D , +98: i2s = 0x5E , +99: iadd = 0x42 , +100: iaload = 0x27 , +101: iand = 0x54 , +102: iastore = 0x3A , +103: icmp = 0x5F , +104: iconst_m1 = 0x9 , +105: iconst_0 = 0xA , +106: iconst_1 = 0xB , +107: iconst_2 = 0xC , +108: iconst_3 = 0xD , +109: iconst_4 = 0xE , +110: iconst_5 = 0xF , +111: idiv = 0x48 , +112: if_acmpeq = 0x68 , +113: if_acmpne = 0x69 , +114: if_acmpeq_w = 0xA0 , +115: if_acmpne_w = 0xA1 , +116: if_scmpeq = 0x6A , +117: if_scmpne = 0x6B , +118: if_scmplt = 0x6C , +119: if_scmpge = 0x6D , +120: if_scmpgt = 0x6E , +121: if_scmple = 0x6F , +122: if_scmpeq_w = 0xA2 , +123: if_scmpne_w = 0xA3 , +124: if_scmplt_w = 0xA4 , +125: if_scmpge_w = 0xA5 , +126: if_scmpgt_w = 0xA6 , +127: if_scmple_w = 0xA7 , +128: ifeq = 0x60 , +129: ifne = 0x61 , +130: iflt = 0x62 , +131: ifge = 0x63 , +132: ifgt = 0x64 , +133: ifle = 0x65 , +134: ifeq_w = 0x98 , +135: ifne_w = 0x99 , +136: iflt_w = 0x9A , +137: ifge_w = 0x9B , +138: ifgt_w = 0x9C , +139: ifle_w = 0x9D , +140: ifnonnull = 0x67 , +141: ifnonnull_w = 0x9F , +142: ifnull = 0x66 , +143: ifnull_w = 0x9E , +144: iinc = 0x5A , +145: iinc_w = 0x97 , +146: iipush = 0x14 , +147: iload = 0x17 , +148: iload_0 = 0x20 , +149: iload_1 = 0x21 , +150: iload_2 = 0x22 , +151: iload_3 = 0x23 , +152: ilookupswitch = 0x76 , +153: imul = 0x46 , +154: ineg = 0x4C , +155: instanceof = 0x95 , +156: invokeinterface = 0x8E , +157: invokespecial = 0x8C , +158: invokestatic = 0x8D , +159: invokevirtual = 0x8B , +160: ior = 0x56 , +161: irem = 0x4A , +162: ireturn = 0x79 , +163: ishl = 0x4E , +164: ishr = 0x50 , +165: istore = 0x2A , +166: istore_0 = 0x33 , +167: istore_1 = 0x34 , +168: istore_2 = 0x35 , +169: istore_3 = 0x36 , +170: isub = 0x44 , +171: itableswitch = 0x74 , +172: iushr = 0x52 , +173: ixor = 0x58 , +174: jsr = 0x71 , +175: new = 0x8F , +176: newarray = 0x90 , +177: nop = 0 , +178: pop = 0x3B , +179: pop2 = 0x3C , +180: putfield_a = 0x87 , +181: putfield_b = 0x88 , +182: putfield_s = 0x89 , +183: putfield_i = 0x8A , +184: putfield_a_this = 0xB5 , +185: putfield_b_this = 0xB6 , +186: putfield_s_this = 0xB7 , +187: putfield_i_this = 0xB8 , +188: putfield_a_w = 0xB1 , +189: putfield_b_w = 0xB2 , +190: putfield_s_w = 0xB3 , +191: putfield_i_w = 0xB4 , +192: putstatic_a = 0x7F , +193: putstatic_b = 0x80 , +194: putstatic_s = 0x81 , +195: putstatic_i = 0x82 , +196: ret = 0x72 , +197: Return = 0x7A , +198: s2b = 0x5B , +199: s2i = 0x5C , +200: sadd = 0x41 , +201: saload = 0x46 , +202: sand = 0x53 , +203: sastore = 0x39 , +204: sconst_m1 = 0x2 , +205: sconst_0 = 0x3 , +206: sconst_1 = 0x4 , +207: sconst_2 = 0x5 , +208: sconst_3 = 0x6 , +209: sconst_4 = 0x7 , +210: sconst_5 = 0x8 , +211: sdiv = 0x47 , +212: sinc = 0x59 , +213: sinc_w = 0x96 , +214: sipush = 0x13 , +215: sload = 0x16 , +216: sload_0 = 0x1C , +217: sload_1 = 0x1D , +218: sload_2 = 0x1E , +219: sload_3 = 0x1F , +220: slookupswitch = 0x75 , +221: smul = 0x45 , +222: sneg = 0x4B , +223: sor = 0x55 , +224: srem = 0x49 , +225: sreturn = 0x78 , +226: sshl = 0x4D , +227: sshr = 0x4F , +228: sspush = 0x11 , +229: sstore = 0x29 , +230: sstore_0 = 0x2F , +231: sstore_1 = 0x30 , +232: sstore_2 = 0x31 , +233: sstore_3 = 0x32 , +234: ssub = 0x43 , +235: stableswitch = 0x73 , +236: sushr = 0x51 , +237: swap_x = 0x40 , +238: sxor = 0x57 +239: } JVCODE ; +240: +241: typedef struct { +242: char minor_version ; +243: char major_version ; +244: char AID_length ; +245: if ( AID_length > 0 ) +246: char AID [ AID_length ] ; +247: } PACKAGE_INFO ; +248: +249: typedef struct { +250: char name_length ; +251: if ( name_length > 0 ) +252: char name [ name_length ] ; +253: } PACKAGE_NAME_INFO ; +254: +255: typedef struct { +256: ushort image_size ; +257: ushort array_init_count ; +258: ushort array_init_size ; +259: } STATIC_FIELD_SIZE_INFO ; +260: +261: typedef struct { +262: uchar component_tag ; +263: ushort size ; +264: uchar AID_length ; +265: if ( AID_length > 0 ) +266: char AID [ AID_length ] ; +267: } CUSTOM_COMPONENT_INFO ; +268: +269: typedef struct { +270: char tag ; +271: ushort size ; +272: uint magic ; +273: uchar minor_version ; +274: uchar major_version ; +275: uchar flags ; +276: PACKAGE_INFO package ; +277: PACKAGE_NAME_INFO package_name ; +278: } HEADER_COMPONENT ; +279: +280: typedef struct { +281: uchar tag ; +282: ushort size ; +283: ushort component_sizes [ 12 ] ; +284: STATIC_FIELD_SIZE_INFO static_field_size ; +285: uchar import_count ; +286: uchar applet_count ; +287: uchar custom_count ; +288: if ( custom_count > 0 ) +289: CUSTOM_COMPONENT_INFO custom_components [ custom_count ] ; +290: } DIRECTORY_COMPONENT ; +291: +292: typedef struct { +293: uchar AID_length ; +294: if ( AID_length > 0 ) +295: char AID [ AID_length ] ; +296: ushort install_method_offset ; +297: } APPLET_INFO ; +298: +299: typedef struct { +300: uchar tag ; +301: ushort size ; +302: uchar count ; +303: if ( count > 0 ) +304: APPLET_INFO applets [ count ] < optimize = false > ; +305: } APPLET_COMPONENT ; +306: +307: typedef struct { +308: uchar tag ; +309: ushort size ; +310: uchar count ; +311: if ( count > 0 ) +312: PACKAGE_INFO packages [ count ] < optimize = false > ; +313: } IMPORT_COMPONENT ; +314: +315: typedef struct { +316: uchar nibble_count ; +317: if ( nibble_count > 0 ) +318: uchar type [ ( nibble_count + 1 ) / 2 ] ; +319: } TYPE_DESCRIPTOR ; +320: +321: typedef struct { +322: if ( ReadByte ( FTell ( ) ) & 0x80 ) { +323: ushort internal_class_ref ; +324: } else { +325: uchar package_token ; +326: uchar class_token ; +327: } +328: } CLASS_REF ; +329: +330: typedef struct { +331: uchar interface_name_length ; +332: if ( interface_name_length > 0 ) +333: uchar interface_name [ interface_name_length ] ; +334: } INTERFACE_NAME_INFO ; +335: +336: typedef struct { +337: CLASS_REF interface ; +338: uchar count ; +339: if ( count > 0 ) +340: uchar index [ count ] ; +341: } IMPLEMENTED_INTERFACE_INFO ; +342: +343: typedef struct { +344: ushort remote_method_hash ; +345: ushort signature_offset ; +346: uchar virtual_method_token ; +347: } REMOTE_METHOD_INFO ; +348: +349: typedef struct { +350: uchar tag ; +351: CLASS_REF class_ref ; +352: uchar padding ; +353: } CONST_CLASSREF_INFO ; +354: +355: typedef struct { +356: uchar tag ; +357: CLASS_REF class ; +358: uchar token ; +359: } CONST_INSTANCEFIELDREF_INFO ; +360: +361: typedef struct { +362: uchar tag ; +363: CLASS_REF class ; +364: uchar token ; +365: } CONST_VIRTUALMETHODREF_INFO ; +366: +367: typedef struct { +368: uchar tag ; +369: CLASS_REF class ; +370: uchar token ; +371: } CONST_SUPERMETHODREF_INFO ; +372: +373: typedef struct { +374: if ( ReadByte ( FTell ( ) ) == 0 ) { +375: uchar padding ; +376: ushort offset ; +377: } else { +378: uchar package_token ; +379: uchar class_token ; +380: uchar token ; +381: } +382: } STATIC_FIELD_REF ; +383: +384: typedef struct { +385: CLASS_REF class ; +386: uchar token ; +387: } INSTANCE_FIELD_REF ; +388: +389: typedef struct { +390: if ( ReadByte ( FTell ( ) ) == 0 ) { +391: uchar padding ; +392: ushort offset ; +393: } else { +394: uchar package_token ; +395: uchar class_token ; +396: uchar token ; +397: } +398: } STATIC_METHOD_REF ; +399: +400: typedef struct { +401: uchar tag ; +402: STATIC_FIELD_REF static_field_ref ; +403: } CONST_STATICFIELDREF_INFO ; +404: +405: typedef struct { +406: uchar tag ; +407: STATIC_METHOD_REF static_method_ref ; +408: } CONST_STATICMETHODREF_INFO ; +409: +410: typedef struct { +411: uchar remote_methods_count ; +412: if ( remote_methods_count > 0 ) +413: REMOTE_METHOD_INFO remote_methods [ remote_methods_count ] < optimize = false > ; +414: uchar hash_modifier_length ; +415: if ( hash_modifier_length > 0 ) +416: uchar hash_modifier [ hash_modifier_length ] < optimize = false > ; +417: uchar class_name_length ; +418: if ( class_name_length > 0 ) +419: uchar class_name [ class_name_length ] < optimize = false > ; +420: uchar remote_interface_count ; +421: if ( remote_interface_count > 0 ) +422: CLASS_REF remote_interfaces [ remote_interface_count ] < optimize = false > ; +423: } REMOTE_INTERFACE_INFO ; +424: +425: typedef struct { +426: +427: uchar flags : 4 ; +428: uchar interface_count : 4 ; +429: CLASS_REF super_class_ref ; +430: uchar declared_instance_size ; +431: uchar first_reference_token ; +432: uchar reference_count ; +433: uchar public_method_table_base ; +434: uchar public_method_table_count ; +435: uchar package_method_table_base ; +436: uchar package_method_table_count ; +437: if ( public_method_table_count > 0 ) +438: ushort public_virtual_method_table [ public_method_table_count ] < optimize = false > ; +439: if ( package_method_table_count > 0 ) +440: ushort package_virtual_method_table [ package_method_table_count ] < optimize = false > ; +441: if ( interface_count > 0 ) +442: IMPLEMENTED_INTERFACE_INFO interfaces [ interface_count ] < optimize = false > ; +443: if ( flags & 0x2 ) +444: REMOTE_INTERFACE_INFO remote_interfaces ; +445: } CLASS_INFO ; +446: +447: typedef struct { +448: +449: uchar flags : 4 ; +450: uchar interface_count : 4 ; +451: if ( interface_count > 0 ) +452: CLASS_REF super_interfaces [ interface_count ] < optimize = false > ; +453: if ( flags & 0x2 ) +454: INTERFACE_NAME_INFO interface_name ; +455: } INTERFACE_INFO ; +456: +457: typedef struct { +458: uchar tag ; +459: ushort size ; +460: local uint64 start_index = FTell ( ) ; +461: ushort signature_pool_length ; +462: local uint64 sign_index = FTell ( ) ; +463: if ( signature_pool_length > 0 ) { +464: +465: while ( FTell ( ) < ( sign_index + signature_pool_length ) ) { +466: TYPE_DESCRIPTOR descriptor ; +467: } +468: } +469: +470: +471: while ( FTell ( ) < ( start_index + size ) ) { +472: if ( ( ReadByte ( FTell ( ) ) & 0x80 ) ) { +473: +474: INTERFACE_INFO interface ; +475: } else { +476: +477: CLASS_INFO class ; +478: } +479: } +480: } CLASS_COMPONENT ; +481: +482: typedef struct { +483: uchar type ; +484: ushort count ; +485: uchar values [ count ] ; +486: } ARRAY_INIT_INFO ; +487: +488: typedef struct { +489: uchar tag ; +490: ushort size ; +491: ushort image_size ; +492: ushort reference_count ; +493: ushort array_init_count ; +494: if ( array_init_count > 0 ) +495: ARRAY_INIT_INFO array_init [ array_init_count ] < optimize = false > ; +496: ushort default_value_count ; +497: ushort non_default_value_count ; +498: if ( non_default_value_count > 0 ) +499: uchar non_default_values [ non_default_value_count ] < optimize = false > ; +500: } STATICFIELD_COMPONENT ; +501: +502: typedef struct { +503: uchar tag ; +504: ushort size ; +505: ushort byte_index_count ; +506: uchar offsets_to_byte_indices [ byte_index_count ] ; +507: ushort byte2_index_count ; +508: uchar offsets_to_byte2_indices [ byte2_index_count ] ; +509: } REFERENCELOC_COMPONENT ; +510: +511: typedef struct { +512: uchar tag ; +513: ushort size ; +514: uchar class_count ; +515: struct { +516: ushort class_offset ; +517: uchar static_field_count ; +518: uchar static_method_count ; +519: ushort static_field_offsets [ static_field_count ] ; +520: ushort static_method_offsets [ static_method_count ] ; +521: } class_exports [ class_count ] < optimize = false > ; +522: } EXPORT_COMPONENT ; +523: +524: typedef struct { +525: ushort start_offset ; +526: +527: ushort stop_bit : 1 ; +528: ushort active_length : 15 ; +529: ushort handler_offset ; +530: ushort catch_type_index ; +531: } EXCEPTION_HANDLER_INFO ; +532: +533: typedef struct { +534: uchar flags : 4 ; +535: uchar max_stack : 4 ; +536: uchar nargs : 4 ; +537: uchar max_locals : 4 ; +538: } METHOD_HEADER_INFO ; +539: +540: typedef struct { +541: uchar flags : 4 ; +542: uchar padding : 4 ; +543: uchar max_stack ; +544: uchar nargs ; +545: uchar max_locals ; +546: } EXTENDED_METHOD_HEADER_INFO ; +547: +548: typedef struct { +549: JVCODE opcode ; +550: +551: switch ( opcode ) { +552: case aaload : +553: case aastore : +554: case aconst_null : +555: case aload_0 : +556: case aload_1 : +557: case aload_2 : +558: case aload_3 : +559: case areturn : +560: case arraylength : +561: case astore_0 : +562: case astore_1 : +563: case astore_2 : +564: case astore_3 : +565: case athrow : +566: case baload : +567: case bastore : +568: case dup : +569: case dup2 : +570: case i2b : +571: case i2s : +572: case iadd : +573: case iaload : +574: case iand : +575: case iastore : +576: case icmp : +577: case iconst_m1 : +578: case iconst_0 : +579: case iconst_1 : +580: case iconst_2 : +581: case iconst_3 : +582: case iconst_4 : +583: case iconst_5 : +584: case idiv : +585: case iload_0 : +586: case iload_1 : +587: case iload_2 : +588: case iload_3 : +589: case imul : +590: case ineg : +591: case ior : +592: case irem : +593: case ireturn : +594: case ishl : +595: case ishr : +596: case istore_0 : +597: case istore_1 : +598: case istore_2 : +599: case istore_3 : +600: case isub : +601: case iushr : +602: case ixor : +603: case nop : +604: case pop : +605: case pop2 : +606: case Return : +607: case s2b : +608: case s2i : +609: case sadd : +610: case saload : +611: case sand : +612: case sastore : +613: case sconst_m1 : +614: case sconst_0 : +615: case sconst_1 : +616: case sconst_2 : +617: case sconst_3 : +618: case sconst_4 : +619: case sconst_5 : +620: case sdiv : +621: case sload_0 : +622: case sload_1 : +623: case sload_2 : +624: case sload_3 : +625: case smul : +626: case sneg : +627: case sor : +628: case srem : +629: case sreturn : +630: case sshl : +631: case sshr : +632: case sstore_0 : +633: case sstore_1 : +634: case sstore_2 : +635: case sstore_3 : +636: case ssub : +637: case sushr : +638: case sxor : +639: +640: break ; +641: case aload : +642: case astore : +643: case bipush : +644: case bspush : +645: case dup_x : +646: case getfield_a : +647: case getfield_b : +648: case getfield_s : +649: case getfield_i : +650: case getfield_a_this : +651: case getfield_b_this : +652: case getfield_s_this : +653: case getfield_i_this : +654: case goto : +655: case if_acmpeq : +656: case if_acmpne : +657: case if_scmpeq : +658: case if_scmpne : +659: case if_scmplt : +660: case if_scmpge : +661: case if_scmpgt : +662: case if_scmple : +663: case ifeq : +664: case ifne : +665: case iflt : +666: case ifge : +667: case ifgt : +668: case ifle : +669: case ifnonnull : +670: case ifnull : +671: case iload : +672: case istore : +673: case newarray : +674: case putfield_a : +675: case putfield_b : +676: case putfield_s : +677: case putfield_i : +678: case putfield_a_this : +679: case putfield_b_this : +680: case putfield_s_this : +681: case putfield_i_this : +682: case ret : +683: case sload : +684: case sstore : +685: case swap_x : +686: uchar operand1 ; +687: break ; +688: case anewarray : +689: case getfield_a_w : +690: case getfield_b_w : +691: case getfield_s_w : +692: case getfield_i_w : +693: case getstatic_a : +694: case getstatic_b : +695: case getstatic_s : +696: case getstatic_i : +697: case goto_w : +698: case if_acmpeq_w : +699: case if_acmpne_w : +700: case if_scmpeq_w : +701: case if_scmpne_w : +702: case if_scmplt_w : +703: case if_scmpge_w : +704: case if_scmpgt_w : +705: case if_scmple_w : +706: case ifeq_w : +707: case ifne_w : +708: case iflt_w : +709: case ifge_w : +710: case ifgt_w : +711: case ifle_w : +712: case ifnonnull_w : +713: case ifnull_w : +714: case invokespecial : +715: case invokestatic : +716: case invokevirtual : +717: case jsr : +718: case new : +719: case putfield_a_w : +720: case putfield_b_w : +721: case putfield_s_w : +722: case putfield_i_w : +723: case putstatic_a : +724: case putstatic_b : +725: case putstatic_s : +726: case putstatic_i : +727: case sipush : +728: case sspush : +729: ushort operand1 ; +730: break ; +731: case checkcast : +732: case iinc_w : +733: case instanceof : +734: case sinc_w : +735: uchar operand1 ; +736: ushort operand2 ; +737: break ; +738: case iinc : +739: case sinc : +740: uchar operand1 ; +741: uchar operand2 ; +742: break ; +743: case iipush : +744: uint operand1 ; +745: break ; +746: case invokeinterface : +747: uchar args ; +748: ushort index ; +749: uchar method ; +750: break ; +751: case ilookupswitch : +752: ushort default_offset ; +753: ushort pairs ; +754: local ushort index = 0 ; +755: if ( pairs > 0 ) { +756: while ( index < pairs ) { +757: struct { +758: uint match ; +759: ushort offset ; +760: } imo_pairs ; +761: index ++ ; +762: } +763: } +764: break ; +765: case itableswitch : +766: ushort default_offset ; +767: uint low ; +768: uint high ; +769: if ( ( high - low ) > 0 ) +770: ushort offsets [ high - low ] ; +771: break ; +772: case slookupswitch : +773: ushort default_offset ; +774: ushort pairs ; +775: local ushort index = 0 ; +776: if ( pairs > 0 ) { +777: while ( index < pairs ) { +778: struct { +779: ushort match ; +780: ushort offset ; +781: } imo_pairs ; +782: index ++ ; +783: } +784: } +785: break ; +786: case stableswitch : +787: ushort default_offset ; +788: ushort low ; +789: ushort high ; +790: if ( ( high - low ) > 0 ) +791: ushort offsets [ high - low ] ; +792: break ; +793: default : break ; +794: } +795: } JAVA_OPCODE < read = ReadJavaOpcode , optimize = false > ; +796: +797: local uint64 start_bytecode = 0 ; +798: string ReadJavaOpcode ( JAVA_OPCODE & code ) { +799: +800: return EnumToString ( code . opcode ) ; +801: } +802: +803: typedef struct { +804: uchar tag ; +805: ushort size ; +806: local uint64 start_index = FTell ( ) ; +807: local uint64 handler_size = FTell ( ) - start_index ; +808: +809: local uint64 start_method = FTell ( ) ; +810: start_bytecode = start_method ; +811: uchar handler_count ; +812: if ( handler_count > 0 ) +813: EXCEPTION_HANDLER_INFO exception_handlers [ handler_count ] < optimize = false > ; +814: +815: +816: +817: +818: while ( head_index != tail_index ) { +819: FSeek ( start_method + method_offsets [ head_index ] ) ; +820: struct { +821: if ( ( ReadByte ( FTell ( ) ) & 0x80 ) ) { +822: EXTENDED_METHOD_HEADER_INFO method_header ; +823: } else { +824: METHOD_HEADER_INFO method_header ; +825: } +826: start_index = FTell ( ) ; +827: local uint16 codesize = method_codesize [ head_index ] ; +828: +829: if ( codesize != 0 ) { +830: struct { +831: while ( FTell ( ) < ( start_index + codesize ) ) { +832: JAVA_OPCODE code ; +833: } +834: } bytecodes ; +835: } +836: } methods ; +837: head_index ++ ; +838: +839: } +840: FSeek ( start_index + size ) ; +841: } METHOD_COMPONENT ; +842: +843: typedef struct { +844: uchar tag ; +845: uchar info [ 3 ] ; +846: } CP_INFO ; +847: +848: typedef struct { +849: uchar tag ; +850: ushort size ; +851: ushort count ; +852: CP_INFO constant_pool [ count ] ; +853: } CONSTANT_POOL_COMPONENT ; +854: +855: typedef struct { +856: uchar token ; +857: uchar access_flags ; +858: if ( access_flags & 0x8 ) { +859: STATIC_FIELD_REF field_ref ; +860: } else { +861: INSTANCE_FIELD_REF field_ref ; +862: } +863: union { +864: ushort primitive_type ; +865: ushort reference_type ; +866: } type ; +867: } FIELD_DESCRIPTOR_INFO ; +868: +869: typedef struct { +870: uchar token ; +871: uchar access_flags ; +872: ushort method_offset ; +873: ushort type_offset ; +874: ushort bytecode_count ; +875: ushort exception_handler_count ; +876: ushort exception_handler_index ; +877: +878: if ( bytecode_count > 0 ) { +879: method_offsets [ tail_index ] = method_offset ; +880: method_codesize [ tail_index ] = bytecode_count ; +881: tail_index ++ ; +882: } +883: } METHOD_DESCRIPTOR_INFO ; +884: +885: typedef struct { +886: uchar token ; +887: uchar access_flags ; +888: CLASS_REF this_class_ref ; +889: uchar interface_count ; +890: ushort field_count ; +891: ushort method_count ; +892: if ( interface_count > 0 ) +893: CLASS_REF interfaces [ interface_count ] < optimize = false > ; +894: if ( field_count > 0 ) +895: FIELD_DESCRIPTOR_INFO fields [ field_count ] < optimize = false > ; +896: if ( method_count > 0 ) { +897: METHOD_DESCRIPTOR_INFO methods [ method_count ] < optimize = false > ; +898: } +899: } CLASS_DESCRIPTOR_INFO ; +900: +901: typedef struct { +902: uchar tag ; +903: ushort size ; +904: local uint64 start_index = FTell ( ) ; +905: uchar class_count ; +906: if ( class_count > 0 ) +907: CLASS_DESCRIPTOR_INFO classes [ class_count ] < optimize = false > ; +908: +909: local uint64 desc_start_index = FTell ( ) ; +910: struct { +911: ushort constant_pool_count ; +912: if ( constant_pool_count > 0 ) +913: ushort constant_pool_types [ constant_pool_count ] ; +914: while ( FTell ( ) < ( start_index + size ) ) { +915: TYPE_DESCRIPTOR type_desc ; +916: +917: } +918: } types ; +919: +920: } DESCRIPTOR_COMPONENT ; +921: +922: typedef struct { +923: ushort length ; +924: if ( length > 0 ) +925: uchar bytes [ length ] ; +926: } UTF8_INFO ; +927: +928: typedef struct { +929: ushort name_index ; +930: ushort descriptor_index ; +931: ushort access_flags ; +932: uint contents ; +933: } FIELD_DEBUG_INFO ; +934: +935: typedef struct { +936: uchar index ; +937: ushort name_index ; +938: ushort descriptor_index ; +939: ushort start_pc ; +940: ushort length ; +941: } VARIABLE_INFO ; +942: +943: typedef struct { +944: ushort start_pc ; +945: ushort end_pc ; +946: ushort source_line ; +947: } LINE_INFO ; +948: +949: typedef struct { +950: ushort name_index ; +951: ushort descriptor_index ; +952: ushort access_flags ; +953: ushort location ; +954: uchar header_size ; +955: ushort body_size ; +956: ushort variable_count ; +957: ushort line_count ; +958: if ( variable_count > 0 ) +959: VARIABLE_INFO variable_table [ variable_count ] < optimize = false > ; +960: if ( line_count > 0 ) +961: LINE_INFO line_table [ line_count ] < optimize = false > ; +962: } METHOD_DEBUG_INFO ; +963: +964: typedef struct { +965: ushort name_index ; +966: ushort access_flags ; +967: ushort location ; +968: ushort superclass_name_index ; +969: ushort source_file_index ; +970: uchar interface_count ; +971: ushort field_count ; +972: ushort method_count ; +973: if ( interface_count > 0 ) +974: ushort interface_names_indexes [ interface_count ] < optimize = false > ; +975: if ( field_count > 0 ) +976: FIELD_DEBUG_INFO fields [ field_count ] < optimize = false > ; +977: if ( method_count > 0 ) +978: METHOD_DEBUG_INFO methods [ method_count ] < optimize = false > ; +979: } CLASS_DEBUG_INFO ; +980: +981: typedef struct { +982: uchar tag ; +983: ushort size ; +984: ushort string_count ; +985: UTF8_INFO strings_table [ string_count ] < optimize = false > ; +986: ushort package_name_index ; +987: ushort class_count ; +988: CLASS_DEBUG_INFO classes [ class_count ] < optimize = false > ; +989: } DEBUG_COMPONENT ; +990: +991: +992: local uint64 method_comp_offset = 0 ; +993: local uchar descriptor_comp_decoded = false ; +994: local uchar method_comp_decoded = false ; +995: local uint64 current_file_rec_offset = 0 ; +996: local uint64 next_file_rec_offset = 0 ; +997: typedef struct { +998: char signature [ 4 ] ; +999: ushort version ; +1000: ushort flags ; +1001: COMPTYPE mode ; +1002: if ( mode != COMP_STORED ) return "Not a valid CAP file" ; +1003: DOSTIME filetime ; +1004: DOSDATE filedate ; +1005: uint crc < format = hex > ; +1006: uint comp_size ; +1007: uint uncomp_size ; +1008: ushort filename_length ; +1009: ushort extrafield_length ; +1010: if ( filename_length > 0 ) +1011: char filename [ filename_length ] ; +1012: if ( extrafield_length > 0 ) +1013: uchar extrafield [ extrafield_length ] ; +1014: } CAPFILEHEADER ; +1015: +1016: typedef struct { +1017: +1018: CAPFILEHEADER header ; +1019: +1020: +1021: SetBackColor ( cNone ) ; +1022: +1023: +1024: BigEndian ( ) ; +1025: if ( Stricmp ( FileNameGetBase ( header . filename ) , "header.cap" ) == 0 ) { +1026: HEADER_COMPONENT header_component ; +1027: } else if ( Stricmp ( FileNameGetBase ( header . filename ) , "directory.cap" ) == 0 ) { +1028: DIRECTORY_COMPONENT directory_component ; +1029: } else if ( Stricmp ( FileNameGetBase ( header . filename ) , "applet.cap" ) == 0 ) { +1030: APPLET_COMPONENT applet_component ; +1031: } else if ( Stricmp ( FileNameGetBase ( header . filename ) , "class.cap" ) == 0 ) { +1032: CLASS_COMPONENT class_component ; +1033: } else if ( Stricmp ( FileNameGetBase ( header . filename ) , "import.cap" ) == 0 ) { +1034: IMPORT_COMPONENT import_component ; +1035: } else if ( Stricmp ( FileNameGetBase ( header . filename ) , "constantpool.cap" ) == 0 ) { +1036: CONSTANT_POOL_COMPONENT constantpool_component ; +1037: } else if ( Stricmp ( FileNameGetBase ( header . filename ) , "method.cap" ) == 0 ) { +1038: METHOD_COMPONENT method_component ; +1039: method_comp_decoded = true ; +1040: } else if ( Stricmp ( FileNameGetBase ( header . filename ) , "staticfield.cap" ) == 0 ) { +1041: STATICFIELD_COMPONENT staticfield_component ; +1042: } else if ( Stricmp ( FileNameGetBase ( header . filename ) , "reflocation.cap" ) == 0 ) { +1043: REFERENCELOC_COMPONENT refloc_component ; +1044: } else if ( Stricmp ( FileNameGetBase ( header . filename ) , "export.cap" ) == 0 ) { +1045: EXPORT_COMPONENT export_component ; +1046: } else if ( Stricmp ( FileNameGetBase ( header . filename ) , "descriptor.cap" ) == 0 ) { +1047: +1048: DESCRIPTOR_COMPONENT descriptor_component ; +1049: descriptor_comp_decoded = true ; +1050: +1051: +1052: } else if ( Stricmp ( FileNameGetBase ( header . filename ) , "debug.cap" ) == 0 ) { +1053: DEBUG_COMPONENT debug_component ; +1054: } +1055: LittleEndian ( ) ; +1056: } CAPFILERECORD < read = ReadCAPFILERECORD , write = WriteCAPFILERECORD , size = SizeCAPFILERECORD > ; +1057: +1058: int SizeCAPFILERECORD ( CAPFILERECORD & r ) +1059: { +1060: return 30 + +1061: ReadUInt ( startof ( r ) + 18 ) + +1062: ReadUShort ( startof ( r ) + 26 ) + +1063: ReadUShort ( startof ( r ) + 28 ) ; +1064: } ; +1065: +1066: +1067: typedef struct { +1068: char signature [ 4 ] ; +1069: ushort version_src ; +1070: ushort version_trgt ; +1071: ushort flags ; +1072: COMPTYPE mode ; +1073: DOSTIME filetime ; +1074: DOSDATE filedate ; +1075: uint crc < format = hex > ; +1076: uint comp_size ; +1077: uint uncomp_size ; +1078: ushort filename_length ; +1079: ushort extrafield_length ; +1080: ushort comment_length ; +1081: ushort disknum_start ; +1082: ushort internal_attr ; +1083: uint external_attr ; +1084: uint offset_hdr ; +1085: if ( filename_length > 0 ) +1086: char filename [ filename_length ] ; +1087: if ( extrafield_length > 0 ) +1088: uchar extrafield [ extrafield_length ] ; +1089: if ( comment_length > 0 ) +1090: uchar comment [ comment_length ] ; +1091: } CAPDIRENTRY < read = ReadCAPDIRENTRY > ; +1092: +1093: +1094: typedef struct { +1095: char signature [ 4 ] ; +1096: ushort data_length ; +1097: if ( data_length > 0 ) +1098: uchar data [ data_length ] ; +1099: } CAPDIGITALSIG ; +1100: +1101: +1102: typedef struct { +1103: char signature [ 4 ] ; +1104: uint crc < format = hex > ; +1105: uint comp_size ; +1106: uint uncomp_size ; +1107: } CAPDATADESCR ; +1108: +1109: +1110: typedef struct { +1111: char signature [ 4 ] ; +1112: ushort disknum ; +1113: ushort disknum_start ; +1114: ushort disk_entries ; +1115: ushort directory_entries ; +1116: uint directory_size ; +1117: uint directory_offset ; +1118: ushort comment_length ; +1119: if ( comment_length > 0 ) +1120: char comment [ comment_length ] ; +1121: } CAPENDLOCATOR ; +1122: +1123: +1124: +1125: string ReadCAPFILERECORD ( CAPFILERECORD & file ) +1126: { +1127: if ( exists ( file . header . filename ) ) +1128: { +1129: if ( Stricmp ( FileNameGetBase ( file . header . filename ) , "header.cap" ) == 0 ) { +1130: return "Header" ; +1131: } else if ( Stricmp ( FileNameGetBase ( file . header . filename ) , "directory.cap" ) == 0 ) { +1132: return "Directory" ; +1133: } else if ( Stricmp ( FileNameGetBase ( file . header . filename ) , "applet.cap" ) == 0 ) { +1134: return "Applet" ; +1135: } else if ( Stricmp ( FileNameGetBase ( file . header . filename ) , "class.cap" ) == 0 ) { +1136: return "Class" ; +1137: } else if ( Stricmp ( FileNameGetBase ( file . header . filename ) , "import.cap" ) == 0 ) { +1138: return "Import" ; +1139: } else if ( Stricmp ( FileNameGetBase ( file . header . filename ) , "constantpool.cap" ) == 0 ) { +1140: return "ConstantPool" ; +1141: } else if ( Stricmp ( FileNameGetBase ( file . header . filename ) , "method.cap" ) == 0 ) { +1142: return "Method" ; +1143: } else if ( Stricmp ( FileNameGetBase ( file . header . filename ) , "staticfield.cap" ) == 0 ) { +1144: return "StaticField" ; +1145: } else if ( Stricmp ( FileNameGetBase ( file . header . filename ) , "reflocation.cap" ) == 0 ) { +1146: return "ReferenceLocation" ; +1147: } else if ( Stricmp ( FileNameGetBase ( file . header . filename ) , "export.cap" ) == 0 ) { +1148: return "Export" ; +1149: } else if ( Stricmp ( FileNameGetBase ( file . header . filename ) , "descriptor.cap" ) == 0 ) { +1150: return "Descriptor" ; +1151: } else if ( Stricmp ( FileNameGetBase ( file . header . filename ) , "debug.cap" ) == 0 ) { +1152: return "Debug" ; +1153: } +1154: } +1155: return "" ; +1156: } +1157: +1158: string ReadCAPDIRENTRY ( CAPDIRENTRY & entry ) +1159: { +1160: if ( exists ( entry . filename ) ) +1161: { +1162: if ( Stricmp ( FileNameGetBase ( entry . filename ) , "header.cap" ) == 0 ) { +1163: return "Header Entry" ; +1164: } else if ( Stricmp ( FileNameGetBase ( entry . filename ) , "directory.cap" ) == 0 ) { +1165: return "Directory Entry" ; +1166: } else if ( Stricmp ( FileNameGetBase ( entry . filename ) , "applet.cap" ) == 0 ) { +1167: return "Applet Entry" ; +1168: } else if ( Stricmp ( FileNameGetBase ( entry . filename ) , "class.cap" ) == 0 ) { +1169: return "Class Entry" ; +1170: } else if ( Stricmp ( FileNameGetBase ( entry . filename ) , "import.cap" ) == 0 ) { +1171: return "Import Entry" ; +1172: } else if ( Stricmp ( FileNameGetBase ( entry . filename ) , "constantpool.cap" ) == 0 ) { +1173: return "ConstantPool Entry" ; +1174: } else if ( Stricmp ( FileNameGetBase ( entry . filename ) , "method.cap" ) == 0 ) { +1175: return "Method Entry" ; +1176: } else if ( Stricmp ( FileNameGetBase ( entry . filename ) , "staticfield.cap" ) == 0 ) { +1177: return "StaticField Entry" ; +1178: } else if ( Stricmp ( FileNameGetBase ( entry . filename ) , "reflocation.cap" ) == 0 ) { +1179: return "ReferenceLocation Entry" ; +1180: } else if ( Stricmp ( FileNameGetBase ( entry . filename ) , "export.cap" ) == 0 ) { +1181: return "Export Entry" ; +1182: } else if ( Stricmp ( FileNameGetBase ( entry . filename ) , "descriptor.cap" ) == 0 ) { +1183: return "Descriptor Entry" ; +1184: } else if ( Stricmp ( FileNameGetBase ( entry . filename ) , "debug.cap" ) == 0 ) { +1185: return "Debug Entry" ; +1186: } +1187: } +1188: return "Unknown Entry" ; +1189: } +1190: +1191: void WriteCAPFILERECORD ( CAPFILERECORD & file , string s ) +1192: { +1193: local int len = Strlen ( s ) ; +1194: if ( exists ( file . frFileName ) ) +1195: { +1196: Strncpy ( file . frFileName , s , file . frFileNameLength ) ; +1197: if ( len < file . frFileNameLength ) +1198: file . frFileName [ len ] = 0 ; +1199: } +1200: } +1201: +1202: +1203: +1204: local uint tag ; +1205: local ushort filename_len = 0 ; +1206: local char filename [ ] ; +1207: LittleEndian ( ) ; +1208: while ( ! FEof ( ) ) +1209: { +1210: +1211: tag = ReadUInt ( FTell ( ) ) ; +1212: +1213: if ( tag == 0x4034B50 ) +1214: { +1215: SetBackColor ( cLtGray ) ; +1216: current_file_rec_offset = FTell ( ) ; +1217: filename_len = ReadUShort ( FTell ( ) + 26 ) ; +1218: filename = ReadString ( FTell ( ) + 0x1E , filename_len ) ; +1219: +1220: if ( Stricmp ( FileNameGetBase ( filename ) , "header.cap" ) == 0 ) { +1221: CAPFILERECORD record ; +1222: } else if ( Stricmp ( FileNameGetBase ( filename ) , "directory.cap" ) == 0 ) { +1223: CAPFILERECORD record ; +1224: } else if ( Stricmp ( FileNameGetBase ( filename ) , "applet.cap" ) == 0 ) { +1225: CAPFILERECORD record ; +1226: } else if ( Stricmp ( FileNameGetBase ( filename ) , "class.cap" ) == 0 ) { +1227: CAPFILERECORD record ; +1228: } else if ( Stricmp ( FileNameGetBase ( filename ) , "import.cap" ) == 0 ) { +1229: CAPFILERECORD record ; +1230: } else if ( Stricmp ( FileNameGetBase ( filename ) , "constantpool.cap" ) == 0 ) { +1231: CAPFILERECORD record ; +1232: } else if ( Stricmp ( FileNameGetBase ( filename ) , "method.cap" ) == 0 ) { +1233: +1234: method_comp_offset = current_file_rec_offset ; +1235: if ( descriptor_comp_decoded == true ) { +1236: CAPFILERECORD record ; +1237: } else { +1238: method_comp_decoded = false ; +1239: local uint64 pk_header_size = 30 + ReadUInt ( FTell ( ) + 18 ) + ReadUShort ( FTell ( ) + 26 ) + ReadUShort ( FTell ( ) + 28 ) ; +1240: +1241: +1242: +1243: FSeek ( FTell ( ) + pk_header_size ) ; +1244: } +1245: } else if ( Stricmp ( FileNameGetBase ( filename ) , "staticfield.cap" ) == 0 ) { +1246: CAPFILERECORD record ; +1247: } else if ( Stricmp ( FileNameGetBase ( filename ) , "reflocation.cap" ) == 0 ) { +1248: CAPFILERECORD record ; +1249: } else if ( Stricmp ( FileNameGetBase ( filename ) , "export.cap" ) == 0 ) { +1250: CAPFILERECORD record ; +1251: } else if ( Stricmp ( FileNameGetBase ( filename ) , "descriptor.cap" ) == 0 ) { +1252: head_index = 0 ; +1253: tail_index = 0 ; +1254: CAPFILERECORD record ; +1255: next_file_rec_offset = FTell ( ) ; +1256: if ( method_comp_decoded == false ) { +1257: FSeek ( method_comp_offset ) ; +1258: CAPFILERECORD record ; +1259: FSeek ( next_file_rec_offset ) ; +1260: } +1261: } else if ( Stricmp ( FileNameGetBase ( filename ) , "debug.cap" ) == 0 ) { +1262: CAPFILERECORD record ; +1263: } else { +1264: CAPFILERECORD record ; +1265: } +1266: } +1267: else if ( tag == 0x8074B50 ) +1268: { +1269: SetBackColor ( cLtGreen ) ; +1270: CAPDATADESCR dataDescr ; +1271: } +1272: else if ( tag == 0x2014B50 ) +1273: { +1274: SetBackColor ( cLtPurple ) ; +1275: CAPDIRENTRY dirEntry ; +1276: } +1277: else if ( tag == 0x5054B50 ) +1278: { +1279: SetBackColor ( cLtBlue ) ; +1280: CAPDIGITALSIG digitalSig ; +1281: } +1282: else if ( tag == 0x6054B50 ) +1283: { +1284: SetBackColor ( cLtYellow ) ; +1285: CAPENDLOCATOR endLocator ; +1286: } +1287: else +1288: { +1289: Warning ( "Unknown CAP tag encountered. Template stopped." ) ; +1290: return - 1 ; +1291: } +1292: } tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/CDATemplate.bt b/cparser/tests/exp_lex/CDATemplate.bt new file mode 100644 index 0000000..3b7e54b --- /dev/null +++ b/cparser/tests/exp_lex/CDATemplate.bt @@ -0,0 +1,32 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: typedef struct +10: { +11: char szHeader [ 8 ] ; +12: char szFormat [ 8 ] ; +13: DWORD dwEOLn ; +14: } CDAFILEHEADER ; +15: +16: typedef struct +17: { +18: WORD wTrackFirst ; +19: WORD wTrackCount ; +20: DWORD dwVolumeSerialNumber ; +21: DWORD dwStartFrame ; +22: DWORD dwLengthFrame ; +23: DWORD dwStartMS ; +24: DWORD dwLengthMS ; +25: } CDAINFORMATION ; +26: +27: LittleEndian ( ) ; +28: CDAFILEHEADER Header ; +29: CDAINFORMATION Information ; +30: +31: +32: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/CLASSTemplate.bt b/cparser/tests/exp_lex/CLASSTemplate.bt new file mode 100644 index 0000000..4385d5d --- /dev/null +++ b/cparser/tests/exp_lex/CLASSTemplate.bt @@ -0,0 +1,254 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: +21: +22: +23: +24: +25: +26: +27: BigEndian ( ) ; +28: +29: +30: +31: typedef uint32 u4 ; +32: typedef uint16 u2 ; +33: typedef ubyte u1 ; +34: +35: typedef enum < u2 > eACCESS_FLAGS { +36: ACC_PUBLIC = 0x1 , +37: ACC_PRIVATE = 0x2 , +38: ACC_PROTECTED = 0x4 , +39: ACC_STATIC = 0x8 , +40: ACC_FINAL = 0x10 , +41: ACC_SUPER = 0x20 , +42: ACC_VOLATILE = 0x40 , +43: ACC_TRANSIENT = 0x80 , +44: ACC_NATIVE = 0x100 , +45: ACC_INTERFACE = 0x200 , +46: ACC_ABSTRACT = 0x400 , +47: ACC_STRICT = 0x800 +48: } AF < read = read_AF > ; +49: +50: string read_AF ( local AF & af ) { +51: local string s = "" ; +52: local int commaNeeded = 0 ; +53: local AF i = 1 ; +54: +55: SPrintf ( s , "%d: " , af ) ; +56: +57: +58: +59: +60: +61: while ( i < ACC_STRICT ) { +62: if ( af && i ) { +63: if ( commaNeeded ) { +64: s += ", " ; +65: } +66: s += EnumToString ( i ) ; +67: commaNeeded = 1 ; +68: } +69: i = i << 1 ; +70: } +71: return s ; +72: } +73: +74: +75: typedef enum < u1 > eCP_CONST { +76: CONSTANT_Utf8 = 1 , +77: CONSTANT_Integer = 3 , +78: CONSTANT_Float = 4 , +79: CONSTANT_Long = 5 , +80: CONSTANT_Double = 6 , +81: CONSTANT_Class = 7 , +82: CONSTANT_String = 8 , +83: CONSTANT_Fieldref = 9 , +84: CONSTANT_Methodref = 10 , +85: CONSTANT_InterfaceMethodref = 11 , +86: CONSTANT_NameAndType = 12 , +87: } CP_CONST ; +88: +89: +90: +91: +92: +93: +94: typedef struct { +95: CP_CONST tag ; +96: switch ( tag ) +97: { +98: case CONSTANT_Class : +99: u2 name_index ; +100: break ; +101: case CONSTANT_Methodref : +102: case CONSTANT_Fieldref : +103: case CONSTANT_InterfaceMethodref : +104: u2 class_index ; +105: u2 name_and_type_index ; +106: break ; +107: case CONSTANT_Utf8 : +108: u2 length ; +109: char bytes [ length ] ; +110: break ; +111: case CONSTANT_Integer : +112: case CONSTANT_Float : +113: u4 bytes ; +114: break ; +115: case CONSTANT_Long : +116: case CONSTANT_Double : +117: u4 high_bytes ; +118: u4 low_bytes ; +119: break ; +120: case CONSTANT_String : +121: u2 string_index ; +122: break ; +123: case CONSTANT_NameAndType : +124: u2 name_index ; +125: u2 descriptor_index ; +126: break ; +127: default : +128: local string s ; +129: SPrintf ( s , "Unknown 'constant_pool' tag: %d" , tag ) ; +130: Warning ( s ) ; +131: return - 3 ; +132: } +133: } cp_info < read = read_cp_info , optimize = false > ; +134: +135: +136: +137: +138: +139: string read_cp_info ( local cp_info & i ) +140: { +141: local string s = "" ; +142: s = EnumToString ( i . tag ) ; +143: if ( i . tag == CONSTANT_Utf8 ) { +144: s += ": " + i . bytes ; +145: } +146: return s ; +147: } +148: +149: typedef struct { +150: u2 attribute_name_index ; +151: u4 attribute_length ; +152: u1 info [ attribute_length ] ; +153: } attribute_info < optimize = false > ; +154: +155: typedef struct { +156: AF access_flags ; +157: u2 name_index ; +158: u2 descriptor_index ; +159: u2 attributes_count ; +160: attribute_info attributes [ attributes_count ] ; +161: } field_info < optimize = false > ; +162: +163: typedef struct { +164: AF access_flags ; +165: u2 name_index ; +166: u2 descriptor_index ; +167: u2 attributes_count ; +168: attribute_info attributes [ attributes_count ] ; +169: } method_info < optimize = false > ; +170: +171: +172: +173: typedef struct { +174: u4 magic < format = hex > ; +175: if ( magic != 0xCAFEBABE ) { +176: Warning ( "Incorrect Magic Number. This is not a JVM Class. Template Terminated." ) ; +177: return - 1 ; +178: } +179: u2 minor_version ; +180: u2 major_version ; +181: u2 constant_pool_count ; +182: cp_info constant_pool [ constant_pool_count - 1 ] ; +183: AF access_flags ; +184: u2 this_class ; +185: if ( this_class < 1 || this_class > constant_pool_count - 1 ) { +186: local string s ; +187: SPrintf ( s , "Bad 'this_class' reference (%d). It should be in the range [1..%d]" , this_class , constant_pool_count - 1 ) ; +188: Warning ( s ) ; +189: return - 2 ; +190: } +191: u2 super_class ; +192: if ( super_class < 1 || super_class > constant_pool_count - 1 ) { +193: local string s ; +194: SPrintf ( s , "Bad 'super_class' reference (%d). It should be in the range [1..%d]" , super_class , constant_pool_count - 1 ) ; +195: Warning ( s ) ; +196: return - 2 ; +197: } +198: u2 interfaces_count ; +199: u2 interfaces [ interfaces_count ] ; +200: u2 fields_count ; +201: field_info fields [ fields_count ] ; +202: u2 methods_count ; +203: method_info methods [ methods_count ] ; +204: u2 attributes_count ; +205: attribute_info attributes [ attributes_count ] ; +206: } JVMClass < read = read_JVMClass , optimize = false > ; +207: +208: +209: +210: +211: +212: +213: +214: +215: string read_JVMClass ( local JVMClass & j ) +216: { +217: +218: local string s ; +219: SPrintf ( s , "JVM class v%d.%d" , j . major_version , j . minor_version ) ; +220: +221: +222: local int major = 1 ; +223: local int minor = 0 ; +224: +225: if ( j . major_version == 45 ) { +226: if ( j . minor_version >= 3 ) minor = 1 ; +227: } else { +228: if ( j . major_version >= 46 ) { +229: minor = j . major_version - 44 ; +230: } else { +231: +232: major = 0 ; +233: minor = 0 ; +234: Warning ( "Unexpected JVM major version number." ) ; +235: } +236: } +237: +238: if ( major || minor ) { +239: local string jre_v ; +240: SPrintf ( jre_v , " (Java %d.%d)" , major , minor ) ; +241: s += jre_v ; +242: } else { +243: s += " (Unknown Java Version)" ; +244: } +245: +246: return s ; +247: } +248: +249: +250: +251: +252: +253: struct JVMClass jc ; +254: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/CLASSTemplate2.bt b/cparser/tests/exp_lex/CLASSTemplate2.bt new file mode 100644 index 0000000..f10f95c --- /dev/null +++ b/cparser/tests/exp_lex/CLASSTemplate2.bt @@ -0,0 +1,122 @@ +1: BigEndian ( ) ; +2: +3: typedef struct { +4: enum < ubyte > { +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 < format = binary > ; +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 < format = hex > ; +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 < format = binary > ; +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: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/CLASSTemplate3.bt b/cparser/tests/exp_lex/CLASSTemplate3.bt new file mode 100644 index 0000000..ffc3f78 --- /dev/null +++ b/cparser/tests/exp_lex/CLASSTemplate3.bt @@ -0,0 +1,1477 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: BigEndian ( ) ; +11: +12: typedef ubyte u1 ; +13: typedef uint16 u2 ; +14: typedef uint32 u4 ; +15: typedef uint64 u8 ; +16: typedef byte i1 ; +17: typedef int16 i2 ; +18: typedef int32 i4 ; +19: +20: enum Constant_pool +21: { +22: CONSTANT_Class = 7 , +23: CONSTANT_Fieldref = 9 , +24: CONSTANT_Methodref = 10 , +25: CONSTANT_InterfaceMethodref = 11 , +26: CONSTANT_String = 8 , +27: CONSTANT_Integer = 3 , +28: CONSTANT_Float = 4 , +29: CONSTANT_Long = 5 , +30: CONSTANT_Double = 6 , +31: CONSTANT_NameAndType = 12 , +32: CONSTANT_Utf8 = 1 , +33: CONSTANT_MethodHandle = 15 , +34: CONSTANT_MethodType = 16 , +35: CONSTANT_InvokeDynamic = 18 +36: } ; +37: +38: enum < u2 > access_property_flags +39: { +40: ACC_PUBLIC = 0x1 , +41: ACC_PRIVATE = 0x2 , +42: ACC_PROTECTED = 0x4 , +43: ACC_STATIC = 0x8 , +44: ACC_FINAL = 0x10 , +45: ACC_SUPER_ACC_SYNCHRONIZED = 0x20 , +46: ACC_BRIDGE_ACC_VOLATILE = 0x40 , +47: ACC_VARARGS_ACC_TRANSIENT = 0x80 , +48: ACC_NATIVE = 0x100 , +49: ACC_INTERFACE = 0x200 , +50: ACC_ABSTRACT = 0x400 , +51: ACC_STRICT = 0x800 , +52: ACC_SYNTHETIC = 0x1000 , +53: ACC_ANNOTATION = 0x2000 , +54: ACC_ENUM = 0x4000 +55: } ; +56: +57: enum enum_type +58: { +59: Class , +60: Method , +61: Field , +62: Nested_Class +63: } ; +64: +65: +66: enum < u1 > enum_opcodes +67: { +68: nop = 0x0 , +69: aconst_null = 0x1 , +70: iconst_m1 = 0x2 , +71: iconst_0 = 0x3 , +72: iconst_1 = 0x4 , +73: iconst_2 = 0x5 , +74: iconst_3 = 0x6 , +75: iconst_4 = 0x7 , +76: iconst_5 = 0x8 , +77: lconst_0 = 0x9 , +78: lconst_1 = 0xA , +79: fconst_0 = 0xB , +80: fconst_1 = 0xC , +81: fconst_2 = 0xD , +82: dconst_0 = 0xE , +83: dconst_1 = 0xF , +84: bipush = 0x10 , +85: sipush = 0x11 , +86: ldc = 0x12 , +87: ldc_w = 0x13 , +88: ldc2_w = 0x14 , +89: iload = 0x15 , +90: lload = 0x16 , +91: fload = 0x17 , +92: dload = 0x18 , +93: aload = 0x19 , +94: iload_0 = 0x1A , +95: iload_1 = 0x1B , +96: iload_2 = 0x1C , +97: iload_3 = 0x1D , +98: lload_0 = 0x1E , +99: lload_1 = 0x1F , +100: lload_2 = 0x20 , +101: lload_3 = 0x21 , +102: fload_0 = 0x22 , +103: fload_1 = 0x23 , +104: fload_2 = 0x24 , +105: fload_3 = 0x25 , +106: dload_0 = 0x26 , +107: dload_1 = 0x27 , +108: dload_2 = 0x28 , +109: dload_3 = 0x29 , +110: aload_0 = 0x2A , +111: aload_1 = 0x2B , +112: aload_2 = 0x2C , +113: aload_3 = 0x2D , +114: iaload = 0x2E , +115: laload = 0x2F , +116: faload = 0x30 , +117: daload = 0x31 , +118: aaload = 0x32 , +119: baload = 0x33 , +120: caload = 0x34 , +121: saload = 0x35 , +122: istore = 0x36 , +123: lstore = 0x37 , +124: fstore = 0x38 , +125: dstore = 0x39 , +126: astore = 0x3A , +127: istore_0 = 0x3B , +128: istore_1 = 0x3C , +129: istore_2 = 0x3D , +130: istore_3 = 0x3E , +131: lstore_0 = 0x3F , +132: lstore_1 = 0x40 , +133: lstore_2 = 0x41 , +134: lstore_3 = 0x42 , +135: fstore_0 = 0x43 , +136: fstore_1 = 0x44 , +137: fstore_2 = 0x45 , +138: fstore_3 = 0x46 , +139: dstore_0 = 0x47 , +140: dstore_1 = 0x48 , +141: dstore_2 = 0x49 , +142: dstore_3 = 0x4A , +143: astore_0 = 0x4B , +144: astore_1 = 0x4C , +145: astore_2 = 0x4D , +146: astore_3 = 0x4E , +147: iastore = 0x4F , +148: lastore = 0x50 , +149: fastore = 0x51 , +150: dastore = 0x52 , +151: aastore = 0x53 , +152: bastore = 0x54 , +153: castore = 0x55 , +154: sastore = 0x56 , +155: pop = 0x57 , +156: pop2 = 0x58 , +157: dup = 0x59 , +158: dup_x1 = 0x5A , +159: dup_x2 = 0x5B , +160: dup2 = 0x5C , +161: dup2_x1 = 0x5D , +162: dup2_x2 = 0x5E , +163: swap = 0x5F , +164: iadd = 0x60 , +165: ladd = 0x61 , +166: fadd = 0x62 , +167: dadd = 0x63 , +168: isub = 0x64 , +169: lsub = 0x65 , +170: fsub = 0x66 , +171: dsub = 0x67 , +172: imul = 0x68 , +173: lmul = 0x69 , +174: fmul = 0x6A , +175: dmul = 0x6B , +176: idiv = 0x6C , +177: ldiv = 0x6D , +178: fdiv = 0x6E , +179: ddiv = 0x6F , +180: irem = 0x70 , +181: lrem = 0x71 , +182: frem = 0x72 , +183: drem = 0x73 , +184: ineg = 0x74 , +185: lneg = 0x75 , +186: fneg = 0x76 , +187: dneg = 0x77 , +188: ishl = 0x78 , +189: lshl = 0x79 , +190: ishr = 0x7A , +191: lshr = 0x7B , +192: iushr = 0x7C , +193: lushr = 0x7D , +194: iand = 0x7E , +195: land = 0x7F , +196: ior = 0x80 , +197: lor = 0x81 , +198: ixor = 0x82 , +199: lxor = 0x83 , +200: iinc = 0x84 , +201: i2l = 0x85 , +202: i2f = 0x86 , +203: i2d = 0x87 , +204: l2i = 0x88 , +205: l2f = 0x89 , +206: l2d = 0x8A , +207: f2i = 0x8B , +208: f2l = 0x8C , +209: f2d = 0x8D , +210: d2i = 0x8E , +211: d2l = 0x8F , +212: d2f = 0x90 , +213: i2b = 0x91 , +214: i2c = 0x92 , +215: i2s = 0x93 , +216: lcmp = 0x94 , +217: fcmpl = 0x95 , +218: fcmpg = 0x96 , +219: dcmpl = 0x97 , +220: dcmpg = 0x98 , +221: ifeq = 0x99 , +222: ifne = 0x9A , +223: iflt = 0x9B , +224: ifge = 0x9C , +225: ifgt = 0x9D , +226: ifle = 0x9E , +227: if_icmpeq = 0x9F , +228: if_icmpne = 0xA0 , +229: if_icmplt = 0xA1 , +230: if_icmpge = 0xA2 , +231: if_icmpgt = 0xA3 , +232: if_icmple = 0xA4 , +233: if_acmpeq = 0xA5 , +234: if_acmpne = 0xA6 , +235: goto = 0xA7 , +236: jsr = 0xA8 , +237: ret = 0xA9 , +238: tableswitch = 0xAA , +239: lookupswitch = 0xAB , +240: ireturn = 0xAC , +241: lreturn = 0xAD , +242: freturn = 0xAE , +243: dreturn = 0xAF , +244: areturn = 0xB0 , +245: Return = 0xB1 , +246: getstatic = 0xB2 , +247: putstatic = 0xB3 , +248: getfield = 0xB4 , +249: putfield = 0xB5 , +250: invokevirtual = 0xB6 , +251: invokespecial = 0xB7 , +252: invokestatic = 0xB8 , +253: invokeinterface = 0xB9 , +254: invokedynamic = 0xBA , +255: new = 0xBB , +256: newarray = 0xBC , +257: anewarray = 0xBD , +258: arraylength = 0xBE , +259: athrow = 0xBF , +260: checkcast = 0xC0 , +261: instanceof = 0xC1 , +262: monitorenter = 0xC2 , +263: monitorexit = 0xC3 , +264: wide = 0xC4 , +265: multianewarray = 0xC5 , +266: ifnull = 0xC6 , +267: ifnonnull = 0xC7 , +268: goto_w = 0xC8 , +269: jsr_w = 0xC9 , +270: breakpoint = 0xCA , +271: impdep1 = 0xFE , +272: impdep2 = 0xFF +273: } ; +274: +275: enum < u1 > enum_array_type +276: { +277: no_body = 0 , +278: index_body = 1 , +279: index_const_body = 2 , +280: sipush_body = 3 , +281: bipush_body = 4 , +282: newarray_body = 5 , +283: indexbyte_1_2_body = 6 , +284: branchbyte1_2_body = 7 , +285: branchbyte1_4_body = 8 , +286: invokeinterface_body = 9 , +287: invokedynamic_body = 10 , +288: multianewarray_body = 11 , +289: wide_body = 12 , +290: tableswitch_body = 13 , +291: lookupswitch_body = 14 , +292: index_v2_body = 15 +293: } ; +294: +295: +296: enum < u1 > enum_opcodes_body_type +297: { +298: T_BOOLEAN = 4 , +299: T_CHAR = 5 , +300: T_FLOAT = 6 , +301: T_DOUBLE = 7 , +302: T_BYTE = 8 , +303: T_SHORT = 9 , +304: T_INT = 10 , +305: T_LONG = 11 +306: } ; +307: +308: +309: const u4 address_constant_pool = 0xA ; +310: const u4 address_constant_pool_count = 0x8 ; +311: const u2 constant_pool_count = ReadUShort ( address_constant_pool_count ) - 1 ; +312: +313: local u8 map_address_constant_pool [ constant_pool_count ] < format = hex > ; +314: local u1 array_opcodes_body_type [ 256 ] ; +315: +316: +317: array_opcodes_body_type [ tableswitch ] = tableswitch_body ; +318: array_opcodes_body_type [ lookupswitch ] = lookupswitch_body ; +319: +320: +321: array_opcodes_body_type [ bipush ] = bipush_body ; +322: +323: array_opcodes_body_type [ iload ] = index_body ; +324: array_opcodes_body_type [ lload ] = index_body ; +325: array_opcodes_body_type [ fload ] = index_body ; +326: array_opcodes_body_type [ dload ] = index_body ; +327: array_opcodes_body_type [ aload ] = index_body ; +328: +329: array_opcodes_body_type [ istore ] = index_body ; +330: array_opcodes_body_type [ lstore ] = index_body ; +331: array_opcodes_body_type [ fstore ] = index_body ; +332: array_opcodes_body_type [ dstore ] = index_body ; +333: array_opcodes_body_type [ astore ] = index_body ; +334: +335: array_opcodes_body_type [ sipush ] = sipush_body ; +336: array_opcodes_body_type [ ldc ] = index_v2_body ; +337: array_opcodes_body_type [ ldc_w ] = indexbyte_1_2_body ; +338: array_opcodes_body_type [ ldc2_w ] = indexbyte_1_2_body ; +339: +340: array_opcodes_body_type [ iinc ] = index_const_body ; +341: +342: array_opcodes_body_type [ ifeq ] = branchbyte1_2_body ; +343: array_opcodes_body_type [ ifne ] = branchbyte1_2_body ; +344: array_opcodes_body_type [ iflt ] = branchbyte1_2_body ; +345: array_opcodes_body_type [ ifge ] = branchbyte1_2_body ; +346: array_opcodes_body_type [ ifgt ] = branchbyte1_2_body ; +347: array_opcodes_body_type [ ifle ] = branchbyte1_2_body ; +348: +349: array_opcodes_body_type [ if_icmpeq ] = branchbyte1_2_body ; +350: array_opcodes_body_type [ if_icmpne ] = branchbyte1_2_body ; +351: array_opcodes_body_type [ if_icmplt ] = branchbyte1_2_body ; +352: array_opcodes_body_type [ if_icmpge ] = branchbyte1_2_body ; +353: array_opcodes_body_type [ if_icmpgt ] = branchbyte1_2_body ; +354: array_opcodes_body_type [ if_icmple ] = branchbyte1_2_body ; +355: +356: array_opcodes_body_type [ if_acmpeq ] = branchbyte1_2_body ; +357: array_opcodes_body_type [ if_acmpne ] = branchbyte1_2_body ; +358: +359: array_opcodes_body_type [ goto ] = branchbyte1_2_body ; +360: array_opcodes_body_type [ jsr ] = branchbyte1_2_body ; +361: +362: array_opcodes_body_type [ ret ] = index_body ; +363: +364: array_opcodes_body_type [ getstatic ] = indexbyte_1_2_body ; +365: array_opcodes_body_type [ putstatic ] = indexbyte_1_2_body ; +366: +367: array_opcodes_body_type [ getfield ] = indexbyte_1_2_body ; +368: array_opcodes_body_type [ putfield ] = indexbyte_1_2_body ; +369: +370: array_opcodes_body_type [ new ] = indexbyte_1_2_body ; +371: array_opcodes_body_type [ newarray ] = newarray_body ; +372: +373: array_opcodes_body_type [ invokevirtual ] = indexbyte_1_2_body ; +374: array_opcodes_body_type [ invokespecial ] = indexbyte_1_2_body ; +375: array_opcodes_body_type [ invokestatic ] = indexbyte_1_2_body ; +376: +377: array_opcodes_body_type [ anewarray ] = indexbyte_1_2_body ; +378: array_opcodes_body_type [ checkcast ] = indexbyte_1_2_body ; +379: array_opcodes_body_type [ instanceof ] = indexbyte_1_2_body ; +380: +381: array_opcodes_body_type [ wide ] = wide_body ; +382: array_opcodes_body_type [ multianewarray ] = multianewarray_body ; +383: +384: array_opcodes_body_type [ ifnull ] = branchbyte1_2_body ; +385: array_opcodes_body_type [ ifnonnull ] = branchbyte1_2_body ; +386: +387: array_opcodes_body_type [ invokeinterface ] = invokeinterface_body ; +388: array_opcodes_body_type [ invokedynamic ] = invokedynamic_body ; +389: array_opcodes_body_type [ goto_w ] = branchbyte1_4_body ; +390: array_opcodes_body_type [ jsr_w ] = branchbyte1_4_body ; +391: +392: +393: +394: +395: +396: +397: +398: +399: +400: +401: +402: +403: +404: +405: +406: +407: +408: +409: +410: +411: +412: +413: +414: struct element_value ; +415: +416: typedef struct { +417: u2 type_index ; +418: u2 num_element_value_pairs ; +419: if ( 0 < num_element_value_pairs ) +420: { +421: +422: +423: struct { +424: u2 element_name_index < comment = Name_OnComment > ; +425: element_value value ; +426: } element_value_pairs [ num_element_value_pairs ] < optimize = false > ; +427: +428: +429: +430: } +431: } annotation < comment = annotation_OnComment > ; +432: +433: typedef struct { +434: u1 tag ; +435: if ( tag == 'e' ) +436: { +437: struct { +438: u2 type_name_index < comment = Name_OnComment > ; +439: u2 const_name_index < comment = Name_OnComment > ; +440: } enum_const_value < comment = "enum" > ; +441: } +442: else if ( tag == 'c' ) +443: { +444: u2 class_info_index ; +445: } +446: else if ( tag == '@' ) +447: { +448: annotation annotation_value ; +449: } +450: else if ( tag == '[' ) +451: { +452: struct { +453: u2 num_values ; +454: element_value values [ num_values ] < optimize = false > ; +455: } array_value < comment = "array" > ; +456: } +457: else +458: { +459: +460: u2 const_value_index < comment = Name_OnComment > ; +461: } +462: } element_value < comment = element_value_OnComment > ; +463: +464: typedef struct { +465: u1 tag ; +466: +467: +468: +469: +470: +471: +472: +473: if ( tag == 7 ) +474: { +475: +476: u2 cpool_index < comment = Name_OnComment > ; +477: } +478: else if ( tag == 8 ) +479: { +480: +481: u2 offset ; +482: } +483: } verification_type_info ; +484: +485: typedef struct { +486: u1 frame_type ; +487: if ( frame_type >= 64 && frame_type <= 127 ) +488: { +489: +490: verification_type_info stack [ 1 ] < optimize = false > ; +491: } +492: else if ( frame_type == 247 ) +493: { +494: +495: u2 offset_delta ; +496: verification_type_info stack [ 1 ] ; +497: } +498: else if ( frame_type >= 248 && frame_type <= 251 ) +499: { +500: +501: u2 offset_delta ; +502: } +503: else if ( frame_type >= 252 && frame_type <= 254 ) +504: { +505: +506: u2 offset_delta ; +507: verification_type_info locals [ frame_type - 251 ] < optimize = false > ; +508: } +509: else if ( frame_type == 255 ) +510: { +511: +512: u2 offset_delta ; +513: u2 number_of_locals ; +514: if ( 0 < number_of_locals ) verification_type_info locals [ number_of_locals ] < optimize = false > ; +515: u2 number_of_stack_items ; +516: if ( 0 < number_of_stack_items ) verification_type_info stack [ number_of_stack_items ] < optimize = false > ; +517: } +518: } stack_map_frame < comment = stack_map_frame_OnComment > ; +519: +520: typedef struct ( int hidden , u8 offsets ) { +521: +522: if ( exists ( hidden ) ) +523: { +524: u1 operation < format = hex > ; +525: switch ( array_opcodes_body_type [ operation ] ) +526: { +527: case index_body : +528: case index_v2_body : +529: u1 index ; +530: break ; +531: case index_const_body : +532: u1 index ; +533: i1 _const < name = "const" > ; +534: break ; +535: case sipush_body : +536: u2 _byte < name = "byte" > ; +537: break ; +538: case bipush_body : +539: u1 _byte < name = "byte" > ; +540: break ; +541: case newarray_body : +542: u1 atype ; +543: break ; +544: case multianewarray_body : +545: u2 indexbyte ; +546: u1 dimensions ; +547: break ; +548: case wide_body : +549: u1 operation2 ; +550: u2 indexbyte ; +551: if ( operation2 == iinc ) +552: { +553: u2 constbyte ; +554: } +555: break ; +556: case tableswitch_body : +557: local u4 len = 4 - ( offsets + 1 ) % 4 ; +558: if ( len < 4 ) u1 byte_pad [ len ] ; +559: i4 defaultbyte ; +560: i4 lowbyte ; +561: i4 highbyte ; +562: u4 jump [ highbyte - lowbyte + 1 ] < optimize = false > ; +563: break ; +564: case lookupswitch_body : +565: local u4 len = 4 - ( offsets + 1 ) % 4 ; +566: if ( len < 4 ) u1 byte_pad [ len ] ; +567: i4 defaultbyte ; +568: i4 npairs ; +569: struct +570: { +571: i4 match ; +572: i4 offset ; +573: } match_offset [ npairs ] ; +574: break ; +575: case indexbyte_1_2_body : +576: u2 indexbyte ; +577: break ; +578: case branchbyte1_2_body : +579: i2 branchbyte ; +580: break ; +581: case branchbyte1_4_body : +582: i4 branchbyte ; +583: break ; +584: case invokeinterface_body : +585: u2 indexbyte ; +586: u1 _count < name = "const" > ; +587: u1 zero ; +588: break ; +589: case invokedynamic_body : +590: u2 indexbyte ; +591: u1 zero ; +592: u1 zero ; +593: break ; +594: default : +595: break ; +596: } +597: } +598: } opcodes_operation < comment = opcodes_operation_OnComment > ; +599: +600: +601: struct attribute_info ; +602: +603: typedef struct { +604: u2 attribute_name_index ; +605: u4 attribute_length ; +606: +607: local string attribute_name = get_constant_pool_Utf8 ( attribute_name_index ) ; +608: +609: if ( attribute_name == "ConstantValue" ) +610: { +611: u2 constantvalue_index < comment = Name_OnComment > ; +612: } +613: else if ( attribute_name == "Code" ) +614: { +615: u2 max_stack ; +616: u2 max_locals ; +617: u4 code_length < format = hex > ; +618: +619: struct +620: { +621: local u8 begin_address = FTell ( ) ; +622: local u8 current_address = FTell ( ) ; +623: local u8 end_address = begin_address + code_length ; +624: local u4 i ; +625: local u8 Len ; +626: while ( FTell ( ) < end_address ) +627: { +628: opcodes_operation operation ( 0 , current_address - begin_address ) ; +629: Len = FTell ( ) - current_address - 1 ; +630: FSkip ( - Len ) ; +631: for ( i = 0 ; i < Len ; i ++ ) +632: { +633: opcodes_operation operation ( 1 , 0 ) < size = 1 , hidden = true > ; +634: } +635: current_address = FTell ( ) ; +636: } +637: } code ; +638: +639: u2 exception_table_length ; +640: if ( exception_table_length > 0 ) +641: { +642: struct +643: { +644: u2 start_pc ; +645: u2 end_pc ; +646: u2 handler_pc ; +647: u2 catch_type < comment = Name_Exception_OnComment > ; +648: } exception_table [ exception_table_length ] ; +649: } +650: u2 attributes_count ; +651: if ( attributes_count > 0 ) attribute_info attributes [ attributes_count ] < optimize = false > ; +652: } +653: else if ( attribute_name == "Exceptions" ) +654: { +655: u2 number_of_exceptions ; +656: u2 exception_index_table [ number_of_exceptions ] < comment = Name_Exception_OnComment , optimize = false > ; +657: } +658: else if ( attribute_name == "LineNumberTable" ) +659: { +660: u2 line_number_table_length ; +661: struct { +662: u2 start_pc ; +663: u2 line_number ; +664: } line_number_table [ line_number_table_length ] < optimize = false > ; +665: } +666: else if ( attribute_name == "LocalVariableTable" ) +667: { +668: u2 local_variable_table_length ; +669: struct LocalVariableTable_struct { +670: u2 start_pc ; +671: u2 length ; +672: u2 name_index < comment = Name_OnComment > ; +673: u2 descriptor_index < comment = Name_OnComment > ; +674: u2 index ; +675: } local_variable_table [ local_variable_table_length ] < comment = attribute_info_LocalVariableTable_OnComment , optimize = false > ; +676: } +677: else if ( attribute_name == "LocalVariableTypeTable" ) +678: { +679: u2 local_variable_type_table_length ; +680: struct { +681: u2 start_pc ; +682: u2 length ; +683: u2 name_index ; +684: u2 signature_index ; +685: u2 index ; +686: } local_variable_type_table [ local_variable_type_table_length ] < optimize = false > ; +687: } +688: else if ( attribute_name == "SourceFile" ) +689: { +690: u2 sourcefile_index < comment = Name_OnComment > ; +691: } +692: else if ( attribute_name == "InnerClasses" ) +693: { +694: u2 number_of_classes ; +695: struct InnerClasses_struct { +696: u2 inner_class_info_index < comment = Name_OnComment > ; +697: u2 outer_class_info_index < comment = Name_OnComment > ; +698: u2 inner_name_index < comment = Name_OnComment > ; +699: u2 inner_class_access_flags < comment = Nested_Class_access_flags_OnComment > ; +700: } classes [ number_of_classes ] < comment = attribute_info_InnerClasses_OnComment , optimize = false > ; +701: } +702: else if ( attribute_name == "EnclosingMethod" ) +703: { +704: u2 class_index < comment = Name_OnComment > ; +705: u2 method_index < comment = Name_OnComment > ; +706: } +707: else if ( attribute_name == "Signature" ) +708: { +709: u2 signature_index < comment = Name_OnComment > ; +710: } +711: else if ( attribute_name == "SourceDebugExtension" ) +712: { +713: u1 debug_extension [ attribute_length ] < optimize = false > ; +714: } +715: else if ( attribute_name == "RuntimeVisibleAnnotations" || attribute_name == "RuntimeInvisibleAnnotations" ) +716: { +717: u2 num_annotations ; +718: annotation annotations [ num_annotations ] < optimize = false > ; +719: } +720: else if ( attribute_name == "RuntimeVisibleParameterAnnotations" || attribute_name == "RuntimeInvisibleParameterAnnotations" ) +721: { +722: u1 num_parameters ; +723: struct { +724: u2 num_annotations ; +725: annotation annotations [ num_annotations ] < optimize = false > ; +726: } parameter_annotations [ num_parameters ] < optimize = false > ; +727: } +728: else if ( attribute_name == "AnnotationDefault" ) +729: { +730: element_value default_value ; +731: } +732: else if ( attribute_name == "BootstrapMethods" ) +733: { +734: u2 num_bootstrap_methods ; +735: struct { +736: u2 bootstrap_method_ref ; +737: u2 num_bootstrap_arguments ; +738: u2 bootstrap_arguments [ num_bootstrap_arguments ] < optimize = false > ; +739: } bootstrap_methods [ num_bootstrap_methods ] < optimize = false > ; +740: } +741: else if ( attribute_name == "StackMapTable" ) +742: { +743: u2 number_of_entries ; +744: stack_map_frame entries [ number_of_entries ] < optimize = false > ; +745: } +746: else +747: { +748: if ( attribute_length > 0 ) u1 info [ attribute_length ] < optimize = false > ; +749: } +750: } attribute_info < comment = attribute_info_OnComment > ; +751: +752: typedef struct +753: { +754: u2 access_flags < comment = Field_access_flags_OnComment > ; +755: u2 name_index ; +756: u2 descriptor_index ; +757: u2 attributes_count ; +758: if ( 0 < attributes_count ) +759: { +760: attribute_info attributes [ attributes_count ] < optimize = false > ; +761: } +762: } field_info < comment = field_info_OnComment > ; +763: +764: typedef struct { +765: u2 access_flags < comment = Method_access_flags_OnComment > ; +766: u2 name_index ; +767: u2 descriptor_index ; +768: u2 attributes_count ; +769: if ( 0 < attributes_count ) +770: { +771: attribute_info attributes [ attributes_count ] < optimize = false > ; +772: } +773: } method_info < comment = method_info_OnComment > ; +774: +775: +776: +777: +778: typedef struct { +779: if ( sizeof ( this ) > 1 ) +780: { +781: u1 tag ; +782: switch ( tag ) +783: { +784: case CONSTANT_Class : +785: u2 name_index ; +786: break ; +787: case CONSTANT_Fieldref : +788: case CONSTANT_Methodref : +789: case CONSTANT_InterfaceMethodref : +790: u2 class_index ; +791: u2 name_and_type_index ; +792: break ; +793: case CONSTANT_String : +794: u2 string_index ; +795: break ; +796: case CONSTANT_Integer : +797: case CONSTANT_Float : +798: u4 bytes ; +799: break ; +800: case CONSTANT_Long : +801: case CONSTANT_Double : +802: u4 high_bytes < format = hex > ; +803: u4 low_bytes < format = hex > ; +804: break ; +805: case CONSTANT_NameAndType : +806: u2 name_index ; +807: u2 descriptor_index ; +808: break ; +809: case CONSTANT_Utf8 : +810: u2 length ; +811: if ( length > 0 ) +812: { +813: u1 bytes [ length ] < optimize = false > ; +814: } +815: break ; +816: case CONSTANT_MethodHandle : +817: u1 reference_kind ; +818: u2 reference_index ; +819: break ; +820: case CONSTANT_MethodType : +821: u2 descriptor_index ; +822: break ; +823: case CONSTANT_InvokeDynamic : +824: u2 bootstrap_method_attr_index ; +825: u2 name_and_type_index ; +826: break ; +827: default : +828: Warning ( "fix cp_info" ) ; +829: break ; +830: } +831: } +832: } cp_info < comment = cp_infoOnComment , size = cp_infoOnSize > ; +833: +834: +835: typedef struct +836: { +837: u4 magic < format = hex > ; +838: u2 minor_version ; +839: u2 major_version ; +840: u2 constant_pool_count ; +841: cp_info constant_pool [ constant_pool_count - 1 ] < optimize = false > ; +842: u2 access_flags < comment = Class_access_flags_OnComment > ; +843: u2 this_class < comment = Name_OnComment > ; +844: u2 super_class < comment = Name_OnComment > ; +845: +846: u2 interfaces_count ; +847: if ( 0 < interfaces_count ) +848: { +849: u2 interfaces [ interfaces_count ] < comment = ClassFile_interfaces_OnComment , optimize = false > ; +850: } +851: +852: u2 fields_count ; +853: if ( 0 < fields_count ) +854: { +855: field_info fields [ fields_count ] < optimize = false > ; +856: } +857: +858: u2 methods_count ; +859: if ( 0 < methods_count ) +860: { +861: method_info methods [ methods_count ] < optimize = false > ; +862: } +863: +864: u2 attributes_count ; +865: if ( 0 < attributes_count ) +866: { +867: attribute_info attributes [ attributes_count ] < optimize = false > ; +868: } +869: +870: } ClassFile < comment = ClassFileOnComment > ; +871: +872: +873: +874: +875: void generator_map_address_constant_pool ( ) +876: { +877: local u8 address = address_constant_pool ; +878: local u1 tag ; +879: +880: +881: local int i ; +882: for ( i = 0 ; i < constant_pool_count ; i ++ ) +883: { +884: map_address_constant_pool [ i ] = address ; +885: +886: tag = ReadUByte ( address ) ; +887: +888: switch ( tag ) +889: { +890: case CONSTANT_Class : +891: case CONSTANT_String : +892: case CONSTANT_MethodType : +893: address = address + 3 ; +894: break ; +895: case CONSTANT_Fieldref : +896: case CONSTANT_Methodref : +897: case CONSTANT_InterfaceMethodref : +898: case CONSTANT_NameAndType : +899: case CONSTANT_InvokeDynamic : +900: case CONSTANT_Integer : +901: case CONSTANT_Float : +902: address = address + 5 ; +903: break ; +904: case CONSTANT_Long : +905: case CONSTANT_Double : +906: i ++ ; +907: map_address_constant_pool [ i ] = 0 ; +908: address = address + 9 ; +909: break ; +910: case CONSTANT_Utf8 : +911: address = address + 3 + ReadUShort ( address + 1 ) ; +912: break ; +913: case CONSTANT_MethodHandle : +914: address = address + 4 ; +915: break ; +916: default : +917: Warning ( "fix generator_map_address_constant_pool" ) ; +918: break ; +919: } +920: } +921: } +922: +923: u8 find_constant_pool2 ( u2 n ) +924: { +925: return map_address_constant_pool [ n - 1 ] ; +926: } +927: +928: string get_constant_pool_Utf8 ( u2 n ) +929: { +930: if ( n <= 0 ) return "NO NAME" ; +931: +932: local u8 address = find_constant_pool2 ( n ) ; +933: local u8 address2 = 0 ; +934: local u8 address3 = 0 ; +935: local string str = "" ; +936: switch ( ReadUByte ( address ) ) +937: { +938: case CONSTANT_Class : +939: case CONSTANT_String : +940: case CONSTANT_InvokeDynamic : +941: address = find_constant_pool2 ( ReadUShort ( address + 1 ) ) ; +942: break ; +943: case CONSTANT_NameAndType : +944: address2 = address ; +945: address = find_constant_pool2 ( ReadUShort ( address + 1 ) ) ; +946: address2 = find_constant_pool2 ( ReadUShort ( address2 + 3 ) ) ; +947: break ; +948: case CONSTANT_Fieldref : +949: case CONSTANT_Methodref : +950: case CONSTANT_InterfaceMethodref : +951: address2 = address ; +952: address = find_constant_pool2 ( ReadUShort ( address + 1 ) ) ; +953: address = find_constant_pool2 ( ReadUShort ( address + 1 ) ) ; +954: address2 = find_constant_pool2 ( ReadUShort ( address2 + 3 ) ) ; +955: address3 = address2 ; +956: address2 = find_constant_pool2 ( ReadUShort ( address3 + 1 ) ) ; +957: address3 = find_constant_pool2 ( ReadUShort ( address3 + 3 ) ) ; +958: break ; +959: case CONSTANT_Integer : +960: SPrintf ( str , "%d" , ReadUInt ( address + 1 ) ) ; +961: break ; +962: case CONSTANT_Long : +963: SPrintf ( str , "%Ld" , ReadInt64 ( address + 1 ) ) ; +964: break ; +965: case CONSTANT_Float : +966: SPrintf ( str , "%f" , ReadFloat ( address + 1 ) ) ; +967: break ; +968: case CONSTANT_Double : +969: SPrintf ( str , "%Lf" , ReadDouble ( address + 1 ) ) ; +970: break ; +971: case CONSTANT_Utf8 : +972: break ; +973: default : +974: Warning ( "fix get_constant_pool_Utf8" ) ; +975: return "NULL" ; +976: break ; +977: } +978: +979: if ( 0 < Strlen ( str ) ) return str ; +980: if ( address2 == 0 ) return ReadUShort ( address + 1 ) == 0 ? " " : ReadString ( address + 3 , ReadUShort ( address + 1 ) ) ; +981: if ( address3 == 0 ) return ReadString ( address + 3 , ReadUShort ( address + 1 ) ) + ReadString ( address2 + 3 , ReadUShort ( address2 + 1 ) ) ; +982: +983: return ReadString ( address + 3 , ReadUShort ( address + 1 ) ) + "." + ReadString ( address2 + 3 , ReadUShort ( address2 + 1 ) ) + ReadString ( address3 + 3 , ReadUShort ( address3 + 1 ) ) ; +984: +985: } +986: +987: string Access_flags ( u2 access_flags , enum_type type ) +988: { +989: string access_flags_text ; +990: +991: if ( ( access_flags & ACC_PUBLIC ) == ACC_PUBLIC ) +992: { +993: access_flags_text = access_flags_text + "public" ; +994: } +995: +996: if ( type == Field || type == Method || type == Nested_Class ) +997: { +998: +999: if ( ( access_flags & ACC_PRIVATE ) == ACC_PRIVATE ) +1000: { +1001: access_flags_text = access_flags_text + "private" ; +1002: } +1003: +1004: if ( ( access_flags & ACC_PROTECTED ) == ACC_PROTECTED ) +1005: { +1006: access_flags_text = access_flags_text + "protected" ; +1007: } +1008: +1009: if ( ( access_flags & ACC_STATIC ) == ACC_STATIC ) +1010: { +1011: access_flags_text = access_flags_text + " static" ; +1012: } +1013: +1014: } +1015: +1016: if ( ( access_flags & ACC_FINAL ) == ACC_FINAL ) +1017: { +1018: access_flags_text = access_flags_text + " final" ; +1019: } +1020: +1021: if ( type == Class ) +1022: { +1023: if ( ( access_flags & ACC_SUPER_ACC_SYNCHRONIZED ) == ACC_SUPER_ACC_SYNCHRONIZED ) +1024: { +1025: access_flags_text = access_flags_text + " superclass" ; +1026: } +1027: } +1028: +1029: if ( type == Method ) +1030: { +1031: +1032: if ( ( access_flags & ACC_SUPER_ACC_SYNCHRONIZED ) == ACC_SUPER_ACC_SYNCHRONIZED ) +1033: { +1034: access_flags_text = access_flags_text + " synchronized" ; +1035: } +1036: +1037: if ( ( access_flags & ACC_BRIDGE_ACC_VOLATILE ) == ACC_BRIDGE_ACC_VOLATILE ) +1038: { +1039: access_flags_text = access_flags_text + " bridge" ; +1040: } +1041: +1042: if ( ( access_flags & ACC_VARARGS_ACC_TRANSIENT ) == ACC_VARARGS_ACC_TRANSIENT ) +1043: { +1044: access_flags_text = access_flags_text + " varargs" ; +1045: } +1046: +1047: if ( ( access_flags & ACC_NATIVE ) == ACC_NATIVE ) +1048: { +1049: access_flags_text = access_flags_text + " native" ; +1050: } +1051: +1052: if ( ( access_flags & ACC_STRICT ) == ACC_STRICT ) +1053: { +1054: access_flags_text = access_flags_text + " strictfp" ; +1055: } +1056: +1057: } +1058: +1059: if ( type == Field ) +1060: { +1061: if ( ( access_flags & ACC_BRIDGE_ACC_VOLATILE ) == ACC_BRIDGE_ACC_VOLATILE ) +1062: { +1063: access_flags_text = access_flags_text + " volatile" ; +1064: } +1065: +1066: if ( ( access_flags & ACC_VARARGS_ACC_TRANSIENT ) == ACC_VARARGS_ACC_TRANSIENT ) +1067: { +1068: access_flags_text = access_flags_text + " transient" ; +1069: } +1070: +1071: } +1072: +1073: if ( type == Class || type == Nested_Class ) +1074: { +1075: +1076: if ( ( access_flags & ACC_INTERFACE ) == ACC_INTERFACE ) +1077: { +1078: access_flags_text = access_flags_text + " interface" ; +1079: } +1080: +1081: if ( ( access_flags & ACC_ANNOTATION ) == ACC_ANNOTATION ) +1082: { +1083: access_flags_text = access_flags_text + " annotation" ; +1084: } +1085: +1086: } +1087: +1088: if ( type == Class || type == Method || type == Nested_Class ) +1089: { +1090: if ( ( access_flags & ACC_ABSTRACT ) == ACC_ABSTRACT ) +1091: { +1092: access_flags_text = access_flags_text + " abstract" ; +1093: } +1094: } +1095: +1096: +1097: if ( ( access_flags & ACC_SYNTHETIC ) == ACC_SYNTHETIC ) +1098: { +1099: access_flags_text = access_flags_text + " synthetic" ; +1100: } +1101: +1102: if ( type == Class || type == Field || type == Nested_Class ) +1103: { +1104: if ( ( access_flags & ACC_ENUM ) == ACC_ENUM ) +1105: { +1106: access_flags_text = access_flags_text + " enum" ; +1107: } +1108: } +1109: return access_flags_text ; +1110: } +1111: +1112: +1113: +1114: string ClassFileOnComment ( ClassFile & obj ) +1115: { +1116: switch ( obj . major_version ) +1117: { +1118: case 45 : +1119: return "JDK 1.0 or JDK 1.1" ; +1120: break ; +1121: case 46 : +1122: return "JDK 1.2" ; +1123: break ; +1124: case 47 : +1125: return "JDK 1.3" ; +1126: break ; +1127: case 48 : +1128: return "JDK 1.4" ; +1129: break ; +1130: case 49 : +1131: return "JDK 1.5" ; +1132: break ; +1133: case 50 : +1134: return "JDK 1.6" ; +1135: break ; +1136: case 51 : +1137: return "JDK 1.7" ; +1138: break ; +1139: default : +1140: return "JDK ?.?" ; +1141: break ; +1142: } +1143: } +1144: +1145: local u1 flag_CONSTANT_Long_CONSTANT_Double = 0 ; +1146: +1147: u4 cp_infoOnSize ( cp_info & obj ) +1148: { +1149: switch ( ReadUByte ( FTell ( ) ) ) +1150: { +1151: case CONSTANT_Class : +1152: case CONSTANT_String : +1153: case CONSTANT_MethodType : +1154: return 3 ; +1155: break ; +1156: case CONSTANT_Fieldref : +1157: case CONSTANT_Methodref : +1158: case CONSTANT_InterfaceMethodref : +1159: case CONSTANT_NameAndType : +1160: case CONSTANT_InvokeDynamic : +1161: case CONSTANT_Integer : +1162: case CONSTANT_Float : +1163: return 5 ; +1164: break ; +1165: case CONSTANT_Long : +1166: case CONSTANT_Double : +1167: { +1168: if ( flag_CONSTANT_Long_CONSTANT_Double == 0 ) +1169: { +1170: FSkip ( - 9 ) ; +1171: flag_CONSTANT_Long_CONSTANT_Double = 1 ; +1172: return 9 ; +1173: +1174: } +1175: else +1176: { +1177: flag_CONSTANT_Long_CONSTANT_Double = 0 ; +1178: FSkip ( 8 ) ; +1179: return 1 ; +1180: } +1181: break ; +1182: } +1183: case CONSTANT_Utf8 : +1184: return 3 + ReadUShort ( FTell ( ) + 1 ) ; +1185: break ; +1186: case CONSTANT_MethodHandle : +1187: return 4 ; +1188: break ; +1189: default : +1190: Warning ( "fix cp_infoOnSize" ) ; +1191: return 0 ; +1192: break ; +1193: } +1194: } +1195: +1196: string cp_infoOnComment ( cp_info & obj ) +1197: { +1198: +1199: switch ( ReadUByte ( startof ( obj ) ) ) +1200: { +1201: case CONSTANT_Class : +1202: return "CONSTANT_Class_info" ; +1203: break ; +1204: case CONSTANT_Fieldref : +1205: return "CONSTANT_Fieldref" ; +1206: break ; +1207: case CONSTANT_Methodref : +1208: return "CONSTANT_Methodref" ; +1209: break ; +1210: case CONSTANT_InterfaceMethodref : +1211: return "CONSTANT_InterfaceMethodref" ; +1212: break ; +1213: case CONSTANT_String : +1214: return "CONSTANT_String" ; +1215: break ; +1216: case CONSTANT_Integer : +1217: return "CONSTANT_Integer" ; +1218: break ; +1219: case CONSTANT_Float : +1220: return "CONSTANT_Float" ; +1221: break ; +1222: case CONSTANT_Long : +1223: if ( sizeof ( obj ) == 1 ) return "CONSTANT_Long continued" ; +1224: return "CONSTANT_Long" ; +1225: break ; +1226: case CONSTANT_Double : +1227: if ( sizeof ( obj ) == 1 ) return "CONSTANT_Double continued" ; +1228: return "CONSTANT_Double" ; +1229: break ; +1230: case CONSTANT_NameAndType : +1231: return "CONSTANT_NameAndType" ; +1232: break ; +1233: case CONSTANT_Utf8 : +1234: return "CONSTANT_Utf8" ; +1235: break ; +1236: case CONSTANT_MethodHandle : +1237: return "CONSTANT_MethodHandle" ; +1238: break ; +1239: case CONSTANT_MethodType : +1240: return "CONSTANT_MethodType" ; +1241: break ; +1242: case CONSTANT_InvokeDynamic : +1243: return "CONSTANT_InvokeDynamic" ; +1244: break ; +1245: default : +1246: Warning ( "fix cp_infoOnCommen" ) ; +1247: return "fix cp_infoOnCommen" ; +1248: break ; +1249: } +1250: } +1251: +1252: string ClassFile_interfaces_OnComment ( u2 interfaces ) +1253: { +1254: return get_constant_pool_Utf8 ( interfaces ) ; +1255: } +1256: +1257: string Class_access_flags_OnComment ( u2 access_flags ) +1258: { +1259: return Access_flags ( access_flags , Class ) ; +1260: } +1261: +1262: string Field_access_flags_OnComment ( u2 access_flags ) +1263: { +1264: return Access_flags ( access_flags , Field ) ; +1265: } +1266: +1267: string Method_access_flags_OnComment ( u2 access_flags ) +1268: { +1269: return Access_flags ( access_flags , Method ) ; +1270: } +1271: +1272: string Nested_Class_access_flags_OnComment ( u2 access_flags ) +1273: { +1274: return Access_flags ( access_flags , Nested_Class ) ; +1275: } +1276: +1277: string method_info_OnComment ( method_info & obj ) +1278: { +1279: return get_constant_pool_Utf8 ( obj . name_index ) + get_constant_pool_Utf8 ( obj . descriptor_index ) ; +1280: } +1281: +1282: string field_info_OnComment ( field_info & obj ) +1283: { +1284: return get_constant_pool_Utf8 ( obj . descriptor_index ) + " " + get_constant_pool_Utf8 ( obj . name_index ) ; +1285: } +1286: +1287: string attribute_info_OnComment ( attribute_info & obj ) +1288: { +1289: return get_constant_pool_Utf8 ( obj . attribute_name_index ) ; +1290: } +1291: +1292: string attribute_info_InnerClasses_OnComment ( InnerClasses_struct & obj ) +1293: { +1294: return get_constant_pool_Utf8 ( obj . inner_name_index ) ; +1295: } +1296: +1297: string attribute_info_LocalVariableTable_OnComment ( LocalVariableTable_struct & obj ) +1298: { +1299: return get_constant_pool_Utf8 ( obj . name_index ) ; +1300: } +1301: +1302: +1303: +1304: string stack_map_frame_OnComment ( stack_map_frame & obj ) +1305: { +1306: if ( obj . frame_type >= 0 && obj . frame_type <= 63 ) +1307: { +1308: return "same_frame" ; +1309: } +1310: else if ( obj . frame_type >= 64 && obj . frame_type <= 127 ) +1311: { +1312: return "same_locals_1_stack_item_frame" ; +1313: } +1314: else if ( obj . frame_type == 247 ) +1315: { +1316: return "same_locals_1_stack_item_frame_extended" ; +1317: } +1318: else if ( obj . frame_type >= 248 && obj . frame_type <= 251 ) +1319: { +1320: return "chop_frame or same_frame_extended" ; +1321: } +1322: else if ( obj . frame_type >= 252 && obj . frame_type <= 254 ) +1323: { +1324: return "append_frame" ; +1325: } +1326: else if ( obj . frame_type == 255 ) +1327: { +1328: return "full_frame" ; +1329: } +1330: } +1331: +1332: +1333: string annotation_OnComment ( annotation & obj ) +1334: { +1335: return get_constant_pool_Utf8 ( obj . type_index ) ; +1336: } +1337: +1338: string Name_OnComment ( u2 n ) +1339: { +1340: return get_constant_pool_Utf8 ( n ) ; +1341: } +1342: +1343: string Name_Exception_OnComment ( u2 n ) +1344: { +1345: if ( n == 0 ) return "any" ; +1346: return get_constant_pool_Utf8 ( n ) ; +1347: } +1348: +1349: string element_value_OnComment ( element_value & obj ) +1350: { +1351: switch ( obj . tag ) +1352: { +1353: case 's' : +1354: return "String" ; +1355: break ; +1356: case 'e' : +1357: return "enum" ; +1358: break ; +1359: case 'c' : +1360: return "class" ; +1361: break ; +1362: case '@' : +1363: return "annotation type" ; +1364: break ; +1365: case '[' : +1366: return "array" ; +1367: break ; +1368: default : +1369: return "" ; +1370: break ; +1371: } +1372: } +1373: +1374: +1375: string opcodes_operation_OnComment ( opcodes_operation & obj ) +1376: { +1377: if ( ! exists ( obj . operation ) ) return "" ; +1378: +1379: string str ; +1380: string str2 ; +1381: enum_opcodes obj_operation = obj . operation ; +1382: +1383: switch ( array_opcodes_body_type [ obj . operation ] ) +1384: { +1385: case index_body : +1386: SPrintf ( str , " %d" , obj . index ) ; +1387: break ; +1388: case index_v2_body : +1389: str = " " + get_constant_pool_Utf8 ( obj . index ) ; +1390: break ; +1391: case index_const_body : +1392: SPrintf ( str , " %d" , obj . index ) ; +1393: SPrintf ( str2 , " %d" , obj . _const ) ; +1394: str = str + " by" + str2 ; +1395: break ; +1396: case sipush_body : +1397: SPrintf ( str , " %d" , obj . _byte ) ; +1398: break ; +1399: case bipush_body : +1400: SPrintf ( str , " %d" , obj . _byte ) ; +1401: break ; +1402: case newarray_body : +1403: switch ( obj . atype ) +1404: { +1405: case T_BOOLEAN : +1406: str = " boolean" ; +1407: break ; +1408: case T_CHAR : +1409: str = " char" ; +1410: break ; +1411: case T_FLOAT : +1412: str = " float" ; +1413: break ; +1414: case T_DOUBLE : +1415: str = " double" ; +1416: break ; +1417: case T_BYTE : +1418: str = " byte" ; +1419: break ; +1420: case T_SHORT : +1421: str = " short" ; +1422: break ; +1423: case T_INT : +1424: str = " int" ; +1425: break ; +1426: case T_LONG : +1427: str = " long" ; +1428: break ; +1429: default : +1430: Warning ( "fix opcodes_operation_OnComment" ) ; +1431: break ; +1432: } +1433: break ; +1434: case multianewarray_body : +1435: SPrintf ( str , "%d" , obj . dimensions ) ; +1436: str = " " + get_constant_pool_Utf8 ( obj . indexbyte ) + " dimensions " + str ; +1437: break ; +1438: case wide_body : +1439: enum_opcodes obj_operation2 = obj . operation2 ; +1440: str = " " + EnumToString ( obj_operation2 ) + get_constant_pool_Utf8 ( obj . indexbyte ) ; +1441: if ( obj_operation2 == iinc ) +1442: { +1443: SPrintf ( str2 , "%d" , obj . constbyte ) ; +1444: str = str + " by " + str2 ; +1445: } +1446: break ; +1447: case tableswitch_body : +1448: SPrintf ( str , "%d" , obj . lowbyte ) ; +1449: SPrintf ( str2 , "%d" , obj . highbyte ) ; +1450: str = " " + str + " to " + str2 ; +1451: break ; +1452: case lookupswitch_body : +1453: SPrintf ( str , "%d" , obj . npairs ) ; +1454: str = " " + str ; +1455: break ; +1456: case invokedynamic_body : +1457: case indexbyte_1_2_body : +1458: str = " " + get_constant_pool_Utf8 ( obj . indexbyte ) ; +1459: break ; +1460: case branchbyte1_2_body : +1461: case branchbyte1_4_body : +1462: SPrintf ( str , " %d" , obj . branchbyte ) ; +1463: break ; +1464: case invokeinterface_body : +1465: SPrintf ( str , " %d" , obj . _count ) ; +1466: str = " " + get_constant_pool_Utf8 ( obj . indexbyte ) + " count " + str ; +1467: break ; +1468: default : +1469: break ; +1470: } +1471: +1472: return EnumToString ( obj_operation ) + str ; +1473: } +1474: +1475: generator_map_address_constant_pool ( ) ; +1476: +1477: ClassFile classFile ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/CRXTemplate.bt b/cparser/tests/exp_lex/CRXTemplate.bt new file mode 100644 index 0000000..b992716 --- /dev/null +++ b/cparser/tests/exp_lex/CRXTemplate.bt @@ -0,0 +1,209 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: typedef enum < short > { +16: COMP_STORED = 0 , +17: COMP_SHRUNK = 1 , +18: COMP_REDUCED1 = 2 , +19: COMP_REDUCED2 = 3 , +20: COMP_REDUCED3 = 4 , +21: COMP_REDUCED4 = 5 , +22: COMP_IMPLODED = 6 , +23: COMP_TOKEN = 7 , +24: COMP_DEFLATE = 8 , +25: COMP_DEFLATE64 = 9 +26: } COMPTYPE ; +27: +28: +29: typedef struct { +30: +31: char frSignature [ 4 ] ; +32: ushort frVersion ; +33: ushort frFlags ; +34: COMPTYPE frCompression ; +35: DOSTIME frFileTime ; +36: DOSDATE frFileDate ; +37: uint frCrc < format = hex > ; +38: uint frCompressedSize ; +39: uint frUncompressedSize ; +40: ushort frFileNameLength ; +41: ushort frExtraFieldLength ; +42: if ( frFileNameLength > 0 ) +43: char frFileName [ frFileNameLength ] ; +44: if ( frExtraFieldLength > 0 ) +45: uchar frExtraField [ frExtraFieldLength ] ; +46: +47: +48: SetBackColor ( cNone ) ; +49: if ( frCompressedSize > 0 ) +50: uchar frData [ frCompressedSize ] ; +51: +52: } ZIPFILERECORD < read = ReadZIPFILERECORD , write = WriteZIPFILERECORD > ; +53: +54: +55: typedef struct { +56: char deSignature [ 4 ] ; +57: ushort deVersionMadeBy ; +58: ushort deVersionToExtract ; +59: ushort deFlags ; +60: COMPTYPE deCompression ; +61: DOSTIME deFileTime ; +62: DOSDATE deFileDate ; +63: uint deCrc < format = hex > ; +64: uint deCompressedSize ; +65: uint deUncompressedSize ; +66: ushort deFileNameLength ; +67: ushort deExtraFieldLength ; +68: ushort deFileCommentLength ; +69: ushort deDiskNumberStart ; +70: ushort deInternalAttributes ; +71: uint deExternalAttributes ; +72: uint deHeaderOffset ; +73: if ( deFileNameLength > 0 ) +74: char deFileName [ deFileNameLength ] ; +75: if ( deExtraFieldLength > 0 ) +76: uchar deExtraField [ deExtraFieldLength ] ; +77: if ( deFileCommentLength > 0 ) +78: uchar deFileComment [ deFileCommentLength ] ; +79: } ZIPDIRENTRY < read = ReadZIPDIRENTRY > ; +80: +81: +82: typedef struct { +83: char dsSignature [ 4 ] ; +84: ushort dsDataLength ; +85: if ( dsDataLength > 0 ) +86: uchar dsData [ dsDataLength ] ; +87: } ZIPDIGITALSIG ; +88: +89: +90: typedef struct { +91: char ddSignature [ 4 ] ; +92: uint ddCRC < format = hex > ; +93: uint ddCompressedSize ; +94: uint ddUncompressedSize ; +95: } ZIPDATADESCR ; +96: +97: +98: typedef struct { +99: char elSignature [ 4 ] ; +100: ushort elDiskNumber ; +101: ushort elStartDiskNumber ; +102: ushort elEntriesOnDisk ; +103: ushort elEntriesInDirectory ; +104: uint elDirectorySize ; +105: uint elDirectoryOffset ; +106: ushort elCommentLength ; +107: if ( elCommentLength > 0 ) +108: char elComment [ elCommentLength ] ; +109: } ZIPENDLOCATOR ; +110: +111: +112: +113: +114: +115: +116: string ReadZIPFILERECORD ( ZIPFILERECORD & file ) +117: { +118: if ( exists ( file . frFileName ) ) +119: return file . frFileName ; +120: else +121: return "" ; +122: } +123: +124: string ReadZIPDIRENTRY ( ZIPDIRENTRY & entry ) +125: { +126: if ( exists ( entry . deFileName ) ) +127: return entry . deFileName ; +128: else +129: return "" ; +130: } +131: +132: +133: +134: +135: +136: void WriteZIPFILERECORD ( ZIPFILERECORD & file , string s ) +137: { +138: local int len = Strlen ( s ) ; +139: if ( exists ( file . frFileName ) ) +140: { +141: Strncpy ( file . frFileName , s , file . frFileNameLength ) ; +142: if ( len < file . frFileNameLength ) +143: file . frFileName [ len ] = 0 ; +144: } +145: } +146: +147: typedef struct { +148: SetBackColor ( 0xD8E5ED ) ; +149: char magicNumber [ 4 ] ; +150: SetBackColor ( 0xD8EDD8 ) ; +151: uint32 version ; +152: SetBackColor ( 0xD8E5ED ) ; +153: uint32 pkLength ; +154: SetBackColor ( 0xD8EDD8 ) ; +155: uint32 sigLength ; +156: SetBackColor ( 0xF7D6C3 ) ; +157: byte pubKey [ pkLength ] ; +158: SetBackColor ( 0xD8EDD8 ) ; +159: byte sig [ sigLength ] ; +160: } CRXHEADER ; +161: +162: +163: +164: +165: SetBackColor ( 0xE8E8E8 ) ; +166: CRXHEADER crxHeader ; +167: SetBackColor ( cNone ) ; +168: local uint tag ; +169: LittleEndian ( ) ; +170: while ( ! FEof ( ) ) +171: { +172: +173: tag = ReadUInt ( FTell ( ) ) ; +174: +175: +176: +177: +178: +179: if ( tag == 0x4034B50 ) +180: { +181: SetBackColor ( cLtGray ) ; +182: ZIPFILERECORD record ; +183: } +184: else if ( tag == 0x8074B50 ) +185: { +186: SetBackColor ( cLtGreen ) ; +187: ZIPDATADESCR dataDescr ; +188: } +189: else if ( tag == 0x2014B50 ) +190: { +191: SetBackColor ( cLtPurple ) ; +192: ZIPDIRENTRY dirEntry ; +193: } +194: else if ( tag == 0x5054B50 ) +195: { +196: SetBackColor ( cLtBlue ) ; +197: ZIPDIGITALSIG digitalSig ; +198: } +199: else if ( tag == 0x6054B50 ) +200: { +201: SetBackColor ( cLtYellow ) ; +202: ZIPENDLOCATOR endLocator ; +203: } +204: else +205: { +206: Warning ( "Unknown ZIP tag encountered. Template stopped." ) ; +207: return - 1 ; +208: } +209: } tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/DBFTemplate.bt b/cparser/tests/exp_lex/DBFTemplate.bt new file mode 100644 index 0000000..1e15251 --- /dev/null +++ b/cparser/tests/exp_lex/DBFTemplate.bt @@ -0,0 +1,59 @@ +1: +2: +3: +4: +5: +6: +7: +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 < read = yearFrom1900 , format = decimal > ; +22: char mm < format = decimal > ; +23: char dd < format = decimal > ; +24: } DateOfLastUpdate ; +25: int numberOfRecords ; +26: short lengthOfHeaderStructure ; +27: short lengthOfEachRecord ; +28: char reserved [ 2 ] ; +29: char incompleteTrasaction < format = decimal > ; +30: char encryptionFlag < format = decimal > ; +31: int freeRecordThread ; +32: int reserved1 [ 2 ] ; +33: char mdxFlag < format = decimal > ; +34: char languageDriver < format = decimal > ; +35: short reserved2 ; +36: } header ; +37: struct FIELD { +38: char fieldName [ 11 ] ; +39: char fieldType ; +40: int fieldDataAddress ; +41: char fieldLength < format = decimal > ; +42: char decimalCount < format = decimal > ; +43: short reserved ; +44: char workAreaId < format = decimal > ; +45: short reserved1 ; +46: char flags < format = hex > ; +47: char reserved2 [ 7 ] ; +48: char indexFieldFlag < format = decimal > ; +49: } field [ ( header . lengthOfHeaderStructure - 33 ) / sizeof ( struct FIELD ) ] ; +50: char Terminator < format = hex > ; +51: struct RECORD { +52: char deletedFlag ; +53: char fields [ header . lengthOfEachRecord - 1 ] ; +54: } record [ header . numberOfRecords ] < optimize = false > ; +55: } dbf < optimize = false > ; +56: +57: +58: +59: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/DMPTemplate.bt b/cparser/tests/exp_lex/DMPTemplate.bt new file mode 100644 index 0000000..e39bf8f --- /dev/null +++ b/cparser/tests/exp_lex/DMPTemplate.bt @@ -0,0 +1,83 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: typedef enum < uint32 > { +18: FULL = 1 , +19: KERNEL , +20: SMALL +21: } e_DumpType ; +22: +23: +24: typedef struct { +25: uint32 BasePage < format = hex > ; +26: uint32 PageCount < format = hex > ; +27: } _PHYSICAL_MEMORY_RUN32 ; +28: +29: +30: typedef struct { +31: uint32 NumberOfRuns ; +32: uint32 NumberOfPages < format = hex > ; +33: _PHYSICAL_MEMORY_RUN32 Run [ NumberOfRuns ] ; +34: } _PHYSICAL_MEMORY_DESCRIPTOR32 ; +35: +36: +37: typedef struct { +38: int32 ExceptionCode < format = hex > ; +39: uint32 ExceptionFlags ; +40: uint32 ExceptionRecord ; +41: uint32 ExceptionAddress < format = hex > ; +42: uint32 NumberParameters ; +43: uint32 ExceptionInformation [ 15 ] < format = hex > ; +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 < format = hex > ; +54: uint32 PfnDataBase < format = hex > ; +55: uint32 PsLoadedModuleList < format = hex > ; +56: uint32 PsActiveProcessHead < format = hex > ; +57: uint32 MachineImageType < format = hex > ; +58: uint32 NumberProcessors ; +59: uint32 BugCheckCode < format = hex > ; +60: uint32 BugCheckParameter [ 4 ] < format = hex > ; +61: char VersionUser [ 32 ] ; +62: uchar PaeEnabled ; +63: uchar KdSecondaryVersion ; +64: uchar Spare3 [ 2 ] ; +65: uint32 KdDebuggerDataBlock < format = hex > ; +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: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/EDIDTemplate.bt b/cparser/tests/exp_lex/EDIDTemplate.bt new file mode 100644 index 0000000..4a87dce --- /dev/null +++ b/cparser/tests/exp_lex/EDIDTemplate.bt @@ -0,0 +1,734 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: typedef uint16 EISAId < read = EISAIdToString , write = StringToEISAId > ; +17: +18: string EISAIdToString ( EISAId x ) +19: { +20: uint16 sw = SwapBytes ( x ) ; +21: string s ; +22: SPrintf ( s , "%c%c%c" , '@' + ( sw >> 10 & 0x1F ) , '@' + ( sw >> 5 & 0x1F ) , '@' + ( sw >> 0 & 0x1F ) ) ; +23: return s ; +24: } +25: +26: void StringToEISAId ( EISAId & x , string s ) +27: { +28: char c [ 3 ] ; +29: SScan ( s , "%c%c%c" , c [ 0 ] , c [ 1 ] , c2 [ 2 ] ) ; +30: x = ( c [ 0 ] - '@' ) << 10 | ( c [ 1 ] - '@' ) << 5 | ( c [ 2 ] - '@' ) << 0 ; +31: x = SwapBytes ( x ) ; +32: } +33: +34: +35: +36: typedef struct +37: { +38: ubyte x_resolution ; +39: ubyte vFrequency : 6 ; +40: ubyte pixelRatio : 2 ; +41: } Timing < read = TimingToString > ; +42: +43: string TimingToString ( Timing & t ) +44: { +45: if ( t . x_resolution == 1 && t . vFrequency == 1 && t . pixelRatio == 0 ) return "-" ; +46: int x = ( t . x_resolution + 31 ) * 8 ; +47: int y ; +48: switch ( t . pixelRatio ) +49: { +50: case 0 : y = x * 10 / 16 ; break ; +51: case 1 : y = x * 3 / 4 ; break ; +52: case 2 : y = x * 4 / 5 ; break ; +53: case 3 : y = x * 9 / 16 ; break ; +54: } +55: string s ; +56: SPrintf ( s , "%ux%u, %uHz" , x , y , t . vFrequency + 60 ) ; +57: return s ; +58: } +59: +60: +61: +62: enum < ubyte > DescriptorType +63: { +64: TIMINGS = 0xFA , +65: WHITE_POINT = 0xFB , +66: MONITOR_NAME = 0xFC , +67: RANGE_LIMITS = 0xFD , +68: UNSPECIFIED_TEXT = 0xFE , +69: SERIAL_NUMBER = 0xFF , +70: } ; +71: +72: +73: +74: enum < ubyte > FormatCode +75: { +76: RESERVED = 0 , +77: LPCM = 1 , +78: AC_3 = 2 , +79: MPEG1 = 3 , +80: MP3 = 4 , +81: MPEG2 = 5 , +82: AAC = 6 , +83: DTS = 7 , +84: ATRAC = 8 , +85: SACD = 9 , +86: DD_PLUS = 10 , +87: DTS_HD = 11 , +88: MLP_TRUEHD = 12 , +89: DST = 13 , +90: WMA_PRO = 14 , +91: RESERVED2 = 15 , +92: } ; +93: +94: +95: +96: enum < ubyte > BlockType +97: { +98: AUDIO = 1 , +99: VIDEO = 2 , +100: VENDOR_SPECIFIC = 3 , +101: SPEAKER = 4 , +102: } ; +103: +104: +105: +106: enum < ubyte > SVDIndex +107: { +108: _DMT0659 = 1 , +109: _480p = 2 , +110: _480pH = 3 , +111: _720p = 4 , +112: _1080i = 5 , +113: _480i = 6 , +114: _480iH = 7 , +115: _240p = 8 , +116: _240pH = 9 , +117: _480i4x = 10 , +118: _480i4xH = 11 , +119: _240p4x = 12 , +120: _240p4xH = 13 , +121: _480p2x = 14 , +122: _480p2xH = 15 , +123: _1080p = 16 , +124: _576p = 17 , +125: _576pH = 18 , +126: _720p50 = 19 , +127: _1080i25 = 20 , +128: _576i = 21 , +129: _576iH = 22 , +130: _288p = 23 , +131: _288pH = 24 , +132: _576i4x = 25 , +133: _576i4xH = 26 , +134: _288p4x = 27 , +135: _288p4xH = 28 , +136: _576p2x = 29 , +137: _576p2xH = 30 , +138: _1080p50 = 31 , +139: _1080p24 = 32 , +140: _1080p25 = 33 , +141: _1080p30 = 34 , +142: _480p4x = 35 , +143: _480p4xH = 36 , +144: _576p4x = 37 , +145: _576p4xH = 38 , +146: _1080i25b = 39 , +147: _1080i50 = 40 , +148: _720p100 = 41 , +149: _576p100 = 42 , +150: _576p100H = 43 , +151: _576i50 = 44 , +152: _576i50H = 45 , +153: _1080i60 = 46 , +154: _720p120 = 47 , +155: _480p119 = 48 , +156: _480p119H = 49 , +157: _480i59 = 50 , +158: _480i59H = 51 , +159: _576p200 = 52 , +160: _576p200H = 53 , +161: _576i100 = 54 , +162: _576i100H = 55 , +163: _480p239 = 56 , +164: _480p239H = 57 , +165: _480i119 = 58 , +166: _480i119H = 59 , +167: _720p24 = 60 , +168: _720p25 = 61 , +169: _720p30 = 62 , +170: _1080p120 = 63 , +171: } ; +172: +173: typedef struct +174: { +175: SVDIndex index : 7 < comment = "index value to a table of standard resolutions/timings from CEA/EIA-861E" > ; +176: ubyte native : 1 < comment = "1 to designate that this should be considered a \"native\" resolution, 0 for non-native" > ; +177: } SVD < read = SVDToString , comment = "Short Video Descriptor" > ; +178: +179: string SVDToString ( SVD & svd ) +180: { +181: string s ; +182: SPrintf ( s , "%s%s (%u)" , ( svd . native ? "*" : "" ) , EnumToString ( svd . index ) , svd . index ) ; +183: return s ; +184: } +185: +186: +187: +188: string SPAToString ( uint16 spa ) +189: { +190: string s ; +191: SPrintf ( s , "%u.%u.%u.%u" , spa >> 4 & 15 , spa >> 0 & 15 , spa >> 12 & 15 , spa >> 8 & 15 ) ; +192: return s ; +193: } +194: +195: +196: +197: string TDMSFreqToString ( ubyte f ) +198: { +199: string s ; +200: SPrintf ( s , "%u MHz" , ( uint ) f * 5 ) ; +201: return s ; +202: } +203: +204: +205: +206: string PixelClockToString ( uint16 f ) +207: { +208: string s ; +209: SPrintf ( s , "%.2lf MHz" , ( double ) f / 100 ) ; +210: return s ; +211: } +212: +213: void StringToPixelClock ( uint16 & f , string s ) +214: { +215: f = Atof ( s ) * 100 ; +216: } +217: +218: +219: +220: typedef ubyte PixelRate < read = PixelRateToString , write = StringToPixelRate > ; +221: +222: string PixelRateToString ( PixelRate f ) +223: { +224: string s ; +225: SPrintf ( s , "%u MHz" , ( uint ) f * 10 ) ; +226: return s ; +227: } +228: +229: void StringToPixelRate ( PixelRate & f , string s ) +230: { +231: f = Atof ( s ) / 10 ; +232: } +233: +234: +235: +236: typedef ubyte BitRate < read = BitRateToString , write = StringToBitRate , comment = "maximum supported bitrate divided by 8 kbit/s" > ; +237: +238: string BitRateToString ( BitRate b ) +239: { +240: string s ; +241: SPrintf ( s , "%u kHz" , ( uint ) b * 8 ) ; +242: return s ; +243: } +244: +245: void StringToBitRate ( BitRate & b , string s ) +246: { +247: b = Atof ( s ) / 8 ; +248: } +249: +250: +251: +252: typedef ubyte Latency < read = LatencyToString , write = StringToLatency , comment = "Latency (value=1+ms/2 with a max of 251 meaning 500ms)" > ; +253: +254: string LatencyToString ( Latency l ) +255: { +256: if ( l == 0 ) return "-" ; +257: string s ; +258: SPrintf ( s , "%u ms" , ( ( uint ) l - 1 ) * 2 ) ; +259: return s ; +260: } +261: +262: void StringToLatency ( Latency & l , string s ) +263: { +264: if ( s == "-" ) l = 0 ; else l = ( uint ) ( Atof ( s ) / 2 ) + 1 ; +265: } +266: +267: +268: +269: typedef struct +270: { +271: ubyte size : 5 < comment = "Total number of bytes in this block following this byte" > ; +272: BlockType typeTag : 3 < comment = "Block Type Tag (1 is audio, 2 is video, 3 is vendor specific, 4 is speaker allocation, all other values Reserved)" > ; +273: +274: +275: switch ( typeTag ) +276: { +277: case AUDIO : +278: { +279: ubyte channelCount : 3 < comment = "number of channels minus 1" > ; +280: FormatCode formatCode : 4 < comment = "Audio format code" > ; +281: ubyte reserved1 : 1 ; +282: struct SampleRates +283: { +284: ubyte _32kHz : 1 ; +285: ubyte _44kHz : 1 ; +286: ubyte _48kHz : 1 ; +287: ubyte _88kHz : 1 ; +288: ubyte _96kHz : 1 ; +289: ubyte _176kHz : 1 ; +290: ubyte _192kHz : 1 ; +291: ubyte reserved : 1 ; +292: } sampleRates < comment = "sampling frequencies supported" > ; +293: if ( formatCode == 1 ) +294: { +295: ubyte _16bits : 1 ; +296: ubyte _20bits : 1 ; +297: ubyte _24bits : 1 ; +298: ubyte reserved : 5 ; +299: } +300: else +301: { +302: BitRate bitrate ; +303: } +304: break ; +305: } +306: +307: case VIDEO : +308: { +309: SVD svds [ size ] < bgcolor = cLtGreen , comment = "Short Video Descriptors" > ; +310: break ; +311: } +312: +313: case VENDOR_SPECIFIC : +314: { +315: ubyte oui [ 3 ] < format = hex , comment = "IEEE Registration Identifier" > ; +316: uint16 spa < read = SPAToString , comment = "Source Physical Address" > ; +317: if ( size >= 3 ) +318: { +319: ubyte DVI_Dual : 1 < comment = "sink supports DVI Dual Link Operation" > ; +320: ubyte reserved : 1 ; +321: ubyte reserved : 1 ; +322: ubyte dc_Y444 : 1 < comment = "sink supports 4:4:4 in deep color modes" > ; +323: ubyte dc_30bit : 1 < comment = "sink supports 10-bit-per-channel deep color" > ; +324: ubyte dc_36bit : 1 < comment = "sink supports 12-bit-per-channel deep color" > ; +325: ubyte dc_48bit : 1 < comment = "sink supports 16-bit-per-channel deep color" > ; +326: ubyte supports_AI : 1 < comment = "sink supports a function that needs info from ACP or ISRC packets" > ; +327: } +328: if ( size >= 4 ) +329: ubyte max_TMDS_Frequency < read = TDMSFreqToString , comment = "Maximum TMDS frequency" > ; +330: if ( size >= 5 ) +331: { +332: ubyte reserved : 6 ; +333: ubyte i_latency_fields : 1 < comment = "set if interlaced latency fields are present; if set four latency fields will be present" > ; +334: ubyte latency_fields : 1 < comment = "set if latency fields are present" > ; +335: if ( latency_fields ) +336: { +337: Latency videoLatency < comment = "Video Latency (value=1+ms/2 with a max of 251 meaning 500ms)" > ; +338: Latency audioLatency < comment = "Audio Latency (value=1+ms/2 with a max of 251 meaning 500ms)" > ; +339: } +340: if ( i_latency_fields ) +341: { +342: Latency interlacedVideoLatency < comment = "Interlaced Video Latency (value=1+ms/2 with a max of 251 meaning 500ms)" > ; +343: Latency interlacedAudioLatency < comment = "Interlaced Audio Latency (value=1+ms/2 with a max of 251 meaning 500ms)" > ; +344: } +345: } +346: break ; +347: } +348: +349: case SPEAKER : +350: { +351: ubyte frontLeftRight : 1 < comment = "Front Left / Front Right present for 1, absent for 0" > ; +352: ubyte LFE : 1 < comment = "LFE present for 1, absent for 0" > ; +353: ubyte frontCenter : 1 < comment = "Front Center present for 1, absent for 0" > ; +354: ubyte rearLeftRight : 1 < comment = "Rear Left / Rear Right present for 1, absent for 0" > ; +355: ubyte rearCenter : 1 < comment = "Rear Center present for 1, absent for 0" > ; +356: ubyte frontLeftRightCenter : 1 < comment = "Front Left Center / Front Right Center present for 1, absent for 0" > ; +357: ubyte rearLeftRightCenter : 1 < comment = "Rear Left Center / Rear Right Center present for 1, absent for 0" > ; +358: ubyte reserved : 1 ; +359: ubyte reserved [ 2 ] ; +360: break ; +361: } +362: } +363: +364: +365: +366: +367: +368: +369: +370: +371: +372: } DataBlock < size = DataBlockSize , optimize = false , open = true , comment = "Data block" > ; +373: +374: int DataBlockSize ( DataBlock & b ) +375: { +376: return ( ReadUByte ( startof ( b ) ) & 0x1F ) ; +377: } +378: +379: +380: +381: typedef struct +382: { +383: uint16 pixelClock < read = PixelClockToString , write = StringToPixelClock , comment = "Pixel clock in 10 kHz units. (0.01-655.35 MHz, little-endian)" > ; +384: +385: ubyte hActive_lsb < comment = "Horizontal active pixels 8 lsbits (0-4095)" > ; +386: ubyte hBlanking_lsb < comment = "Horizontal blanking pixels 8 lsbits (0-4095) End of active to start of next active." > ; +387: ubyte hBlanking_msb : 4 < comment = "Horizontal blanking pixels 4 msbits" > ; +388: ubyte hActive_msb : 4 < comment = "Horizontal active pixels 4 msbits" > ; +389: ubyte vActive_lsb < comment = "Vertical active lines 8 lsbits (0-4095)" > ; +390: ubyte vBlanking_lsb < comment = "Vertical blanking lines 8 lsbits (0-4095)" > ; +391: ubyte vBlanking_msb : 4 < comment = "Vertical blanking lines 4 msbits" > ; +392: ubyte vActive_msb : 4 < comment = "Vertical active lines 4 msbits" > ; +393: ubyte hSyncOffset_lsb < comment = "Horizontal sync offset pixels 8 lsbits (0-1023) From blanking start" > ; +394: ubyte hSync_lsb < comment = "Horizontal sync pulse width pixels 8 lsbits (0-1023)" > ; +395: ubyte vSync_lsb : 4 < comment = "Vertical sync pulse width lines 4 lsbits (0-63)" > ; +396: ubyte vSyncOffset_lsb : 4 < comment = "Vertical sync offset lines 4 lsbits (0-63)" > ; +397: ubyte vSync_msb : 2 < comment = "Vertical sync pulse width lines 2 msbits" > ; +398: ubyte vSyncOffset_msb : 2 < comment = "Vertical sync offset lines 2 msbits" > ; +399: ubyte hSync_msb : 2 < comment = "Horizontal sync pulse width pixels 2 msbits" > ; +400: ubyte hSyncOffset_msb : 2 < comment = "Horizontal sync offset pixels 2 msbits" > ; +401: ubyte hSize_lsb < comment = "Horizontal display size, mm, 8 lsbits (0-4095 mm, 161 in)" > ; +402: ubyte vSize_lsb < comment = "Vertical display size, mm, 8 lsbits (0-4095 mm, 161 in)" > ; +403: ubyte vSize_msb : 4 < comment = "Vertical display size, mm, 4 msbits" > ; +404: ubyte hSize_msb : 4 < comment = "Horizontal display size, mm, 4 msbits" > ; +405: ubyte hBorder < comment = "Horizontal border pixels (each side; total is twice this)" > ; +406: ubyte vBorder < comment = "Vertical border lines (each side; total is twice this)" > ; +407: +408: ubyte _f0 : 1 < comment = "2-way line-interleaved stereo, if bits 4-3 are not 00." > ; +409: ubyte _f1 : 1 < comment = "If analog sync: Sync on all 3 RGB lines (else green only). Digital: HSync polarity (1=positive)" > ; +410: ubyte _f2 : 1 < comment = "If digital separate: Vertical sync polarity (1=positive). Other types: VSync serrated (HSync during VSync)" > ; +411: ubyte _f34 : 2 < comment = "Sync type: 00=Analog composite; 01=Bipolar analog composite; 10=Digital composite (on HSync); 11=Digital separate" > ; +412: ubyte _f56 : 2 < comment = "Stereo mode: 00=No stereo; other values depend on bit 0: Bit 0=0: 01=Field sequential, sync=1 during right; 10=similar, sync=1 during left; 11=4-way interleaved stereo. Bit 0=1 2-way interleaved stereo: 01=Right image on even lines; 10=Left image on even lines; 11=side-by-side" > ; +413: ubyte interlaced : 1 < comment = "Interlaced" > ; +414: +415: +416: +417: } ModeLine < read = ModeLineToString , write = StringToModeLine , comment = "Xfree86 modeline" > ; +418: +419: string ModeLineToString ( ModeLine & n ) +420: { +421: uint hActive = ( uint ) n . hActive_msb << 8 | n . hActive_lsb ; +422: uint hSyncOffset = ( uint ) n . hSyncOffset_msb << 8 | n . hSyncOffset_lsb ; +423: uint hSync = ( uint ) n . hSync_msb << 8 | n . hSync_lsb ; +424: uint hBlanking = ( uint ) n . hBlanking_msb << 8 | n . hBlanking_lsb ; +425: +426: uint vActive = ( uint ) n . vActive_msb << 8 | n . vActive_lsb ; +427: uint vSyncOffset = ( uint ) n . vSyncOffset_msb << 8 | n . vSyncOffset_lsb ; +428: uint vSync = ( uint ) n . vSync_msb << 8 | n . vSync_lsb ; +429: uint vBlanking = ( uint ) n . vBlanking_msb << 8 | n . vBlanking_lsb ; +430: +431: uint im = n . interlaced ? 2 : 1 ; +432: string s ; +433: SPrintf ( s , "Modeline \"%ux%u\" %.2lf %4u %4u %4u %4u %4u %4u %4u %4u %chsync %cvsync %s ; %u %u" , +434: hActive , vActive * im , ( double ) n . pixelClock / 100 , +435: hActive , hActive + hSyncOffset , hActive + hSyncOffset + hSync , hActive + hBlanking , +436: vActive * im , ( vActive + vSyncOffset ) * im , ( vActive + vSyncOffset + vSync ) * im , ( vActive + vBlanking ) * im , +437: n . _f1 ? '+' : '-' , n . _f2 ? '+' : '-' , +438: n . interlaced ? "Interlace" : "" , +439: n . hBorder , n . vBorder +440: ) ; +441: return s ; +442: } +443: +444: void StringToModeLine ( ModeLine & n , string s ) +445: { +446: uint dummy ; +447: uint hActive , hActive_hSyncOffset , hActive_hSyncOffset_hSync , hActive_hBlanking ; +448: uint vActive , vActive_vSyncOffset , vActive_vSyncOffset_vSync , vActive_vBlanking ; +449: char hsync , vsync ; +450: string interlaced ; +451: double f ; +452: SScanf ( s , "Modeline \"%ux%u\" %lf %u %u %u %u %u %u %u %u %chsync %cvsync %[^0-9;]" , +453: dummy , dummy , f , +454: hActive , hActive_hSyncOffset , hActive_hSyncOffset_hSync , hActive_hBlanking , +455: vActive , vActive_vSyncOffset , vActive_vSyncOffset_vSync , vActive_vBlanking , +456: hsync , vsync , +457: interlaced +458: ) ; +459: int p = Strchr ( s , ';' ) ; +460: if ( p >= 0 ) SScanf ( SubStr ( s , p ) , "; %u %u" , n . hBorder , n . vBorder ) ; +461: +462: n . interlaced = ( interlaced [ 0 ] == 'I' ) ; +463: uint im = n . interlaced ? 2 : 1 ; +464: +465: uint hBlanking = hActive_hBlanking - hActive ; +466: uint hSync = hActive_hSyncOffset_hSync - hActive_hSyncOffset ; +467: uint hSyncOffset = hActive_hSyncOffset - hActive ; +468: n . hActive_msb = hActive >> 8 ; n . hActive_lsb = ( ubyte ) hActive ; +469: n . hSyncOffset_msb = hSyncOffset >> 8 ; n . hSyncOffset_lsb = ( ubyte ) hSyncOffset ; +470: n . hSync_msb = hSync >> 8 ; n . hSync_lsb = ( ubyte ) hSync ; +471: n . hBlanking_msb = hBlanking >> 8 ; n . hBlanking_lsb = ( ubyte ) hBlanking ; +472: +473: uint vBlanking = ( vActive_vBlanking - vActive ) / im ; +474: uint vSync = ( vActive_vSyncOffset_vSync - vActive_vSyncOffset ) / im ; +475: uint vSyncOffset = ( vActive_vSyncOffset - vActive ) / im ; +476: vActive /= im ; +477: n . vActive_msb = vActive >> 8 ; n . vActive_lsb = ( ubyte ) vActive ; +478: n . vSyncOffset_msb = vSyncOffset >> 8 ; n . vSyncOffset_lsb = ( ubyte ) vSyncOffset ; +479: n . vSync_msb = vSync >> 8 ; n . vSync_lsb = ( ubyte ) vSync ; +480: n . vBlanking_msb = vBlanking >> 8 ; n . vBlanking_lsb = ( ubyte ) vBlanking ; +481: +482: n . _f1 = hsync == '+' ? 1 : 0 ; +483: n . _f2 = vsync == '+' ? 1 : 0 ; +484: n . pixelClock = f * 100 ; +485: } +486: +487: +488: +489: struct File +490: { +491: struct Header +492: { +493: ubyte pattern [ 8 ] < format = hex , comment = "Fixed header pattern: 00 FF FF FF FF FF FF 00" > ; +494: EISAId eisaId < comment = "EISA ID. Encoded as 3 5-bit letters (1=A, 26=Z), big-endian, with msbit reserved." > ; +495: uint16 mfgProductId < comment = "Manufacturer product code. 16-bit number, little-endian." > ; +496: uint32 serial < comment = "Serial number. 32 bits, little endian." > ; +497: ubyte mfgWeek < comment = "Week of manufacture. Week numbering is not consistent between manufacturers." > ; +498: ubyte mfgYear < comment = "Year of manufacture, less 1990. (1990-2245). If week=255, it is the model year instead." > ; +499: ubyte edidVersion < comment = "EDID version, usually 1 (for 1.3)" > ; +500: ubyte edidRevision < comment = "EDID revision, usually 3 (for 1.3)" > ; +501: } header < open = false , comment = "Header information" > ; +502: +503: struct Basic +504: { +505: union Bitmap +506: { +507: ubyte hmz ; +508: if ( hmz & 0x80 ) +509: { +510: struct Digital +511: { +512: ubyte vesa : 1 < comment = "Signal is compatible with VESA DFP 1.x TMDS CRGB, 1 pixel per clock, up to 8 bits per color, MSB aligned," > ; +513: ubyte reserved : 6 < comment = "Reserved, must be 0" > ; +514: ubyte digital : 1 < comment = "1=Digital input" > ; +515: } digital ; +516: } +517: else +518: { +519: struct Analog +520: { +521: ubyte vSeparate : 1 < comment = "VSync pulse must be separated when composite or sync-on-green is used" > ; +522: ubyte syncOnGreen : 1 < comment = "Sync on green supported" > ; +523: +524: ubyte compositeSync : 1 < comment = "Composite sync (on HSync) supported" > ; +525: ubyte separateSync : 1 < comment = "Separate sync supported" > ; +526: ubyte blankToBlack : 1 < comment = "Blank-to-black setup (pedestal) expected" > ; +527: ubyte level : 2 < comment = "Video white and sync levels, relative to blank: 00=+0.7/0.3 V; 01=+0.714/0.286 V; 10=+1.0/0.4 V; 11=+0.7/0 V" > ; +528: ubyte analog : 1 < comment = "0=Analog input" > ; +529: } analog ; +530: } +531: } bitmap < comment = "Video input parameters bitmap" > ; +532: +533: ubyte width < comment = "Maximum horizontal image size, in centimetres (max 292 cm/115 in at 16:9 aspect ratio)" > ; +534: ubyte height < comment = "Maximum vertical image size, in centimetres. If either byte is 0, undefined (e.g. projector)" > ; +535: ubyte gamma < comment = "Display gamma, minus 1, times 100 (range 1.00-3.54)" > ; +536: +537: struct Features +538: { +539: ubyte gtf : 1 < comment = "GTF supported with default parameter values." > ; +540: ubyte prefTimingDesc1 : 1 < comment = "Preferred timing mode specified in descriptor block 1." > ; +541: ubyte sRGB : 1 < comment = "Standard sRGB colour space. Bytes 25-34 must contain sRGB standard values." > ; +542: if ( bitmap . hmz & 0x80 ) +543: ubyte displayType : 2 < comment = "Display type (digital): 00 = RGB 4:4:4; 01 = RGB 4:4:4 + YCrCb 4:4:4; 10 = RGB 4:4:4 + YCrCb 4:2:2; 11 = RGB 4:4:4 + YCrCb 4:4:4 + YCrCb 4:2:2" > ; +544: else +545: ubyte displayType : 2 < comment = "Display type (analog): 00 = Monochrome or Grayscale; 01 = RGB color; 10 = Non-RGB color; 11 = Undefined" > ; +546: ubyte dpmsActiveOff : 1 < comment = "DPMS active-off supported" > ; +547: ubyte dpmsSusepend : 1 < comment = "DPMS suspend supported" > ; +548: ubyte dpmsStandby : 1 < comment = "DPMS standby supported" > ; +549: } features < comment = "Supported features bitmap" > ; +550: } basic < open = false , comment = "Basic display parameters" > ; +551: +552: struct Chromaticity +553: { +554: ubyte green_y_lsb : 2 < comment = "Green y value least-significant 2 bits" > ; +555: ubyte green_x_lsb : 2 < comment = "Green x value least-significant 2 bits" > ; +556: ubyte red_y_lsb : 2 < comment = "Red y value least-significant 2 bits" > ; +557: ubyte red_x_lsb : 2 < comment = "Red x value least-significant 2 bits" > ; +558: ubyte bluewhite_lsb : 2 < comment = "Blue and white least-significant 2 bits" > ; +559: ubyte zero : 6 ; +560: ubyte red_x_msb < comment = "Red x value most significant 8 bits. 0-255 encodes 0-0.996 (255/256); 0-0.999 (1023/1024) with lsbits" > ; +561: ubyte red_y_msb < comment = "Red y value most significant 8 bits" > ; +562: ubyte green_x_msb < comment = "Green x value most significant 8 bits" > ; +563: ubyte green_y_msb < comment = "Green y value most significant 8 bits" > ; +564: ubyte blue_x_msb < comment = "Blue x value most significant 8 bits" > ; +565: ubyte blue_y_msb < comment = "Blue y value most significant 8 bits" > ; +566: ubyte white_x_msb < comment = "Default white point x value most significant 8 bits" > ; +567: ubyte white_y_msb < comment = "Default white point y value most significant 8 bits" > ; +568: } chromaticity < bgcolor = cLtAqua , comment = "Chromaticity coordinates. 10-bit CIE xy coordinates for red, green, blue, and white. [0-1023/1024]." > ; +569: +570: struct Timings +571: { +572: ubyte _800x600_60 : 1 ; +573: ubyte _800x600_56 : 1 ; +574: ubyte _640x480_75 : 1 ; +575: ubyte _640x480_72 : 1 ; +576: ubyte _640x480_67 : 1 ; +577: ubyte _640x480_60 : 1 ; +578: ubyte _720x400_88 : 1 ; +579: ubyte _720x400_70 : 1 ; +580: ubyte _1280x1024_75 : 1 ; +581: ubyte _1024x768_75 : 1 ; +582: ubyte _1024x768_72 : 1 ; +583: ubyte _1024x768_60 : 1 ; +584: ubyte _1024x768i_87 : 1 ; +585: ubyte _832x624_75 : 1 ; +586: ubyte _800x600_75 : 1 ; +587: ubyte _800x600_72 : 1 ; +588: ubyte mfgSpecific : 7 ; +589: ubyte _1152x870_75 : 1 ; +590: } timings < bgcolor = cLtGreen , comment = "Established timing bitmap. Supported bitmap for very common timing modes." > ; +591: +592: Timing timings2 [ 8 ] < bgcolor = cLtGreen , comment = "Standard timing information. Up to 8 2-byte fields describing standard display modes." > ; +593: +594: struct Descriptor +595: { +596: if ( ReadUShort ( FTell ( ) ) != 0 ) +597: { +598: ModeLine numbers ; +599: } +600: else +601: { +602: uint16 zero ; +603: ubyte zero ; +604: DescriptorType descriptorType ; +605: ubyte zero ; +606: switch ( descriptorType ) +607: { +608: case TIMINGS : +609: Timing timings [ 6 ] < comment = "Additional standard timing identifiers. 6- 2-byte descriptors, padded with 0A." > ; +610: break ; +611: +612: case MONITOR_NAME : +613: char name [ 13 ] < comment = "Monitor name (text)" > ; +614: break ; +615: +616: case SERIAL_NUMBER : +617: char serial [ 13 ] < comment = "Monitor serial number (text)" > ; +618: break ; +619: +620: case UNSPECIFIED_TEXT : +621: char text [ 13 ] < comment = "Unspecified text (text)" > ; +622: break ; +623: +624: case RANGE_LIMITS : +625: { +626: ubyte vMinRate < comment = "Minimum vertical field rate" > ; +627: ubyte vMaxRate < comment = "Maximum vertical field rate" > ; +628: ubyte hMinRate < comment = "Minimum horizontal line rate" > ; +629: ubyte hMaxRate < comment = "Maximum horizontal line rate" > ; +630: PixelRate maxPixelRate < comment = "Maximum pixel clock rate, rounded up to 10 MHz multiple (10-2550 MHz)" > ; +631: ubyte extended < comment = "02: Secondary GTF supported, parameters as follows." > ; +632: if ( extended == 0x2 ) +633: { +634: ubyte reserved ; +635: ubyte startFreqSecondCurve < comment = "Start frequency for secondary curve, divided by 2 kHz (0-510 kHz)" > ; +636: ubyte gtf_C < comment = "C value, multiplied by 2 (0-127.5)" > ; +637: uint16 gtf_M < comment = "GTF M value (0-65535, little-endian)" > ; +638: ubyte gtf_K < comment = "GTF K value (0-255)" > ; +639: ubyte gtf_J < comment = "GTF J value, multiplied by 2 (0-127.5)" > ; +640: } +641: else +642: { +643: ubyte padding [ 7 ] < comment = "0A 20 20 20 20 20 20" > ; +644: } +645: break ; +646: } +647: +648: case WHITE_POINT : +649: { +650: struct +651: { +652: ubyte indexNumber < comment = "Point index number (1-255) Usually 1; 0 indicates descriptor not used." > ; +653: ubyte white_y_lsb : 2 < comment = "White point y value least-significant 2 bits" > ; +654: ubyte white_x_lsb : 2 < comment = "White point x value least-significant 2 bits" > ; +655: ubyte unused : 4 ; +656: ubyte white_x_msb < comment = "White point x value most significant 8 bits (like EDID byte 27)" > ; +657: ubyte white_y_msb < comment = "White point y value most significant 8 bits (like EDID byte 28)" > ; +658: ubyte gamma < comment = "Gamma value, minus 1, time 100 (1.0-3.54, like EDID byte 23)" > ; +659: } whitePoints [ 2 ] < bgcolor = cLtAqua , comment = "Additional white point descriptors" > ; +660: ubyte padding [ 3 ] < comment = "0A 20 20" > ; +661: break ; +662: } +663: +664: default : +665: { +666: ubyte unknown [ 13 ] ; +667: Warning ( "Unknown descriptor type" ) ; +668: break ; +669: } +670: } +671: } +672: } descriptors [ 4 ] < optimize = false , bgcolor = cLtGray , comment = "Detailed Timing Descriptor blocks, in decreasing preference order. After all detailed timing descriptors, additional descriptors are permitted." > ; +673: +674: +675: ubyte extensionCount < comment = "Number of extensions to follow. 0 if no extensions." > ; +676: ubyte checksum < format = hex , comment = "Sum of all 128 bytes should equal 0 (mod 256)." > ; +677: +678: +679: +680: struct CEA_EDID +681: { +682: local int64 extensionBlockStart < hidden = true > = FTell ( ) ; +683: +684: ubyte extensionTag < comment = "Extension tag (which kind of extension block this is); 02h for CEA EDID" > ; +685: switch ( extensionTag ) +686: { +687: case 0x2 : +688: { +689: ubyte revision < comment = "Revision number (Version number); 03h for Version 3" > ; +690: ubyte dtdStart < comment = "Byte number \"d\" within this block where the 18-byte DTDs begin." > ; +691: ubyte dtdCount : 4 < comment = "total number of native formats in the DTDs included in this block" > ; +692: ubyte YCbCr422 : 1 < comment = "1 if display supports YCbCr 4:2:2, 0 if not" > ; +693: ubyte YCbCr444 : 1 < comment = "1 if display supports YCbCr 4:4:4, 0 if not" > ; +694: ubyte basic_audio : 1 < comment = "1 if display supports basic audio, 0 if not" > ; +695: ubyte underscan : 1 < comment = "if display supports underscan, 0 if not" > ; +696: +697: while ( FTell ( ) < extensionBlockStart + dtdStart ) +698: { +699: DataBlock dataBlock ; +700: } +701: +702: if ( FTell ( ) != extensionBlockStart + dtdStart ) +703: { +704: Warning ( "Unexpected DTD start" ) ; +705: } +706: +707: FSeek ( extensionBlockStart + dtdStart ) ; +708: +709: while ( ReadUShort ( FTell ( ) ) != 0 ) +710: { +711: Descriptor descriptor < optimize = false , bgcolor = cLtGray , comment = "Detailed Timing Descriptor block" > ; +712: } +713: +714: ubyte padding [ 127 - ( FTell ( ) - extensionBlockStart ) ] < format = hex , comment = "Post-DTD padding. Should be populated with 00h" > ; +715: ubyte checksum < format = hex , comment = "This byte should be programmed such that the sum of all 128 bytes equals 00h." > ; +716: if ( Checksum ( CHECKSUM_SUM8 , extensionBlockStart , 128 ) != 0 ) Warning ( "Invalid extension block checksum!" ) ; +717: +718: break ; +719: } +720: +721: default : +722: Warning ( "Unsupported extension block" ) ; +723: break ; +724: } +725: } extensions [ extensionCount ] < optimize = false , open = true , comment = "EDID Extensions" > ; +726: +727: +728: } file < open = true , fgcolor = cBlue > ; +729: +730: +731: tok_eof +warning: \0 character in file data +warning: \0 character in file data +warning: \0 character in file data \ No newline at end of file diff --git a/cparser/tests/exp_lex/ELFTemplate.bt b/cparser/tests/exp_lex/ELFTemplate.bt new file mode 100644 index 0000000..a5eb71e --- /dev/null +++ b/cparser/tests/exp_lex/ELFTemplate.bt @@ -0,0 +1,795 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: +21: +22: +23: +24: +25: +26: +27: +28: +29: +30: local int sec_tbl_elem [ 255 ] ; +31: +32: typedef enum < uchar > { +33: ELFCLASSNONE = 0 , +34: ELFCLASS32 = 1 , +35: ELFCLASS64 = 2 +36: } ei_class_2_e ; +37: +38: typedef enum < uchar > { +39: ELFDATAONE = 0 , +40: ELFDATA2LSB = 1 , +41: ELFDATA2MSB = 2 +42: } ei_data_e ; +43: +44: typedef enum < uchar > { +45: E_NONE = 0 , +46: E_CURRENT = 1 +47: } ei_version_e ; +48: +49: typedef enum < uchar > { +50: ELFOSABI_NONE = 0 , +51: ELFOSABI_HPUX = 1 , +52: ELFOSABI_NETBSD = 2 , +53: ELFOSABI_SOLARIS = 6 , +54: ELFOSABI_AIX = 7 , +55: ELFOSABI_IRIX = 8 , +56: ELFOSABI_FREEBSD = 9 , +57: ELFOSABI_TRU64 = 10 , +58: ELFOSABI_MODESTO = 11 , +59: ELFOSABI_OPENBSD = 12 , +60: ELFOSABI_OPENVMS = 13 , +61: ELFOSABI_NSK = 14 , +62: ELFOSABI_AROS = 15 +63: } ei_osabi_e ; +64: +65: +66: typedef struct { +67: char file_identification [ 4 ] ; +68: ei_class_2_e ei_class_2 ; +69: ei_data_e ei_data ; +70: if ( ei_data == ELFDATA2LSB ) { +71: LittleEndian ( ) ; +72: } else { +73: BigEndian ( ) ; +74: } +75: ei_version_e ei_version ; +76: ei_osabi_e ei_osabi ; +77: uchar ei_abiversion ; +78: uchar ei_pad [ 6 ] ; +79: uchar ei_nident_SIZE ; +80: } e_ident_t ; +81: +82: +83: +84: typedef uint32 Elf32_Word ; +85: typedef uint32 Elf32_Off ; +86: typedef uint32 Elf32_Addr < read = VAddr32 > ; +87: typedef uint16 Elf32_Half ; +88: typedef uint32 Elf32_Xword ; +89: +90: typedef uint32 Elf64_Word ; +91: typedef uint64 Elf64_Off ; +92: typedef uint64 Elf64_Addr < read = VAddr64 > ; +93: typedef uint16 Elf64_Half ; +94: typedef uint64 Elf64_Xword ; +95: +96: string VAddr32 ( Elf32_Addr & addr ) { +97: local char buf [ 128 ] ; +98: SPrintf ( buf , "0x%08X" , addr ) ; +99: return buf ; +100: } +101: +102: string VAddr64 ( Elf64_Addr & addr ) { +103: local char buf [ 128 ] ; +104: SPrintf ( buf , "0x%016LX" , addr ) ; +105: return buf ; +106: } +107: +108: typedef enum < Elf32_Half > { +109: ET_NONE = 0 , +110: ET_REL = 1 , +111: ET_EXEC = 2 , +112: ET_DYN = 3 , +113: ET_CORE = 4 , +114: ET_LOOS = 0xFE00 , +115: ET_HIOS = 0xFEFF , +116: ET_LOPROC = 0xFF00 , +117: ET_HIPROC = 0xFFFF +118: } e_type32_e ; +119: typedef e_type32_e e_type64_e ; +120: +121: typedef enum < Elf32_Half > { +122: EM_NONE = 0 , +123: EM_M32 = 1 , +124: EM_SPARC = 2 , +125: EM_386 = 3 , +126: EM_68K = 4 , +127: EM_88K = 5 , +128: reserved6 = 6 , +129: EM_860 = 7 , +130: EM_MIPS = 8 , +131: EM_S370 = 9 , +132: EM_MIPS_RS3_LE = 10 , +133: reserved11 = 11 , +134: reserved12 = 12 , +135: reserved13 = 13 , +136: reserved14 = 14 , +137: EM_PARISC = 15 , +138: reserved16 = 16 , +139: EM_VPP500 = 17 , +140: EM_SPARC32PLUS = 18 , +141: EM_960 = 19 , +142: EM_PPC = 20 , +143: EM_PPC64 = 21 , +144: EM_S390 = 22 , +145: reserved23 = 23 , +146: reserved24 = 24 , +147: reserved25 = 25 , +148: reserved26 = 26 , +149: reserved27 = 27 , +150: reserved28 = 28 , +151: reserved29 = 29 , +152: reserved30 = 30 , +153: reserved31 = 31 , +154: reserved32 = 32 , +155: reserved33 = 33 , +156: reserved34 = 34 , +157: reserved35 = 35 , +158: EM_V800 = 36 , +159: EM_FR20 = 37 , +160: EM_RH32 = 38 , +161: EM_RCE = 39 , +162: EM_ARM = 40 , +163: EM_ALPHA = 41 , +164: EM_SH = 42 , +165: EM_SPARCV9 = 43 , +166: EM_TRICORE = 44 , +167: EM_ARC = 45 , +168: EM_H8_300 = 46 , +169: EM_H8_300H = 47 , +170: EM_H8S = 48 , +171: EM_H8_500 = 49 , +172: EM_IA_64 = 50 , +173: EM_MIPS_X = 51 , +174: EM_COLDFIRE = 52 , +175: EM_68HC12 = 53 , +176: EM_MMA = 54 , +177: EM_PCP = 55 , +178: EM_NCPU = 56 , +179: EM_NDR1 = 57 , +180: EM_STARCORE = 58 , +181: EM_ME16 = 59 , +182: EM_ST100 = 60 , +183: EM_TINYJ = 61 , +184: EM_X86_64 = 62 , +185: EM_PDSP = 63 , +186: EM_PDP10 = 64 , +187: EM_PDP11 = 65 , +188: EM_FX66 = 66 , +189: EM_ST9PLUS = 67 , +190: EM_ST7 = 68 , +191: EM_68HC16 = 69 , +192: EM_68HC11 = 70 , +193: EM_68HC08 = 71 , +194: EM_68HC05 = 72 , +195: EM_SVX = 73 , +196: EM_ST19 = 75 , +197: EM_CRIS = 76 , +198: EM_JAVELIN = 77 , +199: EM_FIREPATH = 78 , +200: EM_ZSP = 79 , +201: EM_MMIX = 80 , +202: EM_HUANY = 81 , +203: EM_PRISM = 82 , +204: EM_AVR = 83 , +205: EM_FR30 = 84 , +206: EM_D10V = 85 , +207: EM_D30V = 86 , +208: EM_V850 = 87 , +209: EM_M32R = 88 , +210: EM_MN10300 = 89 , +211: EM_MN10200 = 90 , +212: EM_PJ = 91 , +213: EM_OPENRISC = 92 , +214: EM_ARC_A5 = 93 , +215: EM_XTENSA = 94 , +216: EM_VIDEOCORE = 95 , +217: EM_TMM_GPP = 96 , +218: EM_NS32K = 97 , +219: EM_TPC = 98 , +220: EM_SNP1K = 99 , +221: EM_ST200 = 100 , +222: EM_IP2K = 101 , +223: EM_MAX = 102 , +224: EM_CR = 103 , +225: EM_F2MC16 = 104 , +226: EM_MSP430 = 105 , +227: EM_BLACKFIN = 106 , +228: EM_SE_C33 = 107 , +229: EM_SEP = 108 , +230: EM_ARCA = 109 , +231: EM_UNICORE = 110 +232: } e_machine32_e ; +233: +234: typedef e_machine32_e e_machine64_e ; +235: +236: typedef enum < Elf32_Word > { +237: EV_NONE = 0 , +238: EV_CURRENT = 1 +239: } e_version32_e ; +240: typedef e_version32_e e_version64_e ; +241: +242: +243: +244: typedef enum < Elf32_Word > { +245: PT_NULL = 0 , +246: PT_LOAD = 1 , +247: PT_DYNAMIC = 2 , +248: PT_INERP = 3 , +249: PT_NOTE = 4 , +250: PT_SHLIB = 5 , +251: PT_PHDR = 6 , +252: PT_LOOS = 0x60000000 , +253: PT_HIOS = 0x6FFFFFFF , +254: PT_LOPROC = 0x70000000 , +255: PT_HIPROC = 0x7FFFFFFF +256: } p_type32_e ; +257: typedef p_type32_e p_type64_e ; +258: +259: typedef enum < Elf32_Word > { +260: PF_None = 0 , +261: PF_Exec = 1 , +262: PF_Write = 2 , +263: PF_Write_Exec = 3 , +264: PF_Read = 4 , +265: PF_Read_Exec = 5 , +266: PF_Read_Write = 6 , +267: PF_Read_Write_Exec = 7 +268: } p_flags32_e ; +269: typedef p_flags32_e p_flags64_e ; +270: +271: typedef enum < Elf32_Word > { +272: SHN_UNDEF = 0 , +273: SHN_LORESERVE = 0xFF00 , +274: SHN_LOPROC = 0xFF00 , +275: SHN_HIPROC = 0xFF1F , +276: SHN_LOOS = 0xFF20 , +277: SHN_HIOS = 0xFF3F , +278: SHN_ABS = 0xFFF1 , +279: SHN_COMMON = 0xFFF2 , +280: SHN_HIRESERVE = 0xFFFF +281: } s_name32_e ; +282: typedef s_name32_e s_name64_e ; +283: +284: typedef enum < Elf32_Word > { +285: SHT_NULL = 0 , +286: SHT_PROGBITS = 1 , +287: SHT_SYMTAB = 2 , +288: SHT_STRTAB = 3 , +289: SHT_RELA = 4 , +290: SHT_HASH = 5 , +291: SHT_DYNAMIC = 6 , +292: SHT_NOTE = 7 , +293: SHT_NOBITS = 8 , +294: SHT_REL = 9 , +295: SHT_SHLIB = 10 , +296: SHT_DYNSYM = 11 , +297: +298: SHT_LOOS = 0x60000000 , +299: SHT_HIOS = 0x6FFFFFFF , +300: +301: SHT_LOPROC = 0x70000000 , +302: SHT_HIPROC = 0x7FFFFFFF +303: } s_type32_e ; +304: typedef s_type32_e s_type64_e ; +305: +306: string ReservedSectionName ( s_name32_e id ) { +307: local char buf [ 255 ] ; +308: if ( id == SHN_UNDEF ) return "SHN_UNDEF" ; +309: if ( id >= SHN_LOPROC && id <= SHN_HIPROC ) { +310: SPrintf ( buf , "SHN_PROC_%02X" , id - SHN_LOPROC ) ; +311: return buf ; +312: } +313: if ( id >= SHN_LOOS && id <= SHN_HIOS ) { +314: SPrintf ( buf , "SHN_OS_%02X" , id - SHN_LOOS ) ; +315: return buf ; +316: } +317: if ( id == SHN_ABS ) return "SHN_ABS" ; +318: if ( id == SHN_COMMON ) return "SHN_COMMON" ; +319: +320: SPrintf ( buf , "SHN_RESERVE_%02X" , id - SHN_LORESERVE ) ; +321: return buf ; +322: } +323: +324: +325: typedef struct { +326: local quad off = FTell ( ) ; +327: +328: p_type32_e p_type ; +329: Elf32_Off p_offset_FROM_FILE_BEGIN < format = hex > ; +330: Elf32_Addr p_vaddr_VIRTUAL_ADDRESS ; +331: Elf32_Addr p_paddr_PHYSICAL_ADDRESS ; +332: Elf32_Word p_filesz_SEGMENT_FILE_LENGTH ; +333: Elf32_Word p_memsz_SEGMENT_RAM_LENGTH ; +334: p_flags32_e p_flags ; +335: Elf32_Word p_align ; +336: +337: if ( p_filesz_SEGMENT_FILE_LENGTH > 0 ) { +338: FSeek ( p_offset_FROM_FILE_BEGIN ) ; +339: char p_data [ p_filesz_SEGMENT_FILE_LENGTH ] ; +340: } +341: +342: FSeek ( off + file . elf_header . e_phentsize_PROGRAM_HEADER_ENTRY_SIZE_IN_FILE ) ; +343: } program_table_entry32_t < read = ProgramInfo32 , optimize = false > ; +344: typedef struct { +345: local quad off = FTell ( ) ; +346: +347: p_type64_e p_type ; +348: p_flags64_e p_flags ; +349: Elf64_Off p_offset_FROM_FILE_BEGIN < format = hex > ; +350: Elf64_Addr p_vaddr_VIRTUAL_ADDRESS ; +351: Elf64_Addr p_paddr_PHYSICAL_ADDRESS ; +352: Elf64_Xword p_filesz_SEGMENT_FILE_LENGTH ; +353: Elf64_Xword p_memsz_SEGMENT_RAM_LENGTH ; +354: Elf64_Xword p_align ; +355: +356: if ( p_filesz_SEGMENT_FILE_LENGTH > 0 ) { +357: FSeek ( p_offset_FROM_FILE_BEGIN ) ; +358: char p_data [ p_filesz_SEGMENT_FILE_LENGTH ] ; +359: } +360: +361: FSeek ( off + file . elf_header . e_phentsize_PROGRAM_HEADER_ENTRY_SIZE_IN_FILE ) ; +362: } program_table_entry64_t < read = ProgramInfo64 , optimize = false > ; +363: +364: string ProgramType ( p_type64_e type ) { +365: switch ( type ) { +366: case PT_NULL : return "NULL" ; +367: case PT_LOAD : return "Loadable Segment" ; +368: case PT_DYNAMIC : return "Dynamic Segment" ; +369: case PT_INERP : return "Interpreter Path" ; +370: case PT_NOTE : return "Note" ; +371: case PT_SHLIB : return "PT_SHLIB" ; +372: case PT_PHDR : return "Program Header" ; +373: default : return "Unknown Section" ; +374: } +375: } +376: +377: string ProgramFlags ( p_flags64_e flags ) { +378: local string rv = "(" ; +379: +380: rv += ( flags & PF_Read ) ? "R" : "_" ; +381: rv += ( flags & PF_Write ) ? "W" : "_" ; +382: rv += ( flags & PF_Exec ) ? "X" : "_" ; +383: rv += ")" ; +384: return rv ; +385: } +386: +387: string ProgramInfo64 ( program_table_entry64_t & ent ) { +388: return ProgramFlags ( ent . p_flags ) + " " + ProgramType ( ent . p_type ) ; +389: } +390: +391: string ProgramInfo32 ( program_table_entry32_t & ent ) { +392: return ProgramFlags ( ent . p_flags ) + " " + ProgramType ( ent . p_type ) ; +393: } +394: +395: +396: +397: typedef enum < Elf32_Xword > { +398: SF32_None = 0 , +399: SF32_Exec = 1 , +400: SF32_Alloc = 2 , +401: SF32_Alloc_Exec = 3 , +402: SF32_Write = 4 , +403: SF32_Write_Exec = 5 , +404: SF32_Write_Alloc = 6 , +405: SF32_Write_Alloc_Exec = 7 +406: } s_flags32_e ; +407: typedef enum < Elf64_Xword > { +408: SF64_None = 0 , +409: SF64_Exec = 1 , +410: SF64_Alloc = 2 , +411: SF64_Alloc_Exec = 3 , +412: SF64_Write = 4 , +413: SF64_Write_Exec = 5 , +414: SF64_Write_Alloc = 6 , +415: SF64_Write_Alloc_Exec = 7 +416: } s_flags64_e ; +417: +418: +419: local quad section_name_block_off ; +420: +421: typedef struct { +422: s_name32_e s_name_off < format = hex > ; +423: +424: local quad off = FTell ( ) ; +425: FSeek ( section_name_block_off + s_name_off ) ; +426: +427: string s_name_str ; +428: +429: FSeek ( off ) ; +430: } s_name32_t < read = SectionName > ; +431: +432: typedef s_name32_t s_name64_t ; +433: +434: string SectionName ( s_name32_t & sect ) { +435: if ( sect . s_name_off > SHN_UNDEF && sect . s_name_off < SHN_LORESERVE ) { +436: return sect . s_name_str ; +437: } +438: return ReservedSectionName ( sect . s_name_off ) ; +439: } +440: +441: typedef struct { +442: local quad off = FTell ( ) ; +443: +444: s_name64_t s_name ; +445: s_type64_e s_type ; +446: s_flags64_e s_flags ; +447: Elf64_Addr s_addr ; +448: Elf64_Off s_offset < format = hex > ; +449: Elf64_Xword s_size ; +450: Elf64_Word s_link ; +451: Elf64_Word s_info ; +452: Elf64_Xword s_addralign ; +453: Elf64_Xword s_entsize ; +454: +455: if ( s_type != SHT_NOBITS && s_type != SHT_NULL && s_size > 0 ) { +456: FSeek ( s_offset ) ; +457: +458: char data [ s_size ] ; +459: } +460: FSeek ( off + file . elf_header . e_shentzise_SECTION_HEADER_ENTRY_SIZE ) ; +461: } section_table_entry64_t < optimize = false > ; +462: +463: typedef struct { +464: local quad off = FTell ( ) ; +465: +466: s_name32_t s_name ; +467: s_type32_e s_type ; +468: s_flags32_e s_flags ; +469: Elf32_Addr s_addr ; +470: Elf32_Off s_offset < format = hex > ; +471: Elf32_Xword s_size ; +472: Elf32_Word s_link ; +473: Elf32_Word s_info ; +474: Elf32_Xword s_addralign ; +475: Elf32_Xword s_entsize ; +476: +477: if ( s_type != SHT_NOBITS && s_type != SHT_NULL && s_size > 0 ) { +478: FSeek ( s_offset ) ; +479: +480: char s_data [ s_size ] ; +481: } +482: FSeek ( off + file . elf_header . e_shentzise_SECTION_HEADER_ENTRY_SIZE ) ; +483: } section_table_entry32_t < read = SectionName32 , optimize = false > ; +484: +485: string SectionName64 ( section_table_entry64_t & sect ) { +486: return SectionName ( sect . s_name ) ; +487: } +488: +489: string SectionName32 ( section_table_entry32_t & sect ) { +490: return SectionName ( sect . s_name ) ; +491: } +492: +493: +494: +495: local quad symbol_name_block_off ; +496: +497: typedef struct { +498: Elf32_Word sym_name_off < format = hex > ; +499: +500: local quad off = FTell ( ) ; +501: FSeek ( symbol_name_block_off + sym_name_off ) ; +502: +503: string sym_name_str ; +504: +505: FSeek ( off ) ; +506: } sym_name32_t < read = SymbolName , optimize = false > ; +507: typedef sym_name32_t sym_name64_t ; +508: +509: string SymbolName ( sym_name32_t & sym ) { +510: if ( sym . sym_name_off > 0 ) { +511: return sym . sym_name_str ; +512: } +513: return "" ; +514: } +515: +516: typedef enum < unsigned char > { +517: STB_LOCAL = 0 , +518: STB_GLOBAL = 1 , +519: STB_WEAK = 2 , +520: STB_OS_1 = 10 , +521: STB_OS_2 = 11 , +522: STB_OS_3 = 12 , +523: STB_PROC_1 = 13 , +524: STB_PROC_2 = 14 , +525: STB_PROC_3 = 15 +526: } sym_info_bind_e ; +527: +528: typedef enum < unsigned char > { +529: STT_NOTYPE = 0 , +530: STT_OBJECT = 1 , +531: STT_FUNC = 2 , +532: STT_SECTION = 3 , +533: STT_FILE = 4 , +534: STT_OS_1 = 10 , +535: STT_OS_2 = 11 , +536: STT_OS_3 = 12 , +537: STT_PROC_1 = 13 , +538: STT_PROC_2 = 14 , +539: STT_PROC_3 = 15 +540: } sym_info_type_e ; +541: +542: typedef struct { +543: BitfieldDisablePadding ( ) ; +544: if ( IsBigEndian ( ) ) { +545: uchar sym_info_bind : 4 ; +546: uchar sym_info_type : 4 ; +547: } else { +548: uchar sym_info_type : 4 ; +549: uchar sym_info_bind : 4 ; +550: } +551: BitfieldEnablePadding ( ) ; +552: } sym_info_t < read = SymInfoEnums > ; +553: +554: string SymInfoEnums ( sym_info_t & info ) { +555: local sym_info_bind_e x = info . sym_info_bind ; +556: local sym_info_type_e y = info . sym_info_type ; +557: return EnumToString ( x ) + " | " + EnumToString ( y ) ; +558: } +559: +560: typedef struct { +561: Elf64_Word sym_name ; +562: unsigned char sym_info ; +563: unsigned char sym_other ; +564: Elf64_Half sym_shndx ; +565: Elf64_Addr sym_value ; +566: Elf64_Xword sym_size ; +567: } Elf64_Sym_fixed ; +568: +569: typedef struct { +570: Elf32_Word sym_name ; +571: Elf32_Addr sym_value ; +572: Elf32_Xword sym_size ; +573: unsigned char sym_info ; +574: unsigned char sym_other ; +575: Elf32_Half sym_shndx ; +576: } Elf32_Sym_fixed ; +577: +578: typedef struct { +579: sym_name64_t sym_name ; +580: sym_info_t sym_info ; +581: unsigned char sym_other ; +582: Elf64_Half sym_shndx ; +583: Elf64_Addr sym_value ; +584: Elf64_Xword sym_size ; +585: +586: if ( sym_size && SectionHasData ( sym_shndx ) ) { +587: local quad off = FTell ( ) ; +588: FSeek ( SectionVAddrOffset ( sym_shndx , sym_value ) ) ; +589: +590: char sym_data [ sym_size ] ; +591: +592: FSeek ( off ) ; +593: } +594: } Elf64_Sym < read = SymbolName64 , optimize = false > ; +595: +596: typedef struct { +597: sym_name32_t sym_name ; +598: Elf32_Addr sym_value ; +599: Elf32_Xword sym_size ; +600: sym_info_t sym_info ; +601: unsigned char sym_other ; +602: Elf32_Half sym_shndx ; +603: +604: if ( sym_size && SectionHasData ( sym_shndx ) ) { +605: local quad off = FTell ( ) ; +606: FSeek ( SectionVAddrOffset ( sym_shndx , sym_value ) ) ; +607: +608: char sym_data [ sym_size ] ; +609: +610: FSeek ( off ) ; +611: } +612: } Elf32_Sym < read = SymbolName32 , optimize = false > ; +613: +614: string SymbolName64 ( Elf64_Sym & sym ) { +615: return ( sym . sym_size ? "" : "[U] " ) + SymbolName ( sym . sym_name ) ; +616: } +617: +618: string SymbolName32 ( Elf32_Sym & sym ) { +619: return ( sym . sym_size ? "" : "[U] " ) + SymbolName ( sym . sym_name ) ; +620: } +621: +622: +623: +624: local int iter ; +625: +626: int FindNamedSection ( string sect ) { +627: +628: +629: for ( iter = 0 ; iter < file . elf_header . e_shnum_NUMBER_OF_SECTION_HEADER_ENTRIES ; iter ++ ) { +630: if ( Strcmp ( file . section_header_table . section_table_element [ iter ] . s_name . s_name_str , sect ) == 0 ) { +631: return iter ; +632: } +633: } +634: +635: return - 1 ; +636: } +637: +638: quad FindNamedSectionBlock ( string sect ) { +639: local int off = FindNamedSection ( sect ) ; +640: if ( off != - 1 ) +641: return file . section_header_table . section_table_element [ off ] . s_offset ; +642: +643: return - 1 ; +644: } +645: +646: int SectionHasData ( Elf64_Half s_index ) { +647: +648: if ( sec_tbl_elem [ s_index ] == - 1 ) { +649: sec_tbl_elem [ s_index ] = exists ( file . section_header_table . section_table_element [ s_index ] . s_data ) ; +650: } +651: return sec_tbl_elem [ s_index ] ; +652: } +653: +654: quad SectionVAddrOffset ( Elf64_Half s_index , Elf64_Addr s_vaddr ) { +655: if ( s_index < file . elf_header . e_shnum_NUMBER_OF_SECTION_HEADER_ENTRIES ) { +656: return file . section_header_table . section_table_element [ s_index ] . s_offset + s_vaddr - +657: file . section_header_table . section_table_element [ s_index ] . s_addr ; +658: } +659: return 0 ; +660: } +661: +662: +663: struct { +664: local int i ; +665: for ( i = 0 ; i < 255 ; i ++ ) { +666: sec_tbl_elem [ i ] = - 1 ; +667: } +668: +669: struct { +670: e_ident_t e_ident ; +671: if ( file . elf_header . e_ident . ei_class_2 == ELFCLASS32 ) +672: { +673: +674: e_type32_e e_type ; +675: e_machine32_e e_machine ; +676: e_version32_e e_version ; +677: Elf32_Addr e_entry_START_ADDRESS ; +678: Elf32_Off e_phoff_PROGRAM_HEADER_OFFSET_IN_FILE ; +679: Elf32_Off e_shoff_SECTION_HEADER_OFFSET_IN_FILE ; +680: Elf32_Word e_flags ; +681: Elf32_Half e_ehsize_ELF_HEADER_SIZE ; +682: Elf32_Half e_phentsize_PROGRAM_HEADER_ENTRY_SIZE_IN_FILE ; +683: Elf32_Half e_phnum_NUMBER_OF_PROGRAM_HEADER_ENTRIES ; +684: Elf32_Half e_shentzise_SECTION_HEADER_ENTRY_SIZE ; +685: Elf32_Half e_shnum_NUMBER_OF_SECTION_HEADER_ENTRIES ; +686: Elf32_Half e_shtrndx_STRING_TABLE_INDEX ; +687: } +688: else +689: { +690: +691: e_type64_e e_type ; +692: e_machine64_e e_machine ; +693: e_version64_e e_version ; +694: Elf64_Addr e_entry_START_ADDRESS ; +695: Elf64_Off e_phoff_PROGRAM_HEADER_OFFSET_IN_FILE ; +696: Elf64_Off e_shoff_SECTION_HEADER_OFFSET_IN_FILE ; +697: Elf32_Word e_flags ; +698: Elf64_Half e_ehsize_ELF_HEADER_SIZE ; +699: Elf64_Half e_phentsize_PROGRAM_HEADER_ENTRY_SIZE_IN_FILE ; +700: Elf64_Half e_phnum_NUMBER_OF_PROGRAM_HEADER_ENTRIES ; +701: Elf64_Half e_shentzise_SECTION_HEADER_ENTRY_SIZE ; +702: Elf64_Half e_shnum_NUMBER_OF_SECTION_HEADER_ENTRIES ; +703: Elf64_Half e_shtrndx_STRING_TABLE_INDEX ; +704: } +705: } elf_header ; +706: +707: +708: if ( file . elf_header . e_phnum_NUMBER_OF_PROGRAM_HEADER_ENTRIES > 0 ) { +709: FSeek ( file . elf_header . e_phoff_PROGRAM_HEADER_OFFSET_IN_FILE ) ; +710: struct { +711: if ( file . elf_header . e_ident . ei_class_2 == ELFCLASS32 ) { +712: program_table_entry32_t program_table_element [ file . elf_header . e_phnum_NUMBER_OF_PROGRAM_HEADER_ENTRIES ] ; +713: } else { +714: program_table_entry64_t program_table_element [ file . elf_header . e_phnum_NUMBER_OF_PROGRAM_HEADER_ENTRIES ] ; +715: } +716: } program_header_table ; +717: } +718: +719: +720: local quad section_name_off = +721: file . elf_header . e_shoff_SECTION_HEADER_OFFSET_IN_FILE + +722: ( file . elf_header . e_shentzise_SECTION_HEADER_ENTRY_SIZE * +723: file . elf_header . e_shtrndx_STRING_TABLE_INDEX ) ; +724: +725: +726: if ( file . elf_header . e_ident . ei_class_2 == ELFCLASS32 ) { +727: if ( FileSize ( ) >= section_name_off + 2 * sizeof ( Elf32_Word ) + +728: sizeof ( Elf32_Xword ) + sizeof ( Elf32_Addr ) ) +729: section_name_block_off = ReadUInt ( section_name_off + 2 * sizeof ( Elf32_Word ) + +730: sizeof ( Elf32_Xword ) + sizeof ( Elf32_Addr ) ) ; +731: else { +732: Printf ( "Invalid section header found, skipping!\n" ) ; +733: Warning ( "Invalid section header found, skipped and attempting to continue..." ) ; +734: } +735: } else { +736: if ( FileSize ( ) >= section_name_off + 2 * sizeof ( Elf64_Word ) + +737: sizeof ( Elf64_Xword ) + sizeof ( Elf64_Addr ) ) +738: section_name_block_off = ReadUQuad ( section_name_off + 2 * sizeof ( Elf64_Word ) + +739: sizeof ( Elf64_Xword ) + sizeof ( Elf64_Addr ) ) ; +740: else { +741: Printf ( "Invalid section header found, skipping!\n" ) ; +742: Warning ( "Invalid section header found, skipped and attempting to continue..." ) ; +743: } +744: } +745: +746: local int sec_tbl_cur_elem ; +747: +748: if ( file . elf_header . e_shnum_NUMBER_OF_SECTION_HEADER_ENTRIES > 0 ) { +749: FSeek ( file . elf_header . e_shoff_SECTION_HEADER_OFFSET_IN_FILE ) ; +750: struct { +751: if ( file . elf_header . e_ident . ei_class_2 == ELFCLASS32 ) { +752: sec_tbl_cur_elem = 0 ; +753: section_table_entry32_t section_table_element [ file . elf_header . e_shnum_NUMBER_OF_SECTION_HEADER_ENTRIES ] ; +754: } else { +755: sec_tbl_cur_elem = 0 ; +756: section_table_entry64_t section_table_element [ file . elf_header . e_shnum_NUMBER_OF_SECTION_HEADER_ENTRIES ] ; +757: } +758: } section_header_table ; +759: } +760: +761: local int sym_sect ; +762: local int sym_name_sect ; +763: +764: +765: sym_sect = FindNamedSection ( ".symtab" ) ; +766: if ( sym_sect >= 0 ) { +767: sym_name_sect = file . section_header_table . section_table_element [ sym_sect ] . s_link ; +768: symbol_name_block_off = file . section_header_table . section_table_element [ sym_name_sect ] . s_offset ; +769: +770: FSeek ( file . section_header_table . section_table_element [ sym_sect ] . s_offset ) ; +771: struct { +772: if ( file . elf_header . e_ident . ei_class_2 == ELFCLASS32 ) { +773: Elf32_Sym symtab [ file . section_header_table . section_table_element [ sym_sect ] . s_size / sizeof ( Elf32_Sym_fixed ) ] ; +774: } else { +775: Elf64_Sym symtab [ file . section_header_table . section_table_element [ sym_sect ] . s_size / sizeof ( Elf64_Sym_fixed ) ] ; +776: } +777: } symbol_table ; +778: } +779: +780: +781: sym_sect = FindNamedSection ( ".dynsym" ) ; +782: if ( sym_sect >= 0 ) { +783: sym_name_sect = file . section_header_table . section_table_element [ sym_sect ] . s_link ; +784: symbol_name_block_off = file . section_header_table . section_table_element [ sym_name_sect ] . s_offset ; +785: +786: FSeek ( file . section_header_table . section_table_element [ sym_sect ] . s_offset ) ; +787: struct { +788: if ( file . elf_header . e_ident . ei_class_2 == ELFCLASS32 ) { +789: Elf32_Sym symtab [ file . section_header_table . section_table_element [ sym_sect ] . s_size / sizeof ( Elf32_Sym_fixed ) ] ; +790: } else { +791: Elf64_Sym symtab [ file . section_header_table . section_table_element [ sym_sect ] . s_size / sizeof ( Elf64_Sym_fixed ) ] ; +792: } +793: } dynamic_symbol_table ; +794: } +795: } file ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/ELFTemplate.new.bt b/cparser/tests/exp_lex/ELFTemplate.new.bt new file mode 100644 index 0000000..a5eb71e --- /dev/null +++ b/cparser/tests/exp_lex/ELFTemplate.new.bt @@ -0,0 +1,795 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: +21: +22: +23: +24: +25: +26: +27: +28: +29: +30: local int sec_tbl_elem [ 255 ] ; +31: +32: typedef enum < uchar > { +33: ELFCLASSNONE = 0 , +34: ELFCLASS32 = 1 , +35: ELFCLASS64 = 2 +36: } ei_class_2_e ; +37: +38: typedef enum < uchar > { +39: ELFDATAONE = 0 , +40: ELFDATA2LSB = 1 , +41: ELFDATA2MSB = 2 +42: } ei_data_e ; +43: +44: typedef enum < uchar > { +45: E_NONE = 0 , +46: E_CURRENT = 1 +47: } ei_version_e ; +48: +49: typedef enum < uchar > { +50: ELFOSABI_NONE = 0 , +51: ELFOSABI_HPUX = 1 , +52: ELFOSABI_NETBSD = 2 , +53: ELFOSABI_SOLARIS = 6 , +54: ELFOSABI_AIX = 7 , +55: ELFOSABI_IRIX = 8 , +56: ELFOSABI_FREEBSD = 9 , +57: ELFOSABI_TRU64 = 10 , +58: ELFOSABI_MODESTO = 11 , +59: ELFOSABI_OPENBSD = 12 , +60: ELFOSABI_OPENVMS = 13 , +61: ELFOSABI_NSK = 14 , +62: ELFOSABI_AROS = 15 +63: } ei_osabi_e ; +64: +65: +66: typedef struct { +67: char file_identification [ 4 ] ; +68: ei_class_2_e ei_class_2 ; +69: ei_data_e ei_data ; +70: if ( ei_data == ELFDATA2LSB ) { +71: LittleEndian ( ) ; +72: } else { +73: BigEndian ( ) ; +74: } +75: ei_version_e ei_version ; +76: ei_osabi_e ei_osabi ; +77: uchar ei_abiversion ; +78: uchar ei_pad [ 6 ] ; +79: uchar ei_nident_SIZE ; +80: } e_ident_t ; +81: +82: +83: +84: typedef uint32 Elf32_Word ; +85: typedef uint32 Elf32_Off ; +86: typedef uint32 Elf32_Addr < read = VAddr32 > ; +87: typedef uint16 Elf32_Half ; +88: typedef uint32 Elf32_Xword ; +89: +90: typedef uint32 Elf64_Word ; +91: typedef uint64 Elf64_Off ; +92: typedef uint64 Elf64_Addr < read = VAddr64 > ; +93: typedef uint16 Elf64_Half ; +94: typedef uint64 Elf64_Xword ; +95: +96: string VAddr32 ( Elf32_Addr & addr ) { +97: local char buf [ 128 ] ; +98: SPrintf ( buf , "0x%08X" , addr ) ; +99: return buf ; +100: } +101: +102: string VAddr64 ( Elf64_Addr & addr ) { +103: local char buf [ 128 ] ; +104: SPrintf ( buf , "0x%016LX" , addr ) ; +105: return buf ; +106: } +107: +108: typedef enum < Elf32_Half > { +109: ET_NONE = 0 , +110: ET_REL = 1 , +111: ET_EXEC = 2 , +112: ET_DYN = 3 , +113: ET_CORE = 4 , +114: ET_LOOS = 0xFE00 , +115: ET_HIOS = 0xFEFF , +116: ET_LOPROC = 0xFF00 , +117: ET_HIPROC = 0xFFFF +118: } e_type32_e ; +119: typedef e_type32_e e_type64_e ; +120: +121: typedef enum < Elf32_Half > { +122: EM_NONE = 0 , +123: EM_M32 = 1 , +124: EM_SPARC = 2 , +125: EM_386 = 3 , +126: EM_68K = 4 , +127: EM_88K = 5 , +128: reserved6 = 6 , +129: EM_860 = 7 , +130: EM_MIPS = 8 , +131: EM_S370 = 9 , +132: EM_MIPS_RS3_LE = 10 , +133: reserved11 = 11 , +134: reserved12 = 12 , +135: reserved13 = 13 , +136: reserved14 = 14 , +137: EM_PARISC = 15 , +138: reserved16 = 16 , +139: EM_VPP500 = 17 , +140: EM_SPARC32PLUS = 18 , +141: EM_960 = 19 , +142: EM_PPC = 20 , +143: EM_PPC64 = 21 , +144: EM_S390 = 22 , +145: reserved23 = 23 , +146: reserved24 = 24 , +147: reserved25 = 25 , +148: reserved26 = 26 , +149: reserved27 = 27 , +150: reserved28 = 28 , +151: reserved29 = 29 , +152: reserved30 = 30 , +153: reserved31 = 31 , +154: reserved32 = 32 , +155: reserved33 = 33 , +156: reserved34 = 34 , +157: reserved35 = 35 , +158: EM_V800 = 36 , +159: EM_FR20 = 37 , +160: EM_RH32 = 38 , +161: EM_RCE = 39 , +162: EM_ARM = 40 , +163: EM_ALPHA = 41 , +164: EM_SH = 42 , +165: EM_SPARCV9 = 43 , +166: EM_TRICORE = 44 , +167: EM_ARC = 45 , +168: EM_H8_300 = 46 , +169: EM_H8_300H = 47 , +170: EM_H8S = 48 , +171: EM_H8_500 = 49 , +172: EM_IA_64 = 50 , +173: EM_MIPS_X = 51 , +174: EM_COLDFIRE = 52 , +175: EM_68HC12 = 53 , +176: EM_MMA = 54 , +177: EM_PCP = 55 , +178: EM_NCPU = 56 , +179: EM_NDR1 = 57 , +180: EM_STARCORE = 58 , +181: EM_ME16 = 59 , +182: EM_ST100 = 60 , +183: EM_TINYJ = 61 , +184: EM_X86_64 = 62 , +185: EM_PDSP = 63 , +186: EM_PDP10 = 64 , +187: EM_PDP11 = 65 , +188: EM_FX66 = 66 , +189: EM_ST9PLUS = 67 , +190: EM_ST7 = 68 , +191: EM_68HC16 = 69 , +192: EM_68HC11 = 70 , +193: EM_68HC08 = 71 , +194: EM_68HC05 = 72 , +195: EM_SVX = 73 , +196: EM_ST19 = 75 , +197: EM_CRIS = 76 , +198: EM_JAVELIN = 77 , +199: EM_FIREPATH = 78 , +200: EM_ZSP = 79 , +201: EM_MMIX = 80 , +202: EM_HUANY = 81 , +203: EM_PRISM = 82 , +204: EM_AVR = 83 , +205: EM_FR30 = 84 , +206: EM_D10V = 85 , +207: EM_D30V = 86 , +208: EM_V850 = 87 , +209: EM_M32R = 88 , +210: EM_MN10300 = 89 , +211: EM_MN10200 = 90 , +212: EM_PJ = 91 , +213: EM_OPENRISC = 92 , +214: EM_ARC_A5 = 93 , +215: EM_XTENSA = 94 , +216: EM_VIDEOCORE = 95 , +217: EM_TMM_GPP = 96 , +218: EM_NS32K = 97 , +219: EM_TPC = 98 , +220: EM_SNP1K = 99 , +221: EM_ST200 = 100 , +222: EM_IP2K = 101 , +223: EM_MAX = 102 , +224: EM_CR = 103 , +225: EM_F2MC16 = 104 , +226: EM_MSP430 = 105 , +227: EM_BLACKFIN = 106 , +228: EM_SE_C33 = 107 , +229: EM_SEP = 108 , +230: EM_ARCA = 109 , +231: EM_UNICORE = 110 +232: } e_machine32_e ; +233: +234: typedef e_machine32_e e_machine64_e ; +235: +236: typedef enum < Elf32_Word > { +237: EV_NONE = 0 , +238: EV_CURRENT = 1 +239: } e_version32_e ; +240: typedef e_version32_e e_version64_e ; +241: +242: +243: +244: typedef enum < Elf32_Word > { +245: PT_NULL = 0 , +246: PT_LOAD = 1 , +247: PT_DYNAMIC = 2 , +248: PT_INERP = 3 , +249: PT_NOTE = 4 , +250: PT_SHLIB = 5 , +251: PT_PHDR = 6 , +252: PT_LOOS = 0x60000000 , +253: PT_HIOS = 0x6FFFFFFF , +254: PT_LOPROC = 0x70000000 , +255: PT_HIPROC = 0x7FFFFFFF +256: } p_type32_e ; +257: typedef p_type32_e p_type64_e ; +258: +259: typedef enum < Elf32_Word > { +260: PF_None = 0 , +261: PF_Exec = 1 , +262: PF_Write = 2 , +263: PF_Write_Exec = 3 , +264: PF_Read = 4 , +265: PF_Read_Exec = 5 , +266: PF_Read_Write = 6 , +267: PF_Read_Write_Exec = 7 +268: } p_flags32_e ; +269: typedef p_flags32_e p_flags64_e ; +270: +271: typedef enum < Elf32_Word > { +272: SHN_UNDEF = 0 , +273: SHN_LORESERVE = 0xFF00 , +274: SHN_LOPROC = 0xFF00 , +275: SHN_HIPROC = 0xFF1F , +276: SHN_LOOS = 0xFF20 , +277: SHN_HIOS = 0xFF3F , +278: SHN_ABS = 0xFFF1 , +279: SHN_COMMON = 0xFFF2 , +280: SHN_HIRESERVE = 0xFFFF +281: } s_name32_e ; +282: typedef s_name32_e s_name64_e ; +283: +284: typedef enum < Elf32_Word > { +285: SHT_NULL = 0 , +286: SHT_PROGBITS = 1 , +287: SHT_SYMTAB = 2 , +288: SHT_STRTAB = 3 , +289: SHT_RELA = 4 , +290: SHT_HASH = 5 , +291: SHT_DYNAMIC = 6 , +292: SHT_NOTE = 7 , +293: SHT_NOBITS = 8 , +294: SHT_REL = 9 , +295: SHT_SHLIB = 10 , +296: SHT_DYNSYM = 11 , +297: +298: SHT_LOOS = 0x60000000 , +299: SHT_HIOS = 0x6FFFFFFF , +300: +301: SHT_LOPROC = 0x70000000 , +302: SHT_HIPROC = 0x7FFFFFFF +303: } s_type32_e ; +304: typedef s_type32_e s_type64_e ; +305: +306: string ReservedSectionName ( s_name32_e id ) { +307: local char buf [ 255 ] ; +308: if ( id == SHN_UNDEF ) return "SHN_UNDEF" ; +309: if ( id >= SHN_LOPROC && id <= SHN_HIPROC ) { +310: SPrintf ( buf , "SHN_PROC_%02X" , id - SHN_LOPROC ) ; +311: return buf ; +312: } +313: if ( id >= SHN_LOOS && id <= SHN_HIOS ) { +314: SPrintf ( buf , "SHN_OS_%02X" , id - SHN_LOOS ) ; +315: return buf ; +316: } +317: if ( id == SHN_ABS ) return "SHN_ABS" ; +318: if ( id == SHN_COMMON ) return "SHN_COMMON" ; +319: +320: SPrintf ( buf , "SHN_RESERVE_%02X" , id - SHN_LORESERVE ) ; +321: return buf ; +322: } +323: +324: +325: typedef struct { +326: local quad off = FTell ( ) ; +327: +328: p_type32_e p_type ; +329: Elf32_Off p_offset_FROM_FILE_BEGIN < format = hex > ; +330: Elf32_Addr p_vaddr_VIRTUAL_ADDRESS ; +331: Elf32_Addr p_paddr_PHYSICAL_ADDRESS ; +332: Elf32_Word p_filesz_SEGMENT_FILE_LENGTH ; +333: Elf32_Word p_memsz_SEGMENT_RAM_LENGTH ; +334: p_flags32_e p_flags ; +335: Elf32_Word p_align ; +336: +337: if ( p_filesz_SEGMENT_FILE_LENGTH > 0 ) { +338: FSeek ( p_offset_FROM_FILE_BEGIN ) ; +339: char p_data [ p_filesz_SEGMENT_FILE_LENGTH ] ; +340: } +341: +342: FSeek ( off + file . elf_header . e_phentsize_PROGRAM_HEADER_ENTRY_SIZE_IN_FILE ) ; +343: } program_table_entry32_t < read = ProgramInfo32 , optimize = false > ; +344: typedef struct { +345: local quad off = FTell ( ) ; +346: +347: p_type64_e p_type ; +348: p_flags64_e p_flags ; +349: Elf64_Off p_offset_FROM_FILE_BEGIN < format = hex > ; +350: Elf64_Addr p_vaddr_VIRTUAL_ADDRESS ; +351: Elf64_Addr p_paddr_PHYSICAL_ADDRESS ; +352: Elf64_Xword p_filesz_SEGMENT_FILE_LENGTH ; +353: Elf64_Xword p_memsz_SEGMENT_RAM_LENGTH ; +354: Elf64_Xword p_align ; +355: +356: if ( p_filesz_SEGMENT_FILE_LENGTH > 0 ) { +357: FSeek ( p_offset_FROM_FILE_BEGIN ) ; +358: char p_data [ p_filesz_SEGMENT_FILE_LENGTH ] ; +359: } +360: +361: FSeek ( off + file . elf_header . e_phentsize_PROGRAM_HEADER_ENTRY_SIZE_IN_FILE ) ; +362: } program_table_entry64_t < read = ProgramInfo64 , optimize = false > ; +363: +364: string ProgramType ( p_type64_e type ) { +365: switch ( type ) { +366: case PT_NULL : return "NULL" ; +367: case PT_LOAD : return "Loadable Segment" ; +368: case PT_DYNAMIC : return "Dynamic Segment" ; +369: case PT_INERP : return "Interpreter Path" ; +370: case PT_NOTE : return "Note" ; +371: case PT_SHLIB : return "PT_SHLIB" ; +372: case PT_PHDR : return "Program Header" ; +373: default : return "Unknown Section" ; +374: } +375: } +376: +377: string ProgramFlags ( p_flags64_e flags ) { +378: local string rv = "(" ; +379: +380: rv += ( flags & PF_Read ) ? "R" : "_" ; +381: rv += ( flags & PF_Write ) ? "W" : "_" ; +382: rv += ( flags & PF_Exec ) ? "X" : "_" ; +383: rv += ")" ; +384: return rv ; +385: } +386: +387: string ProgramInfo64 ( program_table_entry64_t & ent ) { +388: return ProgramFlags ( ent . p_flags ) + " " + ProgramType ( ent . p_type ) ; +389: } +390: +391: string ProgramInfo32 ( program_table_entry32_t & ent ) { +392: return ProgramFlags ( ent . p_flags ) + " " + ProgramType ( ent . p_type ) ; +393: } +394: +395: +396: +397: typedef enum < Elf32_Xword > { +398: SF32_None = 0 , +399: SF32_Exec = 1 , +400: SF32_Alloc = 2 , +401: SF32_Alloc_Exec = 3 , +402: SF32_Write = 4 , +403: SF32_Write_Exec = 5 , +404: SF32_Write_Alloc = 6 , +405: SF32_Write_Alloc_Exec = 7 +406: } s_flags32_e ; +407: typedef enum < Elf64_Xword > { +408: SF64_None = 0 , +409: SF64_Exec = 1 , +410: SF64_Alloc = 2 , +411: SF64_Alloc_Exec = 3 , +412: SF64_Write = 4 , +413: SF64_Write_Exec = 5 , +414: SF64_Write_Alloc = 6 , +415: SF64_Write_Alloc_Exec = 7 +416: } s_flags64_e ; +417: +418: +419: local quad section_name_block_off ; +420: +421: typedef struct { +422: s_name32_e s_name_off < format = hex > ; +423: +424: local quad off = FTell ( ) ; +425: FSeek ( section_name_block_off + s_name_off ) ; +426: +427: string s_name_str ; +428: +429: FSeek ( off ) ; +430: } s_name32_t < read = SectionName > ; +431: +432: typedef s_name32_t s_name64_t ; +433: +434: string SectionName ( s_name32_t & sect ) { +435: if ( sect . s_name_off > SHN_UNDEF && sect . s_name_off < SHN_LORESERVE ) { +436: return sect . s_name_str ; +437: } +438: return ReservedSectionName ( sect . s_name_off ) ; +439: } +440: +441: typedef struct { +442: local quad off = FTell ( ) ; +443: +444: s_name64_t s_name ; +445: s_type64_e s_type ; +446: s_flags64_e s_flags ; +447: Elf64_Addr s_addr ; +448: Elf64_Off s_offset < format = hex > ; +449: Elf64_Xword s_size ; +450: Elf64_Word s_link ; +451: Elf64_Word s_info ; +452: Elf64_Xword s_addralign ; +453: Elf64_Xword s_entsize ; +454: +455: if ( s_type != SHT_NOBITS && s_type != SHT_NULL && s_size > 0 ) { +456: FSeek ( s_offset ) ; +457: +458: char data [ s_size ] ; +459: } +460: FSeek ( off + file . elf_header . e_shentzise_SECTION_HEADER_ENTRY_SIZE ) ; +461: } section_table_entry64_t < optimize = false > ; +462: +463: typedef struct { +464: local quad off = FTell ( ) ; +465: +466: s_name32_t s_name ; +467: s_type32_e s_type ; +468: s_flags32_e s_flags ; +469: Elf32_Addr s_addr ; +470: Elf32_Off s_offset < format = hex > ; +471: Elf32_Xword s_size ; +472: Elf32_Word s_link ; +473: Elf32_Word s_info ; +474: Elf32_Xword s_addralign ; +475: Elf32_Xword s_entsize ; +476: +477: if ( s_type != SHT_NOBITS && s_type != SHT_NULL && s_size > 0 ) { +478: FSeek ( s_offset ) ; +479: +480: char s_data [ s_size ] ; +481: } +482: FSeek ( off + file . elf_header . e_shentzise_SECTION_HEADER_ENTRY_SIZE ) ; +483: } section_table_entry32_t < read = SectionName32 , optimize = false > ; +484: +485: string SectionName64 ( section_table_entry64_t & sect ) { +486: return SectionName ( sect . s_name ) ; +487: } +488: +489: string SectionName32 ( section_table_entry32_t & sect ) { +490: return SectionName ( sect . s_name ) ; +491: } +492: +493: +494: +495: local quad symbol_name_block_off ; +496: +497: typedef struct { +498: Elf32_Word sym_name_off < format = hex > ; +499: +500: local quad off = FTell ( ) ; +501: FSeek ( symbol_name_block_off + sym_name_off ) ; +502: +503: string sym_name_str ; +504: +505: FSeek ( off ) ; +506: } sym_name32_t < read = SymbolName , optimize = false > ; +507: typedef sym_name32_t sym_name64_t ; +508: +509: string SymbolName ( sym_name32_t & sym ) { +510: if ( sym . sym_name_off > 0 ) { +511: return sym . sym_name_str ; +512: } +513: return "" ; +514: } +515: +516: typedef enum < unsigned char > { +517: STB_LOCAL = 0 , +518: STB_GLOBAL = 1 , +519: STB_WEAK = 2 , +520: STB_OS_1 = 10 , +521: STB_OS_2 = 11 , +522: STB_OS_3 = 12 , +523: STB_PROC_1 = 13 , +524: STB_PROC_2 = 14 , +525: STB_PROC_3 = 15 +526: } sym_info_bind_e ; +527: +528: typedef enum < unsigned char > { +529: STT_NOTYPE = 0 , +530: STT_OBJECT = 1 , +531: STT_FUNC = 2 , +532: STT_SECTION = 3 , +533: STT_FILE = 4 , +534: STT_OS_1 = 10 , +535: STT_OS_2 = 11 , +536: STT_OS_3 = 12 , +537: STT_PROC_1 = 13 , +538: STT_PROC_2 = 14 , +539: STT_PROC_3 = 15 +540: } sym_info_type_e ; +541: +542: typedef struct { +543: BitfieldDisablePadding ( ) ; +544: if ( IsBigEndian ( ) ) { +545: uchar sym_info_bind : 4 ; +546: uchar sym_info_type : 4 ; +547: } else { +548: uchar sym_info_type : 4 ; +549: uchar sym_info_bind : 4 ; +550: } +551: BitfieldEnablePadding ( ) ; +552: } sym_info_t < read = SymInfoEnums > ; +553: +554: string SymInfoEnums ( sym_info_t & info ) { +555: local sym_info_bind_e x = info . sym_info_bind ; +556: local sym_info_type_e y = info . sym_info_type ; +557: return EnumToString ( x ) + " | " + EnumToString ( y ) ; +558: } +559: +560: typedef struct { +561: Elf64_Word sym_name ; +562: unsigned char sym_info ; +563: unsigned char sym_other ; +564: Elf64_Half sym_shndx ; +565: Elf64_Addr sym_value ; +566: Elf64_Xword sym_size ; +567: } Elf64_Sym_fixed ; +568: +569: typedef struct { +570: Elf32_Word sym_name ; +571: Elf32_Addr sym_value ; +572: Elf32_Xword sym_size ; +573: unsigned char sym_info ; +574: unsigned char sym_other ; +575: Elf32_Half sym_shndx ; +576: } Elf32_Sym_fixed ; +577: +578: typedef struct { +579: sym_name64_t sym_name ; +580: sym_info_t sym_info ; +581: unsigned char sym_other ; +582: Elf64_Half sym_shndx ; +583: Elf64_Addr sym_value ; +584: Elf64_Xword sym_size ; +585: +586: if ( sym_size && SectionHasData ( sym_shndx ) ) { +587: local quad off = FTell ( ) ; +588: FSeek ( SectionVAddrOffset ( sym_shndx , sym_value ) ) ; +589: +590: char sym_data [ sym_size ] ; +591: +592: FSeek ( off ) ; +593: } +594: } Elf64_Sym < read = SymbolName64 , optimize = false > ; +595: +596: typedef struct { +597: sym_name32_t sym_name ; +598: Elf32_Addr sym_value ; +599: Elf32_Xword sym_size ; +600: sym_info_t sym_info ; +601: unsigned char sym_other ; +602: Elf32_Half sym_shndx ; +603: +604: if ( sym_size && SectionHasData ( sym_shndx ) ) { +605: local quad off = FTell ( ) ; +606: FSeek ( SectionVAddrOffset ( sym_shndx , sym_value ) ) ; +607: +608: char sym_data [ sym_size ] ; +609: +610: FSeek ( off ) ; +611: } +612: } Elf32_Sym < read = SymbolName32 , optimize = false > ; +613: +614: string SymbolName64 ( Elf64_Sym & sym ) { +615: return ( sym . sym_size ? "" : "[U] " ) + SymbolName ( sym . sym_name ) ; +616: } +617: +618: string SymbolName32 ( Elf32_Sym & sym ) { +619: return ( sym . sym_size ? "" : "[U] " ) + SymbolName ( sym . sym_name ) ; +620: } +621: +622: +623: +624: local int iter ; +625: +626: int FindNamedSection ( string sect ) { +627: +628: +629: for ( iter = 0 ; iter < file . elf_header . e_shnum_NUMBER_OF_SECTION_HEADER_ENTRIES ; iter ++ ) { +630: if ( Strcmp ( file . section_header_table . section_table_element [ iter ] . s_name . s_name_str , sect ) == 0 ) { +631: return iter ; +632: } +633: } +634: +635: return - 1 ; +636: } +637: +638: quad FindNamedSectionBlock ( string sect ) { +639: local int off = FindNamedSection ( sect ) ; +640: if ( off != - 1 ) +641: return file . section_header_table . section_table_element [ off ] . s_offset ; +642: +643: return - 1 ; +644: } +645: +646: int SectionHasData ( Elf64_Half s_index ) { +647: +648: if ( sec_tbl_elem [ s_index ] == - 1 ) { +649: sec_tbl_elem [ s_index ] = exists ( file . section_header_table . section_table_element [ s_index ] . s_data ) ; +650: } +651: return sec_tbl_elem [ s_index ] ; +652: } +653: +654: quad SectionVAddrOffset ( Elf64_Half s_index , Elf64_Addr s_vaddr ) { +655: if ( s_index < file . elf_header . e_shnum_NUMBER_OF_SECTION_HEADER_ENTRIES ) { +656: return file . section_header_table . section_table_element [ s_index ] . s_offset + s_vaddr - +657: file . section_header_table . section_table_element [ s_index ] . s_addr ; +658: } +659: return 0 ; +660: } +661: +662: +663: struct { +664: local int i ; +665: for ( i = 0 ; i < 255 ; i ++ ) { +666: sec_tbl_elem [ i ] = - 1 ; +667: } +668: +669: struct { +670: e_ident_t e_ident ; +671: if ( file . elf_header . e_ident . ei_class_2 == ELFCLASS32 ) +672: { +673: +674: e_type32_e e_type ; +675: e_machine32_e e_machine ; +676: e_version32_e e_version ; +677: Elf32_Addr e_entry_START_ADDRESS ; +678: Elf32_Off e_phoff_PROGRAM_HEADER_OFFSET_IN_FILE ; +679: Elf32_Off e_shoff_SECTION_HEADER_OFFSET_IN_FILE ; +680: Elf32_Word e_flags ; +681: Elf32_Half e_ehsize_ELF_HEADER_SIZE ; +682: Elf32_Half e_phentsize_PROGRAM_HEADER_ENTRY_SIZE_IN_FILE ; +683: Elf32_Half e_phnum_NUMBER_OF_PROGRAM_HEADER_ENTRIES ; +684: Elf32_Half e_shentzise_SECTION_HEADER_ENTRY_SIZE ; +685: Elf32_Half e_shnum_NUMBER_OF_SECTION_HEADER_ENTRIES ; +686: Elf32_Half e_shtrndx_STRING_TABLE_INDEX ; +687: } +688: else +689: { +690: +691: e_type64_e e_type ; +692: e_machine64_e e_machine ; +693: e_version64_e e_version ; +694: Elf64_Addr e_entry_START_ADDRESS ; +695: Elf64_Off e_phoff_PROGRAM_HEADER_OFFSET_IN_FILE ; +696: Elf64_Off e_shoff_SECTION_HEADER_OFFSET_IN_FILE ; +697: Elf32_Word e_flags ; +698: Elf64_Half e_ehsize_ELF_HEADER_SIZE ; +699: Elf64_Half e_phentsize_PROGRAM_HEADER_ENTRY_SIZE_IN_FILE ; +700: Elf64_Half e_phnum_NUMBER_OF_PROGRAM_HEADER_ENTRIES ; +701: Elf64_Half e_shentzise_SECTION_HEADER_ENTRY_SIZE ; +702: Elf64_Half e_shnum_NUMBER_OF_SECTION_HEADER_ENTRIES ; +703: Elf64_Half e_shtrndx_STRING_TABLE_INDEX ; +704: } +705: } elf_header ; +706: +707: +708: if ( file . elf_header . e_phnum_NUMBER_OF_PROGRAM_HEADER_ENTRIES > 0 ) { +709: FSeek ( file . elf_header . e_phoff_PROGRAM_HEADER_OFFSET_IN_FILE ) ; +710: struct { +711: if ( file . elf_header . e_ident . ei_class_2 == ELFCLASS32 ) { +712: program_table_entry32_t program_table_element [ file . elf_header . e_phnum_NUMBER_OF_PROGRAM_HEADER_ENTRIES ] ; +713: } else { +714: program_table_entry64_t program_table_element [ file . elf_header . e_phnum_NUMBER_OF_PROGRAM_HEADER_ENTRIES ] ; +715: } +716: } program_header_table ; +717: } +718: +719: +720: local quad section_name_off = +721: file . elf_header . e_shoff_SECTION_HEADER_OFFSET_IN_FILE + +722: ( file . elf_header . e_shentzise_SECTION_HEADER_ENTRY_SIZE * +723: file . elf_header . e_shtrndx_STRING_TABLE_INDEX ) ; +724: +725: +726: if ( file . elf_header . e_ident . ei_class_2 == ELFCLASS32 ) { +727: if ( FileSize ( ) >= section_name_off + 2 * sizeof ( Elf32_Word ) + +728: sizeof ( Elf32_Xword ) + sizeof ( Elf32_Addr ) ) +729: section_name_block_off = ReadUInt ( section_name_off + 2 * sizeof ( Elf32_Word ) + +730: sizeof ( Elf32_Xword ) + sizeof ( Elf32_Addr ) ) ; +731: else { +732: Printf ( "Invalid section header found, skipping!\n" ) ; +733: Warning ( "Invalid section header found, skipped and attempting to continue..." ) ; +734: } +735: } else { +736: if ( FileSize ( ) >= section_name_off + 2 * sizeof ( Elf64_Word ) + +737: sizeof ( Elf64_Xword ) + sizeof ( Elf64_Addr ) ) +738: section_name_block_off = ReadUQuad ( section_name_off + 2 * sizeof ( Elf64_Word ) + +739: sizeof ( Elf64_Xword ) + sizeof ( Elf64_Addr ) ) ; +740: else { +741: Printf ( "Invalid section header found, skipping!\n" ) ; +742: Warning ( "Invalid section header found, skipped and attempting to continue..." ) ; +743: } +744: } +745: +746: local int sec_tbl_cur_elem ; +747: +748: if ( file . elf_header . e_shnum_NUMBER_OF_SECTION_HEADER_ENTRIES > 0 ) { +749: FSeek ( file . elf_header . e_shoff_SECTION_HEADER_OFFSET_IN_FILE ) ; +750: struct { +751: if ( file . elf_header . e_ident . ei_class_2 == ELFCLASS32 ) { +752: sec_tbl_cur_elem = 0 ; +753: section_table_entry32_t section_table_element [ file . elf_header . e_shnum_NUMBER_OF_SECTION_HEADER_ENTRIES ] ; +754: } else { +755: sec_tbl_cur_elem = 0 ; +756: section_table_entry64_t section_table_element [ file . elf_header . e_shnum_NUMBER_OF_SECTION_HEADER_ENTRIES ] ; +757: } +758: } section_header_table ; +759: } +760: +761: local int sym_sect ; +762: local int sym_name_sect ; +763: +764: +765: sym_sect = FindNamedSection ( ".symtab" ) ; +766: if ( sym_sect >= 0 ) { +767: sym_name_sect = file . section_header_table . section_table_element [ sym_sect ] . s_link ; +768: symbol_name_block_off = file . section_header_table . section_table_element [ sym_name_sect ] . s_offset ; +769: +770: FSeek ( file . section_header_table . section_table_element [ sym_sect ] . s_offset ) ; +771: struct { +772: if ( file . elf_header . e_ident . ei_class_2 == ELFCLASS32 ) { +773: Elf32_Sym symtab [ file . section_header_table . section_table_element [ sym_sect ] . s_size / sizeof ( Elf32_Sym_fixed ) ] ; +774: } else { +775: Elf64_Sym symtab [ file . section_header_table . section_table_element [ sym_sect ] . s_size / sizeof ( Elf64_Sym_fixed ) ] ; +776: } +777: } symbol_table ; +778: } +779: +780: +781: sym_sect = FindNamedSection ( ".dynsym" ) ; +782: if ( sym_sect >= 0 ) { +783: sym_name_sect = file . section_header_table . section_table_element [ sym_sect ] . s_link ; +784: symbol_name_block_off = file . section_header_table . section_table_element [ sym_name_sect ] . s_offset ; +785: +786: FSeek ( file . section_header_table . section_table_element [ sym_sect ] . s_offset ) ; +787: struct { +788: if ( file . elf_header . e_ident . ei_class_2 == ELFCLASS32 ) { +789: Elf32_Sym symtab [ file . section_header_table . section_table_element [ sym_sect ] . s_size / sizeof ( Elf32_Sym_fixed ) ] ; +790: } else { +791: Elf64_Sym symtab [ file . section_header_table . section_table_element [ sym_sect ] . s_size / sizeof ( Elf64_Sym_fixed ) ] ; +792: } +793: } dynamic_symbol_table ; +794: } +795: } file ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/EMFTemplate.bt b/cparser/tests/exp_lex/EMFTemplate.bt new file mode 100644 index 0000000..15723cd --- /dev/null +++ b/cparser/tests/exp_lex/EMFTemplate.bt @@ -0,0 +1,222 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: typedef enum < DWORD > { +14: EMR_HEADER = 0x1 , +15: EMR_POLYBEZIER = 0x2 , +16: EMR_POLYGON = 0x3 , +17: EMR_POLYLINE = 0x4 , +18: EMR_POLYBEZIERTO = 0x5 , +19: EMR_POLYLINETO = 0x6 , +20: EMR_POLYPOLYLINE = 0x7 , +21: EMR_POLYPOLYGON = 0x8 , +22: EMR_SETWINDOWEXTEX = 0x9 , +23: EMR_SETWINDOWORGEX = 0xA , +24: EMR_SETVIEWPORTEXTEX = 0xB , +25: EMR_SETVIEWPORTORGEX = 0xC , +26: EMR_SETBRUSHORGEX = 0xD , +27: EMR_EOF = 0xE , +28: EMR_SETPIXELV = 0xF , +29: EMR_SETMAPPERFLAGS = 0x10 , +30: EMR_SETMAPMODE = 0x11 , +31: EMR_SETBKMODE = 0x12 , +32: EMR_SETPOLYFILLMODE = 0x13 , +33: EMR_SETROP2 = 0x14 , +34: EMR_SETSTRETCHBLTMODE = 0x15 , +35: EMR_SETTEXTALIGN = 0x16 , +36: EMR_SETCOLORADJUSTMENT = 0x17 , +37: EMR_SETTEXTCOLOR = 0x18 , +38: EMR_SETBKCOLOR = 0x19 , +39: EMR_OFFSETCLIPRGN = 0x1A , +40: EMR_MOVETOEX = 0x1B , +41: EMR_SETMETARGN = 0x1C , +42: EMR_EXCLUDECLIPRECT = 0x1D , +43: EMR_INTERSECTCLIPRECT = 0x1E , +44: EMR_SCALEVIEWPORTEXTEX = 0x1F , +45: EMR_SCALEWINDOWEXTEX = 0x20 , +46: EMR_SAVEDC = 0x21 , +47: EMR_RESTOREDC = 0x22 , +48: EMR_SETWORLDTRANSFORM = 0x23 , +49: EMR_MODIFYWORLDTRANSFORM = 0x24 , +50: EMR_SELECTOBJECT = 0x25 , +51: EMR_CREATEPEN = 0x26 , +52: EMR_CREATEBRUSHINDIRECT = 0x27 , +53: EMR_DELETEOBJECT = 0x28 , +54: EMR_ANGLEARC = 0x29 , +55: EMR_ELLIPSE = 0x2A , +56: EMR_RECTANGLE = 0x2B , +57: EMR_ROUNDRECT = 0x2C , +58: EMR_ARC = 0x2D , +59: EMR_CHORD = 0x2E , +60: EMR_PIE = 0x2F , +61: EMR_SELECTPALETTE = 0x30 , +62: EMR_CREATEPALETTE = 0x31 , +63: EMR_SETPALETTEENTRIES = 0x32 , +64: EMR_RESIZEPALETTE = 0x33 , +65: EMR_REALIZEPALETTE = 0x34 , +66: EMR_EXTFLOODFILL = 0x35 , +67: EMR_LINETO = 0x36 , +68: EMR_ARCTO = 0x37 , +69: EMR_POLYDRAW = 0x38 , +70: EMR_SETARCDIRECTION = 0x39 , +71: EMR_SETMITERLIMIT = 0x3A , +72: EMR_BEGINPATH = 0x3B , +73: EMR_ENDPATH = 0x3C , +74: EMR_CLOSEFIGURE = 0x3D , +75: EMR_FILLPATH = 0x3E , +76: EMR_STROKEANDFILLPATH = 0x3F , +77: EMR_STROKEPATH = 0x40 , +78: EMR_FLATTENPATH = 0x41 , +79: EMR_WIDENPATH = 0x42 , +80: EMR_SELECTCLIPPATH = 0x43 , +81: EMR_ABORTPATH = 0x44 , +82: EMR_RESERVED_69 = 0x45 , +83: EMR_COMMENT = 0x46 , +84: EMR_FILLRGN = 0x47 , +85: EMR_FRAMERGN = 0x48 , +86: EMR_INVERTRGN = 0x49 , +87: EMR_PAINTRGN = 0x4A , +88: EMR_EXTSELECTCLIPRGN = 0x4B , +89: EMR_BITBLT = 0x4C , +90: EMR_STRETCHBLT = 0x4D , +91: EMR_MASKBLT = 0x4E , +92: EMR_PLGBLT = 0x4F , +93: EMR_SETDIBITSTODEVICE = 0x50 , +94: EMR_STRETCHDIBITS = 0x51 , +95: EMR_EXTCREATEFONTINDIRECTW = 0x52 , +96: EMR_EXTTEXTOUTA = 0x53 , +97: EMR_EXTTEXTOUTW = 0x54 , +98: EMR_POLYBEZIER16 = 0x55 , +99: EMR_POLYGON16 = 0x56 , +100: EMR_POLYLINE16 = 0x57 , +101: EMR_POLYBEZIERTO16 = 0x58 , +102: EMR_POLYLINETO16 = 0x59 , +103: EMR_POLYPOLYLINE16 = 0x5A , +104: EMR_POLYPOLYGON16 = 0x5B , +105: EMR_POLYDRAW16 = 0x5C , +106: EMR_CREATEMONOBRUSH = 0x5D , +107: EMR_CREATEDIBPATTERNBRUSHPT = 0x5E , +108: EMR_EXTCREATEPEN = 0x5F , +109: EMR_POLYTEXTOUTA = 0x60 , +110: EMR_POLYTEXTOUTW = 0x61 , +111: EMR_SETICMMODE = 0x62 , +112: EMR_CREATECOLORSPACE = 0x63 , +113: EMR_SETCOLORSPACE = 0x64 , +114: EMR_DELETECOLORSPACE = 0x65 , +115: EMR_GLSRECORD = 0x66 , +116: EMR_GLSBOUNDEDRECORD = 0x67 , +117: EMR_PIXELFORMAT = 0x68 , +118: EMR_DRAWESCAPE = 0x69 , +119: EMR_EXTESCAPE = 0x6A , +120: EMR_RESERVED_107 = 0x6B , +121: EMR_SMALLTEXTOUT = 0x6C , +122: EMR_FORCEUFIMAPPING = 0x6D , +123: EMR_NAMEDESCAPE = 0x6E , +124: EMR_COLORCORRECTPALETTE = 0x6F , +125: EMR_SETICMPROFILEA = 0x70 , +126: EMR_SETICMPROFILEW = 0x71 , +127: EMR_ALPHABLEND = 0x72 , +128: EMR_SETLAYOUT = 0x73 , +129: EMR_TRANSPARENTBLT = 0x74 , +130: EMR_RESERVED_117 = 0x75 , +131: EMR_GRADIENTFILL = 0x76 , +132: EMR_SETLINKEDUFIS = 0x77 , +133: EMR_SETTEXTJUSTIFICATION = 0x78 , +134: EMR_COLORMATCHTOTARGETW = 0x79 , +135: EMR_CREATECOLORSPACEW = 0x7A +136: } RecordType ; +137: +138: typedef struct { +139: LONG cx ; +140: LONG cy ; +141: } SIZEL ; +142: +143: typedef struct _RECTL { +144: LONG left ; +145: LONG top ; +146: LONG right ; +147: LONG bottom ; +148: } RECTL ; +149: +150: typedef struct { +151: RecordType iType ; +152: DWORD nSize ; +153: +154: RECTL rclBounds ; +155: RECTL rclFrame ; +156: +157: DWORD dSignature ; +158: DWORD nVersion ; +159: DWORD nBytes ; +160: DWORD nRecords ; +161: WORD nHandles ; +162: +163: WORD sReserved ; +164: DWORD nDescription ; +165: +166: DWORD offDescription ; +167: +168: DWORD nPalEntries ; +169: SIZEL szlDevice ; +170: SIZEL szlMillimeters ; +171: } Header ; +172: +173: typedef struct { +174: WORD desc [ header . nDescription ] ; +175: } Description ; +176: +177: typedef struct { +178: RecordType iType ; +179: DWORD nSize ; +180: DWORD dParm [ ( ( nSize - 8 ) / 4 ) ] ; +181: } Record ; +182: +183: typedef struct { +184: uchar Reserved ; +185: uchar Blue ; +186: uchar Green ; +187: uchar Red ; +188: } PaletteEntry ; +189: +190: +191: +192: LittleEndian ( ) ; +193: +194: +195: Header header ; +196: +197: +198: FSeek ( header . offDescription ) ; +199: Description description ; +200: +201: +202: FSeek ( header . nSize ) ; +203: +204: +205: local int recCnt = 0 ; +206: for ( recCnt = 0 ; recCnt < header . nRecords - 1 ; recCnt ++ ) { +207: Record record ; +208: } +209: +210: +211: do { +212: Record extrarecord ; +213: recCnt ++ ; +214: } while ( record [ recCnt - 1 ] . iType != EMR_EOF ) ; +215: +216: +217: local int palCnt = 0 ; +218: for ( palCnt = 0 ; palCnt < header . nPalEntries ; palCnt ++ ) { +219: PaletteEntry paletteentry ; +220: } +221: +222: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/EOTTemplate.bt b/cparser/tests/exp_lex/EOTTemplate.bt new file mode 100644 index 0000000..23cf11c --- /dev/null +++ b/cparser/tests/exp_lex/EOTTemplate.bt @@ -0,0 +1,78 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: LittleEndian ( ) ; +12: +13: +14: typedef enum < DWORD > { TTEMBED_SUBSET = 0x1 , +15: TTEMBED_TTCOMPRESSED = 0x4 , +16: TTEMBED_FAILIFVARIATIONSIMULATED = 0x10 , +17: TTMBED_EMBEDEUDC = 0x20 , +18: TTEMBED_VALIDATIONTESTS = 0x40 , +19: TTEMBED_WEBOBJECT = 0x80 , +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 ; +28: byte FontPANOSE [ 10 ] ; +29: byte Charset ; +30: byte Italic ; +31: unsigned long Weight ; +32: unsigned short fsType ; +33: unsigned short MagicNumber < bgcolor = cLtRed > ; +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 ; +42: unsigned long Reserved2 ; +43: unsigned long Reserved3 ; +44: unsigned long Reserved4 ; +45: unsigned short Padding1 ; +46: unsigned short FamilyNameSize ; +47: byte FamilyName [ FamilyNameSize ] ; +48: +49: unsigned short Padding2 ; +50: unsigned short StyleNameSize ; +51: byte StyleName [ StyleNameSize ] ; +52: +53: unsigned short Padding3 ; +54: unsigned short VersionNameSize ; +55: byte VersionName [ VersionNameSize ] ; +56: +57: unsigned short Padding4 ; +58: unsigned short FullNameSize ; +59: byte FullName [ FullNameSize ] ; +60: +61: unsigned short Padding5 ; +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 ] < bgcolor = cLtAqua > ; +73: } ; +74: +75: LittleEndian ( ) ; +76: +77: FSeek ( 0 ) ; +78: embedded_opentype_file EOT ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/EVSBTemplate.bt b/cparser/tests/exp_lex/EVSBTemplate.bt new file mode 100644 index 0000000..6825a91 --- /dev/null +++ b/cparser/tests/exp_lex/EVSBTemplate.bt @@ -0,0 +1,104 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +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 ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/EXETemplate.bt b/cparser/tests/exp_lex/EXETemplate.bt new file mode 100644 index 0000000..bcc9a46 --- /dev/null +++ b/cparser/tests/exp_lex/EXETemplate.bt @@ -0,0 +1,385 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: typedef struct { +12: char Signature [ 2 ] ; +13: if ( Memcmp ( Signature , "MZ" , 2 ) ) +14: { +15: Warning ( "Invalid file format" ) ; +16: return 1 ; +17: } +18: WORD LengthOfImage ; +19: WORD SizeOfFile ; +20: WORD NumberOfRelocationItems ; +21: WORD SizeOfHeader ; +22: WORD MinPara ; +23: WORD MaxPara ; +24: WORD OffsetStack ; +25: WORD InitialSp ; +26: WORD NegativeChecksum ; +27: WORD InitialIp ; +28: WORD OffsetCs ; +29: WORD OffsetFirstRelocationItem ; +30: WORD OverlayNumber ; +31: WORD Res1 ; +32: WORD Res2 ; +33: WORD Res3 ; +34: WORD Res4 ; +35: WORD OemId ; +36: WORD OemInfo ; +37: WORD Res5 [ 10 ] ; +38: DWORD OffsetToPEHeader ; +39: } DosExeHeader ; +40: +41: typedef struct { +42: int32 DirExport ; +43: int32 DirExportSize ; +44: int32 DirImport ; +45: int32 DirImportSize ; +46: int32 DirResource ; +47: int32 DirResourceSize ; +48: int32 DirException ; +49: int32 DirExceptionSize ; +50: int32 DirSecurity ; +51: int32 DirSecuritySize ; +52: int32 DirBasereloc ; +53: int32 DirBaserelocSize ; +54: int32 DirDebug ; +55: int32 DirDebugSize ; +56: int32 DirArchitecture ; +57: int32 DirArchitectureSize ; +58: int32 DirGlobalptr ; +59: int32 DirGlobalptrSize ; +60: int32 DirTls ; +61: int32 DirTlsSize ; +62: int32 DirLoadConfig ; +63: int32 DirLoadConfig_size ; +64: int32 DirBoundImport ; +65: int32 DirBoundImportSize ; +66: int32 DirIat ; +67: int32 DirIatSize ; +68: int32 DirDelayImport ; +69: int32 DirDelayImportSize ; +70: int32 DirComDescriptor ; +71: int32 DirComDescriptorSize ; +72: int32 DirX ; +73: int32 DirXSize ; +74: } DataDirectory ; +75: +76: typedef struct { +77: int32 rva ; +78: int32 size ; +79: } DataDir ; +80: +81: typedef struct { +82: char Sig [ 4 ] ; +83: if ( Memcmp ( Sig , "PE" , 2 ) ) +84: { +85: Warning ( "Invalid file format" ) ; +86: return 1 ; +87: } +88: int16 CpuType ; +89: int16 NumSections ; +90: time_t Tm ; +91: int32 PointerToSymbolTable ; +92: int32 NumberOfSymbols ; +93: int16 NtHeaderSize ; +94: int16 Flags ; +95: } PeHeader ; +96: +97: typedef struct { +98: int16 Res3 ; +99: char LMajor ; +100: char LMinor ; +101: int32 SizeOfCode ; +102: int32 SizeOfInitData ; +103: int32 SizeOfUninitData ; +104: int32 EntrypointRva ; +105: int32 BaseOfCode ; +106: int32 BaseOfData ; +107: int32 ImageBase ; +108: int32 SectionAlign ; +109: int32 FileAlign ; +110: int16 OsMajor ; +111: int16 OsMinor ; +112: int16 UserMajor ; +113: int16 UserMinor ; +114: int16 SubsystemMajor ; +115: int16 SubsystemMinor ; +116: int32 Win32VersionValue ; +117: int32 ImageSize ; +118: int32 HeaderSize ; +119: int32 FileChecksum ; +120: int16 Subsystem ; +121: int16 DllFlags ; +122: int32 StackReserveSize ; +123: int32 StackCommitSize ; +124: int32 HeapReserveSize ; +125: int32 HeapCommitSize ; +126: int32 LoaderFlags ; +127: int32 NumInterestingRvaSize ; +128: } OptionalHeader ; +129: +130: typedef struct { +131: char Name [ 8 ] ; +132: int32 VirtualSize ; +133: int32 VirtualAddress ; +134: int32 SizeOfRawData ; +135: int32 PointerToRawData ; +136: int32 PointerToRelocations ; +137: int32 PointerToLinenumbers ; +138: int16 NumberOfRelocations ; +139: int16 NumberOfLinenumbers ; +140: int32 Characteristics ; +141: } SectionTable ; +142: +143: void GetResourceDirectory ( ) +144: { +145: res_level += 1 ; +146: struct +147: { +148: local int32 j ; +149: uint32 Characteristics ; +150: DOSTIME TimeStamp ; +151: DOSDATE DataStamp ; +152: uint16 MajorVersion ; +153: uint16 MinorVersion ; +154: uint16 NumberOfNameEntries ; +155: uint16 NumberOfIDEntries ; +156: for ( j = 0 ; j < NumberOfNameEntries ; j ++ ) +157: { +158: struct +159: { +160: local int64 currentaddress ; +161: uint32 NameRVA : 31 < format = hex > ; +162: int TopBit : 1 ; +163: currentaddress = FTell ( ) ; +164: FSeek ( resource_sa + NameRVA ) ; +165: int16 Length ; +166: wchar_t UnicodeString [ Length ] ; +167: if ( res_show_log == 1 ) { Printf ( "\nLevel %d. " , res_level ) ; } +168: if ( res_show_log == 1 ) { Printf ( "Name: %s" , UnicodeString ) ; } +169: FSeek ( currentaddress ) ; +170: +171: uint32 DataEntryRVA : 31 < format = hex > ; +172: int PointToChild : 1 ; +173: currentaddress = FTell ( ) ; +174: if ( PointToChild == 1 ) +175: { +176: FSeek ( resource_sa + DataEntryRVA ) ; +177: GetResourceDirectory ( ) ; +178: FSeek ( currentaddress ) ; +179: } ; +180: } DirectoryNameEntry ; +181: } ; +182: for ( j = 0 ; j < NumberOfIDEntries ; j ++ ) +183: { +184: struct +185: { +186: local int64 currentaddress ; +187: +188: switch ( res_level ) +189: { +190: case 1 : +191: uint32 IntegerID < comment = ShowType > ; +192: rTypeID = IntegerID ; +193: if ( res_show_log == 1 ) { Printf ( "\n%s" , ShowType ( rTypeID ) ) ; } +194: break ; +195: case 2 : +196: uint32 IntegerID < comment = ShowName > ; +197: rNameID = IntegerID ; +198: if ( res_show_log == 1 ) { Printf ( "\n%s" , ShowName ( rNameID ) ) ; } +199: break ; +200: case 3 : +201: uint32 IntegerID < comment = ShowLanguage > ; +202: rLanguageID = IntegerID ; +203: if ( res_show_log == 1 ) { Printf ( "\n%s" , ShowLanguage ( rLanguageID ) ) ; } +204: break ; +205: } +206: uint32 DataEntryRVA : 31 < format = hex > ; +207: int PointToChild : 1 ; +208: currentaddress = FTell ( ) ; +209: if ( PointToChild == 1 ) +210: { +211: FSeek ( resource_sa + DataEntryRVA ) ; +212: GetResourceDirectory ( ) ; +213: FSeek ( currentaddress ) ; +214: } +215: else +216: { +217: FSeek ( resource_sa + DataEntryRVA ) ; +218: struct +219: { +220: local int64 ba1 , ba2 ; +221: int32 DataRVA < format = hex > ; +222: int32 Size ; +223: int32 Codepage ; +224: int32 Reserved ; +225: FSeek ( DataRVA - ( SectionVirtualAddress - resource_sa ) ) ; +226: if ( rTypeID == 16 ) +227: { +228: struct +229: { +230: ba1 = FTell ( ) ; +231: char VersionInfoRAWData [ Size ] ; +232: ba2 = FTell ( ) ; +233: FSeek ( ba1 ) ; +234: struct { } VersionInfoStructure ; +235: FSeek ( ba2 ) ; +236: } versioninfo ; +237: } +238: else +239: { +240: char ResourceRAWData [ Size ] ; +241: } ; +242: } DataEntry ; +243: FSeek ( currentaddress ) ; +244: } ; +245: } DirectoryIDEntry ; +246: } ; +247: } DirectoryTable ; +248: res_level -= 1 ; +249: } ; +250: +251: string ShowType ( uint32 ID ) +252: { +253: local string s ; +254: switch ( ID ) +255: { +256: case 1 : s = "Cursor" ; break ; +257: case 2 : s = "Bitmap" ; break ; +258: case 3 : s = "Icon" ; break ; +259: case 4 : s = "Menu" ; break ; +260: case 5 : s = "Dialog box" ; break ; +261: case 6 : s = "String table entry" ; break ; +262: case 7 : s = "Font directory" ; break ; +263: case 8 : s = "Font" ; break ; +264: case 9 : s = "Accelerator table" ; break ; +265: case 10 : s = "Application defined resource (raw data)" ; break ; +266: case 11 : s = "Message table entry" ; break ; +267: case 12 : s = "Group cursor" ; break ; +268: case 14 : s = "Group icon" ; break ; +269: case 16 : s = "Version information" ; break ; +270: case 17 : s = "Dlginclude" ; break ; +271: case 19 : s = "Plug and play resource" ; break ; +272: case 20 : s = "VXD" ; break ; +273: case 21 : s = "Animated cursor" ; break ; +274: case 22 : s = "Animated icon" ; break ; +275: case 23 : s = "HTML" ; break ; +276: case 24 : s = "Side-by-side assembly manifest" ; break ; +277: } +278: SPrintf ( s , "Level 1. Resource type: %s" , s ) ; +279: return s ; +280: } +281: string ShowName ( uint32 ID ) +282: { +283: local string s ; +284: SPrintf ( s , "Level 2. Name ID: %d" , ID ) ; +285: return s ; +286: } +287: +288: string ShowLanguage ( uint32 ID ) +289: { +290: local string s ; +291: SPrintf ( s , "Level 3. Language ID: %d" , ID ) ; +292: return s ; +293: } +294: +295: +296: local int32 i , done , j ; +297: local int32 rTypeID , rNameID , rLanguageID ; +298: local int64 resource_sa , resource_ea , res_level ; +299: local int64 SectionVirtualAddress ; +300: local int res_show_log = 0 ; +301: SetBackColor ( cLtGray ) ; +302: DosExeHeader DOSHead ; +303: +304: char dosstub [ DOSHead . OffsetToPEHeader - ( DOSHead . SizeOfHeader * 0x10 ) ] ; +305: +306: PeHeader PEHead ; +307: +308: OptionalHeader OptionalHead ; +309: +310: DataDir dd [ 16 ] ; +311: +312: SectionTable sec [ PEHead . NumSections ] ; +313: +314: for ( i = 0 ; i < PEHead . NumSections ; i ++ ) +315: { +316: done = 0 ; +317: FSeek ( sec [ i ] . PointerToRawData ) ; +318: if ( ! Strcmp ( sec [ i ] . Name , ".text" ) ) +319: { +320: char textsection [ sec [ i ] . SizeOfRawData ] ; +321: done = 1 ; +322: } +323: if ( ! Strcmp ( sec [ i ] . Name , ".bss" ) ) +324: { +325: char bsssection [ sec [ i ] . SizeOfRawData ] ; +326: done = 1 ; +327: } +328: if ( ! Strcmp ( sec [ i ] . Name , ".rsrc" ) ) +329: { +330: struct +331: { +332: resource_sa = FTell ( ) ; +333: SectionVirtualAddress = sec [ i ] . VirtualAddress ; +334: char rawrsrcsection [ sec [ i ] . SizeOfRawData ] ; +335: resource_ea = FTell ( ) ; +336: FSeek ( resource_sa ) ; +337: struct +338: { +339: if ( res_show_log == 1 ) { Printf ( "\nResources list." ) ; } +340: res_level = 0 ; +341: GetResourceDirectory ( ) ; +342: } ResourcesStructure ; +343: FSeek ( resource_ea ) ; +344: } rsrcsection ; +345: done = 1 ; +346: } +347: if ( ! Strcmp ( sec [ i ] . Name , ".rdata" ) ) +348: { +349: char rdatasection [ sec [ i ] . SizeOfRawData ] ; +350: done = 1 ; +351: } +352: if ( ! Strcmp ( sec [ i ] . Name , ".data" ) ) +353: { +354: char datasection [ sec [ i ] . SizeOfRawData ] ; +355: done = 1 ; +356: } +357: if ( ! Strcmp ( sec [ i ] . Name , ".edata" ) ) +358: { +359: char edatasection [ sec [ i ] . SizeOfRawData ] ; +360: done = 1 ; +361: } +362: if ( ! Strcmp ( sec [ i ] . Name , ".idata" ) ) +363: { +364: char idatasection [ sec [ i ] . SizeOfRawData ] ; +365: done = 1 ; +366: } +367: if ( ! Strcmp ( sec [ i ] . Name , ".pdata" ) ) +368: { +369: char pdatasection [ sec [ i ] . SizeOfRawData ] ; +370: done = 1 ; +371: } +372: if ( ! Strcmp ( sec [ i ] . Name , ".debug" ) ) +373: { +374: char debugsection [ sec [ i ] . SizeOfRawData ] ; +375: done = 1 ; +376: } +377: if ( done == 0 ) +378: { +379: struct +380: { +381: char unknownsection [ sec [ i ] . SizeOfRawData ] ; +382: } unknown ; +383: } +384: } +385: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/EXETemplate2.bt b/cparser/tests/exp_lex/EXETemplate2.bt new file mode 100644 index 0000000..6c5cd5d --- /dev/null +++ b/cparser/tests/exp_lex/EXETemplate2.bt @@ -0,0 +1,420 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: LittleEndian ( ) ; +20: +21: typedef struct { +22: WORD MZSignature < format = hex > ; +23: if ( MZSignature != 0x5A4D ) { +24: Warning ( "Not a valid EXE file" ) ; +25: return 1 ; +26: } +27: +28: WORD UsedBytesInTheLastPage ; +29: WORD FileSizeInPages ; +30: WORD NumberOfRelocationItems ; +31: WORD HeaderSizeInParagraphs ; +32: WORD MinimumExtraParagraphs ; +33: WORD MaximumExtraParagraphs ; +34: WORD InitialRelativeSS < format = hex > ; +35: WORD InitialSP < format = hex > ; +36: WORD Checksum < format = hex > ; +37: WORD InitialIP < format = hex > ; +38: WORD InitialRelativeCS < format = hex > ; +39: WORD AddressOfRelocationTable < format = hex > ; +40: WORD OverlayNumber ; +41: WORD Reserved [ 4 ] ; +42: WORD OEMid ; +43: WORD OEMinfo ; +44: WORD Reserved2 [ 10 ] ; +45: LONG AddressOfNewExeHeader < format = hex > ; +46: } IMAGE_DOS_HEADER ; +47: +48: typedef struct { +49: WORD Offset ; +50: WORD Segment ; +51: } DOS_RELOCATION_TABLE_ITEM ; +52: +53: typedef enum < WORD > { IMAGE_FILE_MACHINE_UNKNOWN = 0 , IMAGE_FILE_MACHINE_I386 = 0x14C , +54: IMAGE_FILE_MACHINE_AMD64 = 0x8664 , IMAGE_FILE_MACHINE_ARM = 0x1C0 , +55: +56: IMAGE_FILE_MACHINE_R3000 = 0x162 , +57: IMAGE_FILE_MACHINE_R4000 = 0x166 , IMAGE_FILE_MACHINE_R10000 = 0x168 , +58: IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x169 , IMAGE_FILE_MACHINE_ALPHA = 0x184 , +59: IMAGE_FILE_MACHINE_SH3 = 0x1A2 , IMAGE_FILE_MACHINE_SH3DSP = 0x1A3 , +60: IMAGE_FILE_MACHINE_SH3E = 0x1A4 , IMAGE_FILE_MACHINE_SH4 = 0x1A6 , +61: IMAGE_FILE_MACHINE_SH5 = 0x1A8 , IMAGE_FILE_MACHINE_THUMB = 0x1C2 , +62: IMAGE_FILE_MACHINE_AM33 = 0x1D3 , IMAGE_FILE_MACHINE_POWERPC = 0x1F0 , +63: IMAGE_FILE_MACHINE_POWERPCFP = 0x1F1 , IMAGE_FILE_MACHINE_IA64 = 0x200 , +64: IMAGE_FILE_MACHINE_MIPS16 = 0x266 , IMAGE_FILE_MACHINE_ALPHA64 = 0x284 , +65: IMAGE_FILE_MACHINE_MIPSFPU = 0x366 , IMAGE_FILE_MACHINE_MIPSFPU16 = 0x466 , +66: IMAGE_FILE_MACHINE_TRICORE = 0x520 , IMAGE_FILE_MACHINE_CEF = 0xCEF , +67: IMAGE_FILE_MACHINE_EBC = 0xEBC , IMAGE_FILE_MACHINE_M32R = 0x9041 , +68: IMAGE_FILE_MACHINE_CEE = 0xC0EE } MACHINE ; +69: +70: +71: typedef struct { +72: ushort RelocsStripped : 1 ; +73: ushort ExecutableImage : 1 ; +74: ushort LineNumsStripped : 1 ; +75: ushort LocalSymsStripped : 1 ; +76: ushort AggresiveWorksetTrim : 1 ; +77: ushort LargeAddressAware : 1 ; +78: ushort Reserved : 1 ; +79: ushort BytesReversedLo : 1 ; +80: ushort _32bitMachine : 1 ; +81: ushort DebugStripped : 1 ; +82: ushort RemovableRunFromSwap : 1 ; +83: ushort NetRunFromSwap : 1 ; +84: ushort System : 1 ; +85: ushort DLL : 1 ; +86: ushort UPSystemOnly : 1 ; +87: ushort BytesReversedHi : 1 ; +88: } CHARACTERISTICS < read = ReadCHARACTERISTICS > ; +89: +90: string ReadCHARACTERISTICS ( CHARACTERISTICS & flags ) { +91: string s = "" ; +92: if ( flags . AggresiveWorksetTrim ) Strcat ( s , "AggresiveWorksetTrim " ) ; +93: if ( flags . LargeAddressAware ) Strcat ( s , "LargeAddressAware " ) ; +94: if ( flags . RemovableRunFromSwap ) Strcat ( s , "RemovableRunFromSwap " ) ; +95: if ( flags . NetRunFromSwap ) Strcat ( s , "NetRunFromSwap " ) ; +96: if ( flags . System ) Strcat ( s , "SystemDriver " ) ; +97: if ( flags . DLL ) Strcat ( s , "DLL " ) ; +98: if ( flags . UPSystemOnly ) Strcat ( s , "UniprocessorSystemOnly " ) ; +99: if ( flags . BytesReversedLo ) Strcat ( s , "BytesReversedLo " ) ; +100: if ( flags . BytesReversedHi ) Strcat ( s , "BytesReversedHi " ) ; +101: if ( flags . DebugStripped ) Strcat ( s , "NoDebug " ) ; +102: if ( flags . RelocsStripped ) Strcat ( s , "NoRelocs " ) ; +103: if ( flags . LineNumsStripped ) Strcat ( s , "NoLineNums " ) ; +104: if ( flags . LocalSymsStripped ) Strcat ( s , "NoLocalSyms " ) ; +105: if ( flags . _32bitMachine ) Strcat ( s , "32bit " ) ; +106: if ( flags . ExecutableImage ) Strcat ( s , "Executable " ) ; +107: return s ; +108: } +109: +110: typedef struct { +111: MACHINE Machine ; +112: WORD NumberOfSections ; +113: time_t TimeDateStamp ; +114: DWORD PointerToSymbolTable < format = hex > ; +115: DWORD NumberOfSymbols ; +116: WORD SizeOfOptionalHeader ; +117: CHARACTERISTICS Characteristics ; +118: } IMAGE_FILE_HEADER ; +119: +120: typedef enum < WORD > { UNKNOWN = 0 , NATIVE = 1 , WINDOWS_GUI = 2 , +121: WINDOWS_CONSOLE = 3 , OS2_CONSOLE = 5 , POSIX_CONSOLE = 7 , NATIVE_WIN9X_DRIVER = 8 , +122: WINDOWS_CE_GUI = 9 , EFI_APPLICATION = 10 , EFI_BOOT_SERVICE_DRIVER = 11 , EFI_RUNTIME_DRIVER = 12 , +123: EFI_ROM = 13 , XBOX = 14 } SUBSYSTEM ; +124: +125: typedef struct { +126: ushort NOTIFY_DLL_PROCESS_INIT : 1 ; +127: ushort NOTIFY_DLL_PROCESS_TERM : 1 ; +128: ushort NOTIFY_DLL_THREAD_TERM : 1 ; +129: ushort NOTIFY_DLL_THREAD_TERM : 1 ; +130: ushort Reserved : 2 ; +131: ushort DYNAMIC_BASE : 1 ; +132: ushort FORCE_INTEGRITY : 1 ; +133: ushort NX_COMPAT : 1 ; +134: ushort NO_ISOLATION : 1 ; +135: ushort NO_SEH : 1 ; +136: ushort NO_BIND : 1 ; +137: ushort Reserved2 : 1 ; +138: ushort WDM_DRIVER : 1 ; +139: ushort Reserved3 : 1 ; +140: ushort TERMINAL_SERVER_AWARE : 1 ; +141: } DLLCHARACTERISTICS ; +142: +143: typedef struct { +144: DWORD VirtualAddress < format = hex > ; +145: DWORD Size ; +146: } DATA_DIR ; +147: +148: typedef struct { +149: local int len = OptionalHeader . NumberOfRvaAndSizes ; +150: if ( len > 16 ) +151: len = 16 ; +152: if ( len > 0 ) DATA_DIR Export ; +153: if ( len > 1 ) DATA_DIR Import ; +154: if ( len > 2 ) DATA_DIR Resource ; +155: if ( len > 3 ) DATA_DIR Exception ; +156: if ( len > 4 ) DATA_DIR Security ; +157: if ( len > 5 ) DATA_DIR BaseRelocationTable ; +158: if ( len > 6 ) DATA_DIR DebugDirectory ; +159: if ( len > 7 ) DATA_DIR CopyrightOrArchitectureSpecificData ; +160: if ( len > 8 ) DATA_DIR GlobalPtr ; +161: if ( len > 9 ) DATA_DIR TLSDirectory ; +162: if ( len > 10 ) DATA_DIR LoadConfigurationDirectory ; +163: if ( len > 11 ) DATA_DIR BoundImportDirectory ; +164: if ( len > 12 ) DATA_DIR ImportAddressTable ; +165: if ( len > 13 ) DATA_DIR DelayLoadImportDescriptors ; +166: if ( len > 14 ) DATA_DIR COMRuntimedescriptor ; +167: if ( len > 15 ) DATA_DIR Reserved ; +168: } IMAGE_DATA_DIRECTORIES ; +169: +170: typedef struct { +171: +172: WORD Magic < format = hex > ; +173: BYTE MajorLinkerVersion ; +174: BYTE MinorLinkerVersion ; +175: DWORD SizeOfCode ; +176: DWORD SizeOfInitializedData ; +177: DWORD SizeOfUninitializedData ; +178: DWORD AddressOfEntryPoint < format = hex > ; +179: DWORD BaseOfCode < format = hex > ; +180: DWORD BaseOfData < format = hex > ; +181: +182: DWORD ImageBase < format = hex > ; +183: DWORD SectionAlignment ; +184: DWORD FileAlignment ; +185: WORD MajorOperatingSystemVersion ; +186: WORD MinorOperatingSystemVersion ; +187: WORD MajorImageVersion ; +188: WORD MinorImageVersion ; +189: WORD MajorSubsystemVersion ; +190: WORD MinorSubsystemVersion ; +191: DWORD Win32VersionValue ; +192: DWORD SizeOfImage ; +193: DWORD SizeOfHeaders ; +194: DWORD CheckSum < format = hex > ; +195: SUBSYSTEM Subsystem ; +196: DLLCHARACTERISTICS DllCharacteristics ; +197: DWORD SizeOfStackReserve ; +198: DWORD SizeOfStackCommit ; +199: DWORD SizeOfHeapReserve ; +200: DWORD SizeOfHeapCommit ; +201: DWORD LoaderFlags ; +202: DWORD NumberOfRvaAndSizes ; +203: IMAGE_DATA_DIRECTORIES DataDirectory ; +204: } IMAGE_OPTIONAL_HEADER32 ; +205: +206: typedef struct { +207: WORD Magic < format = hex > ; +208: BYTE MajorLinkerVersion ; +209: BYTE MinorLinkerVersion ; +210: DWORD SizeOfCode ; +211: DWORD SizeOfInitializedData ; +212: DWORD SizeOfUninitializedData ; +213: DWORD AddressOfEntryPoint < format = hex > ; +214: DWORD BaseOfCode < format = hex > ; +215: quad ImageBase < format = hex > ; +216: DWORD SectionAlignment ; +217: DWORD FileAlignment ; +218: WORD MajorOperatingSystemVersion ; +219: WORD MinorOperatingSystemVersion ; +220: WORD MajorImageVersion ; +221: WORD MinorImageVersion ; +222: WORD MajorSubsystemVersion ; +223: WORD MinorSubsystemVersion ; +224: DWORD Win32VersionValue ; +225: DWORD SizeOfImage ; +226: DWORD SizeOfHeaders ; +227: DWORD CheckSum < format = hex > ; +228: SUBSYSTEM Subsystem ; +229: DLLCHARACTERISTICS DllCharacteristics ; +230: quad SizeOfStackReserve ; +231: quad SizeOfStackCommit ; +232: quad SizeOfHeapReserve ; +233: quad SizeOfHeapCommit ; +234: DWORD LoaderFlags ; +235: DWORD NumberOfRvaAndSizes ; +236: IMAGE_DATA_DIRECTORIES DataDirectory ; +237: } IMAGE_OPTIONAL_HEADER64 ; +238: +239: typedef struct { +240: DWORD PESignature < format = hex > ; +241: if ( PESignature != 0x4550 ) { +242: Warning ( "Not a valid PE file" ) ; +243: return 1 ; +244: } +245: IMAGE_FILE_HEADER FileHeader ; +246: local short OptionalHeaderMagic = ReadShort ( FTell ( ) ) ; +247: if ( OptionalHeaderMagic == 0x10B ) +248: IMAGE_OPTIONAL_HEADER32 OptionalHeader ; +249: else if ( OptionalHeaderMagic == 0x20B ) +250: IMAGE_OPTIONAL_HEADER64 OptionalHeader ; +251: else { +252: Warning ( "Not a valid PE file %x" , OptionalHeaderMagic ) ; +253: return 1 ; +254: } +255: } IMAGE_NT_HEADERS ; +256: +257: typedef struct { +258: DWORD Reserved : 5 ; +259: DWORD Code : 1 ; +260: DWORD InitializedData : 1 ; +261: DWORD UninitializedData : 1 ; +262: DWORD Reserved2 : 1 ; +263: DWORD LinkerInfoOrComments : 1 ; +264: DWORD Reserved3 : 1 ; +265: DWORD LinkerShouldRemove : 1 ; +266: DWORD CommonBlockData : 1 ; +267: DWORD Reserved4 : 1 ; +268: DWORD NoDeferSpeculativeExceptions : 1 ; +269: DWORD FarData : 1 ; +270: DWORD Reserved5 : 1 ; +271: DWORD PurgeableOr16Bit : 1 ; +272: DWORD Locked : 1 ; +273: DWORD PreLoad : 1 ; +274: DWORD Alignment : 4 ; +275: DWORD ExtendedRelocations : 1 ; +276: DWORD Discardable : 1 ; +277: DWORD NotCachable : 1 ; +278: DWORD NotPageable : 1 ; +279: DWORD Shareable : 1 ; +280: DWORD Executable : 1 ; +281: DWORD Readable : 1 ; +282: DWORD Writeable : 1 ; +283: } SECTION_FLAGS < read = ReadSECTION_FLAGS > ; +284: +285: string ReadSECTION_FLAGS ( SECTION_FLAGS & flags ) { +286: string s = "" ; +287: if ( flags . Code ) Strcat ( s , "Code " ) ; +288: if ( flags . InitializedData ) Strcat ( s , "InitializedData " ) ; +289: if ( flags . UninitializedData ) Strcat ( s , "UninitializedData " ) ; +290: if ( flags . LinkerInfoOrComments ) Strcat ( s , "LinkerInfoOrComments " ) ; +291: if ( flags . LinkerShouldRemove ) Strcat ( s , "LinkerShouldRemove " ) ; +292: if ( flags . CommonBlockData ) Strcat ( s , "CommonBlockData " ) ; +293: if ( flags . NoDeferSpeculativeExceptions ) Strcat ( s , "NoDeferSpeculativeExceptions " ) ; +294: if ( flags . FarData ) Strcat ( s , "FarData " ) ; +295: if ( flags . PurgeableOr16Bit ) Strcat ( s , "PurgeableOr16Bit " ) ; +296: if ( flags . Locked ) Strcat ( s , "Locked " ) ; +297: if ( flags . PreLoad ) Strcat ( s , "PreLoad " ) ; +298: if ( flags . ExtendedRelocations ) Strcat ( s , "ExtendedRelocations " ) ; +299: if ( flags . Discardable ) Strcat ( s , "Discardable " ) ; +300: if ( flags . NotCachable ) Strcat ( s , "NotCachable " ) ; +301: if ( flags . NotPageable ) Strcat ( s , "NotPageable " ) ; +302: if ( flags . Shareable ) Strcat ( s , "Shareable " ) ; +303: if ( flags . Executable ) Strcat ( s , "Executable " ) ; +304: if ( flags . Readable ) Strcat ( s , "Readable " ) ; +305: if ( flags . Writeable ) Strcat ( s , "Writeable " ) ; +306: if ( flags . Alignment ) { +307: string p ; +308: SPrintf ( p , "Alignment: %g" , Pow ( 2 , flags . Alignment - 1 ) ) ; +309: Strcat ( s , p ) ; +310: } +311: return s ; +312: } +313: +314: typedef struct { +315: BYTE Name [ 8 ] ; +316: DWORD VirtualSize ; +317: DWORD VirtualAddress < format = hex > ; +318: DWORD SizeOfRawData ; +319: DWORD PointerToRawData < format = hex > ; +320: DWORD NonUsedPointerToRelocations ; +321: DWORD NonUsedPointerToLinenumbers ; +322: WORD NonUsedNumberOfRelocations ; +323: WORD NonUsedNumberOfLinenumbers ; +324: SECTION_FLAGS Characteristics ; +325: } IMAGE_SECTION_HEADER < read = ReadIMAGE_SECTION_HEADER > ; +326: +327: string ReadIMAGE_SECTION_HEADER ( IMAGE_SECTION_HEADER & sect ) { +328: if ( exists ( sect . Name ) ) +329: return sect . Name ; +330: else +331: return "" ; +332: } +333: +334: +335: IMAGE_DOS_HEADER dos_header ; +336: FSeek ( dos_header . HeaderSizeInParagraphs * 16 ) ; +337: local int dosstubsize = dos_header . FileSizeInPages * 512 ; +338: if ( dos_header . UsedBytesInTheLastPage ) +339: dosstubsize -= ( 512 - dos_header . UsedBytesInTheLastPage ) ; +340: if ( dosstubsize > dos_header . AddressOfNewExeHeader ) +341: dosstubsize = dos_header . AddressOfNewExeHeader ; +342: dosstubsize -= dos_header . HeaderSizeInParagraphs * 16 ; +343: local quad richpos ; +344: local quad richstart , richsize = 0 ; +345: if ( ( richpos = FindFirst ( "Rich" , true , false , false , 0 . 0 , 1 , FTell ( ) , dosstubsize ) ) > 0 && +346: ( ReadUInt ( richpos - 4 ) & 0xFFFFFF00 ) == ( ReadUInt ( richpos + 4 ) & 0xFFFFFF00 ) ) { +347: local int a = 0 ; +348: local quad save = FTell ( ) ; +349: FSeek ( richpos ) ; +350: richstart = FindFirst ( a , true , false , false , 0 . 0 , 0 , FTell ( ) , richpos - FTell ( ) ) ; +351: FSeek ( save ) ; +352: richpos += 8 ; +353: richstart += 4 ; +354: richsize = richpos - richstart ; +355: dosstubsize = richstart - FTell ( ) ; +356: } +357: if ( dosstubsize > 0 ) +358: UCHAR doscode [ dosstubsize ] ; +359: if ( richsize > 0 ) { +360: FSeek ( richstart ) ; +361: DWORD MSlinkerSignatureRich [ richsize / 4 ] < format = hex > ; +362: } +363: +364: if ( dos_header . NumberOfRelocationItems ) { +365: FSeek ( dos_header . AddressOfRelocationTable ) ; +366: if ( FileSize ( ) - FTell ( ) >= dos_header . NumberOfRelocationItems * +367: sizeof ( DOS_RELOCATION_TABLE_ITEM ) ) +368: DOS_RELOCATION_TABLE_ITEM relocation_items [ dos_header . NumberOfRelocationItems ] ; +369: } +370: +371: FSeek ( dos_header . AddressOfNewExeHeader ) ; +372: IMAGE_NT_HEADERS nt_headers ; +373: FSeek ( dos_header . AddressOfNewExeHeader + sizeof ( DWORD ) + sizeof ( IMAGE_FILE_HEADER ) + +374: nt_headers . FileHeader . SizeOfOptionalHeader ) ; +375: IMAGE_SECTION_HEADER sections_table [ nt_headers . FileHeader . NumberOfSections ] ; +376: local int sectend = FTell ( ) ; +377: local int i , max = 0 ; +378: for ( i = 0 ; i < nt_headers . FileHeader . NumberOfSections ; ++ i ) +379: if ( sections_table [ i ] . PointerToRawData && sections_table [ i ] . SizeOfRawData ) { +380: FSeek ( sections_table [ i ] . PointerToRawData ) ; +381: if ( 0 == Strcmp ( sections_table [ i ] . Name , ".text" ) && ! exists ( textsection ) ) +382: BYTE textsection [ sections_table [ i ] . SizeOfRawData ] ; +383: else if ( 0 == Strcmp ( sections_table [ i ] . Name , ".data" ) && ! exists ( datasection ) ) +384: BYTE datasection [ sections_table [ i ] . SizeOfRawData ] ; +385: else if ( 0 == Strcmp ( sections_table [ i ] . Name , ".rsrc" ) && ! exists ( rsrcsection ) ) +386: BYTE rsrcsection [ sections_table [ i ] . SizeOfRawData ] ; +387: else if ( 0 == Strcmp ( sections_table [ i ] . Name , ".idata" ) && ! exists ( idatasection ) ) +388: BYTE idatasection [ sections_table [ i ] . SizeOfRawData ] ; +389: else if ( 0 == Strcmp ( sections_table [ i ] . Name , ".rdata" ) && ! exists ( rdatasection ) ) +390: BYTE rdatasection [ sections_table [ i ] . SizeOfRawData ] ; +391: else if ( 0 == Strcmp ( sections_table [ i ] . Name , ".pdata" ) && ! exists ( pdatasection ) ) +392: BYTE pdatasection [ sections_table [ i ] . SizeOfRawData ] ; +393: else if ( 0 == Strcmp ( sections_table [ i ] . Name , ".reloc" ) && ! exists ( relocsection ) ) +394: BYTE relocsection [ sections_table [ i ] . SizeOfRawData ] ; +395: else if ( 0 == Strcmp ( sections_table [ i ] . Name , ".edata" ) && ! exists ( edatasection ) ) +396: BYTE edatasection [ sections_table [ i ] . SizeOfRawData ] ; +397: else if ( 0 == Strcmp ( sections_table [ i ] . Name , ".tls" ) && ! exists ( tlssection ) ) +398: BYTE tlssection [ sections_table [ i ] . SizeOfRawData ] ; +399: else if ( ( 0 == Strcmp ( sections_table [ i ] . Name , "CODE" ) || +400: 0 == Strcmp ( sections_table [ i ] . Name , ".code" ) ) && ! exists ( codesection ) ) +401: BYTE codesection [ sections_table [ i ] . SizeOfRawData ] ; +402: +403: else if ( 0 == Strcmp ( sections_table [ i ] . Name , "DATA" ) && ! exists ( datasection ) ) +404: BYTE datasection [ sections_table [ i ] . SizeOfRawData ] ; +405: else if ( 0 == Strcmp ( SubStr ( sections_table [ i ] . Name , 0 , 3 ) , "UPX" ) && ! exists ( upxsection ) ) +406: BYTE upxsection [ sections_table [ i ] . SizeOfRawData ] ; +407: else if ( 0 == Strcmp ( sections_table [ i ] . Name , ".flat" ) && ! exists ( fasmsection ) ) +408: BYTE fasmsection [ sections_table [ i ] . SizeOfRawData ] ; +409: else if ( 0 == Strcmp ( sections_table [ i ] . Name , ".aspack" ) && ! exists ( aspacksection ) ) +410: BYTE aspacksection [ sections_table [ i ] . SizeOfRawData ] ; +411: else +412: struct { +413: BYTE sectiondata [ sections_table [ i ] . SizeOfRawData ] ; +414: } section ; +415: if ( sections_table [ i ] . PointerToRawData + sections_table [ i ] . SizeOfRawData > max ) +416: max = sections_table [ i ] . PointerToRawData + sections_table [ i ] . SizeOfRawData ; +417: } +418: if ( max < FileSize ( ) ) { +419: BYTE Overlay [ FileSize ( ) - max ] ; +420: } tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/FAT16Template.bt b/cparser/tests/exp_lex/FAT16Template.bt new file mode 100644 index 0000000..859ae80 --- /dev/null +++ b/cparser/tests/exp_lex/FAT16Template.bt @@ -0,0 +1,155 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +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 < format = hex > ; +41: if ( Signature55AA != 0xAA55 ) +42: { +43: Warning ( "Invalid MBR" ) ; +44: return 1 ; +45: } +46: } MBR ; +47: +48: +49: +50: typedef struct _FAT16BootSector +51: { +52: BYTE JumpCode [ 3 ] ; +53: BYTE OEM_Name [ 8 ] ; +54: WORD BytesPerSector ; +55: BYTE SectorsPerCluster ; +56: WORD ReservedSectorCount ; +57: BYTE NumberOfFAT ; +58: WORD MAX_RootDirEntry ; +59: WORD TotalSectors ; +60: BYTE MediaDescriptor ; +61: WORD SectorsPerFAT ; +62: WORD SectorsPerTrack ; +63: WORD NumberOfHeads ; +64: DWORD HiddenSectorsBeforePartition ; +65: DWORD TotalSectors ; +66: BYTE PhysicalDriveNumber ; +67: BYTE Reserved ; +68: BYTE ExtendedBootSignature ; +69: BYTE SerialNumber [ 4 ] ; +70: BYTE VolumeLable [ 11 ] ; +71: BYTE FAT_Type [ 8 ] ; +72: BYTE BootCode [ 448 ] ; +73: WORD BootSectorSignature ; +74: } FAT16BootSector ; +75: +76: +77: +78: local unsigned int FATEntryCount = 0 ; +79: typedef struct _FAT16 +80: { +81: WORD Table [ FATEntryCount ] ; +82: } FAT16 ; +83: +84: +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: +102: MBR MasterBootRecord ; +103: +104: +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: +116: +117: +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: +130: +131: RootDirEntry rootDir [ BtSector . MAX_RootDirEntry ] ; +132: +133: +134: } Fat16Partition ; +135: +136: +137: +138: typedef struct _Disk +139: { +140: +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: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/FLVTemplate.bt b/cparser/tests/exp_lex/FLVTemplate.bt new file mode 100644 index 0000000..17e97d2 --- /dev/null +++ b/cparser/tests/exp_lex/FLVTemplate.bt @@ -0,0 +1,93 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: typedef struct { +14: CHAR signature [ 3 ] ; +15: UBYTE version ; +16: UBYTE dummy : 5 ; +17: UBYTE audio : 1 ; +18: UBYTE dummy2 : 1 ; +19: UBYTE video : 1 ; +20: DWORD dataoffset ; +21: DWORD zero ; +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 ) +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 ) +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 ) +58: { +59: UINT fristbyte : 8 ; +60: } +61: UBYTE data [ taglen ] ; +62: UINT lastsize ; +63: +64: +65: +66: +67: } Tag ; +68: +69: BigEndian ( ) ; +70: SetBackColor ( cLtGray ) ; +71: HEADER hdr ; +72: +73: +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: +87: SetBackColor ( cNone ) ; +88: +89: while ( ! FEof ( ) ) +90: { +91: Tag tag ; +92: } +93: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/GIFTemplate.bt b/cparser/tests/exp_lex/GIFTemplate.bt new file mode 100644 index 0000000..637c1c1 --- /dev/null +++ b/cparser/tests/exp_lex/GIFTemplate.bt @@ -0,0 +1,200 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: +21: +22: +23: +24: +25: +26: LittleEndian ( ) ; +27: +28: typedef struct { +29: UBYTE R ; +30: UBYTE G ; +31: UBYTE B ; +32: } RGB < read = ReadRGB > ; +33: string ReadRGB ( RGB & color ) +34: { +35: string s ; +36: SPrintf ( s , "#%02X%02X%02X" , color . R , color . G , color . B ) ; +37: return s ; +38: } +39: typedef struct { +40: local UBYTE size = ReadUByte ( FTell ( ) ) ; +41: while ( size != 0 ) { +42: struct DATASUBBLOCK { +43: UBYTE Size ; +44: char Data [ size ] ; +45: } DataSubBlock ; +46: size = ReadUByte ( FTell ( ) ) ; +47: } +48: UBYTE BlockTerminator ; +49: } DATASUBBLOCKS ; +50: +51: typedef struct { +52: char Signature [ 3 ] ; +53: char Version [ 3 ] ; +54: } GIFHEADER ; +55: +56: typedef struct { +57: ushort Width ; +58: ushort Height ; +59: BitfieldLeftToRight ( ) ; +60: struct LOGICALSCREENDESCRIPTOR_PACKEDFIELDS { +61: UBYTE GlobalColorTableFlag : 1 ; +62: UBYTE ColorResolution : 3 ; +63: UBYTE SortFlag : 1 ; +64: UBYTE SizeOfGlobalColorTable : 3 ; +65: } PackedFields ; +66: UBYTE BackgroundColorIndex ; +67: UBYTE PixelAspectRatio ; +68: } LOGICALSCREENDESCRIPTOR ; +69: +70: +71: +72: SetBackColor ( 0xFFFFFF ) ; +73: GIFHEADER GifHeader ; +74: if ( GifHeader . Signature != "GIF" ) +75: { +76: Warning ( "File is not a valid GIF. Template stopped." ) ; +77: return - 1 ; +78: } +79: +80: +81: SetBackColor ( 0xE0E0E0 ) ; +82: LOGICALSCREENDESCRIPTOR LogicalScreenDescriptor ; +83: +84: if ( LogicalScreenDescriptor . PackedFields . GlobalColorTableFlag == 1 ) { +85: SetBackColor ( 0xC0C0C0 ) ; +86: struct GLOBALCOLORTABLE { +87: local int i ; +88: local int size = 1 ; +89: for ( i = 0 ; i <= LogicalScreenDescriptor . PackedFields . SizeOfGlobalColorTable ; i ++ ) { +90: size *= 2 ; +91: } +92: RGB rgb [ size ] ; +93: } GlobalColorTable < optimize = false > ; ; +94: } +95: +96: SetBackColor ( 0xFFFFFF ) ; +97: struct DATA { +98: while ( ReadUByte ( FTell ( ) ) != 0x3B ) { +99: +100: if ( ReadUByte ( FTell ( ) ) == 0x2C ) { +101: SetBackColor ( 0xE0FFE0 ) ; +102: struct IMAGEDESCRIPTOR { +103: UBYTE ImageSeperator ; +104: ushort ImageLeftPosition ; +105: ushort ImageTopPosition ; +106: ushort ImageWidth ; +107: ushort ImageHeight ; +108: struct IMAGEDESCRIPTOR_PACKEDFIELDS { +109: UBYTE LocalColorTableFlag : 1 ; +110: UBYTE InterlaceFlag : 1 ; +111: UBYTE SortFlag : 1 ; +112: UBYTE Reserved : 2 ; +113: UBYTE SizeOfLocalColorTable : 3 ; +114: } PackedFields ; +115: } ImageDescriptor ; +116: if ( ImageDescriptor . PackedFields . LocalColorTableFlag == 1 ) { +117: SetBackColor ( 0xC0FFC0 ) ; +118: struct LOCALCOLORTABLE { +119: local int i ; +120: local int size = 1 ; +121: for ( i = 0 ; i <= ImageDescriptor . PackedFields . SizeOfLocalColorTable ; i ++ ) { +122: size *= 2 ; +123: } +124: RGB rgb [ size ] ; +125: } LocalColorTable < optimize = false > ; ; +126: } +127: SetBackColor ( 0xA0FFA0 ) ; +128: struct IMAGEDATA { +129: UBYTE LZWMinimumCodeSize ; +130: DATASUBBLOCKS DataSubBlocks ; +131: } ImageData ; +132: } else if ( ReadUShort ( FTell ( ) ) == 0xF921 ) { +133: SetBackColor ( 0xC0FFFF ) ; +134: struct GRAPHICCONTROLEXTENSION { +135: UBYTE ExtensionIntroducer ; +136: UBYTE GraphicControlLabel ; +137: struct GRAPHICCONTROLSUBBLOCK { +138: UBYTE BlockSize ; +139: struct GRAPHICCONTROLEXTENSION_DATASUBBLOCK_PACKEDFIELDS { +140: UBYTE Reserved : 3 ; +141: UBYTE DisposalMethod : 3 ; +142: UBYTE UserInputFlag : 1 ; +143: UBYTE TransparentColorFlag : 1 ; +144: } PackedFields ; +145: ushort DelayTime ; +146: UBYTE TransparentColorIndex ; +147: } GraphicControlSubBlock ; +148: UBYTE BlockTerminator ; +149: } GraphicControlExtension ; +150: } else if ( ReadUShort ( FTell ( ) ) == 0xFE21 ) { +151: SetBackColor ( 0xFFFFC0 ) ; +152: struct COMMENTEXTENSION { +153: UBYTE ExtensionIntroducer ; +154: UBYTE CommentLabel ; +155: DATASUBBLOCKS CommentData ; +156: } CommentExtension ; +157: } else if ( ReadUShort ( FTell ( ) ) == 0x121 ) { +158: SetBackColor ( 0xC0C0C0 ) ; +159: struct PLAINTEXTEXTENTION { +160: UBYTE ExtensionIntroducer ; +161: UBYTE PlainTextLabel ; +162: struct PLAINTEXTSUBBLOCK { +163: UBYTE BlockSize ; +164: ushort TextGridLeftPosition ; +165: ushort TextGridTopPosition ; +166: ushort TextGridWidth ; +167: ushort TextGridHeight ; +168: UBYTE CharacterCellWidth ; +169: UBYTE CharacterCellHeight ; +170: UBYTE TextForegroundColorIndex ; +171: UBYTE TextBackgroundColorIndex ; +172: } PlainTextSubBlock ; +173: DATASUBBLOCKS PlainTextData ; +174: } PlainTextExtension ; +175: } else if ( ReadUShort ( FTell ( ) ) == 0xFF21 ) { +176: SetBackColor ( 0xC0C0FF ) ; +177: struct APPLICATIONEXTENTION { +178: UBYTE ExtensionIntroducer ; +179: UBYTE ApplicationLabel ; +180: struct APPLICATIONSUBBLOCK { +181: UBYTE BlockSize ; +182: char ApplicationIdentifier [ 8 ] ; +183: char ApplicationAuthenticationCode [ 3 ] ; +184: } ApplicationSubBlock ; +185: DATASUBBLOCKS ApplicationData ; +186: } ApplicationExtension ; +187: } else { +188: SetBackColor ( 0xFF8080 ) ; +189: struct UNDEFINEDDATA { +190: UBYTE ExtensionIntroducer ; +191: UBYTE Label ; +192: DATASUBBLOCKS DataSubBlocks ; +193: } UndefinedData ; +194: } +195: } +196: } Data ; +197: SetBackColor ( 0xFFFFFF ) ; +198: struct TRAILER { +199: UBYTE GIFTrailer ; +200: } Trailer ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/GPTTemplate.bt b/cparser/tests/exp_lex/GPTTemplate.bt new file mode 100644 index 0000000..b5e1b86 --- /dev/null +++ b/cparser/tests/exp_lex/GPTTemplate.bt @@ -0,0 +1,68 @@ +1: +2: +3: +4: +5: +6: +7: +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 ; +31: uint64 FirstUsableLBA ; +32: uint64 LastUsableLBA ; +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 ] ; +48: } GPTPAPTITIONTABLE < size = 128 > ; +49: +50: LittleEndian ( ) ; +51: struct { +52: BYTE bootcode [ 446 ] ; +53: MBRPARTITIONTABLE partitionTable [ 4 ] ; +54: WORD signature ; +55: } MBR < size = 512 > ; +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: } tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/GZipTemplate.bt b/cparser/tests/exp_lex/GZipTemplate.bt new file mode 100644 index 0000000..26e1709 --- /dev/null +++ b/cparser/tests/exp_lex/GZipTemplate.bt @@ -0,0 +1,185 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: +21: +22: +23: +24: +25: +26: +27: +28: +29: LittleEndian ( ) ; +30: +31: +32: typedef ubyte MAGIC [ 2 ] < read = MAGICRead , format = hex > ; +33: +34: string MAGICRead ( MAGIC magic ) { +35: string ret ; +36: string tmp ; +37: int i ; +38: +39: for ( i = 0 ; i < 2 ; i ++ ) { +40: SPrintf ( tmp , "%.2X" , magic [ i ] ) ; +41: ret += tmp ; +42: } +43: +44: return ret ; +45: } +46: +47: typedef enum < ubyte > { +48: +49: STORED = 0 , +50: COMPRESSED = 1 , +51: PACKED = 2 , +52: LZHED = 3 , +53: RESERVED_4 = 4 , +54: RESERVED_5 = 5 , +55: RESERVED_6 = 6 , +56: RESERVED_7 = 7 , +57: +58: DEFLATE = 8 +59: } COMPRESSION ; +60: +61: +62: +63: typedef struct { +64: +65: byte FLAG_ASCII_TEXT : 1 ; +66: +67: +68: byte FLAG_CONTINUATION : 1 ; +69: +70: +71: byte FLAG_EXTRA : 1 ; +72: +73: +74: byte FLAG_NAME : 1 ; +75: +76: +77: byte FLAG_COMMENT : 1 ; +78: +79: +80: byte FLAG_ENCRYPTED : 1 ; +81: +82: +83: byte FLAG_RESERVED : 1 ; +84: byte FLAG_RESERVED : 1 ; +85: } FLAGS ; +86: +87: typedef enum < byte > { +88: FAT_FILESYSTEM = 0 , +89: AMIGA = 1 , +90: VMS = 2 , +91: UNIX = 3 , +92: VM_CMS = 4 , +93: ATARI_TOS = 5 , +94: HPFS_FILESYSTEM = 6 , +95: MACINTOSH = 7 , +96: Z_SYSTEM = 8 , +97: CPM = 9 , +98: TOPS_20 = 10 , +99: NTFS_FILESYSTEM = 11 , +100: QDOS = 12 , +101: ACORN_RISCOS = 13 , +102: UNKNOWN = 255 +103: } OS ; +104: +105: typedef struct { +106: MAGIC magic_bytes < format = hex , comment = "Magic bytes for the file" > ; +107: +108: +109: if ( magic_bytes [ 0 ] == 0x1F ) { +110: if ( magic_bytes [ 1 ] == 0x8B ) { +111: +112: Printf ( "Appears to be a valid GZIP compressed file, attempting to parse.\n" ) ; +113: } else if ( magic_bytes [ 1 ] == 0x1E ) { +114: +115: Printf ( "Appears to be a generic compressed file, attempting to parse - don't expect much though.\n" ) ; +116: } else if ( magic_bytes [ 1 ] == 0x9E ) { +117: +118: Printf ( "Appears to be an old GZip compressed file, attempting to parse - don't expect much though.\n" ) ; +119: } else if ( magic_bytes [ 1 ] == 0xA0 ) { +120: +121: Printf ( "Appears to be a LZH compressed file, attempting to parse - don't expect much though.\n" ) ; +122: } +123: } else if ( magic_bytes [ 0 ] == 0x50 && magic_bytes [ 1 ] == 0x4B ) { +124: Warning ( "Appears to be a possible ZIP file - unable to parse with this template!" ) ; +125: Exit ( - 1 ) ; +126: } else { +127: Warning ( "Does not appear to be a GZip file!" ) ; +128: Exit ( - 1 ) ; +129: } +130: +131: COMPRESSION compression_method < comment = "Compression method used by engine" > ; +132: FLAGS flags < comment = "Optional flags for compressed section" > ; +133: +134: +135: uint modification_time < comment = "Unix timestamp of the file modification time" > ; +136: +137: +138: ubyte extra_flags < comment = "Extra flags, dependant on compression method" > ; +139: +140: +141: OS operating_system < comment = "Operating system compression took place on" > ; +142: +143: +144: if ( flags . FLAG_CONTINUATION == 1 ) { +145: ushort part < comment = "Part number of the continuation" > ; +146: } +147: +148: +149: if ( flags . FLAG_EXTRA == 1 ) { +150: ushort extra_length < comment = "Length of extra field" > ; +151: byte extra_bytes [ extra_length ] < comment = "Data for extra field" > ; +152: } +153: +154: if ( flags . FLAG_NAME == 1 ) { +155: string original_file_name < comment = "Original file name" > ; +156: } +157: +158: if ( flags . FLAG_COMMENT == 1 ) { +159: string file_comment < comment = "File comment" > ; +160: } +161: +162: +163: +164: +165: +166: +167: if ( flags . FLAG_ENCRYPTED == 1 ) { +168: +169: } +170: } gzip_header ; +171: +172: +173: struct { +174: +175: gzip_header header < comment = "GZip header information" > ; +176: +177: +178: +179: byte compressed [ FileSize ( ) - FTell ( ) - 8 ] < comment = "compressed data section" > ; +180: +181: uint CRC32 < format = hex , comment = "CRC of the data section" > ; +182: +183: +184: uint uncompressed_sized < comment = "Size of the uncompressed input" > ; +185: } gzip_file ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/GeoTIFTemplate.bt b/cparser/tests/exp_lex/GeoTIFTemplate.bt new file mode 100644 index 0000000..5b659a6 --- /dev/null +++ b/cparser/tests/exp_lex/GeoTIFTemplate.bt @@ -0,0 +1,1119 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: +21: +22: +23: +24: +25: +26: +27: +28: +29: +30: +31: +32: +33: +34: +35: +36: local uint16 tbom ; +37: tbom = ReadUShort ( 0 ) ; +38: if ( tbom == 0x4949 ) { LittleEndian ( ) ; } +39: else if ( tbom == 0x4D4D ) { BigEndian ( ) ; } +40: else { +41: Warning ( "Invalid TIFF File: Bad BOM (Byte Order Mark). Template Terminated." ) ; +42: return - 1 ; +43: } +44: +45: local quad nextIFD = 0 ; +46: +47: +48: +49: typedef enum < uint16 > eTAG { +50: GPSVersionID = 0 , GPSLatitudeRef , GPSLatitude , GPSLongitudeRef , GPSLongitude , GPSAltitudeRef , GPSAltitude , GPSTimeStamp , GPSSatellites , GPSStatus , GPSMeasureMode , GPSDOP , GPSSpeedRef , GPSSpeed , GPSTrackRef , GPSTrack , GPSImgDirectionRef , GPSImgDirection , GPSMapDatum , GPSDestLatitudeRef , GPSDestLatitude , GPSDestLongitudeRef , GPSDestLongitude , GPSDestBearingRef , GPSDestBearing , GPSDestDistanceRef , GPSDestDistance , GPSProcessingMethod , GPSAreaInformation , GPSDateStamp , GPSDifferential , +51: NewSubFileType = 254 , SubFileType , ImageWidth , ImageLength , BitsPerSample , Compression , +52: PhotometricInterpretation = 262 , Thresholding , CellWidth , CellLength , FillOrder , +53: DocumentName = 269 , ImageDescription , Make , Model , StripOffsets , Orientation , +54: SamplesPerPixel = 277 , RowsPerStrip , StripByteCounts , MinSampleValue , MaxSampleValue , XResolution , YResolution , PlanarConfiguration , PageName , XPosition , YPosition , FreeOffsets , FreeByteCounts , GrayResponseUnit , GrayResponseCurve , Group3Options , Group4Options , +55: ResolutionUnit = 296 , PageNumber , +56: ColorResponseUnit = 300 , TransferFunction , +57: Software = 305 , DateTime , +58: Artist = 315 , HostComputer , Predictor , WhitePoint , PrimaryChromacities , ColorMap , HalftoneHints , TileWidth , TileLength , TileOffsets , TileByteCounts , BadFaxLines , CleanFaxData , ConsecutiveBadFaxLines , +59: SubIFDs = 330 , +60: InkSet = 332 , InkNames , NumberOfInks , +61: DotRange = 336 , TargetPrinter , ExtraSamples , SampleFormat , SMinSampleValue , SMaxSampleValue , TransferRange , ClipPath , XClipPathUnits , YClipPathUnits , Indexed , JPEGTables , +62: OPIProxy = 351 , +63: GlobalParametersIFD = 400 , ProfileType , FaxProfile , CodingMethods , VersionYear , ModeNumber , +64: JPEGProc = 512 , JPEGInterchangeFormat , JPEGInterchangeFormatLength , JPEGRestartInterval , +65: JPEGLosslessPredictors = 517 , JPEGPointTransforms , JPEGQTables , JPEGDCTables , JPEGACTables , +66: YCbCrCoefficients = 529 , YCbCrSubsampling , YCbCrPositioning , ReferenceBlackWhite , +67: XMP = 700 , +68: ImageID = 32781 , +69: Wang_Annotation = 32932 , +70: Matteing = 32995 , DataType , ImageDepth , TileDepth , +71: CFARepeatPatternDim = 33421 , CFAPattern , BatteryLevel , +72: Copyright = 33432 , +73: ExposureTime = 33434 , +74: FNumber = 33437 , +75: ModelPixelScaleTag = 33550 , +76: IPTC_NAA = 33723 , +77: INGR_Packet_Data_Tag = 33918 , INGR_Flag_Registers , IntergraphMatrixTag , +78: ModelTiepointTag = 33922 , +79: Site = 34016 , ColorSequence , IT8Header , RasterPadding , BitsPerRunLength , BitsPerExtendedRunLength , ColorTable , ImageColorIndicator , BackgroundColorIndicator , ImageColorValue , BackgroundColorValue , PixelInensityRange , TransparencyIndicator , ColorCharacterization , HCUsage , +80: ModelTransformationTag = 34264 , +81: PhotoshopImageResources = 34377 , +82: ExifIFD = 34665 , +83: InterColourProfile = 34675 , +84: GeoKeyDirectoryTag = 34735 , GeoDoubleParamsTag , GeoAsciiParamsTag , +85: ExposureProgram = 34850 , +86: SpectralSensitibity = 34852 , GPSInfo , +87: ISOSpeedRatings = 34855 , OECF , Interlace , TimeZoneOffset , SelfTimerMode , +88: FaxRecvParams = 34908 , FaxSubAddress , FaxRecvTime , +89: ExifVersion = 36864 , +90: DateTimeOriginal = 36867 , DateTimeDigitized , +91: ComponentsConfiguration = 37121 , CompressedBitsPerPixel , +92: ShutterSpeedValue = 37377 , ApertureValue , BrightnessValue , ExposureBiasValue , MaxApertureValue , SubjectDistance , MeteringMode , LightSource , Flash , FocalLength , FlashEnergy , SpatialFrequencyResponse , Noise , FocalPlaneXResolution , FocalPlaneYResolution , FocalPlaneResolutionUnit , ImageNumber , SecurityClassification , ImageHistory , SubjectArea , ExposureIndex , TIFF_EPStandardID , SensingMethod , +93: StoNits = 37439 , +94: MakerNote = 37500 , +95: UserComment = 37510 , +96: SubSecTime = 37520 , SubSecTimeOriginal , SubSecTimeDigitized , +97: ImageSourceData = 37724 , +98: MSFax_CSID = 40001 , MSFax_TSID , MSFax_Device , MSFax_RoutingInfo , MSFax_CallerID , MSFax_RecipientName , MSFax_RecipientFaxNumber , MSFax_RecipientCompany , MSFax_RecipientAddress , MSFax_RecipientStreet , MSFax_RecipientCity , MSFax_RecipientZipCode , MSFax_RecipientCountry , MSFax_RecipientTitle , MSFax_RecipientDepartment , MSFax_RecipientOffice , MSFax_RecipientOfficePhone , MSFax_RecipientHomePhone , MSFax_Recipient40019 , MSFax_RecipientEmail , MSFax_SenderName , MSFax_SenderFaxNumber , MSFax_SenderCompany , MSFax_SenderAddress , MSFax_SenderStreet , MSFax_SenderCity , MSFax_SenderZipCode , MSFax_SenderCountry , MSFax_SenderTitle , MSFax_SenderDepartment , MSFax_SenderOffice , MSFax_SenderOfficePhone , MSFax_SenderHomePhone , MSFax_Sender40034 , MSFax_SenderEmail , MSFax_BillingCode , MSFax_UserName , MSFax_40038 , MSFax_Document , MSFax_CoverPageSubject , MSFax_Retries , MSFax_Priority , MSFax_ParentJobID , MSFax_SubmissionTime , MSFax_Scheduled , MSFax_TotalPages , MSFax_Type , MSFax_40048 , MSFax_ErrorCode , MSFax_40050 , MSFax_StartTime , MSFax_EndTime , MSFax_40053 , +99: FlashpixVersion = 40960 , ColorSpace , PixelXDimension , PixelYDimension , RelatedSoundFile , InteroperabilityIFD , +100: FlashEnergy_Exif = 41483 , SpatialFrequencyResponse_Exif , +101: FocalPlaneXResolution_Exif = 41486 , FocalPlaneYResolution_Exif , FocalPlaneResolutionUnit_Exif , +102: SubjectLocation_Exif = 41492 , ExposureIndex_Exif , +103: SensingMethod_Exif = 41495 , +104: FileSource = 41728 , SceneType , CFAPattern_Exif , +105: CustomRendered = 41985 , ExposureMode , WhiteBalance , DigitalZoomRatio , FocalLengthIn35mmFilm , SceneCaptureType , GainControl , Contrast , Saturation , Sharpness , DeviceSettingDescription , SubjectDistanceRange , +106: GDAL_METADATA = 42112 , GDAL_NODATA , +107: Oce_Scanjob_Description = 50215 , Oce_Application_Selector , Oce_Identification_Number , Oce_ImageLogic_Characteristics , +108: PhotoshopAnnotations = 50255 , +109: DNGVersion = 50706 , DNGBackwardVersion , UniqueCameraModel , LocalizedCameraModel , CFAPlaneColor , CFALayout , LinearizationTable , BlackLevelRepeatDim , BlackLevel , BlackLevelDeltaH , BlackLevelDeltaV , WhiteLevel , DefaultScale , DefaultCropOrigin , DefaultCropSize , ColorMatrix1 , ColorMatrix2 , CameraCalibration1 , CameraCalibration2 , ReductionMatrix1 , ReductionMatrix2 , AnalogBalnace , AsShortNeutral , AsShortWhiteXY , BaselineExposure , BaselineNoise , BaselineSharpness , BayerGreenSplit , LinearResponseLimit , CameraSerialNumber , LensInfo , ChromaBlurRadius , AntiAliasStrength , +110: DNGPrivateDatea = 50740 , MakerNoteSafety , +111: CalibrationIlluminant1 = 50778 , CalibrationIlluminant2 , BestQualityScale , +112: Alias_Layer_Metadata = 50784 +113: } TAG ; +114: +115: +116: typedef enum < uint16 > eTAGTYPE { +117: eBYTE = 1 , eASCII , eSHORT , eLONG , eRATIONAL , +118: eSBYTE , eUNDEF , eSSHORT , eSLONG , eSRATIONAL , +119: eFLOAT , eDOUBLE +120: } TAGTYPE ; +121: +122: +123: typedef enum < uint16 > eCOMP { +124: Uncompressed = 1 , CCITT_1D , Group3Fax , Group4Fax , LZW , JPEG , JPEG2 , +125: Deflate = 8 , +126: NeXT2Bit = 32766 , CCITT_RLE = 32771 , PackBits = 32773 , +127: ThunderScan4bit = 32809 , cRasterPadding = 32895 , +128: RLEforLW = 32896 , RLEforHC , RLEforBL , +129: Pixar10bitLZW = 32908 , PixarCompanded11bitZIP , +130: PKZIP_Deflate = 32946 , +131: Kodak_DCS = 32947 , +132: JBIG = 34661 , +133: SGI32LogLum = 34676 , +134: SIG24LogLum = 34677 , +135: JPEG_2000 = 34712 +136: } COMP ; +137: +138: +139: typedef enum < uint16 > ePHOTO { +140: WhiteIsZero , BlackIsZero , RGB , RGB_Palette , Transparency_Mask , CMYK , YCbCr , +141: CIELab = 8 , ICCLab , ITULab , CFA = 32803 , CIELog2L = 32844 , CIELog2Luv , LinearRaw = 34892 +142: } PHOTO ; +143: +144: +145: typedef enum < uint16 > eRES { +146: None = 1 , Inch , Centimeter +147: } RES ; +148: +149: +150: typedef enum < uint16 > eKEYGeoTiff { +151: undefinedGeoKey = 1 , +152: +153: +154: +155: +156: +157: +158: +159: +160: GTModelTypeGeoKey = 1024 , +161: GTRasterTypeGeoKey = 1025 , +162: GTCitationGeoKey = 1026 , +163: +164: +165: +166: GeographicTypeGeoKey = 2048 , +167: GeogCitationGeoKey = 2049 , +168: GeogGeodeticDatumGeoKey = 2050 , +169: GeogPrimeMeridianGeoKey = 2051 , +170: GeogLinearUnitsGeoKey = 2052 , +171: GeogLinearUnitSizeGeoKey = 2053 , +172: GeogAngularUnitsGeoKey = 2054 , +173: GeogAngularUnitSizeGeoKey = 2055 , +174: GeogEllipsoidGeoKey = 2056 , +175: GeogSemiMajorAxisGeoKey = 2057 , +176: GeogSemiMinorAxisGeoKey = 2058 , +177: GeogInvFlatteningGeoKey = 2059 , +178: GeogAzimuthUnitsGeoKey = 2060 , +179: GeogPrimeMeridianLongGeoKey = 2061 , +180: GeogTOWGS84GeoKey = 2062 , +181: +182: +183: +184: +185: +186: ProjectedCSTypeGeoKey = 3072 , +187: PCSCitationGeoKey = 3073 , +188: ProjectionGeoKey = 3074 , +189: ProjCoordTransGeoKey = 3075 , +190: ProjLinearUnitsGeoKey = 3076 , +191: ProjLinearUnitSizeGeoKey = 3077 , +192: ProjStdParallel1GeoKey = 3078 , +193: +194: ProjStdParallel2GeoKey = 3079 , +195: ProjNatOriginLongGeoKey = 3080 , +196: +197: ProjNatOriginLatGeoKey = 3081 , +198: +199: ProjFalseEastingGeoKey = 3082 , +200: ProjFalseNorthingGeoKey = 3083 , +201: ProjFalseOriginLongGeoKey = 3084 , +202: ProjFalseOriginLatGeoKey = 3085 , +203: ProjFalseOriginEastingGeoKey = 3086 , +204: ProjFalseOriginNorthingGeoKey = 3087 , +205: ProjCenterLongGeoKey = 3088 , +206: ProjCenterLatGeoKey = 3089 , +207: ProjCenterEastingGeoKey = 3090 , +208: ProjCenterNorthingGeoKey = 3091 , +209: ProjScaleAtNatOriginGeoKey = 3092 , +210: +211: ProjScaleAtCenterGeoKey = 3093 , +212: ProjAzimuthAngleGeoKey = 3094 , +213: ProjStraightVertPoleLongGeoKey = 3095 , +214: ProjRectifiedGridAngleGeoKey = 3096 , +215: +216: +217: +218: VerticalCSTypeGeoKey = 4096 , +219: VerticalCitationGeoKey = 4097 , +220: VerticalDatumGeoKey = 4098 , +221: VerticalUnitsGeoKey = 4099 , +222: +223: +224: +225: userDefinedGeoKey = 32767 +226: } GeoKEYlabel ; +227: +228: +229: +230: +231: +232: +233: +234: typedef enum < short > { +235: ModelTypeProjected = 1 , +236: ModelTypeGeographic = 2 , +237: ModelTypeGeocentric = 3 , +238: +239: +240: +241: } modeltype_t ; +242: +243: +244: typedef enum < short > { +245: RasterPixelIsArea = 1 , +246: RasterPixelIsPoint = 2 +247: } rastertype_t ; +248: +249: +250: typedef enum < short > { +251: Linear_Meter = 9001 , +252: Linear_Foot = 9002 , +253: Linear_Foot_US_Survey = 9003 , +254: Linear_Foot_Modified_American = 9004 , +255: Linear_Foot_Clarke = 9005 , +256: Linear_Foot_Indian = 9006 , +257: Linear_Link = 9007 , +258: Linear_Link_Benoit = 9008 , +259: Linear_Link_Sears = 9009 , +260: Linear_Chain_Benoit = 9010 , +261: Linear_Chain_Sears = 9011 , +262: Linear_Yard_Sears = 9012 , +263: Linear_Yard_Indian = 9013 , +264: Linear_Fathom = 9014 , +265: Linear_Mile_International_Nautical = 9015 +266: } LinearUnitCode_t ; +267: +268: +269: typedef enum < short > { +270: Angular_Radian = 9101 , +271: Angular_Degree = 9102 , +272: Angular_Arc_Minute = 9103 , +273: Angular_Arc_Second = 9104 , +274: Angular_Grad = 9105 , +275: Angular_Gon = 9106 , +276: Angular_DMS = 9107 , +277: Angular_DMS_Hemisphere = 9108 +278: } AngularUnitCode_t ; +279: +280: +281: +282: typedef enum < short > { +283: GCS_Adindan = 4201 , +284: GCS_AGD66 = 4202 , +285: GCS_AGD84 = 4203 , +286: GCS_Ain_el_Abd = 4204 , +287: GCS_Afgooye = 4205 , +288: GCS_Agadez = 4206 , +289: GCS_Lisbon = 4207 , +290: GCS_Aratu = 4208 , +291: GCS_Arc_1950 = 4209 , +292: GCS_Arc_1960 = 4210 , +293: GCS_Batavia = 4211 , +294: GCS_Barbados = 4212 , +295: GCS_Beduaram = 4213 , +296: GCS_Beijing_1954 = 4214 , +297: GCS_Belge_1950 = 4215 , +298: GCS_Bermuda_1957 = 4216 , +299: GCS_Bern_1898 = 4217 , +300: GCS_Bogota = 4218 , +301: GCS_Bukit_Rimpah = 4219 , +302: GCS_Camacupa = 4220 , +303: GCS_Campo_Inchauspe = 4221 , +304: GCS_Cape = 4222 , +305: GCS_Carthage = 4223 , +306: GCS_Chua = 4224 , +307: GCS_Corrego_Alegre = 4225 , +308: GCS_Cote_d_Ivoire = 4226 , +309: GCS_Deir_ez_Zor = 4227 , +310: GCS_Douala = 4228 , +311: GCS_Egypt_1907 = 4229 , +312: GCS_ED50 = 4230 , +313: GCS_ED87 = 4231 , +314: GCS_Fahud = 4232 , +315: GCS_Gandajika_1970 = 4233 , +316: GCS_Garoua = 4234 , +317: GCS_Guyane_Francaise = 4235 , +318: GCS_Hu_Tzu_Shan = 4236 , +319: GCS_HD72 = 4237 , +320: GCS_ID74 = 4238 , +321: GCS_Indian_1954 = 4239 , +322: GCS_Indian_1975 = 4240 , +323: GCS_Jamaica_1875 = 4241 , +324: GCS_JAD69 = 4242 , +325: GCS_Kalianpur = 4243 , +326: GCS_Kandawala = 4244 , +327: GCS_Kertau = 4245 , +328: GCS_KOC = 4246 , +329: GCS_La_Canoa = 4247 , +330: GCS_PSAD56 = 4248 , +331: GCS_Lake = 4249 , +332: GCS_Leigon = 4250 , +333: GCS_Liberia_1964 = 4251 , +334: GCS_Lome = 4252 , +335: GCS_Luzon_1911 = 4253 , +336: GCS_Hito_XVIII_1963 = 4254 , +337: GCS_Herat_North = 4255 , +338: GCS_Mahe_1971 = 4256 , +339: GCS_Makassar = 4257 , +340: GCS_EUREF89 = 4258 , +341: GCS_Malongo_1987 = 4259 , +342: GCS_Manoca = 4260 , +343: GCS_Merchich = 4261 , +344: GCS_Massawa = 4262 , +345: GCS_Minna = 4263 , +346: GCS_Mhast = 4264 , +347: GCS_Monte_Mario = 4265 , +348: GCS_M_poraloko = 4266 , +349: GCS_NAD27 = 4267 , +350: GCS_NAD_Michigan = 4268 , +351: GCS_NAD83 = 4269 , +352: GCS_Nahrwan_1967 = 4270 , +353: GCS_Naparima_1972 = 4271 , +354: GCS_GD49 = 4272 , +355: GCS_NGO_1948 = 4273 , +356: GCS_Datum_73 = 4274 , +357: GCS_NTF = 4275 , +358: GCS_NSWC_9Z_2 = 4276 , +359: GCS_OSGB_1936 = 4277 , +360: GCS_OSGB70 = 4278 , +361: GCS_OS_SN80 = 4279 , +362: GCS_Padang = 4280 , +363: GCS_Palestine_1923 = 4281 , +364: GCS_Pointe_Noire = 4282 , +365: GCS_GDA94 = 4283 , +366: GCS_Pulkovo_1942 = 4284 , +367: GCS_Qatar = 4285 , +368: GCS_Qatar_1948 = 4286 , +369: GCS_Qornoq = 4287 , +370: GCS_Loma_Quintana = 4288 , +371: GCS_Amersfoort = 4289 , +372: GCS_RT38 = 4290 , +373: GCS_SAD69 = 4291 , +374: GCS_Sapper_Hill_1943 = 4292 , +375: GCS_Schwarzeck = 4293 , +376: GCS_Segora = 4294 , +377: GCS_Serindung = 4295 , +378: GCS_Sudan = 4296 , +379: GCS_Tananarive = 4297 , +380: GCS_Timbalai_1948 = 4298 , +381: GCS_TM65 = 4299 , +382: GCS_TM75 = 4300 , +383: GCS_Tokyo = 4301 , +384: GCS_Trinidad_1903 = 4302 , +385: GCS_TC_1948 = 4303 , +386: GCS_Voirol_1875 = 4304 , +387: GCS_Voirol_Unifie = 4305 , +388: GCS_Bern_1938 = 4306 , +389: GCS_Nord_Sahara_1959 = 4307 , +390: GCS_Stockholm_1938 = 4308 , +391: GCS_Yacare = 4309 , +392: GCS_Yoff = 4310 , +393: GCS_Zanderij = 4311 , +394: GCS_MGI = 4312 , +395: GCS_Belge_1972 = 4313 , +396: GCS_DHDN = 4314 , +397: GCS_Conakry_1905 = 4315 , +398: GCS_WGS_72 = 4322 , +399: GCS_WGS_72BE = 4324 , +400: GCS_WGS_84 = 4326 , +401: GCS_Bern_1898_Bern = 4801 , +402: GCS_Bogota_Bogota = 4802 , +403: GCS_Lisbon_Lisbon = 4803 , +404: GCS_Makassar_Jakarta = 4804 , +405: GCS_MGI_Ferro = 4805 , +406: GCS_Monte_Mario_Rome = 4806 , +407: GCS_NTF_Paris = 4807 , +408: GCS_Padang_Jakarta = 4808 , +409: GCS_Belge_1950_Brussels = 4809 , +410: GCS_Tananarive_Paris = 4810 , +411: GCS_Voirol_1875_Paris = 4811 , +412: GCS_Voirol_Unifie_Paris = 4812 , +413: GCS_Batavia_Jakarta = 4813 , +414: GCS_ATF_Paris = 4901 , +415: GCS_NDG_Paris = 4902 , +416: GCSE_Airy1830 = 4001 , +417: GCSE_AiryModified1849 = 4002 , +418: GCSE_AustralianNationalSpheroid = 4003 , +419: GCSE_Bessel1841 = 4004 , +420: GCSE_BesselModified = 4005 , +421: GCSE_BesselNamibia = 4006 , +422: GCSE_Clarke1858 = 4007 , +423: GCSE_Clarke1866 = 4008 , +424: GCSE_Clarke1866Michigan = 4009 , +425: GCSE_Clarke1880_Benoit = 4010 , +426: GCSE_Clarke1880_IGN = 4011 , +427: GCSE_Clarke1880_RGS = 4012 , +428: GCSE_Clarke1880_Arc = 4013 , +429: GCSE_Clarke1880_SGA1922 = 4014 , +430: GCSE_Everest1830_1937Adjustment = 4015 , +431: GCSE_Everest1830_1967Definition = 4016 , +432: GCSE_Everest1830_1975Definition = 4017 , +433: GCSE_Everest1830Modified = 4018 , +434: GCSE_GRS1980 = 4019 , +435: GCSE_Helmert1906 = 4020 , +436: GCSE_IndonesianNationalSpheroid = 4021 , +437: GCSE_International1924 = 4022 , +438: GCSE_International1967 = 4023 , +439: GCSE_Krassowsky1940 = 4024 , +440: GCSE_NWL9D = 4025 , +441: GCSE_NWL10D = 4026 , +442: GCSE_Plessis1817 = 4027 , +443: GCSE_Struve1860 = 4028 , +444: GCSE_WarOffice = 4029 , +445: GCSE_WGS84 = 4030 , +446: GCSE_GEM10C = 4031 , +447: GCSE_OSU86F = 4032 , +448: GCSE_OSU91A = 4033 , +449: GCSE_Clarke1880 = 4034 , +450: GCSE_Sphere = 4035 +451: } GCSCode_t ; +452: +453: +454: +455: +456: typedef enum < short > { +457: Datum_Adindan = 6201 , +458: Datum_Australian_Geodetic_Datum_1966 = 6202 , +459: Datum_Australian_Geodetic_Datum_1984 = 6203 , +460: Datum_Ain_el_Abd_1970 = 6204 , +461: Datum_Afgooye = 6205 , +462: Datum_Agadez = 6206 , +463: Datum_Lisbon = 6207 , +464: Datum_Aratu = 6208 , +465: Datum_Arc_1950 = 6209 , +466: Datum_Arc_1960 = 6210 , +467: Datum_Batavia = 6211 , +468: Datum_Barbados = 6212 , +469: Datum_Beduaram = 6213 , +470: Datum_Beijing_1954 = 6214 , +471: Datum_Reseau_National_Belge_1950 = 6215 , +472: Datum_Bermuda_1957 = 6216 , +473: Datum_Bern_1898 = 6217 , +474: Datum_Bogota = 6218 , +475: Datum_Bukit_Rimpah = 6219 , +476: Datum_Camacupa = 6220 , +477: Datum_Campo_Inchauspe = 6221 , +478: Datum_Cape = 6222 , +479: Datum_Carthage = 6223 , +480: Datum_Chua = 6224 , +481: Datum_Corrego_Alegre = 6225 , +482: Datum_Cote_d_Ivoire = 6226 , +483: Datum_Deir_ez_Zor = 6227 , +484: Datum_Douala = 6228 , +485: Datum_Egypt_1907 = 6229 , +486: Datum_European_Datum_1950 = 6230 , +487: Datum_European_Datum_1987 = 6231 , +488: Datum_Fahud = 6232 , +489: Datum_Gandajika_1970 = 6233 , +490: Datum_Garoua = 6234 , +491: Datum_Guyane_Francaise = 6235 , +492: Datum_Hu_Tzu_Shan = 6236 , +493: Datum_Hungarian_Datum_1972 = 6237 , +494: Datum_Indonesian_Datum_1974 = 6238 , +495: Datum_Indian_1954 = 6239 , +496: Datum_Indian_1975 = 6240 , +497: Datum_Jamaica_1875 = 6241 , +498: Datum_Jamaica_1969 = 6242 , +499: Datum_Kalianpur = 6243 , +500: Datum_Kandawala = 6244 , +501: Datum_Kertau = 6245 , +502: Datum_Kuwait_Oil_Company = 6246 , +503: Datum_La_Canoa = 6247 , +504: Datum_Provisional_S_American_Datum_1956 = 6248 , +505: Datum_Lake = 6249 , +506: Datum_Leigon = 6250 , +507: Datum_Liberia_1964 = 6251 , +508: Datum_Lome = 6252 , +509: Datum_Luzon_1911 = 6253 , +510: Datum_Hito_XVIII_1963 = 6254 , +511: Datum_Herat_North = 6255 , +512: Datum_Mahe_1971 = 6256 , +513: Datum_Makassar = 6257 , +514: Datum_European_Reference_System_1989 = 6258 , +515: Datum_Malongo_1987 = 6259 , +516: Datum_Manoca = 6260 , +517: Datum_Merchich = 6261 , +518: Datum_Massawa = 6262 , +519: Datum_Minna = 6263 , +520: Datum_Mhast = 6264 , +521: Datum_Monte_Mario = 6265 , +522: Datum_M_poraloko = 6266 , +523: Datum_North_American_Datum_1927 = 6267 , +524: Datum_NAD_Michigan = 6268 , +525: Datum_North_American_Datum_1983 = 6269 , +526: Datum_Nahrwan_1967 = 6270 , +527: Datum_Naparima_1972 = 6271 , +528: Datum_New_Zealand_Geodetic_Datum_1949 = 6272 , +529: Datum_NGO_1948 = 6273 , +530: Datum_Datum_73 = 6274 , +531: Datum_Nouvelle_Triangulation_Francaise = 6275 , +532: Datum_NSWC_9Z_2 = 6276 , +533: Datum_OSGB_1936 = 6277 , +534: Datum_OSGB_1970_SN = 6278 , +535: Datum_OS_SN_1980 = 6279 , +536: Datum_Padang_1884 = 6280 , +537: Datum_Palestine_1923 = 6281 , +538: Datum_Pointe_Noire = 6282 , +539: Datum_Geocentric_Datum_of_Australia_1994 = 6283 , +540: Datum_Pulkovo_1942 = 6284 , +541: Datum_Qatar = 6285 , +542: Datum_Qatar_1948 = 6286 , +543: Datum_Qornoq = 6287 , +544: Datum_Loma_Quintana = 6288 , +545: Datum_Amersfoort = 6289 , +546: Datum_RT38 = 6290 , +547: Datum_South_American_Datum_1969 = 6291 , +548: Datum_Sapper_Hill_1943 = 6292 , +549: Datum_Schwarzeck = 6293 , +550: Datum_Segora = 6294 , +551: Datum_Serindung = 6295 , +552: Datum_Sudan = 6296 , +553: Datum_Tananarive_1925 = 6297 , +554: Datum_Timbalai_1948 = 6298 , +555: Datum_TM65 = 6299 , +556: Datum_TM75 = 6300 , +557: Datum_Tokyo = 6301 , +558: Datum_Trinidad_1903 = 6302 , +559: Datum_Trucial_Coast_1948 = 6303 , +560: Datum_Voirol_1875 = 6304 , +561: Datum_Voirol_Unifie_1960 = 6305 , +562: Datum_Bern_1938 = 6306 , +563: Datum_Nord_Sahara_1959 = 6307 , +564: Datum_Stockholm_1938 = 6308 , +565: Datum_Yacare = 6309 , +566: Datum_Yoff = 6310 , +567: Datum_Zanderij = 6311 , +568: Datum_Militar_Geographische_Institut = 6312 , +569: Datum_Reseau_National_Belge_1972 = 6313 , +570: Datum_Deutsche_Hauptdreiecksnetz = 6314 , +571: Datum_Conakry_1905 = 6315 , +572: Datum_WGS72 = 6322 , +573: Datum_WGS72_Transit_Broadcast_Ephemeris = 6324 , +574: Datum_WGS84 = 6326 , +575: Datum_Ancienne_Triangulation_Francaise = 6901 , +576: Datum_Nord_de_Guerre = 6902 , +577: +578: +579: +580: DatumE_Airy1830 = 6001 , +581: DatumE_AiryModified1849 = 6002 , +582: DatumE_AustralianNationalSpheroid = 6003 , +583: DatumE_Bessel1841 = 6004 , +584: DatumE_BesselModified = 6005 , +585: DatumE_BesselNamibia = 6006 , +586: DatumE_Clarke1858 = 6007 , +587: DatumE_Clarke1866 = 6008 , +588: DatumE_Clarke1866Michigan = 6009 , +589: DatumE_Clarke1880_Benoit = 6010 , +590: DatumE_Clarke1880_IGN = 6011 , +591: DatumE_Clarke1880_RGS = 6012 , +592: DatumE_Clarke1880_Arc = 6013 , +593: DatumE_Clarke1880_SGA1922 = 6014 , +594: DatumE_Everest1830_1937Adjustment = 6015 , +595: DatumE_Everest1830_1967Definition = 6016 , +596: DatumE_Everest1830_1975Definition = 6017 , +597: DatumE_Everest1830Modified = 6018 , +598: DatumE_GRS1980 = 6019 , +599: DatumE_Helmert1906 = 6020 , +600: DatumE_IndonesianNationalSpheroid = 6021 , +601: DatumE_International1924 = 6022 , +602: DatumE_International1967 = 6023 , +603: DatumE_Krassowsky1960 = 6024 , +604: DatumE_NWL9D = 6025 , +605: DatumE_NWL10D = 6026 , +606: DatumE_Plessis1817 = 6027 , +607: DatumE_Struve1860 = 6028 , +608: DatumE_WarOffice = 6029 , +609: DatumE_WGS84 = 6030 , +610: DatumE_GEM10C = 6031 , +611: DatumE_OSU86F = 6032 , +612: DatumE_OSU91A = 6033 , +613: DatumE_Clarke1880 = 6034 , +614: DatumE_Sphere = 6035 +615: } DatumCode_t ; +616: +617: +618: +619: +620: typedef enum < short > { +621: Ellipse_Airy_1830 = 7001 , +622: Ellipse_Airy_Modified_1849 = 7002 , +623: Ellipse_Australian_National_Spheroid = 7003 , +624: Ellipse_Bessel_1841 = 7004 , +625: Ellipse_Bessel_Modified = 7005 , +626: Ellipse_Bessel_Namibia = 7006 , +627: Ellipse_Clarke_1858 = 7007 , +628: Ellipse_Clarke_1866 = 7008 , +629: Ellipse_Clarke_1866_Michigan = 7009 , +630: Ellipse_Clarke_1880_Benoit = 7010 , +631: Ellipse_Clarke_1880_IGN = 7011 , +632: Ellipse_Clarke_1880_RGS = 7012 , +633: Ellipse_Clarke_1880_Arc = 7013 , +634: Ellipse_Clarke_1880_SGA_1922 = 7014 , +635: Ellipse_Everest_1830_1937_Adjustment = 7015 , +636: Ellipse_Everest_1830_1967_Definition = 7016 , +637: Ellipse_Everest_1830_1975_Definition = 7017 , +638: Ellipse_Everest_1830_Modified = 7018 , +639: Ellipse_GRS_1980 = 7019 , +640: Ellipse_Helmert_1906 = 7020 , +641: Ellipse_Indonesian_National_Spheroid = 7021 , +642: Ellipse_International_1924 = 7022 , +643: Ellipse_International_1967 = 7023 , +644: Ellipse_Krassowsky_1940 = 7024 , +645: Ellipse_NWL_9D = 7025 , +646: Ellipse_NWL_10D = 7026 , +647: Ellipse_Plessis_1817 = 7027 , +648: Ellipse_Struve_1860 = 7028 , +649: Ellipse_War_Office = 7029 , +650: Ellipse_WGS_84 = 7030 , +651: Ellipse_GEM_10C = 7031 , +652: Ellipse_OSU86F = 7032 , +653: Ellipse_OSU91A = 7033 , +654: Ellipse_Clarke_1880 = 7034 , +655: Ellipse_Sphere = 7035 +656: } EllipsoidCode_t ; +657: +658: +659: +660: typedef enum < short > { +661: PM_Greenwich = 8901 , +662: PM_Lisbon = 8902 , +663: PM_Paris = 8903 , +664: PM_Bogota = 8904 , +665: PM_Madrid = 8905 , +666: PM_Rome = 8906 , +667: PM_Bern = 8907 , +668: PM_Jakarta = 8908 , +669: PM_Ferro = 8909 , +670: PM_Brussels = 8910 , +671: PM_Stockholm = 8911 +672: } PrimeMeridianCode_t ; +673: +674: +675: +676: +677: +678: +679: typedef enum < short > { +680: CT_TransverseMercator = 1 , +681: CT_TransvMercator_Modified_Alaska = 2 , +682: CT_ObliqueMercator = 3 , +683: CT_ObliqueMercator_Laborde = 4 , +684: CT_ObliqueMercator_Rosenmund = 5 , +685: CT_ObliqueMercator_Spherical = 6 , +686: CT_Mercator = 7 , +687: CT_LambertConfConic_2SP = 8 , +688: CT_LambertConfConic_Helmert = 9 , +689: CT_LambertAzimEqualArea = 10 , +690: CT_AlbersEqualArea = 11 , +691: CT_AzimuthalEquidistant = 12 , +692: CT_EquidistantConic = 13 , +693: CT_Stereographic = 14 , +694: CT_PolarStereographic = 15 , +695: CT_ObliqueStereographic = 16 , +696: CT_Equirectangular = 17 , +697: CT_CassiniSoldner = 18 , +698: CT_Gnomonic = 19 , +699: CT_MillerCylindrical = 20 , +700: CT_Orthographic = 21 , +701: CT_Polyconic = 22 , +702: CT_Robinson = 23 , +703: CT_Sinusoidal = 24 , +704: CT_VanDerGrinten = 25 , +705: CT_NewZealandMapGrid = 26 , +706: CT_TransvMercator_SouthOriented = 27 +707: } CTCode_t ; +708: +709: +710: +711: +712: +713: typedef struct { +714: SetBackColor ( cLtAqua ) ; +715: GeoKEYlabel label ; +716: if ( ReadUShort ( FTell ( ) ) != 0 ) +717: { +718: TAG TiffTagLocation ; +719: uint16 Length ; +720: uint16 Offset ; +721: } +722: else +723: { +724: uint16 direct ; +725: uint16 size ; +726: +727: +728: switch ( size ) { +729: case 1 : +730: +731: +732: switch ( label ) { +733: case GTModelTypeGeoKey : +734: modeltype_t value ; +735: break ; +736: +737: case GTRasterTypeGeoKey : +738: rastertype_t value ; +739: break ; +740: +741: case GeographicTypeGeoKey : +742: GCSCode_t value ; +743: break ; +744: +745: case GeogGeodeticDatumGeoKey : +746: DatumCode_t value ; +747: break ; +748: +749: case GeogPrimeMeridianGeoKey : +750: PrimeMeridianCode_t value ; +751: break ; +752: +753: case GeogLinearUnitsGeoKey : +754: LinearUnitCode_t value ; +755: break ; +756: +757: case GeogAngularUnitsGeoKey : +758: AngularUnitCode_t value ; +759: break ; +760: +761: case GeogEllipsoidGeoKey : +762: EllipsoidCode_t value ; +763: break ; +764: +765: case GeogAzimuthUnitsGeoKey : +766: AngularUnitCode_t value ; +767: break ; +768: +769: case ProjectedCSTypeGeoKey : +770: short value ; +771: break ; +772: +773: case ProjectionGeoKey : +774: short value ; +775: break ; +776: +777: case ProjCoordTransGeoKey : +778: short value ; +779: break ; +780: +781: case ProjLinearUnitsGeoKey : +782: short value ; +783: break ; +784: +785: case VerticalCSTypeGeoKey : +786: short value ; +787: break ; +788: +789: case VerticalDatumGeoKey : +790: short value ; +791: break ; +792: +793: case VerticalUnitsGeoKey : +794: LinearUnitCode_t value ; +795: break ; +796: +797: default : +798: short value ; +799: } ; +800: break ; +801: +802: default : +803: double value ; +804: } ; +805: +806: } +807: } GEOKEY < read = readGEOKEY > ; +808: +809: +810: +811: +812: +813: +814: string readGEOKEY ( local GEOKEY & gk ) { +815: local string s ; +816: +817: SPrintf ( s , "%s (%d)" , EnumToString ( gk . label ) , gk . label ) ; +818: return s ; +819: } +820: +821: +822: typedef struct eGEOKEYDIR { +823: SetBackColor ( cLtAqua ) ; +824: uint16 GeoTiffVersion ; +825: uint16 GeoTiffRevMajor ; +826: uint16 GeoTiffRevMinor ; +827: uint16 GeoKeyCount ; +828: local uint16 i ; +829: for ( i == 0 ; i < GeoKeyCount ; i ++ ) +830: { GEOKEY GeoKeyValue ; } ; +831: } GEOKEYDIR ; +832: +833: +834: +835: +836: typedef struct { +837: uint32 num ; +838: uint32 dom ; +839: } RATIONAL < read = readRATIONAL , write = writeRATIONAL > ; +840: +841: string readRATIONAL ( local RATIONAL & r ) { +842: local string s ; +843: SPrintf ( s , "%d/%d" , r . num , r . dom ) ; +844: return s ; +845: } +846: +847: void writeRATIONAL ( local RATIONAL & r , local string s ) { +848: SScanf ( s , "%d/%d" , r . num , r . dom ) ; +849: } +850: +851: +852: +853: typedef struct { +854: int32 num ; +855: int32 dom ; +856: } SRATIONAL < read = readSRATIONAL , write = writeSRATIONAL > ; +857: +858: string readSRATIONAL ( local SRATIONAL & r ) { +859: local string s ; +860: SPrintf ( s , "%d/%d" , r . num , r . dom ) ; +861: return s ; +862: } +863: +864: void writeSRATIONAL ( local SRATIONAL & r , local string s ) { +865: SScanf ( s , "%d/%d" , r . num , r . dom ) ; +866: } +867: +868: +869: +870: +871: +872: +873: +874: typedef struct { +875: SetBackColor ( cLtGreen ) ; +876: +877: TAG tag ; +878: TAGTYPE typ ; +879: uint32 count ; +880: if ( typ == eBYTE ) { +881: if ( count < 4 ) { +882: ubyte data [ count ] ; +883: ubyte padding [ 4 - count ] ; +884: } else if ( count == 4 ) { +885: ubyte data [ count ] ; +886: } else { +887: SetBackColor ( cLtBlue ) ; +888: uint32 offset < format = hex > ; +889: local quad curpos = FTell ( ) ; +890: FSeek ( offset ) ; +891: +892: ubyte value [ count ] ; +893: FSeek ( curpos ) ; +894: } +895: } else if ( typ == eASCII ) { +896: if ( count < 4 ) { +897: char data [ count ] ; +898: char padding [ 4 - count ] ; +899: } else if ( count == 4 ) { +900: char data [ count ] ; +901: } else { +902: SetBackColor ( cLtBlue ) ; +903: uint32 offset < format = hex > ; +904: local quad curpos = FTell ( ) ; +905: FSeek ( offset ) ; +906: char data [ count ] ; +907: FSeek ( curpos ) ; +908: } +909: } else if ( typ == eSHORT ) { +910: if ( count == 1 ) { +911: if ( tag == Compression ) { +912: COMP value ; +913: } else if ( tag == PhotometricInterpretation ) { +914: PHOTO value ; +915: } else if ( tag == ResolutionUnit ) { +916: RES value ; +917: } else { +918: uint16 value ; +919: +920: } +921: uint16 padding ; +922: } else if ( count == 2 ) { +923: uint16 value [ 2 ] ; +924: } else { +925: SetBackColor ( cLtBlue ) ; +926: uint32 offset < format = hex > ; +927: local quad curpos = FTell ( ) ; +928: FSeek ( offset ) ; +929: +930: +931: if ( tag == GeoKeyDirectoryTag ) { +932: GEOKEYDIR value ; +933: } else { +934: +935: +936: uint16 value [ count ] ; +937: } +938: +939: FSeek ( curpos ) ; +940: } +941: } else if ( typ == eLONG ) { +942: if ( count == 1 ) { +943: uint32 value ; +944: } else { +945: SetBackColor ( cLtBlue ) ; +946: uint32 offset < format = hex > ; +947: local quad curpos = FTell ( ) ; +948: FSeek ( offset ) ; +949: uint32 value [ count ] ; +950: FSeek ( curpos ) ; +951: } +952: } else if ( typ == eRATIONAL ) { +953: SetBackColor ( cLtBlue ) ; +954: uint32 offset < format = hex > ; +955: local quad curpos = FTell ( ) ; +956: FSeek ( offset ) ; +957: if ( count == 1 ) { +958: RATIONAL value ; +959: } else { +960: RATIONAL value [ count ] ; +961: } +962: FSeek ( curpos ) ; +963: } else if ( typ == eSBYTE ) { +964: if ( count < 4 ) { +965: byte data [ count ] ; +966: ubyte padding [ 4 - count ] ; +967: } else if ( count == 4 ) { +968: byte data [ count ] ; +969: } else { +970: SetBackColor ( cLtBlue ) ; +971: uint32 offset < format = hex > ; +972: local quad curpos = FTell ( ) ; +973: FSeek ( offset ) ; +974: byte value [ count ] ; +975: FSeek ( curpos ) ; +976: } +977: } else if ( typ == eUNDEF ) { +978: if ( count < 4 ) { +979: ubyte data [ count ] ; +980: ubyte padding [ 4 - count ] ; +981: } else if ( count == 4 ) { +982: ubyte data [ count ] ; +983: } else { +984: SetBackColor ( cLtBlue ) ; +985: uint32 offset < format = hex > ; +986: local quad curpos = FTell ( ) ; +987: FSeek ( offset ) ; +988: ubyte value [ count ] ; +989: FSeek ( curpos ) ; +990: } +991: } else if ( typ == eSSHORT ) { +992: if ( count == 1 ) { +993: int16 value ; +994: int16 padding ; +995: } else if ( count == 2 ) { +996: int16 value [ 2 ] ; +997: } else { +998: SetBackColor ( cLtBlue ) ; +999: uint32 offset < format = hex > ; +1000: local quad curpos = FTell ( ) ; +1001: FSeek ( offset ) ; +1002: int16 value [ count ] ; +1003: FSeek ( curpos ) ; +1004: } +1005: } else if ( typ == eSLONG ) { +1006: if ( count == 1 ) { +1007: int32 value ; +1008: } else { +1009: SetBackColor ( cLtBlue ) ; +1010: uint32 offset < format = hex > ; +1011: local quad curpos = FTell ( ) ; +1012: FSeek ( offset ) ; +1013: int32 value [ count ] ; +1014: FSeek ( curpos ) ; +1015: } +1016: } else if ( typ == eSRATIONAL ) { +1017: SetBackColor ( cLtBlue ) ; +1018: uint32 offset < format = hex > ; +1019: local quad curpos = FTell ( ) ; +1020: FSeek ( offset ) ; +1021: if ( count == 1 ) { +1022: SRATIONAL value ; +1023: } else { +1024: SRATIONAL value [ count ] ; +1025: } +1026: FSeek ( curpos ) ; +1027: } else if ( typ == eFLOAT ) { +1028: if ( count == 1 ) { +1029: float value ; +1030: } else { +1031: SetBackColor ( cLtBlue ) ; +1032: uint32 offset < format = hex > ; +1033: local quad curpos = FTell ( ) ; +1034: FSeek ( offset ) ; +1035: float value [ count ] ; +1036: FSeek ( curpos ) ; +1037: } +1038: } else if ( typ == eDOUBLE ) { +1039: SetBackColor ( cLtBlue ) ; +1040: uint32 offset < format = hex > ; +1041: local quad curpos = FTell ( ) ; +1042: FSeek ( offset ) ; +1043: if ( count == 1 ) { +1044: double value ; +1045: } else { +1046: double value [ count ] ; +1047: } +1048: FSeek ( curpos ) ; +1049: } else { +1050: +1051: +1052: +1053: uint32 valOffset < format = hex > ; +1054: } +1055: } ENT < read = readENT > ; +1056: +1057: +1058: +1059: +1060: +1061: +1062: string readENT ( local ENT & ent ) { +1063: local string s ; +1064: +1065: SPrintf ( s , "%s (%d): %s" , EnumToString ( ent . tag ) , ent . tag , EnumToString ( ent . typ ) ) ; +1066: return s ; +1067: } +1068: +1069: +1070: typedef struct { +1071: uint16 numentries ; +1072: ENT dir [ numentries ] < optimize = false > ; +1073: uint32 offset < format = hex > ; +1074: nextIFD = ( quad ) offset ; +1075: } IFD < read = readIFD > ; +1076: +1077: +1078: +1079: +1080: +1081: +1082: string readIFD ( local IFD & ifd ) { +1083: local string s ; +1084: +1085: SPrintf ( s , "%d: %s" , ifd . numentries , ( ifd . numentries > 0 ) ? EnumToString ( ifd . dir [ 0 ] . tag ) : "" ) ; +1086: return s ; +1087: } +1088: +1089: +1090: typedef struct { +1091: char bom [ 2 ] ; +1092: uint16 magic ; +1093: if ( magic != 42 ) { +1094: Warning ( "Invalid TIFF File: Bad Magic number" ) ; +1095: return - 1 ; +1096: } +1097: uint32 offset < format = hex > ; +1098: +1099: +1100: if ( offset == 0 ) { +1101: Warning ( "Invalid TIFF File: No initial IFD" ) ; +1102: return - 1 ; +1103: } +1104: +1105: nextIFD = ( quad ) offset ; +1106: } IFH ; +1107: +1108: +1109: +1110: +1111: +1112: SetBackColor ( cLtRed ) ; +1113: IFH ifh ; +1114: while ( nextIFD ) { +1115: SetBackColor ( cLtGreen ) ; +1116: FSeek ( nextIFD ) ; +1117: IFD ifd ; +1118: } +1119: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/GocleverTemplate.bt b/cparser/tests/exp_lex/GocleverTemplate.bt new file mode 100644 index 0000000..6eff4c4 --- /dev/null +++ b/cparser/tests/exp_lex/GocleverTemplate.bt @@ -0,0 +1,42 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +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 < number_of_records ; i ++ ) +38: { +39: s = TimeTToString ( goclever [ i ] . date ) ; +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: } ; +42: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/ICOTemplate.bt b/cparser/tests/exp_lex/ICOTemplate.bt new file mode 100644 index 0000000..53d52d7 --- /dev/null +++ b/cparser/tests/exp_lex/ICOTemplate.bt @@ -0,0 +1,159 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: typedef struct +15: { +16: BYTE bWidth ; +17: BYTE bHeight ; +18: BYTE bColorCount ; +19: BYTE bReserved ; +20: WORD wPlanes ; +21: WORD wBitCount ; +22: DWORD dwBytesInRes ; +23: DWORD dwImageOffset ; +24: } ICONDIRENTRY < read = ReadIconDirEntry > ; +25: +26: typedef struct +27: { +28: WORD idReserved ; +29: WORD idType ; +30: WORD idCount ; +31: ICONDIRENTRY idEntries [ idCount ] ; +32: } ICONDIR ; +33: +34: typedef struct { +35: UBYTE rgbBlue ; +36: UBYTE rgbGreen ; +37: UBYTE rgbRed ; +38: UBYTE rgbReserved ; +39: } RGBQUAD < read = ReadRGBQUAD > ; +40: +41: typedef struct { +42: UBYTE rgbBlue ; +43: UBYTE rgbGreen ; +44: UBYTE rgbRed ; +45: } RGBTRIPLE < read = ReadRGBTRIPLE > ; +46: +47: typedef struct { +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: +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: +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: +78: struct BITMAPLINE { +79: +80: +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: +91: if ( padding != 0 ) +92: UBYTE padBytes [ padding ] ; +93: +94: } lines [ bmiHeader . biHeight / 2 ] < optimize = false > ; +95: +96: +97: struct MASKLINE { +98: UBYTE line [ ( ( bmiHeader . biWidth + 31 ) / 32 ) * 4 ] < format = hex > ; +99: } mask [ bmiHeader . biHeight / 2 ] < optimize = false > ; +100: +101: } IMAGEDATA ; +102: +103: typedef struct { +104: SetBackColor ( cLtAqua ) ; +105: BITMAPINFOHEADER bmiHeader ; +106: SetBackColor ( cLtGray ) ; +107: IMAGEDATA data ; +108: } ICONIMAGE < read = ReadDIBHeader > ; +109: +110: +111: +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: +145: LittleEndian ( ) ; +146: +147: local short res = ReadShort ( FTell ( ) ) ; +148: local short type = ReadShort ( FTell ( ) + 2 ) ; +149: +150: +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 ] < optimize = false > ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/ISOBMFTemplate.bt b/cparser/tests/exp_lex/ISOBMFTemplate.bt new file mode 100644 index 0000000..ecd3299 --- /dev/null +++ b/cparser/tests/exp_lex/ISOBMFTemplate.bt @@ -0,0 +1,157 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: BigEndian ( ) ; +11: +12: typedef struct +13: { +14: uint32 size < hidden = true > ; +15: char type [ 4 ] < hidden = true > ; +16: switch ( type ) +17: { +18: case "ftyp" : +19: char fileType [ 4 ] < name = "File type" , comment = "http://ftyps.com/" > ; +20: break ; +21: +22: case "co64" : +23: ubyte version < name = "Version" > ; +24: ubyte flags [ 3 ] < name = "Flags" , format = binary > ; +25: uint32 n < hidden = true > ; +26: uint64 entries [ n ] < name = "Chunk offsets" > ; +27: break ; +28: +29: case "ctts" : +30: ubyte version < name = "Version" > ; +31: ubyte flags [ 3 ] < name = "Flags" , format = binary > ; +32: uint32 n < hidden = true > ; +33: struct { +34: uint32 sampleCount < name = "Sample count" > ; +35: uint32 offset < name = "Offset" > ; +36: } entries [ n ] < name = "Chunk offsets" > ; +37: break ; +38: +39: case "elst" : +40: ubyte version < name = "Version" > ; +41: ubyte flags [ 3 ] < name = "Flags" , format = binary > ; +42: uint32 n < hidden = true > ; +43: struct { +44: uint32 duration < name = "Duration" , comment = "In global timescale units" > ; +45: uint32 mediaTime < name = "Media time" , comment = "In trak timescale units" > ; +46: uint32 playbackSpeed < name = "Playback speed" > ; +47: } entries [ n ] < name = "Edit list entries" > ; +48: break ; +49: +50: case "fiel" : +51: ubyte fields < name = "Scan mode" , comment = "1 for progressive scan, 2 for 2:1 interlaced" > ; +52: ubyte detail < name = "Detail" , comment = "https://developer.apple.com/quicktime/icefloe/dispatch019.html#fiel" > ; +53: break ; +54: +55: case "hdlr" : +56: ubyte version < name = "Version" > ; +57: ubyte flags [ 3 ] < name = "Flags" , format = binary > ; +58: char component_type [ 4 ] < name = "Component type" > ; +59: char subtype [ 4 ] < name = "Component subtype" > ; +60: uint32 manufacturer < name = "Component manufacturer" > ; +61: uint32 flags < name = "Component flags" > ; +62: uint32 flags_mask < name = "Component flags mask" > ; +63: string name < name = "Component name" > ; +64: break ; +65: +66: case "mdhd" : +67: ubyte version < name = "Version" > ; +68: ubyte flags [ 3 ] < name = "Flags" , format = binary > ; +69: if ( version < 1 ) +70: { +71: uint32 creation_time < name = "Creation time" > ; +72: uint32 modification_time < name = "Modification time" > ; +73: } +74: else +75: { +76: uint64 creation_time < name = "Creation time" > ; +77: uint64 modification_time < name = "Modification time" > ; +78: } +79: uint32 time_scale < name = "Time scale" > ; +80: if ( version < 1 ) +81: { +82: uint32 duration < name = "Duration" > ; +83: } +84: else +85: { +86: uint64 duration < name = "Duration" > ; +87: } +88: uint16 lang < name = "Language" , format = binary , comment = "ISO-639 language code represented with three 5-bit values (each of which is the ASCII value of the letter minus 0x60)" > ; +89: uint16 quality < name = "Quality" > ; +90: break ; +91: +92: case "stco" : +93: ubyte version < name = "Version" > ; +94: ubyte flags [ 3 ] < name = "Flags" , format = binary > ; +95: uint32 n < hidden = true > ; +96: uint32 entries [ n ] < name = "Chunk offsets" > ; +97: break ; +98: +99: case "stss" : +100: ubyte version < name = "Version" > ; +101: ubyte flags [ 3 ] < name = "Flags" , format = binary > ; +102: uint32 n < hidden = true > ; +103: uint32 entries [ n ] < name = "Sync samples" > ; +104: break ; +105: +106: case "stsz" : +107: ubyte version < name = "Version" > ; +108: ubyte flags [ 3 ] < name = "Flags" , format = binary > ; +109: uint32 uniform_size < name = "Uniform size" > ; +110: uint32 n < hidden = true > ; +111: uint32 entries [ n ] < name = "Sample sizes" > ; +112: break ; +113: +114: case "cmov" : +115: case "edts" : +116: case "mdia" : +117: case "minf" : +118: case "moov" : +119: case "rmda" : +120: case "rmra" : +121: case "stbl" : +122: case "trak" : +123: while ( FTell ( ) - startof ( this ) < size ) +124: { +125: struct Atom child ; +126: } +127: break ; +128: +129: default : +130: FSeek ( FTell ( ) - 8 ) ; +131: break ; +132: } +133: +134: local int left = size - ( FTell ( ) - startof ( this ) ) ; +135: if ( left > 0 ) +136: { +137: ubyte data [ left ] < format = hex > ; +138: } +139: } +140: Atom < name = GetAtomName , size = GetAtomSize > ; +141: +142: int GetAtomSize ( Atom & atom ) +143: { +144: return ReadUInt ( startof ( atom ) ) ; +145: } +146: +147: string GetAtomName ( Atom & atom ) +148: { +149: char type [ 4 ] ; +150: ReadBytes ( type , startof ( atom ) + 4 , 4 ) ; +151: return type ; +152: } +153: +154: while ( ! FEof ( ) ) +155: { +156: Atom atom ; +157: } tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/InspectorDates.bt b/cparser/tests/exp_lex/InspectorDates.bt new file mode 100644 index 0000000..18e6ec9 --- /dev/null +++ b/cparser/tests/exp_lex/InspectorDates.bt @@ -0,0 +1,175 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: RequiresVersion ( 4 . 0 ) ; +14: +15: +16: +17: +18: local int64 pos ; +19: if ( GetSelSize ( ) > 0 ) +20: pos = GetSelStart ( ) ; +21: else +22: pos = GetCursorPos ( ) ; +23: +24: +25: FSeek ( pos ) ; byte _si8 < name = "Signed Byte" > ; +26: FSeek ( pos ) ; ubyte _ui8 < name = "Unsigned Byte" > ; +27: FSeek ( pos ) ; short _si16 < name = "Signed Short" > ; +28: FSeek ( pos ) ; ushort _ui16 < name = "Unsigned Short" > ; +29: FSeek ( pos ) ; int _si32 < name = "Signed Int" > ; +30: FSeek ( pos ) ; uint _ui32 < name = "Unsigned Int" > ; +31: FSeek ( pos ) ; int64 _si64 < name = "Signed Int64" > ; +32: FSeek ( pos ) ; uint64 _ui64 < name = "Unsigned Int64" > ; +33: FSeek ( pos ) ; float _f < name = "Float" > ; +34: FSeek ( pos ) ; double _d < name = "Double" > ; +35: FSeek ( pos ) ; char _s [ ReadStringLength ( pos , 256 ) ] < name = "String" > ; +36: FSeek ( pos ) ; wchar_t _ws [ ReadWStringLength ( pos , 256 ) ] < name = "Unicode" > ; +37: FSeek ( pos ) ; DOSDATE _dd < name = "DOS Date" > ; +38: FSeek ( pos ) ; DOSTIME _dt < name = "DOS Time" > ; +39: FSeek ( pos ) ; time_t _tt < name = "time_t" > ; +40: FSeek ( pos ) ; FILETIME _ft < name = "FILETIME" > ; +41: FSeek ( pos ) ; OLETIME _ot < name = "OLETIME" > ; +42: +43: +44: +45: +46: typedef uint64 WebkitTime < read = WebkitTimeRead , write = WebkitTimeWrite > ; +47: FSeek ( pos ) ; WebkitTime _wkt < name = "WebkitTime" > ; +48: string WebkitTimeRead ( WebkitTime t ) +49: { +50: +51: return FileTimeToString ( t * 10 ) ; +52: } +53: int WebkitTimeWrite ( WebkitTime & t , string value ) +54: { +55: +56: FILETIME ft ; +57: int result = StringToFileTime ( value , ft ) ; +58: t = ( int64 ) ft / 10 ; +59: return result ; +60: } +61: +62: +63: +64: +65: typedef uint HFSTime < read = HFSTimeRead , write = HFSTimeWrite > ; +66: FSeek ( pos ) ; HFSTime _hft < name = "HFSTime" > ; +67: string HFSTimeRead ( HFSTime t ) +68: { +69: +70: return FileTimeToString ( t * 10000000 L + 95616288000000000 L ) ; +71: } +72: int HFSTimeWrite ( HFSTime & t , string value ) +73: { +74: +75: FILETIME ft ; +76: int result = StringToFileTime ( value , ft ) ; +77: t = ( int ) ( ( ( uint64 ) ft - 95616288000000000 L ) / 10000000 L ) ; +78: return result ; +79: } +80: +81: +82: +83: +84: typedef uint AppleTime < read = AppleTimeRead , write = AppleTimeWrite > ; +85: FSeek ( pos ) ; AppleTime _at < name = "AppleTime" > ; +86: string AppleTimeRead ( AppleTime t ) +87: { +88: +89: return FileTimeToString ( t * 10000000 L + 126227808000000000 L ) ; +90: } +91: int AppleTimeWrite ( AppleTime & t , string value ) +92: { +93: +94: FILETIME ft ; +95: int result = StringToFileTime ( value , ft ) ; +96: t = ( int ) ( ( ( uint64 ) ft - 126227808000000000 L ) / 10000000 L ) ; +97: return result ; +98: } +99: +100: +101: +102: +103: typedef uint64 PRTime < read = PRTimeRead , write = PRTimeWrite > ; +104: FSeek ( pos ) ; PRTime _prt < name = "PRTime" > ; +105: string PRTimeRead ( PRTime t ) +106: { +107: +108: return FileTimeToString ( t * 10 L + 116444736000000000 L ) ; +109: } +110: int PRTimeWrite ( PRTime & t , string value ) +111: { +112: +113: FILETIME ft ; +114: int result = StringToFileTime ( value , ft ) ; +115: t = ( ( ( uint64 ) ft - 116444736000000000 L ) / 10 L ) ; +116: return result ; +117: } +118: +119: +120: +121: +122: typedef uint64 JavaTime < read = JavaTimeRead , write = JavaTimeWrite > ; +123: FSeek ( pos ) ; JavaTime _jt < name = "JavaTime" > ; +124: string JavaTimeRead ( JavaTime t ) +125: { +126: +127: return FileTimeToString ( t * 10000 L + 116444736000000000 L ) ; +128: } +129: int JavaTimeWrite ( JavaTime & t , string value ) +130: { +131: +132: FILETIME ft ; +133: int result = StringToFileTime ( value , ft ) ; +134: t = ( ( ( uint64 ) ft - 116444736000000000 L ) / 10000 L ) ; +135: return result ; +136: } +137: +138: +139: +140: +141: typedef uint GPSTime < read = GPSTimeRead , write = GPSTimeWrite > ; +142: FSeek ( pos ) ; GPSTime _gpst < name = "GPSTime" > ; +143: string GPSTimeRead ( GPSTime t ) +144: { +145: +146: return FileTimeToString ( t * 10000000 L + 119604384000000000 ) ; +147: } +148: int GPSTimeWrite ( GPSTime & t , string value ) +149: { +150: +151: FILETIME ft ; +152: int result = StringToFileTime ( value , ft ) ; +153: t = ( int ) ( ( ( uint64 ) ft - 119604384000000000 ) / 10000000 L ) ; +154: return result ; +155: } +156: +157: +158: +159: +160: typedef uint BlackberryDate < read = BlackberryDateRead , write = BlackberryDateWrite > ; +161: FSeek ( pos ) ; BlackberryDate _gt < name = "BlackberryDate" > ; +162: string BlackberryDateRead ( BlackberryDate t ) +163: { +164: +165: return FileTimeToString ( t * 600000000 L + 94354848000000000 L ) ; +166: } +167: int BlackberryDateWrite ( BlackberryDate & t , string value ) +168: { +169: +170: FILETIME ft ; +171: int result = StringToFileTime ( value , ft ) ; +172: t = ( int ) ( ( ( uint64 ) ft - 94354848000000000 L ) / 600000000 L ) ; +173: return result ; +174: } +175: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/InspectorWithMP4DateTime.bt b/cparser/tests/exp_lex/InspectorWithMP4DateTime.bt new file mode 100644 index 0000000..20cbc61 --- /dev/null +++ b/cparser/tests/exp_lex/InspectorWithMP4DateTime.bt @@ -0,0 +1,117 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: RequiresVersion ( 4 . 0 ) ; +19: +20: +21: +22: +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 < read = MP4_TimeRead , write = MP4_TimeWrite > ; +39: +40: string MP4_TimeRead ( MP4_Time secs ) +41: { +42: +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 ; +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 ; +83: SScanf ( dateTime , "%d.%d.%d %d:%d:%d" , day , month , year , hour , min , sec ) ; +84: +85: int days = day - 1 ; +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: +98: FSeek ( position ) ; MP4_Time _mp4t < name = "MP4 time" > ; +99: FSeek ( position ) ; byte _si8 < name = "Signed Byte" > ; +100: FSeek ( position ) ; ubyte _ui8 < name = "Unsigned Byte" > ; +101: FSeek ( position ) ; short _si16 < name = "Signed Short" > ; +102: FSeek ( position ) ; ushort _ui16 < name = "Unsigned Short" > ; +103: FSeek ( position ) ; int _si32 < name = "Signed Int" > ; +104: FSeek ( position ) ; uint _ui32 < name = "Unsigned Int" > ; +105: FSeek ( position ) ; int64 _si64 < name = "Signed Int64" > ; +106: FSeek ( position ) ; uint64 _ui64 < name = "Unsigned Int64" > ; +107: FSeek ( position ) ; float _f < name = "Float" > ; +108: FSeek ( position ) ; double _d < name = "Double" > ; +109: FSeek ( position ) ; hfloat _hf < name = "Half Float" > ; +110: FSeek ( position ) ; char _s [ ReadStringLength ( position , 256 ) ] < name = "String" > ; +111: FSeek ( position ) ; wchar_t _ws [ ReadWStringLength ( position , 256 ) ] < name = "Unicode" > ; +112: FSeek ( position ) ; DOSDATE _dd < name = "DOS Date" > ; +113: FSeek ( position ) ; DOSTIME _dt < name = "DOS Time" > ; +114: FSeek ( position ) ; FILETIME _ft < name = "FILETIME" > ; +115: FSeek ( position ) ; OLETIME _ot < name = "OLETIME" > ; +116: FSeek ( position ) ; time_t _tt < name = "time_t" > ; +117: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/JPGTemplate.bt b/cparser/tests/exp_lex/JPGTemplate.bt new file mode 100644 index 0000000..203e580 --- /dev/null +++ b/cparser/tests/exp_lex/JPGTemplate.bt @@ -0,0 +1,1605 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: +21: +22: +23: +24: +25: +26: +27: +28: +29: +30: +31: +32: +33: +34: +35: +36: +37: +38: +39: +40: +41: +42: +43: +44: +45: LittleEndian ( ) ; BitfieldLeftToRight ( ) ; +46: BigEndian ( ) ; BitfieldLeftToRight ( ) ; +47: +48: local quad JpegFileEnd = 0 ; +49: local int colorId = 0 ; +50: local int colorSelect = 0 ; +51: local DWORD clr = 0 ; +52: local DWORD jetMap [ 6 * 3 ] = { +53: 0xCC , 0xFF , 0x33FF , 0x66FF , 0x99FF , 0xCCFF , +54: 0xFFFF , 0x33FFCC , 0x66FF99 , 0x99FF66 , 0xCCFF33 , 0xFFFF00 , +55: 0xFFCC00 , 0xFF9900 , 0xFF6600 , 0xFF3300 , 0xFF0000 , 0xCC0000 +56: } ; +57: local char CameraMake [ 32 ] ; +58: local char CameraModel [ 40 ] ; +59: +60: local string stack_IFD_dirtype = "" ; +61: +62: enum IFD_dirtype { +63: IFD_TYPE_EXIF = 1 , +64: IFD_TYPE_GEOTAG , +65: IFD_TYPE_CASIO_QV_R62 , +66: } ; +67: +68: +69: +70: void Stack_push ( string & s , int x ) +71: { +72: s += ( char ) x ; +73: } +74: +75: void Stack_pop ( string & s ) +76: { +77: s = SubStr ( s , 0 , Strlen ( s ) - 1 ) ; +78: } +79: +80: int Stack_top ( string & s ) +81: { +82: return s [ Strlen ( s ) - 1 ] ; +83: } +84: +85: string ReadStringN ( int64 pos , int n ) +86: { +87: local uchar s [ n ] ; +88: ReadBytes ( s , pos , n ) ; +89: return s ; +90: } +91: +92: +93: +94: void ChangeColor ( byte bChangeColor ) { +95: if ( bChangeColor == 1 ) { colorSelect ++ ; colorId = 0 ; } +96: clr = jetMap [ ( colorSelect % 3 ) * 6 + ( colorId % 6 ) ] ; +97: SetBackColor ( clr ) ; +98: +99: colorId ++ ; +100: } +101: +102: +103: +104: typedef enum < WORD > tagID +105: { +106: M_SOF0 = 0xFFC0 , +107: M_SOF1 , +108: M_SOF2 , +109: M_SOF3 , +110: M_DHT , +111: M_SOF5 , +112: M_SOF6 , +113: M_SOF7 , +114: M_JPG , +115: M_SOF9 , +116: M_SOF10 , +117: M_SOF11 , +118: M_DAC = 0xFFCC , +119: M_SOF13 , +120: M_SOF14 , +121: M_SOF15 , +122: M_RST0 = 0xFFD0 , +123: M_RST1 , M_RST2 , M_RST3 , M_RST4 , M_RST5 , M_RST6 , M_RST7 , +124: M_SOI = 0xFFD8 , +125: M_EOI , +126: M_SOS , +127: M_DQT , +128: M_DNL , +129: M_DRI , +130: M_DHP , +131: M_EXP , +132: M_APP0 = 0xFFE0 , +133: M_APP1 , +134: M_APP2 , +135: M_APP3 , +136: M_APP4 , +137: M_APP5 , +138: M_APP6 , +139: M_APP7 , +140: M_APP8 , +141: M_APP9 , +142: M_APP10 , +143: M_APP11 , +144: M_APP12 , +145: M_APP13 , +146: M_APP14 , +147: M_APP15 , +148: M_JPG0 = 0xFFF0 , +149: M_JPG1 , M_JPG2 , M_JPG3 , M_JPG4 , M_JPG5 , M_JPG6 , M_JPGLS , +150: M_JPG8 , M_JPG9 , M_JPG10 , M_JPG11 , M_JPG12 , M_JPG13 , M_JPG14 , M_JPG15 , +151: M_COMM = 0xFFFE +152: } M_ID < format = hex > ; +153: +154: +155: +156: +157: +158: typedef enum < WORD > tagExifTag { +159: +160: InteropIndex = 0x1 , +161: InteropVersion = 0x2 , +162: SubfileType = 0xFE , +163: OldSubfileType = 0xFF , +164: ImageWidth = 0x100 , +165: ImageHeight = 0x101 , +166: BitsPerSample = 0x102 , +167: Compression = 0x103 , +168: PhotometricInterpretation = 0x106 , +169: Thresholding = 0x107 , +170: CellWidth = 0x108 , +171: CellLength = 0x109 , +172: FillOrder = 0x10A , +173: DocumentName = 0x10D , +174: ImageDescription = 0x10E , +175: Make = 0x10F , +176: Model = 0x110 , +177: StripOffsets = 0x111 , +178: Orientation = 0x112 , +179: SamplesPerPixel = 0x115 , +180: RowsPerStrip = 0x116 , +181: StripByteCounts = 0x117 , +182: MinSampleValue = 0x118 , +183: MaxSampleValue = 0x119 , +184: XResolution = 0x11A , +185: YResolution = 0x11B , +186: PlanarConfiguration = 0x11C , +187: PageName = 0x11D , +188: XPosition = 0x11E , +189: YPosition = 0x11F , +190: FreeOffsets = 0x120 , +191: FreeByteCounts = 0x121 , +192: GrayResponseUnit = 0x122 , +193: GrayResponseCurve = 0x123 , +194: T4Options = 0x124 , +195: T6Options = 0x125 , +196: ResolutionUnit = 0x128 , +197: PageNumber = 0x129 , +198: ColorResponseUnit = 0x12C , +199: TransferFunction = 0x12D , +200: Software = 0x131 , +201: ModifyDate = 0x132 , +202: Artist = 0x13B , +203: HostComputer = 0x13C , +204: Predictor = 0x13D , +205: WhitePoint = 0x13E , +206: PrimaryChromaticities = 0x13F , +207: ColorMap = 0x140 , +208: HalftoneHints = 0x141 , +209: TileWidth = 0x142 , +210: TileLength = 0x143 , +211: TileOffsets = 0x144 , +212: TileByteCounts = 0x145 , +213: BadFaxLines = 0x146 , +214: CleanFaxData = 0x147 , +215: ConsecutiveBadFaxLines = 0x148 , +216: SubIFD = 0x14A , +217: InkSet = 0x14C , +218: InkNames = 0x14D , +219: NumberofInks = 0x14E , +220: DotRange = 0x150 , +221: TargetPrinter = 0x151 , +222: ExtraSamples = 0x152 , +223: SampleFormat = 0x153 , +224: SMinSampleValue = 0x154 , +225: SMaxSampleValue = 0x155 , +226: TransferRange = 0x156 , +227: ClipPath = 0x157 , +228: XClipPathUnits = 0x158 , +229: YClipPathUnits = 0x159 , +230: Indexed = 0x15A , +231: JPEGTables = 0x15B , +232: OPIProxy = 0x15F , +233: GlobalParametersIFD = 0x190 , +234: ProfileType = 0x191 , +235: FaxProfile = 0x192 , +236: CodingMethods = 0x193 , +237: VersionYear = 0x194 , +238: ModeNumber = 0x195 , +239: Decode = 0x1B1 , +240: DefaultImageColor = 0x1B2 , +241: JPEGProc = 0x200 , +242: ThumbnailOffset = 0x201 , +243: ThumbnailLength = 0x202 , +244: JPEGRestartInterval = 0x203 , +245: JPEGLosslessPredictors = 0x205 , +246: JPEGPointTransforms = 0x206 , +247: JPEGQTables = 0x207 , +248: JPEGDCTables = 0x208 , +249: JPEGACTables = 0x209 , +250: YCbCrCoefficients = 0x211 , +251: YCbCrSubSampling = 0x212 , +252: YCbCrPositioning = 0x213 , +253: ReferenceBlackWhite = 0x214 , +254: StripRowCounts = 0x22F , +255: ApplicationNotes = 0x2BC , +256: RelatedImageFileFormat = 0x1000 , +257: RelatedImageWidth = 0x1001 , +258: RelatedImageLength = 0x1002 , +259: ImageID = 0x800D , +260: WangAnnotation = 0x80A4 , +261: Matteing = 0x80E3 , +262: DataType = 0x80E4 , +263: ImageDepth = 0x80E5 , +264: TileDepth = 0x80E6 , +265: Model2 = 0x827D , +266: CFARepeatPatternDim = 0x828D , +267: CFAPattern2 = 0x828E , +268: BatteryLevel = 0x828F , +269: Copyright = 0x8298 , +270: ExposureTime = 0x829A , +271: FNumber = 0x829D , +272: PixelScale = 0x830E , +273: IPTC_NAA = 0x83BB , +274: IntergraphPacketData = 0x8474 , +275: IntergraphFlagRegisters = 0x847F , +276: IntergraphMatrix = 0x8480 , +277: ModelTiePoint = 0x8482 , +278: Site = 0x84E0 , +279: ColorSequence = 0x84E1 , +280: IT8Header = 0x84E2 , +281: RasterPadding = 0x84E3 , +282: BitsPerRunLength = 0x84E4 , +283: BitsPerExtendedRunLength = 0x84E5 , +284: ColorTable = 0x84E6 , +285: ImageColorIndicator = 0x84E7 , +286: BackgroundColorIndicator = 0x84E8 , +287: ImageColorValue = 0x84E9 , +288: BackgroundColorValue = 0x84EA , +289: PixelIntensityRange = 0x84EB , +290: TransparencyIndicator = 0x84EC , +291: ColorCharacterization = 0x84ED , +292: HCUsage = 0x84EE , +293: IPTC_NAA2 = 0x8568 , +294: ModelTransform = 0x85D8 , +295: PhotoshopSettings = 0x8649 , +296: ExifOffset = 0x8769 , +297: ICC_Profile = 0x8773 , +298: ImageLayer = 0x87AC , +299: GeoTiffDirectory = 0x87AF , +300: GeoTiffDoubleParams = 0x87B0 , +301: GeoTiffAsciiParams = 0x87B1 , +302: ExposureProgram = 0x8822 , +303: SpectralSensitivity = 0x8824 , +304: GPSInfo = 0x8825 , +305: ISO = 0x8827 , +306: OptoElectricConvFactor = 0x8828 , +307: Interlace = 0x8829 , +308: TimeZoneOffset = 0x882A , +309: SelfTimerMode = 0x882B , +310: FaxRecvParams = 0x885C , +311: FaxSubAddress = 0x885D , +312: FaxRecvTime = 0x885E , +313: ExifVersion = 0x9000 , +314: DateTimeOriginal = 0x9003 , +315: CreateDate = 0x9004 , +316: ComponentsConfiguration = 0x9101 , +317: CompressedBitsPerPixel = 0x9102 , +318: ShutterSpeedValue = 0x9201 , +319: ApertureValue = 0x9202 , +320: BrightnessValue = 0x9203 , +321: ExposureCompensation = 0x9204 , +322: MaxApertureValue = 0x9205 , +323: SubjectDistance = 0x9206 , +324: MeteringMode = 0x9207 , +325: LightSource = 0x9208 , +326: Flash = 0x9209 , +327: FocalLength = 0x920A , +328: FlashEnergy = 0x920B , +329: SpatialFrequencyResponse = 0x920C , +330: Noise = 0x920D , +331: FocalPlaneXResolution = 0x920E , +332: FocalPlaneYResolution = 0x920F , +333: FocalPlaneResolutionUnit = 0x9210 , +334: ImageNumber = 0x9211 , +335: SecurityClassification = 0x9212 , +336: ImageHistory = 0x9213 , +337: SubjectLocation = 0x9214 , +338: ExposureIndex = 0x9215 , +339: TIFF_EPStandardID = 0x9216 , +340: SensingMethod = 0x9217 , +341: StoNits = 0x923F , +342: MakerNote = 0x927C , +343: UserComment = 0x9286 , +344: SubSecTime = 0x9290 , +345: SubSecTimeOriginal = 0x9291 , +346: SubSecTimeDigitized = 0x9292 , +347: ImageSourceData = 0x935C , +348: XPTitle = 0x9C9B , +349: XPComment = 0x9C9C , +350: XPAuthor = 0x9C9D , +351: XPKeywords = 0x9C9E , +352: XPSubject = 0x9C9F , +353: FlashpixVersion = 0xA000 , +354: ColorSpace = 0xA001 , +355: ExifImageWidth = 0xA002 , +356: ExifImageLength = 0xA003 , +357: RelatedSoundFile = 0xA004 , +358: InteropOffset = 0xA005 , +359: FlashEnergy2 = 0xA20B , +360: SpatialFrequencyResponse2 = 0xA20C , +361: Noise2 = 0xA20D , +362: FocalPlaneXResolution2 = 0xA20E , +363: FocalPlaneYResolution2 = 0xA20F , +364: FocalPlaneResolutionUnit2 = 0xA210 , +365: ImageNumber2 = 0xA211 , +366: SecurityClassification2 = 0xA212 , +367: ImageHistory2 = 0xA213 , +368: SubjectLocation2 = 0xA214 , +369: ExposureIndex2 = 0xA215 , +370: TIFF_EPStandardID2 = 0xA216 , +371: SensingMethod2 = 0xA217 , +372: FileSource = 0xA300 , +373: SceneType = 0xA301 , +374: CFAPattern = 0xA302 , +375: CustomRendered = 0xA401 , +376: ExposureMode = 0xA402 , +377: WhiteBalance = 0xA403 , +378: DigitalZoomRatio = 0xA404 , +379: FocalLengthIn35mmFormat = 0xA405 , +380: SceneCaptureType = 0xA406 , +381: GainControl = 0xA407 , +382: Contrast = 0xA408 , +383: Saturation = 0xA409 , +384: Sharpness = 0xA40A , +385: DeviceSettingDescription = 0xA40B , +386: SubjectDistanceRange = 0xA40C , +387: ImageUniqueID = 0xA420 , +388: GDALMetadata = 0xA480 , +389: GDALNoData = 0xA481 , +390: Gamma = 0xA500 , +391: FilmProductCode = 0xC350 , +392: ImageSourceEK = 0xC351 , +393: CaptureConditionsPAR = 0xC352 , +394: CameraOwner = 0xC353 , +395: SerialNumber = 0xC354 , +396: UserSelectGroupTitle = 0xC355 , +397: DealerIDNumber = 0xC356 , +398: CaptureDeviceFID = 0xC357 , +399: EnvelopeNumber = 0xC358 , +400: FrameNumber = 0xC359 , +401: FilmCategory = 0xC35A , +402: FilmGencode = 0xC35B , +403: ModelAndVersion = 0xC35C , +404: FilmSize = 0xC35D , +405: SBA_RGBShifts = 0xC35E , +406: SBAInputImageColorspace = 0xC35F , +407: SBAInputImageBitDepth = 0xC360 , +408: SBAExposureRecord = 0xC361 , +409: UserAdjSBA_RGBShifts = 0xC362 , +410: ImageRotationStatus = 0xC363 , +411: RollGuidElements = 0xC364 , +412: MetadataNumber = 0xC365 , +413: EditTagArray = 0xC366 , +414: Magnification = 0xC367 , +415: NativeXResolution = 0xC36C , +416: NativeYResolution = 0xC36D , +417: KodakEffectsIFD = 0xC36E , +418: KodakBordersIFD = 0xC36F , +419: NativeResolutionUnit = 0xC37A , +420: SourceImageDirectory = 0xC418 , +421: SourceImageFileName = 0xC419 , +422: SourceImageVolumeName = 0xC41A , +423: OceScanjobDesc = 0xC427 , +424: OceApplicationSelector = 0xC428 , +425: OceIDNumber = 0xC429 , +426: OceImageLogic = 0xC42A , +427: Annotations = 0xC44F , +428: PrintQuality = 0xC46C , +429: ImagePrintStatus = 0xC46E , +430: PrintIM = 0xC4A5 , +431: DNGVersion = 0xC612 , +432: DNGBackwardVersion = 0xC613 , +433: UniqueCameraModel = 0xC614 , +434: LocalizedCameraModel = 0xC615 , +435: CFAPlaneColor = 0xC616 , +436: CFALayout = 0xC617 , +437: LinearizationTable = 0xC618 , +438: BlackLevelRepeatDim = 0xC619 , +439: BlackLevel = 0xC61A , +440: BlackLevelDeltaH = 0xC61B , +441: BlackLevelDeltaV = 0xC61C , +442: WhiteLevel = 0xC61D , +443: DefaultScale = 0xC61E , +444: DefaultCropOrigin = 0xC61F , +445: DefaultCropSize = 0xC620 , +446: ColorMatrix1 = 0xC621 , +447: ColorMatrix2 = 0xC622 , +448: CameraCalibration1 = 0xC623 , +449: CameraCalibration2 = 0xC624 , +450: ReductionMatrix1 = 0xC625 , +451: ReductionMatrix2 = 0xC626 , +452: AnalogBalance = 0xC627 , +453: AsShotNeutral = 0xC628 , +454: AsShotWhiteXY = 0xC629 , +455: BaselineExposure = 0xC62A , +456: BaselineNoise = 0xC62B , +457: BaselineSharpness = 0xC62C , +458: BayerGreenSplit = 0xC62D , +459: LinearResponseLimit = 0xC62E , +460: DNGCameraSerialNumber = 0xC62F , +461: DNGLensInfo = 0xC630 , +462: ChromaBlurRadius = 0xC631 , +463: AntiAliasStrength = 0xC632 , +464: ShadowScale = 0xC633 , +465: DNGPrivateData = 0xC634 , +466: MakerNoteSafety = 0xC635 , +467: CalibrationIlluminant1 = 0xC65A , +468: CalibrationIlluminant2 = 0xC65B , +469: BestQualityScale = 0xC65C , +470: AliasLayerMetadata = 0xC660 , +471: OwnerName = 0xFDE8 , +472: SerialNumber2 = 0xFDE9 , +473: Lens = 0xFDEA , +474: RawFile = 0xFE4C , +475: Converter = 0xFE4D , +476: WhiteBalance2 = 0xFE4E , +477: Exposure = 0xFE51 , +478: Shadows = 0xFE52 , +479: Brightness = 0xFE53 , +480: Contrast2 = 0xFE54 , +481: Saturation2 = 0xFE55 , +482: Sharpness2 = 0xFE56 , +483: Smoothness = 0xFE57 , +484: MoireFilter = 0xFE58 , +485: } ExifTag ; +486: +487: enum < WORD > GeoTag { +488: GPSVersionID , +489: GPSLatitudeRef , +490: GPSLatitude , +491: GPSLongitudeRef , +492: GPSLongitude , +493: GPSAltitudeRef , +494: GPSAltitude , +495: GPSTimeStamp , +496: GPSSatellites , +497: GPSStatus , +498: GPSMeasureMode , +499: GPSDOP , +500: GPSSpeedRef , +501: GPSSpeed , +502: GPSTrackRef , +503: GPSTrack , +504: GPSImgDirectionRef , +505: GPSImgDirection , +506: GPSMapDatum , +507: GPSDestLatitudeRef , +508: GPSDestLatitude , +509: GPSDestLongitudeRef , +510: GPSDestLongitude , +511: GPSDestBearingRef , +512: GPSDestBearing , +513: GPSDestDistanceRef , +514: GPSDestDistance , +515: GPSProcessingMehotd , +516: GPSAreaInformation , +517: GPSDateStamp , +518: GPSDifferential , +519: } ; +520: +521: +522: +523: typedef enum < WORD > tagCasioTag2 { +524: PreviewThumbnailDimensions = 0x2 , +525: PreviewThumbnailSize = 0x3 , +526: PreviewThumbnailOffset = 0x4 , +527: CSQualityMode = 0x8 , +528: CsImageSize = 0x9 , +529: CSFocusMode = 0xD , +530: CsIsoSensitivity = 0x14 , +531: CsWhiteBalance = 0x19 , +532: CsFocalLength = 0x1D , +533: CsSaturation = 0x1F , +534: CsContrast = 0x20 , +535: CsSharpness = 0x21 , +536: CsPrintImageMatchingInfo = 0xE00 , +537: CasioPreviewThumbnail = 0x2000 , +538: CsWhiteBalanceBias = 0x2011 , +539: CsFlashMode = 0x2012 , +540: CsObjectDistance = 0x2022 , +541: CsFlashDistance = 0x2034 , +542: CsRecordMode = 0x3000 , +543: CsSelfTimer = 0x3001 , +544: CsQuality = 0x3002 , +545: CsMeteringMode2 = 0x3003 , +546: CsTimeZone = 0x3006 , +547: CsBestshotMode = 0x3007 , +548: CsCCDISOSensitivity = 0x3014 , +549: CsColourMode = 0x3015 , +550: CsEnhancement = 0x3016 , +551: CsFilter = 0x3017 , +552: } CasioTag2 ; +553: +554: +555: +556: +557: typedef uint32 DC_UINT32 ; +558: typedef int32 DC_SINT32 ; +559: typedef float DC_FLOAT32 ; +560: +561: typedef struct tgCifDirEntry { +562: uint16 storage_method : 2 ; +563: uint16 data_type : 3 ; +564: uint16 id_code : 11 < format = hex > ; +565: if ( storage_method == kStg_InHeapSpace ) { +566: DWORD sData ; +567: DWORD oData ; +568: } else { +569: switch ( data_type << 11 | id_code ) { +570: case kTC_ImageFormat : +571: DC_UINT32 fileFormat ; +572: DC_FLOAT32 targetCompressionRatio ; +573: break ; +574: default : +575: byte data [ 8 ] ; +576: break ; +577: } +578: } +579: } CifDirEntry < read = ReadCifDirEntry > ; +580: +581: enum CIFFTagStg { +582: kStg_InHeapSpace , +583: kStg_InRecordEntry , +584: kStg_reversed2 , +585: kStg_reversed3 , +586: } ; +587: +588: enum CIFFTagDataType { +589: kDT_BYTE = 0x0 , +590: kDT_ASCII = 0x800 , +591: kDT_WORD = 0x1000 , +592: kDT_DWORD = 0x1800 , +593: kDT_BYTE2 = 0x2000 , +594: kDT_HeapTypeProperty1 = 0x2800 , +595: kDT_HeapTypeProperty2 = 0x3000 , +596: } ; +597: +598: enum < uint16 > CIFFTagType { +599: kTC_Null = 0 , +600: kTC_Free , +601: kTC_ExFree , +602: +603: kTC_Description = 0x805 , +604: kTC_ModelName = 0x80A , +605: kTC_FirmwareVersion = 0x80B , +606: kTC_ComponentVersion = 0x80C , +607: kTC_ROMOperationMode = 0x80D , +608: kTC_OwnerName = 0x810 , +609: kTC_ImageFileName = 0x816 , +610: kTC_ThumbnailFileName = 0x817 , +611: +612: kTC_TargetImageType = 0x100A , +613: kTC_SR_ReleaseMethod = 0x1010 , +614: kTC_SR_ReleaseTiming = 0x1011 , +615: kTC_ReleaseSetting = 0x1016 , +616: kTC_BodySensitivity = 0x101C , +617: +618: kTC_ImageFormat = 0x1803 , +619: kTC_RecordID = 0x1804 , +620: kTC_SelfTimerTime = 0x1806 , +621: kTC_SR_TargetDistanceSetting = 0x1807 , +622: kTC_BodyID = 0x180B , +623: kTC_CapturedTime = 0x180E , +624: kTC_ImageSpec = 0x1810 , +625: kTC_SR_EF = 0x1813 , +626: kTC_MI_EV = 0x1814 , +627: kTC_SerialNumber = 0x1817 , +628: +629: kTC_CameraObject = 0x2807 , +630: kTC_ShootingRecord = 0x3002 , +631: kTC_MeasuredInfo = 0x3003 , +632: kTC_CameraSpecification = 0x3004 , +633: } ; +634: +635: string ReadCifDirEntry ( CifDirEntry & e ) +636: { +637: local string s ; +638: local uint16 tc = e . data_type << 11 | e . id_code ; +639: local CIFFTagType x = ( CIFFTagType ) tc ; +640: local CIFFTagStg stg = ( CIFFTagStg ) e . storage_method ; +641: local CIFFTagDataType dt = ( CIFFTagDataType ) ( e . data_type << 11 ) ; +642: if ( EnumToString ( x ) != "" ) { +643: SPrintf ( s , "%s, %s" , +644: EnumToString ( stg ) , +645: EnumToString ( x ) ) ; +646: } else { +647: SPrintf ( s , "%s, %s, 0x%x" , +648: EnumToString ( stg ) , +649: EnumToString ( dt ) , +650: e . id_code ) ; +651: } +652: +653: return s ; +654: } +655: +656: typedef struct tgCDir { +657: ChangeColor ( 0 ) ; +658: +659: local quad myOffset = cDirOffset ; +660: local DWORD S = ReadInt ( myOffset + cDirSize - 4 ) ; +661: FSeek ( cDirOffset + S ) ; +662: +663: WORD nDirEntry ; +664: +665: ChangeColor ( 0 ) ; +666: CifDirEntry dirEntries [ nDirEntry ] < optimize = false > ; +667: DWORD szValues ; +668: local int i ; +669: for ( i = 0 ; i < nDirEntry ; i ++ ) { +670: +671: if ( dirEntries [ i ] . storage_method == kStg_InHeapSpace ) { +672: +673: FSeek ( myOffset + dirEntries [ i ] . oData ) ; +674: ChangeColor ( 0 ) ; +675: +676: switch ( dirEntries [ i ] . data_type << 11 | dirEntries [ i ] . id_code ) { +677: case kTC_ImageSpec : +678: struct { +679: DC_UINT32 imageWidth ; +680: DC_UINT32 imageHeight ; +681: DC_FLOAT32 pixelAspectRatio ; +682: DC_SINT32 rotationAngle ; +683: DC_UINT32 componentBitDepth ; +684: DC_UINT32 colorBitDepth ; +685: DC_UINT32 colorBW ; +686: } DC_IMAGESPEC ; +687: break ; +688: default : +689: switch ( dirEntries [ i ] . data_type << 11 ) { +690: case kDT_BYTE : +691: struct { +692: byte bData [ dirEntries [ i ] . sData ] ; +693: } strBytes ; +694: break ; +695: case kDT_ASCII : +696: struct { +697: char sData [ dirEntries [ i ] . sData ] ; +698: } strStrings ; +699: break ; +700: case kDT_WORD : +701: struct { +702: WORD wData [ dirEntries [ i ] . sData >> 1 ] ; +703: } str2Bytes ; +704: break ; +705: case kDT_DWORD : +706: union { +707: DWORD dwData [ dirEntries [ i ] . sData >> 2 ] ; +708: DWORD flData [ dirEntries [ i ] . sData >> 2 ] ; +709: } str4Bytes ; +710: break ; +711: case kDT_HeapTypeProperty1 : +712: case kDT_HeapTypeProperty2 : +713: cDirOffset = dirEntries [ i ] . oData + myOffset ; +714: cDirSize = dirEntries [ i ] . sData ; +715: struct CDIR subDir ; +716: break ; +717: default : +718: struct { +719: char uData [ dirEntries [ i ] . sData ] ; +720: } strUnknown ; +721: break ; +722: } +723: break ; +724: } +725: } +726: +727: } +728: +729: } CDIR ; +730: +731: +732: +733: const local int dataFormatLength [ 13 ] = { 0 , 1 , 1 , 2 , 4 , 8 , 1 , 1 , 2 , 4 , 8 , 4 , 8 } ; +734: +735: typedef enum < WORD > tagDataFormat { +736: uByte = 1 , +737: ascString , +738: uShort , +739: uLong , +740: uRatio , +741: sByte , +742: undefined = 7 , +743: sShort , +744: sLong = 9 , +745: sRatio , +746: sFloat , +747: dFloat , +748: } DataFormat ; +749: +750: +751: typedef struct tgDIRENTRY { +752: ChangeColor ( 0 ) ; +753: switch ( Stack_top ( stack_IFD_dirtype ) ) { +754: case IFD_TYPE_EXIF : +755: ExifTag tagNumber ; +756: break ; +757: case IFD_TYPE_GEOTAG : +758: GeoTag tagNumber ; +759: break ; +760: case IFD_TYPE_CASIO_QV_R62 : +761: CasioTag2 tagNumber ; +762: break ; +763: } +764: DataFormat dataFormat ; +765: DWORD nComponent ; +766: local int j = 0 ; +767: local int length = - 1 ; +768: +769: if ( 1 <= dataFormat && dataFormat < 13 ) +770: length = dataFormatLength [ dataFormat ] * nComponent ; +771: else { +772: +773: } +774: +775: if ( 1 <= dataFormat && dataFormat < 13 && 0 <= length && length <= 4 ) { +776: switch ( tagNumber ) { +777: case ExposureProgram : +778: enum < short > { +779: EP_Not_defined , +780: EP_Manual , +781: EP_Normal_program , +782: EP_Aperture_priority , +783: EP_Shutter_priority , +784: EP_Creative_program , +785: EP_Action_program , +786: EP_Portrait_mode , +787: EP_Landscape_mode , +788: } ExposureProgram ; +789: break ; +790: case MeteringMode : +791: enum < short > { +792: MM_unknown , +793: MM_Average , +794: MM_CenterWeightedAverage , +795: MM_Spot , +796: MM_MultiSpot , +797: MM_Pattern , +798: MM_Partial , +799: MM_other = 255 , +800: } MeteringMode ; +801: break ; +802: case LightSource : +803: enum < short > { +804: LS_unknown , +805: LS_Daylight , +806: LS_Fluorescent , +807: LS_Tungsten , +808: LS_Flash , +809: LS_Fine_weather = 9 , +810: LS_Cloudy_weather , +811: LS_Shade , +812: LS_Daylight_fluorescent , +813: LS_Day_white_fluorescent , +814: LS_Cool_white_fluorescent , +815: LS_White_fluorescent , +816: LS_Standard_light_A , +817: LS_Standard_light_B , +818: LS_Standard_light_C , +819: LS_D55 , +820: LS_D65 , +821: LS_D75 , +822: LS_D50 , +823: LS_ISO_studio_tungsten , +824: LS_other_light_scoure = 255 , +825: } LightSource ; +826: break ; +827: case Flash : +828: short unused : 9 ; +829: short red_eye_mode : 1 ; +830: short flash_function : 1 ; +831: short flash_mode : 2 ; +832: short flash_return : 2 ; +833: short flash_fired : 1 ; +834: break ; +835: case ExposureMode : +836: enum < short > { +837: EM_Auto_exposure , +838: EM_Manual_exposure , +839: EM_Auto_bracket , +840: } ExposureMode ; +841: break ; +842: case WhiteBalance : +843: enum < short > { +844: WB_Auto_white_balance , +845: WB_Manual_white_balance , +846: } WhiteBalance ; +847: break ; +848: case SceneCaptureType : +849: enum < short > { +850: SCT_Standard , +851: SCT_Landscape , +852: SCT_Portrait , +853: SCT_Night_scene , +854: } SceneCaptureType ; +855: break ; +856: case SubjectDistanceRange : +857: enum < short > { +858: SDR_unknown , +859: SDR_Macro , +860: SDR_Close_view , +861: SDR_Distant_view , +862: } SubjectDistanceRange ; +863: break ; +864: default : +865: switch ( dataFormat ) { +866: case uByte : +867: struct { +868: uchar oneByteData [ nComponent ] ; +869: } strAscii ; +870: break ; +871: case ascString : +872: struct StrAscii1 { +873: char oneByteData [ nComponent ] ; +874: } strAscii < read = ReadAscString1 > ; +875: break ; +876: case undefined : +877: struct { +878: uchar oneByteData [ nComponent ] ; +879: } strAscii ; +880: break ; +881: case uShort : +882: for ( j = 0 ; j < nComponent ; j ++ ) +883: ushort usValue ; +884: break ; +885: case uLong : +886: if ( nComponent == 1 ) +887: ulong ulValue ; +888: break ; +889: case sByte : +890: struct { +891: char sBValue [ nComponent ] ; +892: } strSByte ; +893: break ; +894: case sShort : +895: struct { +896: short sisValue [ nComponent ] ; +897: } strSShort ; +898: break ; +899: case sLong : +900: if ( nComponent == 1 ) +901: ulong siLValue ; +902: break ; +903: case sFloat : +904: if ( nComponent == 1 ) +905: float flValue ; +906: break ; +907: } +908: break ; +909: } +910: if ( length != 4 ) +911: uchar padding [ 4 - length ] ; +912: } else { +913: DWORD offsetData ; +914: } +915: } DIRENTRY < read = ReadDirEntry > ; +916: +917: string ReadDirEntry ( DIRENTRY & entry ) { +918: local char no [ 50 ] ; +919: SPrintf ( no , "Tag# = 0x%x (%s)" , entry . tagNumber , EnumToString ( entry . tagNumber ) ) ; +920: return no ; +921: } +922: +923: +924: typedef struct tgIFD { +925: WORD nDirEntry ; +926: DIRENTRY dirEntry [ nDirEntry ] < optimize = false > ; +927: DWORD nextIFDoffset ; +928: local int i = 0 ; +929: for ( i = 0 ; i < nDirEntry ; i ++ ) { +930: ChangeColor ( 0 ) ; +931: switch ( dirEntry [ i ] . tagNumber ) { +932: case Make : +933: ReadBytes ( CameraMake , offset + dirEntry [ i ] . offsetData , dirEntry [ i ] . nComponent ) ; +934: Printf ( "Maker: %s\n" , CameraMake ) ; +935: break ; +936: case Model : +937: ReadBytes ( CameraModel , offset + dirEntry [ i ] . offsetData , dirEntry [ i ] . nComponent ) ; +938: Printf ( "Model: %s\n" , CameraModel ) ; +939: break ; +940: } +941: +942: +943: if ( ! ( 1 <= dirEntry [ i ] . dataFormat && dirEntry [ i ] . dataFormat < 13 ) ) +944: continue ; +945: if ( dataFormatLength [ dirEntry [ i ] . dataFormat ] * dirEntry [ i ] . nComponent <= 4 ) { +946: continue ; +947: } +948: +949: FSeek ( offset + dirEntry [ i ] . offsetData ) ; +950: switch ( dirEntry [ i ] . tagNumber ) { +951: default : +952: switch ( dirEntry [ i ] . dataFormat ) { +953: case ascString : +954: struct StrAscii { +955: char oneByteData [ dirEntry [ i ] . nComponent ] ; +956: } strAscii < read = ReadAscString > ; +957: break ; +958: case undefined : +959: struct { +960: uchar oneByteData [ dirEntry [ i ] . nComponent ] ; +961: } strAscii ; +962: break ; +963: case uShort : +964: struct { +965: ushort usValue [ dirEntry [ i ] . nComponent ] ; +966: } strUShort ; +967: break ; +968: case uLong : +969: struct { +970: ulong ulValue [ dirEntry [ i ] . nComponent ] ; +971: } strULong ; +972: break ; +973: case uRatio : +974: struct URatio { +975: struct { +976: DWORD num ; +977: DWORD den ; +978: } uRValue [ dirEntry [ i ] . nComponent ] ; +979: } strURatio < read = ReadURatio > ; +980: break ; +981: case sByte : +982: struct { +983: char sBValue [ dirEntry [ i ] . nComponent ] ; +984: } strSByte ; +985: break ; +986: case sShort : +987: struct { +988: short sisValue [ dirEntry [ i ] . nComponent ] ; +989: } strSShort ; +990: break ; +991: case sLong : +992: struct { +993: ulong siLValue [ dirEntry [ i ] . nComponent ] ; +994: } strSLong ; +995: break ; +996: case sRatio : +997: struct { +998: struct { +999: int num ; +1000: int den ; +1001: } siRValue [ dirEntry [ i ] . nComponent ] ; +1002: } strSRatio ; +1003: break ; +1004: case sFloat : +1005: struct { +1006: float flValue [ dirEntry [ i ] . nComponent ] ; +1007: } strsFloat ; +1008: break ; +1009: case dFloat : +1010: struct { +1011: double dFValue [ dirEntry [ i ] . nComponent ] ; +1012: } strdFloat ; +1013: break ; +1014: } +1015: } +1016: } +1017: +1018: for ( i = 0 ; i < nDirEntry ; i ++ ) { +1019: ChangeColor ( 0 ) ; +1020: switch ( dirEntry [ i ] . tagNumber ) { +1021: case ExifOffset : +1022: FSeek ( offset + dirEntry [ i ] . ulValue ) ; +1023: Stack_push ( stack_IFD_dirtype , IFD_TYPE_EXIF ) ; +1024: struct IFD subDir ; +1025: Stack_pop ( stack_IFD_dirtype ) ; +1026: break ; +1027: case GPSInfo : +1028: FSeek ( offset + dirEntry [ i ] . ulValue ) ; +1029: Stack_push ( stack_IFD_dirtype , IFD_TYPE_GEOTAG ) ; +1030: struct IFD subDir ; +1031: Stack_pop ( stack_IFD_dirtype ) ; +1032: break ; +1033: case InteropOffset : +1034: FSeek ( offset + dirEntry [ i ] . ulValue ) ; +1035: Stack_push ( stack_IFD_dirtype , IFD_TYPE_EXIF ) ; +1036: struct IFD subDir ; +1037: Stack_pop ( stack_IFD_dirtype ) ; +1038: break ; +1039: case MakerNote : +1040: if ( ! Strncmp ( "CASIO COMPUTER CO.,LTD" , CameraMake , 22 ) && +1041: ! Strncmp ( "QV-R62" , CameraModel , 6 ) ) { +1042: FSeek ( offset + dirEntry [ i ] . ulValue ) ; +1043: struct { +1044: char Header [ 6 ] ; +1045: Stack_push ( stack_IFD_dirtype , IFD_TYPE_CASIO_QV_R62 ) ; +1046: struct IFD CasioIFD ; +1047: Stack_pop ( stack_IFD_dirtype ) ; +1048: } CasioMake ; +1049: } +1050: break ; +1051: case CasioPreviewThumbnail : +1052: FSeek ( offset + dirEntry [ i ] . ulValue ) ; +1053: Printf ( "Casio Thumbnail Offset = %#Lx\n" , offset + dirEntry [ i ] . ulValue ) ; +1054: local quad JpegFileEnd2 = JpegFileEnd ; +1055: JpegFileEnd = FTell ( ) + dirEntry [ i ] . nComponent ; +1056: struct JPGFILE CasioMakerThumbnail ; +1057: JpegFileEnd = JpegFileEnd2 ; +1058: break ; +1059: } +1060: } +1061: } IFD ; +1062: +1063: string ReadAscString1 ( StrAscii1 & s ) +1064: { +1065: return s . oneByteData ; +1066: } +1067: string ReadAscString ( StrAscii & s ) +1068: { +1069: return s . oneByteData ; +1070: } +1071: +1072: string ReadURatio ( URatio & ur ) +1073: { +1074: local int i ; +1075: local string s ; +1076: local string result = "" ; +1077: for ( i = 0 ; exists ( ur . uRValue [ i ] ) ; i ++ ) { +1078: SPrintf ( s , "%d/%d" , ur . uRValue [ i ] . num , ur . uRValue [ i ] . den ) ; +1079: result += s + " " ; +1080: } +1081: return result ; +1082: } +1083: +1084: +1085: typedef struct tagApp0 { +1086: M_ID marker ; +1087: WORD szSection ; +1088: +1089: if ( ReadStringN ( FTell ( ) , 5 ) == "JFIF" ) { +1090: +1091: char App0Type [ 5 ] ; +1092: short versionHigh : 8 ; +1093: short versionLow : 8 ; +1094: ubyte units ; +1095: WORD Xdensity ; +1096: WORD Ydensity ; +1097: ubyte xThumbnail ; +1098: ubyte yThumbnail ; +1099: if ( xThumbnail != 0 && yThumbnail != 0 ) { +1100: struct { +1101: uchar r , g , b ; +1102: } rgb [ ( ushort ) xThumbnail * yThumbnail ] ; +1103: } +1104: } else if ( ReadStringN ( FTell ( ) , 5 ) == "JFXX" ) { +1105: +1106: char App0Type [ 5 ] ; +1107: byte extension_code < format = hex > ; +1108: switch ( extension_code ) { +1109: case 0x10 : +1110: local quad JpegFileEnd2 = JpegFileEnd ; +1111: JpegFileEnd = FTell ( ) + szSection - 8 ; +1112: struct JPGFILE thumbnail ; +1113: JpegFileEnd = JpegFileEnd2 ; +1114: break ; +1115: case 0x11 : +1116: ubyte xThumbnail ; +1117: ubyte yThumbnail ; +1118: struct { +1119: uchar r , g , b ; +1120: } palette [ 256 ] ; +1121: uchar pixel [ szSection - 8 ] ; +1122: break ; +1123: case 0x13 : +1124: ubyte xThumbnail ; +1125: ubyte yThumbnail ; +1126: struct { +1127: uchar r , g , b ; +1128: } pixel [ ( ushort ) xThumbnail * yThumbnail ] ; +1129: break ; +1130: default : +1131: +1132: char unknown [ szSection - 8 ] ; +1133: } +1134: } else if ( ( ReadStringN ( FTell ( ) , 2 ) == "II" || ReadStringN ( FTell ( ) , 2 ) == "MM" ) +1135: && ReadStringN ( FTell ( ) + 6 , 8 ) == "HEAPJPGM" ) { +1136: +1137: local quad cDirSize = 0 ; +1138: local quad cDirOffset = 0 ; +1139: local quad cifOffset = FTell ( ) ; +1140: +1141: char ByteOrder [ 2 ] ; +1142: if ( ! Strncmp ( ByteOrder , "II" , 2 ) ) LittleEndian ( ) ; +1143: DWORD HeaderLength ; +1144: char type [ 4 ] ; +1145: char subtype [ 4 ] ; +1146: +1147: +1148: cDirOffset = HeaderLength + cifOffset ; +1149: cDirSize = szSection - 2 - HeaderLength ; +1150: CDIR APP0_Ciff ; +1151: BigEndian ( ) ; +1152: FSeek ( cifOffset + szSection - 2 ) ; +1153: } +1154: else { +1155: +1156: char unknown [ szSection - 2 ] ; +1157: } +1158: } APP0 ; +1159: +1160: typedef struct tgAPP1 { +1161: M_ID marker ; +1162: WORD szSection ; +1163: +1164: if ( ReadStringN ( FTell ( ) , 5 ) == "Exif" ) { +1165: char EXIF [ 6 ] ; +1166: local quad offset = FTell ( ) ; +1167: byte align [ 2 ] ; +1168: if ( align [ 0 ] == 'I' ) { LittleEndian ( ) ; } +1169: WORD tagMark ; +1170: DWORD offsetFirstIFD ; +1171: if ( offsetFirstIFD != 8 ) +1172: FSeek ( offset + offsetFirstIFD ) ; +1173: ChangeColor ( 0 ) ; +1174: Stack_push ( stack_IFD_dirtype , IFD_TYPE_EXIF ) ; +1175: IFD ifdMainImage ; +1176: Stack_pop ( stack_IFD_dirtype ) ; +1177: if ( ifdMainImage . nextIFDoffset ) { +1178: FSeek ( offset + ifdMainImage . nextIFDoffset ) ; +1179: ChangeColor ( 0 ) ; +1180: Stack_push ( stack_IFD_dirtype , IFD_TYPE_EXIF ) ; +1181: IFD ifdThumbnailImage ; +1182: Stack_pop ( stack_IFD_dirtype ) ; +1183: local int i = 0 ; +1184: local int thumbOffset = 0 ; +1185: local int thumbLength = 0 ; +1186: local int compression = 10 ; +1187: for ( i ; i < ifdThumbnailImage . nDirEntry ; i ++ ) { +1188: switch ( ifdThumbnailImage . dirEntry [ i ] . tagNumber ) { +1189: case Compression : +1190: compression = ifdThumbnailImage . dirEntry [ i ] . usValue ; +1191: break ; +1192: case ThumbnailOffset : +1193: case StripOffsets : +1194: thumbOffset = ifdThumbnailImage . dirEntry [ i ] . ulValue ; +1195: break ; +1196: case ThumbnailLength : +1197: case StripByteCounts : +1198: thumbLength = ifdThumbnailImage . dirEntry [ i ] . ulValue ; +1199: break ; +1200: } +1201: } +1202: if ( thumbLength && thumbOffset ) { +1203: FSeek ( offset + thumbOffset ) ; +1204: Printf ( "Thumbnail Offset = %#Lx\n" , offset + thumbOffset ) ; +1205: if ( compression == 6 ) { +1206: local quad JpegFileEnd2 = JpegFileEnd ; +1207: JpegFileEnd = FTell ( ) + thumbLength ; +1208: struct JPGFILE thumbnail ; +1209: JpegFileEnd = JpegFileEnd2 ; +1210: } +1211: else +1212: char imageData [ thumbLength ] ; +1213: } +1214: } +1215: FSeek ( offset + szSection - 8 ) ; +1216: if ( align [ 0 ] == 'I' ) { BigEndian ( ) ; } +1217: } else if ( ReadStringN ( FTell ( ) , 29 ) == "http://ns.adobe.com/xap/1.0/" ) { +1218: +1219: char XAP [ 29 ] ; +1220: char remain [ szSection - 31 ] ; +1221: } else { +1222: +1223: char unknown [ szSection - 2 ] ; +1224: } +1225: } APP1 ; +1226: +1227: typedef struct tgAPP2 { +1228: M_ID marker ; +1229: WORD szSection ; +1230: +1231: if ( ReadStringN ( FTell ( ) , 5 ) == "FPXR" ) { +1232: char FPXR [ 5 ] ; +1233: uchar version ; +1234: char remain [ szSection - 8 ] ; +1235: +1236: } else if ( ReadStringN ( FTell ( ) , 12 ) == "ICC_PROFILE" ) { +1237: char ICC_PROFILE [ 12 ] ; +1238: uchar block_num ; +1239: uchar block_total ; +1240: char data [ szSection - 16 ] ; +1241: } else { +1242: +1243: char unknown [ szSection - 2 ] ; +1244: } +1245: } APP2 ; +1246: +1247: typedef struct tagAPP12 { +1248: M_ID marker ; +1249: WORD szSection ; +1250: +1251: if ( ReadStringN ( FTell ( ) , 5 ) == "Ducky" ) { +1252: +1253: char Ducky [ 5 ] ; +1254: local WORD s = szSection ; +1255: while ( s > 0 ) { +1256: struct { +1257: enum < uint16 > { +1258: DK_End , +1259: DK_Quality , +1260: DK_Comment , +1261: DK_Copyright , +1262: } tag ; +1263: if ( tag == DK_End ) +1264: break ; +1265: +1266: uint16 len ; +1267: +1268: switch ( tag ) { +1269: case DK_End : +1270: break ; +1271: case DK_Quality : +1272: uint32 value ; +1273: break ; +1274: case DK_Comment : +1275: uint32 count ; +1276: char comment [ len - 4 ] ; +1277: break ; +1278: case DK_Copyright : +1279: uint32 count ; +1280: char comment [ len - 4 ] ; +1281: break ; +1282: default : +1283: char unknown [ len ] ; +1284: break ; +1285: } +1286: } entry ; +1287: if ( entry . tag == DK_End ) +1288: break ; +1289: s -= sizeof ( entry ) ; +1290: } +1291: } else { +1292: +1293: char unknown [ szSection - 2 ] ; +1294: } +1295: } APP12 ; +1296: +1297: typedef struct tagAPP13 { +1298: M_ID marker ; +1299: WORD szSection ; +1300: +1301: if ( ReadStringN ( FTell ( ) , 14 ) == "Photoshop 3.0" ) { +1302: +1303: char photoshop30 [ 14 ] ; +1304: local int remainsize = szSection - 16 ; +1305: while ( remainsize > 0 ) { +1306: struct { +1307: char type [ 4 ] ; +1308: if ( type == "8BIM" ) { +1309: } else if ( type == "PHUT" || type == "DCSR" || type == "AgHg" ) { +1310: } else { +1311: char unknown [ remainsize - 4 ] ; +1312: break ; +1313: } +1314: enum < uint16 > { +1315: PS_IPTCData = 0x404 , +1316: PS_JPEG_Quality = 0x406 , +1317: PS_PhotoshopBGRThumbnail = 0x409 , +1318: PS_CopyrightFlag = 0x40A , +1319: PS_URL = 0x40B , +1320: PS_PhotoshopThumbnail = 0x40C , +1321: PS_ICC_Profile = 0x40F , +1322: PS_GlobalAltitude = 0x419 , +1323: PS_EXIFInfo = 0x422 , +1324: PS_XMP = 0x424 , +1325: PS_IPTCDigest = 0x425 , +1326: PS_ClippingPathName = 0xBB7 , +1327: } tag ; +1328: uchar namelen ; +1329: if ( namelen ) +1330: char name [ namelen ] ; +1331: if ( namelen % 2 != 1 ) +1332: char padding ; +1333: uint32 size ; +1334: if ( size ) +1335: char data [ size ] ; +1336: if ( size % 2 != 0 ) +1337: char padding ; +1338: } block ; +1339: remainsize -= sizeof ( block ) ; +1340: } +1341: } else if ( ReadStringN ( FTell ( ) , 9 ) == "Adobe_CM" ) { +1342: char adobe_cm [ 9 ] ; +1343: uchar AdobeCMType ; +1344: if ( szSection != 12 ) +1345: char unknown [ szSection - 12 ] ; +1346: } else { +1347: +1348: char unknown [ szSection - 2 ] ; +1349: } +1350: } APP13 ; +1351: +1352: typedef struct tagAPP14 { +1353: M_ID marker ; +1354: WORD szSection ; +1355: +1356: if ( ReadStringN ( FTell ( ) , 5 ) == "Adobe" ) { +1357: +1358: char adobe [ 5 ] ; +1359: uint16 version ; +1360: uint16 flag0 ; +1361: uint16 flag1 ; +1362: uchar color_transform_code ; +1363: if ( FTell ( ) < szSection + startof ( szSection ) ) char unknown [ szSection + startof ( szSection ) - FTell ( ) ] ; +1364: } else { +1365: +1366: char unknown [ szSection - 2 ] ; +1367: } +1368: } APP14 ; +1369: +1370: +1371: +1372: typedef struct tagSOS { +1373: M_ID marker ; +1374: WORD szSection ; +1375: ubyte nr_comp ; +1376: ChangeColor ( 0 ) ; +1377: struct COMPSOS { +1378: ubyte AC : 4 ; +1379: ubyte DC : 4 ; +1380: } comp [ nr_comp ] ; +1381: uchar Ss ; +1382: uchar Se ; +1383: uchar Ah : 4 ; +1384: uchar Al : 4 ; +1385: } SOS ; +1386: +1387: typedef struct tagUNK { +1388: M_ID UnknownMarker ; +1389: +1390: WORD szSection ; +1391: if ( FTell ( ) + szSection - 2 >= JpegFileEnd ) { +1392: Warning ( "unknown section length pass the end of jpeg file" ) ; +1393: ubyte unknown [ JpegFileEnd - FTell ( ) ] ; +1394: } else { +1395: ubyte unknown [ szSection - 2 ] ; +1396: } +1397: } UNKNOWN ; +1398: +1399: typedef struct tagDHT { +1400: M_ID marker ; +1401: WORD szSection ; +1402: local WORD huffsz = szSection - 2 ; +1403: while ( huffsz > 0 ) { +1404: ChangeColor ( 0 ) ; +1405: struct Huffmann_Table { +1406: ubyte htInfo ; +1407: ubyte length [ 16 ] ; +1408: local int sumLen = 0 ; +1409: local int i = 0 ; +1410: for ( i ; i < 16 ; i ++ ) { +1411: sumLen += length [ i ] ; +1412: } +1413: ubyte HTV [ sumLen ] ; +1414: } huff_table ; +1415: huffsz -= sizeof ( huff_table ) ; +1416: } +1417: } DHT ; +1418: +1419: typedef struct tagDQT { +1420: M_ID marker ; +1421: WORD szSection ; +1422: local WORD qtsz = szSection - 2 ; +1423: while ( qtsz > 0 ) { +1424: ChangeColor ( 0 ) ; +1425: struct QuanTable { +1426: uchar Pq : 4 ; +1427: uchar Tq : 4 ; +1428: if ( Pq == 0 ) +1429: byte qTable [ 64 ] ; +1430: else +1431: uint16 qTable [ 64 ] ; +1432: } qtable ; +1433: qtsz -= sizeof ( qtable ) ; +1434: } +1435: } DQT ; +1436: +1437: typedef struct tagDRI { +1438: M_ID marker ; +1439: WORD szSection ; +1440: WORD Ri ; +1441: } DRI ; +1442: +1443: typedef struct tagDHP { +1444: M_ID marker ; +1445: WORD szSection ; +1446: uchar P ; +1447: uint16 Y ; +1448: uint16 X ; +1449: uchar Nf ; +1450: struct { +1451: uchar id ; +1452: uchar h_factor : 4 ; +1453: uchar v_factor : 4 ; +1454: uchar Tq ; +1455: } component_param [ Nf ] ; +1456: } DHP ; +1457: +1458: typedef struct tgSOFx { +1459: M_ID marker ; +1460: WORD szSection ; +1461: ubyte precision ; +1462: WORD Y_image ; +1463: WORD X_image ; +1464: ubyte nr_comp ; +1465: ChangeColor ( 0 ) ; +1466: struct COMPS { +1467: ubyte compId ; +1468: ubyte Horz : 4 ; +1469: ubyte Vert : 4 ; +1470: ubyte compNr ; +1471: } comp [ nr_comp ] ; +1472: } SOFx ; +1473: +1474: typedef struct tagCOMMENT { +1475: M_ID CommentMarker ; +1476: WORD szSection ; +1477: char comment [ szSection - 2 ] ; +1478: +1479: +1480: local char comments [ szSection - 1 ] = { 0 } ; +1481: local int i = 0 ; +1482: Memcpy ( comments , comment , szSection - 2 ) ; +1483: for ( i = 0 ; i < szSection - 1 ; i ++ ) { +1484: if ( comments [ i ] == 0 ) comments [ i ] = 'x' ; +1485: } +1486: comments [ szSection - 2 ] = 0 ; +1487: Printf ( "\nCOMMENT :\n%s\n\n" , comments ) ; +1488: +1489: } COMMENT < read = ReadComment > ; +1490: +1491: typedef struct tagJPGLS { +1492: M_ID marker ; +1493: WORD szSection ; +1494: +1495: uchar precision < comment = "bits per sample" > ; +1496: WORD Y_numlines ; +1497: WORD X_numcols ; +1498: uchar Nf < comment = "number of components in frame" > ; +1499: uchar C_compID ; +1500: uchar sub_sampling ; +1501: uchar Tq < comment = "always 0" > ; +1502: +1503: if ( 11 < szSection ) +1504: uchar uknown [ szSection - 11 ] ; +1505: } JPGLS ; +1506: +1507: string ReadComment ( COMMENT & com ) +1508: { +1509: return com . comment ; +1510: } +1511: +1512: JpegFileEnd = FileSize ( ) ; +1513: +1514: +1515: +1516: +1517: SetBackColor ( jetMap [ 0 ] ) ; +1518: typedef struct tgJPGFile { +1519: local int was_bigendian = IsBigEndian ( ) ; +1520: BigEndian ( ) ; +1521: local WORD NextMarker ; +1522: local quad fpos2 ; +1523: local byte bEOI = 0 ; +1524: while ( FTell ( ) < JpegFileEnd && ! bEOI ) { +1525: +1526: while ( ReadUShort ( FTell ( ) ) == 0xFFFF ) FSkip ( 1 ) ; +1527: +1528: NextMarker = ReadUShort ( FTell ( ) ) ; +1529: switch ( NextMarker ) { +1530: case M_SOI : +1531: M_ID SOIMarker ; +1532: Printf ( "Start of Image Marker\n" ) ; +1533: break ; +1534: case M_SOS : +1535: SOS scanStart ; +1536: Printf ( "Start of Scan Marker\n" ) ; +1537: NextMarker = ReadUShort ( JpegFileEnd - 2 ) ; +1538: fpos2 = 0 ; +1539: while ( NextMarker != M_EOI ) { +1540: NextMarker = ReadUShort ( JpegFileEnd - 2 - ( ++ fpos2 ) ) ; +1541: } +1542: char scanData [ JpegFileEnd - FTell ( ) - 2 - fpos2 ] ; +1543: ChangeColor ( 1 ) ; +1544: M_ID EOIMarker ; +1545: Printf ( "End of File Image\n" ) ; +1546: if ( fpos2 ) char unknownPadding [ fpos2 ] ; +1547: bEOI = 1 ; +1548: break ; +1549: case M_APP0 : +1550: APP0 app0 ; +1551: break ; +1552: case M_DHT : +1553: DHT dht ; +1554: break ; +1555: case M_DQT : +1556: DQT dqt ; +1557: break ; +1558: case M_DRI : +1559: DRI dri ; +1560: break ; +1561: case M_DHP : +1562: DHP dhp ; +1563: break ; +1564: case M_SOF0 : +1565: SOFx sof0 ; +1566: break ; +1567: case M_SOF1 : +1568: SOFx sof1 ; +1569: break ; +1570: case M_SOF2 : +1571: SOFx sof2 ; +1572: break ; +1573: case M_APP1 : +1574: APP1 app1 ; +1575: break ; +1576: case M_APP2 : +1577: APP2 app2 ; +1578: break ; +1579: case M_APP12 : +1580: APP12 app12 ; +1581: break ; +1582: case M_APP13 : +1583: APP13 app13 ; +1584: break ; +1585: case M_APP14 : +1586: APP14 app14 ; +1587: break ; +1588: case M_COMM : +1589: COMMENT comment ; +1590: break ; +1591: case M_JPGLS : +1592: JPGLS jpgls ; +1593: break ; +1594: default : +1595: UNKNOWN unknownSection ; +1596: break ; +1597: } +1598: ChangeColor ( ! bEOI ) ; +1599: } +1600: if ( ! was_bigendian ) +1601: LittleEndian ( ) ; +1602: } JPGFILE ; +1603: +1604: JPGFILE jpgfile ; +1605: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/LNKTemplate.bt b/cparser/tests/exp_lex/LNKTemplate.bt new file mode 100644 index 0000000..58ce2fb --- /dev/null +++ b/cparser/tests/exp_lex/LNKTemplate.bt @@ -0,0 +1,425 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: +21: +22: +23: +24: +25: +26: +27: +28: +29: +30: +31: +32: +33: +34: +35: local int iCOLOR = 0x95E8FF ; +36: +37: local int iToggleColor = iCOLOR ; +38: +39: void ToggleBackColor ( ) +40: { +41: if ( iToggleColor == iCOLOR ) +42: iToggleColor = cNone ; +43: else +44: iToggleColor = iCOLOR ; +45: SetBackColor ( iToggleColor ) ; +46: } +47: +48: typedef struct +49: { +50: int HasLinkTargetIDList : 1 ; +51: int HasLinkInfo : 1 ; +52: int HasName : 1 ; +53: int HasRelativePath : 1 ; +54: int HasWorkingDir : 1 ; +55: int HasArguments : 1 ; +56: int HasIconLocation : 1 ; +57: int IsUnicode : 1 ; +58: int ForceNoLinkInfo : 1 ; +59: int HasExpString : 1 ; +60: int RunInSeparateProcess : 1 ; +61: int Unused1 : 1 ; +62: int HasDarwinID : 1 ; +63: int RunAsUser : 1 ; +64: int HasExpIcon : 1 ; +65: int NoPidlAlias : 1 ; +66: int Unused2 : 1 ; +67: int RunWithShimLayer : 1 ; +68: int ForceNoLinkTrack : 1 ; +69: int EnableTargetMetadata : 1 ; +70: int DisableLinkPathTracking : 1 ; +71: int DisableKnownFolderTracking : 1 ; +72: int DisableKnownFolderAlias : 1 ; +73: int AllowLinkToLink : 1 ; +74: int UnaliasOnSave : 1 ; +75: int PreferEnvironmentPath : 1 ; +76: int KeepLocalIDListForUNCTarget : 1 ; +77: int Unused3 : 5 ; +78: } LinkFlags ; +79: +80: typedef struct +81: { +82: int FILE_ATTRIBUTE_READONLY : 1 ; +83: int FILE_ATTRIBUTE_HIDDEN : 1 ; +84: int FILE_ATTRIBUTE_SYSTEM : 1 ; +85: int Reserved1 : 1 ; +86: int FILE_ATTRIBUTE_DIRECTORY : 1 ; +87: int FILE_ATTRIBUTE_ARCHIVE : 1 ; +88: int FILE_ATTRIBUTE_NORMAL : 1 ; +89: int FILE_ATTRIBUTE_TEMPORARY : 1 ; +90: int FILE_ATTRIBUTE_SPARSE_FILE : 1 ; +91: int FILE_ATTRIBUTE_REPARSE_POINT : 1 ; +92: int FILE_ATTRIBUTE_COMPRESSED : 1 ; +93: int FILE_ATTRIBUTE_OFFLINE : 1 ; +94: int FILE_ATTRIBUTE_NOT_CONTENT_INDEXED : 1 ; +95: int FILE_ATTRIBUTE_ENCRYPTED : 1 ; +96: int Unused1 : 18 ; +97: } FileAttributes ; +98: +99: typedef struct +100: { +101: DWORD HeaderSize < read = ReadCheckHeaderSize > ; +102: BYTE LinkCLSID [ 16 ] ; +103: LinkFlags sLinkFlags ; +104: FileAttributes sFileAttributes ; +105: FILETIME CreationTime ; +106: FILETIME AccessTime ; +107: FILETIME WriteTime ; +108: DWORD FileSize ; +109: DWORD IconIndex ; +110: DWORD ShowCommand < read = ReadShowCommand > ; +111: WORD HotKey ; +112: WORD Reserved1 ; +113: DWORD Reserved2 ; +114: DWORD Reserved3 ; +115: } ShellLinkHeader ; +116: +117: string ReadCheckHeaderSize ( DWORD data ) +118: { +119: string result ; +120: +121: switch ( data ) +122: { +123: case 0x4C : +124: result = "76" ; +125: break ; +126: +127: default : +128: SPrintf ( result , "Unexpected headersize: 0x%08X" , data ) ; +129: } +130: +131: return result ; +132: } +133: +134: string ReadShowCommand ( DWORD function ) +135: { +136: string result ; +137: +138: switch ( function ) +139: { +140: case 0x1 : +141: result = "SW_SHOWNORMAL" ; +142: break ; +143: +144: case 0x3 : +145: result = "SW_SHOWMAXIMIZED" ; +146: break ; +147: +148: case 0x7 : +149: result = "SW_SHOWMINNOACTIVE" ; +150: break ; +151: +152: default : +153: SPrintf ( result , "0x%08X" , function ) ; +154: } +155: +156: return result ; +157: } +158: +159: +160: typedef struct +161: { +162: WORD ItemIDSize ; +163: if ( ItemIDSize == 0x14 ) +164: { +165: BYTE Type ; +166: BYTE Unknown ; +167: BYTE GUID [ ItemIDSize - 4 ] ; +168: } +169: else +170: BYTE Data [ ItemIDSize - 2 ] ; +171: } IDList < read = ReadIDList > ; +172: +173: string ReadIDList ( IDList & sIDList ) +174: { +175: string sGUID ; +176: +177: if ( sIDList . ItemIDSize == 0x14 ) +178: { +179: SPrintf ( sGUID , "{%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X}" , sIDList . GUID [ 3 ] , sIDList . GUID [ 2 ] , sIDList . GUID [ 1 ] , sIDList . GUID [ 0 ] , sIDList . GUID [ 5 ] , sIDList . GUID [ 4 ] , sIDList . GUID [ 7 ] , sIDList . GUID [ 6 ] , sIDList . GUID [ 8 ] , sIDList . GUID [ 9 ] , sIDList . GUID [ 10 ] , sIDList . GUID [ 11 ] , sIDList . GUID [ 12 ] , sIDList . GUID [ 13 ] , sIDList . GUID [ 14 ] , sIDList . GUID [ 15 ] ) ; +180: return LookupGUID ( sGUID ) ; +181: } +182: else +183: return "" ; +184: } +185: +186: +187: string LookupGUID ( string sGUID ) +188: { +189: if ( ! Stricmp ( sGUID , "{208D2C60-3AEA-1069-A2D7-08002B30309D}" ) ) +190: return "CLSID_NetworkPlaces" ; +191: else if ( ! Stricmp ( sGUID , "{46e06680-4bf0-11d1-83ee-00a0c90dc849}" ) ) +192: return "CLSID_NetworkDomain" ; +193: else if ( ! Stricmp ( sGUID , "{c0542a90-4bf0-11d1-83ee-00a0c90dc849}" ) ) +194: return "CLSID_NetworkServer" ; +195: else if ( ! Stricmp ( sGUID , "{54a754c0-4bf1-11d1-83ee-00a0c90dc849}" ) ) +196: return "CLSID_NetworkShare" ; +197: else if ( ! Stricmp ( sGUID , "{20D04FE0-3AEA-1069-A2D8-08002B30309D}" ) ) +198: return "CLSID_MyComputer" ; +199: else if ( ! Stricmp ( sGUID , "{871C5380-42A0-1069-A2EA-08002B30309D}" ) ) +200: return "CLSID_Internet" ; +201: else if ( ! Stricmp ( sGUID , "{F3364BA0-65B9-11CE-A9BA-00AA004AE837}" ) ) +202: return "CLSID_ShellFSFolder" ; +203: else if ( ! Stricmp ( sGUID , "{645FF040-5081-101B-9F08-00AA002F954E}" ) ) +204: return "CLSID_RecycleBin" ; +205: else if ( ! Stricmp ( sGUID , "{21EC2020-3AEA-1069-A2DD-08002B30309D}" ) ) +206: return "CLSID_ControlPanel" ; +207: else if ( ! Stricmp ( sGUID , "{450D8FBA-AD25-11D0-98A8-0800361B1103}" ) ) +208: return "CLSID_MyDocuments" ; +209: else +210: return sGUID ; +211: } +212: +213: typedef struct +214: { +215: WORD IDListSize ; +216: +217: while ( ReadUShort ( FTell ( ) ) != 0x0 ) +218: { +219: IDList sIDList ; +220: } +221: WORD TerminalID ; +222: } LinkTargetIDList ; +223: +224: typedef struct +225: { +226: int VolumeIDAndLocalBasePath : 1 ; +227: int CommonNetworkRelativeLinkAndPathSuffix : 1 ; +228: int Unused1 : 30 ; +229: } LinkInfoFlags ; +230: +231: typedef struct +232: { +233: DWORD VolumeIDSize ; +234: DWORD DriveType < read = ReadDriveType > ; ; +235: DWORD DriveSerialNumber ; +236: DWORD VolumeLabelOffset ; +237: if ( VolumeLabelOffset == 0x14 ) +238: { +239: DWORD VolumeLabelOffsetUnicode ; +240: } +241: string Data ; +242: } VolumeID ; +243: +244: typedef struct +245: { +246: DWORD CommonNetworkRelativeLinkSize ; +247: DWORD CommonNetworkRelativeLinkFlags ; +248: DWORD NetNameOffset ; +249: DWORD DeviceNameOffset ; +250: DWORD NetworkProviderType ; +251: if ( NetNameOffset > 0x14 ) +252: { +253: DWORD NetNameOffsetUnicode ; +254: DWORD DeviceNameOffsetUnicode ; +255: } +256: string NetName ; +257: string DeviceName ; +258: if ( NetNameOffset > 0x14 ) +259: { +260: string NetNameUnicode ; +261: string DeviceNameUnicode ; +262: } +263: } CommonNetworkRelativeLink ; +264: +265: string ReadDriveType ( DWORD function ) +266: { +267: string result ; +268: +269: switch ( function ) +270: { +271: case 0x0 : +272: result = "DRIVE_UNKNOWN" ; +273: break ; +274: +275: case 0x1 : +276: result = "DRIVE_NO_ROOT_DIR" ; +277: break ; +278: +279: case 0x2 : +280: result = "DRIVE_REMOVABLE" ; +281: break ; +282: +283: case 0x3 : +284: result = "DRIVE_FIXED" ; +285: break ; +286: +287: case 0x4 : +288: result = "DRIVE_REMOTE" ; +289: break ; +290: +291: case 0x5 : +292: result = "DRIVE_CDROM" ; +293: break ; +294: +295: case 0x6 : +296: result = "DRIVE_RAMDISK" ; +297: break ; +298: +299: default : +300: SPrintf ( result , "0x%08X" , function ) ; +301: } +302: +303: return result ; +304: } +305: +306: typedef struct +307: { +308: DWORD LinkInfoSize ; +309: DWORD LinkInfoHeaderSize ; +310: LinkInfoFlags sLinkInfoFlags ; +311: DWORD VolumeIDOffset ; +312: DWORD LocalBasePathOffset ; +313: DWORD CommonNetworkRelativeLinkOffset ; +314: DWORD CommonPathSuffixOffset ; +315: if ( LinkInfoHeaderSize >= 0x24 ) +316: { +317: DWORD LocalBasePathOffsetUnicode ; +318: DWORD CommonPathSuffixOffsetUnicode ; +319: } +320: if ( sLinkInfoFlags . VolumeIDAndLocalBasePath == 1 ) +321: { +322: VolumeID sVolumeID ; +323: string LocalBasePath ; +324: string CommonPathSuffix ; +325: } +326: if ( sLinkInfoFlags . CommonNetworkRelativeLinkAndPathSuffix == 1 ) +327: { +328: CommonNetworkRelativeLink sCommonNetworkRelativeLink ; +329: } +330: } LinkInfo ; +331: +332: typedef struct +333: { +334: WORD CountCharacters ; +335: BYTE String [ CountCharacters * 2 ] ; +336: } StringData ; +337: +338: typedef struct +339: { +340: DWORD BlockSize ; +341: DWORD BlockSignature ; +342: BYTE BlockData [ BlockSize - 8 ] ; +343: } ExtraDataBlock ; +344: +345: typedef struct +346: { +347: DWORD BlockSize ; +348: DWORD BlockSignature ; +349: DWORD Length ; +350: DWORD Version ; +351: BYTE MachineID [ 16 ] ; +352: BYTE Droid [ 32 ] ; +353: BYTE DroidBirth [ 32 ] ; +354: } TrackerDataBlock ; +355: +356: typedef struct +357: { +358: while ( ReadUInt ( FTell ( ) ) >= 0x4 ) +359: { +360: switch ( ReadUInt ( FTell ( ) + 4 ) ) +361: { +362: case 0xA0000003 : +363: TrackerDataBlock sTrackerDataBlock ; +364: break ; +365: +366: default : +367: ExtraDataBlock sExtraDataBlock ; +368: } +369: } +370: DWORD TerminalBlock ; +371: } ExtraData ; +372: +373: +374: LittleEndian ( ) ; +375: +376: SetBackColor ( iToggleColor ) ; +377: ShellLinkHeader sShellLinkHeader ; +378: +379: if ( sShellLinkHeader . sLinkFlags . HasLinkTargetIDList == 1 ) +380: { +381: ToggleBackColor ( ) ; +382: LinkTargetIDList sLinkTargetIDList ; +383: } +384: +385: if ( sShellLinkHeader . sLinkFlags . HasLinkInfo == 1 ) +386: { +387: ToggleBackColor ( ) ; +388: LinkInfo sLinkInfo ; +389: } +390: +391: if ( sShellLinkHeader . sLinkFlags . HasName == 1 ) +392: { +393: ToggleBackColor ( ) ; +394: StringData NAME_STRING ; +395: } +396: +397: if ( sShellLinkHeader . sLinkFlags . HasRelativePath == 1 ) +398: { +399: ToggleBackColor ( ) ; +400: StringData RELATIVE_PATH ; +401: } +402: +403: if ( sShellLinkHeader . sLinkFlags . HasWorkingDir == 1 ) +404: { +405: ToggleBackColor ( ) ; +406: StringData WORKING_DIR ; +407: } +408: +409: if ( sShellLinkHeader . sLinkFlags . HasArguments == 1 ) +410: { +411: ToggleBackColor ( ) ; +412: StringData COMMAND_LINE_ARGUMENTS ; +413: } +414: +415: if ( sShellLinkHeader . sLinkFlags . HasIconLocation == 1 ) +416: { +417: ToggleBackColor ( ) ; +418: StringData ICON_LOCATION ; +419: } +420: +421: ToggleBackColor ( ) ; +422: ExtraData sExtraData ; +423: +424: SetBackColor ( cNone ) ; +425: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/MBRTemplate.bt b/cparser/tests/exp_lex/MBRTemplate.bt new file mode 100644 index 0000000..1694c14 --- /dev/null +++ b/cparser/tests/exp_lex/MBRTemplate.bt @@ -0,0 +1,461 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: BitfieldRightToLeft ( ) ; +18: BitfieldDisablePadding ( ) ; +19: +20: string BootID ( unsigned char boot_id ) { +21: string ret ; +22: +23: if ( boot_id & 0x80 ) +24: Strcat ( ret , "Bootable" ) ; +25: else +26: Strcat ( ret , "Not bootable" ) ; +27: +28: return ret ; +29: } +30: +31: +32: +33: string PartitionID ( unsigned char ptype ) { +34: switch ( ptype ) { +35: case 0 : +36: return "Empty" ; +37: case 1 : +38: return "DOS 12-bit FAT" ; +39: case 2 : +40: return "XENIX root" ; +41: case 3 : +42: return "XENIX /usr" ; +43: case 4 : +44: return "DOS 3.0+ 16-bit FAT (up to 32M)" ; +45: case 5 : +46: return "DOS 3.3+ Extended Partition" ; +47: case 6 : +48: return "DOS 3.31+ 16-bit FAT (over 32M)" ; +49: case 7 : +50: return "OS/2 IFS (e.g., HPFS), Windows NT NTFS, exFAT, Advanced Unix, QNX2.x pre-1988 (see below under IDs 4d-4f)" ; +51: case 8 : +52: return "OS/2 (v1.0-1.3 only), AIX boot partition, SplitDrive, Commodore DOS, DELL partition spanning multiple drives, QNX 1.x and 2.x (\"qny\")" ; +53: case 9 : +54: return "AIX data partition, Coherent filesystem, QNX 1.x and 2.x (\"qnz\")" ; +55: case 10 : +56: return "OS/2 Boot Manager, Coherent swap partition, OPUS" ; +57: case 11 : +58: return "WIN95 OSR2 FAT32" ; +59: case 12 : +60: return "WIN95 OSR2 FAT32, LBA-mapped" ; +61: case 13 : +62: return "SILICON SAFE" ; +63: case 14 : +64: return "WIN95: DOS 16-bit FAT, LBA-mapped" ; +65: case 15 : +66: return "WIN95: Extended partition, LBA-mapped" ; +67: case 16 : +68: return "OPUS (?)" ; +69: case 17 : +70: return "Hidden DOS 12-bit FAT" ; +71: case 18 : +72: return "Configuration/diagnostics partition" ; +73: case 20 : +74: return "Hidden DOS 16-bit FAT <32M" ; +75: case 22 : +76: return "Hidden DOS 16-bit FAT >=32M" ; +77: case 23 : +78: return "Hidden IFS (e.g., HPFS)" ; +79: case 24 : +80: return "AST SmartSleep Partition" ; +81: case 25 : +82: return "Unused" ; +83: case 27 : +84: return "Hidden WIN95 OSR2 FAT32" ; +85: case 28 : +86: return "Hidden WIN95 OSR2 FAT32, LBA-mapped" ; +87: case 30 : +88: return "Hidden WIN95 16-bit FAT, LBA-mapped" ; +89: case 32 : +90: return "Unused" ; +91: case 33 : +92: return "Reserved, Unused" ; +93: case 34 : +94: return "Unused" ; +95: case 35 : +96: return "Reserved" ; +97: case 36 : +98: return "NEC DOS 3.x" ; +99: case 38 : +100: return "Reserved" ; +101: case 39 : +102: return "PQservice, Windows RE hidden partition, MirOS partition, RouterBOOT kernel partition" ; +103: case 42 : +104: return "AtheOS File System (AFS)" ; +105: case 49 : +106: return "Reserved" ; +107: case 50 : +108: return "NOS" ; +109: case 51 : +110: return "Reserved" ; +111: case 52 : +112: return "Reserved" ; +113: case 53 : +114: return "JFS on OS/2 or eCS " ; +115: case 54 : +116: return "Reserved" ; +117: case 56 : +118: return "THEOS ver 3.2 2gb partition" ; +119: case 57 : +120: return "Plan 9 partition, THEOS ver 4 spanned partition" ; +121: case 58 : +122: return "THEOS ver 4 4gb partition" ; +123: case 59 : +124: return "THEOS ver 4 extended partition" ; +125: case 60 : +126: return "PartitionMagic recovery partition" ; +127: case 61 : +128: return "Hidden NetWare" ; +129: case 64 : +130: return "Venix 80286, PICK" ; +131: case 65 : +132: return "Linux/MINIX (sharing disk with DRDOS), Personal RISC Boot, PPC PReP (Power PC Reference Platform) Boot" ; +133: case 66 : +134: return "Linux swap (sharing disk with DRDOS), SFS (Secure Filesystem), Windows 2000 dynamic extended partition marker" ; +135: case 67 : +136: return "Linux native (sharing disk with DRDOS)" ; +137: case 68 : +138: return "GoBack partition" ; +139: case 69 : +140: return "Boot-US boot manager, Priam, EUMEL/Elan " ; +141: case 70 : +142: return "EUMEL/Elan " ; +143: case 71 : +144: return "EUMEL/Elan " ; +145: case 72 : +146: return "EUMEL/Elan " ; +147: case 74 : +148: return "Mark Aitchison's ALFS/THIN lightweight filesystem for DOS, AdaOS Aquila (Withdrawn)" ; +149: case 76 : +150: return "Oberon partition" ; +151: case 77 : +152: return "QNX4.x" ; +153: case 78 : +154: return "QNX4.x 2nd part" ; +155: case 79 : +156: return "QNX4.x 3rd part, Oberon partition" ; +157: case 80 : +158: return "OnTrack Disk Manager (older versions) RO, Lynx RTOS, Native Oberon (alt)" ; +159: case 81 : +160: return "OnTrack Disk Manager RW (DM6 Aux1), Novell" ; +161: case 82 : +162: return "CP/M, Microport SysV/AT" ; +163: case 83 : +164: return "Disk Manager 6.0 Aux3" ; +165: case 84 : +166: return "Disk Manager 6.0 Dynamic Drive Overlay (DDO)" ; +167: case 85 : +168: return "EZ-Drive" ; +169: case 86 : +170: return "Golden Bow VFeature Partitioned Volume., DM converted to EZ-BIOS" ; +171: case 87 : +172: return "DrivePro, VNDI Partition" ; +173: case 92 : +174: return "Priam EDisk" ; +175: case 97 : +176: return "SpeedStor" ; +177: case 99 : +178: return "Unix System V (SCO, ISC Unix, UnixWare, ...), Mach, GNU Hurd" ; +179: case 100 : +180: return "PC-ARMOUR protected partition, Novell Netware 286, 2.xx" ; +181: case 101 : +182: return "Novell Netware 386, 3.xx or 4.xx" ; +183: case 102 : +184: return "Novell Netware SMS Partition" ; +185: case 103 : +186: return "Novell" ; +187: case 104 : +188: return "Novell" ; +189: case 105 : +190: return "Novell Netware 5+, Novell Netware NSS Partition" ; +191: case 110 : +192: return "??" ; +193: case 112 : +194: return "DiskSecure Multi-Boot" ; +195: case 113 : +196: return "Reserved" ; +197: case 114 : +198: return "V7/x86" ; +199: case 115 : +200: return "Reserved" ; +201: case 116 : +202: return "Reserved, Scramdisk partition" ; +203: case 117 : +204: return "IBM PC/IX" ; +205: case 118 : +206: return "Reserved" ; +207: case 119 : +208: return "M2FS/M2CS partition, VNDI Partition" ; +209: case 120 : +210: return "XOSL FS" ; +211: case 126 : +212: return "Unused" ; +213: case 127 : +214: return "Unused" ; +215: case 128 : +216: return "MINIX until 1.4a" ; +217: case 129 : +218: return "MINIX since 1.4b, early Linux, Mitac disk manager" ; +219: case 130 : +220: return "Prime, Solaris x86, Linux swap" ; +221: case 131 : +222: return "Linux native partition" ; +223: case 132 : +224: return "OS/2 hidden C: drive, Hibernation partition" ; +225: case 133 : +226: return "Linux extended partition" ; +227: case 134 : +228: return "Old Linux RAID partition superblock, FAT16 volume set" ; +229: case 135 : +230: return "NTFS volume set" ; +231: case 136 : +232: return "Linux plaintext partition table" ; +233: case 138 : +234: return "Linux Kernel Partition (used by AiR-BOOT)" ; +235: case 139 : +236: return "Legacy Fault Tolerant FAT32 volume" ; +237: case 140 : +238: return "Legacy Fault Tolerant FAT32 volume using BIOS extd INT 13h" ; +239: case 141 : +240: return "Free FDISK 0.96+ hidden Primary DOS FAT12 partitition" ; +241: case 142 : +242: return "Linux Logical Volume Manager partition" ; +243: case 144 : +244: return "Free FDISK 0.96+ hidden Primary DOS FAT16 partitition" ; +245: case 145 : +246: return "Free FDISK 0.96+ hidden DOS extended partitition" ; +247: case 146 : +248: return "Free FDISK 0.96+ hidden Primary DOS large FAT16 partitition" ; +249: case 147 : +250: return "Hidden Linux native partition, Amoeba" ; +251: case 148 : +252: return "Amoeba bad block table" ; +253: case 149 : +254: return "MIT EXOPC native partitions" ; +255: case 150 : +256: return "CHRP ISO-9660 filesystem" ; +257: case 151 : +258: return "Free FDISK 0.96+ hidden Primary DOS FAT32 partitition" ; +259: case 152 : +260: return "Free FDISK 0.96+ hidden Primary DOS FAT32 partitition (LBA), Datalight ROM-DOS Super-Boot Partition" ; +261: case 153 : +262: return "DCE376 logical drive" ; +263: case 154 : +264: return "Free FDISK 0.96+ hidden Primary DOS FAT16 partitition (LBA)" ; +265: case 155 : +266: return "Free FDISK 0.96+ hidden DOS extended partitition (LBA)" ; +267: case 158 : +268: return "ForthOS partition" ; +269: case 159 : +270: return "BSD/OS" ; +271: case 160 : +272: return "Laptop hibernation partition" ; +273: case 161 : +274: return "Laptop hibernation partition, HP Volume Expansion (SpeedStor variant)" ; +275: case 163 : +276: return "HP Volume Expansion (SpeedStor variant)" ; +277: case 164 : +278: return "HP Volume Expansion (SpeedStor variant)" ; +279: case 165 : +280: return "BSD/386, 386BSD, NetBSD, FreeBSD" ; +281: case 166 : +282: return "OpenBSD, HP Volume Expansion (SpeedStor variant)" ; +283: case 167 : +284: return "NeXTStep" ; +285: case 168 : +286: return "Mac OS-X" ; +287: case 169 : +288: return "NetBSD" ; +289: case 170 : +290: return "Olivetti Fat 12 1.44MB Service Partition" ; +291: case 171 : +292: return "Mac OS-X Boot partition, GO! partition" ; +293: case 173 : +294: return "RISC OS ADFS" ; +295: case 174 : +296: return "ShagOS filesystem" ; +297: case 175 : +298: return "ShagOS swap partition, MacOS X HFS" ; +299: case 176 : +300: return "BootStar Dummy" ; +301: case 177 : +302: return "HP Volume Expansion (SpeedStor variant), QNX Neutrino Power-Safe filesystem" ; +303: case 178 : +304: return "QNX Neutrino Power-Safe filesystem" ; +305: case 179 : +306: return "HP Volume Expansion (SpeedStor variant), QNX Neutrino Power-Safe filesystem" ; +307: case 180 : +308: return "HP Volume Expansion (SpeedStor variant)" ; +309: case 182 : +310: return "HP Volume Expansion (SpeedStor variant), Corrupted Windows NT mirror set (master), FAT16 file system" ; +311: case 183 : +312: return "Corrupted Windows NT mirror set (master), NTFS file system, BSDI BSD/386 filesystem" ; +313: case 184 : +314: return "BSDI BSD/386 swap partition" ; +315: case 187 : +316: return "Boot Wizard hidden" ; +317: case 188 : +318: return "Acronis backup partition" ; +319: case 189 : +320: return "BonnyDOS/286" ; +321: case 190 : +322: return "Solaris 8 boot partition" ; +323: case 191 : +324: return "New Solaris x86 partition" ; +325: case 192 : +326: return "CTOS, REAL/32 secure small partition, NTFT Partition, DR-DOS/Novell DOS secured partition" ; +327: case 193 : +328: return "DRDOS/secured (FAT-12)" ; +329: case 194 : +330: return "Unused, Hidden Linux" ; +331: case 195 : +332: return "Hidden Linux swap" ; +333: case 196 : +334: return "DRDOS/secured (FAT-16, < 32M)" ; +335: case 197 : +336: return "DRDOS/secured (extended)" ; +337: case 198 : +338: return "DRDOS/secured (FAT-16, >= 32M), Windows NT corrupted FAT16 volume/stripe set" ; +339: case 199 : +340: return "Windows NT corrupted NTFS volume/stripe set, Syrinx boot" ; +341: case 200 : +342: return "Reserved for DR-DOS 8.0+" ; +343: case 201 : +344: return "Reserved for DR-DOS 8.0+" ; +345: case 202 : +346: return "Reserved for DR-DOS 8.0+" ; +347: case 203 : +348: return "DR-DOS 7.04+ secured FAT32 (CHS)/" ; +349: case 204 : +350: return "DR-DOS 7.04+ secured FAT32 (LBA)/" ; +351: case 205 : +352: return "CTOS Memdump? " ; +353: case 206 : +354: return "DR-DOS 7.04+ FAT16X (LBA)/" ; +355: case 207 : +356: return "DR-DOS 7.04+ secured EXT DOS (LBA)/" ; +357: case 208 : +358: return "REAL/32 secure big partition, Multiuser DOS secured partition" ; +359: case 209 : +360: return "Old Multiuser DOS secured FAT12" ; +361: case 212 : +362: return "Old Multiuser DOS secured FAT16 <32M" ; +363: case 213 : +364: return "Old Multiuser DOS secured extended partition" ; +365: case 214 : +366: return "Old Multiuser DOS secured FAT16 >=32M" ; +367: case 216 : +368: return "CP/M-86" ; +369: case 218 : +370: return "Non-FS Data, Powercopy Backup" ; +371: case 219 : +372: return "Digital Research CP/M, Concurrent CP/M, Concurrent DOS, CTOS (Convergent Technologies OS -Unisys), KDG Telemetry SCPU boot" ; +373: case 221 : +374: return "Hidden CTOS Memdump? " ; +375: case 222 : +376: return "Dell PowerEdge Server utilities (FAT fs)" ; +377: case 223 : +378: return "DG/UX virtual disk manager partition, BootIt EMBRM" ; +379: case 225 : +380: return "DOS access or SpeedStor 12-bit FAT extended partition" ; +381: case 227 : +382: return "DOS R/O or SpeedStor" ; +383: case 228 : +384: return "SpeedStor 16-bit FAT extended partition < 1024 cyl." ; +385: case 230 : +386: return "Storage Dimensions SpeedStor" ; +387: case 232 : +388: return "LUKS" ; +389: case 234 : +390: return "Rufus extra partition, Freedesktop boot" ; +391: case 235 : +392: return "BeOS BFS" ; +393: case 236 : +394: return "SkyOS SkyFS" ; +395: case 237 : +396: return "Unused" ; +397: case 238 : +398: return "Indication that this legacy MBR is followed by an EFI header" ; +399: case 239 : +400: return "Partition that contains an EFI file system" ; +401: case 240 : +402: return "Linux/PA-RISC boot loader" ; +403: case 241 : +404: return "Storage Dimensions SpeedStor" ; +405: case 242 : +406: return "DOS 3.3+ secondary partition" ; +407: case 243 : +408: return "Reserved" ; +409: case 244 : +410: return "SpeedStor large partition, Prologue single-volume partition" ; +411: case 245 : +412: return "Prologue multi-volume partition" ; +413: case 246 : +414: return "Storage Dimensions SpeedStor" ; +415: case 247 : +416: return "DDRdrive Solid State File System" ; +417: case 249 : +418: return "pCache" ; +419: case 250 : +420: return "Bochs" ; +421: case 251 : +422: return "VMware File System partition" ; +423: case 252 : +424: return "VMware Swap partition" ; +425: case 253 : +426: return "Linux raid partition with autodetect using persistent superblock" ; +427: case 254 : +428: return "SpeedStor > 1024 cyl., LANstep, Windows NT Disk Administrator hidden partition, Linux Logical Volume Manager partition (old)" ; +429: case 255 : +430: return "Xenix Bad Block Table" ; +431: default : +432: return "Unknown partition type" ; +433: } +434: } +435: +436: +437: typedef struct fdisk_partition { +438: unsigned char bootid < comment = BootID > ; +439: unsigned short beghead : 8 ; +440: unsigned short begsect : 6 ; +441: unsigned short begcyl : 10 ; +442: unsigned char systid < comment = PartitionID > ; +443: unsigned short endhead : 8 ; +444: unsigned short endsect : 6 ; +445: unsigned short endcyl : 10 ; +446: unsigned int relsect ; +447: unsigned int numsect ; +448: } ; +449: +450: +451: typedef struct master_boot_record { +452: char bootinst [ 446 ] ; +453: fdisk_partition partitions [ 4 ] ; +454: ushort signature ; +455: } ; +456: +457: LittleEndian ( ) ; +458: +459: FSeek ( 0 ) ; +460: master_boot_record MBR ; +461: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/MBRTemplateFAT.bt b/cparser/tests/exp_lex/MBRTemplateFAT.bt new file mode 100644 index 0000000..7d8b110 --- /dev/null +++ b/cparser/tests/exp_lex/MBRTemplateFAT.bt @@ -0,0 +1,888 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: LittleEndian ( ) ; +11: +12: typedef char BOOL ; +13: typedef char BYTE ; +14: typedef unsigned char UBYTE ; +15: typedef short SHORT ; +16: typedef unsigned short USHORT ; +17: typedef long LONG ; +18: typedef unsigned long ULONG ; +19: +20: +21: local quad DataAreaSector ; +22: local quad DataAreaFilePos ; +23: +24: local quad CurrentPosSector ; +25: +26: local unsigned char SizeOfEach_ClusterEntry_InBytes ; +27: +28: +29: +30: +31: +32: typedef enum < uchar > tagSYSTEMID +33: { +34: EMPTY = 0 , +35: FAT_12 = 1 , +36: XENIX_ROOT = 2 , +37: XENIX_USR = 3 , +38: FAT_16_INF32MB = 4 , +39: EXTENDED = 5 , +40: FAT_16 = 6 , +41: NTFS_HPFS = 7 , +42: AIX = 8 , +43: AIX_BOOT = 9 , +44: OS2_BOOT_MGR = 10 , +45: PRI_FAT32_INT13 = 11 , +46: EXT_FAT32_INT13 = 12 , +47: EXT_FAT16_INT13 = 14 , +48: WIN95_EXT = 15 , +49: OPUS = 16 , +50: FAT_12_HIDDEN = 17 , +51: COMPAQ_DIAG = 18 , +52: FAT_16_HIDDEN_INF32MB = 20 , +53: FAT_16_HIDDEN = 22 , +54: NTFS_HPFS_HIDDEN = 23 , +55: VENIX = 64 , +56: NOVEL0 = 81 , +57: MICROPORT = 82 , +58: GNU_HURD = 99 , +59: NOVEL1 = 100 , +60: PC_IX = 117 , +61: MINUX_OLD = 128 , +62: MINUX_LINUX = 129 , +63: LINUX_SWAP = 130 , +64: LINUX_NATIVE = 131 , +65: AMOEBA = 147 , +66: AMOEBA_BBT = 148 , +67: BSD_386 = 165 , +68: BSDI_FS = 183 , +69: BSDI_SWAP = 184 , +70: SYRINX = 199 , +71: CP_M = 219 , +72: ACCESS_DOS = 225 , +73: DOS_R_O = 227 , +74: DOS_SECONDARY = 242 , +75: BBT = 255 +76: } SYSTEMID ; +77: +78: +79: typedef enum < uchar > tagBOOTINDICATOR +80: { +81: NOBOOT = 0 , +82: SYSTEM_PARTITION = 128 , +83: } BOOTINDICATOR ; +84: +85: +86: typedef struct PART_ENTRY +87: { +88: BOOTINDICATOR BootIndicator ; +89: UBYTE StartingHead ; +90: WORD StartingSectCylinder ; +91: SYSTEMID SystemID ; +92: UBYTE EndingHead ; +93: WORD EndingSectCylinder ; +94: DWORD RelativeSector ; +95: DWORD TotalSectors ; +96: } PART_ENTRY ; +97: +98: +99: struct MASTER_BOOT_RECORD +100: { +101: UBYTE BootCode [ 446 ] ; +102: PART_ENTRY partitions [ 4 ] ; +103: WORD EndOfSectorMarker < format = hex > ; +104: } ; +105: +106: +107: +108: +109: struct BOOTSECTOR_FAT16 +110: { +111: UBYTE jmp [ 3 ] ; +112: CHAR OemName [ 8 ] ; +113: +114: typedef struct BPB_FAT16 +115: { +116: USHORT BytesPerSector ; +117: UBYTE SectorsPerCluster ; +118: USHORT ReservedSectors ; +119: UBYTE NumberOfCopiesOfFats ; +120: USHORT MaxRootDirEntries ; +121: USHORT NumberOfSectors ; +122: UBYTE MediaDescriptor ; +123: USHORT SectorsPerFAT ; +124: USHORT SectorsPerTrack ; +125: USHORT NumHeadsPerCylinder ; +126: ULONG NumHiddenSectors ; +127: ULONG NumSectorInPartition ; +128: } ; +129: BPB_FAT16 bpb_fat16 ; +130: USHORT LogicDriveNumber ; +131: UBYTE extBootSignature < format = hex > ; +132: ULONG SerialNumber ; +133: CHAR VolumeLabel [ 11 ] ; +134: CHAR FileSystem [ 8 ] ; +135: UBYTE ExecutableCode [ 448 ] ; +136: WORD EndOfSectorMarker < format = hex > ; +137: } ; +138: +139: +140: +141: +142: typedef enum < ushort > tagMEDIATYPE +143: { +144: HARD_DISK = 0xFFF8 , +145: FLOPPY_DISK = 0xFFF0 +146: } MEDIATYPE ; +147: +148: typedef enum < ushort > tagPARTITIONSTATE +149: { +150: PARTITION_NOT_IN_USE = 0xFFFF , +151: PARTITION_IN_USE = 0xFFF7 +152: } PARTITIONSTATE ; +153: +154: typedef enum < ushort > tagCLUSTERINFO +155: { +156: FREE_CLUSTER = 0x0 , +157: RESERVED_0001 = 0x1 , +158: RESERVED_FFF0 = 0xFFF0 , +159: RESERVED_FFF1 = 0xFFF1 , +160: RESERVED_FFF2 = 0xFFF2 , +161: RESERVED_FFF3 = 0xFFF3 , +162: RESERVED_FFF4 = 0xFFF4 , +163: RESERVED_FFF5 = 0xFFF5 , +164: RESERVED_FFF6 = 0xFFF6 , +165: BAD_CLUSTER = 0xFFF7 , +166: USED_LAST_CLUSTER_FFF8 = 0xFFF8 , +167: USED_LAST_CLUSTER_FFF9 = 0xFFF9 , +168: USED_LAST_CLUSTER_FFFA = 0xFFFA , +169: USED_LAST_CLUSTER_FFFB = 0xFFFB , +170: USED_LAST_CLUSTER_FFFC = 0xFFFC , +171: USED_LAST_CLUSTER_FFFD = 0xFFFD , +172: USED_LAST_CLUSTER_FFFE = 0xFFFE , +173: USED_LAST_CLUSTER_FFFF = 0xFFFF +174: } CLUSTERINFO ; +175: +176: void FAT16_FAT_Table ( quad FilePosStartFatTable , quad SizeOfFatTableInSectors , UBYTE NumberOfCopiesOfFats ) +177: { +178: SizeOfEach_ClusterEntry_InBytes = 2 ; +179: +180: FSeek ( FilePosStartFatTable ) ; +181: +182: if ( NumberOfCopiesOfFats == 1 ) +183: { +184: MEDIATYPE FAT16_MediaType ; +185: PARTITIONSTATE FAT16_PartitionState ; +186: CLUSTERINFO FAT16_Cluster [ ( ( ( SizeOfFatTableInSectors * 512 ) / SizeOfEach_ClusterEntry_InBytes ) - SizeOfEach_ClusterEntry_InBytes ) ] ; +187: } else if ( NumberOfCopiesOfFats == 2 ) +188: { +189: +190: MEDIATYPE FAT16_MediaType_FAT1 ; +191: PARTITIONSTATE FAT16_PartitionState_FAT1 ; +192: CLUSTERINFO FAT16_Cluster_FAT1 [ ( ( ( ( SizeOfFatTableInSectors * 512 ) / SizeOfEach_ClusterEntry_InBytes ) - SizeOfEach_ClusterEntry_InBytes ) / NumberOfCopiesOfFats ) - 1 ] ; +193: +194: MEDIATYPE FAT16_MediaType_FAT2 ; +195: PARTITIONSTATE FAT16_PartitionState_FAT2 ; +196: CLUSTERINFO FAT16_Cluster_FAT2 [ ( ( ( ( SizeOfFatTableInSectors * 512 ) / SizeOfEach_ClusterEntry_InBytes ) - SizeOfEach_ClusterEntry_InBytes ) / NumberOfCopiesOfFats ) - 1 ] ; +197: } +198: } +199: +200: +201: +202: +203: +204: typedef enum < uchar > tagAttribute +205: { +206: NoneOrFile = 0 , +207: ReadOnly = 1 , +208: Hidden = 2 , +209: ReadOnlyHidden = 3 , +210: System = 4 , +211: ReadOnlySystem = 5 , +212: HiddenSystem0 = 6 , +213: ReadOnlyHiddenSystem = 7 , +214: VolumeID = 8 , +215: ReadOnlyVolume = 9 , +216: HiddenSystem1 = 10 , +217: ReadOnlySystemVolume0 = 11 , +218: SystemVolume = 12 , +219: ReadOnlySystemVolume1 = 13 , +220: HiddenSystemVolume = 14 , +221: LFN_Entry = 15 , +222: Directory = 16 , +223: Archive = 32 , +224: ArchiveReadOnly = 33 , +225: ArchiveHidden = 34 +226: } ATTR ; +227: +228: typedef struct tagTime +229: { +230: USHORT Sec : 5 ; +231: USHORT Min : 6 ; +232: USHORT Hour : 5 ; +233: } tTIME ; +234: +235: typedef struct tagDate +236: { +237: USHORT Day : 5 ; +238: USHORT Month : 4 ; +239: USHORT YearSince1980 : 7 ; +240: } tDATE ; +241: +242: typedef struct ShortEntry +243: { +244: CHAR Name [ 8 ] ; +245: CHAR Extension [ 3 ] ; +246: ATTR Attribute ; +247: UBYTE Reserved ; +248: UBYTE CreateTime10ms ; +249: tTIME CreateTime ; +250: tDATE CreateDate ; +251: tDATE AccessDate ; +252: USHORT HCluster ; +253: tTIME UpdateTime ; +254: tDATE UpdateDate ; +255: USHORT Cluster ; +256: ULONG FileSizeInBytes ; +257: } SHORTENTRY < read = Read_SHORT_DIR_ENTRY > ; +258: +259: unsigned char FAT16_Attribute ( ATTR Attribute , string & stmp ) +260: { +261: unsigned char volume = 0 ; +262: +263: switch ( Attribute ) +264: { +265: case NoneOrFile : +266: stmp = "NoneOrFile" ; +267: break ; +268: +269: case ReadOnly : +270: stmp = "ReadOnly" ; +271: break ; +272: +273: case Hidden : +274: stmp = "Hidden" ; +275: break ; +276: +277: case ReadOnlyHidden : +278: stmp = "ReadOnlyHidden" ; +279: break ; +280: +281: case System : +282: stmp = "System" ; +283: volume = 1 ; +284: break ; +285: +286: case ReadOnlySystem : +287: stmp = "ReadOnlySystem" ; +288: volume = 1 ; +289: break ; +290: +291: case HiddenSystem0 : +292: stmp = "HiddenSystem0" ; +293: volume = 1 ; +294: break ; +295: +296: case ReadOnlyHiddenSystem : +297: stmp = "ReadOnlyHiddenSystem" ; +298: volume = 1 ; +299: break ; +300: +301: case VolumeID : +302: stmp = "VolumeID" ; +303: volume = 1 ; +304: break ; +305: +306: case ReadOnlyVolume : +307: stmp = "ReadOnlyVolume" ; +308: volume = 1 ; +309: break ; +310: +311: case HiddenSystem1 : +312: stmp = "HiddenSystem1" ; +313: break ; +314: +315: case ReadOnlySystemVolume0 : +316: stmp = "ReadOnlySystemVolume0" ; +317: break ; +318: +319: case SystemVolume : +320: stmp = "SystemVolume" ; +321: volume = 1 ; +322: break ; +323: +324: case ReadOnlySystemVolume1 : +325: stmp = "ReadOnlySystemVolume1" ; +326: volume = 1 ; +327: break ; +328: +329: case HiddenSystemVolume : +330: stmp = "HiddenSystemVolume" ; +331: volume = 1 ; +332: break ; +333: +334: case LFN_Entry : +335: stmp = "LFN_Entry" ; +336: break ; +337: +338: case Directory : +339: stmp = "Directory" ; +340: volume = 1 ; +341: break ; +342: +343: case Archive : +344: stmp = "Archive" ; +345: break ; +346: +347: case ArchiveReadOnly : +348: stmp = "ArchiveReadOnly" ; +349: break ; +350: +351: case ArchiveHidden : +352: stmp = "ArchiveHidden" ; +353: break ; +354: +355: default : +356: stmp = "Unknown" ; +357: volume = 1 ; +358: break ; +359: } +360: return volume ; +361: } +362: +363: string Read_SHORT_DIR_ENTRY ( SHORTENTRY & f ) +364: { +365: string s ; +366: string stmp ; +367: unsigned char volume = 0 ; +368: +369: s = "" ; +370: if ( f . Name [ 0 ] == 0 ) +371: { +372: return "Last Dir Entry Empty" ; +373: } +374: +375: +376: volume = FAT16_Attribute ( f . Attribute , stmp ) ; +377: s += stmp ; +378: +379: if ( volume ) +380: { +381: SPrintf ( stmp , "=%08s%03s" , f . Name , f . Extension ) ; +382: s += stmp ; +383: } else +384: { +385: SPrintf ( stmp , "=%08s.%03s" , f . Name , f . Extension ) ; +386: s += stmp ; +387: } +388: return s ; +389: } +390: +391: typedef struct tagLFN_RecordSeqNum +392: { +393: UBYTE LFN_RecSeqNum : 6 ; +394: UBYTE Last_LFN_record : 1 ; +395: UBYTE LFN_Erased : 1 ; +396: } tLFN_RecordSeqNum ; +397: +398: local string sconv ; +399: local unsigned short iconv ; +400: string Conv_UnicodeToASCII ( char data [ ] , unsigned short totalsize_inbyte ) +401: { +402: sconv = "" ; +403: for ( iconv = 0 ; iconv < totalsize_inbyte ; iconv += 2 ) +404: { +405: if ( data [ iconv ] != - 1 ) +406: { +407: sconv += data [ iconv ] ; +408: } +409: } +410: return sconv ; +411: } +412: +413: local string s_longentry ; +414: +415: typedef struct LongEntry +416: { +417: +418: +419: +420: typedef struct internalLongEntry +421: { +422: typedef union ulfn +423: { +424: tLFN_RecordSeqNum LFN_RecordSeqNum ; +425: unsigned char char0 ; +426: } ULFN ; +427: ULFN LFN ; +428: char UnicodeChar1 [ 10 ] ; +429: ATTR Attribute ; +430: UBYTE Reserved ; +431: UBYTE ChkShortName ; +432: char UnicodeChar2 [ 12 ] ; +433: USHORT Cluster ; +434: char UnicodeChar3 [ 4 ] ; +435: } ILONGENTRY ; +436: +437: local unsigned char NumberOfLFNEntry ; +438: local unsigned char dirname0 ; +439: dirname0 = ReadByte ( FTell ( ) ) ; +440: if ( ! ( dirname0 == 0x0 ) ) +441: { +442: if ( dirname0 == 0xE5 ) +443: { +444: for ( i = 0 ; i < 63 ; i ++ ) +445: { +446: dirname0 = ReadByte ( FTell ( ) ) ; +447: if ( ! ( dirname0 == 0xE5 ) ) +448: break ; +449: +450: if ( ReadByte ( FTell ( ) + 11 ) != 0xF ) +451: break ; +452: +453: ILONGENTRY long_entry ; +454: } +455: } else +456: { +457: ILONGENTRY long_entry ; +458: NumberOfLFNEntry = long_entry . LFN . LFN_RecordSeqNum . LFN_RecSeqNum - 1 ; +459: for ( i = 0 ; i < NumberOfLFNEntry ; i ++ ) +460: { +461: ILONGENTRY long_entry ; +462: } +463: } +464: } +465: } LONGENTRY < read = Read_LONG_DIR_ENTRY > ; +466: +467: string Read_LONG_DIR_ENTRY ( LONGENTRY & f ) +468: { +469: local unsigned short i ; +470: local unsigned short NumberOfLFNEntry ; +471: local string str ; +472: +473: str = "" ; +474: +475: if ( f . long_entry [ 0 ] . LFN . LFN_RecordSeqNum . LFN_Erased == 1 ) +476: { +477: +478: str += "Erased name:" ; +479: +480: for ( i = 0 ; i < 63 ; i ++ ) +481: { +482: if ( exists ( f . long_entry [ i ] . LFN . char0 ) ) +483: { +484: if ( f . long_entry [ i ] . LFN . char0 != 0xE5 ) +485: { +486: break ; +487: } +488: } else +489: { +490: break ; +491: } +492: } +493: NumberOfLFNEntry = i - 1 ; +494: } else +495: { +496: +497: str += "Name:" ; +498: NumberOfLFNEntry = f . long_entry [ 0 ] . LFN . LFN_RecordSeqNum . LFN_RecSeqNum - 1 ; +499: } +500: for ( i = NumberOfLFNEntry ; i > 0 ; i -- ) +501: { +502: str += Conv_UnicodeToASCII ( f . long_entry [ i ] . UnicodeChar1 , 10 ) ; +503: str += Conv_UnicodeToASCII ( f . long_entry [ i ] . UnicodeChar2 , 12 ) ; +504: str += Conv_UnicodeToASCII ( f . long_entry [ i ] . UnicodeChar3 , 4 ) ; +505: } +506: str += Conv_UnicodeToASCII ( f . long_entry [ 0 ] . UnicodeChar1 , 10 ) ; +507: str += Conv_UnicodeToASCII ( f . long_entry [ 0 ] . UnicodeChar2 , 12 ) ; +508: str += Conv_UnicodeToASCII ( f . long_entry [ 0 ] . UnicodeChar3 , 4 ) ; +509: return str ; +510: } +511: +512: +513: +514: +515: +516: +517: +518: +519: +520: +521: +522: +523: +524: +525: +526: +527: void FAT16_Directory_Entry ( quad FilePosStartDirectoryEntry ) +528: { +529: FSeek ( FilePosStartDirectoryEntry ) ; +530: i = 0 ; +531: while ( 1 ) +532: { +533: if ( ReadByte ( FTell ( ) + 11 ) == 0xF ) +534: { +535: LONGENTRY fat16_long_direntry ; +536: } else +537: { +538: SHORTENTRY fat16_short_direntry ; +539: if ( fat16_short_direntry . Name [ 0 ] == 0 && fat16_short_direntry . Name [ 1 ] == 0 ) +540: { +541: break ; +542: } +543: } +544: } +545: } +546: +547: +548: +549: +550: struct BOOTSECTOR_FAT32 +551: { +552: BYTE jmp [ 3 ] ; +553: CHAR OemName [ 8 ] ; +554: +555: typedef struct BPB_FAT32 +556: { +557: WORD BytesPerSector ; +558: BYTE SectorsPerCluster ; +559: WORD ReservedSectors ; +560: BYTE NumberOfFATs ; +561: WORD RootEntries ; +562: WORD TotalSectors ; +563: BYTE Media ; +564: WORD SectorsPerFAT ; +565: WORD SectorsPerTrack ; +566: WORD HeadsPerCylinder ; +567: DWORD HiddenSectors ; +568: DWORD TotalSectorsBig ; +569: DWORD SectorsPerFAT ; +570: WORD Flags ; +571: WORD Version ; +572: DWORD RootCluster ; +573: WORD InfoSector ; +574: WORD BootBackupStart ; +575: BYTE Reserved [ 12 ] ; +576: } ; +577: +578: BPB_FAT32 bpb_fat32 ; +579: +580: BYTE DriveNumber ; +581: BYTE Unused ; +582: BYTE ExtBootSignature < format = hex > ; +583: DWORD SerialNumber ; +584: CHAR VolumeLabel [ 11 ] ; +585: CHAR FileSystem [ 8 ] ; +586: CHAR BootCode [ 420 ] ; +587: WORD EndOfSectorMarker < format = hex > ; +588: } ; +589: +590: +591: +592: +593: +594: +595: +596: +597: +598: typedef enum < ulong > tagMEDIATYPE_FAT32 +599: { +600: HARD_DISK_FAT32 = 0xFFFFFF8 , +601: FLOPPY_DISK_FAT32 = 0xFFFFFF0 +602: } MEDIATYPE_FAT32 ; +603: +604: typedef enum < ulong > tagPARTITIONSTATE_FAT32 +605: { +606: PARTITION_NOT_IN_USE_FAT32 = 0xFFFFFFFF , +607: PARTITION_IN_USE_FAT32 = 0xFFFFFFF7 +608: } PARTITIONSTATE_FAT32 ; +609: +610: typedef enum < ulong > tagCLUSTERINFO_FAT32 +611: { +612: FREE_CLUSTER_FAT32 = 0x0 , +613: RESERVED_0001_FAT32 = 0x1 , +614: RESERVED_FFF0_FAT32 = 0xFFFFFF0 , +615: RESERVED_FFF1_FAT32 = 0xFFFFFF1 , +616: RESERVED_FFF2_FAT32 = 0xFFFFFF2 , +617: RESERVED_FFF3_FAT32 = 0xFFFFFF3 , +618: RESERVED_FFF4_FAT32 = 0xFFFFFF4 , +619: RESERVED_FFF5_FAT32 = 0xFFFFFF5 , +620: RESERVED_FFF6_FAT32 = 0xFFFFFF6 , +621: BAD_CLUSTER_FAT32 = 0xFFFFFF7 , +622: USED_LAST_CLUSTER_FFF8_FAT32 = 0xFFFFFF8 , +623: USED_LAST_CLUSTER_FFF9_FAT32 = 0xFFFFFF9 , +624: USED_LAST_CLUSTER_FFFA_FAT32 = 0xFFFFFFA , +625: USED_LAST_CLUSTER_FFFB_FAT32 = 0xFFFFFFB , +626: USED_LAST_CLUSTER_FFFC_FAT32 = 0xFFFFFFC , +627: USED_LAST_CLUSTER_FFFD_FAT32 = 0xFFFFFFD , +628: USED_LAST_CLUSTER_FFFE_FAT32 = 0xFFFFFFE , +629: USED_LAST_CLUSTER_FFFF_FAT32 = 0xFFFFFFF +630: } CLUSTERINFO_FAT32 ; +631: +632: void FAT32_FAT_Table ( quad FilePosStartFatTable , quad SizeOfFatTableInSectors , UBYTE NumberOfCopiesOfFats ) +633: { +634: local unsigned char SizeOfEach_ClusterEntry_InBytes ; +635: SizeOfEach_ClusterEntry_InBytes = 4 ; +636: +637: FSeek ( FilePosStartFatTable ) ; +638: +639: if ( NumberOfCopiesOfFats == 1 ) +640: { +641: MEDIATYPE_FAT32 FAT32_MediaType ; +642: PARTITIONSTATE_FAT32 FAT32_PartitionState ; +643: CLUSTERINFO_FAT32 FAT32_Cluster [ ( ( ( SizeOfFatTableInSectors * 512 ) / SizeOfEach_ClusterEntry_InBytes ) - SizeOfEach_ClusterEntry_InBytes ) ] ; +644: +645: } else if ( NumberOfCopiesOfFats == 2 ) +646: { +647: MEDIATYPE_FAT32 FAT32_MediaType_FAT1 ; +648: PARTITIONSTATE_FAT32 FAT32_PartitionState_FAT1 ; +649: CLUSTERINFO_FAT32 FAT32_Cluster_FAT1 [ ( ( ( ( SizeOfFatTableInSectors * 512 ) / SizeOfEach_ClusterEntry_InBytes ) - SizeOfEach_ClusterEntry_InBytes ) / NumberOfCopiesOfFats ) - 0 ] ; +650: +651: MEDIATYPE_FAT32 FAT32_MediaType_FAT2 ; +652: PARTITIONSTATE_FAT32 FAT32_PartitionState_FAT2 ; +653: CLUSTERINFO_FAT32 FAT32_Cluster_FAT2 [ ( ( ( ( SizeOfFatTableInSectors * 512 ) / SizeOfEach_ClusterEntry_InBytes ) - SizeOfEach_ClusterEntry_InBytes ) / NumberOfCopiesOfFats ) - 0 ] ; +654: } +655: } +656: +657: void FAT32_Directory_Entry ( quad FilePosStartDirectoryEntry ) +658: { +659: FSeek ( FilePosStartDirectoryEntry ) ; +660: i = 0 ; +661: while ( 1 ) +662: { +663: if ( ReadByte ( FTell ( ) + 11 ) == 0xF ) +664: { +665: LONGENTRY fat32_long_direntry ; +666: } else +667: { +668: SHORTENTRY fat32_short_direntry ; +669: if ( fat32_short_direntry . Name [ 0 ] == 0 && fat32_short_direntry . Name [ 1 ] == 0 ) +670: { +671: break ; +672: } +673: } +674: } +675: } +676: +677: +678: +679: +680: +681: struct BOOTSECTOR_NTFS +682: { +683: BYTE jmp [ 3 ] ; +684: CHAR OEMName [ 8 ] ; +685: +686: typedef struct BPB_NTFS +687: { +688: WORD BytesPerSector ; +689: BYTE SectorsPerCluster ; +690: WORD ReservedSectors ; +691: BYTE Zero [ 3 ] ; +692: WORD NotUsed ; +693: BYTE MediaDescriptor ; +694: WORD Zero ; +695: WORD SectorsPerTrack ; +696: WORD HeadsPerCylinder ; +697: DWORD HiddenSectors ; +698: DWORD NotUsed ; +699: DWORD NotUsed ; +700: UQUAD TotalSectors ; +701: UQUAD LogicalClusterMFT ; +702: UQUAD LogicalClusterMFTMiror ; +703: DWORD ClustersPerFileRecSegment ; +704: DWORD ClustersPerIndexBlock ; +705: UQUAD SerialNumber ; +706: DWORD Checksum ; +707: } ; +708: +709: BPB_NTFS bpb_ntfs ; +710: BYTE BootCode [ 426 ] ; +711: WORD EndOfSectorMarker < format = hex > ; +712: } ; +713: +714: typedef union boot +715: { +716: struct MASTER_BOOT_RECORD mbr ; +717: struct BOOTSECTOR_FAT16 boot_fat16 ; +718: struct BOOTSECTOR_FAT32 boot_fat32 ; +719: struct BOOTSECTOR_NTFS boot_ntfs ; +720: } ; +721: +722: +723: void FAT16CheckInit ( SYSTEMID SystemID ) +724: { +725: if ( SystemID == FAT_16_INF32MB || +726: SystemID == FAT_16 || +727: SystemID == EXT_FAT16_INT13 +728: ) +729: { +730: CurrentPosSector = FTell ( ) / 512 ; +731: +732: BOOTSECTOR_FAT16 detected_fat16 ; +733: +734: FATTableSector = CurrentPosSector + detected_fat16 . bpb_fat16 . ReservedSectors ; +735: +736: RootDirEntrySector = CurrentPosSector + detected_fat16 . bpb_fat16 . ReservedSectors + +737: ( detected_fat16 . bpb_fat16 . SectorsPerFAT * 2 ) ; +738: RootDirEntryFilePos = RootDirEntrySector * 512 ; +739: +740: FATTableFilePos = FATTableSector * 512 ; +741: FATTableSizeInSectors = RootDirEntrySector - FATTableSector ; +742: +743: +744: FAT16_FAT_Table ( FATTableFilePos , FATTableSizeInSectors , detected_fat16 . bpb_fat16 . NumberOfCopiesOfFats ) ; +745: +746: +747: FAT16_Directory_Entry ( RootDirEntryFilePos ) ; +748: +749: DataAreaSector = CurrentPosSector + detected_fat16 . bpb_fat16 . ReservedSectors + +750: ( detected_fat16 . bpb_fat16 . SectorsPerFAT * 2 ) + +751: ( ( detected_fat16 . bpb_fat16 . MaxRootDirEntries * 32 ) / detected_fat16 . bpb_fat16 . BytesPerSector ) ; +752: DataAreaFilePos = DataAreaSector * 512 ; +753: +754: +755: } +756: } +757: +758: void FAT32CheckInit ( SYSTEMID SystemID ) +759: { +760: if ( SystemID == PRI_FAT32_INT13 || +761: SystemID == EXT_FAT32_INT13 +762: ) +763: { +764: CurrentPosSector = FTell ( ) / 512 ; +765: +766: struct BOOTSECTOR_FAT32 detected_fat32 ; +767: +768: FATTableSector = CurrentPosSector + detected_fat32 . bpb_fat32 . ReservedSectors ; +769: +770: RootDirEntrySector = CurrentPosSector + detected_fat32 . bpb_fat32 . ReservedSectors + +771: ( detected_fat32 . bpb_fat32 . SectorsPerFAT * 2 ) ; +772: RootDirEntryFilePos = RootDirEntrySector * 512 ; +773: +774: FATTableFilePos = FATTableSector * 512 ; +775: FATTableSizeInSectors = RootDirEntrySector - FATTableSector ; +776: +777: +778: FAT32_FAT_Table ( FATTableFilePos , FATTableSizeInSectors , detected_fat32 . bpb_fat32 . NumberOfFATs ) ; +779: +780: +781: FAT32_Directory_Entry ( RootDirEntryFilePos ) ; +782: } +783: } +784: +785: +786: +787: +788: typedef struct _FATStruct +789: { +790: local unsigned short mbr_boot_ok = 0 ; +791: local quad FATTableSector ; +792: local quad FATTableFilePos ; +793: local quad FATTableSizeInSectors ; +794: +795: local quad RootDirEntrySector ; +796: local quad RootDirEntryFilePos ; +797: +798: +799: if ( ReadUShort ( 510 ) == 0xAA55 ) +800: { +801: boot boot_sect ; +802: local unsigned short i ; +803: +804: for ( i = 0 ; i < 4 ; i ++ ) +805: { +806: if ( ( boot_sect . mbr . partitions [ i ] . BootIndicator == SYSTEM_PARTITION || +807: boot_sect . mbr . partitions [ i ] . BootIndicator == NOBOOT ) && +808: boot_sect . mbr . partitions [ i ] . SystemID != EMPTY +809: ) +810: { +811: if ( mbr_boot_ok == 0 ) +812: { +813: FSeek ( 0 ) ; +814: MASTER_BOOT_RECORD detected_mbr ; +815: mbr_boot_ok = 1 ; +816: } +817: +818: FSeek ( boot_sect . mbr . partitions [ i ] . RelativeSector * 512 ) ; +819: +820: FAT16CheckInit ( boot_sect . mbr . partitions [ i ] . SystemID ) ; +821: FAT32CheckInit ( boot_sect . mbr . partitions [ i ] . SystemID ) ; +822: } +823: } +824: +825: if ( boot_sect . boot_fat16 . FileSystem == "FAT16 " ) +826: { +827: FSeek ( 0 ) ; +828: BOOTSECTOR_FAT16 detected_fat16 ; +829: +830: FATTableSector = 0 + detected_fat16 . bpb_fat16 . ReservedSectors ; +831: +832: RootDirEntrySector = 0 + detected_fat16 . bpb_fat16 . ReservedSectors + +833: ( detected_fat16 . bpb_fat16 . SectorsPerFAT * 2 ) ; +834: RootDirEntryFilePos = RootDirEntrySector * 512 ; +835: +836: FATTableFilePos = FATTableSector * 512 ; +837: FATTableSizeInSectors = RootDirEntrySector - FATTableSector ; +838: +839: +840: FAT16_FAT_Table ( FATTableFilePos , FATTableSizeInSectors , detected_fat16 . bpb_fat16 . NumberOfCopiesOfFats ) ; +841: +842: +843: FAT16_Directory_Entry ( RootDirEntryFilePos ) ; +844: +845: DataAreaSector = 0 + detected_fat16 . bpb_fat16 . ReservedSectors + +846: ( detected_fat16 . bpb_fat16 . SectorsPerFAT * 2 ) + +847: ( ( detected_fat16 . bpb_fat16 . MaxRootDirEntries * 32 ) / detected_fat16 . bpb_fat16 . BytesPerSector ) ; +848: DataAreaFilePos = DataAreaSector * 512 ; +849: +850: +851: } +852: +853: if ( boot_sect . boot_fat32 . FileSystem == "FAT32 " ) +854: { +855: FSeek ( 0 ) ; +856: struct BOOTSECTOR_FAT32 detected_fat32 ; +857: +858: FATTableSector = 0 + detected_fat32 . bpb_fat32 . ReservedSectors ; +859: +860: RootDirEntrySector = 0 + detected_fat32 . bpb_fat32 . ReservedSectors + +861: ( detected_fat32 . bpb_fat32 . SectorsPerFAT * 2 ) ; +862: RootDirEntryFilePos = RootDirEntrySector * 512 ; +863: +864: FATTableFilePos = FATTableSector * 512 ; +865: FATTableSizeInSectors = RootDirEntrySector - FATTableSector ; +866: +867: +868: FAT32_FAT_Table ( FATTableFilePos , FATTableSizeInSectors , detected_fat32 . bpb_fat32 . NumberOfFATs ) ; +869: +870: +871: FAT32_Directory_Entry ( RootDirEntryFilePos ) ; +872: +873: } +874: +875: +876: +877: } else +878: { +879: +880: +881: +882: +883: } +884: } MBR_FAT ; +885: +886: MBR_FAT mbr_fat ; +887: +888: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/MFTRecord.bt b/cparser/tests/exp_lex/MFTRecord.bt new file mode 100644 index 0000000..5a44667 --- /dev/null +++ b/cparser/tests/exp_lex/MFTRecord.bt @@ -0,0 +1,310 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: string getMFTNameFromRecurdNumber ( UINT32 record_number ) { +11: +12: switch ( record_number ) { +13: case 0 : +14: return "$MFT" ; +15: case 1 : +16: return "$MFTMirr" ; +17: case 2 : +18: return "$LogFile" ; +19: case 3 : +20: return "$Volume" ; +21: case 4 : +22: return "$AttrDef" ; +23: case 5 : +24: return "$. (root dir)" ; +25: case 6 : +26: return "$Bitmap" ; +27: case 7 : +28: return "$Boot" ; +29: case 8 : +30: return "$BadClus" ; +31: case 9 : +32: return "$Secure" ; +33: case 10 : +34: return "$UpCase" ; +35: case 11 : +36: return "$Extend" ; +37: default : +38: return "" ; +39: } +40: } +41: +42: string GetMFTRecordComment ( struct MFTRecord & record ) { +43: string ret ; +44: +45: SPrintf ( ret , "Record # %u %s (%s)" , +46: record . mftheader . mft_rec_number , +47: getMFTNameFromRecurdNumber ( record . mftheader . mft_rec_number ) , +48: HeaderFlagsToString ( record . mftheader . flags ) +49: ) ; +50: return ret ; +51: } +52: +53: +54: wstring GetMFTNameFromAttribute ( struct Attributes & attrs ) { +55: +56: switch ( attrs . attribute . fixed_header . type ) { +57: case STANDARD_INFORMATION : +58: return "$STANDARD_INFORMATION" ; +59: case ATTRIBUTE_LIST : +60: return "$ATTRIBUTE_LIST" ; +61: case FILE_NAME : +62: string ret ; +63: SPrintf ( ret , "$FILE_NAME (%s)" , +64: attrs . attribute . resident_attribute_content . file_name ) ; +65: return ret ; +66: case OBJECT_ID : +67: return "$OBJECT_ID" ; +68: case SECURITY_DESCRIPTOR : +69: return "$SECURITY_DESCRIPTOR" ; +70: case VOLUME_NAME : +71: return "$VOLUME_NAME" ; +72: case VOLUME_INFORMATION : +73: return "$VOLUME_INFORMATION" ; +74: case DATA : +75: string ret ; +76: if ( attrs . attribute . fixed_header . non_res_flag ) +77: return "$DATA (Non resident)" ; +78: else +79: return "$DATA (Resident)" ; +80: case INDEX_ROOT : +81: return "$INDEX_ROOT" ; +82: case INDEX_ALLOCATION : +83: return "$INDEX_ALLOCATION" ; +84: case BITMAP : +85: string ret ; +86: SPrintf ( ret , +87: "$BITMAP (map of bits telling for each record if they are in use or not)" ) ; +88: return ret ; +89: case REPARSE_POINT : +90: return "$REPARSE_POINT" ; +91: case EA_INFORMATION : +92: return "$EA_INFORMATION" ; +93: case EA : +94: return "$EA" ; +95: case LOGGED_UTILITY_STREAM : +96: return "$LOGGED_UTILITY_STREAM" ; +97: default : +98: return "" ; +99: } +100: } +101: +102: +103: string HeaderFlagsToString ( UINT16 flags ) { +104: string ret ; +105: +106: if ( flags & 0x2 ) +107: Strcat ( ret , "Directory, " ) ; +108: else +109: Strcat ( ret , "File, " ) ; +110: if ( flags & 0x1 ) +111: Strcat ( ret , "In use" ) ; +112: else +113: Strcat ( ret , "Not in use" ) ; +114: return ret ; +115: } +116: +117: +118: string AttributeFlagsToString ( UINT16 flags ) { +119: string ret ; +120: +121: if ( flags & 0x1 ) +122: Strcat ( ret , "Compressed, " ) ; +123: else +124: Strcat ( ret , "Not Compressed, " ) ; +125: if ( flags & 0x4000 ) +126: Strcat ( ret , "Encrypted, " ) ; +127: else +128: Strcat ( ret , "Not Encrypted, " ) ; +129: if ( flags & 0x8000 ) +130: Strcat ( ret , "Sparse" ) ; +131: else +132: Strcat ( ret , "Not Sparse" ) ; +133: return ret ; +134: } +135: +136: +137: string GetParentDirComment ( uint64 ref_to_parent_dir ) { +138: string ret , +139: details ; +140: +141: +142: +143: UINT16 seq_num = ref_to_parent_dir >> 24 ; +144: UQUAD mft_entry = ref_to_parent_dir & 0xFFFFFFFFFFFF ; +145: if ( mft_entry == 0x5 ) { +146: +147: Strcat ( ret , "Root dir, " ) ; +148: } +149: SPrintf ( details , "Seq num = %04xh [!!] , MFT entry = %012xh" , seq_num , mft_entry ) ; +150: Strcat ( ret , details ) ; +151: return ret ; +152: } +153: +154: +155: string GetAllocSize ( UQUAD alloc_size ) { +156: +157: string ret ; +158: UQUAD num_clusters = alloc_size / 4096 + ( alloc_size % 4096 ? 1 : 0 ) ; +159: SPrintf ( ret , "%lu clusters (each cluster 4096 bytes)" , num_clusters ) ; +160: return ret ; +161: } +162: +163: +164: string GetDataRunStart ( UINT16 data_run_info ) { +165: string ret ; +166: SPrintf ( ret , "Starting at 0x%x (assuming cluster size = 4096)" , data_run_info * 4096 ) ; +167: return ret ; +168: } +169: +170: typedef struct MFTAttribute { +171: local int64 mftattribute_start = FTell ( ) ; +172: struct FixedHeader { +173: enum < UINT32 > { +174: STANDARD_INFORMATION = 0x10 , +175: ATTRIBUTE_LIST = 0x20 , +176: FILE_NAME = 0x30 , +177: OBJECT_ID = 0x40 , +178: SECURITY_DESCRIPTOR = 0x50 , +179: VOLUME_NAME = 0x60 , +180: VOLUME_INFORMATION = 0x70 , +181: DATA = 0x80 , +182: INDEX_ROOT = 0x90 , +183: INDEX_ALLOCATION = 0xA0 , +184: BITMAP = 0xB0 , +185: REPARSE_POINT = 0xC0 , +186: EA_INFORMATION = 0xD0 , +187: EA = 0xE0 , +188: LOGGED_UTILITY_STREAM = 0x100 +189: } type ; +190: UINT32 attr_length ; +191: enum < UBYTE > { +192: RESIDENT = 0 , +193: NON_RESIDENT = 1 +194: } non_res_flag < comment = "Resident: stored in the record. Non-resident: stored in the data runs" > ; +195: UBYTE name_length ; +196: UINT16 name_offset ; +197: UINT16 flags < comment = AttributeFlagsToString > ; +198: UINT16 attribute_id ; +199: } fixed_header ; +200: if ( fixed_header . non_res_flag ) { +201: struct NonResidentAttributeHeader { +202: UQUAD start_vcn ; +203: UQUAD end_vcn ; +204: UINT16 datarun_offset ; +205: UINT16 compression_size < comment = "If 0, not compressed" > ; +206: UINT32 padding ; +207: UQUAD alloc_size < comment = GetAllocSize > ; +208: UQUAD real_size < comment = "File size in bytes" > ; +209: UQUAD stream_size < comment = "Equal to real_size unless resized" > ; +210: } non_resident_attribute_header ; +211: if ( fixed_header . type == DATA ) { +212: struct AttributeContentNonResidentData { +213: UBYTE unknown ; +214: UBYTE num_of_clusters ; +215: UINT16 data_run_start < format = hex , comment = GetDataRunStart > ; +216: char padding [ 3 ] ; +217: } attribute_content_non_resident_data ; +218: } else if ( fixed_header . type == BITMAP ) { +219: struct AttributeContentNonResidentBitmap { +220: char bitmap [ fixed_header . attr_length - non_resident_attribute_header . datarun_offset ] ; +221: } attribute_content_non_resident_bitmap ; +222: } else { +223: +224: } +225: } else { +226: struct ResidentAttributeHeader { +227: UINT32 content_size ; +228: UINT16 content_offset ; +229: UINT16 indexed_tag ; +230: } resident_attribute_header ; +231: struct ResidentAttributeContent { +232: if ( fixed_header . type == STANDARD_INFORMATION ) { +233: struct AttributeContentStandardInformation { +234: FILETIME creation_time ; +235: FILETIME alteration_time ; +236: FILETIME mft_changed_time ; +237: FILETIME read_time ; +238: UINT32 dos_permissions ; +239: UINT32 max_num_of_versions ; +240: UINT32 version_number ; +241: UINT32 class_id ; +242: } attribute_content_standard_information ; +243: if ( resident_attribute_header . content_size != 48 ) { +244: UINT32 owner_id ; +245: UINT32 security_id ; +246: UQUAD quota_charged ; +247: UQUAD update_sequence_number ; +248: } +249: } else if ( fixed_header . type == FILE_NAME ) { +250: struct AttributeContentFileName { +251: UQUAD file_ref_to_parent_dir < format = hex , comment = GetParentDirComment > ; +252: FILETIME file_creation_time ; +253: FILETIME file_modification_time ; +254: FILETIME mft_modification_time ; +255: FILETIME file_access_time ; +256: UQUAD allocated_size ; +257: UQUAD real_size ; +258: UINT32 flags ; +259: UINT32 used_by_eas_and_reparse ; +260: UBYTE filename_length_unicode ; +261: UBYTE filename_namespace ; +262: } attribute_content_file_name ; +263: +264: wchar_t file_name [ attribute_content_file_name . filename_length_unicode ] ; +265: } else { +266: UCHAR data [ resident_attribute_header . content_size ] ; +267: +268: } +269: } resident_attribute_content ; +270: } +271: UCHAR padding [ fixed_header . attr_length - ( FTell ( ) - mftattribute_start ) ] ; +272: } mftattribute ; +273: +274: struct MFTRecord { +275: struct MFTHeader { +276: char file_signature [ 4 ] < comment = "Must be FILE" > ; +277: UINT16 fixup_offset ; +278: UINT16 fixup_size ; +279: UQUAD log_seq_number ; +280: UINT16 sequence ; +281: UINT16 hard_links < comment = "Number of hard links" > ; +282: UINT16 attrib_offset ; +283: UINT16 flags < comment = HeaderFlagsToString > ; +284: UINT32 rec_length < comment = "Length of the bytes used for this record. Must be <= 1024" > ; +285: UINT32 all_length < comment = "Length of the whole record. Must be 1024" > ; +286: UQUAD base_mft_rec ; +287: UINT16 next_attr_id ; +288: UINT16 fixup_pattern ; +289: UINT32 mft_rec_number < comment = getMFTNameFromRecurdNumber > ; +290: } mftheader ; +291: UQUAD fixup ; +292: local int i ; +293: local int64 pos ; +294: local UINT32 terminator ; +295: for ( i = 0 ; i == i ; i ++ ) { +296: pos = FTell ( ) ; +297: terminator = ReadUInt ( ) ; +298: if ( terminator == 0xFFFFFFFF ) { +299: struct Terminator { +300: UINT32 terminator < format = hex , comment = "Must be FF FF FF FF" > ; +301: } terminator < comment = "Attribute list terminator" > ; +302: break ; +303: } else { +304: struct Attributes { +305: mftattribute attribute ; +306: } attributes < comment = GetMFTNameFromAttribute > ; +307: } +308: } +309: } mftrecord < comment = GetMFTRecordComment > ; +310: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/MIDITemplate.bt b/cparser/tests/exp_lex/MIDITemplate.bt new file mode 100644 index 0000000..3007677 --- /dev/null +++ b/cparser/tests/exp_lex/MIDITemplate.bt @@ -0,0 +1,242 @@ +1: +2: +3: +4: +5: BigEndian ( ) ; +6: +7: struct MidiHeader +8: { +9: char m_magic [ 4 ] < format = hex > ; +10: uint m_seclen ; +11: enum < short > +12: { +13: MIDI_SINGLE = 0 , +14: MIDI_MULTIPLE = 1 , +15: MIDI_PATTERN = 2 +16: } m_format ; +17: short m_ntracks ; +18: short m_tickdiv ; +19: } ; +20: +21: struct DeltaTime +22: { +23: local uint total = 0 ; +24: char t0 ; +25: total += t0 & 0x7F ; +26: if ( ! ( t0 & 0x80 ) ) +27: break ; +28: +29: total <<= 7 ; +30: char t1 ; +31: total += t1 & 0x7F ; +32: if ( ! ( t1 & 0x80 ) ) +33: break ; +34: +35: total <<= 7 ; +36: char t2 ; +37: total += t2 & 0x7F ; +38: if ( ! ( t2 & 0x80 ) ) +39: break ; +40: +41: total <<= 7 ; +42: char t3 ; +43: total += t3 & 0x7F ; +44: if ( ! ( t3 & 0x80 ) ) +45: break ; +46: } ; +47: +48: struct MidiMessage +49: { +50: DeltaTime m_dtime ; +51: char m_status ; +52: local char m_channel = m_status & 0xF ; +53: if ( ( m_status & 0xF0 ) == 0x80 ) +54: { +55: struct +56: { +57: char m_note ; +58: char m_velocity ; +59: } note_off_event ; +60: } +61: else if ( ( m_status & 0xF0 ) == 0x90 ) +62: { +63: struct +64: { +65: char m_note ; +66: char m_velocity ; +67: } note_on_event ; +68: } +69: else if ( ( m_status & 0xF0 ) == 0xA0 ) +70: { +71: struct +72: { +73: char m_note ; +74: char m_pressure ; +75: } note_pressure_event ; +76: } +77: else if ( ( m_status & 0xF0 ) == 0xB0 ) +78: { +79: struct +80: { +81: char m_controller ; +82: char m_value ; +83: } controller_event ; +84: } +85: else if ( ( m_status & 0xF0 ) == 0xC0 ) +86: { +87: struct +88: { +89: char m_program ; +90: } program_event ; +91: } +92: else if ( ( m_status & 0xF0 ) == 0xD0 ) +93: { +94: struct +95: { +96: char m_pressure ; +97: } channel_pressure_event ; +98: } +99: else if ( ( m_status & 0xF0 ) == 0xE0 ) +100: { +101: struct +102: { +103: char m_lsb ; +104: char m_msb ; +105: } pitch_bend_event ; +106: } +107: else if ( m_status == - 1 ) +108: { +109: struct +110: { +111: enum < char > +112: { +113: META_SEQUENCE_NUM = 0 , +114: META_TEXT = 1 , +115: META_COPYRIGHT = 2 , +116: META_SEQUENCE_NAME = 3 , +117: META_INSTRUMENT_NAME = 4 , +118: META_LYRIC = 5 , +119: META_MARKER = 6 , +120: META_CUE_POINT = 7 , +121: META_PROGRAM_NAME = 8 , +122: META_DEVICE_NAME = 9 , +123: META_MIDI_CHANNEL_PREFIX = 0x20 , +124: META_MIDI_PORT = 0x21 , +125: META_END_OF_TRACK = 0x2F , +126: META_TEMPO = 0x51 , +127: META_SMPTE_OFFSET = 0x54 , +128: META_TIME_SIGNATURE = 0x58 , +129: META_KEY_SIGNATURE = 0x59 , +130: META_SEQUENCER_EVENT = 0x7F +131: } m_type ; +132: DeltaTime m_length ; +133: if ( m_type == META_SEQUENCE_NUM ) +134: { +135: short m_seqNum ; +136: } +137: else if ( m_type == META_TEXT ) +138: { +139: char m_text [ m_length . total ] ; +140: } +141: else if ( m_type == META_COPYRIGHT ) +142: { +143: char m_copyright [ m_length . total ] ; +144: } +145: else if ( m_type == META_SEQUENCE_NAME ) +146: { +147: char m_name [ m_length . total ] ; +148: } +149: else if ( m_type == META_INSTRUMENT_NAME ) +150: { +151: char m_name [ m_length . total ] ; +152: } +153: else if ( m_type == META_LYRIC ) +154: { +155: char m_lyric [ m_length . total ] ; +156: } +157: else if ( m_type == META_MARKER ) +158: { +159: char m_marker [ m_length . total ] ; +160: } +161: else if ( m_type == META_CUE_POINT ) +162: { +163: char m_cuePoint [ m_length . total ] ; +164: } +165: else if ( m_type == META_PROGRAM_NAME ) +166: { +167: char m_programName [ m_length . total ] ; +168: } +169: else if ( m_type == META_DEVICE_NAME ) +170: { +171: char m_deviceName [ m_length . total ] ; +172: } +173: else if ( m_type == META_MIDI_CHANNEL_PREFIX ) +174: { +175: char m_channelPrefix ; +176: } +177: else if ( m_type == META_MIDI_PORT ) +178: { +179: char m_port ; +180: } +181: else if ( m_type == META_END_OF_TRACK ) +182: { +183: } +184: else if ( m_type == META_TEMPO ) +185: { +186: uint m_usecPerQuarterNote : 24 ; +187: local uint m_bpm = 60000000 / m_usecPerQuarterNote ; +188: FSeek ( FTell ( ) - 1 ) ; +189: } +190: else if ( m_type == META_SMPTE_OFFSET ) +191: { +192: char m_hours ; +193: char m_mins ; +194: char m_secs ; +195: char m_fps ; +196: char m_fracFrames ; +197: } +198: else if ( m_type == META_TIME_SIGNATURE ) +199: { +200: char m_numerator ; +201: char m_denominator ; +202: char m_clocksPerClick ; +203: char m_32ndPer4th ; +204: } +205: else if ( m_type == META_KEY_SIGNATURE ) +206: { +207: char m_flatsSharps ; +208: char m_majorMinor ; +209: } +210: else +211: { +212: char m_data [ m_length . total ] ; +213: } +214: } meta_event ; +215: } +216: else if ( ( m_status & 0xF0 ) == 0xF0 ) +217: { +218: struct +219: { +220: DeltaTime m_length ; +221: char m_message [ m_length . total ] ; +222: } sysex_event ; +223: } +224: } ; +225: +226: struct MidiTrack +227: { +228: char m_magic [ 4 ] < format = hex > ; +229: uint m_seclen ; +230: local uint remaining = m_seclen ; +231: while ( remaining ) { +232: MidiMessage message ; +233: remaining -= sizeof ( message ) ; +234: } +235: } ; +236: +237: struct +238: { +239: MidiHeader header ; +240: MidiTrack tracks [ header . m_ntracks ] < optimize = false > ; +241: } file ; +242: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/MOBITemplate.bt b/cparser/tests/exp_lex/MOBITemplate.bt new file mode 100644 index 0000000..a93bd10 --- /dev/null +++ b/cparser/tests/exp_lex/MOBITemplate.bt @@ -0,0 +1,714 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: typedef struct { +14: DWORD dataOffset ; +15: UBYTE attributeBits ; +16: UBYTE uid1 ; +17: WORD uid2 ; +18: } ri ; +19: +20: void checkpdfheader ( ) +21: { +22: +23: if ( ( type != "BOOK" || creator != "MOBI" ) +24: && ( type != "TEXt" || creator != "REAd" ) ) +25: { +26: Warning ( "File is not BOOKMOBI or TEXtREAd. Template stopped." ) ; +27: return - 1 ; +28: } +29: } +30: +31: typedef struct { +32: CHAR name [ 32 ] ; +33: WORD attributeBits ; +34: WORD version ; +35: DWORD creationDate ; +36: DWORD modificationDate ; +37: DWORD lastBackupDate ; +38: DWORD modificationNumber ; +39: DWORD appInfoID ; +40: DWORD sortInfoID ; +41: CHAR type [ 4 ] ; +42: CHAR creator [ 4 ] ; +43: checkpdfheader ( ) ; +44: DWORD uniqueIDseed ; +45: DWORD nextRecordListID ; +46: WORD numberOfRecords ; +47: +48: SetBackColor ( cWhite ) ; +49: struct { +50: DWORD dataOffset ; +51: UBYTE attributeBits ; +52: UBYTE uid1 ; +53: WORD uid2 ; +54: } recptr [ pdf . numberOfRecords ] ; +55: } PalmDatabaseFormat ; +56: +57: enum < ushort > eCompression { +58: NoCompression = 1 , +59: PalmDOC = 2 , +60: HUFFCDIC = 17480 +61: } ; +62: +63: enum < ushort > encryptionType { +64: NoEncryption = 0 , +65: OldMobipocketEncryption = 1 , +66: MobipocketEncryption = 2 +67: } ; +68: +69: enum < ushort > TextEncoding { +70: CP1252_WinLatin1 = 1252 , +71: UTF8 = 65001 +72: } ; +73: +74: enum < uint > MobiType { +75: MobipocketBook = 2 , +76: PalmDOCbook = 3 , +77: Audio = 4 , +78: News = 257 , +79: NewsFeed = 258 , +80: NewsMagazine = 259 , +81: PICS = 513 , +82: Word = 514 , +83: XLS = 515 , +84: PPT = 516 , +85: TEXT = 517 , +86: HTML = 518 +87: } ; +88: +89: +90: typedef struct { +91: eCompression compression ; +92: WORD unused ; +93: DWORD textLength ; +94: WORD numPDBrecords ; +95: WORD recMaxSize ; +96: encryptionType encryption ; +97: Assert ( encryption == 0 , "File encrypted. Abort." ) ; +98: WORD unknown1 ; +99: } PalmDOCheader ; +100: +101: typedef enum < uint32 > eMBHflags { +102: multibyte = 0x1 , +103: trailers = 0x2 +104: } MBHflags < read = readMBHflags > ; +105: +106: string readMBHflags ( local MBHflags & flags ) { +107: local string s = "" ; +108: local int commaNeeded = 0 ; +109: local MBHflags i = 1 ; +110: +111: SPrintf ( s , "%x: " , flags ) ; +112: +113: +114: +115: +116: +117: while ( i <= 2 ) { +118: if ( flags && i ) { +119: if ( commaNeeded ) { s += ", " ; } +120: s += EnumToString ( i ) ; +121: commaNeeded = 1 ; +122: } +123: i = i << 1 ; +124: } +125: return s ; +126: } +127: +128: +129: typedef struct { +130: CHAR identifier [ 4 ] < comment = "continuation of Palm DOC Header" > ; +131: DWORD headerLength ; +132: MobiType mobiType ; +133: WORD cryptoType ; +134: TextEncoding textEncoding < comment = "codepage" > ; +135: DWORD uniqueID ; +136: DWORD MOBIversion ; +137: DWORD orthographicIndex < format = hex > ; +138: DWORD inflectionIndex < format = hex > ; +139: DWORD indexNames < format = hex > ; +140: DWORD indexKeys < format = hex > ; +141: DWORD extraIndex0 < format = hex > ; +142: DWORD extraIndex1 < format = hex > ; +143: DWORD extraIndex2 < format = hex > ; +144: DWORD extraIndex3 < format = hex > ; +145: DWORD extraIndex4 < format = hex > ; +146: DWORD extraIndex5 < format = hex > ; +147: DWORD firstNonBookIndex < format = hex > ; +148: DWORD fullNameOffset < comment = "Book Title" > ; +149: DWORD fullNameLength < comment = "Book Title Length" > ; +150: DWORD locale ; +151: DWORD inputLanguage ; +152: DWORD outputLanguage ; +153: DWORD minVersion ; +154: DWORD firstImageIndex ; +155: DWORD huffmanRecordOffset ; +156: DWORD huffmanRecordCount ; +157: DWORD huffmanTableOffset ; +158: DWORD huffmanTableLength ; +159: DWORD EXTHflags ; +160: CHAR unknown2 [ 32 ] ; +161: DWORD DRMoffset ; +162: DWORD DRMcount < format = hex > ; +163: DWORD DRMsize < format = hex > ; +164: DWORD DRMflags ; +165: CHAR unknown3 [ 12 ] ; +166: WORD FirstContentRecNo ; +167: WORD LastContentRecNo ; +168: DWORD unknown4 ; +169: DWORD FCISrecNo ; +170: DWORD unknown5 ; +171: DWORD FLISrecNo ; +172: DWORD unknown6 ; +173: QWORD unknown7 ; +174: DWORD unknown8 ; +175: DWORD unknown9 ; +176: DWORD unknown10 ; +177: DWORD unknown11 ; +178: MBHflags mbhflags ; +179: DWORD INDXrecordOffset ; +180: } MobiHeader ; +181: +182: +183: enum < ubyte > TextToSpeach { +184: TextToSpeechEnabled = 0 , +185: TextToSpeechDisabled = 1 +186: } ; +187: +188: enum < DWORD > CreatorSoftware { +189: mobigen = 1 , +190: MobipocketCreator = 2 , +191: kindlegen_Windows = 200 , +192: kindlegen_Linux = 201 , +193: kindlegen_Mac = 202 +194: } ; +195: +196: typedef struct { +197: enum < DWORD > EXTHrecordType { +198: Drm_Server_Id = 1 , +199: Drm_Commerce_Id = 2 , +200: Drm_Ebookbase_Book_Id = 3 , +201: Creator = 100 , +202: Publisher = 101 , +203: Imprint = 102 , +204: Description = 103 , +205: ISBN = 104 , +206: Subject = 105 , +207: Published = 106 , +208: Review = 107 , +209: Contributor = 108 , +210: Rights = 109 , +211: SubjectCode = 110 , +212: Type = 111 , +213: Source = 112 , +214: ASIN = 113 , +215: VersionNumber = 114 , +216: Sample = 115 , +217: StartReading = 116 , +218: Adult = 117 , +219: Price = 118 , +220: Currency = 119 , +221: K8_Boundary_Section = 121 , +222: fixed_layout = 122 , +223: book_type = 123 , +224: orientation_lock = 124 , +225: K8_Count_of_Resources_Fonts_Images = 125 , +226: original_resolution = 126 , +227: K8_Cover_Image = 129 , +228: K8_Unidentified_Count = 131 , +229: RegionMagnification = 132 , +230: DictShortName = 200 , +231: CoverOffset = 201 , +232: ThumbOffset = 202 , +233: HasFakeCover = 203 , +234: CreatorSoftwareRecord = 204 , +235: CreatorMajorVersion = 205 , +236: CreatorMinorVersion = 206 , +237: CreatorBuildNumber = 207 , +238: Watermark = 208 , +239: Tamper_proof_keys = 209 , +240: FontSignature = 300 , +241: ClippingLimit = 401 , +242: PublisherLimit = 402 , +243: TextToSpeachFlag = 404 , +244: CDE_Type = 501 , +245: last_update_time = 502 , +246: Updated_Title = 503 +247: +248: +249: +250: +251: +252: +253: +254: } recordType ; +255: DWORD recordLength ; +256: switch ( recordType ) { +257: case 1 : +258: UBYTE Drm_Server_Id [ recordLength - 8 ] ; +259: break ; +260: case 2 : +261: UBYTE Drm_Commerce_Id [ recordLength - 8 ] ; +262: break ; +263: case 3 : +264: UBYTE Drm_Ebookbase_Book_Id [ recordLength - 8 ] ; +265: break ; +266: case 100 : +267: UBYTE creator [ recordLength - 8 ] ; +268: break ; +269: case 101 : +270: UBYTE publisher [ recordLength - 8 ] ; +271: break ; +272: case 102 : +273: UBYTE imprint [ recordLength - 8 ] ; +274: break ; +275: case 103 : +276: UBYTE description [ recordLength - 8 ] ; +277: break ; +278: case 104 : +279: UBYTE ISBN [ recordLength - 8 ] ; +280: break ; +281: case 105 : +282: UBYTE subject [ recordLength - 8 ] ; +283: break ; +284: case 106 : +285: UBYTE publishingDate [ recordLength - 8 ] ; +286: break ; +287: case 107 : +288: UBYTE review [ recordLength - 8 ] ; +289: break ; +290: case 108 : +291: UBYTE contributor [ recordLength - 8 ] ; +292: break ; +293: case 109 : +294: UBYTE rights [ recordLength - 8 ] ; +295: break ; +296: case 110 : +297: UBYTE subjectCode [ recordLength - 8 ] ; +298: break ; +299: case 111 : +300: UBYTE type [ recordLength - 8 ] ; +301: break ; +302: case 112 : +303: UBYTE source [ recordLength - 8 ] ; +304: break ; +305: case 113 : +306: UBYTE ASIN [ recordLength - 8 ] ; +307: break ; +308: case 114 : +309: UBYTE versionNumber [ recordLength - 8 ] ; +310: break ; +311: case 115 : +312: Assert ( recordLength == 12 , "sample recordLength-8 != 4 (DWORD)." ) ; +313: DWORD sample ; +314: break ; +315: case 116 : +316: UBYTE startReading [ recordLength - 8 ] ; +317: break ; +318: case 117 : +319: UBYTE adult [ recordLength - 8 ] ; +320: break ; +321: case 118 : +322: UBYTE price [ recordLength - 8 ] ; +323: break ; +324: case 119 : +325: UBYTE currency [ recordLength - 8 ] ; +326: break ; +327: case 121 : +328: case 122 : +329: case 123 : +330: case 124 : +331: case 125 : +332: case 126 : +333: case 129 : +334: case 131 : +335: case 132 : +336: UBYTE unknown [ recordLength - 8 ] ; +337: break ; +338: +339: case 200 : +340: UBYTE dictShortName [ recordLength - 8 ] ; +341: break ; +342: case 201 : +343: Assert ( recordLength == 12 , "coverOffset recordLength-8 != 4 (DWORD)." ) ; +344: DWORD coverOffset ; +345: break ; +346: case 202 : +347: Assert ( recordLength == 12 , "thumbOffset recordLength-8 != 4 (DWORD)." ) ; +348: DWORD thumbOffset ; +349: break ; +350: case 203 : +351: UBYTE hasFakeCover [ recordLength - 8 ] ; +352: break ; +353: case 204 : +354: Assert ( recordLength == 12 , "creatorSoftware recordLength-8 != 4 (DWORD)." ) ; +355: CreatorSoftware creatorSoftware ; +356: break ; +357: case 205 : +358: Assert ( recordLength == 12 , "creatorMajorVersion recordLength-8 != 4 (DWORD)." ) ; +359: DWORD creatorMajorVersion ; +360: break ; +361: case 206 : +362: Assert ( recordLength == 12 , "creatorMinorVersion recordLength-8 != 4 (DWORD)." ) ; +363: DWORD creatorMinorVersion ; +364: break ; +365: case 207 : +366: Assert ( recordLength == 12 , "creatorBuildNumber recordLength-8 != 4. (DWORD)" ) ; +367: DWORD creatorBuildNumber ; +368: break ; +369: case 208 : +370: UBYTE watermark [ recordLength - 8 ] ; +371: break ; +372: case 209 : +373: UBYTE tamper_proof_keys [ recordLength - 8 ] ; +374: break ; +375: case 300 : +376: UBYTE fontSignature [ recordLength - 8 ] ; +377: break ; +378: case 301 : +379: UBYTE clippingLimit [ recordLength - 8 ] ; +380: break ; +381: case 402 : +382: UBYTE publisherLimit [ recordLength - 8 ] ; +383: break ; +384: case 404 : +385: Assert ( recordLength == 9 , "TextToSpeach recordLength-8 != 1 (BYTE)." ) ; +386: TextToSpeach textToSpeach ; +387: break ; +388: case 501 : +389: Assert ( recordLength == 12 , "CDEtype recordLength-8 != 1. (DWORD)" ) ; +390: CHAR CDEtype [ 4 ] ; +391: break ; +392: case 502 : +393: UBYTE lastUpdateTime [ recordLength - 8 ] ; +394: break ; +395: case 503 : +396: UBYTE updatedTitle [ recordLength - 8 ] ; +397: break ; +398: case 504 : +399: UBYTE ASINcopy [ recordLength - 8 ] ; +400: break ; +401: case 524 : +402: UBYTE dclanguage [ recordLength - 8 ] ; +403: break ; +404: default : +405: UBYTE unknown [ recordLength - 8 ] ; +406: break ; +407: } +408: } EXTHrecord ; +409: +410: typedef struct { +411: CHAR identifier [ 4 ] ; +412: DWORD headerLength ; +413: UINT recordCount ; +414: local int i = 0 ; +415: for ( i = 0 ; i < recordCount ; i ++ ) { +416: EXTHrecord exthrecord ; +417: } +418: } ExthHeader ; +419: +420: typedef struct { +421: UINT ID < comment = "FLIS" > ; +422: UINT fixed1 < comment = "fixed value 8" > ; +423: USHORT fixed2 < comment = "fixed value 65" > ; +424: USHORT fixed3 < comment = "fixed value 0" > ; +425: UINT fixed4 < comment = "fixed value 0" > ; +426: UINT fixed5 < comment = "fixed value -1" > ; +427: USHORT fixed6 < comment = "fixed value 1" > ; +428: USHORT fixed7 < comment = "fixed value 3" > ; +429: UINT fixed8 < comment = "fixed value 3" > ; +430: UINT fixed9 < comment = "fixed value 1" > ; +431: UINT fixed10 < comment = "fixed value -1" > ; +432: } FLISRECORD ; +433: +434: +435: typedef struct { +436: UINT ID < comment = "FDST" > ; +437: UINT FDSTstart < comment = "FDST start" > ; +438: UINT fdstcnt < comment = "Number of records inside FDST" > ; +439: struct { +440: UBYTE record [ reclen - 12 ] ; +441: } fdst ; +442: } FDSTkf8RECORD ; +443: +444: typedef struct { +445: UINT ID < comment = "FCIS" > ; +446: UINT fixed1 < comment = "fixed value 20" > ; +447: UINT fixed2 < comment = "fixed value 16" > ; +448: UINT fixed3 < comment = "fixed value 1" > ; +449: UINT fixed4 < comment = "fixed value 0" > ; +450: UINT fixed5 < comment = "text length (the same value as \"text length\" in the PalmDoc header)" > ; +451: UINT fixed6 < comment = "fixed value 0" > ; +452: UINT fixed7 < comment = "fixed value 32" > ; +453: UINT fixed8 < comment = "fixed value 8" > ; +454: USHORT fixed9 < comment = "fixed value 1" > ; +455: USHORT fixed10 < comment = "fixed value 1" > ; +456: UINT fixed11 < comment = "fixed value 0" > ; +457: } FCISRECORD ; +458: +459: typedef struct { +460: UINT ID < comment = "SRCS" > ; +461: struct { +462: UBYTE record [ reclen - 4 ] ; +463: } srcs ; +464: } SRCSRECORD ; +465: +466: typedef struct { +467: UINT ID < comment = "DATP" > ; +468: struct { +469: UBYTE record [ reclen - 4 ] ; +470: } datp ; +471: } DATPRECORD ; +472: +473: typedef struct { +474: QUAD ID < comment = "BOUNDARY" > ; +475: } BOUNDARYRECORD ; +476: +477: typedef struct { +478: struct { +479: UBYTE b [ reclen ] ; +480: } html ; +481: } HTML ; +482: +483: typedef struct { +484: UINT ID < comment = "INDX" > ; +485: UINT headerLength < comment = "" > ; +486: UINT indexType < comment = "" > ; +487: UINT unknown1 < comment = "" > ; +488: UINT unknown2 < comment = "" > ; +489: UINT idxtStart < comment = "offset to the IDXT section" > ; +490: UINT indexEncoding ; +491: UINT indexLanguage < comment = "language code of the index" > ; +492: UINT totalIndexCount < comment = "number of index entries" > ; +493: UINT ordtStart < comment = "offset to the ORDT section" > ; +494: UINT ligtStart < comment = "offset to the LIGT section" > ; +495: UINT unknown3 ; +496: UINT unknown4 ; +497: } INDXRECORD ; +498: +499: typedef struct { +500: UBYTE fixed1 < comment = "fixed value 233 (0xE9)" > ; +501: UBYTE fixed2 < comment = "fixed value 142 (0x8E)" > ; +502: UBYTE fixed3 < comment = "fixed value 13 (0x0D)" > ; +503: UBYTE fixed4 < comment = "fixed value 10 (0x0A)" > ; +504: } ENDRECORD ; +505: +506: +507: +508: +509: +510: BigEndian ( ) ; +511: SetBackColor ( cLtGray ) ; +512: PalmDatabaseFormat pdf ; +513: +514: +515: FSeek ( pdf . recptr [ 0 ] . dataOffset ) ; +516: SetBackColor ( cLtGray ) ; +517: PalmDOCheader pdh ; +518: MobiHeader mbh ; +519: local char fullName [ 255 ] ; +520: local char KF8fullName [ 255 ] ; +521: +522: local int reclen ; +523: local int i , n ; +524: local int endrec ; +525: local char tag [ 9 ] ; +526: +527: if ( mbh . fullNameOffset != 0 ) +528: { +529: +530: FSeek ( pdf . recptr [ 0 ] . dataOffset + mbh . fullNameOffset ) ; +531: ReadBytes ( fullName , FTell ( ) , mbh . fullNameLength ) ; +532: fullName [ mbh . fullNameLength ] = '\0' ; +533: +534: } +535: +536: if ( mbh . EXTHflags & 0x40 ) +537: { +538: +539: FSeek ( pdf . recptr [ 0 ] . dataOffset + 16 + mbh . headerLength ) ; +540: SetBackColor ( cYellow ) ; +541: ExthHeader exth ; +542: } +543: +544: local uint multibyte = 0 ; +545: local uint trailers = 0 ; +546: if ( pdf . type == "BOOK" && pdf . creator == "MOBI" ) +547: { +548: if ( ( mbh . headerLength >= 0xE4 ) && ( pdf . version >= 5 ) ) +549: { +550: multibyte = flags & 1 ; +551: while ( flags > 1 ) +552: { +553: if ( flags & 2 ) +554: { +555: ++ trailers ; +556: flags = flags >> 1 ; +557: } +558: } +559: } +560: } +561: +562: +563: for ( i = 0 ; i < pdf . numberOfRecords - 1 ; i ++ ) +564: { +565: FSeek ( pdf . recptr [ i ] . dataOffset ) ; +566: reclen = ( pdf . recptr [ i + 1 ] . dataOffset - pdf . recptr [ i ] . dataOffset ) ; +567: +568: ReadBytes ( tag , FTell ( ) , 8 ) ; +569: tag [ 8 ] = '\0' ; +570: +571: +572: +573: if ( Memcmp ( tag , "FLIS" , 4 ) == 0 ) +574: { +575: SetBackColor ( cLtGray ) ; +576: FLISRECORD data ; +577: } +578: else if ( Memcmp ( tag , "FDST" , 4 ) == 0 ) +579: { +580: SetBackColor ( cLtGray ) ; +581: FDSTkf8RECORD data ; +582: } +583: else if ( Memcmp ( tag , "FCIS" , 4 ) == 0 ) +584: { +585: SetBackColor ( cLtGreen ) ; +586: FCISRECORD data ; +587: if ( data . fixed1 < 0x10 ) +588: { +589: +590: } +591: +592: +593: } +594: else if ( Memcmp ( tag , "SRCS" , 4 ) == 0 ) +595: { +596: SetBackColor ( cLtRed ) ; +597: SRCSRECORD data ; +598: } +599: else if ( Memcmp ( tag , "DATP" , 4 ) == 0 ) +600: { +601: SetBackColor ( cLtBlue ) ; +602: DATPRECORD data ; +603: for ( n = 0 ; n < reclen - 4 ; n ++ ) +604: { +605: if ( data . datp . record [ n ] < 0x10 ) +606: { +607: +608: } +609: +610: } +611: +612: } +613: else if ( Memcmp ( tag , "INDX" , 4 ) == 0 ) +614: { +615: SetBackColor ( cSilver ) ; +616: INDXRECORD data ; +617: } +618: else if ( Memcmp ( tag , "BOUNDARY" , 8 ) == 0 ) +619: { +620: SetBackColor ( cYellow ) ; +621: BOUNDARYRECORD data ; +622: +623: SetBackColor ( cLtGray ) ; +624: i ++ ; +625: PalmDOCheader data ; +626: MobiHeader KF8mbh ; +627: if ( KF8mbh . fullNameOffset != 0 ) +628: { +629: +630: FSeek ( pdf . recptr [ i ] . dataOffset + KF8mbh . fullNameOffset ) ; +631: ReadBytes ( KF8fullName , FTell ( ) , KF8mbh . fullNameLength ) ; +632: fullName [ KF8mbh . fullNameLength ] = '\0' ; +633: +634: } +635: if ( KF8mbh . EXTHflags & 0x40 ) +636: { +637: +638: +639: FSeek ( pdf . recptr [ i ] . dataOffset + 16 + KF8mbh . headerLength ) ; +640: SetBackColor ( cYellow ) ; +641: ExthHeader KF8exth ; +642: } +643: } +644: else if ( Memcmp ( tag , "" , 6 ) == 0 ) +645: { +646: SetBackColor ( cLtGreen ) ; +647: HTML data ; +648: } +649: else if ( Memcmp ( tag , " ID3_GENRES +58: { +59: Blues , Classic_Rock , Country , Dance , Disco , Funk , Grunge , Hip_Hop , +60: Jazz , Metal , New_Age , Oldies , Other , Pop , R_and_B , Rap , +61: Reggae , Rock , Techno , Industrial , Alternative , Ska , Death_Metal , Pranks , +62: Soundtrack , Euro_Techno , Ambient , Trip_Hop , Vocal , Jazz_Funk , Fusion , Trance , +63: Classical , Instrumental , Acid , House , Game , Sound_Clip , Gospel , Noise , +64: AlternRock , Bass , Soul , Punk , Space , Meditative , Instrumental_Pop , Instrumental_Rock , +65: Ethnic , Gothic , Darkwave , Techno_Industrial , Electronic , Pop_Folk , Eurodance , Dream , +66: Southern_Rock , Comedy , Cult , Gangsta , Top_40 , Christian_Rap , Pop_Funk , Jungle , +67: Native_American , Cabaret , New_Wave , Psychadelic , Rave , Showtunes , Trailer , Lo_Fi , +68: Tribal , Acid_Punk , Acid_Jazz , Polka , Retro , Musical , Rock_n_Roll , Hard_Rock , +69: Folk , Folk_Rock , National_Folk , Swing , Fast_Fusion , Bebob , Latin , Revival , +70: Celtic , Bluegrass , Avantgarde , Gothic_Rock , +71: Progressive_Rock , Psychedelic_Rock , Symphonic_Rock , Slow_Rock , +72: Big_Band , Chorus , Easy_Listening , Acoustic , Humour , Speech , Chanson , Opera , +73: Chamber_Music , Sonata , Symphony , Booty_Bass , Primus , Porn_Groove , Satire , Slow_Jam , +74: Club , Tango , Samba , Folklore , Ballad , Power_Ballad , Rhythmic_Soul , Freestyle , +75: Duet , Punk_Rock , Drum_Solo , A_capella , Euro_House , Dance_Hall , Goa , Drum_and_Bass , +76: Club_House , Hardcore , Terror , Indie , BritPop , Negerpunk , Polsk_Punk , Beat , +77: Christian , Heavy_Metal , Black_Metal , Crossover , +78: Contemporary , Christian_Rock , Merengue , Salsa , Thrash_Metal , Anime , JPop , Synthpop +79: } ; +80: +81: +82: struct ID3v1_TAG +83: { +84: DisplayFormatDecimal ( ) ; +85: +86: SetBackColor ( 0x33BC55 ) ; +87: char id [ 3 ] ; +88: +89: SetBackColor ( 0x48E048 ) ; +90: char title [ 30 ] ; +91: +92: SetBackColor ( 0x5DE45D ) ; +93: char artist [ 30 ] ; +94: +95: SetBackColor ( 0x72E872 ) ; +96: char album [ 30 ] ; +97: +98: SetBackColor ( 0x87EC87 ) ; +99: char year [ 4 ] ; +100: +101: if ( ReadByte ( FTell ( ) + 28 ) == 0 && ReadByte ( FTell ( ) + 29 ) != 0 ) +102: { +103: +104: +105: SetBackColor ( 0x9CF09C ) ; +106: char comment [ 28 ] ; +107: +108: SetBackColor ( 0xB1F4B1 ) ; +109: byte zero ; +110: +111: SetBackColor ( 0xC6F8C6 ) ; +112: ubyte track ; +113: } +114: else +115: { +116: +117: +118: SetBackColor ( 0x9CF09C ) ; +119: char comment [ 30 ] ; +120: } +121: +122: SetBackColor ( 0xDBFCDB ) ; +123: ID3_GENRES genre ; +124: } ; +125: +126: +127: struct ID3v2_HEADER +128: { +129: SetBackColor ( 0x91C4FF ) ; +130: +131: char head [ 3 ] ; +132: +133: DisplayFormatDecimal ( ) ; +134: +135: ubyte ver_major ; +136: ubyte ver_revision ; +137: +138: struct FLAGS { +139: ubyte UNSYNCHRONISATION_USED : 1 ; +140: ubyte EXTENDED_HEADER_PRESENT : 1 ; +141: ubyte EXPERIMENTAL_TAG : 1 ; +142: ubyte : 5 ; +143: } flags ; +144: +145: DisplayFormatHex ( ) ; +146: +147: ubyte size [ 4 ] ; +148: +149: +150: +151: } ; +152: +153: +154: struct ID3v2_EXTENDED_HEADER +155: { +156: SetBackColor ( 0xA1D4FF ) ; +157: +158: DisplayFormatDecimal ( ) ; +159: +160: uint32 size ; +161: +162: uint16 FLAG_CRC_PRESENT : 1 ; +163: uint16 : 15 ; +164: +165: uint32 padding_sz ; +166: +167: if ( FLAG_CRC_PRESENT ) +168: { +169: DisplayFormatHex ( ) ; +170: uint32 crc ; +171: } +172: } ; +173: +174: +175: struct ID3v2_FRAME +176: { +177: char id [ 4 ] ; +178: +179: DisplayFormatDecimal ( ) ; +180: +181: uint32 size ; +182: +183: struct FRAME_FLAGS { +184: uint16 TAG_ALTER_PRESERV : 1 ; +185: uint16 FILE_ALTER_PRESERV : 1 ; +186: uint16 READ_ONLY_FRAME : 1 ; +187: uint16 : 5 ; +188: uint16 COMPRESSED_FRAME : 1 ; +189: uint16 ENCRYPTED_FRAME : 1 ; +190: uint16 GROUP_MEMBER_FRAME : 1 ; +191: uint16 : 5 ; +192: } flags ; +193: +194: if ( id [ 0 ] == 'T' ) +195: { +196: +197: if ( ReadByte ( FTell ( ) ) == 0 && size > 1 ) +198: { +199: byte id_asciiz_str ; +200: char frame_data [ size - 1 ] ; +201: } +202: else +203: char frame_data [ size ] ; +204: } +205: else +206: { +207: DisplayFormatHex ( ) ; +208: ubyte frame_data [ size ] ; +209: } +210: } ; +211: +212: +213: struct ID3v2_TAG +214: { +215: ID3v2_HEADER hdr ; +216: +217: +218: local uint32 tag_sz = hdr . size [ 0 ] ; +219: tag_sz <<= 7 ; +220: tag_sz |= hdr . size [ 1 ] ; +221: tag_sz <<= 7 ; +222: tag_sz |= hdr . size [ 2 ] ; +223: tag_sz <<= 7 ; +224: tag_sz |= hdr . size [ 3 ] ; +225: +226: +227: +228: +229: +230: +231: if ( hdr . ver_major == 0xFF || hdr . ver_revision == 0xFF || +232: hdr . size [ 0 ] >= 0x80 || hdr . size [ 1 ] >= 0x80 || +233: hdr . size [ 2 ] >= 0x80 || hdr . size [ 3 ] >= 0x80 ) +234: { +235: Printf ( "MP3: warning: invalid ID3v2 tag header\n" ) ; +236: } +237: else +238: { +239: if ( hdr . ver_major != 3 || hdr . flags . UNSYNCHRONISATION_USED || hdr . flags . EXPERIMENTAL_TAG ) +240: { +241: Printf ( "MP3: warning: skipping unsupported ID3v2.%d tag\n" , hdr . ver_major ) ; +242: SetBackColor ( 0xA9DCFF ) ; +243: DisplayFormatHex ( ) ; +244: ubyte id3v2_data [ tag_sz ] ; +245: } +246: else +247: { +248: if ( hdr . flags . EXTENDED_HEADER_PRESENT ) +249: ID3v2_EXTENDED_HEADER ext_hdr ; +250: +251: +252: +253: +254: +255: local uint32 frame_color = 0xC9FCFF ; +256: do +257: { +258: SetBackColor ( frame_color ) ; +259: ID3v2_FRAME tf ; +260: frame_color -= 0x20200 ; +261: } +262: while ( FTell ( ) < tag_sz + sizeof ( hdr ) && ReadByte ( FTell ( ) ) != 0 ) ; +263: +264: SetBackColor ( 0x99CCFF ) ; +265: ubyte id3v2_padding [ tag_sz + sizeof ( hdr ) - FTell ( ) ] ; +266: } +267: } +268: } ; +269: +270: +271: +272: +273: +274: struct MPEG_HEADER +275: { +276: SetBackColor ( 0xCC99FF ) ; +277: +278: DisplayFormatHex ( ) ; +279: +280: uint32 frame_sync : 12 ; +281: +282: DisplayFormatDecimal ( ) ; +283: +284: uint32 mpeg_id : 1 ; +285: uint32 layer_id : 2 ; +286: uint32 protection_bit : 1 ; +287: uint32 bitrate_index : 4 ; +288: uint32 frequency_index : 2 ; +289: uint32 padding_bit : 1 ; +290: uint32 private_bit : 1 ; +291: uint32 channel_mode : 2 ; +292: uint32 mode_extension : 2 ; +293: uint32 copyright : 1 ; +294: uint32 original : 1 ; +295: uint32 emphasis : 2 ; +296: +297: if ( protection_bit == 0 ) +298: { +299: DisplayFormatHex ( ) ; +300: uint16 checksum ; +301: } +302: } ; +303: +304: +305: struct MPEG_FRAME +306: { +307: MPEG_HEADER mpeg_hdr ; +308: +309: +310: bitrate = 0 ; +311: +312: +313: if ( mpeg_hdr . frame_sync < 0xFFE || mpeg_hdr . layer_id == 0 || +314: mpeg_hdr . bitrate_index == 0 || mpeg_hdr . bitrate_index == 15 || +315: mpeg_hdr . frequency_index == 3 ) +316: { +317: Printf ( "MP3: warning: invalid MPEG header in frame at offset 0x%X\n" , +318: FTell ( ) - 4 - ( mpeg_hdr . protection_bit == 0 ? 2 : 0 ) ) ; +319: +320: +321: FSeek ( FTell ( ) - 2 ) ; +322: } +323: else +324: { +325: if ( mpeg_hdr . layer_id == 3 ) +326: { +327: bitrate = ( uint32 ) mpeg_hdr . bitrate_index << 5 ; +328: } +329: else +330: { +331: if ( mpeg_hdr . layer_id == 2 ) +332: { +333: bitrate = ( uint32 ) mpeg_hdr . bitrate_index == 1 ? 32 : +334: ( 1 << 5 + ( uint32 ) mpeg_hdr . bitrate_index / 4 ) + +335: ( ( ( uint32 ) mpeg_hdr . bitrate_index & 3 ) << +336: 3 + ( uint32 ) mpeg_hdr . bitrate_index / 4 ) ; +337: } +338: else +339: { +340: if ( mpeg_hdr . mpeg_id == 1 ) +341: { +342: bitrate = ( 1 << 5 + ( ( uint32 ) mpeg_hdr . bitrate_index - 1 ) / 4 ) + +343: ( ( ( uint32 ) mpeg_hdr . bitrate_index - 1 & 3 ) << +344: 3 + ( ( uint32 ) mpeg_hdr . bitrate_index - 1 ) / 4 ) ; +345: } +346: else +347: { +348: bitrate = ( uint32 ) mpeg_hdr . bitrate_index < 4 ? +349: +350: 8 * ( uint32 ) mpeg_hdr . bitrate_index : +351: +352: ( 1 << 4 + ( uint32 ) mpeg_hdr . bitrate_index / 4 ) + +353: ( +354: ( ( uint32 ) mpeg_hdr . bitrate_index & 3 ) == 0 ? 0 : +355: +356: ( ( uint32 ) mpeg_hdr . bitrate_index & 3 ) == 1 ? +357: ( 1 << 4 + ( uint32 ) mpeg_hdr . bitrate_index / 4 ) : +358: +359: ( ( uint32 ) mpeg_hdr . bitrate_index & 3 ) == 2 ? +360: ( 1 << 4 + ( uint32 ) mpeg_hdr . bitrate_index / 4 ) + +361: ( ( 1 << 4 + ( uint32 ) mpeg_hdr . bitrate_index / 4 ) >> 1 ) : +362: +363: ( 1 << 4 + ( uint32 ) mpeg_hdr . bitrate_index / 4 ) - +364: ( ( 1 << 4 + ( uint32 ) mpeg_hdr . bitrate_index / 4 ) >> 2 ) +365: ) ; +366: } +367: } +368: } +369: } +370: +371: if ( bitrate != 0 ) +372: { +373: local uint16 freq [ 3 ] ; +374: freq [ 0 ] = 2205 ; +375: freq [ 1 ] = 2400 ; +376: freq [ 2 ] = 1600 ; +377: +378: sampling_freq = freq [ mpeg_hdr . frequency_index ] ; +379: +380: if ( mpeg_hdr . mpeg_id == 1 ) +381: sampling_freq <<= 1 ; +382: +383: frame_size = ( bitrate * 14400 ) / sampling_freq ; +384: +385: if ( mpeg_hdr . channel_mode == 3 ) +386: frame_size >>= 1 ; +387: +388: frame_size -= 4 + ( mpeg_hdr . protection_bit == 0 ? 2 : 0 ) - mpeg_hdr . padding_bit ; +389: +390: frame_header_offset = FTell ( ) - 4 - ( mpeg_hdr . protection_bit == 0 ? 2 : 0 ) ; +391: +392: +393: if ( FTell ( ) + frame_size > FileSize ( ) ) +394: { +395: Printf ( "MP3: warning: cut MPEG frame at end of file (frame header offset = 0x%LX, data length = %u)\n" , +396: frame_header_offset , frame_size ) ; +397: +398: Printf ( "MP3: file parsing completed!\nMP3: valid MPEG frames found: %d\n" , frames_count ) ; +399: +400: if ( frames_count != 0 ) +401: Printf ( "MP3: average frame bitrate: %d kbit\n" , sum_bitrate / frames_count ) ; +402: +403: return ; +404: } +405: else +406: { +407: DisplayFormatHex ( ) ; +408: SetBackColor ( 0xCCCCFF ) ; +409: ubyte mpeg_frame_data [ frame_size ] ; +410: } +411: +412: sum_bitrate += bitrate ; +413: +414: frames_count ++ ; +415: } +416: } ; +417: +418: +419: +420: +421: +422: BigEndian ( ) ; +423: +424: ReadBytes ( buf , 0 , 3 ) ; +425: +426: if ( ! Strcmp ( buf , "ID3" ) ) +427: { +428: Printf ( "MP3: ID3v2 tag found\n" ) ; +429: ID3v2_TAG id3v2_tag ; +430: } +431: +432: while ( ! FEof ( ) && ! id3v1_tag_found ) +433: { +434: +435: seek_pos = FTell ( ) ; +436: was_bad_sync = 0 ; +437: do +438: { +439: data = ReadShort ( seek_pos ) ; +440: +441: if ( ( uint16 ) data == 0x5441 && ( uchar ) ReadByte ( seek_pos + 2 ) == 0x47 ) +442: id3v1_tag_found = 1 ; +443: +444: if ( ! was_bad_sync && ( uint16 ) data < 0xFFE0 && ! id3v1_tag_found ) +445: { +446: Printf ( "MP3: warning: invalid MPEG frame synchronization at offset 0x%LX\n" , seek_pos ) ; +447: was_bad_sync = 1 ; +448: } +449: +450: seek_pos ++ ; +451: } +452: while ( ( uint16 ) data < 0xFFE0 && seek_pos < ( FileSize ( ) - 1 ) && ! id3v1_tag_found ) ; +453: +454: if ( ( uint16 ) data >= 0xFFE0 || id3v1_tag_found ) +455: { +456: FSeek ( seek_pos - 1 ) ; +457: } +458: else +459: { +460: Printf ( "MP3: file parsing completed!\nMP3: valid MPEG frames found: %d\n" , frames_count ) ; +461: +462: if ( frames_count != 0 ) +463: Printf ( "MP3: average frame bitrate: %d kbit\n" , sum_bitrate / frames_count ) ; +464: +465: return ; +466: } +467: +468: if ( ! id3v1_tag_found ) +469: { +470: MPEG_FRAME mf ; +471: +472: if ( frames_count == 1 && bitrate ) +473: Printf ( "MP3: first found MPEG frame parameters:\nMP3:\t- header ofsset: 0x%LX\nMP3:\t- bitrate: %d kbit\nMP3:\t- MPEG-%d layer %d\nMP3:\t- sampling frequency: %d Hz\nMP3:\t- channel mode: %s\nMP3:\t- CRC protected: %s\n" , +474: frame_header_offset , +475: bitrate , +476: mf . mpeg_hdr . mpeg_id == 1 ? 1 : 2 , +477: mf . mpeg_hdr . layer_id == 1 ? 3 : mf . mpeg_hdr . layer_id == 2 ? 2 : 1 , +478: sampling_freq * 10 , +479: mf . mpeg_hdr . channel_mode == 3 ? "mono" : +480: mf . mpeg_hdr . channel_mode == 0 ? "stereo" : +481: mf . mpeg_hdr . channel_mode == 1 ? "joint stereo" : "dual channel" , +482: mf . mpeg_hdr . protection_bit == 0 ? "Yes" : "No" ) ; +483: } +484: } +485: +486: if ( id3v1_tag_found ) +487: { +488: Printf ( "MP3: ID3v1 tag found\n" ) ; +489: ID3v1_TAG id3v1_tag ; +490: } +491: +492: if ( ! FEof ( ) ) +493: Printf ( "MP3: warning: there is some unknown extra-data after ID3v1 tag at end of file\n" ) ; +494: +495: Printf ( "MP3: file parsing completed!\nMP3: valid MPEG frames found: %d\n" , frames_count ) ; +496: +497: if ( frames_count != 0 ) +498: Printf ( "MP3: average frame bitrate: %d kbit\n" , sum_bitrate / frames_count ) ; +499: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/MP4Template.bt b/cparser/tests/exp_lex/MP4Template.bt new file mode 100644 index 0000000..a9ff64b --- /dev/null +++ b/cparser/tests/exp_lex/MP4Template.bt @@ -0,0 +1,164 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: BigEndian ( ) ; +12: +13: local int64 pos ; +14: local int64 pos2 ; +15: +16: typedef union { +17: +18: char text [ 4 ] ; +19: } _typ ; +20: +21: string typeFullName ( _typ & type ) { +22: if ( Memcmp ( type . text , "ftyp" , 4 ) == 0 ) return "File type compatibility box" ; +23: if ( Memcmp ( type . text , "mvhd" , 4 ) == 0 ) return "Movie header box" ; +24: if ( Memcmp ( type . text , "iods" , 4 ) == 0 ) return "Initial object descriptor box" ; +25: if ( Memcmp ( type . text , "trak" , 4 ) == 0 ) return "Track box" ; +26: if ( Memcmp ( type . text , "udta" , 4 ) == 0 ) return "Uset data box" ; +27: if ( Memcmp ( type . text , "mdat" , 4 ) == 0 ) return "Movie (sample) data box" ; +28: if ( Memcmp ( type . text , "moov" , 4 ) == 0 ) return "Moovie box" ; +29: if ( Memcmp ( type . text , "tkhd" , 4 ) == 0 ) return "Track header box" ; +30: if ( Memcmp ( type . text , "mdia" , 4 ) == 0 ) return "Media box" ; +31: if ( Memcmp ( type . text , "edts" , 4 ) == 0 ) return "Edit box" ; +32: if ( Memcmp ( type . text , "elst" , 4 ) == 0 ) return "Edit list" ; +33: return "I don't know the full name" ; +34: } +35: +36: string typeString ( _typ & type ) { +37: return "Type of the box: \"" + type . text + "\"" ; +38: } +39: +40: +41: +42: while ( FTell ( ) < FileSize ( ) - 1 ) { +43: struct _box { +44: uint size < hidden = true > ; +45: _typ type < bgcolor = cLtRed , fgcolor = cWhite , name = "Box Type" , open = false , +46: name = typeString > ; +47: if ( Memcmp ( type . text , "ftyp" , 4 ) == 0 ) { +48: char major_brand [ 4 ] < bgcolor = cDkGreen , fgcolor = cWhite , name = "Major brand" > ; +49: char minor_ver [ 4 ] < bgcolor = cDkBlue , fgcolor = cWhite , name = "Minor version" > ; +50: uint comp_brands [ ( size - sizeof ( size ) - sizeof ( type ) - sizeof ( major_brand ) - +51: sizeof ( minor_ver ) ) / 4 ] < name = "Compatible brands" , +52: comment = brandName , open = true > ; +53: } else if ( Memcmp ( type . text , "moov" , 4 ) == 0 ) { +54: pos = FTell ( ) ; +55: while ( FTell ( ) < pos + size - sizeof ( size ) - sizeof ( type ) ) +56: struct _box2 { +57: uint size < hidden = true > ; +58: _typ type < bgcolor = cLtRed , fgcolor = cWhite , name = "Box Type" , open = false , +59: name = typeString > ; +60: if ( Memcmp ( type . text , "mvhd" , 4 ) == 0 ) { +61: char version < hidden = true > ; +62: char flags [ 3 ] < hidden = true > ; +63: uint crTime < bgcolor = cLtGreen , fgcolor = cBlack , name = "Creation Time" , open = false > ; +64: uint mdTime < bgcolor = cPurple , fgcolor = cWhite , name = "Modification Time" , open = false > ; +65: uint tmScale < name = "Time scale" , comment = "Number of units per 1 second" > ; +66: uint duration < name = "Duration" , comment = "In units defined in the previous field" > ; +67: char rest [ size - sizeof ( size ) - sizeof ( type ) - sizeof ( version ) - +68: sizeof ( flags ) - sizeof ( crTime ) - sizeof ( mdTime ) - +69: sizeof ( tmScale ) - sizeof ( duration ) ] ; +70: } else if ( Memcmp ( type . text , "trak" , 4 ) == 0 ) { +71: pos2 = FTell ( ) ; +72: while ( FTell ( ) < pos2 + size - sizeof ( size ) - sizeof ( type ) ) +73: struct _box3 { +74: uint size < hidden = true > ; +75: _typ type < bgcolor = cLtRed , fgcolor = cWhite , name = "Box Type" , open = false , +76: name = typeString > ; +77: if ( Memcmp ( type . text , "tkhd" , 4 ) == 0 ) { +78: char version < hidden = true > ; +79: char flags [ 3 ] < hidden = true > ; +80: uint crTime < bgcolor = cLtGreen , fgcolor = cBlack , name = "Creation Time" , open = false > ; +81: uint mdTime < bgcolor = cPurple , fgcolor = cWhite , name = "Modification Time" , open = false > ; +82: uint trkID < name = "Track ID" , open = false > ; +83: uint reserv < hidden = true , name = "Reserved" > ; +84: uint duration < name = "Duration" , open = false > ; +85: char rest [ size - sizeof ( size ) - sizeof ( type ) - sizeof ( version ) - +86: sizeof ( flags ) - sizeof ( crTime ) - sizeof ( mdTime ) - +87: sizeof ( trkID ) - sizeof ( reserv ) - sizeof ( duration ) ] ; +88: } else if ( Memcmp ( type . text , "edts" , 4 ) == 0 ) { +89: struct _box4 { +90: uint size < hidden = true > ; +91: _typ type < bgcolor = cLtRed , fgcolor = cWhite , name = "Box Type" , open = false , +92: name = typeString > ; +93: char version < hidden = true > ; +94: char flags [ 3 ] < hidden = true > ; +95: uint entrs < name = "Number of entries" > ; +96: struct { +97: uint trDuration < name = "Track duration" > ; +98: uint mediaTime < name = "Media time" > ; +99: uint mediaRate < name = "Media rate" > ; +100: } entry [ entrs ] < open = true > ; +101: } box < optimize = false , open = true , comment = boxName4 > ; +102: } else +103: char rest [ size - sizeof ( size ) - sizeof ( type ) ] ; +104: } box < optimize = false , open = true , comment = boxName3 > ; +105: } else +106: char rest [ size - sizeof ( size ) - sizeof ( type ) ] ; +107: } box < optimize = false , open = true , comment = boxName2 > ; +108: } else +109: char rest [ size - sizeof ( size ) - sizeof ( type ) ] ; +110: } box < optimize = false , open = true , comment = boxName > ; +111: } +112: +113: string boxName ( _box & box ) { +114: return box . type . text + " (" + typeFullName ( box . type ) + ")" ; ; +115: } +116: +117: string boxName2 ( _box2 & box ) { +118: return box . type . text + " (" + typeFullName ( box . type ) + ")" ; +119: } +120: +121: string boxName3 ( _box3 & box ) { +122: return box . type . text + " (" + typeFullName ( box . type ) + ")" ; +123: } +124: +125: string boxName4 ( _box4 & box ) { +126: return box . type . text + " (" + typeFullName ( box . type ) + ")" ; +127: } +128: +129: string brandName ( uint brand ) { +130: local char text [ 4 ] ; +131: local int i ; +132: +133: for ( i = 0 ; i < 4 ; ++ i ) +134: text [ i ] = brand >> 8 * ( 3 - i ) & 0xFF ; +135: return text ; +136: } +137: +138: +139: +140: +141: +142: +143: +144: +145: +146: +147: +148: +149: +150: +151: +152: +153: +154: +155: +156: +157: +158: +159: +160: +161: +162: +163: +164: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/Mifare1kTemplate.bt b/cparser/tests/exp_lex/Mifare1kTemplate.bt new file mode 100644 index 0000000..5163bb4 --- /dev/null +++ b/cparser/tests/exp_lex/Mifare1kTemplate.bt @@ -0,0 +1,28 @@ +1: +2: +3: +4: +5: +6: +7: +8: struct FILE { +9: struct Manufacturer_block { +10: char Card_UID [ 4 ] < fgcolor = cDkGreen > ; +11: char LRC [ 1 ] < fgcolor = cDkRed > ; +12: char Internal [ 11 ] < fgcolor = cWhite > ; +13: char Data [ 32 ] ; +14: char Key_A [ 6 ] < bgcolor = cDkGray , fgcolor = cLtRed > ; +15: char Access_Bits [ 3 ] < bgcolor = cDkGray , fgcolor = cWhite > ; +16: char GPB [ 1 ] < bgcolor = cDkGray , fgcolor = cLtBlue > ; +17: char Key_B [ 6 ] < bgcolor = cDkGray , fgcolor = cYellow > ; +18: } manufacturer_block ; +19: +20: struct Sec_4blk { +21: char Data [ 48 ] ; +22: char Key_A [ 6 ] < bgcolor = cDkGray , fgcolor = cLtRed > ; +23: char Access_Bits [ 3 ] < bgcolor = cDkGray , fgcolor = cWhite > ; +24: char GPB [ 1 ] < bgcolor = cDkGray , fgcolor = cLtBlue > ; +25: char Key_B [ 6 ] < bgcolor = cDkGray , fgcolor = cYellow > ; +26: } sec_4blk [ 15 ] ; +27: +28: } file < bgcolor = cSilver > ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/Mifare4kTemplate.bt b/cparser/tests/exp_lex/Mifare4kTemplate.bt new file mode 100644 index 0000000..53b7e9c --- /dev/null +++ b/cparser/tests/exp_lex/Mifare4kTemplate.bt @@ -0,0 +1,36 @@ +1: +2: +3: +4: +5: +6: +7: +8: struct FILE { +9: struct Manufacturer_block { +10: char Card_UID [ 4 ] < fgcolor = cDkGreen > ; +11: char LRC [ 1 ] < fgcolor = cDkRed > ; +12: char Internal [ 11 ] < fgcolor = cWhite > ; +13: char Data [ 32 ] ; +14: char Key_A [ 6 ] < bgcolor = cDkGray , fgcolor = cLtRed > ; +15: char Access_Bits [ 3 ] < bgcolor = cDkGray , fgcolor = cWhite > ; +16: char GPB [ 1 ] < bgcolor = cDkGray , fgcolor = cLtBlue > ; +17: char Key_B [ 6 ] < bgcolor = cDkGray , fgcolor = cYellow > ; +18: } manufacturer_block ; +19: +20: struct Sec_4blk { +21: char Data [ 48 ] ; +22: char Key_A [ 6 ] < bgcolor = cDkGray , fgcolor = cLtRed > ; +23: char Access_Bits [ 3 ] < bgcolor = cDkGray , fgcolor = cWhite > ; +24: char GPB [ 1 ] < bgcolor = cDkGray , fgcolor = cLtBlue > ; +25: char Key_B [ 6 ] < bgcolor = cDkGray , fgcolor = cYellow > ; +26: } sec_4blk [ 31 ] ; +27: +28: struct Sec_16blk { +29: char Data [ 240 ] ; +30: char Key_A [ 6 ] < bgcolor = cDkGray , fgcolor = cLtRed > ; +31: char Access_Bits [ 3 ] < bgcolor = cDkGray , fgcolor = cWhite > ; +32: char GPB [ 1 ] < bgcolor = cDkGray , fgcolor = cLtBlue > ; +33: char Key_B [ 6 ] < bgcolor = cDkGray , fgcolor = cYellow > ; +34: } sec_16blk [ 8 ] ; +35: +36: } file < bgcolor = cSilver > ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/NetflowVersion5.bt b/cparser/tests/exp_lex/NetflowVersion5.bt new file mode 100644 index 0000000..4059e36 --- /dev/null +++ b/cparser/tests/exp_lex/NetflowVersion5.bt @@ -0,0 +1,48 @@ +1: +2: +3: +4: +5: +6: +7: +8: +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 ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/OGGTemplate.bt b/cparser/tests/exp_lex/OGGTemplate.bt new file mode 100644 index 0000000..27cdf96 --- /dev/null +++ b/cparser/tests/exp_lex/OGGTemplate.bt @@ -0,0 +1,57 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: local uint MAXPAGES = 1000 ; +12: +13: typedef struct { +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: +24: UBYTE SegmentLen [ PageSegments ] ; +25: +26: +27: local uint i ; +28: for ( i = 0 ; i < PageSegments ; i ++ ) { +29: struct { +30: BYTE Data [ SegmentLen [ i ] ] < bgcolor = cLtGray > ; +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 < bgcolor = cLtBlue > ; +49: +50: +51: if ( page . CapturePattern != "OggS" ) +52: { +53: Warning ( "File is not a valid ogg file. Template stopped." ) ; +54: return - 1 ; +55: } +56: } +57: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/OrCAD3.20a_LIB.bt b/cparser/tests/exp_lex/OrCAD3.20a_LIB.bt new file mode 100644 index 0000000..31ce5fe --- /dev/null +++ b/cparser/tests/exp_lex/OrCAD3.20a_LIB.bt @@ -0,0 +1,289 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: enum < byte > YesNo { No , Yes } ; +12: enum < byte > Vtype { END , LINE , CIRCLE , TEXT , ARC , FILL } ; +13: enum < byte > ptype { IN , I_O , OUT , OC , PAS , hiZ , OE , PWR } ; +14: enum < byte > pquad { II , IV } ; +15: enum < byte > pside { Left , Right , Top , Bottom } ; +16: +17: typedef byte bit ; +18: +19: typedef struct sText +20: { byte Length < hidden = true > ; +21: if ( Length > 0 ) char String [ Length ] ; +22: } ; +23: +24: typedef struct fTxt ( byte fixLen ) +25: { byte Length < hidden = true > ; +26: if ( Length > 0 ) char String [ Length ] ; +27: if ( ( fixLen > 0 ) && ( fixLen > Length ) ) char filler [ fixLen - Length ] ; +28: } ; +29: +30: typedef struct Coord +31: { short X ; +32: short Y ; +33: } ; +34: +35: typedef struct idxP +36: { ushort NameOffset < format = hex > ; +37: ushort DefOffset < format = hex > ; +38: BigEndian ( ) ; +39: WORD PrefixBitmap < format = binary > ; +40: LittleEndian ( ) ; +41: WORD unknown < format = hex > ; +42: } ; +43: +44: typedef struct Offsets +45: { ushort offsetLarge ; +46: ushort offsetMedium ; +47: ushort offsetSmall ; +48: } ; +49: +50: typedef struct PartDet +51: { BigEndian ( ) ; +52: WORD raw < format = binary > ; +53: LittleEndian ( ) ; +54: FSkip ( - 2 ) ; +55: BitfieldLeftToRight ( ) ; +56: YesNo hasConvDef : 1 ; +57: bit bitE : 1 < hidden = true > ; +58: bit bitD : 1 < hidden = true > ; +59: ubyte subparts : 5 ; +60: YesNo isGridArray : 1 ; +61: bit bit6 : 1 < hidden = true > ; +62: bit bit5 : 1 < hidden = true > ; +63: bit bit4 : 1 < hidden = true > ; +64: bit bit3 : 1 < hidden = true > ; +65: YesNo NormBitmap : 1 ; +66: YesNo ConvBitmap : 1 ; +67: bit bit0 : 1 < hidden = true > ; +68: } ; +69: +70: typedef struct PinDet +71: { BigEndian ( ) ; +72: WORD raw < format = binary > ; +73: LittleEndian ( ) ; +74: FSkip ( - 2 ) ; +75: BitfieldLeftToRight ( ) ; +76: YesNo vertical : 1 < hidden = true > ; ; +77: byte location : 7 ; +78: ptype type : 3 ; +79: YesNo isShort : 1 ; +80: YesNo hasDOT : 1 ; +81: YesNo hasCLK : 1 ; +82: bit bit1 : 1 < hidden = true > ; +83: pquad quadrant : 1 < hidden = true > ; +84: local pside side = quadrant + ( 2 * vertical ) ; +85: } ; +86: +87: typedef struct DefPart +88: { ushort Length < format = hex > ; +89: local ushort PartStart < format = hex , hidden = true > ; +90: local ushort PartEnd < format = hex , hidden = true > ; +91: local ushort NextPart < format = hex , hidden = true > ; +92: PartStart = FTell ( ) ; +93: PartEnd = PartStart + Length - 1 ; +94: NextPart = PartEnd + 1 ; +95: short sizeX < format = decimal > ; +96: short sizeY < format = decimal > ; +97: PartDet PartDetails ; +98: short PinsPerPart ; +99: WORD unknown1 < format = hex > ; +100: if ( PartDetails . NormBitmap == Yes ) +101: Offsets NormalBitmap ; +102: if ( PartDetails . ConvBitmap == Yes ) +103: { WORD unknown2 < format = hex > ; +104: Offsets ConvertBitmap ; +105: } ; +106: sText RefDesPrefix ; +107: typedef struct DefPin +108: { PinDet PinDetails ; +109: sText Name ; +110: if ( PartDetails . subparts > 0 ) +111: { if ( PartDetails . isGridArray == No ) +112: byte PinNumber [ PartDetails . subparts ] < optimize = false > ; +113: else sText PinNumber [ PartDetails . subparts ] < optimize = false > ; +114: } ; +115: } ; +116: if ( PinsPerPart > 0 ) +117: { DefPin NormalPin [ PinsPerPart ] < optimize = false > ; +118: if ( PartDetails . ConvBitmap == Yes ) +119: { j = 0 ; +120: while ( ( FTell ( ) < NextPart ) && ( j < PinsPerPart ) ) +121: { DefPin ConvertPin ; +122: j ++ ; +123: } +124: } +125: else j = PinsPerPart ; +126: } ; +127: if ( FTell ( ) < NextPart ) +128: { Printf ( " Part %i has orphaned pin definition(s).\n" , i ) ; +129: while ( FTell ( ) < NextPart ) DefPin orphanPin ; +130: } ; +131: if ( j < PinsPerPart ) +132: { Printf ( " Part %i has %i missing pin definition(s).\n" , i , PinsPerPart - j ) ; +133: FSkip ( NextPart - FTell ( ) ) ; +134: } ; +135: i ++ ; +136: } ; +137: +138: typedef struct BM +139: { ushort Length ; +140: ushort offsetVectormap ; +141: byte graphic [ Length - 2 ] < format = binary > ; +142: } ; +143: +144: typedef struct VM +145: { ushort Length ; +146: typedef struct VecDef +147: { Vtype Type ; +148: switch ( Type ) +149: { case END : break ; +150: case LINE : { Coord start ; +151: Coord finish ; break ; } +152: case CIRCLE : { Coord center ; +153: short radius ; break ; } +154: case TEXT : { Coord origin ; +155: ubyte size ; +156: sText text ; break ; } +157: case ARC : { Coord center ; +158: Coord start ; +159: Coord finish ; +160: short radius ; break ; } +161: case FILL : { Coord location ; break ; } +162: default : { Printf ( " Unknown vector type %i at 0x%X\n" , Type , FTell ( ) ) ; +163: return - 1 ; } +164: } ; +165: } ; +166: do VecDef Vector ; +167: while ( Vector . Type != END ) ; +168: } ; +169: +170: void SORTlist ( int start , int finish ) +171: { local int left = start ; +172: local int right = finish ; +173: local ushort pivot = list [ ( ( start + finish ) / 2 ) ] ; +174: local ushort temp ; +175: do +176: { while ( left <= right ) +177: { while ( list [ left ] < pivot ) left ++ ; +178: while ( list [ right ] > pivot ) right -- ; +179: if ( left <= right ) +180: { temp = list [ left ] ; list [ left ] = list [ right ] ; list [ right ] = temp ; +181: left ++ ; +182: right -- ; +183: } ; +184: } ; +185: if ( start < right ) SORTlist ( start , right ) ; +186: if ( left < finish ) SORTlist ( left , finish ) ; +187: } while ( left <= right ) ; +188: } ; +189: +190: +191: LittleEndian ( ) ; +192: +193: struct HeaderDef +194: { struct IDstring +195: { char text [ 14 ] ; +196: char term [ 3 ] ; +197: } head ; +198: if ( head . text != "LIBRARY OBJECT" ) +199: { Warning ( "\nFile is not an OrCAD library file.\n" ) ; +200: Exit ( - 1 ) ; +201: } ; +202: byte filler [ 8 ] ; +203: ushort IndexOffset ; +204: int idxLength < format = hex > ; +205: } HEADER ; +206: local int entries < hidden = true > ; +207: entries = HEADER . idxLength / 8 ; +208: local int parts < hidden = true > ; +209: parts = entries - 1 ; +210: local ushort list [ entries ] < hidden = true > ; +211: local int i < hidden = true > ; +212: local int j < hidden = true > ; +213: local int k < hidden = true > ; +214: +215: +216: struct IndexDef +217: { idxP Pointer [ entries ] < format = hex > ; +218: sText Name [ entries ] < format = hex , optimize = false > ; +219: } INDEX ; +220: for ( k = 0 ; k < entries ; k ++ ) +221: list [ k ] = INDEX . Pointer [ k ] . DefOffset ; +222: SORTlist ( 0 , parts ) ; +223: list [ parts ] = 0 ; +224: for ( i = 0 ; i < entries - 1 ; i ++ ) +225: { j = i + 1 ; +226: while ( ( list [ i ] == list [ j ] ) && ( j <= parts ) ) +227: j ++ ; +228: if ( ( j <= parts ) && ( j > i + 1 ) ) +229: while ( j > i + 1 ) +230: { for ( k = i + 1 ; k < parts ; k ++ ) +231: list [ k ] = list [ k + 1 ] ; +232: list [ k ] = 0 ; +233: j -- ; +234: parts -- ; +235: } ; +236: } ; +237: Printf ( "\nIndex has %i entries, %i distinct parts.\n" , entries , parts ) ; +238: +239: +240: struct PrefixDef +241: { DWORD unknown [ 16 ] < format = hex > ; +242: fTxt LEFT ( 7 ) [ 16 ] ; +243: fTxt RIGHT ( 7 ) [ 16 ] ; +244: } PREFIX ; +245: +246: +247: local uint PartSecStart < format = hex , hidden = true > ; +248: PartSecStart = FTell ( ) ; +249: ushort PartSectionLength < format = hex > ; +250: local uint PartSecEnd < format = hex , hidden = true > ; +251: PartSecEnd = FTell ( ) + PartSectionLength - 1 ; +252: Printf ( "Part section has %i bytes (0x%X-0x%X)\n" , PartSectionLength , PartSecStart , PartSecEnd ) ; +253: i = 0 ; +254: while ( FTell ( ) < PartSecEnd ) DefPart Part ; +255: +256: +257: local uint BitmapSecStart < format = hex , hidden = true > ; +258: BitmapSecStart = FTell ( ) ; +259: ushort BitmapSectionLength < format = hex > ; +260: local uint BitmapSecEnd < hidden = true > ; +261: BitmapSecEnd = FTell ( ) + BitmapSectionLength - 1 ; +262: Printf ( "Bitmap section has %i bytes (0x%X-0x%X)\n" , BitmapSectionLength , BitmapSecStart , BitmapSecEnd ) ; +263: while ( FTell ( ) < BitmapSecEnd ) BM Bitmap ; +264: +265: +266: local uint VecSecStart < format = hex , hidden = true > ; +267: VecSecStart = FTell ( ) ; +268: ushort VectorSectionLength < format = hex > ; +269: local uint VecSecEnd < hidden = true > ; +270: VecSecEnd = FTell ( ) + VectorSectionLength - 1 ; +271: Printf ( "Vector section has %i bytes (0x%X-0x%X)\n" , VectorSectionLength , VecSecStart , VecSecEnd ) ; +272: while ( FTell ( ) < VecSecEnd ) VM VectorSet ; +273: +274: +275: local uint SheetIndexStart < format = hex , hidden = true > ; +276: SheetIndexStart = FTell ( ) ; +277: Printf ( "Sheetpath index starts at 0x%X\n" , SheetIndexStart ) ; +278: ushort SheetpathIndex [ entries ] ; +279: +280: +281: ushort SheetSectionLength ; +282: local uint SheetSectionStart < format = hex , hidden = true > ; +283: SheetSectionStart = FTell ( ) ; +284: local uint SheetSecEnd < hidden = true > ; +285: SheetSecEnd = FTell ( ) + SheetSectionLength - 1 ; +286: Printf ( "Sheetpath section starts at 0x%X\n" , SheetSectionStart ) ; +287: while ( FTell ( ) < SheetSecEnd ) sText Sheetpath ; +288: +289: if ( ! FEof ( ) ) Printf ( "Found extra bytes at end of file." ) ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/OrCad3.20a_SCH.bt b/cparser/tests/exp_lex/OrCad3.20a_SCH.bt new file mode 100644 index 0000000..f79d986 --- /dev/null +++ b/cparser/tests/exp_lex/OrCad3.20a_SCH.bt @@ -0,0 +1,246 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: enum < ubyte > fType { BLOCK , WORKSHEET } ; +12: enum < ubyte > YesNo { no , yes } ; +13: enum < ubyte > paper { OrcadA , OrcadB , OrcadC , OrcadD , OrcadE } ; +14: enum < ubyte > rotate { none , CCW_90 , CCW_180 , CCW_270 } ; +15: enum < ubyte > primT { dwgDetails , sheet , part , line , bus , junction , modulePort , label , busEntry , dashedLine , powerSymbol , text , EndOfList = 0xF } ; +16: enum < ubyte > IOtype { UNSPEC , OUTPUT , INPUT , BIDIR } ; +17: enum < ubyte > Pstyle { block , pointL , pointR , pointLR } ; +18: enum < ubyte > side { left , right , top , bottom } ; +19: enum < ubyte > PStype { circle , arrow , bar , wave } ; +20: enum < ubyte > align { centered , just_left , just_right } ; +21: enum < ubyte > Btype { downleft , upleft } ; +22: +23: typedef byte bit ; +24: +25: typedef struct sText +26: { byte Length < hidden = true > ; +27: if ( Length > 0 ) char String [ Length ] ; +28: } ; +29: +30: typedef struct fTxt ( byte fixLen ) +31: { byte Length < hidden = true > ; +32: if ( Length > 0 ) char String [ Length ] ; +33: if ( ( fixLen > 0 ) && ( fixLen > Length ) ) char filler [ fixLen - Length ] ; +34: } ; +35: +36: typedef struct Coord +37: { short X ; +38: short Y ; +39: } ; +40: +41: typedef struct PartField +42: { Coord Location ; +43: sText Value ; +44: } ; +45: +46: typedef struct IDstring +47: { char text [ 14 ] ; +48: char terminator [ 3 ] ; +49: } ; +50: +51: typedef struct hdrDet +52: { IDstring head ; +53: if ( head . text != "Schematic FILE" ) +54: { Warning ( "File is not recognized as an OrCAD schematic file." ) ; +55: return - 1 ; +56: } +57: ubyte tail [ 5 ] ; +58: int primitiveSectionLength < format = hex > ; +59: Coord cursor ; +60: ushort zoom ; +61: } ; +62: +63: typedef struct pP00 +64: { ushort sheetNumber ; +65: ushort ofSheets ; +66: paper PaperSize ; +67: fTxt DocDate ( 12 ) ; +68: fTxt DocNumber ( 36 ) ; +69: fTxt RevNumber ( 3 ) ; +70: fTxt Title ( 44 ) ; +71: fTxt Organisation ( 44 ) ; +72: fTxt AddressLine ( 44 ) [ 4 ] < optimize = false > ; +73: } ; +74: +75: typedef struct pP01 +76: { local int i < hidden = true > ; +77: Coord Location ; +78: Coord Size ; +79: ubyte unknown [ 4 ] ; +80: ubyte Ports ; +81: sText FileName ; +82: sText SheetName ; +83: for ( i = 0 ; i < Ports ; i ++ ) +84: struct PortDef +85: { short NameXoffset ; +86: short PortYoffset ; +87: IOtype Type ; +88: sText Name ; +89: } Port ; +90: } ; +91: +92: typedef struct pP02 +93: { Coord Location ; +94: Coord RefDesLocation ; +95: Coord ValueLocation ; +96: struct PartDet1 +97: { ubyte raw < format = binary > ; +98: FSkip ( - 1 ) ; +99: BitfieldLeftToRight ( ) ; +100: YesNo mirror : 1 ; +101: rotate rotation : 2 ; +102: byte subpackage : 5 ; +103: } Details ; +104: struct PartDet2 +105: { BigEndian ( ) ; +106: ushort raw < format = binary > ; +107: LittleEndian ( ) ; +108: FSkip ( - 2 ) ; +109: BitfieldLeftToRight ( ) ; +110: bit bitF : 1 < hidden = true > ; +111: YesNo XtraFields : 1 ; +112: bit bitD : 1 < hidden = true > ; +113: bit bitC : 1 < hidden = true > ; +114: bit bitB : 1 < hidden = true > ; +115: YesNo HideValue : 1 ; +116: YesNo HideRefDes : 1 ; +117: bit bit8 : 1 < hidden = true > ; +118: YesNo HideField8 : 1 ; +119: YesNo HideField7 : 1 ; +120: YesNo HideField6 : 1 ; +121: YesNo HideField5 : 1 ; +122: YesNo HideField4 : 1 ; +123: YesNo HideField3 : 1 ; +124: YesNo HideField2 : 1 ; +125: YesNo HideField1 : 1 ; +126: } Visibility ; +127: ubyte unknown [ 13 ] < format = hex > ; +128: sText RefDes ; +129: sText PartValue ; +130: if ( Visibility . XtraFields == yes ) +131: PartField Xfield [ 8 ] < optimize = false > ; +132: } ; +133: +134: typedef struct pP03 +135: { Coord Start ; +136: Coord End ; +137: } ; +138: +139: typedef struct pP05 +140: { Coord Location ; +141: } ; +142: +143: typedef struct pP06 +144: { Coord Location ; +145: struct PortDet +146: { ubyte MinLength ; +147: ubyte raw < format = binary > ; +148: FSkip ( - 1 ) ; +149: BitfieldLeftToRight ( ) ; +150: IOtype PortType : 2 ; +151: Pstyle PortStyle : 2 ; +152: bit bit3 : 1 < hidden = true > ; +153: bit bit2 : 1 < hidden = true > ; +154: bit bit1 : 1 < hidden = true > ; +155: bit bit0 : 1 < hidden = true > ; +156: } Details ; +157: sText PortName ; +158: } ; +159: +160: typedef struct pP07 +161: { Coord Location ; +162: short rawSize < hidden = true > ; +163: local ushort Size = Abs ( rawSize ) ; +164: local YesNo Vertical = ( rawSize < 0 ) ; +165: sText Name ; +166: } ; +167: +168: typedef struct pP08 +169: { Coord Location ; +170: struct BusDet +171: { ubyte raw < format = binary > ; +172: FSkip ( - 1 ) ; +173: BitfieldLeftToRight ( ) ; +174: bit bit7 : 1 < hidden = true > ; +175: bit bit6 : 1 < hidden = true > ; +176: bit bit5 : 1 < hidden = true > ; +177: bit bit4 : 1 < hidden = true > ; +178: bit bit3 : 1 < hidden = true > ; +179: bit bit2 : 1 < hidden = true > ; +180: YesNo isBusType : 1 ; +181: Btype direction : 1 ; +182: } Details ; +183: } ; +184: +185: typedef struct pP0A +186: { Coord Location ; +187: struct PSDet +188: { ubyte raw < format = binary > ; +189: FSkip ( - 1 ) ; +190: BitfieldLeftToRight ( ) ; +191: bit bit7 : 1 < hidden = true > ; +192: bit bit6 : 1 < hidden = true > ; +193: bit bit5 : 1 < hidden = true > ; +194: bit bit4 : 1 < hidden = true > ; +195: side Orientation : 2 ; +196: PStype Shape : 2 ; +197: } Details ; +198: sText Name ; +199: } ; +200: +201: typedef struct Element +202: { primT Type < hidden = true > ; +203: ushort DataLength < hidden = true > ; +204: switch ( Type ) +205: { case 0x0 : { pP00 TITLE_BLOCK ; break ; } +206: case 0x1 : { pP01 SHEET ; break ; } +207: case 0x2 : { pP02 PART ; break ; } +208: case 0x3 : { pP03 LINE ; break ; } +209: case 0x4 : { pP03 BUS ; break ; } +210: case 0x5 : { pP05 JUNCTION ; break ; } +211: case 0x6 : { pP06 MOD_PORT ; break ; } +212: case 0x7 : { pP07 LABEL ; break ; } +213: case 0x8 : { pP08 BUS_ENTRY ; break ; } +214: case 0x9 : { pP03 DASH_LINE ; break ; } +215: case 0xA : { pP0A PWR_SYM ; break ; } +216: case 0xB : { pP07 TEXT ; break ; } +217: case 0xF : { break ; } +218: case 0x11 : { pP01 bSHEET ; break ; } +219: case 0x12 : { pP02 bPART ; break ; } +220: case 0x13 : { pP03 bLINE ; break ; } +221: case 0x14 : { pP03 bBUS ; break ; } +222: case 0x15 : { pP05 bJUNCTION ; break ; } +223: case 0x16 : { pP06 bMOD_PORT ; break ; } +224: case 0x17 : { pP07 bLABEL ; break ; } +225: case 0x18 : { pP08 bBUS_ENTRY ; break ; } +226: case 0x19 : { pP03 bDASH_LINE ; break ; } +227: case 0x1A : { pP0A bPWR_SYM ; break ; } +228: case 0x1B : { pP07 bTEXT ; break ; } +229: default : { Printf ( "Unknown primitive: %x, " , Type ) ; +230: return ( - 1 ) ; +231: } +232: } +233: } ; +234: +235: +236: +237: hdrDet HEADER ; +238: do +239: { Element primitive ; +240: } +241: while ( primitive . Type != EndOfList ) ; +242: +243: while ( ! FEof ( ) ) +244: { sText part ; +245: } +246: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/OscarItemTemplate.bt b/cparser/tests/exp_lex/OscarItemTemplate.bt new file mode 100644 index 0000000..c70adcd --- /dev/null +++ b/cparser/tests/exp_lex/OscarItemTemplate.bt @@ -0,0 +1,119 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: while ( ! FEof ( ) ) { +11: struct RECORD { +12: char type ; +13: if ( r . type == 'A' ) { +14: char unused < bgcolor = 0xFF0000 > ; +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 < bgcolor = 0xDDDD00 > ; +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 < bgcolor = 0xFF > ; +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 < bgcolor = 0xDDDD > ; +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 < bgcolor = 0x551A8B > ; +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 < bgcolor = 0xFF00 > ; +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 ] < bgcolor = 0xAAAAAA > ; +116: } } } } } } +117: } r ; +118: } +119: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/PALTemplate.bt b/cparser/tests/exp_lex/PALTemplate.bt new file mode 100644 index 0000000..42bd4b6 --- /dev/null +++ b/cparser/tests/exp_lex/PALTemplate.bt @@ -0,0 +1,45 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: typedef struct +16: { +17: uchar red ; +18: uchar green ; +19: uchar blue ; +20: uchar alpha ; +21: } RGBQUAD < read = ReadRGBQUAD > ; +22: +23: +24: +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: +35: char file_signature [ 4 ] ; +36: int file_length ; +37: char tag_type [ 4 ] ; +38: +39: +40: char chunk_signature [ 4 ] ; +41: int chunk_size ; +42: ushort version < format = hex > ; +43: ushort num_colors ; +44: RGBQUAD colors [ num_colors ] ; +45: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/PCAPTemplate.bt b/cparser/tests/exp_lex/PCAPTemplate.bt new file mode 100644 index 0000000..d4aef6e --- /dev/null +++ b/cparser/tests/exp_lex/PCAPTemplate.bt @@ -0,0 +1,187 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: typedef struct { +15: uint32 magic_number < format = hex > ; +16: if ( magic_number != 0xA1B2C3D4 ) { +17: Warning ( "Not a valid PCAP file" ) ; +18: return 1 ; +19: } +20: uint16 version_major ; +21: uint16 version_minor ; +22: int32 thiszone ; +23: uint32 sigfigs ; +24: uint32 snaplen ; +25: uint32 network ; +26: } PCAPHEADER ; +27: +28: typedef struct +29: { +30: uchar Byte [ 6 ] ; +31: } MACaddr < read = MACname > ; +32: +33: typedef struct +34: { +35: MACaddr DstMac < name = "Destination MAC" > ; +36: MACaddr SrcMac < name = "Source MAC" > ; +37: uint16 L3type < name = "Layer 3 Protocol" > ; +38: } Layer_2 < size = 14 > ; +39: +40: typedef struct +41: { +42: uchar Byte [ 4 ] ; +43: } IPv4addr < read = IPv4addrName > ; +44: +45: string IPv4addrName ( IPv4addr & IP ) +46: { +47: string strReturn ; +48: SPrintf ( strReturn , "%d.%d.%d.%d" , IP . Byte [ 0 ] , IP . Byte [ 1 ] , IP . Byte [ 2 ] , IP . Byte [ 3 ] ) ; +49: return strReturn ; +50: } +51: typedef struct ( uint16 proto_type ) +52: { +53: uchar version : 4 ; +54: uchar ip_hdr_len : 4 ; +55: local int hdr_length = ip_hdr_len * 4 ; +56: BYTE DiffServField ; +57: uint16 total_length ; +58: if ( proto_type == 0x800 ) +59: { +60: uint16 Identification ; +61: uint16 Flags ; +62: BYTE TTL ; +63: BYTE L4proto < name = "Layer 4 Protocol" , read = L4protoName > ; +64: uint16 HdrChecksum ; +65: IPv4addr SRC_IP < name = "Source IP" > ; +66: IPv4addr DST_IP < name = "Dest IP" > ; +67: } +68: else +69: { +70: BYTE Unknown [ hdr_length - 4 ] ; +71: } +72: } Layer_3 ; +73: +74: typedef struct ( ushort VER_HDR , uint16 total_length , uint L4proto ) +75: { +76: local uint16 ip_hdr_length = VER_HDR * 4 ; +77: +78: if ( L4proto == 0x11 ) +79: { +80: uint16 SrcPort < name = "Source Port" > ; +81: uint16 DstPort < name = "Destination Port" > ; +82: uint16 udp_hdr_len < name = "Datagram Length" > ; +83: uint16 ChkSum < name = "Checksum" > ; +84: } +85: else if ( L4proto == 0x6 ) +86: { +87: uint16 SrcPort < name = "Source Port" > ; +88: uint16 DstPort < name = "Destination Port" > ; +89: uint32 SEQ ; +90: uint32 ACK ; +91: uchar tcp_hdr_len : 4 ; +92: uchar Reserved : 4 ; +93: BYTE Crap [ tcp_hdr_len * 4 - 13 ] ; +94: } +95: else +96: { +97: BYTE packet [ total_length - ip_hdr_length ] < name = "Unknown Layer 4 Data" > ; +98: } +99: +100: } Layer_4 ; +101: +102: string L4protoName ( BYTE val ) +103: { +104: if ( val == 0x6 ) +105: { +106: return "TCP" ; +107: } +108: else if ( val == 0x11 ) +109: { +110: return "UDP" ; +111: } +112: else +113: { +114: return "Unknown" ; +115: } +116: } +117: +118: typedef struct { +119: time_t ts_sec ; +120: uint32 ts_usec ; +121: uint32 incl_len ; +122: uint32 orig_len ; +123: BigEndian ( ) ; +124: Layer_2 L2 < name = "Layer 2" > ; +125: Layer_3 L3 ( L2 . L3type ) < name = "Layer 3" > ; +126: Layer_4 L4 ( L3 . ip_hdr_len , L3 . total_length , L3 . L4proto ) < name = "Layer 4" > ; +127: +128: if ( L3 . L4proto == 0x6 ) +129: { +130: local uint16 AppDataLen = L3 . total_length - L3 . ip_hdr_len * 4 - L4 . tcp_hdr_len * 4 ; +131: if ( AppDataLen > 0 ) +132: { +133: BYTE AppData [ AppDataLen ] < name = "TCP Application Data" > ; +134: } +135: } +136: else if ( L3 . L4proto == 0x11 ) +137: { +138: local uint AppDataLen = L4 . udp_hdr_len - 8 ; +139: if ( AppDataLen > 0 ) +140: { +141: BYTE AppData [ AppDataLen ] < name = "UDP Application Data" > ; +142: } +143: } +144: LittleEndian ( ) ; +145: } PCAPRECORD < read = ReadPCAPRECORD , comment = PCAPcomments > ; +146: +147: string PCAPcomments ( PCAPRECORD & P ) +148: { +149: local uint16 L4_proto = P . L3 . L4proto ; +150: string strReturn ; +151: local uint16 AppDataLen = 0 ; +152: if ( L4_proto == 0x6 ) +153: { +154: AppDataLen = P . L3 . total_length - P . L3 . ip_hdr_len * 4 - P . L4 . tcp_hdr_len * 4 ; +155: } +156: else if ( L4_proto == 0x11 ) +157: { +158: AppDataLen = P . L4 . udp_hdr_len - 8 ; +159: } +160: SPrintf ( strReturn , "%s:%d -> %s:%d %s %s" , IPv4addrName ( P . L3 . SRC_IP ) , P . L4 . SrcPort , IPv4addrName ( P . L3 . DST_IP ) , P . L4 . DstPort , L4protoName ( L4_proto ) , AppDataLen > 0 ? "***" : "" ) ; +161: return strReturn ; +162: } +163: string ReadPCAPRECORD ( PCAPRECORD & record ) +164: { +165: string strReturn ; +166: +167: SPrintf ( strReturn , "%s.%06u" , TimeTToString ( record . ts_sec ) , record . ts_usec ) ; +168: return strReturn ; +169: } +170: +171: string MACname ( MACaddr & addr ) +172: { +173: string strReturn ; +174: SPrintf ( strReturn , "%.02x:%.02x:%.02x:%.02x:%.02x:%.02x" , addr . Byte [ 0 ] , addr . Byte [ 1 ] , addr . Byte [ 2 ] , addr . Byte [ 3 ] , addr . Byte [ 4 ] , addr . Byte [ 5 ] ) ; +175: return strReturn ; +176: } +177: +178: +179: LittleEndian ( ) ; +180: PCAPHEADER header ; +181: +182: while ( ! FEof ( ) ) +183: { +184: PCAPRECORD record < name = "Frame" > ; +185: +186: } +187: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/PCXTemplate.bt b/cparser/tests/exp_lex/PCXTemplate.bt new file mode 100644 index 0000000..6407cd8 --- /dev/null +++ b/cparser/tests/exp_lex/PCXTemplate.bt @@ -0,0 +1,40 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: enum < ubyte > PCX_TYPE { +11: v25 = 0 , +12: v28Pal = 2 , +13: v28 = 3 , +14: v5Win = 4 , +15: v3up = 5 +16: } ; +17: +18: struct PCX { +19: ubyte Manufacturer ; +20: PCX_TYPE version ; +21: ubyte encoding ; +22: ubyte BitsPerPixel ; +23: ushort Xmin ; +24: ushort Ymin ; +25: ushort Xmax ; +26: ushort Ymax ; +27: ushort HDpi ; +28: ushort VDpi ; +29: ubyte Colormap [ 48 ] ; +30: ubyte Reserved ; +31: ubyte NPlanes ; +32: ushort BytesPerLine ; +33: ushort PaletteInfo ; +34: ushort HscreenSize ; +35: ushort VscreenSize ; +36: ubyte Filler [ 54 ] ; +37: } ; +38: +39: PCX file ; +40: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/PDFTemplate.bt b/cparser/tests/exp_lex/PDFTemplate.bt new file mode 100644 index 0000000..04c9832 --- /dev/null +++ b/cparser/tests/exp_lex/PDFTemplate.bt @@ -0,0 +1,566 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: +21: +22: +23: +24: +25: +26: +27: +28: +29: local int iCOLOR = 0x95E8FF ; +30: +31: enum int { TYPE_UNKNOWN , TYPE_HEADER , TYPE_TRAILER , TYPE_OBJ , TYPE_ENDOBJ } ; +32: +33: +34: +35: local int iKeywordCount ; +36: local int iStructureCount ; +37: local TFindResults tfrHeaders ; +38: local TFindResults tfrTrailers ; +39: local TFindResults tfrObjs ; +40: local TFindResults tfrEndobjs ; +41: +42: local int iPDFHeaderCount = 0 ; +43: local int iPDFTrailerCount = 0 ; +44: local int iPDFUnknownCount = 0 ; +45: local int iPDFCommentCount = 0 ; +46: local int iPDFWhitespaceCount = 0 ; +47: local int iPDFXrefCount = 0 ; +48: local int iPDFObjectCount = 0 ; +49: +50: +51: +52: local int iIndexLength ; +53: local int iWhiteSpace1Length ; +54: local int iVersionLength ; +55: local int iWhiteSpace2Length ; +56: local int iDataLength ; +57: local int iFoundEndobj ; +58: local int iWhiteSpace3Length ; +59: typedef struct { +60: BYTE Index [ iIndexLength ] ; +61: BYTE WhiteSpace1 [ iWhiteSpace1Length ] ; +62: BYTE Version [ iVersionLength ] ; +63: BYTE WhiteSpace2 [ iWhiteSpace2Length ] ; +64: BYTE Object [ 3 ] ; +65: BYTE Data [ iDataLength ] ; +66: if ( iFoundEndobj ) +67: BYTE EndObject [ 6 ] ; +68: BYTE WhiteSpace3 [ iWhiteSpace3Length ] ; +69: } PDFObj < read = ReadPDFObj > ; +70: +71: string ReadPDFObj ( PDFObj & sPDFObj ) +72: { +73: local string sResult ; +74: SPrintf ( sResult , "%s %s obj %s" , sPDFObj . Index , sPDFObj . Version , sPDFObj . Data ) ; +75: return sResult ; +76: } +77: +78: local int iHeaderSize ; +79: typedef struct { +80: BYTE Header [ iHeaderSize ] ; +81: } PDFHeader ; +82: +83: local int iTrailerSize ; +84: typedef struct { +85: BYTE Trailer [ iTrailerSize ] ; +86: } PDFTrailer ; +87: +88: local int iUnknownSize ; +89: typedef struct { +90: BYTE Data [ iUnknownSize ] ; +91: } PDFUnknown ; +92: +93: local int iCommentSize ; +94: typedef struct { +95: BYTE Comment [ iCommentSize ] ; +96: } PDFComment ; +97: +98: local int iWhitespaceSize ; +99: typedef struct { +100: BYTE Whitespace [ iWhitespaceSize ] ; +101: } PDFWhitespace ; +102: +103: local int iXrefSize ; +104: typedef struct { +105: BYTE Data [ iXrefSize ] ; +106: } PDFXref ; +107: +108: +109: +110: int64 FindStartOfObj ( int64 iStart , int & iIndexLength , int & iWhiteSpace1Length , int & iVersionLength , int & iWhiteSpace2Length ) +111: { +112: local int iIter ; +113: local BYTE bChar ; +114: local int64 iIndex ; +115: local int64 iStartIndex = - 1 ; +116: local int64 iEndIndex = - 1 ; +117: local int64 iStartVersion = - 1 ; +118: local int64 iEndVersion = - 1 ; +119: +120: for ( iIter = 1 ; iIter <= 20 ; iIter ++ ) +121: { +122: iIndex = iStart - iIter ; +123: if ( iIndex < 0 ) +124: break ; +125: bChar = ReadByte ( iIndex ) ; +126: if ( iEndVersion == - 1 ) +127: { +128: if ( bChar == ' ' ) +129: ; +130: else if ( bChar >= '0' && bChar <= '9' ) +131: iEndVersion = iIndex ; +132: else +133: break ; +134: } +135: else if ( iStartVersion == - 1 ) +136: { +137: if ( bChar >= '0' && bChar <= '9' ) +138: ; +139: else if ( bChar == ' ' ) +140: iStartVersion = iIndex + 1 ; +141: else +142: break ; +143: } +144: else if ( iEndIndex == - 1 ) +145: { +146: if ( bChar == ' ' ) +147: ; +148: else if ( bChar >= '0' && bChar <= '9' ) +149: iEndIndex = iIndex ; +150: else +151: break ; +152: } +153: else if ( iStartIndex == - 1 ) +154: { +155: if ( bChar < '0' || bChar > '9' ) +156: { +157: iStartIndex = iIndex + 1 ; +158: break ; +159: } +160: } +161: } +162: +163: if ( iEndIndex != - 1 && iStartVersion != - 1 && iEndVersion != - 1 ) +164: { +165: if ( iStartIndex == - 1 ) +166: { +167: if ( iIndex == - 1 ) +168: iStartIndex = 0 ; +169: else +170: return - 1 ; +171: } +172: iIndexLength = iEndIndex - iStartIndex + 1 ; +173: iWhiteSpace1Length = iStartVersion - iEndIndex - 1 ; +174: iVersionLength = iEndVersion - iStartVersion + 1 ; +175: iWhiteSpace2Length = iStart - iEndVersion ; +176: return iStartIndex ; +177: } +178: else +179: return - 1 ; +180: } +181: +182: int64 FindEOL ( int64 iStart ) +183: { +184: local int64 iIter ; +185: for ( iIter = iStart ; iIter < FileSize ( ) ; iIter ++ ) +186: if ( ReadByte ( iIter ) == 0xD && iIter + 1 < FileSize ( ) && ReadByte ( iIter + 1 ) == 0xA ) +187: return iIter + 1 ; +188: else if ( ReadByte ( iIter ) == 0xD || ReadByte ( iIter ) == 0xA ) +189: return iIter ; +190: return - 1 ; +191: } +192: +193: void FindAllKeywords ( void ) +194: { +195: tfrHeaders = FindAll ( "%PDF" ) ; +196: tfrTrailers = FindAll ( "%%EOF" ) ; +197: tfrObjs = FindAll ( " obj" ) ; +198: tfrEndobjs = FindAll ( "endobj" ) ; +199: iKeywordCount = tfrHeaders . count + tfrTrailers . count + tfrObjs . count + tfrEndobjs . count ; +200: } +201: +202: int MergeKeywords ( int iMerge1Size , int iMerge2Size ) +203: { +204: local int64 iIndex1 = 0 ; +205: local int64 iIndex2 = 0 ; +206: local int64 iIndex3 = 0 ; +207: +208: while ( true ) +209: { +210: if ( iIndex1 == iMerge1Size ) +211: { +212: while ( iIndex2 < iMerge2Size ) +213: { +214: aiMerge3KeywordType [ iIndex3 ] = aiMerge2KeywordType [ iIndex2 ] ; +215: aiMerge3KeywordStart [ iIndex3 ] = aiMerge2KeywordStart [ iIndex2 ] ; +216: aiMerge3KeywordSize [ iIndex3 ] = aiMerge2KeywordSize [ iIndex2 ] ; +217: iIndex2 ++ ; +218: iIndex3 ++ ; +219: } +220: break ; +221: } +222: if ( iIndex2 == iMerge2Size ) +223: { +224: while ( iIndex1 < iMerge1Size ) +225: { +226: aiMerge3KeywordType [ iIndex3 ] = aiMerge1KeywordType [ iIndex1 ] ; +227: aiMerge3KeywordStart [ iIndex3 ] = aiMerge1KeywordStart [ iIndex1 ] ; +228: aiMerge3KeywordSize [ iIndex3 ] = aiMerge1KeywordSize [ iIndex1 ] ; +229: iIndex1 ++ ; +230: iIndex3 ++ ; +231: } +232: break ; +233: } +234: if ( aiMerge1KeywordStart [ iIndex1 ] < aiMerge2KeywordStart [ iIndex2 ] ) +235: { +236: aiMerge3KeywordType [ iIndex3 ] = aiMerge1KeywordType [ iIndex1 ] ; +237: aiMerge3KeywordStart [ iIndex3 ] = aiMerge1KeywordStart [ iIndex1 ] ; +238: aiMerge3KeywordSize [ iIndex3 ] = aiMerge1KeywordSize [ iIndex1 ] ; +239: iIndex1 ++ ; +240: iIndex3 ++ ; +241: } +242: else +243: { +244: aiMerge3KeywordType [ iIndex3 ] = aiMerge2KeywordType [ iIndex2 ] ; +245: aiMerge3KeywordStart [ iIndex3 ] = aiMerge2KeywordStart [ iIndex2 ] ; +246: aiMerge3KeywordSize [ iIndex3 ] = aiMerge2KeywordSize [ iIndex2 ] ; +247: iIndex2 ++ ; +248: iIndex3 ++ ; +249: } +250: } +251: for ( iIndex1 = 0 ; iIndex1 < iMerge1Size + iMerge2Size ; iIndex1 ++ ) +252: { +253: aiMerge1KeywordType [ iIndex1 ] = aiMerge3KeywordType [ iIndex1 ] ; +254: aiMerge1KeywordStart [ iIndex1 ] = aiMerge3KeywordStart [ iIndex1 ] ; +255: aiMerge1KeywordSize [ iIndex1 ] = aiMerge3KeywordSize [ iIndex1 ] ; +256: } +257: return iMerge1Size + iMerge2Size ; +258: } +259: +260: void MergeAndFilterAllKeywords ( void ) +261: { +262: local int iIter ; +263: local int iIter2 ; +264: local int iTempCount ; +265: +266: for ( iIter = 0 ; iIter < tfrHeaders . count ; iIter ++ ) +267: { +268: aiMerge1KeywordType [ iIter ] = TYPE_HEADER ; +269: aiMerge1KeywordStart [ iIter ] = tfrHeaders . start [ iIter ] ; +270: aiMerge1KeywordSize [ iIter ] = tfrHeaders . size [ iIter ] ; +271: } +272: for ( iIter = 0 ; iIter < tfrTrailers . count ; iIter ++ ) +273: { +274: aiMerge2KeywordType [ iIter ] = TYPE_TRAILER ; +275: aiMerge2KeywordStart [ iIter ] = tfrTrailers . start [ iIter ] ; +276: aiMerge2KeywordSize [ iIter ] = tfrTrailers . size [ iIter ] ; +277: } +278: iTempCount = MergeKeywords ( tfrHeaders . count , tfrTrailers . count ) ; +279: iIter2 = 0 ; +280: for ( iIter = 0 ; iIter < tfrObjs . count ; iIter ++ ) +281: { +282: if ( - 1 != FindStartOfObj ( tfrObjs . start [ iIter ] , iIndexLength , iWhiteSpace1Length , iVersionLength , iWhiteSpace2Length ) ) +283: { +284: aiMerge2KeywordType [ iIter2 ] = TYPE_OBJ ; +285: aiMerge2KeywordStart [ iIter2 ] = tfrObjs . start [ iIter ] ; +286: aiMerge2KeywordSize [ iIter2 ] = tfrObjs . size [ iIter ] ; +287: iIter2 ++ ; +288: } +289: } +290: iTempCount = MergeKeywords ( iTempCount , iIter2 ) ; +291: for ( iIter = 0 ; iIter < tfrEndobjs . count ; iIter ++ ) +292: { +293: aiMerge2KeywordType [ iIter ] = TYPE_ENDOBJ ; +294: aiMerge2KeywordStart [ iIter ] = tfrEndobjs . start [ iIter ] ; +295: aiMerge2KeywordSize [ iIter ] = tfrEndobjs . size [ iIter ] ; +296: } +297: iKeywordCount = MergeKeywords ( iTempCount , tfrEndobjs . count ) ; +298: } +299: +300: int CalculateSizeWithEOL ( int64 iStart ) +301: { +302: local int64 iIndexEOL ; +303: +304: iIndexEOL = FindEOL ( iStart ) ; +305: if ( iIndexEOL == - 1 ) +306: return - 1 ; +307: else +308: return iIndexEOL - iStart + 1 ; +309: } +310: +311: void PrepareStructures ( void ) +312: { +313: local int iIter ; +314: local int64 iEndPreviousStructure = 0 ; +315: local int iSize ; +316: local int64 iStartIndirectObject ; +317: local BYTE bRead ; +318: local int iWhitespaceCount ; +319: iStructureCount = 0 ; +320: +321: for ( iIter = 0 ; iIter < iKeywordCount ; iIter ++ ) +322: { +323: if ( aiMerge1KeywordType [ iIter ] == TYPE_OBJ ) +324: iStartIndirectObject = FindStartOfObj ( aiMerge1KeywordStart [ iIter ] , iIndexLength , iWhiteSpace1Length , iVersionLength , iWhiteSpace2Length ) ; +325: else +326: iStartIndirectObject = aiMerge1KeywordStart [ iIter ] ; +327: +328: if ( iStartIndirectObject != iEndPreviousStructure && aiMerge1KeywordType [ iIter ] != TYPE_ENDOBJ ) +329: { +330: aiStructureType [ iStructureCount ] = TYPE_UNKNOWN ; +331: aiStructureStart [ iStructureCount ] = iEndPreviousStructure ; +332: aiStructureSize [ iStructureCount ] = iStartIndirectObject - iEndPreviousStructure ; +333: iStructureCount ++ ; +334: } +335: +336: if ( aiMerge1KeywordType [ iIter ] == TYPE_HEADER ) +337: { +338: iSize = CalculateSizeWithEOL ( aiMerge1KeywordStart [ iIter ] ) ; +339: if ( iSize == - 1 ) +340: iSize = aiMerge1KeywordSize [ iIter ] ; +341: aiStructureType [ iStructureCount ] = TYPE_HEADER ; +342: aiStructureStart [ iStructureCount ] = aiMerge1KeywordStart [ iIter ] ; +343: aiStructureSize [ iStructureCount ] = iSize ; +344: iEndPreviousStructure = aiStructureStart [ iStructureCount ] + aiStructureSize [ iStructureCount ] ; +345: iStructureCount ++ ; +346: } +347: else if ( aiMerge1KeywordType [ iIter ] == TYPE_TRAILER ) +348: { +349: iSize = CalculateSizeWithEOL ( aiMerge1KeywordStart [ iIter ] ) ; +350: if ( iSize == - 1 ) +351: iSize = aiMerge1KeywordSize [ iIter ] ; +352: aiStructureType [ iStructureCount ] = TYPE_TRAILER ; +353: aiStructureStart [ iStructureCount ] = aiMerge1KeywordStart [ iIter ] ; +354: aiStructureSize [ iStructureCount ] = iSize ; +355: iEndPreviousStructure = aiStructureStart [ iStructureCount ] + aiStructureSize [ iStructureCount ] ; +356: iStructureCount ++ ; +357: } +358: else if ( aiMerge1KeywordType [ iIter ] == TYPE_OBJ ) +359: { +360: iSize = aiMerge1KeywordStart [ iIter + 1 ] - iStartIndirectObject ; +361: if ( aiMerge1KeywordType [ iIter + 1 ] == TYPE_ENDOBJ ) +362: iSize += 6 ; +363: iWhitespaceCount = 0 ; +364: bRead = ReadByte ( iStartIndirectObject + iSize ) ; +365: while ( bRead == 0xD || bRead == 0xA || bRead == 0x20 ) +366: { +367: iWhitespaceCount ++ ; +368: bRead = ReadByte ( iStartIndirectObject + iSize + iWhitespaceCount ) ; +369: } +370: iSize += iWhitespaceCount ; +371: aiStructureType [ iStructureCount ] = TYPE_OBJ ; +372: aiStructureStart [ iStructureCount ] = iStartIndirectObject ; +373: aiStructureSize [ iStructureCount ] = iSize ; +374: aiStructureExtraParameter1 [ iStructureCount ] = iIndexLength ; +375: aiStructureExtraParameter2 [ iStructureCount ] = iWhiteSpace1Length ; +376: aiStructureExtraParameter3 [ iStructureCount ] = iVersionLength ; +377: aiStructureExtraParameter4 [ iStructureCount ] = iWhiteSpace2Length ; +378: aiStructureExtraParameter5 [ iStructureCount ] = aiMerge1KeywordType [ iIter + 1 ] == TYPE_ENDOBJ ; +379: aiStructureExtraParameter6 [ iStructureCount ] = iWhitespaceCount ; +380: iEndPreviousStructure = aiStructureStart [ iStructureCount ] + aiStructureSize [ iStructureCount ] ; +381: iStructureCount ++ ; +382: } +383: } +384: +385: +386: if ( FileSize ( ) - aiStructureStart [ iStructureCount - 1 ] - aiStructureSize [ iStructureCount - 1 ] != 0 ) +387: { +388: aiStructureType [ iStructureCount ] = TYPE_UNKNOWN ; +389: aiStructureStart [ iStructureCount ] = aiStructureStart [ iStructureCount - 1 ] + aiStructureSize [ iStructureCount - 1 ] ; +390: aiStructureSize [ iStructureCount ] = FileSize ( ) - aiStructureStart [ iStructureCount - 1 ] - aiStructureSize [ iStructureCount - 1 ] ; +391: iStructureCount ++ ; +392: } +393: } +394: +395: void CreatePDFHeader ( int64 iStart , int iSize ) +396: { +397: iPDFHeaderCount ++ ; +398: FSeek ( iStart ) ; +399: iHeaderSize = iSize ; +400: PDFHeader sPDFHeader ; +401: } +402: +403: void CreatePDFTrailer ( int64 iStart , int iSize ) +404: { +405: iPDFTrailerCount ++ ; +406: FSeek ( iStart ) ; +407: iTrailerSize = iSize ; +408: PDFTrailer sPDFTrailer ; +409: } +410: +411: void CreatePDFUnknown ( int64 iStart , int iSize ) +412: { +413: iPDFUnknownCount ++ ; +414: FSeek ( iStart ) ; +415: iUnknownSize = iSize ; +416: PDFUnknown sPDFUnknown ; +417: } +418: +419: void CreatePDFComment ( int64 iStart , int iSize ) +420: { +421: iPDFCommentCount ++ ; +422: FSeek ( iStart ) ; +423: iCommentSize = iSize ; +424: PDFComment sPDFComment ; +425: } +426: +427: int IsWhitespace ( int64 iStart , int iSize ) +428: { +429: local int64 iIter ; +430: local BYTE bRead ; +431: +432: for ( iIter = iStart ; iIter < iStart + iSize ; iIter ++ ) +433: { +434: bRead = ReadByte ( iIter ) ; +435: if ( bRead != 0x9 && bRead != 0xA && bRead != 0xD && bRead != 0x20 ) +436: return false ; +437: } +438: return true ; +439: } +440: +441: void CreatePDFWhitespace ( int64 iStart , int iSize ) +442: { +443: iPDFWhitespaceCount ++ ; +444: FSeek ( iStart ) ; +445: iWhitespaceSize = iSize ; +446: PDFWhitespace sPDFWhitespace ; +447: } +448: +449: int StartsWith ( int64 iStart , int iSize , string sData ) +450: { +451: local int64 iIter ; +452: +453: if ( Strlen ( sData ) > iSize ) +454: return false ; +455: +456: for ( iIter = 0 ; iIter < Strlen ( sData ) ; iIter ++ ) +457: if ( ReadByte ( iStart + iIter ) != sData [ iIter ] ) +458: return false ; +459: return true ; +460: } +461: +462: void CreatePDFXref ( int64 iStart , int iSize ) +463: { +464: iPDFXrefCount ++ ; +465: FSeek ( iStart ) ; +466: iXrefSize = iSize ; +467: PDFXref sPDFXref ; +468: } +469: +470: void CreatePDFObject ( int64 iStart , int iSize , int iIndexLengthArg , int iWhiteSpace1LengthArg , int iVersionLengthArg , int iWhiteSpace2LengthArg , int iFoundEndobjArg , int iWhiteSpace3LengthArg ) +471: { +472: iPDFObjectCount ++ ; +473: iIndexLength = iIndexLengthArg ; +474: iWhiteSpace1Length = iWhiteSpace1LengthArg ; +475: iVersionLength = iVersionLengthArg ; +476: iWhiteSpace2Length = iWhiteSpace2LengthArg ; +477: iFoundEndobj = iFoundEndobjArg ; +478: iWhiteSpace3Length = iWhiteSpace3LengthArg ; +479: FSeek ( iStart ) ; +480: iDataLength = iSize - iIndexLength - iWhiteSpace1Length - iVersionLength - iWhiteSpace2Length - 6 - 3 - iWhiteSpace3LengthArg ; +481: PDFObj sPDFObj ; +482: } +483: +484: local int iToggleColor = iCOLOR ; +485: void ToggleBackColor ( ) +486: { +487: if ( iToggleColor == iCOLOR ) +488: iToggleColor = cNone ; +489: else +490: iToggleColor = iCOLOR ; +491: SetBackColor ( iToggleColor ) ; +492: } +493: +494: void CreatePDFStructures ( void ) +495: { +496: local int iIter ; +497: for ( iIter = 0 ; iIter < iStructureCount ; iIter ++ ) +498: { +499: ToggleBackColor ( ) ; +500: if ( aiStructureType [ iIter ] == TYPE_UNKNOWN && StartsWith ( aiStructureStart [ iIter ] , aiStructureSize [ iIter ] , "%" ) ) +501: CreatePDFComment ( aiStructureStart [ iIter ] , aiStructureSize [ iIter ] ) ; +502: else if ( aiStructureType [ iIter ] == TYPE_UNKNOWN && StartsWith ( aiStructureStart [ iIter ] , aiStructureSize [ iIter ] , "xref" ) ) +503: CreatePDFXref ( aiStructureStart [ iIter ] , aiStructureSize [ iIter ] ) ; +504: else if ( aiStructureType [ iIter ] == TYPE_UNKNOWN && IsWhitespace ( aiStructureStart [ iIter ] , aiStructureSize [ iIter ] ) ) +505: CreatePDFWhitespace ( aiStructureStart [ iIter ] , aiStructureSize [ iIter ] ) ; +506: else if ( aiStructureType [ iIter ] == TYPE_UNKNOWN ) +507: CreatePDFUnknown ( aiStructureStart [ iIter ] , aiStructureSize [ iIter ] ) ; +508: else if ( aiStructureType [ iIter ] == TYPE_HEADER ) +509: CreatePDFHeader ( aiStructureStart [ iIter ] , aiStructureSize [ iIter ] ) ; +510: else if ( aiStructureType [ iIter ] == TYPE_TRAILER ) +511: CreatePDFTrailer ( aiStructureStart [ iIter ] , aiStructureSize [ iIter ] ) ; +512: else if ( aiStructureType [ iIter ] == TYPE_OBJ ) +513: CreatePDFObject ( aiStructureStart [ iIter ] , aiStructureSize [ iIter ] , aiStructureExtraParameter1 [ iIter ] , aiStructureExtraParameter2 [ iIter ] , aiStructureExtraParameter3 [ iIter ] , aiStructureExtraParameter4 [ iIter ] , aiStructureExtraParameter5 [ iIter ] , aiStructureExtraParameter6 [ iIter ] ) ; +514: } +515: SetBackColor ( cNone ) ; +516: } +517: +518: void PrintPDFCounters ( void ) +519: { +520: Printf ( "Structure counts:\n" ) ; +521: Printf ( " PDFHeader = %5d\n" , iPDFHeaderCount ) ; +522: Printf ( " PDFTrailer = %5d\n" , iPDFTrailerCount ) ; +523: Printf ( " PDFObject = %5d\n" , iPDFObjectCount ) ; +524: Printf ( " PDFComment = %5d\n" , iPDFCommentCount ) ; +525: Printf ( " PDFXref = %5d\n" , iPDFXrefCount ) ; +526: Printf ( " PDFWhitespace = %5d\n" , iPDFWhitespaceCount ) ; +527: Printf ( " PDFUnknown = %5d\n" , iPDFUnknownCount ) ; +528: } +529: +530: +531: +532: FindAllKeywords ( ) ; +533: if ( iKeywordCount == 0 ) +534: { +535: Printf ( "Keywords not found, not a PDF file!\n" ) ; +536: return ; +537: } +538: +539: local int aiMerge1KeywordType [ iKeywordCount ] ; +540: local int64 aiMerge1KeywordStart [ iKeywordCount ] ; +541: local int aiMerge1KeywordSize [ iKeywordCount ] ; +542: local int aiMerge2KeywordType [ iKeywordCount ] ; +543: local int64 aiMerge2KeywordStart [ iKeywordCount ] ; +544: local int aiMerge2KeywordSize [ iKeywordCount ] ; +545: local int aiMerge3KeywordType [ iKeywordCount ] ; +546: local int64 aiMerge3KeywordStart [ iKeywordCount ] ; +547: local int aiMerge3KeywordSize [ iKeywordCount ] ; +548: +549: MergeAndFilterAllKeywords ( ) ; +550: +551: local int aiStructureType [ iKeywordCount * 2 + 1 ] ; +552: local int64 aiStructureStart [ iKeywordCount * 2 + 1 ] ; +553: local int aiStructureSize [ iKeywordCount * 2 + 1 ] ; +554: local int aiStructureExtraParameter1 [ iKeywordCount * 2 + 1 ] ; +555: local int aiStructureExtraParameter2 [ iKeywordCount * 2 + 1 ] ; +556: local int aiStructureExtraParameter3 [ iKeywordCount * 2 + 1 ] ; +557: local int aiStructureExtraParameter4 [ iKeywordCount * 2 + 1 ] ; +558: local int aiStructureExtraParameter5 [ iKeywordCount * 2 + 1 ] ; +559: local int aiStructureExtraParameter6 [ iKeywordCount * 2 + 1 ] ; +560: +561: PrepareStructures ( ) ; +562: +563: CreatePDFStructures ( ) ; +564: +565: PrintPDFCounters ( ) ; +566: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/PETemplate.bt b/cparser/tests/exp_lex/PETemplate.bt new file mode 100644 index 0000000..345947d --- /dev/null +++ b/cparser/tests/exp_lex/PETemplate.bt @@ -0,0 +1,821 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: typedef QWORD ULONGLONG ; +18: +19: typedef struct _IMAGE_DOS_HEADER +20: { +21: WORD e_magic < format = hex , comment = "IMAGE_DOS_SIGNATURE = 0x5A4D" > ; +22: WORD e_cblp < comment = "Bytes on last page of file" > ; +23: WORD e_cp < comment = "Pages in file" > ; +24: WORD e_crlc < comment = "Relocations" > ; +25: WORD e_cparhdr < comment = "Size of header in paragraphs" > ; +26: WORD e_minalloc < comment = "Minimum extra paragraphs needed" > ; +27: WORD e_maxalloc < comment = "Maximum extra paragraphs needed" > ; +28: WORD e_ss < comment = "Initial (relative) SS value" > ; +29: WORD e_sp < comment = "Initial SP value" > ; +30: WORD e_csum < comment = "Checksum" > ; +31: WORD e_ip < comment = "Initial IP value" > ; +32: WORD e_cs < comment = "Initial (relative) CS value" > ; +33: WORD e_lfarlc < comment = "File address of relocation table" > ; +34: WORD e_ovno < comment = "Overlay number" > ; +35: WORD e_res [ 4 ] < comment = "Reserved words" > ; +36: WORD e_oemid < comment = "OEM identifier (for e_oeminfo)" > ; +37: WORD e_oeminfo < comment = "OEM information; e_oemid specific" > ; +38: WORD e_res2 [ 10 ] < comment = "Reserved words" > ; +39: LONG e_lfanew < fgcolor = cPurple , format = hex , comment = "NtHeader Offset" > ; +40: } IMAGE_DOS_HEADER ; +41: +42: typedef enum < WORD > _IMAGE_MACHINE +43: { +44: IMAGE_MACHINE_UNKNOWN = 0 , +45: I386 = 0x14C , +46: R3000 = 0x162 , +47: R4000 = 0x166 , +48: R10000 = 0x168 , +49: WCEMIPSV2 = 0x169 , +50: ALPHA = 0x184 , +51: SH3 = 0x1A2 , +52: SH3DSP = 0x1A3 , +53: SH3E = 0x1A4 , +54: SH4 = 0x1A6 , +55: SH5 = 0x1A8 , +56: ARM = 0x1C0 , +57: THUMB = 0x1C2 , +58: AM33 = 0x1D3 , +59: POWERPC = 0x1F0 , +60: POWERPCFP = 0x1F1 , +61: IA64 = 0x200 , +62: MIPS16 = 0x266 , +63: ALPHA64 = 0x284 , +64: MIPSFPU = 0x366 , +65: MIPSFPU16 = 0x466 , +66: TRICORE = 0x520 , +67: CEF = 0xCEF , +68: EBC = 0xEBC , +69: AMD64 = 0x8664 , +70: M32R = 0x9041 , +71: CEE = 0xC0EE +72: } IMAGE_MACHINE < comment = "WORD" > ; +73: +74: +75: typedef struct _FILE_CHARACTERISTICS +76: { +77: WORD IMAGE_FILE_RELOCS_STRIPPED : 1 < comment = "0x0001 Relocation info stripped from file" > ; +78: WORD IMAGE_FILE_EXECUTABLE_IMAGE : 1 < comment = "0x0002 File is executable" > ; +79: WORD IMAGE_FILE_LINE_NUMS_STRIPPED : 1 < comment = "0x0004 Line nunbers stripped from file" > ; +80: WORD IMAGE_FILE_LOCAL_SYMS_STRIPPED : 1 < comment = "0x0008 Local symbols stripped from file" > ; +81: WORD IMAGE_FILE_AGGRESIVE_WS_TRIM : 1 < comment = "0x0010 Agressively trim working set" > ; +82: WORD IMAGE_FILE_LARGE_ADDRESS_AWARE : 1 < comment = "0x0020 App can handle >2gb addresses" > ; +83: WORD : 1 < comment = "0x0040 Reserved" , hidden = true > ; +84: WORD IMAGE_FILE_BYTES_REVERSED_LO : 1 < comment = "0x0080 Bytes of machine word are reversed" > ; +85: WORD IMAGE_FILE_32BIT_MACHINE : 1 < comment = "0x0100 32 bit word machine" > ; +86: WORD IMAGE_FILE_DEBUG_STRIPPED : 1 < comment = "0x0200 Debugging info stripped from file in .DBG file" > ; +87: WORD IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP : 1 < comment = "0x0400 If Image is on removable media, copy and run from the swap file" > ; +88: WORD IMAGE_FILE_NET_RUN_FROM_SWAP : 1 < comment = "0x0800 If Image is on Net, copy and run from the swap file" > ; +89: WORD IMAGE_FILE_SYSTEM : 1 < comment = "0x1000 System File" > ; +90: WORD IMAGE_FILE_DLL : 1 < comment = "0x2000 File is a DLL" > ; +91: WORD IMAGE_FILE_UP_SYSTEM_ONLY : 1 < comment = "0x4000 File should only be run on a UP machine" > ; +92: WORD IMAGE_FILE_BYTES_REVERSED_HI : 1 < comment = "0x8000 Bytes of machine word are reversed" > ; +93: } FILE_CHARACTERISTICS < comment = "WORD" > ; +94: +95: typedef struct _IMAGE_FILE_HEADER +96: { +97: IMAGE_MACHINE Machine < fgcolor = cPurple , format = hex , comment = "WORD" > ; +98: WORD NumberOfSections < fgcolor = cBlue , comment = "Section num" > ; +99: time_t TimeDateStamp < format = hex , comment = "DWORD,from 01/01/1970 12:00 AM" > ; +100: DWORD PointerToSymbolTable ; +101: DWORD NumberOfSymbols ; +102: WORD SizeOfOptionalHeader ; +103: FILE_CHARACTERISTICS Characteristics < comment = "WORD" > ; +104: } IMAGE_FILE_HEADER ; +105: +106: typedef struct _IMAGE_DATA_DIRECTORY +107: { +108: DWORD VirtualAddress < format = hex , comment = CommentRVA2FOA > ; +109: DWORD Size ; +110: } IMAGE_DATA_DIRECTORY ; +111: +112: typedef struct _IMAGE_DATA_DIRECTORY_ARRAY +113: { +114: IMAGE_DATA_DIRECTORY DataDir0 < comment = "IMAGE_DIRECTORY_ENTRY_EXPORT" > ; +115: IMAGE_DATA_DIRECTORY DataDir1 < fgcolor = cPurple , comment = "IMAGE_DIRECTORY_ENTRY_IMPORT" > ; +116: IMAGE_DATA_DIRECTORY DataDir2 < comment = "IMAGE_DIRECTORY_ENTRY_RESOURCE" > ; +117: IMAGE_DATA_DIRECTORY DataDir3 < comment = "IMAGE_DIRECTORY_ENTRY_EXCEPTION" > ; +118: IMAGE_DATA_DIRECTORY DataDir4 < comment = "IMAGE_DIRECTORY_ENTRY_SECURITY" > ; +119: IMAGE_DATA_DIRECTORY DataDir5 < fgcolor = cPurple , comment = "IMAGE_DIRECTORY_ENTRY_BASERELOC" > ; +120: IMAGE_DATA_DIRECTORY DataDir6 < comment = "IMAGE_DIRECTORY_ENTRY_DEBUG" > ; +121: IMAGE_DATA_DIRECTORY DataDir7 < comment = "IMAGE_DIRECTORY_ENTRY_ARCHITECTURE" > ; +122: IMAGE_DATA_DIRECTORY DataDir8 < comment = "IMAGE_DIRECTORY_ENTRY_GLOBALPTR" > ; +123: IMAGE_DATA_DIRECTORY DataDir9 < comment = "IMAGE_DIRECTORY_ENTRY_TLS" > ; +124: IMAGE_DATA_DIRECTORY DataDir10 < comment = "IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG" > ; +125: IMAGE_DATA_DIRECTORY DataDir11 < comment = "IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT" > ; +126: IMAGE_DATA_DIRECTORY DataDir12 < fgcolor = cPurple , comment = "IMAGE_DIRECTORY_ENTRY_IAT" > ; +127: IMAGE_DATA_DIRECTORY DataDir13 < comment = "IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT" > ; +128: IMAGE_DATA_DIRECTORY DataDir14 < comment = "IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR" > ; +129: IMAGE_DATA_DIRECTORY DataDir15 < comment = "System Reserved" > ; +130: } IMAGE_DATA_DIRECTORY_ARRAY ; +131: +132: typedef enum < WORD > _IMAGE_SUBSYSTEM +133: { +134: IMAGE_SUBSYSTEM_UNKNOWN = 0 , +135: NATIVE = 1 , +136: WINDOWS_GUI = 2 , +137: WINDOWS_CUI = 3 , +138: OS2_CUI = 5 , +139: POSIX_CUI = 7 , +140: NATIVE_WINDOWS = 8 , +141: WINDOWS_CE_GUI = 9 , +142: EFI_APPLICATION = 10 , +143: EFI_BOOT_SERVICE_DRIVER = 11 , +144: EFI_RUNTIME_DRIVER = 12 , +145: EFI_ROM = 13 , +146: XBOX = 14 , +147: WINDOWS_BOOT_APPLICATION = 16 +148: } IMAGE_SUBSYSTEM < comment = "WORD" > ; +149: +150: typedef struct _DLL_CHARACTERISTICS +151: { +152: WORD IMAGE_LIBRARY_PROCESS_INIT : 1 < comment = "0x0001 Reserved" , hidden = true > ; +153: WORD IMAGE_LIBRARY_PROCESS_TERM : 1 < comment = "0x0002 Reserved" , hidden = true > ; +154: WORD IMAGE_LIBRARY_THREAD_INIT : 1 < comment = "0x0004 Reserved" , hidden = true > ; +155: WORD IMAGE_LIBRARY_THREAD_TERM : 1 < comment = "0x0008 Reserved" , hidden = true > ; +156: WORD : 2 < comment = "0x0010,0x0020" , hidden = true > ; +157: WORD IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE : 1 < comment = "0x0040" > ; +158: WORD IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY : 1 < comment = "0x0080" > ; +159: WORD IMAGE_DLLCHARACTERISTICS_NX_COMPAT : 1 < comment = "0x0100" > ; +160: WORD IMAGE_DLLCHARACTERISTICS_NO_ISOLATION : 1 < comment = "0x0200" > ; +161: WORD IMAGE_DLLCHARACTERISTICS_NO_SEH : 1 < comment = "0x0400" > ; +162: WORD IMAGE_DLLCHARACTERISTICS_NO_BIND : 1 < comment = "0x0800" > ; +163: WORD : 1 < comment = "0x1000" , hidden = true > ; +164: WORD IMAGE_DLLCHARACTERISTICS_WDM_DRIVER : 1 < comment = "0x2000" > ; +165: WORD : 1 < comment = "0x4000" , hidden = true > ; +166: WORD IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE : 1 < comment = "0x8000" > ; +167: } DLL_CHARACTERISTICS < comment = "WORD" > ; +168: +169: typedef enum < WORD > _OPTIONAL_MAGIC +170: { +171: PE32 = 0x10B , +172: PE64 = 0x20B , +173: ROM = 0x107 +174: } OPTIONAL_MAGIC < comment = "WORD" > ; +175: +176: typedef struct _IMAGE_OPTIONAL_HEADER32 +177: { +178: OPTIONAL_MAGIC Magic < format = hex > ; +179: BYTE MajorLinkerVersion ; +180: BYTE MinorLinkerVersion ; +181: DWORD SizeOfCode < format = hex > ; +182: DWORD SizeOfInitializedData ; +183: DWORD SizeOfUninitializedData ; +184: DWORD AddressOfEntryPoint < fgcolor = cPurple , format = hex , comment = CommentRVA2FOA > ; +185: DWORD BaseOfCode < format = hex , comment = CommentRVA2FOA > ; +186: DWORD BaseOfData < format = hex , comment = CommentRVA2FOA > ; +187: DWORD ImageBase < format = hex > ; +188: DWORD SectionAlignment < format = hex > ; +189: DWORD FileAlignment < format = hex > ; +190: WORD MajorOperatingSystemVersion ; +191: WORD MinorOperatingSystemVersion ; +192: WORD MajorImageVersion ; +193: WORD MinorImageVersion ; +194: WORD MajorSubsystemVersion ; +195: WORD MinorSubsystemVersion ; +196: DWORD Win32VersionValue ; +197: DWORD SizeOfImage < format = hex > ; +198: DWORD SizeOfHeaders < format = hex > ; +199: DWORD CheckSum < format = hex > ; +200: IMAGE_SUBSYSTEM Subsystem ; +201: DLL_CHARACTERISTICS DllCharacteristics ; +202: DWORD SizeOfStackReserve < format = hex > ; +203: DWORD SizeOfStackCommit < format = hex > ; +204: DWORD SizeOfHeapReserve < format = hex > ; +205: DWORD SizeOfHeapCommit < format = hex > ; +206: DWORD LoaderFlags ; +207: DWORD NumberOfRvaAndSizes ; +208: IMAGE_DATA_DIRECTORY_ARRAY DataDirArray ; +209: } IMAGE_OPTIONAL_HEADER32 ; +210: +211: typedef struct _IMAGE_OPTIONAL_HEADER64 +212: { +213: OPTIONAL_MAGIC Magic < format = hex > ; +214: BYTE MajorLinkerVersion ; +215: BYTE MinorLinkerVersion ; +216: DWORD SizeOfCode ; +217: DWORD SizeOfInitializedData ; +218: DWORD SizeOfUninitializedData ; +219: DWORD AddressOfEntryPoint < format = hex , comment = CommentRVA2FOA > ; +220: DWORD BaseOfCode < format = hex > ; +221: ULONGLONG ImageBase < format = hex > ; +222: DWORD SectionAlignment ; +223: DWORD FileAlignment ; +224: WORD MajorOperatingSystemVersion ; +225: WORD MinorOperatingSystemVersion ; +226: WORD MajorImageVersion ; +227: WORD MinorImageVersion ; +228: WORD MajorSubsystemVersion ; +229: WORD MinorSubsystemVersion ; +230: DWORD Win32VersionValue ; +231: DWORD SizeOfImage < format = hex > ; +232: DWORD SizeOfHeaders ; +233: DWORD CheckSum ; +234: IMAGE_SUBSYSTEM Subsystem ; +235: DLL_CHARACTERISTICS DllCharacteristics ; +236: ULONGLONG SizeOfStackReserve < format = hex > ; +237: ULONGLONG SizeOfStackCommit < format = hex > ; +238: ULONGLONG SizeOfHeapReserve < format = hex > ; +239: ULONGLONG SizeOfHeapCommit < format = hex > ; +240: DWORD LoaderFlags ; +241: DWORD NumberOfRvaAndSizes ; +242: IMAGE_DATA_DIRECTORY_ARRAY DataDirArray ; +243: } IMAGE_OPTIONAL_HEADER64 ; +244: +245: typedef struct _IMAGE_NT_HEADERS +246: { +247: DWORD Signature < format = hex , comment = "IMAGE_NT_SIGNATURE = 0x00004550" > ; +248: IMAGE_FILE_HEADER FileHeader ; +249: +250: local WORD OptionalHeaderMagic = ReadShort ( FTell ( ) ) ; +251: +252: if ( 0x10B == OptionalHeaderMagic ) +253: { +254: IMAGE_OPTIONAL_HEADER32 OptionalHeader ; +255: } +256: else if ( 0x20B == OptionalHeaderMagic ) +257: { +258: IMAGE_OPTIONAL_HEADER64 OptionalHeader ; +259: } +260: else +261: { +262: Printf ( "not valid Optional header magic %x.\n" , OptionalHeaderMagic ) ; +263: return 1 ; +264: } +265: } IMAGE_NT_HEADERS < size = CalcImageNtHeadersSize > ; +266: +267: int CalcImageNtHeadersSize ( IMAGE_NT_HEADERS & stNtHeader ) +268: { +269: local WORD OptionalHeaderMagic = ReadShort ( startof ( stNtHeader ) + sizeof ( DWORD ) + sizeof ( IMAGE_FILE_HEADER ) ) ; +270: +271: if ( 0x10B == OptionalHeaderMagic ) +272: { +273: Printf ( "PE32\n" ) ; +274: return 0xF8 ; +275: } +276: else if ( 0x20B == OptionalHeaderMagic ) +277: { +278: Printf ( "PE64\n" ) ; +279: return 0x108 ; +280: } +281: else +282: { +283: return sizeof ( DWORD ) + sizeof ( IMAGE_FILE_HEADER ) + 0 ; +284: } +285: return 0 ; +286: } +287: +288: typedef struct _SECTION_CHARACTERISTICS +289: { +290: ULONG IMAGE_SCN_TYPE_DSECT : 1 < hidden = true , comment = "0x00000001 Reserved" > ; +291: ULONG IMAGE_SCN_TYPE_NOLOAD : 1 < hidden = true , comment = "0x00000002 Reserved" > ; +292: ULONG IMAGE_SCN_TYPE_GROUP : 1 < hidden = true , comment = "0x00000004 Reserved" > ; +293: ULONG IMAGE_SCN_TYPE_NO_PAD : 1 < comment = "0x00000008 Reserved" > ; +294: ULONG IMAGE_SCN_TYPE_COPY : 1 < hidden = true , comment = "0x00000010 Reserved" > ; +295: +296: ULONG IMAGE_SCN_CNT_CODE : 1 < comment = "0x00000020 Section contains code" > ; +297: ULONG IMAGE_SCN_CNT_INITIALIZED_DATA : 1 < comment = "0x00000040 Section contains initialized data" > ; +298: ULONG IMAGE_SCN_CNT_UNINITIALIZED_DATA : 1 < comment = "0x00000080 Section contains uninitialized data" > ; +299: +300: ULONG IMAGE_SCN_LNK_OTHER : 1 < comment = "0x00000100 Reserved" > ; +301: ULONG IMAGE_SCN_LNK_INFO : 1 < comment = "0x00000200 Section contains comments or some other type of information" > ; +302: ULONG IMAGE_SCN_TYPE_OVER : 1 < hidden = true , comment = "0x00000400 Reserved" > ; +303: ULONG IMAGE_SCN_LNK_REMOVE : 1 < comment = "0x00000800 Section contents will not become part of image" > ; +304: ULONG IMAGE_SCN_LNK_COMDAT : 1 < comment = "0x00001000 Section contents comdat" > ; +305: ULONG : 1 < comment = "0x00002000 Reserved" > ; +306: ULONG IMAGE_SCN_NO_DEFER_SPEC_EXC : 1 < hidden = true , comment = "0x00004000 Reset speculative exceptions handling bits in the TLB entries for this section." > ; +307: ULONG IMAGE_SCN_GPREL : 1 < comment = "0x00008000 Section content can be accessed relative to GP" > ; +308: ULONG IMAGE_SCN_MEM_SYSHEAP : 1 < hidden = true , comment = "0x00010000 Obsolete" > ; +309: ULONG IMAGE_SCN_MEM_16BIT : 1 < comment = "0x00020000" > ; +310: ULONG IMAGE_SCN_MEM_LOCKED : 1 < comment = "0x00040000 " > ; +311: ULONG IMAGE_SCN_MEM_PRELOAD : 1 < comment = "0x00080000" > ; +312: +313: ULONG IMAGE_SCN_ALIGN_1BYTES : 1 < comment = "0x00100000" > ; +314: ULONG IMAGE_SCN_ALIGN_2BYTES : 1 < comment = "0x00200000" > ; +315: ULONG IMAGE_SCN_ALIGN_8BYTES : 1 < comment = "0x00400000" > ; +316: ULONG IMAGE_SCN_ALIGN_128BYTES : 1 < comment = "0x00800000" > ; +317: +318: ULONG IMAGE_SCN_LNK_NRELOC_OVFL : 1 < comment = "0x01000000 Section contains extended relocations" > ; +319: ULONG IMAGE_SCN_MEM_DISCARDABLE : 1 < comment = "0x02000000 Section can be discarded." > ; +320: ULONG IMAGE_SCN_MEM_NOT_CACHED : 1 < comment = "0x04000000 Section is not cachable" > ; +321: ULONG IMAGE_SCN_MEM_NOT_PAGED : 1 < comment = "0x08000000 Section is not pageable." > ; +322: ULONG IMAGE_SCN_MEM_SHARED : 1 < comment = "0x10000000 Section is shareable" > ; +323: ULONG IMAGE_SCN_MEM_EXECUTE : 1 < comment = "0x20000000 Section is executable" > ; +324: ULONG IMAGE_SCN_MEM_READ : 1 < comment = "0x40000000 Section is readable" > ; +325: ULONG IMAGE_SCN_MEM_WRITE : 1 < comment = "0x80000000 Section is writeable" > ; +326: } SECTION_CHARACTERISTICS ; +327: +328: typedef struct _IMAGE_SECTION_HEADER +329: { +330: BYTE Name [ 8 ] < comment = "can end without zero" > ; +331: union { +332: DWORD PhysicalAddress ; +333: DWORD VirtualSize ; +334: } Misc ; +335: DWORD VirtualAddress < format = hex > ; +336: DWORD SizeOfRawData < format = hex > ; +337: DWORD PointerToRawData < format = hex > ; +338: DWORD PointerToRelocations < format = hex > ; +339: DWORD PointerToLinenumbers ; +340: WORD NumberOfRelocations ; +341: WORD NumberOfLinenumbers ; +342: SECTION_CHARACTERISTICS Characteristics < format = hex > ; +343: } IMAGE_SECTION_HEADER ; +344: +345: typedef struct _IMAGE_SECTION_DATA ( IMAGE_SECTION_HEADER & SecHeader ) +346: { +347: local string sSecName = SecHeader . Name ; +348: +349: UCHAR Data [ SecHeader . SizeOfRawData ] ; +350: } IMAGE_SECTION_DATA < comment = commentSectionData > ; +351: +352: string commentSectionData ( IMAGE_SECTION_DATA & SecData ) +353: { +354: return SecData . sSecName ; +355: } +356: +357: typedef struct _IMAGE_IMPORT_BY_NAME ( int nNameLen ) +358: { +359: WORD Hint ; +360: BYTE Name [ nNameLen ] ; +361: } IMAGE_IMPORT_BY_NAME < comment = commentImageImportByName > ; +362: +363: string commentImageImportByName ( IMAGE_IMPORT_BY_NAME & ImportByName ) +364: { +365: return ImportByName . Name ; +366: } +367: +368: typedef struct _IMAGE_IMPORT_DESCRIPTOR +369: { +370: local int nNameIndex = 0 ; +371: local ULONG ulThrunk = 0 ; +372: local int nNameLen = 0 ; +373: local string sDllName = "" ; +374: local ULONG ulOriginalFirstThunkFOA = 0 ; +375: +376: union +377: { +378: ULONG Characteristics ; +379: ULONG OriginalFirstThunk < format = hex , comment = CommentRVA2FOA > ; +380: } DUMMYUNIONNAME ; +381: +382: ULONG TimeDateStamp < comment = "0 if not bound" > ; +383: ULONG ForwarderChain < comment = "-1 if no forwarders" > ; +384: ULONG Name < format = hex , comment = CommentRVAString > ; +385: ULONG FirstThunk < format = hex , comment = CommentRVA2FOA > ; +386: +387: +388: ulOriginalFirstThunkFOA = RVA2FOA ( DUMMYUNIONNAME . OriginalFirstThunk ) ; +389: if ( ( 0x20B == NtHeader . OptionalHeader . Magic ) ) +390: { +391: +392: } +393: else +394: { +395: nNameIndex = 0 ; +396: while ( 1 ) +397: { +398: ulThrunk = ReadUInt ( ulOriginalFirstThunkFOA + 4 * nNameIndex ) ; +399: if ( 0 == ulThrunk ) +400: { +401: break ; +402: } +403: +404: if ( ulThrunk & 0x80000000 ) +405: { +406: Printf ( "mport by order \n" ) ; +407: } +408: else +409: { +410: nNameLen = Strlen ( ReadString ( RVA2FOA ( ulThrunk ) + sizeof ( WORD ) ) ) ; +411: if ( 0 != nNameLen ) +412: { +413: FSeek ( RVA2FOA ( ulThrunk ) ) ; +414: IMAGE_IMPORT_BY_NAME ImportByName ( nNameLen + 1 ) < open = false > ; +415: } +416: } +417: nNameIndex ++ ; +418: } +419: } +420: } IMAGE_IMPORT_DESCRIPTOR < comment = commentImageImportDescriptor > ; +421: +422: string commentImageImportDescriptor ( IMAGE_IMPORT_DESCRIPTOR & ImportDescriptor ) +423: { +424: return ReadString ( RVA2FOA ( ImportDescriptor . Name ) ) ; +425: } +426: +427: typedef struct _IMAGE_EXPORT_BY_NAME ( string & sExportFuncName , ULONG ulDestRVA , string & sJmpName ) +428: { +429: local ULONG ulLocalDestRVA = ulDestRVA ; +430: local string sLocalJmpName = sJmpName ; +431: +432: char Function [ Strlen ( sExportFuncName ) ] ; +433: } IMAGE_EXPORT_BY_NAME < read = ReadExportByName , comment = commentExportByName > ; +434: +435: string ReadExportByName ( IMAGE_EXPORT_BY_NAME & ExportByName ) +436: { +437: return ExportByName . Function ; +438: } +439: +440: string commentExportByName ( IMAGE_EXPORT_BY_NAME & ExportByName ) +441: { +442: local string sComment = "" ; +443: +444: if ( 0 == Strlen ( ExportByName . sLocalJmpName ) ) +445: { +446: SPrintf ( sComment , "0x%X" , ExportByName . ulLocalDestRVA ) ; +447: } +448: else +449: { +450: SPrintf ( sComment , "%s" , ExportByName . sLocalJmpName ) ; +451: } +452: +453: return sComment ; +454: } +455: +456: typedef struct _IMAGE_EXPORT_DIRECTORY { +457: DWORD Characteristics ; +458: time_t TimeDateStamp ; +459: WORD MajorVersion ; +460: WORD MinorVersion ; +461: DWORD Name < format = hex , comment = CommentRVAString > ; +462: DWORD Base ; +463: DWORD NumberOfFunctions ; +464: DWORD NumberOfNames ; +465: DWORD AddressOfFunctions < format = hex , comment = CommentRVA2FOA > ; +466: DWORD AddressOfNames < format = hex , comment = CommentRVA2FOA > ; +467: DWORD AddressOfNameOrdinals < format = hex , comment = CommentRVA2FOA > ; +468: +469: local int nIndex = 0 ; +470: local ULONG NameArrayFOA = 0 ; +471: local ULONG OrdinalArrayFOA = 0 ; +472: local ULONG FuncArrayFOA = 0 ; +473: local ULONG ulNameRVA = 0 ; +474: local ULONG ulNameFOA = 0 ; +475: local ULONG ulFuncRVA = 0 ; +476: local WORD wOrdinal = 0 ; +477: +478: local string sExportName = "" ; +479: local string sJmpName = "" ; +480: +481: +482: NameArrayFOA = RVA2FOA ( ExportDir . AddressOfNames ) ; +483: OrdinalArrayFOA = RVA2FOA ( ExportDir . AddressOfNameOrdinals ) ; +484: FuncArrayFOA = RVA2FOA ( ExportDir . AddressOfFunctions ) ; +485: +486: for ( nIndex = 0 ; nIndex < ExportDir . NumberOfNames ; nIndex ++ ) +487: { +488: ulNameRVA = ReadUInt ( NameArrayFOA + nIndex * sizeof ( ULONG ) ) ; +489: ulNameFOA = RVA2FOA ( ulNameRVA ) ; +490: sExportName = ReadString ( ulNameFOA ) ; +491: +492: if ( 0 != Strlen ( sExportName ) ) +493: { +494: wOrdinal = ReadUShort ( OrdinalArrayFOA + nIndex * sizeof ( USHORT ) ) ; +495: ulFuncRVA = ReadUInt ( FuncArrayFOA + wOrdinal * sizeof ( ULONG ) ) ; +496: +497: if ( ( ulFuncRVA > NtHeader . OptionalHeader . DataDirArray . DataDir0 . VirtualAddress ) && +498: ( ulFuncRVA < NtHeader . OptionalHeader . DataDirArray . DataDir0 . VirtualAddress + NtHeader . OptionalHeader . DataDirArray . DataDir0 . Size ) ) +499: { +500: +501: +502: sJmpName = ReadString ( RVA2FOA ( ulFuncRVA ) ) ; +503: FSeek ( ulNameFOA ) ; +504: IMAGE_EXPORT_BY_NAME ExportByName ( sExportName , ulFuncRVA , sJmpName ) ; +505: } +506: else +507: { +508: +509: sJmpName = "" ; +510: FSeek ( ulNameFOA ) ; +511: IMAGE_EXPORT_BY_NAME ExportByName ( sExportName , ulFuncRVA , sJmpName ) ; +512: } +513: } +514: } +515: } IMAGE_EXPORT_DIRECTORY < comment = commentExportDirectory > ; +516: +517: string commentExportDirectory ( IMAGE_EXPORT_DIRECTORY & ExportDir ) +518: { +519: return ReadString ( RVA2FOA ( ExportDir . Name ) ) ; +520: } +521: +522: ULONG RVA2FOA ( ULONG ulRVA ) +523: { +524: local int i = 0 ; +525: +526: for ( i = 0 ; i < NtHeader . FileHeader . NumberOfSections ; i ++ ) +527: { +528: if ( ( ulRVA >= SectionHeaders [ i ] . VirtualAddress ) && ( ulRVA <= SectionHeaders [ i ] . VirtualAddress + SectionHeaders [ i ] . SizeOfRawData ) ) +529: { +530: return SectionHeaders [ i ] . PointerToRawData + ( ulRVA - SectionHeaders [ i ] . VirtualAddress ) ; +531: } +532: } +533: return 0 ; +534: } +535: +536: string LocationRVA ( ULONG ulRVA ) +537: { +538: local int i = 0 ; +539: +540: for ( i = 0 ; i < NtHeader . FileHeader . NumberOfSections ; i ++ ) +541: { +542: if ( ( ulRVA >= SectionHeaders [ i ] . VirtualAddress ) && ( ulRVA <= SectionHeaders [ i ] . VirtualAddress + SectionHeaders [ i ] . SizeOfRawData ) ) +543: { +544: return SectionHeaders [ i ] . Name ; +545: } +546: } +547: return "" ; +548: } +549: +550: string CommentRVA2FOA ( DWORD dwRVA ) +551: { +552: local string sComment = "" ; +553: if ( 0 != dwRVA ) +554: { +555: SPrintf ( sComment , "%s FOA = 0x%X \n" , LocationRVA ( dwRVA ) , RVA2FOA ( dwRVA ) ) ; +556: } +557: return sComment ; +558: } +559: +560: string CommentRVAString ( DWORD dwRVA ) +561: { +562: local string sComment = "" ; +563: +564: if ( 0 != dwRVA ) +565: { +566: SPrintf ( sComment , "%s FOA = 0x%X -> %s" , LocationRVA ( dwRVA ) , RVA2FOA ( dwRVA ) , ReadString ( RVA2FOA ( dwRVA ) ) ) ; +567: } +568: return sComment ; +569: } +570: +571: typedef struct _IMAGE_BASE_RELOCATION +572: { +573: DWORD VirtualAddress < format = hex , comment = CommentRVA2FOA > ; +574: DWORD SizeOfBlock ; +575: +576: +577: local ULONG ulBlockNum = 0 ; +578: local ULONG ulIndex = 0 ; +579: +580: ulBlockNum = ( SizeOfBlock - 8 ) / 2 ; +581: for ( ulIndex = 0 ; ulIndex < ulBlockNum ; ulIndex ++ ) +582: { +583: WORD Block < format = hex , comment = CommentBaseRelocBlock > ; +584: } +585: +586: } IMAGE_BASE_RELOCATION < comment = commentImageBaseRelocation > ; +587: +588: +589: +590: string CommentBaseRelocBlock ( WORD Block ) +591: { +592: if ( 0x3000 == ( Block & 0xF000 ) ) +593: { +594: return "HIGHLOW" ; +595: } +596: else +597: { +598: return "ABSULUTE" ; +599: } +600: +601: return "" ; +602: } +603: +604: +605: string commentImageBaseRelocation ( IMAGE_BASE_RELOCATION & BaseReloc ) +606: { +607: local string sComment = "" ; +608: SPrintf ( sComment , "%d" , BaseReloc . ulBlockNum ) ; +609: return sComment ; +610: } +611: +612: typedef struct _BASE_RELOCATION_TABLE +613: { +614: local ULONG ulRelocNum = 0 ; +615: +616: while ( 1 ) +617: { +618: if ( 0 == ReadUInt ( FTell ( ) ) ) +619: { +620: break ; +621: } +622: IMAGE_BASE_RELOCATION BaseReloc ; +623: ulRelocNum ++ ; +624: } +625: } BASE_RELOCATION_TABLE < comment = commentBaseRelocationTable > ; +626: +627: string commentBaseRelocationTable ( BASE_RELOCATION_TABLE & RelocTable ) +628: { +629: local string sComment = "" ; +630: SPrintf ( sComment , "%d" , RelocTable . ulRelocNum ) ; +631: return sComment ; +632: } +633: +634: +635: +636: +637: void ParseEAT ( void ) +638: { +639: if ( ( NtHeader . OptionalHeader . DataDirArray . DataDir0 . VirtualAddress != 0 ) && ( NtHeader . OptionalHeader . DataDirArray . DataDir0 . Size != 0 ) ) +640: { +641: local ULONG ulExportFOA = RVA2FOA ( NtHeader . OptionalHeader . DataDirArray . DataDir0 . VirtualAddress ) ; +642: FSeek ( ulExportFOA ) ; +643: IMAGE_EXPORT_DIRECTORY ExportDir ; +644: } +645: } +646: +647: +648: void ParseIAT ( ) +649: { +650: if ( ( NtHeader . OptionalHeader . DataDirArray . DataDir1 . VirtualAddress != 0 ) && ( NtHeader . OptionalHeader . DataDirArray . DataDir1 . Size != 0 ) ) +651: { +652: local ULONG ulImportFOA = RVA2FOA ( NtHeader . OptionalHeader . DataDirArray . DataDir1 . VirtualAddress ) ; +653: local ULONG ulOriginalFirstThunk = 0 ; +654: local ULONG ulOriginalFirstThunkFOA = 0 ; +655: local int nImportIndex = 0 ; +656: +657: FSeek ( ulImportFOA ) ; +658: while ( 1 ) +659: { +660: ulOriginalFirstThunk = ReadUInt ( ulImportFOA + 0x14 * nImportIndex ) ; +661: if ( 0 == ulOriginalFirstThunk ) +662: { +663: break ; +664: } +665: FSeek ( ulImportFOA + 0x14 * nImportIndex ) ; +666: IMAGE_IMPORT_DESCRIPTOR ImportDescriptor ; +667: nImportIndex ++ ; +668: } +669: } +670: } +671: +672: +673: void ParseResource ( ) +674: { +675: if ( ( NtHeader . OptionalHeader . DataDirArray . DataDir2 . VirtualAddress == 0 ) || ( NtHeader . OptionalHeader . DataDirArray . DataDir2 . Size == 0 ) ) +676: { +677: return ; +678: } +679: +680: } +681: +682: +683: void ParseException ( ) +684: { +685: if ( ( NtHeader . OptionalHeader . DataDirArray . DataDir3 . VirtualAddress == 0 ) || ( NtHeader . OptionalHeader . DataDirArray . DataDir3 . Size == 0 ) ) +686: { +687: return ; +688: } +689: +690: } +691: +692: +693: void ParseSecurity ( ) +694: { +695: if ( ( NtHeader . OptionalHeader . DataDirArray . DataDir4 . VirtualAddress == 0 ) || ( NtHeader . OptionalHeader . DataDirArray . DataDir4 . Size == 0 ) ) +696: { +697: return ; +698: } +699: +700: } +701: +702: +703: void ParseBaseReloc ( ) +704: { +705: if ( ( NtHeader . OptionalHeader . DataDirArray . DataDir5 . VirtualAddress == 0 ) || ( NtHeader . OptionalHeader . DataDirArray . DataDir5 . Size == 0 ) ) +706: { +707: return ; +708: } +709: FSeek ( RVA2FOA ( NtHeader . OptionalHeader . DataDirArray . DataDir5 . VirtualAddress ) ) ; +710: BASE_RELOCATION_TABLE RelocTable ; +711: } +712: +713: +714: void ParseDebug ( ) +715: { +716: if ( ( NtHeader . OptionalHeader . DataDirArray . DataDir6 . VirtualAddress == 0 ) || ( NtHeader . OptionalHeader . DataDirArray . DataDir6 . Size == 0 ) ) +717: { +718: return ; +719: } +720: +721: } +722: +723: +724: void ParseTLS ( ) +725: { +726: if ( ( NtHeader . OptionalHeader . DataDirArray . DataDir9 . VirtualAddress == 0 ) || ( NtHeader . OptionalHeader . DataDirArray . DataDir9 . Size == 0 ) ) +727: { +728: return ; +729: } +730: +731: +732: } +733: +734: +735: void ParseBoundImport ( ) +736: { +737: if ( ( NtHeader . OptionalHeader . DataDirArray . DataDir11 . VirtualAddress == 0 ) || ( NtHeader . OptionalHeader . DataDirArray . DataDir11 . Size == 0 ) ) +738: { +739: return ; +740: } +741: +742: } +743: +744: +745: void ParseDelayImport ( ) +746: { +747: if ( ( NtHeader . OptionalHeader . DataDirArray . DataDir13 . VirtualAddress == 0 ) || ( NtHeader . OptionalHeader . DataDirArray . DataDir13 . Size == 0 ) ) +748: { +749: return ; +750: } +751: +752: } +753: +754: +755: +756: Printf ( "Parse PE Begin.\n" ) ; +757: IMAGE_DOS_HEADER DosHeader ; +758: if ( DosHeader . e_magic != 0x5A4D ) +759: { +760: Printf ( "invalid dos magic.\n" ) ; +761: return 1 ; +762: } +763: if ( 0 == DosHeader . e_lfanew ) +764: { +765: Warning ( "not invalid e_lfanew = 0x%X" , DosHeader . e_lfanew ) ; +766: return 2 ; +767: } +768: +769: UCHAR Space1 [ DosHeader . e_lfanew - sizeof ( IMAGE_DOS_HEADER ) ] < hidden = true , fgcolor = cRed , comment = "Space between dos header and nt header" > ; +770: Printf ( "Space between dos header and nt header is %d bytes \n" , DosHeader . e_lfanew - sizeof ( IMAGE_DOS_HEADER ) ) ; +771: FSeek ( DosHeader . e_lfanew ) ; +772: +773: IMAGE_NT_HEADERS NtHeader ; +774: if ( 0x4550 != NtHeader . Signature ) +775: { +776: Printf ( "invalid nt Signature 0x%x \n" , NtHeader . Signature ) ; +777: return 3 ; +778: } +779: +780: IMAGE_SECTION_HEADER SectionHeaders [ NtHeader . FileHeader . NumberOfSections ] ; +781: +782: +783: local ULONG ulRawHeaderSize = DosHeader . e_lfanew + sizeof ( NtHeader ) + NtHeader . FileHeader . NumberOfSections * sizeof ( IMAGE_SECTION_HEADER ) ; +784: +785: if ( NtHeader . OptionalHeader . SizeOfHeaders - ulRawHeaderSize > 0 ) +786: { +787: UCHAR Space2 [ NtHeader . OptionalHeader . SizeOfHeaders - ulRawHeaderSize ] < hidden = true , fgcolor = cRed , comment = "Space between header and first section" > ; +788: } +789: Printf ( "Space between headers and first sections is %d bytes\n" , NtHeader . OptionalHeader . SizeOfHeaders - ulRawHeaderSize ) ; +790: +791: FSeek ( NtHeader . OptionalHeader . SizeOfHeaders ) ; +792: +793: local ULONG ulIndex = 0 ; +794: for ( ulIndex = 0 ; ulIndex < NtHeader . FileHeader . NumberOfSections ; ulIndex ++ ) +795: { +796: if ( 0 == SectionHeaders [ ulIndex ] . PointerToRawData ) +797: { +798: continue ; +799: } +800: if ( 0 == SectionHeaders [ ulIndex ] . SizeOfRawData ) +801: { +802: continue ; +803: } +804: IMAGE_SECTION_DATA Section ( SectionHeaders [ ulIndex ] ) ; +805: } +806: +807: FSeek ( NtHeader . OptionalHeader . SizeOfHeaders ) ; +808: +809: +810: ParseEAT ( ) ; +811: ParseIAT ( ) ; +812: ParseResource ( ) ; +813: ParseException ( ) ; +814: ParseSecurity ( ) ; +815: ParseBaseReloc ( ) ; +816: ParseDebug ( ) ; +817: ParseTLS ( ) ; +818: ParseBoundImport ( ) ; +819: ParseDelayImport ( ) ; +820: +821: Printf ( "Parse PE finish.\n" ) ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/PNG12Template.bt b/cparser/tests/exp_lex/PNG12Template.bt new file mode 100644 index 0000000..b1ae4b2 --- /dev/null +++ b/cparser/tests/exp_lex/PNG12Template.bt @@ -0,0 +1,405 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: typedef struct { +13: WORD btPngSignature [ 4 ] < format = hex > ; +14: } PNG_SIGNATURE ; +15: +16: typedef struct { +17: DWORD btChunkLen ; +18: SetForeColor ( cYellow ) ; +19: SetBackColor ( cBlue ) ; +20: CHAR btChunkType [ 4 ] ; +21: SetBackColor ( cWhite ) ; +22: } PNG_CHUNK_HEADER ; +23: +24: typedef enum < byte > pngColorSpaceType { +25: GrayScale = 0 , +26: TrueColor = 2 , +27: Indexed = 3 , +28: AlphaGrayScale = 4 , +29: AlphaTrueColor = 6 +30: } PNG_COLOR_SPACE_TYPE ; +31: +32: +33: typedef enum < byte > pngCompressionMethod { +34: Deflate = 0 +35: } PNG_COMPR_METHOD ; +36: +37: +38: typedef enum < byte > pngFilterMethod { +39: AdaptiveFiltering = 0 +40: } PNG_FILTER_METHOD ; +41: +42: +43: typedef enum < byte > pngInterlaceMethod { +44: NoInterlace = 0 , +45: Adam7Interlace = 1 +46: } PNG_INTERLACE_METHOD ; +47: +48: +49: typedef struct { +50: UINT width ; +51: UINT height ; +52: BYTE bit_depth ; +53: PNG_COLOR_SPACE_TYPE color_type ; +54: PNG_COMPR_METHOD compr_method ; +55: PNG_FILTER_METHOD filter_method ; +56: PNG_INTERLACE_METHOD interlace_method ; +57: } IHDR_CHUNK_DATA ; +58: +59: typedef struct { +60: BYTE btRed < format = hex > ; +61: BYTE btGreen < format = hex > ; +62: BYTE btBlue < format = hex > ; +63: } PNG_PALETTE_PIXEL ; +64: +65: typedef struct { +66: uint x ; +67: uint y ; +68: } PNG_POINT ; +69: +70: typedef struct { +71: PNG_POINT white ; +72: PNG_POINT red ; +73: PNG_POINT green ; +74: PNG_POINT blue ; +75: } PNG_CHRM_CHUNK_DATA ; +76: +77: typedef enum < byte > { +78: Perceptual = 0 , +79: RelativeColorimetric = 1 , +80: Saturation = 2 , +81: AbsoluteColorimetric = 3 +82: } PNG_SRGB_CHUNK_DATA ; +83: +84: typedef struct { +85: string profile_name ; +86: unsigned byte red ; +87: } PNG_ICCP_CHUNK_DATA ; +88: +89: +90: +91: +92: BigEndian ( ) ; +93: +94: +95: struct PngFile { +96: +97: +98: SetForeColor ( cRed ) ; +99: PNG_SIGNATURE sig ; +100: +101: if ( sig . btPngSignature [ 0 ] != 0x8950 || +102: sig . btPngSignature [ 1 ] != 0x4E47 || +103: sig . btPngSignature [ 2 ] != 0xD0A || +104: sig . btPngSignature [ 3 ] != 0x1A0A ) { +105: Warning ( "File is not a PNG image. Template stopped." ) ; +106: return - 1 ; +107: } +108: +109: +110: +111: +112: +113: +114: SetForeColor ( cGreen ) ; +115: PNG_CHUNK_HEADER ihdrChunkHdr ; +116: if ( Strncmp ( ihdrChunkHdr . btChunkType , "IHDR" , 4 ) != 0 ) +117: { +118: Warning ( "PNG File does not start with IHDR chunk." ) ; +119: return - 2 ; +120: } +121: +122: SetForeColor ( cBlack ) ; +123: IHDR_CHUNK_DATA ihdrChunkData ; +124: +125: SetForeColor ( cBlue ) ; +126: DWORD ihdrCrc < format = hex > ; +127: +128: while ( ! FEof ( ) ) +129: { +130: +131: +132: +133: +134: +135: SetForeColor ( cGreen ) ; +136: PNG_CHUNK_HEADER chunkHdr ; +137: if ( Strncmp ( chunkHdr . btChunkType , "PLTE" , 4 ) == 0 ) +138: { +139: SetForeColor ( cBlack ) ; +140: struct PNG_CHUNK_PLTE +141: { +142: PNG_PALETTE_PIXEL plteChunkData [ chunkHdr . btChunkLen / 3 ] ; +143: +144: SetForeColor ( cBlue ) ; +145: DWORD plteCrc < format = hex > ; +146: } chunk_plte ; +147: } +148: else if ( Strncmp ( chunkHdr . btChunkType , "tRNS" , 4 ) == 0 ) +149: { +150: SetForeColor ( cBlack ) ; +151: struct PNG_CHUNK_TRNS +152: { +153: BYTE trnsChunkData [ chunkHdr . btChunkLen ] < format = hex > ; +154: +155: SetForeColor ( cBlue ) ; +156: DWORD trnsCrc < format = hex > ; +157: } chunk_trns ; +158: } +159: else if ( Strncmp ( chunkHdr . btChunkType , "IDAT" , 4 ) == 0 ) +160: { +161: SetForeColor ( cWhite ) ; +162: SetBackColor ( cBlack ) ; +163: struct PNG_CHUNK_IDAT +164: { +165: BYTE idatChunkData [ chunkHdr . btChunkLen ] < format = hex > ; +166: SetForeColor ( cBlack ) ; +167: SetBackColor ( cWhite ) ; +168: +169: SetForeColor ( cBlue ) ; +170: DWORD idatCrc < format = hex > ; +171: } chunk_idat ; +172: } +173: else if ( Strncmp ( chunkHdr . btChunkType , "gAMA" , 4 ) == 0 ) +174: { +175: SetForeColor ( cBlack ) ; +176: struct PNG_CHUNK_GAMA +177: { +178: BYTE gamaChunkData [ chunkHdr . btChunkLen ] ; +179: +180: SetForeColor ( cBlue ) ; +181: DWORD gamaCrc < format = hex > ; +182: } chunk_gama ; +183: } +184: else if ( Strncmp ( chunkHdr . btChunkType , "cHRM" , 4 ) == 0 ) +185: { +186: SetForeColor ( cBlack ) ; +187: struct PNG_CHUNK_CHRM +188: { +189: PNG_CHRM_CHUNK_DATA chrmChunkData ; +190: +191: SetForeColor ( cBlue ) ; +192: DWORD chrmCrc < format = hex > ; +193: } chunk_chrm ; +194: } +195: else if ( Strncmp ( chunkHdr . btChunkType , "sRGB" , 4 ) == 0 ) +196: { +197: SetForeColor ( cBlack ) ; +198: struct PNG_CHUNK_SRGB +199: { +200: PNG_SRGB_CHUNK_DATA srgbChunkData ; +201: +202: SetForeColor ( cBlue ) ; +203: DWORD srgbCrc < format = hex > ; +204: } chunk_srgb ; +205: } +206: else if ( Strncmp ( chunkHdr . btChunkType , "iEXt" , 4 ) == 0 ) +207: { +208: SetForeColor ( cBlack ) ; +209: struct PNG_CHUNK_IEXT +210: { +211: string iextIdChunkData ; +212: byte iextCompressionFlag ; +213: PNG_COMPR_METHOD iextComprMethod ; +214: string iextLanguageTag ; +215: string iextTranslatedKeyword ; +216: char iextValChunkData [ chunkHdr . btChunkLen - +217: Strlen ( iextIdChunkData ) - 1 - +218: Strlen ( iextLanguageTag ) - 1 - +219: Strlen ( iextTranslatedKeyword ) - 1 - +220: 2 ] ; +221: +222: SetForeColor ( cBlue ) ; +223: DWORD iextCrc < format = hex > ; +224: } chunk_iext ; +225: } +226: else if ( Strncmp ( chunkHdr . btChunkType , "tEXt" , 4 ) == 0 ) +227: { +228: SetForeColor ( cBlack ) ; +229: struct PNG_CHUNK_TEXT +230: { +231: string textIdChunkData ; +232: char textValChunkData [ chunkHdr . btChunkLen - Strlen ( textIdChunkData ) - 1 ] ; +233: +234: SetForeColor ( cBlue ) ; +235: DWORD textCrc < format = hex > ; +236: } chunk_text ; +237: } +238: else if ( Strncmp ( chunkHdr . btChunkType , "zEXt" , 4 ) == 0 ) +239: { +240: SetForeColor ( cBlack ) ; +241: struct PNG_CHUNK_ZEXT +242: { +243: string zextIdChunkData ; +244: PNG_COMPR_METHOD comprMethod ; +245: char zextValChunkData [ chunkHdr . btChunkLen - Strlen ( zextIdChunkData ) - 2 ] ; +246: +247: SetForeColor ( cBlue ) ; +248: DWORD zextCrc < format = hex > ; +249: } chunk_text ; +250: } +251: else if ( Strncmp ( chunkHdr . btChunkType , "tIME" , 4 ) == 0 ) +252: { +253: SetForeColor ( cBlack ) ; +254: struct PNG_CHUNK_TIME +255: { +256: short timeYear < format = decimal > ; +257: byte timeMonth < format = decimal > ; +258: byte timeDay < format = decimal > ; +259: byte timeHour < format = decimal > ; +260: byte timeMin < format = decimal > ; +261: byte timeSec < format = decimal > ; +262: +263: SetForeColor ( cBlue ) ; +264: DWORD zextCrc < format = hex > ; +265: } chunk_time ; +266: } +267: else if ( Strncmp ( chunkHdr . btChunkType , "bKGD" , 4 ) == 0 ) +268: { +269: SetForeColor ( cBlack ) ; +270: struct PNG_CHUNK_BKGD +271: { +272: switch ( ihdrChunkData . color_type ) +273: { +274: case 3 : +275: unsigned byte bgColorPaletteIndex < format = hex > ; +276: break ; +277: +278: case 0 : +279: case 4 : +280: unsigned short bgGrayscalePixelValue < format = hex > ; +281: break ; +282: +283: case 2 : +284: case 6 : +285: unsigned short bgColorPixelRed < format = hex > ; +286: unsigned short bgColorPixelGreen < format = hex > ; +287: unsigned short bgColorPixelBlue < format = hex > ; +288: break ; +289: +290: default : +291: Warning ( "Unknown Color Model Type for background color chunk." ) ; +292: return - 4 ; +293: } +294: +295: SetForeColor ( cBlue ) ; +296: DWORD zextCrc < format = hex > ; +297: } chunk_bkgd ; +298: } +299: else if ( Strncmp ( chunkHdr . btChunkType , "pHYs" , 4 ) == 0 ) +300: { +301: SetForeColor ( cBlack ) ; +302: struct PNG_CHUNK_PHYS +303: { +304: uint physPixelPerUnitX ; +305: uint physPixelPerUnitY ; +306: enum < byte > { +307: UnkownUnit = 0 , +308: Meter = 1 +309: } physUnitSpec ; +310: +311: SetForeColor ( cBlue ) ; +312: DWORD zextCrc < format = hex > ; +313: } chunk_phys ; +314: } +315: else if ( Strncmp ( chunkHdr . btChunkType , "sBIT" , 4 ) == 0 ) +316: { +317: SetForeColor ( cBlack ) ; +318: struct PNG_CHUNK_SBIT +319: { +320: switch ( ihdrChunkData . color_type ) +321: { +322: case 3 : +323: byte sbitRed ; +324: byte sbitGreen ; +325: byte sbitBlue ; +326: break ; +327: +328: case 0 : +329: byte sbitGraySource ; +330: break ; +331: +332: case 4 : +333: byte sbitGrayAlphaSource ; +334: byte sbitGrayAlphaSourceAlpha ; +335: break ; +336: +337: case 2 : +338: byte sbitColorRed ; +339: byte sbitColorGreen ; +340: byte sbitColorBlue ; +341: break ; +342: +343: case 6 : +344: byte sbitColorAlphaRed ; +345: byte sbitColorAlphaGreen ; +346: byte sbitColorAlphaBlue ; +347: byte sbitColorAlphaAlpha ; +348: break ; +349: +350: default : +351: Warning ( "Unknown Color Model Type for background color chunk." ) ; +352: return - 4 ; +353: } +354: +355: SetForeColor ( cBlue ) ; +356: DWORD sbitCrc < format = hex > ; +357: } chunk_sbit ; +358: } +359: else if ( Strncmp ( chunkHdr . btChunkType , "sPLT" , 4 ) == 0 ) +360: { +361: SetForeColor ( cBlue ) ; +362: struct PNG_CHUNK_SPLT +363: { +364: string paletteName ; +365: byte sampleDepth ; +366: byte spltData [ chunkHdr . btChunkLen - Strlen ( paletteName ) - 2 ] ; +367: +368: SetForeColor ( cBlue ) ; +369: DWORD spltCrc < format = hex > ; +370: } chunk_splt ; +371: } +372: else if ( Strncmp ( chunkHdr . btChunkType , "hIST" , 4 ) == 0 ) +373: { +374: SetForeColor ( cBlue ) ; +375: struct PNG_CHUNK_HIST +376: { +377: DWORD iendCrc < format = hex > ; +378: +379: SetForeColor ( cBlue ) ; +380: DWORD histCrc < format = hex > ; +381: } chunk_hist ; +382: } +383: else if ( Strncmp ( chunkHdr . btChunkType , "IEND" , 4 ) == 0 ) +384: { +385: SetForeColor ( cBlue ) ; +386: struct PNG_CHUNK_IEND +387: { +388: DWORD iendCrc < format = hex > ; +389: } chunk_iend ; +390: } +391: else +392: { +393: SetForeColor ( cBlack ) ; +394: struct PNG_CHUNK_UNKNOWN +395: { +396: BYTE genChunkData [ chunkHdr . btChunkLen ] ; +397: +398: SetForeColor ( cBlue ) ; +399: DWORD genCrc < format = hex > ; +400: } chunk_unknown ; +401: } +402: } +403: +404: } myPngFile ; +405: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/PNGTemplate.bt b/cparser/tests/exp_lex/PNGTemplate.bt new file mode 100644 index 0000000..d178aff --- /dev/null +++ b/cparser/tests/exp_lex/PNGTemplate.bt @@ -0,0 +1,139 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: +21: +22: +23: +24: +25: +26: +27: BigEndian ( ) ; +28: +29: const uint64 PNGMAGIC = 0x89504E470D0A1A0A L ; +30: +31: +32: typedef union { +33: uint32 ctype < format = hex > ; +34: char cname [ 4 ] ; +35: } CTYPE < read = readCTYPE > ; +36: +37: string readCTYPE ( local CTYPE & t ) { +38: return t . cname ; +39: } +40: +41: +42: +43: +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 < read = readIHDR > ; +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: +62: +63: typedef struct { +64: string label ; +65: char data [ length - Strlen ( label ) - 1 ] ; +66: } tEXt < read = readtEXt > ; +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: +75: +76: local uint32 CHUNK_CNT = 0 ; +77: +78: +79: typedef struct { +80: uint32 length ; +81: local quad pos_start = FTell ( ) ; +82: CTYPE type ; +83: if ( type . cname == "IHDR" ) { +84: IHDR ihdr ; +85: } else if ( type . cname == "tEXt" ) { +86: tEXt text ; +87: } else { +88: ubyte data [ length ] ; +89: } +90: local quad data_size = FTell ( ) - pos_start ; +91: uint32 crc < format = hex > ; +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 < read = readCHUNK > ; +101: +102: +103: +104: +105: +106: +107: +108: +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: +121: +122: +123: uint64 pngid < format = hex > ; +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: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/PSFTemplate.bt b/cparser/tests/exp_lex/PSFTemplate.bt new file mode 100644 index 0000000..606448b --- /dev/null +++ b/cparser/tests/exp_lex/PSFTemplate.bt @@ -0,0 +1,220 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: +21: +22: +23: +24: +25: +26: +27: +28: +29: +30: +31: +32: typedef struct { +33: char signature [ 8 ] ; +34: ushort unknown1 < format = hex > ; +35: ushort unknown2 < format = hex > ; +36: uint psf_size_minus_1AFx < format = hex > ; +37: uint small_patch_offset < format = hex > ; +38: uint large_patch_offset < format = hex > ; +39: uint unknown3 < format = hex > ; +40: uint num_files ; +41: uint offset < format = hex > ; +42: uint num_offsets < format = hex > ; +43: uint zero1 < format = hex > ; +44: uint zero2 < format = hex > ; +45: uint random [ 4 ] < format = hex > ; +46: char description [ ] ; +47: uchar zeros [ offset - FTell ( ) ] ; +48: uint file_info_offsets [ num_offsets ] < format = hex > ; +49: +50: } PSFHeader < read = get_package_name > ; +51: +52: string get_package_name ( struct PSFHeader & h ) +53: { +54: local char s [ 512 ] ; +55: SPrintf ( s , "%s" , exists ( h . name ) ? h . name : "" ) ; +56: return s ; +57: +58: } +59: +60: struct FileInfo ; +61: +62: string get_file_name ( struct FileInfo & fi ) +63: { +64: local char s [ 512 ] ; +65: SPrintf ( s , "%s pit %Xh, %d patches + 1" , exists ( fi . name ) ? fi . name : "" , fi . patch_info_table_offset , fi . num_patches ) ; +66: return s ; +67: +68: } +69: +70: struct PatchInfo ; +71: +72: string get_patch_info ( struct PatchInfo & pi ) +73: { +74: local char s [ 512 ] ; +75: SPrintf ( s , "index %Xh pos %Xh len %Xh" , pi . index , pi . position , pi . length ) ; +76: return s ; +77: +78: } +79: +80: +81: LittleEndian ( ) ; +82: SetBackColor ( cYellow ) ; +83: PSFHeader header ; +84: +85: +86: if ( 0 != Memcmp ( header . signature , "PSTREAM\0" , +87: sizeof ( header . signature ) ) ) +88: { +89: Printf ( "File is not a PSF file. Expected PSTREAM header.\n" ) ; +90: return - 1 ; +91: +92: } +93: +94: +95: local uint pos = 0 ; +96: local uint size = 0 ; +97: local uint align = 0 ; +98: local uint o = 0 ; +99: local uint offset = 0 ; +100: local uint f = 0 ; +101: local uint p = 0 ; +102: +103: for ( o = 0 ; o < header . num_offsets ; ++ o ) { +104: if ( header . file_info_offsets [ o ] == 0 ) +105: continue ; +106: FSeek ( header . file_info_offsets [ o ] ) ; +107: +108: for ( ++ f ; true ; ++ f ) { +109: SetBackColor ( cLtGreen ) ; +110: struct FileInfo { +111: uchar unknown [ 3 ] ; +112: uchar name_len < format = hex > ; +113: ushort num_patches ; +114: ushort compression ; +115: uint dependant_file_info_offset < format = hex > ; +116: uint unknown_struct_offset < format = hex > ; +117: uint patch_info_table_offset < format = hex > ; +118: char name [ name_len ] ; +119: +120: pos = FTell ( ) ; +121: align = ( pos + 3 ) & ~ 3 ; +122: if ( pos != align ) { +123: uchar padding [ align - pos ] ; +124: } +125: +126: +127: for ( size = 0 , pos = FTell ( ) ; ReadUInt ( pos ) == 0 ; ++ size , pos += 4 ) { +128: } +129: if ( size > 0 ) { +130: SetBackColor ( cSilver ) ; +131: uint zeros [ size ] ; +132: } +133: } file_info < read = get_file_name > ; +134: +135: if ( file_info . compression != 3 ) { +136: Printf ( "File %d %s, num_patches %d, compression %X.\n" , f - 1 , file_info . name , file_info . num_patches , file_info . compression ) ; +137: } +138: +139: FSeek ( file_info . unknown_struct_offset ) ; +140: SetBackColor ( f & 1 ? 0x99FF : 0xFF9900 ) ; +141: struct Unknown { +142: uint unknown [ 5 ] < format = hex > ; +143: } unknown ; +144: +145: +146: FSeek ( file_info . patch_info_table_offset ) ; +147: for ( p = 0 ; p < file_info . num_patches + 1 ; ++ p ) { +148: SetBackColor ( p & 1 ? cLtRed : cLtPurple ) ; +149: +150: struct PatchInfo { +151: uchar index < format = hex > ; +152: uchar unknown [ 3 ] < format = hex > ; +153: uint length < format = hex > ; +154: uint position < format = hex > ; +155: } patch_info < read = get_patch_info > ; +156: } +157: +158: +159: for ( size = 0 , pos = FTell ( ) ; ReadUInt ( pos ) == 0 ; ++ size , pos += 4 ) { +160: } +161: if ( size > 0 ) { +162: SetBackColor ( cSilver ) ; +163: struct PIPadding { +164: uint zeros [ size ] ; +165: } pi_padding ; +166: } +167: +168: if ( file_info . dependant_file_info_offset == 0 ) +169: break ; +170: FSeek ( file_info . dependant_file_info_offset ) ; +171: } +172: +173: } +174: +175: if ( f != header . num_files ) { +176: Printf ( "Only %d of %d files found.\n" , f , header . num_files ) ; +177: return - 1 ; +178: +179: } +180: +181: +182: local uint pi = 0 ; +183: for ( f = 0 ; f < header . num_files ; ++ f ) { +184: for ( p = 0 ; p < file_info [ f ] . num_patches + 1 ; ++ p , ++ pi ) { +185: SetBackColor ( pi & 1 ? cLtYellow : cLtBlue ) ; +186: FSeek ( patch_info [ pi ] . position ) ; +187: +188: +189: +190: +191: +192: +193: struct Patch { +194: char signature [ 4 ] ; +195: uchar flag1 < format = hex > ; +196: uchar flag2 < format = hex > ; +197: uchar flag3 < format = hex > ; +198: uchar flag4 < format = hex > ; +199: +200: +201: uint file1 < format = hex > ; +202: uint file2 < format = hex > ; +203: uint file3 < format = hex > ; +204: uint patch1 < format = hex > ; +205: uint patch2 < format = hex > ; +206: if ( patch_info [ pi ] . length > 7 * 4 ) { +207: uchar unknown [ patch_info [ pi ] . length - 7 * 4 ] ; +208: } +209: } patch ; +210: +211: +212: if ( 0 != Memcmp ( patch . signature , "PA19" , sizeof ( patch . signature ) ) ) { +213: Printf ( "Invalid patch signature. Expected 'PA19'. File %d %s, patch info %d (index %d, position %Xh, length %Xh).\n" , f , file_info [ f ] . name , pi , patch_info [ pi ] . index , patch_info [ pi ] . position , patch_info [ pi ] . length ) ; +214: +215: } +216: } +217: +218: } +219: +220: SetBackColor ( cNone ) ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/PYCTemplate.bt b/cparser/tests/exp_lex/PYCTemplate.bt new file mode 100644 index 0000000..68b9b25 --- /dev/null +++ b/cparser/tests/exp_lex/PYCTemplate.bt @@ -0,0 +1,472 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: enum < uint16 > MagicValue { +12: PY_24a0 = 62041 , +13: PY_24a3 = 62051 , +14: PY_24b1 = 62061 , +15: PY_25a0_1 = 62071 , +16: PY_25a0_2 = 62081 , +17: PY_25a0_3 = 62091 , +18: PY_25a0_4 = 62092 , +19: PY_25b3_1 = 62101 , +20: PY_25b3_2 = 62111 , +21: PY_25c1 = 62121 , +22: PY_25c2 = 62131 , +23: PY_26a0 = 62151 , +24: PY_26a1 = 62161 , +25: PY_27a0_1 = 62171 , +26: PY_27a0_2 = 62181 , +27: } ; +28: +29: +30: +31: enum < char > ObjType { +32: TYPE_NULL = '0' , +33: TYPE_NONE = 'N' , +34: TYPE_FALSE = 'F' , +35: TYPE_TRUE = 'T' , +36: TYPE_STOPITER = 'S' , +37: TYPE_ELLIPSIS = '.' , +38: TYPE_INT = 'i' , +39: TYPE_INT64 = 'I' , +40: TYPE_FLOAT = 'f' , +41: TYPE_BINARY_FLOAT = 'g' , +42: TYPE_COMPLEX = 'x' , +43: TYPE_BINARY_COMPLEX = 'y' , +44: TYPE_LONG = 'l' , +45: TYPE_STRING = 's' , +46: TYPE_INTERNED = 't' , +47: TYPE_STRINGREF = 'R' , +48: TYPE_TUPLE = '(' , +49: TYPE_LIST = '[' , +50: TYPE_DICT = '{' , +51: TYPE_CODE = 'c' , +52: TYPE_UNICODE = 'u' , +53: TYPE_UNKNOWN = '?' , +54: TYPE_SET = '<' , +55: TYPE_FROZENSET = '>' , +56: } ; +57: +58: +59: struct Magic { +60: MagicValue magic1 ; +61: char magic2 [ 2 ] ; +62: if ( magic2 != "\r\n" ) { +63: Warning ( "bad magic" ) ; +64: return 0 ; +65: } +66: if ( EnumToString ( magic1 ) == "" ) { +67: Warning ( "Unknown magic version" ) ; +68: return 0 ; +69: } +70: } ; +71: +72: +73: +74: +75: enum < ubyte > OpCode { +76: STOP_CODE = 0 , +77: POP_TOP = 1 , +78: ROT_TWO = 2 , +79: ROT_THREE = 3 , +80: DUP_TOP = 4 , +81: ROT_FOUR = 5 , +82: +83: UNARY_POSITIVE = 10 , +84: UNARY_NEGATIVE = 11 , +85: UNARY_NOT = 12 , +86: UNARY_CONVERT = 13 , +87: +88: UNARY_INVERT = 15 , +89: +90: LIST_APPEND = 18 , +91: BINARY_POWER = 19 , +92: +93: BINARY_MULTIPLY = 20 , +94: BINARY_DIVIDE = 21 , +95: BINARY_MODULO = 22 , +96: BINARY_ADD = 23 , +97: BINARY_SUBTRACT = 24 , +98: BINARY_SUBSCR = 25 , +99: BINARY_FLOOR_DIVIDE = 26 , +100: BINARY_TRUE_DIVIDE = 27 , +101: INPLACE_FLOOR_DIVIDE = 28 , +102: INPLACE_TRUE_DIVIDE = 29 , +103: +104: SLICE = 30 , +105: +106: SLICE_a = 31 , +107: SLICE_b = 32 , +108: SLICE_c = 33 , +109: +110: STORE_SLICE = 40 , +111: +112: STORE_SLICE_a = 41 , +113: STORE_SLICE_b = 42 , +114: STORE_SLICE_c = 43 , +115: +116: DELETE_SLICE = 50 , +117: +118: DELETE_SLICE_a = 51 , +119: DELETE_SLICE_b = 52 , +120: DELETE_SLICE_c = 53 , +121: +122: INPLACE_ADD = 55 , +123: INPLACE_SUBTRACT = 56 , +124: INPLACE_MULTIPLY = 57 , +125: INPLACE_DIVIDE = 58 , +126: INPLACE_MODULO = 59 , +127: STORE_SUBSCR = 60 , +128: DELETE_SUBSCR = 61 , +129: +130: BINARY_LSHIFT = 62 , +131: BINARY_RSHIFT = 63 , +132: BINARY_AND = 64 , +133: BINARY_XOR = 65 , +134: BINARY_OR = 66 , +135: INPLACE_POWER = 67 , +136: GET_ITER = 68 , +137: +138: PRINT_EXPR = 70 , +139: PRINT_ITEM = 71 , +140: PRINT_NEWLINE = 72 , +141: PRINT_ITEM_TO = 73 , +142: PRINT_NEWLINE_TO = 74 , +143: INPLACE_LSHIFT = 75 , +144: INPLACE_RSHIFT = 76 , +145: INPLACE_AND = 77 , +146: INPLACE_XOR = 78 , +147: INPLACE_OR = 79 , +148: BREAK_LOOP = 80 , +149: WITH_CLEANUP = 81 , +150: LOAD_LOCALS = 82 , +151: RETURN_VALUE = 83 , +152: IMPORT_STAR = 84 , +153: EXEC_STMT = 85 , +154: YIELD_VALUE = 86 , +155: POP_BLOCK = 87 , +156: END_FINALLY = 88 , +157: BUILD_CLASS = 89 , +158: +159: +160: STORE_NAME = 90 , +161: DELETE_NAME = 91 , +162: UNPACK_SEQUENCE = 92 , +163: FOR_ITER = 93 , +164: +165: STORE_ATTR = 95 , +166: DELETE_ATTR = 96 , +167: STORE_GLOBAL = 97 , +168: DELETE_GLOBAL = 98 , +169: DUP_TOPX = 99 , +170: LOAD_CONST = 100 , +171: LOAD_NAME = 101 , +172: BUILD_TUPLE = 102 , +173: BUILD_LIST = 103 , +174: BUILD_MAP = 104 , +175: LOAD_ATTR = 105 , +176: COMPARE_OP = 106 , +177: IMPORT_NAME = 107 , +178: IMPORT_FROM = 108 , +179: +180: JUMP_FORWARD = 110 , +181: JUMP_IF_FALSE = 111 , +182: JUMP_IF_TRUE = 112 , +183: JUMP_ABSOLUTE = 113 , +184: +185: LOAD_GLOBAL = 116 , +186: +187: CONTINUE_LOOP = 119 , +188: SETUP_LOOP = 120 , +189: SETUP_EXCEPT = 121 , +190: SETUP_FINALLY = 122 , +191: +192: LOAD_FAST = 124 , +193: STORE_FAST = 125 , +194: DELETE_FAST = 126 , +195: +196: RAISE_VARARGS = 130 , +197: +198: CALL_FUNCTION = 131 , +199: MAKE_FUNCTION = 132 , +200: BUILD_SLICE = 133 , +201: +202: MAKE_CLOSURE = 134 , +203: LOAD_CLOSURE = 135 , +204: LOAD_DEREF = 136 , +205: STORE_DEREF = 137 , +206: +207: +208: +209: CALL_FUNCTION_VAR = 140 , +210: CALL_FUNCTION_KW = 141 , +211: CALL_FUNCTION_VAR_KW = 142 , +212: +213: +214: EXTENDED_ARG = 143 , +215: } ; +216: +217: +218: const int HAVE_ARGUMENT = 90 ; +219: const int EXTENDED_ARG = 143 ; +220: struct Instruction { +221: if ( ReadUByte ( FTell ( ) ) == EXTENDED_ARG ) { +222: ubyte opcode_extended_arg ; +223: uint16 oparg_hi ; +224: ubyte opcode ; +225: if ( opcode >= HAVE_ARGUMENT ) +226: uint16 oparg ; +227: } else { +228: ubyte opcode ; +229: if ( opcode >= HAVE_ARGUMENT ) +230: uint16 oparg ; +231: } +232: } ; +233: +234: typedef int32 r_long ; +235: typedef int64 r_long64 ; +236: typedef int16 r_short ; +237: typedef ubyte r_byte ; +238: +239: struct Code { +240: ObjType type ; +241: if ( type != TYPE_STRING ) { +242: Warning ( "code not in string type" ) ; +243: Exit ( 1 ) ; +244: } +245: r_long n ; +246: local int remain = n ; +247: local int end = FTell ( ) + n ; +248: +249: +250: while ( remain >= 6 ) { +251: Instruction inst [ remain / 6 ] < read = ReadInstruction , optimize = false > ; +252: remain = end - FTell ( ) ; +253: } +254: remain = end - FTell ( ) ; +255: +256: while ( remain > 0 ) { +257: Instruction inst < read = ReadInstruction > ; +258: remain -= sizeof ( inst ) ; +259: } +260: } ; +261: +262: string Opcode2Opname ( OpCode opcode ) +263: { +264: uint16 magic = file . magic . magic1 ; +265: local string opname = EnumToString ( opcode ) ; +266: if ( magic >= 0 ) { +267: +268: if ( opcode == 114 ) opname = "" ; +269: +270: if ( opcode == 81 ) opname = "RETURN_NONE" ; +271: +272: if ( opcode == 81 ) opname = "" ; +273: +274: if ( opcode == 9 ) opname = "NOP" ; +275: +276: if ( opcode == 9 ) opcode = "" ; +277: +278: if ( opcode == 18 ) opname = "LIST_APPEND" ; +279: +280: if ( opcode == 9 ) opname = "NOP" ; +281: } +282: +283: +284: +285: +286: +287: if ( magic >= 62091 ) { +288: +289: if ( opcode == 81 ) opname = "WITH_CLEANUP" ; +290: } +291: +292: +293: +294: +295: +296: if ( magic >= 62151 ) { +297: +298: if ( opcode == 54 ) opname = "STORE_MAP" ; +299: } +300: +301: if ( magic >= 62171 ) { +302: +303: if ( opcode == 18 ) opname = "" ; +304: if ( opcode == 94 ) opname = "LIST_APPEND" ; +305: } +306: if ( magic >= 62181 ) { +307: +308: if ( opcode == 111 ) opname = "JUMP_IF_FALSE_OR_POP" ; +309: if ( opcode == 112 ) opname = "JUMP_IF_TRUE_OR_POP" ; +310: if ( opcode == 114 ) opname = "POP_JUMP_IF_FALSE" ; +311: if ( opcode == 115 ) opname = "POP_JUMP_IF_TRUE" ; +312: } +313: +314: return opname ; +315: } +316: +317: string ReadInstruction ( Instruction & ins ) +318: { +319: string s ; +320: uint16 magic = file . magic . magic1 ; +321: OpCode opcode = ( OpCode ) ins . opcode ; +322: string opname = Opcode2Opname ( opcode ) ; +323: if ( exists ( ins . oparg ) ) { +324: uint32 oparg = ins . oparg ; +325: if ( exists ( ins . oparg_hi ) ) +326: oparg += ( uint32 ) ins . oparg_hi << 16 ; +327: +328: if ( opname == "COMPARE_OP" ) { +329: string cmp_op ; +330: switch ( oparg ) { +331: case 0 : cmp_op = "<" ; break ; +332: case 1 : cmp_op = "<=" ; break ; +333: case 2 : cmp_op = "==" ; break ; +334: case 3 : cmp_op = "!=" ; break ; +335: case 4 : cmp_op = ">" ; break ; +336: case 5 : cmp_op = ">=" ; break ; +337: case 6 : cmp_op = "in" ; break ; +338: case 7 : cmp_op = "not in" ; break ; +339: case 8 : cmp_op = "is" ; break ; +340: case 9 : cmp_op = "is not" ; break ; +341: case 10 : cmp_op = "exception match" ; break ; +342: case 11 : cmp_op = "BAD" ; break ; +343: } +344: SPrintf ( s , "%s (%s)" , opname , cmp_op ) ; +345: +346: } else { +347: SPrintf ( s , "%s %d" , opname , oparg ) ; +348: } +349: } else { +350: s = opname ; +351: } +352: return s ; +353: } +354: +355: struct LnoTab { +356: ObjType type ; +357: if ( type != TYPE_STRING ) { +358: Warning ( "lnotab not in string type" ) ; +359: Exit ( 1 ) ; +360: } +361: r_long n ; +362: struct { +363: uchar bytecode_offset_diff ; +364: uchar line_diff ; +365: } pair [ n / 2 ] ; +366: } ; +367: +368: +369: typedef struct r_object { +370: ObjType type ; +371: switch ( type ) { +372: case TYPE_NULL : +373: case TYPE_NONE : +374: case TYPE_STOPITER : +375: case TYPE_ELLIPSIS : +376: case TYPE_FALSE : +377: case TYPE_TRUE : +378: break ; +379: case TYPE_INT : +380: r_long value ; +381: break ; +382: case TYPE_INT64 : +383: r_long64 value ; +384: break ; +385: case TYPE_LONG : +386: r_long n ; +387: local int size = n < 0 ? - n : n ; +388: r_short digit [ size ] ; +389: break ; +390: case TYPE_FLOAT : +391: r_byte n ; +392: char value [ n ] ; +393: break ; +394: case TYPE_BINARY_FLOAT : +395: double value ; +396: break ; +397: +398: case TYPE_COMPLEX : +399: r_byte nr ; +400: char real [ nr ] ; +401: r_byte ni ; +402: char imag [ ni ] ; +403: break ; +404: +405: case TYPE_BINARY_COMPLEX : +406: double real ; +407: double imag ; +408: break ; +409: +410: case TYPE_INTERNED : +411: case TYPE_STRING : +412: r_long n ; +413: if ( n ) +414: char str [ n ] ; +415: break ; +416: case TYPE_STRINGREF : +417: r_long n ; +418: break ; +419: case TYPE_TUPLE : +420: r_long n ; +421: if ( n ) +422: struct r_object elements [ n ] < optimize = false > ; +423: break ; +424: case TYPE_LIST : +425: r_long n ; +426: if ( n ) +427: struct r_object elements [ n ] < optimize = false > ; +428: break ; +429: case TYPE_DICT : +430: while ( 1 ) { +431: struct r_object key ; +432: if ( key . type == TYPE_NULL ) +433: break ; +434: struct r_object val ; +435: } +436: break ; +437: case TYPE_SET : +438: case TYPE_FROZENSET : +439: r_long n ; +440: if ( n ) +441: struct r_object elements [ n ] < optimize = false > ; +442: break ; +443: case TYPE_CODE : +444: r_long argcount ; +445: r_long nlocals ; +446: r_long stacksize ; +447: r_long flags ; +448: +449: Code code ; +450: struct r_object consts ; +451: struct r_object names ; +452: struct r_object varnames ; +453: struct r_object freevars ; +454: struct r_object cellvars ; +455: struct r_object filename ; +456: struct r_object name ; +457: r_long firstlineno ; +458: +459: LnoTab lnotab ; +460: break ; +461: default : +462: Warning ( "unknown type code" ) ; +463: Exit ( 1 ) ; +464: } +465: } r_object ; +466: +467: struct { +468: Magic magic ; +469: char mtime [ 4 ] ; +470: r_object data ; +471: } file ; +472: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/RARTemplate.bt b/cparser/tests/exp_lex/RARTemplate.bt new file mode 100644 index 0000000..4993d63 --- /dev/null +++ b/cparser/tests/exp_lex/RARTemplate.bt @@ -0,0 +1,457 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: LittleEndian ( ) ; +16: +17: local const uint16 SignatureLen = 7 ; +18: const string RarSignature = "Rar!" + '\x1A' + '\x07' ; +19: +20: +21: +22: struct FileHeadBlock ; +23: struct OldCommentBlock ; +24: struct OldSubBlock ; +25: struct SubBlock ; +26: +27: +28: +29: enum < byte > RarBlockType +30: { +31: MARKER = 0x72 , ARCHIVE , FILE_OR_DIR , COMMENT_OLD , AV_OLD_1 , SUBBLOCK_OLD , RR_OLD , AV_OLD_2 , SUBBLOCK , _END_ +32: } ; +33: +34: +35: +36: local uint16 _flags = 0 ; +37: +38: +39: local uquad iBlocksCounter = 0 ; +40: local uquad iFiles = 0 ; +41: local uquad iDirs = 0 ; +42: local uquad iComments = 0 ; +43: local uquad iSubBlocks = 0 ; +44: local uquad iUniNames = 0 ; +45: local uquad iBadCRCCounter = 0 ; +46: local ubyte iMinVerToUnpack = 0xFF ; +47: local ubyte iMaxVerToUnpack = 0 ; +48: local uquad iTotalUnpackedSize = 0 ; +49: local uint iAV1 = 0 ; +50: local uint iAV2 = 0 ; +51: +52: +53: +54: enum < ubyte > OsType +55: { +56: _MS_DOS , _OS_2 , _Win32 , _Unix , _Mac_OS , _BeOS +57: } ; +58: +59: enum < char > PackMethod +60: { +61: Store = '0' , Fastest , Fast , Normal , Good , Best +62: } ; +63: +64: enum < uint16 > SubType_OldStyle +65: { +66: OS2_EA = 0x100 +67: } ; +68: +69: struct UnixStyleAttrs +70: { +71: uint32 owner_may_eXecute : 1 ; +72: uint32 owner_may_Write : 1 ; +73: uint32 owner_may_Read : 1 ; +74: +75: uint32 group_may_eXecute : 1 ; +76: uint32 gorup_may_Write : 1 ; +77: uint32 group_may_Read : 1 ; +78: +79: uint32 everybody_may_eXecute : 1 ; +80: uint32 everybody_may_Write : 1 ; +81: uint32 everybody_may_Read : 1 ; +82: +83: uint32 _s : 1 ; +84: uint32 _s : 1 ; +85: +86: uint32 _unused : 21 ; +87: } ; +88: +89: struct DosFileAttrs +90: { +91: uint32 READONLY : 1 ; +92: uint32 HIDDEN : 1 ; +93: uint32 SYSTEM : 1 ; +94: uint32 VOLUME : 1 ; +95: uint32 DIRECTORY : 1 ; +96: uint32 ARCHIVE : 1 ; +97: uint32 _res : 26 ; +98: } ; +99: +100: struct WinFileAttrs +101: { +102: uint32 READONLY : 1 ; +103: uint32 HIDDEN : 1 ; +104: uint32 SYSTEM : 1 ; +105: uint32 VOLUME : 1 ; +106: uint32 DIRECTORY : 1 ; +107: uint32 ARCHIVE : 1 ; +108: uint32 DEVICE : 1 ; +109: uint32 NORMAL : 1 ; +110: uint32 TEMPORARY : 1 ; +111: uint32 SPARSE_FILE : 1 ; +112: uint32 REPARSE_POINT : 1 ; +113: uint32 COMPRESSED : 1 ; +114: uint32 OFFLINE : 1 ; +115: uint32 NOT_CONTENT_INDEXED : 1 ; +116: uint32 ENCRYPTED : 1 ; +117: uint32 _res2 : 17 ; +118: } ; +119: +120: struct CommonBlockFlags +121: { +122: ushort _reserved : 14 ; +123: ushort OLD_VERSION_IGNORE : 1 ; +124: ushort ADD_SIZE_PRESENT : 1 ; +125: } ; +126: +127: struct MainHeadFlags +128: { +129: ubyte ARCHIVE_VOLUME : 1 ; +130: ubyte ARCHIVE_COMMENT_PRESENT : 1 ; +131: ubyte ARCHIVE_LOCKED : 1 ; +132: ubyte ARCHIVE_SOLID : 1 ; +133: ubyte NEW_VOLUME_NAMING : 1 ; +134: ubyte AV_PRESENT : 1 ; +135: ubyte RECOVERY_PRESENT : 1 ; +136: ubyte BLOCK_HEADERS_ENCRYPTED : 1 ; +137: ubyte IS_FIRST_VOLUME : 1 ; +138: ubyte _reserved : 5 ; +139: ubyte OLD_VERSION_IGNORE : 1 ; +140: ubyte ADD_SIZE_PRESENT : 1 ; +141: } ; +142: +143: +144: enum < byte > FileDictType +145: { +146: _64K , _128K , _256K , _512K , _1024K , _2048K , _4096K , _Directory +147: } ; +148: +149: struct FileHeadFlags +150: { +151: ubyte from_PREV_VOLUME : 1 ; +152: ubyte to_NEXT_VOLUME : 1 ; +153: ubyte PASSWORD_ENCRYPTED : 1 ; +154: ubyte FILE_COMMENT_PRESENT : 1 ; +155: ubyte SOLID : 1 ; +156: FileDictType DICTIONARY : 3 ; +157: ubyte HIGH_SIZE : 1 ; +158: ubyte has_UNICODE_FILENAME : 1 ; +159: ubyte ENCRYPTION_SALT : 1 ; +160: ubyte IS_OLD_FILE_VERSION : 1 ; +161: ubyte EXTENDED_TIME_INFO : 1 ; +162: ubyte _reserved : 1 ; +163: ubyte OLD_VERSION_IGNORE : 1 ; +164: ubyte ADD_SIZE_PRESENT : 1 ; +165: } ; +166: +167: struct RarBlock +168: { +169: local quad iOfs = FTell ( ) ; +170: +171: uint16 HEAD_CRC < format = hex , fgcolor = cRed > ; +172: +173: RarBlockType HeadType < fgcolor = cGreen > ; +174: +175: _flags = ReadUShort ( FTell ( ) ) ; +176: +177: if ( HeadType == ARCHIVE ) +178: MainHeadFlags HEAD_FLAGS ; +179: else if ( HeadType == FILE_OR_DIR ) +180: FileHeadFlags HEAD_FLAGS ; +181: else +182: CommonBlockFlags HEAD_FLAGS ; +183: +184: ++ iBlocksCounter ; +185: +186: if ( HeadType < MARKER || HeadType > _END_ ) +187: { +188: Warning ( "Unknown Header Type (0x%02x) in Block #%Lu" , HeadType , iBlocksCounter ) ; +189: Printf ( "Unknown Header Type (0x%02x) in Block #%Lu\n" , HeadType , iBlocksCounter ) ; +190: } +191: +192: uint16 HeaderSize ; +193: +194: if ( HeaderSize < 7 ) +195: { +196: Warning ( "Invalid block size (%u) in Block #%Lu" , HeaderSize , iBlocksCounter ) ; +197: Printf ( "Invalid block size (%u) in Block #%Lu\n" , HeaderSize , iBlocksCounter ) ; +198: return - 1 ; +199: } +200: +201: if ( HeadType != MARKER ) +202: { +203: local uint16 crcCheck = Checksum ( CHECKSUM_CRC32 , startof ( HeadType ) , HeaderSize - sizeof ( HEAD_CRC ) ) & 0xFFFF ; +204: if ( crcCheck != HEAD_CRC ) +205: { +206: Warning ( "Header CRC mismatch in Block #%Lu" , iBlocksCounter ) ; +207: Printf ( "Header CRC mismatch in Block #%Lu: expected CRC is 0x%X, got 0x%X\n" , iBlocksCounter , crcCheck , HEAD_CRC ) ; +208: ++ iBadCRCCounter ; +209: } +210: } +211: +212: if ( HEAD_FLAGS . ADD_SIZE_PRESENT ) +213: uint32 RawDataSize ; +214: else +215: local uint32 RawDataSize = 0 ; +216: +217: switch ( HeadType ) { +218: case ARCHIVE : +219: uint16 _reserved1 ; +220: uint32 _reserved2 ; +221: if ( HEAD_FLAGS . ARCHIVE_COMMENT_PRESENT ) struct RarBlock MainComment ; +222: break ; +223: case FILE_OR_DIR : +224: if ( HEAD_FLAGS . DICTIONARY == 7 ) +225: { +226: ++ iDirs ; +227: FileHeadBlock dir ; +228: } +229: else +230: { +231: ++ iFiles ; +232: FileHeadBlock file ; +233: } +234: break ; +235: case COMMENT_OLD : +236: OldCommentBlock cmm ; +237: break ; +238: case SUBBLOCK_OLD : +239: OldSubBlocksub ; +240: break ; +241: case SUBBLOCK : +242: SubBlock sub ; +243: break ; +244: case AV_OLD_1 : +245: ++ iAV1 ; +246: Printf ( "*** AV was found (RAR v. < 2.60) @ block #%Lu.\n" , iBlocksCounter ) ; +247: break ; +248: case AV_OLD_2 : +249: ++ iAV2 ; +250: Printf ( "*** AV was found (RAR v. 2.60 - 2.9x) @ block #%Lu.\n" , iBlocksCounter ) ; +251: break ; +252: } +253: +254: iOfs = HeaderSize - ( FTell ( ) - iOfs ) ; +255: +256: if ( iOfs > 0 ) +257: ubyte _reserved [ iOfs ] ; +258: +259: if ( RawDataSize > 0 ) +260: ubyte _raw [ RawDataSize ] < format = hex , fgcolor = cBlue > ; +261: } ; +262: +263: struct FileHeadBlock +264: { +265: uint32 UnpackedSize ; +266: iTotalUnpackedSize += UnpackedSize ; +267: +268: OsType Host_OS ; +269: uint32 FileCRC32 < format = hex > ; +270: DOSTIME FileTime ; +271: DOSDATE FileDate ; +272: ubyte VersionToUnpack ; +273: +274: if ( VersionToUnpack > iMaxVerToUnpack ) +275: iMaxVerToUnpack = VersionToUnpack ; +276: +277: if ( VersionToUnpack < iMinVerToUnpack ) +278: iMinVerToUnpack = VersionToUnpack ; +279: +280: PackMethod Method ; +281: uint16 NameSize ; +282: +283: switch ( Host_OS ) { +284: case _Win32 : +285: WinFileAttrs Attributes ; +286: break ; +287: case _MS_DOS : +288: case _Mac_OS : +289: case _OS_2 : +290: DosFileAttrs Attributes ; +291: break ; +292: case _Unix : +293: case _BeOS : +294: UnixStyleAttrs Attributes ; +295: break ; +296: default : +297: uint32 Attributes < format = binary > ; +298: } +299: +300: if ( _flags & 0x100 ) +301: { +302: uint32 HIGH_PACK_SIZE ; +303: uint32 HIGH_UNP_SIZE ; +304: +305: iTotalUnpackSize += ( HIGH_UNP_SIZE << 32 ) ; +306: } +307: +308: if ( _flags & 0x200 ) +309: { +310: ++ iUniNames ; +311: +312: string FileName ; +313: uint16 WideFileNameData [ ( NameSize - sizeof ( FileName ) ) / 2 ] ; +314: } +315: else +316: char FileName [ NameSize ] ; +317: +318: if ( _flags & 0x8 ) +319: { +320: RarBlock FileComment ; +321: } +322: +323: if ( _flags & 0x400 ) +324: uquad SALT < format = hex > ; +325: } ; +326: +327: +328: +329: struct OldCommentBlock { +330: ++ iComments ; +331: +332: uint16 UnpackedSize ; +333: ubyte VersionToUnpack ; +334: PackMethod Method ; +335: uint16 CommentCRC < format = hex > ; +336: +337: Printf ( "*** Old style CommentBlock: (Block #%Lu)\n" , iBlocksCounter ) ; +338: } ; +339: +340: struct OldSubBlock { +341: ++ iSubBlocks ; +342: +343: SubType_OldStyle SubType ; +344: ubyte _reserved ; +345: +346: Printf ( "*** Old style SubBlock: %u (Block #%Lu)\n" , SubType , iBlocksCounter ) ; +347: } ; +348: +349: struct SubBlock { +350: ++ iSubBlocks ; +351: +352: ubyte _unknown_to_me_1 [ 15 ] ; +353: ubyte SubTypeLen ; +354: ubyte _unknown_to_me_2 [ 5 ] ; +355: char SubType [ SubTypeLen ] ; +356: +357: Printf ( "*** SubBlock: %s (Block #%Lu)\n" , SubType + '\0' , iBlocksCounter ) ; +358: switch ( SubType ) { +359: case "CMT" : +360: ++ iComments ; +361: break ; +362: case "AV" : +363: Printf ( "*** Authenticity Verification info (RAR v. 3.x) @ block #%Lu.\n" , iBlocksCounter ) ; +364: break ; +365: case "RR" : +366: Printf ( "*** Recovery Record was found (RAR v. 3.x) @ block #%Lu.\n" , iBlocksCounter ) ; +367: break ; +368: } +369: } ; +370: +371: +372: +373: local string fn = GetFileName ( ) ; +374: local quad SignaturePos = 0 ; +375: local char Signature [ SignatureLen ] ; +376: +377: if ( Strstr ( fn , ".rar" ) != Strlen ( fn ) - 4 ) +378: { +379: Warning ( "Seeking for RAR signature..." ) ; +380: +381: local quad _p = FindFirst ( RarSignature ) ; +382: if ( _p >= 0 ) +383: FSeek ( _p ) ; +384: else +385: { +386: Warning ( "Not a RAR archive!" ) ; +387: return - 1 ; +388: } +389: +390: Warning ( "RAR signature found at 0x%08x." , _p ) ; +391: Printf ( "RAR signature found at 0x%08x.\n" , _p ) ; +392: } +393: else +394: { +395: ReadBytes ( Signature , SignaturePos , SignatureLen ) ; +396: +397: if ( Strcmp ( Signature , RarSignature ) ) +398: { +399: Warning ( "Invalid RAR Archive Signature!" ) ; +400: return SignaturePos ; +401: } +402: } +403: +404: RarBlock Marker ; +405: +406: RarBlock ArcHeader ; +407: if ( ArcHeader . HeadType != ARCHIVE ) +408: { +409: Warning ( "Main archive header is either bad or missing!" ) ; +410: return - 2 ; +411: } +412: else +413: { +414: Printf ( "It is a %s%s %s %s RAR archive.\n" , +415: SignaturePos > 0 ? "SelF-eXtractable " : "" , +416: ArcHeader . HEAD_FLAGS . ARCHIVE_LOCKED ? "LOCKED" : "non-locked" , +417: ArcHeader . HEAD_FLAGS . ARCHIVE_SOLID ? "SOLID" : "regular" , +418: ArcHeader . HEAD_FLAGS . ARCHIVE_VOLUME ? "VOLUME'd" : "one-part" ) ; +419: +420: if ( ArcHeader . HEAD_FLAGS . ARCHIVE_COMMENT_PRESENT ) +421: Printf ( "Main comment is present.\n" ) ; +422: if ( ArcHeader . HEAD_FLAGS . AV_PRESENT ) +423: Printf ( "Old style Authenticity Verification is present.\n" ) ; +424: if ( ArcHeader . HEAD_FLAGS . RECOVERY_PRESENT ) +425: Printf ( "Recovery Record is present.\n" ) ; +426: +427: if ( ArcHeader . HEAD_FLAGS . BLOCK_HEADERS_ENCRYPTED ) +428: { +429: Printf ( "It's an encrypted archive. Cannot proceed, exiting...\n" ) ; +430: return - 3 ; +431: } +432: } +433: +434: while ( ! FEof ( ) ) +435: { +436: RarBlock block ; +437: } +438: +439: if ( block . HeadType != _END_ && iMaxVerToUnpack > 20 ) +440: { +441: Warning ( "END Marker block was expected here." ) ; +442: } +443: +444: if ( iFiles || iDirs ) +445: { +446: Printf ( "Version to unpack: %u.%u\n" , iMaxVerToUnpack / 10 , iMaxVerToUnpack % 10 ) ; +447: if ( iMinVerToUnpack != iMaxVerToUnpack ) +448: Printf ( "Some data can also be retrieved by an earlier version of %u.%u\n" , +449: iMinVerToUnpack / 10 , iMinVerToUnpack % 10 ) ; +450: } +451: +452: Printf ( "Files: %Lu, Dirs: %Lu, Comments: %Lu, SubBlocks: %Lu, Unpacked Size: %Lu\n" , iFiles , iDirs , iComments , iSubBlocks , iTotalUnpackedSize ) ; +453: Printf ( "UNICODE Names: %Lu\n" , iUniNames ) ; +454: if ( iBadCRCCounter ) +455: Printf ( "%Lu blocks corrupted.\n" , iBadCRCCounter ) ; +456: Printf ( "Done. %Lu blocks processed.\n" , iBlocksCounter ) ; +457: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/RDBTemplate.bt b/cparser/tests/exp_lex/RDBTemplate.bt new file mode 100644 index 0000000..c844d0a --- /dev/null +++ b/cparser/tests/exp_lex/RDBTemplate.bt @@ -0,0 +1,59 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: typedef struct { +16: CHAR reserved [ 16 ] ; +17: DWORD fhFileTotalCount ; +18: INT64 fhFileNameOffBits < format = hex > ; +19: INT64 fhFileDataOffBits < format = hex > ; +20: } RDBFILEHEADER ; +21: +22: +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 != 0x0 ) ; +31: +32: CHAR frCurFileName [ fileNameLength ] ; +33: INT64 frCurFileDataOffBits < format = hex > ; +34: INT64 frCurFileDataSize ; +35: } RDBFILERECORD < read = ReadRDBFILERECORD > ; +36: +37: string ReadRDBFILERECORD ( RDBFILERECORD & r ) +38: { +39: string s ; +40: SPrintf ( s , "%s" , r . frCurFileName ) ; +41: return s ; +42: } +43: +44: +45: +46: +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: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/RESTemplate.bt b/cparser/tests/exp_lex/RESTemplate.bt new file mode 100644 index 0000000..c27c99b --- /dev/null +++ b/cparser/tests/exp_lex/RESTemplate.bt @@ -0,0 +1,552 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: local int64 rsrc_va , rsrc_sa , rsrc_ea , res_level ; +20: local int32 rTypeID , rNameID , rLanguageID ; +21: local int res_show_log = 0 ; +22: +23: +24: GoTo_rsrc_section ( ) ; +25: if ( rsrc_va > 0 ) +26: { +27: +28: RESfromPEDiscover ( ) ; +29: } +30: else +31: { +32: +33: RESfromRESDiscover ( ) ; +34: } +35: +36: +37: typedef struct { +38: char Signature [ 2 ] ; +39: WORD LengthOfImage ; +40: WORD SizeOfFile ; +41: WORD NumberOfRelocationItems ; +42: WORD SizeOfHeader ; +43: WORD MinPara ; +44: WORD MaxPara ; +45: WORD OffsetStack ; +46: WORD InitialSp ; +47: WORD NegativeChecksum ; +48: WORD InitialIp ; +49: WORD OffsetCs ; +50: WORD OffsetFirstRelocationItem ; +51: WORD OverlayNumber ; +52: WORD Res1 ; +53: WORD Res2 ; +54: WORD Res3 ; +55: WORD Res4 ; +56: WORD OemId ; +57: WORD OemInfo ; +58: WORD Res5 [ 10 ] ; +59: DWORD OffsetToPEHeader ; +60: } DosExeHeader ; +61: +62: typedef struct { +63: int32 DirExport ; +64: int32 DirExportSize ; +65: int32 DirImport ; +66: int32 DirImportSize ; +67: int32 DirResource ; +68: int32 DirResourceSize ; +69: int32 DirException ; +70: int32 DirExceptionSize ; +71: int32 DirSecurity ; +72: int32 DirSecuritySize ; +73: int32 DirBasereloc ; +74: int32 DirBaserelocSize ; +75: int32 DirDebug ; +76: int32 DirDebugSize ; +77: int32 DirArchitecture ; +78: int32 DirArchitectureSize ; +79: int32 DirGlobalptr ; +80: int32 DirGlobalptrSize ; +81: int32 DirTls ; +82: int32 DirTlsSize ; +83: int32 DirLoadConfig ; +84: int32 DirLoadConfig_size ; +85: int32 DirBoundImport ; +86: int32 DirBoundImportSize ; +87: int32 DirIat ; +88: int32 DirIatSize ; +89: int32 DirDelayImport ; +90: int32 DirDelayImportSize ; +91: int32 DirComDescriptor ; +92: int32 DirComDescriptorSize ; +93: int32 DirX ; +94: int32 DirXSize ; +95: } DataDirectory ; +96: +97: typedef struct { +98: int32 rva ; +99: int32 size ; +100: } DataDir ; +101: +102: typedef struct { +103: char Sig [ 4 ] ; +104: int16 CpuType ; +105: int16 NumSections ; +106: time_t Tm ; +107: int32 PointerToSymbolTable ; +108: int32 NumberOfSymbols ; +109: int16 NtHeaderSize ; +110: int16 Flags ; +111: } PeHeader ; +112: +113: typedef struct { +114: int16 Res3 ; +115: char LMajor ; +116: char LMinor ; +117: int32 SizeOfCode ; +118: int32 SizeOfInitData ; +119: int32 SizeOfUninitData ; +120: int32 EntrypointRva ; +121: int32 BaseOfCode ; +122: int32 BaseOfData ; +123: int32 ImageBase ; +124: int32 SectionAlign ; +125: int32 FileAlign ; +126: int16 OsMajor ; +127: int16 OsMinor ; +128: int16 UserMajor ; +129: int16 UserMinor ; +130: int16 SubsystemMajor ; +131: int16 SubsystemMinor ; +132: int32 Win32VersionValue ; +133: int32 ImageSize ; +134: int32 HeaderSize ; +135: int32 FileChecksum ; +136: int16 Subsystem ; +137: int16 DllFlags ; +138: int32 StackReserveSize ; +139: int32 StackCommitSize ; +140: int32 HeapReserveSize ; +141: int32 HeapCommitSize ; +142: int32 LoaderFlags ; +143: int32 NumInterestingRvaSize ; +144: } OptionalHeader ; +145: +146: typedef struct { +147: char Name [ 8 ] ; +148: int32 VirtualSize ; +149: int32 VirtualAddress ; +150: int32 SizeOfRawData ; +151: int32 PointerToRawData ; +152: int32 PointerToRelocations ; +153: int32 PointerToLinenumbers ; +154: int16 NumberOfRelocations ; +155: int16 NumberOfLinenumbers ; +156: int32 Characteristics ; +157: } SectionTable ; +158: +159: void GetResourceDirectory ( ) +160: { +161: res_level += 1 ; +162: struct +163: { +164: local int32 j ; +165: uint32 Characteristics ; +166: DOSTIME TimeStamp ; +167: DOSDATE DataStamp ; +168: uint16 MajorVersion ; +169: uint16 MinorVersion ; +170: uint16 NumberOfNameEntries ; +171: uint16 NumberOfIDEntries ; +172: for ( j = 0 ; j < NumberOfNameEntries ; j ++ ) +173: { +174: struct +175: { +176: local int64 currentaddress ; +177: uint32 NameRVA : 31 < format = hex > ; +178: int TopBit : 1 ; +179: currentaddress = FTell ( ) ; +180: FSeek ( rsrc_sa + NameRVA ) ; +181: int16 Length ; +182: wchar_t UnicodeString [ Length ] ; +183: if ( res_show_log == 1 ) { Printf ( "\nLevel %d. " , res_level ) ; } +184: if ( res_show_log == 1 ) { Printf ( "Name: %s" , UnicodeString ) ; } +185: FSeek ( currentaddress ) ; +186: +187: uint32 DataEntryRVA : 31 < format = hex > ; +188: int PointToChild : 1 ; +189: currentaddress = FTell ( ) ; +190: if ( PointToChild == 1 ) +191: { +192: FSeek ( rsrc_sa + DataEntryRVA ) ; +193: GetResourceDirectory ( ) ; +194: FSeek ( currentaddress ) ; +195: } ; +196: } DirectoryNameEntry ; +197: } ; +198: for ( j = 0 ; j < NumberOfIDEntries ; j ++ ) +199: { +200: struct +201: { +202: local int64 currentaddress ; +203: switch ( res_level ) +204: { +205: case 1 : +206: uint32 IntegerID < comment = ShowType > ; +207: rTypeID = IntegerID ; +208: if ( res_show_log == 1 ) { Printf ( "\n%s" , ShowType ( rTypeID ) ) ; } +209: break ; +210: case 2 : +211: uint32 IntegerID < comment = ShowName > ; +212: rNameID = IntegerID ; +213: if ( res_show_log == 1 ) { Printf ( "\n%s" , ShowName ( rNameID ) ) ; } +214: break ; +215: case 3 : +216: uint32 IntegerID < comment = ShowLanguage > ; +217: rLanguageID = IntegerID ; +218: if ( res_show_log == 1 ) { Printf ( "\n%s" , ShowLanguage ( rLanguageID ) ) ; } +219: break ; +220: } +221: uint32 DataEntryRVA : 31 < format = hex > ; +222: int PointToChild : 1 ; +223: currentaddress = FTell ( ) ; +224: if ( PointToChild == 1 ) +225: { +226: FSeek ( rsrc_sa + DataEntryRVA ) ; +227: GetResourceDirectory ( ) ; +228: FSeek ( currentaddress ) ; +229: } +230: else +231: { +232: FSeek ( rsrc_sa + DataEntryRVA ) ; +233: struct +234: { +235: local int64 ba1 , ba2 ; +236: int32 DataRVA < format = hex > ; +237: int32 Size ; +238: int32 Codepage ; +239: int32 Reserved ; +240: FSeek ( DataRVA - ( rsrc_va - rsrc_sa ) ) ; +241: if ( rTypeID == 16 ) +242: { +243: struct +244: { +245: ba1 = FTell ( ) ; +246: char VersionInfoRAWData [ Size ] ; +247: ba2 = FTell ( ) ; +248: FSeek ( ba1 ) ; +249: VersionInfo ( ) ; +250: FSeek ( ba2 ) ; +251: } versioninfo ; +252: } +253: else +254: { +255: char ResourceRAWData [ Size ] ; +256: } ; +257: } DataEntry ; +258: FSeek ( currentaddress ) ; +259: } ; +260: } DirectoryIDEntry ; +261: } ; +262: } DirectoryTable ; +263: res_level -= 1 ; +264: } ; +265: +266: string ShowType ( uint32 ID ) +267: { +268: local string s ; +269: switch ( ID ) +270: { +271: case 1 : s = "Cursor" ; break ; +272: case 2 : s = "Bitmap" ; break ; +273: case 3 : s = "Icon" ; break ; +274: case 4 : s = "Menu" ; break ; +275: case 5 : s = "Dialog box" ; break ; +276: case 6 : s = "String table entry" ; break ; +277: case 7 : s = "Font directory" ; break ; +278: case 8 : s = "Font" ; break ; +279: case 9 : s = "Accelerator table" ; break ; +280: case 10 : s = "Application defined resource (raw data)" ; break ; +281: case 11 : s = "Message table entry" ; break ; +282: case 12 : s = "Group cursor" ; break ; +283: case 14 : s = "Group icon" ; break ; +284: case 16 : s = "Version information" ; break ; +285: case 17 : s = "Dlginclude" ; break ; +286: case 19 : s = "Plug and play resource" ; break ; +287: case 20 : s = "VXD" ; break ; +288: case 21 : s = "Animated cursor" ; break ; +289: case 22 : s = "Animated icon" ; break ; +290: case 23 : s = "HTML" ; break ; +291: case 24 : s = "Side-by-side assembly manifest" ; break ; +292: } +293: SPrintf ( s , "1. Resource type: %s" , s ) ; +294: return s ; +295: } +296: string ShowName ( uint32 ID ) +297: { +298: local string s ; +299: SPrintf ( s , "2. Name ID: %d" , ID ) ; +300: return s ; +301: } +302: +303: string ShowSName ( wstring Str ) +304: { +305: local string s ; +306: SPrintf ( s , "2. Name: %s" , Str ) ; +307: return s ; +308: } +309: +310: string ShowLanguage ( uint32 ID ) +311: { +312: local string s ; +313: SPrintf ( s , "3. Language ID: %d" , ID ) ; +314: return s ; +315: } +316: +317: void RESfromPEDiscover ( ) +318: { +319: rsrc_sa = FTell ( ) ; +320: struct +321: { +322: if ( res_show_log == 1 ) Printf ( "\nResources list." ) ; +323: res_level = 0 ; +324: GetResourceDirectory ( ) ; +325: } ResourcesStructure ; +326: } +327: +328: void GoTo_rsrc_section ( ) +329: { +330: local int32 i ; +331: rsrc_sa = 0 ; +332: rsrc_va = 0 ; +333: DosExeHeader DOSHead < hidden = true > ; +334: +335: if ( ! Memcmp ( DOSHead . Signature , "MZ" , 2 ) ) +336: { +337: char dosstub [ DOSHead . OffsetToPEHeader - ( DOSHead . SizeOfHeader * 0x10 ) ] < hidden = true > ; +338: PeHeader PEHead < hidden = true > ; +339: if ( ! Memcmp ( PEHead . Sig , "PE" , 2 ) ) +340: { +341: OptionalHeader OptionalHead < hidden = true > ; +342: DataDir dd [ 16 ] < hidden = true > ; +343: SectionTable sec [ PEHead . NumSections ] < hidden = true > ; +344: for ( i = 0 ; i < PEHead . NumSections ; i ++ ) +345: { +346: FSeek ( sec [ i ] . PointerToRawData ) ; +347: if ( ! Strcmp ( sec [ i ] . Name , ".rsrc" ) ) +348: { +349: rsrc_sa = FTell ( ) ; +350: rsrc_va = sec [ i ] . VirtualAddress ; +351: } +352: } +353: } +354: } +355: FSeek ( rsrc_sa ) ; +356: } +357: +358: int Padding4Bytes ( int Value ) +359: { +360: return ( Value % 4 > 0 ) * ( 4 - Value % 4 ) ; +361: } +362: +363: void VersionInfo ( ) +364: { +365: struct +366: { +367: WORD wLength ; +368: WORD wValueLength ; +369: WORD wType ; +370: wstring szKey ; +371: if ( ! Strcmp ( szKey , "VS_VERSION_INFO" ) ) +372: { +373: byte padding_n [ Padding4Bytes ( sizeof ( wValueLength ) ) ] ; +374: struct +375: { +376: DWORD dwSignature < format = hex > ; +377: struct +378: { +379: WORD StructureMinorVersion ; +380: WORD StructureMajorVersion ; +381: } dwStrucVersion ; +382: struct +383: { +384: WORD FileMinorVersion ; +385: WORD FileMajorVersion ; +386: } dwFileVersionMS ; +387: struct +388: { +389: WORD FileBuildNumber ; +390: WORD FileRevision ; +391: } dwFileVersionLS ; +392: struct +393: { +394: WORD FileMinorVersion ; +395: WORD FileMajorVersion ; +396: } dwProductVersionMS ; +397: struct +398: { +399: WORD FileBuildNumber ; +400: WORD FileRevision ; +401: } dwProductVersionLS ; +402: DWORD dwFileFlagsMask ; +403: DWORD dwFileFlags ; +404: DWORD dwFileOS ; +405: DWORD dwFileType ; +406: DWORD dwFileSubtype ; +407: DWORD dwFileDateMS ; +408: DWORD dwFileDateLS ; +409: } VS_FIXEDFILEINFO ; +410: if ( VS_FIXEDFILEINFO . dwSignature == 0xFEEF04BD ) +411: { +412: byte Padding2 [ Padding4Bytes ( sizeof ( VS_FIXEDFILEINFO ) ) ] ; +413: +414: struct +415: { +416: FSkip ( 6 ) ; +417: wstring szKeyCheck < hidden = true > ; +418: FSkip ( - 6 - sizeof ( szKeyCheck ) ) ; +419: if ( ! Strcmp ( szKeyCheck , "StringFileInfo" ) ) +420: { +421: local int HeaderLength ; +422: local int64 LenghtLeft ; +423: WORD wLength ; +424: WORD wValueLength ; +425: WORD wType ; +426: wstring szKey ; +427: HeaderLength = 6 + sizeof ( szKey ) ; +428: byte Padding [ Padding4Bytes ( HeaderLength ) ] ; +429: LenghtLeft = wLength - HeaderLength - Padding4Bytes ( HeaderLength ) ; +430: while ( LenghtLeft > 0 ) +431: { +432: struct +433: { +434: local int HeaderLength ; +435: WORD wLength ; +436: WORD wValueLength ; +437: WORD wType ; +438: wstring szKey ; +439: HeaderLength = 6 + sizeof ( szKey ) ; +440: byte Padding [ Padding4Bytes ( HeaderLength ) ] ; +441: local int64 LenghtLeft ; +442: LenghtLeft = wLength - 6 - sizeof ( szKey ) ; +443: while ( LenghtLeft > 0 ) +444: { +445: struct +446: { +447: local int HeaderLength ; +448: WORD wLength ; +449: WORD wValueLength ; +450: WORD wType ; +451: wstring szKey ; +452: HeaderLength = 6 + sizeof ( szKey ) ; +453: byte Padding [ Padding4Bytes ( HeaderLength ) ] ; +454: wstring Value ; +455: byte padding_v [ Padding4Bytes ( sizeof ( Value ) ) ] ; +456: } String ; +457: LenghtLeft -= sizeof ( String ) ; +458: } +459: } StringTable ; +460: LenghtLeft -= sizeof ( StringTable ) ; +461: } +462: } +463: } StringFileInfo ; +464: +465: struct +466: { +467: FSkip ( 6 ) ; +468: wstring szKeyCheck < hidden = true > ; +469: FSkip ( - 6 - sizeof ( szKeyCheck ) ) ; +470: if ( ! Strcmp ( szKeyCheck , "VarFileInfo" ) ) +471: { +472: local int HeaderLength ; +473: local int64 LenghtLeft ; +474: WORD wLength ; +475: WORD wValueLength ; +476: WORD wType ; +477: wstring szKey ; +478: HeaderLength = 6 + sizeof ( szKey ) ; +479: byte Padding [ Padding4Bytes ( HeaderLength ) ] ; +480: LenghtLeft = wLength - HeaderLength - Padding4Bytes ( HeaderLength ) ; +481: while ( LenghtLeft > 0 ) +482: { +483: struct +484: { +485: local int HeaderLength ; +486: WORD wLength ; +487: WORD wValueLength ; +488: WORD wType ; +489: wstring szKey ; +490: HeaderLength = 6 + sizeof ( szKey ) ; +491: byte Padding [ Padding4Bytes ( HeaderLength ) ] ; +492: DWORD Value < format = hex > ; +493: } Var ; +494: LenghtLeft -= sizeof ( Var ) ; +495: } +496: } +497: } VarFileInfo ; +498: } +499: } +500: } VS_VERSIONINFO ; +501: } +502: +503: void RESfromRESDiscover ( ) +504: { +505: while ( ! FEof ( ) ) +506: { +507: struct +508: { +509: DWORD DataSize ; +510: DWORD HeaderSize ; +511: WORD TYPE_type ; +512: if ( TYPE_type == 0xFFFF ) +513: { +514: WORD TYPE < comment = ShowType > ; +515: } +516: else +517: { +518: FSkip ( - 2 ) ; +519: wstring sType ; +520: byte padding_t [ Padding4Bytes ( sizeof ( sType ) ) ] ; +521: } +522: WORD NAME_type ; +523: if ( NAME_type == 0xFFFF ) +524: { +525: WORD NAME < comment = ShowName > ; +526: } +527: else +528: { +529: FSkip ( - 2 ) ; +530: wstring sName < comment = ShowSName > ; +531: local int32 pn_size ; +532: byte padding_n [ Padding4Bytes ( sizeof ( sName ) ) ] ; +533: } +534: DWORD DataVersion ; +535: WORD MemoryFlags ; +536: WORD LanguageId < comment = ShowLanguage > ; +537: DWORD Version ; +538: DWORD Characteristics ; +539: char ResourceRAWData [ DataSize ] ; +540: if ( TYPE == 16 ) +541: { +542: local int64 ba1 , ba2 ; +543: ba2 = FTell ( ) ; +544: ba1 = ba2 - DataSize ; +545: FSeek ( ba1 ) ; +546: VersionInfo ( ) ; +547: FSeek ( ba2 ) ; +548: } +549: byte padding [ Padding4Bytes ( DataSize ) ] ; +550: } Resource ; +551: } +552: } tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/RIFFTemplate.bt b/cparser/tests/exp_lex/RIFFTemplate.bt new file mode 100644 index 0000000..e750778 --- /dev/null +++ b/cparser/tests/exp_lex/RIFFTemplate.bt @@ -0,0 +1,150 @@ +1: +2: +3: +4: +5: +6: +7: +8: +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: +33: +34: typedef struct { +35: ID chunkID ; +36: DWORD chunkSize ; +37: UCHAR data [ chunkSize ] ; +38: +39: +40: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +41: UCHAR padding ; +42: } CHUNK < read = ReadCHUNK > ; +43: +44: string ReadCHUNK ( struct CHUNK & s ) +45: { +46: return s . chunkID ; +47: } +48: +49: +50: struct LISTCHUNK { +51: ID chunkID ; +52: DWORD chunkSize ; +53: local quad pos = FTell ( ) ; +54: ID chunkType ; +55: +56: +57: local char tag [ 5 ] ; +58: local DWORD size ; +59: while ( FTell ( ) - pos < chunkSize ) +60: { +61: +62: ReadBytes ( tag , FTell ( ) , 4 ) ; +63: tag [ 4 ] = 0 ; +64: +65: +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: +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: +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: +104: local quad riff_pos = FTell ( ) ; +105: LittleEndian ( ) ; +106: SetBackColor ( cGrayZone ) ; +107: RIFFHEADER header ; +108: +109: +110: if ( header . groupID != "RIFF" ) +111: { +112: Warning ( "File is not a valid RIFF file. Template stopped." ) ; +113: return - 1 ; +114: } +115: +116: +117: local char tag [ 5 ] ; +118: local DWORD size ; +119: while ( FTell ( ) + 8 <= FileSize ( ) && FTell ( ) - riff_pos != header . size + 8 ) +120: { +121: +122: ReadBytes ( tag , FTell ( ) , 4 ) ; +123: tag [ 4 ] = 0 ; +124: +125: +126: size = ReadUInt ( FTell ( ) + 4 ) ; +127: +128: +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: +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: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/RegistryHive.bt b/cparser/tests/exp_lex/RegistryHive.bt new file mode 100644 index 0000000..5f1863c --- /dev/null +++ b/cparser/tests/exp_lex/RegistryHive.bt @@ -0,0 +1,282 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: LittleEndian ( ) ; +11: +12: +13: typedef struct { +14: +15: char HeaderSignature [ 4 ] < fgcolor = cBlack , bgcolor = 0xFF00 > ; +16: int PrimarySequenceNumber ; +17: int SecondarySequenceNumber ; +18: FILETIME LastWriteTime < fgcolor = cBlack , bgcolor = 0xDFF4FF > ; +19: int MajorVersion < fgcolor = cBlack , bgcolor = cLtRed > ; +20: int MinorVersion < fgcolor = cBlack , bgcolor = cRed > ; +21: int FileType ; +22: int Unknown ; +23: int RootKeyOffset < fgcolor = cBlack , bgcolor = cLtBlue > ; +24: int HbinTotalSize < fgcolor = cBlack , bgcolor = cPurple , format = hex > ; +25: int Unknown2 ; +26: wchar_t EmbeddedFilename [ 32 ] < fgcolor = cBlack , bgcolor = cLtGreen > ; +27: char Unknown3 [ 396 ] ; +28: int Checksum ; +29: +30: } REGISTRYHEADER < size = 4096 > ; +31: +32: typedef struct ( int recordSize ) { +33: int Size ; +34: char Signature [ 2 ] < fgcolor = cBlack , bgcolor = 0xFF10 > ; +35: short Flags < format = binary > ; +36: FILETIME LastWriteTime < fgcolor = cBlack , bgcolor = 0xDFF4FF > ; +37: int Spare ; +38: int ParentCellOffset ; +39: int SubkeyCountStable < fgcolor = cBlack , bgcolor = cLtBlue > ; +40: int SubkeyCountVolatile ; +41: int SubkeyListOffsetStable < fgcolor = cBlack , bgcolor = cLtBlue > ; +42: int SubkeyListOffsetVolatile ; +43: int ValueCount < fgcolor = cWhite , bgcolor = cDkGray > ; +44: int ValuelistOffset < fgcolor = cBlack , bgcolor = cGray > ; +45: int SecurityKeyOffset ; +46: int ClassOffset ; +47: short MaxNameLength ; +48: byte UserVirtFlags ; +49: byte Debug ; +50: int MaxClassLength ; +51: int MaxValueNameLength ; +52: int MaxValueDataLength ; +53: int WorkVar ; +54: short NameLength < fgcolor = cBlack , bgcolor = cAqua > ; +55: short ClassLength ; +56: char Name [ NameLength ] < fgcolor = cBlack , bgcolor = cLtAqua > ; +57: local int PaddingSize = recordSize - 0x50 - NameLength ; +58: if ( PaddingSize > 0 ) +59: { +60: char Padding [ recordSize - 0x50 - NameLength ] ; +61: } +62: +63: +64: } NKCELL < read = ReadNKCell , optimize = false > ; +65: +66: string ReadNKCell ( NKCELL & nk ) +67: { +68: return nk . Name ; +69: } +70: +71: typedef struct ( int recordSize ) { +72: int Size ; +73: char Signature [ 2 ] < fgcolor = cBlack , bgcolor = 0xFF10 > ; +74: short NameLength < fgcolor = cBlack , bgcolor = cAqua > ; +75: int DataLength ; +76: int DataOffset ; +77: int Type ; +78: short Flags < format = binary > ; +79: short Spare ; +80: if ( NameLength > 0 ) +81: { +82: char Name [ NameLength ] < fgcolor = cBlack , bgcolor = cLtAqua > ; +83: } +84: local int PaddingSize = recordSize - 0x18 - NameLength ; +85: if ( PaddingSize > 0 ) +86: { +87: char Padding [ recordSize - 0x18 - NameLength ] ; +88: } +89: +90: } VKCELL < read = ReadVKCell , optimize = false > ; +91: +92: string ReadVKCell ( VKCELL & vk ) +93: { +94: if ( vk . NameLength > 0 ) +95: { +96: return vk . Name ; +97: } +98: else +99: { +100: return "(Default)" ; +101: } +102: } +103: +104: +105: typedef struct ( int recordSize ) { +106: byte AceType ; +107: byte AceFlags ; +108: short AceSize ; +109: int Mask < format = binary > ; +110: char SID [ AceSize - 8 ] ; +111: +112: } ACE < optimize = false > ; +113: +114: typedef struct ( int recordSize ) { +115: byte AclRevision ; +116: byte Sbz1 ; +117: short AclSize ; +118: short AceCount ; +119: short Sbz2 ; +120: if ( AclSize > 0 ) +121: { +122: local int aceSize = 0 ; +123: local int i ; +124: for ( i = 0 ; i < AceCount ; i ++ ) +125: { +126: aceSize = ReadInt ( FTell ( ) + 2 ) ; +127: ACE Ace ( aceSize ) ; +128: } +129: } +130: +131: } ACL < optimize = false > ; +132: +133: typedef struct ( int recordSize ) { +134: byte Revision ; +135: byte Spare ; +136: short ControlFlag < format = binary > ; +137: int OffsetToOwner ; +138: int OffsetToGroup ; +139: int OffsetToSACL ; +140: int OffsetToDACL ; +141: +142: local int sizeSACL = OffsetToDACL - OffsetToSACL ; +143: local int sizeDACL = OffsetToOwner - OffsetToDACL ; +144: local int sizeOwnerSid = OffsetToGroup - OffsetToOwner ; +145: local int sizeGroupSid = recordSize - OffsetToGroup ; +146: +147: if ( ( ControlFlag & 0x10 ) == 0x10 ) +148: { +149: ACL SACL ( sizeSACL ) ; +150: } +151: if ( ( ControlFlag & 0x4 ) == 0x4 ) +152: { +153: ACL DACL ( sizeDACL ) ; +154: } +155: char OwnerSID [ sizeOwnerSid ] ; +156: char GroupSID [ sizeGroupSid ] ; +157: } DESCRIPTOR < optimize = false > ; +158: +159: typedef struct ( int recordSize ) { +160: int Size ; +161: char Signature [ 2 ] < fgcolor = cBlack , bgcolor = 0xFF10 > ; +162: short Reserved ; +163: int Flink ; +164: int Blink ; +165: int ReferenceCount ; +166: int DescriptorLength ; +167: if ( DescriptorLength ) +168: { +169: DESCRIPTOR Descriptor ( DescriptorLength ) ; +170: } +171: +172: local int PaddingSize = recordSize - 0x18 - DescriptorLength ; +173: if ( PaddingSize > 0 ) +174: { +175: char Padding [ recordSize - 0x18 - DescriptorLength ] ; +176: } +177: +178: } SKCELL < optimize = false > ; +179: +180: typedef struct { +181: int Offset ; +182: char Hash [ 4 ] ; +183: +184: } LXOFFSET < optimize = false > ; +185: +186: typedef struct ( int recordSize ) { +187: int Size ; +188: char Signature [ 2 ] < fgcolor = cBlack , bgcolor = 0xFF10 > ; +189: short NumberOfOffsets ; +190: if ( NumberOfOffsets > 0 ) +191: { +192: LXOFFSET offsets [ NumberOfOffsets ] ; +193: } +194: +195: local int PaddingSize = recordSize - 8 - ( 8 * NumberOfOffsets ) ; +196: if ( PaddingSize > 0 ) +197: { +198: char Padding [ recordSize - 8 - ( 8 * NumberOfOffsets ) ] ; +199: } +200: +201: } LXLIST < optimize = false > ; +202: +203: typedef struct ( int recordSize ) { +204: int Size ; +205: char Signature [ 2 ] < fgcolor = cBlack , bgcolor = 0xFF10 > ; +206: short NumberOfOffsets ; +207: LXOFFSET offsets [ NumberOfOffsets ] ; +208: +209: } LILIST < optimize = false > ; +210: +211: typedef struct { +212: char HbinSignature [ 4 ] < fgcolor = cBlack , bgcolor = 0xFF10 > ; +213: int RelativeOffset ; +214: int SizeOfHbin ; +215: int Unknown1 ; +216: int Unknown2 ; +217: FILETIME Timestamp < fgcolor = cBlack , bgcolor = 0xDFF4FF > ; +218: int unknown3 ; +219: +220: local string sig ; +221: +222: local int index = 0 ; +223: +224: local int cellSize = ReadInt ( FTell ( ) ) ; +225: +226: while ( index < SizeOfHbin ) +227: { +228: sig = GetCellSignature ( ) ; +229: +230: cellSize = ReadInt ( FTell ( ) ) ; +231: +232: if ( cellSize == 0 ) +233: { +234: break ; +235: } +236: +237: switch ( sig ) +238: { +239: case "nk" : NKCELL nk ( Abs ( cellSize ) ) ; break ; +240: case "sk" : SKCELL sk ( Abs ( cellSize ) ) ; break ; +241: case "vk" : VKCELL vk ( Abs ( cellSize ) ) ; break ; +242: case "li" : LILIST li ( Abs ( cellSize ) ) ; break ; +243: case "lf" : LXLIST lf ( Abs ( cellSize ) ) ; break ; +244: case "lh" : LXLIST lh ( Abs ( cellSize ) ) ; break ; +245: default : +246: +247: FSkip ( Abs ( cellSize ) ) ; +248: } +249: +250: index += Abs ( cellSize ) ; +251: } +252: +253: } HBINRECORD < size = SizeHbinRecord , optimize = false > ; +254: +255: int SizeHbinRecord ( HBINRECORD & r ) +256: { +257: return ReadInt ( startof ( r ) + 8 ) ; +258: } +259: +260: char [ ] GetCellSignature ( ) +261: { +262: +263: return ReadString ( FTell ( ) + 4 , 2 ) ; +264: } +265: +266: REGISTRYHEADER Header < bgcolor = cLtPurple > ; +267: +268: local int indexPosition = FTell ( ) ; +269: +270: local int indexPosStart = indexPosition ; +271: +272: local int absoluteEndPosition = Header . HbinTotalSize + 0x1000 ; +273: +274: while ( indexPosition < absoluteEndPosition ) +275: { +276: HBINRECORD Hbin ; +277: +278: indexPosition += Hbin . SizeOfHbin ; +279: } +280: +281: +282: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/RegistryPolicyFileTemplate.bt b/cparser/tests/exp_lex/RegistryPolicyFileTemplate.bt new file mode 100644 index 0000000..95e6787 --- /dev/null +++ b/cparser/tests/exp_lex/RegistryPolicyFileTemplate.bt @@ -0,0 +1,145 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +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 ] < hidden = true > ; +21: wstring Key ; +22: SHORT seperator0 < hidden = true > ; +23: wstring ValueName ; +24: SHORT seperator1 < hidden = true > ; +25: DWORD Type < comment = DataValueTypeComment > ; +26: SHORT seperator2 < hidden = true > ; +27: DWORD DataSize ; +28: SHORT seperator3 < hidden = true > ; +29: union { +30: UBYTE Raw [ DataSize ] ; +31: DWORD Int ; +32: wstring String ; +33: } Data ; +34: +35: CHAR RBRACKET [ 2 ] < hidden = true > ; +36: +37: } REGISTRY_RECORD < comment = RegistryRecordComment > ; +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 != 0x1 ) +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: } tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/SF2Template.bt b/cparser/tests/exp_lex/SF2Template.bt new file mode 100644 index 0000000..6437a13 --- /dev/null +++ b/cparser/tests/exp_lex/SF2Template.bt @@ -0,0 +1,823 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: typedef CHAR ID [ 4 ] ; +13: +14: local int cGrayZone = 0xD9DADC ; +15: local int cOrange = 0xAAE3F9 ; +16: local int cSytrus = 0xAAF7FF ; +17: local int cGreenGreens = 0xAAECDF ; +18: local int cCureMarine = 0xFFE1CE ; +19: local int cCureMarine_Alt = 0xFDF1DD ; +20: local int cPurpleMadness = 0xEEC3DD ; +21: local int cPurpleMadness_Alt = 0xFFE1FA ; +22: +23: +24: +25: +26: +27: typedef enum < WORD > { +28: monoSample = 1 , +29: rightSample = 2 , +30: leftSample = 4 , +31: linkedSample = 8 , +32: RomMonoSample = 0x8001 , +33: RomRightSample = 0x8002 , +34: RomLeftSample = 0x8004 , +35: RomLinkedSample = 0x8008 , +36: } SFSampleLink ; +37: +38: typedef enum < WORD > { +39: startAddrsOffset = 0 , +40: endAddrsOffset = 1 , +41: startloopAddrsOffset = 2 , +42: endloopAddrsOffset = 3 , +43: startAddrsCoarseOffset = 4 , +44: modLfoToPitch = 5 , +45: vibLfoToPitch = 6 , +46: modEnvToPitch = 7 , +47: initialFilterFc = 8 , +48: initialFilterQ = 9 , +49: modLfoToFilterFc = 10 , +50: modEnvToFilterFc = 11 , +51: endAddrsCoarseOffset = 12 , +52: modLfoToVolume = 13 , +53: chorusEffectsSend = 15 , +54: reverbEffectsSend = 16 , +55: pan = 17 , +56: delayModLFO = 21 , +57: freqModLFO = 22 , +58: delayVibLFO = 23 , +59: freqVibLFO = 24 , +60: delayModEnv = 25 , +61: attackModEnv = 26 , +62: holdModEnv = 27 , +63: decayModEnv = 28 , +64: sustainModEnv = 29 , +65: releaseModEnv = 30 , +66: keynumToModEnvHold = 31 , +67: keynumToModEnvDecay = 32 , +68: delayVolEnv = 33 , +69: attackVolEnv = 34 , +70: holdVolEnv = 35 , +71: decayVolEnv = 36 , +72: sustainVolEnv = 37 , +73: releaseVolEnv = 38 , +74: keynumToVolEnvHold = 39 , +75: keynumToVolEnvDecay = 40 , +76: instrument = 41 , +77: keyRange = 43 , +78: velRange = 44 , +79: startloopAddrsCoarseOffset = 45 , +80: keynum = 46 , +81: velocity = 47 , +82: initialAttenuation = 48 , +83: endloopAddrsCoarseOffset = 50 , +84: coarseTune = 51 , +85: fineTune = 52 , +86: sampleID = 53 , +87: sampleModes = 54 , +88: scaleTuning = 56 , +89: exclusiveClass = 57 , +90: overridingRootKey = 58 , +91: endOper = 60 , +92: } SFGenerator ; +93: +94: typedef enum < BYTE > { +95: noController = 0 , +96: noteOnVelocity = 2 , +97: noteOnKeyNumber = 3 , +98: polyPressure = 10 , +99: channelPressure = 13 , +100: pitchWheel = 14 , +101: pitchWheelSensitivity = 16 , +102: link = 127 , +103: } SFGeneralController ; +104: +105: typedef enum < BYTE > { +106: generalController = 0 , +107: midiController = 1 , +108: } SFControllerPalette ; +109: +110: typedef enum < BYTE > { +111: increase = 0 , +112: decrease = 1 , +113: } SFControllerDirection ; +114: +115: typedef enum < BYTE > { +116: unipolar = 0 , +117: bipolar = 1 , +118: } SFControllerPolarity ; +119: +120: typedef enum < BYTE > { +121: linearType = 0 , +122: concaveType = 1 , +123: convexType = 2 , +124: switchType = 3 , +125: } SFControllerType ; +126: +127: typedef struct { +128: union { +129: SFGeneralController general : 7 ; +130: BYTE midi : 7 ; +131: } index ; +132: SFControllerPalette palette : 1 ; +133: SFControllerDirection direction : 1 ; +134: SFControllerPolarity polarity : 1 ; +135: SFControllerType type : 6 ; +136: } SFModulator ; +137: +138: typedef enum < WORD > { +139: linear = 0 , +140: absoluteValue = 2 , +141: } SFTransform ; +142: +143: typedef struct +144: { +145: BYTE byLo ; +146: BYTE byHi ; +147: } rangesType ; +148: +149: typedef union +150: { +151: rangesType ranges ; +152: SHORT shAmount ; +153: WORD wAmount ; +154: } genAmountType ; +155: +156: +157: typedef struct { +158: WORD wMajor ; +159: WORD wMinor ; +160: } sfVersionTag ; +161: +162: typedef struct { +163: CHAR achPresetName [ 20 ] ; +164: WORD wPreset ; +165: WORD wBank ; +166: WORD wPresetBagNdx ; +167: DWORD dwLibrary ; +168: DWORD dwGenre ; +169: DWORD dwMorphology ; +170: } sfPresetHeader ; +171: +172: typedef struct +173: { +174: WORD wGenNdx ; +175: WORD wModNdx ; +176: } sfPresetBag ; +177: +178: typedef struct +179: { +180: SFModulator sfModSrcOper ; +181: SFGenerator sfModDestOper ; +182: SHORT modAmount ; +183: SFModulator sfModAmtSrcOper ; +184: SFTransform sfModTransOper ; +185: } sfModList ; +186: +187: typedef struct +188: { +189: SFGenerator sfGenOper ; +190: genAmountType genAmount ; +191: } sfGenList ; +192: +193: typedef struct +194: { +195: CHAR achInstName [ 20 ] ; +196: WORD wInstBagNdx ; +197: } sfInst ; +198: +199: typedef struct +200: { +201: WORD wInstGenNdx ; +202: WORD wInstModNdx ; +203: } sfInstBag ; +204: +205: typedef struct +206: { +207: SFModulator sfModSrcOper ; +208: SFGenerator sfModDestOper ; +209: SHORT modAmount ; +210: SFModulator sfModAmtSrcOper ; +211: SFTransform sfModTransOper ; +212: } sfInstModList ; +213: +214: typedef struct +215: { +216: SFGenerator sfGenOper ; +217: genAmountType genAmount ; +218: } sfInstGenList ; +219: +220: typedef struct +221: { +222: CHAR achSampleName [ 20 ] ; +223: DWORD dwStart ; +224: DWORD dwEnd ; +225: DWORD dwStartloop ; +226: DWORD dwEndloop ; +227: DWORD dwSampleRate ; +228: BYTE byOriginalKey ; +229: CHAR chCorrection ; +230: WORD wSampleLink ; +231: SFSampleLink sfSampleType ; +232: } sfSample ; +233: +234: +235: typedef struct { +236: ID chunkID ; +237: DWORD chunkSize ; +238: CHAR text [ chunkSize ] ; +239: +240: +241: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +242: UCHAR padding ; +243: } ZSTRCk ; +244: +245: typedef struct { +246: ID chunkID ; +247: DWORD chunkSize ; +248: local quad pos = FTell ( ) ; +249: +250: if ( FileSize ( ) - pos >= sizeof ( sfVersionTag ) ) { +251: sfVersionTag version ; +252: } +253: +254: local int unknownDataSize = chunkSize - ( FTell ( ) - pos ) ; +255: if ( unknownDataSize > 0 ) { +256: Printf ( "Encountered unknown data in chunk '%s' of size %d at position 0x%LX.\n" , +257: chunkID , unknownDataSize , FTell ( ) ) ; +258: UCHAR unknownData [ unknownDataSize ] ; +259: } +260: +261: +262: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +263: UCHAR padding ; +264: } sfVersionTagCk ; +265: +266: typedef struct { +267: ID chunkID ; +268: DWORD chunkSize ; +269: +270: SHORT samples [ chunkSize / 2 ] ; +271: +272: local int unknownDataSize = chunkSize - ( FTell ( ) - pos ) ; +273: if ( unknownDataSize > 0 ) { +274: Printf ( "Encountered unknown data in chunk '%s' of size %d at position 0x%LX.\n" , +275: chunkID , unknownDataSize , FTell ( ) ) ; +276: UCHAR unknownData [ unknownDataSize ] ; +277: } +278: +279: +280: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +281: UCHAR padding ; +282: } smplCk ; +283: +284: typedef struct { +285: ID chunkID ; +286: DWORD chunkSize ; +287: +288: BYTE samples [ chunkSize ] ; +289: +290: +291: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +292: UCHAR padding ; +293: } sm24Ck ; +294: +295: typedef struct { +296: ID chunkID ; +297: DWORD chunkSize ; +298: local quad pos = FTell ( ) ; +299: +300: while ( chunkSize - ( FTell ( ) - pos ) >= sizeof ( sfPresetHeader ) ) { +301: sfPresetHeader header ; +302: } +303: +304: local int unknownDataSize = chunkSize - ( FTell ( ) - pos ) ; +305: if ( unknownDataSize > 0 ) { +306: Printf ( "Encountered unknown data in chunk '%s' of size %d at position 0x%LX.\n" , +307: chunkID , unknownDataSize , FTell ( ) ) ; +308: UCHAR unknownData [ unknownDataSize ] ; +309: } +310: +311: +312: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +313: UCHAR padding ; +314: } phdrCk ; +315: +316: typedef struct { +317: ID chunkID ; +318: DWORD chunkSize ; +319: local quad pos = FTell ( ) ; +320: +321: while ( chunkSize - ( FTell ( ) - pos ) >= sizeof ( sfPresetBag ) ) { +322: sfPresetBag bag ; +323: } +324: +325: local int unknownDataSize = chunkSize - ( FTell ( ) - pos ) ; +326: if ( unknownDataSize > 0 ) { +327: Printf ( "Encountered unknown data in chunk '%s' of size %d at position 0x%LX.\n" , +328: chunkID , unknownDataSize , FTell ( ) ) ; +329: UCHAR unknownData [ unknownDataSize ] ; +330: } +331: +332: +333: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +334: UCHAR padding ; +335: } pbagCk ; +336: +337: typedef struct { +338: ID chunkID ; +339: DWORD chunkSize ; +340: local quad pos = FTell ( ) ; +341: +342: while ( chunkSize - ( FTell ( ) - pos ) >= sizeof ( sfModList ) ) { +343: sfModList mod ; +344: } +345: +346: local int unknownDataSize = chunkSize - ( FTell ( ) - pos ) ; +347: if ( unknownDataSize > 0 ) { +348: Printf ( "Encountered unknown data in chunk '%s' of size %d at position 0x%LX.\n" , +349: chunkID , unknownDataSize , FTell ( ) ) ; +350: UCHAR unknownData [ unknownDataSize ] ; +351: } +352: +353: +354: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +355: UCHAR padding ; +356: } pmodCk ; +357: +358: typedef struct { +359: ID chunkID ; +360: DWORD chunkSize ; +361: local quad pos = FTell ( ) ; +362: +363: while ( chunkSize - ( FTell ( ) - pos ) >= sizeof ( sfGenList ) ) { +364: sfGenList gen ; +365: } +366: +367: local int unknownDataSize = chunkSize - ( FTell ( ) - pos ) ; +368: if ( unknownDataSize > 0 ) { +369: Printf ( "Encountered unknown data in chunk '%s' of size %d at position 0x%LX.\n" , +370: chunkID , unknownDataSize , FTell ( ) ) ; +371: UCHAR unknownData [ unknownDataSize ] ; +372: } +373: +374: +375: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +376: UCHAR padding ; +377: } pgenCk ; +378: +379: typedef struct { +380: ID chunkID ; +381: DWORD chunkSize ; +382: local quad pos = FTell ( ) ; +383: +384: while ( chunkSize - ( FTell ( ) - pos ) >= sizeof ( sfInst ) ) { +385: sfInst inst ; +386: } +387: +388: local int unknownDataSize = chunkSize - ( FTell ( ) - pos ) ; +389: if ( unknownDataSize > 0 ) { +390: Printf ( "Encountered unknown data in chunk '%s' of size %d at position 0x%LX.\n" , +391: chunkID , unknownDataSize , FTell ( ) ) ; +392: UCHAR unknownData [ unknownDataSize ] ; +393: } +394: +395: +396: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +397: UCHAR padding ; +398: } instCk ; +399: +400: typedef struct { +401: ID chunkID ; +402: DWORD chunkSize ; +403: local quad pos = FTell ( ) ; +404: +405: while ( chunkSize - ( FTell ( ) - pos ) >= sizeof ( sfInstBag ) ) { +406: sfInstBag bag ; +407: } +408: +409: local int unknownDataSize = chunkSize - ( FTell ( ) - pos ) ; +410: if ( unknownDataSize > 0 ) { +411: Printf ( "Encountered unknown data in chunk '%s' of size %d at position 0x%LX.\n" , +412: chunkID , unknownDataSize , FTell ( ) ) ; +413: UCHAR unknownData [ unknownDataSize ] ; +414: } +415: +416: +417: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +418: UCHAR padding ; +419: } ibagCk ; +420: +421: typedef struct { +422: ID chunkID ; +423: DWORD chunkSize ; +424: local quad pos = FTell ( ) ; +425: +426: while ( chunkSize - ( FTell ( ) - pos ) >= sizeof ( sfInstModList ) ) { +427: sfInstModList mod ; +428: } +429: +430: local int unknownDataSize = chunkSize - ( FTell ( ) - pos ) ; +431: if ( unknownDataSize > 0 ) { +432: Printf ( "Encountered unknown data in chunk '%s' of size %d at position 0x%LX.\n" , +433: chunkID , unknownDataSize , FTell ( ) ) ; +434: UCHAR unknownData [ unknownDataSize ] ; +435: } +436: +437: +438: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +439: UCHAR padding ; +440: } imodCk ; +441: +442: typedef struct { +443: ID chunkID ; +444: DWORD chunkSize ; +445: local quad pos = FTell ( ) ; +446: +447: while ( chunkSize - ( FTell ( ) - pos ) >= sizeof ( sfInstGenList ) ) { +448: sfInstGenList gen ; +449: } +450: +451: local int unknownDataSize = chunkSize - ( FTell ( ) - pos ) ; +452: if ( unknownDataSize > 0 ) { +453: Printf ( "Encountered unknown data in chunk '%s' of size %d at position 0x%LX.\n" , +454: chunkID , unknownDataSize , FTell ( ) ) ; +455: UCHAR unknownData [ unknownDataSize ] ; +456: } +457: +458: +459: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +460: UCHAR padding ; +461: } igenCk ; +462: +463: typedef struct { +464: ID chunkID ; +465: DWORD chunkSize ; +466: local quad pos = FTell ( ) ; +467: +468: while ( chunkSize - ( FTell ( ) - pos ) >= sizeof ( sfSample ) ) { +469: sfSample sample ; +470: } +471: +472: local int unknownDataSize = chunkSize - ( FTell ( ) - pos ) ; +473: if ( unknownDataSize > 0 ) { +474: Printf ( "Encountered unknown data in chunk '%s' of size %d at position 0x%LX.\n" , +475: chunkID , unknownDataSize , FTell ( ) ) ; +476: UCHAR unknownData [ unknownDataSize ] ; +477: } +478: +479: +480: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +481: UCHAR padding ; +482: } shdrCk ; +483: +484: +485: typedef struct { +486: ID chunkID ; +487: DWORD chunkSize ; +488: CHAR data [ chunkSize ] ; +489: +490: +491: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +492: UCHAR padding ; +493: } UNKNOWNLISTSUBCHUNK ; +494: +495: typedef struct { +496: ID chunkID ; +497: DWORD chunkSize ; +498: local quad pos = FTell ( ) ; +499: ID chunkType ; +500: +501: +502: local char tag [ 5 ] ; +503: local DWORD size ; +504: while ( FTell ( ) - pos < chunkSize ) +505: { +506: +507: ReadBytes ( tag , FTell ( ) , 4 ) ; +508: tag [ 4 ] = 0 ; +509: +510: +511: size = ReadUInt ( FTell ( ) + 4 ) ; +512: if ( FTell ( ) - pos + size > chunkSize ) { +513: Printf ( "Chunk '%s' of size %d at position 0x%LX exceeds the parent chunk size boundary.\n" , tag , size , FTell ( ) ) ; +514: return - 1 ; +515: } +516: +517: +518: switch ( tag ) +519: { +520: case "ifil" : +521: SetBackColor ( cOrange ) ; +522: sfVersionTagCk ifil ; +523: break ; +524: case "isng" : +525: SetBackColor ( cOrange ) ; +526: ZSTRCk isng ; +527: break ; +528: case "INAM" : +529: SetBackColor ( cOrange ) ; +530: ZSTRCk INAM ; +531: break ; +532: case "iver" : +533: SetBackColor ( cSytrus ) ; +534: sfVersionTagCk iver ; +535: break ; +536: case "ICRD" : +537: SetBackColor ( cSytrus ) ; +538: ZSTRCk ICRD ; +539: break ; +540: case "IENG" : +541: SetBackColor ( cSytrus ) ; +542: ZSTRCk IENG ; +543: break ; +544: case "IPRD" : +545: SetBackColor ( cSytrus ) ; +546: ZSTRCk IPRD ; +547: break ; +548: case "ICOP" : +549: SetBackColor ( cSytrus ) ; +550: ZSTRCk ICOP ; +551: break ; +552: case "ICMT" : +553: SetBackColor ( cSytrus ) ; +554: ZSTRCk ICMT ; +555: break ; +556: case "ISFT" : +557: SetBackColor ( cSytrus ) ; +558: ZSTRCk ISFT ; +559: break ; +560: default : +561: +562: Printf ( "Encountered unknown chunk '%s' of size %d at position 0x%LX.\n" , +563: tag , size , FTell ( ) ) ; +564: SetBackColor ( cNone ) ; +565: UNKNOWNLISTSUBCHUNK chunk ; +566: break ; +567: } +568: } +569: +570: +571: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +572: UCHAR padding ; +573: } INFOCk ; +574: +575: typedef struct { +576: ID chunkID ; +577: DWORD chunkSize ; +578: local quad pos = FTell ( ) ; +579: ID chunkType ; +580: +581: +582: local char tag [ 5 ] ; +583: local DWORD size ; +584: while ( FTell ( ) - pos < chunkSize ) +585: { +586: +587: ReadBytes ( tag , FTell ( ) , 4 ) ; +588: tag [ 4 ] = 0 ; +589: +590: +591: size = ReadUInt ( FTell ( ) + 4 ) ; +592: if ( FTell ( ) - pos + size > chunkSize ) { +593: Printf ( "Chunk '%s' of size %d at position 0x%LX exceeds the parent chunk size boundary.\n" , tag , size , FTell ( ) ) ; +594: return - 1 ; +595: } +596: +597: +598: switch ( tag ) +599: { +600: case "smpl" : +601: SetBackColor ( cGreenGreens ) ; +602: smplCk smpl ; +603: break ; +604: case "sm24" : +605: SetBackColor ( cGreenGreens ) ; +606: sm24Ck sm24 ; +607: break ; +608: default : +609: +610: Printf ( "Encountered unknown chunk '%s' of size %d at position 0x%LX.\n" , +611: tag , size , FTell ( ) ) ; +612: SetBackColor ( cNone ) ; +613: UNKNOWNLISTSUBCHUNK chunk ; +614: break ; +615: } +616: } +617: +618: +619: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +620: UCHAR padding ; +621: } sdtaCk ; +622: +623: typedef struct { +624: ID chunkID ; +625: DWORD chunkSize ; +626: local quad pos = FTell ( ) ; +627: ID chunkType ; +628: +629: +630: local char tag [ 5 ] ; +631: local DWORD size ; +632: while ( FTell ( ) - pos < chunkSize ) +633: { +634: +635: ReadBytes ( tag , FTell ( ) , 4 ) ; +636: tag [ 4 ] = 0 ; +637: +638: +639: size = ReadUInt ( FTell ( ) + 4 ) ; +640: if ( FTell ( ) - pos + size > chunkSize ) { +641: Printf ( "Chunk '%s' of size %d at position 0x%LX exceeds the parent chunk size boundary.\n" , tag , size , FTell ( ) ) ; +642: return - 1 ; +643: } +644: +645: +646: switch ( tag ) +647: { +648: case "phdr" : +649: SetBackColor ( cCureMarine ) ; +650: phdrCk phdr ; +651: break ; +652: case "pbag" : +653: SetBackColor ( cCureMarine_Alt ) ; +654: pbagCk pbag ; +655: break ; +656: case "pmod" : +657: SetBackColor ( cCureMarine ) ; +658: pmodCk pmod ; +659: break ; +660: case "pgen" : +661: SetBackColor ( cCureMarine_Alt ) ; +662: pgenCk pgen ; +663: break ; +664: case "inst" : +665: SetBackColor ( cPurpleMadness ) ; +666: instCk inst ; +667: break ; +668: case "ibag" : +669: SetBackColor ( cPurpleMadness_Alt ) ; +670: ibagCk ibag ; +671: break ; +672: case "imod" : +673: SetBackColor ( cPurpleMadness ) ; +674: imodCk imod ; +675: break ; +676: case "igen" : +677: SetBackColor ( cPurpleMadness_Alt ) ; +678: igenCk igen ; +679: break ; +680: case "shdr" : +681: SetBackColor ( cSytrus ) ; +682: shdrCk shdr ; +683: break ; +684: default : +685: +686: Printf ( "Encountered unknown chunk '%s' of size %d at position 0x%LX.\n" , +687: tag , size , FTell ( ) ) ; +688: SetBackColor ( cNone ) ; +689: UNKNOWNLISTSUBCHUNK subchunk ; +690: break ; +691: } +692: } +693: +694: +695: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +696: UCHAR padding ; +697: } pdtaCk ; +698: +699: +700: typedef struct { +701: ID chunkID ; +702: DWORD chunkSize ; +703: local quad pos = FTell ( ) ; +704: ID chunkType ; +705: +706: +707: local char tag [ 5 ] ; +708: local DWORD size ; +709: while ( FTell ( ) - pos < chunkSize ) +710: { +711: +712: ReadBytes ( tag , FTell ( ) , 4 ) ; +713: tag [ 4 ] = 0 ; +714: +715: +716: size = ReadUInt ( FTell ( ) + 4 ) ; +717: if ( FTell ( ) - pos + size > chunkSize ) { +718: Printf ( "Chunk '%s' of size %d at position 0x%LX exceeds the parent chunk size boundary.\n" , tag , size , FTell ( ) ) ; +719: return - 1 ; +720: } +721: +722: UNKNOWNLISTSUBCHUNK subchunk ; +723: } +724: +725: +726: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +727: UCHAR padding ; +728: } UNKNOWNLISTCHUNK ; +729: +730: typedef struct { +731: ID chunkID ; +732: DWORD chunkSize ; +733: UCHAR unknownData [ chunkSize ] ; +734: +735: +736: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +737: UCHAR padding ; +738: } UNKNOWNCHUNK ; +739: +740: +741: typedef struct +742: { +743: ID groupID ; +744: DWORD size ; +745: ID riffType ; +746: } RIFFHEADER ; +747: +748: +749: +750: +751: +752: +753: local quad riff_pos = FTell ( ) ; +754: LittleEndian ( ) ; +755: SetBackColor ( cGrayZone ) ; +756: RIFFHEADER header ; +757: +758: +759: if ( header . groupID != "RIFF" || header . riffType != "sfbk" ) +760: { +761: Warning ( "File is not a valid SF2 file. Template stopped." ) ; +762: return - 1 ; +763: } +764: +765: +766: local char tag [ 5 ] ; +767: local DWORD size ; +768: local char list_tag [ 5 ] ; +769: while ( FTell ( ) + 8 <= FileSize ( ) && FTell ( ) - riff_pos != header . size + 8 ) +770: { +771: +772: ReadBytes ( tag , FTell ( ) , 4 ) ; +773: tag [ 4 ] = 0 ; +774: +775: +776: size = ReadUInt ( FTell ( ) + 4 ) ; +777: +778: +779: switch ( tag ) +780: { +781: case "LIST" : +782: +783: ReadBytes ( list_tag , FTell ( ) + 8 , 4 ) ; +784: list_tag [ 4 ] = 0 ; +785: +786: switch ( list_tag ) +787: { +788: case "INFO" : +789: SetBackColor ( cGrayZone ) ; +790: INFOCk INFO ; +791: break ; +792: case "sdta" : +793: SetBackColor ( cGrayZone ) ; +794: sdtaCk sdta ; +795: break ; +796: case "pdta" : +797: SetBackColor ( cGrayZone ) ; +798: pdtaCk pdta ; +799: break ; +800: default : +801: SetBackColor ( cNone ) ; +802: UNKNOWNLISTCHUNK list ; +803: break ; +804: } +805: break ; +806: default : +807: +808: Printf ( "Encountered unknown chunk '%s' of size %d at position 0x%LX.\n" , +809: tag , size , FTell ( ) ) ; +810: SetBackColor ( cNone ) ; +811: UNKNOWNCHUNK unknown ; +812: break ; +813: } +814: } +815: +816: +817: local quad actual_size = FTell ( ) - riff_pos ; +818: if ( actual_size != 8 + header . size ) +819: { +820: Printf ( "RIFF file size mismatch (header value %Ld, actual size %Ld).\n" , header . size , actual_size - 8 ) ; +821: return - 1 ; +822: } +823: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/SHPTemplate.bt b/cparser/tests/exp_lex/SHPTemplate.bt new file mode 100644 index 0000000..1af2d2e --- /dev/null +++ b/cparser/tests/exp_lex/SHPTemplate.bt @@ -0,0 +1,87 @@ +1: +2: +3: +4: +5: +6: +7: +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 < read = GetByteSize > ; +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 < read = GetByteSize > ; +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 ] < optimize = false > ; +87: } esri_shape ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/SHXTemplate.bt b/cparser/tests/exp_lex/SHXTemplate.bt new file mode 100644 index 0000000..369a9ac --- /dev/null +++ b/cparser/tests/exp_lex/SHXTemplate.bt @@ -0,0 +1,52 @@ +1: +2: +3: +4: +5: +6: +7: +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 < read = GetByteSize > ; +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 < read = GetByteSize > ; +49: int contentLength < read = GetByteSize > ; +50: } record [ ( FileSize ( ) - 100 ) / 8 ] ; +51: +52: } esri_index ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/SRecTemplate.bt b/cparser/tests/exp_lex/SRecTemplate.bt new file mode 100644 index 0000000..6687043 --- /dev/null +++ b/cparser/tests/exp_lex/SRecTemplate.bt @@ -0,0 +1,70 @@ +1: +2: +3: +4: +5: +6: +7: +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" : +27: case "S1" : +28: case "S5" : +29: case "S9" : +30: ADDRESS16 address16 ; +31: addrwidth = 4 ; +32: break ; +33: case "S2" : +34: case "S8" : +35: ADDRESS24 address24 ; +36: addrwidth = 6 ; +37: break ; +38: case "S3" : +39: case "S7" : +40: ADDRESS32 adress32 ; +41: addrwidth = 8 ; +42: break ; +43: +44: +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: +63: char checksum [ 2 ] ; +64: char crlf [ 2 ] ; +65: } SREC ; +66: +67: while ( ! FEof ( ) ) +68: { +69: SREC srec ; +70: } tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/SSPTemplate.bt b/cparser/tests/exp_lex/SSPTemplate.bt new file mode 100644 index 0000000..3b001bd --- /dev/null +++ b/cparser/tests/exp_lex/SSPTemplate.bt @@ -0,0 +1,67 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: typedef BYTE IP_ADDRESS [ 4 ] < read = IP2Str > ; +13: typedef BYTE MAC_ADDRESS [ 6 ] < read = MAC2Str > ; +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 ] ; +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 ] < fgcolor = cRed , bgcolor = cYellow > ; +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: +58: LittleEndian ( ) ; +59: SSP_HEADER header ; +60: +61: while ( ! FEof ( ) ) +62: { +63: SSP_PACKET record ; +64: } +65: +66: return 1 ; +67: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/STLTemplate.bt b/cparser/tests/exp_lex/STLTemplate.bt new file mode 100644 index 0000000..37bb9eb --- /dev/null +++ b/cparser/tests/exp_lex/STLTemplate.bt @@ -0,0 +1,58 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: typedef struct { +13: CHAR Caption [ 80 ] ; +14: DWORD trCount ; +15: } STLFILEHEADER < read = STLFILEHEADERRead > ; +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 < read = tVector3fRead > ; +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 < format = hex > ; +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: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/SWFTemplate.bt b/cparser/tests/exp_lex/SWFTemplate.bt new file mode 100644 index 0000000..0b67c1f --- /dev/null +++ b/cparser/tests/exp_lex/SWFTemplate.bt @@ -0,0 +1,2206 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: local quad ActionTagEnd = 0 ; +20: local byte isCompressed = 0 ; +21: +22: typedef struct { +23: ubyte Register ; +24: string ParamName ; +25: } REGISTERPARAM ; +26: +27: typedef struct { +28: string value ; +29: } CONSTANTPOOL ; +30: +31: typedef struct { +32: string value ; +33: } PARAMS ; +34: +35: typedef struct { +36: ubyte Type ; +37: switch ( Type ) { +38: case 0 : +39: string String ; +40: break ; +41: case 1 : +42: float Float ; +43: break ; +44: case 4 : +45: ubyte RegisterNumber ; +46: break ; +47: case 5 : +48: ubyte Boolean ; +49: break ; +50: case 6 : +51: double Double ; +52: break ; +53: case 7 : +54: int Integer ; +55: break ; +56: case 8 : +57: ubyte Constant8 ; +58: break ; +59: case 9 : +60: ushort Constant16 ; +61: break ; +62: default : +63: Warning ( "Unexpected Value detected." ) ; +64: } +65: } TYPECONST ; +66: +67: typedef struct { +68: local int i ; +69: +70: ubyte ActionCode ; +71: if ( ActionCode >= 0x80 ) { +72: ushort Length ; +73: ActionTagEnd = FTell ( ) + Length ; +74: } +75: +76: switch ( ActionCode ) { +77: +78: +79: +80: case 0x81 : +81: if ( Length != 2 ) { +82: Warning ( "ActionGotoFrame: Length must be 2." ) ; +83: } +84: ushort Frame ; +85: break ; +86: case 0x83 : +87: string UrlString ; +88: string TargetString ; +89: break ; +90: case 0x4 : +91: case 0x5 : +92: case 0x6 : +93: case 0x7 : +94: case 0x8 : +95: case 0x9 : +96: break ; +97: case 0x8A : +98: if ( Length != 3 ) { +99: Warning ( "ActionWaitForFrame: Length must be 3." ) ; +100: } +101: ushort Frame ; +102: ubyte SkipCount ; +103: break ; +104: case 0x8B : +105: string TargetName ; +106: break ; +107: case 0x8C : +108: string Label ; +109: break ; +110: +111: +112: +113: +114: case 0x96 : +115: do { +116: TYPECONST TypeConst ; +117: } while ( FTell ( ) < ActionTagEnd ) ; +118: break ; +119: case 0x17 : +120: case 0xA : +121: case 0xB : +122: case 0xC : +123: case 0xD : +124: case 0xE : +125: case 0xF : +126: case 0x10 : +127: case 0x11 : +128: case 0x12 : +129: case 0x13 : +130: case 0x14 : +131: case 0x21 : +132: case 0x15 : +133: case 0x29 : +134: case 0x31 : +135: case 0x35 : +136: case 0x18 : +137: case 0x32 : +138: case 0x33 : +139: case 0x36 : +140: case 0x37 : +141: break ; +142: case 0x99 : +143: short BranchOffset ; +144: break ; +145: case 0x9D : +146: short BranchOffset ; +147: break ; +148: case 0x9E : +149: case 0x1C : +150: case 0x1D : +151: break ; +152: case 0x9A : +153: ubyte SendVarsMethod : 2 ; +154: ubyte Reserved : 4 ; +155: ubyte LoadTargetFlag : 1 ; +156: ubyte LoadVariablesFlag : 1 ; +157: break ; +158: case 0x9F : +159: ubyte Reserved : 6 ; +160: ubyte SceneBiasFlag : 1 ; +161: ubyte PlayFlag : 1 ; +162: if ( SceneBiasFlag == 1 ) { +163: ushort SceneBias ; +164: } +165: break ; +166: case 0x20 : +167: case 0x22 : +168: case 0x23 : +169: case 0x24 : +170: case 0x25 : +171: case 0x27 : +172: case 0x28 : +173: break ; +174: case 0x8D : +175: ubyte SkipCount ; +176: break ; +177: case 0x26 : +178: case 0x34 : +179: case 0x30 : +180: break ; +181: +182: +183: +184: +185: case 0x3D : +186: case 0x52 : +187: break ; +188: case 0x88 : +189: ushort Count ; +190: for ( i = 0 ; i < Count ; i ++ ) { +191: CONSTANTPOOL Constant ; +192: } +193: break ; +194: case 0x9B : +195: string FunctionName ; +196: ushort NumParams ; +197: for ( i = 0 ; i < NumParams ; i ++ ) { +198: PARAMS Param ; +199: } +200: ushort codeSize ; +201: break ; +202: case 0x3C : +203: case 0x41 : +204: case 0x3A : +205: case 0x3B : +206: case 0x46 : +207: case 0x49 : +208: case 0x4E : +209: case 0x42 : +210: case 0x43 : +211: case 0x53 : +212: case 0x40 : +213: case 0x4F : +214: case 0x45 : +215: break ; +216: case 0x94 : +217: ushort Size ; +218: break ; +219: case 0x4A : +220: case 0x4B : +221: case 0x44 : +222: case 0x47 : +223: case 0x48 : +224: case 0x3F : +225: case 0x60 : +226: case 0x63 : +227: case 0x61 : +228: case 0x64 : +229: case 0x65 : +230: case 0x62 : +231: case 0x51 : +232: case 0x50 : +233: case 0x4C : +234: case 0x3E : +235: case 0x4D : +236: break ; +237: case 0x87 : +238: ubyte RegisterNumber ; +239: break ; +240: +241: +242: +243: +244: case 0x55 : +245: case 0x66 : +246: case 0x67 : +247: case 0x68 : +248: break ; +249: +250: +251: +252: +253: case 0x8E : +254: string FunctionName ; +255: ushort NumParams ; +256: ubyte RegisterCount ; +257: ubyte PreloadParentFlag : 1 ; +258: ubyte PreloadRootFlag : 1 ; +259: ubyte SuppressSuperFlag : 1 ; +260: ubyte PreloadSuperFlag : 1 ; +261: ubyte SuppressArgumentsFlag : 1 ; +262: ubyte PreloadArgumentsFlag : 1 ; +263: ubyte SuppressThisFlag : 1 ; +264: ubyte PreloadThisFlag : 1 ; +265: ubyte Reserved : 7 ; +266: ubyte PreloadGlobalFlag : 1 ; +267: +268: for ( i = 0 ; i < NumParams ; i ++ ) { +269: REGISTERPARAM Parameter ; +270: } +271: ushort codeSize ; +272: break ; +273: case 0x69 : +274: case 0x2B : +275: case 0x2C : +276: break ; +277: case 0x8F : +278: ubyte Reserved : 5 ; +279: ubyte CatchInRegisterFlag : 1 ; +280: ubyte FinallyBlockFlag : 1 ; +281: ubyte CatchBlockFlag : 1 ; +282: ushort TrySize ; +283: ushort CatchSize ; +284: ushort FinallySize ; +285: if ( CatchInRegisterFlag == 0 ) { +286: string CatchName ; +287: } +288: else { +289: ubyte CatchRegister ; +290: } +291: if ( TrySize ) ubyte TryBody [ TrySize ] ; +292: if ( CatchSize ) ubyte CatchBody [ CatchSize ] ; +293: if ( FinallySize ) ubyte FinallyBody [ FinallySize ] ; +294: break ; +295: case 0x2A : +296: break ; +297: +298: +299: +300: +301: +302: default : +303: if ( ActionCode >= 0x80 ) { +304: ubyte Padding [ ActionTagEnd - FTell ( ) ] ; +305: } +306: break ; +307: } +308: +309: +310: +311: +312: +313: +314: +315: +316: if ( ActionCode >= 0x80 ) { +317: if ( ActionTagEnd > FTell ( ) ) { +318: ubyte Padding [ ActionTagEnd - FTell ( ) ] ; +319: Printf ( "WARNING: ActionTag padded to 0x%LXh\n" , FTell ( ) ) ; +320: } +321: else if ( ActionTagEnd < FTell ( ) - 1 ) { +322: Printf ( "WARNING: ActionTag overrun to 0x%LXh, expected end at 0x%LXh\n" , FTell ( ) , ActionTagEnd ) ; +323: } +324: } +325: +326: } ACTIONRECORD < read = GetActionType > ; +327: +328: string GetActionType ( ACTIONRECORD & ActionTag ) +329: { +330: string action ; +331: ubyte ActionType = ActionTag . ActionCode ; +332: +333: switch ( ActionType ) +334: { +335: case 0x81 : return "ActionGotoFrame" ; +336: case 0x83 : return "ActionGetURL" ; +337: case 0x4 : return "ActionNextFrame" ; +338: case 0x5 : return "ActionPreviousFrame" ; +339: case 0x6 : return "ActionPlay" ; +340: case 0x7 : return "ActionStop" ; +341: case 0x8 : return "ActionToggleQuality" ; +342: case 0x9 : return "ActionStopSounds" ; +343: case 0x8A : return "ActionWaitForFrame" ; +344: case 0x8B : return "ActionSetTarget" ; +345: case 0x8C : return "ActionGoToLabel" ; +346: case 0x96 : return "ActionPush" ; +347: case 0x17 : return "ActionPop" ; +348: case 0xA : return "ActionAdd" ; +349: case 0xB : return "ActionSubtract" ; +350: case 0xC : return "ActionMultiply" ; +351: case 0xD : return "ActionDivide" ; +352: case 0xE : return "ActionEquals" ; +353: case 0xF : return "ActionLess" ; +354: case 0x10 : return "ActionAnd" ; +355: case 0x11 : return "ActionOr" ; +356: case 0x12 : return "ActionNot" ; +357: case 0x13 : return "ActionStringEquals" ; +358: case 0x14 : return "ActionStringLength" ; +359: case 0x21 : return "ActionStringAdd" ; +360: case 0x15 : return "ActionStringExtract" ; +361: case 0x29 : return "ActionStringLess" ; +362: case 0x31 : return "ActionMBStringLength" ; +363: case 0x35 : return "ActionMBStringExtract" ; +364: case 0x18 : return "ActionToInteger" ; +365: case 0x32 : return "ActionCharToAscii" ; +366: case 0x33 : return "ActionAsciiToChar" ; +367: case 0x36 : return "ActionMBCharToAscii" ; +368: case 0x37 : return "ActionMBAsciiToChar" ; +369: case 0x99 : return "ActionJump" ; +370: case 0x9D : return "ActionIf" ; +371: case 0x9E : return "ActionCall" ; +372: case 0x1C : return "ActionGetVariable" ; +373: case 0x1D : return "ActionSetVariable" ; +374: case 0x9A : return "ActionGetURL2" ; +375: case 0x9F : return "ActionGotoFrame2" ; +376: case 0x20 : return "ActionSetTarget2" ; +377: case 0x22 : return "ActionGetProperty" ; +378: case 0x23 : return "ActionSetProperty" ; +379: case 0x24 : return "ActionCloneSprite" ; +380: case 0x25 : return "ActionRemoveSprite" ; +381: case 0x27 : return "ActionStartDrag" ; +382: case 0x28 : return "ActionEndDrag" ; +383: case 0x8D : return "ActionWaitForFrame2" ; +384: case 0x26 : return "ActionTrace" ; +385: case 0x34 : return "ActionGetTime" ; +386: case 0x30 : return "ActionRandomNumber" ; +387: case 0x3D : return "ActionCallFunction" ; +388: case 0x52 : return "ActionCallMethod" ; +389: case 0x88 : return "ActionConstantPool" ; +390: case 0x9B : return "ActionDefineFunction" ; +391: case 0x3C : return "ActionDefineLocal" ; +392: case 0x41 : return "ActionDefineLocal2" ; +393: case 0x3A : return "ActionDelete" ; +394: case 0x3B : return "ActionDelete2" ; +395: case 0x46 : return "ActionEnumerate" ; +396: case 0x49 : return "ActionEquals2" ; +397: case 0x4E : return "ActionGetMember" ; +398: case 0x42 : return "ActionInitArray" ; +399: case 0x43 : return "ActionInitObject" ; +400: case 0x53 : return "ActionNewMethod" ; +401: case 0x40 : return "ActionNewObject" ; +402: case 0x4F : return "ActionSetMember" ; +403: case 0x45 : return "ActionTargetPath" ; +404: case 0x94 : return "ActionWith" ; +405: case 0x4A : return "ActionToNumber" ; +406: case 0x4B : return "ActionToString" ; +407: case 0x44 : return "ActionTypeOf" ; +408: case 0x47 : return "ActionAdd2" ; +409: case 0x48 : return "ActionLess2" ; +410: case 0x3F : return "ActionModulo" ; +411: case 0x60 : return "ActionBitAnd" ; +412: case 0x63 : return "ActionBitLShift" ; +413: case 0x61 : return "ActionBitOr" ; +414: case 0x64 : return "ActionBitRShift" ; +415: case 0x65 : return "ActionBitURShift" ; +416: case 0x62 : return "ActionBitXor" ; +417: case 0x51 : return "ActionDecrement" ; +418: case 0x50 : return "ActionIncrement" ; +419: case 0x4C : return "ActionPushDuplicate" ; +420: case 0x3E : return "ActionReturn" ; +421: case 0x4D : return "ActionStackSwap" ; +422: case 0x87 : return "ActionStoreRegister" ; +423: case 0x55 : return "ActionEnumerate2" ; +424: case 0x66 : return "ActionStrictEquals" ; +425: case 0x67 : return "ActionGreater" ; +426: case 0x68 : return "ActionStringGreater" ; +427: case 0x8E : return "ActionDefineFunction2" ; +428: case 0x69 : return "ActionExtends" ; +429: case 0x2B : return "ActionCastOp" ; +430: case 0x2C : return "ActionImplementsOp" ; +431: case 0x8F : return "ActionTry" ; +432: case 0x2A : return "ActionThrow" ; +433: +434: case 0x0 : return "END" ; +435: default : SPrintf ( action , "%02Xh" , ActionType ) ; +436: +437: } +438: return action ; +439: } +440: +441: +442: +443: +444: +445: +446: local quad SWFTagEnd ; +447: local ushort CurrentTag ; +448: +449: typedef struct { +450: byte value ; +451: } SI8 ; +452: +453: typedef struct { +454: short value ; +455: } SI16 ; +456: +457: typedef struct { +458: int value ; +459: } SI32 ; +460: +461: typedef struct { +462: ubyte value ; +463: } UI8 ; +464: +465: typedef struct { +466: ushort value ; +467: } UI16 ; +468: +469: typedef struct { +470: uint value ; +471: } UI32 ; +472: +473: typedef struct { +474: quad value ; +475: } UI64 ; +476: +477: typedef struct { +478: int whole : 16 ; +479: int decimal : 16 ; +480: } FIXED ; +481: +482: typedef struct { +483: short whole : 8 ; +484: short decimal : 8 ; +485: } FIXED8 ; +486: +487: typedef struct { +488: ushort sign : 1 ; +489: ushort exponent : 5 ; +490: ushort mantissa : 10 ; +491: } FLOAT16 ; +492: +493: typedef struct { +494: BigEndian ( ) ; +495: local int i = 0 ; +496: do { +497: byte next : 1 ; +498: byte value : 7 ; +499: i ++ ; +500: } while ( i < 5 & next ) ; +501: } EncodedU32 ; +502: +503: typedef struct { +504: do { +505: char character ; +506: } while ( character != 0x0 ) ; +507: } STRING ; +508: +509: typedef struct { +510: ubyte LanguageCode ; +511: } LANGCODE ; +512: +513: typedef struct { +514: ubyte Red ; +515: ubyte Green ; +516: ubyte Blue ; +517: } RGB ; +518: +519: typedef struct { +520: ubyte Red ; +521: ubyte Green ; +522: ubyte Blue ; +523: ubyte Alpha ; +524: } RGBA ; +525: +526: typedef struct { +527: ubyte Alpha ; +528: ubyte Red ; +529: ubyte Green ; +530: ubyte Blue ; +531: } ARGB ; +532: +533: +534: +535: +536: +537: +538: +539: +540: +541: +542: +543: typedef struct { +544: ubyte Nbits : 5 ; +545: BitfieldDisablePadding ( ) ; +546: int Xmin : Nbits ; +547: int Xmax : Nbits ; +548: int Ymin : Nbits ; +549: int Ymax : Nbits ; +550: BitfieldEnablePadding ( ) ; +551: } RECT ; +552: +553: typedef struct { +554: BitfieldEnablePadding ( ) ; +555: BitfieldLeftToRight ( ) ; +556: ubyte HasScale : 1 ; +557: if ( HasScale ) { +558: ubyte NScaleBits : 5 ; +559: BitfieldDisablePadding ( ) ; +560: int ScaleX : NScaleBits ; +561: int ScaleY : NScaleBits ; +562: } +563: ubyte HasRotate : 1 ; +564: if ( HasRotate ) { +565: ubyte NRotateBits : 5 ; +566: BitfieldDisablePadding ( ) ; +567: int RotateSkew0 : NRotateBits ; +568: int RotateSkew1 : NRotateBits ; +569: } +570: ubyte NTranslateBits : 5 ; +571: BitfieldDisablePadding ( ) ; +572: int TranslateX : NTranslateBits ; +573: int TranslateY : NTranslateBits ; +574: BitfieldEnablePadding ( ) ; +575: } MATRIX ; +576: +577: typedef struct { +578: ushort Tag ; +579: string Name ; +580: } ASSETS ; +581: +582: typedef struct { +583: EncodedU32 Offset ; +584: string Name ; +585: } OFFSETANDNAME ; +586: +587: typedef struct { +588: BitfieldEnablePadding ( ) ; +589: ubyte HasAddTerms : 1 ; +590: ubyte HasMultTerms : 1 ; +591: ubyte Nbits : 4 ; +592: BitfieldDisablePadding ( ) ; +593: if ( HasMultTerms ) { +594: short RedMultTerm : Nbits ; +595: short GreenMultTerm : Nbits ; +596: short BlueMultTerm : Nbits ; +597: } +598: if ( HasAddTerms ) { +599: short RedAddTerm : Nbits ; +600: short GreenAddTerm : Nbits ; +601: short BlueAddTerm : Nbits ; +602: } +603: BitfieldEnablePadding ( ) ; +604: } CXFORM ; +605: +606: typedef struct { +607: BitfieldEnablePadding ( ) ; +608: ubyte HasAddTerms : 1 ; +609: ubyte HasMultTerms : 1 ; +610: ubyte Nbits : 4 ; +611: BitfieldDisablePadding ( ) ; +612: if ( HasMultTerms ) { +613: short RedMultTerm : Nbits ; +614: short GreenMultTerm : Nbits ; +615: short BlueMultTerm : Nbits ; +616: short AlphaMultTerm : Nbits ; +617: } +618: if ( HasAddTerms ) { +619: short RedAddTerm : Nbits ; +620: short GreenAddTerm : Nbits ; +621: short BlueAddTerm : Nbits ; +622: short AlphaAddTerm : Nbits ; +623: } +624: BitfieldEnablePadding ( ) ; +625: } CXFORMWITHALPHA ; +626: +627: typedef struct { +628: ushort ClipEventKeyUp : 1 ; +629: ushort ClipEventKeyDown : 1 ; +630: ushort ClipEventMouseUp : 1 ; +631: ushort ClipEventMouseDown : 1 ; +632: ushort ClipEventMouseMove : 1 ; +633: ushort ClipEventUnload : 1 ; +634: ushort ClipEventEnterFrame : 1 ; +635: ushort ClipEventLoad : 1 ; +636: ushort ClipEventDragOver : 1 ; +637: ushort ClipEventRollOut : 1 ; +638: ushort ClipEventRollOver : 1 ; +639: ushort ClipEventReleaseOutside : 1 ; +640: ushort ClipEventRelease : 1 ; +641: ushort ClipEventPress : 1 ; +642: ushort ClipEventInitialize : 1 ; +643: ushort ClipEventData : 1 ; +644: if ( File . Header . Version >= 6 ) { +645: ushort Reserved : 5 ; +646: ushort ClipEventConstruct : 1 ; +647: ushort ClipEventKeyPress : 1 ; +648: ushort ClipEventDragout : 1 ; +649: ushort Reserved : 8 ; +650: } +651: } CLIPEVENTFLAGS ; +652: +653: typedef struct { +654: CLIPEVENTFLAGS EventFlags ; +655: uint ActionRecordSize ; +656: if ( ( File . Header . Version > 5 ) && EventFlags . ClipEventKeyPress ) { +657: ubyte KeyCode ; +658: } +659: do { +660: ACTIONRECORD Action ; +661: } while ( Action . ActionCode != 0x0 ) ; +662: } CLIPACTIONRECORD ; +663: +664: +665: typedef struct { +666: local uint clips ; +667: ushort Reserved ; +668: CLIPEVENTFLAGS AllEventFlags ; +669: do { +670: CLIPACTIONRECORD ClipActionRecord ; +671: } while ( ( SWFTagEnd - FTell ( ) ) > 9 ) ; +672: if ( File . Header . Version > 5 ) { +673: uint ClipActionEndFlag ; +674: } +675: else { +676: ushort ClipActionEndFlag ; +677: } +678: } CLIPACTIONS ; +679: +680: typedef struct { +681: float Matrix [ 20 ] ; +682: } COLORMATRIXFILTER ; +683: +684: typedef struct { +685: ubyte MatrixX ; +686: ubyte MatrixY ; +687: float Divisor ; +688: float Bias ; +689: float Matrix [ MatrixX * MatrixY ] ; +690: RGBA DefaultColor ; +691: ubyte Reserved : 6 ; +692: ubyte Clamp : 1 ; +693: ubyte PreserveAlpha : 1 ; +694: } CONVOLUTIONFILTER ; +695: +696: typedef struct { +697: FIXED BlurX ; +698: FIXED BlurY ; +699: ubyte Passes : 5 ; +700: ubyte Reserved : 3 ; +701: } BLURFILTER ; +702: +703: typedef struct { +704: RGBA DropShadowColor ; +705: FIXED BlurX ; +706: FIXED BlurY ; +707: FIXED Angle ; +708: FIXED Distance ; +709: FIXED8 Strength ; +710: ubyte InnerShadow : 1 ; +711: ubyte Knockout : 1 ; +712: ubyte CompositeSource : 1 ; +713: ubyte Passes : 5 ; +714: } DROPSHADOWFILTER ; +715: +716: typedef struct { +717: RGBA GlowColor ; +718: FIXED BlurX ; +719: FIXED BlurY ; +720: FIXED8 Strength ; +721: ubyte InnerShadow : 1 ; +722: ubyte Knockout : 1 ; +723: ubyte CompositeSource : 1 ; +724: ubyte Passes : 5 ; +725: } GLOWFILTER ; +726: +727: typedef struct { +728: RGBA ShadowColor ; +729: RGBA HighlightColor ; +730: FIXED BlurX ; +731: FIXED BlurY ; +732: FIXED Angle ; +733: FIXED Distance ; +734: FIXED8 Strength ; +735: ubyte InnerShadow : 1 ; +736: ubyte Knockout : 1 ; +737: ubyte CompositeSource : 1 ; +738: ubyte OnTop : 1 ; +739: ubyte Passes : 4 ; +740: } BEVELFILTER ; +741: +742: typedef struct { +743: ubyte Ratio ; +744: if ( ( CurrentTag == 2 ) +745: || ( CurrentTag == 22 ) ) { +746: RGB Color ; +747: } +748: else { +749: RGBA Color ; +750: } +751: } GRADRECORD ; +752: +753: typedef struct { +754: local short i ; +755: ubyte SpreadMode : 2 ; +756: ubyte InterpolationMode : 2 ; +757: ubyte NumGradients : 4 ; +758: for ( i = 0 ; i < NumGradients ; i ++ ) { +759: GRADRECORD GradientRecord ; +760: } +761: } GRADIENT ; +762: +763: typedef struct { +764: local short i ; +765: ubyte SpreadMode : 2 ; +766: ubyte InterpolationMode : 2 ; +767: ubyte NumGradients : 4 ; +768: for ( i = 0 ; i < NumGradients ; i ++ ) { +769: GRADRECORD GradientRecord ; +770: } +771: FIXED8 FocalPoint ; +772: } FOCALGRADIENT ; +773: +774: typedef struct { +775: ubyte NumColors ; +776: RGBA GradientColors [ NumColors ] ; +777: ubyte GradientRatio [ NumColors ] ; +778: FIXED BlurX ; +779: FIXED BlurY ; +780: FIXED Angle ; +781: FIXED Distance ; +782: FIXED8 Strength ; +783: ubyte InnerShadow : 1 ; +784: ubyte Knockout : 1 ; +785: ubyte CompositeSource : 1 ; +786: ubyte OnTop : 1 ; +787: ubyte Passes : 4 ; +788: } GRADIENTGLOWFILTER ; +789: +790: typedef struct { +791: ubyte NumColors ; +792: RGBA GradientColors [ NumColors ] ; +793: ubyte GradientRatio [ NumColors ] ; +794: FIXED BlurX ; +795: FIXED BlurY ; +796: FIXED Angle ; +797: FIXED Distance ; +798: FIXED8 Strength ; +799: ubyte InnerShadow : 1 ; +800: ubyte Knockout : 1 ; +801: ubyte CompositeSource : 1 ; +802: ubyte OnTop : 1 ; +803: ubyte Passes : 4 ; +804: } GRADIENTBEVELFILTER ; +805: +806: +807: +808: typedef struct { +809: ushort FilterId ; +810: switch ( FilterId ) { +811: case 0 : +812: DROPSHADOWFILTER DropShadowFilter ; +813: break ; +814: case 1 : +815: BLURFILTER BlurFilter ; +816: break ; +817: case 2 : +818: GLOWFILTER GlowFilter ; +819: break ; +820: case 3 : +821: BEVELFILTER BevelFilter ; +822: break ; +823: case 4 : +824: GRADIENTGLOWFILTER GradientGlowFilter ; +825: break ; +826: case 5 : +827: CONVOLUTIONFILTER ConvolutionFilter ; +828: break ; +829: case 6 : +830: COLORMATRIXFILTER ColorMatrixFilter ; +831: break ; +832: case 7 : +833: GRADIENTBEVELFILTER GradientBevelFilter ; +834: break ; +835: } +836: } FILTER ; +837: +838: typedef struct { +839: local ushort i ; +840: ubyte NumberOfFilters ; +841: for ( i = 0 ; i < NumberOfFilters ; i ++ ) { +842: FILTER Filter ; +843: } +844: } FILTERLIST ; +845: +846: typedef struct { +847: ubyte FillStyleType ; +848: switch ( FillStyleType ) { +849: case 0x0 : +850: if ( ( CurrentTag == 2 ) +851: || ( CurrentTag == 22 ) ) { +852: RGB Color ; +853: } +854: else { +855: RGBA Color ; +856: } +857: break ; +858: case 0x10 : +859: case 0x12 : +860: MATRIX GradientMatrix ; +861: GRADIENT Gradient ; +862: break ; +863: case 0x13 : +864: FOCALGRADIENT Gradient ; +865: break ; +866: case 0x40 : +867: case 0x41 : +868: case 0x42 : +869: case 0x43 : +870: ushort BitmapId ; +871: MATRIX BitmapMatrix ; +872: break ; +873: default : +874: break ; +875: } +876: } FILLSTYLE ; +877: +878: typedef struct { +879: local ushort i ; +880: ubyte FillStyleCount ; +881: if ( FillStyleCount == 0xFF ) { +882: UI16 FillStyleCountExtended ; +883: for ( i = 0 ; i < FillStyleCount ; i ++ ) { +884: FILLSTYLE FillStyle ; +885: } +886: } +887: else { +888: for ( i = 0 ; i < FillStyleCount ; i ++ ) { +889: FILLSTYLE FillStyle ; +890: } +891: } +892: } FILLSTYLEARRAY ; +893: +894: typedef struct { +895: ushort Width ; +896: if ( ( CurrentTag == 2 ) +897: || ( CurrentTag == 22 ) ) { +898: RGB Color ; +899: } +900: else { +901: RGBA Color ; +902: } +903: } LINESTYLE ; +904: +905: typedef struct { +906: ushort Width ; +907: ubyte StartCapStyle : 2 ; +908: ubyte JoinStyle : 2 ; +909: ubyte HasFillFlag : 1 ; +910: ubyte NoHScaleFlag : 1 ; +911: ubyte NoVScaleFlag : 1 ; +912: ubyte PixelHintingFlag : 1 ; +913: ubyte Reserved : 5 ; +914: ubyte NoClose : 1 ; +915: ubyte EndCapStyle : 2 ; +916: if ( JoinStyle == 2 ) { +917: ushort MiterLimitFactor ; +918: } +919: if ( HasFillFlag ) { +920: FILLSTYLE FillType ; +921: } +922: else { +923: RGBA Color ; +924: } +925: } LINESTYLE2 ; +926: +927: typedef struct { +928: local ushort i ; +929: BitfieldDisablePadding ( ) ; +930: ubyte LineStyleCount ; +931: if ( LineStyleCount == 0xFF ) { +932: UI16 LineStyleCountExtended ; +933: for ( i = 0 ; i < LineStyleCountExtended ; i ++ ) { +934: if ( ( CurrentTag == 2 ) +935: || ( CurrentTag == 22 ) +936: || ( CurrentTag == 32 ) ) { +937: LINESTYLE LineStyle ; +938: } +939: else if ( CurrentTag == 83 ) { +940: LINESTYLE2 LineStyle ; +941: } +942: } +943: } +944: else { +945: for ( i = 0 ; i < LineStyleCount ; i ++ ) { +946: if ( ( CurrentTag == 2 ) +947: || ( CurrentTag == 22 ) +948: || ( CurrentTag == 32 ) ) { +949: LINESTYLE LineStyle ; +950: } +951: else if ( CurrentTag == 83 ) { +952: LINESTYLE2 LineStyle ; +953: } +954: } +955: } +956: BitfieldEnablePadding ( ) ; +957: } LINESTYLEARRAY ; +958: +959: typedef struct { +960: BitfieldDisablePadding ( ) ; +961: ubyte TypeFlag : 1 ; +962: if ( TypeFlag ) { +963: ubyte StraightFlag : 1 ; +964: if ( StraightFlag ) { +965: ubyte NumBits : 4 ; +966: ubyte GeneralLineFlag : 1 ; +967: if ( GeneralLineFlag ) { +968: int DeltaX : NumBits + 2 ; +969: int DeltaY : NumBits + 2 ; +970: } +971: else { +972: ubyte VertLineFlag : 1 ; +973: if ( VertLineFlag ) { +974: int DeltaY : NumBits + 2 ; +975: } +976: else { +977: int DeltaX : NumBits + 2 ; +978: } +979: } +980: } +981: else { +982: ubyte NumBits : 4 ; +983: int ControlDeltaX : NumBits + 2 ; +984: int ControlDeltaY : NumBits + 2 ; +985: int AnchorDeltaX : NumBits + 2 ; +986: int AnchorDeltaY : NumBits + 2 ; +987: } +988: } +989: else { +990: ubyte StateNewStyles : 1 ; +991: ubyte StateLineStyle : 1 ; +992: ubyte StateFillStyle1 : 1 ; +993: ubyte StateFillStyle0 : 1 ; +994: ubyte StateMoveTo : 1 ; +995: if ( StateMoveTo ) { +996: ubyte MoveBits : 5 ; +997: int MoveDeltaX : MoveBits ; +998: int MoveDeltaY : MoveBits ; +999: } +1000: if ( StateFillStyle0 ) { +1001: int FillStyle0 : FillBits ; +1002: } +1003: if ( StateFillStyle1 ) { +1004: int FillStyle1 : FillBits ; +1005: } +1006: if ( StateLineStyle ) { +1007: int LineStyle : LineBits ; +1008: } +1009: if ( ( CurrentTag == 22 || CurrentTag == 32 ) && StateNewStyles ) { +1010: FILLSTYLEARRAY FillStyles ; +1011: LINESTYLEARRAY LineStyles ; +1012: ubyte NumFillBits : 4 ; +1013: ubyte NumLineBits : 4 ; +1014: FillBits = NumFillBits ; +1015: LineBits = NumLineBits ; +1016: } +1017: } +1018: +1019: +1020: +1021: +1022: +1023: +1024: +1025: +1026: +1027: +1028: +1029: +1030: } SHAPERECORD < read = GetShapeRecordType > ; +1031: +1032: string GetShapeRecordType ( SHAPERECORD & ShapeRecord ) +1033: { +1034: if ( ShapeRecord . TypeFlag ) { +1035: if ( ShapeRecord . StraightFlag ) { +1036: return "StraightEdgeRecord" ; +1037: } +1038: else { +1039: return "CurvedEdgeRecord" ; +1040: } +1041: } +1042: else if ( ShapeRecord . TypeFlag +1043: || ShapeRecord . StateNewStyles +1044: || ShapeRecord . StateLineStyle +1045: || ShapeRecord . StateFillStyle1 +1046: || ShapeRecord . StateFillStyle0 +1047: || ShapeRecord . StateMoveTo ) { +1048: return "StyleChangeRecord" ; +1049: } +1050: else { +1051: return "EndShapeRecord" ; +1052: } +1053: +1054: } +1055: +1056: typedef struct { +1057: BitfieldEnablePadding ( ) ; +1058: ubyte NumFillBits : 4 ; +1059: ubyte NumLineBits : 4 ; +1060: local ubyte FillBits = NumFillBits ; +1061: local ubyte LineBits = NumLineBits ; +1062: BitfieldDisablePadding ( ) ; +1063: do { +1064: SHAPERECORD ShapeRecord ; +1065: } while ( ShapeRecord . TypeFlag +1066: || ShapeRecord . StateNewStyles +1067: || ShapeRecord . StateLineStyle +1068: || ShapeRecord . StateFillStyle1 +1069: || ShapeRecord . StateFillStyle0 +1070: || ShapeRecord . StateMoveTo ) ; +1071: BitfieldEnablePadding ( ) ; +1072: } SHAPE ; +1073: +1074: typedef struct { +1075: BitfieldEnablePadding ( ) ; +1076: FILLSTYLEARRAY FillStyles ; +1077: LINESTYLEARRAY LineStyles ; +1078: ubyte NumFillBits : 4 ; +1079: ubyte NumLineBits : 4 ; +1080: local ubyte FillBits = NumFillBits ; +1081: local ubyte LineBits = NumLineBits ; +1082: BitfieldDisablePadding ( ) ; +1083: do { +1084: SHAPERECORD ShapeRecord ; +1085: } while ( ShapeRecord . TypeFlag +1086: || ShapeRecord . StateNewStyles +1087: || ShapeRecord . StateLineStyle +1088: || ShapeRecord . StateFillStyle1 +1089: || ShapeRecord . StateFillStyle0 +1090: || ShapeRecord . StateMoveTo ) ; +1091: BitfieldEnablePadding ( ) ; +1092: } SHAPEWITHSTYLE ; +1093: +1094: typedef struct { +1095: ubyte StartRatio ; +1096: RGBA StartColor ; +1097: ubyte EndRatio ; +1098: RGBA EndColor ; +1099: } MORPHGRADRECORD ; +1100: +1101: typedef struct { +1102: local ushort i ; +1103: ubyte NumGradients ; +1104: for ( i = 0 ; i < NumGradients ; i ++ ) { +1105: MORPHGRADRECORD GradientRecords ; +1106: } +1107: } MORPHGRADIENT ; +1108: +1109: typedef struct { +1110: ubyte FillStyleType ; +1111: switch ( FillStyleType ) { +1112: case 0x0 : +1113: RGBA StartColor ; +1114: RGBA EndColor ; +1115: break ; +1116: case 0x10 : +1117: case 0x12 : +1118: MATRIX StartGradientMatrix ; +1119: MATRIX EndGradientMatrix ; +1120: MORPHGRADIENT Gradient ; +1121: break ; +1122: case 0x40 : +1123: case 0x41 : +1124: case 0x42 : +1125: case 0x43 : +1126: MATRIX StartBitmapMatrix ; +1127: MATRIX EndBitmapMatrix ; +1128: break ; +1129: default : +1130: break ; +1131: } +1132: } MORPHFILLSTYLE ; +1133: +1134: typedef struct { +1135: ushort StartWidth ; +1136: ushort EndWidth ; +1137: ubyte StartCapStyle : 2 ; +1138: ubyte JoinStyle : 2 ; +1139: ubyte HasFillFlag : 1 ; +1140: ubyte NoHScaleFlag : 1 ; +1141: ubyte NoVScaleFlag : 1 ; +1142: ubyte PixelHintingFlag : 1 ; +1143: ubyte NoClose : 1 ; +1144: ubyte EndCapStyle : 2 ; +1145: if ( JoinStyle == 2 ) { +1146: ushort MiterLimitFactor ; +1147: } +1148: if ( HasFillFlag == 0 ) { +1149: RGBA StartColor ; +1150: RGBA EndColor ; +1151: } +1152: else { +1153: MORPHFILLSTYLE FillType ; +1154: } +1155: } MORPHLINESTYLE2 ; +1156: +1157: typedef struct { +1158: ushort StartWidth ; +1159: ushort EndWidth ; +1160: RGBA StartColor ; +1161: RGBA EndColor ; +1162: } MORPHLINESTYLE ; +1163: +1164: typedef struct { +1165: ubyte LineStyleCount ; +1166: if ( LineStyleCount == 0xFF ) { +1167: ushort LineStyleCountExtended ; +1168: for ( i = 0 ; i < LineStyleCountExtended ; i ++ ) { +1169: if ( CurrentTag == 46 ) { +1170: MORPHLINESTYLE LineStyle ; +1171: } +1172: else if ( CurrentTag == 84 ) { +1173: MORPHLINESTYLE2 LineStyle ; +1174: } +1175: } +1176: } +1177: else { +1178: for ( i = 0 ; i < LineStyleCount ; i ++ ) { +1179: if ( CurrentTag == 46 ) { +1180: MORPHLINESTYLE LineStyle ; +1181: } +1182: else if ( CurrentTag == 84 ) { +1183: MORPHLINESTYLE2 LineStyle ; +1184: } +1185: } +1186: } +1187: } MORPHLINESTYLES ; +1188: +1189: typedef struct { +1190: local ushort i ; +1191: ubyte FillStyleCount ; +1192: if ( FillStyleCount == 0xFF ) { +1193: for ( i = 0 ; i < FillStyleCountExtended ; i ++ ) { +1194: MORPHFILLSTYLE FillStyle ; +1195: } +1196: } +1197: else { +1198: for ( i = 0 ; i < FillStyleCount ; i ++ ) { +1199: MORPHFILLSTYLE FillStyle ; +1200: } +1201: } +1202: } MORPHFILLSTYLEARRAY ; +1203: +1204: typedef struct { +1205: ubyte Pix15Reserved : 1 ; +1206: ubyte Pix15Red : 5 ; +1207: ubyte Pix15Green : 5 ; +1208: ubyte Pix15Blue : 5 ; +1209: } PIX15 ; +1210: +1211: typedef struct { +1212: ubyte Pix24Reserved ; +1213: ubyte Pix24Red ; +1214: ubyte Pix24Green ; +1215: ubyte Pix24Blue ; +1216: } PIX24 ; +1217: +1218: typedef struct { +1219: RGB ColorTableRGB [ ( BitmapColorTableSize + 1 ) ] ; +1220: ubyte ColormapPixelData [ ( BitmapWidth * BitmapHeight ) ] ; +1221: } COLORMAPDATA ; +1222: +1223: typedef struct { +1224: if ( BitmapFormat == 4 ) { +1225: PIX15 BitmapPixelData [ ( BitmapWidth * BitmapHeight ) ] ; +1226: } +1227: else if ( BitmapFormat == 5 ) { +1228: PIX24 BitmapPixelData [ ( BitmapWidth * BitmapHeight ) ] ; +1229: } +1230: } BITMAPDATA ; +1231: +1232: typedef struct { +1233: RGBA ColorTableRGB [ ( BitmapColorTableSize + 1 ) ] ; +1234: ubyte ColormapPixelData [ ( 4 - ( BitmapWidth & 3 ) ) * BitmapHeight ] ; +1235: } ALPHACOLORMAPDATA ; +1236: +1237: typedef struct { +1238: ARGB BitmapPixelData [ ( BitmapWidth * BitmapHeight ) ] ; +1239: } ALPHABITMAPDATA ; +1240: +1241: typedef struct { +1242: ubyte ButtonReserved : 2 ; +1243: ubyte ButtonHasBlendMode : 1 ; +1244: ubyte ButtonHasFilterList : 1 ; +1245: ubyte ButtonStateHitTest : 1 ; +1246: ubyte ButtonStateDown : 1 ; +1247: ubyte ButtonStateOver : 1 ; +1248: ubyte ButtonStateUp : 1 ; +1249: +1250: if ( Character . ButtonReserved +1251: || Character . ButtonHasBlendMode +1252: || Character . ButtonHasFilterList +1253: || Character . ButtonStateHitTest +1254: || Character . ButtonStateDown +1255: || Character . ButtonStateOver +1256: || Character . ButtonStateUp ) { +1257: ushort CharacterID ; +1258: ushort PlaceDepth ; +1259: MATRIX PlaceMatrix ; +1260: if ( CurrentTag == 34 ) { +1261: CXFORMWITHALPHA ColorTransform ; +1262: if ( ButtonHasFilterList ) { +1263: FILTERLIST FilterList ; +1264: } +1265: if ( ButtonHasBlendMode ) { +1266: ubyte BlendMode ; +1267: } +1268: } +1269: } +1270: } BUTTONRECORD ; +1271: +1272: typedef struct { +1273: ushort CondActionSize ; +1274: ubyte CondIdleToOverDown : 1 ; +1275: ubyte CondOutDownToIdle : 1 ; +1276: ubyte CondOutDownToOverDown : 1 ; +1277: ubyte CondOverDownToOutDown : 1 ; +1278: ubyte CondOverDownToOverUp : 1 ; +1279: ubyte CondOverUpToOverDown : 1 ; +1280: ubyte CondOverUpToIdle : 1 ; +1281: ubyte CondIdleToOverUp : 1 ; +1282: ubyte CondKeyPress : 7 ; +1283: ubyte CondOverDownToIdle : 1 ; +1284: do { +1285: ACTIONRECORD Action ; +1286: } while ( Action . ActionCode != 0x0 ) ; +1287: } BUTTONCONDACTION ; +1288: +1289: typedef struct { +1290: uint Pos44 ; +1291: ushort LeftLevel ; +1292: ushort RightLevel ; +1293: } SOUNDENVELOPE ; +1294: +1295: typedef struct { +1296: ubyte Reserved : 2 ; +1297: ubyte SyncStop : 1 ; +1298: ubyte SyncNoMultiple : 1 ; +1299: ubyte HasEnvelope : 1 ; +1300: ubyte HasLoops : 1 ; +1301: ubyte HasOutPoint : 1 ; +1302: ubyte HasInPoint : 1 ; +1303: if ( HasInPoint ) { +1304: uint InPoint ; +1305: } +1306: if ( HasOutPoint ) { +1307: uint OutPoint ; +1308: } +1309: if ( HasLoops ) { +1310: ushort LoopCount ; +1311: } +1312: if ( HasEnvelope ) { +1313: ubyte EnvPoints ; +1314: SOUNDENVELOPE EnvelopeRecords [ EnvPoints ] ; +1315: } +1316: } SOUNDINFO ; +1317: +1318: typedef struct { +1319: if ( FontFlagsWideCodes ) { +1320: ushort FontKerningCode1 ; +1321: ushort FontKerningCode2 ; +1322: } +1323: else { +1324: ubyte FontKerningCode1 ; +1325: ubyte FontKerningCode2 ; +1326: } +1327: BigEndian ( ) ; +1328: short FontKerningAdjustment ; +1329: LittleEndian ( ) ; +1330: } KERNINGRECORD ; +1331: +1332: +1333: +1334: +1335: +1336: +1337: +1338: +1339: typedef struct { +1340: BitfieldEnablePadding ( ) ; +1341: ushort TagType : 10 ; +1342: ushort TagLength : 6 ; +1343: if ( TagLength == 0x3F ) { +1344: int Length ; +1345: } +1346: } RECORDHEADER ; +1347: +1348: typedef struct { +1349: local int i ; +1350: BitfieldLeftToRight ( ) ; +1351: +1352: RECORDHEADER Header ; +1353: CurrentTag = Header . TagType ; +1354: +1355: if ( Header . TagLength < 0x3F ) { +1356: SWFTagEnd = FTell ( ) + Header . TagLength ; +1357: } +1358: else { +1359: SWFTagEnd = FTell ( ) + Header . Length ; +1360: } +1361: +1362: switch ( Header . TagType ) { +1363: +1364: +1365: +1366: case 59 : +1367: ushort SpriteID ; +1368: case 12 : +1369: do { +1370: ACTIONRECORD ActionTag ; +1371: } while ( ActionTag . ActionCode != 0x0 ) ; +1372: break ; +1373: case 82 : +1374: ubyte ByteCode [ SWFTagEnd - FTell ( ) ] ; +1375: break ; +1376: +1377: +1378: +1379: +1380: +1381: case 4 : +1382: ushort CharacterId ; +1383: ushort Depth ; +1384: MATRIX Matrix ; +1385: if ( Header . TagLength == 0x3F ) { +1386: if ( Header . Length < ( sizeof ( Matrix ) + 4 ) ) { +1387: CXFORM ColorTransform ; +1388: } +1389: } +1390: else if ( Header . TagLength < ( sizeof ( Matrix ) + 4 ) ) { +1391: CXFORM ColorTransform ; +1392: } +1393: break ; +1394: case 26 : +1395: ubyte PlaceFlagHasClipActions : 1 ; +1396: ubyte PlaceFlagHasClipDepth : 1 ; +1397: ubyte PlaceFlagHasName : 1 ; +1398: ubyte PlaceFlagHasRatio : 1 ; +1399: ubyte PlaceFlagHasColorTransform : 1 ; +1400: ubyte PlaceFlagHasMatrix : 1 ; +1401: ubyte PlaceFlagHasCharacter : 1 ; +1402: ubyte PlaceFlagMove : 1 ; +1403: ushort Depth ; +1404: if ( PlaceFlagHasCharacter ) ushort CharacterId ; +1405: if ( PlaceFlagHasMatrix ) MATRIX Matrix ; +1406: if ( PlaceFlagHasColorTransform ) CXFORMWITHALPHA ColorTransform ; +1407: if ( PlaceFlagHasRatio ) ushort Ratio ; +1408: if ( PlaceFlagHasName ) string Name ; +1409: if ( PlaceFlagHasClipDepth ) ushort ClipDepth ; +1410: if ( PlaceFlagHasClipActions ) CLIPACTIONS ClipActions ; +1411: break ; +1412: case 70 : +1413: ubyte PlaceFlagHasClipActions : 1 ; +1414: ubyte PlaceFlagHasClipDepth : 1 ; +1415: ubyte PlaceFlagHasName : 1 ; +1416: ubyte PlaceFlagHasRatio : 1 ; +1417: ubyte PlaceFlagHasColorTransform : 1 ; +1418: ubyte PlaceFlagHasMatrix : 1 ; +1419: ubyte PlaceFlagHasCharacter : 1 ; +1420: ubyte PlaceFlagMove : 1 ; +1421: ubyte Reserved : 3 ; +1422: ubyte PlaceFlagHasImage : 1 ; +1423: ubyte PlaceFlagHasClassName : 1 ; +1424: ubyte PlaceFlagHasCacheAsBitmap : 1 ; +1425: ubyte PlaceFlagHasBlendMode : 1 ; +1426: ubyte PlaceFlagHasFilterList : 1 ; +1427: ushort Depth ; +1428: if ( PlaceFlagHasClassName +1429: || ( PlaceFlagHasImage && PlaceFlagHasCharacter ) ) { +1430: string ClassName ; +1431: } +1432: if ( PlaceFlagHasCharacter ) { +1433: ushort CharacterId ; +1434: } +1435: if ( PlaceFlagHasMatrix ) { +1436: MATRIX Matrix ; +1437: } +1438: if ( PlaceFlagHasColorTransform ) { +1439: CXFORMWITHALPHA ColorTransform ; +1440: } +1441: if ( PlaceFlagHasRatio ) { +1442: ushort Ratio ; +1443: } +1444: if ( PlaceFlagHasName ) { +1445: string Name ; +1446: } +1447: if ( PlaceFlagHasFilterList ) { +1448: FILTERLIST SurfaceFilterList ; +1449: } +1450: if ( PlaceFlagHasBlendMode ) { +1451: ubyte BlendMode ; +1452: } +1453: if ( PlaceFlagHasClipActions ) { +1454: CLIPACTIONS ClipActions ; +1455: } +1456: break ; +1457: case 5 : +1458: ushort CharacterId ; +1459: ushort Depth ; +1460: break ; +1461: case 28 : +1462: ushort Depth ; +1463: break ; +1464: case 1 : +1465: break ; +1466: +1467: +1468: +1469: +1470: +1471: case 9 : +1472: RGB BackgroundColor ; +1473: break ; +1474: case 43 : +1475: string Name ; +1476: if ( ( File . Header . Version >= 6 ) && ( SWFTagEnd > FTell ( ) ) ) { +1477: ubyte NamedAnchor ; +1478: } +1479: break ; +1480: case 24 : +1481: if ( ( SWFTagEnd - FTell ( ) ) > 0 ) { +1482: ubyte Password [ SWFTagEnd - FTell ( ) ] ; +1483: } +1484: break ; +1485: case 0 : +1486: break ; +1487: case 56 : +1488: ushort Count ; +1489: for ( i = 0 ; i < Count ; i ++ ) { +1490: ASSETS Asset ; +1491: } +1492: break ; +1493: case 57 : +1494: string URL ; +1495: ushort Count ; +1496: for ( i = 0 ; i < Count ; i ++ ) { +1497: ASSETS Asset ; +1498: } +1499: break ; +1500: case 58 : +1501: string Password ; +1502: break ; +1503: case 64 : +1504: ushort Reserved ; +1505: string Password ; +1506: break ; +1507: case 65 : +1508: ushort MaxRecursionDepth ; +1509: ushort ScriptTimeoutSeconds ; +1510: break ; +1511: case 66 : +1512: ushort Depth ; +1513: ushort TabIndex ; +1514: break ; +1515: case 69 : +1516: uint Reserved : 3 ; +1517: uint HasMetadata : 1 ; +1518: uint ActionScript3 : 1 ; +1519: uint Reserved2 : 2 ; +1520: uint UseNetwork : 1 ; +1521: uint Reserved3 : 24 ; +1522: break ; +1523: case 71 : +1524: string URL ; +1525: ubyte Reserved ; +1526: ubyte Reserved2 ; +1527: ushort Count ; +1528: for ( i = 0 ; i < Count ; i ++ ) { +1529: ASSETS Asset ; +1530: } +1531: break ; +1532: case 76 : +1533: ushort NumSymbols ; +1534: for ( i = 0 ; i < NumSymbols ; i ++ ) { +1535: ASSETS Symbol ; +1536: } +1537: break ; +1538: case 77 : +1539: string Metadata ; +1540: break ; +1541: case 78 : +1542: ushort CharacterId ; +1543: RECT Splitter ; +1544: break ; +1545: case 86 : +1546: EncodedU32 SceneCount ; +1547: if ( ( SWFTagEnd - FTell ( ) ) > 0 ) { +1548: ubyte SceneAndFrameData [ SWFTagEnd - FTell ( ) ] ; +1549: } +1550: break ; +1551: +1552: +1553: +1554: +1555: +1556: case 2 : +1557: ushort ShapeId ; +1558: RECT ShapeBounds ; +1559: SHAPEWITHSTYLE Shapes ; +1560: break ; +1561: case 22 : +1562: ushort ShapeId ; +1563: RECT ShapeBounds ; +1564: SHAPEWITHSTYLE Shapes ; +1565: break ; +1566: case 32 : +1567: ushort ShapeId ; +1568: RECT ShapeBounds ; +1569: SHAPEWITHSTYLE Shapes ; +1570: break ; +1571: case 83 : +1572: ushort ShapeId ; +1573: RECT ShapeBounds ; +1574: RECT EdgeBounds ; +1575: ubyte Reserved : 6 ; +1576: ubyte UsesNonScalingStrokes : 1 ; +1577: ubyte UsesScalingStrokes : 1 ; +1578: SHAPEWITHSTYLE Shapes ; +1579: break ; +1580: +1581: +1582: +1583: +1584: +1585: case 6 : +1586: ushort CharacterId ; +1587: if ( ( SWFTagEnd - FTell ( ) ) > 0 ) { +1588: ubyte JPEGData [ SWFTagEnd - FTell ( ) ] ; +1589: } +1590: break ; +1591: case 8 : +1592: if ( ( SWFTagEnd - FTell ( ) ) > 0 ) { +1593: ubyte JPEGData [ SWFTagEnd - FTell ( ) ] ; +1594: } +1595: break ; +1596: case 21 : +1597: ushort CharacterId ; +1598: if ( ( SWFTagEnd - FTell ( ) ) > 0 ) { +1599: ubyte JPEGData [ SWFTagEnd - FTell ( ) ] ; +1600: } +1601: break ; +1602: case 35 : +1603: ushort CharacterID ; +1604: uint AlphaDataOffset ; +1605: if ( AlphaDataOffset ) { +1606: ubyte JPEGData [ AlphaDataOffset ] ; +1607: } +1608: if ( ( SWFTagEnd - FTell ( ) ) > 0 ) { +1609: ubyte BitmapAlphaData [ SWFTagEnd - FTell ( ) ] ; +1610: } +1611: break ; +1612: case 20 : +1613: ushort CharacterID ; +1614: ubyte BitmapFormat ; +1615: ushort BitmapWidth ; +1616: ushort BitmapHeight ; +1617: if ( BitmapFormat == 3 ) { +1618: ubyte BitmapColorTableSize ; +1619: ubyte ZlibBitmapData [ SWFTagEnd - FTell ( ) ] ; +1620: } +1621: else if ( BitmapFormat == 4 || BitmapFormat == 5 ) { +1622: ubyte ZlibBitmapData [ SWFTagEnd - FTell ( ) ] ; +1623: } +1624: break ; +1625: case 36 : +1626: ushort CharacterID ; +1627: ubyte BitmapFormat ; +1628: ushort BitmapWidth ; +1629: ushort BitmapHeight ; +1630: if ( BitmapFormat == 3 ) { +1631: ubyte BitmapColorTableSize ; +1632: ubyte ZlibBitmapData [ SWFTagEnd - FTell ( ) ] ; +1633: } +1634: else if ( BitmapFormat == 4 || BitmapFormat == 5 ) { +1635: ubyte ZlibBitmapData [ SWFTagEnd - FTell ( ) ] ; +1636: } +1637: break ; +1638: +1639: +1640: +1641: +1642: +1643: case 46 : +1644: ushort CharacterId ; +1645: RECT StartBounds ; +1646: RECT EndBounds ; +1647: uint Offset ; +1648: MORPHFILLSTYLEARRAY MorphFillStyles ; +1649: MORPHLINESTYLES MorphLineStyles ; +1650: SHAPE StartEdges ; +1651: SHAPE EndEdges ; +1652: break ; +1653: case 46 : +1654: ushort CharacterId ; +1655: RECT StartBounds ; +1656: RECT EndBounds ; +1657: RECT StartEdgeBounds ; +1658: RECT EndEdgeBounds ; +1659: ubyte Reserved : 6 ; +1660: ubyte UsesNonScalingStrokes : 1 ; +1661: ubyte UsesScalingStrokes : 1 ; +1662: uint Offset ; +1663: MORPHFILLSTYLEARRAY MorphFillStyles ; +1664: MORPHLINESTYLES MorphLineStyles ; +1665: SHAPE StartEdges ; +1666: SHAPE EndEdges ; +1667: break ; +1668: +1669: +1670: +1671: +1672: +1673: case 10 : +1674: ushort FontID ; +1675: ubyte Data [ SWFTagEnd - FTell ( ) ] ; +1676: break ; +1677: case 13 : +1678: ushort FontID ; +1679: ubyte FontNameLen ; +1680: BitfieldDisablePadding ( ) ; +1681: ubyte FontName [ FontNameLen ] ; +1682: BitfieldEnablePadding ( ) ; +1683: ubyte FontFlagsReserved : 2 ; +1684: ubyte FontFlagsSmallText : 1 ; +1685: ubyte FontFlagsShiftJIS : 1 ; +1686: ubyte FontFlagsANSI : 1 ; +1687: ubyte FontFlagsBold : 1 ; +1688: ubyte FontFlagsWideCodes : 1 ; +1689: ubyte CodeTable [ SWFTagEnd - FTell ( ) ] ; +1690: break ; +1691: case 62 : +1692: ushort FontID ; +1693: ubyte FontNameLen ; +1694: BitfieldDisablePadding ( ) ; +1695: ubyte FontName [ FontNameLen ] ; +1696: BitfieldEnablePadding ( ) ; +1697: ubyte FontFlagsReserved : 2 ; +1698: ubyte FontFlagsSmallText : 1 ; +1699: ubyte FontFlagsShiftJIS : 1 ; +1700: ubyte FontFlagsANSI : 1 ; +1701: ubyte FontFlagsBold : 1 ; +1702: ubyte FontFlagsWideCodes : 1 ; +1703: LANGCODE LanguageCode ; +1704: ubyte CodeTable [ SWFTagEnd - FTell ( ) ] ; +1705: break ; +1706: case 48 : +1707: case 75 : +1708: ushort FontID ; +1709: ubyte FontFlagsHasLayout : 1 ; +1710: ubyte FontFlagsShiftJIS : 1 ; +1711: ubyte FontFlagsSmallText : 1 ; +1712: ubyte FontFlagsANSI : 1 ; +1713: ubyte FontFlagsWideOffsets : 1 ; +1714: ubyte FontFlagsWideCodes : 1 ; +1715: ubyte FontFlagsItalic : 1 ; +1716: ubyte FontFlagsBold : 1 ; +1717: LANGCODE LanguageCode ; +1718: ubyte FontNameLen ; +1719: ubyte FontName [ FontNameLen ] ; +1720: ushort NumGlyphs ; +1721: if ( FontFlagsWideOffsets ) { +1722: if ( NumGlyphs ) { +1723: uint OffsetTable [ NumGlyphs ] ; +1724: } +1725: uint CodeTableOffset ; +1726: } +1727: else { +1728: if ( NumGlyphs ) { +1729: ushort OffsetTable [ NumGlyphs ] ; +1730: } +1731: ushort CodeTableOffset ; +1732: } +1733: for ( i = 0 ; i < NumGlyphs ; i ++ ) { +1734: SHAPE GlyphShapeTable ; +1735: } +1736: if ( FontFlagsWideCodes ) { +1737: if ( NumGlyphs ) { +1738: ushort CodeTable [ NumGlyphs ] ; +1739: } +1740: } +1741: else { +1742: if ( NumGlyphs ) { +1743: ubyte CodeTable [ NumGlyphs ] ; +1744: } +1745: } +1746: if ( FontFlagsHasLayout ) { +1747: short FontAscent ; +1748: short FontDescent ; +1749: short FontLeading ; +1750: short FontAdvanceTable [ NumGlyphs ] ; +1751: for ( i = 0 ; i < NumGlyphs ; i ++ ) { +1752: RECT FontBoundsTable ; +1753: } +1754: ushort KerningCount ; +1755: for ( i = 0 ; i < KerningCount ; i ++ ) { +1756: KERNINGRECORD FontKerningTable ; +1757: } +1758: } +1759: break ; +1760: case 73 : +1761: ushort FontID ; +1762: ubyte CSMTableHint : 2 ; +1763: ubyte Reserved : 6 ; +1764: if ( ( SWFTagEnd - FTell ( ) ) > 0 ) { +1765: ubyte ZoneTable [ SWFTagEnd - FTell ( ) ] ; +1766: } +1767: break ; +1768: case 88 : +1769: ushort FontID ; +1770: string FontName ; +1771: string FontCopyright ; +1772: break ; +1773: case 11 : +1774: case 33 : +1775: ushort CharacterID ; +1776: RECT TextBounds ; +1777: MATRIX TextMatrix ; +1778: ubyte GlyphBits ; +1779: ubyte AdvanceBits ; +1780: ubyte TextRecords [ SWFTagEnd - FTell ( ) ] ; +1781: break ; +1782: case 37 : +1783: ushort CharacterID ; +1784: RECT Bounds ; +1785: ubyte HasText : 1 ; +1786: ubyte WordWrap : 1 ; +1787: ubyte Multiline : 1 ; +1788: ubyte Password : 1 ; +1789: ubyte ReadOnly : 1 ; +1790: ubyte HasTextColor : 1 ; +1791: ubyte HasMaxLength : 1 ; +1792: ubyte HasFont : 1 ; +1793: ubyte HasFontClass : 1 ; +1794: ubyte AutoSize : 1 ; +1795: ubyte HasLayout : 1 ; +1796: ubyte NoSelect : 1 ; +1797: ubyte Border : 1 ; +1798: ubyte WasStatic : 1 ; +1799: ubyte HTML : 1 ; +1800: ubyte UseOutlines : 1 ; +1801: if ( HasFont ) { +1802: ushort FontID ; +1803: } +1804: if ( HasFontClass ) { +1805: string FontClass ; +1806: } +1807: if ( HasFont ) { +1808: ushort FontHeight ; +1809: } +1810: if ( HasTextColor ) { +1811: RGBA TextColor ; +1812: } +1813: if ( HasMaxLength ) { +1814: ushort MaxLength ; +1815: } +1816: if ( HasLayout ) { +1817: ubyte Align ; +1818: ushort LeftMargin ; +1819: ushort RightMargin ; +1820: ushort Indent ; +1821: ushort Leading ; +1822: } +1823: string VariableName ; +1824: if ( HasText ) { +1825: string InitialText ; +1826: } +1827: break ; +1828: case 74 : +1829: ushort TextID ; +1830: ubyte UseFlashType : 2 ; +1831: ubyte GridFit : 3 ; +1832: ubyte Reserved : 3 ; +1833: float Thickness ; +1834: float Sharpness ; +1835: ubyte Reserved2 ; +1836: break ; +1837: +1838: +1839: +1840: +1841: +1842: case 14 : +1843: ushort SoundId ; +1844: ubyte SoundFormat : 4 ; +1845: ubyte SoundRate : 2 ; +1846: ubyte SoundSize : 1 ; +1847: ubyte SoundType : 1 ; +1848: uint SoundSampleCount ; +1849: ubyte SoundData [ SWFTagEnd - FTell ( ) ] ; +1850: break ; +1851: case 15 : +1852: ushort SoundId ; +1853: SOUNDINFO SoundInfo ; +1854: break ; +1855: case 89 : +1856: string SoundClassName ; +1857: SOUNDINFO SoundInfo ; +1858: break ; +1859: case 18 : +1860: ubyte Reserved : 4 ; +1861: ubyte PlaybackSoundRate : 2 ; +1862: ubyte PlaybackSoundSize : 1 ; +1863: ubyte PlaybackSoundType : 1 ; +1864: ubyte StreamSoundCompression : 4 ; +1865: ubyte StreamSoundRate : 2 ; +1866: ubyte StreamSoundSize : 1 ; +1867: ubyte StreamSoundType : 1 ; +1868: ushort StreamSoundSampleCount ; +1869: if ( StreamSoundCompression == 2 ) { +1870: short LatencySeek ; +1871: } +1872: break ; +1873: case 45 : +1874: ubyte Reserved : 4 ; +1875: ubyte PlaybackSoundRate : 2 ; +1876: ubyte PlaybackSoundSize : 1 ; +1877: ubyte PlaybackSoundType : 1 ; +1878: ubyte StreamSoundCompression : 4 ; +1879: ubyte StreamSoundRate : 2 ; +1880: ubyte StreamSoundSize : 1 ; +1881: ubyte StreamSoundType : 1 ; +1882: ushort StreamSoundSampleCount ; +1883: if ( StreamSoundCompression == 2 ) { +1884: short LatencySeek ; +1885: } +1886: break ; +1887: case 19 : +1888: ubyte StreamSoundData [ SWFTagEnd - FTell ( ) ] ; +1889: break ; +1890: +1891: +1892: +1893: +1894: +1895: case 7 : +1896: ushort ButtonId ; +1897: do { +1898: BUTTONRECORD Character ; +1899: } while ( Character . ButtonReserved +1900: || Character . ButtonHasBlendMode +1901: || Character . ButtonHasFilterList +1902: || Character . ButtonStateHitTest +1903: || Character . ButtonStateDown +1904: || Character . ButtonStateOver +1905: || Character . ButtonStateUp ) ; +1906: do { +1907: ACTIONRECORD Action ; +1908: } while ( Action . ActionCode != 0x0 ) ; +1909: break ; +1910: case 34 : +1911: ushort ButtonId ; +1912: ubyte ReservedFlags : 7 ; +1913: ubyte TrackAsMenu : 1 ; +1914: local quad off_end = FTell ( ) ; +1915: ushort ActionOffset ; +1916: ubyte TODO [ SWFTagEnd - FTell ( ) ] ; +1917: break ; +1918: while ( FTell ( ) < ( off_end + ActionOffset ) ) { +1919: BUTTONRECORD Character ; +1920: } +1921: do { +1922: BUTTONCONDACTION Action ; +1923: } while ( ( SWFTagEnd - FTell ( ) ) > 1 ) ; +1924: break ; +1925: case 23 : +1926: ushort ButtonId ; +1927: CXFORM ButtonColorTransform ; +1928: break ; +1929: case 17 : +1930: ushort ButtonId ; +1931: ushort ButtonSoundChar0 ; +1932: if ( ButtonSoundChar0 ) { +1933: SOUNDINFO ButtonSoundInfo0 ; +1934: } +1935: ushort ButtonSoundChar1 ; +1936: if ( ButtonSoundChar1 ) { +1937: SOUNDINFO ButtonSoundInfo1 ; +1938: } +1939: ushort ButtonSoundChar2 ; +1940: if ( ButtonSoundChar2 ) { +1941: SOUNDINFO ButtonSoundInfo2 ; +1942: } +1943: ushort ButtonSoundChar3 ; +1944: if ( ButtonSoundChar3 ) { +1945: SOUNDINFO ButtonSoundInfo3 ; +1946: } +1947: break ; +1948: +1949: +1950: +1951: +1952: +1953: case 39 : +1954: ushort SpriteID ; +1955: ushort FrameCount ; +1956: ubyte Data [ SWFTagEnd - FTell ( ) ] ; +1957: break ; +1958: +1959: +1960: +1961: +1962: +1963: case 60 : +1964: ushort CharacterID ; +1965: ushort NumFrames ; +1966: ushort Width ; +1967: ushort Height ; +1968: ubyte VideoFlagsReserved : 4 ; +1969: ubyte VideoFlagsDeblocking : 3 ; +1970: ubyte VideoFlagsSmoothing : 1 ; +1971: ubyte CodecID ; +1972: break ; +1973: case 61 : +1974: ushort StreamID ; +1975: ushort FrameNum ; +1976: ubyte VideoData [ SWFTagEnd - FTell ( ) ] ; +1977: break ; +1978: +1979: +1980: +1981: +1982: +1983: case 87 : +1984: ushort Tag ; +1985: uint Reserved ; +1986: ubyte Data [ SWFTagEnd - FTell ( ) ] ; +1987: break ; +1988: +1989: +1990: +1991: +1992: +1993: case 41 : +1994: if ( ( SWFTagEnd - FTell ( ) ) > 0 ) { +1995: ubyte Data [ SWFTagEnd - FTell ( ) ] ; +1996: } +1997: break ; +1998: case 63 : +1999: if ( ( SWFTagEnd - FTell ( ) ) > 0 ) { +2000: ubyte Data [ SWFTagEnd - FTell ( ) ] ; +2001: } +2002: break ; +2003: case 253 : +2004: if ( ( SWFTagEnd - FTell ( ) ) > 0 ) { +2005: ubyte Data [ SWFTagEnd - FTell ( ) ] ; +2006: } +2007: break ; +2008: default : +2009: if ( ( SWFTagEnd - FTell ( ) ) > 0 ) { +2010: ubyte Data [ SWFTagEnd - FTell ( ) ] ; +2011: } +2012: break ; +2013: } +2014: +2015: if ( ( SWFTagEnd - FTell ( ) ) > 0 ) { +2016: ubyte Padding [ SWFTagEnd - FTell ( ) ] ; +2017: if ( Header . TagType != 83 ) { +2018: Printf ( "PADDING: Tag padded to 0x%LXh\n" , FTell ( ) ) ; +2019: } +2020: } +2021: else if ( ( SWFTagEnd - FTell ( ) ) < 0 ) { +2022: if ( Header . TagType != 48 ) { +2023: Printf ( "TAG OVERRUN: Expected next tag at 0x%LXh\n" , SWFTagEnd ) ; +2024: } +2025: } +2026: +2027: } SWFTAG < read = GetTagType > ; +2028: +2029: string GetTagType ( SWFTAG & Tag ) +2030: { +2031: string result ; +2032: ubyte TagType = Tag . Header . TagType ; +2033: +2034: switch ( TagType ) { +2035: +2036: +2037: +2038: case 59 : return "DoInitAction" ; +2039: case 12 : return "DoAction" ; +2040: case 82 : return "DoABC" ; +2041: +2042: +2043: +2044: +2045: case 4 : return "PlaceObject" ; +2046: case 26 : return "PlaceObject2" ; +2047: case 70 : return "PlaceObject3" ; +2048: case 5 : return "RemoveObject" ; +2049: case 28 : return "RemoveObject2" ; +2050: case 1 : return "ShowFrame" ; +2051: +2052: +2053: +2054: +2055: case 9 : return "SetBackgroundColor" ; +2056: case 43 : return "FrameLabel" ; +2057: case 24 : return "Protect" ; +2058: case 0 : return "End" ; +2059: case 56 : return "ExportAssets" ; +2060: case 57 : return "ImportAssets" ; +2061: case 58 : return "EnableDebugger" ; +2062: case 64 : return "EnableDebugger2" ; +2063: case 65 : return "ScriptLimits" ; +2064: case 66 : return "SetTabIndex" ; +2065: case 69 : return "FileAttributes" ; +2066: case 71 : return "ImportAsset2" ; +2067: case 76 : return "SymbolClass" ; +2068: case 77 : return "Metadata" ; +2069: case 78 : return "DefineScalingGrid" ; +2070: case 86 : return "DefineSceneAndFrameLabelData" ; +2071: +2072: +2073: +2074: +2075: case 2 : return "DefineShape" ; +2076: case 22 : return "DefineShape2" ; +2077: case 32 : return "DefineShape3" ; +2078: case 83 : return "DefineShape4" ; +2079: +2080: +2081: +2082: +2083: case 6 : return "DefineBits" ; +2084: case 8 : return "JPEGTables" ; +2085: case 21 : return "DefineBitsJPEG2" ; +2086: case 35 : return "DefineBitsJPEG3" ; +2087: case 20 : return "DefineBitsLossless" ; +2088: case 36 : return "DefineBitsLossless2" ; +2089: +2090: +2091: +2092: +2093: case 46 : return "DefineMorphShape" ; +2094: case 84 : return "DefineMorphShape2" ; +2095: +2096: +2097: +2098: +2099: case 10 : return "DefineFont" ; +2100: case 13 : return "DefineFontInfo" ; +2101: case 62 : return "DefineFontInfo2" ; +2102: case 48 : return "DefineFont2" ; +2103: case 75 : return "DefineFont3" ; +2104: case 73 : return "DefineFontAlignZones" ; +2105: case 88 : return "DefineFontName" ; +2106: case 11 : return "DefineText" ; +2107: case 33 : return "DefineText2" ; +2108: case 37 : return "DefineEditText" ; +2109: case 74 : return "CSMTextSettings" ; +2110: +2111: +2112: +2113: +2114: case 14 : return "DefineSound" ; +2115: case 15 : return "StartSound" ; +2116: case 89 : return "StartSound2" ; +2117: case 18 : return "SoundStreamHead" ; +2118: case 45 : return "SoundStreamHead2" ; +2119: case 19 : return "SoundStreamBlock" ; +2120: +2121: +2122: +2123: +2124: case 7 : return "DefineButton" ; +2125: case 34 : return "DefineButton2" ; +2126: case 23 : return "DefineButtonCxform" ; +2127: case 17 : return "DefineButtonSound" ; +2128: +2129: +2130: +2131: +2132: case 39 : return "DefineSprite" ; +2133: +2134: +2135: +2136: +2137: case 60 : return "DefineVideoSteam" ; +2138: case 61 : return "VideoFrame" ; +2139: +2140: +2141: +2142: +2143: case 87 : return "DefineBinaryData" ; +2144: +2145: +2146: +2147: +2148: case 41 : return "Serial Number" ; +2149: case 63 : return "MX4" ; +2150: case 253 : return "Amayeta Encrypt" ; +2151: +2152: default : return "\0" ; +2153: } +2154: return "\0" ; +2155: } +2156: +2157: +2158: +2159: +2160: +2161: +2162: +2163: +2164: +2165: +2166: BitfieldLeftToRight ( ) ; +2167: +2168: typedef struct { +2169: SetBackColor ( cLtGray ) ; +2170: uchar Signature [ 3 ] ; +2171: uchar Version ; +2172: +2173: if ( Signature [ 0 ] == 'F' && Signature [ 1 ] == 'W' && Signature [ 2 ] == 'S' ) +2174: { +2175: uint FileLength ; +2176: RECT Rect ; +2177: BigEndian ( ) ; +2178: ushort FrameRate ; +2179: LittleEndian ( ) ; +2180: ushort FrameCount ; +2181: } +2182: else if ( Signature [ 0 ] == 'C' && Signature [ 1 ] == 'W' && Signature [ 2 ] == 'S' ) +2183: { +2184: Printf ( "This is a SWF compressed file\n" ) ; +2185: isCompressed = 1 ; +2186: uint UncompressedSize ; +2187: byte ZlibData [ FileSize ( ) - FTell ( ) ] ; +2188: } +2189: } SWFHEADER ; +2190: +2191: typedef struct { +2192: SWFHEADER Header ; +2193: if ( 0 == isCompressed ) +2194: { +2195: do { +2196: SWFTAG Tag ; +2197: } while ( ! FEof ( ) ) ; +2198: } +2199: } SWF ; +2200: +2201: +2202: +2203: +2204: +2205: SWF File ; +2206: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/SinclairMicrodriveImage.bt b/cparser/tests/exp_lex/SinclairMicrodriveImage.bt new file mode 100644 index 0000000..c262f23 --- /dev/null +++ b/cparser/tests/exp_lex/SinclairMicrodriveImage.bt @@ -0,0 +1,34 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: struct { +13: ubyte HDFLAG [ 1 ] ; +14: +15: ubyte HDNUMB [ 1 ] ; +16: ubyte UNUSED [ 2 ] ; +17: ubyte HDNAME [ 10 ] ; +18: ubyte HDCHK [ 1 ] ; +19: +20: ubyte RECFLG [ 1 ] ; +21: +22: +23: +24: +25: ubyte RECNUM [ 1 ] ; +26: ubyte RECLEN [ 2 ] ; +27: ubyte RECNAM [ 10 ] ; +28: ubyte DESCHK [ 1 ] ; +29: ubyte CHDATA [ 512 ] ; +30: ubyte DCHK [ 1 ] ; +31: +32: } MicrodriveSector [ 254 ] ; +33: ubyte WriteProtectionFlag [ 1 ] ; +34: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/TGATemplate.bt b/cparser/tests/exp_lex/TGATemplate.bt new file mode 100644 index 0000000..3dfd9a4 --- /dev/null +++ b/cparser/tests/exp_lex/TGATemplate.bt @@ -0,0 +1,159 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +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 < read = ReadImageSpecification > ; +26: +27: typedef struct { +28: UBYTE IDLength ; +29: UBYTE ColorMapType ; +30: UBYTE ImageType ; +31: COLORMAPSPECIFICATION CMSpecification ; +32: IMAGESPECIFICATION ISpecification ; +33: } TGAFILEHEADER < read = ReadTGAHeader > ; +34: +35: typedef struct { +36: DWORD B : 5 ; +37: DWORD G : 5 ; +38: DWORD R : 5 ; +39: } RGB555 < read = ReadRGB555 > ; +40: +41: typedef struct { +42: DWORD B : 5 ; +43: DWORD G : 5 ; +44: DWORD R : 5 ; +45: DWORD X : 1 ; +46: } XRGB1555 < read = ReadXRGB1555 > ; +47: +48: typedef struct { +49: UBYTE B ; +50: UBYTE G ; +51: UBYTE R ; +52: } RGB888 < read = ReadRGB888 > ; +53: +54: typedef struct { +55: UBYTE B ; +56: UBYTE G ; +57: UBYTE R ; +58: UBYTE A ; +59: } ARGB8888 < read = ReadARGB8888 > ; +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: +117: TGAFILEHEADER TGAfh ; +118: +119: +120: if ( TGAfh . IDLength != 0 ) +121: UBYTE ImageID [ TGAfh . IDLength ] ; +122: +123: SetBackColor ( cSilver ) ; +124: +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 ] < optimize = true > ; +159: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/TIFTemplate.bt b/cparser/tests/exp_lex/TIFTemplate.bt new file mode 100644 index 0000000..f187362 --- /dev/null +++ b/cparser/tests/exp_lex/TIFTemplate.bt @@ -0,0 +1,1114 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: +21: +22: +23: +24: +25: +26: +27: +28: +29: +30: +31: +32: local uint16 tbom ; +33: tbom = ReadUShort ( 0 ) ; +34: if ( tbom == 0x4949 ) { +35: LittleEndian ( ) ; +36: } +37: else if ( tbom == 0x4D4D ) { +38: BigEndian ( ) ; +39: } +40: else { +41: Warning ( "Invalid TIFF File: Bad BOM (Byte Order Mark). Template Terminated." ) ; +42: return - 1 ; +43: } +44: +45: local quad nextIFD = 0 ; +46: +47: +48: +49: typedef enum < uint16 > eTAG { +50: GPSVersionID = 0 , GPSLatitudeRef , GPSLatitude , GPSLongitudeRef , GPSLongitude , GPSAltitudeRef , GPSAltitude , GPSTimeStamp , GPSSatellites , GPSStatus , GPSMeasureMode , GPSDOP , GPSSpeedRef , GPSSpeed , GPSTrackRef , GPSTrack , GPSImgDirectionRef , GPSImgDirection , GPSMapDatum , GPSDestLatitudeRef , GPSDestLatitude , GPSDestLongitudeRef , GPSDestLongitude , GPSDestBearingRef , GPSDestBearing , GPSDestDistanceRef , GPSDestDistance , GPSProcessingMethod , GPSAreaInformation , GPSDateStamp , GPSDifferential , +51: NewSubFileType = 254 , SubFileType , ImageWidth , ImageLength , BitsPerSample , Compression , +52: PhotometricInterpretation = 262 , Thresholding , CellWidth , CellLength , FillOrder , +53: DocumentName = 269 , ImageDescription , Make , Model , StripOffsets , Orientation , +54: SamplesPerPixel = 277 , RowsPerStrip , StripByteCounts , MinSampleValue , MaxSampleValue , XResolution , YResolution , PlanarConfiguration , PageName , XPosition , YPosition , FreeOffsets , FreeByteCounts , GrayResponseUnit , GrayResponseCurve , Group3Options , Group4Options , +55: ResolutionUnit = 296 , PageNumber , +56: ColorResponseUnit = 300 , TransferFunction , +57: Software = 305 , DateTime , +58: Artist = 315 , HostComputer , Predictor , WhitePoint , PrimaryChromacities , ColorMap , HalftoneHints , TileWidth , TileLength , TileOffsets , TileByteCounts , BadFaxLines , CleanFaxData , ConsecutiveBadFaxLines , +59: SubIFDs = 330 , +60: InkSet = 332 , InkNames , NumberOfInks , +61: DotRange = 336 , TargetPrinter , ExtraSamples , SampleFormat , SMinSampleValue , SMaxSampleValue , TransferRange , ClipPath , XClipPathUnits , YClipPathUnits , Indexed , JPEGTables , +62: OPIProxy = 351 , +63: GlobalParametersIFD = 400 , ProfileType , FaxProfile , CodingMethods , VersionYear , ModeNumber , +64: JPEGProc = 512 , JPEGInterchangeFormat , JPEGInterchangeFormatLength , JPEGRestartInterval , +65: JPEGLosslessPredictors = 517 , JPEGPointTransforms , JPEGQTables , JPEGDCTables , JPEGACTables , +66: YCbCrCoefficients = 529 , YCbCrSubsampling , YCbCrPositioning , ReferenceBlackWhite , +67: XMP = 700 , +68: ImageID = 32781 , +69: Wang_Annotation = 32932 , +70: Matteing = 32995 , DataType , ImageDepth , TileDepth , +71: CFARepeatPatternDim = 33421 , CFAPattern , BatteryLevel , +72: Copyright = 33432 , +73: ExposureTime = 33434 , +74: FNumber = 33437 , +75: ModelPixelScaleTag = 33550 , +76: IPTC_NAA = 33723 , +77: INGR_Packet_Data_Tag = 33918 , INGR_Flag_Registers , IntergraphMatrixTag , +78: ModelTiepointTag = 33922 , +79: Site = 34016 , ColorSequence , IT8Header , RasterPadding , BitsPerRunLength , BitsPerExtendedRunLength , ColorTable , ImageColorIndicator , BackgroundColorIndicator , ImageColorValue , BackgroundColorValue , PixelInensityRange , TransparencyIndicator , ColorCharacterization , HCUsage , +80: ModelTransformationTag = 34264 , +81: PhotoshopImageResources = 34377 , +82: ExifIFD = 34665 , +83: InterColourProfile = 34675 , +84: GeoKeyDirectoryTag = 34735 , GeoDoubleParamsTag , GeoAsciiParamsTag , +85: ExposureProgram = 34850 , +86: SpectralSensitibity = 34852 , GPSInfo , +87: ISOSpeedRatings = 34855 , OECF , Interlace , TimeZoneOffset , SelfTimerMode , +88: FaxRecvParams = 34908 , FaxSubAddress , FaxRecvTime , +89: ExifVersion = 36864 , +90: DateTimeOriginal = 36867 , DateTimeDigitized , +91: ComponentsConfiguration = 37121 , CompressedBitsPerPixel , +92: ShutterSpeedValue = 37377 , ApertureValue , BrightnessValue , ExposureBiasValue , MaxApertureValue , SubjectDistance , MeteringMode , LightSource , Flash , FocalLength , FlashEnergy , SpatialFrequencyResponse , Noise , FocalPlaneXResolution , FocalPlaneYResolution , FocalPlaneResolutionUnit , ImageNumber , SecurityClassification , ImageHistory , SubjectArea , ExposureIndex , TIFF_EPStandardID , SensingMethod , +93: StoNits = 37439 , +94: MakerNote = 37500 , +95: UserComment = 37510 , +96: SubSecTime = 37520 , SubSecTimeOriginal , SubSecTimeDigitized , +97: ImageSourceData = 37724 , +98: MSFax_CSID = 40001 , MSFax_TSID , MSFax_Device , MSFax_RoutingInfo , MSFax_CallerID , MSFax_RecipientName , MSFax_RecipientFaxNumber , MSFax_RecipientCompany , MSFax_RecipientAddress , MSFax_RecipientStreet , MSFax_RecipientCity , MSFax_RecipientZipCode , MSFax_RecipientCountry , MSFax_RecipientTitle , MSFax_RecipientDepartment , MSFax_RecipientOffice , MSFax_RecipientOfficePhone , MSFax_RecipientHomePhone , MSFax_Recipient40019 , MSFax_RecipientEmail , MSFax_SenderName , MSFax_SenderFaxNumber , MSFax_SenderCompany , MSFax_SenderAddress , MSFax_SenderStreet , MSFax_SenderCity , MSFax_SenderZipCode , MSFax_SenderCountry , MSFax_SenderTitle , MSFax_SenderDepartment , MSFax_SenderOffice , MSFax_SenderOfficePhone , MSFax_SenderHomePhone , MSFax_Sender40034 , MSFax_SenderEmail , MSFax_BillingCode , MSFax_UserName , MSFax_40038 , MSFax_Document , MSFax_CoverPageSubject , MSFax_Retries , MSFax_Priority , MSFax_ParentJobID , MSFax_SubmissionTime , MSFax_Scheduled , MSFax_TotalPages , MSFax_Type , MSFax_40048 , MSFax_ErrorCode , MSFax_40050 , MSFax_StartTime , MSFax_EndTime , MSFax_40053 , +99: FlashpixVersion = 40960 , ColorSpace , PixelXDimension , PixelYDimension , RelatedSoundFile , InteroperabilityIFD , +100: FlashEnergy_Exif = 41483 , SpatialFrequencyResponse_Exif , +101: FocalPlaneXResolution_Exif = 41486 , FocalPlaneYResolution_Exif , FocalPlaneResolutionUnit_Exif , +102: SubjectLocation_Exif = 41492 , ExposureIndex_Exif , +103: SensingMethod_Exif = 41495 , +104: FileSource = 41728 , SceneType , CFAPattern_Exif , +105: CustomRendered = 41985 , ExposureMode , WhiteBalance , DigitalZoomRatio , FocalLengthIn35mmFilm , SceneCaptureType , GainControl , Contrast , Saturation , Sharpness , DeviceSettingDescription , SubjectDistanceRange , +106: GDAL_METADATA = 42112 , GDAL_NODATA , +107: Oce_Scanjob_Description = 50215 , Oce_Application_Selector , Oce_Identification_Number , Oce_ImageLogic_Characteristics , +108: PhotoshopAnnotations = 50255 , +109: DNGVersion = 50706 , DNGBackwardVersion , UniqueCameraModel , LocalizedCameraModel , CFAPlaneColor , CFALayout , LinearizationTable , BlackLevelRepeatDim , BlackLevel , BlackLevelDeltaH , BlackLevelDeltaV , WhiteLevel , DefaultScale , DefaultCropOrigin , DefaultCropSize , ColorMatrix1 , ColorMatrix2 , CameraCalibration1 , CameraCalibration2 , ReductionMatrix1 , ReductionMatrix2 , AnalogBalnace , AsShortNeutral , AsShortWhiteXY , BaselineExposure , BaselineNoise , BaselineSharpness , BayerGreenSplit , LinearResponseLimit , CameraSerialNumber , LensInfo , ChromaBlurRadius , AntiAliasStrength , +110: DNGPrivateDatea = 50740 , MakerNoteSafety , +111: CalibrationIlluminant1 = 50778 , CalibrationIlluminant2 , BestQualityScale , +112: Alias_Layer_Metadata = 50784 +113: } TAG ; +114: +115: +116: typedef enum < uint16 > eTAGTYPE { +117: eBYTE = 1 , eASCII , eSHORT , eLONG , eRATIONAL , +118: eSBYTE , eUNDEF , eSSHORT , eSLONG , eSRATIONAL , +119: eFLOAT , eDOUBLE +120: } TAGTYPE ; +121: +122: +123: typedef enum < uint16 > eCOMP { +124: Uncompressed = 1 , CCITT_1D , Group3Fax , Group4Fax , LZW , JPEG , JPEG2 , +125: Deflate = 8 , +126: NeXT2Bit = 32766 , CCITT_RLE = 32771 , PackBits = 32773 , +127: ThunderScan4bit = 32809 , cRasterPadding = 32895 , +128: RLEforLW = 32896 , RLEforHC , RLEforBL , +129: Pixar10bitLZW = 32908 , PixarCompanded11bitZIP , +130: PKZIP_Deflate = 32946 , +131: Kodak_DCS = 32947 , +132: JBIG = 34661 , +133: SGI32LogLum = 34676 , +134: SIG24LogLum = 34677 , +135: JPEG_2000 = 34712 +136: } COMP ; +137: +138: +139: typedef enum < uint16 > ePHOTO { +140: WhiteIsZero , BlackIsZero , RGB , RGB_Palette , Transparency_Mask , CMYK , YCbCr , +141: CIELab = 8 , ICCLab , ITULab , CFA = 32803 , CIELog2L = 32844 , CIELog2Luv , LinearRaw = 34892 +142: } PHOTO ; +143: +144: +145: typedef enum < uint16 > eRES { +146: None = 1 , Inch , Centimeter +147: } RES ; +148: +149: +150: typedef enum < uint16 > eKEYGeoTiff { +151: undefinedGeoKey = 1 , +152: +153: +154: +155: +156: +157: +158: +159: +160: GTModelTypeGeoKey = 1024 , +161: GTRasterTypeGeoKey = 1025 , +162: GTCitationGeoKey = 1026 , +163: +164: +165: +166: GeographicTypeGeoKey = 2048 , +167: GeogCitationGeoKey = 2049 , +168: GeogGeodeticDatumGeoKey = 2050 , +169: GeogPrimeMeridianGeoKey = 2051 , +170: GeogLinearUnitsGeoKey = 2052 , +171: GeogLinearUnitSizeGeoKey = 2053 , +172: GeogAngularUnitsGeoKey = 2054 , +173: GeogAngularUnitSizeGeoKey = 2055 , +174: GeogEllipsoidGeoKey = 2056 , +175: GeogSemiMajorAxisGeoKey = 2057 , +176: GeogSemiMinorAxisGeoKey = 2058 , +177: GeogInvFlatteningGeoKey = 2059 , +178: GeogAzimuthUnitsGeoKey = 2060 , +179: GeogPrimeMeridianLongGeoKey = 2061 , +180: GeogTOWGS84GeoKey = 2062 , +181: +182: +183: +184: +185: +186: ProjectedCSTypeGeoKey = 3072 , +187: PCSCitationGeoKey = 3073 , +188: ProjectionGeoKey = 3074 , +189: ProjCoordTransGeoKey = 3075 , +190: ProjLinearUnitsGeoKey = 3076 , +191: ProjLinearUnitSizeGeoKey = 3077 , +192: ProjStdParallel1GeoKey = 3078 , +193: +194: ProjStdParallel2GeoKey = 3079 , +195: ProjNatOriginLongGeoKey = 3080 , +196: +197: ProjNatOriginLatGeoKey = 3081 , +198: +199: ProjFalseEastingGeoKey = 3082 , +200: ProjFalseNorthingGeoKey = 3083 , +201: ProjFalseOriginLongGeoKey = 3084 , +202: ProjFalseOriginLatGeoKey = 3085 , +203: ProjFalseOriginEastingGeoKey = 3086 , +204: ProjFalseOriginNorthingGeoKey = 3087 , +205: ProjCenterLongGeoKey = 3088 , +206: ProjCenterLatGeoKey = 3089 , +207: ProjCenterEastingGeoKey = 3090 , +208: ProjCenterNorthingGeoKey = 3091 , +209: ProjScaleAtNatOriginGeoKey = 3092 , +210: +211: ProjScaleAtCenterGeoKey = 3093 , +212: ProjAzimuthAngleGeoKey = 3094 , +213: ProjStraightVertPoleLongGeoKey = 3095 , +214: ProjRectifiedGridAngleGeoKey = 3096 , +215: +216: +217: +218: VerticalCSTypeGeoKey = 4096 , +219: VerticalCitationGeoKey = 4097 , +220: VerticalDatumGeoKey = 4098 , +221: VerticalUnitsGeoKey = 4099 , +222: +223: +224: +225: userDefinedGeoKey = 32767 +226: } GeoKEYlabel ; +227: +228: +229: +230: +231: +232: +233: +234: typedef enum < short > { +235: ModelTypeProjected = 1 , +236: ModelTypeGeographic = 2 , +237: ModelTypeGeocentric = 3 , +238: +239: +240: +241: } modeltype_t ; +242: +243: +244: typedef enum < short > { +245: RasterPixelIsArea = 1 , +246: RasterPixelIsPoint = 2 +247: } rastertype_t ; +248: +249: +250: typedef enum < short > { +251: Linear_Meter = 9001 , +252: Linear_Foot = 9002 , +253: Linear_Foot_US_Survey = 9003 , +254: Linear_Foot_Modified_American = 9004 , +255: Linear_Foot_Clarke = 9005 , +256: Linear_Foot_Indian = 9006 , +257: Linear_Link = 9007 , +258: Linear_Link_Benoit = 9008 , +259: Linear_Link_Sears = 9009 , +260: Linear_Chain_Benoit = 9010 , +261: Linear_Chain_Sears = 9011 , +262: Linear_Yard_Sears = 9012 , +263: Linear_Yard_Indian = 9013 , +264: Linear_Fathom = 9014 , +265: Linear_Mile_International_Nautical = 9015 +266: } LinearUnitCode_t ; +267: +268: +269: typedef enum < short > { +270: Angular_Radian = 9101 , +271: Angular_Degree = 9102 , +272: Angular_Arc_Minute = 9103 , +273: Angular_Arc_Second = 9104 , +274: Angular_Grad = 9105 , +275: Angular_Gon = 9106 , +276: Angular_DMS = 9107 , +277: Angular_DMS_Hemisphere = 9108 +278: } AngularUnitCode_t ; +279: +280: +281: +282: typedef enum < short > { +283: GCS_Adindan = 4201 , +284: GCS_AGD66 = 4202 , +285: GCS_AGD84 = 4203 , +286: GCS_Ain_el_Abd = 4204 , +287: GCS_Afgooye = 4205 , +288: GCS_Agadez = 4206 , +289: GCS_Lisbon = 4207 , +290: GCS_Aratu = 4208 , +291: GCS_Arc_1950 = 4209 , +292: GCS_Arc_1960 = 4210 , +293: GCS_Batavia = 4211 , +294: GCS_Barbados = 4212 , +295: GCS_Beduaram = 4213 , +296: GCS_Beijing_1954 = 4214 , +297: GCS_Belge_1950 = 4215 , +298: GCS_Bermuda_1957 = 4216 , +299: GCS_Bern_1898 = 4217 , +300: GCS_Bogota = 4218 , +301: GCS_Bukit_Rimpah = 4219 , +302: GCS_Camacupa = 4220 , +303: GCS_Campo_Inchauspe = 4221 , +304: GCS_Cape = 4222 , +305: GCS_Carthage = 4223 , +306: GCS_Chua = 4224 , +307: GCS_Corrego_Alegre = 4225 , +308: GCS_Cote_d_Ivoire = 4226 , +309: GCS_Deir_ez_Zor = 4227 , +310: GCS_Douala = 4228 , +311: GCS_Egypt_1907 = 4229 , +312: GCS_ED50 = 4230 , +313: GCS_ED87 = 4231 , +314: GCS_Fahud = 4232 , +315: GCS_Gandajika_1970 = 4233 , +316: GCS_Garoua = 4234 , +317: GCS_Guyane_Francaise = 4235 , +318: GCS_Hu_Tzu_Shan = 4236 , +319: GCS_HD72 = 4237 , +320: GCS_ID74 = 4238 , +321: GCS_Indian_1954 = 4239 , +322: GCS_Indian_1975 = 4240 , +323: GCS_Jamaica_1875 = 4241 , +324: GCS_JAD69 = 4242 , +325: GCS_Kalianpur = 4243 , +326: GCS_Kandawala = 4244 , +327: GCS_Kertau = 4245 , +328: GCS_KOC = 4246 , +329: GCS_La_Canoa = 4247 , +330: GCS_PSAD56 = 4248 , +331: GCS_Lake = 4249 , +332: GCS_Leigon = 4250 , +333: GCS_Liberia_1964 = 4251 , +334: GCS_Lome = 4252 , +335: GCS_Luzon_1911 = 4253 , +336: GCS_Hito_XVIII_1963 = 4254 , +337: GCS_Herat_North = 4255 , +338: GCS_Mahe_1971 = 4256 , +339: GCS_Makassar = 4257 , +340: GCS_EUREF89 = 4258 , +341: GCS_Malongo_1987 = 4259 , +342: GCS_Manoca = 4260 , +343: GCS_Merchich = 4261 , +344: GCS_Massawa = 4262 , +345: GCS_Minna = 4263 , +346: GCS_Mhast = 4264 , +347: GCS_Monte_Mario = 4265 , +348: GCS_M_poraloko = 4266 , +349: GCS_NAD27 = 4267 , +350: GCS_NAD_Michigan = 4268 , +351: GCS_NAD83 = 4269 , +352: GCS_Nahrwan_1967 = 4270 , +353: GCS_Naparima_1972 = 4271 , +354: GCS_GD49 = 4272 , +355: GCS_NGO_1948 = 4273 , +356: GCS_Datum_73 = 4274 , +357: GCS_NTF = 4275 , +358: GCS_NSWC_9Z_2 = 4276 , +359: GCS_OSGB_1936 = 4277 , +360: GCS_OSGB70 = 4278 , +361: GCS_OS_SN80 = 4279 , +362: GCS_Padang = 4280 , +363: GCS_Palestine_1923 = 4281 , +364: GCS_Pointe_Noire = 4282 , +365: GCS_GDA94 = 4283 , +366: GCS_Pulkovo_1942 = 4284 , +367: GCS_Qatar = 4285 , +368: GCS_Qatar_1948 = 4286 , +369: GCS_Qornoq = 4287 , +370: GCS_Loma_Quintana = 4288 , +371: GCS_Amersfoort = 4289 , +372: GCS_RT38 = 4290 , +373: GCS_SAD69 = 4291 , +374: GCS_Sapper_Hill_1943 = 4292 , +375: GCS_Schwarzeck = 4293 , +376: GCS_Segora = 4294 , +377: GCS_Serindung = 4295 , +378: GCS_Sudan = 4296 , +379: GCS_Tananarive = 4297 , +380: GCS_Timbalai_1948 = 4298 , +381: GCS_TM65 = 4299 , +382: GCS_TM75 = 4300 , +383: GCS_Tokyo = 4301 , +384: GCS_Trinidad_1903 = 4302 , +385: GCS_TC_1948 = 4303 , +386: GCS_Voirol_1875 = 4304 , +387: GCS_Voirol_Unifie = 4305 , +388: GCS_Bern_1938 = 4306 , +389: GCS_Nord_Sahara_1959 = 4307 , +390: GCS_Stockholm_1938 = 4308 , +391: GCS_Yacare = 4309 , +392: GCS_Yoff = 4310 , +393: GCS_Zanderij = 4311 , +394: GCS_MGI = 4312 , +395: GCS_Belge_1972 = 4313 , +396: GCS_DHDN = 4314 , +397: GCS_Conakry_1905 = 4315 , +398: GCS_WGS_72 = 4322 , +399: GCS_WGS_72BE = 4324 , +400: GCS_WGS_84 = 4326 , +401: GCS_Bern_1898_Bern = 4801 , +402: GCS_Bogota_Bogota = 4802 , +403: GCS_Lisbon_Lisbon = 4803 , +404: GCS_Makassar_Jakarta = 4804 , +405: GCS_MGI_Ferro = 4805 , +406: GCS_Monte_Mario_Rome = 4806 , +407: GCS_NTF_Paris = 4807 , +408: GCS_Padang_Jakarta = 4808 , +409: GCS_Belge_1950_Brussels = 4809 , +410: GCS_Tananarive_Paris = 4810 , +411: GCS_Voirol_1875_Paris = 4811 , +412: GCS_Voirol_Unifie_Paris = 4812 , +413: GCS_Batavia_Jakarta = 4813 , +414: GCS_ATF_Paris = 4901 , +415: GCS_NDG_Paris = 4902 , +416: GCSE_Airy1830 = 4001 , +417: GCSE_AiryModified1849 = 4002 , +418: GCSE_AustralianNationalSpheroid = 4003 , +419: GCSE_Bessel1841 = 4004 , +420: GCSE_BesselModified = 4005 , +421: GCSE_BesselNamibia = 4006 , +422: GCSE_Clarke1858 = 4007 , +423: GCSE_Clarke1866 = 4008 , +424: GCSE_Clarke1866Michigan = 4009 , +425: GCSE_Clarke1880_Benoit = 4010 , +426: GCSE_Clarke1880_IGN = 4011 , +427: GCSE_Clarke1880_RGS = 4012 , +428: GCSE_Clarke1880_Arc = 4013 , +429: GCSE_Clarke1880_SGA1922 = 4014 , +430: GCSE_Everest1830_1937Adjustment = 4015 , +431: GCSE_Everest1830_1967Definition = 4016 , +432: GCSE_Everest1830_1975Definition = 4017 , +433: GCSE_Everest1830Modified = 4018 , +434: GCSE_GRS1980 = 4019 , +435: GCSE_Helmert1906 = 4020 , +436: GCSE_IndonesianNationalSpheroid = 4021 , +437: GCSE_International1924 = 4022 , +438: GCSE_International1967 = 4023 , +439: GCSE_Krassowsky1940 = 4024 , +440: GCSE_NWL9D = 4025 , +441: GCSE_NWL10D = 4026 , +442: GCSE_Plessis1817 = 4027 , +443: GCSE_Struve1860 = 4028 , +444: GCSE_WarOffice = 4029 , +445: GCSE_WGS84 = 4030 , +446: GCSE_GEM10C = 4031 , +447: GCSE_OSU86F = 4032 , +448: GCSE_OSU91A = 4033 , +449: GCSE_Clarke1880 = 4034 , +450: GCSE_Sphere = 4035 +451: } GCSCode_t ; +452: +453: +454: +455: +456: typedef enum < short > { +457: Datum_Adindan = 6201 , +458: Datum_Australian_Geodetic_Datum_1966 = 6202 , +459: Datum_Australian_Geodetic_Datum_1984 = 6203 , +460: Datum_Ain_el_Abd_1970 = 6204 , +461: Datum_Afgooye = 6205 , +462: Datum_Agadez = 6206 , +463: Datum_Lisbon = 6207 , +464: Datum_Aratu = 6208 , +465: Datum_Arc_1950 = 6209 , +466: Datum_Arc_1960 = 6210 , +467: Datum_Batavia = 6211 , +468: Datum_Barbados = 6212 , +469: Datum_Beduaram = 6213 , +470: Datum_Beijing_1954 = 6214 , +471: Datum_Reseau_National_Belge_1950 = 6215 , +472: Datum_Bermuda_1957 = 6216 , +473: Datum_Bern_1898 = 6217 , +474: Datum_Bogota = 6218 , +475: Datum_Bukit_Rimpah = 6219 , +476: Datum_Camacupa = 6220 , +477: Datum_Campo_Inchauspe = 6221 , +478: Datum_Cape = 6222 , +479: Datum_Carthage = 6223 , +480: Datum_Chua = 6224 , +481: Datum_Corrego_Alegre = 6225 , +482: Datum_Cote_d_Ivoire = 6226 , +483: Datum_Deir_ez_Zor = 6227 , +484: Datum_Douala = 6228 , +485: Datum_Egypt_1907 = 6229 , +486: Datum_European_Datum_1950 = 6230 , +487: Datum_European_Datum_1987 = 6231 , +488: Datum_Fahud = 6232 , +489: Datum_Gandajika_1970 = 6233 , +490: Datum_Garoua = 6234 , +491: Datum_Guyane_Francaise = 6235 , +492: Datum_Hu_Tzu_Shan = 6236 , +493: Datum_Hungarian_Datum_1972 = 6237 , +494: Datum_Indonesian_Datum_1974 = 6238 , +495: Datum_Indian_1954 = 6239 , +496: Datum_Indian_1975 = 6240 , +497: Datum_Jamaica_1875 = 6241 , +498: Datum_Jamaica_1969 = 6242 , +499: Datum_Kalianpur = 6243 , +500: Datum_Kandawala = 6244 , +501: Datum_Kertau = 6245 , +502: Datum_Kuwait_Oil_Company = 6246 , +503: Datum_La_Canoa = 6247 , +504: Datum_Provisional_S_American_Datum_1956 = 6248 , +505: Datum_Lake = 6249 , +506: Datum_Leigon = 6250 , +507: Datum_Liberia_1964 = 6251 , +508: Datum_Lome = 6252 , +509: Datum_Luzon_1911 = 6253 , +510: Datum_Hito_XVIII_1963 = 6254 , +511: Datum_Herat_North = 6255 , +512: Datum_Mahe_1971 = 6256 , +513: Datum_Makassar = 6257 , +514: Datum_European_Reference_System_1989 = 6258 , +515: Datum_Malongo_1987 = 6259 , +516: Datum_Manoca = 6260 , +517: Datum_Merchich = 6261 , +518: Datum_Massawa = 6262 , +519: Datum_Minna = 6263 , +520: Datum_Mhast = 6264 , +521: Datum_Monte_Mario = 6265 , +522: Datum_M_poraloko = 6266 , +523: Datum_North_American_Datum_1927 = 6267 , +524: Datum_NAD_Michigan = 6268 , +525: Datum_North_American_Datum_1983 = 6269 , +526: Datum_Nahrwan_1967 = 6270 , +527: Datum_Naparima_1972 = 6271 , +528: Datum_New_Zealand_Geodetic_Datum_1949 = 6272 , +529: Datum_NGO_1948 = 6273 , +530: Datum_Datum_73 = 6274 , +531: Datum_Nouvelle_Triangulation_Francaise = 6275 , +532: Datum_NSWC_9Z_2 = 6276 , +533: Datum_OSGB_1936 = 6277 , +534: Datum_OSGB_1970_SN = 6278 , +535: Datum_OS_SN_1980 = 6279 , +536: Datum_Padang_1884 = 6280 , +537: Datum_Palestine_1923 = 6281 , +538: Datum_Pointe_Noire = 6282 , +539: Datum_Geocentric_Datum_of_Australia_1994 = 6283 , +540: Datum_Pulkovo_1942 = 6284 , +541: Datum_Qatar = 6285 , +542: Datum_Qatar_1948 = 6286 , +543: Datum_Qornoq = 6287 , +544: Datum_Loma_Quintana = 6288 , +545: Datum_Amersfoort = 6289 , +546: Datum_RT38 = 6290 , +547: Datum_South_American_Datum_1969 = 6291 , +548: Datum_Sapper_Hill_1943 = 6292 , +549: Datum_Schwarzeck = 6293 , +550: Datum_Segora = 6294 , +551: Datum_Serindung = 6295 , +552: Datum_Sudan = 6296 , +553: Datum_Tananarive_1925 = 6297 , +554: Datum_Timbalai_1948 = 6298 , +555: Datum_TM65 = 6299 , +556: Datum_TM75 = 6300 , +557: Datum_Tokyo = 6301 , +558: Datum_Trinidad_1903 = 6302 , +559: Datum_Trucial_Coast_1948 = 6303 , +560: Datum_Voirol_1875 = 6304 , +561: Datum_Voirol_Unifie_1960 = 6305 , +562: Datum_Bern_1938 = 6306 , +563: Datum_Nord_Sahara_1959 = 6307 , +564: Datum_Stockholm_1938 = 6308 , +565: Datum_Yacare = 6309 , +566: Datum_Yoff = 6310 , +567: Datum_Zanderij = 6311 , +568: Datum_Militar_Geographische_Institut = 6312 , +569: Datum_Reseau_National_Belge_1972 = 6313 , +570: Datum_Deutsche_Hauptdreiecksnetz = 6314 , +571: Datum_Conakry_1905 = 6315 , +572: Datum_WGS72 = 6322 , +573: Datum_WGS72_Transit_Broadcast_Ephemeris = 6324 , +574: Datum_WGS84 = 6326 , +575: Datum_Ancienne_Triangulation_Francaise = 6901 , +576: Datum_Nord_de_Guerre = 6902 , +577: +578: +579: +580: DatumE_Airy1830 = 6001 , +581: DatumE_AiryModified1849 = 6002 , +582: DatumE_AustralianNationalSpheroid = 6003 , +583: DatumE_Bessel1841 = 6004 , +584: DatumE_BesselModified = 6005 , +585: DatumE_BesselNamibia = 6006 , +586: DatumE_Clarke1858 = 6007 , +587: DatumE_Clarke1866 = 6008 , +588: DatumE_Clarke1866Michigan = 6009 , +589: DatumE_Clarke1880_Benoit = 6010 , +590: DatumE_Clarke1880_IGN = 6011 , +591: DatumE_Clarke1880_RGS = 6012 , +592: DatumE_Clarke1880_Arc = 6013 , +593: DatumE_Clarke1880_SGA1922 = 6014 , +594: DatumE_Everest1830_1937Adjustment = 6015 , +595: DatumE_Everest1830_1967Definition = 6016 , +596: DatumE_Everest1830_1975Definition = 6017 , +597: DatumE_Everest1830Modified = 6018 , +598: DatumE_GRS1980 = 6019 , +599: DatumE_Helmert1906 = 6020 , +600: DatumE_IndonesianNationalSpheroid = 6021 , +601: DatumE_International1924 = 6022 , +602: DatumE_International1967 = 6023 , +603: DatumE_Krassowsky1960 = 6024 , +604: DatumE_NWL9D = 6025 , +605: DatumE_NWL10D = 6026 , +606: DatumE_Plessis1817 = 6027 , +607: DatumE_Struve1860 = 6028 , +608: DatumE_WarOffice = 6029 , +609: DatumE_WGS84 = 6030 , +610: DatumE_GEM10C = 6031 , +611: DatumE_OSU86F = 6032 , +612: DatumE_OSU91A = 6033 , +613: DatumE_Clarke1880 = 6034 , +614: DatumE_Sphere = 6035 +615: } DatumCode_t ; +616: +617: +618: +619: +620: typedef enum < short > { +621: Ellipse_Airy_1830 = 7001 , +622: Ellipse_Airy_Modified_1849 = 7002 , +623: Ellipse_Australian_National_Spheroid = 7003 , +624: Ellipse_Bessel_1841 = 7004 , +625: Ellipse_Bessel_Modified = 7005 , +626: Ellipse_Bessel_Namibia = 7006 , +627: Ellipse_Clarke_1858 = 7007 , +628: Ellipse_Clarke_1866 = 7008 , +629: Ellipse_Clarke_1866_Michigan = 7009 , +630: Ellipse_Clarke_1880_Benoit = 7010 , +631: Ellipse_Clarke_1880_IGN = 7011 , +632: Ellipse_Clarke_1880_RGS = 7012 , +633: Ellipse_Clarke_1880_Arc = 7013 , +634: Ellipse_Clarke_1880_SGA_1922 = 7014 , +635: Ellipse_Everest_1830_1937_Adjustment = 7015 , +636: Ellipse_Everest_1830_1967_Definition = 7016 , +637: Ellipse_Everest_1830_1975_Definition = 7017 , +638: Ellipse_Everest_1830_Modified = 7018 , +639: Ellipse_GRS_1980 = 7019 , +640: Ellipse_Helmert_1906 = 7020 , +641: Ellipse_Indonesian_National_Spheroid = 7021 , +642: Ellipse_International_1924 = 7022 , +643: Ellipse_International_1967 = 7023 , +644: Ellipse_Krassowsky_1940 = 7024 , +645: Ellipse_NWL_9D = 7025 , +646: Ellipse_NWL_10D = 7026 , +647: Ellipse_Plessis_1817 = 7027 , +648: Ellipse_Struve_1860 = 7028 , +649: Ellipse_War_Office = 7029 , +650: Ellipse_WGS_84 = 7030 , +651: Ellipse_GEM_10C = 7031 , +652: Ellipse_OSU86F = 7032 , +653: Ellipse_OSU91A = 7033 , +654: Ellipse_Clarke_1880 = 7034 , +655: Ellipse_Sphere = 7035 +656: } EllipsoidCode_t ; +657: +658: +659: +660: typedef enum < short > { +661: PM_Greenwich = 8901 , +662: PM_Lisbon = 8902 , +663: PM_Paris = 8903 , +664: PM_Bogota = 8904 , +665: PM_Madrid = 8905 , +666: PM_Rome = 8906 , +667: PM_Bern = 8907 , +668: PM_Jakarta = 8908 , +669: PM_Ferro = 8909 , +670: PM_Brussels = 8910 , +671: PM_Stockholm = 8911 +672: } PrimeMeridianCode_t ; +673: +674: +675: +676: +677: +678: +679: typedef enum < short > { +680: CT_TransverseMercator = 1 , +681: CT_TransvMercator_Modified_Alaska = 2 , +682: CT_ObliqueMercator = 3 , +683: CT_ObliqueMercator_Laborde = 4 , +684: CT_ObliqueMercator_Rosenmund = 5 , +685: CT_ObliqueMercator_Spherical = 6 , +686: CT_Mercator = 7 , +687: CT_LambertConfConic_2SP = 8 , +688: CT_LambertConfConic_Helmert = 9 , +689: CT_LambertAzimEqualArea = 10 , +690: CT_AlbersEqualArea = 11 , +691: CT_AzimuthalEquidistant = 12 , +692: CT_EquidistantConic = 13 , +693: CT_Stereographic = 14 , +694: CT_PolarStereographic = 15 , +695: CT_ObliqueStereographic = 16 , +696: CT_Equirectangular = 17 , +697: CT_CassiniSoldner = 18 , +698: CT_Gnomonic = 19 , +699: CT_MillerCylindrical = 20 , +700: CT_Orthographic = 21 , +701: CT_Polyconic = 22 , +702: CT_Robinson = 23 , +703: CT_Sinusoidal = 24 , +704: CT_VanDerGrinten = 25 , +705: CT_NewZealandMapGrid = 26 , +706: CT_TransvMercator_SouthOriented = 27 +707: } CTCode_t ; +708: +709: +710: +711: +712: +713: typedef struct { +714: SetBackColor ( cLtAqua ) ; +715: GeoKEYlabel label ; +716: if ( ReadUShort ( FTell ( ) ) != 0 ) +717: { +718: TAG TiffTagLocation ; +719: uint16 Length ; +720: uint16 Offset ; +721: } +722: else +723: { +724: uint16 direct ; +725: uint16 size ; +726: +727: +728: switch ( size ) { +729: case 1 : +730: +731: +732: switch ( label ) { +733: case GTModelTypeGeoKey : +734: modeltype_t value ; +735: break ; +736: +737: case GTRasterTypeGeoKey : +738: rastertype_t value ; +739: break ; +740: +741: case GeographicTypeGeoKey : +742: GCSCode_t value ; +743: break ; +744: +745: case GeogGeodeticDatumGeoKey : +746: DatumCode_t value ; +747: break ; +748: +749: case GeogPrimeMeridianGeoKey : +750: PrimeMeridianCode_t value ; +751: break ; +752: +753: case GeogLinearUnitsGeoKey : +754: LinearUnitCode_t value ; +755: break ; +756: +757: case GeogAngularUnitsGeoKey : +758: AngularUnitCode_t value ; +759: break ; +760: +761: case GeogEllipsoidGeoKey : +762: EllipsoidCode_t value ; +763: break ; +764: +765: case GeogAzimuthUnitsGeoKey : +766: AngularUnitCode_t value ; +767: break ; +768: +769: case ProjectedCSTypeGeoKey : +770: short value ; +771: break ; +772: +773: case ProjectionGeoKey : +774: short value ; +775: break ; +776: +777: case ProjCoordTransGeoKey : +778: short value ; +779: break ; +780: +781: case ProjLinearUnitsGeoKey : +782: short value ; +783: break ; +784: +785: case VerticalCSTypeGeoKey : +786: short value ; +787: break ; +788: +789: case VerticalDatumGeoKey : +790: short value ; +791: break ; +792: +793: case VerticalUnitsGeoKey : +794: LinearUnitCode_t value ; +795: break ; +796: +797: default : +798: short value ; +799: } ; +800: break ; +801: +802: default : +803: double value ; +804: } ; +805: +806: } +807: } GEOKEY < read = readGEOKEY > ; +808: +809: +810: +811: +812: +813: +814: string readGEOKEY ( local GEOKEY & gk ) { +815: local string s ; +816: +817: SPrintf ( s , "%s (%d)" , EnumToString ( gk . label ) , gk . label ) ; +818: return s ; +819: } +820: +821: +822: typedef struct eGEOKEYDIR { +823: SetBackColor ( cLtAqua ) ; +824: uint16 GeoTiffVersion ; +825: uint16 GeoTiffRevMajor ; +826: uint16 GeoTiffRevMinor ; +827: uint16 GeoKeyCount ; +828: local uint16 i ; +829: for ( i == 0 ; i < GeoKeyCount ; i ++ ) +830: { +831: GEOKEY GeoKeyValue ; +832: } ; +833: } GEOKEYDIR ; +834: +835: +836: +837: +838: typedef struct { +839: uint32 num ; +840: uint32 dom ; +841: } RATIONAL < read = readRATIONAL , write = writeRATIONAL > ; +842: +843: string readRATIONAL ( local RATIONAL & r ) { +844: local string s ; +845: SPrintf ( s , "%d/%d" , r . num , r . dom ) ; +846: return s ; +847: } +848: +849: void writeRATIONAL ( local RATIONAL & r , local string s ) { +850: SScanf ( s , "%d/%d" , r . num , r . dom ) ; +851: } +852: +853: +854: +855: typedef struct { +856: int32 num ; +857: int32 dom ; +858: } SRATIONAL < read = readSRATIONAL , write = writeSRATIONAL > ; +859: +860: string readSRATIONAL ( local SRATIONAL & r ) { +861: local string s ; +862: SPrintf ( s , "%d/%d" , r . num , r . dom ) ; +863: return s ; +864: } +865: +866: void writeSRATIONAL ( local SRATIONAL & r , local string s ) { +867: SScanf ( s , "%d/%d" , r . num , r . dom ) ; +868: } +869: +870: +871: +872: +873: +874: typedef struct { +875: SetBackColor ( cLtGreen ) ; +876: TAG tag ; +877: TAGTYPE typ ; +878: uint32 count ; +879: if ( typ == eBYTE ) { +880: if ( count < 4 ) { +881: ubyte data [ count ] ; +882: ubyte padding [ 4 - count ] ; +883: } else if ( count == 4 ) { +884: ubyte data [ count ] ; +885: } else { +886: SetBackColor ( cLtBlue ) ; +887: uint32 offset < format = hex > ; +888: local quad curpos = FTell ( ) ; +889: FSeek ( offset ) ; +890: ubyte value [ count ] ; +891: FSeek ( curpos ) ; +892: } +893: } else if ( typ == eASCII ) { +894: if ( count < 4 ) { +895: char data [ count ] ; +896: char padding [ 4 - count ] ; +897: } else if ( count == 4 ) { +898: char data [ count ] ; +899: } else { +900: SetBackColor ( cLtBlue ) ; +901: uint32 offset < format = hex > ; +902: local quad curpos = FTell ( ) ; +903: FSeek ( offset ) ; +904: char data [ count ] ; +905: FSeek ( curpos ) ; +906: } +907: } else if ( typ == eSHORT ) { +908: if ( count == 1 ) { +909: if ( tag == Compression ) { +910: COMP value ; +911: } else if ( tag == PhotometricInterpretation ) { +912: PHOTO value ; +913: } else if ( tag == ResolutionUnit ) { +914: RES value ; +915: } else { +916: uint16 value ; +917: } +918: uint16 padding ; +919: } else if ( count == 2 ) { +920: uint16 value [ 2 ] ; +921: } else { +922: SetBackColor ( cLtBlue ) ; +923: uint32 offset < format = hex > ; +924: local quad curpos = FTell ( ) ; +925: FSeek ( offset ) ; +926: if ( tag == GeoKeyDirectoryTag ) { +927: GEOKEYDIR value ; +928: } else { +929: uint16 value [ count ] ; +930: } +931: FSeek ( curpos ) ; +932: } +933: } else if ( typ == eLONG ) { +934: if ( count == 1 ) { +935: uint32 value ; +936: } else { +937: SetBackColor ( cLtBlue ) ; +938: uint32 offset < format = hex > ; +939: local quad curpos = FTell ( ) ; +940: FSeek ( offset ) ; +941: uint32 value [ count ] ; +942: FSeek ( curpos ) ; +943: } +944: } else if ( typ == eRATIONAL ) { +945: SetBackColor ( cLtBlue ) ; +946: uint32 offset < format = hex > ; +947: local quad curpos = FTell ( ) ; +948: FSeek ( offset ) ; +949: if ( count == 1 ) { +950: RATIONAL value ; +951: } else { +952: RATIONAL value [ count ] ; +953: } +954: FSeek ( curpos ) ; +955: } else if ( typ == eSBYTE ) { +956: if ( count < 4 ) { +957: byte data [ count ] ; +958: ubyte padding [ 4 - count ] ; +959: } else if ( count == 4 ) { +960: byte data [ count ] ; +961: } else { +962: SetBackColor ( cLtBlue ) ; +963: uint32 offset < format = hex > ; +964: local quad curpos = FTell ( ) ; +965: FSeek ( offset ) ; +966: byte value [ count ] ; +967: FSeek ( curpos ) ; +968: } +969: } else if ( typ == eUNDEF ) { +970: if ( count < 4 ) { +971: ubyte data [ count ] ; +972: ubyte padding [ 4 - count ] ; +973: } else if ( count == 4 ) { +974: ubyte data [ count ] ; +975: } else { +976: SetBackColor ( cLtBlue ) ; +977: uint32 offset < format = hex > ; +978: local quad curpos = FTell ( ) ; +979: FSeek ( offset ) ; +980: ubyte value [ count ] ; +981: FSeek ( curpos ) ; +982: } +983: } else if ( typ == eSSHORT ) { +984: if ( count == 1 ) { +985: int16 value ; +986: int16 padding ; +987: } else if ( count == 2 ) { +988: int16 value [ 2 ] ; +989: } else { +990: SetBackColor ( cLtBlue ) ; +991: uint32 offset < format = hex > ; +992: local quad curpos = FTell ( ) ; +993: FSeek ( offset ) ; +994: int16 value [ count ] ; +995: FSeek ( curpos ) ; +996: } +997: } else if ( typ == eSLONG ) { +998: if ( count == 1 ) { +999: int32 value ; +1000: } else { +1001: SetBackColor ( cLtBlue ) ; +1002: uint32 offset < format = hex > ; +1003: local quad curpos = FTell ( ) ; +1004: FSeek ( offset ) ; +1005: int32 value [ count ] ; +1006: FSeek ( curpos ) ; +1007: } +1008: } else if ( typ == eSRATIONAL ) { +1009: SetBackColor ( cLtBlue ) ; +1010: uint32 offset < format = hex > ; +1011: local quad curpos = FTell ( ) ; +1012: FSeek ( offset ) ; +1013: if ( count == 1 ) { +1014: SRATIONAL value ; +1015: } else { +1016: SRATIONAL value [ count ] ; +1017: } +1018: FSeek ( curpos ) ; +1019: } else if ( typ == eFLOAT ) { +1020: if ( count == 1 ) { +1021: float value ; +1022: } else { +1023: SetBackColor ( cLtBlue ) ; +1024: uint32 offset < format = hex > ; +1025: local quad curpos = FTell ( ) ; +1026: FSeek ( offset ) ; +1027: float value [ count ] ; +1028: FSeek ( curpos ) ; +1029: } +1030: } else if ( typ == eDOUBLE ) { +1031: SetBackColor ( cLtBlue ) ; +1032: uint32 offset < format = hex > ; +1033: local quad curpos = FTell ( ) ; +1034: FSeek ( offset ) ; +1035: if ( count == 1 ) { +1036: double value ; +1037: } else { +1038: double value [ count ] ; +1039: } +1040: FSeek ( curpos ) ; +1041: } else { +1042: +1043: +1044: +1045: SetBackColor ( cLtRed ) ; +1046: uint32 valOffset < format = hex > ; +1047: } +1048: SetBackColor ( cNone ) ; +1049: } ENT < read = readENT > ; +1050: +1051: +1052: +1053: +1054: +1055: +1056: string readENT ( local ENT & ent ) { +1057: local string s ; +1058: +1059: SPrintf ( s , "%s (%d): %s" , EnumToString ( ent . tag ) , ent . tag , EnumToString ( ent . typ ) ) ; +1060: return s ; +1061: } +1062: +1063: +1064: typedef struct { +1065: uint16 numentries ; +1066: ENT dir [ numentries ] < optimize = false > ; +1067: uint32 offset < format = hex > ; +1068: nextIFD = ( quad ) offset ; +1069: } IFD < read = readIFD > ; +1070: +1071: +1072: +1073: +1074: +1075: +1076: string readIFD ( local IFD & ifd ) { +1077: local string s ; +1078: +1079: SPrintf ( s , "%d: %s" , ifd . numentries , ( ifd . numentries > 0 ) ? EnumToString ( ifd . dir [ 0 ] . tag ) : "" ) ; +1080: return s ; +1081: } +1082: +1083: +1084: typedef struct { +1085: char bom [ 2 ] ; +1086: uint16 magic ; +1087: if ( magic != 42 ) { +1088: Warning ( "Invalid TIFF File: Bad Magic number" ) ; +1089: return - 1 ; +1090: } +1091: uint32 offset < format = hex > ; +1092: +1093: +1094: if ( offset == 0 ) { +1095: Warning ( "Invalid TIFF File: No initial IFD" ) ; +1096: return - 1 ; +1097: } +1098: +1099: nextIFD = ( quad ) offset ; +1100: } IFH ; +1101: +1102: +1103: +1104: +1105: +1106: SetBackColor ( cLtAqua ) ; +1107: IFH ifh ; +1108: while ( nextIFD ) { +1109: FSeek ( nextIFD ) ; +1110: SetBackColor ( cLtGreen ) ; +1111: IFD ifd ; +1112: SetBackColor ( cNone ) ; +1113: } +1114: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/TOCTemplate.bt b/cparser/tests/exp_lex/TOCTemplate.bt new file mode 100644 index 0000000..322809c --- /dev/null +++ b/cparser/tests/exp_lex/TOCTemplate.bt @@ -0,0 +1,127 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: enum < WORD > type { In , Out , Junk , Trash , User , IMAP = 8 } ; +10: enum < WORD > class { user , system } ; +11: enum < WORD > stat { unread , read , replied , forwarded , redirected , rebuilt , sendable , queued , sent , unsent , timed , sending , recovered } ; +12: +13: typedef struct +14: { char EudoraVersion [ 8 ] ; +15: char MailboxName [ 32 ] ; +16: type MailboxType ; +17: short Unknown0 ; +18: class MailboxClass ; +19: struct +20: { short TopLeftX ; +21: short TopLeftY ; +22: short BottomRightX ; +23: short BottomRightY ; +24: } WindowPosition ; +25: +26: +27: +28: +29: +30: +31: +32: struct +33: { short StatusColumnWidth ; +34: short JunkScoreColumnWidth ; +35: short PriorityColumnWidth ; +36: short AttachmentColumnWidth ; +37: short LabelColumnWidth ; +38: short WhoColumnWidth ; +39: short DateColumnWidth ; +40: short SizeColumnWidth ; +41: } ColumnWidths ; +42: +43: +44: +45: +46: +47: +48: short Unknown1 ; +49: long HighestMsgSeqNumber ; +50: short Unknown2 [ 4 ] ; +51: short PreviewPaneDivider ; +52: short Unknown3 [ 5 ] ; +53: long NewMessageOffsetMBXfile ; +54: short Unknown4 ; +55: short MessagesInMailbox ; +56: } TOChdr ; +57: +58: typedef struct +59: { long OffsetMBXfile < format = hex > ; +60: long Length ; +61: time_t GMTtimestamp ; +62: stat Status ; +63: SetForeColor ( cGreen ) ; +64: ubyte Flags1 : 8 < format = binary > ; +65: +66: +67: +68: +69: +70: +71: +72: +73: ubyte Flags2 : 8 < format = binary > ; +74: +75: +76: +77: +78: +79: +80: +81: +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 < format = hex > ; +96: long MsgSeqNumber ; +97: SetForeColor ( cPurple ) ; +98: ubyte Flags3 : 8 < format = binary > ; +99: +100: +101: +102: +103: +104: +105: +106: +107: ubyte Flags4 : 8 < format = binary > ; +108: +109: +110: +111: +112: +113: +114: +115: +116: SetForeColor ( cNone ) ; +117: short Unknown [ 10 ] ; +118: } TOCmsg ; +119: +120: +121: +122: LittleEndian ( ) ; +123: TOChdr hdr ; +124: while ( ! FEof ( ) ) +125: { TOCmsg msg ; +126: } +127: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/TTFTemplate.bt b/cparser/tests/exp_lex/TTFTemplate.bt new file mode 100644 index 0000000..fa05353 --- /dev/null +++ b/cparser/tests/exp_lex/TTFTemplate.bt @@ -0,0 +1,991 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: BigEndian ( ) ; +20: +21: typedef signed long TT_Fixed ; +22: +23: typedef signed short TT_FWord ; +24: typedef unsigned short TT_UFWord ; +25: +26: typedef signed short TT_Short ; +27: typedef unsigned short TT_UShort ; +28: typedef signed long TT_Long ; +29: typedef unsigned long TT_ULong ; +30: typedef unsigned long TT_Offset ; +31: typedef OLETIME LONGDATETIME ; +32: +33: typedef signed short F2Dot14 ; +34: +35: typedef struct tOffsetTable { +36: TT_Fixed SFNT_Ver ; +37: USHORT numTables ; +38: USHORT searchRange ; +39: USHORT entrySelector ; +40: USHORT rangeShift ; +41: } ; +42: +43: typedef struct tTable { +44: union { +45: char asChar [ 4 ] ; +46: ULONG asLong ; +47: } Tag ; +48: ULONG checkSum ; +49: ULONG offset ; +50: ULONG length ; +51: } ; +52: +53: string tTableRead ( tTable & d ) { +54: char s [ 20 ] ; +55: SPrintf ( s , " (%u) at %u for %u" , d . Tag . asLong , d . offset , d . length ) ; +56: s = d . Tag . asChar + s ; +57: +58: return s ; +59: } +60: +61: +62: local quad cmap_table ; +63: local quad cmap_record ; +64: local quad cmap_subtable ; +65: local quad next_cmap_record ; +66: +67: typedef struct tcmap_format0 { +68: cmap_subtable = FTell ( ) ; +69: USHORT format ; +70: USHORT length ; +71: USHORT language ; +72: BYTE glyphIdArray [ 256 ] ; +73: } ; +74: +75: typedef struct tcmap_format4 { +76: cmap_subtable = FTell ( ) ; +77: USHORT format ; +78: USHORT length ; +79: USHORT language ; +80: USHORT segCountX2 ; +81: USHORT searchRange ; +82: USHORT entrySelector ; +83: USHORT rangeShift ; +84: USHORT endCount [ segCountX2 / 2 ] ; +85: USHORT reservedPad ; +86: USHORT startCount [ segCountX2 / 2 ] ; +87: SHORT idDelta [ segCountX2 / 2 ] ; +88: USHORT idRangeOffset [ segCountX2 / 2 ] ; +89: USHORT glyphIdArray [ ( length - ( FTell ( ) - cmap_subtable ) ) / 2 ] ; +90: +91: } ; +92: +93: typedef struct tcmap_format6 { +94: cmap_subtable = FTell ( ) ; +95: USHORT format ; +96: USHORT length ; +97: USHORT language ; +98: USHORT firstCode ; +99: USHORT entryCount ; +100: USHORT glyphIdArray [ entryCount ] ; +101: } ; +102: +103: typedef struct tcmap_format8 { +104: cmap_subtable = FTell ( ) ; +105: USHORT format ; +106: USHORT reserved ; +107: ULONG length ; +108: ULONG language ; +109: BYTE is32 [ 8192 ] ; +110: ULONG nGroups ; +111: struct { +112: ULONG startCharCode ; +113: ULONG endCharCode ; +114: ULONG startGlyphID ; +115: } groupings [ nGroups ] ; +116: } ; +117: +118: typedef struct tcmap_format12 { +119: USHORT format ; +120: USHORT reserved ; +121: ULONG length ; +122: ULONG language ; +123: ULONG nGroups ; +124: struct { +125: ULONG startCharCode ; +126: ULONG endCharCode ; +127: ULONG startGlyphID ; +128: } groupings [ nGroups ] ; +129: } ; +130: +131: +132: typedef struct tcmap { +133: cmap_table = FTell ( ) ; +134: USHORT version ; +135: USHORT numTables ; +136: struct tEncodingRecord { +137: cmap_record = FTell ( ) ; +138: USHORT platformID ; +139: USHORT encodingID ; +140: ULONG offset ; +141: next_cmap_record = FTell ( ) ; +142: FSeek ( cmap_table + offset ) ; +143: switch ( ReadUShort ( FTell ( ) ) ) { +144: case 0 : struct tcmap_format0 format0 ; break ; +145: +146: case 4 : struct tcmap_format4 format4 ; break ; +147: case 6 : struct tcmap_format6 format6 ; break ; +148: case 8 : struct tcmap_format8 format8 ; break ; +149: +150: case 12 : struct tcmap_format12 format12 ; break ; +151: default : ; +152: } +153: FSeek ( next_cmap_record ) ; +154: } EncodingRecord [ numTables ] < optimize = false > ; +155: +156: } ; +157: +158: typedef struct thdmx { +159: USHORT version ; +160: SHORT numRecords ; +161: LONG sizeDeviceRecord ; +162: struct { +163: local quad hdmx_DeviceRecord = FTell ( ) ; +164: UBYTE pixelSize ; +165: UBYTE maxWidth ; +166: local quad numGlyphs = ( sizeDeviceRecord - ( FTell ( ) - hdmx_DeviceRecord ) ) / 1 ; +167: UBYTE widths [ numGlyphs ] ; +168: } DeviceRecord [ numRecords ] < optimize = false > ; +169: } ; +170: +171: string thdmxRead ( thdmx & d ) { +172: string s ; +173: SPrintf ( s , "V%i %u records %u bytes" , d . version , d . numRecords , d . sizeDeviceRecord ) ; +174: return s ; +175: +176: } +177: +178: typedef struct thead { +179: TT_Fixed version ; +180: TT_Fixed fontRevision ; +181: ULONG checkSumAdjustment ; +182: ULONG magicNumber ; +183: USHORT flags ; +184: +185: +186: +187: +188: +189: +190: +191: +192: +193: +194: +195: +196: +197: USHORT unitsPerEm ; +198: LONGDATETIME created ; +199: LONGDATETIME modified ; +200: SHORT xMin ; +201: SHORT yMin ; +202: SHORT xMax ; +203: SHORT yMax ; +204: USHORT macStyle ; +205: +206: +207: +208: +209: +210: +211: +212: +213: +214: +215: USHORT lowestRecPPEM ; +216: SHORT fontDirectionHint ; +217: +218: +219: +220: +221: +222: +223: +224: SHORT indexToLocFormat ; +225: SHORT glyphDataFormat ; +226: } ; +227: +228: typedef struct thhea { +229: TT_Fixed version ; +230: TT_FWord Ascender ; +231: TT_FWord Descender ; +232: TT_FWord LineGap ; +233: +234: +235: +236: TT_UFWord advanceWidthMax ; +237: TT_FWord minLeftSideBearing ; +238: TT_FWord minRightSideBearing ; +239: TT_FWord xMaxExtent ; +240: SHORT caretSlopeRise ; +241: SHORT caretSlopeRun ; +242: SHORT caretOffset ; +243: SHORT reserved ; +244: SHORT reserved ; +245: SHORT reserved ; +246: SHORT reserved ; +247: SHORT metricDataFormat ; +248: USHORT numberOfHMetrics ; +249: } ; +250: +251: string thheaRead ( thhea & d ) { +252: string s ; +253: SPrintf ( s , "v%.2f %u hmtx records" , d . version / 65535 . 0 , d . numberOfHMetrics ) ; +254: return s ; +255: +256: } +257: +258: typedef struct tlongHorMetric { +259: USHORT advanceWidth ; +260: SHORT lsb ; +261: } ; +262: +263: typedef struct thmtx { +264: +265: +266: local ulong numberOfHMetrics = hhea . numberOfHMetrics ; +267: struct tlongHorMetric hMetrics [ numberOfHMetrics ] ; +268: +269: +270: local ulong numLeftSideBearing = ( Table [ currentTable ] . length - ( FTell ( ) - Table [ currentTable ] . offset ) ) / 2 ; +271: SHORT leftSideBearing [ numLeftSideBearing ] ; +272: +273: +274: +275: +276: } ; +277: +278: string thmtxRead ( thmtx & d ) { +279: string s ; +280: SPrintf ( s , "%u HMetrics %u leftSideBearing" , d . numberOfHMetrics , d . numLeftSideBearing ) ; +281: return s ; +282: } +283: +284: typedef struct tmaxp { +285: TT_Fixed version ; +286: +287: if ( version == 0x5000 ) { +288: USHORT numGlyphs ; +289: } +290: else { +291: +292: USHORT numGlyphs ; +293: USHORT maxPoints ; +294: USHORT maxContours ; +295: USHORT maxCompositePoints ; +296: USHORT maxCompositeContours ; +297: USHORT maxZones ; +298: USHORT maxTwilightPoints ; +299: USHORT maxStorage ; +300: USHORT maxFunctionDefs ; +301: USHORT maxInstructionDefs ; +302: USHORT maxStackElements ; +303: USHORT maxSizeOfInstructions ; +304: USHORT maxComponentElements ; +305: USHORT maxComponentDepth ; +306: } +307: } ; +308: +309: string tmaxpRead ( tmaxp & d ) { +310: string s ; +311: if ( d . version == 0x5000 ) { +312: SPrintf ( s , "v%.2f %u glyphs" , d . version / 65535 . 0 , d . numGlyphs ) ; +313: } +314: else { +315: SPrintf ( s , "v%.2f %u glyphs %u points %u contours" , d . version / 65535 . 0 , d . numGlyphs , d . maxPoints , d . maxContours ) ; +316: } +317: return s ; +318: } +319: +320: typedef struct tname { +321: +322: local quad name_table = FTell ( ) ; +323: USHORT format ; +324: USHORT count ; +325: USHORT stringOffset ; +326: local quad NextNameRecord ; +327: struct tNameRecord { +328: USHORT platformID ; +329: USHORT encodingID ; +330: USHORT languageID ; +331: USHORT nameID ; +332: USHORT length ; +333: USHORT offset ; +334: NextNameRecord = FTell ( ) ; +335: FSeek ( name_table + stringOffset + offset ) ; +336: char name [ length ] ; +337: FSeek ( NextNameRecord ) ; +338: } NameRecord [ count ] < read = NameRecordRead , optimize = false > ; +339: } ; +340: +341: string NameRecordRead ( tNameRecord & d ) { +342: string s ; +343: SPrintf ( s , "p%i E%i L%i %s" , d . platformID , d . encodingID , d . languageID , d . name ) ; +344: return s ; +345: +346: } +347: +348: string tnameRead ( tname & name ) { +349: string s ; +350: SPrintf ( s , "%li Names" , name . count ) ; +351: return s ; +352: } +353: +354: typedef struct tOS_2 { +355: +356: USHORT version ; +357: SHORT xAvgCharWidth ; +358: USHORT usWeightClass ; +359: USHORT usWidthClass ; +360: USHORT fsType ; +361: SHORT ySubscriptXSize ; +362: SHORT ySubscriptYSize ; +363: SHORT ySubscriptXOffset ; +364: SHORT ySubscriptYOffset ; +365: SHORT ySuperscriptXSize ; +366: SHORT ySuperscriptYSize ; +367: SHORT ySuperscriptXOffset ; +368: SHORT ySuperscriptYOffset ; +369: SHORT yStrikeoutSize ; +370: SHORT yStrikeoutPosition ; +371: SHORT sFamilyClass ; +372: struct tpanose { +373: UBYTE bFamilyType ; +374: UBYTE bSerifStyle ; +375: UBYTE bWeight ; +376: UBYTE bProportion ; +377: UBYTE bContrast ; +378: UBYTE bStrokeVariation ; +379: UBYTE bArmStyle ; +380: UBYTE bLetterform ; +381: UBYTE bMidline ; +382: UBYTE bXHeight ; +383: } panose ; +384: ULONG ulUnicodeRange1 ; +385: ULONG ulUnicodeRange2 ; +386: ULONG ulUnicodeRange3 ; +387: ULONG ulUnicodeRange4 ; +388: CHAR achVendID [ 4 ] ; +389: USHORT fsSelection ; +390: USHORT usFirstCharIndex ; +391: USHORT usLastCharIndex ; +392: SHORT sTypoAscender ; +393: SHORT sTypoDescender ; +394: SHORT sTypoLineGap ; +395: USHORT usWinAscent ; +396: USHORT usWinDescent ; +397: ULONG ulCodePageRange1 ; +398: ULONG ulCodePageRange2 ; +399: SHORT sxHeight ; +400: SHORT sCapHeight ; +401: USHORT usDefaultChar ; +402: USHORT usBreakChar ; +403: USHORT usMaxContext ; +404: } ; +405: +406: string tOS_2Read ( tOS_2 & d ) { +407: string s ; +408: SPrintf ( s , "v%i chars %i to %i from %4s" , d . version , d . usFirstCharIndex , d . usLastCharIndex , d . achVendID ) ; +409: return s ; +410: } +411: +412: typedef struct tpost { +413: local quad post = FTell ( ) ; +414: TT_Fixed version ; +415: +416: +417: +418: +419: TT_Fixed italicAngle ; +420: TT_FWord underlinePosition ; +421: +422: TT_FWord underlineThickness ; +423: ULONG isFixedPitch ; +424: ULONG minMemType42 ; +425: ULONG maxMemType42 ; +426: ULONG minMemType1 ; +427: ULONG maxMemType1 ; +428: if ( version == 0x10000 ) { +429: } +430: if ( version == 0x20000 ) { +431: USHORT numberOfGlyphs ; +432: local ushort numGlyphs = numberOfGlyphs ; +433: USHORT glyphNameIndex [ numGlyphs ] ; +434: local ushort numberNewGlyphs = numberOfGlyphs ; +435: local quad end_name = post + Table [ currentTable ] . length ; +436: local quad next_name = FTell ( ) ; +437: while ( next_name < end_name ) { +438: struct tpostName { +439: UBYTE length ; +440: CHAR text [ length ] ; +441: } name < read = tpostNameRead > ; +442: next_name = FTell ( ) ; +443: } ; +444: } +445: if ( version == 0x25000 ) { +446: USHORT numberOfGlyphs ; +447: local ushort numGlyphs = numberOfGlyphs ; +448: USHORT offset [ numGlyphs ] ; +449: } +450: if ( version == 0x30000 ) { +451: } +452: } ; +453: +454: string tpostNameRead ( tpostName & d ) { +455: return d . text ; +456: } +457: +458: string tpostRead ( tpost & d ) { +459: string s ; +460: SPrintf ( s , "v%.2f %u glyphs" , d . version / 65535 . 0 , d . numberOfGlyphs ) ; +461: if ( d . isFixedPitch ) { s += " fixed pitch" ; } else { s += " proportional" ; } ; +462: return s ; +463: } ; +464: +465: typedef struct tcvt { +466: local quad n = Table [ currentTable ] . length / sizeof ( TT_FWord ) ; +467: TT_FWord value [ n ] ; +468: } ; +469: +470: typedef struct tfpgm { +471: local quad n = Table [ currentTable ] . length / sizeof ( UBYTE ) ; +472: UBYTE bytecode [ n ] ; +473: } ; +474: +475: typedef struct tloca { +476: local ulong n = maxp . numGlyphs + 1 ; +477: local short format = head . indexToLocFormat ; +478: if ( format == 0 ) { +479: USHORT offsets [ n ] ; +480: } +481: else { +482: ULONG offsets [ n ] ; +483: } +484: } ; +485: +486: string tlocaRead ( tloca & d ) { +487: string s ; +488: if ( d . format == 0 ) SPrintf ( s , "%u short offsets" , d . n ) ; +489: else SPrintf ( s , "%u long offsets" , d . n ) ; +490: return s ; +491: } +492: +493: +494: local USHORT ARG_1_AND_2_ARE_WORDS = 1 << 0 ; +495: local USHORT ARGS_ARE_XY_VALUES = 1 << 1 ; +496: local USHORT ROUND_XY_TO_GRID = 1 << 2 ; +497: local USHORT WE_HAVE_A_SCALE = 1 << 3 ; +498: local USHORT RESERVED = 1 << 4 ; +499: local USHORT MORE_COMPONENTS = 1 << 5 ; +500: local USHORT WE_HAVE_AN_X_AND_Y_SCALE = 1 << 6 ; +501: local USHORT WE_HAVE_A_TWO_BY_TWO = 1 << 7 ; +502: local USHORT WE_HAVE_INSTRUCTIONS = 1 << 8 ; +503: local USHORT USE_MY_METRICS = 1 << 9 ; +504: local USHORT OVERLAP_COMPOUND = 1 << 10 ; +505: local USHORT SCALED_COMPONENT_OFFSET = 1 << 11 ; +506: local USHORT UNSCALED_COMPONENT_OFFSET = 1 << 12 ; +507: +508: +509: +510: local UBYTE ON_CURVE = 1 << 0 ; +511: local UBYTE X_BYTE = 1 << 1 ; +512: local UBYTE Y_BYTE = 1 << 2 ; +513: +514: +515: local UBYTE REPEAT = 1 << 3 ; +516: +517: local UBYTE X_TYPE = 1 << 4 ; +518: +519: +520: +521: +522: +523: +524: local UBYTE Y_TYPE = 1 << 5 ; +525: +526: +527: +528: +529: +530: +531: local UBYTE RES_1 = 1 << 6 ; +532: local UBYTE RES_2 = 1 << 7 ; +533: +534: typedef struct tSimpleGlyphPoints { +535: local ulong i ; +536: local quad xStart , xLast ; xStart = xLast = FTell ( ) ; +537: local quad yStart , yLast ; yStart = FTell ( ) ; +538: yLast = 0 ; +539: local byte xLastByte = 0 ; +540: local byte yLastByte = 0 ; +541: +542: for ( i = 0 ; i < numPoints ; i ++ ) { +543: +544: if ( ! ( flag [ i ] & X_BYTE ) && ( flag [ i ] & X_TYPE ) ) { } +545: else { +546: yStart ++ ; +547: if ( ! ( flag [ i ] & X_BYTE ) ) { yStart ++ ; } +548: +549: } +550: } Printf ( "yStart: %u\n" , yStart ) ; +551: +552: for ( i = 0 ; i < numPoints ; i ++ ) { +553: struct tPoints { +554: FSeek ( xStart ) ; +555: if ( flag [ i ] & X_BYTE ) { +556: xLast = FTell ( ) ; xLastByte = 1 ; +557: UBYTE xDelta ; xStart = FTell ( ) ; +558: } +559: else { +560: if ( ( flag [ i ] & X_TYPE ) ) { +561: FSeek ( xLast ) ; +562: if ( xLast > 0 ) { if ( xLastByte ) UBYTE xDeltaRepeat ; else SHORT xDeltaRepeat ; } +563: } +564: else { +565: xLast = FTell ( ) ; xLastByte = 0 ; +566: SHORT xDelta ; xStart = FTell ( ) ; +567: } +568: } +569: +570: +571: FSeek ( yStart ) ; +572: if ( flag [ i ] & Y_BYTE ) { +573: yLast = FTell ( ) ; yLastByte = 1 ; +574: UBYTE yDelta ; yStart = FTell ( ) ; +575: } +576: else { +577: if ( ( flag [ i ] & Y_TYPE ) ) { +578: FSeek ( yLast ) ; +579: if ( yLast > 0 ) { if ( yLastByte ) UBYTE yDeltaRepeat ; else SHORT yDeltaRepeat ; } +580: } +581: else { +582: yLast = FTell ( ) ; yLastByte = 0 ; +583: SHORT yDelta ; yStart = FTell ( ) ; +584: } +585: } +586: FSeek ( xStart ) ; +587: +588: } points < optimize = false > ; +589: } +590: } ; +591: +592: string tPointsRead ( tSimpleGlyphPoints & d ) { +593: string s ; +594: s = "hello" ; +595: +596: +597: +598: +599: return s ; +600: } +601: +602: typedef UBYTE bitFlag ; +603: +604: local bitFlag flag_repeat = 0 ; +605: +606: typedef struct tSimpleGlyphFlags { +607: if ( flag_repeat ) { +608: UBYTE count ; +609: flag_repeat = 0 ; +610: } +611: else { +612: BitfieldRightToLeft ( ) ; +613: bitFlag onCurve : 1 ; +614: bitFlag xByte : 1 ; +615: bitFlag yByte : 1 ; +616: bitFlag repeat : 1 ; +617: bitFlag xType : 1 ; +618: bitFlag yType : 1 ; +619: if ( repeat ) flag_repeat = 1 ; +620: } +621: } ; +622: +623: string tSimpleGlyphFlagsRead ( tSimpleGlyphFlags & d ) { +624: string s ; +625: if ( exists ( d . count ) ) { +626: SPrintf ( s , " repeat %u times" , d . count ) ; +627: +628: } +629: else { +630: s = "Point" ; +631: if ( d . onCurve ) s += " OnCurve" ; +632: if ( ! d . xByte ) { s += " X" ; if ( d . xType ) s += "R" ; } +633: if ( d . xByte ) { s += " x" ; if ( d . xType ) s += "+" ; else s += "-" ; } +634: if ( ! d . yByte ) { s += " Y" ; if ( d . yType ) s += "R" ; } +635: if ( d . yByte ) { s += " y" ; if ( d . yType ) s += "+" ; else s += "-" ; } +636: if ( d . repeat ) s += " REPEAT:" ; +637: } +638: return s ; +639: } +640: +641: +642: typedef struct tSimpleGlyph { +643: SHORT numberOfContours ; +644: SHORT xMin ; +645: SHORT yMin ; +646: SHORT xMax ; +647: SHORT yMax ; +648: USHORT endPtsOfContours [ numberOfContours ] ; +649: USHORT instructionLength ; +650: if ( instructionLength > 0 ) { +651: UBYTE instructions [ instructionLength ] ; +652: } +653: local USHORT numPoints ; +654: numPoints = endPtsOfContours [ numberOfContours - 1 ] + 1 ; +655: +656: +657: +658: local quad glyf_flag_table = FTell ( ) ; +659: local quad glyf_flag_index = FTell ( ) ; +660: local ushort i ; +661: local ubyte repeat = 0 ; +662: local ubyte flag [ numPoints ] ; +663: +664: local ubyte flag_value ; +665: for ( i = 0 ; i < numPoints ; i ++ ) { +666: if ( repeat > 0 ) repeat -- ; +667: else { +668: flag_value = ReadUByte ( glyf_flag_index ++ ) ; +669: +670: if ( flag [ i ] & 8 ) repeat = ReadUByte ( glyf_flag_index ++ ) ; +671: } +672: flag [ i ] = flag_value ; +673: } +674: local ushort numFlags = glyf_flag_index - glyf_flag_table ; +675: struct { +676: tSimpleGlyphFlags flag [ numFlags ] < optimize = false , read = tSimpleGlyphFlagsRead > ; +677: } compressedFlags ; +678: +679: +680: +681: +682: +683: struct tSimpleGlyphPoints contours ; +684: } ; +685: +686: typedef struct tglyf { +687: local quad glyf_table = FTell ( ) ; +688: local quad glyf_offset ; +689: +690: +691: +692: +693: local ulong n ; +694: for ( n = 0 ; n <= 9 ; n ++ ) { +695: +696: +697: glyf_offset = loca . offsets [ n ] ; +698: +699: +700: if ( head . indexToLocFormat == 0 ) glyf_offset *= 2 ; +701: +702: FSeek ( glyf_table + glyf_offset ) ; +703: if ( ReadShort ( FTell ( ) ) > 0 ) { +704: +705: struct tSimpleGlyph SimpleGlyph < read = tSimpleGlyphRead > ; +706: } +707: +708: if ( ReadShort ( FTell ( ) ) < 0 & 0 == 1 ) { +709: +710: +711: SHORT numberOfContours ; +712: SHORT xMin ; +713: SHORT yMin ; +714: SHORT xMax ; +715: SHORT yMax ; +716: do { +717: USHORT flags ; +718: struct tGlyph { +719: +720: USHORT glyphIndex ; +721: if ( flags & ARG_1_AND_2_ARE_WORDS ) { +722: SHORT argument1 ; +723: SHORT argument2 ; +724: } +725: else { +726: USHORT arg1and2 ; +727: } +728: if ( flags & WE_HAVE_A_SCALE ) { +729: F2Dot14 scale ; +730: } +731: else if ( flags & WE_HAVE_AN_X_AND_Y_SCALE ) { +732: F2Dot14 xscale ; +733: F2Dot14 yscale ; +734: } +735: else if ( flags & WE_HAVE_A_TWO_BY_TWO ) { +736: F2Dot14 xscale ; +737: F2Dot14 scale01 ; +738: F2Dot14 scale10 ; +739: F2Dot14 yscale ; +740: } +741: if ( flags & WE_HAVE_INSTRUCTIONS ) { +742: USHORT numInstr ; +743: BYTE instr [ numInstr ] ; +744: } +745: } Glyph ; +746: } while ( flags & MORE_COMPONENTS ) ; +747: +748: +749: } ; +750: +751: } +752: } ; +753: +754: string tSimpleGlyphRead ( tSimpleGlyph & d ) { +755: string s ; +756: SPrintf ( s , "%u contours %u insts %u flags %u points" , d . numberOfContours , d . instructionLength , d . numFlags , d . numPoints ) ; +757: return s ; +758: } +759: +760: typedef struct tGDEF { +761: TT_Fixed Version ; +762: TT_Offset GlyphClassDef ; +763: TT_Offset AttachList ; +764: TT_Offset LigCaretList ; +765: TT_Offset MarkAttachClassDef ; +766: } ; +767: +768: typedef struct tprep { +769: local quad n = Table [ currentTable ] . length / sizeof ( UBYTE ) ; +770: UBYTE bytecode [ n ] ; +771: } ; +772: +773: typedef struct tDSIG { +774: local quad DSIG_table = FTell ( ) ; +775: local quad nextSig ; +776: ULONG ulVersion ; +777: USHORT usNumSigs ; +778: USHORT usFlag ; +779: +780: +781: struct { +782: nextSig = FTell ( ) ; FSeek ( nextSig ) ; +783: ULONG ulFormat ; +784: ULONG ulLength ; +785: ULONG ulOffset ; +786: nextSig = FTell ( ) ; FSeek ( DSIG_table + ulOffset ) ; +787: USHORT usReserved1 ; +788: USHORT usReserved2 ; +789: ULONG cbSignature ; +790: UBYTE bSignature [ cbSignature ] ; +791: } Sigs [ usNumSigs ] < optimize = false > ; +792: +793: } ; +794: string tDSIGRead ( tDSIG & d ) { +795: string s ; +796: SPrintf ( s , "v%u %u signature(s)" , d . ulVersion , d . usNumSigs ) ; +797: return s ; +798: } +799: +800: typedef struct tLangSysTable { +801: USHORT LookupOrder ; +802: uint16 ReqFeatureIndex ; +803: uint16 FeatureCount ; +804: uint16 FeatureIndex [ FeatureCount ] ; +805: } ; +806: +807: typedef struct tLangSysRecord { +808: char LangSysTag [ 4 ] ; +809: USHORT Offset ; +810: local quad next = FTell ( ) ; FSeek ( ScriptTable_table + Offset ) ; +811: local quad LangSys = FTell ( ) ; +812: tLangSysTable LangSysTable ; +813: FSeek ( next ) ; +814: } ; +815: +816: string tLangSysRecordRead ( tLangSysRecord & d ) { +817: return d . LangSysTag ; +818: } +819: +820: typedef struct tScriptRecord { +821: char ScriptTag [ 4 ] ; +822: USHORT Offset ; +823: local quad next = FTell ( ) ; FSeek ( ScriptList + Offset ) ; +824: local quad ScriptTable_table = FTell ( ) ; +825: struct { +826: USHORT DefaultLangSys ; +827: uint16 LangSysCount ; +828: tLangSysRecord LangSysRecord [ LangSysCount ] < optimize = false , read = tLangSysRecordRead > ; +829: +830: } ScriptTable ; +831: FSeek ( ScriptTable_table + ScriptTable . DefaultLangSys ) ; +832: tLangSysTable DefaultLangSysTable ; +833: FSeek ( next ) ; +834: } ; +835: +836: string tScriptRecordRead ( tScriptRecord & d ) { +837: return d . ScriptTag ; +838: } +839: +840: typedef struct tScriptList { +841: USHORT Offset ; +842: local quad next = FTell ( ) ; +843: FSeek ( GSUBorGPOS_table + Offset ) ; +844: local quad ScriptList = FTell ( ) ; +845: uint16 ScriptCount ; +846: tScriptRecord ScriptRecord [ ScriptCount ] < read = tScriptRecordRead , optimize = false > ; +847: +848: FSeek ( next ) ; +849: } ; +850: +851: string tScriptListRead ( tScriptList & d ) { +852: string s ; +853: SPrintf ( s , "%u scripts" , d . ScriptCount ) ; +854: return s ; +855: } +856: +857: typedef struct tFeatureRecord { +858: char FeatureTag [ 4 ] ; +859: USHORT Offset ; +860: local quad next = FTell ( ) ; FSeek ( FeatureList + Offset ) ; +861: local quad FeatureTable_table = FTell ( ) ; +862: struct { +863: uint16 FeatureParams ; +864: uint16 LookupListCount ; +865: uint16 LookupListIndex [ LookupListCount ] < optimize = false > ; +866: } FeatureTable < optimize = false > ; +867: FSeek ( next ) ; +868: } ; +869: +870: string tFeatureRecordRead ( tFeatureRecord & d ) { +871: return d . FeatureTag ; +872: } +873: +874: typedef struct tFeatureList { +875: USHORT Offset ; +876: local quad next = FTell ( ) ; +877: FSeek ( GSUBorGPOS_table + Offset ) ; +878: local quad FeatureList = FTell ( ) ; +879: uint16 FeatureCount ; +880: tFeatureRecord FeatureRecord [ FeatureCount ] < read = tFeatureRecordRead , optimize = false > ; +881: +882: FSeek ( next ) ; +883: } ; +884: +885: string tFeatureListRead ( tFeatureList & d ) { +886: string s ; +887: SPrintf ( s , "%u Features" , d . FeatureCount ) ; +888: return s ; +889: } +890: +891: +892: typedef struct tLookupRecord { +893: USHORT Offset ; +894: local quad next = FTell ( ) ; +895: FSeek ( LookupList_table + Offset ) ; +896: uint16 LookupType ; +897: uint16 LookupFlag ; +898: uint16 SubTableCount ; +899: USHORT SubTable [ SubTableCount ] ; +900: FSeek ( next ) ; +901: } ; +902: +903: typedef struct tLookupList { +904: USHORT Offset ; +905: local quad next = FTell ( ) ; +906: FSeek ( GSUBorGPOS_table + Offset ) ; +907: local quad LookupList_table = FTell ( ) ; +908: uint16 LookupCount ; +909: tLookupRecord LookupRecord [ LookupCount ] < optimize = false > ; +910: +911: FSeek ( next ) ; +912: } ; +913: +914: typedef struct tGSUBorGPOS { +915: local quad GSUBorGPOS_table = FTell ( ) ; +916: TT_Fixed Version ; +917: tScriptList ScriptList < read = tScriptListRead > ; +918: tFeatureList FeatureList < read = tFeatureListRead > ; +919: tLookupList LookupList ; +920: +921: +922: +923: +924: +925: +926: +927: +928: +929: +930: +931: +932: +933: +934: +935: } ; +936: +937: string tGSUBorGPOSRead ( tGSUBorGPOS & d ) { +938: string s ; +939: SPrintf ( s , "v%.2f" , d . Version / 65535 . 0 ) ; +940: return s ; +941: } +942: +943: +944: struct tOffsetTable OffsetTable ; +945: +946: struct tTable Table [ OffsetTable . numTables ] < read = tTableRead > ; +947: +948: local int currentTable ; +949: +950: int findTable ( char tag [ ] ) { +951: +952: +953: +954: local int i = 0 ; +955: for ( i = 0 ; i < OffsetTable . numTables ; i ++ ) { +956: if ( Strncmp ( Table [ i ] . Tag . asChar , tag , 4 ) == 0 ) { +957: currentTable = i ; +958: FSeek ( Table [ i ] . offset ) ; +959: return i + 1 ; +960: } +961: } +962: return 0 ; +963: } +964: +965: if ( findTable ( "head" ) ) { struct thead head ; } ; +966: if ( findTable ( "hdmx" ) ) { struct thdmx hdmx < read = thdmxRead > ; } ; +967: if ( findTable ( "hhea" ) ) { struct thhea hhea < read = thheaRead > ; } ; +968: if ( findTable ( "hmtx" ) ) { struct thmtx hmtx < read = thmtxRead > ; } ; +969: if ( findTable ( "maxp" ) ) { struct tmaxp maxp < read = tmaxpRead > ; } ; +970: if ( findTable ( "name" ) ) { struct tname name < read = tnameRead > ; } ; +971: if ( findTable ( "post" ) ) { struct tpost post < read = tpostRead > ; } ; +972: +973: if ( findTable ( "cvt " ) ) { struct tcvt cvt ; } ; +974: if ( findTable ( "fpgm" ) ) { struct tfpgm fpgm ; } ; +975: if ( findTable ( "prep" ) ) { struct tprep prep ; } ; +976: +977: if ( findTable ( "GDEF" ) ) { struct tGDEF GDEF ; } ; +978: if ( findTable ( "OS/2" ) ) { struct tOS_2 OS_2 < read = tOS_2Read > ; } ; +979: if ( findTable ( "cmap" ) ) { struct tcmap cmap ; } ; +980: if ( findTable ( "loca" ) ) { struct tloca loca < read = tlocaRead > ; } ; +981: if ( findTable ( "glyf" ) ) { struct tglyf glyf ; } ; +982: +983: if ( findTable ( "DSIG" ) ) { struct tDSIG DSIG < read = tDSIGRead > ; } ; +984: if ( findTable ( "GSUB" ) ) { struct tGSUBorGPOS GSUB < read = tGSUBorGPOSRead > ; } ; +985: if ( findTable ( "GPOS" ) ) { struct tGSUBORGPOS GPOS < read = tGSUBorGPOSRead > ; } ; +986: +987: +988: +989: +990: +991: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/TacxTemplate.bt b/cparser/tests/exp_lex/TacxTemplate.bt new file mode 100644 index 0000000..f9737de --- /dev/null +++ b/cparser/tests/exp_lex/TacxTemplate.bt @@ -0,0 +1,426 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: typedef struct { +14: WORD FileFingerprint ; +15: WORD FileVersion ; +16: DWORD BlockCount ; +17: } HEADER ; +18: +19: typedef struct { +20: +21: WORD BlockFingerprint ; +22: WORD BlockVersion ; +23: DWORD RecordCount ; +24: DWORD RecordSize ; +25: } INFOBLOCK ; +26: +27: typedef struct { +28: DWORD CheckSum ; +29: CHAR CourseName [ 34 ] ; +30: DWORD WattSlopePulse ; +31: DWORD TimeDist ; +32: DOUBLE TotalTimeDist ; +33: DOUBLE EnergyCons ; +34: FLOAT AltitudeStart ; +35: DWORD BrakeCategory ; +36: } GENERALINFO ; +37: +38: typedef struct { +39: FLOAT DurationDistance ; +40: FLOAT PulseSlopeWatts ; +41: FLOAT RollingFriction ; +42: } PROGRAM ; +43: +44: typedef struct { +45: FLOAT Start ; +46: FLOAT End ; +47: CHAR CourseSegmentName [ 66 ] ; +48: CHAR TextFile [ 522 ] ; +49: } COURSEINFO ; +50: +51: typedef struct { +52: CHAR VideoFileName [ 522 ] ; +53: FLOAT FrameRate ; +54: FLOAT OrgRunWeight ; +55: INT FrameOffset ; +56: } RLVINFO ; +57: +58: typedef struct { +59: UINT16 Year ; +60: UINT16 Month ; +61: UINT16 DayOfWeek ; +62: UINT16 DayOfMonth ; +63: UINT16 Hour ; +64: UINT16 Minute ; +65: UINT16 Second ; +66: UINT16 Millisecond ; +67: FLOAT RecordInterval ; +68: DOUBLE Distance ; +69: DOUBLE Duration ; +70: INT32 CoolDownCount ; +71: UINT32 NotFinished ; +72: BYTE HRMin ; +73: BYTE HRMax ; +74: CHAR Feeling [ 42 ] ; +75: CHAR Temperature [ 22 ] ; +76: UINT16 VendorID ; +77: UINT16 BrakeType ; +78: UINT32 SerialNo ; +79: UINT32 DriverVersion ; +80: UINT16 TrainerYear ; +81: BYTE TrainerMonth ; +82: BYTE TrainerDay ; +83: UINT32 BrakeSerialNo ; +84: UINT32 BrakeVersion ; +85: UINT16 BrakeYear ; +86: BYTE BrakeMonth ; +87: BYTE BrakeDay ; +88: INT16 CalibrationX10 ; +89: BYTE ScaleFactor ; +90: BYTE Reserved_1 ; +91: UINT32 Reserved_2 ; +92: FLOAT CA ; +93: FLOAT Ccw ; +94: FLOAT Crho ; +95: FLOAT Crr ; +96: FLOAT CeffBike ; +97: FLOAT CeffCyclist ; +98: FLOAT Slope ; +99: INT16 AirSpeedAbs ; +100: BYTE BikeMass ; +101: BYTE CyclistWeight ; +102: FLOAT VirtSpeedAccelFactor ; +103: UINT32 Reserved_3 ; +104: UINT32 Reserved_4 ; +105: INT32 LazyMode ; +106: INT32 VRParamExt ; +107: INT32 RLVFlags ; +108: } RIDEINFO_100 ; +109: +110: typedef struct { +111: UINT16 Year ; +112: UINT16 Month ; +113: UINT16 DayOfWeek ; +114: UINT16 DayOfMonth ; +115: UINT16 Hour ; +116: UINT16 Minute ; +117: UINT16 Second ; +118: UINT16 Millisecond ; +119: FLOAT RecordInterval ; +120: DOUBLE Distance ; +121: DOUBLE Duration ; +122: INT32 CoolDownCount ; +123: UINT32 NotFinished ; +124: BYTE HRMin ; +125: BYTE HRMax ; +126: CHAR Feeling [ 42 ] ; +127: CHAR Temperature [ 22 ] ; +128: UINT16 VendorID ; +129: UINT16 BrakeType ; +130: UINT32 SerialNo ; +131: UINT32 DriverVersion ; +132: UINT16 TrainerYear ; +133: BYTE TrainerMonth ; +134: BYTE TrainerDay ; +135: UINT32 BrakeSerialNo ; +136: UINT32 BrakeVersion ; +137: UINT16 BrakeYear ; +138: BYTE BrakeMonth ; +139: BYTE BrakeDay ; +140: INT16 CalibrationX10 ; +141: BYTE ScaleFactor ; +142: BYTE Reserved_1 ; +143: UINT32 Reserved_2 ; +144: FLOAT CA ; +145: FLOAT Ccw ; +146: FLOAT Crho ; +147: FLOAT Crr ; +148: FLOAT CeffBike ; +149: FLOAT CeffCyclist ; +150: FLOAT Slope ; +151: INT16 AirSpeedAbs ; +152: BYTE BikeMass ; +153: BYTE CyclistWeight ; +154: FLOAT VirtSpeedAccelFactor ; +155: UINT32 Reserved_3 ; +156: UINT32 Reserved_4 ; +157: INT32 RLVSlopeAdjustmentPercent ; +158: INT32 VRParamExt ; +159: INT32 RLVFlags ; +160: CHAR CourseName [ 34 ] ; +161: } RIDEINFO_110 ; +162: +163: +164: typedef struct { +165: CHAR Team [ 34 ] ; +166: CHAR RiderName [ 34 ] ; +167: FLOAT Weight ; +168: BYTE Gender ; +169: FLOAT Height ; +170: UINT BirthYear ; +171: BYTE BirthMonth ; +172: BYTE BirthDay ; +173: BYTE HRMax ; +174: BYTE HRRest ; +175: BYTE HRAThreshold ; +176: BYTE HRZone1 ; +177: BYTE HRZone2 ; +178: BYTE HRZone3 ; +179: BYTE HRZone4 ; +180: BYTE HRZone5 ; +181: CHAR Email [ 522 ] ; +182: CHAR Country [ 66 ] ; +183: CHAR Remarks [ 522 ] ; +184: } RIDERINFO ; +185: +186: typedef struct { +187: FLOAT Distance ; +188: BYTE HR ; +189: BYTE Cadence ; +190: UINT16 PowerX10 ; +191: UINT16 SpeedX10 ; +192: } RIDEDATA ; +193: +194: typedef struct { +195: UINT CRC32 ; +196: CHAR SegmentName [ 66 ] ; +197: CHAR InfoFile [ 522 ] ; +198: DOUBLE Distance ; +199: INT32 PrgCnt ; +200: } RLV_MULTICOURSE ; +201: +202: typedef struct { +203: UINT32 CRC32 ; +204: CHAR ProgName [ 34 ] ; +205: INT32 PrgIdx ; +206: DOUBLE DistTimeBeg ; +207: DOUBLE DistTimeEnd ; +208: CHAR Name [ 66 ] ; +209: CHAR InfoFil [ 522 ] ; +210: INT32 LapCount ; +211: } RLV_MULTISECT ; +212: +213: typedef struct { +214: UINT32 FrameNumber ; +215: FLOAT DistancePerFrame ; +216: } RLV_FRAMEDISTANCE ; +217: +218: typedef struct { +219: INT32 Frame ; +220: INT32 Cmd ; +221: } RLV_INFOBOX ; +222: +223: typedef struct { +224: DWORD CheckSum ; +225: CHAR CourseName [ 34 ] ; +226: CHAR Terrain [ 34 ] ; +227: FLOAT RecordInterval ; +228: DOUBLE CourseDistance ; +229: DOUBLE RunTime ; +230: INT32 CoolDownCount ; +231: INT32 RunFlags ; +232: INT32 BrakeType ; +233: } GENERAL_INFO_VR ; +234: +235: typedef struct { +236: FLOAT X ; +237: FLOAT Y ; +238: FLOAT Z ; +239: FLOAT Alpha ; +240: FLOAT Beta ; +241: FLOAT Gamma ; +242: BYTE HeartRate ; +243: BYTE Cadence ; +244: INT16 PowerX10 ; +245: INT16 SpeedX10 ; +246: FLOAT TerrainAngle ; +247: FLOAT ForkAngle ; +248: } COURSE_DATA_VR ; +249: +250: typedef struct { +251: CHAR CourseName [ 34 ] ; +252: CHAR Terrain [ 34 ] ; +253: UINT16 Year ; +254: UINT16 Month ; +255: UINT16 DayOfWeek ; +256: UINT16 DayOfMonth ; +257: UINT16 Hour ; +258: UINT16 Minute ; +259: UINT16 Second ; +260: UINT16 Millisecond ; +261: FLOAT RecordInterval ; +262: DOUBLE Distance ; +263: DOUBLE Duration ; +264: INT32 CoolDownCount ; +265: UINT32 NotFinished ; +266: BYTE HRMin ; +267: BYTE HRMax ; +268: CHAR Feeling [ 42 ] ; +269: CHAR Temperature [ 22 ] ; +270: UINT16 VendorID ; +271: UINT16 BrakeType ; +272: UINT32 SerialNo ; +273: UINT32 DriverVersion ; +274: UINT16 TrainerYear ; +275: BYTE TrainerMonth ; +276: BYTE TrainerDay ; +277: UINT32 BrakeSerialNo ; +278: UINT32 BrakeVersion ; +279: UINT16 BrakeYear ; +280: BYTE BrakeMonth ; +281: BYTE BrakeDay ; +282: INT16 CalibrationX10 ; +283: BYTE ScaleFactor ; +284: BYTE Reserved_1 ; +285: UINT32 Reserved_2 ; +286: FLOAT CA ; +287: FLOAT Ccw ; +288: FLOAT Crho ; +289: FLOAT Crr ; +290: FLOAT CeffBike ; +291: FLOAT CeffCyclist ; +292: FLOAT Slope ; +293: INT16 AirSpeedAbs ; +294: BYTE BikeMass ; +295: BYTE CyclistWeight ; +296: FLOAT VirtSpeedAccelFactor ; +297: UINT32 Reserved_3 ; +298: UINT32 Reserved_4 ; +299: INT32 LazyMode ; +300: INT32 VRParamExt ; +301: INT32 CollisionsOn ; +302: FLOAT WindStrength ; +303: FLOAT WindDirection ; +304: FLOAT ScaleFactor2 ; +305: INT32 CrashTimesCount ; +306: } RIDEINFO_VR ; +307: +308: typedef struct { +309: FLOAT X ; +310: FLOAT Y ; +311: FLOAT Z ; +312: FLOAT Alpha ; +313: FLOAT Beta ; +314: FLOAT Gamma ; +315: BYTE HR ; +316: BYTE Cadence ; +317: UINT16 PowerX10 ; +318: UINT16 SpeedX10 ; +319: FLOAT TerrainAngle ; +320: FLOAT ForkAngle ; +321: } RIDEDATA_VR ; +322: +323: typedef struct { +324: UINT32 LapTime ; +325: } LAPDATA ; +326: +327: +328: LittleEndian ( ) ; +329: +330: HEADER head ; +331: +332: +333: if ( head . FileFingerprint != 4000 +334: && head . FileFingerprint != 3000 +335: && head . FileFingerprint != 2000 +336: && head . FileFingerprint != 1000 ) +337: { +338: Warning ( "File is not a Tacx file. Template stopped." ) ; +339: return - 1 ; +340: } +341: local int i ; +342: +343: for ( i = 0 ; i < head . BlockCount ; i ++ ) +344: { +345: INFOBLOCK blk ; +346: if ( blk . BlockFingerprint == 1010 ) +347: { +348: GENERALINFO ginfo [ blk . RecordCount ] ; +349: } +350: else if ( blk . BlockFingerprint == 2040 ) +351: { +352: COURSEINFO courseinfo [ blk . RecordCount ] ; +353: } +354: else if ( blk . BlockFingerprint == 1020 ) +355: { +356: PROGRAM pdata [ blk . RecordCount ] ; +357: } +358: else if ( blk . BlockFingerprint == 210 ) +359: { +360: RIDERINFO rinfo ; +361: } +362: else if ( blk . BlockFingerprint == 2010 ) +363: { +364: RLVINFO rlvinfo ; +365: } +366: else if ( blk . BlockFingerprint == 3010 ) +367: { +368: if ( blk . BlockVersion == 100 ) +369: RIDEINFO_100 rideinfo ; +370: else if ( blk . BlockVersion == 110 ) +371: RIDEINFO_110 rideinfo ; +372: } +373: else if ( blk . BlockFingerprint == 120 ) +374: { +375: char notes [ blk . RecordCount * blk . RecordSize ] ; +376: } +377: else if ( blk . BlockFingerprint == 3020 ) +378: { +379: RIDEDATA ride [ blk . RecordCount ] ; +380: } +381: else if ( blk . BlockFingerprint == 6010 ) +382: { +383: RLV_MULTICOURSE rlvmcourse ; +384: } +385: else if ( blk . BlockFingerprint == 6020 ) +386: { +387: RLV_MULTISECT rlvmsect ; +388: } +389: else if ( blk . BlockFingerprint == 130 ) +390: { +391: DOUBLE unkown_130 ; +392: } +393: else if ( blk . BlockFingerprint == 2020 ) +394: { +395: RLV_FRAMEDISTANCE rlvfd [ blk . RecordCount ] ; +396: } +397: else if ( blk . BlockFingerprint == 2030 ) +398: { +399: RLV_INFOBOX iboxes [ blk . RecordCount ] ; +400: } +401: else if ( blk . BlockFingerprint == 4010 ) +402: { +403: GENERAL_INFO_VR ginfovr [ blk . RecordCount ] ; +404: } +405: else if ( blk . BlockFingerprint == 4020 ) +406: { +407: COURSE_DATA_VR cdatavr [ blk . RecordCount ] ; +408: } +409: else if ( blk . BlockFingerprint == 4030 ) +410: { +411: RIDEINFO_VR rinfovr [ blk . RecordCount ] ; +412: } +413: else if ( blk . BlockFingerprint == 110 ) +414: { +415: LAPDATA lapdata [ blk . RecordCount ] ; +416: } +417: else if ( blk . BlockFingerprint == 4040 ) +418: { +419: RIDEDATA_VR ridedata_vr [ blk . RecordCount ] ; +420: } +421: else +422: { +423: Warning ( "Unknown Block Fingerprint" ) ; +424: return - 1 ; +425: } +426: } tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/VHDTemplate.bt b/cparser/tests/exp_lex/VHDTemplate.bt new file mode 100644 index 0000000..01a0aea --- /dev/null +++ b/cparser/tests/exp_lex/VHDTemplate.bt @@ -0,0 +1,197 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: BigEndian ( ) ; +12: typedef uint64 ULONGLONG ; +13: +14: enum < DWORD > OS { +15: OS_WI2R = 0x57693272 , +16: OS_WINDOWS = 0x5769326B , +17: OS_W2RU = 0x57327275 , +18: OS_W2KU = 0x57326B75 , +19: OS_MACINTOSH = 0x4D616320 , +20: OS_MACX = 0x4D163258 , +21: } ; +22: +23: enum < DWORD > DISK { +24: NONE = 0x0 , +25: DEPRECATE = 0x1 , +26: FIXED = 0x2 , +27: DYNAMIC = 0x3 , +28: DIFFERENCING = 0x4 , +29: DEPRECATE1 = 0x5 , +30: DEPRECATE2 = 0x6 , +31: } ; +32: +33: typedef struct { +34: char cookie [ 8 ] ; +35: DWORD Features < read = feaRead > ; +36: DWORD FileformatVersion ; +37: ULONGLONG DataOffset < comment = OffsetCheck > ; +38: time_t TimeStamp < read = CorrectTime > ; +39: char CreaterApplication [ 4 ] ; +40: DWORD CreaterVersion ; +41: OS CreaterHostOS ; +42: ULONGLONG OrginalSize ; +43: ULONGLONG CurrentSize ; +44: struct { +45: WORD Cylinder ; +46: BYTE Heads ; +47: BYTE SectorsPerCylinder ; +48: } DiskGeometry ; +49: DISK DiskType ; +50: DWORD CheckSum < comment = "Checksum Of footer" > ; +51: BYTE UUID [ 16 ] ; +52: BYTE SavedState < read = statecheck > ; +53: BYTE hidden ; +54: BYTE Reserved [ 426 ] ; +55: } FOOTER < size = 512 , open = true > ; +56: +57: string statecheck ( BYTE SavedState ) +58: { +59: if ( 0x1 == SavedState ) return "In saved state" ; +60: return "not saved" ; +61: } +62: +63: string feaRead ( WORD Features ) +64: { +65: string s ; +66: if ( Features & 0x1 ) { s = s + "Temporary, " ; } +67: if ( Features & 0x2 ) { s = s + "Reserved, " ; } +68: return s ; +69: } +70: +71: string CorrectTime ( time_t TimeStamp ) +72: { +73: +74: +75: return TimeTToString ( ( DWORD ) TimeStamp + 946684800 ) ; +76: } +77: +78: string OffsetCheck ( ULONGLONG DataOffset ) +79: { +80: if ( ( DataOffset & 0xFFFFFFFF ) == 0xFFFFFFFF ) +81: { +82: return "Fixed disks" ; +83: } +84: return "" ; +85: } +86: +87: typedef struct { +88: char Cookie [ 8 ] ; +89: ULONGLONG DataOffset ; +90: ULONGLONG TableOffset ; +91: DWORD HeaderVersion ; +92: DWORD MaxTableEntries ; +93: DWORD BlockSize < comment = sizecmt > ; +94: DWORD Checksum ; +95: BYTE ParentUUID [ 16 ] ; +96: time_t ParentTimeStamp < read = CorrectTime > ; +97: DWORD reserved ; +98: BYTE parentUnicodeName [ 512 ] ; +99: typedef struct { +100: DWORD PlatformCode ; +101: DWORD PlatformDataSpace ; +102: DWORD PlatformDataLength ; +103: DWORD reserved ; +104: ULONGLONG PlatformDataOffset ; +105: } ENTRY ; +106: +107: ENTRY ParentLocatorEntry [ 8 ] ; +108: BYTE reserved1 [ 256 ] ; +109: } DYNAMICDISKHDEAR < size = 1024 > ; +110: +111: string sizecmt ( DWORD blocksize ) +112: { +113: string s ; +114: SPrintf ( s , "block siez:%dMB" , blocksize / 1024 / 1024 ) ; +115: return s ; +116: } +117: +118: +119: FOOTER copyOfFooter ; +120: DYNAMICDISKHDEAR DynamicDiskHeader ; +121: FSeek ( DynamicDiskHeader . TableOffset ) ; +122: struct { +123: DWORD entry [ DynamicDiskHeader . MaxTableEntries ] < comment = entryCmt > ; +124: } bat < open = true > ; +125: +126: string entryCmt ( DWORD entry ) +127: { +128: if ( 0xFFFFFFFF == entry ) return "Unused" ; +129: return "" ; +130: } +131: +132: +133: typedef struct { +134: char magic [ 8 ] ; +135: ULONGLONG batmap_offset ; +136: DWORD batmap_size ; +137: DWORD batmap_version ; +138: DWORD Checksum ; +139: } TDBATMAP ; +140: +141: char magic [ 8 ] ; +142: +143: if ( Memcmp ( magic , "tdbatmap" , 8 ) == 0 ) +144: { +145: TDBATMAP batmap ; +146: } else { +147: FSkip ( - 8 ) ; +148: } +149: +150: +151: local int index = 0 ; +152: local int BytesInSector = 512 ; +153: +154: local int SectorsPerBlock = DynamicDiskHeader . BlockSize / BytesInSector ; +155: local int BitmapBytes = SectorsPerBlock / 8 ; +156: +157: +158: +159: typedef struct { +160: BYTE bitmap [ BitmapBytes ] ; +161: BYTE data [ DynamicDiskHeader . BlockSize ] ; +162: } DATABLOCK ; +163: +164: +165: +166: do { +167: +168: if ( bat . entry [ index ] != 0xFFFFFFFF ) { +169: Printf ( "Block[%d] -> VHD sector:0x%x" , index , bat . entry [ index ] ) ; +170: Printf ( " VHD offset:0x%x\n" , bat . entry [ index ] * 512 ) ; +171: FSeek ( bat . entry [ index ] * 512 ) ; +172: DATABLOCK data ; +173: } else { +174: +175: } +176: index ++ ; +177: } while ( index < DynamicDiskHeader . MaxTableEntries ) ; +178: +179: +180: FSeek ( FileSize ( ) - 512 ) ; +181: FOOTER Footer ; +182: +183: +184: +185: string readData ( uint64 offset ) +186: { +187: local uint64 BlockIndex = offset / SectorsPerBlock ; +188: local uint64 sectorIndex = offset % SectorsPerBlock ; +189: +190: local uint64 byteoffset = offset / 8 ; +191: local uint64 bitfield = offset % 8 ; +192: if ( bitfield & data [ BlockIndex ] . bitmap [ byteoffset ] ) { +193: +194: Printf ( "Zeros sector" ) ; +195: } +196: +197: } tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/WAVTemplate.bt b/cparser/tests/exp_lex/WAVTemplate.bt new file mode 100644 index 0000000..aeaec86 --- /dev/null +++ b/cparser/tests/exp_lex/WAVTemplate.bt @@ -0,0 +1,232 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: typedef char ID [ 4 ] ; +13: +14: +15: local int haveValidFormat = false ; +16: +17: +18: +19: +20: +21: typedef struct +22: { +23: ID groupID ; +24: long size ; +25: ID riffType ; +26: } WAVRIFFHEADER ; +27: +28: +29: typedef struct { +30: ID chunkID ; +31: long chunkSize ; +32: local int pos = FTell ( ) ; +33: short wFormatTag ; +34: unsigned short wChannels ; +35: unsigned long dwSamplesPerSec ; +36: unsigned long dwAvgBytesPerSec ; +37: unsigned short wBlockAlign ; +38: unsigned short wBitsPerSample ; +39: +40: +41: haveValidFormat = true ; +42: +43: +44: if ( chunkSize > ( FTell ( ) - pos ) ) +45: uchar unknown [ chunkSize - ( FTell ( ) - pos ) ] ; +46: +47: +48: if ( chunkSize & 1 ) +49: uchar padding ; +50: } FORMATCHUNK ; +51: +52: +53: typedef struct +54: { +55: ID chunkID ; +56: long chunkSize ; +57: +58: +59: if ( ! haveValidFormat ) +60: { +61: Warning ( "File contains no valid WAVE format chunk." ) ; +62: return - 1 ; +63: } +64: +65: +66: if ( ( ( format . wBitsPerSample != 8 ) && ( format . wBitsPerSample != 16 ) && ( format . wBitsPerSample != 32 ) ) +67: || ( chunkSize % ( int ) format . wBlockAlign != 0 ) ) +68: { +69: +70: unsigned char waveformData [ chunkSize ] ; +71: } +72: else if ( ( format . wChannels == 1 ) && ( format . wBitsPerSample == 8 ) ) +73: { +74: +75: uchar samples [ chunkSize ] ; +76: } +77: else if ( ( format . wChannels == 1 ) && ( format . wBitsPerSample == 16 ) ) +78: { +79: +80: short samples [ chunkSize / 2 ] ; +81: } +82: else if ( ( format . wChannels == 1 ) && ( format . wBitsPerSample == 32 ) ) +83: { +84: +85: int samples [ chunkSize / 4 ] ; +86: } +87: else +88: { +89: +90: struct SAMPLES { +91: if ( format . wBitsPerSample == 8 ) +92: uchar channels [ format . wChannels ] ; +93: else if ( format . wBitsPerSample == 16 ) +94: short channels [ format . wChannels ] ; +95: else if ( format . wBitsPerSample == 32 ) +96: int channels [ format . wChannels ] ; +97: } samples [ chunkSize / ( int ) format . wBlockAlign ] ; +98: } +99: +100: +101: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +102: uchar padding ; +103: } DATACHUNK ; +104: +105: +106: typedef struct +107: { +108: ID chunkID ; +109: long chunkSize ; +110: unsigned long uncompressedSize ; +111: } FACTCHUNK ; +112: +113: +114: typedef struct { +115: long dwIdentifier ; +116: long dwPosition ; +117: ID fccChunk ; +118: long dwChunkStart ; +119: long dwBlockStart ; +120: long dwSampleOffset ; +121: } CUEPOINT ; +122: +123: typedef struct { +124: ID chunkID ; +125: long chunkSize ; +126: local int pos = FTell ( ) ; +127: long dwCuePoints ; +128: CUEPOINT points [ dwCuePoints ] ; +129: +130: +131: if ( chunkSize > ( FTell ( ) - pos ) ) +132: uchar unknown [ chunkSize - ( FTell ( ) - pos ) ] ; +133: } CUECHUNK ; +134: +135: +136: typedef struct { +137: ID chunkID ; +138: long chunkSize ; +139: char listData [ chunkSize ] ; +140: +141: +142: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +143: uchar padding ; +144: } LISTSUBCHUNK ; +145: +146: typedef struct { +147: ID chunkID ; +148: long chunkSize ; +149: local quad pos = FTell ( ) ; +150: ID chunkType ; +151: +152: +153: while ( FTell ( ) - pos < chunkSize ) +154: LISTSUBCHUNK subchunk ; +155: +156: +157: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +158: uchar padding ; +159: } LISTCHUNK ; +160: +161: +162: typedef struct { +163: ID chunkID ; +164: long chunkSize ; +165: uchar unknownData [ chunkSize ] ; +166: +167: +168: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +169: uchar padding ; +170: } UNKNOWNCHUNK ; +171: +172: +173: +174: +175: LittleEndian ( ) ; +176: SetBackColor ( cLtPurple ) ; +177: WAVRIFFHEADER header ; +178: +179: +180: if ( header . groupID != "RIFF" || header . riffType != "WAVE" ) +181: { +182: Warning ( "File is not a valid wave file. Template stopped." ) ; +183: return - 1 ; +184: } +185: +186: +187: local char tag [ 5 ] ; +188: local uint size ; +189: while ( ! FEof ( ) ) +190: { +191: +192: ReadBytes ( tag , FTell ( ) , 4 ) ; +193: tag [ 4 ] = 0 ; +194: +195: +196: switch ( tag ) +197: { +198: case "fmt " : +199: SetBackColor ( cLtGray ) ; +200: FORMATCHUNK format ; +201: break ; +202: case "data" : +203: SetBackColor ( cNone ) ; +204: DATACHUNK data ; +205: break ; +206: case "fact" : +207: SetBackColor ( cLtBlue ) ; +208: FACTCHUNK fact ; +209: break ; +210: case "cue " : +211: SetBackColor ( cLtGray ) ; +212: CUECHUNK cue ; +213: break ; +214: case "LIST" : +215: SetBackColor ( cLtYellow ) ; +216: LISTCHUNK list ; +217: break ; +218: default : +219: +220: size = ReadUInt ( FTell ( ) + 4 ) ; +221: Printf ( "Encountered unknown chunk '%s' of size %d at position %Ld.\n" , +222: tag , size , FTell ( ) ) ; +223: SetBackColor ( cNone ) ; +224: UNKNOWNCHUNK unknown ; +225: break ; +226: } +227: } +228: +229: +230: +231: +232: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/WAVTemplateAdv.bt b/cparser/tests/exp_lex/WAVTemplateAdv.bt new file mode 100644 index 0000000..1515691 --- /dev/null +++ b/cparser/tests/exp_lex/WAVTemplateAdv.bt @@ -0,0 +1,561 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: typedef char ID [ 4 ] ; +16: +17: +18: local int haveValidFormat = false ; +19: +20: +21: +22: +23: +24: typedef struct +25: { +26: ID groupID ; +27: long size ; +28: ID riffType ; +29: } WAVRIFFHEADER ; +30: +31: +32: typedef struct { +33: ID chunkID ; +34: long chunkSize ; +35: local int pos = FTell ( ) ; +36: short wFormatTag ; +37: unsigned short wChannels ; +38: unsigned long dwSamplesPerSec ; +39: unsigned long dwAvgBytesPerSec ; +40: unsigned short wBlockAlign ; +41: unsigned short wBitsPerSample ; +42: +43: +44: haveValidFormat = true ; +45: +46: +47: if ( chunkSize > ( FTell ( ) - pos ) ) +48: uchar unknown [ chunkSize - ( FTell ( ) - pos ) ] ; +49: +50: +51: if ( chunkSize & 1 ) +52: uchar padding ; +53: } FORMATCHUNK ; +54: +55: +56: typedef struct +57: { +58: ID chunkID ; +59: long chunkSize ; +60: +61: +62: if ( ! haveValidFormat ) +63: { +64: Warning ( "File contains no valid WAVE format chunk." ) ; +65: return - 1 ; +66: } +67: +68: +69: if ( ( ( format . wBitsPerSample != 8 ) && ( format . wBitsPerSample != 16 ) && ( format . wBitsPerSample != 32 ) ) +70: || ( chunkSize % ( int ) format . wBlockAlign != 0 ) ) +71: { +72: +73: unsigned char waveformData [ chunkSize ] ; +74: } +75: else if ( ( format . wChannels == 1 ) && ( format . wBitsPerSample == 8 ) ) +76: { +77: +78: uchar samples [ chunkSize ] ; +79: } +80: else if ( ( format . wChannels == 1 ) && ( format . wBitsPerSample == 16 ) ) +81: { +82: +83: short samples [ chunkSize / 2 ] ; +84: } +85: else if ( ( format . wChannels == 1 ) && ( format . wBitsPerSample == 32 ) ) +86: { +87: +88: int samples [ chunkSize / 4 ] ; +89: } +90: else +91: { +92: +93: struct SAMPLES { +94: if ( format . wBitsPerSample == 8 ) +95: uchar channels [ format . wChannels ] ; +96: else if ( format . wBitsPerSample == 16 ) +97: short channels [ format . wChannels ] ; +98: else if ( format . wBitsPerSample == 32 ) +99: int channels [ format . wChannels ] ; +100: } samples [ chunkSize / ( int ) format . wBlockAlign ] ; +101: } +102: +103: +104: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +105: uchar padding ; +106: } DATACHUNK ; +107: +108: +109: typedef struct +110: { +111: ID chunkID ; +112: long chunkSize ; +113: unsigned long uncompressedSize ; +114: } FACTCHUNK ; +115: +116: +117: typedef struct { +118: long dwIdentifier ; +119: long dwPosition ; +120: ID fccChunk ; +121: long dwChunkStart ; +122: long dwBlockStart ; +123: long dwSampleOffset ; +124: } CUEPOINT ; +125: +126: typedef struct { +127: ID chunkID ; +128: long chunkSize ; +129: local int pos = FTell ( ) ; +130: long dwCuePoints ; +131: CUEPOINT points [ dwCuePoints ] ; +132: +133: +134: if ( chunkSize > ( FTell ( ) - pos ) ) +135: uchar unknown [ chunkSize - ( FTell ( ) - pos ) ] ; +136: } CUECHUNK ; +137: +138: +139: typedef struct { +140: ID chunkID ; +141: long chunkSize ; +142: char listData [ chunkSize ] ; +143: +144: +145: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +146: uchar padding ; +147: } LISTSUBCHUNK ; +148: +149: typedef struct { +150: ID chunkID ; +151: long chunkSize ; +152: local quad pos = FTell ( ) ; +153: ID chunkType ; +154: +155: +156: while ( FTell ( ) - pos < chunkSize ) +157: LISTSUBCHUNK subchunk ; +158: +159: +160: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +161: uchar padding ; +162: } LISTCHUNK ; +163: +164: +165: typedef struct { +166: ID chunkID ; +167: long chunkSize ; +168: uchar unknownData [ chunkSize ] ; +169: +170: +171: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +172: uchar padding ; +173: } UNKNOWNCHUNK ; +174: +175: +176: +177: +178: +179: typedef long SMPLLOOPS_Cue_ID < read = WAV_SMPLLOOPS_Cue_ID > ; +180: +181: string +182: WAV_SMPLLOOPS_Cue_ID ( SMPLLOOPS_Cue_ID cid ) +183: { +184: string sret ; +185: SPrintf ( sret , "Cue Point ID: %u" , cid ) ; +186: +187: return sret ; +188: } +189: +190: +191: +192: typedef long SMPLLOOPS_Play_Count < read = WAV_SMPLLOOPS_Play_Count > ; +193: +194: string +195: WAV_SMPLLOOPS_Play_Count ( SMPLLOOPS_Play_Count pc ) +196: { +197: string sret ; +198: +199: if ( pc == 0 ) +200: { +201: SPrintf ( sret , " Infinite Sustain Loop (%u)" , pc ) ; +202: } +203: else +204: { +205: SPrintf ( sret , "Play Count: %u" , pc ) ; +206: } +207: +208: return sret ; +209: } +210: +211: +212: +213: typedef long SMPLLOOPS_Start < read = WAV_SMPLLOOPS_Start > ; +214: +215: string +216: WAV_SMPLLOOPS_Start ( SMPLLOOPS_Start st ) +217: { +218: string sret ; +219: SPrintf ( sret , "Loop Start at %u byte offset" , st ) ; +220: +221: return sret ; +222: } +223: +224: +225: typedef long SMPLLOOPS_End < read = WAV_SMPLLOOPS_End > ; +226: +227: string +228: WAV_SMPLLOOPS_End ( SMPLLOOPS_End end ) +229: { +230: string sret ; +231: SPrintf ( sret , "Loop End at %u byte offset" , end ) ; +232: +233: return sret ; +234: } +235: +236: +237: typedef long SMPLLOOPS_Fraction < read = WAV_SMPLLOOPS_Fraction > ; +238: +239: string +240: WAV_SMPLLOOPS_Fraction ( SMPLLOOPS_Fraction f ) +241: { +242: string sret ; +243: SPrintf ( sret , "Fraction: %u" , f ) ; +244: +245: return sret ; +246: } +247: +248: +249: typedef long SMPL_SL < read = WAV_SMPL_SL > ; +250: +251: string +252: WAV_SMPL_SL ( SMPL_SL sl ) +253: { +254: string sret ; +255: SPrintf ( sret , "Number of Samples Loops (Sustain Loops): %u" , sl ) ; +256: +257: return sret ; +258: } +259: +260: +261: typedef long SMPL_SD < read = WAV_SMPL_SD > ; +262: +263: string +264: WAV_SMPL_SD ( SMPL_SD sd ) +265: { +266: string sret ; +267: SPrintf ( sret , "Sample Data (number of bytes): %u" , sd ) ; +268: +269: return sret ; +270: } +271: +272: +273: +274: typedef long SMPL_SMPTE_Offset < read = WAV_SMPL_SMPTE_Offset > ; +275: +276: string +277: WAV_SMPL_SMPTE_Offset ( SMPL_SMPTE_Offset so ) +278: { +279: string sret ; +280: SPrintf ( sret , "SMPTE Offset (for synchronization): %u" , so ) ; +281: +282: return sret ; +283: } +284: +285: +286: typedef long SMPL_MIDI_Pitch_Fraction < read = WAV_SMPL_MIDI_Pitch_Fraction > ; +287: +288: string +289: WAV_SMPL_MIDI_Pitch_Fraction ( SMPL_MIDI_Pitch_Fraction pf ) +290: { +291: string sret ; +292: SPrintf ( sret , "MIDI Pitch Fraction: %u" , pf ) ; +293: +294: return sret ; +295: } +296: +297: +298: typedef long SMPL_MIDI_Unity_Note < read = WAV_SMPL_MIDI_Unity_Note > ; +299: +300: string +301: WAV_SMPL_MIDI_Unity_Note ( SMPL_MIDI_Unity_Note un ) +302: { +303: string sret ; +304: SPrintf ( sret , "MIDI unity note value: %u" , un ) ; +305: +306: return sret ; +307: } +308: +309: +310: typedef long SMPL_Product < read = WAV_SMPL_Product > ; +311: +312: string +313: WAV_SMPL_Product ( SMPL_Product product ) +314: { +315: string sret ; +316: SPrintf ( sret , "MIDI model ID (defined by the manufacturer): %u" , product ) ; +317: +318: return sret ; +319: } +320: +321: +322: typedef long SMPL_Sample_Period < read = WAV_SMPL_Sample_Period > ; +323: +324: string +325: WAV_SMPL_Sample_Period ( SMPL_Sample_Period sp ) +326: { +327: string sret ; +328: +329: SPrintf ( sret , "Sample Period: %u" , sp ) ; +330: +331: return sret ; +332: } +333: +334: +335: typedef long SMPL_SMPTE < read = WAV_SMPL_SMPTE > ; +336: +337: string +338: WAV_SMPL_SMPTE ( SMPL_SMPTE smptef ) +339: { +340: string s ; +341: string sret ; +342: +343: switch ( smptef ) +344: { +345: case 0 : SPrintf ( s , "No SMPTE offset" ) ; break ; +346: case 24 : SPrintf ( s , "24 frames per second" ) ; break ; +347: case 25 : SPrintf ( s , "25 frames per second" ) ; break ; +348: case 29 : SPrintf ( s , "30 frames per second with frame dropping (30 drop)" ) ; break ; +349: case 30 : SPrintf ( s , "30 frames per second" ) ; break ; +350: default : SPrintf ( s , "unknown (%u)" , smptef ) ; break ; +351: } +352: +353: SPrintf ( sret , "SMPTE Format: %s" , s ) ; +354: +355: return sret ; +356: } +357: +358: +359: typedef long SMPL_Manufacturer < read = WAV_SMPL_Manufacturer > ; +360: +361: string +362: WAV_SMPL_Manufacturer ( SMPL_Manufacturer manufacture ) +363: { +364: string s ; +365: string sret ; +366: +367: switch ( manufacture ) +368: { +369: case 0 : SPrintf ( s , "Unknown" ) ; break ; +370: case 1 : SPrintf ( s , "Sequential Circuits" ) ; break ; +371: case 2 : SPrintf ( s , "Big Briar" ) ; break ; +372: case 3 : SPrintf ( s , "Octave / Plateau" ) ; break ; +373: case 4 : SPrintf ( s , "Moog" ) ; break ; +374: case 5 : SPrintf ( s , "Passport Designs" ) ; break ; +375: case 6 : SPrintf ( s , "Lexicon" ) ; break ; +376: case 7 : SPrintf ( s , "Kurzweil" ) ; break ; +377: case 8 : SPrintf ( s , "Fender" ) ; break ; +378: case 9 : SPrintf ( s , "Gulbransen" ) ; break ; +379: case 10 : SPrintf ( s , "Delta Labs" ) ; break ; +380: case 11 : SPrintf ( s , "Sound Comp." ) ; break ; +381: case 12 : SPrintf ( s , "General Electro" ) ; break ; +382: case 13 : SPrintf ( s , "Techmar" ) ; break ; +383: case 14 : SPrintf ( s , "Matthews Research" ) ; break ; +384: case 16 : SPrintf ( s , "Oberheim" ) ; break ; +385: case 17 : SPrintf ( s , "PAIA" ) ; break ; +386: case 18 : SPrintf ( s , "Simmons" ) ; break ; +387: case 19 : SPrintf ( s , "DigiDesign" ) ; break ; +388: case 20 : SPrintf ( s , "Fairlight" ) ; break ; +389: case 21 : SPrintf ( s , "JL Cooper" ) ; break ; +390: case 22 : SPrintf ( s , "Lowery" ) ; break ; +391: case 23 : SPrintf ( s , "Lin" ) ; break ; +392: case 24 : SPrintf ( s , "Emu" ) ; break ; +393: case 27 : SPrintf ( s , "Peavey" ) ; break ; +394: case 32 : SPrintf ( s , "Bon Tempi" ) ; break ; +395: case 33 : SPrintf ( s , "S.I.E.L." ) ; break ; +396: case 35 : SPrintf ( s , "SyntheAxe" ) ; break ; +397: case 36 : SPrintf ( s , "Hohner" ) ; break ; +398: case 37 : SPrintf ( s , "Crumar" ) ; break ; +399: case 38 : SPrintf ( s , "Solton" ) ; break ; +400: case 39 : SPrintf ( s , "Jellinghaus Ms" ) ; break ; +401: case 40 : SPrintf ( s , "CTS" ) ; break ; +402: case 41 : SPrintf ( s , "PPG" ) ; break ; +403: case 47 : SPrintf ( s , "Elka" ) ; break ; +404: case 54 : SPrintf ( s , "Cheetah" ) ; break ; +405: case 62 : SPrintf ( s , "Waldorf" ) ; break ; +406: case 64 : SPrintf ( s , "Kawai" ) ; break ; +407: case 65 : SPrintf ( s , "Roland" ) ; break ; +408: case 66 : SPrintf ( s , "Korg" ) ; break ; +409: case 67 : SPrintf ( s , "Yamaha" ) ; break ; +410: case 68 : SPrintf ( s , "Casio" ) ; break ; +411: case 70 : SPrintf ( s , "Kamiya Studio" ) ; break ; +412: case 71 : SPrintf ( s , "Akai" ) ; break ; +413: case 72 : SPrintf ( s , "Victor" ) ; break ; +414: case 75 : SPrintf ( s , "Fujitsu" ) ; break ; +415: case 76 : SPrintf ( s , "Sony" ) ; break ; +416: case 78 : SPrintf ( s , "Teac" ) ; break ; +417: case 80 : SPrintf ( s , "Matsushita" ) ; break ; +418: case 81 : SPrintf ( s , "Fostex" ) ; break ; +419: case 82 : SPrintf ( s , "Zoom" ) ; break ; +420: case 84 : SPrintf ( s , "Matsushita" ) ; break ; +421: case 85 : SPrintf ( s , "Suzuki" ) ; break ; +422: case 86 : SPrintf ( s , "Fuji Sound" ) ; break ; +423: case 87 : SPrintf ( s , "Acoustic Technical Laboratory" ) ; break ; +424: default : SPrintf ( s , "Unknown" ) ; break ; +425: } +426: +427: SPrintf ( sret , "Manufacturer: %s" , s ) ; +428: +429: return sret ; +430: } +431: +432: +433: typedef long SMPLLOOPS_Type < read = WAV_SMPL_Loop_Type > ; +434: +435: string +436: WAV_SMPL_Loop_Type ( SMPLLOOPS_Type loop ) +437: { +438: string s ; +439: +440: switch ( loop ) +441: { +442: case 0 : +443: SPrintf ( s , "Loop: Forward (%u)" , loop ) ; +444: break ; +445: +446: case 1 : +447: SPrintf ( s , "Loop: Ping Pong (%u)" , loop ) ; +448: break ; +449: +450: case 2 : +451: SPrintf ( s , "Loop: Reverse (%u)" , loop ) ; +452: break ; +453: +454: case 3 : +455: SPrintf ( s , "Loop [reserved for future standard types] (%u)" , loop ) ; +456: break ; +457: +458: default : +459: s = "Loop: " ; +460: } +461: +462: return s ; +463: } +464: +465: +466: +467: typedef struct { +468: SMPLLOOPS_Cue_ID Cue_Point ; +469: SMPLLOOPS_Type Type ; +470: SMPLLOOPS_Start Start ; +471: SMPLLOOPS_End End ; +472: SMPLLOOPS_Fraction Fraction ; +473: SMPLLOOPS_Play_Count Play_Count ; +474: +475: } SMPLLOOPS ; +476: +477: +478: +479: typedef struct { +480: ID chunkID ; +481: long chunkSize ; +482: SMPL_Manufacturer Manufacturer ; +483: SMPL_Product Product ; +484: SMPL_Sample_Period Sample_Period ; +485: SMPL_MIDI_Unity_Note MIDI_Unity_Note ; +486: SMPL_MIDI_Pitch_Fraction MIDI_Pitch_Fraction ; +487: SMPL_SMPTE SMPTE ; +488: SMPL_SMPTE_Offset SMPTE_Offset ; +489: SMPL_SL Num_Sample_Loops ; +490: SMPL_SD Sampler_Data ; +491: SMPLLOOPS loops [ Num_Sample_Loops ] ; +492: +493: +494: if ( ( chunkSize & 1 ) && ( FTell ( ) < FileSize ( ) ) ) +495: uchar padding ; +496: +497: } SMPLCHUNK ; +498: +499: +500: +501: +502: +503: +504: LittleEndian ( ) ; +505: SetBackColor ( cLtPurple ) ; +506: WAVRIFFHEADER header ; +507: +508: +509: if ( header . groupID != "RIFF" || header . riffType != "WAVE" ) +510: { +511: Warning ( "File is not a valid wave file. Template stopped." ) ; +512: return - 1 ; +513: } +514: +515: +516: local char tag [ 5 ] ; +517: local uint size ; +518: while ( ! FEof ( ) ) +519: { +520: +521: ReadBytes ( tag , FTell ( ) , 4 ) ; +522: tag [ 4 ] = 0 ; +523: +524: +525: switch ( tag ) +526: { +527: case "fmt " : +528: SetBackColor ( cLtGray ) ; +529: FORMATCHUNK format ; +530: break ; +531: case "data" : +532: SetBackColor ( cNone ) ; +533: DATACHUNK data ; +534: break ; +535: case "fact" : +536: SetBackColor ( cLtBlue ) ; +537: FACTCHUNK fact ; +538: break ; +539: case "cue " : +540: SetBackColor ( cLtGray ) ; +541: CUECHUNK cue ; +542: break ; +543: case "smpl" : +544: SetBackColor ( cLtGray ) ; +545: SMPLCHUNK smpl ; +546: break ; +547: case "LIST" : +548: SetBackColor ( cLtYellow ) ; +549: LISTCHUNK list ; +550: break ; +551: default : +552: +553: size = ReadUInt ( FTell ( ) + 4 ) ; +554: Printf ( "Encountered unknown chunk '%s' of size %d at position %Ld.\n" , +555: tag , size , FTell ( ) ) ; +556: SetBackColor ( cNone ) ; +557: UNKNOWNCHUNK unknown ; +558: break ; +559: } +560: } +561: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/WMFTemplate.bt b/cparser/tests/exp_lex/WMFTemplate.bt new file mode 100644 index 0000000..718cdb4 --- /dev/null +++ b/cparser/tests/exp_lex/WMFTemplate.bt @@ -0,0 +1,429 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: typedef struct +15: { +16: DWORD Key ; +17: WORD Handle ; +18: SHORT Left ; +19: SHORT Top ; +20: SHORT Right ; +21: SHORT Bottom ; +22: WORD Inch ; +23: DWORD Reserved ; +24: WORD Checksum < read = CalcCheckSum > ; +25: } WMFSPECIAL ; +26: +27: typedef struct +28: { +29: WORD FileType ; +30: WORD HeaderSize ; +31: WORD Version ; +32: DWORD FileSize < read = CheckFileSize > ; +33: WORD NumOfObjects ; +34: DWORD MaxRecordSize ; +35: WORD NoParameters ; +36: } WMFHEAD ; +37: +38: typedef struct +39: { +40: DWORD Size ; +41: WORD Function < read = ReadFunction > ; +42: WORD Parmeters [ Size - 3 ] ; +43: } WMFRECORD ; +44: +45: +46: string ReadFunction ( WORD function ) +47: { +48: string result ; +49: +50: switch ( function ) +51: { +52: case 0x0 : +53: result = "EOF" ; +54: break ; +55: +56: case 0x1E : +57: result = "SaveDC" ; +58: break ; +59: +60: case 0x35 : +61: result = "RealizePalette" ; +62: break ; +63: +64: case 0x37 : +65: result = "SetPalEntries" ; +66: break ; +67: +68: case 0x4F : +69: result = "StartPage" ; +70: break ; +71: +72: case 0x50 : +73: result = "EndPage" ; +74: break ; +75: +76: case 0x52 : +77: result = "AbortDoc" ; +78: break ; +79: +80: case 0x5E : +81: result = "EndDoc" ; +82: break ; +83: +84: case 0xF7 : +85: result = "CreatePalette" ; +86: break ; +87: +88: case 0xF8 : +89: result = "CreateBrush" ; +90: break ; +91: +92: case 0x102 : +93: result = "SetBkMode" ; +94: break ; +95: +96: case 0x103 : +97: result = "SetMapMode" ; +98: break ; +99: +100: case 0x104 : +101: result = "SetROP2" ; +102: break ; +103: +104: case 0x105 : +105: result = "SetRelabs" ; +106: break ; +107: +108: case 0x106 : +109: result = "SetPolyFillMode" ; +110: break ; +111: +112: case 0x107 : +113: result = "SetStretchBltMode" ; +114: break ; +115: +116: case 0x108 : +117: result = "SetTextCharExtra" ; +118: break ; +119: +120: case 0x127 : +121: result = "RestoreDC" ; +122: break ; +123: +124: case 0x12A : +125: result = "InvertRegion" ; +126: break ; +127: +128: case 0x12B : +129: result = "PaintRegion" ; +130: break ; +131: +132: case 0x12C : +133: result = "SelectClipRegion" ; +134: break ; +135: +136: case 0x12D : +137: result = "SelectObject" ; +138: break ; +139: +140: case 0x12E : +141: result = "SetTextAlign" ; +142: break ; +143: +144: case 0x139 : +145: result = "ResizePalette" ; +146: break ; +147: +148: case 0x142 : +149: result = "DibCreatePatternBrush" ; +150: break ; +151: +152: case 0x14C : +153: result = "ResetDc" ; +154: break ; +155: +156: case 0x14D : +157: result = "StartDoc" ; +158: break ; +159: +160: case 0x1F0 : +161: result = "DeleteObject" ; +162: break ; +163: +164: case 0x1F9 : +165: result = "CreatePatternBrush" ; +166: break ; +167: +168: case 0x1F0 : +169: result = "DeleteObject" ; +170: break ; +171: +172: case 0x201 : +173: result = "SetBkColor" ; +174: break ; +175: +176: case 0x209 : +177: result = "SetTextColor" ; +178: break ; +179: +180: case 0x20A : +181: result = "SetTextJustification" ; +182: break ; +183: +184: case 0x20B : +185: result = "SetWindowOrg" ; +186: break ; +187: +188: case 0x20C : +189: result = "SetWindowExt" ; +190: break ; +191: +192: case 0x20D : +193: result = "SetViewportOrg" ; +194: break ; +195: +196: case 0x20E : +197: result = "SetViewportExt" ; +198: break ; +199: +200: case 0x20F : +201: result = "OffsetWindowOrg" ; +202: break ; +203: +204: case 0x211 : +205: result = "OffsetViewportOrg" ; +206: break ; +207: +208: case 0x213 : +209: result = "LineTo" ; +210: break ; +211: +212: case 0x214 : +213: result = "MoveTo" ; +214: break ; +215: +216: case 0x220 : +217: result = "OffsetClipRgn" ; +218: break ; +219: +220: case 0x228 : +221: result = "FillRegion" ; +222: break ; +223: +224: case 0x231 : +225: result = "SetMapperFlags" ; +226: break ; +227: +228: case 0x234 : +229: result = "SelectPalette" ; +230: break ; +231: +232: case 0x2FA : +233: result = "CreatePenIndirect" ; +234: break ; +235: +236: case 0x2FB : +237: result = "CreateFontIndirect" ; +238: break ; +239: +240: case 0x2FC : +241: result = "CreateBrushIndirect" ; +242: break ; +243: +244: case 0x2FD : +245: result = "CreateBitmapIndirect" ; +246: break ; +247: +248: case 0x324 : +249: result = "Polygon" ; +250: break ; +251: +252: case 0x325 : +253: result = "Polyline" ; +254: break ; +255: +256: case 0x410 : +257: result = "ScaleWindowExt" ; +258: break ; +259: +260: case 0x412 : +261: result = "ScaleViewportExt" ; +262: break ; +263: +264: case 0x415 : +265: result = "ExcludeClipRect" ; +266: break ; +267: +268: case 0x416 : +269: result = "IntersectClipRect" ; +270: break ; +271: +272: case 0x418 : +273: result = "Ellipse" ; +274: break ; +275: +276: case 0x419 : +277: result = "FloodFill" ; +278: break ; +279: +280: case 0x41B : +281: result = "Rectangle" ; +282: break ; +283: +284: case 0x41F : +285: result = "SetPixel" ; +286: break ; +287: +288: case 0x429 : +289: result = "FrameRegion" ; +290: break ; +291: +292: case 0x436 : +293: result = "AnimatePalette" ; +294: break ; +295: +296: case 0x521 : +297: result = "TextOut" ; +298: break ; +299: +300: case 0x538 : +301: result = "PolyPolygon" ; +302: break ; +303: +304: case 0x548 : +305: result = "ExtFloodFill" ; +306: break ; +307: +308: case 0x61C : +309: result = "RoundRect" ; +310: break ; +311: +312: case 0x61D : +313: result = "PatBlt" ; +314: break ; +315: +316: case 0x626 : +317: result = "Escape" ; +318: break ; +319: +320: case 0x62F : +321: result = "DrawText" ; +322: break ; +323: +324: case 0x6FE : +325: result = "CreateBitmap" ; +326: break ; +327: +328: case 0x6FF : +329: result = "CreateRegion" ; +330: break ; +331: +332: case 0x817 : +333: result = "Arc" ; +334: break ; +335: +336: case 0x81A : +337: result = "Pie" ; +338: break ; +339: +340: case 0x830 : +341: result = "Chord" ; +342: break ; +343: +344: case 0x922 : +345: result = "BitBlt" ; +346: break ; +347: +348: case 0x940 : +349: result = "DibBitblt" ; +350: break ; +351: +352: case 0xA32 : +353: result = "ExtTextOut" ; +354: break ; +355: +356: case 0xB23 : +357: result = "StretchBlt" ; +358: break ; +359: +360: case 0xB41 : +361: result = "DibStretchBlt" ; +362: break ; +363: +364: case 0xF43 : +365: result = "StretchDIBits" ; +366: break ; +367: +368: case 0xD33 : +369: result = "SetDibToDev" ; +370: break ; +371: +372: default : +373: SPrintf ( result , "0x%04X" , function ) ; +374: } +375: return result ; +376: } +377: +378: string CalcCheckSum ( WORD checksum ) +379: { +380: string result ; +381: int i ; +382: WORD calculatedchecksum = 0 ; +383: +384: for ( i = 0 ; i < 10 ; i ++ ) +385: calculatedchecksum ^= ReadUInt ( i * 2 ) ; +386: +387: if ( checksum == calculatedchecksum ) +388: SPrintf ( result , "%04X" , checksum ) ; +389: else +390: SPrintf ( result , "NOK: stored: 0x%04X calculated: 0x%04X" , checksum , calculatedchecksum ) ; +391: +392: return result ; +393: } +394: +395: string CheckFileSize ( WORD FileSize ) +396: { +397: string result ; +398: WORD actualFileSize = FileSize ( ) / 2 ; +399: +400: if ( IsSpecial ) +401: actualFileSize -= 11 ; +402: if ( FileSize == actualFileSize ) +403: SPrintf ( result , "0x%04X" , FileSize ) ; +404: else +405: SPrintf ( result , "NOK: stored: 0x%04X actual: 0x%04X" , FileSize , actualFileSize ) ; +406: +407: return result ; +408: } +409: +410: +411: LittleEndian ( ) ; +412: local int IsSpecial = 0 ; +413: if ( 0x9AC6CDD7 == ReadQuad ( 0 ) ) +414: { +415: WMFSPECIAL special ; +416: IsSpecial = 1 ; +417: } +418: WMFHEAD header ; +419: +420: local int recCnt = 0 ; +421: while ( ! FEof ( ) ) +422: { +423: WMFRECORD record ; +424: recCnt ++ ; +425: } +426: +427: if ( recCnt != header . NumOfObjects ) +428: Warning ( "%d objects declared and %d objects counted" , header . NumOfObjects , recCnt ) ; +429: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/WinhexPosTemplate.bt b/cparser/tests/exp_lex/WinhexPosTemplate.bt new file mode 100644 index 0000000..88f21b6 --- /dev/null +++ b/cparser/tests/exp_lex/WinhexPosTemplate.bt @@ -0,0 +1,34 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: string Wh_WinhexID < comment = "file signature" > ; +14: uint32 Wh_Flags < comment = "currently - 0x00, 0X01 - Unicode" > ; +15: uint32 Wh_n_ch < comment = "number of chunks" > ; +16: struct chunk { +17: uint16 Chsize < comment = "chunk size" > ; +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: +33: } wh_pos [ Wh_n_ch ] < optimize = false > ; +34: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/ZIPTemplate.bt b/cparser/tests/exp_lex/ZIPTemplate.bt new file mode 100644 index 0000000..7cad195 --- /dev/null +++ b/cparser/tests/exp_lex/ZIPTemplate.bt @@ -0,0 +1,196 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: typedef enum < short > { +21: COMP_STORED = 0 , +22: COMP_SHRUNK = 1 , +23: COMP_REDUCED1 = 2 , +24: COMP_REDUCED2 = 3 , +25: COMP_REDUCED3 = 4 , +26: COMP_REDUCED4 = 5 , +27: COMP_IMPLODED = 6 , +28: COMP_TOKEN = 7 , +29: COMP_DEFLATE = 8 , +30: COMP_DEFLATE64 = 9 +31: } COMPTYPE ; +32: +33: +34: typedef struct { +35: +36: char frSignature [ 4 ] ; +37: ushort frVersion ; +38: ushort frFlags ; +39: COMPTYPE frCompression ; +40: DOSTIME frFileTime ; +41: DOSDATE frFileDate ; +42: uint frCrc < format = hex > ; +43: uint frCompressedSize ; +44: uint frUncompressedSize ; +45: ushort frFileNameLength ; +46: ushort frExtraFieldLength ; +47: if ( frFileNameLength > 0 ) +48: char frFileName [ frFileNameLength ] ; +49: if ( frExtraFieldLength > 0 ) +50: uchar frExtraField [ frExtraFieldLength ] ; +51: +52: +53: SetBackColor ( cNone ) ; +54: if ( frCompressedSize > 0 ) +55: uchar frData [ frCompressedSize ] ; +56: +57: } ZIPFILERECORD < read = ReadZIPFILERECORD , write = WriteZIPFILERECORD > ; +58: +59: +60: typedef struct { +61: char deSignature [ 4 ] ; +62: ushort deVersionMadeBy ; +63: ushort deVersionToExtract ; +64: ushort deFlags ; +65: COMPTYPE deCompression ; +66: DOSTIME deFileTime ; +67: DOSDATE deFileDate ; +68: uint deCrc < format = hex > ; +69: uint deCompressedSize ; +70: uint deUncompressedSize ; +71: ushort deFileNameLength ; +72: ushort deExtraFieldLength ; +73: ushort deFileCommentLength ; +74: ushort deDiskNumberStart ; +75: ushort deInternalAttributes ; +76: uint deExternalAttributes ; +77: uint deHeaderOffset ; +78: if ( deFileNameLength > 0 ) +79: char deFileName [ deFileNameLength ] ; +80: if ( deExtraFieldLength > 0 ) +81: uchar deExtraField [ deExtraFieldLength ] ; +82: if ( deFileCommentLength > 0 ) +83: uchar deFileComment [ deFileCommentLength ] ; +84: } ZIPDIRENTRY < read = ReadZIPDIRENTRY > ; +85: +86: +87: typedef struct { +88: char dsSignature [ 4 ] ; +89: ushort dsDataLength ; +90: if ( dsDataLength > 0 ) +91: uchar dsData [ dsDataLength ] ; +92: } ZIPDIGITALSIG ; +93: +94: +95: typedef struct { +96: char ddSignature [ 4 ] ; +97: uint ddCRC < format = hex > ; +98: uint ddCompressedSize ; +99: uint ddUncompressedSize ; +100: } ZIPDATADESCR ; +101: +102: +103: typedef struct { +104: char elSignature [ 4 ] ; +105: ushort elDiskNumber ; +106: ushort elStartDiskNumber ; +107: ushort elEntriesOnDisk ; +108: ushort elEntriesInDirectory ; +109: uint elDirectorySize ; +110: uint elDirectoryOffset ; +111: ushort elCommentLength ; +112: if ( elCommentLength > 0 ) +113: char elComment [ elCommentLength ] ; +114: } ZIPENDLOCATOR ; +115: +116: +117: +118: +119: +120: +121: string ReadZIPFILERECORD ( ZIPFILERECORD & file ) +122: { +123: if ( exists ( file . frFileName ) ) +124: return file . frFileName ; +125: else +126: return "" ; +127: } +128: +129: string ReadZIPDIRENTRY ( ZIPDIRENTRY & entry ) +130: { +131: if ( exists ( entry . deFileName ) ) +132: return entry . deFileName ; +133: else +134: return "" ; +135: } +136: +137: +138: +139: +140: +141: void WriteZIPFILERECORD ( ZIPFILERECORD & file , string s ) +142: { +143: local int len = Strlen ( s ) ; +144: if ( exists ( file . frFileName ) ) +145: { +146: Strncpy ( file . frFileName , s , file . frFileNameLength ) ; +147: if ( len < file . frFileNameLength ) +148: file . frFileName [ len ] = 0 ; +149: } +150: } +151: +152: +153: +154: +155: local uint tag ; +156: LittleEndian ( ) ; +157: while ( ! FEof ( ) ) +158: { +159: +160: tag = ReadUInt ( FTell ( ) ) ; +161: +162: +163: +164: +165: +166: if ( tag == 0x4034B50 ) +167: { +168: SetBackColor ( cLtGray ) ; +169: ZIPFILERECORD record ; +170: } +171: else if ( tag == 0x8074B50 ) +172: { +173: SetBackColor ( cLtGreen ) ; +174: ZIPDATADESCR dataDescr ; +175: } +176: else if ( tag == 0x2014B50 ) +177: { +178: SetBackColor ( cLtPurple ) ; +179: ZIPDIRENTRY dirEntry ; +180: } +181: else if ( tag == 0x5054B50 ) +182: { +183: SetBackColor ( cLtBlue ) ; +184: ZIPDIGITALSIG digitalSig ; +185: } +186: else if ( tag == 0x6054B50 ) +187: { +188: SetBackColor ( cLtYellow ) ; +189: ZIPENDLOCATOR endLocator ; +190: } +191: else +192: { +193: Warning ( "Unknown ZIP tag encountered. Template stopped." ) ; +194: return - 1 ; +195: } +196: } tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/ZIPTemplateAdv.bt b/cparser/tests/exp_lex/ZIPTemplateAdv.bt new file mode 100644 index 0000000..056f9f0 --- /dev/null +++ b/cparser/tests/exp_lex/ZIPTemplateAdv.bt @@ -0,0 +1,667 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: +21: +22: +23: +24: +25: +26: +27: +28: +29: +30: +31: +32: typedef enum < uint > { +33: S_ZIPFILERECORD = 0x4034B50 , +34: S_ZIPDATADESCR = 0x8074B50 , +35: S_ZIPDIRENTRY = 0x2014B50 , +36: S_ZIPDIGITALSIG = 0x5054B50 , +37: S_ZIP64ENDLOCATORRECORD = 0x6064B50 , +38: S_ZIP64ENDLOCATOR = 0x7064B50 , +39: S_ZIPENDLOCATOR = 0x6054B50 +40: } SignatureTYPE < format = hex > ; +41: +42: typedef enum < byte > { +43: OS_FAT = 0 , +44: OS_AMIGA = 1 , +45: OS_VMS = 2 , +46: OS_Unix = 3 , +47: OS_VM_CMS = 4 , +48: OS_Atari = 5 , +49: OS_HPFS = 6 , +50: OS_Mac = 7 , +51: OS_Z_System = 8 , +52: OS_CPM = 9 , +53: OS_TOPS20 = 10 , +54: OS_NTFS = 11 , +55: OS_QDOS = 12 , +56: OS_Acorn = 13 , +57: OS_VFAT = 14 , +58: OS_MVS = 15 , +59: OS_BeOS = 16 , +60: OS_Tandem = 17 , +61: OS_OS400 = 18 , +62: OS_OSX = 19 +63: } HOSTOSTYPE ; +64: +65: typedef byte VERSIONTYPE < read = read_VERSIONTYPE > ; +66: +67: string read_VERSIONTYPE ( local VERSIONTYPE & af ) { +68: local string s = "" ; +69: SPrintf ( s , "%1.1f" , ( float ) af / 10 ) ; +70: return s ; +71: } +72: +73: typedef struct { +74: VERSIONTYPE Version ; +75: HOSTOSTYPE HostOS ; +76: } VERECORD < read = read_VERECORD > ; +77: +78: string read_VERECORD ( local VERECORD & af ) { +79: local string s = "" ; +80: SPrintf ( s , "Ver %1.1f, " , ( float ) af . Version / 10 ) ; +81: s += EnumToString ( af . HostOS ) ; +82: return s ; +83: } +84: +85: +86: typedef enum < short > { +87: COMP_STORED = 0 , +88: COMP_SHRUNK = 1 , +89: COMP_REDUCED1 = 2 , +90: COMP_REDUCED2 = 3 , +91: COMP_REDUCED3 = 4 , +92: COMP_REDUCED4 = 5 , +93: COMP_IMPLODED = 6 , +94: COMP_TOKEN = 7 , +95: COMP_DEFLATE = 8 , +96: COMP_DEFLATE64 = 9 , +97: COMP_PKImploding = 10 , +98: +99: COMP_BZip2 = 12 , +100: COMP_LZMA = 14 , +101: COMP_Terse = 18 , +102: COMP_Lz77 = 19 , +103: +104: COMP_Jpeg = 0x60 , +105: COMP_WavPack = 0x61 , +106: COMP_PPMd = 0x62 , +107: COMP_WzAES = 0x63 +108: } COMPTYPE ; +109: +110: typedef enum < ushort > { +111: FLAG_Encrypted = 0x1 , +112: FLAG_CompressionFlagBit1 = 0x2 , +113: FLAG_CompressionFlagBit2 = 0x4 , +114: FLAG_DescriptorUsedMask = 0x8 , +115: FLAG_Reserved1 = 0x10 , +116: FLAG_Reserved2 = 0x20 , +117: FLAG_StrongEncrypted = 0x40 , +118: FLAG_CurrentlyUnused1 = 0x80 , +119: FLAG_CurrentlyUnused2 = 0x100 , +120: FLAG_CurrentlyUnused3 = 0x200 , +121: FLAG_CurrentlyUnused4 = 0x400 , +122: FLAG_Utf8 = 0x800 , +123: FLAG_ReservedPKWARE1 = 0x1000 , +124: FLAG_CDEncrypted = 0x2000 , +125: FLAG_ReservedPKWARE2 = 0x4000 , +126: FLAG_ReservedPKWARE3 = 0x8000 , +127: +128: } FLAGTYPE < read = read_FLAGTYPE > ; +129: +130: string read_FLAGTYPE ( local FLAGTYPE & af ) { +131: local string s = "" ; +132: local int commaNeeded = 0 ; +133: local FLAGTYPE i = 1 ; +134: +135: SPrintf ( s , "%d: " , af ) ; +136: while ( i < FLAG_ReservedPKWARE3 ) +137: { +138: if ( af & i ) +139: { +140: if ( commaNeeded ) +141: { s += ", " ; } +142: s += EnumToString ( i ) ; +143: commaNeeded = 1 ; +144: } +145: i = i << 1 ; +146: } +147: return s ; +148: } +149: +150: typedef enum < ushort > { +151: EH_Zip64 = 0x1 , +152: EH_AVInfo = 0x7 , +153: EH_ExtLanguage = 0x8 , +154: EH_OS2 = 0x9 , +155: EH_NTFS = 0xA , +156: EH_OpenVMS = 0xC , +157: EH_UNIX = 0xD , +158: EH_fileStream = 0xE , +159: EH_PatchDescriptor = 0xF , +160: EH_PKCS7X509 = 0x14 , +161: EH_X509IDSignature = 0x15 , +162: EH_X509IDCD = 0x16 , +163: EH_StrongEncryption = 0x17 , +164: EH_RecordManagement = 0x18 , +165: EH_PKCS7List = 0x19 , +166: EH_Attributes = 0x65 , +167: EH_ReservedAttributes = 0x66 , +168: EH_POSZIP4690 = 0x4690 , +169: EH_Mac = 0x7C8 , +170: EH_ZipItMac1 = 0x2605 , +171: EH_ZipItMac2 = 0x2705 , +172: EH_ZipItMac3 = 0x2805 , +173: EH_InfoZIPMac = 0x334D , +174: EH_Acorn = 0x4341 , +175: EH_WinNTSecurity = 0x4453 , +176: EH_VM_CMS = 0x4704 , +177: EH_MVS = 0x470F , +178: EH_FWKCS = 0x4B46 , +179: EH_OS2AccessList = 0x4C41 , +180: EH_InfoZIPOpenVMS = 0x4D49 , +181: EH_Xceed = 0x4F4C , +182: EH_AOSVS = 0x5356 , +183: EH_extTimestamp = 0x5455 , +184: EH_XceedUnicode = 0x554E , +185: EH_InfoZIPUNIX = 0x5855 , +186: EH_InfoZIPUnicodeComment = 0x6375 , +187: EH_BeOS = 0x6542 , +188: EH_InfoZIPUnicodePath = 0x7075 , +189: EH_ASiUNIX = 0x756E , +190: EH_InfoZIPUNIXNew = 0x7855 , +191: EH_InfoZIPUNIXNew3rd = 0x7875 , +192: EH_WinGrowth = 0xA220 , +193: EH_SMSQDOS = 0xFD4A , +194: EH_WzAES = 0x9901 , +195: } HEADERFLAG ; +196: +197: typedef enum < ushort > { +198: AlgID_DES = 0x6601 , +199: AlgID_RC2OLD = 0x6602 , +200: AlgID_3DES168 = 0x6603 , +201: AlgID_3DES112 = 0x6609 , +202: AlgID_AES128 = 0x660E , +203: AlgID_AES192 = 0x660F , +204: AlgID_AES256 = 0x6610 , +205: AlgID_RC2 = 0x6702 , +206: AlgID_Blowfish = 0x6720 , +207: AlgID_Twofish = 0x6721 , +208: AlgID_RC4 = 0x6801 , +209: AlgID_Unknown = 0xFFFF , +210: } ALGFLAG ; +211: +212: typedef enum < byte > { +213: AES128 = 0x1 , +214: AES192 = 0x2 , +215: AES256 = 0x3 , +216: } AESMODE ; +217: +218: typedef enum < ushort > { +219: pfPassword = 0x1 , +220: pfCertificates = 0x2 , +221: pfPasswordCertificates = 0x3 , +222: } PRCFLAG ; +223: +224: typedef struct { +225: HEADERFLAG efHeaderID ; +226: ushort efDataSize ; +227: +228: Printf ( "%d" , efHeaderID ) ; +229: switch ( efHeaderID ) +230: { +231: case EH_Zip64 : +232: uint64 efOriginalSize ; +233: uint64 efCompressedSize ; +234: +235: +236: break ; +237: case EH_InfoZIPUnicodePath : +238: byte efVersion ; +239: uint efNameCRC32 ; +240: if ( efDataSize > 0 ) +241: char efUnicodeName [ efDataSize - 5 ] ; +242: break ; +243: case EH_NTFS : +244: int Reserved ; +245: local int len = efDataSize - 4 ; +246: while ( len > 0 ) +247: { +248: ushort Tag ; +249: ushort Size ; +250: if ( Tag == 0x1 ) +251: { +252: FILETIME Mtime ; +253: FILETIME Atime ; +254: FILETIME Ctime ; +255: } +256: else +257: byte Data [ Size ] ; +258: len -= Size + 4 ; +259: } +260: break ; +261: case EH_StrongEncryption : +262: ushort Format ; +263: ALGFLAG AlgID ; +264: ushort Bitlen ; +265: PRCFLAG Flags ; +266: if ( efDataSize > 8 ) +267: byte CertData [ efDataSize - 8 ] ; +268: break ; +269: case EH_WzAES : +270: ushort version ; +271: char VendorID [ 2 ] ; +272: AESMODE Strength ; +273: COMPTYPE deCompression ; +274: break ; +275: default : +276: if ( efDataSize > 0 ) +277: char efData [ efDataSize ] ; +278: break ; +279: } +280: } EXTRAFIELD < read = read_EXTRAFIELD > ; +281: +282: string read_EXTRAFIELD ( local EXTRAFIELD & af ) +283: { +284: return EnumToString ( af . efHeaderID ) ; +285: } +286: +287: typedef struct { +288: HEADERFLAG efHeaderID ; +289: uint efDataSize ; +290: +291: Printf ( "%d" , efHeaderID ) ; +292: switch ( efHeaderID ) +293: { +294: case EH_Zip64 : +295: uint64 efOriginalSize ; +296: uint64 efCompressedSize ; +297: +298: +299: break ; +300: case EH_InfoZIPUnicodePath : +301: byte efVersion ; +302: uint efNameCRC32 ; +303: if ( efDataSize > 0 ) +304: char efUnicodeName [ efDataSize - 5 ] ; +305: break ; +306: default : +307: if ( efDataSize > 0 ) +308: char efData [ efDataSize ] ; +309: break ; +310: } +311: } EXTRA64FIELD ; +312: +313: typedef enum < uint > { +314: FA_READONLY = 0x1 , +315: FA_HIDDEN = 0x2 , +316: FA_SYSTEM = 0x4 , +317: FA_DIRECTORY = 0x10 , +318: FA_ARCHIVE = 0x20 , +319: FA_DEVICE = 0x40 , +320: FA_NORMAL = 0x80 , +321: FA_TEMPORARY = 0x100 , +322: FA_SPARSE_FILE = 0x200 , +323: FA_REPARSE_POINT = 0x400 , +324: FA_COMPRESSED = 0x800 , +325: FA_OFFLINE = 0x1000 , +326: FA_NOT_CONTENT_INDEXED = 0x2000 , +327: FA_ENCRYPTED = 0x4000 , +328: FA_VIRTUAL = 0x10000 , +329: +330: kIFMT = 170000 << 16 , +331: +332: kIFDIR = 40000 << 16 , +333: kIFREG = 100000 << 16 , +334: kIFSOCK = 140000 << 16 , +335: kIFLNK = 120000 << 16 , +336: kIFBLK = 60000 << 16 , +337: kIFCHR = 20000 << 16 , +338: kIFIFO = 10000 << 16 , +339: +340: kISUID = 4000 << 16 , +341: kISGID = 2000 << 16 , +342: kISVTX = 1000 << 16 , +343: kIRWXU = 700 << 16 , +344: kIRUSR = 400 << 16 , +345: kIWUSR = 200 << 16 , +346: kIXUSR = 100 << 16 , +347: kIRWXG = 70 << 16 , +348: kIRGRP = 40 << 16 , +349: kIWGRP = 20 << 16 , +350: kIXGRP = 10 << 16 , +351: kIRWXO = 7 << 16 , +352: kIROTH = 4 << 16 , +353: kIWOTH = 2 << 16 , +354: kIXOTH = 1 << 16 +355: } FILEATTRIBUTE < read = read_FILEATTRIBUTE > ; +356: +357: string read_FILEATTRIBUTE ( local FILEATTRIBUTE & af ) { +358: local string s = "" ; +359: local int commaNeeded = 0 ; +360: local FILEATTRIBUTE i = 1 ; +361: +362: SPrintf ( s , "0x%X: " , af ) ; +363: while ( i < 0xFFFFFF - 2 ) +364: { +365: if ( af & i ) +366: { +367: if ( commaNeeded ) +368: { +369: s += ", " ; +370: } +371: s += EnumToString ( i ) ; +372: commaNeeded = 1 ; +373: } +374: i = i << 1 ; +375: } +376: return s ; +377: } +378: +379: +380: typedef struct { +381: SignatureTYPE ddSignature ; +382: uint ddCRC < format = hex > ; +383: uint ddCompressedSize ; +384: uint ddUncompressedSize ; +385: } ZIPDATADESCR ; +386: +387: +388: typedef struct { +389: +390: SignatureTYPE frSignature ; +391: VERECORD frVersion ; +392: FLAGTYPE frFlags ; +393: COMPTYPE frCompression ; +394: DOSTIME frFileTime ; +395: DOSDATE frFileDate ; +396: uint frCrc < format = hex > ; +397: uint frCompressedSize ; +398: uint frUncompressedSize ; +399: ushort frFileNameLength ; +400: ushort frExtraFieldLength ; +401: if ( frFileNameLength > 0 ) +402: char frFileName [ frFileNameLength ] ; +403: +404: local int len = frExtraFieldLength ; +405: while ( len > 0 ) +406: { +407: EXTRAFIELD frExtraField ; +408: len -= frExtraField . efDataSize + 4 ; +409: } +410: +411: SetBackColor ( cNone ) ; +412: +413: if ( ( frFlags & FLAG_Encrypted ) && ( frFlags & FLAG_StrongEncrypted ) ) +414: { +415: struct +416: { +417: ushort IVSize ; +418: byte IVData [ IVSize ] ; +419: uint Size ; +420: ushort Format ; +421: ALGFLAG AlgID ; +422: ushort BitLen ; +423: ushort Flags ; +424: ushort ErdSize ; +425: byte ErdData [ ErdSize ] ; +426: uint Reserved ; +427: ushort VSize ; +428: byte VData [ VSize - 4 ] ; +429: uint VCRC32 ; +430: } StrongEncryptedHeader ; +431: char frData [ frCompressedSize - StrongEncryptedHeader . IVSize - StrongEncryptedHeader . Size - 6 ] ; +432: } +433: else if ( ( frFlags & FLAG_Encrypted ) && ( frCompression == COMP_WzAES ) ) +434: { +435: local int lenSalt = 0 ; +436: if ( frExtraField . efHeaderID == EH_WzAES ) +437: { +438: switch ( frExtraField . Strength ) +439: { +440: case AES128 : +441: lenSalt = 8 ; +442: break ; +443: case AES192 : +444: lenSalt = 12 ; +445: break ; +446: case AES256 : +447: lenSalt = 16 ; +448: break ; +449: } +450: } +451: uchar SaltValue [ lenSalt ] ; +452: ushort PassVerification ; +453: uchar frData [ frCompressedSize - 12 - lenSalt ] ; +454: uchar AuthenticationCode [ 10 ] ; +455: } +456: else if ( ( frCompressedSize > 0 ) && ( frCompressedSize < 0xFFFFFFFF ) ) +457: { +458: uchar frData [ frCompressedSize ] ; +459: } +460: else if ( frCompressedSize == 0 && ( frFlags & FLAG_DescriptorUsedMask ) ) +461: { +462: +463: +464: +465: local int64 posCurrent = FTell ( ) ; +466: local int64 posNext = FindFirst ( S_ZIPDATADESCR , true , false , false , 0 . 0 , 1 , posCurrent ) ; +467: if ( posNext >= posCurrent ) +468: { +469: uchar frData [ posNext - posCurrent ] ; +470: +471: SetBackColor ( cLtGreen ) ; +472: ZIPDATADESCR dataDescr ; +473: } +474: } +475: +476: } ZIPFILERECORD < read = ReadZIPFILERECORD , write = WriteZIPFILERECORD > ; +477: +478: +479: typedef struct { +480: SignatureTYPE deSignature ; +481: VERECORD deVersionMadeBy ; +482: VERECORD deVersionToExtract ; +483: FLAGTYPE deFlags ; +484: COMPTYPE deCompression ; +485: DOSTIME deFileTime ; +486: DOSDATE deFileDate ; +487: uint deCrc < format = hex > ; +488: uint deCompressedSize ; +489: uint deUncompressedSize ; +490: ushort deFileNameLength ; +491: ushort deExtraFieldLength ; +492: ushort deFileCommentLength ; +493: ushort deDiskNumberStart ; +494: ushort deInternalAttributes ; +495: FILEATTRIBUTE deExternalAttributes ; +496: uint deHeaderOffset ; +497: if ( deFileNameLength > 0 ) +498: char deFileName [ deFileNameLength ] ; +499: local int len = deExtraFieldLength ; +500: while ( len > 0 ) +501: { +502: EXTRAFIELD deExtraField ; +503: len -= deExtraField . efDataSize + 4 ; +504: } +505: if ( deFileCommentLength > 0 ) +506: uchar deFileComment [ deFileCommentLength ] ; +507: } ZIPDIRENTRY < read = ReadZIPDIRENTRY > ; +508: +509: +510: typedef struct { +511: SignatureTYPE dsSignature ; +512: ushort dsDataLength ; +513: if ( dsDataLength > 0 ) +514: uchar dsData [ dsDataLength ] ; +515: } ZIPDIGITALSIG ; +516: +517: +518: typedef struct { +519: SignatureTYPE elr64Signature ; +520: int64 elr64DirectoryRecordSize ; +521: if ( elr64DirectoryRecordSize > 1 ) +522: VERECORD elr64VersionMadeBy ; +523: if ( elr64DirectoryRecordSize > 2 ) +524: VERECORD elr64VersionToExtract ; +525: if ( elr64DirectoryRecordSize > 4 ) +526: uint el64DiskNumber ; +527: if ( elr64DirectoryRecordSize > 8 ) +528: uint el64StartDiskNumber ; +529: if ( elr64DirectoryRecordSize > 12 ) +530: int64 el64EntriesOnDisk ; +531: if ( elr64DirectoryRecordSize > 20 ) +532: int64 el64EntriesInDirectory ; +533: if ( elr64DirectoryRecordSize > 28 ) +534: int64 el64DirectorySize ; +535: if ( elr64DirectoryRecordSize > 36 ) +536: int64 el64DirectoryOffset ; +537: if ( elr64DirectoryRecordSize > 44 ) +538: { +539: char DataSect [ elr64DirectoryRecordSize - 44 ] ; +540: +541: +542: +543: +544: +545: +546: +547: } +548: } ZIP64ENDLOCATORRECORD ; +549: +550: +551: typedef struct { +552: SignatureTYPE elSignature ; +553: uint elStartDiskNumber ; +554: int64 elDirectoryOffset ; +555: uint elEntriesInDirectory ; +556: } ZIP64ENDLOCATOR ; +557: +558: +559: typedef struct { +560: SignatureTYPE elSignature ; +561: ushort elDiskNumber ; +562: ushort elStartDiskNumber ; +563: ushort elEntriesOnDisk ; +564: ushort elEntriesInDirectory ; +565: uint elDirectorySize ; +566: uint elDirectoryOffset ; +567: ushort elCommentLength ; +568: if ( elCommentLength > 0 ) +569: char elComment [ elCommentLength ] ; +570: } ZIPENDLOCATOR ; +571: +572: +573: +574: +575: +576: +577: string ReadZIPFILERECORD ( ZIPFILERECORD & file ) +578: { +579: if ( exists ( file . frFileName ) ) +580: return file . frFileName ; +581: else +582: return "" ; +583: } +584: +585: string ReadZIPDIRENTRY ( ZIPDIRENTRY & entry ) +586: { +587: if ( exists ( entry . deFileName ) ) +588: return entry . deFileName ; +589: else +590: return "" ; +591: } +592: +593: +594: +595: +596: +597: void WriteZIPFILERECORD ( ZIPFILERECORD & file , string s ) +598: { +599: local int len = Strlen ( s ) ; +600: if ( exists ( file . frFileName ) ) +601: { +602: Strncpy ( file . frFileName , s , file . frFileNameLength ) ; +603: if ( len < file . frFileNameLength ) +604: file . frFileName [ len ] = 0 ; +605: } +606: } +607: +608: +609: +610: +611: local uint tag ; +612: LittleEndian ( ) ; +613: while ( ! FEof ( ) ) +614: { +615: +616: tag = ReadUInt ( FTell ( ) ) ; +617: +618: +619: +620: +621: +622: if ( tag == S_ZIPFILERECORD ) +623: { +624: SetBackColor ( cLtGray ) ; +625: ZIPFILERECORD record ; +626: if ( record . frExtraFieldLength > 0 && record . frExtraField . efHeaderID == EH_Zip64 ) +627: { +628: +629: FSkip ( record . frExtraField . efCompressedSize ) ; +630: } +631: } +632: else if ( tag == S_ZIPDATADESCR ) +633: { +634: SetBackColor ( cLtGreen ) ; +635: ZIPDATADESCR dataDescr ; +636: } +637: else if ( tag == S_ZIPDIRENTRY ) +638: { +639: SetBackColor ( cLtPurple ) ; +640: ZIPDIRENTRY dirEntry ; +641: } +642: else if ( tag == S_ZIPDIGITALSIG ) +643: { +644: SetBackColor ( cLtBlue ) ; +645: ZIPDIGITALSIG digitalSig ; +646: } +647: else if ( tag == S_ZIP64ENDLOCATORRECORD ) +648: { +649: SetBackColor ( cYellow ) ; +650: ZIP64ENDLOCATORRECORD end64Locator ; +651: } +652: else if ( tag == S_ZIP64ENDLOCATOR ) +653: { +654: SetBackColor ( cDkYellow ) ; +655: ZIP64ENDLOCATOR end64Locator ; +656: } +657: else if ( tag == S_ZIPENDLOCATOR ) +658: { +659: SetBackColor ( cLtYellow ) ; +660: ZIPENDLOCATOR endLocator ; +661: } +662: else +663: { +664: Warning ( "Unknown ZIP tag encountered. Template stopped." ) ; +665: return - 1 ; +666: } +667: } tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/comment.bt b/cparser/tests/exp_lex/comment.bt new file mode 100644 index 0000000..3c865b9 --- /dev/null +++ b/cparser/tests/exp_lex/comment.bt @@ -0,0 +1,9 @@ +1: +2: int x = 5 ; +3: +4: +5: +6: +7: +8: +9: int y = 4 ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/comment_error.bt b/cparser/tests/exp_lex/comment_error.bt new file mode 100644 index 0000000..88baa8c --- /dev/null +++ b/cparser/tests/exp_lex/comment_error.bt @@ -0,0 +1,3 @@ +1: +2: +3: error(line 3, col 32, "unexpected end of file in block comment") \ No newline at end of file diff --git a/cparser/tests/exp_lex/exFATTemplate.bt b/cparser/tests/exp_lex/exFATTemplate.bt new file mode 100644 index 0000000..739d734 --- /dev/null +++ b/cparser/tests/exp_lex/exFATTemplate.bt @@ -0,0 +1,656 @@ +1: +2: +3: +4: +5: +6: +7: +8: +9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: +21: +22: +23: +24: +25: +26: +27: +28: +29: +30: +31: +32: +33: +34: +35: +36: +37: +38: +39: +40: +41: +42: +43: +44: +45: +46: +47: +48: +49: +50: +51: +52: +53: +54: +55: +56: +57: +58: +59: +60: +61: +62: +63: +64: +65: +66: +67: +68: LittleEndian ( ) ; +69: FSeek ( 0 ) ; +70: +71: typedef char S08 ; +72: typedef unsigned char U08 ; +73: typedef unsigned short U16 ; +74: typedef unsigned int U32 ; +75: typedef uint64 U64 ; +76: +77: struct tagTempVariable +78: { +79: local U08 flags [ 2 ] ; +80: local U32 cluster_max = 512 ; +81: local U32 cluster_array [ cluster_max ] ; +82: local U32 cluster_count = 0 ; +83: local U32 cluster_iter = 0 ; +84: local U32 bitmap_cluster = 2 ; +85: } exfat_temp_variable < read = TotalSizeRead > ; +86: +87: local U64 ______EXFAT_BOOT_SECTOR_REGION ; +88: string TotalSizeRead ( struct tagTempVariable & v ) +89: { +90: string s ; +91: SPrintf ( s , "Disk Bytes: %Lu(%Lxh)" , FileSize ( ) , FileSize ( ) ) ; +92: return s ; +93: } +94: +95: typedef U08 exFatVersion [ 2 ] < read = VersionRead > ; +96: string VersionRead ( exFatVersion v ) +97: { +98: string s ; +99: SPrintf ( s , "exFAT Revision: %01d.%02d" , v [ 1 ] , v [ 0 ] ) ; +100: return s ; +101: } +102: string ShiftRead ( U08 v ) +103: { +104: string s ; +105: SPrintf ( s , "%d(%d)" , v , ( 1 << v ) ) ; +106: return s ; +107: } +108: U08 IsValidBootSector ( U08 aucJumpBoot [ 3 ] , +109: S08 aucFileSystemName [ 8 ] ) +110: { +111: if ( aucJumpBoot [ 0 ] == 0xEB +112: && aucJumpBoot [ 1 ] == 0x76 +113: && aucJumpBoot [ 2 ] == 0x90 +114: && aucFileSystemName [ 0 ] == 'E' +115: && aucFileSystemName [ 1 ] == 'X' +116: && aucFileSystemName [ 2 ] == 'F' +117: && aucFileSystemName [ 3 ] == 'A' +118: && aucFileSystemName [ 4 ] == 'T' ) +119: { +120: return 1 ; +121: } +122: return 0 ; +123: } +124: +125: typedef struct +126: { +127: U08 aucJumpBoot [ 3 ] < format = hex > ; +128: S08 aucFileSystemName [ 8 ] ; +129: U08 aucMustBeZero [ 53 ] ; +130: U64 ulPartitionOffset ; +131: U64 ulVolumeLength ; +132: U32 uiFatOffset ; +133: U32 uiFatLength ; +134: U32 uiClusterHeapOffset ; +135: U32 uiClusterCount ; +136: U32 uiFirstClusterOfRootDirectory ; +137: U32 uiVolumeSerialNumber < format = hex > ; +138: exFatVersion usFileSystemRevision ; +139: U16 usVolumeFlags_ActiveFat : 1 ; +140: U16 usVolumeFlags_VolumeDirty : 1 ; +141: U16 usVolumeFlags_MediaFailure : 1 ; +142: U16 usVolumeFlags_ClearToZero : 1 ; +143: U16 usVolumeFlags_Reserved : 12 ; +144: U08 ucBytesPerSectorShift < read = ShiftRead > ; +145: U08 ucSectorsPerClusterShift < read = ShiftRead > ; +146: U08 ucNumberOfFats ; +147: U08 ucDriveSelect < format = hex > ; +148: U08 ucPercentInUse ; +149: U08 aucReserved [ 7 ] ; +150: U08 aucBootCode [ 390 ] ; +151: U16 usBootSignature < format = hex > ; +152: if ( IsValidBootSector ( aucJumpBoot , aucFileSystemName ) == 1 +153: && ( 1 << ucBytesPerSectorShift ) - 512 ) +154: { +155: U08 aucExcessSpace [ ( 1 << ucBytesPerSectorShift ) - 512 ] ; +156: } +157: } BootSector_S < read = BootSectorRead > ; +158: BootSector_S BootSector ; +159: string BootSectorRead ( BootSector_S & v ) +160: { +161: string s ; +162: if ( IsValidBootSector ( v . aucJumpBoot , v . aucFileSystemName ) == 1 ) +163: { +164: SPrintf ( s , "Valid exFAT Volume" ) ; +165: } +166: else +167: { +168: SPrintf ( s , "Invalid exFAT Volume, %s?" , v . aucFileSystemName ) ; +169: } +170: return s ; +171: } +172: +173: if ( IsValidBootSector ( BootSector . aucJumpBoot , BootSector . aucFileSystemName ) == 0 ) +174: { +175: return 0 ; +176: } +177: +178: local U64 ______EXFAT_VOLUME_LAYOUT_REGION ; +179: FSeek ( 0 ) ; +180: typedef struct +181: { +182: BootSector_S BootSector ; +183: struct +184: { +185: U08 aucExendedBootCode [ ( 1 << BootSector . ucBytesPerSectorShift ) - 4 ] ; +186: U32 uiExtendedBootSignature < format = hex > ; +187: } ExtendedBootSector [ 8 ] ; +188: +189: struct +190: { +191: struct +192: { +193: U08 aucParametersGuid [ 16 ] ; +194: U08 aucCustomDefined [ 32 ] ; +195: } stParameters [ 10 ] ; +196: U08 aucReserved [ ( 1 << BootSector . ucBytesPerSectorShift ) - 480 ] ; +197: } OEMParametersSector ; +198: +199: struct +200: { +201: U08 aucReserved [ ( 1 << BootSector . ucBytesPerSectorShift ) ] ; +202: } ReservedSector ; +203: +204: struct +205: { +206: U32 aucReserved [ ( 1 << BootSector . ucBytesPerSectorShift ) / 4 ] < format = hex > ; +207: } BootChecksumSector ; +208: +209: } Boot_Region_S < read = BootRegionRead > ; +210: string BootRegionRead ( Boot_Region_S & boot ) +211: { +212: string s ; +213: SPrintf ( s , "Volume Bytes: %Lu(%Lxh)" , +214: boot . BootSector . ulVolumeLength << boot . BootSector . ucBytesPerSectorShift , +215: boot . BootSector . ulVolumeLength << boot . BootSector . ucBytesPerSectorShift ) ; +216: return s ; +217: } +218: +219: +220: Boot_Region_S Main_Boot_Region ; +221: Boot_Region_S Backup_Boot_Region ; +222: +223: typedef struct +224: { +225: if ( Main_Boot_Region . BootSector . uiFatOffset - 24 ) +226: { +227: struct +228: { +229: U08 aucReserved [ ( 1 << Main_Boot_Region . BootSector . ucBytesPerSectorShift ) ] ; +230: } FatAlignmentSector [ Main_Boot_Region . BootSector . uiFatOffset - 24 ] ; +231: } +232: struct +233: { +234: U32 uiFatEntry [ Main_Boot_Region . BootSector . uiClusterCount + 2 ] < format = hex > ; +235: U32 uiExcessEntry [ Main_Boot_Region . BootSector . uiFatLength * +236: ( 1 << Main_Boot_Region . BootSector . ucBytesPerSectorShift ) / 4 +237: - ( Main_Boot_Region . BootSector . uiClusterCount + 2 ) ] < format = hex > ; +238: } FirstFAT ; +239: if ( Main_Boot_Region . BootSector . ucNumberOfFats > 1 ) +240: { +241: struct +242: { +243: U32 uiFatEntry [ Main_Boot_Region . BootSector . uiClusterCount + 2 ] < format = hex > ; +244: U32 uiExcessEntry [ Main_Boot_Region . BootSector . uiFatLength * +245: ( 1 << Main_Boot_Region . BootSector . ucBytesPerSectorShift ) / 4 +246: - ( Main_Boot_Region . BootSector . uiClusterCount + 2 ) ] < format = hex > ; +247: } SecondFAT ; +248: } +249: } Fat_Region_S < read = FatRegionRead > ; +250: string FatRegionRead ( Fat_Region_S & v ) +251: { +252: string s ; +253: SPrintf ( s , "FATs: %d, EntryTotalPerFAT: %d" , Main_Boot_Region . BootSector . ucNumberOfFats , +254: Main_Boot_Region . BootSector . uiClusterCount + 2 ) ; +255: return s ; +256: } +257: Fat_Region_S Fat_Region ; +258: typedef struct +259: { +260: local U32 uiClusterNo = 2 ; +261: struct +262: { +263: U08 aucData [ 1 << Main_Boot_Region . BootSector . ucBytesPerSectorShift ] ; +264: } DataSector [ 1 << Main_Boot_Region . BootSector . ucSectorsPerClusterShift ] ; +265: } Cluster_S < read = ClusterRead > ; +266: string ClusterRead ( Cluster_S & v ) +267: { +268: string s ; +269: SPrintf ( s , "ClusterNo: %d" , v . uiClusterNo ) ; +270: return s ; +271: } +272: struct tagDataRegion +273: { +274: if ( Main_Boot_Region . BootSector . uiClusterHeapOffset - +275: ( Main_Boot_Region . BootSector . uiFatOffset + +276: Main_Boot_Region . BootSector . ucNumberOfFats * +277: Main_Boot_Region . BootSector . uiFatLength ) ) +278: { +279: struct +280: { +281: U08 aucReserved [ ( 1 << Main_Boot_Region . BootSector . ucBytesPerSectorShift ) ] ; +282: } ClusterHeapAlignmentSector [ Main_Boot_Region . BootSector . uiClusterHeapOffset - +283: ( Main_Boot_Region . BootSector . uiFatOffset + +284: Main_Boot_Region . BootSector . ucNumberOfFats * +285: Main_Boot_Region . BootSector . uiFatLength ) ] ; +286: } +287: local U64 data_cluster_total = ( FileSize ( ) - FTell ( ) ) >> +288: Main_Boot_Region . BootSector . ucBytesPerSectorShift >> +289: Main_Boot_Region . BootSector . ucSectorsPerClusterShift ; +290: if ( data_cluster_total > Main_Boot_Region . BootSector . uiClusterCount ) +291: { +292: data_cluster_total = Main_Boot_Region . BootSector . uiClusterCount ; +293: } +294: local U32 curr_cluster_no = 0 ; +295: for ( exfat_temp_variable . cluster_iter = 0 ; +296: exfat_temp_variable . cluster_iter < data_cluster_total ; +297: exfat_temp_variable . cluster_iter ++ ) +298: { +299: Cluster_S ClusterHeap ; +300: ClusterHeap . uiClusterNo += curr_cluster_no ; +301: curr_cluster_no ++ ; +302: } +303: } Data_Region < read = DataRegionRead > ; +304: string DataRegionRead ( struct tagDataRegion & v ) +305: { +306: string s ; +307: SPrintf ( s , "Cluster Total(%s): %d(%d)" , +308: ( v . data_cluster_total == Main_Boot_Region . BootSector . uiClusterCount ) ? "FINE" : "FAIL" , +309: Main_Boot_Region . BootSector . uiClusterCount , v . data_cluster_total ) ; +310: return s ; +311: } +312: +313: if ( Main_Boot_Region . BootSector . ulVolumeLength - +314: Main_Boot_Region . BootSector . uiClusterHeapOffset - +315: ( Main_Boot_Region . BootSector . uiClusterCount << +316: Main_Boot_Region . BootSector . ucSectorsPerClusterShift ) ) +317: { +318: struct +319: { +320: struct +321: { +322: U08 aucReserved [ ( 1 << Main_Boot_Region . BootSector . ucBytesPerSectorShift ) ] ; +323: } ReservedSector ; +324: } ExcessSpace [ Main_Boot_Region . BootSector . ulVolumeLength - +325: Main_Boot_Region . BootSector . uiClusterHeapOffset - +326: ( Main_Boot_Region . BootSector . uiClusterCount << +327: Main_Boot_Region . BootSector . ucSectorsPerClusterShift ) ] ; +328: } +329: +330: +331: +332: local int ______EXFAT_ALLOCATION_BITMAP_REGION ; +333: FSeek ( ( ( ( exfat_temp_variable . bitmap_cluster - 2 ) << +334: Main_Boot_Region . BootSector . ucSectorsPerClusterShift ) + +335: Main_Boot_Region . BootSector . uiClusterHeapOffset ) << +336: Main_Boot_Region . BootSector . ucBytesPerSectorShift ) ; +337: typedef struct +338: { +339: local U32 byte_count ; +340: U08 bitmap ; +341: } Bitmap_S < read = BitmapRead > ; +342: string BitmapRead ( Bitmap_S & stBitmapByte ) +343: { +344: string s ; +345: SPrintf ( s , "%08d: %d%d%d%d%d%d%d%d" , stBitmapByte . byte_count + 2 , +346: ( stBitmapByte . bitmap >> 0 ) & 0x1 , +347: ( stBitmapByte . bitmap >> 1 ) & 0x1 , +348: ( stBitmapByte . bitmap >> 2 ) & 0x1 , +349: ( stBitmapByte . bitmap >> 3 ) & 0x1 , +350: ( stBitmapByte . bitmap >> 4 ) & 0x1 , +351: ( stBitmapByte . bitmap >> 5 ) & 0x1 , +352: ( stBitmapByte . bitmap >> 6 ) & 0x1 , +353: ( stBitmapByte . bitmap >> 7 ) & 0x1 ) ; +354: return s ; +355: } +356: +357: struct tagBitmapRegion +358: { +359: local U32 bitmap_length = Main_Boot_Region . BootSector . uiClusterCount ; +360: for ( exfat_temp_variable . cluster_iter = 0 ; +361: exfat_temp_variable . cluster_iter < ( bitmap_length + 7 ) / 8 ; +362: exfat_temp_variable . cluster_iter ++ ) +363: { +364: Bitmap_S Bitmap ; +365: Bitmap . byte_count = exfat_temp_variable . cluster_iter << 3 ; +366: } +367: } BITMAP_REGION < read = AllocationBitmapRegionRead > ; +368: string AllocationBitmapRegionRead ( struct tagBitmapRegion & stBitmapRegion ) +369: { +370: string s ; +371: SPrintf ( s , "Bits: %d(Bytes: %d)" , stBitmapRegion . bitmap_length , +372: ( stBitmapRegion . bitmap_length + 7 ) / 8 ) ; +373: return s ; +374: } +375: +376: +377: local int ______EXFAT_DIRECTORY_REGION ; +378: +379: typedef struct +380: { +381: local U08 uc10msIncrement = 0 ; +382: U16 bDoubleSeconds : 5 ; +383: U16 bMinute : 6 ; +384: U16 bHour : 5 ; +385: U16 bDay : 5 ; +386: U16 bMonth : 4 ; +387: U16 bYear : 7 ; +388: } FileTime_S < read = FileTimeRead > ; +389: string FileTimeRead ( FileTime_S & v ) +390: { +391: string s ; +392: SPrintf ( s , "%04d/%02d/%02d %02d:%02d:%02d.%02d" , v . bYear + 1980 , +393: v . bMonth , v . bDay , v . bHour , v . bMinute , +394: v . bDoubleSeconds * 2 + v . uc10msIncrement / 100 , +395: ( v . uc10msIncrement % 100 ) ) ; +396: return s ; +397: } +398: +399: typedef U08 FileName_S [ 30 ] < read = FileNameRead > ; +400: typedef U08 VolumeLabel_S [ 22 ] < read = VolumeLabelRead > ; +401: typedef struct +402: { +403: struct +404: { +405: U08 bTypeCode : 5 ; +406: U08 bTypeImportance : 1 ; +407: U08 bTypeCategory : 1 ; +408: U08 bInUse : 1 ; +409: } stEntryType ; +410: +411: if ( stEntryType . bTypeCategory == 0 && stEntryType . bTypeImportance == 0 ) +412: { +413: switch ( stEntryType . bTypeCode ) +414: { +415: case 1 : +416: U08 bBitmapIdentifier : 1 ; +417: U08 bReserved : 7 ; +418: U08 aucCustomDefined [ 18 ] ; +419: U32 uiFirstCluster ; +420: U64 ulDataLength ; +421: break ; +422: case 2 : +423: U08 aucReserved1 [ 3 ] ; +424: U32 uiTableChecksum < format = hex > ; +425: U08 aucReserved2 [ 12 ] ; +426: U32 uiFirstCluster ; +427: U64 ulDataLength ; +428: break ; +429: case 3 : +430: U08 ucCharacterCount ; +431: VolumeLabel_S stVolumeLabel ; +432: U08 aucReserved [ 8 ] ; +433: break ; +434: case 5 : +435: U08 ucSecondaryCount ; +436: U16 usSetCheckSum < format = hex > ; +437: U16 bAttrReadOnly : 1 ; +438: U16 bAttrHidden : 1 ; +439: U16 bAttrSystem : 1 ; +440: U16 bAttrReserved1 : 1 ; +441: U16 bAttrDirectory : 1 ; +442: U16 bAttrArchive : 1 ; +443: U16 bAttrReserved2 : 10 ; +444: U08 ausReserved1 [ 2 ] ; +445: FileTime_S stCreat ; +446: FileTime_S stLastModified ; +447: FileTime_S stLastAccessed ; +448: U08 ucCreate10msIncrement ; +449: U08 ucModified10msIncrement ; +450: U08 ucLastAcc10msdIncrement ; +451: U08 ausReserved2 [ 9 ] ; +452: stCreat . uc10msIncrement = ucCreate10msIncrement ; +453: stLastModified . uc10msIncrement = ucModified10msIncrement ; +454: stLastAccessed . uc10msIncrement = ucLastAcc10msdIncrement ; +455: if ( bAttrDirectory == 1 +456: && stEntryType . bInUse == 1 +457: && exfat_temp_variable . cluster_count < exfat_temp_variable . cluster_max ) +458: { +459: exfat_temp_variable . cluster_array [ exfat_temp_variable . cluster_count ] = 1 ; +460: } +461: break ; +462: default : +463: U08 ucSecondaryCount ; +464: U16 usSetCheckSum < format = hex > ; +465: U16 bAllocationPossible : 1 ; +466: U16 bNoFatChain : 1 ; +467: U16 bCustomDefined : 14 ; +468: U08 aucCustomDefined [ 14 ] ; +469: U32 uiFirstCluster ; +470: U64 ulDataLength ; +471: break ; +472: } +473: } +474: else if ( stEntryType . bTypeCategory == 0 && stEntryType . bTypeImportance == 1 ) +475: { +476: switch ( stEntryType . bTypeCode ) +477: { +478: case 0 : +479: U08 ucSecondaryCount ; +480: U16 usSetCheckSum ; +481: U16 bAllocationPossible : 1 ; +482: U16 bNoFatChain : 1 ; +483: U16 bCustomDefined : 14 ; +484: U08 aucVolumeGuid [ 16 ] ; +485: U08 aucReserved [ 10 ] ; +486: break ; +487: case 1 : +488: U08 aucCustomDefined [ 31 ] ; break ; +489: case 2 : +490: U08 aucCustomDefined [ 31 ] ; break ; +491: default : +492: U08 aucCustomDefined [ 31 ] ; break ; +493: } +494: } +495: else if ( stEntryType . bTypeCategory == 1 && stEntryType . bTypeImportance == 0 ) +496: { +497: switch ( stEntryType . bTypeCode ) +498: { +499: case 0 : +500: U08 bAllocationPossible : 1 ; +501: U08 bNoFatChain : 1 ; +502: U08 bCustomDefined : 6 ; +503: U08 ucReserved1 ; +504: U08 ucNameLength ; +505: U16 usNameHash < format = hex > ; +506: U08 aucReserved2 [ 2 ] ; +507: U64 ulValidDataLength ; +508: U08 aucReserved3 [ 4 ] ; +509: U32 uiFirstCluster ; +510: U64 ulDataLength ; +511: if ( stEntryType . bInUse == 1 +512: && exfat_temp_variable . cluster_count < exfat_temp_variable . cluster_max +513: && exfat_temp_variable . cluster_array [ exfat_temp_variable . cluster_count ] == 1 ) +514: { +515: exfat_temp_variable . cluster_array [ exfat_temp_variable . cluster_count ] = uiFirstCluster ; +516: exfat_temp_variable . cluster_count ++ ; +517: } +518: break ; +519: case 1 : +520: U08 bAllocationPossible : 1 ; +521: U08 bNoFatChain : 1 ; +522: U08 bCustomDefined : 6 ; +523: FileName_S stFileNmae ; +524: break ; +525: default : +526: U08 bAllocationPossible : 1 ; +527: U08 bNoFatChain : 1 ; +528: U08 bCustomDefined : 6 ; +529: U08 aucCustomDefined [ 18 ] ; +530: U32 uiFirstCluster ; +531: U64 ulDataLength ; +532: break ; +533: } +534: } +535: else +536: { +537: U08 aucCustomDefined [ 31 ] ; +538: } +539: } DirectoryEntry_S < read = DirectoryRead > ; +540: +541: string FileNameRead ( FileName_S astFileName ) +542: { +543: char s [ 16 ] ; +544: U08 i ; +545: for ( i = 0 ; i < 15 ; i ++ ) +546: { +547: s [ i ] = astFileName [ i * 2 ] ; +548: } +549: return s ; +550: } +551: string VolumeLabelRead ( VolumeLabel_S astFileName ) +552: { +553: char s [ 12 ] ; +554: U08 i ; +555: for ( i = 0 ; i < 11 ; i ++ ) +556: { +557: s [ i ] = astFileName [ i * 2 ] ; +558: } +559: return s ; +560: } +561: +562: string DirectoryRead ( DirectoryEntry_S & stDirEntry ) +563: { +564: string s = "Unknow Type" ; +565: if ( stDirEntry . stEntryType . bTypeCategory == 0 && stDirEntry . stEntryType . bTypeImportance == 0 ) +566: { +567: switch ( stDirEntry . stEntryType . bTypeCode ) +568: { +569: case 1 : SPrintf ( s , "[C/P/%s]: Allocation Bitmap" , +570: stDirEntry . stEntryType . bInUse == 0 ? "F" : "U" ) ; break ; +571: case 2 : SPrintf ( s , "[C/P/%s]: Up-case Table" , +572: stDirEntry . stEntryType . bInUse == 0 ? "F" : "U" ) ; break ; +573: case 3 : SPrintf ( s , "[C/P/%s]: Valume Label(%s)" , +574: stDirEntry . stEntryType . bInUse == 0 ? "F" : "U" , +575: VolumeLabelRead ( stDirEntry . stVolumeLabel ) ) ; break ; +576: case 5 : SPrintf ( s , "[C/P/%s]: Regular File(%s)" , +577: stDirEntry . stEntryType . bInUse == 0 ? "F" : "U" , +578: stDirEntry . bAttrDirectory == 0 ? "File" : "Directroy" ) ; break ; +579: default : SPrintf ( s , "[C/P/%s]: Unknow" , +580: stDirEntry . stEntryType . bInUse == 0 ? "F" : "U" ) ; break ; +581: } +582: } +583: if ( stDirEntry . stEntryType . bTypeCategory == 0 && stDirEntry . stEntryType . bTypeImportance == 1 ) +584: { +585: switch ( stDirEntry . stEntryType . bTypeCode ) +586: { +587: case 0 : SPrintf ( s , "[B/P/%s]: Volume GUID" , +588: stDirEntry . stEntryType . bInUse == 0 ? "F" : "U" ) ; break ; +589: case 1 : SPrintf ( s , "[B/P/%s]: TexFAT Padding" , +590: stDirEntry . stEntryType . bInUse == 0 ? "F" : "U" ) ; break ; +591: case 2 : SPrintf ( s , "[B/P/%s]: WinCE ACL Table" , +592: stDirEntry . stEntryType . bInUse == 0 ? "F" : "U" ) ; break ; +593: default : SPrintf ( s , "[B/P/%s]: Unknow" , +594: stDirEntry . stEntryType . bInUse == 0 ? "F" : "U" ) ; break ; +595: } +596: } +597: if ( stDirEntry . stEntryType . bTypeCategory == 1 && stDirEntry . stEntryType . bTypeImportance == 0 ) +598: { +599: switch ( stDirEntry . stEntryType . bTypeCode ) +600: { +601: case 0 : SPrintf ( s , "[C/S/%s]: Stream Extension" , +602: stDirEntry . stEntryType . bInUse == 0 ? "F" : "U" ) ; break ; +603: case 1 : SPrintf ( s , "[C/S/%s]: File Name(%s)" , +604: stDirEntry . stEntryType . bInUse == 0 ? "F" : "U" , +605: FileNameRead ( stDirEntry . stFileNmae ) ) ; break ; +606: default : SPrintf ( s , "[C/S/%s]: Unknow" , +607: stDirEntry . stEntryType . bInUse == 0 ? "F" : "U" ) ; break ; +608: } +609: } +610: if ( stDirEntry . stEntryType . bTypeCategory == 1 && stDirEntry . stEntryType . bTypeImportance == 1 ) +611: { +612: switch ( stDirEntry . stEntryType . bTypeCode ) +613: { +614: default : SPrintf ( s , "[B/S/%s]: Unknow" , +615: stDirEntry . stEntryType . bInUse == 0 ? "F" : "U" ) ; break ; +616: } +617: } +618: return s ; +619: } +620: +621: exfat_temp_variable . cluster_count = 1 ; +622: exfat_temp_variable . cluster_array [ 0 ] = Main_Boot_Region . BootSector . uiFirstClusterOfRootDirectory ; +623: for ( exfat_temp_variable . cluster_iter = 0 ; +624: exfat_temp_variable . cluster_iter < exfat_temp_variable . cluster_count ; +625: exfat_temp_variable . cluster_iter ++ ) +626: { +627: FSeek ( ( ( ( exfat_temp_variable . cluster_array [ exfat_temp_variable . cluster_iter ] - 2 ) << +628: Main_Boot_Region . BootSector . ucSectorsPerClusterShift ) + +629: Main_Boot_Region . BootSector . uiClusterHeapOffset ) << +630: Main_Boot_Region . BootSector . ucBytesPerSectorShift ) ; +631: struct tagDirCluster +632: { +633: local int dir_cluster = exfat_temp_variable . cluster_array [ exfat_temp_variable . cluster_iter ] ; +634: while ( ! FEof ( ) ) +635: { +636: ReadBytes ( exfat_temp_variable . flags , FTell ( ) , 1 ) ; +637: if ( exfat_temp_variable . flags [ 0 ] == 0 ) +638: { +639: break ; +640: } +641: DirectoryEntry_S stEntry ; +642: } +643: } DirectoryCluster < read = DirectoryClusterRead > ; +644: } +645: +646: string DirectoryClusterRead ( struct tagDirCluster & v ) +647: { +648: string s ; +649: SPrintf ( s , "Directory Cluster No: %d" , v . dir_cluster ) ; +650: return s ; +651: } +652: +653: +654: +655: +656: tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/stringlit.bt b/cparser/tests/exp_lex/stringlit.bt new file mode 100644 index 0000000..eba078b --- /dev/null +++ b/cparser/tests/exp_lex/stringlit.bt @@ -0,0 +1 @@ +1: string test = "this is a test\nwith a \0zero terminat and \x1B" ; tok_eof \ No newline at end of file diff --git a/cparser/tests/exp_lex/stringlit_error.bt b/cparser/tests/exp_lex/stringlit_error.bt new file mode 100644 index 0000000..a461db2 --- /dev/null +++ b/cparser/tests/exp_lex/stringlit_error.bt @@ -0,0 +1 @@ +1: string test = error(line 1, col 30, "unexpected newline in string literal (1)") \ No newline at end of file diff --git a/cparser/tests/exp_lex/test.bt b/cparser/tests/exp_lex/test.bt new file mode 100644 index 0000000..2c4b6e6 --- /dev/null +++ b/cparser/tests/exp_lex/test.bt @@ -0,0 +1,10 @@ +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 ; tok_eof \ No newline at end of file