typedef ubyte mac_address[6]<read=Str("%02X%02X%02X%02X%02X%02X",this[0],this[1],this[2],this[3],this[4],this[5])>;
uint16 CalcChecksum(uint64 address, uint32 size)
{
local uint32 result;
local uint32 i;
result = 0;
for (i = 0; i < size; i++) {
result += ReadUByte(address + i);
}
return result;
}
enum <ubyte> Region {
REGION_CH = 0x01,
REGION_CH2 = 0x20,
REGION_TW = 0x02,
REGION_TW2 = 0x32,
REGION_WR = 0x03,
REGION_WR2 = 0x30,
REGION_HK = 0x04,
REGION_HK2 = 0x31,
REGION_BJ = 0x21,
REGION_SH = 0x22,
REGION_GZ = 0x23,
REGION_CD = 0x24,
REGION_JP = 0x33,
REGION_AS = 0x34,
REGION_EU = 0x35,
REGION_NA = 0x36,
/ all other - REGION_RR
};
enum <ubyte> VideoOutType {
VIDEO_NO_OUT = 0,
VIDEO_CVBS = 1,
VIDEO_HDMI = 2,
VIDEO_SDI = 3
};
typedef struct _SWKHHeader {
local uint64 start = FTell();
char magic[4]<bgcolor=cBlue>;
uint32 checksum; / sum(header[12:])
uint32 size<bgcolor=cPurple>;
uint32 unk0; / ???
enum <uint32> { LANG_EN = 1, LANG_CN = 2 } languange<bgcolor=cAqua>;
uint32 device_class; / ???
uint32 unk1;
uint16 devType_part1<format=hex,bgcolor=cYellow>;
char verification_code[6]<bgcolor=cLtGreen>;
ubyte unk2[8];
uint16 encodeChans<bgcolor=cLtBlue>;
uint16 decodeChans<bgcolor=cLtGray>;
ubyte unk3[4];
ubyte alarmInNums<bgcolor=cWhite>;
mac_address mac<format=hex,bgcolor=cLtRed>;
mac_address mac2<format=hex,bgcolor=cLtRed>;
char serial_date[8]<bgcolor=cGreen>;
char subserial[9]<bgcolor=cAqua>;
ubyte videoStandard<bgcolor=cDkGreen>;
ubyte unk_ser2; / 1 - A, 2 - B, other - C
ubyte unk_ser3; / 1 - A, 2 - B, other - C
Region region<bgcolor=cPurple>; / zone
ubyte has_audio_input<bgcolor=cLtPurple>;
ubyte unk4;
ubyte USBNum<bgcolor=cBlue>;
ubyte unk5;
ubyte alarmOutNums<bgcolor=cLtBlue>;
ubyte unk6;
ubyte has_speaker<bgcolor=cAqua>;
VideoOutType videoOutType<bgcolor=cLtYellow>;
ubyte videoInType<bgcolor=cLtAqua>;
ubyte unk7_0;
ubyte unk7_1;
ubyte IRSupport<bgcolor=cBlue>;
ubyte has_wifi<bgcolor=cLtGreen>; / 1 - yes, 0 - no
ubyte OnepushFocus<bgcolor=cPurple>;
uint16 devType_part2<format=hex,bgcolor=cYellow>; / devType_part1 << 16 | devType_part2
ubyte unk_8;
ubyte unk_9;
ubyte unk10[24];
char dev_type_readable[64]<bgcolor=cLtGreen>;
ubyte unk11[12];
ubyte unk12;
ubyte unk99[51];
local uint16 real_checksum = CalcChecksum(start + 12, size);
local uint32 checksum_color = cGreen;
if (checksum != real_checksum) {
checksum_color = cRed;
Printf("Computed checksum = %08X", this.real_checksum);
}
local uint64 curr_pos = FTell(); / hack to apply color after
FSeek(start + 4);
SetBackColor(checksum_color);
ubyte bla[4]<hidden=true>;
SetBackColor(cNone);
FSeek(curr_pos);
} SWKHHeader;
SWKHHeader header;