Advertisement
Guest User

changep

a guest
Nov 25th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7. #include <elf.h>
  8.  
  9. int
  10. main(int argc, char *argv[])
  11. {
  12.     int fd;
  13.     char *buf;
  14.     struct stat elf_stat;
  15.     Elf32_Ehdr *elf_header;
  16.     int size, sh_size;
  17.        
  18.     if(argc < 3)
  19.     {
  20.         printf( "Usage: %s <file> <address>\n", argv[0] );
  21.  
  22.         return 1;
  23.     }
  24.  
  25.     printf( "@ File name           \t: %s .\n", argv[1] );
  26.    
  27.     if ((fd = open(argv[1],O_RDWR)) <0) /* Open file in read/write mode */
  28.         return 2;
  29.    
  30.     if( fstat( fd, &elf_stat ) < 0 )  /* Getting size with fstat */
  31.         return 3;
  32.  
  33.     size = elf_stat.st_size;
  34.        
  35.     printf( "@ File size           \t: %d bytes .\n", size );
  36.        
  37.     buf = (char*)malloc(sizeof(char)*size+1);
  38.  
  39.     read(fd,buf,size); /* Read whole file */
  40.        
  41.     elf_header = (Elf32_Ehdr *)buf; /* Copy the buffer into elf structure */
  42.  
  43.     printf("@ Entry point      \t: 0x%X .\n", elf_header->e_entry );
  44.  
  45.     elf_header->e_entry = strtol( argv[2], NULL, 16 );
  46.  
  47.     printf("@ New Entry point      \t: 0x%X .\n", elf_header->e_entry );
  48.  
  49.     lseek( fd, 0, SEEK_SET );
  50.  
  51.     write( fd, elf_header, size );
  52.        
  53.     close(fd);
  54.  
  55.     free(buf);
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement