annotate TOOLS/mem2dump.c @ 6221:4b2459557340

add XShape support for gui's submenu
author pontscho
date Tue, 28 May 2002 14:12:33 +0000
parents 04c80ace9581
children 51276a7f4ea1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2356
04c80ace9581 re-eng tool
nick
parents:
diff changeset
1 /*
04c80ace9581 re-eng tool
nick
parents:
diff changeset
2 bios2dump.c - Was designed to dump memory block to file.
04c80ace9581 re-eng tool
nick
parents:
diff changeset
3 Usage: as argument requires absolute address of memory dump and its lenght
04c80ace9581 re-eng tool
nick
parents:
diff changeset
4 (int hexadecimal form).
04c80ace9581 re-eng tool
nick
parents:
diff changeset
5 as output - will write file which will named: memADDR_LEN.dump
04c80ace9581 re-eng tool
nick
parents:
diff changeset
6 where: ADDR - given address of memory
04c80ace9581 re-eng tool
nick
parents:
diff changeset
7 LEN - given length of memory
04c80ace9581 re-eng tool
nick
parents:
diff changeset
8 Licence: GNU GPL v2
04c80ace9581 re-eng tool
nick
parents:
diff changeset
9 Copyright: Nick Kurshev <nickols_k@mail.ru>
04c80ace9581 re-eng tool
nick
parents:
diff changeset
10 */
04c80ace9581 re-eng tool
nick
parents:
diff changeset
11 #include <stdio.h>
04c80ace9581 re-eng tool
nick
parents:
diff changeset
12 #include <stdlib.h>
04c80ace9581 re-eng tool
nick
parents:
diff changeset
13
04c80ace9581 re-eng tool
nick
parents:
diff changeset
14 int main( int argc, char *argv[])
04c80ace9581 re-eng tool
nick
parents:
diff changeset
15 {
04c80ace9581 re-eng tool
nick
parents:
diff changeset
16 FILE * fd_mem, *fd_out;
04c80ace9581 re-eng tool
nick
parents:
diff changeset
17 unsigned long i,addr,len;
04c80ace9581 re-eng tool
nick
parents:
diff changeset
18 int int_no;
04c80ace9581 re-eng tool
nick
parents:
diff changeset
19 char outname[80];
04c80ace9581 re-eng tool
nick
parents:
diff changeset
20 unsigned char ch;
04c80ace9581 re-eng tool
nick
parents:
diff changeset
21 if(argc < 3)
04c80ace9581 re-eng tool
nick
parents:
diff changeset
22 {
04c80ace9581 re-eng tool
nick
parents:
diff changeset
23 printf("Usage: %s address length (in hex)\n",argv[0]);
04c80ace9581 re-eng tool
nick
parents:
diff changeset
24 return EXIT_FAILURE;
04c80ace9581 re-eng tool
nick
parents:
diff changeset
25 }
04c80ace9581 re-eng tool
nick
parents:
diff changeset
26 addr = strtol(argv[1],NULL,16);
04c80ace9581 re-eng tool
nick
parents:
diff changeset
27 len = strtol(argv[2],NULL,16);
04c80ace9581 re-eng tool
nick
parents:
diff changeset
28 if(!(fd_mem = fopen("/dev/mem","rb")))
04c80ace9581 re-eng tool
nick
parents:
diff changeset
29 {
04c80ace9581 re-eng tool
nick
parents:
diff changeset
30 perror("Can't open file - /dev/mem");
04c80ace9581 re-eng tool
nick
parents:
diff changeset
31 return EXIT_FAILURE;
04c80ace9581 re-eng tool
nick
parents:
diff changeset
32 }
04c80ace9581 re-eng tool
nick
parents:
diff changeset
33 sprintf(outname,"mem%08X_%08X.dump",addr,len);
04c80ace9581 re-eng tool
nick
parents:
diff changeset
34 if(!(fd_out = fopen(outname,"wb")))
04c80ace9581 re-eng tool
nick
parents:
diff changeset
35 {
04c80ace9581 re-eng tool
nick
parents:
diff changeset
36 perror("Can't open output file");
04c80ace9581 re-eng tool
nick
parents:
diff changeset
37 fclose(fd_mem);
04c80ace9581 re-eng tool
nick
parents:
diff changeset
38 return EXIT_FAILURE;
04c80ace9581 re-eng tool
nick
parents:
diff changeset
39 }
04c80ace9581 re-eng tool
nick
parents:
diff changeset
40 fseek(fd_mem,addr,SEEK_SET);
04c80ace9581 re-eng tool
nick
parents:
diff changeset
41 for(i=0;i<len;i++)
04c80ace9581 re-eng tool
nick
parents:
diff changeset
42 {
04c80ace9581 re-eng tool
nick
parents:
diff changeset
43 fread(&ch,1,1,fd_mem);
04c80ace9581 re-eng tool
nick
parents:
diff changeset
44 fwrite(&ch,1,1,fd_out);
04c80ace9581 re-eng tool
nick
parents:
diff changeset
45 }
04c80ace9581 re-eng tool
nick
parents:
diff changeset
46 fclose(fd_out);
04c80ace9581 re-eng tool
nick
parents:
diff changeset
47 fclose(fd_mem);
04c80ace9581 re-eng tool
nick
parents:
diff changeset
48 return EXIT_SUCCESS;
04c80ace9581 re-eng tool
nick
parents:
diff changeset
49 }