Guest User

Untitled

a guest
Jun 7th, 2014
247
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #include <fcntl.h>
  3. #include <string.h>
  4.  
  5. int main(int argc, char* argv[])
  6. {
  7.   char buffer[512];
  8.   if(argc < 3)
  9.   {
  10.     strcpy (buffer, "Usage: EOF_Abuser obj_file_name src_file_name\n");
  11.     write (2, buffer, strlen (buffer));
  12.     exit(1);
  13.   }
  14.  
  15.   int obj_fd, src_fc;
  16.   if((obj_fd = open(argv[1], O_WRONLY, 0666)) < 0)
  17.   {
  18.     strcpy (buffer, "Error opening objective file.\n");
  19.     write (2, buffer, strlen (buffer));
  20.     exit (1);
  21.   }
  22.   if((src_fc = open(argv[2], O_RDONLY, 0666)) < 0)
  23.   {
  24.     strcpy (buffer, "Error opening source file.\n");
  25.     write (2, buffer, strlen (buffer));
  26.     exit (1);
  27.   }
  28.  
  29.   //We go to the EOF of the objective
  30.   lseek(obj_fd, 0, SEEK_END);
  31.   while(read(src_fc, buffer, strlen(buffer)) > 0)
  32.   {
  33.     if(write(obj_fd, buffer, strlen(buffer)) < 0)
  34.       strcpy (buffer, "Error in write.\n");
  35.     else strcpy (buffer, "512b.\n");
  36.     write (1, buffer, strlen (buffer));
  37.   }
  38.   strcpy (buffer, "Finished.\n");
  39.   write (1, buffer, strlen (buffer));
  40.  
  41.   close(obj_fd); close(src_fc);
  42.   exit (1);
  43. }
RAW Paste Data