Skip to content

Instantly share code, notes, and snippets.

@akimasa
Created March 19, 2020 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akimasa/5b6048f8558add253080de47e4c2362d to your computer and use it in GitHub Desktop.
Save akimasa/5b6048f8558add253080de47e4c2362d to your computer and use it in GitHub Desktop.
get digest of aac stream
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/md5.h>
// find /mnt/c/Users/Akimasa/Documents/radikocompare/ -name "*.aac" -print0 | xargs -0 -P1 -I {} ./a.out {}
// gcc main.c -lcrypto
void main(int argc, char *argv[])
{
MD5_CTX c;
char *data = "hoge";
unsigned char md[MD5_DIGEST_LENGTH];
char mdString[33];
int r, i;
FILE *fp;
// /mnt/c/Users/Akimasa/Documents/aacparse/QRR-20190715003000-小倉唯のyui*room.aac
if ((fp = fopen(argv[1], "r")) == NULL) {
perror("fopen err");
exit(1);
}
if (fseek(fp, 0, SEEK_END) != 0) {
perror("fopen err");
exit(1);
}
fpos_t pos;
if (fgetpos (fp, &pos) != 0) {
perror("fopen err");
exit(1);
}
long filesize = (long)(pos.__pos);
fseek(fp, 0, SEEK_SET);
r = MD5_Init(&c);
if(r != 1) {
perror("init");
exit(1);
}
int blk=0;
for(long i=0; i<filesize; i++){
uint8_t cont[8];
fseek(fp, i, SEEK_SET);
fread(cont, sizeof(uint8_t), 8, fp);
uint16_t sync = cont[0] <<8 | cont[1];
sync = (0xfff9 & sync) == 0xfff9;
if(sync){
int crc = cont[0] & 1;
long len = cont[3] << 16 | cont[4] << 8 | cont[5];
len = (len >> 5) & 0x1ff;
if(len == 0){
printf("len=0\n");
continue;
}
uint8_t pkt[1024] = {0};
if(len > 1024){
perror("lent too long!\n");
exit(1);
}
fseek(fp, i, SEEK_SET);
int sizeread = fread(pkt, sizeof(uint8_t), len, fp);
// if(sizeread != len){
// printf("cannnot read len: %d, %d\n", sizeread, len);
// exit(1);
// }
if(0 && ++blk > 24257 && blk < 24260){
for(int j = 0; j < len-1; j++)
printf("%02x", (unsigned int)pkt[j]);
printf("\n");
}
r = MD5_Update(&c, pkt, len);
if (r != 1)
{
perror("update");
exit(1);
}
// printf("len:%d\n", len);
i += len-1;
}
}
r = MD5_Final(md, &c);
if(r != 1) {
perror("final");
exit(1);
}
for(i = 0; i < 16; i++)
sprintf(&mdString[i * 2], "%02x", (unsigned int)md[i]);
printf("%s: %s\n", argv[1], mdString);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment