Rev 7696 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7696 | Rev 7983 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | (* |
1 | (* |
2 | BSD 2-Clause License |
2 | BSD 2-Clause License |
Line 3... | Line 3... | ||
3 | 3 | ||
4 | Copyright (c) 2018-2019, Anton Krotov |
4 | Copyright (c) 2018-2020, Anton Krotov |
5 | All rights reserved. |
5 | All rights reserved. |
Line 6... | Line 6... | ||
6 | *) |
6 | *) |
Line 43... | Line 43... | ||
43 | BEGIN |
43 | BEGIN |
44 | reloc := program.rel_list.first(BIN.RELOC); |
44 | reloc := program.rel_list.first(BIN.RELOC); |
45 | WHILE reloc # NIL DO |
45 | WHILE reloc # NIL DO |
Line 46... | Line 46... | ||
46 | 46 | ||
47 | CASE reloc.opcode OF |
- | |
48 | 47 | CASE reloc.opcode OF |
|
49 | |BIN.RIMP, BIN.IMPTAB: |
48 | |BIN.RIMP, |
50 | WriteReloc(File, reloc.offset, 4, 6) |
- | |
51 | - | ||
52 | |BIN.RBSS: |
49 | BIN.IMPTAB: WriteReloc(File, reloc.offset, 4, 6) |
53 | WriteReloc(File, reloc.offset, 5, 6) |
- | |
54 | - | ||
55 | |BIN.RDATA: |
50 | |BIN.RBSS: WriteReloc(File, reloc.offset, 5, 6) |
56 | WriteReloc(File, reloc.offset, 2, 6) |
- | |
57 | - | ||
58 | |BIN.RCODE: |
51 | |BIN.RDATA: WriteReloc(File, reloc.offset, 2, 6) |
59 | WriteReloc(File, reloc.offset, 1, 6) |
- | |
60 | 52 | |BIN.RCODE: WriteReloc(File, reloc.offset, 1, 6) |
|
Line 61... | Line 53... | ||
61 | END; |
53 | END; |
62 | 54 | ||
63 | reloc := reloc.next(BIN.RELOC) |
55 | reloc := reloc.next(BIN.RELOC) |
Line 68... | Line 60... | ||
68 | PROCEDURE RelocCount (program: BIN.PROGRAM): INTEGER; |
60 | PROCEDURE RelocCount (program: BIN.PROGRAM): INTEGER; |
69 | VAR |
61 | VAR |
70 | reloc: BIN.RELOC; |
62 | reloc: BIN.RELOC; |
71 | iproc: BIN.IMPRT; |
63 | iproc: BIN.IMPRT; |
72 | res, L: INTEGER; |
64 | res, L: INTEGER; |
- | 65 | code: CHL.BYTELIST; |
|
Line 73... | Line 66... | ||
73 | 66 | ||
74 | BEGIN |
67 | BEGIN |
- | 68 | res := 0; |
|
75 | res := 0; |
69 | code := program.code; |
76 | reloc := program.rel_list.first(BIN.RELOC); |
70 | reloc := program.rel_list.first(BIN.RELOC); |
Line 77... | Line 71... | ||
77 | WHILE reloc # NIL DO |
71 | WHILE reloc # NIL DO |
Line 78... | Line 72... | ||
78 | 72 | ||
79 | INC(res); |
73 | INC(res); |
80 | 74 | ||
81 | IF reloc.opcode = BIN.RIMP THEN |
75 | IF reloc.opcode = BIN.RIMP THEN |
82 | L := BIN.get32le(program.code, reloc.offset); |
76 | L := BIN.get32le(code, reloc.offset); |
Line 83... | Line 77... | ||
83 | iproc := BIN.GetIProc(program, L); |
77 | iproc := BIN.GetIProc(program, L); |
84 | BIN.put32le(program.code, reloc.offset, iproc.label) |
78 | BIN.put32le(code, reloc.offset, iproc.label) |
85 | END; |
79 | END; |
86 | 80 | ||
Line 87... | Line 81... | ||
87 | IF reloc.opcode = BIN.RCODE THEN |
81 | IF reloc.opcode = BIN.RCODE THEN |
88 | L := BIN.get32le(program.code, reloc.offset); |
82 | L := BIN.get32le(code, reloc.offset); |
Line 157... | Line 151... | ||
157 | ecount := CHL.Length(program.export); |
151 | ecount := CHL.Length(program.export); |
Line 158... | Line 152... | ||
158 | 152 | ||
159 | FileHeader.Machine := 014CX; |
153 | FileHeader.Machine := 014CX; |
160 | FileHeader.NumberOfSections := 5X; |
154 | FileHeader.NumberOfSections := 5X; |
161 | FileHeader.TimeDateStamp := UTILS.UnixTime(); |
155 | FileHeader.TimeDateStamp := UTILS.UnixTime(); |
162 | //FileHeader.PointerToSymbolTable := 0; |
156 | (* FileHeader.PointerToSymbolTable := 0; *) |
163 | FileHeader.NumberOfSymbols := 6; |
157 | FileHeader.NumberOfSymbols := 6; |
164 | FileHeader.SizeOfOptionalHeader := 0X; |
158 | FileHeader.SizeOfOptionalHeader := 0X; |
Line 165... | Line 159... | ||
165 | FileHeader.Characteristics := 0184X; |
159 | FileHeader.Characteristics := 0184X; |
166 | 160 | ||
167 | flat.Name := ".flat"; |
161 | flat.Name := ".flat"; |
168 | flat.VirtualSize := 0; |
162 | flat.VirtualSize := 0; |
169 | flat.VirtualAddress := 0; |
163 | flat.VirtualAddress := 0; |
170 | flat.SizeOfRawData := ccount; |
164 | flat.SizeOfRawData := ccount; |
171 | flat.PointerToRawData := ORD(FileHeader.NumberOfSections) * PE32.SIZE_OF_IMAGE_SECTION_HEADER + PE32.SIZE_OF_IMAGE_FILE_HEADER; |
165 | flat.PointerToRawData := ORD(FileHeader.NumberOfSections) * PE32.SIZE_OF_IMAGE_SECTION_HEADER + PE32.SIZE_OF_IMAGE_FILE_HEADER; |
172 | //flat.PointerToRelocations := 0; |
166 | (* flat.PointerToRelocations := 0; *) |
173 | flat.PointerToLinenumbers := 0; |
167 | flat.PointerToLinenumbers := 0; |
174 | SetNumberOfRelocations(flat, RelocCount(program)); |
168 | SetNumberOfRelocations(flat, RelocCount(program)); |
Line 189... | Line 183... | ||
189 | edata.Name := ".edata"; |
183 | edata.Name := ".edata"; |
190 | edata.VirtualSize := 0; |
184 | edata.VirtualSize := 0; |
191 | edata.VirtualAddress := 0; |
185 | edata.VirtualAddress := 0; |
192 | edata.SizeOfRawData := ((ExpCount + 1) * 2 + 1) * SIZE_OF_DWORD + LENGTH(szversion) + 1 + ecount; |
186 | edata.SizeOfRawData := ((ExpCount + 1) * 2 + 1) * SIZE_OF_DWORD + LENGTH(szversion) + 1 + ecount; |
193 | edata.PointerToRawData := data.PointerToRawData + data.SizeOfRawData; |
187 | edata.PointerToRawData := data.PointerToRawData + data.SizeOfRawData; |
194 | //edata.PointerToRelocations := 0; |
188 | (* edata.PointerToRelocations := 0; *) |
195 | edata.PointerToLinenumbers := 0; |
189 | edata.PointerToLinenumbers := 0; |
196 | SetNumberOfRelocations(edata, ExpCount * 2 + 1); |
190 | SetNumberOfRelocations(edata, ExpCount * 2 + 1); |
197 | edata.NumberOfLinenumbers := 0X; |
191 | edata.NumberOfLinenumbers := 0X; |
198 | edata.Characteristics := SHC_data; |
192 | edata.Characteristics := SHC_data; |
Line 199... | Line 193... | ||
199 | 193 | ||
200 | idata.Name := ".idata"; |
194 | idata.Name := ".idata"; |
201 | idata.VirtualSize := 0; |
195 | idata.VirtualSize := 0; |
202 | idata.VirtualAddress := 0; |
196 | idata.VirtualAddress := 0; |
203 | idata.SizeOfRawData := isize; |
197 | idata.SizeOfRawData := isize; |
204 | idata.PointerToRawData := edata.PointerToRawData + edata.SizeOfRawData; |
198 | idata.PointerToRawData := edata.PointerToRawData + edata.SizeOfRawData; |
205 | //idata.PointerToRelocations := 0; |
199 | (* idata.PointerToRelocations := 0; *) |
206 | idata.PointerToLinenumbers := 0; |
200 | idata.PointerToLinenumbers := 0; |
207 | SetNumberOfRelocations(idata, ICount(ImportTable, ILen)); |
201 | SetNumberOfRelocations(idata, ICount(ImportTable, ILen)); |
208 | idata.NumberOfLinenumbers := 0X; |
202 | idata.NumberOfLinenumbers := 0X; |