prop_lastchancehook.htm
Differences
This shows you the differences between two versions of the page.
prop_lastchancehook.htm [2021/04/15 15:57] – external edit 127.0.0.1 | prop_lastchancehook.htm [2022/04/14 03:50] (current) – Format Code carlbarnes | ||
---|---|---|---|
Line 44: | Line 44: | ||
**Example: | **Example: | ||
- | | ** PROGRAM** | | + | < |
- | | | | + | PROGRAM |
- | | ** INCLUDE('CWEXCPT.INT'),ONCE** | | + | INCLUDE(’CWEXCPT.INT’),ONCE |
- | | | | + | MAP |
- | | ** MAP** | | + | |
- | | ** Test (LONG,LONG)** | | + | |
- | | ** Hook (*ICWExceptionInfo), | + | |
- | | ** HEX (LONG), | + | |
- | | ** MODULE(" | + | MessageBox(UNSIGNED, |
- | | ** MessageBox (UNSIGNED, CONST *CSTRING, CONST *CSTRING, UNSIGNED)|**** , | + | |
- | | ** END** | | + | |
- | | ** END** | | + | END |
- | | | | + | MB_ICONHAND EQUATE(00000010h) |
- | | **MB_ICONHAND EQUATE(00000010h)** | | + | CODE |
- | | | | + | SYSTEM{PROP: |
- | | **CODE** | | + | Test (10, 0) !intentionally causes an exception |
- | | **SYSTEM{PROP: | + | RETURN |
- | | **Test (10, 0) !intentionally causes an exception** | | + | </ |
- | | **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: | ||
- | | | | + | < |
- | | **Hook PROCEDURE(*ICWExceptionInfo info)** | | + | Hook PROCEDURE(*ICWExceptionInfo info) |
- | | | | + | S CSTRING(1024) |
- | | **S CSTRING(1024)** | | + | Caption |
- | | **Caption | + | |
- | | | | + | IF info &= NULL |
- | | ** CODE** | | + | RETURN 0 |
- | | ** IF info &= NULL** | | + | END |
- | | ** RETURN 0** | | + | |
- | | ** END** | | + | |
- | | | | + | S =' |
- | | ** Caption = ' | + | '< |
- | | ** S = ' | + | ' EBX= ' & HEX (info.Register (i386_Register: |
- | | ** '<;13, | + | ' ECX= ' & HEX (info.Register (i386_Register: |
- | | ** ' EBX=** **' & HEX (info.Register (i386_Register: | + | ' EDX= ' & HEX (info.Register (i386_Register: |
- | | ** ' ECX=** **' & HEX (info.Register (i386_Register: | + | '< |
- | | ** ' EDX=** **' & HEX (info.Register (i386_Register: | + | ' EDI= ' & HEX (info.Register (i386_Register: |
- | | ** '<;13, | + | ' ESP= ' & HEX (info.Register (i386_Register: |
- | | ** ' EDI=** **' & HEX (info.Register (i386_Register: | + | ' EBP= ' & HEX (info.Register (i386_Register: |
- | | ** ' ESP=** **' & HEX (info.Register (i386_Register: | + | '< |
- | | ** ' EBP=** **' & HEX (info.Register (i386_Register: | + | |
- | | ** '<;13, | + | |
- | | | | + | |
- | | ** 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, | + | |
- | | **S STRING(8), | + | |
- | | **DIGITS STRING(' | + | |
- | | | | + | |
- | | ** 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, |
+ | RETURN 1 !a positive value signals | ||
+ | |||
+ | ! ***************************** | ||
+ | Test PROCEDURE (LONG a, LONG b) | ||
+ | CODE | ||
+ | a %= b | ||
- | **SYSTEM{PROP: | + | ! ***************************** |
+ | HEX PROCEDURE (LONG A) | ||
+ | i | ||
+ | S | ||
+ | DIGITS | ||
+ | | ||
+ | i = SIZE(S) | ||
+ | LOOP WHILE i <> 0 | ||
+ | S [i] = DIGITS [BAND (A, 0Fh) + 1] | ||
+ | A = BSHIFT (A, -4) | ||
+ | i -= 1 | ||
+ | END | ||
+ | RETURN S | ||
+ | </ | ||
- | **Test (10, 0) ! causes | + | These first two lines of code assign our exception handler function and then call the Test procedure that raises |
- | The exception | + | < |
+ | SYSTEM{PROP: | ||
+ | Test (10, 0) ! causes an exception | ||
+ | </ | ||
- | 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** | | + | < |
- | | | | + | PROGRAM |
- | | ** INCLUDE(' | + | |
- | | | | + | MAP |
- | | ** MAP** | | + | |
- | | ** MyHandler(*ICWExceptionInfo), | + | |
- | | ** BadCode()** | | + | |
- | | ** MODULE('' | + | |
- | | ** SLEEP(LONG), | + | |
- | | ** END** | | + | END |
- | | ** END** | | + | badPtr |
- | | | | + | temp LONG |
- | | **badPtr | + | oldHandler |
- | | **temp LONG** | | + | continue |
- | | **oldHandler | + | CODE |
- | | **continue | + | |
- | | | | + | |
- | | ** CODE** | | + | |
- | | ** RESUME(START(BadCode))** | | + | |
- | | ** LOOP WHILE NOT continue** | | + | |
- | | ** SLEEP(100)** | | + | |
- | | ** END** | | + | RETURN |
- | | ** badPtr &= NULL** | | + | |
- | | ** badPtr = 0** | | + | BadCode |
- | | | | + | |
- | | **BadCode | + | |
- | | ** CODE** | | + | |
- | | ** oldHandler = SYSTEM{PROP: | + | |
- | | ** SYSTEM{PROP: | + | RETURN |
- | | ** badPtr = 0** | | + | |
- | | ** ** | | + | MyHandler |
- | | | | + | |
- | | **MyHandler | + | |
- | | ** CODE** | | + | |
- | | ** SYSTEM{PROP: | + | |
- | | ** MESSAGE(' | + | |
- | | ** continue = TRUE** | | + | </ |
- | | ** RETURN 1** | | + | |
prop_lastchancehook.htm.txt · Last modified: 2022/04/14 03:50 by carlbarnes