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

  1. // TimeCopy  V1.01 Copyright (c) 1991 IP Makers
  2.  
  3. // This program writes four dumps in four files
  4. // every INTERVAL seconds after INITIAL DELAY time has passed
  5. // Compile this file in tiny model
  6.  
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <dos.h>
  11. #include <io.h>
  12. #include <fcntl.h>
  13. #include <sys/stat.h>
  14. #define TRUE  1
  15. #define FALSE 0
  16.  
  17. extern void interrupt Timer(...);
  18.  
  19. long ini_time,
  20.      interval;
  21. void interrupt ( *OldTimer )(...);
  22. char CommandLine[ 256 ];
  23.  
  24. main( int nargs, char *args[] )
  25. {
  26.   printf( "TimeCopy  Version 1.01 Copyright (c) 1991 IP Makers\n" );
  27.   if( nargs < 4 ||
  28.      !( ini_time = 18 * atoi( args[1] )) ||
  29.      !( interval = 18 * atoi( args[2] ))){
  30.     printf( "Usage:  TimeCopy <initial delay(sec)> <interval(sec)>  Command line\n" );
  31.     exit( 0 );
  32.     }
  33.   for( int i = 3; i < nargs; i++ ){
  34.     strcat( CommandLine, args[i] );
  35.     strcat( CommandLine, " " );
  36.     }
  37.   OldTimer = getvect( 8 );     //  After parameters are successfully
  38.   setvect( 8, Timer );          //  transformed we hook timer
  39.   system ( CommandLine );       //  and make system call,
  40.   setvect( 8, OldTimer );       //  then restore timer
  41. }
  42.  
  43. void _write_( unsigned handle, unsigned seg,
  44.     unsigned off, unsigned l )
  45. {
  46.   asm {
  47.     mov  bx, handle        // this is replacement
  48.     mov  dx, off        // for function _write;
  49.     mov  cx, l        // Borland does not want
  50.     mov  ax, seg        // to understand that in
  51.     push ds            // tiny model we need
  52.     mov  ds, ax        // features of huge
  53.     mov  ah, 40h
  54.     int  21h
  55.     pop  ds
  56.   }
  57. }
  58.  
  59. void interrupt Timer(...)
  60. {
  61.   static ini_passed;
  62.   static FileNumber = 0;
  63.   static long ticks = interval;
  64.   static char* FileName[] = { "000", "111", "222", "333" };
  65.  
  66.   OldTimer();
  67.   if( !ini_passed )             //  Wait until initial
  68.     if( !ini_time-- )               //  delay is passed
  69.         ini_passed = TRUE;
  70.       else
  71.         return;
  72.  
  73.   if( !ticks-- && FileNumber < 4 ){                     //  Get dump every
  74.     unsigned PSP = getpsp();                        //  interval ticks
  75.     int handle = open( FileName[ FileNumber++ ],
  76.         O_WRONLY | O_CREAT | O_BINARY, S_IWRITE );
  77.  
  78.     if( handle != -1 ){
  79.         while( PSP < 0xA000 ){
  80.         _write_( handle, PSP, 0, 0xffff );
  81.         _write_( handle, PSP, 0xffff, 1 );
  82.         PSP += 0x1000;
  83.         }
  84.         close( handle );
  85.         ticks = interval;
  86.         }
  87.     }
  88. }