home *** CD-ROM | disk | FTP | other *** search
/ TopWare Tools / TOOLS.iso / tools / top1318 / gepackt.exe / UTILITY / SOURCE / REMADI.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-12-30  |  14.0 KB  |  413 lines

  1. {$R-}    {Bereichsprüfung aus}
  2. {$B+}    {vollständige Auswertung boolscher Ausdrücke}
  3. {$S+}    {Stackprüfung an}
  4. {$I+}    {I/O-Prüfung an}
  5. {$N-}    {kein numerischer Coprozessor}
  6. {$M 10000,0,655360} {3.0-Standardvorgaben für Stack&Heap}
  7.  
  8. { $u-}
  9.  
  10. uses
  11.   umcb,autocopy,Dos;
  12.  
  13. type
  14.   strtyp = array [1..10000] of char;
  15.   string2 =string[2];
  16.   string4 = string[4];
  17. {***********************************************************}
  18. {*                                                         *}
  19. {*         UMWANDLUNG EINES BYTES IN EINE HEX-ZAHL         *}
  20. {*                                                         *}
  21. {***********************************************************}
  22.  
  23.   FUNCTION HEX1(B:BYTE):STRING2;
  24.     CONST
  25.       ASCII = '0123456789ABCDEF';
  26.     VAR
  27.       B1,B2 : BYTE;
  28.     BEGIN
  29.       B2:=B AND $0F;
  30.       B1:=(B AND $F0) DIV 16;
  31.       HEX1:=COPY(ASCII,B1+1,1)+COPY(ASCII,B2+1,1);
  32.     END;
  33.  
  34. {***********************************************************}
  35. {*                                                         *}
  36. {*  UMWANDLUNG EINER INTEGER-ZAHL IN EINE HEX-ZAHL         *}
  37. {*                                                         *}
  38. {***********************************************************}
  39.  
  40.   FUNCTION HEXINT(I:INTEGER):STRING4;
  41.     BEGIN
  42. {      if i=0 then hexint:='    ' else}
  43.       HEXINT:=HEX1(HI(I))+HEX1(LO(I));
  44.     END;
  45.  
  46.  
  47. function int(i : integer) : real;
  48.  
  49.   begin
  50.     if i<0 then int:= 65536.0-i else int:=i;
  51.   end;
  52.  
  53. type
  54.   dword  = array [0..1] of word;
  55.   mcbzeigertyp = ^mcbtyp;
  56.   mcbtyp = record
  57.              id : char;
  58.              psp,len : word;
  59.            end;
  60.   pspzeigertyp = ^psptyp;
  61.   psptyp = record
  62.              int20   : word;
  63.              freemem : word;
  64.              dos     : byte;
  65.              bioscall : array [0..4] of byte;
  66.              int22,int23,
  67.              int24   : dword;
  68.              pid     : word;
  69.              filestruc : array [$18..$2b] of byte;
  70.              envseg  : word;
  71.              stack   : dword;
  72.              files   : word;
  73.              fileptr : dword;
  74.              dos1    : array [$38..$4f] of byte;
  75.              doscall : dword;
  76.              dos2    : array [$53..$5b] of byte;
  77.            end;
  78.   envstrtyp = array [1..$7fff] of char;
  79.   batstrtyp = record
  80.                 b  : array [0..4] of byte;
  81.                 ff : array [1..20] of byte;
  82.                 name : array [1..128] of char;
  83.               end;
  84.  
  85.   procedure get_first_mcb(var mcb : mcbzeigertyp);
  86.  
  87. (*    type
  88.       cpuregtyp                        = registers;
  89.       dos1typ                          = record
  90.                                            dos             : array [1..3] of byte;
  91.                                            nul             : word;
  92.                                            dummy           : array [1..10] of byte;
  93.                                          end;
  94.       dos2typ                          = record
  95.                                            dos             : array [1..4] of byte;
  96.                                            nul             : word;
  97.                                            dummy           : array [1..10] of byte;
  98.                                          end;
  99.       deviceztyp                       = ^devicetyp;
  100.       devicezeigertyp                  = record
  101.                                            case boolean of
  102.                                              false  : (zeiger          : deviceztyp);
  103.                                              true   : (offset,segment  : word);
  104.                                          end;
  105.  
  106.       devicetyp                        = record
  107.                                            next            : devicezeigertyp;
  108.                                            attr,strat,intr : word;
  109.                                            name            : array [1..8] of char;
  110.                                          end;
  111.  
  112.     var
  113.       cpureg                           : cpuregtyp;
  114.       mcb1                             : mcbzeigertyp;
  115.       psp                              : pspzeigertyp;
  116.       st                               : boolean;
  117.       mcbi                             : record
  118.                                            offset,segment  : word;
  119.                                          end absolute mcb;
  120.       fcb                              : record
  121.                                            disk            : byte;
  122.                                            name            : array [1..11] of char;
  123.                                            blkpos,blklen   : word;
  124.                                            filelen         : array [0..1] of word;
  125.                                            date,time       : word;
  126.                                            case boolean of
  127.                                              false         : (dos2 : dos1typ);
  128.                                              true          : (dos3 : dos2typ);
  129.                                          end;
  130.       device,nul                       : devicezeigertyp;
  131.  
  132.     begin
  133.       with cpureg do with fcb do begin
  134.         name:='NUL        ';
  135.         disk:=0;
  136.         dx:=ofs(fcb);
  137.         ds:=seg(fcb);
  138.         ah:=$f;
  139.         msdos(Dos.Registers(cpureg));
  140.         dx:=ofs(fcb);
  141.         ds:=seg(fcb);
  142.     ah:=$10;
  143.         msdos(Dos.Registers(cpureg));
  144.     st:=al<>0;
  145.         if not st then begin
  146.           ah:=$30;
  147.           msdos(Dos.Registers(cpureg));
  148.           case al of
  149.             2 : nul.zeiger:=ptr(dos2.nul,0);
  150.             3 : nul.zeiger:=ptr(dos3.nul,0);
  151.             else st:=true;
  152.           end;
  153.           if st then nul.zeiger:=ptr($40,0);
  154.           repeat
  155.             nul.offset:=succ(nul.offset);
  156.           until (nul.offset=0) or (nul.zeiger^.name='NUL     ');
  157.           st:=nul.offset=0;
  158.           if not st then begin
  159.             nul.segment:=nul.segment+nul.offset shr 4;
  160.             nul.offset:=nul.offset and $f;
  161.             device.zeiger:=nul.zeiger;
  162.             repeat
  163.               device.zeiger:=device.zeiger^.next.zeiger;
  164.             until (device.zeiger^.next.zeiger=ptr($ffff,$ffff)) or (device.zeiger^.next.segment<nul.segment);
  165.             st:=(device.segment<=nul.segment) or (device.zeiger^.next.zeiger=ptr($ffff,$ffff));
  166.             if not st then mcb:=ptr(pred(seg(device.zeiger^)),0);
  167.           end;
  168.         end;
  169.       end;
  170.       mcb1:=ptr(seg(mcb^)+succ(mcb^.len),0);
  171.       if (mcb^.id<>'M') or (mcb1^.id<>'M') or st then begin
  172.         mcb:=ptr($40,0);
  173.           while true do begin
  174.           mcb1:=ptr(seg(mcb^)+succ(mcb^.len),0);
  175.           if (mcb^.id='M') and (mcb1^.id='M') then begin
  176.         psp:=ptr(1+(seg(mcb^)),0);
  177.             if (psp^.int20=$20cd) and (seg(psp^)=psp^.pid) then exit;
  178.         psp:=ptr(1+(seg(mcb1^)),0);
  179.         if (psp^.int20=$20cd) and (seg(psp^)=psp^.pid) then exit;
  180.       end;
  181.       mcbi.segment:=succ(mcbi.segment);
  182.     end;
  183.       end;
  184.     end;*)
  185.     begin
  186.       mcb:=pointer(mcbadr);
  187.     end;
  188.  
  189. const
  190.   max = $1fff;
  191.   comstr : string[10] ='COMSPEC=';
  192.   gueltig : set of char = [' '..#255];
  193.  
  194. var
  195.   mcbs : array [1..max] of ^mcbtyp;
  196.   envstr : ^envstrtyp;
  197.   batstr : ^batstrtyp absolute envstr;
  198.   mcb,mcb1  : mcbzeigertyp;
  199.   psp  : psptyp;
  200.   ch : char;
  201.   s : string[127];
  202.   str : ^strtyp;
  203.   recs : registers;
  204.   st,envst,comst : boolean;
  205.   intr : pointer;
  206.   st1,st2,st3,st4 : boolean;
  207.   i,j,n,i1,i2 : word;
  208. {    intrtable                        : array [0..255] of record
  209.                                          case boolean of
  210.                                            false    : (zeiger : pointer);
  211.                                            true     : (lo,hi  : word);
  212.                                        end;                           }
  213. type
  214.   string128 = string[128];
  215.  
  216. function gross(s : string128) : string128;
  217.  
  218.   var
  219.     i                                  : byte;
  220.  
  221.   begin
  222.     for i:=1 to length(s) do s[i]:=upcase(s[i]);
  223.     gross:=s;
  224.   end;
  225.  
  226. procedure remove(w : word);
  227.  
  228.   begin
  229.     with recs do begin
  230.       ah:=$49;
  231.       es:=w;
  232.       msdos(recs);
  233.     end;
  234.   end;
  235.  
  236. begin
  237.   if paramstr(1)='?' then begin
  238.     writeln('Bei Aufruf ohne Parameter werden die ADI-Treiber DSGENOA und PPDRV entfernt.');
  239.     writeln('Bei Angabe der Adresse eines MCB als Hexzahl, wird dieser Speicherbereich');
  240.     writeln('freigegeben. (Die Adressen werden von dem Programm MEM ausgegben.)');
  241.     writeln('Von allen Programmen, die hinter der Option /e angegeben werden, wird das');
  242.     writeln('Environment freigegeben.');
  243.     writeln('Mit der Option /c kann der 1. Command.com aus dem Speicher entfernt werden,');
  244.     writeln('aber nur dann, wenn kein anderes Programm vor ihm in Speicher steht.');
  245.     halt;
  246.   end;
  247.   if (paramcount>0) and (copy(paramstr(1),1,1)<>'/') then begin
  248.     for i:=1 to paramcount do begin
  249.       s:=paramstr(i);
  250.       j:=0;
  251.       repeat
  252.         ch:=upcase(s[1]);
  253.         if s<>'' then case ch of
  254.           '0'..'9' : j:=(j shl 4) + ord(ch) - ord('0');
  255.           'A'..'F' : j:=(j shl 4) + ord(ch) - ord('A') + 10;
  256.           else halt;
  257.         end;
  258.         delete(s,1,1);
  259.       until s='';
  260.       st:=false;
  261.       mcb:=ptr(j,0);
  262.       with mcb^ do begin
  263.         if (id='Z') or (id='M') then begin
  264.           st1:=true;
  265.           if memw[psp:$2c]=succ(j) then memw[psp:$2c]:=0
  266.           else if psp=succ(j) then begin
  267.             for n:=0 to $40 do begin
  268.               getintvec(n,intr);
  269.               i1:=seg(intr^);
  270.               if (i1>=psp) and (i1<psp+len) then st1:=false;
  271.             end;
  272.             remove(memw[psp:$2c]);
  273.             if st1 then for n:=$41 to 255 do begin
  274.               getintvec(n,intr);
  275.               i1:=seg(intr^);
  276.               if (i1>=psp) and (i1<psp+len) then setintvec(n,ptr(0,0));
  277.             end;
  278.           end;
  279.           if st1 then remove(succ(j));
  280.         end;
  281.       end;
  282.     end;
  283.     halt;
  284.   end;
  285.   st2:=gross(paramstr(1))='/C';
  286.   st3:=false;
  287.   st4:=true;
  288.   j:=0;
  289.   i:=$0;
  290.   n:=0;
  291.   i1:=$00;
  292.   comst:=false;
  293.   get_first_mcb(mcb);
  294.   n:=0;
  295. {  writeln;
  296.   writeln('T  Treiber   P  Programm   D  Data    E  Environment');
  297.   writeln;}
  298.   repeat
  299.     n:=succ(n);
  300.     mcb1:=mcb;
  301.     with mcb^ do if (id='M') or (id='Z') then begin
  302. {      if n mod 20 =1 then writeln('mcb   id  len   psp   env   next  lpsp  int20 ');
  303.       write(hexint(seg(mcb^)),id:4,hexint(len):6,hexint(psp):6);
  304.       if psp and $ff80=0 then write('':6) else write(hexint(memw[psp:$2c]):6);
  305.       write(hexint(seg(mcb^)+succ(len)):6);
  306.       if psp and $ff80=0 then write('':14)
  307.       else write(hexint(memw[psp:16]):6,'  ',hexint(memw[psp:0]),'  ');}
  308.       j:=memw[psp:$2c];
  309.       st:=false;
  310.       s:='';
  311.       envstr:=ptr(1+(seg(mcb^)),0);
  312.       with batstr^ do begin
  313.         i1:=3;
  314.         while (i1<21) and not st do begin
  315.           st:=ff[i1]<>$ff;
  316.           i1:=succ(i1);
  317.         end;
  318.         i1:=1;
  319.         while not st and (i1<128) and (name[i1] in gueltig) do begin
  320.           s:=s+name[i1];
  321.           i1:=succ(i1);
  322.         end;
  323.         if name[i1]<>#0 then s:='';
  324.       end;
  325.       if st and (memw[pred(memw[psp:$2c]):1]=psp) then begin
  326.         i1:=0;
  327.         while (i1<2000) and (memw[j:i1]<>0) do i1:=succ(i1);
  328.         while (i1<2000) and (memw[j:i1]<>1) do i1:=succ(i1);
  329.         i1:=i1+2;
  330.         if i1<2000 then begin
  331.           i2:=0;
  332.           while (i2<80) and (chr(mem[j:i1+i2]) in gueltig) do begin
  333.             s:=s+chr(mem[j:i1+i2]);
  334.             i2:=succ(i2);
  335.           end;
  336.           if mem[j:i1+i2]<>0 then s:='';
  337.         end;
  338.       end;
  339.       if psp<$60 then s:='dos';
  340.       if (psp=memw[psp:$16]) then s:='COMMAND.COM';
  341.       st:=false;
  342.       i1:=1;
  343.       i2:=1;
  344.       j:=1;
  345.       envst:=memw[psp:$2c]=seg(envstr^);
  346.       if psp<>8 then while (not st or (envstr^[i1]<>#0)) and (i1<=int(len)*16) and (i1>=0) and not envst do begin
  347.         st:=envstr^[i1]=#0;
  348.         if envstr^[i1]=comstr[i2] then begin
  349.           i2:=succ(i2);
  350.           envst:=i2>length(comstr);
  351.         end
  352.         else begin
  353.           i2:=1;
  354.           j:=succ(j);
  355.           i1:=j;
  356.         end;
  357.         i1:=succ(i1);
  358.       end;
  359.       if psp=0 then begin
  360. {        write(' ');}
  361.         s:='frei';
  362.       end
  363.       else if envst then {write('E')}
  364.       else if psp=8 then {write('T')}
  365.       else if psp=1+(seg(mcb^)) then {write('P')} begin
  366.         st1:=false;
  367.         if (pos('COMMAND.COM',s)>0) and st4 then st3:=true
  368.         else st4:=false;
  369.         if not st2 then for j:=2 to paramcount do if pos(gross(paramstr(j)),s)>0 then st1:=true;
  370.         if (pos('DSGENOA.EXE',S)+pos('PPDRV.EXE',s)+pos('DSADI.EXE',s)
  371.         +pos('TPACK.COM',s)+pos('CEGADI8.EXE',s)+pos('CEGADI6.EXE',s)>0) or st1 then begin
  372.       remove(memw[psp:$2c]);
  373.           if not st1 then begin
  374.             remove(psp);
  375.             if pos('PPDRV.EXE',S)=0 then setintvec($7a,ptr(0,0))
  376.             else setintvec($7b,ptr(0,0));
  377.             writeln('remove adi-treiber ',s{,hexint(psp):6,hexint(len):6,hexint(memw[psp:$2c]):6});
  378.           end
  379.           else begin
  380.             memw[psp:$2c]:=0;
  381.             writeln('remove environment ',s);
  382.           end;
  383.         end;
  384.       end
  385.       else if st2 and (pos('COMMAND.COM',s)>0) and st3 then begin
  386.         j:=pred(psp);
  387.         i1:=memw[psp:$2c];
  388.         i2:=mcbzeigertyp(ptr(j,0))^.len+psp;
  389.         if i1<>0 then halt;
  390.         if mcbzeigertyp(ptr(i2,0))^.psp=psp then remove(succ(i2));
  391.         remove(psp);
  392.     remove(1+(seg(mcb^)));
  393.         writeln('remove 1. command.com');
  394. {        writeln;
  395.         writeln(' psp=',hexint(psp):6,' env=',hexint(i1):6,
  396.                 ' mcb=',hexint(seg(mcb^)):6,' next mcb=',hexint(i2):6,
  397.                 ' psp next mcb=',hexint(mcbzeigertyp(ptr(i2,0))^.psp));
  398.         writeln(s,' D',hexint(psp):6);
  399.         readln;}
  400.         halt;
  401.       end;
  402. {      writeln(' ',s); }
  403.     end;
  404.     mcb:=ptr((seg(mcb^))+succ(mcb^.len),0);
  405.     if (mcb^.id<>'M') and (seg(mcb^)<$c000) then begin
  406.       mcb:=ptr($c000,0);
  407.       while ((mcb^.id<>'M') or (seg(mcb^)+succ(mcb^.len)<$c000)) and (seg(mcb^)<$ffff) do begin
  408.         inc(memw[seg(mcb):ofs(mcb)+2]);
  409.       end;
  410.     end;
  411.   until mcb1^.id<>'M';
  412. end.
  413.