1 /*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
2  *
3  *  Use of this source code is governed by a BSD-style license that can
4  *  be found in the License.html file in the root of the source tree.
5  */
6 
7 //---------------------------------------------------------------------------
8 // Pre-compilation
9 #include "MediaInfo/PreComp.h"
10 #ifdef __BORLANDC__
11     #pragma hdrstop
12 #endif
13 //---------------------------------------------------------------------------
14 
15 //---------------------------------------------------------------------------
16 #include "MediaInfo/Setup.h"
17 //---------------------------------------------------------------------------
18 
19 #if MEDIAINFO_TRACE
20 //---------------------------------------------------------------------------
21 #include "MediaInfo/File__Analyze.h"
22 #include "MediaInfo/MediaInfo_Config.h"
23 #include "ZenLib/BitStream_LE.h"
24 #include <cmath>
25 using namespace std;
26 //---------------------------------------------------------------------------
27 
28 namespace MediaInfoLib
29 {
30 
31 //---------------------------------------------------------------------------
32 extern MediaInfo_Config Config;
33 //---------------------------------------------------------------------------
34 
35 //Integrity test
36 #define INTEGRITY(TOVALIDATE, ERRORTEXT, OFFSET) \
37     if (!(TOVALIDATE)) \
38     { \
39         Trusted_IsNot(ERRORTEXT); \
40         return; \
41     } \
42 
43 #define INTEGRITY_INT(TOVALIDATE, ERRORTEXT, OFFSET) \
44     if (!(TOVALIDATE)) \
45     { \
46         Trusted_IsNot(ERRORTEXT); \
47         Info=0; \
48         return; \
49     } \
50 
51 #define INTEGRITY_SIZE_ATLEAST(_BYTES) \
52     if (Element_Offset+_BYTES>Element_Size) \
53     { \
54         Trusted_IsNot("Size is wrong"); \
55         return; \
56     } \
57 
58 #define INTEGRITY_SIZE_ATLEAST_STRING(_BYTES) \
59     if (Element_Offset+_BYTES>Element_Size) \
60     { \
61         Trusted_IsNot("Size is wrong"); \
62         Info.clear(); \
63         return; \
64     } \
65 
66 #define INTEGRITY_SIZE_ATLEAST_INT(_BYTES) \
67     if (Element_Offset+_BYTES>Element_Size) \
68     { \
69         Trusted_IsNot("Size is wrong"); \
70         Info=0; \
71         return; \
72     } \
73 
74 #define INTEGRITY_SIZE_ATLEAST_BUFFER() \
75     if (BS->Remain()==0) \
76     { \
77         Trusted_IsNot("Size is wrong"); \
78         Info=0; \
79         return; \
80     } \
81 
82 //***************************************************************************
83 // Init
84 //***************************************************************************
85 
86 //---------------------------------------------------------------------------
BS_Begin()87 void File__Analyze::BS_Begin()
88 {
89     #if !MEDIAINFO_TRACE
90         size_t BS_Size;
91     #endif
92     if (Element_Offset>=Element_Size)
93         BS_Size=0;
94     else if (Buffer_Offset+Element_Size<=Buffer_Size)
95         BS_Size=(size_t)(Element_Size-Element_Offset);
96     else if (Buffer_Offset+Element_Offset<=Buffer_Size)
97         BS_Size=Buffer_Size-(size_t)(Buffer_Offset+Element_Offset);
98     else
99         BS_Size=0;
100 
101     BS->Attach(Buffer+Buffer_Offset+(size_t)(BS_Size?Element_Offset:0), BS_Size);
102     #if MEDIAINFO_TRACE
103         BS_Size<<=3; //In bits
104     #endif
105 }
106 
107 //---------------------------------------------------------------------------
BS_Begin_LE()108 void File__Analyze::BS_Begin_LE()
109 {
110     #if !MEDIAINFO_TRACE
111         size_t BS_Size;
112     #endif
113     if (Buffer_Offset+Element_Size<=Buffer_Size)
114         BS_Size=(size_t)(Element_Size-Element_Offset);
115     else if (Buffer_Offset+Element_Offset<=Buffer_Size)
116         BS_Size=Buffer_Size-(size_t)(Buffer_Offset+Element_Offset);
117     else
118         BS_Size=0;
119 
120     BT->Attach(Buffer+Buffer_Offset+(size_t)Element_Offset, BS_Size);
121     #if MEDIAINFO_TRACE
122         BS_Size<<=3; //In bits
123     #endif
124 }
125 
126 //---------------------------------------------------------------------------
BS_End()127 void File__Analyze::BS_End()
128 {
129     BS->Byte_Align();
130     Element_Offset+=BS->Offset_Get();
131     BS->Attach(NULL, 0);
132     #if MEDIAINFO_TRACE
133         BS_Size=0;
134     #endif
135 }
136 
137 //---------------------------------------------------------------------------
BS_End_LE()138 void File__Analyze::BS_End_LE()
139 {
140     BT->Byte_Align();
141     Element_Offset+=BT->Offset_Get();
142     BT->Attach(NULL, 0);
143     #if MEDIAINFO_TRACE
144         BS_Size=0;
145     #endif
146 }
147 
148 //***************************************************************************
149 // Big Endian
150 //***************************************************************************
151 
152 //---------------------------------------------------------------------------
Get_B1(int8u & Info,const char * Name)153 void File__Analyze::Get_B1(int8u  &Info, const char* Name)
154 {
155     INTEGRITY_SIZE_ATLEAST_INT(1);
156     Info=BigEndian2int8u(Buffer+Buffer_Offset+(size_t)Element_Offset);
157     if (Trace_Activated) Param(Name, Info);
158     Element_Offset+=1;
159 }
160 
161 //---------------------------------------------------------------------------
Get_B2(int16u & Info,const char * Name)162 void File__Analyze::Get_B2(int16u &Info, const char* Name)
163 {
164     INTEGRITY_SIZE_ATLEAST_INT(2);
165     Info=BigEndian2int16u(Buffer+Buffer_Offset+(size_t)Element_Offset);
166     if (Trace_Activated) Param(Name, Info);
167     Element_Offset+=2;
168 }
169 
170 //---------------------------------------------------------------------------
Get_B3(int32u & Info,const char * Name)171 void File__Analyze::Get_B3(int32u &Info, const char* Name)
172 {
173     INTEGRITY_SIZE_ATLEAST_INT(3);
174     Info=BigEndian2int24u(Buffer+Buffer_Offset+(size_t)Element_Offset);
175     if (Trace_Activated)
176         Param(Name, Info, 24);
177     Element_Offset+=3;
178 }
179 
180 //---------------------------------------------------------------------------
Get_B4(int32u & Info,const char * Name)181 void File__Analyze::Get_B4(int32u &Info, const char* Name)
182 {
183     INTEGRITY_SIZE_ATLEAST_INT(4);
184     Info=BigEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset);
185     if (Trace_Activated)
186         Param(Name, Info);
187     Element_Offset+=4;
188 }
189 
190 //---------------------------------------------------------------------------
Get_B5(int64u & Info,const char * Name)191 void File__Analyze::Get_B5(int64u &Info, const char* Name)
192 {
193     INTEGRITY_SIZE_ATLEAST_INT(5);
194     Info=BigEndian2int40u(Buffer+Buffer_Offset+(size_t)Element_Offset);
195     if (Trace_Activated) Param(Name, Info);
196     Element_Offset+=5;
197 }
198 
199 //---------------------------------------------------------------------------
Get_B6(int64u & Info,const char * Name)200 void File__Analyze::Get_B6(int64u &Info, const char* Name)
201 {
202     INTEGRITY_SIZE_ATLEAST_INT(6);
203     Info=BigEndian2int48u(Buffer+Buffer_Offset+(size_t)Element_Offset);
204     if (Trace_Activated) Param(Name, Info);
205     Element_Offset+=6;
206 }
207 
208 //---------------------------------------------------------------------------
Get_B7(int64u & Info,const char * Name)209 void File__Analyze::Get_B7(int64u &Info, const char* Name)
210 {
211     INTEGRITY_SIZE_ATLEAST_INT(7);
212     Info=BigEndian2int56u(Buffer+Buffer_Offset+(size_t)Element_Offset);
213     if (Trace_Activated) Param(Name, Info);
214     Element_Offset+=7;
215 }
216 
217 //---------------------------------------------------------------------------
Get_B8(int64u & Info,const char * Name)218 void File__Analyze::Get_B8(int64u &Info, const char* Name)
219 {
220     INTEGRITY_SIZE_ATLEAST_INT(8);
221     Info=BigEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset);
222     if (Trace_Activated) Param(Name, Info);
223     Element_Offset+=8;
224 }
225 
226 //---------------------------------------------------------------------------
Get_B16(int128u & Info,const char * Name)227 void File__Analyze::Get_B16(int128u &Info, const char* Name)
228 {
229     INTEGRITY_SIZE_ATLEAST_INT(16);
230     //Info=BigEndian2int128u(Buffer+Buffer_Offset+(size_t)Element_Offset);
231     Info.hi=BigEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset);
232     Info.lo=BigEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset+8);
233     if (Trace_Activated) Param(Name, Info);
234     Element_Offset+=16;
235 }
236 
237 //---------------------------------------------------------------------------
238 // Big Endian - float 16 bits
239 // TODO: remove it when Linux version of ZenLib is updated
BigEndian2float16corrected(const char * Liste)240 float32 BigEndian2float16corrected(const char* Liste)
241 {
242     //sign          1 bit
243     //exponent      5 bit
244     //significand  10 bit
245 
246     //Retrieving data
247     int16u Integer=BigEndian2int16u(Liste);
248 
249     //Retrieving elements
250     bool   Sign    =(Integer&0x8000)?true:false;
251     int32u Exponent=(Integer>>10)&0xFF;
252     int32u Mantissa= Integer&0x03FF;
253 
254     //Some computing
255     if (Exponent==0 || Exponent==0xFF)
256         return 0; //These are denormalised numbers, NANs, and other horrible things
257     Exponent-=0x0F; //Bias
258     float64 Answer=(((float64)Mantissa)/8388608+1.0)*std::pow((float64)2, (int)Exponent); //(1+Mantissa) * 2^Exponent
259     if (Sign)
260         Answer=-Answer;
261 
262     return (float32)Answer;
263 }
BigEndian2float16corrected(const int8u * List)264 inline float32 BigEndian2float16corrected  (const int8u* List) {return BigEndian2float16corrected   ((const char*)List);}
265 
266 //---------------------------------------------------------------------------
Get_BF2(float32 & Info,const char * Name)267 void File__Analyze::Get_BF2(float32 &Info, const char* Name)
268 {
269     INTEGRITY_SIZE_ATLEAST_INT(2);
270     Info=BigEndian2float16corrected(Buffer+Buffer_Offset+(size_t)Element_Offset);
271     if (Trace_Activated) Param(Name, Info);
272     Element_Offset+=2;
273 }
274 
275 //---------------------------------------------------------------------------
Get_BF4(float32 & Info,const char * Name)276 void File__Analyze::Get_BF4(float32 &Info, const char* Name)
277 {
278     INTEGRITY_SIZE_ATLEAST_INT(4);
279     Info=BigEndian2float32(Buffer+Buffer_Offset+(size_t)Element_Offset);
280     if (Trace_Activated) Param(Name, Info);
281     Element_Offset+=4;
282 }
283 
284 //---------------------------------------------------------------------------
Get_BF8(float64 & Info,const char * Name)285 void File__Analyze::Get_BF8(float64 &Info, const char* Name)
286 {
287     INTEGRITY_SIZE_ATLEAST_INT(8);
288     Info=BigEndian2float64(Buffer+Buffer_Offset+(size_t)Element_Offset);
289     if (Trace_Activated) Param(Name, Info);
290     Element_Offset+=8;
291 }
292 
293 //---------------------------------------------------------------------------
Get_BF10(float80 & Info,const char * Name)294 void File__Analyze::Get_BF10(float80 &Info, const char* Name)
295 {
296     INTEGRITY_SIZE_ATLEAST_INT(10);
297     Info=BigEndian2float80(Buffer+Buffer_Offset+(size_t)Element_Offset);
298     if (Trace_Activated) Param(Name, Info);
299     Element_Offset+=10;
300 }
301 
302 //---------------------------------------------------------------------------
Get_BFP4(int8u Bits,float32 & Info,const char * Name)303 void File__Analyze::Get_BFP4(int8u Bits, float32 &Info, const char* Name)
304 {
305     INTEGRITY_SIZE_ATLEAST_INT(4);
306     BS_Begin();
307     int32s Integer=(int32s)BS->Get4(Bits);
308     int32u Fraction=BS->Get4(32-Bits);
309     BS_End();
310     Element_Offset-=4; //Because of BS_End()
311     if (Integer>=(1<<Bits)/2)
312         Integer-=1<<Bits;
313     Info=Integer+((float32)Fraction)/(1<<(32-Bits));
314     if (Trace_Activated) Param(Name, Info);
315     Element_Offset+=4;
316 }
317 
318 //---------------------------------------------------------------------------
Peek_B1(int8u & Info)319 void File__Analyze::Peek_B1(int8u  &Info)
320 {
321     INTEGRITY_SIZE_ATLEAST_INT(1);
322     Info=BigEndian2int8u(Buffer+Buffer_Offset+(size_t)Element_Offset);
323 }
324 
325 //---------------------------------------------------------------------------
Peek_B2(int16u & Info)326 void File__Analyze::Peek_B2(int16u &Info)
327 {
328     INTEGRITY_SIZE_ATLEAST_INT(2);
329     Info=BigEndian2int16u(Buffer+Buffer_Offset+(size_t)Element_Offset);
330 }
331 
332 //---------------------------------------------------------------------------
Peek_B3(int32u & Info)333 void File__Analyze::Peek_B3(int32u &Info)
334 {
335     INTEGRITY_SIZE_ATLEAST_INT(3);
336     Info=BigEndian2int24u(Buffer+Buffer_Offset+(size_t)Element_Offset);
337 }
338 
339 //---------------------------------------------------------------------------
Peek_B4(int32u & Info)340 void File__Analyze::Peek_B4(int32u &Info)
341 {
342     INTEGRITY_SIZE_ATLEAST_INT(4);
343     Info=BigEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset);
344 }
345 
346 //---------------------------------------------------------------------------
Peek_B5(int64u & Info)347 void File__Analyze::Peek_B5(int64u &Info)
348 {
349     INTEGRITY_SIZE_ATLEAST_INT(5);
350     Info=BigEndian2int40u(Buffer+Buffer_Offset+(size_t)Element_Offset);
351 }
352 
353 //---------------------------------------------------------------------------
Peek_B6(int64u & Info)354 void File__Analyze::Peek_B6(int64u &Info)
355 {
356     INTEGRITY_SIZE_ATLEAST_INT(6);
357     Info=BigEndian2int48u(Buffer+Buffer_Offset+(size_t)Element_Offset);
358 }
359 
360 //---------------------------------------------------------------------------
Peek_B7(int64u & Info)361 void File__Analyze::Peek_B7(int64u &Info)
362 {
363     INTEGRITY_SIZE_ATLEAST_INT(7);
364     Info=BigEndian2int56u(Buffer+Buffer_Offset+(size_t)Element_Offset);
365 }
366 
367 //---------------------------------------------------------------------------
Peek_B8(int64u & Info)368 void File__Analyze::Peek_B8(int64u &Info)
369 {
370     INTEGRITY_SIZE_ATLEAST_INT(8);
371     Info=BigEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset);
372 }
373 
374 //---------------------------------------------------------------------------
Peek_B16(int128u & Info)375 void File__Analyze::Peek_B16(int128u &Info)
376 {
377     INTEGRITY_SIZE_ATLEAST_INT(16);
378     Info=BigEndian2int128u(Buffer+Buffer_Offset+(size_t)Element_Offset);
379 }
380 
381 //---------------------------------------------------------------------------
Skip_B1(const char * Name)382 void File__Analyze::Skip_B1(const char* Name)
383 {
384     INTEGRITY_SIZE_ATLEAST(1);
385     if (Trace_Activated) Param(Name, BigEndian2int8u(Buffer+Buffer_Offset+(size_t)Element_Offset));
386     Element_Offset+=1;
387 }
388 
389 //---------------------------------------------------------------------------
Skip_B2(const char * Name)390 void File__Analyze::Skip_B2(const char* Name)
391 {
392     INTEGRITY_SIZE_ATLEAST(2);
393     if (Trace_Activated) Param(Name, BigEndian2int16u(Buffer+Buffer_Offset+(size_t)Element_Offset));
394     Element_Offset+=2;
395 }
396 
397 //---------------------------------------------------------------------------
Skip_B3(const char * Name)398 void File__Analyze::Skip_B3(const char* Name)
399 {
400     INTEGRITY_SIZE_ATLEAST(3);
401     if (Trace_Activated)
402     {
403         int32u Info=BigEndian2int24u(Buffer+Buffer_Offset+(size_t)Element_Offset);
404         Param(Name, Info, 24);
405     }
406     Element_Offset+=3;
407 }
408 
409 //---------------------------------------------------------------------------
Skip_B4(const char * Name)410 void File__Analyze::Skip_B4(const char* Name)
411 {
412     INTEGRITY_SIZE_ATLEAST(4);
413     if (Trace_Activated)
414     {
415         int32u Info=BigEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset);
416         Param(Name, Info);
417     }
418     Element_Offset+=4;
419 }
420 
421 //---------------------------------------------------------------------------
Skip_B5(const char * Name)422 void File__Analyze::Skip_B5(const char* Name)
423 {
424     INTEGRITY_SIZE_ATLEAST(5);
425     if (Trace_Activated) Param(Name, BigEndian2int40u(Buffer+Buffer_Offset+(size_t)Element_Offset));
426     Element_Offset+=5;
427 }
428 
429 //---------------------------------------------------------------------------
Skip_B6(const char * Name)430 void File__Analyze::Skip_B6(const char* Name)
431 {
432     INTEGRITY_SIZE_ATLEAST(6);
433     if (Trace_Activated) Param(Name, BigEndian2int48u(Buffer+Buffer_Offset+(size_t)Element_Offset));
434     Element_Offset+=6;
435 }
436 
437 //---------------------------------------------------------------------------
Skip_B7(const char * Name)438 void File__Analyze::Skip_B7(const char* Name)
439 {
440     INTEGRITY_SIZE_ATLEAST(7);
441     if (Trace_Activated) Param(Name, BigEndian2int56u(Buffer+Buffer_Offset+(size_t)Element_Offset));
442     Element_Offset+=7;
443 }
444 
445 //---------------------------------------------------------------------------
Skip_B8(const char * Name)446 void File__Analyze::Skip_B8(const char* Name)
447 {
448     INTEGRITY_SIZE_ATLEAST(8);
449     if (Trace_Activated) Param(Name, BigEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset));
450     Element_Offset+=8;
451 }
452 
453 //---------------------------------------------------------------------------
Skip_B16(const char * Name)454 void File__Analyze::Skip_B16(const char* Name)
455 {
456     INTEGRITY_SIZE_ATLEAST(16);
457     if (Trace_Activated) Param(Name, BigEndian2int128u(Buffer+Buffer_Offset+(size_t)Element_Offset));
458     Element_Offset+=16;
459 }
460 
461 //---------------------------------------------------------------------------
Skip_Hexa(int8u Bytes,const char * Name)462 void File__Analyze::Skip_Hexa(int8u Bytes, const char* Name)
463 {
464     INTEGRITY_SIZE_ATLEAST(Bytes);
465     if (Trace_Activated)
466     {
467         string ValueS;
468         ValueS.resize(Bytes*2);
469         const int8u* Buffer_Temp=Buffer+Buffer_Offset+(size_t)Element_Offset;
470         for (int8u i=0; i<Bytes; i++)
471         {
472             int8u Value=Buffer_Temp[i];
473             int8u Value0=Value>>4;
474             int8u Value1=Value&0xF;
475             ValueS[i*2  ]=Value0+(Value0>9?('A'-10):('0'));
476             ValueS[i*2+1]=Value1+(Value1>9?('A'-10):('0'));
477         }
478         Param(Name, ValueS);
479     }
480     Element_Offset+=Bytes;
481 }
482 
483 //---------------------------------------------------------------------------
Skip_BF4(const char * Name)484 void File__Analyze::Skip_BF4(const char* Name)
485 {
486     INTEGRITY_SIZE_ATLEAST(4);
487     if (Trace_Activated) Param(Name, BigEndian2float32(Buffer+Buffer_Offset+(size_t)Element_Offset));
488     Element_Offset+=4;
489 }
490 
491 //---------------------------------------------------------------------------
Skip_BFP4(int8u Bits,const char * Name)492 void File__Analyze::Skip_BFP4(int8u Bits, const char* Name)
493 {
494     INTEGRITY_SIZE_ATLEAST(4);
495     BS_Begin();
496     int32u Integer=BS->Get4(Bits);
497     int32u Fraction=BS->Get4(32-Bits);
498     BS_End();
499     Element_Offset-=4; //Because of BS_End()
500     if (Trace_Activated) Param(Name, Integer+((float32)Fraction)/(1<<(32-Bits)));
501     Element_Offset+=4;
502 }
503 
504 //***************************************************************************
505 // Little Endian
506 //***************************************************************************
507 
508 //---------------------------------------------------------------------------
Get_L1(int8u & Info,const char * Name)509 void File__Analyze::Get_L1(int8u  &Info, const char* Name)
510 {
511     INTEGRITY_SIZE_ATLEAST_INT(1);
512     Info=LittleEndian2int8u(Buffer+Buffer_Offset+(size_t)Element_Offset);
513     if (Trace_Activated) Param(Name, Info);
514     Element_Offset+=1;
515 }
516 
517 //---------------------------------------------------------------------------
Get_L2(int16u & Info,const char * Name)518 void File__Analyze::Get_L2(int16u &Info, const char* Name)
519 {
520     INTEGRITY_SIZE_ATLEAST_INT(2);
521     Info=LittleEndian2int16u(Buffer+Buffer_Offset+(size_t)Element_Offset);
522     if (Trace_Activated) Param(Name, Info);
523     Element_Offset+=2;
524 }
525 
526 //---------------------------------------------------------------------------
Get_L3(int32u & Info,const char * Name)527 void File__Analyze::Get_L3(int32u &Info, const char* Name)
528 {
529     INTEGRITY_SIZE_ATLEAST_INT(3);
530     Info=LittleEndian2int24u(Buffer+Buffer_Offset+(size_t)Element_Offset);
531     if (Trace_Activated) Param(Name, Info);
532     Element_Offset+=3;
533 }
534 
535 //---------------------------------------------------------------------------
Get_L4(int32u & Info,const char * Name)536 void File__Analyze::Get_L4(int32u &Info, const char* Name)
537 {
538     INTEGRITY_SIZE_ATLEAST_INT(4);
539     Info=LittleEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset);
540     if (Trace_Activated) Param(Name, Info);
541     Element_Offset+=4;
542 }
543 
544 //---------------------------------------------------------------------------
Get_L5(int64u & Info,const char * Name)545 void File__Analyze::Get_L5(int64u &Info, const char* Name)
546 {
547     INTEGRITY_SIZE_ATLEAST_INT(5);
548     Info=LittleEndian2int40u(Buffer+Buffer_Offset+(size_t)Element_Offset);
549     if (Trace_Activated) Param(Name, Info);
550     Element_Offset+=5;
551 }
552 
553 //---------------------------------------------------------------------------
Get_L6(int64u & Info,const char * Name)554 void File__Analyze::Get_L6(int64u &Info, const char* Name)
555 {
556     INTEGRITY_SIZE_ATLEAST_INT(6);
557     Info=LittleEndian2int48u(Buffer+Buffer_Offset+(size_t)Element_Offset);
558     if (Trace_Activated) Param(Name, Info);
559     Element_Offset+=6;
560 }
561 
562 //---------------------------------------------------------------------------
Get_L7(int64u & Info,const char * Name)563 void File__Analyze::Get_L7(int64u &Info, const char* Name)
564 {
565     INTEGRITY_SIZE_ATLEAST_INT(7);
566     Info=LittleEndian2int56u(Buffer+Buffer_Offset+(size_t)Element_Offset);
567     if (Trace_Activated) Param(Name, Info);
568     Element_Offset+=7;
569 }
570 
571 //---------------------------------------------------------------------------
Get_L8(int64u & Info,const char * Name)572 void File__Analyze::Get_L8(int64u &Info, const char* Name)
573 {
574     INTEGRITY_SIZE_ATLEAST_INT(8);
575     Info=LittleEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset);
576     if (Trace_Activated) Param(Name, Info);
577     Element_Offset+=8;
578 }
579 
580 //---------------------------------------------------------------------------
Get_L16(int128u & Info,const char * Name)581 void File__Analyze::Get_L16(int128u &Info, const char* Name)
582 {
583     INTEGRITY_SIZE_ATLEAST_INT(16);
584     //Info=LittleEndian2int128u(Buffer+Buffer_Offset+(size_t)Element_Offset);
585     Info.hi=LittleEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset);
586     Info.lo=LittleEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset+8);
587     if (Trace_Activated) Param(Name, Info);
588     Element_Offset+=16;
589 }
590 
591 //---------------------------------------------------------------------------
Get_LF4(float32 & Info,const char * Name)592 void File__Analyze::Get_LF4(float32 &Info, const char* Name)
593 {
594     INTEGRITY_SIZE_ATLEAST_INT(4);
595     Info=LittleEndian2float32(Buffer+Buffer_Offset+(size_t)Element_Offset);
596     if (Trace_Activated) Param(Name, Info);
597     Element_Offset+=4;
598 }
599 
600 //---------------------------------------------------------------------------
Get_LF8(float64 & Info,const char * Name)601 void File__Analyze::Get_LF8(float64 &Info, const char* Name)
602 {
603     INTEGRITY_SIZE_ATLEAST_INT(8);
604     Info=LittleEndian2float64(Buffer+Buffer_Offset+(size_t)Element_Offset);
605     if (Trace_Activated) Param(Name, Info);
606     Element_Offset+=8;
607 }
608 
609 //---------------------------------------------------------------------------
Peek_L1(int8u & Info)610 void File__Analyze::Peek_L1(int8u  &Info)
611 {
612     INTEGRITY_SIZE_ATLEAST_INT(1);
613     Info=LittleEndian2int8u(Buffer+Buffer_Offset+(size_t)Element_Offset);
614 }
615 
616 //---------------------------------------------------------------------------
Peek_L2(int16u & Info)617 void File__Analyze::Peek_L2(int16u &Info)
618 {
619     INTEGRITY_SIZE_ATLEAST_INT(2);
620     Info=LittleEndian2int16u(Buffer+Buffer_Offset+(size_t)Element_Offset);
621 }
622 
623 //---------------------------------------------------------------------------
Peek_L3(int32u & Info)624 void File__Analyze::Peek_L3(int32u &Info)
625 {
626     INTEGRITY_SIZE_ATLEAST_INT(3);
627     Info=LittleEndian2int24u(Buffer+Buffer_Offset+(size_t)Element_Offset);
628 }
629 
630 //---------------------------------------------------------------------------
Peek_L4(int32u & Info)631 void File__Analyze::Peek_L4(int32u &Info)
632 {
633     INTEGRITY_SIZE_ATLEAST_INT(4);
634     Info=LittleEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset);
635 }
636 
637 //---------------------------------------------------------------------------
Peek_L5(int64u & Info)638 void File__Analyze::Peek_L5(int64u &Info)
639 {
640     INTEGRITY_SIZE_ATLEAST_INT(5);
641     Info=LittleEndian2int40u(Buffer+Buffer_Offset+(size_t)Element_Offset);
642 }
643 
644 //---------------------------------------------------------------------------
Peek_L6(int64u & Info)645 void File__Analyze::Peek_L6(int64u &Info)
646 {
647     INTEGRITY_SIZE_ATLEAST_INT(6);
648     Info=LittleEndian2int48u(Buffer+Buffer_Offset+(size_t)Element_Offset);
649 }
650 
651 //---------------------------------------------------------------------------
Peek_L7(int64u & Info)652 void File__Analyze::Peek_L7(int64u &Info)
653 {
654     INTEGRITY_SIZE_ATLEAST_INT(7);
655     Info=LittleEndian2int56u(Buffer+Buffer_Offset+(size_t)Element_Offset);
656 }
657 
658 //---------------------------------------------------------------------------
Peek_L8(int64u & Info)659 void File__Analyze::Peek_L8(int64u &Info)
660 {
661     INTEGRITY_SIZE_ATLEAST_INT(8);
662     Info=LittleEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset);
663 }
664 
665 //---------------------------------------------------------------------------
Skip_L1(const char * Name)666 void File__Analyze::Skip_L1(const char* Name)
667 {
668     INTEGRITY_SIZE_ATLEAST(1);
669     if (Trace_Activated) Param(Name, LittleEndian2int8u(Buffer+Buffer_Offset+(size_t)Element_Offset));
670     Element_Offset+=1;
671 }
672 
673 //---------------------------------------------------------------------------
Skip_L2(const char * Name)674 void File__Analyze::Skip_L2(const char* Name)
675 {
676     INTEGRITY_SIZE_ATLEAST(2);
677     if (Trace_Activated) Param(Name, LittleEndian2int16u(Buffer+Buffer_Offset+(size_t)Element_Offset));
678     Element_Offset+=2;
679 }
680 
681 //---------------------------------------------------------------------------
Skip_L3(const char * Name)682 void File__Analyze::Skip_L3(const char* Name)
683 {
684     INTEGRITY_SIZE_ATLEAST(3);
685     if (Trace_Activated)
686     {
687         int32u Info=LittleEndian2int24u(Buffer+Buffer_Offset+(size_t)Element_Offset);
688         Param(Name, Info, 24);
689     }
690     Element_Offset+=3;
691 }
692 
693 //---------------------------------------------------------------------------
Skip_L4(const char * Name)694 void File__Analyze::Skip_L4(const char* Name)
695 {
696     INTEGRITY_SIZE_ATLEAST(4);
697     if (Trace_Activated)
698     {
699         int32u Info=LittleEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset);
700         Param(Name, Info);
701     }
702     Element_Offset+=4;
703 }
704 
705 //---------------------------------------------------------------------------
Skip_L5(const char * Name)706 void File__Analyze::Skip_L5(const char* Name)
707 {
708     INTEGRITY_SIZE_ATLEAST(5);
709     if (Trace_Activated) Param(Name, LittleEndian2int40u(Buffer+Buffer_Offset+(size_t)Element_Offset));
710     Element_Offset+=5;
711 }
712 
713 //---------------------------------------------------------------------------
Skip_L6(const char * Name)714 void File__Analyze::Skip_L6(const char* Name)
715 {
716     INTEGRITY_SIZE_ATLEAST(6);
717     if (Trace_Activated) Param(Name, LittleEndian2int48u(Buffer+Buffer_Offset+(size_t)Element_Offset));
718     Element_Offset+=6;
719 }
720 
721 //---------------------------------------------------------------------------
Skip_L7(const char * Name)722 void File__Analyze::Skip_L7(const char* Name)
723 {
724     INTEGRITY_SIZE_ATLEAST(7);
725     if (Trace_Activated) Param(Name, LittleEndian2int56u(Buffer+Buffer_Offset+(size_t)Element_Offset));
726     Element_Offset+=7;
727 }
728 
729 //---------------------------------------------------------------------------
Skip_L8(const char * Name)730 void File__Analyze::Skip_L8(const char* Name)
731 {
732     INTEGRITY_SIZE_ATLEAST(8);
733     if (Trace_Activated) Param(Name, LittleEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset));
734     Element_Offset+=8;
735 }
736 
737 //---------------------------------------------------------------------------
Skip_L16(const char * Name)738 void File__Analyze::Skip_L16(const char* Name)
739 {
740     INTEGRITY_SIZE_ATLEAST(16);
741     if (Trace_Activated) Param(Name, LittleEndian2int128u(Buffer+Buffer_Offset+(size_t)Element_Offset));
742     Element_Offset+=16;
743 }
744 
745 //***************************************************************************
746 // Little and Big Endian together
747 //***************************************************************************
748 
749 //---------------------------------------------------------------------------
Get_D1(int8u & Info,const char * Name)750 void File__Analyze::Get_D1(int8u  &Info, const char* Name)
751 {
752     INTEGRITY_SIZE_ATLEAST_INT(2);
753     Info=LittleEndian2int8u(Buffer+Buffer_Offset+(size_t)Element_Offset);
754     if (Trace_Activated) Param(Name, Info);
755     Element_Offset+=2;
756 }
757 
758 //---------------------------------------------------------------------------
Get_D2(int16u & Info,const char * Name)759 void File__Analyze::Get_D2(int16u &Info, const char* Name)
760 {
761     INTEGRITY_SIZE_ATLEAST_INT(4);
762     Info=LittleEndian2int16u(Buffer+Buffer_Offset+(size_t)Element_Offset);
763     if (Trace_Activated) Param(Name, Info);
764     Element_Offset+=4;
765 }
766 
767 //---------------------------------------------------------------------------
Get_D3(int32u & Info,const char * Name)768 void File__Analyze::Get_D3(int32u &Info, const char* Name)
769 {
770     INTEGRITY_SIZE_ATLEAST_INT(6);
771     Info=LittleEndian2int24u(Buffer+Buffer_Offset+(size_t)Element_Offset);
772     if (Trace_Activated) Param(Name, Info);
773     Element_Offset+=6;
774 }
775 
776 //---------------------------------------------------------------------------
Get_D4(int32u & Info,const char * Name)777 void File__Analyze::Get_D4(int32u &Info, const char* Name)
778 {
779     INTEGRITY_SIZE_ATLEAST_INT(8);
780     Info=LittleEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset);
781     if (Trace_Activated) Param(Name, Info);
782     Element_Offset+=8;
783 }
784 
785 //---------------------------------------------------------------------------
Get_D5(int64u & Info,const char * Name)786 void File__Analyze::Get_D5(int64u &Info, const char* Name)
787 {
788     INTEGRITY_SIZE_ATLEAST_INT(10);
789     Info=LittleEndian2int40u(Buffer+Buffer_Offset+(size_t)Element_Offset);
790     if (Trace_Activated) Param(Name, Info);
791     Element_Offset+=10;
792 }
793 
794 //---------------------------------------------------------------------------
Get_D6(int64u & Info,const char * Name)795 void File__Analyze::Get_D6(int64u &Info, const char* Name)
796 {
797     INTEGRITY_SIZE_ATLEAST_INT(12);
798     Info=LittleEndian2int48u(Buffer+Buffer_Offset+(size_t)Element_Offset);
799     if (Trace_Activated) Param(Name, Info);
800     Element_Offset+=12;
801 }
802 
803 //---------------------------------------------------------------------------
Get_D7(int64u & Info,const char * Name)804 void File__Analyze::Get_D7(int64u &Info, const char* Name)
805 {
806     INTEGRITY_SIZE_ATLEAST_INT(14);
807     Info=LittleEndian2int56u(Buffer+Buffer_Offset+(size_t)Element_Offset);
808     if (Trace_Activated) Param(Name, Info);
809     Element_Offset+=14;
810 }
811 
812 //---------------------------------------------------------------------------
Get_D8(int64u & Info,const char * Name)813 void File__Analyze::Get_D8(int64u &Info, const char* Name)
814 {
815     INTEGRITY_SIZE_ATLEAST_INT(16);
816     Info=LittleEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset);
817     if (Trace_Activated) Param(Name, Info);
818     Element_Offset+=16;
819 }
820 
821 //---------------------------------------------------------------------------
Get_D16(int128u & Info,const char * Name)822 void File__Analyze::Get_D16(int128u &Info, const char* Name)
823 {
824     INTEGRITY_SIZE_ATLEAST_INT(32);
825     //Info=LittleEndian2int128u(Buffer+Buffer_Offset+(size_t)Element_Offset);
826     Info.hi=LittleEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset);
827     Info.lo=LittleEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset+8);
828     if (Trace_Activated) Param(Name, Info);
829     Element_Offset+=32;
830 }
831 
832 //---------------------------------------------------------------------------
Get_DF4(float32 & Info,const char * Name)833 void File__Analyze::Get_DF4(float32 &Info, const char* Name)
834 {
835     INTEGRITY_SIZE_ATLEAST_INT(8);
836     Info=LittleEndian2float32(Buffer+Buffer_Offset+(size_t)Element_Offset);
837     if (Trace_Activated) Param(Name, Info);
838     Element_Offset+=8;
839 }
840 
841 //---------------------------------------------------------------------------
Get_DF8(float64 & Info,const char * Name)842 void File__Analyze::Get_DF8(float64 &Info, const char* Name)
843 {
844     INTEGRITY_SIZE_ATLEAST_INT(16);
845     Info=LittleEndian2float64(Buffer+Buffer_Offset+(size_t)Element_Offset);
846     if (Trace_Activated) Param(Name, Info);
847     Element_Offset+=16;
848 }
849 
850 //---------------------------------------------------------------------------
Peek_D1(int8u & Info)851 void File__Analyze::Peek_D1(int8u  &Info)
852 {
853     INTEGRITY_SIZE_ATLEAST_INT(8);
854     Info=LittleEndian2int8u(Buffer+Buffer_Offset+(size_t)Element_Offset);
855 }
856 
857 //---------------------------------------------------------------------------
Peek_D2(int16u & Info)858 void File__Analyze::Peek_D2(int16u &Info)
859 {
860     INTEGRITY_SIZE_ATLEAST_INT(4);
861     Info=LittleEndian2int16u(Buffer+Buffer_Offset+(size_t)Element_Offset);
862 }
863 
864 //---------------------------------------------------------------------------
Peek_D3(int32u & Info)865 void File__Analyze::Peek_D3(int32u &Info)
866 {
867     INTEGRITY_SIZE_ATLEAST_INT(6);
868     Info=LittleEndian2int24u(Buffer+Buffer_Offset+(size_t)Element_Offset);
869 }
870 
871 //---------------------------------------------------------------------------
Peek_D4(int32u & Info)872 void File__Analyze::Peek_D4(int32u &Info)
873 {
874     INTEGRITY_SIZE_ATLEAST_INT(8);
875     Info=LittleEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset);
876 }
877 
878 //---------------------------------------------------------------------------
Peek_D5(int64u & Info)879 void File__Analyze::Peek_D5(int64u &Info)
880 {
881     INTEGRITY_SIZE_ATLEAST_INT(10);
882     Info=LittleEndian2int40u(Buffer+Buffer_Offset+(size_t)Element_Offset);
883 }
884 
885 //---------------------------------------------------------------------------
Peek_D6(int64u & Info)886 void File__Analyze::Peek_D6(int64u &Info)
887 {
888     INTEGRITY_SIZE_ATLEAST_INT(12);
889     Info=LittleEndian2int48u(Buffer+Buffer_Offset+(size_t)Element_Offset);
890 }
891 
892 //---------------------------------------------------------------------------
Peek_D7(int64u & Info)893 void File__Analyze::Peek_D7(int64u &Info)
894 {
895     INTEGRITY_SIZE_ATLEAST_INT(14);
896     Info=LittleEndian2int56u(Buffer+Buffer_Offset+(size_t)Element_Offset);
897 }
898 
899 //---------------------------------------------------------------------------
Peek_D8(int64u & Info)900 void File__Analyze::Peek_D8(int64u &Info)
901 {
902     INTEGRITY_SIZE_ATLEAST_INT(16);
903     Info=LittleEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset);
904 }
905 
906 //---------------------------------------------------------------------------
Skip_D1(const char * Name)907 void File__Analyze::Skip_D1(const char* Name)
908 {
909     INTEGRITY_SIZE_ATLEAST(2);
910     if (Trace_Activated) Param(Name, LittleEndian2int8u(Buffer+Buffer_Offset+(size_t)Element_Offset));
911     Element_Offset+=2;
912 }
913 
914 //---------------------------------------------------------------------------
Skip_D2(const char * Name)915 void File__Analyze::Skip_D2(const char* Name)
916 {
917     INTEGRITY_SIZE_ATLEAST(4);
918     if (Trace_Activated) Param(Name, LittleEndian2int16u(Buffer+Buffer_Offset+(size_t)Element_Offset));
919     Element_Offset+=4;
920 }
921 
922 //---------------------------------------------------------------------------
Skip_D3(const char * Name)923 void File__Analyze::Skip_D3(const char* Name)
924 {
925     INTEGRITY_SIZE_ATLEAST(6);
926     if (Trace_Activated)
927     {
928         int32u Info=LittleEndian2int24u(Buffer+Buffer_Offset+(size_t)Element_Offset);
929         Param(Name, Info, 24);
930     }
931     Element_Offset+=6;
932 }
933 
934 //---------------------------------------------------------------------------
Skip_D4(const char * Name)935 void File__Analyze::Skip_D4(const char* Name)
936 {
937     INTEGRITY_SIZE_ATLEAST(8);
938     if (Trace_Activated)
939     {
940         int32u Info=LittleEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset);
941         Param(Name, Info);
942     }
943     Element_Offset+=8;
944 }
945 
946 //---------------------------------------------------------------------------
Skip_D5(const char * Name)947 void File__Analyze::Skip_D5(const char* Name)
948 {
949     INTEGRITY_SIZE_ATLEAST(10);
950     if (Trace_Activated) Param(Name, LittleEndian2int40u(Buffer+Buffer_Offset+(size_t)Element_Offset));
951     Element_Offset+=5;
952 }
953 
954 //---------------------------------------------------------------------------
Skip_D6(const char * Name)955 void File__Analyze::Skip_D6(const char* Name)
956 {
957     INTEGRITY_SIZE_ATLEAST(12);
958     if (Trace_Activated) Param(Name, LittleEndian2int48u(Buffer+Buffer_Offset+(size_t)Element_Offset));
959     Element_Offset+=12;
960 }
961 
962 //---------------------------------------------------------------------------
Skip_D7(const char * Name)963 void File__Analyze::Skip_D7(const char* Name)
964 {
965     INTEGRITY_SIZE_ATLEAST(14);
966     if (Trace_Activated) Param(Name, LittleEndian2int56u(Buffer+Buffer_Offset+(size_t)Element_Offset));
967     Element_Offset+=14;
968 }
969 
970 //---------------------------------------------------------------------------
Skip_D8(const char * Name)971 void File__Analyze::Skip_D8(const char* Name)
972 {
973     INTEGRITY_SIZE_ATLEAST(16);
974     if (Trace_Activated) Param(Name, LittleEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset));
975     Element_Offset+=16;
976 }
977 
978 //---------------------------------------------------------------------------
Skip_D16(const char * Name)979 void File__Analyze::Skip_D16(const char* Name)
980 {
981     INTEGRITY_SIZE_ATLEAST(32);
982     if (Trace_Activated) Param(Name, LittleEndian2int128u(Buffer+Buffer_Offset+(size_t)Element_Offset));
983     Element_Offset+=32;
984 }
985 
986 //***************************************************************************
987 // GUID
988 //***************************************************************************
989 
990 //---------------------------------------------------------------------------
Get_GUID(int128u & Info,const char * Name)991 void File__Analyze::Get_GUID(int128u &Info, const char* Name)
992 {
993     INTEGRITY_SIZE_ATLEAST_INT(16);
994     Info.hi=BigEndian2int64u   (Buffer+Buffer_Offset+(size_t)Element_Offset);
995     Info.lo=BigEndian2int64u   (Buffer+Buffer_Offset+(size_t)Element_Offset+8);
996     if (Trace_Activated) Param_GUID(Name, Info);
997     Element_Offset+=16;
998 }
999 
1000 //---------------------------------------------------------------------------
Skip_GUID(const char * Name)1001 void File__Analyze::Skip_GUID(const char* Name)
1002 {
1003     INTEGRITY_SIZE_ATLEAST(16);
1004     if (Trace_Activated) Param_GUID(Name, BigEndian2int128u(Buffer+Buffer_Offset+(size_t)Element_Offset));
1005     Element_Offset+=16;
1006 }
1007 
1008 //***************************************************************************
1009 // UUID
1010 //***************************************************************************
1011 
1012 //---------------------------------------------------------------------------
Get_UUID(int128u & Info,const char * Name)1013 void File__Analyze::Get_UUID(int128u &Info, const char* Name)
1014 {
1015     INTEGRITY_SIZE_ATLEAST_INT(16);
1016     Info.hi=BigEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset);
1017     Info.lo=BigEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset+8);
1018     if (Trace_Activated) Param_UUID(Name, Info);
1019     Element_Offset+=16;
1020 }
1021 
1022 //---------------------------------------------------------------------------
Skip_UUID(const char * Name)1023 void File__Analyze::Skip_UUID(const char* Name)
1024 {
1025     INTEGRITY_SIZE_ATLEAST(16);
1026     if (Trace_Activated) Param_UUID(Name, BigEndian2int128u(Buffer+Buffer_Offset+(size_t)Element_Offset));
1027     Element_Offset+=16;
1028 }
1029 
1030 //***************************************************************************
1031 // EBML
1032 //***************************************************************************
1033 
1034 //---------------------------------------------------------------------------
Get_EB(int64u & Info,const char * Name)1035 void File__Analyze::Get_EB(int64u &Info, const char* Name)
1036 {
1037     //Element size
1038     INTEGRITY_SIZE_ATLEAST_INT(1);
1039     if (Buffer[Buffer_Offset+(size_t)Element_Offset]==0xFF)
1040     {
1041         if (Trace_Activated) Param(Name, "Unlimited");
1042         Element_Offset++;
1043         Info=Element_TotalSize_Get()-Element_Offset;
1044         return;
1045     }
1046     int8u Size=0;
1047     int32u Size_Mark=0;
1048     BS_Begin();
1049     while (Size_Mark==0 && BS->Remain() && Size<=8)
1050     {
1051         Size++;
1052         Peek_BS(Size, Size_Mark);
1053     }
1054 
1055     //Integrity
1056     if (!BS->Remain() || Size>8)
1057     {
1058         if (Size>8)
1059         {
1060             //Element[Element_Level].IsComplete=true; //If it is in a header
1061             Trusted_IsNot("EBML integer parsing error");
1062         }
1063         Info=0;
1064         return;
1065     }
1066     BS_End();
1067     if (File_Offset+Buffer_Offset+Element_Offset>=Element[Element_Level].Next)
1068     {
1069         //Element[Element_Level].IsComplete=true; //If it is in a header
1070         Trusted_IsNot("Not enough place to have an EBML");
1071         Info=0;
1072         return; //Not enough space
1073     }
1074     INTEGRITY_SIZE_ATLEAST_INT(Size);
1075 
1076     //Element Name
1077     switch (Size)
1078     {
1079         case 1 : {
1080                     int8u Element_Name;
1081                     Peek_B1 (Element_Name);
1082                     Info=Element_Name&0x7F; //Keep out first bit
1083                  }
1084                  break;
1085         case 2 : {
1086                     int16u Element_Name;
1087                     Peek_B2(Element_Name);
1088                     Info=Element_Name&0x3FFF; //Keep out first bits
1089                  }
1090                  break;
1091         case 3 : {
1092                     int32u Element_Name;
1093                     Peek_B3(Element_Name);
1094                     Info=Element_Name&0x1FFFFF; //Keep out first bits
1095                  }
1096                  break;
1097         case 4 : {
1098                     int32u Element_Name;
1099                     Peek_B4(Element_Name);
1100                     Info=Element_Name&0x0FFFFFFF; //Keep out first bits
1101                  }
1102                  break;
1103         case 5 : {
1104                     int64u Element_Name;
1105                     Peek_B5(Element_Name);
1106                     Info=Element_Name&0x07FFFFFFFFLL; //Keep out first bits
1107                  }
1108                  break;
1109         case 6 : {
1110                     int64u Element_Name;
1111                     Peek_B6(Element_Name);
1112                     Info=Element_Name&0x03FFFFFFFFFFLL; //Keep out first bits
1113                  }
1114                  break;
1115         case 7 : {
1116                     int64u Element_Name;
1117                     Peek_B7(Element_Name);
1118                     Info=Element_Name&0x01FFFFFFFFFFFFLL; //Keep out first bits
1119                  }
1120                  break;
1121         case 8 : {
1122                     int64u Element_Name;
1123                     Peek_B8(Element_Name);
1124                     Info=Element_Name&0x00FFFFFFFFFFFFFFLL; //Keep out first bits
1125                  }
1126                  break;
1127     }
1128 
1129     if (Trace_Activated) Param(Name, Info, Size * 7);
1130     Element_Offset+=Size;
1131 }
1132 
1133 //---------------------------------------------------------------------------
Get_ES(int64s & Info,const char * Name)1134 void File__Analyze::Get_ES(int64s &Info, const char* Name)
1135 {
1136     //Element size
1137     INTEGRITY_SIZE_ATLEAST_INT(1);
1138     int8u Size=0;
1139     int32u Size_Mark=0;
1140     BS_Begin();
1141     while (Size_Mark==0 && BS->Remain() && Size<=8)
1142     {
1143         Size++;
1144         Peek_BS(Size, Size_Mark);
1145     }
1146 
1147     //Integrity
1148     if (!BS->Remain() || Size>8)
1149     {
1150         if (Size>8)
1151         {
1152             //Element[Element_Level].IsComplete=true; //If it is in a header
1153             Trusted_IsNot("EBML integer parsing error");
1154         }
1155         Info=0;
1156         return;
1157     }
1158     BS_End();
1159     if (File_Offset+Buffer_Offset+Element_Offset>=Element[Element_Level].Next)
1160     {
1161         //Element[Element_Level].IsComplete=true; //If it is in a header
1162         Trusted_IsNot("Not enough place to have an EBML");
1163         Info=0;
1164         return; //Not enough space
1165     }
1166     INTEGRITY_SIZE_ATLEAST_INT(Size);
1167 
1168     //Element Name
1169     switch (Size)
1170     {
1171         case 1 : {
1172                     int8u Element_Name;
1173                     Peek_B1 (Element_Name);
1174                     Info=(Element_Name&0x7F)-0x3F; //Keep out first bit and sign
1175                  }
1176                  break;
1177         case 2 : {
1178                     int16u Element_Name;
1179                     Peek_B2(Element_Name);
1180                     Info=(Element_Name&0x3FFF)-0x1FFF; //Keep out first bits and sign
1181                  }
1182                  break;
1183         case 3 : {
1184                     int32u Element_Name;
1185                     Peek_B3(Element_Name);
1186                     Info=(Element_Name&0x1FFFFF)-0x0FFFFF; //Keep out first bits and sign
1187                  }
1188                  break;
1189         case 4 : {
1190                     int32u Element_Name;
1191                     Peek_B4(Element_Name);
1192                     Info=(Element_Name&0x0FFFFFFF)-0x07FFFFFF; //Keep out first bits and sign
1193                  }
1194                  break;
1195         case 5 : {
1196                     int64u Element_Name;
1197                     Peek_B5(Element_Name);
1198                     Info=(Element_Name&0x07FFFFFFFFLL)-0x03FFFFFFFFLL; //Keep out first bits and sign
1199                  }
1200                  break;
1201         case 6 : {
1202                     int64u Element_Name;
1203                     Peek_B6(Element_Name);
1204                     Info=(Element_Name&0x03FFFFFFFFFFLL)-0x01FFFFFFFFFFLL; //Keep out first bits and sign
1205                  }
1206                  break;
1207         case 7 : {
1208                     int64u Element_Name;
1209                     Peek_B7(Element_Name);
1210                     Info=(Element_Name&0x01FFFFFFFFFFFFLL)-0x00FFFFFFFFFFFFLL; //Keep out first bits and sign
1211                  }
1212                  break;
1213         case 8 : {
1214                     int64u Element_Name;
1215                     Peek_B8(Element_Name);
1216                     Info=(Element_Name&0x00FFFFFFFFFFFFFFLL)-0x007FFFFFFFFFFFFFLL; //Keep out first bits and sign
1217                  }
1218                  break;
1219     }
1220 
1221     if (Trace_Activated) Param(Name, Info);
1222     Element_Offset+=Size;
1223 }
1224 
1225 //***************************************************************************
1226 // Variable Size Value
1227 //***************************************************************************
1228 
1229 //---------------------------------------------------------------------------
Get_VS(int64u & Info,const char * Name)1230 void File__Analyze::Get_VS(int64u &Info, const char* Name)
1231 {
1232     //Element size
1233     Info=0;
1234     int8u  Size=0;
1235     bool more_data;
1236     BS_Begin();
1237     do
1238     {
1239         Size++;
1240         INTEGRITY_INT(8<=BS->Remain(), "Size is wrong", BS->Offset_Get())
1241         more_data=BS->GetB();
1242         Info=128*Info+BS->Get1(7);
1243     }
1244     while (more_data && Size<=8 && BS->Remain());
1245     BS_End();
1246 
1247     //Integrity
1248     if (Size>8)
1249     {
1250         Trusted_IsNot("Variable Size Value parsing error");
1251         Info=0;
1252         return;
1253     }
1254     if (File_Offset+Buffer_Offset+Element_Offset>=Element[Element_Level].Next)
1255     {
1256         Trusted_IsNot("Not enough place to have a Variable Size Value");
1257         Info=0;
1258         return; //Not enough space
1259     }
1260 
1261     if (Trace_Activated)
1262     {
1263         Element_Offset-=Size;
1264         Param(Name, Info);
1265         Element_Offset+=Size;
1266     }
1267 }
1268 
1269 //---------------------------------------------------------------------------
Skip_VS(const char * Name)1270 void File__Analyze::Skip_VS(const char* Name)
1271 {
1272     //Element size
1273     int64u Info=0;
1274     int8u  Size=0;
1275     bool more_data;
1276     BS_Begin();
1277     do
1278     {
1279         Size++;
1280         INTEGRITY_INT(8<=BS->Remain(), "Size is wrong", BS->Offset_Get())
1281         more_data=BS->GetB();
1282         Info=128*Info+BS->Get1(7);
1283     }
1284     while (more_data && Size<=8 && BS->Remain());
1285     BS_End();
1286 
1287     //Integrity
1288     if (Size>8)
1289     {
1290         Trusted_IsNot("Variable Size Value parsing error");
1291         Info=0;
1292         return;
1293     }
1294     if (File_Offset+Buffer_Offset+Element_Offset>=Element[Element_Level].Next)
1295     {
1296         Trusted_IsNot("Not enough place to have a Variable Size Value");
1297         Info=0;
1298         return; //Not enough space
1299     }
1300 
1301     if (Trace_Activated)
1302     {
1303         Element_Offset-=Size;
1304         Param(Name, Info);
1305         Element_Offset+=Size;
1306     }
1307 }
1308 
1309 //***************************************************************************
1310 // Exp-Golomb
1311 //***************************************************************************
1312 
1313 //---------------------------------------------------------------------------
Get_SE(int32s & Info,const char * Name)1314 void File__Analyze::Get_SE(int32s &Info, const char* Name)
1315 {
1316     INTEGRITY_SIZE_ATLEAST_BUFFER();
1317     int8u LeadingZeroBits=0;
1318     while(BS->Remain()>0 && !BS->GetB())
1319         LeadingZeroBits++;
1320     INTEGRITY_INT(LeadingZeroBits<=32, "(Problem)", 0)
1321     double InfoD=pow((float)2, (float)LeadingZeroBits)-1+BS->Get4(LeadingZeroBits);
1322     INTEGRITY_INT(InfoD<int32u(-1), "(Problem)", 0)
1323     Info=(int32s)(pow((double)-1, InfoD+1)*(int32u)ceil(InfoD/2));
1324 
1325     if (Trace_Activated)
1326         Param(Name, Info, LeadingZeroBits<<1);
1327 }
1328 
1329 //---------------------------------------------------------------------------
Skip_SE(const char * Name)1330 void File__Analyze::Skip_SE(const char* Name)
1331 {
1332     INTEGRITY(BS->Remain(), "Size is wrong", 0)
1333     int8u LeadingZeroBits=0;
1334     while(BS->Remain()>0 && !BS->GetB())
1335         LeadingZeroBits++;
1336     if (Trace_Activated)
1337     {
1338         INTEGRITY(LeadingZeroBits<=32, "(Problem)", 0)
1339         double InfoD=pow((float)2, (float)LeadingZeroBits)-1+BS->Get4(LeadingZeroBits);
1340         INTEGRITY(InfoD<int32u(-1), "(Problem)", 0)
1341         Param(Name, (int32s)(pow(-1, InfoD+1)*(int32u)ceil(InfoD/2)), LeadingZeroBits<<1);
1342     }
1343     else
1344         BS->Skip(LeadingZeroBits);
1345 }
1346 
1347 //---------------------------------------------------------------------------
Get_UE(int32u & Info,const char * Name)1348 void File__Analyze::Get_UE(int32u &Info, const char* Name)
1349 {
1350     INTEGRITY_SIZE_ATLEAST_BUFFER();
1351     int8u LeadingZeroBits=0;
1352     while(BS->Remain()>0 && !BS->GetB())
1353         LeadingZeroBits++;
1354     INTEGRITY_INT(LeadingZeroBits<=32, "(Problem)", 0)
1355     double InfoD=pow(2, (float)LeadingZeroBits);
1356     Info=(int32u)InfoD-1+BS->Get4(LeadingZeroBits);
1357 
1358     if (Trace_Activated)
1359         Param(Name, Info, LeadingZeroBits<<1);
1360 }
1361 
1362 //---------------------------------------------------------------------------
Skip_UE(const char * Name)1363 void File__Analyze::Skip_UE(const char* Name)
1364 {
1365     INTEGRITY(BS->Remain(), "Size is wrong", 0)
1366     int8u LeadingZeroBits=0;
1367     while(BS->Remain()>0 && !BS->GetB())
1368         LeadingZeroBits++;
1369     if (Trace_Activated)
1370     {
1371         INTEGRITY(LeadingZeroBits<=32, "(Problem)", 0)
1372         double InfoD=pow(2, (float)LeadingZeroBits);
1373         Param(Name, (int32u)InfoD-1+BS->Get4(LeadingZeroBits), LeadingZeroBits<<1);
1374     }
1375     else
1376         BS->Skip(LeadingZeroBits);
1377 }
1378 
1379 //***************************************************************************
1380 // Inverted Exp-Golomb
1381 //***************************************************************************
1382 
1383 //---------------------------------------------------------------------------
Get_SI(int32s & Info,const char * Name)1384 void File__Analyze::Get_SI(int32s &Info, const char* Name)
1385 {
1386     INTEGRITY_SIZE_ATLEAST_BUFFER();
1387 
1388     Info=1;
1389     while(BS->Remain()>0 && BS->GetB()==0)
1390     {
1391         Info<<=1;
1392         if (BS->Remain()==0)
1393         {
1394             Trusted_IsNot("(Problem)");
1395             Info=0;
1396             return;
1397         }
1398         if(BS->GetB()==1)
1399             Info++;
1400     }
1401     Info--;
1402 
1403     if (Info!=0 && BS->Remain()>0 && BS->GetB()==1)
1404         Info=-Info;
1405 
1406     if (Trace_Activated)
1407         Param(Name, Info);
1408 }
1409 
1410 //---------------------------------------------------------------------------
Skip_SI(const char * Name)1411 void File__Analyze::Skip_SI(const char* Name)
1412 {
1413     int32s Info;
1414     Get_SI(Info, Name);
1415 }
1416 
1417 //---------------------------------------------------------------------------
Get_UI(int32u & Info,const char * Name)1418 void File__Analyze::Get_UI(int32u &Info, const char* Name)
1419 {
1420     INTEGRITY_SIZE_ATLEAST_BUFFER();
1421     Info=1;
1422     while(BS->Remain()>0 && BS->GetB()==0)
1423     {
1424         Info<<=1;
1425         if (BS->Remain()==0)
1426         {
1427             Trusted_IsNot("(Problem)");
1428             Info=0;
1429             return;
1430         }
1431         if(BS->GetB()==1)
1432             Info++;
1433     }
1434     Info--;
1435 
1436     if (Trace_Activated)
1437         Param(Name, Info);
1438 }
1439 
1440 //---------------------------------------------------------------------------
Skip_UI(const char * Name)1441 void File__Analyze::Skip_UI(const char* Name)
1442 {
1443     int32u Info;
1444     Get_UI(Info, Name);
1445 }
1446 
1447 //***************************************************************************
1448 // Variable Length Code
1449 //***************************************************************************
1450 
1451 //---------------------------------------------------------------------------
Get_VL(const vlc Vlc[],size_t & Info,const char * Name)1452 void File__Analyze::Get_VL(const vlc Vlc[], size_t &Info, const char* Name)
1453 {
1454     Info=0;
1455     int32u Value=0;
1456 
1457     int8u CountOfBits=0;
1458     for(;;)
1459     {
1460         switch (Vlc[Info].bit_increment)
1461         {
1462             case 255 :
1463                         Trusted_IsNot("Variable Length Code error");
1464                         return;
1465             default  : ;
1466                         Value<<=Vlc[Info].bit_increment;
1467                         Value|=BS->Get1(Vlc[Info].bit_increment);
1468                         CountOfBits+=Vlc[Info].bit_increment;
1469                         break;
1470             case   1 :
1471                         Value<<=1;
1472                         if (BS->GetB())
1473                             Value++;
1474                         CountOfBits++;
1475             case   0 :  ;
1476         }
1477 
1478         if (Value==Vlc[Info].value)
1479         {
1480             if (Trace_Activated)
1481             {
1482                 Ztring ToDisplay=Ztring::ToZtring(Value, 2);
1483                 ToDisplay.insert(0, CountOfBits-ToDisplay.size(), __T('0'));
1484                 ToDisplay+=__T(" (")+Ztring::ToZtring(CountOfBits)+__T(" bits)");
1485                 Param(Name, ToDisplay);
1486             }
1487             return;
1488         }
1489         Info++;
1490     }
1491 }
1492 
1493 //---------------------------------------------------------------------------
Get_VL_Prepare(vlc_fast & Vlc)1494 void File__Analyze::Get_VL_Prepare(vlc_fast &Vlc)
1495 {
1496     Vlc.Array=new int8u[((size_t)1)<<Vlc.Size];
1497     Vlc.BitsToSkip=new int8u[((size_t)1)<<Vlc.Size];
1498     memset(Vlc.Array, 0xFF, ((size_t)1)<<Vlc.Size);
1499     int8u  Increment=0;
1500     int8u  Pos=0;
1501     for(; ; Pos++)
1502     {
1503         if (Vlc.Vlc[Pos].bit_increment==255)
1504             break;
1505         Increment+=Vlc.Vlc[Pos].bit_increment;
1506         size_t Value=((size_t)Vlc.Vlc[Pos].value)<<(Vlc.Size-Increment);
1507         size_t ToFill_Size=((size_t)1)<<(Vlc.Size-Increment);
1508         for (size_t ToFill_Pos=0; ToFill_Pos<ToFill_Size; ToFill_Pos++)
1509         {
1510             Vlc.Array[Value+ToFill_Pos]=Pos;
1511             Vlc.BitsToSkip[Value+ToFill_Pos]=Increment;
1512         }
1513     }
1514     for (size_t Pos2=0; Pos2<(((size_t)1)<<Vlc.Size); Pos2++)
1515         if (Vlc.Array[Pos2]==(int8u)-1)
1516         {
1517             Vlc.Array[Pos2]=Pos;
1518             Vlc.BitsToSkip[Pos2]=(int8u)-1;
1519         }
1520 }
1521 
1522 //---------------------------------------------------------------------------
Get_VL(vlc_fast & Vlc,size_t & Info,const char * Name)1523 void File__Analyze::Get_VL(vlc_fast &Vlc, size_t &Info, const char* Name)
1524 {
1525     if (BS->Remain()<Vlc.Size)
1526     {
1527         Get_VL(Vlc.Vlc, Info, Name);
1528         return;
1529     }
1530 
1531     int32u Value=BS->Peek4(Vlc.Size);
1532     Info=Vlc.Array[Value];
1533 
1534     if (Vlc.BitsToSkip[Value]==(int8u)-1)
1535     {
1536         Trusted_IsNot("Variable Length Code error");
1537         return;
1538     }
1539 
1540     if (Trace_Activated)
1541     {
1542         Ztring ToDisplay=Ztring::ToZtring(Value, 2);
1543         ToDisplay.insert(0, Vlc.Size-ToDisplay.size(), __T('0'));
1544         ToDisplay.resize(Vlc.BitsToSkip[Value]);
1545         ToDisplay+=__T(" (")+Ztring::ToZtring(Vlc.BitsToSkip[Value])+__T(" bits)");
1546         Param(Name, ToDisplay);
1547     }
1548 
1549     BS->Skip(Vlc.BitsToSkip[Value]);
1550 }
1551 
1552 //---------------------------------------------------------------------------
Skip_VL(const vlc Vlc[],const char * Name)1553 void File__Analyze::Skip_VL(const vlc Vlc[], const char* Name)
1554 {
1555     size_t Info;
1556     Get_VL(Vlc, Info, Name);
1557 }
1558 
1559 //***************************************************************************
1560 // Characters
1561 //***************************************************************************
1562 
1563 //---------------------------------------------------------------------------
Get_C1(int8u & Info,const char * Name)1564 void File__Analyze::Get_C1(int8u &Info, const char* Name)
1565 {
1566     INTEGRITY_SIZE_ATLEAST_INT(1);
1567     Info=CC1(Buffer+Buffer_Offset+(size_t)Element_Offset);
1568     if (Trace_Activated) Param_CC(Name, Buffer+Buffer_Offset+(size_t)Element_Offset, 1);
1569     Element_Offset+=1;
1570 }
1571 
1572 //---------------------------------------------------------------------------
Get_C2(int16u & Info,const char * Name)1573 void File__Analyze::Get_C2(int16u &Info, const char* Name)
1574 {
1575     INTEGRITY_SIZE_ATLEAST_INT(2);
1576     Info=CC2(Buffer+Buffer_Offset+(size_t)Element_Offset);
1577     if (Trace_Activated) Param_CC(Name, Buffer+Buffer_Offset+(size_t)Element_Offset, 2);
1578     Element_Offset+=2;
1579 }
1580 
1581 //---------------------------------------------------------------------------
Get_C3(int32u & Info,const char * Name)1582 void File__Analyze::Get_C3(int32u &Info, const char* Name)
1583 {
1584     INTEGRITY_SIZE_ATLEAST_INT(3);
1585     Info=CC3(Buffer+Buffer_Offset+(size_t)Element_Offset);
1586     if (Trace_Activated) Param_CC(Name, Buffer+Buffer_Offset+(size_t)Element_Offset, 3);
1587     Element_Offset+=3;
1588 }
1589 
1590 //---------------------------------------------------------------------------
Get_C4(int32u & Info,const char * Name)1591 void File__Analyze::Get_C4(int32u &Info, const char* Name)
1592 {
1593     INTEGRITY_SIZE_ATLEAST_INT(4);
1594     Info=CC4(Buffer+Buffer_Offset+(size_t)Element_Offset);
1595     if (Trace_Activated) Param_CC(Name, Buffer+Buffer_Offset+(size_t)Element_Offset, 4);
1596     Element_Offset+=4;
1597 }
1598 
1599 //---------------------------------------------------------------------------
Get_C5(int64u & Info,const char * Name)1600 void File__Analyze::Get_C5(int64u &Info, const char* Name)
1601 {
1602     INTEGRITY_SIZE_ATLEAST_INT(5);
1603     Info=CC5(Buffer+Buffer_Offset+(size_t)Element_Offset);
1604     if (Trace_Activated) Param_CC(Name, Buffer+Buffer_Offset+(size_t)Element_Offset, 5);
1605     Element_Offset+=5;
1606 }
1607 
1608 //---------------------------------------------------------------------------
Get_C6(int64u & Info,const char * Name)1609 void File__Analyze::Get_C6(int64u &Info, const char* Name)
1610 {
1611     INTEGRITY_SIZE_ATLEAST_INT(6);
1612     Info=CC6(Buffer+Buffer_Offset+(size_t)Element_Offset);
1613     if (Trace_Activated) Param_CC(Name, Buffer+Buffer_Offset+(size_t)Element_Offset, 6);
1614     Element_Offset+=6;
1615 }
1616 
1617 //---------------------------------------------------------------------------
Get_C7(int64u & Info,const char * Name)1618 void File__Analyze::Get_C7(int64u &Info, const char* Name)
1619 {
1620     INTEGRITY_SIZE_ATLEAST_INT(7);
1621     Info=CC7(Buffer+Buffer_Offset+(size_t)Element_Offset);
1622     if (Trace_Activated) Param_CC(Name, Buffer+Buffer_Offset+(size_t)Element_Offset, 7);
1623     Element_Offset+=7;
1624 }
1625 
1626 //---------------------------------------------------------------------------
Get_C8(int64u & Info,const char * Name)1627 void File__Analyze::Get_C8(int64u &Info, const char* Name)
1628 {
1629     INTEGRITY_SIZE_ATLEAST_INT(8);
1630     Info=CC8(Buffer+Buffer_Offset+(size_t)Element_Offset);
1631     if (Trace_Activated) Param_CC(Name, Buffer+Buffer_Offset+(size_t)Element_Offset, 8);
1632     Element_Offset+=8;
1633 }
1634 
1635 //---------------------------------------------------------------------------
Skip_C1(const char * Name)1636 void File__Analyze::Skip_C1(const char* Name)
1637 {
1638     INTEGRITY_SIZE_ATLEAST(1);
1639     if (Trace_Activated) Param_CC(Name, Buffer+Buffer_Offset+(size_t)Element_Offset, 1);
1640     Element_Offset+=1;
1641 }
1642 
1643 //---------------------------------------------------------------------------
Skip_C2(const char * Name)1644 void File__Analyze::Skip_C2(const char* Name)
1645 {
1646     INTEGRITY_SIZE_ATLEAST(2);
1647     if (Trace_Activated) Param_CC(Name, Buffer+Buffer_Offset+(size_t)Element_Offset, 2);
1648     Element_Offset+=2;
1649 }
1650 
1651 //---------------------------------------------------------------------------
Skip_C3(const char * Name)1652 void File__Analyze::Skip_C3(const char* Name)
1653 {
1654     INTEGRITY_SIZE_ATLEAST(3);
1655     if (Trace_Activated) Param_CC(Name, Buffer+Buffer_Offset+(size_t)Element_Offset, 3);
1656     Element_Offset+=3;
1657 }
1658 
1659 //---------------------------------------------------------------------------
Skip_C4(const char * Name)1660 void File__Analyze::Skip_C4(const char* Name)
1661 {
1662     INTEGRITY_SIZE_ATLEAST(4);
1663     if (Trace_Activated) Param_CC(Name, Buffer+Buffer_Offset+(size_t)Element_Offset, 4);
1664     Element_Offset+=4;
1665 }
1666 
1667 //---------------------------------------------------------------------------
Skip_C5(const char * Name)1668 void File__Analyze::Skip_C5(const char* Name)
1669 {
1670     INTEGRITY_SIZE_ATLEAST(5);
1671     if (Trace_Activated) Param_CC(Name, Buffer+Buffer_Offset+(size_t)Element_Offset, 5);
1672     Element_Offset+=5;
1673 }
1674 
1675 //---------------------------------------------------------------------------
Skip_C6(const char * Name)1676 void File__Analyze::Skip_C6(const char* Name)
1677 {
1678     INTEGRITY_SIZE_ATLEAST(6);
1679     if (Trace_Activated) Param_CC(Name, Buffer+Buffer_Offset+(size_t)Element_Offset, 6);
1680     Element_Offset+=6;
1681 }
1682 
1683 //---------------------------------------------------------------------------
Skip_C7(const char * Name)1684 void File__Analyze::Skip_C7(const char* Name)
1685 {
1686     INTEGRITY_SIZE_ATLEAST(7);
1687     if (Trace_Activated) Param_CC(Name, Buffer+Buffer_Offset+(size_t)Element_Offset, 7);
1688     Element_Offset+=7;
1689 }
1690 
1691 //---------------------------------------------------------------------------
Skip_C8(const char * Name)1692 void File__Analyze::Skip_C8(const char* Name)
1693 {
1694     INTEGRITY_SIZE_ATLEAST(8);
1695     if (Trace_Activated) Param_CC(Name, Buffer+Buffer_Offset+(size_t)Element_Offset, 8);
1696     Element_Offset+=8;
1697 }
1698 
1699 //***************************************************************************
1700 // Text
1701 //***************************************************************************
1702 
1703 //---------------------------------------------------------------------------
Get_Local(int64u Bytes,Ztring & Info,const char * Name)1704 void File__Analyze::Get_Local(int64u Bytes, Ztring &Info, const char* Name)
1705 {
1706     INTEGRITY_SIZE_ATLEAST_STRING(Bytes);
1707     #ifdef WINDOWS
1708     Info.From_Local((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes);
1709     #else //WINDOWS
1710     Info.From_ISO_8859_1((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes); //Trying with the most commonly used charset before UTF8
1711     #endif //WINDOWS
1712     if (Trace_Activated && Bytes) Param(Name, Info);
1713     Element_Offset+=Bytes;
1714 }
1715 
1716 //---------------------------------------------------------------------------
1717 extern const wchar_t ISO_6937_2_Tables[];
Get_ISO_6937_2(int64u Bytes,Ztring & Info,const char * Name)1718 void File__Analyze::Get_ISO_6937_2(int64u Bytes, Ztring &Info, const char* Name)
1719 {
1720     INTEGRITY_SIZE_ATLEAST_STRING(Bytes);
1721     Info.clear();
1722     size_t End = Buffer_Offset + (size_t)Element_Offset + (size_t)Bytes;
1723     for (size_t Pos=Buffer_Offset+(size_t)Element_Offset; Pos<End; ++Pos)
1724     {
1725         wchar_t EscapeChar=L'\x0000';
1726         wchar_t NewChar=L'\x0000';
1727         switch (Buffer[Pos])
1728         {
1729             case 0xA9 :    NewChar=L'\x2018'; break;
1730             case 0xAA :    NewChar=L'\x201C'; break;
1731             case 0xAC :    NewChar=L'\x2190'; break;
1732             case 0xAD :    NewChar=L'\x2191'; break;
1733             case 0xAE :    NewChar=L'\x2192'; break;
1734             case 0xAF :    NewChar=L'\x2193'; break;
1735             case 0xB4 :    NewChar=L'\x00D7'; break;
1736             case 0xB8 :    NewChar=L'\x00F7'; break;
1737             case 0xB9 :    NewChar=L'\x2019'; break;
1738             case 0xBA :    NewChar=L'\x201D'; break;
1739             case 0xC1 : EscapeChar=L'\x0300'; break;
1740             case 0xC2 : EscapeChar=L'\x0301'; break;
1741             case 0xC3 : EscapeChar=L'\x0302'; break;
1742             case 0xC4 : EscapeChar=L'\x0303'; break;
1743             case 0xC5 : EscapeChar=L'\x0304'; break;
1744             case 0xC6 : EscapeChar=L'\x0306'; break;
1745             case 0xC7 : EscapeChar=L'\x0307'; break;
1746             case 0xC8 : EscapeChar=L'\x0308'; break;
1747             case 0xCA : EscapeChar=L'\x030A'; break;
1748             case 0xCB : EscapeChar=L'\x0327'; break;
1749             case 0xCD : EscapeChar=L'\x030B'; break;
1750             case 0xCE : EscapeChar=L'\x0328'; break;
1751             case 0xCF : EscapeChar=L'\x030C'; break;
1752             case 0xD0 :    NewChar=L'\x2015'; break;
1753             case 0xD1 :    NewChar=L'\x00B9'; break;
1754             case 0xD2 :    NewChar=L'\x00AE'; break;
1755             case 0xD3 :    NewChar=L'\x00A9'; break;
1756             case 0xD4 :    NewChar=L'\x2122'; break;
1757             case 0xD5 :    NewChar=L'\x266A'; break;
1758             case 0xD6 :    NewChar=L'\x00AC'; break;
1759             case 0xD7 :    NewChar=L'\x00A6'; break;
1760             case 0xDC :    NewChar=L'\x215B'; break;
1761             case 0xDD :    NewChar=L'\x215C'; break;
1762             case 0xDE :    NewChar=L'\x215D'; break;
1763             case 0xDF :    NewChar=L'\x215E'; break;
1764             case 0xE0 :    NewChar=L'\x2126'; break;
1765             case 0xE1 :    NewChar=L'\x00C6'; break;
1766             case 0xE2 :    NewChar=L'\x0110'; break;
1767             case 0xE3 :    NewChar=L'\x00AA'; break;
1768             case 0xE4 :    NewChar=L'\x0126'; break;
1769             case 0xE6 :    NewChar=L'\x0132'; break;
1770             case 0xE7 :    NewChar=L'\x013F'; break;
1771             case 0xE8 :    NewChar=L'\x0141'; break;
1772             case 0xE9 :    NewChar=L'\x00D8'; break;
1773             case 0xEA :    NewChar=L'\x0152'; break;
1774             case 0xEB :    NewChar=L'\x00BA'; break;
1775             case 0xEC :    NewChar=L'\x00DE'; break;
1776             case 0xED :    NewChar=L'\x0166'; break;
1777             case 0xEE :    NewChar=L'\x014A'; break;
1778             case 0xEF :    NewChar=L'\x0149'; break;
1779             case 0xF0 :    NewChar=L'\x0138'; break;
1780             case 0xF1 :    NewChar=L'\x00E6'; break;
1781             case 0xF2 :    NewChar=L'\x0111'; break;
1782             case 0xF3 :    NewChar=L'\x00F0'; break;
1783             case 0xF4 :    NewChar=L'\x0127'; break;
1784             case 0xF5 :    NewChar=L'\x0131'; break;
1785             case 0xF6 :    NewChar=L'\x0133'; break;
1786             case 0xF7 :    NewChar=L'\x0140'; break;
1787             case 0xF8 :    NewChar=L'\x0142'; break;
1788             case 0xF9 :    NewChar=L'\x00F8'; break;
1789             case 0xFA :    NewChar=L'\x0153'; break;
1790             case 0xFB :    NewChar=L'\x0153'; break;
1791             case 0xFC :    NewChar=L'\x00FE'; break;
1792             case 0xFD :    NewChar=L'\x00FE'; break;
1793             case 0xFE :    NewChar=L'\x014B'; break;
1794             case 0xFF :    NewChar=L'\x00AD'; break;
1795             case 0xC0 :
1796             case 0xC9 :
1797             case 0xCC :
1798             case 0xD8 :
1799             case 0xD9 :
1800             case 0xDA :
1801             case 0xDB :
1802             case 0xE5 :
1803                                                  break;
1804             default  : NewChar=(Char)(Buffer[Pos]);
1805         }
1806 
1807         if (EscapeChar)
1808         {
1809             if (Pos+1<End)
1810             {
1811                 if (Buffer[Pos]>=0xC0 && Buffer[Pos]<=0xCF && Buffer[Pos+1]>=0x40 && Buffer[Pos+1]<=0x7F)
1812                     Info+=Ztring().From_Unicode(ISO_6937_2_Tables[((Buffer[Pos]-0xC0))*0x40+(Buffer[Pos+1]-0x40)]);
1813                 else
1814                 {
1815                 Info+=(Char)(Buffer[Pos+1]);
1816                 Info+=Ztring().From_Unicode(&EscapeChar, 1); //(EscapeChar) after new ZenLib release
1817                 }
1818                 EscapeChar=__T('\x0000');
1819                 Pos++;
1820             }
1821         }
1822         else if (NewChar)
1823             Info+=Ztring().From_Unicode(&NewChar, 1); //(NewChar) after new ZenLib release
1824     }
1825     if (Trace_Activated && Bytes) Param(Name, Info);
1826     Element_Offset+=Bytes;
1827 }
1828 
1829 //---------------------------------------------------------------------------
Get_ISO_8859_1(int64u Bytes,Ztring & Info,const char * Name)1830 void File__Analyze::Get_ISO_8859_1(int64u Bytes, Ztring &Info, const char* Name)
1831 {
1832     INTEGRITY_SIZE_ATLEAST_STRING(Bytes);
1833     Info.From_ISO_8859_1((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes);
1834     if (Trace_Activated && Bytes) Param(Name, Info);
1835     Element_Offset+=Bytes;
1836 }
1837 
1838 //---------------------------------------------------------------------------
Get_ISO_8859_2(int64u Bytes,Ztring & Info,const char * Name)1839 void File__Analyze::Get_ISO_8859_2(int64u Bytes, Ztring &Info, const char* Name)
1840 {
1841     INTEGRITY_SIZE_ATLEAST_STRING(Bytes);
1842     Info.From_ISO_8859_2((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes);
1843     if (Trace_Activated && Bytes) Param(Name, Info);
1844     Element_Offset+=Bytes;
1845 }
1846 
1847 //---------------------------------------------------------------------------
Get_ISO_8859_5(int64u Bytes,Ztring & Info,const char * Name)1848 void File__Analyze::Get_ISO_8859_5(int64u Bytes, Ztring &Info, const char* Name)
1849 {
1850     INTEGRITY_SIZE_ATLEAST_STRING(Bytes);
1851     Info.clear();
1852     size_t End = Buffer_Offset + (size_t)Element_Offset + (size_t)Bytes;
1853     for (size_t Pos=Buffer_Offset+(size_t)Element_Offset; Pos<End; ++Pos)
1854     {
1855         switch (Buffer[Pos])
1856         {
1857             case 0xAD : Info+=Ztring().From_Unicode(L"\xAD"); break; //L'\xAD' after new ZenLib release
1858             case 0xF0 : Info+=Ztring().From_Unicode(L"\x2116"); break; //L'\x2116' after new ZenLib release
1859             case 0xFD : Info+=Ztring().From_Unicode(L"\xA7"); break; //L'\xA7' after new ZenLib release
1860             default   :
1861                         {
1862                         wchar_t NewChar=(Buffer[Pos]<=0xA0?0x0000:0x0360)+Buffer[Pos];
1863                         Info+=Ztring().From_Unicode(&NewChar, 1); //(NewChar) after new ZenLib release
1864                         }
1865         }
1866     }
1867     if (Trace_Activated && Bytes) Param(Name, Info);
1868     Element_Offset+=Bytes;
1869 }
1870 
1871 //---------------------------------------------------------------------------
1872 extern const int16u Ztring_MacRoman[128];
Get_MacRoman(int64u Bytes,Ztring & Info,const char * Name)1873 void File__Analyze::Get_MacRoman(int64u Bytes, Ztring& Info, const char* Name)
1874 {
1875     INTEGRITY_SIZE_ATLEAST_STRING(Bytes);
1876 
1877     // Use From_MacRoman() after new ZenLib release
1878     const int8u* Input=Buffer+Buffer_Offset+(size_t)Element_Offset;
1879 
1880     wchar_t* Temp=new wchar_t[Bytes];
1881 
1882     for (size_t Pos=0; Pos<Bytes; Pos++)
1883     {
1884         if (Input[Pos]>=0x80)
1885             Temp[Pos]=(wchar_t)Ztring_MacRoman[Input[Pos]-0x80];
1886         else
1887             Temp[Pos]=(wchar_t)Input[Pos];
1888     }
1889 
1890     Info.From_Unicode(Temp, Bytes);
1891     delete[] Temp;
1892 
1893     if (Trace_Activated && Bytes) Param(Name, Info);
1894     Element_Offset+=Bytes;
1895 }
1896 
1897 //---------------------------------------------------------------------------
Get_String(int64u Bytes,std::string & Info,const char * Name)1898 void File__Analyze::Get_String(int64u Bytes, std::string &Info, const char* Name)
1899 {
1900     INTEGRITY_SIZE_ATLEAST_STRING(Bytes);
1901     Info.assign((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes);
1902     if (Trace_Activated && Bytes) Param(Name, Ztring().From_ISO_8859_1((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes)); //Trying with the most commonly used charset
1903     Element_Offset+=Bytes;
1904 }
1905 
1906 //---------------------------------------------------------------------------
Peek_Local(int64u Bytes,Ztring & Info)1907 void File__Analyze::Peek_Local(int64u Bytes, Ztring &Info)
1908 {
1909     INTEGRITY_SIZE_ATLEAST_STRING(Bytes);
1910     #ifdef WINDOWS
1911     Info.From_Local((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes);
1912     #else //WINDOWS
1913     Info.From_ISO_8859_1((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes); //Trying with the most commonly used charset before UTF8
1914     #endif //WINDOWS
1915 }
1916 
1917 //---------------------------------------------------------------------------
Peek_String(int64u Bytes,std::string & Info)1918 void File__Analyze::Peek_String(int64u Bytes, std::string &Info)
1919 {
1920     INTEGRITY_SIZE_ATLEAST_STRING(Bytes);
1921     Info.assign((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes);
1922 }
1923 
1924 //---------------------------------------------------------------------------
Get_UTF8(int64u Bytes,Ztring & Info,const char * Name)1925 void File__Analyze::Get_UTF8(int64u Bytes, Ztring &Info, const char* Name)
1926 {
1927     INTEGRITY_SIZE_ATLEAST_STRING(Bytes);
1928     Info.From_UTF8((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes);
1929     if (Trace_Activated && Bytes) Param(Name, Info);
1930     Element_Offset+=Bytes;
1931 }
1932 
1933 //---------------------------------------------------------------------------
Get_UTF16(int64u Bytes,Ztring & Info,const char * Name)1934 void File__Analyze::Get_UTF16(int64u Bytes, Ztring &Info, const char* Name)
1935 {
1936     INTEGRITY_SIZE_ATLEAST_STRING(Bytes);
1937     Info.From_UTF16((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes);
1938     if (Trace_Activated && Bytes) Param(Name, Info);
1939     Element_Offset+=Bytes;
1940 }
1941 
1942 //---------------------------------------------------------------------------
Get_UTF16B(int64u Bytes,Ztring & Info,const char * Name)1943 void File__Analyze::Get_UTF16B(int64u Bytes, Ztring &Info, const char* Name)
1944 {
1945     INTEGRITY_SIZE_ATLEAST_STRING(Bytes);
1946     Info.From_UTF16BE((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes);
1947     if (Trace_Activated && Bytes) Param(Name, Info);
1948     Element_Offset+=Bytes;
1949 }
1950 
1951 //---------------------------------------------------------------------------
Get_UTF16L(int64u Bytes,Ztring & Info,const char * Name)1952 void File__Analyze::Get_UTF16L(int64u Bytes, Ztring &Info, const char* Name)
1953 {
1954     INTEGRITY_SIZE_ATLEAST_STRING(Bytes);
1955     Info.From_UTF16LE((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes);
1956     if (Trace_Activated && Bytes) Param(Name, Info);
1957     Element_Offset+=Bytes;
1958 }
1959 
1960 //---------------------------------------------------------------------------
Skip_Local(int64u Bytes,const char * Name)1961 void File__Analyze::Skip_Local(int64u Bytes, const char* Name)
1962 {
1963     INTEGRITY_SIZE_ATLEAST(Bytes);
1964     #ifdef WINDOWS
1965     if (Trace_Activated && Bytes) Param(Name, Ztring().From_Local((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes));
1966     #else //WINDOWS
1967     if (Trace_Activated && Bytes) Param(Name, Ztring().From_ISO_8859_1((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes)); //Trying with the most commonly used charset before UTF8
1968     #endif //WINDOWS
1969     Element_Offset+=Bytes;
1970 }
1971 
1972 //---------------------------------------------------------------------------
Skip_ISO_6937_2(int64u Bytes,const char * Name)1973 void File__Analyze::Skip_ISO_6937_2(int64u Bytes, const char* Name)
1974 {
1975     INTEGRITY_SIZE_ATLEAST(Bytes);
1976     if (Trace_Activated && Bytes)
1977     {
1978         Ztring Temp;
1979         Get_ISO_6937_2(Bytes, Temp, Name);
1980     }
1981     else
1982         Element_Offset+=Bytes;
1983 }
1984 
1985 //---------------------------------------------------------------------------
Skip_String(int64u Bytes,const char * Name)1986 void File__Analyze::Skip_String(int64u Bytes, const char* Name)
1987 {
1988     INTEGRITY_SIZE_ATLEAST(Bytes);
1989     if (Trace_Activated && Bytes) Param(Name, Ztring().From_ISO_8859_1((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes)); //Trying with the most commonly used charset
1990     Element_Offset+=Bytes;
1991 }
1992 
1993 //---------------------------------------------------------------------------
Skip_UTF8(int64u Bytes,const char * Name)1994 void File__Analyze::Skip_UTF8(int64u Bytes, const char* Name)
1995 {
1996     INTEGRITY_SIZE_ATLEAST(Bytes);
1997     if (Trace_Activated && Bytes) Param(Name, Ztring().From_UTF8((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes));
1998     Element_Offset+=Bytes;
1999 }
2000 
2001 //---------------------------------------------------------------------------
Skip_UTF16B(int64u Bytes,const char * Name)2002 void File__Analyze::Skip_UTF16B(int64u Bytes, const char* Name)
2003 {
2004     INTEGRITY_SIZE_ATLEAST(Bytes);
2005     if (Trace_Activated && Bytes) Param(Name, Ztring().From_UTF16BE((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes));
2006     Element_Offset+=Bytes;
2007 }
2008 
2009 //---------------------------------------------------------------------------
Skip_UTF16L(int64u Bytes,const char * Name)2010 void File__Analyze::Skip_UTF16L(int64u Bytes, const char* Name)
2011 {
2012     INTEGRITY_SIZE_ATLEAST(Bytes);
2013     if (Trace_Activated && Bytes) Param(Name, Ztring().From_UTF16LE((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset), (size_t)Bytes));
2014     Element_Offset+=Bytes;
2015 }
2016 
2017 //***************************************************************************
2018 // Text
2019 //***************************************************************************
2020 
2021 //---------------------------------------------------------------------------
Skip_PA(const char * Name)2022 void File__Analyze::Skip_PA(const char* Name)
2023 {
2024     INTEGRITY_SIZE_ATLEAST(1);
2025     int8u Size=Buffer[Buffer_Offset+(size_t)Element_Offset];
2026     INTEGRITY_SIZE_ATLEAST(1+Size);
2027     #ifdef WINDOWS
2028     if (Trace_Activated && Size) Param(Name, Ztring().From_Local((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset+1), (size_t)Size));
2029     #else //WINDOWS
2030     if (Trace_Activated && Size) Param(Name, Ztring().From_ISO_8859_1((const char*)(Buffer+Buffer_Offset+(size_t)Element_Offset+1), (size_t)Size)); //Trying with the most commonly used charset before UTF8
2031     #endif //WINDOWS
2032     Element_Offset+=1+Size;
2033 }
2034 
2035 //***************************************************************************
2036 // Unknown
2037 //***************************************************************************
2038 
2039 //---------------------------------------------------------------------------
Skip_XX(int64u Bytes,const char * Name)2040 void File__Analyze::Skip_XX(int64u Bytes, const char* Name)
2041 {
2042     if (Element_Offset+Bytes!=Element_TotalSize_Get()) //Exception for seek to end of the element
2043     {
2044         INTEGRITY_SIZE_ATLEAST(Bytes);
2045     }
2046     if (Trace_Activated && Bytes) Param(Name, Ztring("(")+Ztring::ToZtring(Bytes)+Ztring(" bytes)"));
2047     Element_Offset+=Bytes;
2048 }
2049 
2050 //***************************************************************************
2051 // Flags
2052 //***************************************************************************
2053 
2054 //---------------------------------------------------------------------------
Get_Flags(int64u Flags,size_t Order,bool & Info,const char * Name)2055 void File__Analyze::Get_Flags (int64u Flags, size_t Order, bool &Info, const char* Name)
2056 {
2057     if (Flags&((int64u)1<<Order))
2058         Info=true;
2059     else
2060         Info=false;
2061 
2062     Element_Begin0();
2063     if (Trace_Activated && MediaInfoLib::Config.Trace_Format_Get()!=MediaInfoLib::Config.Trace_Format_XML && MediaInfoLib::Config.Trace_Format_Get()!=MediaInfoLib::Config.Trace_Format_MICRO_XML) Param(Name, Info);
2064     Element_End0();
2065 }
2066 
2067 //---------------------------------------------------------------------------
Get_Flags(int64u ValueToPut,int8u & Info,const char * Name)2068 void File__Analyze::Get_Flags (int64u ValueToPut, int8u &Info, const char* Name)
2069 {
2070     Info=(int8u)ValueToPut;
2071 
2072     Element_Begin0();
2073     if (Trace_Activated && MediaInfoLib::Config.Trace_Format_Get()!=MediaInfoLib::Config.Trace_Format_XML && MediaInfoLib::Config.Trace_Format_Get()!=MediaInfoLib::Config.Trace_Format_MICRO_XML) Param(Name, Info);
2074     Element_End0();
2075 }
2076 
2077 //---------------------------------------------------------------------------
Skip_Flags(int64u Flags,size_t Order,const char * Name)2078 void File__Analyze::Skip_Flags(int64u Flags, size_t Order, const char* Name)
2079 {
2080     Element_Begin0();
2081     if (Trace_Activated && MediaInfoLib::Config.Trace_Format_Get()!=MediaInfoLib::Config.Trace_Format_XML && MediaInfoLib::Config.Trace_Format_Get()!=MediaInfoLib::Config.Trace_Format_MICRO_XML) Param(Name, (Flags&((int64u)1<<Order))); //TODO: support flags in XML trace
2082     Element_End0();
2083 }
2084 
2085 //---------------------------------------------------------------------------
Skip_Flags(int64u ValueToPut,const char * Name)2086 void File__Analyze::Skip_Flags(int64u ValueToPut, const char* Name)
2087 {
2088     Element_Begin0();
2089     if (Trace_Activated && MediaInfoLib::Config.Trace_Format_Get()!=MediaInfoLib::Config.Trace_Format_XML && MediaInfoLib::Config.Trace_Format_Get()!=MediaInfoLib::Config.Trace_Format_MICRO_XML) Param(Name, ValueToPut);
2090     Element_End0();
2091 }
2092 
2093 //***************************************************************************
2094 // BitStream
2095 //***************************************************************************
2096 
2097 //---------------------------------------------------------------------------
Get_BS(int8u Bits,int32u & Info,const char * Name)2098 void File__Analyze::Get_BS(int8u Bits, int32u &Info, const char* Name)
2099 {
2100     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2101     Info=BS->Get4(Bits);
2102     if (Trace_Activated) Param(Name, Info, Bits);
2103 }
2104 
2105 //---------------------------------------------------------------------------
Get_SB(bool & Info,const char * Name)2106 void File__Analyze::Get_SB(             bool &Info, const char* Name)
2107 {
2108     INTEGRITY_INT(1<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2109     Info=BS->GetB();
2110     if (Trace_Activated) Param(Name, Info, 1);
2111 }
2112 
2113 //---------------------------------------------------------------------------
Get_S1(int8u Bits,int8u & Info,const char * Name)2114 void File__Analyze::Get_S1(int8u Bits, int8u &Info, const char* Name)
2115 {
2116     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2117     Info=BS->Get1(Bits);
2118     #if MEDIAINFO_TRACE
2119         if (Trace_Activated)
2120         {
2121             Param(Name, Info, Bits);
2122             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2123         }
2124     #endif //MEDIAINFO_TRACE
2125 }
2126 
2127 //---------------------------------------------------------------------------
Get_S2(int8u Bits,int16u & Info,const char * Name)2128 void File__Analyze::Get_S2(int8u Bits, int16u &Info, const char* Name)
2129 {
2130     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2131     Info=BS->Get2(Bits);
2132     #if MEDIAINFO_TRACE
2133         if (Trace_Activated)
2134         {
2135             Param(Name, Info, Bits);
2136             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2137         }
2138     #endif //MEDIAINFO_TRACE
2139 }
2140 
2141 //---------------------------------------------------------------------------
Get_S3(int8u Bits,int32u & Info,const char * Name)2142 void File__Analyze::Get_S3(int8u Bits, int32u &Info, const char* Name)
2143 {
2144     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2145     Info=BS->Get4(Bits);
2146     #if MEDIAINFO_TRACE
2147         if (Trace_Activated)
2148         {
2149             Param(Name, Info, Bits);
2150             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2151         }
2152     #endif //MEDIAINFO_TRACE
2153 }
2154 
2155 //---------------------------------------------------------------------------
Get_S4(int8u Bits,int32u & Info,const char * Name)2156 void File__Analyze::Get_S4(int8u Bits, int32u &Info, const char* Name)
2157 {
2158     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2159     Info=BS->Get4(Bits);
2160     #if MEDIAINFO_TRACE
2161         if (Trace_Activated)
2162         {
2163             Param(Name, Info, Bits);
2164             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2165         }
2166     #endif //MEDIAINFO_TRACE
2167 }
2168 
2169 //---------------------------------------------------------------------------
Get_S5(int8u Bits,int64u & Info,const char * Name)2170 void File__Analyze::Get_S5(int8u Bits, int64u &Info, const char* Name)
2171 {
2172     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2173     Info=BS->Get8(Bits);
2174     #if MEDIAINFO_TRACE
2175         if (Trace_Activated)
2176         {
2177             Param(Name, Info, Bits);
2178             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2179         }
2180     #endif //MEDIAINFO_TRACE
2181 }
2182 
2183 //---------------------------------------------------------------------------
Get_S6(int8u Bits,int64u & Info,const char * Name)2184 void File__Analyze::Get_S6(int8u Bits, int64u &Info, const char* Name)
2185 {
2186     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2187     Info=BS->Get8(Bits);
2188     #if MEDIAINFO_TRACE
2189         if (Trace_Activated)
2190         {
2191             Param(Name, Info, Bits);
2192             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2193         }
2194     #endif //MEDIAINFO_TRACE
2195 }
2196 
2197 //---------------------------------------------------------------------------
Get_S7(int8u Bits,int64u & Info,const char * Name)2198 void File__Analyze::Get_S7(int8u Bits, int64u &Info, const char* Name)
2199 {
2200     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2201     Info=BS->Get8(Bits);
2202     #if MEDIAINFO_TRACE
2203         if (Trace_Activated)
2204         {
2205             Param(Name, Info, Bits);
2206             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2207         }
2208     #endif //MEDIAINFO_TRACE
2209 }
2210 
2211 //---------------------------------------------------------------------------
Get_S8(int8u Bits,int64u & Info,const char * Name)2212 void File__Analyze::Get_S8(int8u Bits, int64u &Info, const char* Name)
2213 {
2214     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2215     Info=BS->Get8(Bits);
2216     #if MEDIAINFO_TRACE
2217         if (Trace_Activated)
2218         {
2219             Param(Name, Info, Bits);
2220             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2221         }
2222     #endif //MEDIAINFO_TRACE
2223 }
2224 
2225 //---------------------------------------------------------------------------
Peek_BS(int8u Bits,int32u & Info)2226 void File__Analyze::Peek_BS(int8u Bits, int32u &Info)
2227 {
2228     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2229     Info=BS->Peek4(Bits);
2230 }
2231 
2232 //---------------------------------------------------------------------------
Peek_SB(bool & Info)2233 void File__Analyze::Peek_SB(              bool &Info)
2234 {
2235     INTEGRITY_INT(1<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2236     Info=BS->PeekB();
2237 }
2238 
2239 //---------------------------------------------------------------------------
Peek_S1(int8u Bits,int8u & Info)2240 void File__Analyze::Peek_S1(int8u Bits, int8u &Info)
2241 {
2242     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2243     Info=BS->Peek1(Bits);
2244 }
2245 
2246 //---------------------------------------------------------------------------
Peek_S2(int8u Bits,int16u & Info)2247 void File__Analyze::Peek_S2(int8u Bits, int16u &Info)
2248 {
2249     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2250     Info=BS->Peek2(Bits);
2251 }
2252 
2253 //---------------------------------------------------------------------------
Peek_S3(int8u Bits,int32u & Info)2254 void File__Analyze::Peek_S3(int8u Bits, int32u &Info)
2255 {
2256     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2257     Info=BS->Peek4(Bits);
2258 }
2259 
2260 //---------------------------------------------------------------------------
Peek_S4(int8u Bits,int32u & Info)2261 void File__Analyze::Peek_S4(int8u Bits, int32u &Info)
2262 {
2263     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2264     Info=BS->Peek4(Bits);
2265 }
2266 
2267 //---------------------------------------------------------------------------
Peek_S5(int8u Bits,int64u & Info)2268 void File__Analyze::Peek_S5(int8u Bits, int64u &Info)
2269 {
2270     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2271     Info=BS->Peek8(Bits);
2272 }
2273 
2274 //---------------------------------------------------------------------------
Peek_S6(int8u Bits,int64u & Info)2275 void File__Analyze::Peek_S6(int8u Bits, int64u &Info)
2276 {
2277     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2278     Info=BS->Peek8(Bits);
2279 }
2280 
2281 //---------------------------------------------------------------------------
Peek_S7(int8u Bits,int64u & Info)2282 void File__Analyze::Peek_S7(int8u Bits, int64u &Info)
2283 {
2284     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2285     Info=BS->Peek8(Bits);
2286 }
2287 
2288 //---------------------------------------------------------------------------
Peek_S8(int8u Bits,int64u & Info)2289 void File__Analyze::Peek_S8(int8u Bits, int64u &Info)
2290 {
2291     INTEGRITY_INT(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2292     Info=BS->Peek8(Bits);
2293 }
2294 
2295 //---------------------------------------------------------------------------
Skip_BS(size_t Bits,const char * Name)2296 void File__Analyze::Skip_BS(size_t Bits, const char* Name)
2297 {
2298     INTEGRITY(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2299     if (Trace_Activated)
2300     {
2301         if (Bits<=32) //TODO: in BitStream.h, handle >32 bit gets
2302         {
2303             Param(Name, BS->Get4((int8u)Bits), Bits);
2304             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2305         }
2306         else
2307         {
2308             Param(Name, "(Data)");
2309             BS->Skip(Bits);
2310         }
2311     }
2312     else
2313         BS->Skip(Bits);
2314 }
2315 
2316 //---------------------------------------------------------------------------
Skip_SB(const char * Name)2317 void File__Analyze::Skip_SB(              const char* Name)
2318 {
2319     INTEGRITY(1<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2320     if (Trace_Activated)
2321         Param(Name, BS->GetB(), 1);
2322     else
2323         BS->Skip(1);
2324 }
2325 
2326 //---------------------------------------------------------------------------
Skip_S1(int8u Bits,const char * Name)2327 void File__Analyze::Skip_S1(int8u Bits, const char* Name)
2328 {
2329     INTEGRITY(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2330     #if MEDIAINFO_TRACE
2331         if (Trace_Activated)
2332         {
2333             Param(Name, BS->Get1(Bits), 1);
2334             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2335         }
2336         else
2337     #endif //MEDIAINFO_TRACE
2338         BS->Skip(Bits);
2339 }
2340 
2341 //---------------------------------------------------------------------------
Skip_S2(int8u Bits,const char * Name)2342 void File__Analyze::Skip_S2(int8u Bits, const char* Name)
2343 {
2344     INTEGRITY(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2345     #if MEDIAINFO_TRACE
2346         if (Trace_Activated)
2347         {
2348             Param(Name, BS->Get2(Bits), Bits);
2349             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2350         }
2351         else
2352     #endif //MEDIAINFO_TRACE
2353         BS->Skip(Bits);
2354 }
2355 
2356 //---------------------------------------------------------------------------
Skip_S3(int8u Bits,const char * Name)2357 void File__Analyze::Skip_S3(int8u Bits, const char* Name)
2358 {
2359     INTEGRITY(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2360     #if MEDIAINFO_TRACE
2361         if (Trace_Activated)
2362         {
2363             Param(Name, BS->Get4(Bits), Bits);
2364             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2365         }
2366         else
2367     #endif //MEDIAINFO_TRACE
2368         BS->Skip(Bits);
2369 }
2370 
2371 //---------------------------------------------------------------------------
Skip_S4(int8u Bits,const char * Name)2372 void File__Analyze::Skip_S4(int8u Bits, const char* Name)
2373 {
2374     INTEGRITY(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2375     #if MEDIAINFO_TRACE
2376         if (Trace_Activated)
2377         {
2378             Param(Name, BS->Get4(Bits), Bits);
2379             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2380         }
2381         else
2382     #endif //MEDIAINFO_TRACE
2383         BS->Skip(Bits);
2384 }
2385 
2386 //---------------------------------------------------------------------------
Skip_S5(int8u Bits,const char * Name)2387 void File__Analyze::Skip_S5(int8u Bits, const char* Name)
2388 {
2389     INTEGRITY(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2390     #if MEDIAINFO_TRACE
2391         if (Trace_Activated)
2392         {
2393             Param(Name, BS->Get8(Bits), Bits);
2394             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2395         }
2396         else
2397     #endif //MEDIAINFO_TRACE
2398         BS->Skip(Bits);
2399 }
2400 
2401 //---------------------------------------------------------------------------
Skip_S6(int8u Bits,const char * Name)2402 void File__Analyze::Skip_S6(int8u Bits, const char* Name)
2403 {
2404     INTEGRITY(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2405     #if MEDIAINFO_TRACE
2406         if (Trace_Activated)
2407         {
2408             Param(Name, BS->Get8(Bits), Bits);
2409             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2410         }
2411         else
2412     #endif //MEDIAINFO_TRACE
2413         BS->Skip(Bits);
2414 }
2415 
2416 //---------------------------------------------------------------------------
Skip_S7(int8u Bits,const char * Name)2417 void File__Analyze::Skip_S7(int8u Bits, const char* Name)
2418 {
2419     INTEGRITY(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2420     #if MEDIAINFO_TRACE
2421         if (Trace_Activated)
2422         {
2423             Param(Name, BS->Get8(Bits), Bits);
2424             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2425         }
2426         else
2427     #endif //MEDIAINFO_TRACE
2428         BS->Skip(Bits);
2429 }
2430 
2431 //---------------------------------------------------------------------------
Skip_S8(int8u Bits,const char * Name)2432 void File__Analyze::Skip_S8(int8u Bits, const char* Name)
2433 {
2434     INTEGRITY(Bits<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2435     #if MEDIAINFO_TRACE
2436         if (Trace_Activated)
2437         {
2438             Param(Name, BS->Get8(Bits), Bits);
2439             Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2440         }
2441         else
2442     #endif //MEDIAINFO_TRACE
2443         BS->Skip(Bits);
2444 }
2445 
2446 //---------------------------------------------------------------------------
Mark_0()2447 void File__Analyze::Mark_0()
2448 {
2449     INTEGRITY(1<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2450     bool Info=BS->GetB();
2451     if (Info)
2452     {
2453         Param("0", Info, 1);
2454         Element_DoNotTrust("Mark bit is wrong");
2455     }
2456 }
2457 
2458 //---------------------------------------------------------------------------
Mark_0_NoTrustError()2459 void File__Analyze::Mark_0_NoTrustError()
2460 {
2461     INTEGRITY(1<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2462     bool Info=BS->GetB();
2463     if (Info)
2464     {
2465         Param("0", Info, 1);
2466         Param_Info("Warning: should be 0");
2467     }
2468 }
2469 
2470 //---------------------------------------------------------------------------
Mark_1()2471 void File__Analyze::Mark_1()
2472 {
2473     INTEGRITY(1<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2474     bool Info=BS->GetB();
2475     if (!Info)
2476     {
2477         Param("1", Info, 1);
2478         Element_DoNotTrust("Mark bit is wrong");
2479     }
2480 }
2481 
2482 //---------------------------------------------------------------------------
Mark_1_NoTrustError()2483 void File__Analyze::Mark_1_NoTrustError()
2484 {
2485     INTEGRITY(1<=BS->Remain(), "Size is wrong", BS->Offset_Get())
2486     bool Info=BS->GetB();
2487     if (!Info)
2488     {
2489         Param("1", Info, 1);
2490         Param_Info("Warning: should be 1");
2491     }
2492 }
2493 
2494 //***************************************************************************
2495 // BitStream (Little Endian)
2496 //***************************************************************************
2497 
2498 //---------------------------------------------------------------------------
Get_BT(size_t Bits,int32u & Info,const char * Name)2499 void File__Analyze::Get_BT(size_t Bits, int32u &Info, const char* Name)
2500 {
2501     INTEGRITY_INT(Bits<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2502     Info=BT->Get(Bits);
2503     if (Trace_Activated) Param(Name, Info);
2504 }
2505 
2506 //---------------------------------------------------------------------------
Get_TB(bool & Info,const char * Name)2507 void File__Analyze::Get_TB(             bool &Info, const char* Name)
2508 {
2509     INTEGRITY_INT(1<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2510     Info=BT->GetB();
2511     if (Trace_Activated) Param(Name, Info);
2512 }
2513 
2514 //---------------------------------------------------------------------------
Get_T1(size_t Bits,int8u & Info,const char * Name)2515 void File__Analyze::Get_T1(size_t Bits, int8u &Info, const char* Name)
2516 {
2517     INTEGRITY_INT(Bits<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2518     Info=BT->Get1(Bits);
2519     if (Trace_Activated)
2520     {
2521         Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2522         Param(Name, Info);
2523     }
2524 }
2525 
2526 //---------------------------------------------------------------------------
Get_T2(size_t Bits,int16u & Info,const char * Name)2527 void File__Analyze::Get_T2(size_t Bits, int16u &Info, const char* Name)
2528 {
2529     INTEGRITY_INT(Bits<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2530     Info=BT->Get2(Bits);
2531     if (Trace_Activated) Param(Name, Info);
2532 }
2533 
2534 //---------------------------------------------------------------------------
Get_T4(size_t Bits,int32u & Info,const char * Name)2535 void File__Analyze::Get_T4(size_t Bits, int32u &Info, const char* Name)
2536 {
2537     INTEGRITY_INT(Bits<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2538     Info=BT->Get4(Bits);
2539     if (Trace_Activated) Param(Name, Info);
2540 }
2541 
2542 //---------------------------------------------------------------------------
Get_T8(size_t Bits,int64u & Info,const char * Name)2543 void File__Analyze::Get_T8(size_t Bits, int64u &Info, const char* Name)
2544 {
2545     INTEGRITY_INT(Bits<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2546     Info=BT->Get8(Bits);
2547     if (Trace_Activated) Param(Name, Info);
2548 }
2549 
2550 //---------------------------------------------------------------------------
Peek_BT(size_t Bits,int32u & Info)2551 void File__Analyze::Peek_BT(size_t Bits, int32u &Info)
2552 {
2553     INTEGRITY_INT(Bits<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2554     Info=BT->Peek(Bits);
2555 }
2556 
2557 //---------------------------------------------------------------------------
Peek_TB(bool & Info)2558 void File__Analyze::Peek_TB(              bool &Info)
2559 {
2560     INTEGRITY_INT(1<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2561     Info=BT->PeekB();
2562 }
2563 
2564 //---------------------------------------------------------------------------
Peek_T1(size_t Bits,int8u & Info)2565 void File__Analyze::Peek_T1(size_t Bits, int8u &Info)
2566 {
2567     INTEGRITY_INT(Bits<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2568     Info=BT->Peek1(Bits);
2569 }
2570 
2571 //---------------------------------------------------------------------------
Peek_T2(size_t Bits,int16u & Info)2572 void File__Analyze::Peek_T2(size_t Bits, int16u &Info)
2573 {
2574     INTEGRITY_INT(Bits<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2575     Info=BT->Peek2(Bits);
2576 }
2577 
2578 //---------------------------------------------------------------------------
Peek_T4(size_t Bits,int32u & Info)2579 void File__Analyze::Peek_T4(size_t Bits, int32u &Info)
2580 {
2581     INTEGRITY_INT(Bits<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2582     Info=BT->Peek4(Bits);
2583 }
2584 
2585 //---------------------------------------------------------------------------
Peek_T8(size_t Bits,int64u & Info)2586 void File__Analyze::Peek_T8(size_t Bits, int64u &Info)
2587 {
2588     INTEGRITY_INT(Bits<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2589     Info=BT->Peek8(Bits);
2590 }
2591 
2592 //---------------------------------------------------------------------------
Skip_BT(size_t Bits,const char * Name)2593 void File__Analyze::Skip_BT(size_t Bits, const char* Name)
2594 {
2595     INTEGRITY(Bits<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2596     if (Trace_Activated)
2597     {
2598         if (Bits<=32) //TODO: in BitStream.h, handle >32 bit gets
2599             Param(Name, BT->Get(Bits));
2600         else
2601         {
2602             Param(Name, "(Data)");
2603             BT->Skip(Bits);
2604         }
2605     }
2606     else
2607         BT->Skip(Bits);
2608 }
2609 
2610 //---------------------------------------------------------------------------
Skip_TB(const char * Name)2611 void File__Analyze::Skip_TB(              const char* Name)
2612 {
2613     INTEGRITY(1<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2614     if (Trace_Activated)
2615         Param(Name, BT->GetB());
2616     else
2617         BT->SkipB();
2618 }
2619 
2620 //---------------------------------------------------------------------------
Skip_T1(size_t Bits,const char * Name)2621 void File__Analyze::Skip_T1(size_t Bits, const char* Name)
2622 {
2623     INTEGRITY(Bits<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2624     if (Trace_Activated)
2625     {
2626         Param_Info(__T("(")+Ztring::ToZtring(Bits)+__T(" bits)"));
2627         Param(Name, BT->Get1(Bits));
2628     }
2629     else
2630         BT->Skip1(Bits);
2631 }
2632 
2633 //---------------------------------------------------------------------------
Skip_T2(size_t Bits,const char * Name)2634 void File__Analyze::Skip_T2(size_t Bits, const char* Name)
2635 {
2636     INTEGRITY(Bits<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2637     if (Trace_Activated)
2638         Param(Name, BT->Get2(Bits));
2639     else
2640         BT->Skip2(Bits);
2641 }
2642 
2643 //---------------------------------------------------------------------------
Skip_T4(size_t Bits,const char * Name)2644 void File__Analyze::Skip_T4(size_t Bits, const char* Name)
2645 {
2646     INTEGRITY(Bits<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2647     if (Trace_Activated)
2648         Param(Name, BT->Get4(Bits));
2649     else
2650         BT->Skip4(Bits);
2651 }
2652 
2653 //---------------------------------------------------------------------------
Skip_T8(size_t Bits,const char * Name)2654 void File__Analyze::Skip_T8(size_t Bits, const char* Name)
2655 {
2656     INTEGRITY(Bits<=BT->Remain(), "Size is wrong", BT->Offset_Get())
2657     if (Trace_Activated)
2658         Param(Name, BT->Get8(Bits));
2659     else
2660         BT->Skip8(Bits);
2661 }
2662 
2663 } //NameSpace
2664 #endif //MEDIAINFO_TRACE
2665