//------------------------------------------------ //--- 010 Editor v4.0 Binary Template // // File: InspectorWithMP4DateTime.bt // Authors: SweetScape Software, Marian Denes // Version: 1.3 // Purpose: Adds MP4_Time to the Inspector template. // This template may be used // to customize the auto tab of the // Inspector with your own variables. // See the Inspector section of the // Options dialog for more information. // Category: Inspector // File Mask: // ID Bytes: // History: // 1.3 2016-02-12 SweetScape Software: Updated header for repository submission. // 1.2 Marian Denes: Added MP4_Time data type. // 1.1 SweetScape Software: Added hfloat data type. // 1.0 SweetScape Software: Initial release. //------------------------------------------------ RequiresVersion( 4.0 ); // Calculate the position for each variable, // either at the beginning of the selection // or at the current cursor position. local int64 position; if( GetSelSize() > 0 ) position = GetSelStart(); else position = GetCursorPos(); int leap(int year) { return year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 ); } int daysInYear(int year) {return 365 + leap(year);} typedef uint MP4_Time ; string MP4_TimeRead( MP4_Time secs ) { // secs - seconds since midnight, January 1, 1904 int days = secs / 86400; secs = secs % 86400; int year = 1904; int month = 1; int daysInMonth[13] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int extraDay [13] = {-1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; while (days > daysInYear(year)) { days -= daysInYear(year); year++; } while (days > daysInMonth[month] + leap(year) * extraDay[month]) { days -= daysInMonth[month] + leap(year) * extraDay[month]; month++; } int day = ++days; // 0 (full) days remaining means the 1st day of the monht, and so on int hours = secs / 3600; secs = secs % 3600; int mins = secs / 60; secs = secs % 60; string s; SPrintf( s, "%02d.%02d.%4d %02d:%02d:%02d", day, month, year, hours, mins, secs ); return s; } void MP4_TimeWrite( MP4_Time &secs, string dateTime ) { int daysInMonth[13] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int extraDay [13] = {-1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int day, month, year, hour, min, sec; //secs = 0x1122; SScanf(dateTime, "%d.%d.%d %d:%d:%d", day, month, year, hour, min, sec); int days = day - 1; // January 1, 1994 is 0 days after this date, and so on int months, hours, mins, y, m; for (y = 1904; y < year; ++y) days += daysInYear(y); for (m = 1; m < month; ++m) days += daysInMonth[m] + leap(year) * extraDay[m]; secs = days * 86400 + hour * 3600 + min * 60 + sec; } // Define variables for the inspector FSeek( position ); MP4_Time _mp4t ; FSeek( position ); byte _si8 ; FSeek( position ); ubyte _ui8 ; FSeek( position ); short _si16 ; FSeek( position ); ushort _ui16 ; FSeek( position ); int _si32 ; FSeek( position ); uint _ui32 ; FSeek( position ); int64 _si64 ; FSeek( position ); uint64 _ui64 ; FSeek( position ); float _f ; FSeek( position ); double _d ; FSeek( position ); hfloat _hf ; FSeek( position ); char _s [ReadStringLength(position,256)] ; // limit to 256 characters FSeek( position ); wchar_t _ws[ReadWStringLength(position,256)] ; // limit to 256 characters FSeek( position ); DOSDATE _dd ; FSeek( position ); DOSTIME _dt ; FSeek( position ); FILETIME _ft ; FSeek( position ); OLETIME _ot ; FSeek( position ); time_t _tt ;