-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathelf64.cul
More file actions
98 lines (87 loc) · 3.17 KB
/
Copy pathelf64.cul
File metadata and controls
98 lines (87 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
( $Id: elf64.cul,v 1.2 2019/11/05 12:16:02 albert Exp $ )
( Copyright{2004}: Albert van der Horst, HCC FIG Holland by GNU Public License)
HEX
0 -ORG- \ Preliminary, to analyse header
0 B@ 7F <> "Fatal, not an elf header!" ?ABORT
1 TARGET>HOST 3 "ELF" $= 0 = "Fatal, not an elf header!" ?ABORT
4 TARGET>HOST C@ 2 <> "Fatal, this file for 64 bit!" ?ABORT
5 TARGET>HOST C@ 1 <> "Fatal, this file for big endian!" ?ABORT
'\ ALIAS \D \ Comment out for debugging.
0 ( e_ident)
\ Cell size for elf 32/64 , also determines header format.
DUP LABEL e_ident 10 +
DUP LABEL e_type 2 +
DUP LABEL e_machine 2 +
DUP LABEL e_version 4 +
DUP LABEL e_entry 8 +
DUP LABEL e_phoff 8 +
DUP LABEL e_shoff 8 +
DUP LABEL e_flags 4 +
DUP LABEL e_ehsize 2 +
DUP LABEL e_phentsize 2 +
DUP LABEL e_phnum 2 +
DUP LABEL e_shentsize 2 +
DUP LABEL e_shnum 2 +
DUP LABEL e_shstrndx 2 +
LABEL e_headerend
\D
\D e_ident TARGET>HOST ." e_ident " CR 10 DUMP
\D e_type W@ ." e_type " . CR
\D e_machine W@ ." e_machine " . CR
\D e_version L@ ." e_version " . CR
\D e_entry Q@ ." e_entry " . CR
\D e_phoff Q@ ." e_phoff " . CR
\D e_shoff Q@ ." e_shoff " . CR
\D e_flags L@ ." e_flags " . CR
\D e_ehsize W@ ." e_ehsize " . CR
\D e_phentsize W@ ." e_phentsize " . CR
\D e_phnum W@ ." e_phnum " . CR
\D e_shentsize W@ ." e_shentsize " . CR
\D e_shnum W@ ." e_shnum " . CR
\D e_shstrndx W@ ." e_shstrndx " . CR
e_phoff Q@ \ Where the programheader starts
DUP 0= "Not a program, cidis can't handle multiple segments" ?ABORT
DUP LABEL p_type 4 +
DUP LABEL p_flags 4 +
DUP LABEL p_offset 8 +
DUP LABEL p_vaddr 8 +
DUP LABEL p_paddr 8 +
DUP LABEL p_filesz 8 +
DUP LABEL p_memsz 8 +
DUP LABEL p_align 4 +
LABEL p_headerend
\D p_type L@ ." p_type " . CR
\D p_offset Q@ ." p_offset " . CR
\D p_vaddr Q@ ." p_vaddr " . CR
\D p_paddr Q@ ." p_paddr " . CR
\D p_filesz Q@ ." p_filesz " . CR
\D p_memsz Q@ ." p_memsz " . CR
\D p_flags L@ ." p_flags " . CR
\D p_align L@ ." p_align " . CR
\D MAKE-CUL
p_vaddr Q@ p_offset Q@ - -ORG-
\ Correct the labels to have the target position.
\ Note that the value of the label was stored at 2 places,
\ this may be a design error.
: test EQU-LABELS DO-LAB
TARGET-START I +! TARGET-START I CELL+ @ >DFA +!
LOOP-LAB ; test
e_ident DUP 10 + -d$-
e_type e_version -dw-
e_version e_entry -dl-
e_entry e_flags -dq-
e_flags e_ehsize -dl-
e_ehsize e_headerend -dw-
\ Important size derived from the header.
p_filesz Q@ EQU filesz
p_vaddr Q@ EQU filest
filest filesz + LABEL _end
e_entry Q@ LABEL _start
\ TODO split in dl/dq
p_type p_offset -dl-
p_offset p_align -dq-
p_align _start -dl-
\ Crawl using elf's information. In rare case it is ill-advised
\ to do it automatically.
: ELF-CRAWL _start CRAWL ;
"ASSEMBLER BITS-64" START-DIRECTIVE $!