ASM 写DLL 模拟鼠标操作代码

;====================myDLL.asm

.586
.model flat,stdcall
option casemap:none

   include myDLL.inc


.const

 
  INPUT_MOUSE equ 0h
  INPUT_KEYBOARD equ 1h
  INPUT_HARDWARE equ 2h
 
  CTROL_ID equ 16Dh
 
.data


.data?
 
   hInstance dd ?
   ;hMainWND  dd ?
   g_hDllMain dd ?
         
  
 MOUSEINPUT struct
 dxx dword ?
 dy dword ?
 mouseData dword ?
 dwFlags dword ?
 time dword ?
 dwExtraInfo dword ?
MOUSEINPUT Ends

 KEYBDINPUT struct
 wVk  dword ?
 wScan dword ?
 dwFlags dword ?
 time dword ?
 dwExtraInfo dword ?
KEYBDINPUT Ends

 HARDWAREINPUT struct
 uMsg dword ?
 wParamL dword ?
 wParamH dword ?
HARDWAREINPUT Ends

 INPUT_MOUSE_DATA struct
 dwtype dword ?
 mi  MOUSEINPUT <?,?,?,?,?,?>
INPUT_MOUSE_DATA Ends


 INPUT_KEYBD_DATA struct
 typee dword ?
 ki  KEYBDINPUT <?>
INPUT_KEYBD_DATA Ends


 INPUT_HD_DATA struct
 typee dword ?
 hi  HARDWAREINPUT <?>
INPUT_HD_DATA Ends


   .code
  
;DLL的入口函数
;#########################################################################

DllEntry proc hModule:HINSTANCE, dwReason:DWORD, lpReserved:DWORD
 
    .IF dwReason == DLL_PROCESS_ATTACH
        mov eax, hModule
        mov g_hDllMain, eax
        mov eax, TRUE
    .ELSEIF
        mov eax, FALSE
    .ENDIF
    ret
    
DllEntry Endp


;--------------------以上这些内容为DLL函数导出为可注册DLL必须的过程
;#########################################################################
;  Output Window procs

  myDLL_Mouse proc   hMainWND:DWORD,hCTROLID:DWORD                              
                 LOCAL keydata:KEYBDINPUT
                 LOCAL x:MOUSEINPUT
                 LOCAL y:HARDWAREINPUT
                 LOCAL inputdata: INPUT_MOUSE_DATA                
                 LOCAL TRECT:RECT
                
                 pushad
                                   
        ;mov edx,206ECh
       
        .IF hCTROLID==0
         push CTROL_ID
         pop hCTROLID
        .endif                  
                                                
        invoke GetDlgItem,hMainWND,hCTROLID ;获取窗口控件句柄,通过控件ID
        mov edx,eax
       
        invoke GetWindowRect,edx,addr TRECT
       
        mov eax,TRECT.left
        add eax,25
        mov TRECT.left,eax
        mov eax,TRECT.top
        add eax,6
        mov TRECT.top,eax
        invoke SetCursorPos,TRECT.left,TRECT.top
    
                                            
        mov inputdata.dwtype,INPUT_MOUSE
        mov inputdata.mi.dxx,0
        mov inputdata.mi.dy,0
        mov inputdata.mi.mouseData,0
        mov inputdata.mi.dwFlags,MOUSEEVENTF_MOVE or MOUSEEVENTF_LEFTDOWN or MOUSEEVENTF_LEFTUP
        ;invoke GetTickCount
        mov inputdata.mi.time,0
        ;invoke GetMessageExtraInfo
        mov inputdata.mi.dwExtraInfo,0
                                               
        invoke SendInput,1,addr inputdata,sizeof inputdata
       
        popad
       
        ret
 
  myDLL_Mouse endp

 


;#########################################################################

End DllEntry

 

 

;============================myDLL.inc

 

   include windows.inc
   include user32.inc
   include kernel32.inc
   include shell32.inc
  
   includelib user32.lib
   includelib kernel32.lib
   includelib shell32.lib

 

;======================myDLL.Def

 

LIBRARY "myDLL.DLL"

DESCRIPTION "myDLL DLL"

EXPORTS

        myDLL_Mouse


 

 

;=================== 调用方法其它ASM中调用代码

.DATA

szDLLFile db 'myDLL.dll',0
szlpModule db 'myDLL_Mouse',0
szDllKernel32 db 'Kernel32.dll',0
szlpLoadLibraryA db 'LoadLibraryA',0

.DATA?

   hDLLFile dd ?
   hlpModule dd ?
   hlpLoadLibraryA dd ?
   hDllKernel32 dd ?

.CODE

   myDLL proc

   
 invoke GetModuleHandle,addr szDllKernel32
 mov hDllKernel32,eax

        invoke GetProcAddress,hDllKernel32,addr szlpLoadLibraryA
 mov hlpLoadLibraryA,eax
   
    push offset szDLLFile
    call hlpLoadLibraryA ;获取我的DLL句柄
 ;invoke LoadLibrary,addr szDLLFile
 
 mov hDLLFile,eax
 invoke GetProcAddress,hDLLFile,addr szlpModule
 mov hlpModule,eax
 
 mov eax,dword ptr[ebp+100h]
 mov ebx,eax
 push IDC_CLOSE
 push hMainWND
 call hlpModule
 
    ret

   myDLL endp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值