Autor Beitrag
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 23.03.05 01:46 
Da ich selber daran mit Unterstützung durch uall@ogc gearbeitet hab, eh das so funktionierte, wie es sollte, hab ich mir überlegt den gefundenen Source für Exception-Handling mit reinem ASM mal zu veröffentlichen:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
// debugger detection: 
Function IsSoftIce1: Boolean; 
Asm 
//Try (Init)
    PUSH    EBP                   // save EBP on stack 
    XOR     EDX, EDX              // EDX := 0 
    PUSH    OFFSET @@MyHandler    // push address of our exception handler 
    PUSH    DWORD PTR FS:[EDX]    // push the adress of next exception handler 
    MOV     FS:[EDX], ESP         // change top excpetion handler to excpetion handler record 
                                  // 
                                  // record 
                                  //    nextexceptionhandler, currentexceptionhandler: pointer; 
                                  // end; 
                                  // ESP = address of record 
                                  // nextexceptiohandler = FS:[0] 
                                  // currenexcpetionhandler = @@myHandler 
 
    MOV     [EBP-$00000004], ESP  // save ESP 
 
//Try (Code)

    // here can be every function which can result into an excpetion

    //  The query for the INT 3h
    MOV     EBP, 'BCHK'           // 'BCHK' -> 4243484Bh 
    MOV     EAX, $00000004        // Function 4h 
    INT     $03                   // call int 3 (Makes Delphi stop at this location, simply continue) 
    CMP     AL, $03               // compare AL with 3 
    SETNZ   AL                    // if <> SoftIce is loaded 

//Except (Init)

    // Skip the Except Handler if no Exception occured. 
    JMP     @@BehindMyHandler     // if the function havent caused an excpetion 
                                  // jump to end 
@@MyHandler: 
    MOV     ESP, [EBP-$4]         // fix the stack 

//Except (Code)

    // here stands all the code you need to handle the exception 
    XOR     EAX, EAX              // result := false 

//End (Init)
 
@@BehindMyHandler: 
    XOR     EDX, EDX              // EDX := 0 
    POP     DWORD PTR FS:[EDX]    // uninstall our excpetion handler 
                                  // by overwriting with nextexception handler 
    POP     EDX                   // get our handler address from stack 
    POP     EBP                   // get ebp from stack 

//End (End)

End;


Für Try-Finally muss man nur eine Zeile ändern (gibt immer False zurück):

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
// debugger detection: 
Function IsSoftIce1: Boolean; 
Asm 
//Try (Init)

    PUSH    EBP                   // save EBP on stack 
    XOR     EDX, EDX              // EDX := 0 
    PUSH    OFFSET @@MyHandler    // push address of our exception handler 
    PUSH    DWORD PTR FS:[EDX]    // push the adress of next exception handler 
    MOV     FS:[EDX], ESP         // change top excpetion handler to excpetion handler record 
                                  // 
                                  // record 
                                  //    nextexceptionhandler, currentexceptionhandler: pointer; 
                                  // end; 
                                  // ESP = address of record 
                                  // nextexceptiohandler = FS:[0] 
                                  // currenexcpetionhandler = @@myHandler 
 
    MOV     [EBP-$00000004], ESP  // save ESP 
 
//Try (Code)

    // here can be every function which can result into an excpetion

    //  The query for the INT 3h
    MOV     EBP, 'BCHK'           // 'BCHK' -> 4243484Bh 
    MOV     EAX, $00000004        // Function 4h 
    INT     $03                   // call int 3 (Makes Delphi stop at this location, simply continue) 
    CMP     AL, $03               // compare AL with 3 
    SETNZ   AL                    // if <> SoftIce is loaded 

//Finally (Init)

    // Skip the Except Handler if no Exception occured. 
    JMP     @@BehindMyHandler     // if the function havent caused an excpetion 
                                  // jump to end 
@@MyHandler: 
    MOV     ESP, [EBP-$4]         // fix the stack 

@@BehindMyHandler: 
//Finally (Code)
    // here stands all the code you want to execute always
    XOR     EAX, EAX              // result := false 

//end (Init)

    XOR     EDX, EDX              // EDX := 0 
    POP     DWORD PTR FS:[EDX]    // uninstall our excpetion handler 
                                  // by overwriting with nextexception handler 
    POP     EDX                   // get our handler address from stack 
    POP     EBP                   // get ebp from stack 
//End (End)
End;


That's it!


Moderiert von user profile iconraziel: Topic aus Algorithmen, Optimierung und Assembler verschoben am Do 24.03.2005 um 09:52
Moderiert von user profile iconTino: Topic aus Neue Einträge / Hinweise / etc. verschoben am Do 26.05.2005 um 09:44

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.