flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Examples and Tutorials > Doubleclickable binary string & error codes show

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 148
Location: Russian Federation, Sochi

Doubleclickable binary string & error codes show


Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

ID_ERRBIN = 100
ID_ERRHEX = 101
ID_ERRNUM = 102
ID_EDESC  = 103
ID_SHOW   = 104


section '.text' code readable executable

  start:
        invoke  GetModuleHandle,0
        invoke  DialogBoxParam,eax,37,HWND_DESKTOP,DialogProc,0
  exit:
        invoke  ExitProcess,0

proc DialogProc hwnddlg,msg,wparam,lparam
        push    ebx esi edi
        cmp     [msg],WM_COMMAND
        je      .wmcommand
        cmp     [msg],WM_CLOSE
        je      .wmclose
        xor     eax,eax
        jmp     .finish
  .wmcommand:
        cmp     [wparam],STN_DBLCLK shl 16 + ID_ERRBIN
        je      .errdblclicked
        cmp     [wparam],BN_CLICKED shl 16 + ID_SHOW
        jne     .processed
        invoke  FormatMessage,\
                        FORMAT_MESSAGE_ALLOCATE_BUFFER+\
                        FORMAT_MESSAGE_FROM_SYSTEM ,\  ; it will check both for the error.
                        NULL,\
                        [CurrErr],\
                        LANG_NEUTRAL,\
                        lpBuffer,\
                        0,\
                        0
        invoke  SetDlgItemText,[hwnddlg],ID_EDESC,[lpBuffer]
        invoke  LocalFree,[lpBuffer]
        jmp     .processed
  .errdblclicked:
        invoke  GetCursorPos,pt
        invoke  GetDlgItem,[hwnddlg],ID_ERRBIN
        push    eax
        invoke  GetWindowRect,eax,rect
        mov     eax,[pt]
        sub     eax,[rect]
        ; ================================================================================
        ; formula: charindex = (mpm3 + 3 * (mpm3 div 51)) div 6, where mpm3 = MousePos.x-3
        ; ================================================================================
        sub     eax,3
        mov     ebx,eax
        xor     edx,edx
        mov     ecx,51
        div     ecx
        mov     ecx,3
        mul     ecx
        add     eax,ebx
        xor     edx,edx
        mov     ecx,6
        div     ecx
        mov     esi,eax ; formula is done in esi,eax - charindex
        xor     edx,edx ; skip all chars with (9n-1) index
        mov     ecx,9
        div     ecx
        cmp     edx,8
        pop     ebx
        jz      .processed
        invoke  GetWindowText,ebx,Buffer,255
        pop     eax
        xor     [Buffer+esi],1
        invoke  SetWindowText,ebx,Buffer;,0
        xor     esi,esi
        mov     ecx,0
        mov     edi,Buffer+34
  .loop_bin:
        xor     eax,eax
        neg     ecx
        mov     al,[edi+ecx;-ecx needed
        neg     ecx
        and     al,1
        shl     eax,cl
        add     esi,eax
        inc     ecx
        cmp     ecx,8
        jne     .test_ecx
  .skip_space:
        dec     edi
        jmp     .loop_bin
  .test_ecx:
        cmp     ecx,16
        je     .skip_space
        cmp     ecx,24
        je     .skip_space
        cmp     ecx,32
        jb      .loop_bin
        mov     [CurrErr],esi
        invoke  wsprintf,Buffer,Fmt,esi
        invoke  SetDlgItemText,[hwnddlg],ID_ERRHEX,Buffer
        jmp     .processed
  .wmclose:
        invoke  EndDialog,[hwnddlg],0
  .processed:
        mov     eax,1
  .finish:
        pop     edi esi ebx
        ret
endp

section '.data' data readable writeable
         CurrErr  dd 0
         Fmt      db 'HEX: %08X',0
         valid    dd ?
         lpBuffer dd ?
         pt:
                  dd ?
                  dd ?
         Buffer   db 255 dup (?)
         rect:
                  dd 4 dup (?)

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL'

  import kernel,\
         GetModuleHandle,'GetModuleHandleA',\
         FormatMessage,'FormatMessageA',\
         ExitProcess,'ExitProcess',\
         LocalFree,'LocalFree'

  import user,\
         DialogBoxParam,'DialogBoxParamA',\
         GetDlgItemInt,'GetDlgItemInt',\
         CheckRadioButton,'CheckRadioButton',\
         GetDlgItemText,'GetDlgItemTextA',\
         SetDlgItemText,'SetDlgItemTextA',\
         IsDlgButtonChecked,'IsDlgButtonChecked',\
         MessageBox,'MessageBoxA',\
         GetWindowLong,'GetWindowLongA',\
         GetWindowText,'GetWindowTextA',\
         SetWindowText,'SetWindowTextA',\
         GetWindowRect,'GetWindowRect',\
         ChildWindowFromPoint,'ChildWindowFromPoint',\
         GetCapture,'GetCapture',\
         GetCursorPos,'GetCursorPos',\
         GetMessagePos,'GetMessagePos',\
         GetDlgItem,'GetDlgItem',\
         PostMessage,'PostMessageA',\
         wsprintf,'wsprintfA',\
         EndDialog,'EndDialog'

section '.rsrc' resource data readable

  directory RT_DIALOG,dialogs

  resource dialogs,\
           37,LANG_ENGLISH+SUBLANG_DEFAULT,demonstration
; to compile with fasm oficial release delete one "," of sequence ",," from next line
  dialog demonstration,,'Error description Box',70,70,225,140,WS_CAPTION or WS_POPUP or WS_SYSMENU or DS_MODALFRAME or DS_SETFONT ; for official fasm release DS_SETFONT is style added by default and can be skipped
    dialogitem 'STATIC','00000000 00000000 00000000 00000000',ID_ERRBIN,5,5,140,13,WS_VISIBLE+WS_CHILD+WS_BORDER+WS_TABSTOP+SS_NOTIFY ; force use SS_NOTIFY style because in fasm it is not added by default (in masm it is added) 
    dialogitem 'STATIC','HEX: 00000000',ID_ERRHEX,5,20,66,11,WS_VISIBLE+WS_CHILD
    dialogitem 'BUTTON','Show Description',ID_SHOW,150,4,65,15,WS_VISIBLE+WS_CHILD+WS_TABSTOP+BS_PUSHBUTTON
    dialogitem 'STATIC','',ID_EDESC,5,30,215,100,WS_VISIBLE+WS_CHILD
  enddialog  



Maybe control named here with ID ID_ERRBIN will be useful in some your demo projects.


Description:
Filesize: 14.57 KB
Viewed: 504 Time(s)

Безымянный.jpg



_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 19 Jan 2018, 09:23
View user's profile Send private message Send e-mail Reply with quote
yeohhs



Joined: 19 Jan 2004
Posts: 168
Location: N 5.43564° E 100.3091°

Nice. Very Happy Thanks for sharing.

_________________
“It’s not that we have a short time to live, but that we waste a lot of it.”
-Lucius Annaeus Seneca
Post 20 Jan 2018, 10:41
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2018, Tomasz Grysztar.
Powered by rwasa.