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 IPTR offset
,start_address
,dump_size
= 0;
57 int PROGRAM_ERROR
= RETURN_OK
;
58 char *ERROR_TEXT
,*HELPTXT
;
61 "ADDRESS The start address to dump from (in hex)\n"
62 "SIZE The number of bytes to dump\n"
63 "SERIAL If specified, output will use serial debugging instead of stdout\n"
64 "QUIET Do not display warnings\n";
66 rda
= ReadArgs(ARG_TEMPLATE
, args
, NULL
);
69 if (args
[ARG_ADDRESS
]!=0)
72 if (args
[ARG_SIZE
]!=0)
74 BOOL serial_out
= (BOOL
)args
[ARG_SERIAL
];
75 BOOL quiet_out
= (BOOL
)args
[ARG_QUIET
];
76 ULONG
*sizptr
= (ULONG
*)args
[ARG_SIZE
];
79 if ( sizptr
!= NULL
) dump_size
= *sizptr
;
80 else PROGRAM_ERROR
= RETURN_FAIL
;
82 start_address
= strtoul((CONST_STRPTR
) args
[ARG_ADDRESS
], &pEnd
, 16 );
83 dump_size
= ( dump_size
/ sizeof(unsigned int));
87 ERROR_TEXT
= "Size must be a positive value\n";
88 PROGRAM_ERROR
= RETURN_FAIL
;
92 if ( ( !quiet_out
) && ( PROGRAM_ERROR
!= RETURN_FAIL
) )
95 printf( "\n *Some memory areas should NOT be read\n use this tool carefully!\n would you like to proceed? ");
101 if ( ( strncmp( szInput
, "n", 1) )||( strncmp( szInput
, "N", 1) ) )
103 ERROR_TEXT
= "User canceled..\n";
104 PROGRAM_ERROR
= RETURN_FAIL
;
108 if ( PROGRAM_ERROR
!= RETURN_FAIL
)
110 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.. */
111 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
, (int)(dump_size
* sizeof(unsigned int))); /* use kprintf so it is output on serial.. */
113 for ( offset
= 0 ; offset
< dump_size
; offset
+= sizeof(unsigned int) )
115 if ( SetSignal(0L,0L) & SIGBREAKF_CTRL_C
)
117 SetIoErr( ERROR_BREAK
);
118 PROGRAM_ERROR
= RETURN_WARN
;
122 if ( ( (offset
/sizeof(unsigned int) ) % 6) == 0 )
124 if (serial_out
) kprintf("0x%8.8llX ",(unsigned long long)(start_address
+offset
));
125 else printf("0x%8.8llX ",(unsigned long long)(start_address
+offset
));
128 if (serial_out
) kprintf("%8.8X", (unsigned int)((IPTR
*)start_address
+offset
)[0]); /* use kprintf so it is output on serial.. */
129 else printf("%8.8X", (unsigned int)((IPTR
*)start_address
+offset
)[0]); /* use kprintf so it is output on serial.. */
130 sprintf( (char *) &outpstring
+ ((((offset
/sizeof(unsigned int)) % 6) * 4)) ,"%4.4s", (char *)((IPTR
*)start_address
+offset
)[0]);
132 if ( ((offset
/sizeof(unsigned int)) % 6) == 5 )
134 clean_string( outpstring
);
136 if (serial_out
) kprintf(" '%24.24s' \t\n",outpstring
);
137 else printf(" '%24.24s' \t\n",outpstring
);
141 if (serial_out
) kprintf(" ");
147 if (serial_out
) kprintf("\n\nDump Complete. ");
148 else printf("\n\nDump Complete. ");
151 else ERROR_TEXT
= HELPTXT
;
153 else ERROR_TEXT
= HELPTXT
;
156 else ERROR_TEXT
= HELPTXT
;
158 if (ERROR_TEXT
) puts( ERROR_TEXT
);
159 return PROGRAM_ERROR
;
162 /* convert a hex string to an int - deprecated */
164 unsigned int hextoint(char **value)
171 const int HexMapL = 16;
172 struct CHexMap HiHexMap[] =
179 {"A", 10}, {"B", 11},
180 {"C", 12}, {"D", 13},
181 {"E", 14}, {"F", 15},
184 struct CHexMap LoHexMap[] =
191 {"a", 10}, {"b", 11},
192 {"c", 12}, {"d", 13},
193 {"e", 14}, {"f", 15},
196 unsigned int result = 0,start=0;
198 printf(" converting %s to an int..\n",value);
200 if ((char *)value[0] == '0' && (((char *)value[1] == 'X')||((char *)value[1] == 'x') ) ) start = 2;
202 BOOL firsttime = TRUE;
206 for (vallen = start; vallen < strlen(value) ; vallen++)
211 printf(" Parsing $s\n",(char *)value[vallen]);
213 for ( i = 0 ; i < HexMapL; i++)
215 if (( (char *)value[vallen] == HiHexMap[i].chr )||( (char *)value[vallen] == LoHexMap[i].chr ))
217 if (!firsttime) result <<= 4;
218 result |= HiHexMap[i].value;
229 /* Replace all non printable characters with a '.' */
231 void clean_string( char *dirtystring
)
235 for (i
= 0 ; i
< (sizeof(unsigned int) * 6) ; i
++)
237 if ((dirtystring
[i
] < 32) || (dirtystring
[i
] > 126))
238 dirtystring
[i
] = '.';