Utilize doshunks.h & a.out.h. Use ntohx macros.

This commit is contained in:
Krystian Bacławski 2012-02-16 19:31:44 -08:00
parent e2ba3b77c5
commit a71ca84c27
3 changed files with 32 additions and 67 deletions

View File

@ -49,6 +49,8 @@
#include "defs.h"
typedef struct nlist BSD_SYM;
static int ExeFile,NbOffs;
static int32_t *SearchOffs;
@ -153,13 +155,13 @@ void GetLines (int32_t symsz, BSD_SYM *syms, int32_t string_offset)
int i;
while (nbsyms--) {
switch (sym->type) {
switch (sym->n_type) {
case N_SO:
case N_SOL:
srcname = GETLONG (sym->strx);
srcname = GETLONG (sym->n_un.n_strx);
break;
case N_SLINE:
offs = OFFSET_N_SLINE (GETLONG (sym->value));
offs = OFFSET_N_SLINE (GETLONG (sym->n_value));
for (i = 0; i < NbOffs; i++) {
if (SearchOffs[i] >= prev_offs && SearchOffs[i] < offs) {
printf ("%s: line %hd, offset 0x%x\n", get_string(prev_src +
@ -167,11 +169,11 @@ void GetLines (int32_t symsz, BSD_SYM *syms, int32_t string_offset)
}
}
prev_offs = offs;
prev_line = GETWORD (sym->desc);
prev_line = GETWORD (sym->n_desc);
prev_src = srcname;
break;
}
prev_type = sym->type;
prev_type = sym->n_type;
sym++;
}
/* the last SLINE is a special case */
@ -199,15 +201,15 @@ void HunkDebug (void)
strsz = GETLONG (hdr.strsz);
symsz = GETLONG (hdr.symsz);
if (strsz + symsz != 0) {
syms = (char*)malloc (symsz);
if (syms) {
if (read (ExeFile, syms, symsz) == symsz) {
pos = lseek(ExeFile, strsz, SEEK_CUR);
syms = (char*)malloc (symsz);
if (syms) {
if (read (ExeFile, syms, symsz) == symsz) {
pos = lseek(ExeFile, strsz, SEEK_CUR);
if (pos > 0)
GetLines (symsz, (BSD_SYM*)syms, pos - strsz);
}
free (syms);
}
GetLines (symsz, (BSD_SYM*)syms, pos - strsz);
}
free (syms);
}
}
}
}
@ -239,9 +241,9 @@ void DoHunks (struct Header *h)
case HUNK_RELOC32:
case HUNK_RELOC16:
case HUNK_RELOC8:
case HUNK_DRELOC32:
case HUNK_DRELOC16:
case HUNK_DRELOC8:
case HUNK_DREL32:
case HUNK_DREL16:
case HUNK_DREL8:
SkipRelocation();
break;
case HUNK_RELOC32SHORT:

View File

@ -5,7 +5,7 @@ BINS = GccFindHit hunk2aout
all: $(BINS)
GccFindHit.o: GccFindHit.c defs.h
GccFindHit.o: GccFindHit.c defs.h a.out.h
hunk2aout.o: hunk2aout.c a.out.h
clean:

View File

@ -4,20 +4,19 @@
* See the file COPYING for information about the GPL
*/
#if BYTE_ORDER==LITTLE_ENDIAN
/* reverse for endianness */
#define GETLONG(x) ((((((x)&0xff)<<8) | (((x)&0xff00)>>8))<<16) | \
(((((x)&0xff000000)>>8)&0x00ff0000) | \
((x)&0x00ff0000)<<8)>>16)
#define GETWORD(x) ((((x)&0xff)<<8) | ((((x)&0xff00)>>8)&0xff))
#else
#define GETLONG(x) (x)
#define GETWORD(x) (x)
#endif
#ifndef _DEFS_H_
#define _DEFS_H_
#define ZMAGIC 0x10b /* demand-paged executable */
#define N_SO 0x64
#define N_SOL 0x84
#include <arpa/inet.h>
#include <dos/doshunks.h>
#include "a.out.h"
#define GETWORD(x) ntohs(x)
#define GETLONG(x) ntohl(x)
#define N_SO 0x64
#define N_SOL 0x84
#define N_SLINE 0x44
/* Converts an SLINE value to an offset in the text section.
@ -25,35 +24,6 @@
but you may change that for another linker */
#define OFFSET_N_SLINE(x) (x)
enum {
HUNK_UNIT=0x3e7,
HUNK_NAME,
HUNK_CODE,
HUNK_DATA,
HUNK_BSS,
HUNK_RELOC32,
HUNK_RELOC16,
HUNK_RELOC8,
HUNK_EXT,
HUNK_SYMBOL,
HUNK_DEBUG,
HUNK_END,
HUNK_HEADER,
HUNK_3F4, /* ? */
HUNK_OVERLAY,
HUNK_BREAK,
HUNK_DRELOC32,
HUNK_DRELOC16,
HUNK_DRELOC8,
HUNK_3FA, /* ? */
HUNK_LIB,
/* AmigaOS Manual 3rd ed. takes 0x3fc for both HUNK_INDEX and
HUNK_RELOC32SHORT. I don't know if it's an error or something;
anyway, there shouldn't be HUNK_INDEX in executable files, so
let's take the other one */
HUNK_RELOC32SHORT
};
/* amigaos hunk header structure */
struct Header {
int32_t nb_hunks;
@ -69,11 +39,4 @@ struct bsd_header{
int32_t strsz;
};
typedef struct {
int32_t strx;
uint8_t type;
uint8_t other;
uint16_t desc;
int32_t value;
} BSD_SYM;
#endif