Author Topic: Button opens open the current directory but....  (Read 7807 times)

Magnum

  • Member
  • *****
  • Posts: 2354
Button opens open the current directory but....
« on: December 09, 2012, 07:47:10 AM »
The open for repair button works ok and comes up with a list of files in the current directory, but can't find the file.
I have puts some notes on various lines.

I tried putting in the whole path.

I hope some will help me.

Thanks.

Code: [Select]
;
 ; REPARIEREN.ASM Help from Fetten,Dave,Frank K.,Qword,TightCoderEx,
 
INCLUDE \masm32\include\masm32rt.inc

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
Convert proto :DWORD,:DWORD

.const

MAXSTR equ 100
MAXSIZE equ 260
ButtonOpenID equ 100
ButtonPatchID equ 101
StringID equ 200
NStringID equ 201

.data

ClassName      db "WinClass",0

NotEqual       db "Length of strings must be equal",0
Error          db "Error!",0
NoMem          db "Error allocating memory",0
FilterString   db "All Files",0,"*.*",0

; INCOMPLETE and important to repair ??
;
;db "Executable Files",0,"*.exe",0,0
;
;
FilePath db 260 dup (0)

Caption db "Choose the file to fix :",0
AppName db "REPARIEREN",0
Done    db "File fixed succesfully !",0

ofn   OPENFILENAME <>

FSize   dd 0
NString db 50 dup (0)
OString db 50 dup (0)
StrLenA dd 0
StrLen2 dd 0

ButtonOpen      db "Open item to be fixed.",0
ButtonPatch     db "Repair Item",0
EditClassName   db "edit",0
ButtonClassName db "button",0
WinName         db  " ",0

StringBuf   db MAXSTR dup (0)
NStringBuf  db MAXSTR dup (0)
NotFound    db "The string can not be found !",0

.data?

hwndOpen HWND ?
hwndPatch HWND ?
hwndString HWND ?
hwndNString HWND ?
hInstance HINSTANCE ?
hwndname HWND ?
hFile HANDLE ?
Numb dd ?
FPointer dd ?

.code

start:

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD

LOCAL wc:WNDCLASSEX ; create local variables on stack
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX ; fill values in members of wc
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,NULL
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 ; register our window class

;invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,

invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,WS_OVERLAPPEDWINDOW or WS_VISIBLE,3,3,400,280,NULL,NULL,hInstance,NULL ; Create the window
mov hwnd,eax

invoke ShowWindow, hwnd,CmdShow ; show our window
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
LOCAL Fpointer

.IF uMsg==WM_CREATE

; Create 2 buttons and 2 edit boxes

invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,ADDR WinName,WS_CHILD,30,15,210,20,hWnd,StringID,hInstance,NULL

 ; CreateWindowEx(
 ;
 ;     DWORD dwExStyle, // extended window style
 ;     LPCTSTR lpClassName, // pointer to registered class name
 ;     LPCTSTR lpWindowName, // pointer to window name
 ;     DWORD dwStyle, // window style
 ;     int x, // horizontal position of window
 ;     int y, // vertical position of window
 ;     int nWidth, // window width
 ;     int nHeight, // window height
 ;     HWND hWndParent, // handle to parent or owner window
 ;     HMENU hMenu, // handle to menu, or child-window identifier
 ;     HINSTANCE hInstance, // handle to application instance
 ;     LPVOID lpParam // pointer to window-creation data

mov hwndString,eax

;                                                                                Window where input is made              3rd number is width
invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,NULL,WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or ES_AUTOHSCROLL,30,40,310,20,hWnd,NStringID,hInstance,NULL

mov hwndNString,eax

invoke SetFocus, hwndString
                                ; open item
invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonOpen,WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,10,70,200,20,hWnd,ButtonOpenID,hInstance,NULL

mov hwndOpen,eax
                        ; repair window                                                                     ; horiz and vertical position
invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonPatch,WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,250,70,100,20,hWnd,ButtonPatchID,hInstance,NULL

mov hwndPatch,eax

.ELSEIF uMsg==WM_COMMAND

mov eax,wParam
mov edx,wParam
shr edx,16

.IF dx==BN_CLICKED

.IF ax==ButtonOpenID ; Open button clicked?

mov ofn.lStructSize,SIZEOF ofn
mov ofn.lpstrFile, OFFSET FilePath
mov ofn.lpstrFilter, OFFSET FilterString
mov ofn.nMaxFile,MAXSIZE
mov ofn.Flags, OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY
mov ofn.lpstrTitle, OFFSET Caption

invoke GetOpenFileName, ADDR ofn

.IF eax == TRUE

; Open file to be repaired
invoke CreateFile, ofn.lpstrFile, GENERIC_READ OR GENERIC_WRITE, FILE_SHARE_READ OR FILE_SHARE_WRITE, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL

.IF eax!=INVALID_HANDLE_VALUE

int 3

mov hFile, eax
Invoke GetFileSize, hFile, NULL

mov FSize, eax ; Save FileSize
Invoke GlobalAlloc, GMEM_FIXED, FSize
mov FPointer, eax

.IF eax == NULL ; If no pointer, error message

push MB_OK OR MB_ICONINFORMATION
push OFFSET NoMem
push OFFSET Error

JMP MESSAGE

.ENDIF

Invoke ReadFile, hFile,FPointer,FSize, ADDR Numb, NULL

.ELSE ; error message if no valid handle

push MB_OK OR MB_ICONINFORMATION
push OFFSET NoFile
push OFFSET Error

jmp MESSAGE

.ENDIF

.ENDIF

.ELSEIF ax == ButtonPatchID ; See if Fix Button has been hit

Invoke GetDlgItemText,hWnd,StringID,ADDR StringBuf,MAXSTR ; Get first string
mov StrLenA, eax ; Save string length



Invoke Convert,ADDR StringBuf, ADDR OString ; Convert to bytes
;                         NString =    201             
Invoke GetDlgItemText,hWnd,NStringID,ADDR NStringBuf,MAXSTR ;Get 2nd string

.IF eax != StrLenA ; both strings equal?

push MB_OK OR MB_ICONINFORMATION ; If not, error message
push OFFSET Error
push OFFSET NotEqual
JMP MESSAGE

.ENDIF

end start
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: Button opens open the current directory but....
« Reply #1 on: December 09, 2012, 08:10:43 AM »
seems to be some code missing, Andy

i added the following just before "end start"
Code: [Select]
            .endif
        .endif
    .else
        invoke DefWindowProc,hWnd,uMsg,wParam,lParam
    .endif
    ret

WndProc endp

that helped a little bit   :P

Magnum

  • Member
  • *****
  • Posts: 2354
Re: Button opens open the current directory but....
« Reply #2 on: December 09, 2012, 08:19:24 AM »
I didn't think it would work when I put it there.

C:\masm32\SOURCE\Repair.asm(428) : fatal error A1010: unmatched block nesting : WndProc

There's supposed to some if's in there and I stil don't think that would work.

Convert endp

WndProc endp


  .endif
        .endif
    .else
        invoke DefWindowProc,hWnd,uMsg,wParam,lParam
    .endif
    ret


end start
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: Button opens open the current directory but....
« Reply #3 on: December 09, 2012, 08:44:06 AM »
here is what i have, Andy
the block nesting and if/else block errors are fixed

the errors are some missing labels, now

Magnum

  • Member
  • *****
  • Posts: 2354
Re: Button opens open the current directory but....
« Reply #4 on: December 09, 2012, 12:01:21 PM »
 : error LNK2001: unresolved external symbol _Convert@8
 : fatal error LNK1120: 1 unresolved externals
Code: [Select]
;
; REPARIEREN.ASM Help from Fetten,Dave,Frank K.,Qword,TightCoderEx,

INCLUDE \masm32\include\masm32rt.inc

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
Convert proto :DWORD,:DWORD

.const

MAXSTR equ 100
MAXSIZE equ 260
ButtonOpenID equ 100
ButtonPatchID equ 101
StringID equ 200
NStringID equ 201

.data

ClassName      db "WinClass",0

NotEqual       db "Length of strings must be equal",0
Error          db "Error!",0
NoMem          db "Error allocating memory",0
FilterString   db "All Files",0,"*.*",0
NoFile          db "file not present.",0

; INCOMPLETE and important to repair ??
;
;db "Executable Files",0,"*.exe",0,0
;
;
FilePath db 260 dup (0)

Caption db "Choose the file to fix :",0
AppName db "REPARIEREN",0
Done    db "File fixed succesfully !",0

ofn   OPENFILENAME <>

FSize   dd 0
NString db 50 dup (0)
OString db 50 dup (0)
StrLenA dd 0
StrLen2 dd 0

ButtonOpen      db "Open item to be fixed.",0
ButtonPatch     db "Repair Item",0
EditClassName   db "edit",0
ButtonClassName db "button",0
WinName         db  " ",0

StringBuf   db MAXSTR dup (0)
NStringBuf  db MAXSTR dup (0)
NotFound    db "The string can not be found !",0

.data?

hwndOpen HWND ?
hwndPatch HWND ?
hwndString HWND ?
hwndNString HWND ?
hInstance HINSTANCE ?
hwndname HWND ?
hFile HANDLE ?
Numb dd ?
FPointer dd ?

.code

start:

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD

LOCAL wc:WNDCLASSEX ; create local variables on stack
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX ; fill values in members of wc
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,NULL
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 ; register our window class

;invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,

invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,WS_OVERLAPPEDWINDOW or WS_VISIBLE,3,3,400,280,NULL,NULL,hInstance,NULL ; Create the window
mov hwnd,eax

invoke ShowWindow, hwnd,CmdShow ; show our window
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
LOCAL Fpointer

.IF uMsg==WM_CREATE

; Create 2 buttons and 2 edit boxes

invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,ADDR WinName,WS_CHILD,30,15,210,20,hWnd,StringID,hInstance,NULL

; CreateWindowEx(
;
;     DWORD dwExStyle, // extended window style
;     LPCTSTR lpClassName, // pointer to registered class name
;     LPCTSTR lpWindowName, // pointer to window name
;     DWORD dwStyle, // window style
;     int x, // horizontal position of window
;     int y, // vertical position of window
;     int nWidth, // window width
;     int nHeight, // window height
;     HWND hWndParent, // handle to parent or owner window
;     HMENU hMenu, // handle to menu, or child-window identifier
;     HINSTANCE hInstance, // handle to application instance
;     LPVOID lpParam // pointer to window-creation data

mov hwndString,eax

;                                                                                Window where input is made              3rd number is width
invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,NULL,WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or ES_AUTOHSCROLL,30,40,310,20,hWnd,NStringID,hInstance,NULL

mov hwndNString,eax

invoke SetFocus, hwndString
; open item
invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonOpen,WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,10,70,200,20,hWnd,ButtonOpenID,hInstance,NULL

mov hwndOpen,eax
; repair window                                                                     ; horiz and vertical position
invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonPatch,WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,250,70,100,20,hWnd,ButtonPatchID,hInstance,NULL

mov hwndPatch,eax

.ELSEIF uMsg==WM_COMMAND

mov eax,wParam
mov edx,wParam
shr edx,16

.IF dx==BN_CLICKED

.IF ax==ButtonOpenID ; Open button clicked?

mov ofn.lStructSize,SIZEOF ofn
mov ofn.lpstrFile, OFFSET FilePath
mov ofn.lpstrFilter, OFFSET FilterString
mov ofn.nMaxFile,MAXSIZE
mov ofn.Flags, OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY
mov ofn.lpstrTitle, OFFSET Caption

invoke GetOpenFileName, ADDR ofn

.IF eax == TRUE

invoke MessageBox,0,ofn.lpstrFile,0,0

; Open file to be repaired

invoke CreateFile, ofn.lpstrFile, GENERIC_READ OR GENERIC_WRITE, FILE_SHARE_READ OR FILE_SHARE_WRITE, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL

.IF eax!=INVALID_HANDLE_VALUE

int 3

mov hFile, eax
Invoke GetFileSize, hFile, NULL

mov FSize, eax ; Save FileSize
Invoke GlobalAlloc, GMEM_FIXED, FSize
mov FPointer, eax

.IF eax == NULL ; If no pointer, error message

push MB_OK OR MB_ICONINFORMATION
push OFFSET NoMem
push OFFSET Error

JMP MESSAGE

.ENDIF

Invoke ReadFile, hFile,FPointer,FSize, ADDR Numb, NULL

.ELSE ; error message if no valid handle

push MB_OK OR MB_ICONINFORMATION
push OFFSET NoFile
push OFFSET Error

jmp MESSAGE

.ENDIF

.ENDIF

.ELSEIF ax == ButtonPatchID ; See if Fix Button has been hit

Invoke GetDlgItemText,hWnd,StringID,ADDR StringBuf,MAXSTR ; Get first string
mov StrLenA, eax ; Save string length

Invoke Convert,ADDR StringBuf, ADDR OString ; Convert to bytes
;                         NString =    201             
Invoke GetDlgItemText,hWnd,NStringID,ADDR NStringBuf,MAXSTR ;Get 2nd string

.IF eax != StrLenA ; both strings equal?

push MB_OK OR MB_ICONINFORMATION ; If not, error message
push OFFSET Error
push OFFSET NotEqual
JMP MESSAGE

.ENDIF

.endif
.endif
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
.endif

MESSAGE:

push NULL
Call MessageBox

ret

WndProc endp

end start
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: Button opens open the current directory but....
« Reply #5 on: December 09, 2012, 12:11:20 PM »
you have a PROTO for Convert - but no PROC   :biggrin:

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: Button opens open the current directory but....
« Reply #6 on: December 09, 2012, 01:05:22 PM »
Andy,

Looking back over your posts I cannot find anything but part of a Convert procedure definition. Your choices are basically:
  • Place the procedure definition directly in your source.
  • Include the procedure definition in your source with the include directive.
  • Assemble (or compile if the procedure is in a HLL) the procedure definition to an object module and link your app with that object module.
  • Place the procedure object module in a static library and link your app with the library.
I would go for the first choice.

Also, as qword suggested, you should format your code with some sort of block structure so it will be easier to navigate.

Well Microsoft, here’s another nice mess you’ve gotten us into.

Magnum

  • Member
  • *****
  • Posts: 2354
Re: Button opens open the current directory but....
« Reply #7 on: December 09, 2012, 01:07:46 PM »
Result of raking leaves, hearing screams of 2 year old grand daughter, and hanging up Christmas lights.

I think it took Edison around a 1000 different tries to come up with a suitable filament material. :-)

 fatal error A1011: directive must be in control block


; Anti-Reverse_Sore-ss_Code
; REPAIR.ASM Help from Fetten, Dave, Frank K., Qword,TightCoderEx,Brain_From_The_Wizard
;
;
Code: [Select]
INCLUDE \masm32\include\masm32rt.inc

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
Convert proto :DWORD,:DWORD

.const

MAXSTR equ 100
MAXSIZE equ 260
ButtonOpenID equ 100
ButtonPatchID equ 101
StringID equ 200
NStringID equ 201

.data

ClassName      db "WinClass",0

NotEqual       db "Length of strings must be equal",0
Error          db "Error!",0
NoMem          db "Error allocating memory",0
FilterString   db "All Files",0,"*.*",0

; in other source, looks incomplete ??
;db "Executable Files",0,"*.exe",0,0

FilePath db 260 dup (0)

Caption db "Choose the file to fix :",0
AppName db "REPARIEREN",0
Done    db "File fixed succesfully !",0

NoFile db "Can't find the file !",0
WrFile db "Error writing to file !",0

ofn   OPENFILENAME <>

FSize            dd 0
NString          db 50 dup (0)
OString          db 50 dup (0)
StrLenA          dd 0
StrLen2          dd 0

ButtonOpen      db "Open item to be fixed.",0
ButtonPatch     db "Repair Item",0
EditClassName   db "edit",0
ButtonClassName db "button",0
WinName         db  " ",0

StringBuf   db MAXSTR dup (0)
NStringBuf  db MAXSTR dup (0)
NotFound    db "The string can not be found !",0

.data?

hwndOpen HWND ?
hwndPatch HWND ?
hwndString HWND ?
hwndNString HWND ?
hInstance HINSTANCE ?
hwndname HWND ?
hFile HANDLE ?
Numb dd ?
FPointer dd ?

.code

start:

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD

LOCAL wc:WNDCLASSEX ; create local variables on stack
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX ; fill values in members of wc
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,NULL
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 ; register our window class

invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,WS_OVERLAPPEDWINDOW or WS_VISIBLE,3,3,400,280,NULL,NULL,hInstance,NULL ; Create the window
mov hwnd,eax

invoke ShowWindow, hwnd,CmdShow ; show our window
invoke UpdateWindow, hwnd

.WHILE TRUE ; The MessageLoop use of register assumed to ERROR <error FIXED Friday, December 07, 2012>

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
LOCAL Fpointer

.IF uMsg==WM_CREATE

; Create 2 buttons and 2 editboxes

invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,ADDR WinName,WS_CHILD,30,15,210,20,hWnd,StringID,hInstance,NULL

 ; CreateWindowEx
 ;     DWORD dwExStyle, // extended window style
 ;     LPCTSTR lpClassName, // pointer to registered class name
 ;     LPCTSTR lpWindowName, // pointer to window name
 ;     DWORD dwStyle, // window style
 ;     int x, // horizontal position of window
 ;     int y, // vertical position of window
 ;     int nWidth, // window width
 ;     int nHeight, // window height
 ;     HWND hWndParent, // handle to parent or owner window
 ;     HMENU hMenu, // handle to menu, or child-window identifier
 ;     HINSTANCE hInstance, // handle to application instance
 ;     LPVOID lpParam // pointer to window-creation data

mov hwndString,eax
;                       Window where input is made                                              3rd number is width
invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,NULL,WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or ES_AUTOHSCROLL,30,40,310,20,hWnd,NStringID,hInstance,NULL

mov hwndNString,eax

invoke SetFocus, hwndString
                        ; open item
invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonOpen,WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,10,70,200,20,hWnd,ButtonOpenID,hInstance,NULL

mov hwndOpen,eax
                        ; repair window                                                              ; horiz and vertical position
invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonPatch,WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,250,70,100,20,hWnd,ButtonPatchID,hInstance,NULL

mov hwndPatch,eax

.ELSEIF uMsg==WM_COMMAND

mov eax,wParam
mov edx,wParam
shr edx,16

.IF dx==BN_CLICKED

.IF ax==ButtonOpenID ; Open button clicked?

mov ofn.lStructSize,SIZEOF ofn
mov ofn.lpstrFile, OFFSET FilePath
mov ofn.lpstrFilter, OFFSET FilterString
mov ofn.nMaxFile,MAXSIZE
mov ofn.Flags, OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY
mov ofn.lpstrTitle, OFFSET Caption

invoke GetOpenFileName, ADDR ofn

.IF eax == TRUE

; Open file to be repaired
invoke CreateFile, ofn.lpstrFile, GENERIC_READ OR GENERIC_WRITE, FILE_SHARE_READ OR FILE_SHARE_WRITE, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL

.IF eax!=INVALID_HANDLE_VALUE

; message about invalid file handle
;
; int 3

mov hFile, eax
Invoke GetFileSize, hFile, NULL

mov FSize, eax ; Save FileSize
Invoke GlobalAlloc, GMEM_FIXED, FSize
mov FPointer, eax

.IF eax == NULL ; If no pointer, error message

push MB_OK OR MB_ICONINFORMATION
push OFFSET NoMem
push OFFSET Error
push NULL
Call MessageBox

.ENDIF ; 6 if, 1 endif

Invoke ReadFile, hFile,FPointer,FSize, ADDR Numb, NULL

.ELSE ; error message if no valid handle

push MB_OK OR MB_ICONINFORMATION
push OFFSET NoFile
push OFFSET Error

push NULL
Call MessageBox

.ENDIF

.ENDIF ; 8 ifs, 1 endif

.ELSEIF ax == ButtonPatchID ; See if Fix Button has been hit

Invoke GetDlgItemText,hWnd,StringID,ADDR StringBuf,MAXSTR ; Get first string
mov StrLenA, eax ; Save string length

Invoke Convert,ADDR StringBuf, ADDR OString ; Convert to bytes
;                         NString =    201             
Invoke GetDlgItemText,hWnd,NStringID,ADDR NStringBuf,MAXSTR ;Get 2nd string

.IF eax != StrLenA ; both strings equal?

push MB_OK OR MB_ICONINFORMATION ; If not, error message
push OFFSET Error
push OFFSET NotEqual

push NULL
Call MessageBox

.ENDIF ; 9 ifs, 2 endifs

Invoke Convert,ADDR NStringBuf, ADDR NString ; Convert to bytes

mov edi,FPointer ;move pointer to memory to edi
mov ecx,FSize ;move Filesize to ecx
mov esi,offset OString ;set ESI to the Opcode string we search
mov al, byte ptr [esi] ;move the first byte of the string to AL

SEARCH:

repnz scasb ;repeat until ECX=0 or AL equals the value of the byte [EDI], EDI is incremented by 1 every run

cmp ecx,0 ;If ECX=0, no matching string is found

jz NOT_FOUND

FOUND_A_MATCH :         ;found matching byte
push ecx                ;save registers
push edi
push esi
dec edi                 ;EDI-1 because REPZ added 1 byte to much
mov ecx,StrLen2         ;ECX = length of the string
repz cmpsb              ;repeat until the values in the memory o ;[EDI] and [ESI] are not equal, or ecx=0
cmp ecx,0               ;If ecx = 0, we have found the correct string

jz FIX

pop esi                 ;Restore registers for continuing search
pop edi
pop ecx
jmp SEARCH              ;go on with search

FIX:

pop esi
pop edi
pop ecx
dec edi ;EDI - 1
inc ecx ;ECX + 1
mov eax,FSize

sub eax,ecx ;compute the File Offset to repair FileSize - remaining bytes (ecx) = Offset to repair

Invoke SetFilePointer, hFile, eax, NULL, FILE_BEGIN

Invoke WriteFile, hFile,offset NString, StrLen2, ADDR Numb, NULL

mov eax, Numb ; 9 ifs, 2 endifs

.IF eax == StrLen2 ; bytes written = Bytes to write ?

push MB_OK ; If so success-message
push OFFSET AppName
push OFFSET Done

push NULL
Call MessageBox

.ELSE

push MB_OK OR MB_ICONINFORMATION ; If not, error message
push OFFSET Error
push OFFSET WrFile

.ENDIF ; 10 ifs, 3 endifs

NOT_FOUND:

push MB_OK OR MB_ICONINFORMATION ; If no handle, error message
push OFFSET Error
push OFFSET NotFound
 
push NULL
Call MessageBox

.ENDIF

.ENDIF ;10 ifs, 4 endifs

.ELSEIF uMsg==WM_DESTROY ; Close program

invoke CloseHandle, hFile ; Release handle
invoke GlobalFree,Fpointer ; Release memory block
invoke ExitProcess,eax ; Exit
invoke PostQuitMessage,NULL

.ELSE

invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret

.ENDIF

xor eax,eax

.ENDIF
.ENDIF
.ENDIF
.ENDIF

ret

WndProc endp

; This routine converts the ascii strings to their byte equivalent. eg
; string 7415FF -> 74h,15h,FFh
; Use only numbers, and uppercase letters (A,B,C,D,E,F)

; Change a string to its byte equivalent.
; Use only numbers, and uppercase letters

Convert proc LpBuffer:DWORD,LpString:DWORD

    push eax
    push esi
    push ecx
    push edx
    mov esi, LpBuffer
    mov edx, LpString
    xor ecx, ecx

MORE:

    MOV al, [esi]

    .IF al > 29h
       
        .if al&0Fh

            IMUL eax, 10h

        .ELSE

        .IF al>64

            .IF al

                SUB al, 55

                IMUL eax, 10h

            .ENDIF

        .ENDIF

    .ENDIF

    .ENDIF

MOV byte ptr [edx+ecx], al
INC esi
mov al, [esi]

  .IF al > 29h

      .if al&0Fh

            ADD byte ptr [edx+ecx], al

        .ELSE

            .IF al > 64

                 sub al,55

                .if !ZERO?

                    ADD byte ptr [edx+ecx], al

                .ENDIF

            .ENDIF

        .ENDIF

.ENDIF

        .IF byte ptr [edx+ecx] != NULL

                INC esi
                INC ecx
                JMP MORE

        .ENDIF

mov StrLen2, ecx

pop edx
pop ecx
pop esi
pop eax

ret

Convert endp

;WndProc endp


  ;.endif
   ;     .endif
    ;.else
        invoke DefWindowProc,hWnd,uMsg,wParam,lParam
    ;.endif
    ;ret

WndProc endp

end start
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

  • Member
  • *****
  • Posts: 2354
Re: Button opens open the current directory but....
« Reply #8 on: December 09, 2012, 01:35:22 PM »
This bombs after I pick a file.

I kinda like making those buttons and windows.

Code: [Select]
; last error in is LASTERR Error No impersonation token
;
 ; REPARIEREN.ASM Help from Fetten,Dave,Frank K.,Qword,TightCoderEx,
 
INCLUDE \masm32\include\masm32rt.inc

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
Convert proto :DWORD,:DWORD

.const

MAXSTR equ 100
MAXSIZE equ 260
ButtonOpenID equ 100
ButtonPatchID equ 101
StringID equ 200
NStringID equ 201

.data

ClassName      db "WinClass",0

NotEqual       db "Length of strings must be equal",0
Error          db "Error!",0
NoMem          db "Error allocating memory",0
FilterString   db "All Files",0,"*.*",0

; in other source, looks incomplete ??
;db "Executable Files",0,"*.exe",0,0

FilePath db 260 dup (0)

Caption db "Choose the file to fix :",0
AppName db "REPARIEREN",0
Done    db "File fixed succesfully !",0

NoFile db "Can't find the file !",0
WrFile db "Error writing to file !",0

ofn   OPENFILENAME <>

FSize   dd 0
NString db 50 dup (0)
OString db 50 dup (0)
StrLenA dd 0
StrLen2 dd 0

ButtonOpen      db "Open item to be fixed.",0
ButtonPatch     db "Repair Item",0
EditClassName   db "edit",0
ButtonClassName db "button",0
WinName         db  " ",0

StringBuf   db MAXSTR dup (0)
NStringBuf  db MAXSTR dup (0)
NotFound    db "The string can not be found !",0

.data?

hwndOpen HWND ?
hwndPatch HWND ?
hwndString HWND ?
hwndNString HWND ?
hInstance HINSTANCE ?
hwndname HWND ?
hFile HANDLE ?
Numb dd ?
FPointer dd ?

.code

start:

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD

LOCAL wc:WNDCLASSEX ; create local variables on stack
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX ; fill values in members of wc
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,NULL
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 ; register our window class

;invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,

invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,WS_OVERLAPPEDWINDOW or WS_VISIBLE,3,3,400,280,NULL,NULL,hInstance,NULL ; Create the window
mov hwnd,eax

invoke ShowWindow, hwnd,CmdShow ; show our window
invoke UpdateWindow, hwnd

.WHILE TRUE ; The MessageLoop use of register assumed to ERROR <error FIXED Friday, December 07, 2012>

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
LOCAL Fpointer

.IF uMsg==WM_CREATE

; Create 2 buttons and 2 editboxes

invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,ADDR WinName,WS_CHILD,30,15,210,20,hWnd,StringID,hInstance,NULL

 ; CreateWindowEx(
 ;
 ;     DWORD dwExStyle, // extended window style
 ;     LPCTSTR lpClassName, // pointer to registered class name
 ;     LPCTSTR lpWindowName, // pointer to window name
 ;     DWORD dwStyle, // window style
 ;     int x, // horizontal position of window
 ;     int y, // vertical position of window
 ;     int nWidth, // window width
 ;     int nHeight, // window height
 ;     HWND hWndParent, // handle to parent or owner window
 ;     HMENU hMenu, // handle to menu, or child-window identifier
 ;     HINSTANCE hInstance, // handle to application instance
 ;     LPVOID lpParam // pointer to window-creation data

mov hwndString,eax

;                                                                                Window where input is made              3rd number is width
invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,NULL,WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or ES_AUTOHSCROLL,30,40,310,20,hWnd,NStringID,hInstance,NULL

mov hwndNString,eax

invoke SetFocus, hwndString
                                ; open item
invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonOpen,WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,10,70,200,20,hWnd,ButtonOpenID,hInstance,NULL

mov hwndOpen,eax
                        ; repair window                                                                     ; horiz and vertical position
invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonPatch,WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,250,70,100,20,hWnd,ButtonPatchID,hInstance,NULL

mov hwndPatch,eax

.ELSEIF uMsg==WM_COMMAND

mov eax,wParam
mov edx,wParam
shr edx,16

.IF dx==BN_CLICKED

.IF ax==ButtonOpenID ; Open button clicked?

mov ofn.lStructSize,SIZEOF ofn
mov ofn.lpstrFile, OFFSET FilePath
mov ofn.lpstrFilter, OFFSET FilterString
mov ofn.nMaxFile,MAXSIZE
mov ofn.Flags, OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY
mov ofn.lpstrTitle, OFFSET Caption

invoke GetOpenFileName, ADDR ofn

.IF eax == TRUE

; Open file to be repaired

invoke CreateFile, ofn.lpstrFile, GENERIC_READ OR GENERIC_WRITE, FILE_SHARE_READ OR FILE_SHARE_WRITE, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL

.IF eax!=INVALID_HANDLE_VALUE

int 3

mov hFile, eax
Invoke GetFileSize, hFile, NULL

mov FSize, eax ; Save FileSize
Invoke GlobalAlloc, GMEM_FIXED, FSize
mov FPointer, eax

.IF eax == NULL ; If no pointer, error message

push MB_OK OR MB_ICONINFORMATION
push OFFSET NoMem
push OFFSET Error

JMP MESSAGE

.ENDIF

Invoke ReadFile, hFile,FPointer,FSize, ADDR Numb, NULL

.ELSE ; error message if no valid handle

push MB_OK OR MB_ICONINFORMATION
push OFFSET NoFile
push OFFSET Error

jmp MESSAGE

.ENDIF

.ENDIF

.ELSEIF ax == ButtonPatchID ; See if Fix Button has been hit

Invoke GetDlgItemText,hWnd,StringID,ADDR StringBuf,MAXSTR ; Get first string
mov StrLenA, eax ; Save string length

Invoke Convert,ADDR StringBuf, ADDR OString ; Convert to bytes
;                         NString =    201             
Invoke GetDlgItemText,hWnd,NStringID,ADDR NStringBuf,MAXSTR ;Get 2nd string

.IF eax != StrLenA ; both strings equal?

push MB_OK OR MB_ICONINFORMATION ; If not, error message
push OFFSET Error
push OFFSET NotEqual
JMP MESSAGE

.ENDIF

Invoke Convert,ADDR NStringBuf, ADDR NString ; Convert to bytes

mov edi,FPointer ;move pointer to memory to edi
mov ecx,FSize ;move Filesize to ecx
mov esi,offset OString ;set ESI to the Opcode string we search
mov al, byte ptr [esi] ;move the first byte of the string to AL

SEARCH :

repnz scasb ;repeat until ECX=0 or AL equals the value of the byte [EDI], EDI is incremented by 1 every run

cmp ecx,0 ;If ECX=0, no matching string is found

jz NOT_FOUND

FOUND_A_MATCH :         ;found matching byte
push ecx                ;save registers
push edi
push esi
dec edi                 ;EDI-1 because REPZ added 1 byte to much
mov ecx,StrLen2         ;ECX = length of the string
repz cmpsb              ;repeat until the values in the memory o ;[EDI] and [ESI] are not equal, or ecx=0
cmp ecx,0               ;If ecx = 0, we have found the correct string

jz FIX

pop esi                 ;Restore registers for continuing search
pop edi
pop ecx
jmp SEARCH              ;go on with search

FIX :

pop esi
pop edi
pop ecx
dec edi ;EDI - 1
inc ecx ;ECX + 1
mov eax,FSize

sub eax,ecx ;compute the File Offset to repair FileSize - remaining bytes (ecx) = Offset to repair

Invoke SetFilePointer, hFile, eax, NULL, FILE_BEGIN

Invoke WriteFile, hFile,offset NString, StrLen2, ADDR Numb, NULL

mov eax, Numb
.IF eax == StrLen2 ; bytes written = Bytes to write ?

push MB_OK ; If so success-message
push OFFSET AppName
push OFFSET Done

JMP MESSAGE

.ELSE

push MB_OK OR MB_ICONINFORMATION ; If not, error message
push OFFSET Error
push OFFSET WrFile

.ENDIF

NOT_FOUND :

push MB_OK OR MB_ICONINFORMATION ; If no handle, error message
push OFFSET Error
push OFFSET NotFound

MESSAGE :

push NULL
Call MessageBox

.ENDIF

.ENDIF


.ELSEIF uMsg==WM_DESTROY ; Close program

invoke CloseHandle, hFile ; Release handle
invoke GlobalFree,Fpointer ; Release memory block
invoke ExitProcess,eax ; Exit
invoke PostQuitMessage,NULL

.ELSE

invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret

WndProc endp

; This routine converts the ascii strings to their byte equivalent. eg
; string 7415FF -> 74h,15h,FFh
; Use only numbers, and uppercase letters (A,B,C,D,E,F)

; Change a string to its byte equivalent.
; Use only numbers, and uppercase letters

Convert proc LpBuffer:DWORD,LpString:DWORD

    push eax
    push esi
    push ecx
    push edx
    mov esi, LpBuffer
    mov edx, LpString
    xor ecx, ecx

MORE :

    MOV al, [esi]

    .IF al > 29h
       
        .if al&0Fh

            IMUL eax, 10h

        .ELSE

        .IF al>64

            .IF al

                SUB al, 55

                IMUL eax, 10h

            .ENDIF

        .ENDIF

    .ENDIF

    .ENDIF

    MOV byte ptr [edx+ecx], al
    INC esi
    mov al, [esi]

  .IF al >29h

      .if al&0Fh

            ADD byte ptr [edx+ecx], al

        .ELSE

            .IF al > 64

                 sub al,55

                .if !ZERO?

                    ADD byte ptr [edx+ecx], al

                .ENDIF

            .ENDIF

        .ENDIF

        .ENDIF

            .IF byte ptr [edx+ecx] != NULL

                INC esi
                INC ecx
                JMP MORE

            .ENDIF
            mov StrLen2, ecx

            pop edx
            pop ecx
            pop esi
            pop eax

            ret

Convert endp

end start



Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: Button opens open the current directory but....
« Reply #9 on: December 09, 2012, 01:49:29 PM »
lol
well - i can't understand the if/else structures - too confusing
but - GetOpenFileName returns non-zero if the user selects a file and clicks OK
you have...
Code: [Select]
.IF eax==TRUE
just use...
Code: [Select]
.IF eax
which is logically the same as
Code: [Select]
.IF eax!=0
that way, any non-zero value will satisfy the case test

i think the "else" choice is INT3, so that would explain the crash

Magnum

  • Member
  • *****
  • Posts: 2354
Re: Button opens open the current directory but....
« Reply #10 on: December 10, 2012, 05:14:28 AM »
I guess you didn't notice this in my code.

This commented code is supposed to open another test.exe that I have and search for text.

; in other source, looks incomplete ??
;db "Executable Files",0,"*.exe",0,0

Andy

P.S. One of my failures opened up multiple windows at a rather fast rate. I had to do a 3 finger salute to stop that "puppy."  :t

Future project will me making a plugin type SEH for my progs.

M.S. told me they were making a new security update for some new error codes in the kernel based on behavior of some of my progs. :-)
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: Button opens open the current directory but....
« Reply #11 on: December 10, 2012, 06:12:35 AM »
M.S. told me they were making a new security update for some new
error codes in the kernel based on behavior of some of my progs. :-)

lol - i am not sure i would admit to that one   :biggrin:

Magnum

  • Member
  • *****
  • Posts: 2354
Re: Button opens open the current directory but....
« Reply #12 on: December 10, 2012, 06:42:05 AM »
It was a joke.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org