blob: 9da7801662b755522211501524b46fbd4dc32d72 (
plain)
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
|
/*
* Copyright (C) 2005-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#pragma once
//#pragma message("including coffldr.h")
#include "coff.h"
#include <stdio.h>
class CoffLoader
{
public:
CoffLoader();
virtual ~CoffLoader();
int ParseCoff(FILE *fp);
int ParseHeaders(void* hModule);
void *hModule; //standard windows HINSTANCE handle hold the whole image
//Pointers to somewhere in hModule, do not free these pointers
COFF_FileHeader_t *CoffFileHeader;
OptionHeader_t *OptionHeader;
WindowsHeader_t *WindowsHeader;
Image_Data_Directory_t *Directory;
SectionHeader_t *SectionHeader;
protected:
// Allocated structures... hModule now hold the master Memory handle
SymbolTable_t *SymTable;
char *StringTable;
char **SectionData;
unsigned long EntryAddress; //Initialize entry point
// Unnecessary data
// This is data that is used only during linking and is not necessary
// while the program is running in general
int NumberOfSymbols;
int SizeOfStringTable;
int NumOfDirectories;
int NumOfSections;
int FileHeaderOffset;
// Members for printing the structures
static void PrintFileHeader(COFF_FileHeader_t *FileHeader);
static void PrintWindowsHeader(WindowsHeader_t *WinHdr);
static void PrintOptionHeader(OptionHeader_t *OptHdr);
static void PrintSection(SectionHeader_t* ScnHdr, const char* data);
void PrintStringTable(void);
void PrintSymbolTable(void);
// Members for Loading the Different structures
int LoadCoffHModule(FILE * fp);
int LoadSymTable(FILE *fp);
int LoadStringTable(FILE *fp);
int LoadSections(FILE *fp);
// Members for access some of the Data
int RVA2Section(unsigned long RVA);
void* RVA2Data(unsigned long RVA);
unsigned long Data2RVA(void* address);
char *GetStringTblIndex(int index);
char *GetStringTblOff(int Offset);
char *GetSymbolName(SymbolTable_t *sym);
char *GetSymbolName(int index);
void PerformFixups(void);
};
|