4 #include "../Include/Winheaders.h"
5 #include "../Include/Types.h"
6 #include "../Misc/Utils.h"
10 #endif // COMPILER_MSVC
16 #include <unordered_map>
44 std::string importName;
58 ExportData(
const std::string& name_, uint32_t rva_ )
64 return name == other.name;
69 return name < other.name;
74 typedef std::unordered_map<std::wstring, std::vector<ImportData>> mapImports;
75 typedef std::vector<IMAGE_SECTION_HEADER> vecSections;
76 typedef std::vector<ExportData> vecExports;
83 typedef const IMAGE_NT_HEADERS32* PCHDR32;
84 typedef const IMAGE_NT_HEADERS64* PCHDR64;
88 BLACKBONE_API ~PEImage(
void );
96 BLACKBONE_API NTSTATUS
Load(
const std::wstring&
path,
bool skipActx =
false );
105 BLACKBONE_API NTSTATUS
Load(
void* pData,
size_t size,
bool plainData =
true );
116 BLACKBONE_API NTSTATUS
Parse(
void* pImageBase =
nullptr );
123 BLACKBONE_API mapImports&
GetImports(
bool useDelayed =
false );
129 BLACKBONE_API
void GetExports( vecExports& exports );
138 BLACKBONE_API
int GetTLSCallbacks( module_t targetBase, std::vector<ptr_t>& result )
const;
146 BLACKBONE_API
size_t DirectoryAddress(
int index,
bool keepRelative =
false )
const;
161 BLACKBONE_API
size_t ResolveRVAToVA(
size_t Rva,
bool keepRelative =
false )
const;
167 BLACKBONE_API
inline const std::wstring&
path()
const {
return _imagePath; }
179 BLACKBONE_API
inline void*
base()
const {
return _pFileBase; }
185 BLACKBONE_API
inline module_t
imageBase()
const {
return _imgBase; }
191 BLACKBONE_API
inline size_t imageSize()
const {
return _imgSize; }
197 BLACKBONE_API
inline size_t headersSize()
const {
return _hdrSize; }
204 BLACKBONE_API
inline ptr_t
entryPoint( module_t
base )
const {
return ((_epRVA != 0) ? (_epRVA + base) : 0); };
210 BLACKBONE_API
inline const vecSections&
sections()
const {
return _sections; }
216 BLACKBONE_API
inline bool IsExe()
const {
return _isExe; }
228 BLACKBONE_API
inline eModType
mType()
const {
return _is64 ? mt_mod64 : mt_mod32; }
234 BLACKBONE_API
inline HANDLE
actx()
const {
return _hctx; }
240 BLACKBONE_API
inline bool isPlainData()
const {
return _isPlainData; }
246 BLACKBONE_API
inline int manifestID()
const {
return _manifestIdx; }
252 BLACKBONE_API
inline uint32_t
subsystem()
const {
return _subsystem; }
258 BLACKBONE_API
inline const std::wstring&
manifestFile()
const {
return _manifestPath; }
264 BLACKBONE_API
inline bool noPhysFile()
const {
return _noFile; }
267 BLACKBONE_API ImageNET& net() {
return _netImage; }
280 NTSTATUS PrepareACTX(
const wchar_t* filepath =
nullptr );
288 void* GetManifest( uint32_t& size,
int&
manifestID );
291 HANDLE _hFile = INVALID_HANDLE_VALUE;
292 HANDLE _hMapping = NULL;
293 void* _pFileBase =
nullptr;
294 bool _isPlainData =
false;
297 bool _isPureIL =
false;
298 bool _noFile =
false;
299 PCHDR32 _pImageHdr32 =
nullptr;
300 PCHDR64 _pImageHdr64 =
nullptr;
302 uint32_t _imgSize = 0;
304 uint32_t _hdrSize = 0;
305 HANDLE _hctx = INVALID_HANDLE_VALUE;
306 int _manifestIdx = 0;
309 vecSections _sections;
311 mapImports _delayImports;
313 std::wstring _imagePath;
314 std::wstring _manifestPath;
BLACKBONE_API bool IsExe() const
Check if image is an executable file and not a dll
Definition: PEImage.h:216
BLACKBONE_API mapImports & GetImports(bool useDelayed=false)
Processes image imports
Definition: PEImage.cpp:218
Import information
Definition: PEImage.h:42
BLACKBONE_API bool isPlainData() const
true if image is mapped as plain data file
Definition: PEImage.h:240
BLACKBONE_API eModType mType() const
Get image type. 32/64 bit
Definition: PEImage.h:228
BLACKBONE_API module_t imageBase() const
Get image base address
Definition: PEImage.h:185
BLACKBONE_API int manifestID() const
Get manifest resource ID
Definition: PEImage.h:246
Export function info
Definition: PEImage.h:53
BLACKBONE_API NTSTATUS Load(const std::wstring &path, bool skipActx=false)
Load image from file
Definition: PEImage.cpp:33
BLACKBONE_API std::wstring name() const
Get image name
Definition: PEImage.h:173
BLACKBONE_API size_t headersSize() const
Get size of image headers
Definition: PEImage.h:197
BLACKBONE_API size_t DirectorySize(int index) const
Get data directory size
Definition: PEImage.cpp:404
BLACKBONE_API void * base() const
Get image load address
Definition: PEImage.h:179
BLACKBONE_API void GetExports(vecExports &exports)
Retrieve all exported functions with names
Definition: PEImage.cpp:332
Primitive PE parsing class
Definition: PEImage.h:81
BLACKBONE_API size_t DirectoryAddress(int index, bool keepRelative=false) const
Retrieve data directory address
Definition: PEImage.cpp:357
BLACKBONE_API const std::wstring & path() const
Get image path
Definition: PEImage.h:167
BLACKBONE_API HANDLE actx() const
Get activation context handle
Definition: PEImage.h:234
BLACKBONE_API size_t imageSize() const
Get image size in bytes
Definition: PEImage.h:191
BLACKBONE_API size_t ResolveRVAToVA(size_t Rva, bool keepRelative=false) const
Resolve virtual memory address to physical file offset
Definition: PEImage.cpp:378
BLACKBONE_API void Release()
Release mapping, if any
Definition: PEImage.cpp:102
BLACKBONE_API const std::wstring & manifestFile() const
Get manifest resource file
Definition: PEImage.h:258
BLACKBONE_API ptr_t entryPoint(module_t base) const
Get image entry point rebased to another image base
Definition: PEImage.h:204
BLACKBONE_API uint32_t subsystem() const
Get image subsystem
Definition: PEImage.h:252
BLACKBONE_API bool IsPureManaged() const
Check if image is pure IL image
Definition: PEImage.h:222
static BLACKBONE_API std::wstring StripPath(const std::wstring &path)
Get filename from full-qualified path
Definition: Utils.cpp:81
Definition: AsmHelper32.cpp:6
BLACKBONE_API int GetTLSCallbacks(module_t targetBase, std::vector< ptr_t > &result) const
Retrieve image TLS callbacks Callbacks are rebased for target image
Definition: PEImage.cpp:427
BLACKBONE_API NTSTATUS Parse(void *pImageBase=nullptr)
Parses PE image
Definition: PEImage.cpp:145
BLACKBONE_API const vecSections & sections() const
Get image sections
Definition: PEImage.h:210
BLACKBONE_API bool noPhysFile() const
If true - no actual PE file available on disk
Definition: PEImage.h:264