10l: comparison of char* ptrs with string literals
[mplayer.git] / TOOLS / bios2dump.c
blobcdd74e146010fb35b896e6af2675b7f3cbd292ba
1 /*
2 bios2dump.c - Was designed to extract BIOS of your PC and save it to file.
3 Usage: as argument requires DOS interrupt number in hexadecimal form.
4 as output - will write 64KB file which will named: SSSS_OOOO.intXX
5 where: SSSS - segment of BIOS interrupt handler
6 OOOO - offset of BIOS interrupt handler
7 XX - interrupt number which was passed as argument
8 Licence: GNU GPL v2
9 Copyright: Nick Kurshev <nickols_k@mail.ru>
11 #include <stdio.h>
12 #include <stdlib.h>
14 int main( int argc, char *argv[])
16 FILE * fd_mem, *fd_out;
17 unsigned short int_seg,int_off;
18 unsigned long bios_off;
19 int int_no;
20 size_t i;
21 char outname[80];
22 unsigned char ch;
23 if(argc < 2)
25 printf("Usage: %s int_no(in hex)\n",argv[0]);
26 return EXIT_FAILURE;
28 int_no = strtol(argv[1],NULL,16);
29 if(!(fd_mem = fopen("/dev/mem","rb")))
31 perror("Can't open file - /dev/mem");
32 return EXIT_FAILURE;
34 fseek(fd_mem,int_no*4,SEEK_SET);
35 fread(&int_off,sizeof(unsigned short),1,fd_mem);
36 fread(&int_seg,sizeof(unsigned short),1,fd_mem);
37 sprintf(outname,"%04X_%04X.int%02X",int_seg,int_off,int_no);
38 if(!(fd_out = fopen(outname,"wb")))
40 perror("Can't open output file");
41 fclose(fd_mem);
42 return EXIT_FAILURE;
44 bios_off = (int_seg << 4) + int_off;
45 bios_off &= 0xf0000;
46 fseek(fd_mem,bios_off,SEEK_SET);
47 for(i=0;i<0x10000;i++)
49 fread(&ch,1,1,fd_mem);
50 fwrite(&ch,1,1,fd_out);
52 fclose(fd_out);
53 fclose(fd_mem);
54 return EXIT_SUCCESS;