ShadowRayz Posted September 7, 2008 Posted September 7, 2008 start:invoke ShellExecute,NULL ,NULL ,addr Notepad ,NULL ,NULL, SW_SHOWNORMALend startthat's the whole code, besides the Notepad variable Notepad db "C:\Windows\Notepad.exe",0it opens notepad but then i get a memory crash, mem cannot be read.why is that?.
DrPepUr Posted September 7, 2008 Posted September 7, 2008 (edited) Try this.dataszNotepad db "Notepad.exe",0szAction db "Open",0.codeinvoke ShellExecute,NULL ,Addr szAction ,addr szNotepad ,NULL ,NULL, SW_SHOWNORMALinvoke ExitProcess,00 Edited September 7, 2008 by DrPepUr
ShadowRayz Posted September 7, 2008 Author Posted September 7, 2008 I know that the ExitProcess would 'kill' the crash error but i thought its just a cheap way to avoiding something that i might have forgotten, but if its the way it should be then thx
mudlord Posted September 7, 2008 Posted September 7, 2008 (edited) it opens notepad but then i get a memory crash, mem cannot be read.could have got your notepad var wrong.In Win32 C, paths that are accepted by ShellExecute are expected to be like this:"C:\\Windows\\Notepad.exe"That could be your issue.... Edited September 7, 2008 by mudlord
Killboy Posted September 7, 2008 Posted September 7, 2008 The two backslashes are just needed for C(++) since \ denotes a special char, so you need two backslashes to indicate you want the '\' character itself. The resulting string looks like the one posted by ShadowRayz, just one backslash It seems like MASM doesnt need that
ShadowRayz Posted September 7, 2008 Author Posted September 7, 2008 Actaully i debugged the .exe and i saw that MASM Does use double \\, or so Olly say's, but the string in the dump remins C:\Windows\Notepad.exe
HVC Posted September 7, 2008 Posted September 7, 2008 (edited) start:invoke ShellExecute,NULL ,NULL ,addr Notepad ,NULL ,NULL, SW_SHOWNORMALend startThe app crashes because once the API call is executed, section padding starts executed as code. (Relatively to the compiler, a code section is filled with 000h or 0CCh bytes, till its size is rounded up to the next multiple of an alignment value defined in the "SectionAlignment" member of the optional header - MASM linker sets this value by default to 1000h.)So, the application crashes, cause the alignment bytes start being executed as code, with unpredictable results.00401000 > $ 6A 01 PUSH 1 ; /IsShown = 100401002 . 6A 00 PUSH 0 ; |DefDir = NULL00401004 . 6A 00 PUSH 0 ; |Parameters = NULL00401006 . 68 00304000 PUSH Test.00403000; |FileName = "C:\Windows\Notepad.exe"0040100B . 6A 00 PUSH 0 ; |Operation = NULL0040100D . 6A 00 PUSH 0 ; |hWnd = NULL0040100F . E8 00000000 CALL <JMP.&shell32.ShellExecuteA>; \ShellExecuteA00401014 $-FF25 00204000 JMP DWORD PTR DS:[<&shell32.ShellExecute>; shell32.ShellExecuteA0040101A 0000 ADD BYTE PTR DS:[EAX],AL;---------|0040101C 0000 ADD BYTE PTR DS:[EAX],AL;---------|0040101E 0000 ADD BYTE PTR DS:[EAX],AL;---------| ALIGNMENT BYTES TREATED AS CODE00401020 0000 ADD BYTE PTR DS:[EAX],AL;---------|00401022 0000 ADD BYTE PTR DS:[EAX],AL;---------|00401024 0000 ADD BYTE PTR DS:[EAX],AL;---------|.............You need to terminate the program somehow... If this is all you want your executable to do, terminating it by the method DrPepUr suggested is not a "cheap" way - it's the recommended way. Edited September 7, 2008 by HVC
human Posted September 7, 2008 Posted September 7, 2008 you have to close program, if i remember correctly you can put ret instead of exitprocess and it will work same way.without close it will continue from code after that call, so random behaviour.
metr0 Posted September 7, 2008 Posted September 7, 2008 The retn thingy caused some problems for me in the past, the top of the stack holds ExitThread, but it seems like some compiler like to overwrite this value, replacing it with local variables. :x - If the simple retn does not work for you, just call ExitProcess/-Thread which will terminate your application in a rather secure way.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now