[8003] | 1 | /* $Id: kFileInterfaces.h,v 1.1 2002-02-24 02:47:26 bird Exp $
|
---|
| 2 | *
|
---|
| 3 | * This headerfile contains interfaces for the common tools classes.
|
---|
| 4 | *
|
---|
| 5 | * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
| 6 | *
|
---|
| 7 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 8 | *
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | #ifndef _kInterfaces_h_
|
---|
| 13 | #define _kInterfaces_h_
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 | /*******************************************************************************
|
---|
| 17 | * Defined Constants And Macros *
|
---|
| 18 | *******************************************************************************/
|
---|
| 19 | #define MAXEXPORTNAME 256
|
---|
| 20 | #define MAXDBGNAME 256
|
---|
| 21 |
|
---|
| 22 |
|
---|
| 23 | /*******************************************************************************
|
---|
| 24 | * Structures and Typedefs *
|
---|
| 25 | *******************************************************************************/
|
---|
| 26 | class kPageI;
|
---|
| 27 | class kExportI;
|
---|
| 28 | class kExportEntry;
|
---|
| 29 | class kModuleI;
|
---|
| 30 | class kExecutableI;
|
---|
| 31 | class kDbgTypeI;
|
---|
| 32 | class kRelocI;
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | /**
|
---|
| 37 | * Interface class (ie. virtual) which defines the interface for
|
---|
| 38 | * executables (resources and object too perhaps) files used to
|
---|
| 39 | * get and put pages.
|
---|
| 40 | * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
| 41 | */
|
---|
| 42 | class kPageI
|
---|
| 43 | {
|
---|
| 44 | public:
|
---|
| 45 | /** @cat Get and put page methods. */
|
---|
| 46 |
|
---|
| 47 | /**
|
---|
| 48 | * Get a code, data or resource page from the file.
|
---|
| 49 | * @returns 0 on success. kError number on error.
|
---|
| 50 | * @param pachPage Pointer to a buffer of the size of a page which
|
---|
| 51 | * will receive the page data on the specified address.
|
---|
| 52 | * @param ulAddress Page address. This must be page aligned.
|
---|
| 53 | */
|
---|
| 54 | virtual int pageGet(char *pachPage, unsigned long ulAddress) const = 0;
|
---|
| 55 |
|
---|
| 56 | /**
|
---|
| 57 | * Get a code, data or resource page from the file.
|
---|
| 58 | * @returns 0 on success. kError number on error.
|
---|
| 59 | * @param pachPage Pointer to a buffer of the size of a page which
|
---|
| 60 | * will receive the page data on the specified address.
|
---|
| 61 | * @param iSegment Segment number. (0-based)
|
---|
| 62 | * @param offObject Offset into the object. This must be page aligned.
|
---|
| 63 | * @remark Object = Section.
|
---|
| 64 | */
|
---|
| 65 | virtual int pageGet(char *pachPage, int iSegment, int offObject) const = 0;
|
---|
| 66 |
|
---|
| 67 | /**
|
---|
| 68 | * Updates or adds a code, data, or resource page to the file.
|
---|
| 69 | * @returns 0 on success. kError number on error.
|
---|
| 70 | * @param pachPage Pointer to a buffer of the size of a page which
|
---|
| 71 | * holds the page data.
|
---|
| 72 | * @param ulAddress Page address. This must be page aligned.
|
---|
| 73 | */
|
---|
| 74 | virtual int pagePut(const char *pachPage, unsigned long ulAddress) = 0;
|
---|
| 75 |
|
---|
| 76 | /**
|
---|
| 77 | * Updates or adds a code, data, or resource page to the file.
|
---|
| 78 | * @returns 0 on success. kError number on error.
|
---|
| 79 | * @param pachPage Pointer to a buffer of the size of a page which
|
---|
| 80 | * holds the page data.
|
---|
| 81 | * @param iSegment Segment number. (0-based)
|
---|
| 82 | * @param offObject Offset into the object. This must be page aligned.
|
---|
| 83 | */
|
---|
| 84 | virtual int pagePut(const char *pachPage, int iSegment, int offObject) = 0;
|
---|
| 85 |
|
---|
| 86 | /**
|
---|
| 87 | * Get pagesize for the file.
|
---|
| 88 | * @returns Pagesize in bytes.
|
---|
| 89 | */
|
---|
| 90 | virtual int pageGetPageSize() const = 0;
|
---|
| 91 | };
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | /**
|
---|
| 95 | * ExportEntry used by the findFirstExport/findNextExport functions
|
---|
| 96 | */
|
---|
| 97 | class kExportEntry
|
---|
| 98 | {
|
---|
| 99 | public:
|
---|
| 100 | unsigned long ulOrdinal; /* Ordinal of export. 0 if invalid. */
|
---|
| 101 | char achName[MAXEXPORTNAME]; /* Public or exported name. */
|
---|
| 102 | char achIntName[MAXEXPORTNAME]; /* Optional. not used by PEFile */
|
---|
| 103 |
|
---|
| 104 | unsigned long ulOffset; /* Offset. -1 if invalid. */
|
---|
| 105 | unsigned long iObject; /* Object number. -1 if invalid. */
|
---|
| 106 | unsigned long ulAddress; /* Address of symbol. -1 if invalid. */
|
---|
| 107 |
|
---|
| 108 | public:
|
---|
| 109 | /** @cat Internal use - don't mess! */
|
---|
| 110 | void * pv; /* Internal pointer. */
|
---|
| 111 | };
|
---|
| 112 |
|
---|
| 113 | /**
|
---|
| 114 | * Interface class (ie. virtual) which defines the interface for executables
|
---|
| 115 | * (objects and libraries to perhaps) files used to enumerate exports and
|
---|
| 116 | * public exported names.
|
---|
| 117 | * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
| 118 | */
|
---|
| 119 | class kExportI
|
---|
| 120 | {
|
---|
| 121 | public:
|
---|
| 122 | /** @cat Export enumeration methods. */
|
---|
| 123 |
|
---|
| 124 | /**
|
---|
| 125 | * Find the first export/public name.
|
---|
| 126 | * @returns Success indicator.
|
---|
| 127 | * @param pExport Communication area.
|
---|
| 128 | */
|
---|
| 129 | virtual KBOOL exportFindFirst(kExportEntry * pExport) = 0;
|
---|
| 130 |
|
---|
| 131 | /**
|
---|
| 132 | * Find the next export/public name.
|
---|
| 133 | * @returns Success indicator.
|
---|
| 134 | * FALSE when no more exports (exportFindClose has been processed then).
|
---|
| 135 | * @param pExport Communication area which has been successfully
|
---|
| 136 | * processed by findFirstExport.
|
---|
| 137 | */
|
---|
| 138 | virtual KBOOL exportFindNext(kExportEntry * pExport) = 0;
|
---|
| 139 |
|
---|
| 140 | /**
|
---|
| 141 | * Frees resources associated with the communicatin area.
|
---|
| 142 | * It's not necessary to call this when exportFindNext has return FALSE.
|
---|
| 143 | * @param pExport Communication area which has been successfully
|
---|
| 144 | * processed by findFirstExport.
|
---|
| 145 | */
|
---|
| 146 | virtual void exportFindClose(kExportEntry * pExport) = 0;
|
---|
| 147 |
|
---|
| 148 |
|
---|
| 149 | /** @cat Export Search methods */
|
---|
| 150 |
|
---|
| 151 | /**
|
---|
| 152 | * Lookup information on a spesific export given by ordinal number.
|
---|
| 153 | * @returns Success indicator.
|
---|
| 154 | * @param pExport Communication area containing export information
|
---|
| 155 | * on successful return.
|
---|
| 156 | */
|
---|
| 157 | virtual KBOOL exportLookup(unsigned long ulOrdinal, kExportEntry *pExport) = 0;
|
---|
| 158 |
|
---|
| 159 | /**
|
---|
| 160 | * Lookup information on a spesific export given by name.
|
---|
| 161 | * @returns Success indicator.
|
---|
| 162 | * @param pExport Communication area containing export information
|
---|
| 163 | * on successful return.
|
---|
| 164 | */
|
---|
| 165 | virtual KBOOL exportLookup(const char * pszName, kExportEntry *pExport) = 0;
|
---|
| 166 | };
|
---|
| 167 |
|
---|
| 168 |
|
---|
| 169 | /**
|
---|
| 170 | * Interface class (ie. virtual) which defines the interface for executables
|
---|
| 171 | * (objects and libraries to perhaps) files used to enumerate exports and
|
---|
| 172 | * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
| 173 | */
|
---|
| 174 | class kModuleI
|
---|
| 175 | {
|
---|
| 176 | public:
|
---|
| 177 | /** @cat Module information methods. */
|
---|
| 178 | virtual KBOOL moduleGetName(char *pszBuffer, int cbBuffer = 260) = 0;
|
---|
| 179 | };
|
---|
| 180 |
|
---|
| 181 |
|
---|
| 182 | /**
|
---|
| 183 | * Interface class (ie. virtual) which defines the interface for
|
---|
| 184 | * executables files.
|
---|
| 185 | * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
| 186 | */
|
---|
| 187 | class kExecutableI : public kModuleI, public kExportI
|
---|
| 188 | {
|
---|
| 189 | public:
|
---|
| 190 | /** @cat Executable information methods. */
|
---|
| 191 | #if 0
|
---|
| 192 | virtual BOOL execIsDLL(void) = 0;
|
---|
| 193 | virtual BOOL execIsProgram(void) = 0;
|
---|
| 194 | virtual BOOL execIsDriver(void) = 0;
|
---|
| 195 | #endif
|
---|
| 196 | };
|
---|
| 197 |
|
---|
| 198 |
|
---|
| 199 | /**
|
---|
| 200 | * Communication class/struct used by kDbgTypeI and others.
|
---|
| 201 | * This is structure or union member class.
|
---|
| 202 | * (This might turn out very similar to a normal variable class,
|
---|
| 203 | * and will if so be changed to that when time comes.)
|
---|
| 204 | * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
| 205 | */
|
---|
| 206 | class kDbgMemberEntry
|
---|
| 207 | {
|
---|
| 208 | public:
|
---|
| 209 | char szName[MAXDBGNAME]; /* Member name. */
|
---|
| 210 | char cb; /* Count of bytes it covers. */
|
---|
| 211 | char szTypeName[MAXDBGNAME]; /* Type name. */
|
---|
| 212 | int flFlags; /* Type flags. One of the kDbgTypeI::enm*. optional: defaults to kDbgTypeI::enmAny */
|
---|
| 213 | };
|
---|
| 214 |
|
---|
| 215 |
|
---|
| 216 | /**
|
---|
| 217 | * Communication class/struct used by kDbgTypeI.
|
---|
| 218 | * This is the type.
|
---|
| 219 | * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
| 220 | */
|
---|
| 221 | class kDbgTypeEntry
|
---|
| 222 | {
|
---|
| 223 | public:
|
---|
| 224 | char szName[MAXDBGNAME]; /* Name of the type. */
|
---|
| 225 | char cb; /* Count of bytes it covers. */
|
---|
| 226 | int flFlags; /* Type flags. One of the kDbgTypeI::enm*. */
|
---|
| 227 |
|
---|
| 228 | int cMembers; /* Number of members. This is 0 if not a union or a struct. */
|
---|
| 229 | kDbgMemberEntry * paMembers; /* Pointer array of member entries if union or struct. */
|
---|
| 230 |
|
---|
| 231 | public:
|
---|
| 232 | /** @cat Internal use only - don't mess! */
|
---|
| 233 | int flSearchFlags; /* Type flags which this search was started with. One of the kDbgTypeI::enm*. */
|
---|
| 234 | };
|
---|
| 235 |
|
---|
| 236 |
|
---|
| 237 |
|
---|
| 238 | /**
|
---|
| 239 | * Interface class (ie. virtual) which defines the interface for
|
---|
| 240 | * debug typeinfo on debug module level.
|
---|
| 241 | * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
| 242 | */
|
---|
| 243 | class kDbgTypeI
|
---|
| 244 | {
|
---|
| 245 | public:
|
---|
| 246 | /** @cat Debug Type information methods. */
|
---|
| 247 | virtual kDbgTypeEntry * dbgtypeFindFirst(int flFlags) = 0;
|
---|
| 248 | virtual kDbgTypeEntry * dbgtypeFindNext(kDbgTypeEntry *kDbgTypeEntry) = 0;
|
---|
| 249 | virtual void dbgtypeFindClose(kDbgTypeEntry *kDbgTypeEntry) = 0;
|
---|
| 250 |
|
---|
| 251 | virtual kDbgTypeEntry * dbgtypeLookup(const char *pszName, int flFlags) = 0;
|
---|
| 252 | enum
|
---|
| 253 | { enmAny, /* Any/unknown type. */
|
---|
| 254 | enmStruct, /* Structure: struct _somestruct {..}; */
|
---|
| 255 | enmUnion, /* Union: union _someunion {..}; */
|
---|
| 256 | enmEnum, /* Enumeration: enum _someenum {..}; */
|
---|
| 257 | enmTypedef, /* Type definition: typedef <type expr> sometype; */
|
---|
| 258 | enmMask = 0x0000000ff, /* Type mask. */
|
---|
| 259 | enmFlagMask = 0xffffff00, /* Flag mask. */
|
---|
| 260 | enmflPointer = 0x00000100 /* This is pointer to something. (flag) */
|
---|
| 261 | };
|
---|
| 262 | };
|
---|
| 263 |
|
---|
| 264 |
|
---|
| 265 | /**
|
---|
| 266 | * One reallocation (reloc for short).
|
---|
| 267 | * @author knut st. osmundsen (kosmunds@csc.com)
|
---|
| 268 | */
|
---|
| 269 | class kRelocEntry
|
---|
| 270 | {
|
---|
| 271 | public:
|
---|
| 272 | /** @cat constants and flags */
|
---|
| 273 | enum
|
---|
| 274 | {
|
---|
| 275 | /* flags */
|
---|
| 276 | enmFlagMask = 0x0000FFFF,
|
---|
| 277 | enmLittleEndian = 0x0001, /* Little endian */
|
---|
| 278 | enmBigEndian = 0x0002, /* Big endian */
|
---|
| 279 | enmAdditive = 0x0004, /* There is a addition (like extra offset) to the fixup. */
|
---|
| 280 |
|
---|
| 281 | /* relocation type part 1 */
|
---|
| 282 | enmType1Mask= 0x000F0000,
|
---|
| 283 | enmName = 0x00010000, /* Name import (no dll/module) */
|
---|
| 284 | enmNameDLL = 0x00020000, /* Name import (from a given dll/module) */
|
---|
| 285 | enmOrdDLL = 0x00030000, /* Ordinal import (from a given dll/module) */
|
---|
| 286 | enmDelta = 0x00040000, /* Delta fixup - add the relocation delta */
|
---|
| 287 | enmInternal = 0x00050000, /* Write the pointer as enmSizeMask describes. */
|
---|
| 288 |
|
---|
| 289 | /* relocation type part 2 */
|
---|
| 290 | enmType2Mask= 0x00F00000,
|
---|
| 291 | enmOffset = 0x00100000, /* Offset fixup. */
|
---|
| 292 | enmRelStart = 0x00200000, /* The fixup is relative to the fixup location. */
|
---|
| 293 | enmRelEnd = 0x00300000, /* The fixup is relative to the fixup location + size. */
|
---|
| 294 |
|
---|
| 295 | /* size */
|
---|
| 296 | enmSizeMask = 0xFF000000, /* Size mask */
|
---|
| 297 | enm8 = 0x01000000, /* 8 bit fixup */
|
---|
| 298 | enm16 = 0x02000000, /* 16 bit fixup */
|
---|
| 299 | enm32 = 0x03000000, /* 32 bit fixup */
|
---|
| 300 | enm64 = 0x04000000, /* 64 bit fixup */
|
---|
| 301 | enm16_00 = 0x05000000, /* 16:00 fixup (selector only) */
|
---|
| 302 | enm16_16 = 0x06000000, /* 16:16 fixup (selector:offset) */
|
---|
| 303 | enm16_32 = 0x07000000, /* 16:32 fixup (selector:offset) */
|
---|
| 304 | enm16_48 = 0x08000000, /* 16:48 fixup (selector:offset) */
|
---|
| 305 | enm16hb = 0x09000000, /* 16 bit fixup - high byte */
|
---|
| 306 | enm32hw = 0x0a000000, /* 32 bit fixup - high word */
|
---|
| 307 | enm64hdw = 0x0b000000, /* 64 bit fixup - high dword */
|
---|
| 308 |
|
---|
| 309 | /* defaults */
|
---|
| 310 | enmFirstSelector= 0xfffffffe, /* Selector used if the offset is a Relative Virtual Address. */
|
---|
| 311 | enmRVASelector = 0xffffffff, /* Selector used if the offset is a Relative Virtual Address. */
|
---|
| 312 | enmVASelector = 0xfffffffe /* Selector used if the offset is a FLAT address. */
|
---|
| 313 | };
|
---|
| 314 |
|
---|
| 315 | /** @cat public data (speed/size) */
|
---|
| 316 | unsigned long offSegment; /* The address of the fixup. (page offset, segment offset, RVA or FLAT address) */
|
---|
| 317 | unsigned long ulSegment; /* Segment number the offSegment is relative to. Special selectors may be used. (0-based) */
|
---|
| 318 | unsigned long fFlags; /* Combination of the above flags. Don't mess with this member. */
|
---|
| 319 | unsigned long ulAdd; /* Value to add if additiv relocation. */
|
---|
| 320 |
|
---|
| 321 | union _RelocInfo
|
---|
| 322 | {
|
---|
| 323 | struct InternalInfo {
|
---|
| 324 | unsigned long offSegment; /* Offset into ulSegment of the 'target'. */
|
---|
| 325 | unsigned long ulSegment; /* Segemnt number of the 'traget'. Special selectors may be used. (0-based) */
|
---|
| 326 | } Internal;
|
---|
| 327 |
|
---|
| 328 | struct NameImportInfo {
|
---|
| 329 | char * pszName; /* Pointer to string or NULL. Don't mess with this pointer! */
|
---|
| 330 | char * pszModule; /* Pointer to module name or NULL. Don't mess with this pointer! */
|
---|
| 331 | unsigned long ulOrdinal; /* Ordinal value if applicable. */
|
---|
| 332 | } Name;
|
---|
| 333 | } Info;
|
---|
| 334 |
|
---|
| 335 | /** @cat helper functions */
|
---|
| 336 | KBOOL isName() const { return (fFlags & enmType1Mask) <= enmOrdDLL; };
|
---|
| 337 | KBOOL isInternal() const { return (fFlags & enmType1Mask) > enmOrdDLL; };
|
---|
| 338 |
|
---|
| 339 |
|
---|
| 340 | public:
|
---|
| 341 | /** @cat Internal use only - don't mess! */
|
---|
| 342 | void * pv1; /* some pointer - used by relocFind*() implementations. */
|
---|
| 343 | void * pv2; /* some pointer - used by relocXRef*(). */
|
---|
| 344 | };
|
---|
| 345 |
|
---|
| 346 |
|
---|
| 347 |
|
---|
| 348 | /**
|
---|
| 349 | * Relocation interface.
|
---|
| 350 | * @author knut st. osmundsen (kosmunds@csc.com)
|
---|
| 351 | * @remark This interface will not return any address by using the special selectors
|
---|
| 352 | * since there is no pulic way of converting them - yet.
|
---|
| 353 | * relocFindFirst will accept special selectors as input.
|
---|
| 354 | * relocXRefFindFirst will not.
|
---|
| 355 | */
|
---|
| 356 | class kRelocI
|
---|
| 357 | {
|
---|
| 358 | public:
|
---|
| 359 | /** @cat Relocation enumeration menthods */
|
---|
| 360 | virtual KBOOL relocFindFirst(unsigned long ulSegment, unsigned long offSegment, kRelocEntry *preloc) = 0;
|
---|
| 361 | virtual KBOOL relocFindFirst(unsigned long ulAddress, kRelocEntry *preloc) = 0;
|
---|
| 362 | virtual KBOOL relocFindNext(kRelocEntry *preloc) = 0;
|
---|
| 363 | virtual void relocFindClose(kRelocEntry *preloc) = 0;
|
---|
| 364 |
|
---|
| 365 | /** @cat Common worker methods. */
|
---|
| 366 | KBOOL relocXRefFindFirst(unsigned long ulSegment, unsigned long offSegment, kRelocEntry *preloc);
|
---|
| 367 | KBOOL relocXRefFindNext(kRelocEntry *preloc);
|
---|
| 368 | void relocXRefFindClose(kRelocEntry *preloc);
|
---|
| 369 |
|
---|
| 370 | };
|
---|
| 371 |
|
---|
| 372 |
|
---|
| 373 |
|
---|
| 374 | #endif
|
---|