News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Masm32 password input dialog window

Started by Bugaga, April 02, 2020, 08:05:30 PM

Previous topic - Next topic

Bugaga

Hello to the forum! I am very novice to assembly, so want to say sorry if my question is too weird  :dazzled:

I want to write a simple program that outputs (or not) one piece of data based on if password did match or not. The password must be xor encrypted (there's not much of a problem here).

I found a great example in examples/dialogs/ called "nested". It is almost perfectly what I need, but with all the code in .inc file + main file, it is too complex for me.

So I wanted to ask, maybe there are simplier examples of the input window? Or maybe this nested example can be trimmed down a little bit? I actually only need one input window and a result MessageBox based on the input. Or, if not all of that, maybe someone could comment just a little bit of the code in this "nested" example to show the path of the input data from the moment I input it to the moment it invokes in MessageBox, so I would know where I need to modify the code? I am beforehand thankful to any help  :thumbsup:

Update:
Here is the gist for this "nested" example, the thing I changed are printed strings and added all the code from the .inc file to this one .asm file, that's it - https://gist.github.com/Buogogo/dce2469dc3af9ec711ec01dfb23f0817

Vortex

Hello,

Maybe not the best option but this can give you an idea :

http://www.masmforum.com/board/index.php?topic=18485.0

jj2007

Are you eager to roll your own, or do you just want a job done?

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
DlgDefine "Hi there:", 0, 0, 120, -2, , 12    ; x, y ignored, 120 wide, 2 lines, blank, font size 12
  DlgControl dcEdit,   "歡迎", WS_BORDER or WS_TABSTOP or ES_PASSWORD, 1, -2
  DlgControl dcStatic, "Type your password:", SS_LEFT, 1, -1, 70.0
  DlgControl dcButton, "OK", BS_DEFPUSHBUTTON or WS_TABSTOP, 60.0, -1, 15.0, , IDOK
  DlgControl dcButton, "Cancel", BS_PUSHBUTTON or WS_TABSTOP, 77.0, -1, 23.0, , IDCANCEL
  DlgShow
  .if eax==IDOK                         ; user clicked OK, let's see what was typed into the edit box:
        .if StringsDiffer(Utf8$(Dlg$(0)), "歡迎", 1)  ; 1=case-insensitive
                MsgBox 0, "No cigar!!!!", "Retry?", MB_YESNO
                If_ eax==IDYES Then Launch "Password.exe"       ; just for fun, try again
        .else
                wMsgBox 0, Dlg$(0), "Congrats!!!!", MB_OK
                ; insert ACTION here
        .endif
  .endif
EndOfCode


Source attached. As you can see, it works with Unicode, too.

Bugaga

Quote from: jj2007 on April 03, 2020, 02:40:37 AM
Are you eager to roll your own, or do you just want a job done?
Thank you for this example! I would like to do at least something myself, if you mean that  :biggrin:. Is there a way to do this using just bare masm32 libs? If there were just simpliest ever example with inputbox and result with if condition in MessageBox - I think I would be able to add what I need it to do. It would just be good to see the simpliest example that I would understand, but I am struggling to find any on the Internet.

Bugaga

Maybe it would be better to state question like that: if I needed to insert xor encryption of input, "if" comparing it to the actual password and then output, where in the example I attached is the best place to insert it? Cause I don't even understand what variable\register holds the input after confirmation.

hutch--

What you are after if you know how to write the code is a resource dialog that has a text box and a couple of buttons. When the dialog is closed you get the text in the text box into a buffer that you allocate then do what you like with the text data. The catch is that no-one will write it for you.

jj2007

Quote from: Bugaga on April 03, 2020, 03:42:56 AM
Maybe it would be better to state question like that: if I needed to insert xor encryption of input, "if" comparing it to the actual password and then output, where in the example I attached is the best place to insert it? Cause I don't even understand what variable\register holds the input after confirmation.

After the .if eax==IDOK, insert mov esi, Dlg$(0). Now esi holds a pointer to the password text.

Bugaga

Quote from: jj2007 on April 03, 2020, 11:44:19 AM
After the .if eax==IDOK, insert mov esi, Dlg$(0). Now esi holds a pointer to the password text.
And may I ask where can it be in this "nested" example I attached? If I understand properly - the ecx register (or buffer var) holds it there, but I might be wrong.

And if I understand correctly, I need to code a check for a password match and ifs related to that somewhere here, in dlgproc, am I right?

dlgproc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    LOCAL buffer:DWORD

    .if uMsg == WM_INITDIALOG
      invoke SetWindowLong,hWin,GWL_USERDATA,lParam
      mov eax, lParam
      mov eax, [eax]
      invoke SendMessage,hWin,WM_SETICON,1,[eax]

    .elseif uMsg == WM_COMMAND
      .if wParam == IDOK
        invoke GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT, 32
        mov buffer, eax
        invoke GetWindowLong,hWin,GWL_USERDATA
        mov ecx, [eax]
        invoke GetText,hWin,[ecx],buffer
        mov ecx, buffer
        cmp BYTE PTR [ecx], 0
        je @F
        invoke MessageBox,hWin,buffer,SADD("Target data"),MB_OK
        jmp nxt
      @@:
        invoke MessageBox,hWin,SADD("You did not enter any password"),
                               SADD("No data to display"),MB_OK
      nxt:
        invoke GlobalFree,buffer

      .elseif wParam == IDCANCEL
        jmp quit_dialog
      .endif

    .elseif uMsg == WM_CLOSE
      quit_dialog:
      invoke EndDialog,hWin,0

    .endif

    xor eax, eax
    ret

dlgproc endp

hutch--

Do you know how to create a resource dialog with a dialog editor ?

jj2007

Quote from: Bugaga on April 03, 2020, 11:19:35 PMAnd may I ask where can it be in this "nested" example I attached? If I understand properly - the ecx register (or buffer var) holds it there, but I might be wrong.

Yes, that's correct.
        mov ecx, buffer
        cmp BYTE PTR [ecx], 0

Bugaga

Quote from: hutch-- on April 04, 2020, 01:08:00 AM
Do you know how to create a resource dialog with a dialog editor ?

No, I never did that. Do I need to do it with Visual Studio? Now I am only using Masm32 Editor.

Bugaga

Quote from: jj2007 on April 04, 2020, 01:22:27 AM
Quote from: Bugaga on April 03, 2020, 11:19:35 PMAnd may I ask where can it be in this "nested" example I attached? If I understand properly - the ecx register (or buffer var) holds it there, but I might be wrong.

Yes, that's correct.
        mov ecx, buffer
        cmp BYTE PTR [ecx], 0

If I understand right, that is the place where I can add the comparison of variables:
je @F
        mov esi, buffer
        mov edi, password
        repe cmpsd
        je nequal
        invoke MessageBox,hWin,buffer,SADD("Target data"),MB_OK
        jmp nxt
        nequal:
            invoke MessageBox,hWin,SADD("You entered wrong password"),SADD("Wrong password"),MB_OK
            jmp nxt
      @@:
        invoke MessageBox,hWin,SADD("You did not enter any password"),
                               SADD("No data to display"),MB_OK
      nxt:
        invoke GlobalFree,buffer


The password is the dword variable with the password.
The problem is I tried using a debugger and when I do mov esi, buffer - the esi appears to be always different with same text input, that is quite strange. + on repe cmpsd I get Program received signal SIGSEGV, Segmentation fault. error and program exits. The thing I don't understand how to match my input (buffer I guess) and the password variable.

jj2007

I have a suspicion that you should study the logic of repX cmpsd, and in particular the role of ecx
        mov esi, buffer
        mov edi, password
        repe cmpsd

hutch--

> No, I never did that. Do I need to do it with Visual Studio? Now I am only using Masm32 Editor.

Get the dialog editor at URL http://masm32.com/board/index.php?topic=6512.0

You use it to make a resource script file (.rc). This is how to make the dialog you require for the text entry.

What we need to know is where the dialog will be called from, will it be a free standing executable OR will it be a dialog called from within an application because the code is very similar but is called from a different location in the main source.

The nested example that I wrote many years ago is probably a bit advanced for you at the moment as it creates the dialog in memory, a resource dialog is simpler and more orthodox in programming terms.

hutch--

As learning dialogs from scratch is hard going, here is a working example of a proper resource dialog that does the basic interface stuff that you need. The main app is a resource dialog and it calls another resource dialog where you enter text. The text is then available to the caller and from there you can do whatever you need to do in terms of encryption and saving the data to disk.

Learning how to make dialogs is a bit complicated at first but once you are familiar with the techniques and code, they are reasonably straight forward after that.