Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Tasm32 dialog input


  • Please log in to reply
5 replies to this topic

#1 JMC31337

JMC31337

    CC Regular

  • Member
  • PipPipPip
  • 34 posts

Posted 16 June 2010 - 07:23 AM

Seraching for awhile i stumbled upon some source to grab dialogbox input and display the buffer... modded it up using a Radix 32 bit source style which you can probably find via google various sections of the code....






DLG.asm
;COMPILATION STYLE
;tasm /ml dlg
;brcc32 -32 dlg.rc  ==CREATE THE RESOURCE (.RES) FILE
;tlink32 -Tpe -c -aa dlg,,,import32,,dlg.res
 
.386 
.model flat, stdcall 
include windows.inc    
include resource.inc   
includelib import32.lib 
extrn SetFocus:PROC
extrn InternetOpenUrlA:PROC  ;==========
extrn ExitProcess:PROC   
extrn VirtualFree:PROC 
extrn FindFirstFileA:PROC 
extrn FindNextFileA:PROC 
extrn FindClose:PROC 
extrn InternetOpenA:PROC  ;==============
extrn GetModuleFileNameA:PROC 
extrn ReadFile:PROC 
extrn WriteFile:PROC 
extrn CreateFileA:PROC 
;extrn bind:PROC         ;===============
extrn CloseHandle:PROC 
extrn MessageBoxA:PROC 
extrn InternetReadFile:PROC    ;=================
extrn GetFileSize:PROC 
extrn VirtualAlloc:PROC 
extrn DeviceIoControl:PROC 
extrn GetFileAttributesA:PROC 
;extrn WSAStartup:PROC     ;================
extrn GetTempFileNameA:PROC 
extrn CreateProcessA:PROC 
extrn GetVersion:PROC
extrn WinExec:PROC
extrn GetCommandLineA:PROC
extrn InternetQueryDataAvailable:PROC   ;===========
extrn GetStdHandle:PROC
extrn WriteConsoleA:PROC
extrn WriteFile:proc
extrn GetModuleHandleA:PROC
extrn DefWindowProcA:PROC
;extrn socket:PROC    ;=============
extrn ExitProcess:PROC
extrn LoadIconA:PROC
extrn LoadCursorA:PROC
extrn DialogBoxParamA:PROC
extrn EndDialog:PROC
;extrn recv:PROC     ;==============
extrn WinExec:PROC
extrn LoadLibraryA:PROC
;extrn htons:PROC ;=================
extrn GetProcAddress:PROC
extrn RegCreateKeyExA:PROC
;extrn listen:PROC ;=================
extrn RegSetValueExA:PROC
extrn RegCloseKey:PROC
extrn GetWindowsDirectoryA:PROC
;extrn accept:PROC  ;=================
extrn FindWindowA:PROC
extrn CopyFileA:PROC
extrn MoveFileA:PROC
;extrn send:PROC    ;================
extrn DeleteFileA:PROC
extrn closesocket:PROC
extrn ShellExecuteA:PROC
extrn mciSendStringA:PROC
;extrn WSAAsyncSelect:PROC ;==============
extrn GetDlgItemTextA:PROC
extrn GetDlgItem:PROC
extrn GetDlgItemText:PROC
 
MB_ICONINFORMATION equ 00000040h 
MAX_USER_NAME = 20 
 
.data 
szAppName    db  'DLG APP', 0 
szHello    db  'Hello! ' 
szUser    db    MAX_USER_NAME dup (0) 
.code 
start: 
  call    GetModuleHandleA, 0
  call    DialogBoxParamA, eax, IDD_DIALOG, 0,offset DlgProc, 0 
  cmp    eax, IDOK 
  jne    exit 
  call    MessageBoxA, 0, offset szHello, offset szAppName, MB_OK
exit: 
  call    ExitProcess, 0 
DlgProc proc _hDlg:dword, _uMsg:dword, _wParam:dword, _lParam:dword 
  mov eax, [_uMsg]
  cmp   eax, WM_INITDIALOG 
  je    init 
  cmp    eax, WM_COMMAND 
  jne    ret_false 
  mov eax,[_wParam]
 cmp    eax, IDCANCEL 
  je    cancel 
  cmp    eax, IDOK 
  jne    ret_false 
  call    GetDlgItemTextA, _hDlg, IDR_NAME, offset szUser, MAX_USER_NAME 
 mov eax, IDOK
  ;call    EndDialog, IDOK, _hDlg  
cancel: 
  call    EndDialog, _hDlg ,eax
init:
  call    GetDlgItem, _hDlg , IDR_NAME
  call    SetFocus, eax
 jmp ret_false
ret_false: 
  xor    eax, eax  
  ret 
endp 
end start 

DLG.RC
#include "resource.h" 
IDD_DIALOG DIALOGEX 0, 0, 187, 95 
STYLE DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_CAPTION | WS_SYSMENU 
EXSTYLE WS_EX_CLIENTEDGE 
CAPTION "Dialog" 
FONT 8, "MS Sans Serif" 
BEGIN 
  DEFPUSHBUTTON "OK",IDOK,134,76,50,14 
  PUSHBUTTON   "CANCEL",IDCANCEL,73,76,50,14 
  LTEXT     "TEXT",IDC_STATIC,4,36,52,8 
  EDITTEXT     IDR_NAME,72,32,112,14,ES_AUTOHSCROLL 
END 

resource.h
#define  IDD_DIALOG    101 
#define  IDR_NAME      1000 
#define  IDC_STATIC    1001 

resource.inc
IDD_DIALOG  =  101 
IDR_NAME    =  1000
IDC_STATIC  =  1001

i cant remember exactly where i grabbed bits and pieces of this, .ru domains and a Radix tut site.. just modded it up to run on tasm32

Edited by JMC31337, 16 June 2010 - 03:36 PM.
resource.inc

  • 0

#2 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 16 June 2010 - 07:36 PM

This looks interesting, but I can't really figure out what's going on. Can you comment it, please?
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#3 JMC31337

JMC31337

    CC Regular

  • Member
  • PipPipPip
  • 34 posts

Posted 17 June 2010 - 04:30 AM

As per dargueta's request, i will try to step ya thru how this program works with TASM32 and the Win32 API... Im not a very good teacher
"Those who cant do teach" but i'll try

.386
.model flat, stdcall
This is the usual method of compiling EXE

include windows.inc NECESSARY
include resource.inc INCLUDE OUR COOL RES FILE
includelib import32.lib IMPORT KERNEL CALLS

The include files in TASM32 after making a tasm.cfg and inserting -IC:\tasm\include we can auto find the include files like windows.inc which contains the extern calls thru import32 library using the Kernel32.dll
Resource.inc is needed for your cool little buttons like MB_OK or we can set them to standard values
I.E: 0 = normal 32 = ? mark/question
includelib allows us to specify the library on the code level that way we shouldnt have to put it thru TASM commandine param which i did anyways
We have our comprehensive EXTRN List

MB_ICONINFORMATION equ 00000040h specify the MB_ICONINFO value
MAX_USER_NAME = 20 define the MAX_USER buffer of 20 chars

.data
szAppName db 'DLG APP', 0
szHello db 'Hello! '
szUser db MAX_USER_NAME dup (0)
.code
start:

GOTTA HAVE A .data section for this
szHello Our 2nd messagebox's name
szUSer OUR 1st messagebox's name
szUser db MAX_USER_NAME dup (0) define szUser as our MAX_USER above and clear the 20 spaces fo the buffer

.code Our code section start: start of the code section (can call it anything)

call GetModuleHandleA, 0
call DialogBoxParamA, eax, IDD_DIALOG, 0,offset DlgProc, 0
cmp eax, IDOK
jne exit
call MessageBoxA, 0, offset szHello, offset szAppName, MB_OK

call GetModuleHandleA, 0 = GET OUR MODULE NAME or EXE file used to create the calling process
call DialogBoxParamA, eax, IDD_DIALOG, 0,offset DlgProc, 0 = DialogBox Parameter specifying our name + ID_DIALOG which is specified in the resource rc file and Module Name along with the point (offset) to DlgPoc which is also in the resource file
cmp eax, IDOK = DID WE HIT THE OK BUTTON
jne exit = IF NOT we hit the X or or CANCEL in which case we jump to EXIT AND EXIT PROCESS

call MessageBoxA, 0, offset szHello, offset szAppName, MB_OK = IF we hit the ok button we pass a MessageBox placing the pointer to szHEllo (our lil hello title) along with pointer to the Appname (DLG APP)

Now this is where it gets tricky, DlgProc proc _hDlg:dword, _uMsg:dword, _wParam:dword, _lParam:dword
when we told the API to call the DlgProc Param callback, all calls were sent to this proc and returned before calling that 2nd messagebox with our text that we inputted
In checking up with MSDN API list
INT_PTR CALLBACK DialogProc( __in HWND hwndDlg, __in UINT uMsg, __in WPARAM wParam, __in LPARAM lParam);hwndDlg [in] HWNDA handle to the dialog box.

uMsg [in] UINTThe message.
wParam [in] WPARAMAdditional message-specific information.
lParam [in] LPARAMAdditional message-specific information.
the _uMsg

WM_INITDIALOG is the initalizer sent to the dialog box before it actually gets called
WM_COMMAND This message is sent when the user selects a command item from a menu, when a control sends a message to its parent window, or when an accelerator keystroke is translated (from the MSDN)
cmp eax, IDCANCEL = DID WE HIT CANCEL
je cancel
cmp eax, IDOK = DID WE HIT OK
jne ret_false

ret_false: LABEL
xor eax, eax clear our eax register which is where our API normally store values
ret return to command that called our label

cancel: LABEL
call EndDialog, _hDlg ,eax end our dialogbox

call GetDlgItemTextA, _hDlg, IDR_NAME, offset szUser, MAX_USER_NAME = Get the text that we inputted into our dialog box which was placed ther via the resource file
EDITTEXT IDR_NAME,72,32,112,14,ES_AUTOHSCROLL and store it into szUser (our lil buffer holding 20 chars)

This all gets initialized thru the procedure and compared b4 being sent using
je init = INITIALIZE! but IF an error happens we drop the dialogbox

The cool buttons their lables and values are set via .rc and resource files... YOU MUST HAVE A .RC file if you wanna create a cool dialogbox the 1001 1000 values can be set to whatever you want as long as you use the same values throughout your program... I'll let the resource files speak for themselves
Key thing is the IDD_DIALOG label (which can be changed) thats in the .rc and resource files

I chose to try this in TASM32 because i couldnt find any examples that worked online... MASM32 had quite a bit along with Iczelion but those had upwards of 137 lines of code, but the TASM32 only had 132 and thats with all my EXTRNS which we only needed a few like ExitProcess MessageBoxA SetFocus GetDlgItem GetModuleHandleA DialogProc etc....

hope this helps... it can get tricky when dealing with API
  • 0

#4 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 17 June 2010 - 06:43 PM

OOOOH, ok. I've done this before, but never in ASM. Nice! (+rep)

EDIT: Ahhh, sorry, can't +rep you again.
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#5 JMC31337

JMC31337

    CC Regular

  • Member
  • PipPipPip
  • 34 posts

Posted 13 July 2010 - 12:28 AM

Heres how you apply that Dialog input to say a quick password routine.. granted the password is stored in hex plainview through a debugger.....





















;COMPILATION STYLE
;tasm32 /ml pass
;brcc32 -32 pass.rc
;======CREATE THE RESOURCE FILE
;tlink32 -Tpe -c -aa pass,,,import32,,pass.res
 
.386 
.model flat, stdcall 
include windows.inc
 
include pass.inc   
includelib import32.lib 
extrn SetFocus:PROC
extrn ExitProcess:PROC   
extrn CloseHandle:PROC 
extrn MessageBoxA:PROC 
extrn ExitProcess:PROC
extrn DialogBoxParamA:PROC
extrn EndDialog:PROC
extrn GetProcAddress:PROC
extrn GetDlgItemTextA:PROC
extrn GetDlgItem:PROC
extrn GetDlgItemText:PROC
extrn GetModuleHandleA:PROC
extrn lstrcpy:PROC
MAX_USER_NAME = 20 
 
.data 
szAppName    db  'DLG APP', 0 
szHello    db  'Hello! ' 
szUser    db    ?
no db '--------------',0
yes db '-------------',0
no1 db 'PASSWORD IS WRONG',0
yes1 db 'PASSWORD IS RIGHT!!',0
.code 
start: 
@1:
  call    GetModuleHandleA, 0
  call    DialogBoxParamA, eax, IDD_DIALOG, 0,offset DlgProc, 0 
  cmp    eax, IDOK 
  jne    exit 
.IF ([szUser]=='1' && [szUser+1]=='2' && [szUser+2]=='3' && [szUser+3]=='4' && [szUser+4]=='5' && [szUser+5]=='')
  call    MessageBoxA, 0, offset yes1, offset szAppName, MB_OK
  call    ExitProcess
.ELSE
  call    MessageBoxA, 0, offset no1, offset szAppName, MB_OK
jmp @1
.ENDIF 
exit:
  call ExitProcess
 
DlgProc proc _hDlg:dword, _uMsg:dword, _wParam:dword, _lParam:dword 
  mov eax, [_uMsg]
  cmp   eax, WM_INITDIALOG 
  je    init 
  cmp    eax, WM_COMMAND 
  jne    ret_false 
  mov eax,[_wParam]
 cmp    eax, IDCANCEL 
  je    cancel 
  cmp    eax, IDOK 
  jne    ret_false 
  call    GetDlgItemTextA, _hDlg, IDR_NAME, offset szUser, MAX_USER_NAME 
  mov eax, IDOK
 
 
cancel: 
  call    EndDialog, _hDlg ,eax
init:
  call    GetDlgItem, _hDlg , IDR_NAME
 
mov edx,_hDlg   
 
  call    SetFocus, eax
  jmp ret_false
ret_false: 
  xor    eax, eax  
  ret 
endp
end start 
the szUser gets checked char by char with an if then else loop, what i could not fig out is why the text overflows into the MessageBoxA API if i dont use a "fake" no yes variable allocation, which is why i used
yes1 no1.. if someone knows the answer please lemme know

Edited by JMC31337, 13 July 2010 - 03:48 PM.

  • 0

#6 JMC31337

JMC31337

    CC Regular

  • Member
  • PipPipPip
  • 34 posts

Posted 13 July 2010 - 03:46 PM

fig out how to keep the overflow from occurring
.DATA? ;uninitialized data

szUser db ?
MAX_USER_NAME = 20

.DATA
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download