1 |
grobian 08/10/19 18:11:59 |
2 |
|
3 |
Modified: paxinc.c paxmacho.c scanmacho.c |
4 |
Log: |
5 |
Made reading archives work. |
6 |
|
7 |
The Darwin linker creates BSD ar archives, which (stupidly) always use |
8 |
the "extended filename" method to store filenames. For this reason I |
9 |
implemented the BSD extended filename method in paxinc's ar_next. |
10 |
Next to some fixes in the macho code not to free and unmap when this is |
11 |
not desired, this yields in a working scanmacho on static archives. |
12 |
|
13 |
The change has been checked with scanelf against a GNU ELF static |
14 |
archive not to break anything. |
15 |
|
16 |
Revision Changes Path |
17 |
1.9 pax-utils/paxinc.c |
18 |
|
19 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/paxinc.c?rev=1.9&view=markup |
20 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/paxinc.c?rev=1.9&content-type=text/plain |
21 |
diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/paxinc.c?r1=1.8&r2=1.9 |
22 |
|
23 |
Index: paxinc.c |
24 |
=================================================================== |
25 |
RCS file: /var/cvsroot/gentoo-projects/pax-utils/paxinc.c,v |
26 |
retrieving revision 1.8 |
27 |
retrieving revision 1.9 |
28 |
diff -u -r1.8 -r1.9 |
29 |
--- paxinc.c 20 Aug 2007 09:54:15 -0000 1.8 |
30 |
+++ paxinc.c 19 Oct 2008 18:11:59 -0000 1.9 |
31 |
@@ -1,7 +1,7 @@ |
32 |
/* |
33 |
* Copyright 2003-2007 Gentoo Foundation |
34 |
* Distributed under the terms of the GNU General Public License v2 |
35 |
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxinc.c,v 1.8 2007/08/20 09:54:15 vapier Exp $ |
36 |
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxinc.c,v 1.9 2008/10/19 18:11:59 grobian Exp $ |
37 |
* |
38 |
* Copyright 2005-2007 Ned Ludd - <solar@g.o> |
39 |
* Copyright 2005-2007 Mike Frysinger - <vapier@g.o> |
40 |
@@ -52,7 +52,7 @@ |
41 |
archive_member *ar_next(archive_handle *ar) |
42 |
{ |
43 |
char *s; |
44 |
- size_t len; |
45 |
+ size_t len = 0; |
46 |
static archive_member ret; |
47 |
|
48 |
if (ar->skip && lseek(ar->fd, ar->skip, SEEK_CUR) == -1) { |
49 |
@@ -82,21 +82,29 @@ |
50 |
return ar_next(ar); |
51 |
} |
52 |
|
53 |
- len = strlen(ar->filename); |
54 |
- assert(len < sizeof(ret.name)-sizeof(ret.buf.formatted.name)-1); |
55 |
- memcpy(ret.name, ar->filename, len); |
56 |
- ret.name[len++] = ':'; |
57 |
- memcpy(ret.name+len, ret.buf.formatted.name, sizeof(ret.buf.formatted.name)); |
58 |
- if ((s=strchr(ret.name+len, '/')) != NULL) |
59 |
+ s = ret.buf.formatted.name; |
60 |
+ if (s[0] == '#' && s[1] == '1' && s[2] == '/') { |
61 |
+ /* BSD extended filename, always in use on Darwin */ |
62 |
+ len = atoi(s + 3); |
63 |
+ if (len <= sizeof(ret.buf.formatted.name)) { |
64 |
+ if (read(ar->fd, ret.buf.formatted.name, len) != len) |
65 |
+ goto close_and_ret; |
66 |
+ } else { |
67 |
+ s = alloca(sizeof(char) * len); |
68 |
+ if (read(ar->fd, s, len) != len) |
69 |
+ goto close_and_ret; |
70 |
+ } |
71 |
+ } |
72 |
+ |
73 |
+ snprintf(ret.name, sizeof(ret.name), "%s:%s", ar->filename, s); |
74 |
+ if ((s=strchr(ret.name+strlen(ar->filename), '/')) != NULL) |
75 |
*s = '\0'; |
76 |
- else |
77 |
- ret.name[len+sizeof(ret.buf.formatted.name)-1] = '\0'; |
78 |
ret.date = atoi(ret.buf.formatted.date); |
79 |
ret.uid = atoi(ret.buf.formatted.uid); |
80 |
ret.gid = atoi(ret.buf.formatted.gid); |
81 |
ret.mode = strtol(ret.buf.formatted.mode, NULL, 8); |
82 |
ret.size = atoi(ret.buf.formatted.size); |
83 |
- ar->skip = ret.size; |
84 |
+ ar->skip = ret.size - len; |
85 |
|
86 |
return &ret; |
87 |
} |
88 |
|
89 |
|
90 |
|
91 |
1.9 pax-utils/paxmacho.c |
92 |
|
93 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/paxmacho.c?rev=1.9&view=markup |
94 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/paxmacho.c?rev=1.9&content-type=text/plain |
95 |
diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/paxmacho.c?r1=1.8&r2=1.9 |
96 |
|
97 |
Index: paxmacho.c |
98 |
=================================================================== |
99 |
RCS file: /var/cvsroot/gentoo-projects/pax-utils/paxmacho.c,v |
100 |
retrieving revision 1.8 |
101 |
retrieving revision 1.9 |
102 |
diff -u -r1.8 -r1.9 |
103 |
--- paxmacho.c 12 Sep 2008 19:59:26 -0000 1.8 |
104 |
+++ paxmacho.c 19 Oct 2008 18:11:59 -0000 1.9 |
105 |
@@ -1,7 +1,7 @@ |
106 |
/* |
107 |
* Copyright 2003-2008 Gentoo Foundation |
108 |
* Distributed under the terms of the GNU General Public License v2 |
109 |
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxmacho.c,v 1.8 2008/09/12 19:59:26 grobian Exp $ |
110 |
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxmacho.c,v 1.9 2008/10/19 18:11:59 grobian Exp $ |
111 |
* |
112 |
* Copyright 2005-2007 Ned Ludd - <solar@g.o> |
113 |
* Copyright 2005-2007 Mike Frysinger - <vapier@g.o> |
114 |
@@ -237,13 +237,13 @@ |
115 |
|
116 |
/* make sure we have enough bytes to scan */ |
117 |
if (len <= sizeof(struct fat_header)) |
118 |
- goto close_fd_and_return; |
119 |
+ return NULL; |
120 |
|
121 |
data = (char*)mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0); |
122 |
if (data == (char*)MAP_FAILED) { |
123 |
warn("mmap on '%s' of %llu bytes failed :(", |
124 |
filename, (unsigned long long)len); |
125 |
- goto close_fd_and_return; |
126 |
+ return NULL; |
127 |
} |
128 |
|
129 |
ret = readmacho_buffer(filename, data, len); |
130 |
@@ -254,8 +254,6 @@ |
131 |
} |
132 |
|
133 |
munmap(data, len); |
134 |
-close_fd_and_return: |
135 |
- close(fd); |
136 |
return NULL; |
137 |
} |
138 |
|
139 |
|
140 |
|
141 |
|
142 |
1.5 pax-utils/scanmacho.c |
143 |
|
144 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanmacho.c?rev=1.5&view=markup |
145 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanmacho.c?rev=1.5&content-type=text/plain |
146 |
diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanmacho.c?r1=1.4&r2=1.5 |
147 |
|
148 |
Index: scanmacho.c |
149 |
=================================================================== |
150 |
RCS file: /var/cvsroot/gentoo-projects/pax-utils/scanmacho.c,v |
151 |
retrieving revision 1.4 |
152 |
retrieving revision 1.5 |
153 |
diff -u -r1.4 -r1.5 |
154 |
--- scanmacho.c 12 Sep 2008 19:59:26 -0000 1.4 |
155 |
+++ scanmacho.c 19 Oct 2008 18:11:59 -0000 1.5 |
156 |
@@ -1,7 +1,7 @@ |
157 |
/* |
158 |
* Copyright 2008 Gentoo Foundation |
159 |
* Distributed under the terms of the GNU General Public License v2 |
160 |
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanmacho.c,v 1.4 2008/09/12 19:59:26 grobian Exp $ |
161 |
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanmacho.c,v 1.5 2008/10/19 18:11:59 grobian Exp $ |
162 |
* |
163 |
* based on scanelf by: |
164 |
* Copyright 2003-2007 Ned Ludd - <solar@g.o> |
165 |
@@ -10,7 +10,7 @@ |
166 |
* 2008 Fabian Groffen - <grobian@g.o> |
167 |
*/ |
168 |
|
169 |
-static const char *rcsid = "$Id: scanmacho.c,v 1.4 2008/09/12 19:59:26 grobian Exp $"; |
170 |
+static const char *rcsid = "$Id: scanmacho.c,v 1.5 2008/10/19 18:11:59 grobian Exp $"; |
171 |
const char * const argv0 = "scanmacho"; |
172 |
|
173 |
#include "paxinc.h" |
174 |
@@ -404,6 +404,7 @@ |
175 |
do { |
176 |
scanmacho_fatobj(walk); |
177 |
} while (walk->next != NULL && (walk = walk->next)); |
178 |
+ fobj->data = NULL; |
179 |
unreadmacho(fobj); |
180 |
} |
181 |
} |