| 1 | /* $Id: kHll.h,v 1.9 2000-05-29 19:46:29 bird Exp $
|
|---|
| 2 | *
|
|---|
| 3 | * kHll - Declarations of the class kHll.
|
|---|
| 4 | * That class is used to create HLL debuginfo.
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
|---|
| 7 | *
|
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 9 | *
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | #ifndef _kHll_h_
|
|---|
| 14 | #define _kHll_h_
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 | /*******************************************************************************
|
|---|
| 18 | * Structures and Typedefs *
|
|---|
| 19 | *******************************************************************************/
|
|---|
| 20 |
|
|---|
| 21 | /**
|
|---|
| 22 | * HLL General entry.
|
|---|
| 23 | * Provided as a base class for kList entries.
|
|---|
| 24 | * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
|---|
| 25 | */
|
|---|
| 26 | class kHllBaseEntry : public kListEntry
|
|---|
| 27 | {
|
|---|
| 28 | public:
|
|---|
| 29 | /**
|
|---|
| 30 | * Write this HLL entry to file.
|
|---|
| 31 | * @returns Count of bytes written (on success).
|
|---|
| 32 | * -3 Invalid offsets.
|
|---|
| 33 | * -2 Seek error.
|
|---|
| 34 | * -1 Write error.
|
|---|
| 35 | * 0 No data written. Concidered as an error!
|
|---|
| 36 | * @param phFile Filehandle.
|
|---|
| 37 | */
|
|---|
| 38 | virtual int write(FILE *phFile) = 0;
|
|---|
| 39 | static int writeList(FILE *phFile, kHllBaseEntry *pEntry);
|
|---|
| 40 |
|
|---|
| 41 | /**
|
|---|
| 42 | * Dumps the HLL entry to ph in a human readable fashion.
|
|---|
| 43 | * @param ph Output file handle the dump is to be written to.
|
|---|
| 44 | * @param cchIndent Number of char to indents the output dump.
|
|---|
| 45 | */
|
|---|
| 46 | virtual void dump(FILE *ph, int cchIndent) = 0;
|
|---|
| 47 | static void dumpList(FILE *ph, int cchIndent, kHllBaseEntry *pEntry);
|
|---|
| 48 |
|
|---|
| 49 | /**
|
|---|
| 50 | * Create IDC (IDA Pro) calls which adds info contained in the entry
|
|---|
| 51 | * to the ida pro database.
|
|---|
| 52 | * !!!NOTE!!! THIS IS ONLY TO BE USED FOR YOUR OWN PROGRAMS!!!
|
|---|
| 53 | * @param pFile Output file.
|
|---|
| 54 | */
|
|---|
| 55 | virtual void ida(kFile *pFile) throw(int) = 0;
|
|---|
| 56 | static void idaList(kFile *pFile, kHllBaseEntry *pEntry) throw(int);
|
|---|
| 57 | };
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 | /**
|
|---|
| 62 | * HLL Public symbol entry.
|
|---|
| 63 | * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
|---|
| 64 | */
|
|---|
| 65 | class kHllPubSymEntry : public kHllBaseEntry
|
|---|
| 66 | {
|
|---|
| 67 | private:
|
|---|
| 68 | PHLLPUBLICSYM pPubSym;
|
|---|
| 69 |
|
|---|
| 70 | public:
|
|---|
| 71 | kHllPubSymEntry(
|
|---|
| 72 | const char * pachName,
|
|---|
| 73 | int cchName,
|
|---|
| 74 | unsigned long off,
|
|---|
| 75 | unsigned short iObject,
|
|---|
| 76 | unsigned short iType
|
|---|
| 77 | );
|
|---|
| 78 | ~kHllPubSymEntry();
|
|---|
| 79 |
|
|---|
| 80 | int write(FILE *phFile);
|
|---|
| 81 | void dump(FILE *ph, int cchIndent);
|
|---|
| 82 | void ida(kFile *pFile) throw(int);
|
|---|
| 83 | };
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 | /**
|
|---|
| 88 | * Linenumber chunk.
|
|---|
| 89 | * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
|---|
| 90 | */
|
|---|
| 91 | class kHllLineNumberChunk : public kHllBaseEntry
|
|---|
| 92 | {
|
|---|
| 93 | private:
|
|---|
| 94 | PHLLLINENUMBERENTRY paLines;
|
|---|
| 95 | HLLFIRSTENTRY FirstEntry;
|
|---|
| 96 |
|
|---|
| 97 | public:
|
|---|
| 98 | kHllLineNumberChunk(
|
|---|
| 99 | unsigned short int iSeg,
|
|---|
| 100 | unsigned long int offBase = 0
|
|---|
| 101 | );
|
|---|
| 102 | ~kHllLineNumberChunk();
|
|---|
| 103 |
|
|---|
| 104 | BOOL addLineInfo(
|
|---|
| 105 | unsigned short int iusFile,
|
|---|
| 106 | unsigned short int usLine,
|
|---|
| 107 | unsigned long int off
|
|---|
| 108 | );
|
|---|
| 109 |
|
|---|
| 110 | int write(FILE *phFile);
|
|---|
| 111 | void dump(FILE *ph, int cchIndent);
|
|---|
| 112 | void ida(kFile *pFile) throw(int);
|
|---|
| 113 |
|
|---|
| 114 | int getSeg() { return FirstEntry.hll04.iSeg; }
|
|---|
| 115 | };
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 | /**
|
|---|
| 119 | * HLL Source entry.
|
|---|
| 120 | * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
|---|
| 121 | */
|
|---|
| 122 | class kHllSrcEntry
|
|---|
| 123 | {
|
|---|
| 124 | private:
|
|---|
| 125 | unsigned long int cFilenames;
|
|---|
| 126 | char * pachFilenames;
|
|---|
| 127 | unsigned long int cbFilenames;
|
|---|
| 128 | unsigned long int cbFilenamesAllocated;
|
|---|
| 129 |
|
|---|
| 130 | kList<kHllLineNumberChunk>
|
|---|
| 131 | Lines;
|
|---|
| 132 |
|
|---|
| 133 | public:
|
|---|
| 134 | kHllSrcEntry();
|
|---|
| 135 | ~kHllSrcEntry();
|
|---|
| 136 |
|
|---|
| 137 | kHllLineNumberChunk *
|
|---|
| 138 | addLineNumberChunk(
|
|---|
| 139 | unsigned short int iSeg,
|
|---|
| 140 | unsigned long int offBase = 0
|
|---|
| 141 | );
|
|---|
| 142 | unsigned short addFile(
|
|---|
| 143 | const char * pszFilename
|
|---|
| 144 | );
|
|---|
| 145 | unsigned short addFile(
|
|---|
| 146 | const char * pachFilename,
|
|---|
| 147 | int cchFilename
|
|---|
| 148 | );
|
|---|
| 149 | int write(FILE *phFile);
|
|---|
| 150 | void dump(FILE *ph, int cchIndent);
|
|---|
| 151 | void ida(kFile *pFile) throw(int);
|
|---|
| 152 | };
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 | /**
|
|---|
| 157 | * HLL Module entry.
|
|---|
| 158 | * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
|---|
| 159 | */
|
|---|
| 160 | class kHllModuleEntry : public kListEntry
|
|---|
| 161 | {
|
|---|
| 162 | private:
|
|---|
| 163 | /** @cat
|
|---|
| 164 | * Internal data.
|
|---|
| 165 | * HLL Module data.
|
|---|
| 166 | * Lists of HLL elements
|
|---|
| 167 | * Offsets and sizes - set by write(..).
|
|---|
| 168 | */
|
|---|
| 169 | PHLLMODULE pModule;
|
|---|
| 170 |
|
|---|
| 171 | kList<kHllPubSymEntry> PublicSymbols;
|
|---|
| 172 | /*
|
|---|
| 173 | kList<kHllTypeEntry> Types;
|
|---|
| 174 | kList<kHllSymEntry> Symbols;
|
|---|
| 175 | */
|
|---|
| 176 | kHllSrcEntry Source;
|
|---|
| 177 |
|
|---|
| 178 | BOOL fValidOffsetsAndSizes;
|
|---|
| 179 | unsigned long offModule;
|
|---|
| 180 | unsigned long cbModule;
|
|---|
| 181 | unsigned long offPublicSymbols;
|
|---|
| 182 | unsigned long cbPublicSymbols;
|
|---|
| 183 | unsigned long offTypes;
|
|---|
| 184 | unsigned long cbTypes;
|
|---|
| 185 | unsigned long offSymbols;
|
|---|
| 186 | unsigned long cbSymbols;
|
|---|
| 187 | unsigned long offSource;
|
|---|
| 188 | unsigned long cbSource;
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 | /** @cat
|
|---|
| 192 | * Internal methods.
|
|---|
| 193 | */
|
|---|
| 194 | int writeList(FILE *phFile, kList<kHllBaseEntry> &List);
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 | public:
|
|---|
| 198 | /** @cat
|
|---|
| 199 | * Constructor and destructor.
|
|---|
| 200 | */
|
|---|
| 201 | kHllModuleEntry(
|
|---|
| 202 | const char * pszName,
|
|---|
| 203 | unsigned short iLib,
|
|---|
| 204 | unsigned char cSegInfo = 0,
|
|---|
| 205 | PHLLSEGINFO paSegInfo = NULL
|
|---|
| 206 | );
|
|---|
| 207 | ~kHllModuleEntry();
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 | /** @cat
|
|---|
| 211 | * Add menthods
|
|---|
| 212 | */
|
|---|
| 213 | BOOL addSegInfo(
|
|---|
| 214 | unsigned short int iObject,
|
|---|
| 215 | unsigned long off,
|
|---|
| 216 | unsigned long cb
|
|---|
| 217 | );
|
|---|
| 218 |
|
|---|
| 219 | const void * addPublicSymbol(
|
|---|
| 220 | const char * pszName,
|
|---|
| 221 | unsigned long int off,
|
|---|
| 222 | unsigned short int iObject,
|
|---|
| 223 | const void * pvType
|
|---|
| 224 | );
|
|---|
| 225 | const void * addPublicSymbol(
|
|---|
| 226 | const char * pachName,
|
|---|
| 227 | int cchName,
|
|---|
| 228 | unsigned long int off,
|
|---|
| 229 | unsigned short int iObject,
|
|---|
| 230 | const void * pvType
|
|---|
| 231 | );
|
|---|
| 232 | kHllSrcEntry * getSourceEntry() { return &Source; }
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 | /** @cat
|
|---|
| 236 | * Output.
|
|---|
| 237 | */
|
|---|
| 238 | int write(FILE *phFile, unsigned long off);
|
|---|
| 239 | int writeDirEntries(FILE *phFile, unsigned short iMod);
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 | /** @cat
|
|---|
| 243 | * Debug dump function.
|
|---|
| 244 | */
|
|---|
| 245 | void dump(FILE *ph);
|
|---|
| 246 | void ida(kFile *pFile) throw(int);
|
|---|
| 247 | };
|
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 | /**
|
|---|
| 252 | * HLL Debug Info generator.
|
|---|
| 253 | * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
|---|
| 254 | */
|
|---|
| 255 | class kHll
|
|---|
| 256 | {
|
|---|
| 257 |
|
|---|
| 258 | private:
|
|---|
| 259 | /** @cat
|
|---|
| 260 | * Internal data.
|
|---|
| 261 | */
|
|---|
| 262 | kList<kHllModuleEntry> Modules;
|
|---|
| 263 | /*
|
|---|
| 264 | kList<kHllLibraryEntry> Libraries;
|
|---|
| 265 | */
|
|---|
| 266 |
|
|---|
| 267 | /** @cat
|
|---|
| 268 | * Internal methods.
|
|---|
| 269 | */
|
|---|
| 270 | int write(FILE *phFile);
|
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 | public:
|
|---|
| 274 | /** @cat
|
|---|
| 275 | * Constructors and Destructors.
|
|---|
| 276 | */
|
|---|
| 277 | kHll();
|
|---|
| 278 | kHll(kFile *pFile) throw (int);
|
|---|
| 279 | ~kHll();
|
|---|
| 280 |
|
|---|
| 281 | /** @cat
|
|---|
| 282 | * Add menthods
|
|---|
| 283 | */
|
|---|
| 284 | kHllModuleEntry * addModule(
|
|---|
| 285 | const char * pszName,
|
|---|
| 286 | const void * pvLib,
|
|---|
| 287 | unsigned cSegInfo = 0,
|
|---|
| 288 | PHLLSEGINFO paSegInfo = NULL
|
|---|
| 289 | );
|
|---|
| 290 | kHllModuleEntry * addModule(
|
|---|
| 291 | const char * pachName,
|
|---|
| 292 | unsigned cchName,
|
|---|
| 293 | const void * pvLib,
|
|---|
| 294 | unsigned cSegInfo = 0,
|
|---|
| 295 | PHLLSEGINFO paSegInfo = NULL
|
|---|
| 296 | );
|
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 | /** @cat
|
|---|
| 300 | * Output.
|
|---|
| 301 | */
|
|---|
| 302 | BOOL write(
|
|---|
| 303 | const char *pszFilename
|
|---|
| 304 | );
|
|---|
| 305 | APIRET writeToLX(
|
|---|
| 306 | const char *pszFilename
|
|---|
| 307 | );
|
|---|
| 308 |
|
|---|
| 309 | /** @cat
|
|---|
| 310 | * Static read function(s).
|
|---|
| 311 | */
|
|---|
| 312 | static kHll * readLX(
|
|---|
| 313 | const char *pszFilename
|
|---|
| 314 | );
|
|---|
| 315 |
|
|---|
| 316 | /** @cat
|
|---|
| 317 | * Debug dump function.
|
|---|
| 318 | */
|
|---|
| 319 | void dump();
|
|---|
| 320 | void ida(kFile *pFile) throw(int);
|
|---|
| 321 | };
|
|---|
| 322 |
|
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 | #endif
|
|---|
| 326 |
|
|---|