View Single Post
Old 02-11-2009, 05:52   #9 (permalink)
elseWestcott
Freak Poster
 
Join Date: Jan 2009
Posts: 170
Member: 956117
Status: Offline
Thanks Meter: 66
I have made some changes, but only to cause some of the files that contain only text to be named .txt instead of .bin.

Which VSM files are you having trouble with?

I'll bet they are the ones that don't have any PNG files in them. Some of the VSM files have images in them others don't and some don't even have ANY resource section at all, just the header.

You can look at the VSM files in question and search for the text "PNG"

Here is the latest code:
Code:
#include <stdio.h>

int
main (int argc, char *argv[])
{
  FILE *fpi, *fpo;
  unsigned short int *buff, *resType;
  buff = (short int *) malloc (0xffff);
  resType = (short int *) malloc (2);
  unsigned int *vendorID, *brandingVersion;
  vendorID = (int *) malloc (4);
  brandingVersion = (int *) malloc (4);
  unsigned short int *filename;
  filename = (char *) malloc (0xff);
  unsigned short int resLen;
  unsigned char len[] = "FFFF";
  unsigned short int a, b;
  char fullpath[100];
  int done;
  unsigned int *footerCheck;
  footerCheck = (int *) malloc (4);
  int fileLen, currentPos;

  if (argc != 2)
    {
      fprintf (stderr, "Error: wrong number of arguments.\n");
      fprintf (stderr, "Usage: %s <in-file>\n", argv[0]);
      return (1);
    }
  if ((fpi = fopen (argv[1], "rb")) == NULL)
    {
      printf ("Cannot open input file.\n");
      exit (1);
    }
  fseek (fpi, 0, 2); //go to end of file
  fileLen = ftell(fpi); //get position
  fseek (fpi, 0xc, 0);
  fread (vendorID, 4, 1, fpi);
  fread (brandingVersion, 4, 1, fpi);
  sprintf (filename, "BV=%x     VID=%d", *brandingVersion, *vendorID);
  strcpy (fullpath, "output\\");
  strcat (fullpath, argv[1]);
  strcat (fullpath, "\\");
  strcat (fullpath, filename);

  if ((fpo = fopen (fullpath, "wb")) == NULL)
    {
      printf ("Cannot create output file %s.\n", fullpath);
      exit (1);
    }
  fseek (fpi, 0x1c, 0);
  while (fpi != EOF && done != 1)
    {
      fread (resType, 2, 1, fpi);
      currentPos = ftell(fpi);
      if ((*resType != 0x2d1f) && (currentPos < fileLen))
    {
      switch (*resType)
        {
        case 0:
          fread (footerCheck, 4, 1, fpi);
          if (*footerCheck == 0xd7c82d1f)
        {
          sprintf (filename, "BVHasPad");
          done = 1;
        }
          else
        {
          sprintf (filename, "0x%x.png", *resType);
          fseek (fpi, ftell (fpi) - 4, 0);
        }
          break;
        case 2:
          sprintf (filename, "%#x.png", *resType);
          break;
        case 0x1000:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x1001:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x1002:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x1003:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x1004:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x1005:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x1100:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x1101:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x1102:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x1200:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x1201:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x1202:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x2000:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x3000:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x3003:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x3004:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x3005:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x3006:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x3100:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x3103:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x3104:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x3105:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x3106:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x3500:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x3501:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x3502:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x3600:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x3601:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x3602:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x4000:
          sprintf (filename, "%#x.png", *resType);
          break;
        case 0x4002:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x4003:
          sprintf (filename, "%#x.asc", *resType);
          break;
        case 0x4004:
          sprintf (filename, "%#x.mid", *resType);
          break;
        case 0x4005:
          sprintf (filename, "%#x.png", *resType);
          break;
        case 0x4006:
          sprintf (filename, "%#x.mp3", *resType);
          break;
        case 0x4007:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x4100:
          sprintf (filename, "%#x.png", *resType);
          break;
        case 0x4101:
          sprintf (filename, "%#x.png", *resType);
          break;
        case 0x4102:
          sprintf (filename, "%#x.png", *resType);
          break;
        case 0x4103:
          sprintf (filename, "%#x.png", *resType);
          break;
        case 0x4104:
          sprintf (filename, "%#x.png", *resType);
          break;
        case 0x4105:
          sprintf (filename, "%#x.png", *resType);
          break;
        case 0x4106:
          sprintf (filename, "%#x.png", *resType);
          break;
        case 0x4107:
          sprintf (filename, "%#x.png", *resType);
          break;
        case 0x4108:
          sprintf (filename, "%#x.png", *resType);
          break;
        case 0x4109:
          sprintf (filename, "%#x.png", *resType);
          break;
        case 0x4200:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x4300:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x5200:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x5201:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x5202:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x5203:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x7000:
          sprintf (filename, "%#x.xml", *resType);
          break;
        case 0x7010:
          sprintf (filename, "%#x.txt", *resType);
          break;
        case 0x7011:
          sprintf (filename, "%#x.txt", *resType);
          break;
        default:
          sprintf (filename, "%#x.bin", *resType);
          break;
        }

      strcpy (fullpath, "output\\");
      strcat (fullpath, argv[1]);
      strcat (fullpath, "\\");
      strcat (fullpath, filename);
      fread (&resLen, 2, 1, fpi);

      if ((fpo = fopen (fullpath, "wb")) == NULL)
        {
          printf ("Cannot create output file %s.\n", fullpath);
          exit (1);
        }
      for (a = 0; a < resLen; a++)
        {
          fread (buff, 1, 1, fpi);
          fwrite (buff, 1, 1, fpo);
        }
      fclose (fpo);

      if (resLen % 2)
        {
          fseek (fpi, 1, 1);
        }
    }
      else
    {
      break;
    }
    }

  fclose (fpi);
}
  Reply With Quote
The Following User Says Thank You to elseWestcott For This Useful Post:
 
Page generated in 0.10706 seconds with 7 queries