/*
    Linux Module Ripper v0.1 [BETA]
    by Belgorath <belgo@share.net>
*/

#include <stdio.h>

#define TITLE_OFFSET 0
#define INST1LEN_OFFSET 42  /* actually (snum*22)+20 should yield it */
#define MK_OFFSET 1080

char *sigs[] = { "M.K.\0", "FLT8\0", "FLT4\0", "6CHN\0", "8CHN\0" };
char *type[] = { "ProTracker\0", "StarTrekker-8\0", "StarTrekker-4\0",
                  "6-Channel\0", "8-Channel\0" };

int main(int argc, char *argv[])
{
  char inchar;
  char title[22];
  char match[5];
  FILE *fp;
  int	xx, foo, apos, bpos;
  long int pos;

  if(argc!=2) {
    printf("Usage: lrip <infile>\r\n");
    exit(-1);
  }
  if((fp=fopen(argv[1],"r"))==NULL) {
    printf("Unable to open input.\r\n");
    exit(-1);
  }
  apos=1212;
  bpos=0;
  while(apos!=bpos) {
    foo=0;
    match[0]=fgetc(fp);
    match[1]=fgetc(fp);
    match[2]=fgetc(fp);
    match[3]=fgetc(fp);
    match[4]=0; 
    for(xx=0;xx<5;xx++) {
      if(strcmp(match,sigs[xx])==0) {
        foo=1;
        pos=ftell(fp);
        fseek(fp,-1084,SEEK_CUR);
        fgets(title,22,fp);
        printf("Found %s [%s] at position %d\r\n",type[xx],title,pos-1084);
        fseek(fp,pos+1,SEEK_SET);
      }
    }
    if(foo==0) fseek(fp,-3,SEEK_CUR);
    apos=bpos;
    bpos=ftell(fp);
  }
  fclose(fp);
}
