grobian 08/10/19 18:11:59
Modified: paxinc.c paxmacho.c scanmacho.c
Log:
Made reading archives work.
The Darwin linker creates BSD ar archives, which (stupidly) always use
the "extended filename" method to store filenames. For this reason I
implemented the BSD extended filename method in paxinc's ar_next.
Next to some fixes in the macho code not to free and unmap when this is
not desired, this yields in a working scanmacho on static archives.
The change has been checked with scanelf against a GNU ELF static
archive not to break anything.
Revision Changes Path
1.9 pax-utils/paxinc.c
file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/paxinc.c?rev=1.9&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/paxinc.c?rev=1.9&content-type=text/plain
diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/paxinc.c?r1=1.8&r2=1.9
Index: paxinc.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/paxinc.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- paxinc.c 20 Aug 2007 09:54:15 -0000 1.8
+++ paxinc.c 19 Oct 2008 18:11:59 -0000 1.9
@@ -1,7 +1,7 @@
/*
* Copyright 2003-2007 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxinc.c,v 1.8 2007/08/20 09:54:15 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxinc.c,v 1.9 2008/10/19 18:11:59 grobian Exp $
*
* Copyright 2005-2007 Ned Ludd - <solar@g.o>
* Copyright 2005-2007 Mike Frysinger - <vapier@g.o>
@@ -52,7 +52,7 @@
archive_member *ar_next(archive_handle *ar)
{
char *s;
- size_t len;
+ size_t len = 0;
static archive_member ret;
if (ar->skip && lseek(ar->fd, ar->skip, SEEK_CUR) == -1) {
@@ -82,21 +82,29 @@
return ar_next(ar);
}
- len = strlen(ar->filename);
- assert(len < sizeof(ret.name)-sizeof(ret.buf.formatted.name)-1);
- memcpy(ret.name, ar->filename, len);
- ret.name[len++] = ':';
- memcpy(ret.name+len, ret.buf.formatted.name, sizeof(ret.buf.formatted.name));
- if ((s=strchr(ret.name+len, '/')) != NULL)
+ s = ret.buf.formatted.name;
+ if (s[0] == '#' && s[1] == '1' && s[2] == '/') {
+ /* BSD extended filename, always in use on Darwin */
+ len = atoi(s + 3);
+ if (len <= sizeof(ret.buf.formatted.name)) {
+ if (read(ar->fd, ret.buf.formatted.name, len) != len)
+ goto close_and_ret;
+ } else {
+ s = alloca(sizeof(char) * len);
+ if (read(ar->fd, s, len) != len)
+ goto close_and_ret;
+ }
+ }
+
+ snprintf(ret.name, sizeof(ret.name), "%s:%s", ar->filename, s);
+ if ((s=strchr(ret.name+strlen(ar->filename), '/')) != NULL)
*s = '\0';
- else
- ret.name[len+sizeof(ret.buf.formatted.name)-1] = '\0';
ret.date = atoi(ret.buf.formatted.date);
ret.uid = atoi(ret.buf.formatted.uid);
ret.gid = atoi(ret.buf.formatted.gid);
ret.mode = strtol(ret.buf.formatted.mode, NULL, 8);
ret.size = atoi(ret.buf.formatted.size);
- ar->skip = ret.size;
+ ar->skip = ret.size - len;
return &ret;
}
1.9 pax-utils/paxmacho.c
file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/paxmacho.c?rev=1.9&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/paxmacho.c?rev=1.9&content-type=text/plain
diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/paxmacho.c?r1=1.8&r2=1.9
Index: paxmacho.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/paxmacho.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- paxmacho.c 12 Sep 2008 19:59:26 -0000 1.8
+++ paxmacho.c 19 Oct 2008 18:11:59 -0000 1.9
@@ -1,7 +1,7 @@
/*
* Copyright 2003-2008 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxmacho.c,v 1.8 2008/09/12 19:59:26 grobian Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxmacho.c,v 1.9 2008/10/19 18:11:59 grobian Exp $
*
* Copyright 2005-2007 Ned Ludd - <solar@g.o>
* Copyright 2005-2007 Mike Frysinger - <vapier@g.o>
@@ -237,13 +237,13 @@
/* make sure we have enough bytes to scan */
if (len <= sizeof(struct fat_header))
- goto close_fd_and_return;
+ return NULL;
data = (char*)mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0);
if (data == (char*)MAP_FAILED) {
warn("mmap on '%s' of %llu bytes failed :(",
filename, (unsigned long long)len);
- goto close_fd_and_return;
+ return NULL;
}
ret = readmacho_buffer(filename, data, len);
@@ -254,8 +254,6 @@
}
munmap(data, len);
-close_fd_and_return:
- close(fd);
return NULL;
}
1.5 pax-utils/scanmacho.c
file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanmacho.c?rev=1.5&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanmacho.c?rev=1.5&content-type=text/plain
diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanmacho.c?r1=1.4&r2=1.5
Index: scanmacho.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/scanmacho.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- scanmacho.c 12 Sep 2008 19:59:26 -0000 1.4
+++ scanmacho.c 19 Oct 2008 18:11:59 -0000 1.5
@@ -1,7 +1,7 @@
/*
* Copyright 2008 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanmacho.c,v 1.4 2008/09/12 19:59:26 grobian Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanmacho.c,v 1.5 2008/10/19 18:11:59 grobian Exp $
*
* based on scanelf by:
* Copyright 2003-2007 Ned Ludd - <solar@g.o>
@@ -10,7 +10,7 @@
* 2008 Fabian Groffen - <grobian@g.o>
*/
-static const char *rcsid = "$Id: scanmacho.c,v 1.4 2008/09/12 19:59:26 grobian Exp $";
+static const char *rcsid = "$Id: scanmacho.c,v 1.5 2008/10/19 18:11:59 grobian Exp $";
const char * const argv0 = "scanmacho";
#include "paxinc.h"
@@ -404,6 +404,7 @@
do {
scanmacho_fatobj(walk);
} while (walk->next != NULL && (walk = walk->next));
+ fobj->data = NULL;
unreadmacho(fobj);
}
}
|