mirror of https://github.com/x64dbg/btparser
first tests (not completely verified)
This commit is contained in:
parent
9dfa58daef
commit
ffe309ca16
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
|
@ -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
|
|
@ -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
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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 "<Undefined>" ;
|
||||
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
|
|
@ -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 "<Undefined>" ;
|
||||
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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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 , "<html>" , 6 ) == 0 )
|
||||
645: {
|
||||
646: SetBackColor ( cLtGreen ) ;
|
||||
647: HTML data ;
|
||||
648: }
|
||||
649: else if ( Memcmp ( tag , "<!DOCTYP" , 8 ) == 0 )
|
||||
650: {
|
||||
651: SetBackColor ( cLtGreen ) ;
|
||||
652: HTML data ;
|
||||
653: }
|
||||
654: else
|
||||
655: {
|
||||
656: SetBackColor ( cLtGray ) ;
|
||||
657: struct {
|
||||
658: UBYTE unknown [ reclen ] ;
|
||||
659: } data ;
|
||||
660: }
|
||||
661: }
|
||||
662:
|
||||
663: endrec = ReadUInt ( FTell ( ) ) ;
|
||||
664:
|
||||
665: if ( endrec == 0xE98E0D0A )
|
||||
666: {
|
||||
667: SetBackColor ( cLtGreen ) ;
|
||||
668: ENDRECORD data ;
|
||||
669: }
|
||||
670:
|
||||
671:
|
||||
672:
|
||||
673:
|
||||
674:
|
||||
675:
|
||||
676:
|
||||
677:
|
||||
678:
|
||||
679:
|
||||
680:
|
||||
681:
|
||||
682:
|
||||
683:
|
||||
684:
|
||||
685:
|
||||
686:
|
||||
687:
|
||||
688:
|
||||
689:
|
||||
690:
|
||||
691:
|
||||
692:
|
||||
693:
|
||||
694:
|
||||
695:
|
||||
696:
|
||||
697:
|
||||
698:
|
||||
699:
|
||||
700:
|
||||
701:
|
||||
702:
|
||||
703:
|
||||
704:
|
||||
705:
|
||||
706:
|
||||
707:
|
||||
708:
|
||||
709:
|
||||
710:
|
||||
711:
|
||||
712:
|
||||
713:
|
||||
714: return ; tok_eof
|
|
@ -0,0 +1,499 @@
|
|||
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: local uint32 bitrate , frame_size , sampling_freq , frames_count = 0 ;
|
||||
51: local quad frame_header_offset , seek_pos , sum_bitrate = 0 ;
|
||||
52: local short data ;
|
||||
53: local byte was_bad_sync , id3v1_tag_found = 0 ;
|
||||
54: local ubyte buf [ 3 ] ;
|
||||
55:
|
||||
56:
|
||||
57: enum < ubyte > 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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
|
@ -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
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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: <unknown>" ;
|
||||
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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1,9 @@
|
|||
1:
|
||||
2: int x = 5 ;
|
||||
3:
|
||||
4:
|
||||
5:
|
||||
6:
|
||||
7:
|
||||
8:
|
||||
9: int y = 4 ; tok_eof
|
|
@ -0,0 +1,3 @@
|
|||
1:
|
||||
2:
|
||||
3: error(line 3, col 32, "unexpected end of file in block comment")
|
|
@ -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
|
|
@ -0,0 +1 @@
|
|||
1: string test = "this is a test\nwith a \0zero terminat and \x1B" ; tok_eof
|
|
@ -0,0 +1 @@
|
|||
1: string test = error(line 1, col 30, "unexpected newline in string literal (1)")
|
|
@ -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
|
Loading…
Reference in New Issue