Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx

上传人:b****2 文档编号:1310706 上传时间:2023-04-30 格式:DOCX 页数:16 大小:17.89KB
下载 相关 举报
Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx_第1页
第1页 / 共16页
Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx_第2页
第2页 / 共16页
Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx_第3页
第3页 / 共16页
Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx_第4页
第4页 / 共16页
Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx_第5页
第5页 / 共16页
Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx_第6页
第6页 / 共16页
Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx_第7页
第7页 / 共16页
Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx_第8页
第8页 / 共16页
Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx_第9页
第9页 / 共16页
Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx_第10页
第10页 / 共16页
Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx_第11页
第11页 / 共16页
Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx_第12页
第12页 / 共16页
Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx_第13页
第13页 / 共16页
Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx_第14页
第14页 / 共16页
Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx_第15页
第15页 / 共16页
Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx_第16页
第16页 / 共16页
亲,该文档总共16页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx

《Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx》由会员分享,可在线阅读,更多相关《Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx(16页珍藏版)》请在冰点文库上搜索。

Coperator整理棉猴论坛VIP之DLL程序编写系列教程笔记文档格式.docx

C"

voidShowInfo();

//TODO:

referenceadditionalheadersyourprogramrequireshere

//{{AFX_INSERT_LOCATION}}

//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.

#endif//!

StdAfx.cpp

//stdafx.cpp:

sourcefilethatincludesjustthestandardincludes

//01_001.pchwillbethepre-compiledheader

//stdafx.objwillcontainthepre-compiledtypeinformation

#include"

stdafx.h"

#include<

windows.h>

//Message()

voidShowInfo()

{

MessageBox(NULL,"

ShowInfo()test"

"

MQ"

MB_OK);

}

调用静态链接库

ExecuteStaticLib.cpp

//ExecuteStaticLib.cpp:

Definestheentrypointfortheapplication.

#pragmacomment(lib,"

StaticLibTest.lib"

intAPIENTRYWinMain(HINSTANCEhInstance,

HINSTANCEhPrevInstance,

LPSTRlpCmdLine,

intnCmdShow)

//TODO:

Placecodehere.

ShowInfo();

return0;

二、动态链接库DynamicLinkLibrary(DLL)

DLL的格式和EXE文件是一样的,但是不能直接执行。

它把代码封装到自己的内部,只是提供函数接口让外面的EXE程序调用。

在编译的时候不会将所包含的动态链接库编译到程序中。

制作静态链接库DynamicLibTest

DynamicLibTest.cpp

//DynamicLibTest.cpp:

DefinestheentrypointfortheDLLapplication.

BOOLAPIENTRYDllMain(HANDLEhModule,

DWORDul_reason_for_call,

LPVOIDlpReserved

returnTRUE;

__declspec(dllexport)voidShowInfo()

DynammicLib"

调用动态链接库

ExecuteDynamicLib.cpp

//ExecuteDynamicLib.cpp:

Definestheentrypointfortheconsoleapplication.

DynamicLibTest.lib"

voidShowInfo();

intmain(intargc,char*argv[])

编译的时候用.lib文件,执行的时候用.dll文件

 

第2课DLL基础再讨论

一、动态链接库的模块定义文件(.def)

模块定义文件是一个有着.def文件扩展名的文本文件。

它被用于导出DLL的函数。

一个.def文件只有两个必需的部分,也就是“LIBRARY”和“EXPORTS”。

DynamicLibDefTest.cpp

//DynamicLibDefTest.cpp:

__declspec(dllexport)voidshowInfo()

MessageBox(NULL,"

DynamicLib"

voidUseDEFShowInfo()

defshow"

EXPORTS.def

LIBRARYDynamicLibDefTest

EXPORTSUseDEFShowInfo@1

ExecuteDynamicDEFLib.cpp

//ExecuteDynamicDEFLib.cpp:

DynamicLibDefTest.lib"

voidshowInfo();

voidUseDEFShowInfo();

showInfo();

UseDEFShowInfo();

二、动态链接库的入口函数(DLLMain()函数)

每一个DLL必须有一个入口函数,DLLMain()函数是一个缺省的入口函数。

DLLMain()函数负责初始化和结束工作。

每当一个新的进程或该进程的新线程访问DLL时,或者访问DLL的每个进程或者线程不再使用DLL或者线程结束时,都会调用DLLMain()函数。

定义只在进入时调用DLLMain()函数

switch(ul_reason_for_call)

{

caseDLL_PROCESS_ATTACH:

{

MessageBox(NULL,"

DLLfirst"

}

default:

returnTRUE;

}

第3次课进程权限的提升

一、OpenProcessToken函数

打开进程令牌环

二、LookupPrivilegeValue函数

获得进程本地唯一ID

三、AdjustTokenPrivileges函数

提升进程的权限

GetCurrentProcess()//获得当前进程句柄

ConRunDll.cpp

//ConRunDll.cpp:

stdio.h>

//提升权限用

//提升权限函数

intEnableDebugPriv(constchar*name)

HANDLEhToken;

if(!

OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&

hToken))

printf("

openfail!

\n"

);

return-1;

LUIDluid;

if(!

LookupPrivilegeValue(NULL,name,&

luid))

lookupfail!

TOKEN_PRIVILEGEStp;

tp.PrivilegeCount=1;

tp.Privileges[0].Luid=luid;

tp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;

AdjustTokenPrivileges(hToken,FALSE,&

tp,NULL,NULL,NULL))

privilegesfail!

printf("

success!

EnableDebugPriv(SE_DEBUG_NAME);

第4次课远程线程的创建

一、打开远程进程

OpenProcess函数

二、在远程进程的内存中分配空间

VirtualAllocEx函数

三、远程进程的内存的写入

WriteProcessMemory函数

四、找到LoadLibrary函数在Kernel32中的地址

GetProcAddress函数

五、在远程进程中线程(远程线程)

CreateRemoteThread函数

BOOLInjectDLL(constchar*DLLFullPath,constDWORDdwRemoteProcessId)

{HANDLEhRemoteProcess;

hRemoteProcess=OpenProcess(PROCESS_CREATE_THREAD|PROCESS_VM_OPERATION|PROCESS_VM_WRITE,FALSE,dwRemoteProcessId);

if(hRemoteProcess==NULL)

openprocessfail!

returnFALSE;

char*pszLibFileRemote;

pszLibFileRemote=(char*)VirtualAllocEx(hRemoteProcess,NULL,lstrlen(DLLFullPath)+1,MEM_COMMIT,PAGE_READWRITE);

if(pszLibFileRemote==NULL)

allocfail!

WriteProcessMemory(hRemoteProcess,pszLibFileRemote,(LPVOID)DLLFullPath,lstrlen(DLLFullPath)+1,NULL))

writememoryfail!

PTHREAD_START_ROUTINEpfnStartAddr=

(PTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle(TEXT("

Kernel32"

)),"

LoadLibraryA"

);

if(pfnStartAddr==NULL)

getprocaddrfail!

if(CreateRemoteThread(hRemoteProcess,NULL,0,pfnStartAddr,pszLibFileRemote,0,NULL)==NULL)

createremotethreadfail!

good!

InjectDLL("

D:

\\DynamicLibDefTest.dll"

4892);

while

(1);

getchar();

第5次课进程ID的获取

一、系统进程快照

CreateToolhelp32Snapshot函数

二、在快照中搜索指定进程

Process32First函数

Processe32Next函数

TlHelp32.h>

unsignedlonggetprocid(char*pn)

HANDLEhnd;

hnd=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);

if(hnd==NULL)

snapshortfail!

return0;

PROCESSENTRY32pe;

pe.dwSize=sizeof(PROCESSENTRY32);

BOOLb;

b=Process32First(hnd,&

pe);

while(b)

if(strcmp(pe.szExeFile,pn)==0)

{

returnpe.th32ProcessID;

}

b=Process32Next(hnd,&

//InjectDLL("

getpro

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 小学教育 > 语文

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2