2 Copyright © 1995-2011 The AROS Development Team. All rights reserved.
5 Desc: Memory Dump util functions.
9 #include <aros/debug.h>
10 #include <exec/memory.h>
12 #include <dos/exall.h>
13 #include <dos/datetime.h>
14 #include <proto/dos.h>
15 #include <proto/utility.h>
16 #include <utility/tagitem.h>
17 #include <utility/utility.h>
19 #include <proto/alib.h>
20 #include <proto/exec.h>
21 #include <proto/dos.h>
28 int (*outfunc
)(const char *, ...);
30 static int HexDump(const UBYTE
*data
, ULONG count
)
35 end
= (count
+ 15) & -16;
39 if ( SetSignal(0L,0L) & SIGBREAKF_CTRL_C
)
41 SetIoErr( ERROR_BREAK
);
46 outfunc("%p:", data
+ t
);
52 outfunc("%02x", ((UBYTE
*)data
)[t
]);
75 static const char version
[] = "$VER: dumpmem.c 45.0 (10.2.2004)\n";
77 #define ARG_TEMPLATE "ADDRESS/A,SIZE/N/A,SERIAL/S,QUIET/S"
88 int main(int argc
, char **argv
)
99 IPTR start_address
,dump_size
= 0;
100 int PROGRAM_ERROR
= RETURN_OK
;
101 char *ERROR_TEXT
= NULL
;
105 "ADDRESS The start address to dump from (in hex)\n"
106 "SIZE The number of bytes to dump\n"
107 "SERIAL If specified, output will use serial debugging instead of stdout\n"
108 "QUIET Do not display warnings\n";
110 rda
= ReadArgs(ARG_TEMPLATE
, args
, NULL
);
113 if (args
[ARG_ADDRESS
]!=0)
116 if (args
[ARG_SIZE
]!=0)
118 BOOL serial_out
= (BOOL
)args
[ARG_SERIAL
];
119 BOOL quiet_out
= (BOOL
)args
[ARG_QUIET
];
120 ULONG
*sizptr
= (ULONG
*)args
[ARG_SIZE
];
123 if ( sizptr
!= NULL
) dump_size
= *sizptr
;
124 else PROGRAM_ERROR
= RETURN_FAIL
;
126 start_address
= strtoul((CONST_STRPTR
) args
[ARG_ADDRESS
], &pEnd
, 16 );
130 ERROR_TEXT
= "Size must be a positive value\n";
131 PROGRAM_ERROR
= RETURN_FAIL
;
134 /* a quick warning */
135 if ( ( !quiet_out
) && ( PROGRAM_ERROR
!= RETURN_FAIL
) )
138 printf( "\n *Some memory areas should NOT be read\n use this tool carefully!\n would you like to proceed? ");
144 if ( ( strncmp( szInput
, "n", 1) )||( strncmp( szInput
, "N", 1) ) )
146 ERROR_TEXT
= "User canceled..\n";
147 PROGRAM_ERROR
= RETURN_FAIL
;
151 outfunc
= serial_out
? (APTR
)kprintf
: (APTR
)printf
;
153 if ( PROGRAM_ERROR
!= RETURN_FAIL
)
155 outfunc("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
);
157 PROGRAM_ERROR
= HexDump((const UBYTE
*)start_address
, dump_size
);
159 outfunc("\n\nDump Complete.\n");
162 else ERROR_TEXT
= HELPTXT
;
164 else ERROR_TEXT
= HELPTXT
;
167 else ERROR_TEXT
= HELPTXT
;
169 if (ERROR_TEXT
) puts( ERROR_TEXT
);
170 return PROGRAM_ERROR
;