News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

help... so.. annoying... [solved]

Started by shadow, June 27, 2005, 05:23:19 AM

Previous topic - Next topic

shadow

ok so basically I am writing a small installer program to copy files off of multiple CD's...  The program must copy itself off the first cd, run its copied self and close the instance from the cd....  here's my non-working code:



rtname db "\RTinstall.exe",0
rtpath db "C:\Temp\rtinstall.exe",0
drivepath db "C:\Temp\drive.txt",0
temppath db "C:\Temp",0


.if uMsg==WM_INITDIALOG
push hWin
pop     hWnd

invoke GetCurrentDirectory,SIZEOF mainbuffer,addr mainbuffer
invoke MessageBox,NULL,addr mainbuffer,addr temppath,MB_OK ;prevent an evil infinite loop... dont compile without me
invoke lstrcmp,addr mainbuffer,addr temppath
.if eax!=0

invoke GetCurrentDirectory,sizeof mainbuffer,addr mainbuffer
invoke CreateDirectory,addr temppath,NULL
INVOKE CreateFile,addr drivepath,GENERIC_READ OR GENERIC_WRITE, NULL, NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL
mov hFile,eax         
invoke WriteFile,hFile,addr mainbuffer,3,addr bytes_written,NULL
invoke CloseHandle,hFile

invoke GetCurrentDirectory,sizeof mainbuffer,addr mainbuffer
invoke lstrcat,addr mainbuffer,addr rtname
invoke CopyFile,addr mainbuffer,addr rtpath,NULL
invoke ShellExecute,NULL,NULL,addr rtpath,NULL,NULL,SW_SHOW
invoke ExitProcess,0

.endif

without the messagebox i put in there, the program will go into an infinite loop of opening and closing itself... taskmanager will be useless and you will have to restart...  The program also puts the cd drive letter in C:\temp\drive.txt.  What is going wrong here and how can I fix it!?  I only want C:\temp\rtinstall.exe to be running in the end.  Thanks for your help  :P

Dark Schneider

The problem is:

invoke ExitProcess,0

You should put it somewhere AFTER 'DialogBoxParams' (or whatever function you used to start that dialog box), otherwise, when lstrcmp returns zero it will never reached ExitProcess function call.

AND you should put this line:

Invoke SendMessage, hWin, WM_ENDDIALOG, 0, 0

at the end of WM_INITDIALOG block and/or in an extra WM_CLOSE block

Mark Jones

If you didn't want to roll your own, check out http://nsis.sourceforge.net/

Some of the assembler IDE's even have support for that, like RadAsm.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Farabi

#3
We better not mess up with CD copy. Better we told to MS to not give access to the CD writer on their OS. CD is the most safe media than flashdisk against virus.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

shadow

o.. that wasn't all of my code, that was just what I am having trouble with.. this is all of it:


.386
.model flat,stdcall
option casemap:none

include windows.inc
include user32.inc
include kernel32.inc
include shell32.inc
include comctl32.inc
include comdlg32.inc
include ole32.inc
include masm32.inc
include shlwapi.inc

includelib user32.lib
includelib kernel32.lib
includelib shell32.lib
includelib comctl32.lib
includelib comdlg32.lib
includelib ole32.lib
includelib masm32.lib
includelib shlwapi.lib


WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :HWND,:UINT,:WPARAM,:LPARAM

.const


;RTinstall.dlg
IDD_DIALOG equ 1000
IDC_GRP1 equ 1005
IDC_STC1 equ 1001
IDC_EDT1 equ 1002
IDC_BTN1 equ 1003
IDC_STC2 equ 1004
IDC_BTN2 equ 1006
IDC_EDT2 equ 1007
IDC_STC3 equ 1008
IDC_STC4 equ 1009
IDC_EDT3 equ 1010

;RTinstall.Rc


.data

;--------------------------------------------------------------------------------
;text
foldt db "Please select a folder in which to install the rainbow table files",0
foldc db "Select an install folder",0
nopatht db "Please click the browse button to select a path to save the files.",0
nopathc db "No Path Specified",0
;--------------------------------------------------------------------------------
ofs OFSTRUCT <>
RichEditDLL db 'riched20.dll',0
szWinClass db 'Bleh',0
;--------------------------------------------------------------------------------
;misc
drive db 'drive.txt',0
size1 dd 0,0
rtname db "\RTinstall.exe",0
rtpath db "C:\Temp\rtinstall.exe",0
drivepath db "C:\Temp\drive.txt",0
temppath db "C:\Temp",0

;--------------------------------------------------------------------------------

.data?

mainbuffer db 4000 DUP (?)
mainbuffer1 db 4000 DUP (?)

hFile dd ?
hRichEdDLL dd ?
hInstance dd ?
CommandLine dd ?
hIcon dd ?
hWnd dd ?
iccex INITCOMMONCONTROLSEX <?>
bytes_written DWORD ?


.code

start:




invoke GetModuleHandle,NULL
mov    hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke InitCommonControls
mov iccex.dwSize,sizeof INITCOMMONCONTROLSEX    ;prepare common control structure
mov iccex.dwICC,ICC_DATE_CLASSES
invoke InitCommonControlsEx,addr iccex
invoke LoadLibrary,addr RichEditDLL
mov hRichEdDLL,eax
invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
push eax
invoke FreeLibrary,hRichEdDLL
pop eax



invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG

mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style,CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc,offset WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,DLGWINDOWEXTRA
push hInst
pop wc.hInstance
mov wc.hbrBackground,COLOR_BTNFACE+1
mov wc.lpszMenuName,0
mov wc.lpszClassName,offset szWinClass
invoke LoadIcon,NULL,IDI_APPLICATION
mov hIcon,eax
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx,addr wc
invoke CreateDialogParam,hInstance,IDD_DIALOG,NULL,
   addr WndProc,NULL
mov hWnd,eax



invoke ShowWindow,hWnd,SW_SHOWNORMAL
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 hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
;LOCAL bytes_written:DWORD
.if uMsg==WM_INITDIALOG


push hWin
pop hWnd

invoke GetCurrentDirectory,SIZEOF mainbuffer,addr mainbuffer

invoke MessageBox,NULL,addr mainbuffer,addr temppath,MB_OK
invoke lstrcmp,addr mainbuffer,addr temppath
.if eax!=0

invoke GetCurrentDirectory,sizeof mainbuffer,addr mainbuffer
invoke CreateDirectory,addr temppath,NULL
INVOKE CreateFile,addr drivepath,GENERIC_READ OR GENERIC_WRITE, NULL, NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL
mov hFile,eax         
invoke WriteFile,hFile,addr mainbuffer,3,addr bytes_written,NULL
invoke CloseHandle,hFile

invoke GetCurrentDirectory,sizeof mainbuffer,addr mainbuffer
invoke lstrcat,addr mainbuffer,addr rtname
invoke CopyFile,addr mainbuffer,addr rtpath,NULL
invoke ShellExecute,NULL,NULL,addr rtpath,NULL,NULL,SW_SHOW
invoke SendMessage,hWin,WM_DESTROY,0,0
.endif

.elseif uMsg==WM_COMMAND
mov eax,wParam
mov edx,eax
shr edx,16
and eax,0FFFFh
.if edx==BN_CLICKED

.if eax==IDC_BTN1
invoke BrowseForFolder,hWin,addr mainbuffer,addr foldc,addr foldt
invoke SetDlgItemText,hWin,IDC_EDT1,addr mainbuffer
invoke GetDlgItemText,hWin,IDC_EDT1,addr mainbuffer,4
invoke GetDiskFreeSpaceEx,addr mainbuffer,addr size1,NULL,NULL
invoke StrFormatByteSize64, size1, size1+4, ADDR mainbuffer1, SIZEOF size1
invoke SetDlgItemText,hWin,IDC_EDT2,addr mainbuffer1

.elseif eax==IDC_BTN2
invoke GetDlgItemText,hWin,IDC_EDT1,addr mainbuffer,SIZEOF mainbuffer
.if mainbuffer==0
invoke MessageBox,hWin,addr nopatht,addr nopathc,MB_OK + MB_ICONERROR
ret
.endif
invoke GetDlgItem,hWin,IDC_BTN1
invoke EnableWindow,eax,FALSE
invoke SetWindowPos,hWin,HWND_TOPMOST,1,1,499,319,SWP_NOMOVE + SWP_NOREPOSITION
;invoke CopyFileEx,

.endif
.endif
.elseif uMsg==WM_CLOSE

;
; invoke DeleteFile,addr drivepath
; invoke DeleteFile,addr rtpath
;;invoke RemoveDirectory,addr temppath
invoke DestroyWindow,hWin
.elseif uMsg==WM_DESTROY

invoke PostQuitMessage,NULL
.else
invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret
.endif
xor    eax,eax
ret

WndProc endp

;#########################################################################

end start

been working on it all last night... GRR i know it's something stupid.  The program is to install 18 GB of rainbow tables off of 5 dvds.  I'm using radasm... I have inno setup compiler, but mines waaaay cooler :)

shadow

O YAY i got it!

i had invoke ShellExecute,NULL,NULL,addr rtname1,NULL,NULL,SW_SHOW instead of invoke ShellExecute,NULL,NULL,addr rtname1,NULL,addr temppath,SW_SHOW, forgot to specify the default directory, so lstrcmp would always come out nonzero.