[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <sys/stat.h> 5 #include "lzx.h" 6 #include "wim.h" 7 8 9 BYTE *InitHash(DWORD myint) 10 { 11 unsigned char *mystr=(unsigned char *) &myint; 12 BYTE *result=(BYTE *)malloc(sizeof(BYTE)*20); 13 int i=0; 14 int j=0; 15 for(j=0;j<5;j++) 16 { 17 for(i=0;i<4;i++) 18 { 19 result[i+j*4]=mystr[i]; 20 } 21 } 22 return result; 23 } 24 25 int main(int argc, char **argv) 26 { 27 FILE *fp; 28 size_t result; 29 30 if (argc != 4) 31 { 32 printf("ERROR: found %d arguments\n",argc); 33 printf("Usage: updatewim <inputwimfile> <outputwimname> <actionfile>\n"); 34 exit(0); 35 } 36 37 FILE *actionfile; 38 actionfile=fopen(argv[3],"rb"); 39 if (actionfile == NULL) 40 { 41 printf("ERROR: Can not open action file %s\n",argv[3]); 42 exit(4); 43 } 44 CHAR *action, *arg1, *arg2; 45 46 // Open input file for reading 47 fp = fopen(argv[1],"rb"); 48 if (fp == NULL) 49 { 50 printf("Error opening input file %s\n",argv[1]); 51 exit(3); 52 } 53 54 LARGE_INTEGER numoffsets=0; 55 WIM_HEADER Header; 56 ReadWimHeader(fp,&Header); 57 FILE_RESOURCE_HEADER *frh=ReadLookupTable(fp,Header.OffsetTable.Offset,Header.OffsetTable.Size,&numoffsets); 58 BYTE *xml=ReadXML(fp,Header.XmlData.Offset,Header.XmlData.Size); 59 BOOT_META_DATA bmd = ReadBootMetaDataTable(fp,Header.BootMetaData); 60 61 // PrintBootMetaData(bmd); 62 63 fseek(actionfile,0,SEEK_SET); 64 DWORD addindex=0; 65 while(fscanf(actionfile,"%as %as %as\r\n",&action,&arg1,&arg2) == 3) 66 { 67 if(!strcmp(action,"rename")) 68 { 69 printf("Renaming file %s to %s\n",arg1,arg2); 70 RenameFile2(bmd.DirEntry,arg1,arg2); 71 } 72 if(!strcmp(action,"add")) 73 { 74 printf("Adding file %s to %s\n",arg1,arg2); 75 BYTE *newhash=InitHash(addindex+1); 76 DIRENTRY *thenewfile=CreateFile(arg1,arg2,newhash); 77 AddFile2(bmd.DirEntry,thenewfile,arg2); 78 addindex++; 79 } 80 if(!strcmp(action,"mkdir")) 81 { 82 printf("Adding dir %s to %s\n",arg1,arg2); 83 BYTE *newhash=InitHash(0); 84 DIRENTRY *thenewdir=CreateDirectory(arg1,arg2,newhash); 85 AddDir(bmd.DirEntry,thenewdir,arg2); 86 } 87 } 88 89 // PrintBootMetaData(bmd); 90 91 FILE_RESOURCE_HEADER **newfrhs=malloc(sizeof(FILE_RESOURCE_HEADER *) * addindex + 1); 92 93 printf("Opening output file\n"); 94 // Open output file for writing 95 FILE *newwim=fopen(argv[2],"wb+"); 96 if (newwim == NULL) 97 { 98 printf("ERROR, Could not open output file %s\n",argv[2]); 99 exit(1); 100 } 101 WriteWimHeader(newwim,&Header); 102 103 printf("Copying resources\n"); 104 CopyFileResources(fp,newwim,frh,numoffsets); 105 106 fseek(actionfile,0,SEEK_SET); 107 addindex=0; 108 while(fscanf(actionfile,"%as %as %as\r\n",&action,&arg1,&arg2) == 3) 109 { 110 if(!strcmp(action,"add")) 111 { 112 printf("Adding file resource for %s\n",arg1); 113 newfrhs[addindex]=AddFileResource(arg1,newwim); 114 memcpy(newfrhs[addindex]->Hash,InitHash(addindex+1),20); 115 addindex++; 116 } 117 } 118 119 printf("Writing metadata\n"); 120 Header.BootMetaData=WriteBootMetaData(newwim,bmd); 121 printf("Writing lookup table\n"); 122 Header.OffsetTable=WriteLookupTable(newwim,frh,numoffsets); 123 124 printf("Writing additional lookup table\n"); 125 fseek(actionfile,0,SEEK_SET); 126 addindex=0; 127 while(fscanf(actionfile,"%as %as %as\r\n",&action,&arg1,&arg2) == 3) 128 { 129 if(!strcmp(action,"add")) 130 { 131 printf("Writing lookup table entry for %s\n",arg1); 132 WriteLookupTable(newwim,newfrhs[addindex],1); 133 Header.OffsetTable.Size+=50; 134 Header.OffsetTable.OriginalSize+=50; 135 addindex++; 136 } 137 } 138 139 printf("Writing XML\n"); 140 Header.XmlData=WriteXML(newwim,xml,Header.XmlData.Size); 141 Header.Integrity=WriteIntegrity(newwim); 142 printf("Writing new header\n"); 143 WriteWimHeader(newwim,&Header); 144 if( fclose( fp )) 145 printf("Input File close error.\n"); 146 if( fclose( newwim )) 147 printf("Output File close error.\n"); 148 if( fclose( actionfile )) 149 printf("Action File close error.\n"); 150 151 exit(0); 152 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |