// LoadRemoteDLL.h: interface for the CLoadRemoteDLL class.
//
//////////////////////////////////////////////////////////////////////

#pragma once

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Module32HLP.h"

class CLoadRemoteDLL  
{
// constructors & destructor
public:
    CLoadRemoteDLL(LPCWSTR swDllName, HANDLE hTargetProcess);
	virtual ~CLoadRemoteDLL( );

// Attributes
private:
    PBYTE                   m_pCopyOf_idata;
    PBYTE                   m_pRemote_idata;
    DWORD                   m_dw_idataSize;
protected:
    HANDLE                  m_hProcessHandle;
public:
    PBYTE                   m_pRemoteModuleBase;
    PBYTE                   m_pRemotePEHeaders;
    IMAGE_NT_HEADERS        m_stPEImageHeaders;
    SIZE_T                  m_nViewSize;
    CModule32HLP            m_objModule32HLP;

// Operations
public:
	PBYTE GetExportEntryAddress(
        PCSTR psEntryName,
        PBYTE pRemoteModuleBase
                               );
	PBYTE FindExportByName( PCSTR psEntryName, PBYTE pRemoteModuleBase );
	bool RelocationsFixUp( );
	bool ImportsTableFixUp( );
	bool ElaborateAll(
        PSECURITY_DESCRIPTOR pDLLFileSD,
        PSECURITY_DESCRIPTOR pDLLSectionSD
                     );
	bool OpenAndMapDLLFile(
        PCWSTR pwsDLLFileName,
        PSECURITY_DESCRIPTOR pDLLFileSD,
        PSECURITY_DESCRIPTOR pDLLSectionSD
                          );
private:
	PBYTE FindExportByName(
        PIMAGE_IMPORT_BY_NAME   pImportStruct,
        PIMAGE_EXPORT_DIRECTORY pExportDirectory,
        PBYTE                   pImageBase,
        DWORD                   dwExportTableRVA,
        DWORD                   dw_edataSize,
        DWORD_PTR               dwUpdateAddr
        );
	PBYTE EvaluteForwardExport( PCSTR psForwardRef );
	bool ParseExportTable(
        HMODULE     hExporter,
        DWORD_PTR   dwImageSize,
        PIMAGE_IMPORT_DESCRIPTOR pImportDesc,
        DWORD_PTR   dwImportUpdateAddr
        );
public:
    CModule32HLP m_objParentModule32HLP;
    WCHAR m_swDllName[260];
    bool m_bProcessNotStartUp;
    IMAGE_IMPORT_DESCRIPTOR* m_pCopyImpDirectoty;
    DWORD m_dw_idataRVA;
    PBYTE m_pLocalModuleBase;
    SIZE_T m_nLocalViewSize;
};
