我编写了一个用C语言程序,过程是将COMMAND.COM文件读入到内存中,然后从该内存地址开始执行。但总是重启?请高人指点。
我的系统:在WINDOWS2000 SERVER下装了一个VMware Workstation,虚拟计算机中装的是MS_DOS7.1 PROMPT版本。
源程序:
#include "stdio.h"
#include<stdlib.h>
void main()
{
struct st
{
short exSignature;
short exExraBytes;
short exPages;
short exRelocItems;
short exHeaderSize;
short exMinAlloc;
short exMaxAlloc;
short exInitSS;
short exInitSP;
short exChechSum;
short exInitIP;
short exInitCS;
short exRelocTable;
short exOverlay;
}fhandle;
FILE *fp;
char ch[28];
unsigned long temp,i;
char a,b;
long *p;
void(*p1)();
fp=fopen("D:\\program\\c\\command.com","rb");
if (fp==NULL)
{
printf("error\n");
getch();
exit(0);
}
else printf("the file has been open!\n");
fseek(fp,0L,SEEK_END);
temp=(unsigned long)ftell(fp);
printf("%x\n",temp);
getch();
printf("now,let's go!\n");
i=0;
fseek(fp,0,SEEK_SET);
p=malloc(temp);
if(p==NULL)
{
printf("the memory is not enought!\n");
getch();
exit(0);
}
b=fread(p,temp,1,fp);
if (b==0)
{
printf("read failure");
getch();
fclose(fp);
exit(0);
}
printf("the file has been read into the memory!\n");
getch();
*p1=(void*)(256+p);
p1();
getch();
free(p);
fclose(fp);
}
[此贴子已经被作者于2008-5-30 8:14:33编辑过] |