-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91c418f
commit 37824da
Showing
8 changed files
with
154 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "stdafx.h" | ||
#include "ImportRebuilder.h" | ||
|
||
bool ImportRebuilder::RebuildImportTable(const WCHAR* newFilePath, | ||
std::map<DWORD_PTR, ImportModuleThunk>& moduleThunkMap){ | ||
bool ret = false; | ||
std::map<DWORD_PTR, ImportModuleThunk> copyModule; | ||
copyModule.insert(moduleThunkMap.begin(), moduleThunkMap.end()); | ||
|
||
if (IsValid()) { | ||
SetDefaultFileAligment(); | ||
|
||
ret = BuildNewImportTable(copyModule); | ||
if (ret) { | ||
AlignAllSectionHeaders(); | ||
|
||
} | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
bool ImportRebuilder::BuildNewImportTable(std::map<DWORD_PTR, ImportModuleThunk>& moduleThunkMap) { | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
#include <PEParser.h> | ||
#include "Thunks.h" | ||
#include "IATReferenceScan.h" | ||
#include <PEParser.h> | ||
|
||
class ImportRebuilder: public PEParser{ | ||
public: | ||
ImportRebuilder(const WCHAR* file): PEParser(file) { | ||
} | ||
bool RebuildImportTable(const WCHAR* newFilePath, std::map<DWORD_PTR, ImportModuleThunk>& moduleThunkMap); | ||
void EnableOFTSupport(); | ||
void EnableNewIATInSection(DWORD_PTR iatAddress, DWORD iatSize); | ||
|
||
private: | ||
PIMAGE_IMPORT_DESCRIPTOR _pImportDescriptor = nullptr; | ||
PIMAGE_THUNK_DATA _pThunkData = nullptr; | ||
PIMAGE_IMPORT_BY_NAME _pImportByName = nullptr; | ||
|
||
size_t _numberOfImportDescriptors; | ||
size_t _sizeOfImportSection; | ||
size_t _sizeOfApiAndModuleNames; | ||
size_t _importSectionIndex; | ||
|
||
// OriginalFirstThunk Array in import section | ||
size_t _sizeOfOFTArray; | ||
bool _useOFT; | ||
bool _newIATInSection; | ||
DWORD_PTR _iatAddress; | ||
|
||
DWORD _iatSize; | ||
DWORD _sizeOfJumpTable; | ||
|
||
DWORD _directImportsJumpTableRVA; | ||
BYTE* _pJmpTableMemory; | ||
DWORD _newIATBaseAddressRVA; | ||
|
||
DWORD FillImportSection(std::map<DWORD_PTR, ImportModuleThunk>& moduleThunkMap); | ||
BYTE* GetMemoryPointerFromRVA(DWORD_PTR rva); | ||
bool CreateNewImportSection(std::map<DWORD_PTR, ImportModuleThunk>& moduleThunkMap); | ||
bool BuildNewImportTable(std::map<DWORD_PTR, ImportModuleThunk>& moduleThunkMap); | ||
void SetFlagToIATSection(DWORD_PTR iatAddress); | ||
size_t AddImportToImportTable(ImportThunk* pImportThunk, PIMAGE_THUNK_DATA* pThunkData, PIMAGE_IMPORT_BY_NAME pImportByName, | ||
DWORD sectionOffset); | ||
size_t AddImportDescriptor(ImportModuleThunk* pImportThunk, DWORD sectionOffset, DWORD sectionOffsetOFTArray); | ||
|
||
void CalculateImportSize(std::map<DWORD_PTR, ImportModuleThunk>& moduleThunkMap); | ||
|
||
void AddSepecialImportDescriptor(DWORD_PTR rvaFirstThunk, DWORD sectionOffsetOFTArray); | ||
void PatchFileForNewIATLocation(); | ||
void ChangeIATBaseAddress(std::map<DWORD_PTR, ImportModuleThunk>& moduleThunkMap); | ||
void PatchFileForDirectImportJumpTable(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters