- 论坛徽章:
- 0
|
[原创]我写的几个程序(很烂请指正)
下面这个程序有点问题,软盘修复的函数回不来???
/**********************************************************/
/* 磁盘超级工具 */
/* 本程序在win9X+Borland C++3.1下编译通过 */
/* 这个程序是我写的,没有时间加详细注释了,抱歉 */
/* 主要的用途是对系统底层的调用,和对硬盘的处理 */
/* 功能十分强大,对CMOS的备份的功能没太调好,先放在这里吧 */
/* 警告:本软件有些功能十分危险,仅供学习之用出现任何后果 */
/* 本人改不负责! */
/**********************************************************/
#include <stdio.h>;
#include <conio.h>;
#include <dos.h>;
#include <stdlib.h>;
#include <alloc.h>;
#include <string.h>;
#include <bios.h>;
#include <fcntl.h>;
#include <sys\types.h>;
#include <sys\stat.h>;
/*int LoadCmosFromFile(char *);
int SaveCmosToFile(char *);*/
int Welcome(void);
int Choice(int i);
void Goodbye(void);
void view_country(void);
int view_Environment(void);
int Addlock(void);
int Untielock(void);
void Repairdisk(void);
int savepart(void);
int Crack_bios(void);
void Show_coms(void);
/*int Save_cmos (void);*/
void Show_bios(void);
int main(void)
{
int End;
for(;
{
End=Choice(Welcome());
if(End)
{
Goodbye();
break;
}
getch();
}
return 0;
}
int Welcome(void)
{
int I;
clrscr();
printf("--------------------<<Welcome the super tool in usage>;>;-------------------------\n"
" 1.National information in DOS\n" /*显示DOS信息*/
" 2.The environment paramemters the deal\n" /*显示环境变量*/
" 3.Add an lock on your hard dish\n"/*硬盘加锁*/
" 4.Unlock your hard desk lock\n"/*硬盘解锁*/
" 5.Repair your floppy drivers\n"/*修复软盘*/
" 6.Save or load Part\n"/*保存与恢复分区表*/
" 7.view your biospassword\n"/*显示BIOS密码*/
" 8.Show your Coms Information\n"/*显示CMOS信息*/
" 9.Show your Bios Information\n"/*显示BIOS信息*/
" 0.Quit\n"
"\n\n\n"
" Please The Choice:"
);
/*" 10.Save your Coms \n"*//*保存CMOS信息(未调好)*/
scanf("%d",&I);
clrscr();
return I;
}
int Choice(int i)
{
printf("---------------------------[[made from @Qu]]------------------------------------\n"
switch(i)
{
case 1:view_country();break;
case 2:view_Environment();break;
case 3:Addlock();break;
case 4:Untielock();break;
case 5:Repairdisk();break;
case 6:savepart();break;
case 7:Crack_bios();break;
case 8:Show_coms();break;
case 9:Show_bios();break;
/*case 10:Save_cmos ();break;*/
case 0:return 1;
default:break;
}
return 0;
}
void Goodbye(void)
{
clrscr();
printf("\n\n\n\n\n"
"-------------------------<<Good bye my friend>;>;---------------------------------\n"
" Super tool in usage\n"
" Edition number 0.91\n"
" If you have any problem\n"
" Please the contact:\n"
" QQ:45268175\n"
" www.dongfangbbs.com\n"
" xunyuetian@yahoo.com.cn\n"
" !Thanks for your usage!\n\n"
"---------------------------[[made from @Qu]]------------------------------------\n"
);
getch();
}
void view_country(void)
{
struct COUNTRY info;
country(0, &info);
if (info.co_date == 0)
printf("Date format: mm/dd/yy\n"
else if (info.co_date == 1)
printf("Date format: dd/mm/yy\n"
else if (info.co_date == 2)
printf("Date format: yy/mm/dd\n"
printf("Currency symbol %s\n", info.co_curr);
printf("Decimal separator %s\n", info.co_thsep);
printf("Date separator %s Time separator %s\n",
info.co_dtsep, info.co_tmsep);
if (info.co_currstyle == 0)
printf("Currency symbol precedes with no leading spaces\n"
else if (info.co_currstyle == 1)
printf("Currency symbol follows with no spaces\n"
else if (info.co_currstyle == 2)
printf("Currency symbol precedes with leading space\n"
if (info.co_currstyle == 4)
printf("Currency symbol follows with space\n"
printf("Currency significant digits %d\n", info.co_digits);
if (info.co_time)
printf("24 hour time\n"
else
printf("12 hour time\n");
printf("Data separator %s\n", info.co_dasep);
}
int view_Environment(void)
{
char *path, *ptr;
int i = 0;
ptr = getenv("ATH");
path = (char *) malloc(strlen(ptr)+15);
strcpy(path,"ATH=");
strcat(path,ptr);
strcat(path,";c:\\temp");
putenv(path);
while (environ)
printf("%s\n",environ[i++]);
return 0;
}
int Addlock(void)
{
int result;
char a='N';
char buffer[512];
printf("Do you hope to be on your hard dish to add the lock?(Y/N)");
scanf("%c",&a);
scanf("%c",&a);
if (a == 'Y')
{
result = biosdisk(2,0x80,0,0,1,1,buffer);
if(result)
{
buffer[510] = 0x0;
buffer[511] = 0x0;
printf("Read the lord the leading an area failure!\n");
}
if(!result) result = biosdisk(3,0x80,0,0,1,1,buffer);
(!result)?(printf("Write the lord the leading an area success!\n"))printf("Write the lord the leading an area failure!\n"));
}
return 0;
}
int Untielock(void)
{
int result;
char a='N';
char buffer[512];
printf("Do you hope to untie your hard dish lock?(Y/N)");
scanf("%c",&a);
scanf("%c",&a);
if (a == 'Y')
{
result = biosdisk(2,0x80,0,0,1,1,buffer);
if(result)
{
buffer[510] = 0x1;
buffer[511] = 0x1;
printf("Read the lord the leading an area failure!\n");
}
if(!result) result = biosdisk(3,0x80,0,0,1,1,buffer);
(!result)?(printf("Write the lord the leading an area success!\n"))printf("Write the lord the leading an area failure!\n"));
}
return 0;
}
void Repairdisk(void)
{
int i,j,dh,ch;
a: printf ("Select drive: (0->;A/1->;B) \n");
scanf(" %d",&ch);
if (ch!= 0 && ch != 1 ) goto a;
printf ("Slect disk:");
printf(" (36->;360KB/72->;720KB/12->;1.2MB/14->;1.44MB) \n");
scanf(" %d" ,&dh);
switch (dh)
{
case 36:
for (i=1; i<3;i++)
{
j=j+2;
absread(ch,1,j,0);
abswrite (ch,1,i,0);
}
break;
case 72:
for (i=1; i<4; i++)
{
j=i+3;
absread (ch,1,j,0);
abswrite(ch,1,i,0);
}
break;
case 12:
for (i=1; i<8; i++)
{
j=i+7;
absread (ch,1,j,0);
abswrite (ch,1,i,0);
}
break;
case 14:
for (i=1; i<10; i++)
{
j=i+9;
absread (ch,1,j,0);
abswrite (ch,1,i,0);
}
break;
}
printf ("OK!");
}
int savepart(void)
{
int I,result;
char buffer[512];
FILE *fp;
printf("lease the choice:1,2\n"
" 1---SAVEPART ->; part.doc\n"
" 2---LOADPART <- part.doc\n"
" Input:"
);
scanf("%d",&I);
if (I==1)
{
result = biosdisk(2,0x80,0,0,0,1,buffer);
if (!result){
printf("Read PART success\n");
if (( fp == fopen("part.doc","wb+"))==NULL)
{
fprintf(stderr,"can't make:c:part.doc \n");
exit(1);
}
fwrite(buffer,1,512,fp);
fclose(fp);
printf("Save PART success\n");
return 0;
}
else {
fprintf(stderr,"Read PART Failure");
exit(1);
}
}
if (I==2)
{
if ((fp == fopen("part.doc","rb+"))==NULL)
{
fprintf(stderr,"can't open file");
exit(1);
}
fread (buffer,1,512,fp);
result = biosdisk(3,0x80,0,0,1,1,buffer);
if (! result){
printf("Load PART success");
fclose(fp);
return 0;
}
else{
fprintf(stderr,"Load PART Failure");
fclose(fp);
exit(1);
}
}
return 0;
}
int Crack_bios(void)
{
int i;
char final[9];
unsigned char value[2];
printf("BIOS Password Recovery Version \n");
outportb(0x70,0x1c);
value[0]=inportb(0x71);
outportb(0x70, 0x1d);
value[1]=inportb(0x71);
for(i=0;i<4;i++)
{final[7-i]=(value[0] & 3) + 0x30;
value[0]=value[0] >;>; 2;
}
for(i=0;i<4;i++)
{final[3-i]=(value[1] & 3) + 0x30;
value[1]=value[1] >;>; 2;
}
final[8]=0;
printf("Your Supervisor BIOS password is %s \n", final);
getch();
return 0;
}
void Show_coms(void)
{
struct CMOS
{
unsigned char current_second;
unsigned char alarm_second;
unsigned char current_minute;
unsigned char alarm_minute;
unsigned char current_hour;
unsigned char alarm_hour;
unsigned char current_day_of_week;
unsigned char current_day;
unsigned char current_month;
unsigned char current_year;
unsigned char status_registers[4];
unsigned char diagnostic_status;
unsigned char shutdown_code;
unsigned char drive_types;
unsigned char reserved_x;
unsigned char disk_1_type;
unsigned char reserved;
unsigned char equipment;
unsigned char lo_mem_base;
unsigned char hi_mem_base;
unsigned char hi_exp_base;
unsigned char lo_exp_base;
unsigned char fdisk_0_type;
unsigned char fdisk_1_type;
unsigned char reserved_2[19];
unsigned char hi_check_sum;
unsigned char lo_check_sum;
unsigned char lo_actual_exp;
unsigned char hi_actual_exp;
unsigned char century;
unsigned char information;
unsigned char reserved3[12];
} cmos;
char i;
char *pointer;
char byte;
pointer = (char *) &
for (i = 0; i < 0x34; i++)
{
outportb(0x70, i);
byte = inportb(0x71);
*pointer++ = byte;
}
printf("Current date %d/%d/%d\n", cmos.current_month,
cmos.current_day, cmos.current_year);
printf("Hard disk type %d\n", cmos.fdisk_0_type);
}
/*int SaveCmosToFile(char *file)
{
FILE *fp;
int IndexPort=0x70,DataPort=0x71,i;
char data[256];
if ((fp=fopen(file,"wb"))==NULL)
{
clrscr();
printf("Can't open the file %s .",file);
return 1;
}
for(i=0;i<256;i++)
{
outportb(IndexPort,i);
data=inportb(DataPort);
}
fwrite(data,1,256,fp);
fclose(fp);
}
int LoadCmosFromFile(char *file)
{
FILE *fp;
int IndexPort=0x70,DataPort=0x71,i;
char data[256];
if ((fp=fopen(file,"rb"))==NULL)
{
clrscr();
printf("Can't open the file %s .",file);
return 1;
}
if (filelength(file)!=256)
{
clrscr();
printf("The file %s not a cmos data file.",file);
fclose(fp);
return 1;
}
fread(data,1,256,fp);
for(i=0;i<256;i++)
{
outportb(IndexPort,i);
outportb(DataPort,data);
}
fclose(fp);
}
int Save_cmos (void)
{
char name[100];
int choose;
printf("lease input a file name:\n");
gets(name);
getch();
printf("ress 1 for save cmos data, 2 for load cmos data from file:\n");
scanf("%d",&choose);
if (choose == 1)
{
SaveCmosToFile(name);
return 0;
}
else if (choose == 2)
{
LoadCmosFromFile(name);
return 0;
}
else printf("No such command,quiting...\n");
return 0;
}*/
void Show_bios(void)
{
struct Equip
{
unsigned floppy_available:1;
unsigned coprocessor_available:1;
unsigned system_memory:2;
unsigned video_memory:2;
unsigned floppy_disk_count:2;
unsigned unused_1:1;
unsigned serial_port_count:3;
unsigned game_adapter_available:1;
unsigned unused_2:1;
unsigned printer_count:2;
};
union Equipment
{
unsigned list;
struct Equip list_bits;
} equip;
equip.list = _bios_equiplist();
if (equip.list_bits.coprocessor_available)
printf("Math coprocessor available\n");
else
printf("No math coprocessor\n");
printf("System board memory %d\n",
(equip.list_bits.system_memory + 1) * 16);
printf("Number of floppies %d\n",
equip.list_bits.floppy_disk_count + 1);
printf("Number of printers %d\n",
equip.list_bits.printer_count);
printf("Number of serial ports %d\n",
equip.list_bits.serial_port_count);
} |
|