flat assembler
Message board for the users of flat assembler.
Index
> Windows > Restoring original control element text |
Author |
|
bitRAKE 29 May 2021, 15:21
The dialog template is in your address space - just need to know the address of the string within the template. The API has FindResource, but you'd still need to find the string. I believe you can change the string text to the ID of a string resource and then programmatically locate that string resource. I'd need to test it - as it's been some years since I did that. IIRC, strings named like "#123" would load resource id 123.
Depends how you have the dialog defined. If you're using DialogBoxIndirectParam with a dialog template or the fasm macros to define the dialog, it shouldn't be too difficult to use the address directly. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
29 May 2021, 15:21 |
|
bitRAKE 29 May 2021, 18:03
I couldn't get the '#123' method to work, but the direct template access works fine. We just examine the resource macro to determine the offset for the string.
Code: ; DialogBox example format PE GUI 4.0 entry start include 'win32w.inc' include 'encoding\utf8.inc' ID_CAPTION = 101 ID_MESSAGE = 102 ID_ICONERROR = 201 ID_ICONINFORMATION = 202 ID_ICONQUESTION = 203 ID_ICONWARNING = 204 ID_TOPMOST = 301 section '.text' code readable executable start: invoke GetModuleHandle,0 invoke DialogBoxParam,eax,37,HWND_DESKTOP,DialogProc or eax,eax jz exit invoke MessageBox,HWND_DESKTOP,message,caption,[flags] exit: invoke ExitProcess,0 proc DialogProc hwnddlg,msg,wparam,lparam push ebx esi edi cmp [msg],WM_INITDIALOG je .wminitdialog cmp [msg],WM_COMMAND je .wmcommand cmp [msg],WM_CLOSE je .wmclose xor eax,eax jmp .finish .wminitdialog: invoke CheckRadioButton,[hwnddlg],ID_ICONERROR,ID_ICONWARNING,ID_ICONINFORMATION jmp .processed .wmcommand: cmp [wparam],BN_CLICKED shl 16 + IDCANCEL je .wmclose cmp [wparam],BN_CLICKED shl 16 + IDOK jne .processed invoke GetDlgItemText,[hwnddlg],ID_CAPTION,caption,40h invoke GetDlgItemText,[hwnddlg],ID_MESSAGE,message,100h mov [flags],MB_OK invoke IsDlgButtonChecked,[hwnddlg],ID_ICONERROR cmp eax,BST_CHECKED jne .iconerror_ok or [flags],MB_ICONERROR .iconerror_ok: invoke IsDlgButtonChecked,[hwnddlg],ID_ICONINFORMATION cmp eax,BST_CHECKED jne .iconinformation_ok or [flags],MB_ICONINFORMATION .iconinformation_ok: invoke IsDlgButtonChecked,[hwnddlg],ID_ICONQUESTION cmp eax,BST_CHECKED jne .iconquestion_ok or [flags],MB_ICONQUESTION .iconquestion_ok: invoke IsDlgButtonChecked,[hwnddlg],ID_ICONWARNING cmp eax,BST_CHECKED jne .iconwarning_ok or [flags],MB_ICONWARNING .iconwarning_ok: invoke IsDlgButtonChecked,[hwnddlg],ID_TOPMOST cmp eax,BST_CHECKED jne .topmost_ok or [flags],MB_TOPMOST .topmost_ok: invoke MessageBox,[hwnddlg],message,caption,[flags] ; allow to test many instead of exit ; invoke EndDialog,[hwnddlg],1 ; reset text of edit controls: invoke SetDlgItemText,[hwnddlg],ID_CAPTION,_WideString00 invoke SetDlgItemText,[hwnddlg],ID_MESSAGE,_WideString01 jmp .processed .wmclose: invoke EndDialog,[hwnddlg],0 .processed: mov eax,1 .finish: pop edi esi ebx ret endp section '.bss' readable writeable flags dd ? caption rw 40h message rw 100h section '.idata' import data readable writeable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL' import kernel,\ GetModuleHandle,'GetModuleHandleW',\ ExitProcess,'ExitProcess' import user,\ DialogBoxParam,'DialogBoxParamW',\ CheckRadioButton,'CheckRadioButton',\ GetDlgItemText,'GetDlgItemTextW',\ IsDlgButtonChecked,'IsDlgButtonChecked',\ MessageBox,'MessageBoxW',\ EndDialog,'EndDialog',\ SetDlgItemText,'SetDlgItemTextW' ; also see: ; https://board.flatassembler.net/topic.php?t=2370 ; https://devblogs.microsoft.com/oldnewthing/20040130-00/?p=40813 macro stringtable label,[quoted] { common local data,size label dd RVA data,size,0,0 data dw ? forward dw (@f - $)/2 - 2 du quoted @@: common size = $ - data } section '.rsrc' resource data readable directory \ RT_STRING,strings,\ RT_DIALOG,dialogs resource strings,\ 1,LANG_NEUTRAL,string_table resource dialogs,\ 37,LANG_ENGLISH+SUBLANG_DEFAULT,demonstration stringtable string_table,\ <"наслаждаться",0>,\ <"Goodbye.",0> dialog demonstration,'Create message box',70,70,190,175,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME dialogitem 'STATIC','&Caption:',-1,10,10,70,8,WS_VISIBLE _WideString00 = $ + 22 dialogitem 'EDIT','Important stuff ...',ID_CAPTION,10,20,170,13,WS_VISIBLE+WS_BORDER+WS_TABSTOP dialogitem 'STATIC','#1',-1,10,40,70,8,WS_VISIBLE _WideString01 = $ + 22 dialogitem 'EDIT','Say a lot of things to be read carefully.',ID_MESSAGE,10,50,170,13,WS_VISIBLE+WS_BORDER+WS_TABSTOP+ES_AUTOHSCROLL dialogitem 'BUTTON','&Icon',-1,10,70,80,70,WS_VISIBLE+BS_GROUPBOX dialogitem 'BUTTON','&Error',ID_ICONERROR,20,82,60,13,WS_VISIBLE+BS_AUTORADIOBUTTON+WS_TABSTOP+WS_GROUP dialogitem 'BUTTON','I&nformation',ID_ICONINFORMATION,20,95,60,13,WS_VISIBLE+BS_AUTORADIOBUTTON dialogitem 'BUTTON','&Question',ID_ICONQUESTION,20,108,60,13,WS_VISIBLE+BS_AUTORADIOBUTTON dialogitem 'BUTTON','&Warning',ID_ICONWARNING,20,121,60,13,WS_VISIBLE+BS_AUTORADIOBUTTON dialogitem 'BUTTON','&Style',-1,100,70,80,70,WS_VISIBLE+BS_GROUPBOX dialogitem 'BUTTON','&Top most',ID_TOPMOST,110,82,60,13,WS_VISIBLE+WS_TABSTOP+BS_AUTOCHECKBOX dialogitem 'BUTTON','OK',IDOK,85,150,45,15,WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON dialogitem 'BUTTON','C&ancel',IDCANCEL,135,150,45,15,WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON enddialog _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
29 May 2021, 18:03 |
|
fasm14 30 May 2021, 05:54
Thanks a lot!
|
|||
30 May 2021, 05:54 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.