Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Mach-O/main.c
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
47 lines (39 sloc)
1.06 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // main.c | |
| // Mach-O | |
| // | |
| // Created by Antonio Frighetto on 03/11/2016. | |
| // Copyright © 2016 Antonio Frighetto. All rights reserved. | |
| // | |
| #include <stdio.h> | |
| #include "parser/mach-o.h" | |
| int main(int argc, const char * argv[]) { | |
| int fd; | |
| uint32_t magic_number; | |
| if (argc != 2) { | |
| fprintf(stderr, "[-] missing binary path.\n"); | |
| exit(1); | |
| } | |
| if ((fd = open(argv[1], O_RDONLY)) < 0) { | |
| fprintf(stderr, "[-] could not open() %s...\n", argv[1]); | |
| exit(1); | |
| } | |
| lseek(fd, 0, SEEK_SET); | |
| struct stat st; | |
| if (fstat(fd, &st) < 0) { | |
| fprintf(stderr, "[-] unable to stat().\n"); | |
| exit(1); | |
| } | |
| void* map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); | |
| if (map == MAP_FAILED) { | |
| fprintf(stderr, "[-] could not mmap().\n"); | |
| exit(1); | |
| } | |
| read(fd, &magic_number, sizeof magic_number); | |
| if (check_magic(magic_number)) { | |
| fprintf(stderr, "[-] not a mach-o binary file.\n"); | |
| exit(1); | |
| } | |
| init_macho(argv[1], map, magic_number, &st); | |
| return 0; | |
| } | |