Anri-chan/Source/aud.cpp

From SDA Knowledge Base

< Anri-chan‎ | Source
Revision as of 22:41, 31 July 2007 by Ballofsnow (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
/*

  Returns the audio type.

  author: ballofsnow
  date: 31 July 2007
  license: none (public domain)
  target: win32 (MINGW), recommend using the free IDE from bloodshed.net
  version: beta 0.2

  AC3       00000000 = 0x00
  Unknown1  00100000 = 0x20
  Mpeg-1    01000000 = 0x40
  Mpeg-2ext 01100000 = 0x60
  LPCM      10000000 = 0x80
  Unknown2  10100000 = 0xA0
  DTS       11000000 = 0xC0
  SDDS      11100000 = 0xE0

  Find the byte at offset 0x204 or decimal 516 of an IFO file.

*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <bitset>
using namespace std;

void usage(char *argv0);
unsigned char checkifo[12]= { 0x44, 0x56, 0x44, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x2D, 0x56, 0x54, 0x53 }; /* DVDVIDEO-VTS */
unsigned char buffer[1024*1024];

int main (int argc, char **argv) {
  FILE *ifo;
  char *ifoname=NULL;
  int rval;
  printf ("Audio type analyzer\n");
  printf ("beta 0.2, ballofsnow\n");
  printf ("This software comes with no warranty.\n");
  printf ("For help, run program with no parameters\n\n");  
  
  if (argc!=2) {
    usage(argv[0]);
    return 0;
  }

  /* LOAD AND VALIDATE THE IFO */
  ifoname=argv[1];
  if ((ifo=fopen(ifoname,"rb"))==NULL) {
    printf ("[-] Failed to open IFO file \"%s\".\n", ifoname);
    return -1;
  } 
  // Source res is at offset 0x0200, or 512 decimal, 2 bytes.
  // Audio type is at offset 0x0204, or 516 decimal, 1 byte. 
  fread(buffer,1,517,ifo);
  if (memcmp(checkifo,buffer,12) != 0) {
     printf ("This isn't an IFO file.\n");
     free(buffer);
     fclose(ifo);
     usage(argv[0]);
     return -1;
  }
  /* FINISHED VALIDATING */
  
  /* MASK THE BYTE TO GET THE RELEVANT BITS */
  bitset<CHAR_BIT> atype (buffer[516]); 
  atype &= 0xE0;
      
  if (atype == 0x00) {
     printf ("AC3\n");
     rval=1;     
  }
  else if (atype == 0x20) {
     printf ("Unknown1\n");
     rval=2;
  }
  else if (atype == 0x40) {
     printf ("Mpeg-1\n");
     rval=3;
  }
  else if (atype == 0x60) {
     printf ("Mpeg-2ext\n");
     rval=4;
  }
  else if (atype == 0x80) {
     printf ("LPCM\n");
     rval=5;
  }
  else if (atype == 0xA0) {
     printf ("Unknown2\n");
     rval=6;
  }
  else if (atype == 0xC0) {
     printf ("DTS\n");
     rval=7;
  }
  else if (atype == 0xE0) {
     printf ("SDDS\n");
     rval=8;
  }

  free(buffer); // ifo buffer
  fclose(ifo);
  return rval;  
}

void usage(char *argv0) {
  printf ("Usage: %s <VTS IFO file>\n\n", argv0);
  printf ("Returns value to %%ERRORLEVEL%%.\n");
  printf ("  1 - AC3\n");
  printf ("  2 - Unknown1\n");
  printf ("  3 - Mpeg-1\n");
  printf ("  4 - Mpeg-2ext\n");
  printf ("  5 - LPCM\n");
  printf ("  6 - Unknown2\n");
  printf ("  7 - DTS\n");
  printf ("  8 - SDDS\n");
}
Personal tools