⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dos4g.c

📁 DOS下进入Protect Mode,任意访问0-4GB内存地址数据。
💻 C
字号:
/*********************************************************************/
/*Project :DOS4G                                                     */
/*Function:Access Physical Memory 0x0000100-0xffffffff(256byte - 4G) */
/*Author  :Faintsnow                                                 */
/*History :                                                          */
/*                1.0............initialization version              */
/*                2.0............1.add ascii code display            */
/*                               2.add four qkey [+]/[-]/[G]/[ESC]   */
/*                               3.add memory address input          */
/*                2.01...........1.iniliant memory form argv         */
/*                               2.change qkey to pgup/pgdn          */
/*********************************************************************/

#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>

typedef unsigned char   BYTE;
typedef unsigned int    WORD;
typedef unsigned long   DWORD;


typedef struct _Descriptor
{
   unsigned wSegLimit;
   unsigned wLowPhyAddr;
   unsigned char bMidPhyAddr;
   unsigned char bAccess;
   unsigned char bFlag_SegLimit;
   unsigned char bHiPhyAddr;
} DT;

typedef struct _GDT
{
   unsigned long dwUnused1;
   unsigned long dwUnused2;
   unsigned long dwGDT_BIOS1;
   unsigned long dwGDT_BIOS2;
   DT SDT;
   DT DDT;
   unsigned long dwCodeDescriptor1_BIOS;
   unsigned long dwCodeDescriptor2_BIOS;
   unsigned long dwStackDescriptor1_BIOS;
   unsigned long dwStackDescriptor2_BIOS;
}  GDT;


/********************************************************************/
/*Function: Read data from physical memory address                  */
/*                                                                  */
/*Input:  unsigned long dwAddr....physical memory address           */
/*        char *Buffer............data buffer in current address    */
/*        int Size................data *buffer size                 */
/*                                                                  */
/*Output :Rlt.....................Return errorlevel code            */
/*          1.....................read physical memory fail         */
/*          0.....................read physical memory successful   */
/********************************************************************/
int ReadRAM(unsigned long dwAddr,char *Buffer,int Size)
{
   GDT gdt;
   unsigned wSegment,wOffset;
   unsigned long dwPhyAddr;
   int Rlt=0;

   memset(&gdt,0,sizeof(GDT));

   dwPhyAddr=(unsigned long)FP_SEG(Buffer);
   dwPhyAddr<<=4;
   dwPhyAddr+=FP_OFF(Buffer);

   gdt.DDT.wSegLimit=0xFFFF;
   gdt.DDT.bFlag_SegLimit=0x0001;
   gdt.DDT.bAccess=0x93;
   gdt.DDT.wLowPhyAddr=dwPhyAddr&0xFFFF;
   gdt.DDT.bMidPhyAddr=(unsigned char)((dwPhyAddr)>>16);

   gdt.SDT.wSegLimit=0xFFFF;
   gdt.SDT.bFlag_SegLimit=0x01;
   gdt.SDT.bAccess=0x93;
   gdt.SDT.wLowPhyAddr=(unsigned)(dwAddr&0xFFFF);
   gdt.SDT.bMidPhyAddr=(unsigned char)((dwAddr>>16)&0xff);
   gdt.SDT.bHiPhyAddr=(unsigned char)(dwAddr>>24);

   wSegment=FP_SEG(&gdt);
   wOffset=FP_OFF(&gdt);
   asm push es
   asm push si
   asm mov ah,87h
   asm mov cx,Size
   asm mov es,wSegment
   asm mov si,wOffset
   asm int 15h
   asm jnc  OK
   asm mov Rlt,1
OK:
   asm pop si
   asm pop es
   return Rlt;
}



/******************Write RAM Address Start*****************************/
int WriteRAM(unsigned long dwAddr,char *Buffer,int Size)
{
   GDT gdt;
   unsigned wSegment,wOffset;
   unsigned long dwPhyAddr;
   int Rlt=0;

   memset(&gdt,0,sizeof(GDT));

   dwPhyAddr=(unsigned long)FP_SEG(Buffer);
   dwPhyAddr<<=4;
   dwPhyAddr+=FP_OFF(Buffer);

   gdt.DDT.wSegLimit=0xFFFF;
   gdt.DDT.bFlag_SegLimit=0x0001;
   gdt.DDT.bAccess=0x93;
   gdt.DDT.wLowPhyAddr=(unsigned)(dwAddr&0xFFFF);
   gdt.DDT.bMidPhyAddr=(unsigned char)((dwAddr>>16)&0xff);
   gdt.DDT.bHiPhyAddr=(unsigned char)(dwAddr>>24);

   gdt.SDT.wSegLimit=0xFFFF;
   gdt.SDT.bFlag_SegLimit=0x01;
   gdt.SDT.bAccess=0x93;
   gdt.SDT.wLowPhyAddr=dwPhyAddr&0xFFFF;
   gdt.SDT.bMidPhyAddr=(unsigned char)((dwPhyAddr)>>16);


   wSegment=FP_SEG(&gdt);
   wOffset=FP_OFF(&gdt);
   asm push es
   asm push si
   asm mov ah,87h
   asm mov cx,Size
   asm mov es,wSegment
   asm mov si,wOffset
   asm int 15h
   asm jnc  OK
   asm mov Rlt,1
OK:
   asm pop si
   asm pop es
   return Rlt;
}
/******************Write RAM Address End*****************************/




int main(int argc, char *argv[])
{

   unsigned long buffer[256]={NULL};
   unsigned long dwAddr=0;
   unsigned long tmp;
   int           i,m,n;
   char          KeyBuffer[256];

     union REGS rs,r;
     rs.h.ah=1;
     rs.h.ch=0xfe;
     rs.h.cl=0xfe;
     int86(0x10,&rs,&rs);
   if(argc==2)
   {
    sscanf(argv[1],"%lX",&tmp);
   }else
    {
     printf("-");
     gets(KeyBuffer);
     sscanf(KeyBuffer,"%lX",&tmp);
     if((KeyBuffer[0]=='q')||(KeyBuffer[0]=='Q'))  return 1;
     if(KeyBuffer[0]==NULL) return 1;
    }

   dwAddr=tmp;
   while(1)
    {

      textbackground(BLUE);
      textcolor(YELLOW);
      clrscr();
      gotoxy(20,21);
      printf("START MEMORY ADDRESS : %0lX",tmp);
      gotoxy(1,25);
      printf(" [ESC] EXIT    [PgDn] NEXT OFFSET    [PgUp] FORWARD OFFSET    [G] Input Address");
      gotoxy(1,1);
      for(i=0;i<0x100;i+=1)
      {
       dwAddr=tmp+i;
       ReadRAM(dwAddr,(char*)&buffer[i],1);
       buffer[i]=buffer[i]&0x00ff;
        if( ((i+1)%16==0)  )
         {
           printf("%02X\n",buffer[i]);
          }else
           {
            printf("%02X ",buffer[i]);
           }
       }

       for(n=1;n<17;n++)
       {
         for(m=55;m<71;m++)
          {
           gotoxy(m,n);
            if( (buffer[(n-1)*16+m-55]<0x20) || (buffer[(n-1)*16+m-55]>0x7A) )
             {
              printf(".");
             }else
               {
                printf("%c",buffer[(n-1)*16+m-55]);
               }
          }                                                                 \
        }
getkey:
        r.h.ah=0;
        int86(0x16,&r,&r);
        /*
        printf("%02x",r.h.al);
        getch();
        */
        if(r.h.al==0x1b)
         {
           textbackground(BLACK);
           textcolor(WHITE);
           clrscr();
           break;
          }else if(r.h.ah==0x49)
             {
               sound(800);
               delay(50);
               nosound();
               tmp-=0x100;
             }else if(r.h.ah==0x51)
               {
                 sound(3000);
                 delay(50);
                 nosound();
                 tmp+=0x100;
                }else if((r.h.ah==0x22)&&(r.h.al==0x67))
                  {
                    sound(3000);
                    delay(50);
                    nosound();
                    gotoxy(43,21);
                    printf("        ");
                    gotoxy(43,21);
                    gets(KeyBuffer);
                    sscanf(KeyBuffer,"%lX",&tmp);
                   }else
                   {
                    goto getkey;
                    }
    }

  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -