Other Advanced Topic on DLL - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Other Advanced Topic on DLL

Description:

Other Advanced Topic on DLL http://debut.cis.nctu.edu.tw/~ching Export name DLL .def export ... – PowerPoint PPT presentation

Number of Views:62
Avg rating:3.0/5.0
Slides: 15
Provided by: edut1550
Category:
Tags: dll | advanced | topic

less

Transcript and Presenter's Notes

Title: Other Advanced Topic on DLL


1
Other Advanced Topic on DLL
????? http//debut.cis.nctu.edu.tw/ching
2
????? Export name
MyDLL.def ??
__declspec(dllexport) ??
  • ???? DLL ? .def ??????? export name

RVA ????
2
1
LIBRARY MyDLL EXPORTS AddnewAdd
?? Addnew ????? Add
dumpbin /exports MyDLL.dll
MyDLL.def
3
3
?? ordinal number
LIBRARY MyDLL EXPORTS AddnewAdd _at_12345
?? Addnew ? ordinal number 12345
MyDLL.def
??? _at_12345 ??
__declspec(dllexport) ??
DLL ???
MyDLL.def ??
dumpbin /exports MyDLL.dll
lib ???
dumpbin /exports MyDLL.lib
4
??? exported ? name
  • ? .def ???
  • NONAME ??
  • ??????? ordinal ???? function
  • export name ???? .dll ??, ??? dll???
  • PRIVATE ?? .def ? EXPORTS ? name ???? .lib ?

5
????
Step 1
?? __declspec(dllexport) ??
ifdef MYLIBExport define MYLIBAPI extern
"C" //__declspec(dllexport) else define
MYLIBAPI extern "C" //__declspec(dllimport) endif
MYLIBAPI int g_nResult MYLIBAPI int Add(int
nLeft, int nRight)
MyDLL.h
Step 3
???? (dumpbin)
Step 2
?? NONAME ? PRIVATE ???
LIBRARY MyDLL EXPORTS AddnewAdd _at_12345 NONAME
DLL ???
lib ???
MyDLL.def
??
6
?? name ?????
  • ?? ordinal number

DLL ???
include ltwindows.hgt typedef int
(ADDPF)(int,int) int _tmain(int argc, _TCHAR
argv) HMODULE hModuleLoadLibrary("MyDLL.dll"
) ADDPF pf(ADDPF)GetProcAddress(hModule,(LPCSTR
)12345) int c(pf)(1,2) return 0
?? ordinal number ?? Function ?????
???????
7
DLL Forward
  • ???? DumpBin ? Kernel32.dll ????

??? forwarded ?????
?????????? HeapAlloc ,
??????? RtlAllocateHeap
8
DLL Forward
2 forwarded
HeapAlloc()
RtlAllocateHeap()
1
3
Kernel32.dll
NTDLL.dll
9
???????? forwarded?
???, ????
????? function
??? name
pragma comment(linker, "/exportAddNewDLL.NewAdd
")
?DLL name
10
??
2
1
???? forwarded ???
int main( ) int dAdd(1,2) cout ltlt
d ltlt endl return 0
pragma comment(linker, \ "/exportAddNewDLL.
NewAdd") // ???? MYLIBAPI int Add(int nLeft, int
nRight) g_nResult nLeft nRight
return(g_nResult)
UseDLL.cpp
MyDLL
// ???? MYLIBAPI int NewAdd(int x, int y)
int sumxy10 return(sum)
3
NewDLL
11
??
  • ?? NewDLL ?? NewDLL.dll ? NewDLL.lib
  • ?? MyDLL ?? MyDLL.dll ? MyDLL.lib
  • ?? UseDLL
  • ?? MyDLL.lib ?????????
  • ???, NewDLL.dll ? MyDLL.dll ???????????

UseDLL ? Linker Option
??????? Add symbol
????? Delay Loaded DLLs ???????Add ??
12
????? name
13
????
?? ??? Add ?? forward ? NewDLL??
14
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com