hi ,all. how can i add a new line or new message in the editbox,not replace the messages that the editbox had.
can SetWindowText works?
can SetWindowText works?
Assuming my edit box had the message as follow:
1.Hello,baby
2.I like linkin park
i want to add :"3.I am from china",
i had tried this:
invoke SendMessage,hwndEdit,EM_REPLACESEL,0,addr szText ;szText db "3.I am from china",13,10,0
but the result just as follow:
3.I am from china
1.Hello,baby
2.I like linkin park
how can i add the message after "2.I like linkin park" ?
1.Hello,baby
2.I like linkin park
i want to add :"3.I am from china",
i had tried this:
invoke SendMessage,hwndEdit,EM_REPLACESEL,0,addr szText ;szText db "3.I am from china",13,10,0
but the result just as follow:
3.I am from china
1.Hello,baby
2.I like linkin park
how can i add the message after "2.I like linkin park" ?
Use WM_GETTEXT to get the Text into a Buffer, then use lstrcat to append strings to it and use WM_SETTEXT to set the text back.
Code Not Verified.
.data
NewLine db 13,10,0
AddedData db "Hello World",0
.code
invoke SendMessage, hEdit, WM_GETTEXT, addr Buffer, Sizeof Buffer
invoke lstrcat, addr Buffer, addr Newline
invoke lstrcat, addr Buffer, addr Added Data
invoke SendMessage, hEdit, WM_SETTEXT, addr Buffer,0
Code Not Verified.
The idea is to use the EM_SETSEL message to deselect everything and then set caret position to the end of text.
Try something like this:
Regards.
Kecol.-
PS: read some documentation if it doesn't work (MSDN).
Try something like this:
invoke SendMessage,hwndEdit,EM_SETSEL, -1, -1
invoke SendMessage,hwndEdit,EM_REPLACESEL,0,addr szText
Regards.
Kecol.-
PS: read some documentation if it doesn't work (MSDN).
oh,it doesnt work.
but i have another question,how can i undo the editbox operations?
i have defined a submenu named "UNDO"
.const
.....
IDM_UNDO equ 1
.........
invoke CreateMenu
mov hwndMenu,eax
invoke CreatePopupMenu
mov esi,eax
invoke AppendMenu,hwndMenu,MF_POPUP,esi,addr MenuName
invoke AppendMenu,esi,MF_STRING,IDM_UNDO,addr submenu
.....
......
if ax==IDM_UNDO
invoke SendMessage,hwndEdit,EM_UNDO,0,0 ;but it doesnt work,tell me why?
..........
....
but i have another question,how can i undo the editbox operations?
i have defined a submenu named "UNDO"
.const
.....
IDM_UNDO equ 1
.........
invoke CreateMenu
mov hwndMenu,eax
invoke CreatePopupMenu
mov esi,eax
invoke AppendMenu,hwndMenu,MF_POPUP,esi,addr MenuName
invoke AppendMenu,esi,MF_STRING,IDM_UNDO,addr submenu
.....
......
if ax==IDM_UNDO
invoke SendMessage,hwndEdit,EM_UNDO,0,0 ;but it doesnt work,tell me why?
..........
....
Hey, you didn't check the API documentation. The idea was good but I made a mistake in the code.
This will work:
Search the forum before asking. I will do the same before answering.
Kecol.-
This will work:
invoke SendMessage,hwndEdit,EM_SETSEL, -1, 0
invoke SendMessage,hwndEdit,EM_REPLACESEL,0,addr szText
Search the forum before asking. I will do the same before answering.
Kecol.-
............
invoke EnableMenuItem,hwndMenu,IDM_ADDRESS,MF_GRAYED
invoke EnableMenuItem,hwndMenu,IDM_CLEAR,MF_ENABLED
invoke SetWindowText,hwndEdit,addr buffer
invoke SendMessage,hwndEdit,EM_SETSEL,-1,0
invoke SendMessage,hwndEdit,EM_REPLACESEL,0,addr try
it doesnt work yet,why?
i have search the forum before asking question.but now, what i want to know is how to use the EM_UNDO
invoke EnableMenuItem,hwndMenu,IDM_ADDRESS,MF_GRAYED
invoke EnableMenuItem,hwndMenu,IDM_CLEAR,MF_ENABLED
invoke SetWindowText,hwndEdit,addr buffer
invoke SendMessage,hwndEdit,EM_SETSEL,-1,0
invoke SendMessage,hwndEdit,EM_REPLACESEL,0,addr try
it doesnt work yet,why?
i have search the forum before asking question.but now, what i want to know is how to use the EM_UNDO
i have tested the edit`control undo queue,it return false?why?
my program as follow:
.386
.model flat,stdcall
option casemap:none
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
ClassName db "SimpleWinClass",0
AppName db "Kernel Tools",0
MenuName db "&Function",0
MenuName1 db "&Edit",0
submenu1 db "&Kernel/PE Addr",0
submenu2 db "&Clear",0
submenu3 db "E&xit",0
submenu4 db "&Undo",0
outformat db "Base address of kernel:0x%XH",13,10
db "Address of PE header :0x%XH",0
try db "Haha,you make it!",13,10,0
EditClassName db "edit",0
szWarning db "Failure.:(",0
.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hwndMenu DWORD ?
hwndEdit HWND ?
buffer db 1024 dup(?)
.const
IDM_ADDRESS equ 1
IDM_CLEAR equ 2
IDM_EXIT equ 3
IDM_UNDO equ 4
.code
start:
mov eax,
.while word ptr !="ZM"
dec eax
.endw
mov edx,
add edx,eax
invoke wsprintf,addr buffer,addr outformat,eax,edx
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground,COLOR_BTNFACE+1
mov wc.lpszMenuName,OFFSET MenuName
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
invoke CreateMenu
mov hwndMenu,eax
invoke CreatePopupMenu
mov esi,eax
invoke AppendMenu,hwndMenu,MF_POPUP,esi,addr MenuName
invoke AppendMenu,esi,MF_STRING,IDM_ADDRESS,addr submenu1
invoke AppendMenu,esi,MF_STRING,IDM_CLEAR,addr submenu2
invoke AppendMenu,esi,MF_STRING,IDM_UNDO,addr submenu4
invoke AppendMenu,esi,MF_SEPARATOR,NULL,NULL
invoke AppendMenu,esi,MF_STRING,IDM_EXIT,addr submenu3
invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR ClassName, \
ADDR AppName, WS_OVERLAPPED,\
360, 280,\
400,300,NULL,hwndMenu, hInst,NULL
mov hwnd,eax
invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd
.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE
invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,NULL,\
WS_CHILD or WS_VISIBLE or WS_BORDER or WS_VSCROLL or ES_LEFT or\
ES_READONLY or ES_MULTILINE or ES_AUTOVSCROLL,\
15,25,360,150,hWnd,8,hInstance,NULL
mov hwndEdit,eax
invoke EnableMenuItem,hwndMenu,IDM_CLEAR,MF_GRAYED
.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
.IF lParam==0
.IF ax==IDM_ADDRESS
invoke EnableMenuItem,hwndMenu,IDM_ADDRESS,MF_GRAYED
invoke EnableMenuItem,hwndMenu,IDM_CLEAR,MF_ENABLED
invoke SetWindowText,hwndEdit,addr buffer
;invoke SendMessage,hwndEdit,EM_SETSEL,0,-1
invoke SendMessage,hwndEdit,EM_REPLACESEL,0,addr try
.ELSEIF ax==IDM_CLEAR
invoke SetWindowText,hwndEdit,NULL
invoke EnableMenuItem,hwndMenu,IDM_ADDRESS,MF_ENABLED
invoke EnableMenuItem,hwndMenu,IDM_CLEAR,MF_GRAYED
.ELSEIF ax==IDM_UNDO
invoke SendMessage,hwndEdit,EM_CANUNDO,0,0
.if eax!=0
invoke SendMessage,hwndEdit,EM_UNDO,0,0
.else
invoke MessageBox,NULL,addr szWarning,addr AppName,MB_ICONERROR
.endif
.ELSE
invoke DestroyWindow,hWnd
.ENDIF
.ENDIF
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
end start
who can help me to solve the problem?
my program as follow:
.386
.model flat,stdcall
option casemap:none
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
ClassName db "SimpleWinClass",0
AppName db "Kernel Tools",0
MenuName db "&Function",0
MenuName1 db "&Edit",0
submenu1 db "&Kernel/PE Addr",0
submenu2 db "&Clear",0
submenu3 db "E&xit",0
submenu4 db "&Undo",0
outformat db "Base address of kernel:0x%XH",13,10
db "Address of PE header :0x%XH",0
try db "Haha,you make it!",13,10,0
EditClassName db "edit",0
szWarning db "Failure.:(",0
.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hwndMenu DWORD ?
hwndEdit HWND ?
buffer db 1024 dup(?)
.const
IDM_ADDRESS equ 1
IDM_CLEAR equ 2
IDM_EXIT equ 3
IDM_UNDO equ 4
.code
start:
mov eax,
.while word ptr !="ZM"
dec eax
.endw
mov edx,
add edx,eax
invoke wsprintf,addr buffer,addr outformat,eax,edx
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground,COLOR_BTNFACE+1
mov wc.lpszMenuName,OFFSET MenuName
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
invoke CreateMenu
mov hwndMenu,eax
invoke CreatePopupMenu
mov esi,eax
invoke AppendMenu,hwndMenu,MF_POPUP,esi,addr MenuName
invoke AppendMenu,esi,MF_STRING,IDM_ADDRESS,addr submenu1
invoke AppendMenu,esi,MF_STRING,IDM_CLEAR,addr submenu2
invoke AppendMenu,esi,MF_STRING,IDM_UNDO,addr submenu4
invoke AppendMenu,esi,MF_SEPARATOR,NULL,NULL
invoke AppendMenu,esi,MF_STRING,IDM_EXIT,addr submenu3
invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR ClassName, \
ADDR AppName, WS_OVERLAPPED,\
360, 280,\
400,300,NULL,hwndMenu, hInst,NULL
mov hwnd,eax
invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd
.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE
invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,NULL,\
WS_CHILD or WS_VISIBLE or WS_BORDER or WS_VSCROLL or ES_LEFT or\
ES_READONLY or ES_MULTILINE or ES_AUTOVSCROLL,\
15,25,360,150,hWnd,8,hInstance,NULL
mov hwndEdit,eax
invoke EnableMenuItem,hwndMenu,IDM_CLEAR,MF_GRAYED
.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
.IF lParam==0
.IF ax==IDM_ADDRESS
invoke EnableMenuItem,hwndMenu,IDM_ADDRESS,MF_GRAYED
invoke EnableMenuItem,hwndMenu,IDM_CLEAR,MF_ENABLED
invoke SetWindowText,hwndEdit,addr buffer
;invoke SendMessage,hwndEdit,EM_SETSEL,0,-1
invoke SendMessage,hwndEdit,EM_REPLACESEL,0,addr try
.ELSEIF ax==IDM_CLEAR
invoke SetWindowText,hwndEdit,NULL
invoke EnableMenuItem,hwndMenu,IDM_ADDRESS,MF_ENABLED
invoke EnableMenuItem,hwndMenu,IDM_CLEAR,MF_GRAYED
.ELSEIF ax==IDM_UNDO
invoke SendMessage,hwndEdit,EM_CANUNDO,0,0
.if eax!=0
invoke SendMessage,hwndEdit,EM_UNDO,0,0
.else
invoke MessageBox,NULL,addr szWarning,addr AppName,MB_ICONERROR
.endif
.ELSE
invoke DestroyWindow,hWnd
.ENDIF
.ENDIF
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
end start
who can help me to solve the problem?
mov eax,
.while word ptr !="ZM"
dec eax
.endw
mov edx,
add edx,eax
invoke wsprintf,addr buffer,addr outformat,eax,edx
invoke GetModuleHandle, NULL
what the hell is the point in doing your little scan to find the kernel32 base address when you're using apis from it right after (GetModuleHandle)
is it to look leet or something?, if so you failed, a simple invoke GetModuleHandleA, offset kernel32text (where kernel32text = db 'kernel32.dll',00h) would do the same, and if you are going to do such a scan then it would be wise to do an exception handler to handle the possibility that the dword @ esp might not be inside kernel32 (forwarded/redirected import could cause this).. and try and use msdn as a reference too as previously advised
.while word ptr !="ZM"
dec eax
.endw
mov edx,
add edx,eax
invoke wsprintf,addr buffer,addr outformat,eax,edx
invoke GetModuleHandle, NULL
what the hell is the point in doing your little scan to find the kernel32 base address when you're using apis from it right after (GetModuleHandle)
is it to look leet or something?, if so you failed, a simple invoke GetModuleHandleA, offset kernel32text (where kernel32text = db 'kernel32.dll',00h) would do the same, and if you are going to do such a scan then it would be wise to do an exception handler to handle the possibility that the dword @ esp might not be inside kernel32 (forwarded/redirected import could cause this).. and try and use msdn as a reference too as previously advised