目的是找出所有:无标题 - 记事本 的hand.发送到列表框中,然后在列表框中双击其中一项,出现一个对话框, 点确定,就出问题,出现内存不能为write。为什么点确定要出问题呢?
原码:
.386
.model flat, stdcall
option casemap :none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
IDD_DLG equ 1000
IDC_list equ 1001
.data?
hinstance dd ?
hand dd ?
ttt dd ?
.data
fmat db 'hand=%d',0
find1 db '无标题 - 记事本',0
.code
_enum proc uses ebx esi edi hwnd,lparam
LOCAL @buffer[256]:byte
invoke GetWindowText,hwnd,addr @buffer,sizeof @buffer
invoke lstrcmp,addr @buffer,addr find1
;只找记事本
.if !eax
invoke wsprintf,addr @buffer,addr fmat,hwnd
invoke SendDlgItemMessage,hand,IDC_list ,LB_ADDSTRING,0,addr @buffer
invoke SendDlgItemMessage,hand,IDC_list,LB_SETITEMDATA,eax,hwnd
.endif
ret
_enum endp
_start proc _tt
invoke EnumWindows,_enum,NULL
ret
_start endp
_dlgproc proc uses ebx esi edi hdlg,umsg,wparam,lparam
LOCAL @buffer
mov eax,umsg
.if eax==WM_CLOSE
invoke EndDialog,hdlg,NULL
.elseif eax==WM_INITDIALOG
push hdlg
pop hand
push ecx
invoke CreateThread,NULL,0,addr _start,NULL,NULL,esp
pop ecx
invoke CloseHandle,eax
.elseif eax==WM_COMMAND
mov eax,wparam
;只处理列表框上的双击
shr eax,16
.if ax== LBN_DBLCLK
invoke SendDlgItemMessage,hdlg,IDC_list,LB_GETCURSEL,0,0
invoke SendDlgItemMessage,hdlg,IDC_list,LB_GETITEMDATA,eax,0
invoke wsprintf,addr @buffer,addr fmat,eax
invoke MessageBox,NULL,addr @buffer,NULL,MB_OK
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_dlgproc endp
start:
invoke GetModuleHandle,NULL
mov hinstance,eax
invoke DialogBoxParam,hinstance,IDD_DLG,NULL,offset _dlgproc,NULL
invoke ExitProcess,NULL
end start
资源为
#include <resource.h>
#define IDD_DLG1 1000
#define IDC_list 1001
IDD_DLG1 DIALOGEX -2,-13,255,138
CAPTION "测试"
FONT 8,"MS Sans Serif",0,0,0
STYLE WS_VISIBLE|WS_OVERLAPPEDWINDOW
EXSTYLE WS_EX_TOOLWINDOW
BEGIN
CONTROL "",IDC_list,"ListBox",WS_CHILD|WS_VISIBLE|WS_TABSTOP|LBS_NOINTEGRALHEIGHT|LBS_HASSTRINGS|LBS_NOTIFY,36,24,177,63,WS_EX_CLIENTEDGE
END
在WM_INITDIALOG那只写上
invoke SendDlgItemMessage,hand,IDC_list ,LB_ADDSTRING,0,addr find1
invoke SendDlgItemMessage,hand,IDC_list,LB_SETITEMDATA,eax,10
都没有问题
帮忙调试一下
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课