2nd try: All AAC-HE files will double the frame sample count, not only AAC-HE files...
[maemo-rb.git] / utils / MTP / beastdump.c
blobb426c409ccf3edb30e2bef591f4568ccb14d5b80
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
5 #define NK_SIZE 12965335
6 #define READ_SIZE 1024
8 FILE *in, *out;
10 int bytes_read, bytes_writen, ret;
12 char header[]={0x42, 0x30, 0x30, 0x30, 0x46, 0x46, 0x0A, 0x00, 0x00, 0x20, 0x88, 0x84, 0x3C, 0xCD, 0x00, 0x00,
13 0x00, 0x20, 0x88, 0x04, 0x00, 0x00, 0x00, 0xEB, 0x01, 0x00, 0x00, 0xFE, 0x03, 0x00, 0xEA, 0x40,
14 0x00, 0x20, 0x88, 0x08, 0x00, 0x00, 0x00, 0xC7, 0x02, 0x00, 0x00, 0x45, 0x43, 0x45, 0x43, 0x20,
15 0x22, 0xED, 0x88, 0x48, 0x00, 0x20, 0x88, 0x04, 0x00, 0x00, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x20,
16 0x22, 0xCD, 0x00, 0x00, 0x10, 0x20, 0x88, 0xDC, 0x73, 0x04, 0x00, 0x70, 0xAE, 0xC4, 0x01, 0x00,
17 0x00, 0x0F, 0xE1, 0x13, 0x00, 0xA0, 0xE3, 0x80, 0x00, 0x80, 0xE3, 0x40, 0x00, 0x80, 0xE3, 0x00,
18 0xF0, 0x23, 0xE1, 0x30, 0x0F, 0x11, 0xEE, 0x02, 0x01, 0x80, 0xE3, 0x30, 0x0F, 0x01, 0xEE, 0x10,
19 0x0F, 0x11, 0xEE, 0x01, 0x0A, 0xC0, 0xE3, 0x04, 0x00, 0xC0, 0xE3, 0x01, 0x00, 0xC0, 0xE3, 0x02,
20 0x0A, 0xC0, 0xE3, 0x02, 0x06, 0x80, 0xE3, 0x10, 0x0F, 0x01, 0xEE, 0x55, 0x01, 0xA0, 0xE3, 0x92,
21 0x0F, 0x0F, 0xEE, 0x03, 0x12, 0xA0, 0xE3, 0x00, 0x00, 0xA0, 0xE3, 0x00, 0x01, 0x81, 0xE5, 0x0F,
22 0x06, 0xA0, 0xE3, 0x50, 0x0F, 0x01, 0xEE, 0x1C, 0x1B, 0x9F, 0xE5, 0x1C, 0x2B, 0x9F, 0xE5, 0x00,
23 0x00, 0xA0, 0xE3, 0x24, 0x00, 0x81, 0xE5, 0x28, 0x00, 0x81, 0xE5, 0x2C, 0x00, 0x81, 0xE5, 0x40,
24 0x00, 0x81, 0xE5, 0x44, 0x00, 0x81, 0xE5, 0x48, 0x00, 0x81, 0xE5, 0x4C, 0x00, 0x81, 0xE5, 0x50,
25 0x00, 0x81, 0xE5, 0x24, 0x00, 0x82, 0xE5, 0x28, 0x00, 0x82, 0xE5, 0x2C, 0x00, 0x82, 0xE5, 0x40,
26 0x00, 0x82, 0xE5, 0x44, 0x00, 0x82, 0xE5, 0x48, 0x00, 0x82, 0xE5, 0x4C, 0x00, 0x82, 0xE5, 0x50,
27 0x00, 0x82, 0xE5, 0x01, 0x01, 0x80, 0xE3, 0x20, 0x00, 0x81, 0xE5, 0x20, 0x00, 0x82, 0xE5, 0xCC,
28 0x0A, 0x9F, 0xE5, 0x00, 0x00, 0x81, 0xE5, 0x04, 0x00, 0x81, 0xE5, 0x00, 0x00, 0x82, 0xE5, 0x04,
29 0x00, 0x82, 0xE5, 0xBC, 0x1A, 0x9F, 0xE5, 0xBC, 0x0A, 0x9F, 0xE5, 0x00, 0x00, 0x81, 0xE5, 0x00,
30 0x01, 0x81, 0xE5, 0x00, 0x02, 0x81, 0xE5, 0x00, 0x03, 0x81, 0xE5, 0x00, 0x04, 0x81, 0xE5, 0x10,
31 0x00, 0xA0, 0xE3, 0x10, 0x00, 0x81, 0xE5, 0x10, 0x01, 0x81, 0xE5, 0x10, 0x02, 0x81, 0xE5, 0x10,
32 0x03, 0x81, 0xE5, 0x10, 0x04, 0x81, 0xE5, 0x01, 0x00, 0xA0, 0xE3, 0x00, 0x08, 0x81, 0xE5, 0x00,
33 0x09, 0x81, 0xE5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, 0xE3, 0x20,
56 0x00, 0x81, 0xE5, 0x01, 0x04, 0xA0, 0xE3, 0x24, 0x00, 0x81, 0xE5, 0x80, 0x09, 0x9F, 0xE5, 0x28,
57 0x00, 0x81, 0xE5, 0x7C, 0x09, 0x9F, 0xE5, 0x2C, 0x00, 0x81, 0xE5, 0x78, 0x09, 0x9F, 0xE5, 0x30,
58 0x00, 0x81, 0xE5, 0x74, 0x09, 0x9F, 0xE5, 0x34, 0x00, 0x81, 0xE5, 0x6C, 0x09, 0x9F, 0xE5, 0x38,
59 0x00, 0x81, 0xE5, 0x64, 0x09, 0x9F, 0xE5, 0x3C, 0x00, 0x81, 0xE5, 0x5C, 0x09, 0x9F, 0xE5, 0x40,
60 0x00, 0x81, 0xE5, 0x58, 0x09, 0x9F, 0xE5, 0x44, 0x00, 0x81, 0xE5, 0x4C, 0x09, 0x9F, 0xE5, 0x48,
61 0x00, 0x81, 0xE5, 0x44, 0x09, 0x9F, 0xE5, 0x4C, 0x00, 0x81, 0xE5, 0x40, 0x09, 0x9F, 0xE5, 0x50,
62 0x00, 0x81, 0xE5, 0x3C, 0x09, 0x9F, 0xE5, 0x54, 0x00, 0x81, 0xE5, 0x2C, 0x09, 0x9F, 0xE5, 0x58,
63 0x00, 0x81, 0xE5, 0x24, 0x09, 0x9F, 0xE5, 0x5C, 0x00, 0x81, 0xE5, 0x00, 0x00, 0xA0, 0xE3, 0x60,
64 0x00, 0x81, 0xE5, 0x14, 0x09, 0x9F, 0xE5, 0x64, 0x00, 0x81, 0xE5, 0x18, 0x09, 0x9F, 0xE5, 0x68,
65 0x00, 0x81, 0xE5, 0x04, 0x09, 0x9F, 0xE5, 0x6C, 0x00, 0x81, 0xE5, 0x0C, 0x09, 0x9F, 0xE5, 0x70,
66 0x00, 0x81, 0xE5, 0x08, 0x09, 0x9F, 0xE5, 0x74, 0x00, 0x81, 0xE5, 0x04, 0x09, 0x9F, 0xE5, 0x78,
67 0x00, 0x81, 0xE5, 0x00, 0x09, 0x9F, 0xE5, 0x7C, 0x00, 0x81, 0xE5, 0xFC, 0x08, 0x9F, 0xE5, 0x80,
68 0x00, 0x81, 0xE5, 0xF8, 0x08, 0x9F, 0xE5, 0x84, 0x00, 0x81, 0xE5, 0x12, 0x00, 0xA0, 0xE3, 0x88,
69 0x00, 0x81, 0xE5, 0x00, 0x00, 0xA0, 0xE3, 0x8C, 0x00, 0x81, 0xE5, 0xB0, 0x08, 0x9F, 0xE5, 0x90,
70 0x00, 0x81, 0xE5, 0xDC, 0x08, 0x9F, 0xE5, 0x94, 0x00, 0x81, 0xE5, 0xAC, 0x08, 0x9F, 0xE5, 0x98,
71 0x00, 0x81, 0xE5, 0xA4, 0x08, 0x9F, 0xE5, 0x9C, 0x00, 0x81, 0xE5, 0xC8, 0x08, 0x9F, 0xE5, 0xA0,
72 0x00, 0x81, 0xE5, 0x88, 0x08, 0x9F, 0xE5, 0xA4, 0x00, 0x81, 0xE5, 0x80, 0x08, 0x9F, 0xE5, 0xA8,
73 0x00, 0x81, 0xE5, 0x78, 0x08, 0x9F, 0xE5, 0xAC, 0x00, 0x81, 0xE5, 0xAC, 0x08, 0x9F, 0xE5, 0xB0,
74 0x00, 0x81, 0xE5, 0xA8, 0x08, 0x9F, 0xE5, 0xB4, 0x00, 0x81, 0xE5, 0xA4, 0x08, 0x9F, 0xE5, 0xB8,
75 0x00, 0x81, 0xE5, 0x12, 0x04, 0xA0, 0xE3, 0xBC, 0x00, 0x81, 0xE5, 0x5C, 0x08, 0x9F, 0xE5, 0xC0
80 char buf2[NK_SIZE];
81 char buf[READ_SIZE];
83 void usage(void)
85 fprintf(stderr, "usage: sudo beastdump <path_to_gigabeat>\ne.g. /dev/sdb \n");
88 /*search through an image looking for header_string*/
89 int main(int argc, char **argv)
91 if (argc < 2)
93 usage();
94 return 1;
98 if((in=fopen(argv[1], "r"))==NULL){
99 printf("file open error. Probably invalid path or lack of root/sudo\n");
100 return -1;
105 while((ret=fread(buf, READ_SIZE, 1, in))){
109 if(!memcmp(header, buf, READ_SIZE)){
110 printf("Found header at offset: 0x%x\n",(int) (ftell(in)-READ_SIZE));
111 break;
113 else
115 // printf("fail\n");
117 //return -1;
119 memset(buf,0,READ_SIZE);
121 if(ftell(in)%(READ_SIZE*1000)==0)
122 printf("checking %d\n",(int)ftell(in));
127 if(!ret) {
128 printf("read error or end of file\n");
129 return -1;
131 fseek(in, -READ_SIZE, SEEK_CUR);
133 out= fopen("nk.bin", "w");
134 bytes_read = fread(buf2, sizeof(buf2), 1, in);
135 bytes_writen= fwrite(buf2, sizeof(buf2),1,out);
136 fclose(in);
137 fclose(out);
138 printf("Successfully created file. Please run md5sum to confirm hash:\nfb76b0025cd6bd2cc7512620ebf30b81 nk_orig.bin\n");
139 return 0;