home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / hackers / tools / nsk.arj / FTRACE / STEP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-20  |  2.5 KB  |  149 lines

  1. /* æÑαó¿ß¡δÑ Σπ¡¬µ¿¿ ñ½∩ »α«óÑન ºáΘ¿Γ,
  2. ¿¡¿µ¿á½¿ºáµ¿¿ ßΓαπ¬Γπα ñá¡¡δσ TRACER, ¡Ñ
  3. »αÑñ¡áº¡áτÑ¡á ñ½∩ ¿ß»«½∞º«óá¡¿∩ «Γñѽ∞¡«
  4. «Γ TRACER */
  5.  
  6. #include"ftrace.h"
  7. #include"cpu.h"
  8. #include"intr.h"
  9. #include<alloc.h>
  10. #include<process.h>
  11. #include<stdio.h>
  12.  
  13. fidt    oldidt,newidt={0xffff,0l};
  14. void    * it=0;
  15. unsigned char test,testc,EnIDT;
  16. unsigned char bufc[4],bufc1[4],far * oldcommand,far * oldcommand1;
  17. unsigned char far * fstack=0l;
  18.  
  19. static unsigned char far * c;
  20.  
  21. #ifdef DEBUG
  22.  void DEBstep(void)            /*No enter!!!*/
  23.  {
  24.   void interrupt (* DEB)(void);
  25.   if(EnIDT)
  26.   {
  27.    DEB=getvect(1);
  28.    setvect(1,ftrace);
  29.    step();
  30.    setvect(1,DEB);
  31.   }else{
  32.    _lidt(&newidt);
  33.    step();
  34.    _lidt(&oldidt);
  35.   }
  36.  }
  37. #endif
  38.  
  39. void texit(cod)
  40. int cod;
  41. {
  42.  if(!EnIDT)
  43.  {
  44.   _lidt(&oldidt);
  45.  }
  46.  exit(cod);
  47. }
  48.  
  49. steptest()
  50. {
  51.   topb[4]|=1;
  52.  
  53. #ifdef DEBUG1
  54.      printf("IP=%x\tCS=%x\n",last_command);
  55. #endif
  56.  
  57.   {
  58.    int i=4;
  59.    while(i-- > 0)bufc[i]=c[i];
  60.    oldcommand=c;
  61.    if(!testc)oldcommand1=oldcommand;
  62.   }
  63.  
  64.   if(test)
  65.   {
  66.    if(last_command[-1] == 0x9c)
  67.    {
  68.     topb[6]&=0xfe;
  69.     test=0;
  70.    }
  71.   }
  72.  
  73.   for(c=last_command;;)
  74.   if(ispref(*c)){c++;continue;}
  75.    else if(isatrece(*c)){
  76.    if(havepost(*(c++))){c += sizedata(*c) + 1;}
  77.    continue;
  78.    }else break;
  79.   if((*c)==0x9c)
  80.   {
  81.    test = 1;
  82.   }
  83.   if((*c)==0xcd){return(2);}
  84.   if((*c)==0xcf){return(1);}
  85.  
  86. #ifdef DEBUG
  87.   DEBstep();  /*No enter! Pres F8 if you used TorboDebuger!*/
  88. #else
  89.   step();
  90. #endif
  91.   {
  92.    int i;
  93.    if(testc)
  94.    {
  95.     i=4;
  96.     while(i-- > 0)
  97.     {
  98.      oldcommand1[i]=bufc1[i];
  99.     }
  100.    testc=0;
  101.    }else{
  102.    i=4;
  103.    while((i-- > 0) && !(testc = (oldcommand[i] != bufc[i])));
  104.    }
  105.    if(testc)
  106.    {
  107.     i=4;
  108.     while(i-- > 0)
  109.     {
  110. #ifdef DEBUG1
  111.      printf("Buffer IP=%x\tCS=%x\n",oldcommand1);
  112. #endif
  113.      bufc1[i]=oldcommand1[i];
  114.      oldcommand1[i]=bufc[i];
  115.     }
  116.    }
  117.   }
  118.   return 0;
  119. }
  120.  
  121. void inittrace(funct t)
  122. {
  123.   fstack=save_stat.stack.stack = (void far *) farmalloc(256);
  124.   topstack->CS_IP.point = t;
  125.   topstack->flags = 0x100;
  126.   if(!(EnIDT=CpuTest()))        /*Zero - enable using idt*/
  127.   {
  128.    _sidt(&oldidt);
  129.    if((it = malloc(1024)) == 0)
  130.    {
  131.     EnIDT = 5;
  132.     puts("Warning:Out of memory for new interrupt table");
  133.    }else{
  134.     newidt.table = mkidt(it);
  135. #ifndef DEBUG 
  136.    _lidt(&newidt);
  137. #endif
  138.    }
  139.   }
  140.  if(EnIDT)
  141.  {
  142. #ifndef DEBUG
  143.   setvect(1,ftrace);
  144. #endif
  145.  }else{
  146.   ((long*)it)[1] = (long)ftrace;
  147.  }
  148. }
  149.