nick@lfcs.ed.ac.uk (Nick Rothwell) (01/02/89)
In article <900@husc6.harvard.edu> siegel@endor.UUCP (Rich Siegel) writes: > In fact, you can. LDEFs are quite easy to debug. Other defprocs >that are event-driven, such as CDEFs and MDEFs, can also be debugged >at the source level. Unfortunately, you can't debug WDEFs at the source level, >because of some tricks that the debugger pulls; however, you can embed >them in your program the same as any other defproc. Say, Rich, would you care to quickly explain your little trick again? You said something about creating a 6-byte resource containing "$4EF9 0000 0000". I presume that the $4EF9 is a "call-immediate" or something.... So: (i) Can I do this for any code resource? (ii) What about the resource? Does it have to use A4 rather than A5, if it's actually a bit of the same project? Any restrictions on access to globals, or anything like that? (iii) What code do you use to perform the patch? Is it in-store, or does it make a change to the resource file (which is not really what's required)? > --Rich Nick. -- Nick Rothwell, Laboratory for Foundations of Computer Science, Edinburgh. nick@lfcs.ed.ac.uk <Atlantic Ocean>!mcvax!ukc!lfcs!nick ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ...while the builders of the cages sleep with bullets, bars and stone, they do not see your road to freedom that you build with flesh and bone.
siegel@endor.harvard.edu (Rich Siegel) (01/03/89)
In article <1198@etive.ed.ac.uk> nick@lfcs.ed.ac.uk (Nick Rothwell) writes: > (i) Can I do this for any code resource? The trick allows you to incorporate the code for any code resource as part of the program's source code, not as a separate resource. > (ii) What about the resource? Does it have to use A4 rather than A5, > if it's actually a bit of the same project? Any restrictions on > access to globals, or anything like that? Embedded code resources are actually more flexible than externally built code resources, since they can use external globals and data; the application context is much better defined. > (iii) What code do you use to perform the patch? Is it in-store, The code loads a dummy resource and fills it with the correct infomation. Suppose you have a procedyre MyDefProc(), which is the code for an LDEF, embedded in your program. If you wanted to install MyDefProc as LDEF 128, it would go like this: typedef struct { int jmpInstr; Ptr jmpAddr; } JmpRec, *JmpPtr, **JmpHandle; extern pascal void MyDefProc(); void InstallLDEF() { JmpHandle jH; jH = Get1Resource('LDEF', 128); (**jH).jmpInstr = 0x4EF9; (**jH).jmpAddr = &MyDefProc; HNoPurge(jH); } This loads the dummy defproc, patches it to your routine, and makes it nonpurgeable. You should be sure that the routine is in a segment that is loaded and will stay loaded. --Rich Rich Siegel Staff Software Developer THINK Technologies Division, Symantec Corp. Internet: siegel@endor.harvard.edu UUCP: ..harvard!endor!siegel Phone: (617) 275-4800 x305 Any opinions stated in this article do not necessarily reflect the views or policies of Symantec Corporation or its employees.