//--------------------------------------
//--- 010 Editor v2.0.2 Binary Template
//
// File:
// Author:
// Revision:
// Purpose:
//--------------------------------------

typedef struct {
    long    flashid;
    long    sections_number; //always 0
    long    vtable_offset; //always 0
    time_t  timestamp;
    long    user_version;
    long    fieldrefs_table_offset;
    ushort  type_list_size;
    ushort  reserved; //always 0xFF
    long    data_section; //always 0xFFFF
    long    module_info; //always 0xFFFF
    ushort  version;
    ushort  code_segment_size;
    ushort  data_segemnt_size;
    ushort  cod_file_flags;
} CODFILEHEADER;


typedef struct{ 
   ushort  entry_point_class_offset;
   ushort  entry_point_class_name_offset;
   ushort  entry_point_class_type_index; 
} ENTRYPOINTCLASS;


typedef struct {
    byte      cod_file_flags;
    byte      version;
    short     num_icalls;
    ubyte     num_modules;
    ubyte     num_classes;
    WORD      exported_strings_table; //offset
    WORD      data_bytes_table;  //offset
    WORD      initiated_static_data_table;  //offset
    WORD      class_definitions_table;  //offset
    WORD      type_list_table;  //offset
    WORD      intf_method_refs_table;  //offset
    WORD      class_refs_table;  //offset
    WORD      routine_fixup_table;  //offset
    WORD      static_routine_fixup_table;  //offset
    WORD      virtual_routine_fixup_table;  //offset
    WORD      class_code_fixup_table;  //offset
    WORD      aliases_table; //classDataFixupTable if aliases are not defined
    WORD      fields_fixup_table;  //offset
    WORD      local_fields_fixup_table;  //offset
    WORD      static_fields_fixup_table;  //offset
    WORD      module_code_fixup_table; //nativeRoutinesTable if aliases are not defined
    WORD      static_size;
    ENTRYPOINTCLASS   entry_point;
    ENTRYPOINTCLASS   entry_point2;
} DATASEGHEADER;


typedef struct {
    WORD      identifier;
    WORD      size;
    WORD      offset;
} EXPORTEDSTR;

typedef struct {
     WORD     identifier_obfuscated; 
     WORD     identifier_obfuscated2;
     ubyte    skipped[10];
     WORD     secure_index;
     WORD     index;
     WORD     code_start; // offset from code_segment_start (0x44)
     WORD     code_end;   // offset from code_segment_start (0x44)
     WORD     attributes;	
} CLASSDEFS;


typedef struct {
     WORD     unknown;
     DWORD    unknown;
} INTDSTATICDATA;

typedef struct {
     WORD     module_index; 
     WORD     identifier_obfuscated;
     WORD     identifier_obfuscated2;
     ubyte    field1;
     ubyte    field2;
} CLASSREFS;

typedef struct {
    WORD     field1;
    WORD     field2;
    WORD     field3; 
} MEMBERFIXUP;

typedef struct {
    WORD     field1;
    WORD     field2;
    WORD     field3;
    WORD     field4;
    WORD     field5; 
} VIRTUALMEMBERFIXUP;


//---------------------------------------


LittleEndian();
SetBackColor (cLtBlue);
CODFILEHEADER cod_file_header;

if (cod_file_header.flashid != -16162) {
    Warning( "File is not a valid cod file. Template stopped." );
    return -1;
}

FSkip (cod_file_header.code_segment_size);

local WORD data_segment_offset = FTell();

SetBackColor (cLtBlue);
DATASEGHEADER data_segment_header;

SetBackColor (cLtGreen);
WORD class_table[data_segment_header.num_classes];

SetBackColor (cLtRed);
WORD modules_table[data_segment_header.num_modules];

SetBackColor (cLtBlue);
WORD modules_table2[data_segment_header.num_modules];

SetBackColor (cLtGreen);

local int num_siblings;

num_siblings = (data_segment_header.aliases_table - (FTell()-data_segment_offset))/2;

WORD siblings_table [num_siblings];


SetBackColor (cLtYellow);

local int num_aliases;

num_aliases = (data_segment_header.exported_strings_table - (FTell()-data_segment_offset))/2;

WORD aliases_table[num_aliases];

SetBackColor(cLtRed);

local int num_strings;

num_strings = (data_segment_header.data_bytes_table - (FTell()-data_segment_offset))/6;

EXPORTEDSTR exported_strings[num_strings];

local int remember_pos;

remember_pos = FTell();


SetBackColor (cLtGreen);

local int i;

for (i=0; i<data_segment_header.num_classes;i++) {
	FSeek (data_segment_offset + class_table [i]);
	CLASSDEFS class;
}


SetBackColor (cLtBlue);

FSeek (data_segment_offset + data_segment_header.initiated_static_data_table);

while (FTell() < (data_segment_offset + data_segment_header.class_definitions_table) ) {

   INTDSTATICDATA initializated_static_data;
}


SetBackColor (cLtYellow);

FSeek (data_segment_offset + data_segment_header.class_refs_table);

while (FTell() < (data_segment_offset + data_segment_header.routine_fixup_table) ) {

   CLASSREFS class_ref;
}

WORD num_routine_members;

for (i=0;i<num_routine_members;i++) {
   MEMBERFIXUP routine_fixup_table;
}

WORD num_static_routine_members;

for (i=0;i<num_static_routine_members;i++) {
   MEMBERFIXUP static_routine_fixup_table;   
}

WORD num_virtual_routine_members;

//for (i=0;i<num_virtual_routine_members;i++) {
//   VIRTUALMEMBERFIXUP virtual_routine_fixup_table;  
//}
