hello

is there any method in assembly to know when the program got into a loop ?

im dev a program that in most of cases can turn into a loop...

is there any way to detect it ? and stop .. or advice??

dunno.. register same values,eip, the stack ... anything that could identify a loop can be good

thanks
Posted on 2006-06-02 19:18:37 by GR33d
GR33d

Maybe inc?
Posted on 2006-06-02 19:24:14 by gavin_
yeah i know..

count how many times we are in the loop right?

i was trying to get arround that....

but its ok i guess
Posted on 2006-06-02 19:36:56 by GR33d
What kind of loop are you referring to?
Posted on 2006-06-03 01:41:00 by roticv
Playing around with the halting problem? :)
Posted on 2006-06-03 03:36:04 by f0dder
lol yeah

lest say that i have a "goTo" function
that can goback and reDo some other functions.. and... repeat it self "goTo" same place .. and on ...and on... and on lol
Posted on 2006-06-03 06:45:01 by GR33d
GR33d,
    Are you asking if a program is stuck in a loop?  Or has accessed a loop?  Sounds like you need to get hep on program tracing.  Ratch
Posted on 2006-06-03 07:48:20 by Ratch
im asking if theres anyway to know when a program is stuck in a loop.
Posted on 2006-06-03 09:58:23 by GR33d
GR33d,

im asking if theres anyway to know when a program is stuck in a loop


    Your first clue to that problem is that the program doesn't seem to do anything, and doesn't terminate.  You can then run the prog with a debugger like Ollydbg, and determine why it doesn't exit the loop.  Otherwise you can code judicious memory or register snapshots in various parts of your program to find out what's happening.  Ratch
Posted on 2006-06-03 10:52:54 by Ratch
ratch

the problem that i have is not that i HAVE a loop

but yes to know WHEN the program is stuck

i mean,
to code some routine that checks if the proggy is stuck in a loop

cos... the proggy has a function that if someone bad uses it, 100% shure the program will stuck, and thats what im trying to prevent....

sorr if im making my self or u guys confuse  :P
thanks
Posted on 2006-06-04 08:46:29 by GR33d
Here's how I would do it....

You can use a waitable event object and monitor the loop in a separate thread and if it is caught in the loop for a maximum time then it is considered hung...
// Create an event, this only needs to be done once
invoke CreateEvent,NULL,TRUE,FALSE,"testevent"
mov ,eax

.enterloop
// Reset the object and start our policing thread
invoke ResetEvent,
invoke CreateThread,NULL,NULL,offset ThreadProc,,NULL,offset tid
// We don't need the threads handle so close it
invoke CloseHandle,eax

; create an infinite loop
:
jmp <

// Be sure to signal the thread if you exit the loop normally
invoke SetEvent,

// Close the object when we're done with it
invoke CloseHandle,
invoke ExitProcess,0

ThreadProc FRAME lpParameter

invoke WaitForSingleObject,,2000 ; 2 seconds and it's hung

test eax,eax
jnz >.APPHUNG

invoke MessageBox,NULL,"This application is not hung",NULL,MB_OK
RET

.APPHUNG
invoke MessageBox,NULL,"This application is hung",NULL,MB_OK
invoke CloseHandle,
invoke ExitProcess,0
RET
ENDF
Posted on 2006-06-04 11:00:08 by donkey
hummm

very nice

watch the proggy from another thread ... that seems to work

ill try it !

thanks
Posted on 2006-06-04 17:57:06 by GR33d