📄 mtkinfo.c
字号:
/* mtkinfo, 6/sep/03
(c)copyright 2003, av_pete
a tool to gather the locations of known data within mt1369 firmware.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* bootstrap code seems to always begin with the following instructions */
static const unsigned int bootstrap_magic[] = {
0xea00000e, /* b +0x40 */
0xea00000d, /* b +0x3c */
0xea00000c, /* b +0x38 */
0xea00000b, /* b +0x34 */
0xea00000a, /* b +0x30 */
};
static const unsigned char mtkosd_magic[] = "MTKOSD 0.1";
static const unsigned char mpeg2_start_magic[] = {
0x00, 0x00, 0x01, 0xb3
};
static const unsigned char mpeg2_user_magic[] = {
0x00, 0x00, 0x01, 0xb2
};
static const unsigned char mpeg2_stop_magic[] = {
0x00, 0x00, 0x01, 0xb7
};
int main(int argc, char **argv)
{
FILE *f;
unsigned char * buf;
unsigned int length;
unsigned int i, j;
unsigned int within_mpeg2;
if (argc!=2) {
printf("%s filename.bin\n", argv[0]);
return EXIT_FAILURE;
}
f = fopen(argv[1], "rb");
if (f==NULL) {
printf("fopen %s failed\n", argv[1]);
return EXIT_FAILURE;
}
fseek(f, 0, SEEK_END);
length = ftell(f);
fseek(f, 0, SEEK_SET);
buf = malloc(length);
if (buf==NULL) {
printf("fopen %s failed\n", argv[1]);
return EXIT_FAILURE;
}
fread(buf, length, 1, f);
fclose(f);
within_mpeg2 = 0;
for(i=0; i< length - sizeof(bootstrap_magic); i++) {
if (i%4==0 && memcmp(buf + i, bootstrap_magic, sizeof(bootstrap_magic))==0) {
unsigned int * tmp = (unsigned int*)(buf+i);
printf("0x%x\tbootstrap\n", i);
/* the 12th bootstrap words seems to indicate the number of compressed blocks.
this is followed by the compressed block offets, relative to the bootstrap */
for(j=0; j<tmp[12]; j++) {
printf("0x%x\tcompressed #%i\n", i + tmp[12+j+1], j+1);
}
/* the 11th bootstrap word indicates an offset to some unknown table, relative
to the bootstrap */
printf("0x%x\tunknown table\n", i + tmp[11]);
}else if (i%4==0 && memcmp(buf + i, mtkosd_magic, sizeof(mtkosd_magic))==0) {
/* generally there are two mtkosd blocks, which contain on-screen-display data
the first contains font/bitmap data, the second contains menu strings */
printf("0x%x\tmtkosd\n", i);
}else if (i%4==0 && memcmp(buf + i, mpeg2_start_magic, sizeof(mpeg2_start_magic))==0) {
/* mpeg2 start code */
printf("0x%x\tmpeg2_start\n", i);
within_mpeg2 = 1;
}else if (within_mpeg2 && memcmp(buf + i, mpeg2_user_magic, sizeof(mpeg2_user_magic))==0) {
/* mpeg2 user data code. often indicates the encoding application used */
printf("0x%x\tmpeg2_user \"", i);
i+=4;
while(buf[i+0]!=0x00 || buf[i+1]!=0x00 || buf[i+2]!=0x01) {
printf("%c", buf[i]);
i++;
}
printf("\"\n");
}else if (within_mpeg2 && memcmp(buf + i, mpeg2_stop_magic, sizeof(mpeg2_stop_magic))==0) {
/* mpeg2 stop code */
printf("0x%x\tmpeg2_stop\n", i);
within_mpeg2 = 0;
}
}
free(buf);
return EXIT_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -