[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/wimlib/wimlib-0.2/ -> wimxmlinfo.c (source)

   1  #define _LARGEFILE_SOURCE
   2  #define _FILE_OFFSET_BITS 64
   3  
   4  #include <stdio.h>
   5  #include <stdlib.h>
   6  #include <string.h>
   7  #include <sys/stat.h>
   8  
   9  typedef long long LARGE_INTEGER;
  10  typedef char BYTE ;
  11  
  12  
  13  LARGE_INTEGER GetLargeInteger(FILE *fp)
  14  {
  15        register LARGE_INTEGER li;
  16        li = (LARGE_INTEGER) (fgetc(fp) & 0xFF);
  17        li |= ((LARGE_INTEGER) (fgetc(fp) & 0xFF) << 0x08) ;
  18        li |= ((LARGE_INTEGER) (fgetc(fp) & 0xFF) << 0x10) ;
  19        li |= ((LARGE_INTEGER) (fgetc(fp) & 0xFF) << 0x18) ;
  20        li |= ((LARGE_INTEGER) (fgetc(fp) & 0xFF) << 0x20) ;
  21        li |= ((LARGE_INTEGER) (fgetc(fp) & 0xFF) << 0x28) ;
  22        li |= ((LARGE_INTEGER) (fgetc(fp) & 0xFF) << 0x30) ;
  23        li |= ((LARGE_INTEGER) (fgetc(fp) & 0xFF) << 0x38) ;
  24        return(li);
  25  }
  26  
  27  LARGE_INTEGER GetLargeInteger7(FILE *fp)
  28  {
  29        register LARGE_INTEGER li;
  30        li = (LARGE_INTEGER) (fgetc(fp) & 0xFF);
  31        li |= ((LARGE_INTEGER) (fgetc(fp) & 0xFF) << 0x08) ;
  32        li |= ((LARGE_INTEGER) (fgetc(fp) & 0xFF) << 0x10) ;
  33        li |= ((LARGE_INTEGER) (fgetc(fp) & 0xFF) << 0x18) ;
  34        li |= ((LARGE_INTEGER) (fgetc(fp) & 0xFF) << 0x20) ;
  35        li |= ((LARGE_INTEGER) (fgetc(fp) & 0xFF) << 0x28) ;
  36        li |= ((LARGE_INTEGER) (fgetc(fp) & 0xFF) << 0x30) ;
  37        // li |= ((LARGE_INTEGER) (fgetc(fp) & 0xFF) << 0x38) ;
  38        return(li);
  39  }
  40  
  41  // Thanks to the chntpw project
  42  // see: http://pogostick.net/~pnh/ntpasswd/
  43  static char *w2a(void *string, int len)
  44  {
  45     int i, k;
  46      char *cstring;
  47  
  48      int out_len = 0;
  49      for(i = 0; i < len; i += 2)
  50      {
  51          // unsigned v = ((unsigned char *)string)[i] + ((unsigned char *)string)[i+1] * 256u;
  52          unsigned v = ((unsigned char *)string)[i] + ((unsigned char *)string)[i+1] * 512u;
  53          if (v < 256)
  54              out_len += 1;
  55          else if(v < 0x800)
  56              out_len += 2;
  57          else
  58              out_len += 3;
  59      }
  60      cstring = (char *) malloc(out_len+1);
  61      if (!cstring) {
  62          printf("FATAL! ex_next: malloc() failed! Out of memory?\n");
  63          abort();
  64      }
  65  
  66      for(i = 0, k = 0; i < len; i += 2)
  67      {
  68          unsigned v = ((unsigned char *)string)[i] + ((unsigned char *)string)[i+1] * 512u;
  69          if (v < 256)
  70              cstring[k++] = v;
  71          else if(v < 0x800) {
  72              cstring[k++] = 0xc0 | (v >> 6);
  73              cstring[k++] = 0x80 | (v & 0x3f);
  74          } else {
  75              cstring[k++] = 0xe0 | (v >> 12);
  76              cstring[k++] = 0x80 | ((v >> 6) & 0x3f);
  77              cstring[k++] = 0x80 | (v & 0x3f);
  78          }
  79      }
  80      cstring[out_len] = '\0';
  81      return cstring;
  82  }
  83  
  84  int ReadXMLInfo(FILE *fp)
  85  {
  86  
  87    LARGE_INTEGER pos=72;
  88    fsetpos(fp,(fpos_t *)&pos);
  89    LARGE_INTEGER mysize=GetLargeInteger7(fp);
  90    pos=80;
  91    fsetpos(fp,(fpos_t *)&pos);
  92    LARGE_INTEGER lioffset=GetLargeInteger(fp);
  93    fsetpos(fp,(fpos_t *)&lioffset);
  94    BYTE *buf=malloc(sizeof(BYTE) * mysize);
  95    LARGE_INTEGER ilen=fread(buf,mysize,sizeof(BYTE),fp);
  96    BYTE *xmlnoheader=(BYTE *)malloc(sizeof(BYTE) * (mysize -2));
  97    memcpy(xmlnoheader,&(buf[2]),mysize-2);
  98    char *xmlstring=strdup(w2a(xmlnoheader,mysize-2));
  99    printf("%s",xmlstring);
 100    return 0;
 101  }
 102  
 103  
 104  int main(int argc, char **argv)
 105  {
 106    FILE *fp;
 107  
 108    if (argc != 2)
 109    {
 110      printf("Usage: wimxmlinfo <inputwimfile>\n");
 111      exit(0);
 112    }
 113  
 114    // Open input file for reading
 115    fp = fopen(argv[1],"r");
 116    if (fp == NULL)
 117    {
 118      printf("Error opening file\n");
 119      exit(3);
 120    }
 121    ReadXMLInfo(fp);
 122    if( fclose( fp ))
 123        printf("Input File close error.\n");
 124  
 125    exit(0);
 126  }


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1