Mercurial > hg > Members > taiki > Mach-OLoader
annotate mach-o-loader/loader.c @ 2:747f68297ba5 default tip
add c language mach-O loader program. this program only analize, can't still load now.
author | taiki <taiki@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 04 Mar 2014 14:41:35 +0900 |
parents | |
children |
rev | line source |
---|---|
2
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #include <stdio.h> |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 #include <stdlib.h> |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 #include <unistd.h> |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 #include <fcntl.h> |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 #include <string.h> |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 #include <sys/stat.h> |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 #include <sys/mman.h> |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 #include <mach-o/loader.h> |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 #include "loader.h" |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 #define MAX_COMMAND_LEN 10000 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 #define MAX_SECTION_LEN 10000 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 int analyze(char* head) |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 struct mach_header_64 *mh64 = (struct mach_header_64 *)head; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 // mach header is 32 bytes |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 int com_index = sizeof(struct mach_header_64); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 for (int cmds = 0; cmds < mh64->ncmds; cmds++) { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 struct load_command *com = (struct load_command *) (head + com_index); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 switch(com->cmd) { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 case LC_SEGMENT_64: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 struct segment_command_64 *sc = |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 (struct segment_command_64 *) (head + com_index); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 com_index += sizeof(struct segment_command_64); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 printf("segment command:\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 printf("\tcmd :%0xd \n", sc->cmd); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 printf("\tcmdsize :%d \n", sc->cmdsize); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 printf("\tsegname :%s \n", sc->segname); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 printf("\tvmaddr :%0llx \n", sc->vmaddr); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 printf("\tnsects :%d \n", sc->nsects); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 int nsects = sc->nsects; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 printf("sections:\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 for (int sects = 0; sects < nsects; sects++) { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 struct section_64 *sc64 = (struct section_64*) (head + com_index); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 printf("\t%s\n", sc64->sectname); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 com_index += sizeof(struct section_64); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 case LC_UUID: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 struct uuid_command *uc = |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 (struct uuid_command*) (head + com_index); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 com_index += sizeof(struct uuid_command); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 printf("uuid command\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 for(int i = 0; i < 16; i++) { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 printf("%u", uc->uuid[i]); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 printf("\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 case LC_SYMTAB: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 struct symtab_command *syt = |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 (struct symtab_command*) (head + com_index); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 com_index += sizeof(struct symtab_command); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 printf("symtab_command\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 printf("\tsymoff %d\n", syt->symoff); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 printf("\tnsyms %d\n", syt->nsyms); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 case LC_DYSYMTAB: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 struct dysymtab_command *dysyt = |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 (struct dysymtab_command*) (head + com_index); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 com_index += sizeof(struct dysymtab_command); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 printf("dysymtab_command\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 printf("symtab_command\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 printf("\tsymoff %d\n", dysyt->cmd); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 printf("\tnsyms %d\n", dysyt->cmdsize); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86 case LC_THREAD: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
87 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 printf("thread\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 case LC_UNIXTHREAD: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 printf("unix thread\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96 case LC_ID_DYLIB: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 printf("unix thread\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101 case LC_PREBOUND_DYLIB: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 printf("unix thread\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
104 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
105 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106 case LC_LOAD_DYLINKER: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108 struct dylinker_command *dylc = (struct dylinker_command *) (head + com_index); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109 printf("load dylinker\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110 printf("\tcmdsize: %d\n", dylc->cmdsize); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
111 printf("\tdylc->name.offset: %d\n", dylc->name.offset); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
112 char *name = (head + com_index) + sizeof(struct dylinker_command); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
113 printf("\tname: %s\n", name); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
114 com_index = com_index + dylc->cmdsize; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
116 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117 case LC_ID_DYLINKER: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
118 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119 printf("id dylinker\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
120 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
121 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122 case LC_ROUTINES: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
123 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
124 printf("routines\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
125 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
126 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
127 case LC_ROUTINES_64: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
128 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
129 printf("iroutines 64\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
130 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
131 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
132 case LC_TWOLEVEL_HINTS: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
133 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
134 printf("two level hints\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
135 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
136 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
137 case LC_SUB_FRAMEWORK: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
138 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
139 printf("sub framework\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
140 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
141 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
142 case LC_SUB_UMBRELLA: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
143 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
144 printf("sub umbrella\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
145 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
146 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
147 case LC_SUB_LIBRARY: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
148 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
149 printf("sub library\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
150 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
151 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
152 case LC_SUB_CLIENT: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
153 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
154 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
155 printf("sub client\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
156 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
157 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
158 case LC_DYLD_INFO_ONLY: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
159 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
160 struct dyld_info_command *dyldi_com = (struct dyld_info_command *) (head + com_index); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
161 com_index += sizeof(struct dyld_info_command); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
162 printf("dyld info only\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
163 printf("\tcmdsize: %d\n", dyldi_com->cmdsize); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
164 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
165 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
166 case LC_VERSION_MIN_MACOSX: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
167 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
168 struct version_min_command *vm_com = (struct version_min_command *) (head + com_index); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
169 com_index += sizeof(struct version_min_command); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
170 printf("version min macosx\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
171 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
172 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
173 case LC_SOURCE_VERSION: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
174 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
175 struct source_version_command *sv_com = (struct source_version_command *) (head + com_index); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
176 com_index += sizeof(struct source_version_command); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
177 printf("source version\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
178 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
179 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
180 case LC_DATA_IN_CODE: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
181 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
182 struct linkedit_data_command *ld_com = (struct linkedit_data_command*) (head + com_index); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
183 com_index += sizeof(struct linkedit_data_command); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
184 printf("data in code\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
185 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
186 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
187 case LC_DYLIB_CODE_SIGN_DRS: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
188 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
189 printf("cylib code sign drs\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
190 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
191 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
192 case LC_LOAD_DYLIB: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
193 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
194 struct dylib_command *dl_com = (struct dylib_command *) (head + com_index); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
195 printf("lc load dylib\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
196 int offset = dl_com->dylib.name.offset; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
197 printf("\tname offset: %d\n",offset); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
198 char *name = (head + com_index) + sizeof(struct dylib_command); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
199 printf("\tname: %s\n", name); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
200 com_index = com_index + dl_com->cmdsize; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
201 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
202 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
203 case LC_MAIN: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
204 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
205 struct entry_point_command *ep_com = (struct entry_point_command *) (head + com_index); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
206 com_index += sizeof(struct entry_point_command); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
207 printf("lc main\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
208 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
209 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
210 case LC_FUNCTION_STARTS: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
211 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
212 struct linkedit_data_command *ld_com = (struct linkedit_data_command*) (head + com_index); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
213 com_index += sizeof(struct linkedit_data_command); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
214 printf("lc functions starts\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
215 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
216 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
217 default: |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
218 printf("no suitable cmd:%d\n", com->cmd); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
219 break; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
220 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
221 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
222 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
223 return 0; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
224 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
225 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
226 int check_header(int fp, struct stat sb, char* head) |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
227 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
228 struct mach_header_64 *mh64 = (struct mach_header_64 *)head; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
229 if (MH_MAGIC_64 != mh64->magic) { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
230 fprintf(stderr, "This is no mach header 64.\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
231 return -1; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
232 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
233 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
234 if (MH_EXECUTE != mh64->filetype) { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
235 fprintf(stderr, "This isn't executable file.\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
236 return -1; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
237 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
238 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
239 if (CPU_TYPE_X86_64 != mh64->cputype) { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
240 fprintf(stderr, "No suitable cpu type.\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
241 return -1; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
242 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
243 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
244 printf("numbler of load commands : %d\n", mh64->ncmds); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
245 printf("size of cmds : %d\n", mh64->sizeofcmds); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
246 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
247 return 0; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
248 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
249 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
250 int main(int argc, char *argv[]) |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
251 { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
252 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
253 char *filename = argv[1]; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
254 int fp = 0; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
255 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
256 if ((fp = open(filename, O_RDONLY)) < 0) { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
257 fprintf(stderr, "can not open file\t: %s\n", filename); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
258 return -1; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
259 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
260 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
261 struct stat sb; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
262 if (fstat(fp, &sb) < 0) { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
263 fprintf(stderr, "can not get stat\t: %s\n", filename); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
264 return -1; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
265 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
266 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
267 char *head = (char *)mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fp, 0); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
268 if ((int)head < 0) { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
269 fprintf(stderr, "can't map memory.\n"); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
270 return -1; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
271 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
272 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
273 if (check_header(fp, sb, head) < 0) { |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
274 return -1; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
275 } |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
276 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
277 analyze(head); |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
278 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
279 close(fp); /* close file */ |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
280 |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
281 return 0; |
747f68297ba5
add c language mach-O loader program. this program only analize, can't still load now.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
282 } |