2 Copyright © 1995-2014 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 45.1 (10.4.2014)\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) == 0 )
145 || ( strncmp( szInput
, "N", 1) == 0 ) )
147 ERROR_TEXT
= "User canceled...\n";
148 PROGRAM_ERROR
= RETURN_FAIL
;
152 outfunc
= serial_out
? (APTR
)kprintf
: (APTR
)printf
;
154 if ( PROGRAM_ERROR
!= RETURN_FAIL
)
156 outfunc("dumpmem - Memory Dump tool.\n"
157 "© Copyright the AROS Dev Team.\n"
158 "-----------------------------\n\n"
159 "Dumping From [%p] for %d bytes...\n\n",
160 (void *)start_address
, dump_size
);
162 PROGRAM_ERROR
= HexDump((const UBYTE
*)start_address
, dump_size
);
164 outfunc("\n\nDump Complete.\n");
167 else ERROR_TEXT
= HELPTXT
;
169 else ERROR_TEXT
= HELPTXT
;
172 else ERROR_TEXT
= HELPTXT
;
174 if (ERROR_TEXT
) puts( ERROR_TEXT
);
175 return PROGRAM_ERROR
;