下面是我写的一个动态库,初学者,莫笑!
.386
.model flat,stdcall
option casemap:none
include windows.inc
;∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏
.data?
dwCount dd ?
.data
hInstanceDll dd ?
;∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏
.code
_DllEntry proc hInstDll,dwReason,dwReserved
; mov eax,dwReason
; .if eax == DLL_PROCESS_ATTACH
; puch hInstDll
; pop hInstanceDll
; .endif
mov eax,TRUE
ret
_DllEntry endp
_CheckCount proc
mov eax,dwCount
cmp eax,0
jge @F
mov eax,0
@@:
cmp eax,10
jle @F
mov eax,10
@@:
mov dwCount,eax
ret
_CheckCount endp
;∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏
_IncCount proc
inc dwCount
call _CheckCount
ret
_IncCount endp
;∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏∏
_DecCount proc
dec dwCount
call _CheckCount
ret
_DecCount endp
End _DllEntry
下面是一个调用此DLL的程序:
.386
.model flat,stdcall
option casemap:none
;GLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLF
_PROCVAR0 typedef proto
PROCVAR0 typedef ptr _PROCVAR0
;GLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLF
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include FirstDll.inc
includelib FirstDll.lib
;GLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLF
IDD_DLG1 equ 1000
IDC_STC1 equ 1001
IDC_RESULT equ 1002
IDC_DEC equ 1003
IDC_INC equ 1004
IDC_STC2 equ 1005
;GLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLF
.data?
hWinMain dd ?
hInstance dd ?
hDllInstance dd ?
lpIncCount PROCVAR0 ?
lpDecCount PROCVAR0 ?
.const
szError db '装载FirstDll.dll失败,可能丢失活装载失败,程序功能无法实现!',0
szDll db 'FirstDll.dll',0
szIncCount db '_IncCount',0
szDecCount db '_DecCount',0
;GLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLFGLCWOLF
.code
_DlgFunc proc uses ebx edi esi hWnd,uMsg,wParam,lParam
mov eax,uMsg
.if eax == WM_CLOSE
invoke EndDialog,hWnd,NULL
invoke ExitProcess,NULL
invoke FreeLibrary,hDllInstance
.elseif eax == WM_INITDIALOG
invoke LoadLibrary,offset szDll
.if eax
mov hDllInstance,eax
invoke GetProcAddress,hDllInstance,offset szIncCount
mov lpIncCount,eax
invoke GetProcAddress,hDllInstance,offset szDecCount
mov lpDecCount,eax
.else
invoke MessageBox,hWnd,offset szError,0,MB_OK or MB_ICONWARNING
invoke GetDlgItem,hWnd,IDC_INC
invoke EnableWindow,eax,FALSE
invoke GetDlgItem,hWnd,IDC_DEC
invoke EnableWindow,eax,FALSE
.endif
.elseif eax == WM_COMMAND
mov eax,wParam
.if ax == IDC_INC
.if lpIncCount
invoke lpIncCount
.endif
invoke SetDlgItemInt,hWnd,IDC_RESULT,eax,FALSE
.elseif ax == IDC_DEC
.if lpDecCount
invoke lpDecCount
.endif
invoke SetDlgItemInt,hWnd,IDC_RESULT,eax,FALSE
.else
mov eax,FALSE
ret
.endif
.else
xor eax,eax
ret
.endif
mov eax,TRUE
ret
_DlgFunc endp
start: invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,IDD_DLG1,NULL,_DlgFunc,NULL
mov hWinMain,eax
invoke ExitProcess,NULL
end start
在RADASM里编译通过!
但是在设置DLL工程选项的时候,我已经把连接选项设置成了:7,O,$B\LINK.EXE /SUBSYSTEM:WINDOWS /RELEASE /DLL /SECTION:.BSS|S /DEF:$6 /LIBPATH:"$L" /OUT:"$7",3,但是在使用DLL的时候,还是无法实现.data?数据段的共享,不知道为什么,希望大家给点意见!谢谢!
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)