2 Copyright © 1995-2004 The AROS Development Team. All rights reserved.
5 Desc: Memory Dump util functions.
10 #include <aros/debug.h>
12 #include <exec/memory.h>
14 #include <dos/exall.h>
15 #include <dos/datetime.h>
16 #include <proto/dos.h>
17 #include <proto/utility.h>
18 #include <utility/tagitem.h>
19 #include <utility/utility.h>
21 #include <proto/alib.h>
22 #include <proto/exec.h>
23 #include <proto/dos.h>
30 static const char version
[] = "$VER: dumpmem.c 45.0 (10.2.2004)\n";
32 #define ARG_TEMPLATE "ADDRESS/A,SIZE/N/A,SERIAL/S,QUIET/S"
43 /* unsigned int hextoint( char **value ); */
44 void clean_string( char *dirtystring
);
46 int main(int argc
, char **argv
)
48 IPTR args
[NOOFARGS
] = { (IPTR
) NULL
, // ARG_ADDRESS
49 (IPTR
) NULL
, // ARG_SIZE
55 char outpstring
[sizeof(unsigned int)*6];
56 unsigned int offset
,start_address
,dump_size
;
58 int PROGRAM_ERROR
= RETURN_OK
;
59 char *ERROR_TEXT
,*HELPTXT
;
62 "ADDRESS The start address to dump from (in hex)\n"
63 "SIZE The number of bytes to dump\n"
64 "SERIAL If specified, output will use serial debugging instead of stdout\n"
65 "QUIET Do not display warnings\n";
67 rda
= ReadArgs(ARG_TEMPLATE
, args
, NULL
);
70 if (args
[ARG_ADDRESS
]!=0)
73 if (args
[ARG_SIZE
]!=0)
75 BOOL serial_out
= (BOOL
)args
[ARG_SERIAL
];
76 BOOL quiet_out
= (BOOL
)args
[ARG_QUIET
];
77 ULONG
*sizptr
= (ULONG
*)args
[ARG_SIZE
];
80 if ( sizptr
!= NULL
) dump_size
= *sizptr
;
81 else PROGRAM_ERROR
= RETURN_FAIL
;
83 start_address
= strtoul((CONST_STRPTR
) args
[ARG_ADDRESS
], &pEnd
, 16 );
84 dump_size
= ( dump_size
/ sizeof(unsigned int));
88 ERROR_TEXT
= "Size must be a positive value\n";
89 PROGRAM_ERROR
= RETURN_FAIL
;
93 if ( ( !quiet_out
) && ( PROGRAM_ERROR
!= RETURN_FAIL
) )
96 printf( "\n *Some memory areas should NOT be read\n use this tool carefully!\n would you like to proceed? ");
102 if ( ( strncmp( szInput
, "n", 1) )||( strncmp( szInput
, "N", 1) ) )
104 ERROR_TEXT
= "User canceled..\n";
105 PROGRAM_ERROR
= RETURN_FAIL
;
109 if ( PROGRAM_ERROR
!= RETURN_FAIL
)
111 if (serial_out
) kprintf("dumpmem - Memory Dump tool.\n© Copyright the AROS Dev Team.\n-----------------------------\n\nDumping From [%p] for %d bytes..\n\n", (void *)start_address
, (dump_size
* sizeof(unsigned int))); /* use kprintf so it is output on serial.. */
112 else printf("dumpmem - Memory Dump tool.\n© Copyright the AROS Dev Team.\n-----------------------------\n\nDumping From [%p] for %d bytes..\n\n", (void *)start_address
, (dump_size
* sizeof(unsigned int))); /* use kprintf so it is output on serial.. */
114 for ( offset
= 0 ; offset
< dump_size
; offset
+= sizeof(unsigned int) )
116 if ( SetSignal(0L,0L) & SIGBREAKF_CTRL_C
)
118 SetIoErr( ERROR_BREAK
);
119 PROGRAM_ERROR
= RETURN_WARN
;
123 if ( ( (offset
/sizeof(unsigned int) ) % 6) == 0 )
125 if (serial_out
) kprintf("0x%8.8X ",start_address
+offset
);
126 else printf("0x%8.8X ",start_address
+offset
);
129 if (serial_out
) kprintf("%8.8X", (unsigned int)((IPTR
*)start_address
+offset
)[0]); /* use kprintf so it is output on serial.. */
130 else printf("%8.8X", (unsigned int)((IPTR
*)start_address
+offset
)[0]); /* use kprintf so it is output on serial.. */
131 sprintf( (char *) &outpstring
+ ((((offset
/sizeof(unsigned int)) % 6) * 4)) ,"%4.4s", (char *)((IPTR
*)start_address
+offset
)[0]);
133 if ( ((offset
/sizeof(unsigned int)) % 6) == 5 )
137 clean_string( outpstring
);
139 if (serial_out
) kprintf(" '%24.24s' \t\n",outpstring
);
140 else printf(" '%24.24s' \t\n",outpstring
);
146 if (serial_out
) kprintf(" ");
152 if (serial_out
) kprintf("\n\nDump Complete. ");
153 else printf("\n\nDump Complete. ");
156 else ERROR_TEXT
= HELPTXT
;
158 else ERROR_TEXT
= HELPTXT
;
161 else ERROR_TEXT
= HELPTXT
;
163 if (ERROR_TEXT
) printf( ERROR_TEXT
);
164 return PROGRAM_ERROR
;
167 /* convert a hex string to an int - deprecated */
169 unsigned int hextoint(char **value)
176 const int HexMapL = 16;
177 struct CHexMap HiHexMap[] =
184 {"A", 10}, {"B", 11},
185 {"C", 12}, {"D", 13},
186 {"E", 14}, {"F", 15},
189 struct CHexMap LoHexMap[] =
196 {"a", 10}, {"b", 11},
197 {"c", 12}, {"d", 13},
198 {"e", 14}, {"f", 15},
201 unsigned int result = 0,start=0;
203 printf(" converting %s to an int..\n",value);
205 if ((char *)value[0] == '0' && (((char *)value[1] == 'X')||((char *)value[1] == 'x') ) ) start = 2;
207 BOOL firsttime = TRUE;
211 for (vallen = start; vallen < strlen(value) ; vallen++)
216 printf(" Parsing $s\n",(char *)value[vallen]);
218 for ( i = 0 ; i < HexMapL; i++)
220 if (( (char *)value[vallen] == HiHexMap[i].chr )||( (char *)value[vallen] == LoHexMap[i].chr ))
222 if (!firsttime) result <<= 4;
223 result |= HiHexMap[i].value;
234 /* Replace all non printable characters with a '.' */
236 void clean_string( char *dirtystring
)
240 for (i
= 0 ; i
< (sizeof(unsigned int) * 6) ; i
++)
242 if (( (TEXT
)((IPTR
*)dirtystring
)[i
] < 32 )||( (TEXT
)((IPTR
*)dirtystring
)[i
] > 126 ))
243 (char *)((IPTR
*)dirtystring
)[i
] = ".";