Solved

Brequest in DPMI

Posted on 1997-04-28
10
258 Views
Last Modified: 2012-06-21
Using BP70 to create a DOS-Program.
How to use the btrcall-Interface from brequest
in DPMI-Mode? Or, in other words: how to call
real-Mode Interrupts which need pointers to realmode-memory
as parameters in DPMI-Mode.
Any Idea?
0
Comment
Question by:nmm
  • 5
  • 3
  • 2
10 Comments
 

Expert Comment

by:kilobug
Comment Utility
Does a value must be passed to a segment register (DS/ES)???
0
 

Author Comment

by:nmm
Comment Utility
Yes, there is a data-structure like

bparam=record
  buff: ^byte; {a realmode pointer to the databuffer!}
  len  : word; {the length of the databuffer}
  info: ^word;
 {etc...}
end;

a variable of this type:

var params:bparam;

and you have to put the segment of @params (the pointer to params) to DS , its offset to DX and call INT $7b

For windows there is a DLL: btrcall.dll, exporting a
function (no INT call necessary explicit).

If it is impossible to perform the interupt corrctly, may be one can use the DLL in the DPMI-DOS-Program in some manner??

Any ideas?

Mircea


 
0
 

Expert Comment

by:kilobug
Comment Utility
I have the same problem: you can set the segment value "normally" because this will make a GPF (Error 216)...

Maybe in the SWAGS (http://www.gdsoft.com/swag/swag.html)
0
 

Author Comment

by:nmm
Comment Utility
Hey, this was a nice comment! Yes there is something about our
problem!

0
 

Accepted Solution

by:
aajw earned 80 total points
Comment Utility
Firstly, allocate a buffer in conventional memory to put the params, using the GlobalDOSAlloc function.var paramptr:pointer;  rmseg:word;  sel:word;  res:longint;...  res := GlobalDOSAlloc(sizeof(bparam)); {allocate memory}  if res=0 then  begin    writeln('Error allocating mem');    halt(0);  end;  sel := LoWord(res);  rmseg := hiword(res);  paramptr := ptr(sel,0); {assign pointer to memory}Having allocated the memory, the data must be copied across.  move(params,paramptr^,sizeof(bparam));(alternatively, store the data directly in the allocated mem)Then the real mode int can be called, using the DPMI function 0300h.type DPMIRegs = record  EDI,ESI,EBP:longint;  Res1:longint;  EBX,EDX,ECX,EAX:longint;  Flags:word;  ES,DS,FS,GS:word;  IP,CS:word;  SP,SS:word;end;var regs:Registers;  DRegs:DPMIRegs;...  Regs.ax := $300; {function number}  Regs.bx := $7b;  {interrupt to call}  Regs.cx := 0; {no params on stack}  Regs.es := seg(DRegs); {point to DPMI reg struc}  Regs.di := ofs(DRegs);  DRegs.ss := 0; {no stack}  DRegs.sp := 0;  DRegs.es := rmseg; {segment of pointer}  DRegs.edi := 0;    {offset=0}  {set up other parts of DRegs here}  Intr($31,Regs); {Do the interrupt}  Then copy the data back to the variable (optional)  move(paramptr^,params,sizeof(bparam));
And free the block  sel := GlobalDosFree(sel);  if sel<>0 then  begin    writeln('Error freeing block');    halt(0);  end;Hope this does the trick
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:nmm
Comment Utility
Sorry I was absent for a while, but now I will check
your answer, aajw!
Cheers nmm
0
 

Author Comment

by:nmm
Comment Utility
Hi aajw!
Sorry but it simply crashes, what is wrong?

Here is the code I used (with your extensions, DPMI is
defined)

UNIT BTRCALL;

Interface
uses dos{$ifdef dpmi},winapi{$endif};

const
      b_open    : word =    0;
      b_close   : word =    1;
      b_Insert  : word =    2;
      b_update  : word =    3;
      b_delete  : word =    4;
      b_geteq   : word =    5;
      b_getnx   : word =    6;
      b_getpr   : word =    7;
      b_getgr   : word =    8;
      b_getge   : word =    9;
      b_getlt   : word =   10;
      b_getle   : word =   11;
      b_getfi   : word =   12;
      b_getla   : word =   13;
      b_create  : word =   14;
      b_stat    : word =   15;
      b_extend  : word =   16;
      b_setdir  : word =   17;
      b_getdir  : word =   18;
      b_begtran : word =   19;
      b_endtran : word =   20;
      b_abotran : word =   21;
      b_getpos  : word =   22;
      b_setpos  : word =   23;
      b_snext   : word =   24;
      b_stop    : word =   25;
      b_version : word =   26;
      b_unlock  : word =   27;
      b_reset   : word =   28;
      b_setown  : word =   29;
      b_clrown  : word =   30;
      b_creinx  : word =   31;
      b_droinx  : word =   32;
      b_sfirst  : word =   33;
      b_slast   : word =   34;
      b_sprev   : word =   35;
      s_lockw   : word =  100;
      s_locknw  : word =  200;
      m_lockw   : word =  300;
      m_locknw  : word =  400;
      e_gnext   : word =   36;
      e_gprev   : word =   37;
      e_snext   : word =   38;
      e_sprev   : word =   39;
      e_insert  : word =   40;

      b_getkey_offset : word = 50;

{------- nur fr Btrieve 6.1. belangvoll -------}
      g_percent : word =   44;
      f_percent : word =   45;

type bparameter = record
     btr_data   : ^byte;  {eigentlich der Datenpuffer}
     btr_dlen   :  word;  {Datenpufferl„nge}
     btr_info   : ^word;  {eigentlich Infoblock}
     btr_fcb    : ^byte;  {eigentlich FCB}
     op_code    :  word;  {Operationscode}
     btr_key    : ^byte;
     {eigentlich Key}
     btr_klen   :  byte;
     btr_knr    :  shortint;
     status     : ^word;  {Rckgabewert}
     iface_id   :  word;  {const}
    end;
{$ifdef DPMI}
 type DPMIRegs = record
            EDI,ESI,EBP:longint;
            Res1:longint;
            EBX,EDX,ECX,EAX:longint;
            Flags:word; ES,DS,FS,GS:word;
            IP,CS:word;
            SP,SS:word;
         end;
{$endif}

 function BTRV(op,dlen : word;var pos_block,dat_block,key_block;
               klen,knr:integer) : word;


 var btr_status : word;

 function BTRVaktiv:Boolean;

Implementation

 var btrpar   : bparameter;
{$ifdef DPMI}
     paramptr : pointer;
     rmseg    : word;
     sel      : word;
     res      : longint;

{$endif}

 function BTRVaktiv:Boolean;
 type a=record
         l,h:word;
        end;
 var   bptr : pointer;
       b :a absolute bptr;
 begin
{  getIntVec($7b,bptr);
  BTRVaktiv:=word(bptr)=$33;}
 end;

{$ifndef DPMI}
  procedure aufruf;
  var   regs : registers;
  begin
   with btrpar do
   begin
    if  not BTRVaktiv then
    begin
     status^:=20;
     exit;
    end;
    with regs do
    begin
     bx:=0;
     es:=0;
     dx:= ofs(btrpar);
     ds:= seg(btrpar);
    end;
    intr($7b,regs);
   end;
  end;
{$else}
procedure aufruf;
var regs : Registers;
   DRegs : DPMIRegs;
begin
 move(btrpar,paramptr^,sizeof(btrpar));
 {alternatively, store the data directly in the allocated mem}
{ Then the real mode int can be called, using the DPMI function 0300h.}
 Regs.ax   := $300;       {function number}
 Regs.bx   := $7b;        {interrupt to call}
 Regs.cx   := 0;          {no params on stack}
 Regs.es   := seg(DRegs); {point to DPMI reg struc}
 Regs.di   := ofs(DRegs);
 DRegs.ss  := 0; {no stack}
 DRegs.sp  := 0;
 DRegs.es  := rmseg; {segment of pointer}
 DRegs.edi := 0; {offset=0} {set up other parts of DRegs here}
 Intr($31,Regs); {Do the interrupt}
  { Then copy the  data back to the variable (optional)}
 move(paramptr^,btrpar,sizeof(btrpar));
end;
{$endif}

  procedure Init_Parameter;
  begin
   with btrpar do
   begin
    btr_status:=0;
    iface_id   := $6176;
    status := @btr_status;
   end;
  end;

  function BTRV(op,dlen : word;var pos_block,dat_block,key_block;
                klen,knr:integer) : word;
  var s : word;
      b : array[1..125] of byte absolute pos_block;
  begin
   Init_Parameter;
   with btrpar do
   begin
    op_code :=op;
    btr_dlen:=dlen;
    btr_key :=@key_block;
    btr_data:=@dat_block;
    btr_info:=@pos_block;
    btr_fcb :=@b[91];
    btr_knr :=knr;
    btr_klen:=klen;
    aufruf;
    btrv:=status^;
   end;
  end;

{$ifdef DPMI}
var     ExitSave : Pointer;

procedure BtrCallExit;far;
begin
 ExitProc:=ExitSave;
 { And free the block}
 sel := GlobalDosFree(sel);
 if sel<>0 then
 begin
  writeln('Error freeing block'); halt(0);
 end;
end;

begin
 ExitSave:=ExitProc;
 ExitProc:=@BtrCallExit;
 res := GlobalDOSAlloc(sizeof(btrpar)); {allocate memory}
 if res=0 then
 begin
  writeln('Error allocating mem');
  halt(0);
 end;
 sel      := LoWord(res);

 rmseg    := hiword(res);
 paramptr := ptr(sel,0); {assign pointer to memory}
 {Hope this does the trick}
{$endif}
end.

0
 

Expert Comment

by:aajw
Comment Utility
The memory allocation/deallocation routines work OK on my system.However, the set up of DRegs in your example is not how you described above. I'm sorry if I didn't make it clear, but DRegs should contain the registers as they are needed to call the interrupt. Unfortunately, the registers must be stored as the 32bit EAX,EBX etc, but assigning a word calue to them will just reference the low 16 bits, the normal regs AX,BX etc. and clear the (unused) high 16 bits.
0
 

Author Comment

by:nmm
Comment Utility
Hi aajw!
Is does not work, sorry.
The problem semms to be, that in the strucure btrpar
are elements, which are pointers again to some
DOS-Memory.
If I allocate this mem also via globaldosalloc, I dont know how to get real-mode Pointer to it.
I tried to use wbtrcall.dll, the requestor for windows 3.11, but
it will not run (RTM.exe says: invalid entrypoint called)
Mircea
0
 

Expert Comment

by:aajw
Comment Utility
You can allocate a RM pointer using the rmseg value returned in the call to GlobalDOSAlloc -var  rmptr:pointer;begin...{allocate mem here}  rmptr := ptr(rmseg,0);{Only use rmptr in real mode, or in structures which will be used in real mode}
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now