Anri-chan/Source/fourccc.cpp

From SDA Knowledge Base

< Anri-chan‎ | Source
Revision as of 21:47, 17 August 2007 by Ballofsnow (Talk | contribs)

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

  Reads parameters and compares with fourcc. Returns 0 for false, 1 for true.

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

  vids offset 0x6C, 108 decimal, 4 bytes long.
  fourcc offset 0x70, 112 decimal, 4 bytes long.

*/

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

void usage(char *argv0);
unsigned char checkvids[4]= { 0x76, 0x69, 0x64, 0x73 }; /* vids - fourcc follows */
unsigned char buffer[1024*1024];

int main (int argc, char **argv) {
  FILE *vid;
  char *vidname=NULL;
  char *fourcc=NULL;
  int rval;
  printf ("fourcc compare v0.1, ballofsnow\n");
  
  if (argc!=3) {
    usage(argv[0]);
    return -1;
  }

  /* VERIFY FOURCC EXISTS  */
  vidname=argv[1];
  if ((vid=fopen(vidname,"rb"))==NULL) {
    printf ("[-] Failed to open file \"%s\".\n", vidname);
    return -1;
  } 
  fread(buffer,1,200,vid);
  if (memcmp(checkvids,buffer+108,4) != 0) {
     printf ("This isn't a valid file.\n");
     free(buffer);
     fclose(vid);
     usage(argv[0]);
     return -1;
  }
  /* FINISHED VALIDATING */
  
  /* COMPARE FOURCC WITH PARAMETER */
  fourcc=argv[2];
  if (memcmp(fourcc,buffer+112,4) == 0) {
    printf("%s %s\n", fourcc, "fourcc found");
    rval=1;
  }
  else {
    rval=0;
  }
  /* FINISHED COMPARE */

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

void usage(char *argv0) {
  printf ("Usage: %s <AVI file> <FOURCC>\n\n", argv0);
  printf ("Returns 0 (false) or 1 (true) to %%ERRORLEVEL%%.\n");
}
Personal tools