🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.asm.x86
Article #133

Re: Int3 Code Problems with my Debuger :-(

#133
From: Robert AH Prins
Date: Sat, 09 Jan 1999 00:00
154 lines
5393 bytes
In article <7785em$fie$1@winter.news.rcn.net>,
  lukejedikt@aol.comKnight (LukeJediKt) wrote:
> Hi all,
>
>   I am writing an Assembler (It has a nice interface and debugging fetures).
> It is written in Turbo Pascal but is quite a lot of Assembler + Is an
assembler
> :).  I have got the Machine Code Generating code Fine, the Executing Assembled
> files from my program works perfectly,  It looks GREAT ... Has a nice Help
menu
> ...... BUT I am trying to let the programmer insert Breakpoints .. and Keep
> just crashing my computer :( .
>
>   To simplify things I have written a small program to do the above.  It
should
> do the following :
>
> 1) Change some code in my NewInt3 procedure so AX:BX => the stored byte which
> will be replaced by the CCh (Int3)
>
> 2)   Insert the CCh Break Point byte into the code where I want a Bp.
>
> 3) Save the Old Int3 Address
>
> 4) Set my New Int3
>
> 5) Run the Procedur with the inserted CCh byte .. which should call Int3 which
> should do the following :
>
> 1) PushA , Push Ds
>
> 2) Dec Return address (So returned to same place called from) & Replace the
CCh
> byte with the original code befor the Bp was inserted.
>
> 3) Read a key (This was just to let me know it did get this far <G> )
>
> 4) Pop Ds, PopA
>
> 5) PushF then Call Far The old Int3 procedure
>
> 6) IRet
>
> Here is my code ....
>
> Uses DOS,CRT;
> {$g+}   {Enable 286 Instructions}
>
> Var
>   LookupTable : byte;
>   TestSeg,TestOfs,LookupTableSeg,LookupTableOfs:Word;
>   OldInt3:Procedure;
>
> {$F+}  {Force Far Calles}
>
> Procedure NewInt3;Interrupt;Assembler;
> ASM
>   {Note Return Ofs @ SS:SP, Return Seg @ SS:SP+2}
>   Pusha{Dec SP by 16}
> {Number 1234h stored @ Ofs +2}
> Mov AX, 1234h  {Dummy value to be replaced at runtime with the Main Programs
> Seg of LookupTable}
> {Number 2345h stored @ Ofs +5}
> Mov BX, 2345h  {Dummy value to be replaced at runtime with the Main Programs
> Ofs of LookupTable}
>
>    Push Ds{Dec SP by 2, Total= 12h}
>     Mov Bp, Sp
>
>     Mov Ds, Ax
>     Mov Al, [Bx] {Get saved byte to replace the CCh with}
>
>       Mov Bx, [Bp+$12]{Get the return Ofset from the Stack}
>       Dec Bx {Change it .. to the start of the CCh (which is about to be
> replaced)}
>       Mov Ds, [Bp+$14]{Get Return CS}
>         Mov [Bx], Al {Replace CCh byte with normal code}
>       {Put the changed return Ofset back to the stack}
>       Mov [Bp+$12],Bx
>
>     {ReadKey + Echo   .. For debug perposes .. see if it has got this far <G>}
>     Mov Ah, 01
>     Int 21h
>
>    Pop  Ds
>   Popa
>   PushF {Because of the Iret in OldInt3}
>   Call Old Int3
>   IRet
> End;
>
> Procedure Demo;Assembler;
> Asm
>  {Breakpoit to be placed here}
>   Mov ax, $1234
>   Mov bx, $1234
> End;
>
> Procedure DemoInsertBreakPoint;
> Begin
>   LookupTable[1]:=Mem[Seg(Demo):Ofs(Demo)];
>   Mem[Seg(Demo):Ofs(Demo)]:=$CC;
> End;
>
> Begin
>   {Get Mem Addresses}
>   TestSeg:=Seg(NewInt3{CopyInt3});
>   TestOfs:=Ofs(NewInt3{CopyInt3});
>   LookupTableSeg:=Seg(LookupTable);
>   LookupTableOfs:=Ofs(LookupTable);
>   {Insert Mem Addresses into Interupt code}
>   ASM
>     Push DS
>     Mov Ax, [LookupTableSeg]
>     Mov Cx, [LookupTableOfs]
>     Mov Bx, [TestOfs]
>     Mov Ds, [TestSeg]
>     Mov Word PTR [Bx+2], Ax
>     Mov Word PTR [Bx+5], Cx
>     Pop  DS
>   End;
>
>   DemoInsertBreakPoint;
>
>   GetIntVec($3,@OldInt3);     {Save OldInt3 Address}
>   SetIntVec($3,Addr(NewInt3));{Set my NewInt3}
>
>   Writeln('About to run Demo .. Press Any Key');
>   ReadKey;
>
>   Demo;
>
>   Writeln('Finished Runnin Demo OK .. Press Any Key');
>   ReadKey;
>
>   SetIntVec($3,Addr(OldInt3));{Reset to the OldInt3 }
> End.
>

One, I have great admiration for what you're doing, but it would be nice if
the above program would actually compile.

Two, given that you are using Turbo Pascal, it would have been useful to
cross-post this posting to comp.lang.pascal.borland and
borland.public.turbopascal. I have taken the liberty of doing so with this
reply.

Robert
--
Robert AH Prins
prinsra@williscorroon.com

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    
Technical Details
Message-ID: <778fbj$ml0$1@winter.news.rcn.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7785em$fie$1@winter.news.rcn.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111659,14e5d46a6cbdcf16,start
X-Google-Attributes: gid111659,public
X-Google-Thread: 108ebd,14e5d46a6cbdcf16,start
X-Google-Attributes: gid108ebd,public
X-Google-Thread: 114917,e84c646ebe0ca6a1
X-Google-Attributes: gid114917,public
From: Robert AH Prins <prinsra@williscorroon.com>
Subject: Re: Int3 Code Problems with my Debuger :-(
Date: 1999/01/09
Message-ID: <778fbj$ml0$1@winter.news.rcn.net>
X-Deja-AN: 430655696
Approved: <johnfine@erols.com>
References: <7785em$fie$1@winter.news.rcn.net>
X-Http-User-Agent: Mozilla/3.0 (Win16; I)
X-Mozilla-Status: 0801
X-Complaints-To: abuse@rcn.com
X-Trace: 6J5sZvngR0Njl5s9b04VwjB7EvShr1IKgVGPBNBNiNM=
X-Http-Proxy: 1.0 x9.dejanews.com:80 (Squid/1.1.22) for client 193.130.234.1
Organization: Deja News - The Leader in Internet Discussion
X-Article-Creation-Date: Sat Jan 09 20:45:45 1999 GMT
NNTP-Posting-Date: 9 Jan 1999 20:48:51 GMT
Newsgroups: comp.lang.asm.x86,comp.lang.pascal.borland,borland.public.turbopascal