The MASM Forum

General => The Campus => Topic started by: Magnum on November 27, 2012, 03:09:21 PM

Title: Unhandled application exception
Post by: Magnum on November 27, 2012, 03:09:21 PM
I am testing Intel Inspector XE and came up with this when I run my code below it.

I will be reading up on error handlers.

ID      Problem   Sources   Modules   Object Size   State
P1      Unhandled application exception   [Unknown]   kernel32.dll      New
          Unhandled application exception   kernel32.dll:0x438f5   kernel32.dll      New
P2      Invalid memory access   [Unknown]   Virtual_Prot.exe      New
          Invalid memory access   Virtual_Prot.exe:0x1001   Virtual_Prot.exe      New
P3      Invalid memory access   [Unknown]   Virtual_Prot.exe      New
          Invalid memory access   Virtual_Prot.exe:0x1001   Virtual_Prot.exe      New


INCLUDE \masm32\include\masm32rt.inc

.DATA?

Alt dd ? ; address of variable to get old protection

.CODE

Andern:

mov ebx,041h

print uhex$(ebx),13,10

inkey
invoke ExitProcess,0

Start:

  invoke VirtualProtect,Andern,10,PAGE_EXECUTE_READWRITE,addr Alt
  mov ebx,41h
  mov dword ptr Andern,ebx
  mov byte ptr Andern+4,bl
jmp Andern

END Start
Title: Re: Unhandled application exception
Post by: dedndave on November 27, 2012, 03:26:53 PM
the bytes 41h,0,0,0,41h don't make any sense as code   :P
:004012C6 41                      inc ecx
:004012C7 0000                    add [eax], al   ;<----- crash
:004012C9 004133                  add [ecx+33], al


the code
mov ebx,41h
is
db 0BBh,41h,0,0,0
Title: Re: Unhandled application exception
Post by: qWord on November 27, 2012, 03:30:51 PM
Magnum,
why are you not using OllyDbg to answer such question yourself?
Title: Re: Unhandled application exception
Post by: dedndave on November 27, 2012, 03:46:01 PM
try this...
INCLUDE \masm32\include\masm32rt.inc

.DATA?

Alt dd ? ; address of variable to get old protection

.CODE

Andern:
mov ebx,0FFFFFFFFh
print uhex$(ebx),13,10
inkey
invoke ExitProcess,0

Start:
  invoke VirtualProtect,Andern,2048,PAGE_EXECUTE_READWRITE,addr Alt
mov byte ptr Andern,0BBh
mov dword ptr Andern+1,41h
jmp Andern

END Start

when you alter the attribute for a byte, you alter it for the whole page, which is 2048 bytes

EDIT: oops - had to add MOV EBX,0FFFFFFFFh to make room for the code
Title: Re: Unhandled application exception
Post by: MichaelW on November 27, 2012, 04:25:01 PM
Unless it's changed recently, a page is 4096 bytes.
Title: Re: Unhandled application exception
Post by: dedndave on November 27, 2012, 10:25:51 PM
right - my mistake   :t
don't know why i was thinking 2 k
Title: Re: Unhandled application exception
Post by: Magnum on November 27, 2012, 10:54:16 PM
Quote from: qWord on November 27, 2012, 03:30:51 PM
Magnum,
why are you not using OllyDbg to answer such question yourself?

I am using Ollydbg.

I would like to change some lines of my code based on a specific condition being met and write those to my code to be saved.

Andy
Title: Re: Unhandled application exception
Post by: Magnum on November 27, 2012, 11:08:16 PM
I will load it in Olly again and step thru it and look at each step.

Andy
Title: Re: Unhandled application exception
Post by: dedndave on November 29, 2012, 07:22:05 AM
this is Jeremy Gordon's "Except1" program adapted for MASM

give it a try, Andy...
Title: Re: Unhandled application exception
Post by: Magnum on November 29, 2012, 07:50:59 AM
I have managed to mangle bldall.bat.

The other build bats work ok.

@echo off
; COPY /B c:\masm32\source\bak.bat +,,
; f:
; cd f:\z_keep
; COPY /B F:\z_keep\IMPT_Quickies.txt +,,

if exist %1.obj del %1.obj > nul
if exist %1.exe del %1.exe > nul

if not exist rsrc.rc goto over1

\masm32\bin\rc /v rsrc.rc
\masm32\bin\cvtres /machine:ix86 rsrc.res

:over1

\masm32\bin\ml /c /coff %1.asm
if errorlevel 1 goto errasm

pause

if not exist rsrc.obj goto nores

\masm32\bin\Link /SUBSYSTEM:WINDOWS /OPT:NOREF %1.obj rsrc.obj
if errorlevel 1 goto errlink

pause

dir %1.*
goto TheEnd

:nores
\masm32\bin\Link /SUBSYSTEM:WINDOWS /OPT:NOREF %1.obj
if errorlevel 1 goto errlink
pause
dir %1.*
goto TheEnd

:errlink
echo _
echo Link error
goto TheEnd

:errasm
echo _
echo Assembly Error
goto TheEnd

:TheEnd

if exist *.udd del *.udd
::if exist *.obj del *.obj
if exist *.res del *.res

PING localhost -n 3 > nul


Title: Re: Unhandled application exception
Post by: dedndave on November 29, 2012, 01:25:50 PM
for one thing, semicolon doesn't seem to make a comment
try double colon - it has worked since DOS days "::"
the way it is, it switches to the F: drive, where i do not have a masm32\bin folder   :biggrin:

not sure why you have a PING in there   :P
Title: Re: Unhandled application exception
Post by: Magnum on November 29, 2012, 11:44:47 PM
Thanks.

That ping command is a 3 second delay that I learned from the batch gurus at https://groups.google.com
alt.msdos.batch.nt

I use it to see view any error messages etc. before closing out.
Title: Re: Unhandled application exception
Post by: CommonTater on November 30, 2012, 12:30:15 AM
Quote from: Magnum on November 29, 2012, 11:44:47 PM
Thanks.

That ping command is a 3 second delay that I learned from the batch gurus at https://groups.google.com
alt.msdos.batch.nt

I use it to see view any error messages etc. before closing out.

Comments are either :: or REM
The ping at the end could easily be replaced by PAUSE which will cause it to wait for you to press Enter...

Title: Re: Unhandled application exception
Post by: Magnum on November 30, 2012, 12:55:38 AM
I didn't want to press Enter.

(I worked for 25 years in  laboratories doing a lot of hand work, my joints are sore.)
Title: Re: Unhandled application exception
Post by: dedndave on November 30, 2012, 02:18:42 AM
you have 2 pauses in there - of course, those may be temporary to debug the batch file

i put one pause at the end of the file
when a console app is waiting for a key press, closing the console window will close the app
before the pause, i do a DIR %1.* /O-D     (/O = ordered list, -D = by date/time, reversed)
if all went well, the EXE and LST files will be at the top of the list
if it did not assemble, the ASM file is usually at the top - i read further to see the errors
if it assembled without errors, i click on the X to close the window - not press a key   :P

if you want to add a delay, you could also use NIRCMD
http://www.nirsoft.net/utils/nircmd.html (http://www.nirsoft.net/utils/nircmd.html)
Title: Re: Unhandled application exception
Post by: CommonTater on November 30, 2012, 07:57:03 AM
Ok... shameless plug time  :biggrin:

Have either of you thought about converting your scripts over to Easy Build (dl in the IDE section right here). 
This kind of problem is exactly why I wrote it...



Title: Re: Unhandled application exception
Post by: Magnum on November 30, 2012, 08:06:44 AM
I will dl it and check it out.