annotate TOOLS/bios2dump.c @ 21489:969de5b130ae

fix include clash for mmap_anon on darwin ppc
author nplourde
date Tue, 05 Dec 2006 00:01:19 +0000
parents 51276a7f4ea1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2355
77d81e5c186d re-eng tool
nick
parents:
diff changeset
1 /*
77d81e5c186d re-eng tool
nick
parents:
diff changeset
2 bios2dump.c - Was designed to extract BIOS of your PC and save it to file.
77d81e5c186d re-eng tool
nick
parents:
diff changeset
3 Usage: as argument requires DOS interrupt number in hexadecimal form.
77d81e5c186d re-eng tool
nick
parents:
diff changeset
4 as output - will write 64KB file which will named: SSSS_OOOO.intXX
77d81e5c186d re-eng tool
nick
parents:
diff changeset
5 where: SSSS - segment of BIOS interrupt handler
77d81e5c186d re-eng tool
nick
parents:
diff changeset
6 OOOO - offset of BIOS interrupt handler
77d81e5c186d re-eng tool
nick
parents:
diff changeset
7 XX - interrupt number which was passed as argument
77d81e5c186d re-eng tool
nick
parents:
diff changeset
8 Licence: GNU GPL v2
77d81e5c186d re-eng tool
nick
parents:
diff changeset
9 Copyright: Nick Kurshev <nickols_k@mail.ru>
77d81e5c186d re-eng tool
nick
parents:
diff changeset
10 */
77d81e5c186d re-eng tool
nick
parents:
diff changeset
11 #include <stdio.h>
77d81e5c186d re-eng tool
nick
parents:
diff changeset
12 #include <stdlib.h>
77d81e5c186d re-eng tool
nick
parents:
diff changeset
13
77d81e5c186d re-eng tool
nick
parents:
diff changeset
14 int main( int argc, char *argv[])
77d81e5c186d re-eng tool
nick
parents:
diff changeset
15 {
77d81e5c186d re-eng tool
nick
parents:
diff changeset
16 FILE * fd_mem, *fd_out;
77d81e5c186d re-eng tool
nick
parents:
diff changeset
17 unsigned short int_seg,int_off;
77d81e5c186d re-eng tool
nick
parents:
diff changeset
18 unsigned long bios_off;
77d81e5c186d re-eng tool
nick
parents:
diff changeset
19 int int_no;
77d81e5c186d re-eng tool
nick
parents:
diff changeset
20 size_t i;
77d81e5c186d re-eng tool
nick
parents:
diff changeset
21 char outname[80];
77d81e5c186d re-eng tool
nick
parents:
diff changeset
22 unsigned char ch;
77d81e5c186d re-eng tool
nick
parents:
diff changeset
23 if(argc < 2)
77d81e5c186d re-eng tool
nick
parents:
diff changeset
24 {
77d81e5c186d re-eng tool
nick
parents:
diff changeset
25 printf("Usage: %s int_no(in hex)\n",argv[0]);
77d81e5c186d re-eng tool
nick
parents:
diff changeset
26 return EXIT_FAILURE;
77d81e5c186d re-eng tool
nick
parents:
diff changeset
27 }
77d81e5c186d re-eng tool
nick
parents:
diff changeset
28 int_no = strtol(argv[1],NULL,16);
77d81e5c186d re-eng tool
nick
parents:
diff changeset
29 if(!(fd_mem = fopen("/dev/mem","rb")))
77d81e5c186d re-eng tool
nick
parents:
diff changeset
30 {
77d81e5c186d re-eng tool
nick
parents:
diff changeset
31 perror("Can't open file - /dev/mem");
77d81e5c186d re-eng tool
nick
parents:
diff changeset
32 return EXIT_FAILURE;
77d81e5c186d re-eng tool
nick
parents:
diff changeset
33 }
77d81e5c186d re-eng tool
nick
parents:
diff changeset
34 fseek(fd_mem,int_no*4,SEEK_SET);
77d81e5c186d re-eng tool
nick
parents:
diff changeset
35 fread(&int_off,sizeof(unsigned short),1,fd_mem);
77d81e5c186d re-eng tool
nick
parents:
diff changeset
36 fread(&int_seg,sizeof(unsigned short),1,fd_mem);
77d81e5c186d re-eng tool
nick
parents:
diff changeset
37 sprintf(outname,"%04X_%04X.int%02X",int_seg,int_off,int_no);
77d81e5c186d re-eng tool
nick
parents:
diff changeset
38 if(!(fd_out = fopen(outname,"wb")))
77d81e5c186d re-eng tool
nick
parents:
diff changeset
39 {
2357
427dc863fe4b minor fix
nick
parents: 2355
diff changeset
40 perror("Can't open output file");
2355
77d81e5c186d re-eng tool
nick
parents:
diff changeset
41 fclose(fd_mem);
77d81e5c186d re-eng tool
nick
parents:
diff changeset
42 return EXIT_FAILURE;
77d81e5c186d re-eng tool
nick
parents:
diff changeset
43 }
77d81e5c186d re-eng tool
nick
parents:
diff changeset
44 bios_off = (int_seg << 4) + int_off;
77d81e5c186d re-eng tool
nick
parents:
diff changeset
45 bios_off &= 0xf0000;
77d81e5c186d re-eng tool
nick
parents:
diff changeset
46 fseek(fd_mem,bios_off,SEEK_SET);
77d81e5c186d re-eng tool
nick
parents:
diff changeset
47 for(i=0;i<0x10000;i++)
77d81e5c186d re-eng tool
nick
parents:
diff changeset
48 {
77d81e5c186d re-eng tool
nick
parents:
diff changeset
49 fread(&ch,1,1,fd_mem);
77d81e5c186d re-eng tool
nick
parents:
diff changeset
50 fwrite(&ch,1,1,fd_out);
77d81e5c186d re-eng tool
nick
parents:
diff changeset
51 }
77d81e5c186d re-eng tool
nick
parents:
diff changeset
52 fclose(fd_out);
77d81e5c186d re-eng tool
nick
parents:
diff changeset
53 fclose(fd_mem);
77d81e5c186d re-eng tool
nick
parents:
diff changeset
54 return EXIT_SUCCESS;
12923
51276a7f4ea1 cosmetic warning fix (missing newline at end of file)
diego
parents: 2357
diff changeset
55 }