-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXbe.cpp
More file actions
632 lines (516 loc) · 23.3 KB
/
Xbe.cpp
File metadata and controls
632 lines (516 loc) · 23.3 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
// ******************************************************************
// *
// * .,-::::: .,:: .::::::::. .,:: .:
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
// * $$$ Y$$$P $$""""Y$$ Y$$$P
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
// *
// * Cxbx->Core->Xbe.cpp
// *
// * This file is part of the Cxbx project.
// *
// * Cxbx and Cxbe are free software; you can redistribute them
// * and/or modify them under the terms of the GNU General Public
// * License as published by the Free Software Foundation; either
// * version 2 of the license, or (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have recieved a copy of the GNU General Public License
// * along with this program; see the file COPYING.
// * If not, write to the Free Software Foundation, Inc.,
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
// *
// * (c) 2002-2003 Aaron Robinson <caustik@caustik.com>
// *
// * All rights reserved
// *
// ******************************************************************
#include "Xbe.h"
#include "MicroExe.h"
#include <memory.h>
#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <windows.h>
#define XBE_ERROR(str, ...) do \
{ \
printf("\nError in Xbe::Xbe: " str "\n", __VA_ARGS__); \
if (XbeFile != 0) \
fclose(XbeFile); \
exit(1); \
} while(0)
#define XBE_PATCH_ERROR(str, ...) do \
{ \
printf("\nError in Xbe::PatchExe: " str "\n", __VA_ARGS__); \
return 1; \
} while(0)
#define XBE_WRITE_ERROR(str, ...) do \
{ \
printf("\nError in Xbe::WriteExe: " str "\n", __VA_ARGS__); \
if (ExeBuffer != 0) \
delete [] ExeBuffer; \
return 1; \
} while(0)
// ******************************************************************
// * Signature for MapRegisters patch and the replacing code
// ******************************************************************
#define PATCH_LENGTH 11
static uint08 PatchSignature[] =
"\xC7\x01\x00\x00\x00\xFD"
"\xA1\x04\x18\x00\xFD";
static void __declspec(naked) PatchCode()
{
__asm
{
mov dword ptr [ecx], 0x84000000
xor eax, eax
inc eax
ret
int 3
}
}
// ******************************************************************
// * Trampoline that will be located at entry point
// ******************************************************************
#define TRAMPOLINE_LENGTH 10
static void __declspec(naked) TrampolineCode()
{
__asm
{
mov edx, 0x000100EC
call dword ptr [edx]
ret
nop
nop
}
}
// ******************************************************************
// * constructor
// ******************************************************************
Xbe::Xbe(const char *Filename)
{
HeaderEx = 0;
HeaderExSize = 0;
SectionHeader = 0;
SectionName = 0;
LibraryVersion = 0;
KernelLibraryVersion = 0;
XapiLibraryVersion = 0;
Tls = 0;
Section = 0;
printf("Xbe::Xbe: Opening Xbe file...");
FILE *XbeFile = fopen(Filename, "rb");
if(XbeFile == 0)
XBE_ERROR("Could not open Xbe file.");
printf("OK\n");
// ******************************************************************
// * remember xbe path
// ******************************************************************
{
printf("Xbe::Xbe Storing Xbe Path...");
strcpy(Path, Filename);
int v = 0, c = 0;
while(Path[v] != '\0')
{
if(Path[v] == '\\')
c = v + 1;
v++;
}
Path[c] = '\0';
}
printf("OK\n");
// ******************************************************************
// * read xbe image header
// ******************************************************************
{
printf("Xbe::Xbe: Reading Image Header...");
if(fread(&Header, sizeof(Xbe::HEADER), 1, XbeFile) != 1)
XBE_ERROR("Unexpected end of file while reading Xbe Image Header");
if(Header.Magic != *(uint32 *)"XBEH")
XBE_ERROR("Invalid magic number in Xbe file");
printf("OK\n");
}
// ******************************************************************
// * read xbe image header extra bytes
// ******************************************************************
if(Header.SizeOfHeaders > sizeof(Xbe::HEADER))
{
printf("Xbe::Xbe: Reading Image Header Extra Bytes...");
uint32 HeaderExSize = RoundUp(Header.SizeOfHeaders, PAGE_SIZE) - sizeof(Header);
HeaderEx = new char[HeaderExSize];
if(fread(HeaderEx, HeaderExSize, 1, XbeFile) != 1)
XBE_ERROR("Unexpected end of file while reading Xbe Image Header (Ex)");
printf("OK\n");
}
// ******************************************************************
// * read xbe certificate
// ******************************************************************
{
printf("Xbe::Xbe: Reading Certificate...");
fseek(XbeFile, Header.CertificateAddr - Header.BaseAddr, SEEK_SET);
if(fread(&Certificate, sizeof(Xbe::CERTIFICATE), 1, XbeFile) != 1)
XBE_ERROR("Unexpected end of file while reading Xbe Certificate");
setlocale(LC_ALL, "English");
wcstombs(AsciiTitle, Certificate.TitleName, 40);
printf("OK\n");
printf("Xbe::Xbe: Title identified as %s\n", AsciiTitle);
}
// ******************************************************************
// * read xbe section headers
// ******************************************************************
{
printf("Xbe::Xbe: Reading Section Headers...\n");
fseek(XbeFile, Header.SectionHeadersAddr - Header.BaseAddr, SEEK_SET);
SectionHeader = new Xbe::SECTION_HEADER[Header.Sections];
for(uint32 v = 0; v < Header.Sections; v++)
{
printf("Xbe::Xbe: Reading Section Header 0x%.04X...", v);
if(fread(&SectionHeader[v], sizeof(Xbe::SECTION_HEADER), 1, XbeFile) != 1)
XBE_ERROR("Unexpected end of file while reading Xbe Section Header %d (%Xh)", v, v);
printf("OK\n");
}
}
// ******************************************************************
// * read xbe section names
// ******************************************************************
{
printf("Xbe::Xbe: Reading Section Names...\n");
SectionName = new char[Header.Sections][9];
for(uint32 v = 0; v < Header.Sections; v++)
{
printf("Xbe::Xbe: Reading Section Name 0x%.04X...", v);
uint08 *sn = GetAddr(SectionHeader[v].SectionNameAddr);
memset(SectionName[v], 0, 9);
if(sn != 0)
{
for(int b = 0; b < 8; b++)
{
SectionName[v][b] = sn[b];
if(SectionName[v][b] == '\0')
break;
}
}
printf("OK (%s)\n", SectionName[v]);
}
}
// ******************************************************************
// * read xbe library versions
// ******************************************************************
if(Header.LibraryVersionsAddr != 0)
{
printf("Xbe::Xbe: Reading Library Versions...\n");
fseek(XbeFile, Header.LibraryVersionsAddr - Header.BaseAddr, SEEK_SET);
LibraryVersion = new Xbe::LIBRARY_VERSION[Header.LibraryVersions];
for(uint32 v = 0; v < Header.LibraryVersions; v++)
{
printf("Xbe::Xbe: Reading Library Version 0x%.04X...", v);
if(fread(&LibraryVersion[v], sizeof(Xbe::LIBRARY_VERSION), 1, XbeFile) != 1)
XBE_ERROR("Unexpected end of file while reading Xbe Library Version %d (%Xh)", v, v);
printf("OK\n");
}
// ******************************************************************
// * read xbe kernel library version
// ******************************************************************
{
printf("Xbe::Xbe: Reading Kernel Library Version...");
if(Header.KernelLibraryVersionAddr == 0)
XBE_ERROR("Could not locate kernel library version");
fseek(XbeFile, Header.KernelLibraryVersionAddr - Header.BaseAddr, SEEK_SET);
KernelLibraryVersion = new Xbe::LIBRARY_VERSION;
if(fread(KernelLibraryVersion, sizeof(Xbe::LIBRARY_VERSION), 1, XbeFile) != 1)
XBE_ERROR("Unexpected end of file while reading Xbe Kernel Version");
printf("OK\n");
}
// ******************************************************************
// * read xbe xapi library version
// ******************************************************************
{
printf("Xbe::Xbe: Reading Xapi Library Version...");
if(Header.XapiLibraryVersionAddr == 0)
XBE_ERROR("Could not locate Xapi Library Version", true);
fseek(XbeFile, Header.XapiLibraryVersionAddr - Header.BaseAddr, SEEK_SET);
XapiLibraryVersion = new Xbe::LIBRARY_VERSION;
if(fread(XapiLibraryVersion, sizeof(Xbe::LIBRARY_VERSION), 1, XbeFile) != 1)
XBE_ERROR("Unexpected end of file while reading Xbe Xapi Version", true);
printf("OK\n");
}
}
// ******************************************************************
// * read xbe sections
// ******************************************************************
{
printf("Xbe::Xbe: Reading Sections...\n");
Section = new uint08*[Header.Sections];
memset(Section, 0, Header.Sections);
for(uint32 v = 0; v < Header.Sections; v++)
{
printf("Xbe::Xbe: Reading Section 0x%.04X...", v);
uint32 RawSize = SectionHeader[v].SizeOfRaw;
uint32 RawAddr = SectionHeader[v].RawAddr;
Section[v] = new uint08[RawSize];
fseek(XbeFile, RawAddr, SEEK_SET);
if(RawSize == 0)
{
printf("OK\n");
continue;
}
if(fread(Section[v], RawSize, 1, XbeFile) != 1)
XBE_ERROR("Unexpected end of file while reading Xbe Section %d (%Xh) (%s)", v, v, SectionName[v]);
printf("OK\n");
}
}
// ******************************************************************
// * read xbe thread local storage
// ******************************************************************
if(Header.TlsAddr != 0)
{
printf("Xbe::Xbe: Reading Thread Local Storage...");
void *Addr = GetAddr(Header.TlsAddr);
if(Addr == 0)
XBE_ERROR("Could not locate Thread Local Storage");
Tls = new Xbe::TLS;
memcpy(Tls, Addr, sizeof(Xbe::TLS));
printf("OK\n");
}
fclose(XbeFile);
return;
}
// ******************************************************************
// * deconstructor
// ******************************************************************
Xbe::~Xbe()
{
if(Section != 0)
{
for(uint32 v = 0; v < Header.Sections; v++)
delete[] Section[v];
delete[] Section;
}
delete XapiLibraryVersion;
delete KernelLibraryVersion;
delete[] LibraryVersion;
delete Tls;
delete[] SectionName;
delete[] SectionHeader;
delete[] HeaderEx;
}
// ******************************************************************
// * Patcher
// ******************************************************************
int32 Xbe::PatchXbe()
{
printf("Xbe::PatchExe Patching initialization flags in Xbe...");
Header.InitFlags.MountUtilityDrive = 0;
Header.InitFlags.FormatUtilityDrive = 0;
printf("OK\n");
printf("Xbe::PatchExe Patching MapRegisters in Xbe...");
// ******************************************************************
// * find section with Direct3D code
// ******************************************************************
uint32 v;
for (v = 0; v < Header.Sections; v++)
if (strncmp(SectionName[v], "D3D", 9) == 0)
break;
if (v == Header.Sections)
XBE_PATCH_ERROR("Could not find D3D section");
// ******************************************************************
// * find patching location in D3D section
// ******************************************************************
uint32 i;
for (i = 0; i < SectionHeader[v].SizeOfRaw - PATCH_LENGTH; i++)
if (memcmp(&Section[v][i], PatchSignature, PATCH_LENGTH) == 0)
break;
if (i == SectionHeader[v].SizeOfRaw - PATCH_LENGTH)
XBE_PATCH_ERROR("Could not find signature in D3D section");
// ******************************************************************
// * patch MapRegisters
// ******************************************************************
memcpy(&Section[v][i], &PatchCode, PATCH_LENGTH);
printf("OK\n");
return 0;
}
// ******************************************************************
// * Writer
// ******************************************************************
int32 Xbe::WriteExe(const char *Filename)
{
printf("Xbe::WriteExe Converting Xbe to Exe...");
if (PatchXbe() != 0)
return 1;
// ******************************************************************
// * create buffer for "as-loaded" XBE/EXE hybrid
// ******************************************************************
uint08 *ExeBuffer = new uint08[Header.SizeOfImage];
if (ExeBuffer == 0)
XBE_WRITE_ERROR("Cannot allocate buffer for Exe");
memset(ExeBuffer, 0, Header.SizeOfImage);
// ******************************************************************
// * write xbe section headers
// ******************************************************************
memcpy(ExeBuffer + 0, &Header, sizeof(Xbe::HEADER));
memcpy(ExeBuffer + Header.SizeOfImageHeader, HeaderEx, HeaderExSize);
// ******************************************************************
// * write xbe sections
// ******************************************************************
for (uint32 v = 0; v < Header.Sections; v++)
{
uint32 offs = SectionHeader[v].VirtualAddr - Header.BaseAddr;
memcpy(ExeBuffer + offs, Section[v], SectionHeader[v].SizeOfRaw);
}
// ******************************************************************
// * patch digital signature with PE stub
// ******************************************************************
MICRO_EXE_HEADERS ExeHeaders;
ExeHeaders.DosHeader.Magic = *(uint16 *)"MZ";
ExeHeaders.DosHeader.Unused = 0;
ExeHeaders.Header.Magic = *(uint32 *)"PE\0\0";
ExeHeaders.Header.Machine = IMAGE_FILE_MACHINE_I386;
ExeHeaders.Header.NumberOfSections = 1;
ExeHeaders.Header.TimeDateStamp = Header.TimeDate;
ExeHeaders.Header.PointerToSymbolTable = 0;
ExeHeaders.Header.NumberOfSymbols = 0;
ExeHeaders.Header.SizeOfOptionalHeader = sizeof(MICRO_EXE_HEADERS::OPTIONAL_HEADER);
ExeHeaders.Header.Characteristics =
IMAGE_FILE_RELOCS_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE |
IMAGE_FILE_LARGE_ADDRESS_AWARE | IMAGE_FILE_32BIT_MACHINE;
ExeHeaders.OptionalHeader.Magic = 0x010B;
ExeHeaders.OptionalHeader.MajorLinkerVersion = 0x06;
ExeHeaders.OptionalHeader.MinorLinkerVersion = 0x00;
ExeHeaders.OptionalHeader.SizeOfCode = 0;
ExeHeaders.OptionalHeader.SizeOfInitializedData = 0;
ExeHeaders.OptionalHeader.SizeOfUninitializedData = 0;
ExeHeaders.OptionalHeader.AddressOfEntryPoint = (uint32)&ExeHeaders.Trampoline - (uint32)&ExeHeaders;
ExeHeaders.OptionalHeader.BaseOfCode = 0;
ExeHeaders.OptionalHeader.BaseOfData = 0;
ExeHeaders.OptionalHeader.ImageBase = Header.BaseAddr;
ExeHeaders.OptionalHeader.Lfanew_SectionAlignment = EXE_ALIGNMENT;
ExeHeaders.OptionalHeader.FileAlignment = EXE_ALIGNMENT;
ExeHeaders.OptionalHeader.MajorOperatingSystemVersion = 4;
ExeHeaders.OptionalHeader.MinorOperatingSystemVersion = 0;
// This is where the imported DLL name "DbE\0" will be located
strncpy(ExeHeaders.OptionalHeader.DirtboxDllName, "DbE", 4);
ExeHeaders.OptionalHeader.MajorSubsystemVersion = 4;
ExeHeaders.OptionalHeader.MinorSubsystemVersion = 0;
ExeHeaders.OptionalHeader.Win32VersionValue = 0;
ExeHeaders.OptionalHeader.SizeOfImage = Header.SizeOfImage; // already aligned at 0x20
ExeHeaders.OptionalHeader.SizeOfHeaders = RoundUp(sizeof(MICRO_EXE_HEADERS), EXE_ALIGNMENT);
ExeHeaders.OptionalHeader.CheckSum = 0;
ExeHeaders.OptionalHeader.Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
ExeHeaders.OptionalHeader.DllCharacteristics = 0x400;
ExeHeaders.OptionalHeader.SizeOfStackReserve = 0x100000;
ExeHeaders.OptionalHeader.SizeOfStackCommit = 0x1000;
ExeHeaders.OptionalHeader.SizeOfHeapReserve = 0x100000;
ExeHeaders.OptionalHeader.SizeOfHeapCommit = 0x1000;
ExeHeaders.OptionalHeader.LoaderFlags = 0;
ExeHeaders.OptionalHeader.NumberOfRvaAndSizes = 4;
// ******************************************************************
// * the other directories
// ******************************************************************
for (uint32 v = 0; v < 4; v++)
{
ExeHeaders.OptionalHeader.DataDirectory[v].VirtualAddress = 0;
ExeHeaders.OptionalHeader.DataDirectory[v].Size = 0;
}
// ******************************************************************
// * import directory
// ******************************************************************
uint32 offs = (uint32)&ExeHeaders.ImageImportDescriptor - (uint32)&ExeHeaders;
ExeHeaders.OptionalHeader.DataDirectory[1].VirtualAddress = offs;
ExeHeaders.OptionalHeader.DataDirectory[1].Size =
2*sizeof(MICRO_EXE_HEADERS::IMAGE_IMPORT_DESCRIPTOR);
// ******************************************************************
// * the one and only section header
// ******************************************************************
uint32 XbeSectionAddress = 0; // the whole image
uint32 XbeSectionSize = Header.SizeOfImage - XbeSectionAddress; // already aligned at 0x20
strncpy(ExeHeaders.SectionHeader.Name, "loldong", 8);
ExeHeaders.SectionHeader.VirtualSize = XbeSectionSize;
ExeHeaders.SectionHeader.VirtualAddress = XbeSectionAddress;
ExeHeaders.SectionHeader.SizeOfRawData = XbeSectionSize;
ExeHeaders.SectionHeader.PointerToRawData = XbeSectionAddress;
ExeHeaders.SectionHeader.PointerToRelocations = 0;
ExeHeaders.SectionHeader.PointerToLinenumbers = 0;
ExeHeaders.SectionHeader.NumberOfRelocations = 0;
ExeHeaders.SectionHeader.NumberOfLinenumbers = 0;
ExeHeaders.SectionHeader.Characteristics = 0x60000020;
// ******************************************************************
// * image import descriptor, only one DLL
// ******************************************************************
uint32 offsIat = (uint32)&ExeHeaders.ImportAddressTable - (uint32)&ExeHeaders;
uint32 offsName = (uint32)ExeHeaders.OptionalHeader.DirtboxDllName - (uint32)&ExeHeaders;
ExeHeaders.ImageImportDescriptor[0].OriginalFirstThunk = offsIat;
ExeHeaders.ImageImportDescriptor[0].TimeDateStamp = 0;
ExeHeaders.ImageImportDescriptor[0].ForwarderChain = 0;
ExeHeaders.ImageImportDescriptor[0].Name = offsName;
ExeHeaders.ImageImportDescriptor[0].FirstThunk = offsIat;
ExeHeaders.ImageImportDescriptor[1].OriginalFirstThunk = 0;
ExeHeaders.ImageImportDescriptor[1].TimeDateStamp = 0;
ExeHeaders.ImageImportDescriptor[1].ForwarderChain = 0;
ExeHeaders.ImageImportDescriptor[1].Name = 0;
ExeHeaders.ImageImportDescriptor[1].FirstThunk = 0;
// ******************************************************************
// * import address table, import by ordinal
// ******************************************************************
ExeHeaders.ImportAddressTable[0] = 0x80000001;
ExeHeaders.ImportAddressTable[1] = 0;
// ******************************************************************
// * trampoline that calls the Dirtbox loader in the DLL
// ******************************************************************
memcpy(ExeHeaders.Trampoline, &TrampolineCode, TRAMPOLINE_LENGTH);
// ******************************************************************
// * replaces the magic and digital signature with PE headers
// ******************************************************************
memcpy(ExeBuffer + 0, &ExeHeaders, sizeof(MICRO_EXE_HEADERS));
// ******************************************************************
// * write the created buffer into EXE file
// ******************************************************************
FILE *ExeFile = fopen(Filename, "wb");
if (ExeFile == 0)
XBE_WRITE_ERROR("Could not open Exe file");
fwrite(ExeBuffer, Header.SizeOfImage, 1, ExeFile);
fclose(ExeFile);
// ******************************************************************
// * free buffer for Exe file
// ******************************************************************
delete [] ExeBuffer;
printf("OK\n");
return 0;
}
// ******************************************************************
// * GetAddr
// ******************************************************************
uint08 *Xbe::GetAddr(uint32 VirtualAddress)
{
uint32 offs = VirtualAddress - Header.BaseAddr;
// ******************************************************************
// * offset in image header
// ******************************************************************
if(offs < sizeof(Header))
return &((uint08*)&Header)[offs];
// ******************************************************************
// * offset in image header extra bytes
// ******************************************************************
if(offs < Header.SizeOfHeaders)
return (uint08*)&HeaderEx[offs - sizeof(Header)];
// ******************************************************************
// * offset in some random section
// ******************************************************************
{
for(uint32 v = 0; v < Header.Sections; v++)
{
uint32 VirtAddr = SectionHeader[v].VirtualAddr;
uint32 VirtSize = SectionHeader[v].VirtualSize;
if( (VirtualAddress >= VirtAddr) && (VirtualAddress < (VirtAddr + VirtSize)) )
return &Section[v][VirtualAddress - VirtAddr];
}
}
return 0;
}