汇编环境MASMPlus,以下代码摘自IDA反汇编,小弟初学,搞不清原因,敬请指点。
目的:把以下代码编译成一个obj文件,再在VC++中调用此中的函数
问题:汇编编译时顺利通过,但在VC++中引用产生的obj文件进行编译链接时报错:无法解析的外部符号定义...
;****************************************************************
; * 编译obj文件
; * ml /c /coff study.asm
;****************************************************************
;****************************************************************
;* 在c++ 中调用方式 *
;* extern "C" void _stdcall ChangeSectorSize(BYTE SectorSize); *
;****************************************************************
.686p
.model flat,c
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 数据
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include kernel32.inc ;需在此添加库,不然编译无法通过
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 要使用的外部变量声明
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Equ 数据
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 函数定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data
.......
.......
.......
略过...
.......
.......
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
sub_615CE0 proc near
var_34 = dword ptr -34h
var_30 = dword ptr -30h
var_2C = dword ptr -2Ch
var_28 = dword ptr -28h
var_24 = dword ptr -24h
var_20 = dword ptr -20h
arg_0 = dword ptr 4
arg_4 = dword ptr 8
arg_8 = dword ptr 0Ch
sub esp, 34h
push ebx
push esi
push edi
call sub_615BE0
test eax, eax
jz short loc_615CF9
pop edi
pop esi
or eax, 0FFFFFFFFh
pop ebx
add esp, 34h
retn
; ---------------------------------------------------------------------------
loc_615CF9:
mov ecx, [esp+40h+arg_8]
xor ebx, ebx
xor dl, dl
mov byte ptr [esp+40h+var_34], dl
...
...
...
; ---------------------------------------------------------------------------
loc_615E35:
mov edx, dword_6E6670 ; <--------------case 11:
mov eax, dword_6E6674
push ebx ; time_t *
mov [esp+44h+var_30], edx
mov [esp+44h+var_2C], eax
;call _time
add esp, 4
mov [esp+40h+var_28], eax
call ds:GetTickCount
mov edx, [esp+40h+arg_4]
lea ecx, [esp+40h+var_20]
mov [esp+40h+var_24], eax
push ecx
push edx
lea eax, [esp+48h+var_30]
push 10h
push eax
call sub_615550
add esp, 10h
xor eax, eax
pop edi
pop esi
pop ebx
add esp, 34h
......
......
......
retn
sub_615CE0 endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;sub_615BE0函数代码如下:
sub_615BE0 proc near
push esi
push offset LibFileName ; "kernel32.dll"
call ds:LoadLibraryA
mov esi, eax
test esi, esi
jnz short loc_615BFE
push eax ; hLibModule
call ds:FreeLibrary
or eax, 0FFFFFFFFh
pop esi
retn
; ---------------------------------------------------------------------------
loc_615BFE:
push offset ProcName ; "IsDebuggerPresent"
push esi ; hModule
call ds:GetProcAddress
test eax, eax
jnz short loc_615C1C
push esi ; hLibModule
call ds:FreeLibrary
mov eax, 0FFFFFFFEh
pop esi
retn
; ---------------------------------------------------------------------------
loc_615C1C:
push edi
call eax
push esi ; hLibModule
mov edi, eax
call ds:FreeLibrary
mov eax, edi
pop edi
pop esi
retn
sub_615BE0 endp
请求分析、指点?为何汇编编译通过后,在VC引时出现错误:
error LNK2001: unresolved external symbol _FreeLibrary
error LNK2001: unresolved external symbol _GetProcAddress
error LNK2001: unresolved external symbol _GetTickCount
error LNK2001: unresolved external symbol _LoadLibraryA
fatal error LNK1120: 4 unresolved externals
执行 link.exe 时出错.
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!