Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <elf.h>
- int
- main(int argc, char *argv[])
- {
- int fd;
- char *buf;
- struct stat elf_stat;
- Elf32_Ehdr *elf_header;
- int size, sh_size;
- if(argc < 3)
- {
- printf( "Usage: %s <file> <address>\n", argv[0] );
- return 1;
- }
- printf( "@ File name \t: %s .\n", argv[1] );
- if ((fd = open(argv[1],O_RDWR)) <0) /* Open file in read/write mode */
- return 2;
- if( fstat( fd, &elf_stat ) < 0 ) /* Getting size with fstat */
- return 3;
- size = elf_stat.st_size;
- printf( "@ File size \t: %d bytes .\n", size );
- buf = (char*)malloc(sizeof(char)*size+1);
- read(fd,buf,size); /* Read whole file */
- elf_header = (Elf32_Ehdr *)buf; /* Copy the buffer into elf structure */
- printf("@ Entry point \t: 0x%X .\n", elf_header->e_entry );
- elf_header->e_entry = strtol( argv[2], NULL, 16 );
- printf("@ New Entry point \t: 0x%X .\n", elf_header->e_entry );
- lseek( fd, 0, SEEK_SET );
- write( fd, elf_header, size );
- close(fd);
- free(buf);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement