2 * Copyright (C) 2000, The University of Queensland
3 * Copyright (C) 2001, Sun Microsystems, Inc
5 * See the file "LICENSE.TERMS" for information on usage and
6 * redistribution of this file, and for a DISCLAIMER OF ALL
11 /* File: DOS4GWBinaryFile.h
12 * Desc: This file contains the definition of the class DOS4GWBinaryFile.
15 #ifndef __DOS4GWBINARYFILE_H__
16 #define __DOS4GWBINARYFILE_H_
18 #include "BinaryFile.h"
22 * This file contains the definition of the DOS4GWBinaryFile class, and some
23 * other definitions specific to the exe version of the BinaryFile object
25 /* At present, this loader supports the OS2 file format (also known as
26 * the Linear eXecutable format) as much as I've found necessary to
27 * inspect old DOS4GW apps. This loader could also be used for decompiling
28 * Win9x VxD files or, of course, OS2 binaries, but you're probably better off
29 * making a specific loader for each of these.
30 * 24 Jan 05 - Trent: created.
33 // Given a little endian value x, load its value assuming little endian order
34 // Note: must be able to take address of x
35 // Note: Unlike the LH macro in BinaryFile.h, the paraeter is not a pointer
36 #define LMMH(x) ((unsigned)((Byte *)(&x))[0] + ((unsigned)((Byte *)(&x))[1] << 8) + \
37 ((unsigned)((Byte *)(&x))[2] << 16) + ((unsigned)((Byte *)(&x))[3] << 24))
38 // With this one, x IS a pounsigneder
39 #define LMMH2(x) ((unsigned)((Byte *)(x))[0] + ((unsigned)((Byte *)(x))[1] << 8) + \
40 ((unsigned)((Byte *)(x))[2] << 16) + ((unsigned)((Byte *)(x))[3] << 24))
41 #define LMMHw(x) ((unsigned)((Byte *)(&x))[0] + ((unsigned)((Byte *)(&x))[1] << 8))
43 typedef struct /* exe file header, just the signature really */
45 Byte sigLo
; /* .EXE signature: 0x4D 0x5A */
71 DWord pageoffsetshift
;
72 DWord fixupsectionsize
;
73 DWord fixupsectionchksum
;
74 DWord loadersectionsize
;
75 DWord loadersectionchksum
;
77 DWord numobjsinmodule
;
78 DWord objpagetbloffset
;
79 DWord objiterpagesoffset
;
80 DWord resourcetbloffset
;
81 DWord numresourcetblentries
;
82 DWord residentnametbloffset
;
84 DWord moduledirectivesoffset
;
85 DWord nummoduledirectives
;
86 DWord fixuppagetbloffset
;
87 DWord fixuprecordtbloffset
;
88 DWord importtbloffset
;
89 DWord numimportmoduleentries
;
90 DWord importproctbloffset
;
91 DWord perpagechksumoffset
;
92 DWord datapagesoffset
;
93 DWord numpreloadpages
;
94 DWord nonresnametbloffset
;
95 DWord nonresnametbllen
;
96 DWord nonresnametblchksum
;
97 DWord autodsobjectnum
;
98 DWord debuginfooffset
;
100 DWord numinstancepreload
;
101 DWord numinstancedemand
;
112 DWord NumPageTblEntries
;
119 DWord pagedataoffset
;
125 // this is correct for internal fixups only
132 // unsigned char object; // these are now variable length
133 // unsigned short trgoff;
141 class DOS4GWBinaryFile
: public BinaryFile
144 DOS4GWBinaryFile(); // Default constructor
145 virtual ~DOS4GWBinaryFile(); // Destructor
146 virtual bool Open(const char* sName
); // Open the file for r/w; ???
147 virtual void Close(); // Close file opened with Open()
148 virtual void UnLoad(); // Unload the image
149 virtual LOAD_FMT
GetFormat() const; // Get format (i.e.
151 virtual MACHINE
GetMachine() const; // Get machine (i.e.
154 virtual const char *getFilename() const
158 virtual bool isLibrary() const;
159 virtual std::list
<const char *> getDependencyList();
160 virtual ADDRESS
getImageBase();
161 virtual size_t getImageSize();
163 virtual std::list
<SectionInfo
*>& GetEntryPoints(const char* pEntry
= "main");
164 virtual ADDRESS
GetMainEntryPoint();
165 virtual ADDRESS
GetEntryPoint();
166 ptrdiff_t getDelta();
167 virtual const char* SymbolByAddress(ADDRESS dwAddr
); // Get sym from addr
168 virtual ADDRESS
GetAddressByName(const char* name
,
169 bool bNoTypeOK
= false); // Find addr given name
170 virtual void AddSymbol(ADDRESS uNative
, const char *pName
);
173 // -- -- -- -- -- -- -- -- --
175 // Internal information
177 virtual bool DisplayDetails(const char* fileName
, FILE* f
= stdout
);
181 int dos4gwRead2(short *ps
) const; // Read 2 bytes from native addr
182 int dos4gwRead4(int *pi
) const; // Read 4 bytes from native addr
186 virtual int readNative1(ADDRESS a
); // Read 1 bytes from native addr
187 virtual int readNative2(ADDRESS a
); // Read 2 bytes from native addr
188 virtual int readNative4(ADDRESS a
); // Read 4 bytes from native addr
189 virtual QWord
readNative8(ADDRESS a
); // Read 8 bytes from native addr
190 virtual float readNativeFloat4(ADDRESS a
); // Read 4 bytes as float
191 virtual double readNativeFloat8(ADDRESS a
); // Read 8 bytes as float
193 virtual bool IsDynamicLinkedProcPointer(ADDRESS uNative
);
194 virtual bool IsDynamicLinkedProc(ADDRESS uNative
);
195 virtual const char *GetDynamicProcName(ADDRESS uNative
);
197 virtual std::map
<ADDRESS
, std::string
> &getSymbols()
203 virtual bool RealLoad(const char* sName
); // Load the file; pure virtual
207 bool PostLoad(void* handle
); // Called after archive member loaded
209 Header
* m_pHeader
; // Pointer to header
210 LXHeader
* m_pLXHeader
; // Pointer to lx header
211 LXObject
* m_pLXObjects
; // Pointer to lx objects
212 LXPage
* m_pLXPages
; // Pointer to lx pages
213 size_t m_cbImage
; // Size of image
214 //int m_cReloc; // Number of relocation entries
215 //DWord* m_pRelocTable; // The relocation table
216 unsigned char *base
; // Beginning of the loaded image
217 // Map from address of dynamic pointers to library procedure names:
218 std::map
<ADDRESS
, std::string
> dlprocptrs
;
219 const char *m_pFileName
;
226 #endif // ifndef __DOS4GWBINARYFILE_H__