逆向分析_DLL基础(4)

DLL基础(4) 变量导出
dll项目,名称:dllvar

dllvar.h

//dllvar.h
#include

#ifdef DLLVAR_EXPORTS
#define DLLVAR_API __declspec(dllexport)
#else
#define DLLVAR_API __declspec(dllimport)
#endif

extern DLLVAR_API int nDllvar;

nDllvar全局导出变量

dllvar.cpp

//dllvar.cpp
#include
#include "dllvar.h"

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
			//nDllvar = 100;
			break;
		case DLL_THREAD_ATTACH:
		case DLL_THREAD_DETACH:
		case DLL_PROCESS_DETACH:
			break;
    }
    return TRUE;
}

DLLVAR_API int nDllvar = 10;
创建win32 console项目加载dll

把dllvar.lib dllvar.dll复制到该项目下。
dllvar_main.cpp

//dllvar_main.cpp
#include 
#pragma comment(lib,"dllvar.lib")
extern int _declspec(dllimport) nDllvar;

int main(int argc, char *argv[])
{
	printf("%d ",nDllvar);
	nDllvar = 2;
	printf("%d ",nDllvar);
	return 0;
}

你可能感兴趣的:(Binary)