12   1  /  2  页   跳转

How Are DLLs Linked to Executables

How Are DLLs Linked to Executables

The executable code is located in the .text section of PE files (or in the CODE section, as the Borland linker calls it). When the application calls a function that is in a DLL, the actual CALL instruction does not call the DLL directly. Instead, it goes first to a jump (JMP DWORD PTR [XXXXXXXX]) instruction somewhere in the executable's .text section (or in the CODE section in the case of Borland linkers).
The address that the jump instruction looks up is stored in the .idata section (or sometimes in .text) and is called an entry within the IAT (Import Address Table).

用户系统信息:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; QQDownload 1.7; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506)

对个人来讲,统计,仪器,高速的计算机可以让人们得到大量充裕的时间。
这个社会中,更不可缺的是具备现代化的管理经验。
分享到:
gototop
 

回复:How Are DLLs Linked to Executables

受不了了

你还真来这个了
gototop
 

回复:How Are DLLs Linked to Executables

是用jmp的方式还是直接call,这跟编译器有关。
这段说白了就是输入表是怎么起作用的,好好看看PE文件格式,再加上对Win32汇编的了解,你就会知道是怎么回事了。单纯截取这一段没有意义。
病毒样本请发到可疑文件交流区
gototop
 

回复 1F 文物2 的帖子

哈哈,还是全英语的啊
gototop
 

回复:How Are DLLs Linked to Executables

jmp分短跳转和近跳转。call命令会先行进入下一行命令。

jmp和call有本质的不同。他们MS和引入表关系不密切

对个人来讲,统计,仪器,高速的计算机可以让人们得到大量充裕的时间。
这个社会中,更不可缺的是具备现代化的管理经验。
gototop
 

回复: How Are DLLs Linked to Executables



引用:
原帖由 文物2 于 2008-10-6 22:54:00 发表
jmp分短跳转和近跳转。call命令会先行进入下一行命令。

jmp和call有本质的不同。他们MS和引入表关系不密切 

自己试试吧,两段asm给你试:

a.asm,masm标准方式,使用jmp dword ptr[&API]方式:

.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
.const
LpName db "kernel32",0

.code

start proc
invoke LoadLibrary, offset LpName
invoke ExitProcess, NULL
ret
start endp

end start


b.asm,使用call dword ptr [&API]方式:

.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

.const
LpName db "kernel32",0

.code
_imp__LoadLibraryA proto: DWORD
_imp__ExitProcess proto: DWORD

start proc
push offset LpName
call dword ptr [_imp__LoadLibraryA]
push 0
call dword ptr [_imp__ExitProcess]
ret
start endp

end start
病毒样本请发到可疑文件交流区
gototop
 

回复: How Are DLLs Linked to Executables

a.asm编译后的a.exe,用OD载入:

00401000 >/$  68 0C204000  push    0040200C                        ; /FileName = "kernel32"
00401005  |.  E8 0E000000  call    <jmp.&kernel32.LoadLibraryA>    ; \LoadLibraryA
0040100A  |.  6A 00        push    0                                ; /ExitCode = 0
0040100C  \.  E8 01000000  call    <jmp.&kernel32.ExitProcess>      ; \ExitProcess
00401011  .  C3            retn
00401012  .- FF25 04204000 jmp    dword ptr [<&kernel32.ExitProces>;  kernel32.ExitProcess
00401018  $- FF25 00204000 jmp    dword ptr [<&kernel32.LoadLibrar>;  kernel32.LoadLibraryA

单步到第一个call处,F7,进入最下方的命令处,再F8,进入LoadLibraryA函数开头:

7C801D7B >  8BFF            mov    edi, edi
7C801D7D    55              push    ebp
7C801D7E    8BEC            mov    ebp, esp
7C801D80    837D 08 00      cmp    dword ptr [ebp+8], 0
7C801D84    53              push    ebx
7C801D85    56              push    esi

查看堆栈:

0012FFBC  0040100A  /CALL 到 LoadLibraryA 来自 a.00401005
0012FFC0  0040200C  \FileName = "kernel32"


b.asm编译的b.exe,用OD载入

00401000 >/$  68 0C204000        push    0040200C                                      ; /FileName = "kernel32"
00401005  |.  FF15 04204000      call    dword ptr [<&kernel32.LoadLibraryA>]          ; \LoadLibraryA
0040100B  |.  6A 00              push    0                                            ; /ExitCode = 0
0040100D  \.  FF15 00204000      call    dword ptr [<&kernel32.ExitProcess>]          ; \ExitProcess
00401013  .  C3                retn
00401014  .- FF25 04204000      jmp    dword ptr [<&kernel32.LoadLibraryA>]          ;  kernel32.LoadLibraryA
0040101A  .- FF25 00204000      jmp    dword ptr [<&kernel32.ExitProcess>]          ;  kernel32.ExitProcess

单步到第一个call处,F7,直接进入LoadLibraryA函数开头。

查看堆栈:

0012FFBC  0040100B  /CALL 到 LoadLibraryA 来自 b.00401005
0012FFC0  0040200C  \FileName = "kernel32"


对比两次的堆栈,可以看到,无论是哪种方式,进入LoadLibraryA函数时,堆栈中的返回地址,都指向代码中call命令的下一条指令。因此,进入LoadLibraryA函数时,系统无从“分辨”调用到底是通过两种方式中的哪一种实现的。同样的,这也并不影响LoadLibraryA函数返回。
最后编辑轩辕小聪 最后编辑于 2008-10-07 18:19:37
病毒样本请发到可疑文件交流区
gototop
 

回复:How Are DLLs Linked to Executables

从6楼和7楼的实验,可以看出,用masm是完全可以编译出直接call dword ptr [&API]方式调用API的程序的。

该书中所讲的,其实只是编译器在其一般默认的设置下、程序员用一般的方法调用API(或者不直接调用API,只使用经封装了的库函数),产生的是jmp dword ptr [&API]的代码。

另外,这个实验里编译出来的程序,IAT所在的区块也不是.idata。
最后编辑轩辕小聪 最后编辑于 2008-10-07 18:40:00
病毒样本请发到可疑文件交流区
gototop
 

回复:How Are DLLs Linked to Executables

小聪学长,十分感谢。只是我不明白,使用a.asm,b.asm.编译时发生了错误,我没有办法产生可执行文件


引用:

C:\MASM615>masm a
Microsoft (R) MASM Compatibility Driver
Copyright (C) Microsoft Corp 1993.  All rights reserved.

Invoking: ML.EXE /I. /Zm /c /Ta a.asm

Microsoft (R) Macro Assembler Version 6.15.8803
Copyright (C) Microsoft Corp 1981-2000.  All rights reserved.

Assembling: a.asm
\masm615\include\windows.inc(12276) : error A2161: non-benign structure redefini
tion: too few labels : CREATE_THREAD_DEBUG_INFO
\masm615\include\windows.inc(14271) : error A2005: symbol redefinition : Type1
\masm615\include\windows.inc(14316) : error A2005: symbol redefinition : Type1
\masm615\include\windows.inc(14320) : error A2005: symbol redefinition : Type1
\masm615\include\windows.inc(14323) : fatal error A1010: unmatched block nesting


A2161 non-benign structure redefinition : too few labels
Not enough members were defined in a structure redefinition.

A2005 symbol redefinition : identifier
The given nonredefinable symbol was defined in two places.
最后编辑文物2 最后编辑于 2008-10-09 21:13:15

对个人来讲,统计,仪器,高速的计算机可以让人们得到大量充裕的时间。
这个社会中,更不可缺的是具备现代化的管理经验。
gototop
 

回复:How Are DLLs Linked to Executables

……
你的masm的inc文件有问题吧……
一般使用MASM32进行编译。
最后编辑轩辕小聪 最后编辑于 2008-10-13 17:41:18
病毒样本请发到可疑文件交流区
gototop
 
12   1  /  2  页   跳转
页面顶部
Powered by Discuz!NT