binary_mp3_strip/stripMP3.c

75 lines
1.6 KiB
C

#include<stdio.h>
#include<stdlib.h>
unsigned long ltob(unsigned long n){
unsigned long m = n ? ltob(n /2) : 0;
printf("%d", (int)(n % 2));
return m;
}
int main(int argc, char** argv){
FILE *f_point;
unsigned char record;
unsigned int mp3header = 4294677700;
unsigned int mp3test = 0;
f_point=fopen(argv[1],"rb");
if(!f_point){
printf("Unable to open file!");
return 1;
}
fseek(f_point,0,SEEK_END);
long size = ftell(f_point);
rewind(f_point);
printf("Size of file %ldb\n", size);
unsigned char *b = malloc(size+1);
if(1 !=fread(b,size, 1, f_point)){
fclose(f_point);
free(b);
printf("Error reading file\n");
return 1;
}
long i = 0;
long last = 0;
int x = 0;
while(i < (size - 5)){
if(b[0+i]==0xFF && b[1+i]==0xFB && b[3+i]==0xC4){
last = i;
printf("\t\tMP3 Header (%ld) with bitrate %X\n",i, b[2+i]);
}
if(b[0+i]==0x4C && b[1+i]==0x41 && b[2+i]==0x4d && b[3+i]==0x45){
//b[4+i]==0x33 && b[5+i]==0x2E && b[6+i]==0x39 && b[7+i]==0x38
printf("LAME located at %ld distance (%ld)\n", i, i - last);
if(i >= 141){
if(b[i-141]==0xFF && b[i-140]==0xFB && b[i-138]==0xC4){
printf("\tHigh Possiblity of the start of an mp3 is here %ld | %X%X%X%X\n", i-141, b[i-141],b[i-140],b[i-139],b[i-138]);
x=1;
}
}
if(i >= 35){
if(b[i-35]==0xFF && b[i-34]==0xFB && b[i-32]==0xC4){
printf("\tHigh Possiblity of the start of an mp3 is here %ld | %X%X%X%X\n", i-35, b[i-35],b[i-34],b[i-33],b[i-32]);
x=1;
}
}
if(!x){
printf("\tMaybe the end of an mp3?\n");
}
x=0;
}
i++;
}
free(b);
fclose(f_point);
return 0;
}