1 | /* $Id: kFileLX.h,v 1.6 2002-02-24 02:47:26 bird Exp $
|
---|
2 | *
|
---|
3 | * kFileLX - Linear Executable file reader.
|
---|
4 | *
|
---|
5 | * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
---|
6 | *
|
---|
7 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
8 | *
|
---|
9 | */
|
---|
10 |
|
---|
11 | #ifndef _kFileLX_h_
|
---|
12 | #define _kFileLX_h_
|
---|
13 |
|
---|
14 | struct e32_exe;
|
---|
15 | struct o32_obj;
|
---|
16 | struct o32_map;
|
---|
17 |
|
---|
18 |
|
---|
19 | class kFileLX : public kFileFormatBase, public kExecutableI, public kPageI, public kRelocI
|
---|
20 | {
|
---|
21 | public:
|
---|
22 | kFileLX(const char *pszFilename) throw (kError);
|
---|
23 | kFileLX(kFile *pFile) throw (kError);
|
---|
24 | ~kFileLX() throw (kError);
|
---|
25 |
|
---|
26 | /** @cat Module information methods. */
|
---|
27 | KBOOL moduleGetName(char *pszBuffer, int cchSize = 260);
|
---|
28 |
|
---|
29 | /** @cat Misc */
|
---|
30 | virtual KBOOL isLx() const {return TRUE;};
|
---|
31 |
|
---|
32 | struct o32_obj * getObject(int iObject);
|
---|
33 | int getObjectCount();
|
---|
34 |
|
---|
35 | /** @cat Export enumeration methods. */
|
---|
36 | KBOOL exportFindFirst(kExportEntry *pExport);
|
---|
37 | KBOOL exportFindNext(kExportEntry *pExport);
|
---|
38 | void exportFindClose(kExportEntry *pExport);
|
---|
39 |
|
---|
40 | /** @cat Export Lookup methods */
|
---|
41 | KBOOL exportLookup(unsigned long ulOrdinal, kExportEntry *pExport);
|
---|
42 | KBOOL exportLookup(const char * pszName, kExportEntry *pExport);
|
---|
43 |
|
---|
44 | /** @cat Get and put page methods. */
|
---|
45 | int pageGet(char *pachPage, unsigned long ulAddress) const;
|
---|
46 | int pageGet(char *pachPage, int iObject, int offObject) const;
|
---|
47 | int pagePut(const char *pachPage, unsigned long ulAddress);
|
---|
48 | int pagePut(const char *pachPage, int iObject, int offObject);
|
---|
49 | int pageGetPageSize() const;
|
---|
50 |
|
---|
51 | /** @cat Compression and expansion methods compatible with exepack:1 and exepack:2. */
|
---|
52 | static int expandPage1(char *pachPage, int cchPage, const char * pachSrcPage, int cchSrcPage);
|
---|
53 | static int expandPage2(char *pachPage, int cchPage, const char * pachSrcPage, int cchSrcPage);
|
---|
54 | static int compressPage1(char *pachPage, const char * pachSrcPage, int cchSrcPage);
|
---|
55 | static int compressPage2(char *pachPage, const char * pachSrcPage, int cchSrcPage);
|
---|
56 |
|
---|
57 | /** @cat Relocation methods */
|
---|
58 | KBOOL relocFindFirst(unsigned long iSegment, unsigned long offObject, kRelocEntry *preloc);
|
---|
59 | KBOOL relocFindFirst(unsigned long ulAddress, kRelocEntry *preloc);
|
---|
60 | KBOOL relocFindNext(kRelocEntry *preloc);
|
---|
61 | void relocFindClose(kRelocEntry *preloc);
|
---|
62 |
|
---|
63 |
|
---|
64 | protected:
|
---|
65 | /** @cat Internal data */
|
---|
66 | void * pvBase; /* Pointer to filemapping. */
|
---|
67 | unsigned long cbFile; /* Size of filemapping. */
|
---|
68 | unsigned long offLXHdr; /* Offset of the LX header. */
|
---|
69 | struct e32_exe * pe32; /* Pointer to the exe header within the filemapping. */
|
---|
70 | struct o32_obj * paObject; /* Pointer to the objecttable. */
|
---|
71 | struct o32_map * paMap; /* Pointer to page map table. */
|
---|
72 | unsigned long * paulFixupPageTable; /* Pointer to the fixup page table. */
|
---|
73 | char * pchFixupRecs; /* Pointer to the fixup record table. */
|
---|
74 |
|
---|
75 | /** @cat Export and Module information worker. */
|
---|
76 | KBOOL queryExportName(int iOrdinal, char *pszBuffer);
|
---|
77 |
|
---|
78 | /** @cat Get and put page workers. */
|
---|
79 | /*
|
---|
80 | int pageGetLX(char *pachPage, int iObject, int iPage) const;
|
---|
81 | int pageGetLX(char *pachPage, int iPage) const;
|
---|
82 | int pagePutLX(const char *pachPage, int iObject, int iPage);
|
---|
83 | int pagePutLX(const char *pachPage, int iPage);
|
---|
84 | */
|
---|
85 |
|
---|
86 | /** @cat Address mapping helpers. */
|
---|
87 | unsigned long lxAddressToObjectOffset(unsigned long ulAddress, unsigned long * pulObject) const;
|
---|
88 | unsigned long lxSpecialSelectorToObjectOffset(unsigned long offObject, unsigned long * pulObject) const;
|
---|
89 | KBOOL lxValidateObjectOffset(unsigned long ulObject, unsigned long offOffset) const;
|
---|
90 | KBOOL lxValidateAddress(unsigned long ulAddress) const;
|
---|
91 |
|
---|
92 | /** @cat Import Helpers */
|
---|
93 | char * lxGetImportModuleName(unsigned long ordModule) const;
|
---|
94 | char * lxGetImportProcName(unsigned long offProc) const;
|
---|
95 | };
|
---|
96 |
|
---|
97 | #endif
|
---|