User Tools

Site Tools


prop_lastchancehook.htm

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

prop_lastchancehook.htm [2021/04/15 15:57] – external edit 127.0.0.1prop_lastchancehook.htm [2022/04/14 03:50] (current) – Format Code carlbarnes
Line 44: Line 44:
 **Example:** **Example:**
  
-| ** PROGRAM** | +<code> 
- +PROGRAM 
-| ** INCLUDE('CWEXCPT.INT'),ONCE** | +  INCLUDE(CWEXCPT.INT),ONCE 
- +  MAP 
-| ** MAP** | +   Test (LONG,LONG) 
-| **  Test (LONG,LONG)** | +   Hook (*ICWExceptionInfo),LONG 
-| **  Hook (*ICWExceptionInfo),LONG** | +   HEX (LONG),STRING,PRIVATE 
-| **  HEX (LONG),STRING,PRIVATE** | +   MODULE("
-| **  MODULE(")** | +    MessageBox(UNSIGNED, CONST *CSTRING, CONST *CSTRING, UNSIGNED)| 
-| **   MessageBox (UNSIGNED, CONST *CSTRING, CONST *CSTRING, UNSIGNED)|****               ,SIGNED,PROC,PASCAL,NAME('MessageBoxA')** | +                ,SIGNED,PROC,PASCAL,NAME(MessageBoxA
-| **  END** | +   END 
-| ** END** | +  END 
-|  | +MB_ICONHAND EQUATE(00000010h) 
-| **MB_ICONHAND EQUATE(00000010h)** | +CODE 
-|  | +  SYSTEM{PROP:LastChanceHook} = ADDRESS(Hook) 
-| **CODE** | +  Test (10, 0)  !intentionally causes an exception 
-| **SYSTEM{PROP:LastChanceHook} = ADDRESS(Hook)** | +  RETURN 
-| **Test (10, 0)  !intentionally causes an exception** | +</code> 
-| **RETURN** |+
  
 In this example the procedure named //Hook// is assigned as our exception handler. That's the only procedure we are concerned with, the others are just there to help to make the example work by 1) causing an exception and 2) informing the user about the exception. In this example the procedure named //Hook// is assigned as our exception handler. That's the only procedure we are concerned with, the others are just there to help to make the example work by 1) causing an exception and 2) informing the user about the exception.
Line 68: Line 68:
 Next we have: Next we have:
  
-|  | +<code> 
-| **Hook PROCEDURE(*ICWExceptionInfo info)** | +Hook PROCEDURE(*ICWExceptionInfo info) 
-|  | +       CSTRING(1024) 
-| **       CSTRING(1024)** | +Caption  CSTRING(256) 
-| **Caption  CSTRING(256)** | +   CODE 
-|  | + IF info &= NULL 
-| ** CODE** | +    RETURN 0 
-| **  IF info &amp;= NULL** | + END 
-| **   RETURN 0** | +  
-| **  END** | + Caption = 'Exception ' & HEX (info.ExceptionCode()) & ' at ' & HEX (info.ExceptionAddress()) 
-|  | + S ='Registers' & | 
-| **  Caption = 'Exception ' &amp; HEX (info.ExceptionCode()) &amp; ' at ' &amp; HEX (info.ExceptionAddress())** | +    '<13,10>EAX= ' & HEX (info.Register (i386_Register:Reg32_EAX)) & | 
-| **  S = 'Registers' &amp; |** +    ' EBX= ' & HEX (info.Register (i386_Register:Reg32_EBX)) & | 
-| ** '<;13,10>EAX=** **' &amp; HEX (info.Register (i386_Register:Reg32_EAX)) &amp; |** +    ' ECX= ' & HEX (info.Register (i386_Register:Reg32_ECX)) & | 
-| ** ' EBX=** **' &amp; HEX (info.Register (i386_Register:Reg32_EBX)) &amp; |** +    ' EDX= ' & HEX (info.Register (i386_Register:Reg32_EDX)) & | 
-| ** ' ECX=** **' &amp; HEX (info.Register (i386_Register:Reg32_ECX)) &amp; |** +    '<13,10>ESI= ' & HEX (info.Register (i386_Register:Reg32_ESI)) & | 
-| ** ' EDX=** **' &amp; HEX (info.Register (i386_Register:Reg32_EDX)) &amp; |** +    ' EDI= ' & HEX (info.Register (i386_Register:Reg32_EDI)) & | 
-| ** '<;13,10>ESI=** '** &amp; HEX (info.Register (i386_Register:Reg32_ESI)) &amp; |** +    ' ESP= ' & HEX (info.Register (i386_Register:Reg32_ESP)) & | 
-| ** ' EDI=** **' &amp; HEX (info.Register (i386_Register:Reg32_EDI)) &amp; |** +    ' EBP= ' & HEX (info.Register (i386_Register:Reg32_EBP)) & | 
-| ** ' ESP=** **' &amp; HEX (info.Register (i386_Register:Reg32_ESP)) &amp; |** +    '<13,10,13,10>Current thread is being terminated '
-| ** ' EBP=** **' &amp; HEX (info.Register (i386_Register:Reg32_EBP)) &amp; |** +
-| ** '<;13,10,13,10>Current thread is being terminated** **'** | +
-|  | +
-| ** MessageBox (0, S, Caption, MB_ICONHAND)** | +
-| ** RETURN 1      !a positive value signals the RTL to kill the thread** | +
-|  | +
-| **! ******************************* | +
-|  | +
-| **Test PROCEDURE (LONG a, LONG b)** | +
-|  | +
-| ** CODE** | +
-| **  a %= b** | +
-|  | +
-| **! ******************************* | +
-|  | +
-| **HEX PROCEDURE (LONG A)** | +
-|  | +
-| **i       UNSIGNED,AUTO** | +
-| **S       STRING(8),AUTO** | +
-| **DIGITS  STRING('0123456789ABCDEF'),STATIC** | +
-|  | +
-| **  CODE** | +
-| **   i = SIZE(S)** | +
-|  | +
-| **   LOOP WHILE i <;> 0** | +
-| **    S [i] = DIGITS [BAND (A, 0Fh) + 1]** | +
-| **    A = BSHIFT (A, -4)** | +
-| **    i -= 1** | +
-| **   END** | +
-|  | +
-| **   RETURN S** | +
-|  | +
-|  |+
  
-These first two lines of code assign our exception handler function and then call the Test procedure that raises an exception:+  MessageBox(0, S, Caption, MB_ICONHAND) 
 +  RETURN 1      !a positive value signals the RTL to kill the thread 
 +  
 +! ***************************** 
 +Test PROCEDURE (LONG a, LONG b) 
 +CODE 
 +  a %= b
  
-**SYSTEM{PROP:LastChanceHook} ADDRESS (Hook)**+***************************** 
 +HEX PROCEDURE (LONG A) 
 +i       UNSIGNED,AUTO 
 +S       STRING(8),AUTO 
 +DIGITS  STRING(’0123456789ABCDEF’),STATIC 
 + CODE 
 +    i SIZE(S) 
 +    LOOP WHILE i <> 0 
 +     S [i] = DIGITS [BAND (A, 0Fh) + 1] 
 +     A = BSHIFT (A, -4) 
 +     i -= 1 
 +    END 
 +    RETURN S 
 +</code>
  
-**Test (10, 0) ! causes an exception**+These first two lines of code assign our exception handler function and then call the Test procedure that raises an exception:
  
-The exception is trapped and we show the result in a MessageBox.+<code> 
 +    SYSTEM{PROP:LastChanceHook} = ADDRESS (Hook) 
 +    Test (10, 0) ! causes an exception 
 +</code>
  
-Our Hook PROCEDURE (*ICWExceptionInfo info) uses the methods in the interface to show the exception code, its address, and the values of the registers at the time of the exception.+The exception is trapped and we show the result in an API MessageBox. 
 + 
 +Our Hook PROCEDURE(*ICWExceptionInfo info) uses the methods in the interface to show the exception code, its address, and the values of the registers at the time of the exception.
  
 In our example our Hook PROCEDURE executes a **RETURN 1** and since we are running on the main thread, then immediately after the MessageBox is displayed and the user presses the OK button the program itself is terminated. In our example our Hook PROCEDURE executes a **RETURN 1** and since we are running on the main thread, then immediately after the MessageBox is displayed and the user presses the OK button the program itself is terminated.
Line 136: Line 127:
 **Conceptual Example:** **Conceptual Example:**
  
-| **PROGRAM** | +<code> 
-|  | +PROGRAM 
-| **  INCLUDE('CWEXCPT.INT'),ONCE** | + INCLUDE('CWEXCPT.INT'),ONCE 
-|  | + MAP 
-| **  MAP** | +   MyHandler(*ICWExceptionInfo),LONG 
-| **    MyHandler(*ICWExceptionInfo),LONG** | +   BadCode() 
-| **    BadCode()** | +   MODULE(''
-| **    MODULE('')** | +     SLEEP(LONG),PASCAL 
-| **      SLEEP(LONG),PASCAL** | +   END 
-| **    END** | + END 
-| **  END** | +badPtr      &LONG 
-|  | +temp        LONG 
-| **badPtr      &amp;LONG** | +oldHandler  LONG 
-| **temp        LONG** | +continue    BOOL(FALSE) 
-| **oldHandler  LONG** | +  CODE 
-| **continue    BOOL(FALSE)** | +   RESUME(START(BadCode)) 
- +   LOOP WHILE NOT continue 
-| ** CODE** | +     SLEEP(100) 
-| **  RESUME(START(BadCode))** | +   END 
-| **  LOOP WHILE NOT continue** | +   badPtr &= NULL 
-| **    SLEEP(100)** | +   badPtr = 0 
-| **  END** | +   RETURN 
-| **  badPtr &amp;= NULL** | + 
-| **  badPtr = 0** | +BadCode     PROCEDURE() 
-|  | +   CODE 
-| **BadCode     PROCEDURE()** | +   oldHandler = SYSTEM{PROP:LastChanceHook}        !Read address of oldhandler 
-| **  CODE** | +   SYSTEM{PROP:LastChanceHook} = ADDRESS(MyHandler)!Call new handler 
-| **  oldHandler = SYSTEM{PROP:LastChanceHook}        !Read address of oldhandler** | +   badPtr = 0 
-| **  SYSTEM{PROP:LastChanceHook} = ADDRESS(MyHandler)!Call new handler** | +   RETURN 
-| **  badPtr = 0** | +   
-| **  ** | +MyHandler   PROCEDURE(*ICWExceptionInfo info) 
- | +   CODE 
-| **MyHandler   PROCEDURE(*ICWExceptionInfo info)** | +   SYSTEM{PROP:LastChanceHook} = oldHandler 
-| **  CODE** | +   MESSAGE('Someone did something naughty'
-| **  SYSTEM{PROP:LastChanceHook} = oldHandler** | +   continue = TRUE 
-| **  MESSAGE('Someone did something naughty')** | +   RETURN 1 
-| **  continue = TRUE** | +</code>
-| **  RETURN 1** |+
  
prop_lastchancehook.htm.txt · Last modified: 2022/04/14 03:50 by carlbarnes