home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / hackers / tools / ip.arj / COMPARE4.C next >
Encoding:
C/C++ Source or Header  |  1991-11-21  |  2.2 KB  |  100 lines

  1. /*
  2.    This routine compares dumps to detect bytes
  3.    that satisfy given condition.
  4. */
  5.  
  6. #include <io.h>
  7. #include <fcntl.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <dos.h>
  11.  
  12. #define TRUE  1
  13. #define FALSE 0
  14. #define SIZE_BUF 0x2000
  15.  
  16. unsigned char buff0[SIZE_BUF];
  17. unsigned char buff1[SIZE_BUF];
  18. unsigned char buff2[SIZE_BUF];
  19. unsigned char buff3[SIZE_BUF];
  20.  
  21. main( int nargs, char *fname[] )
  22. {
  23.   int   handle0,
  24.     handle1,
  25.     handle2,
  26.     handle3,
  27.     done = FALSE,
  28.     n0, n1, n2, n3, i;
  29.   long     p = 0;
  30.   char  *file0, *file1, *file2, *file3, *fileres;
  31.   FILE* res;
  32.  
  33.   if( nargs < 6 ){
  34.     printf("\nUsage: compare4 file1 file2 file3 file4 fileres\n");
  35.     exit(0);
  36.     }
  37.   file0   = fname[1];
  38.   file1   = fname[2];
  39.   file2   = fname[3];
  40.   file3   = fname[4];
  41.   fileres = fname[5];
  42.  
  43.   handle0 = open( file0, O_BINARY | O_RDONLY );
  44.   if( handle0 == -1 ){
  45.     printf("\nCan't open file %s", file0 );
  46.     exit(0);
  47.     }
  48.  
  49.   handle1 = open( file1, O_BINARY | O_RDONLY );
  50.   if( handle1 == -1 ){
  51.     printf("\nCan't open file %s", file1 );
  52.     exit(0);
  53.     }
  54.  
  55.   handle2 = open( file2, O_BINARY | O_RDONLY );
  56.   if( handle2 == -1 ){
  57.     printf("\nCan't open file %s", file2 );
  58.     exit(0);
  59.     }
  60.  
  61.   handle3 = open( file3, O_BINARY | O_RDONLY );
  62.   if( handle3 == -1 ){
  63.     printf("\nCan't open file %s", file3 );
  64.     exit(0);
  65.     }
  66.  
  67.   if(( res = fopen( fileres, "w" )) == NULL){
  68.     printf("\nCan't open file %s", fileres );
  69.     exit(0);
  70.     }
  71.  
  72.   done = FALSE;
  73.   while( !done ){
  74.     if(( n0 = read( handle0, buff0, SIZE_BUF )) != SIZE_BUF )
  75.         done = TRUE;
  76.     if(( n1 = read( handle1, buff1, SIZE_BUF )) != SIZE_BUF )
  77.         done = TRUE;
  78.     if(( n2 = read( handle2, buff2, SIZE_BUF )) != SIZE_BUF )
  79.         done = TRUE;
  80.     if(( n3 = read( handle3, buff3, SIZE_BUF )) != SIZE_BUF )
  81.         done = TRUE;
  82.     i = 0;
  83.     while( i < n0 && i < n1 && i < n2 && i < n3 ){
  84.  
  85.         if( buff0[i] - buff1[i] != 0 )   /* Change this condition */
  86.         if( buff1[i] - buff2[i] != 0 )   /* for every concrete    */
  87.         if( buff2[i] - buff3[i] != 0 )   /* situation             */
  88.  
  89.         fprintf( res, "%08lX\t%X\t%X\t%X\t%X\n", p, buff0[i], buff1[i], buff2[i], buff3[i] );
  90.  
  91.         i++;
  92.         p++;
  93.         }
  94.   }
  95.   close( handle0 );
  96.   close( handle1 );
  97.   close( handle2 );
  98.   close( handle3 );
  99.   fclose( res );
  100. }