image28

Binary Patch Filesizer

Jun 25th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.     FILE *input;
  6.     FILE *temp;
  7.     FILE *output;
  8.     long fs=0;
  9.     char inbyte='\0';
  10.     long count=0;
  11.     char name[512];
  12.     char outstring[512];
  13.     int add=0;
  14.     long insize=0;
  15.     long sizecount=0;
  16.     int d=0;
  17.  
  18.     if ( ( input=fopen(argv[1],"rb") ) == NULL )
  19.     {
  20.         printf("Input file not found\n");
  21.         exit(-1);
  22.     }
  23.  
  24.     fseek(input,0L,SEEK_END);
  25.     insize=ftell(input);
  26.     fseek(input,0L,SEEK_SET);
  27.  
  28.     output=fopen("../tempout2","wb");
  29.  
  30.     while ( sizecount < insize )
  31.     {
  32.         inbyte='\0';
  33.         fread(&inbyte,1,1,input);
  34.         sizecount++;
  35.         count=0;
  36.        
  37.         if ( inbyte == 'A' )
  38.         {
  39.             add=1;
  40.         }else{
  41.             add=0;
  42.         }
  43.  
  44.         while ( inbyte != 32 )
  45.         {
  46.             inbyte='\0';
  47.             fread(&inbyte,1,1,input);
  48.             sizecount++;
  49.         }
  50.  
  51.         while ( ( inbyte != '\n' ) && ( ! feof(input) ) )
  52.         {
  53.             inbyte='\0';
  54.             fread(&inbyte,1,1,input);
  55.             sizecount++;
  56.             name[count]=inbyte;
  57.             count++;
  58.         }name[count-1]='\0';
  59.  
  60.         if ( ( temp=fopen(name,"rb") ) == NULL ){
  61.             printf("Target file not found\n");
  62.             exit(-2);
  63.         }
  64.         fseek(temp,0l,SEEK_END);
  65.         fs=ftell(temp);
  66.         fclose(temp);
  67.        
  68.         for(d=0;d<512;d++)
  69.             outstring[d]='\0';
  70.  
  71.         if ( add )
  72.         {
  73.             printf("Writing Line \"Add %d %s\"\n",fs,name);
  74.             sprintf(outstring,"Add %d %s\n\0",fs,name);
  75.         }else{
  76.             printf("Writing Line \"Update %d %s\"\n",fs,name);
  77.             sprintf(outstring, "Update %d %s\n\0",fs,name);
  78.         }
  79.  
  80.         fwrite(&outstring,strlen(outstring),1,output);
  81.        
  82.     }  
  83.        
  84.     fclose(input);
  85.     fclose(output);
  86. }
Add Comment
Please, Sign In to add comment