# Makefile for file(1) cmd.
# Copyright (c) Ian F. Darwin 86/09/01 - see LEGAL.NOTICE.
-# @(#)$Id: Makefile.in,v 1.4 1998/06/27 14:01:39 christos Exp $
+# @(#)$Id: Makefile.in,v 1.5 1998/09/12 13:17:52 christos Exp $
#
# This software is not subject to any license of the American Telephone
# and Telegraph Company or of the Regents of the University of California.
# ever read sources, credits must appear in the documentation.
#
# 4. This notice may not be removed or altered.
-VERSION = 3.25
+VERSION = 3.26
SHELL = /bin/sh
#MAGIC = /etc/magic
prefix = @prefix@
INSTALLCMD = @INSTALL@
MAGICDIR = @datadir@
MAGIC = $(MAGICDIR)/magic
-DEFS = -DMAGIC='"$(MAGIC)"' -DBUILTIN_ELF -DHAVE_CONFIG_H
+DEFS = -DMAGIC='"$(MAGIC)"' -DBUILTIN_ELF -DELFCORE -DHAVE_CONFIG_H
CPPFLAGS = $(DEFS)
CC = @CC@
#COPTS = -O -g # newer compilers allow both; else drop -O
AUTOSRC=configure configure.in install-sh config.h.in Makefile.in
ALLSRC = LEGAL.NOTICE README MAINT PORTING $(SRCS) $(HDRS) \
- Makefile.std file.man magic.man magic2mime $(AUTOSRC)
-ALLMAGIC = Magdir/Makefile Magdir/Localstuff Magdir/Header Magdir/[a-z]*
+ Makefile.std file.man magic.man magic2mime $(AUTOSRC) \
+ Localstuff Header
+ALLMAGIC = Magdir/[a-z]*
all: file magic file.${MANCEXT} magic.${MANFEXT}
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $@
lint: $(SRCS)
lint -ha $(DEFS) $(SRCS) | tee $@
-magic: Magdir
-# Magdir/Makefile's "install" mv's magic to here for testing.
- cd Magdir; $(MAKE) install
+magic: Header Localstuff Magdir
+ cat Header Localstuff Magdir/[a-z]* > $@
ascmagic.o: names.h
# Makefile for file(1) cmd.
# Copyright (c) Ian F. Darwin 86/09/01 - see LEGAL.NOTICE.
-# @(#)$Id: Makefile.std,v 1.4 1998/06/27 14:01:39 christos Exp $
+# @(#)$Id: Makefile.std,v 1.5 1998/09/12 13:17:52 christos Exp $
#
# This software is not subject to any license of the American Telephone
# and Telegraph Company or of the Regents of the University of California.
# ever read sources, credits must appear in the documentation.
#
# 4. This notice may not be removed or altered.
-VERSION = 3.25
+VERSION = 3.26
SHELL = /bin/sh
#MAGIC = /etc/magic
MAGIC = /usr/local/etc/magic
AUTOSRC=configure configure.in install-sh config.h.in Makefile.in
ALLSRC = LEGAL.NOTICE README MAINT PORTING $(SRCS) $(HDRS) \
- Makefile.std file.man magic.man magic2mime $(AUTOSRC)
-ALLMAGIC = Magdir/Makefile Magdir/Localstuff Magdir/Header Magdir/[a-z]*
+ Makefile.std file.man magic.man magic2mime $(AUTOSRC) \
+ Localstuff Header
+ALLMAGIC = Magdir/[a-z]*
all: file magic file.${MANCEXT} magic.${MANFEXT}
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $@
lint: $(SRCS)
lint -ha $(DEFS) $(SRCS) | tee $@
-magic: Magdir
-# Magdir/Makefile's "install" mv's magic to here for testing.
- cd Magdir; $(MAKE) install
+magic: Localstuff Header Magdir
+ cat Header Localstuff Magdir/[a-z] > $@
ascmagic.o: names.h
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: apprentice.c,v 1.27 1998/06/27 13:57:23 christos Exp $")
+FILE_RCSID("@(#)$Id: apprentice.c,v 1.28 1998/09/12 13:17:52 christos Exp $")
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
*/
if (*l == '.') {
l++;
- switch (LOWCASE(*l)) {
+ switch (*l) {
case 'l':
- m->in.type = LONG;
+ m->in.type = LELONG;
+ break;
+ case 'L':
+ m->in.type = BELONG;
break;
case 'h':
case 's':
- m->in.type = SHORT;
+ m->in.type = LESHORT;
+ break;
+ case 'H':
+ case 'S':
+ m->in.type = BESHORT;
break;
case 'c':
case 'b':
+ case 'C':
+ case 'B':
m->in.type = BYTE;
break;
default:
#include <sys/param.h> /* for MAXPATHLEN */
#include <sys/stat.h>
#include <fcntl.h> /* for open() */
-#if (__COHERENT__ >= 0x420)
-# include <sys/utime.h>
-#else
-# ifdef USE_UTIMES
-# include <sys/time.h>
+#ifdef RESTORE_TIME
+# if (__COHERENT__ >= 0x420)
+# include <sys/utime.h>
# else
-# include <utime.h>
+# ifdef USE_UTIMES
+# include <sys/time.h>
+# else
+# include <utime.h>
+# endif
# endif
#endif
#include <unistd.h> /* for read() */
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: file.c,v 1.41 1998/06/27 13:57:23 christos Exp $")
+FILE_RCSID("@(#)$Id: file.c,v 1.42 1998/09/12 13:17:52 christos Exp $")
#endif /* lint */
#ifdef RESTORE_TIME
/*
* Try to restore access, modification times if read it.
+ * This is really *bad* because it will modify the status
+ * time of the file... And of course this will affect
+ * backup programs
*/
# ifdef USE_UTIMES
struct timeval utsbuf[2];
*
* See LEGAL.NOTICE
*
- * $Id: names.h,v 1.14 1998/06/27 13:57:23 christos Exp $
+ * $Id: names.h,v 1.15 1998/09/12 13:17:52 christos Exp $
*/
/* these types are used to index the table 'types': keep em in sync! */
#define L_NEWS 9 /* Usenet Netnews */
#define L_JAVA 10 /* Java code */
#define L_HTML 11 /* HTML */
+#define L_BCPL 12 /* BCPL */
static const char *types[] = {
"C program text",
"news text",
"Java program text",
"HTML document text",
+ "BCPL program text",
"can't happen error on names.h/types",
0};
/* These must be sorted by eye for optimal hit rate */
/* Add to this list only after substantial meditation */
{"import", L_JAVA},
+ {"\"libhdr\"", L_BCPL},
+ {"\"LIBHDR\"", L_BCPL},
{"//", L_CC},
{"template", L_CC},
{"virtual", L_CC},
#include <errno.h>
#ifdef HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
#endif
#include "readelf.h"
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: readelf.c,v 1.8 1998/06/27 13:57:23 christos Exp $")
+FILE_RCSID("@(#)$Id: readelf.c,v 1.9 1998/09/12 13:21:01 christos Exp $")
#endif
+#ifdef ELFCORE
+static void dophn_core __P((int, off_t, int, size_t, char *));
+#endif
+static void dophn_exec __P((int, off_t, int, size_t, char *));
+static void doshn __P((int, off_t, int, size_t, char *));
+
static void
doshn(fd, off, num, size, buf)
int fd;
{
/* I am not sure if this works for 64 bit elf formats */
Elf32_Phdr *ph = (Elf32_Phdr *) buf;
+ char *linking_style = "statically";
+ char *shared_libraries = "";
if (lseek(fd, off, SEEK_SET) == -1)
error("lseek failed (%s).\n", strerror(errno));
for ( ; num; num--) {
if (read(fd, buf, size) == -1)
error("read failed (%s).\n", strerror(errno));
- if (ph->p_type == PT_INTERP) {
- /*
- * Has an interpreter - must be a dynamically-linked
- * executable.
- */
- printf(", dynamically linked");
- return;
+
+ switch (ph->p_type) {
+ case PT_DYNAMIC:
+ linking_style = "dynamically";
+ break;
+ case PT_INTERP:
+ shared_libraries = " (uses shared libs)";
+ break;
}
}
- printf(", statically linked");
+ printf(", %s linked%s", linking_style, shared_libraries);
}
+#ifdef ELFCORE
size_t prpsoffsets[] = {
84, /* SunOS 5.x */
32, /* Linux */
}
}
}
+#endif
void
tryelf(fd, buf, nbytes)
*/
if ((u.c[sizeof(long) - 1] + 1) == elfhdr.e_ident[5]) {
if (elfhdr.e_type == ET_CORE)
+#ifdef ELFCORE
dophn_core(fd, elfhdr.e_phoff, elfhdr.e_phnum,
elfhdr.e_phentsize, buf);
+#else
+ ;
+#endif
else {
if (elfhdr.e_type == ET_EXEC) {
- dophn_exec(fd, elfhdr.e_phoff,
- elfhdr.e_phnum,
- elfhdr.e_phentsize, buf);
+ dophn_exec(fd,
+ elfhdr.e_phoff,
+ elfhdr.e_phnum,
+ elfhdr.e_phentsize, buf);
}
doshn(fd, elfhdr.e_shoff, elfhdr.e_shnum,
elfhdr.e_shentsize, buf);
* byte order....
*/
if ((u.c[sizeof(long) - 1] + 1) == elfhdr.e_ident[5]) {
-#ifdef notyet
if (elfhdr.e_type == ET_CORE)
- dophn_core(fd, elfhdr.e_phoff[1],
+#ifdef ELFCORE
+ dophn_core(fd,
+#ifndef __GNUC__
+ elfhdr.e_phoff[1],
+#else
+ elfhdr.e_phoff,
+#endif
elfhdr.e_phnum,
elfhdr.e_phentsize, buf);
- else
+#else
+ ;
#endif
+ else
{
-#ifdef notyet
if (elfhdr.e_type == ET_EXEC) {
- dophn_exec(fd, elfhdr.e_phoff[1],
+ dophn_exec(fd,
+#ifndef __GNUC__
+ elfhdr.e_phoff[1],
+#else
+ elfhdr.e_phoff,
+#endif
elfhdr.e_phnum,
elfhdr.e_phentsize, buf);
}
+ doshn(fd,
+#ifndef __GNUC__
+ elfhdr.e_shoff[1],
+#else
+ elfhdr.e_shoff,
#endif
- doshn(fd, elfhdr.e_shoff[1],
elfhdr.e_shnum,
elfhdr.e_shentsize, buf);
}
/*
* readelf.h
- * @(#)$Id: readelf.h,v 1.5 1998/06/27 13:57:23 christos Exp $
+ * @(#)$Id: readelf.h,v 1.6 1998/09/12 13:21:01 christos Exp $
*
* Provide elf data structures for non-elf machines, allowing file
* non-elf hosts to determine if an elf binary is stripped.
#define __fake_elf_h__
typedef unsigned int Elf32_Addr;
-typedef unsigned short Elf32_Half;
typedef unsigned int Elf32_Off;
+typedef unsigned short Elf32_Half;
typedef unsigned int Elf32_Word;
typedef unsigned char Elf32_Char;
+#ifdef __GNUC__
+typedef unsigned long long Elf64_Addr;
+typedef unsigned long long Elf64_Off;
+#else
/* XXX: We need 64 bit numbers here */
typedef unsigned int Elf64_Addr[2];
-typedef unsigned short Elf64_Half;
typedef unsigned int Elf64_Off[2];
+#endif
+typedef unsigned short Elf64_Half;
typedef unsigned int Elf64_Word;
typedef unsigned char Elf64_Char;
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: softmagic.c,v 1.37 1998/06/27 13:23:39 christos Exp $")
+FILE_RCSID("@(#)$Id: softmagic.c,v 1.38 1998/09/12 13:21:01 christos Exp $")
#endif /* lint */
static int match __P((unsigned char *, int));
mdump(m);
}
- if (!mconvert(p, m))
- return 0;
-
if (m->flag & INDIR) {
switch (m->in.type) {
case BYTE:
offset = p->b + m->in.offset;
break;
+ case BESHORT:
+ offset = (short)((p->hs[0]<<8)|(p->hs[1]))+
+ m->in.offset;
+ break;
+ case LESHORT:
+ offset = (short)((p->hs[1]<<8)|(p->hs[0]))+
+ m->in.offset;
+ break;
case SHORT:
offset = p->h + m->in.offset;
break;
+ case BELONG:
+ offset = (int32)((p->hl[0]<<24)|(p->hl[1]<<16)|
+ (p->hl[2]<<8)|(p->hl[3]))+
+ m->in.offset;
+ break;
+ case LELONG:
+ offset = (int32)((p->hl[3]<<24)|(p->hl[2]<<16)|
+ (p->hl[1]<<8)|(p->hl[0]))+
+ m->in.offset;
+ break;
case LONG:
offset = p->l + m->in.offset;
break;
mdebug(offset, (char *) p, sizeof(union VALUETYPE));
mdump(m);
}
-
- if (!mconvert(p, m))
- return 0;
}
+ if (!mconvert(p, m))
+ return 0;
return 1;
}