📄 opsector.c
字号:
/***********************************************************/
/*软件功能:这是一个可以直接访问硬盘的程序 */
/* 可以修改硬盘扇区的信息。 */
/*软件支持:该程序只能在windows 9x 或DOS 操作系统上运行 */
/*程序编辑:Ricky */
/*email:lsw_jx@sina.com */
/*QQ:384934531 */
/*时间:2007.1.6 */
/***********************************************************/
#include<bios.h>
#include<stdio.h>
#define DRIVE 0x80
#define PAGEDOWN 0x5100
#define PAGEUP 0x4900
#define DOWN 0x5000
#define UP 0x4800
#define ENTER 0x1c0d
#define ESC 0x11b
int cmd, head=0, track=0, sector=0, nsects=1, status=0, linenum=0;
unsigned char *buf;
int RestDisk();
int ReadDisk();
void ModifyBuff();
void ShowInfo(int x);
int KeyPress();
void WriteDisk();
void SetOperateSector();
int CreateBuff(int n);
main()
{
SetOperateSector();
if(CreateBuff(nsects)==0)
{
printf("can't create buf!");
exit(1);
}
if(RestDisk()==0) exit(1);
if(ReadDisk()==0) exit(1);
ShowInfo(0);
while(KeyPress());
}
void SetOperateSector()
{
printf("what sector do you want to operate?");
printf("\nhead:");
scanf("%d",&head);
printf("track:");
scanf("%d",&track);
printf("sector:");
scanf("%d",§or);
printf("nsects:");
scanf("%d",&nsects);
}
int CreateBuff(int n)
{
buf=(unsigned char *)calloc(n*512,sizeof(unsigned char));
if(buf==NULL)
return 0;
else
return 1;
}
int RestDisk()
{
status=biosdisk(cmd=0,DRIVE,head,track,sector,nsects,buf);
if(status==0)
{
return 1;
}
else
{
printf("Disk rest error!\n");
return 0;
}
}
int ReadDisk()
{
status=biosdisk(cmd=2,DRIVE,head,track,sector,nsects,buf);
if(status!=0)
{
printf("Disk read error!\n");
return 0;
}
else
return 1;
}
void ShowInfo(int x)
{
int i;
int y=3;
clrscr();
/*printf("The sector information as following\n"); */
/* 制作一个输出扇区信息的表栏*/
printf(" 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\n");
/*输出buf[i]中的hex码*/
for(i=x;i<x+128;i++)
{
if(i%16==0)printf("\n%2x:",i/16);
printf(" %2x",buf[i]);
}
/*输出对应的字符表*/
for(i=x;i<x+128;i++)
{
if(i%16==0)
gotoxy(55,y++);
if(buf[i]<=13&&buf[i]>=7)
/*特殊字符处理*/
putchar('.');
else
putchar(buf[i]);
}
printf("\n");
}
void ModifyBuff()
{
int addr;
unsigned char c;
printf("\naddress:");
scanf("%x",&addr);
if(addr>(0x200*nsects-1)||addr<0)
printf("Address is not in this sector!");
else
{
printf("DATA Old:%x New:",buf[addr]);
scanf("%x",&c);
buf[addr]=c;
ShowInfo(linenum*16);
}
}
int KeyPress()
{
switch(bioskey(0))
{
case PAGEDOWN: /*向下移动8行*/
if(linenum<(17+32*(nsects-1)))
linenum+=8;
else
linenum=24+32*(nsects-1);
ShowInfo(linenum*16);
return 1;
case DOWN: /*向下移动1行*/
if(linenum<(24+32*(nsects-1)))
{
linenum++;
ShowInfo(linenum*16);
}
return 1;
case PAGEUP: /*向上移动8行*/
if(linenum<=7)
linenum=0;
else
linenum-=8;
ShowInfo(linenum*16);
return 1;
case UP: /*向上移动1行*/
if(linenum>0)
{
linenum--;
ShowInfo(linenum*16);
}
return 1;
case ENTER: /*调用修改函数*/
ModifyBuff();
return 1;
case ESC: /*退出程序时询问事项*/
printf("You operated sector:head:%d,track:%d,sector:%d,nsects:%d\n",
head,track,sector,nsects);
printf("Do you want to rewrite this sector(Y/N)");
if(getch()=='Y'||getch()=='y')
WriteDisk();
return 0;
}
}
void WriteDisk()
{
status=biosdisk(cmd=3,DRIVE,head,track,sector,nsects,buf);
if(status!=0)
printf("Rewrite sector error!");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -