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

  1. // Immortal Player  V2.0 Copyright (c) 1991 IP Makers
  2.  
  3. // This module inputs data for crack; runtime part is hidden in class IP
  4. // Compile this file in tiny model
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <ctype.h>
  9. #include <string.h>
  10. #include <dir.h>
  11. #include "ip.h"
  12.  
  13. extern getWord( char*, FILE* );
  14. extern void getData( DataIP&, char* );
  15. extern void eatExtension( char* );
  16.  
  17. char CommandLine[ 128 ];
  18. int  Line = 1;
  19. DataIP Data;
  20.  
  21. main( int nargs, char* arg[] )
  22. {
  23.   printf( "The Immortal Player  Version 2.0 Copyright (c) 1991 IP Makers\n" );
  24.  
  25.   if( nargs < 2 ) {                            //  Argument is the name
  26.     printf( "Game is not specified\n" );    //  of game;
  27.     exit(0);                                //  two files with the same
  28.   }                                             //  name and extension
  29.   strcpy( CommandLine, arg[1] );                //  ip & ( bat | com | exe )
  30.                         //  must exist in a directory
  31.   eatExtension( CommandLine );
  32.   strcat( CommandLine, ".ip" );
  33.   getData( Data, CommandLine );             //  Get data from .ip file
  34.  
  35.   struct ffblk ffblk;                           //  Check if .bat,
  36.   eatExtension( CommandLine );                  //  .com or .exe
  37.   strcat( CommandLine, ".bat" );                //  file exists in a
  38.   if( findfirst( CommandLine, &ffblk, 0 )){     //  directory
  39.       eatExtension( CommandLine );
  40.       strcat( CommandLine, ".com" );
  41.       if( findfirst( CommandLine, &ffblk, 0 )){
  42.       eatExtension( CommandLine );
  43.       strcat( CommandLine, ".exe" );
  44.       if( findfirst( CommandLine, &ffblk, 0 )){
  45.           eatExtension( CommandLine );
  46.           printf( "%s: can't find executable file\n", CommandLine );
  47.           exit(1);
  48.           }
  49.       }
  50.       }
  51.   int i = 2;
  52.   while( strcmp( arg[i],"")){                 //  Form command line
  53.       strcat( CommandLine, " " );             //  for function "sytsem"
  54.       strcat( CommandLine, arg[i++] );
  55.       }
  56.  
  57.   IP Game( CommandLine, &Data );            //  Create object of class IP
  58. }
  59.  
  60. //  getData: opens file and gets data in convinient format
  61. //           exits on a first wrong number
  62.  
  63. void getData( DataIP& data, char* FileName )
  64. {
  65.   char  buffer[ 256 ];
  66.   char* endptr;
  67.   FILE* in = fopen( FileName, "r" );
  68.  
  69.   if( !in ) {
  70.     printf( "Can't open file %s\n", FileName );
  71.     exit(1);
  72.     }
  73.   do {
  74.     if( !getWord( buffer, in )) {
  75.          printf( "Error in file %s: delay is not specified\n", FileName );
  76.          exit(1);
  77.          }
  78.   } while( !( data.delay = strtoul( buffer, &endptr, 16 )));
  79.  
  80.   int i = 0;
  81.   while( 2*2 == 4 )
  82.   {
  83.     do {
  84.     if( !getWord( buffer, in ))
  85.          if( !i ) {
  86.           printf( "Error in file %s: offset is not specified\n", FileName );
  87.           exit(1);
  88.           }
  89.         else
  90.           return;
  91.     } while( !( data.change[i].offset = strtoul( buffer, &endptr, 16 )));
  92.     if( data.change[i].offset < 256 ){
  93.     printf( "Error in file %s, Line %d: offset must exceed 0FF\n", FileName, Line );
  94.     exit(1);
  95.     }
  96.     unsigned long tmp;
  97.     do {
  98.     if( !getWord( buffer, in )) {
  99.          printf( "Error in file %s, Line %d: value is not specified\n", FileName, Line );
  100.          exit(1);
  101.          }
  102.     } while( !( tmp = strtoul( buffer, &endptr, 16 )));
  103.     if( tmp > 255 ){
  104.     printf( "Error in file %s, Line %d: value must not exceed 0FF\n", FileName, Line );
  105.     exit(1);
  106.     }
  107.     data.change[i].value = tmp;
  108.     i++;
  109.   }
  110. }
  111.  
  112. //  getWord: takes one word from stream and returns its length,
  113. //           returns 0 if the end of file has been reached;
  114. //         word :: digit { digit | char }
  115.  
  116. getWord( char *s, FILE* in )
  117. {
  118.   static char ch = ' ';
  119.   int n = 0;
  120.  
  121.   if( ch == '\n' )
  122.       Line--;
  123.   while( !isdigit( ch )){
  124.       if( feof( in ))
  125.           return 0;
  126.       if( ch == '\n' )
  127.           Line++;
  128.       ch = fgetc( in );
  129.     }
  130.   do {
  131.     *s++ = ch;
  132.     n++;
  133.     ch = fgetc( in );
  134.     if( ch == '\n' )
  135.         Line++;
  136.     if( feof( in )){
  137.         *s = 0;
  138.         return n;
  139.         }
  140.   } while( isalnum( ch ));
  141.   *s = 0;
  142.   return n;
  143. }
  144.  
  145. //  eatExtension: silently eats extension of dos file
  146.  
  147. void eatExtension( char* s ){ while( *s != '.' && *s++ != 0 ); *s = 0; }