home *** CD-ROM | disk | FTP | other *** search
- /******************************************
- * Debug Protect. *
- * Version 1.0 *
- * *
- * Make by M.Potanin. *
- ******************************************/
-
- #include<sys/stat.h>
- #include<fcntl.h>
- #include<io.h>
- #include<stdio.h>
- #include<alloc.h>
- #include<string.h>
- #include<stdlib.h>
-
- #define JMP 0xE9
- #define CALL 0xE8
-
- unsigned char mt1[] =
- {
- 0x2E, /*cs:*/
- 0x9C, /*puhf*/
- 0x0E, /*push cs*/
- 0x50, /*push ax*/
- 0x50,
- 0x53, /*push bx*/
- 0x51, /*push cx*/
- 0x55, /*push bp*/
- 0x8B,0xEC,/*mov bp,sp*/
- 0x9C, /*pushf*/
- 0x44, /*inc sp*/
- 0x16, /*push ss*/
- 0x16,
- 0xB4, 0x30, /*mov ah,30h*/
- 0x17, /*pop ss*/
- 0xCD,0x21, /*int 21h*/
- 0x17, /*pop ss*/
- 0x9C, /*pushf*/
- 0xBB, /*mov bx,addres*/
- #define mt1adr ((int *)(mt1+22))
- 0,0, /* addres*/
- 0x2E,0xC7,0x07, /*mov cs:[bx],data1*/
- 0,0, /*data1*/
- #define mt1d1 ((int *)(mt1+27))
- 0x44, /*inc sp*/
- 0x2E,0xC6,0x47,0x02, /*mov cs:[bx+2],data2*/
- 0, /*data2*/
- #define mt1d2 (mt1+34)
- 0x9D, /*popf*/
- 0x89,0x5E,0x08, /*mov [bp+8],bx*/
- 0x72,0xEE, /*jc XPEHEBO3HAET*/
- 0x5D,
- 0x59,
- 0x5B,
- 0x58, /*pop*/
- 0xCF
- };
- unsigned char mtr1[]=
- {
- 0x50, /*push ax*/
- 0x50,
- 0x53, /*push bx*/
- 0x51, /*push cx*/
- 0x55, /*push bp*/
- 0x8B,0xEC,/*mov bp,sp*/
- 0x2E, /*cs:*/
- 0x9C, /*pushf*/
- 0x36, /*ss:*/
- 0x9C, /*pushf*/
- 0x44, /*inc sp*/
- 0x16, /*push ss*/
- 0x16,
- 0xB4, 0x30, /*mov ah,30h*/
- 0x17, /*pop ss*/
- 0xCD,0x21, /*int 21h*/
- 0x17, /*pop ss*/
- 0x9C, /*pushf*/
- 0xBB, /*mov bx,addres*/
- #define mtr1adr ((int *)(mtr1+22))
- 0,0, /* addres*/
- 0x44, /*inc sp*/
- 0x9D, /*popf*/
- 0x80,0xD7,0x11, /*adc bh,17*/
- 0x89,0x5E,0x08, /*mov [bp+8],bx*/
- 0x9D,
- 0x5D,
- 0x59,
- 0x5B,
- 0x58, /*pop*/
- 0xC3, /*ret*/
- };
-
- unsigned char mt2[]=
- {
- 0x2E, /*cs:*/
- 0x9C, /*puhf*/
- 0x0E, /*push cs*/
- 0x50, /*push ax*/
- 0x50,
- 0x53, /*push bx*/
- 0xFA, /*cli*/
- 0x51, /*push cx*/
- 0x55, /*push bp*/
- 0x8B,0xEC,/*mov bp,sp*/
- 0xB0,0x0C,/*mov al,12*/
- 0x57, /*push di*/
- 0xBF, /*mov di,xdata*/
- #define xdata ((int*)(mt2+15))
- 0,0, /*xdata*/
- 0xFD, /*sld*/
- 0xD4,0x0A, /*aam*/
- 0xF9, /*stc*/
- 0xAA, /*stosb*/
- 0x12,0x65,01,/*adc ah,[di+1]*/
- 0xBB, /*mov bx,addres*/
- #define mt2adr ((int*)(mt2+26))
- 0,0, /* addres*/
- 0x00,0xE7,/*add bh,ah*/
- 0x2E,0xC7,0x07, /*mov cs:[bx],data1*/
- 0,0, /*data1*/
- #define mt2d1 ((int *)(mt2+33))
- 0x2E,0xC6,0x47,0x02, /*mov cs:[bx+2],data2*/
- 0, /*data2*/
- #define mt2d2 (mt2+39)
- 0x89,0x5E,0x08, /*mov [bp+8],bx*/
- 0x5F,
- 0x5D,
- 0x59,
- 0x5B,
- 0x58, /*pop*/
- 0xCF
- };
- unsigned char mtr2[]=
- {
- 0x50, /*push ax*/
- 0x50,
- 0x53, /*push bx*/
- 0x51, /*push cx*/
- 0x55, /*push bp*/
- 0x8B,0xEC,/*mov bp,sp*/
- 0xB0,0x0C,/*mov al,12*/
- 0x57, /*push di*/
- 0x9C,
- 0xFA, /*cli*/
- 0xBF, /*mov di,xdata*/
- #define xdatar ((int*)(mtr2+13))
- 0,0, /*xdata*/
- 0xFD, /*sld*/
- 0xD4,0x0A, /*aam*/
- 0xF9, /*stc*/
- 0xAA, /*stosb*/
- 0x12,0x65,01,/*adc ah,[di+1]*/
- 0xBB, /*mov bx,addres*/
- #define mtr2adr ((int*)(mtr2+24))
- 0,0, /* addres*/
- 0xC6,0x45,0x01,0x12,/*mov byte ptr [di+1],12h*/
- 0x00,0xE7,/*add bh,ah*/
- 0x89,0x5E,0x08, /*mov [bp+8],bx*/
- 0x9D,
- 0x5F,
- 0x5D,
- 0x59,
- 0x5B,
- 0x58, /*pop*/
- 0xC3
- };
-
- void main(argc,argv)
- int argc;
- char ** argv;
- {
- int file;
- int siz,adr;
- unsigned char * buf;
-
- puts("Debug Protect.\tV1.0\nMake by M.Potanin.");
-
- if(argc != 4)
- {
- puts("at method addres file");
- exit(1);
- }
-
- if((file=open(argv[3],O_RDONLY | O_BINARY)) < 0)
- {
- puts("Can not open comfile.");
- exit(1);
- }
-
- {
- struct stat x;
- fstat(file,&x);
- if((buf = malloc(x.st_size + 0x100)) == 0)
- {
- puts("Out of memory.");
- close(file);
- exit(1);
- }
- }
- if((siz=read(file,buf,0x8000))<0)
- {
- puts("Can not read file");
- close(file);
- free(buf);
- exit(1);
- }
- close(file);
- if(*(argv[1]) == '1')
- {
- if(argv[1][1] == 0)
- {
- *mt1adr = (adr = atoi(argv[2]))+0x100;
- *mt1d1 = *((int*)(buf+adr));
- *mt1d2 = buf[adr+2];
- memcpy(buf+siz,mt1,sizeof(mt1));
- buf[adr] = JMP;
- *((int*)(buf+adr+1)) = siz-adr-3;
- siz+=sizeof(mt1);
- }else{
- adr = atoi(argv[2]);
- if((buf[adr] == JMP) || (buf[adr] == CALL))
- {
- *mtr1adr = adr + *((int*)(buf+adr+1)) + 0x103 - 0x1100;
- }else{
- puts("Not a jmp.");
- free(buf);
- exit(1);
- }
- memcpy(buf+siz,mtr1,sizeof(mtr1));
- *((int*)(buf+adr+1)) = siz-adr-3;
- siz+=sizeof(mtr1);
- }
- }else{
- if(argv[1][1] == 0)
- {
- *mt2adr = (adr = atoi(argv[2]))+0x100 - 0x400;
- *mt2d1 = *((int*)(buf+adr));
- *mt2d2 = buf[adr+2];
- *xdata = 0x100 + siz + 22;
- memcpy(buf+siz,mt2,sizeof(mt2));
- buf[adr] = JMP;
- *((int*)(buf+adr+1)) = siz-adr-3;
- siz+=sizeof(mt2);
- }else{
- adr = atoi(argv[2]);
- if((buf[adr] == JMP) || (buf[adr] == CALL))
- {
- *mtr2adr = adr + *((int*)(buf+adr+1)) + 0x103 - 0x400;
- *xdatar = 0x100 + siz + 19;
- }else{
- puts("Not a jmp.");
- free(buf);
- exit(1);
- }
- memcpy(buf+siz,mtr2,sizeof(mtr2));
- *((int*)(buf+adr+1)) = siz-adr-3;
- siz+=sizeof(mtr2);
- }
- }
-
- if((file=open("res.com",O_WRONLY | O_CREAT | O_BINARY,
- S_IREAD | S_IWRITE))<0)
- {
- puts("Can not write");
- free(buf);
- exit(1);
- }
- write(file,buf,siz);
- free(buf);
- close(file);
- }