home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / hackers / tools / nsk.arj / ZOTLAD / COM / AT.C next >
Encoding:
C/C++ Source or Header  |  1991-12-26  |  5.4 KB  |  271 lines

  1. /******************************************
  2. *        Debug Protect.                   *
  3. *        Version 1.0                      *
  4. *                                         *
  5. *      Make by M.Potanin.                 *
  6. ******************************************/
  7.  
  8. #include<sys/stat.h>
  9. #include<fcntl.h>
  10. #include<io.h>
  11. #include<stdio.h>
  12. #include<alloc.h>
  13. #include<string.h>
  14. #include<stdlib.h>
  15.  
  16. #define JMP 0xE9
  17. #define CALL 0xE8
  18.  
  19. unsigned char mt1[] =
  20. {
  21.  0x2E,  /*cs:*/
  22.  0x9C,  /*puhf*/
  23.  0x0E,  /*push cs*/
  24.  0x50,  /*push ax*/
  25.  0x50,
  26.  0x53,  /*push bx*/
  27.  0x51,  /*push cx*/
  28.  0x55,  /*push bp*/
  29.  0x8B,0xEC,/*mov bp,sp*/
  30.  0x9C,  /*pushf*/
  31.  0x44,  /*inc sp*/
  32.  0x16,  /*push ss*/
  33.  0x16,
  34.  0xB4, 0x30,   /*mov ah,30h*/
  35.  0x17,  /*pop ss*/
  36.  0xCD,0x21, /*int 21h*/
  37.  0x17,  /*pop ss*/
  38.  0x9C,  /*pushf*/
  39.  0xBB,  /*mov bx,addres*/
  40. #define mt1adr ((int *)(mt1+22))
  41.  0,0,   /* addres*/
  42.  0x2E,0xC7,0x07, /*mov cs:[bx],data1*/
  43.  0,0,    /*data1*/
  44. #define mt1d1 ((int *)(mt1+27))
  45.  0x44,   /*inc sp*/
  46.  0x2E,0xC6,0x47,0x02, /*mov cs:[bx+2],data2*/
  47.  0, /*data2*/
  48. #define mt1d2 (mt1+34)
  49.  0x9D,   /*popf*/
  50.  0x89,0x5E,0x08, /*mov [bp+8],bx*/
  51.  0x72,0xEE, /*jc XPEHEBO3HAET*/
  52.  0x5D,
  53.  0x59,
  54.  0x5B,
  55.  0x58,  /*pop*/
  56.  0xCF
  57.  };
  58. unsigned char mtr1[]=
  59. {
  60.  0x50,  /*push ax*/
  61.  0x50,
  62.  0x53,  /*push bx*/
  63.  0x51,  /*push cx*/
  64.  0x55,  /*push bp*/
  65.  0x8B,0xEC,/*mov bp,sp*/
  66.  0x2E,  /*cs:*/
  67.  0x9C,  /*pushf*/
  68.  0x36,  /*ss:*/
  69.  0x9C,  /*pushf*/
  70.  0x44,  /*inc sp*/
  71.  0x16,  /*push ss*/
  72.  0x16,
  73.  0xB4, 0x30,   /*mov ah,30h*/
  74.  0x17,  /*pop ss*/
  75.  0xCD,0x21, /*int 21h*/
  76.  0x17,  /*pop ss*/
  77.  0x9C,  /*pushf*/
  78.  0xBB,  /*mov bx,addres*/
  79. #define mtr1adr ((int *)(mtr1+22))
  80.  0,0,   /* addres*/
  81.  0x44,   /*inc sp*/
  82.  0x9D,   /*popf*/
  83.  0x80,0xD7,0x11, /*adc bh,17*/
  84.  0x89,0x5E,0x08, /*mov [bp+8],bx*/
  85.  0x9D,
  86.  0x5D,
  87.  0x59,
  88.  0x5B,
  89.  0x58,  /*pop*/
  90.  0xC3,  /*ret*/
  91.  };
  92.  
  93. unsigned char mt2[]=
  94. {
  95.  0x2E,  /*cs:*/
  96.  0x9C,  /*puhf*/
  97.  0x0E,  /*push cs*/
  98.  0x50,  /*push ax*/
  99.  0x50,
  100.  0x53,  /*push bx*/
  101.  0xFA,  /*cli*/
  102.  0x51,  /*push cx*/
  103.  0x55,  /*push bp*/
  104.  0x8B,0xEC,/*mov bp,sp*/
  105.  0xB0,0x0C,/*mov al,12*/
  106.  0x57,  /*push di*/
  107.  0xBF,  /*mov di,xdata*/
  108. #define xdata ((int*)(mt2+15))
  109.  0,0,   /*xdata*/
  110.  0xFD,  /*sld*/
  111.  0xD4,0x0A,  /*aam*/
  112.  0xF9,  /*stc*/
  113.  0xAA,  /*stosb*/
  114.  0x12,0x65,01,/*adc ah,[di+1]*/
  115.  0xBB,  /*mov bx,addres*/
  116. #define mt2adr ((int*)(mt2+26))
  117.  0,0,   /* addres*/
  118.  0x00,0xE7,/*add bh,ah*/
  119.  0x2E,0xC7,0x07, /*mov cs:[bx],data1*/
  120.  0,0,    /*data1*/
  121. #define mt2d1 ((int *)(mt2+33))
  122.  0x2E,0xC6,0x47,0x02, /*mov cs:[bx+2],data2*/
  123.  0, /*data2*/
  124. #define mt2d2 (mt2+39)
  125.  0x89,0x5E,0x08, /*mov [bp+8],bx*/
  126.  0x5F,
  127.  0x5D,
  128.  0x59,
  129.  0x5B,
  130.  0x58,  /*pop*/
  131.  0xCF
  132.  };
  133. unsigned char mtr2[]=
  134. {
  135.  0x50,  /*push ax*/
  136.  0x50,
  137.  0x53,  /*push bx*/
  138.  0x51,  /*push cx*/
  139.  0x55,  /*push bp*/
  140.  0x8B,0xEC,/*mov bp,sp*/
  141.  0xB0,0x0C,/*mov al,12*/
  142.  0x57,  /*push di*/
  143.  0x9C,
  144.  0xFA,  /*cli*/
  145.  0xBF,  /*mov di,xdata*/
  146. #define xdatar ((int*)(mtr2+13))
  147.  0,0,   /*xdata*/
  148.  0xFD,  /*sld*/
  149.  0xD4,0x0A,  /*aam*/
  150.  0xF9,  /*stc*/
  151.  0xAA,  /*stosb*/
  152.  0x12,0x65,01,/*adc ah,[di+1]*/
  153.  0xBB,  /*mov bx,addres*/
  154. #define mtr2adr ((int*)(mtr2+24))
  155.  0,0,   /* addres*/
  156.  0xC6,0x45,0x01,0x12,/*mov byte ptr [di+1],12h*/
  157.  0x00,0xE7,/*add bh,ah*/
  158.  0x89,0x5E,0x08, /*mov [bp+8],bx*/
  159.  0x9D,
  160.  0x5F,
  161.  0x5D,
  162.  0x59,
  163.  0x5B,
  164.  0x58,  /*pop*/
  165.  0xC3
  166.  };
  167.  
  168. void main(argc,argv)
  169. int argc;
  170. char ** argv;
  171. {
  172.  int file;
  173.  int siz,adr;
  174.  unsigned char * buf;
  175.  
  176.  puts("Debug Protect.\tV1.0\nMake by M.Potanin.");
  177.  
  178.  if(argc != 4)
  179.  {
  180.   puts("at method addres file");
  181.   exit(1);
  182.  }
  183.  
  184.  if((file=open(argv[3],O_RDONLY | O_BINARY)) < 0)
  185.  {
  186.   puts("Can not open comfile.");
  187.   exit(1);
  188.  }
  189.  
  190.  {
  191.   struct stat x;
  192.   fstat(file,&x);
  193.   if((buf = malloc(x.st_size + 0x100)) == 0)
  194.   {
  195.    puts("Out of memory.");
  196.    close(file);
  197.    exit(1);
  198.   }
  199.  }
  200.  if((siz=read(file,buf,0x8000))<0)
  201.  {
  202.   puts("Can not read file");
  203.   close(file);
  204.   free(buf);
  205.   exit(1);
  206.  }
  207.  close(file);
  208.  if(*(argv[1]) == '1')
  209.  {
  210.   if(argv[1][1] == 0)
  211.   {
  212.    *mt1adr = (adr = atoi(argv[2]))+0x100;
  213.    *mt1d1 = *((int*)(buf+adr));
  214.    *mt1d2 = buf[adr+2];
  215.    memcpy(buf+siz,mt1,sizeof(mt1));
  216.    buf[adr] = JMP;
  217.    *((int*)(buf+adr+1)) = siz-adr-3;
  218.    siz+=sizeof(mt1);
  219.   }else{
  220.    adr = atoi(argv[2]);
  221.    if((buf[adr] == JMP) || (buf[adr] == CALL))
  222.    {
  223.     *mtr1adr = adr + *((int*)(buf+adr+1)) + 0x103 - 0x1100;
  224.    }else{
  225.     puts("Not a jmp.");
  226.     free(buf);
  227.     exit(1);
  228.    }
  229.    memcpy(buf+siz,mtr1,sizeof(mtr1));
  230.    *((int*)(buf+adr+1)) = siz-adr-3;
  231.    siz+=sizeof(mtr1);
  232.   }
  233.  }else{
  234.   if(argv[1][1] == 0)
  235.   {
  236.    *mt2adr = (adr = atoi(argv[2]))+0x100 - 0x400;
  237.    *mt2d1 = *((int*)(buf+adr));
  238.    *mt2d2 = buf[adr+2];
  239.    *xdata = 0x100 + siz + 22;
  240.    memcpy(buf+siz,mt2,sizeof(mt2));
  241.    buf[adr] = JMP;
  242.    *((int*)(buf+adr+1)) = siz-adr-3;
  243.    siz+=sizeof(mt2);
  244.   }else{
  245.    adr = atoi(argv[2]);
  246.    if((buf[adr] == JMP) || (buf[adr] == CALL))
  247.    {
  248.     *mtr2adr = adr + *((int*)(buf+adr+1)) + 0x103 - 0x400;
  249.     *xdatar = 0x100 + siz + 19;
  250.    }else{
  251.     puts("Not a jmp.");
  252.     free(buf);
  253.     exit(1);
  254.    }
  255.    memcpy(buf+siz,mtr2,sizeof(mtr2));
  256.    *((int*)(buf+adr+1)) = siz-adr-3;
  257.    siz+=sizeof(mtr2);
  258.   }
  259.  }
  260.  
  261.  if((file=open("res.com",O_WRONLY | O_CREAT | O_BINARY,
  262.                          S_IREAD | S_IWRITE))<0)
  263.  {
  264.   puts("Can not write");
  265.   free(buf);
  266.   exit(1);
  267.  }
  268.  write(file,buf,siz);
  269.  free(buf);
  270.  close(file);
  271. }