1 |
cebix |
1.1 |
|
2 |
cebix |
1.8 |
cxmon, Version 3.0 |
3 |
cebix |
1.7 |
A command-line file manipulation tool and disassembler |
4 |
cebix |
1.1 |
|
5 |
cebix |
1.11 |
Copyright (C) 1997-2002 Christian Bauer, Marc Hellwig |
6 |
cebix |
1.5 |
GNU binutils disassemblers Copyright (C) 1988, 89, 91, 93, 94, 95, 96, 97, 1998 |
7 |
cebix |
1.4 |
Free Software Foundation, Inc. |
8 |
cebix |
1.1 |
|
9 |
|
|
|
10 |
cebix |
1.2 |
License |
11 |
|
|
------- |
12 |
|
|
|
13 |
cebix |
1.8 |
cxmon is available under the terms of the GNU General Public License. See the |
14 |
cebix |
1.2 |
file "COPYING" that is included in the distribution for details. |
15 |
|
|
|
16 |
|
|
|
17 |
cebix |
1.1 |
Overview |
18 |
|
|
-------- |
19 |
|
|
|
20 |
cebix |
1.8 |
cxmon is an interactive command-driven file manipulation tool that is |
21 |
cebix |
1.10 |
inspired by the "Amiga Monitor" by Timo Rossi. It has commands and features |
22 |
|
|
similar to a machine code monitor/debugger, but it lacks any functions for |
23 |
|
|
running/tracing code. There are, however, built-in PowerPC, 680x0, 80x86, |
24 |
|
|
6502 and Z80 disassemblers and special support for disassembling MacOS code. |
25 |
|
|
By default, cxmon operates on a fixed-size (but adjustable) memory buffer |
26 |
|
|
with adresses starting at 0. |
27 |
cebix |
1.1 |
|
28 |
|
|
|
29 |
|
|
Installation |
30 |
|
|
------------ |
31 |
|
|
|
32 |
cebix |
1.2 |
Please consult the file "INSTALL" for installation instructions. |
33 |
cebix |
1.1 |
|
34 |
|
|
|
35 |
|
|
Usage |
36 |
|
|
----- |
37 |
|
|
|
38 |
cebix |
1.8 |
cxmon can be started from the Shell or from the Tracker (BeOS), but command |
39 |
|
|
line history doesn't work when started from the Tracker. |
40 |
cebix |
1.5 |
|
41 |
|
|
Options: |
42 |
|
|
-m enables symbolic MacOS A-Trap and low memory globals display in the |
43 |
|
|
680x0 disassembler |
44 |
cebix |
1.8 |
-r makes cxmon operate in real (virtual) memory space instead of an |
45 |
|
|
allocated buffer |
46 |
cebix |
1.5 |
|
47 |
cebix |
1.8 |
If no additional command line arguments are given, cxmon enters interactive |
48 |
|
|
mode. Otherwise, all remaining arguments are interpreted and executed as cxmon |
49 |
cebix |
1.5 |
commands. |
50 |
|
|
|
51 |
|
|
The default buffer size is 1MB. |
52 |
|
|
|
53 |
cebix |
1.8 |
The cxmon command prompt looks like this: |
54 |
cebix |
1.1 |
|
55 |
|
|
[00000000]-> |
56 |
|
|
|
57 |
|
|
The number in brackets is the value of "." (the "current address", see the |
58 |
|
|
section on expressions). You can get a short command overview by entering |
59 |
|
|
"h". |
60 |
|
|
|
61 |
|
|
Commands that create a longer output can be interrupted with Ctrl-C. |
62 |
|
|
|
63 |
cebix |
1.8 |
To quit cxmon, enter the command "x". |
64 |
cebix |
1.1 |
|
65 |
|
|
|
66 |
|
|
Constants, variables and expressions |
67 |
|
|
------------------------------------ |
68 |
|
|
|
69 |
|
|
The default number base is hexadecimal. Decimal numbers must be prefixed with |
70 |
|
|
"_". Hexadecimal numbers may also be prefixed with "$" for clarity. Numbers |
71 |
|
|
can also be entered as ASCII characters enclosed in single quotes (e.g. 'BAPP' |
72 |
|
|
is the same as $42415050). All numbers are 32-bit values (one word). |
73 |
|
|
|
74 |
|
|
With the "set" command, variables can be defined that hold 32-bit integer |
75 |
|
|
values. A variable is referred to by its name. Variable names may be arbitrary |
76 |
|
|
combinations of digits and letters (they may also start with a digit) that |
77 |
|
|
are not also valid hexadecimal numbers. Names are case-sensitive. |
78 |
|
|
|
79 |
cebix |
1.8 |
cxmon accepts expressions in all places where you have to specify a number. |
80 |
|
|
The following operators are available and have the same meaning and |
81 |
|
|
precedence as in the C programming language: |
82 |
cebix |
1.1 |
|
83 |
|
|
~ complement |
84 |
|
|
+ unary plus |
85 |
|
|
- unary minus |
86 |
|
|
* multiplication |
87 |
|
|
/ integer division |
88 |
|
|
% modulo |
89 |
|
|
+ addition |
90 |
|
|
- subtraction |
91 |
|
|
<< shift left |
92 |
|
|
>> shift right |
93 |
|
|
& bitwise AND |
94 |
|
|
^ bitwise exclusive OR |
95 |
|
|
| bitwise inclusive OR |
96 |
|
|
|
97 |
|
|
Parentheses may be used to change the evaluation order of sub-expressions. |
98 |
|
|
|
99 |
|
|
There are two special symbols that can be used in expressions: |
100 |
|
|
|
101 |
|
|
. represents the "current address" (the value of "." is also displayed in |
102 |
|
|
the command prompt). What exactly the current address is, depends on the |
103 |
|
|
command last executed. The display commands set "." to the address after |
104 |
|
|
the last address displayed, the "hunt" commands sets "." to the address |
105 |
|
|
of the first found occurence of the search string, etc. |
106 |
|
|
: is used by the "apply" ("y") command and holds the value of the byte/ |
107 |
|
|
half-word/word at the current address. |
108 |
|
|
|
109 |
|
|
The "modify" (":"), "fill" ("f") and "hunt" ("h") commands require you to |
110 |
|
|
specify a byte string. Byte strings consist of an arbitrary number of byte |
111 |
|
|
values and ASCII strings separated by commas. Examples: |
112 |
|
|
|
113 |
|
|
"string" |
114 |
|
|
12,34,56,78,9a,bc,de,f0 |
115 |
|
|
"this",0a,"is a string",0a,"with","newlines",_10 |
116 |
|
|
|
117 |
|
|
|
118 |
|
|
The buffer |
119 |
|
|
---------- |
120 |
|
|
|
121 |
cebix |
1.8 |
Those cxmon commands that operate on "memory" operate on a buffer allocated |
122 |
|
|
by cxmon whose size is adjustable with the "@" command. The default buffer |
123 |
|
|
size is 1MB. The buffer is an array of bytes where each byte has a 32-bit |
124 |
|
|
integer address. Addresses start at 0 and are taken modulo the buffer size |
125 |
|
|
(i.e. for the default 1MB buffer, addresses 0 and 100000 refer to the same |
126 |
|
|
byte). |
127 |
cebix |
1.1 |
|
128 |
cebix |
1.8 |
The buffer is the working area of cxmon where you load files into, manipulate |
129 |
cebix |
1.1 |
them, and write files back from. Arbitraty portions of the buffer may be used |
130 |
|
|
as scratch space. |
131 |
|
|
|
132 |
|
|
|
133 |
|
|
Commands |
134 |
|
|
-------- |
135 |
|
|
|
136 |
cebix |
1.8 |
The following commands are available in cxmon ('[]' marks a parameter than |
137 |
|
|
can be left out): |
138 |
cebix |
1.1 |
|
139 |
|
|
|
140 |
cebix |
1.8 |
x Quit cxmon |
141 |
cebix |
1.1 |
|
142 |
cebix |
1.8 |
quits cxmon and returns to the shell. |
143 |
cebix |
1.1 |
|
144 |
|
|
|
145 |
|
|
h Show help text |
146 |
|
|
|
147 |
|
|
displays a short overview of commands. |
148 |
|
|
|
149 |
|
|
|
150 |
|
|
?? Show list of commands |
151 |
|
|
|
152 |
|
|
displays a short list of available commands. |
153 |
|
|
|
154 |
|
|
|
155 |
|
|
ver Show version |
156 |
|
|
|
157 |
cebix |
1.8 |
shows the version number of cxmon. |
158 |
cebix |
1.1 |
|
159 |
|
|
|
160 |
|
|
? expression Calculate expression |
161 |
|
|
|
162 |
|
|
displays the value of the given expression in hex, decimal, and ASCII |
163 |
|
|
characters. If the value is negative, it is displayed as a signed and unsigned |
164 |
|
|
number. |
165 |
|
|
|
166 |
|
|
|
167 |
|
|
@ [size] Reallocate buffer |
168 |
|
|
|
169 |
|
|
changes the size of the buffer to the given number of bytes while preserving |
170 |
|
|
the contents of the buffer. If the "size" argument is omitted, the current |
171 |
|
|
buffer size is displayed. |
172 |
|
|
|
173 |
|
|
|
174 |
|
|
i [start [end]] ASCII memory dump |
175 |
|
|
|
176 |
|
|
displays the buffer contents from address "start" to address "end" as ASCII |
177 |
|
|
characters. Entering "i" without arguments is equivalent to "i .". The value |
178 |
|
|
of "." is set to the address after the last address displayed. |
179 |
|
|
|
180 |
|
|
|
181 |
cebix |
1.3 |
b [start [end]] Binary memory dump |
182 |
|
|
|
183 |
|
|
displays the buffer contents from address "start" to address "end" in a binary |
184 |
|
|
format. Entering "b" without arguments is equivalent to "b .". The value of |
185 |
|
|
"." is set to the address after the last address displayed. |
186 |
|
|
|
187 |
|
|
|
188 |
cebix |
1.1 |
m [start [end]] Hex/ASCII memory dump |
189 |
|
|
|
190 |
|
|
displays the buffer contents from address "start" to address "end" as hex |
191 |
|
|
words and ASCII characters. Entering "m" without arguments is equivalent to |
192 |
|
|
"m .". The value of "." is set to the address after the last address displayed. |
193 |
|
|
|
194 |
|
|
|
195 |
|
|
d [start [end]] Disassemble PowerPC code |
196 |
|
|
|
197 |
|
|
disassembles the buffer contents from address "start" to address "end". |
198 |
|
|
Entering "d" without arguments is equivalent to "d .". The value of "." is |
199 |
|
|
set to the address after the last address displayed. |
200 |
|
|
|
201 |
|
|
|
202 |
cebix |
1.4 |
d65 [start [end]] Disassemble 6502 code |
203 |
cebix |
1.1 |
|
204 |
|
|
disassembles the buffer contents from address "start" to address "end". |
205 |
|
|
Entering "d65" without arguments is equivalent to "d65 .". The value of |
206 |
|
|
"." is set to the address after the last address displayed. |
207 |
|
|
|
208 |
|
|
|
209 |
cebix |
1.4 |
d68 [start [end]] Disassemble 680x0 code |
210 |
cebix |
1.1 |
|
211 |
|
|
disassembles the buffer contents from address "start" to address "end". |
212 |
|
|
Entering "d68" without arguments is equivalent to "d68 .". The value of |
213 |
|
|
"." is set to the address after the last address displayed. |
214 |
|
|
|
215 |
|
|
|
216 |
cebix |
1.8 |
d80 [start [end]] Disassemble Z80 code |
217 |
cebix |
1.1 |
|
218 |
|
|
disassembles the buffer contents from address "start" to address "end". |
219 |
|
|
Entering "d80" without arguments is equivalent to "d80 .". The value of |
220 |
|
|
"." is set to the address after the last address displayed. |
221 |
|
|
|
222 |
|
|
|
223 |
cebix |
1.6 |
d86 [start [end]] Disassemble 80x86 (32-bit) code |
224 |
cebix |
1.1 |
|
225 |
|
|
disassembles the buffer contents from address "start" to address "end". |
226 |
|
|
Entering "d86" without arguments is equivalent to "d86 .". The value of |
227 |
|
|
"." is set to the address after the last address displayed. |
228 |
cebix |
1.6 |
|
229 |
|
|
|
230 |
|
|
d8086 [start [end]] Disassemble 80x86 (16-bit) code |
231 |
|
|
|
232 |
|
|
disassembles the buffer contents from address "start" to address "end". |
233 |
|
|
Entering "d8086" without arguments is equivalent to "d8086 .". The value |
234 |
|
|
of "." is set to the address after the last address displayed. |
235 |
cebix |
1.1 |
|
236 |
|
|
|
237 |
|
|
: start string Modify memory |
238 |
|
|
|
239 |
|
|
puts the specified byte string at the address "start" into the buffer. The |
240 |
|
|
value of "." is set to the address after the last address modified. |
241 |
|
|
|
242 |
|
|
|
243 |
|
|
f start end string Fill memory |
244 |
|
|
|
245 |
|
|
fill the buffer in the range from "start" to (and including) "end" with the |
246 |
|
|
given byte string. |
247 |
|
|
|
248 |
|
|
|
249 |
|
|
y[b|h|w] start end expr Apply expression to memory |
250 |
|
|
|
251 |
|
|
works like the "fill" ("f") command, but it doesn't fill with a byte string |
252 |
|
|
but with the value of an expression that is re-evaluated for each buffer |
253 |
|
|
location to be filled. The command comes in three flavors: "y"/"yb" works on |
254 |
|
|
bytes (8-bit), "yh" on half-words (16-bit) and "yw" on words (32-bit). The |
255 |
|
|
value of "." is the current address to be modified, the value of ":" holds |
256 |
|
|
the contents of this address before modification. |
257 |
|
|
|
258 |
|
|
Examples: |
259 |
|
|
yw 0 fff :<<8 shifts all words in the address range 0..fff to the left |
260 |
|
|
by 8 bits (you can use this to convert bitmap data from |
261 |
|
|
ARGB to RGBA format, for example) |
262 |
|
|
y 0 1234 ~: inverts all bytes in the address range 0..1234 |
263 |
|
|
yh 2 ff 20000/. creates a table of the fractional parts of the reciprocals |
264 |
|
|
of 1..7f |
265 |
|
|
|
266 |
|
|
|
267 |
|
|
t start end dest Transfer memory |
268 |
|
|
|
269 |
|
|
transfers the buffer contents from "start" to (and including) "end" to "dest". |
270 |
|
|
Source and destination may overlap. |
271 |
|
|
|
272 |
|
|
|
273 |
|
|
c start end dest Compare memory |
274 |
|
|
|
275 |
|
|
compares the buffer contents in the range from "start" to (and including) |
276 |
|
|
"end" with the contents at "dest". The addresses of all different bytes and |
277 |
|
|
the total number of differences (decimal) are printed. |
278 |
|
|
|
279 |
|
|
|
280 |
|
|
h start end string Search for byte string |
281 |
|
|
|
282 |
|
|
searches for the given byte string in the buffer starting at "start" up to |
283 |
|
|
(and including) "end". The addresses and the total number of occurrences are |
284 |
|
|
displayed. The value of "." is set to the address of the first occurrence. |
285 |
|
|
|
286 |
|
|
|
287 |
|
|
\ "command" Execute shell command |
288 |
|
|
|
289 |
|
|
executes the given shell command which must be enclosed in quotes. |
290 |
|
|
|
291 |
|
|
|
292 |
|
|
ls [args] List directory contents |
293 |
|
|
|
294 |
|
|
works as the shell command "ls". |
295 |
|
|
|
296 |
|
|
|
297 |
|
|
rm [args] Remove file(s) |
298 |
|
|
|
299 |
|
|
works as the shell command "rm". |
300 |
|
|
|
301 |
|
|
|
302 |
|
|
cp [args] Copy file(s) |
303 |
|
|
|
304 |
|
|
works as the shell command "cp". |
305 |
|
|
|
306 |
|
|
|
307 |
|
|
mv [args] Move file(s) |
308 |
|
|
|
309 |
|
|
works as the shell command "mv". |
310 |
|
|
|
311 |
|
|
|
312 |
|
|
cd directory Change current directory |
313 |
|
|
|
314 |
|
|
works as the shell command "cd". The name of the directory doesn't have to be |
315 |
|
|
enclosed in quotes. |
316 |
|
|
|
317 |
|
|
|
318 |
|
|
o ["file"] Redirect output |
319 |
|
|
|
320 |
|
|
When a file name is specified, all following output is redirected to this |
321 |
|
|
file. The file name must be enclosed in quotation marks even if it contains |
322 |
|
|
no spaces. Entering "o" without parameters closes the file and directs the |
323 |
|
|
output into the terminal window again. |
324 |
|
|
|
325 |
|
|
|
326 |
|
|
[ start "file" Load data from file |
327 |
|
|
|
328 |
|
|
loads the contents of the specified file into the buffer starting from address |
329 |
|
|
"start". The file name must be enclosed in quotation marks even if it contains |
330 |
|
|
no spaces. The value of "." is set to the address after the last address |
331 |
|
|
affected by the load. |
332 |
|
|
|
333 |
|
|
|
334 |
|
|
] start size "file" Save data to file |
335 |
|
|
|
336 |
|
|
writes "size" number of bytes of the buffer from "start" to the specified file. |
337 |
|
|
The file name must be enclosed in quotation marks even if it contains no spaces. |
338 |
|
|
|
339 |
|
|
|
340 |
|
|
set [var[=value]] Set/clear/show variables |
341 |
|
|
|
342 |
|
|
If no arguments are given, all currently defined variables are displayed. |
343 |
|
|
Otherwise, the value of "var" is set to the specified value. If "=value" |
344 |
|
|
is omitted, the variable "var" is cleared. |
345 |
|
|
|
346 |
|
|
|
347 |
|
|
cv Clear all variables |
348 |
|
|
|
349 |
|
|
clears all currently defined variables. |
350 |
|
|
|
351 |
|
|
|
352 |
|
|
Examples |
353 |
|
|
-------- |
354 |
|
|
|
355 |
cebix |
1.8 |
Here are some simple examples for what is possible with cxmon. |
356 |
cebix |
1.1 |
|
357 |
|
|
Join "file1" and "file2" to "file3": |
358 |
|
|
|
359 |
|
|
[ 0 "file1" |
360 |
|
|
[ . "file2" |
361 |
|
|
] 0 . "file3" |
362 |
|
|
|
363 |
|
|
Remove the first 24 bytes (e.g. an unneeded header) of a file: |
364 |
|
|
|
365 |
|
|
[ 0 "file" |
366 |
|
|
] 18 .-18 "file" |
367 |
|
|
|
368 |
cebix |
1.8 |
Load the cxmon executable and search for PowerPC "nop" commands: |
369 |
cebix |
1.1 |
|
370 |
cebix |
1.8 |
[ 0 "cxmon" |
371 |
cebix |
1.1 |
h 0 . 60,00,00,00 |
372 |
|
|
|
373 |
cebix |
1.8 |
Create a modified version of cxmon so that the prompt has " $" instead of |
374 |
|
|
"->": |
375 |
cebix |
1.1 |
|
376 |
cebix |
1.8 |
[ 0 "cxmon" |
377 |
cebix |
1.1 |
set size=. |
378 |
|
|
h 0 . "->" |
379 |
|
|
: . " $" |
380 |
cebix |
1.8 |
] 0 size "cxmon1" |
381 |
cebix |
1.1 |
|
382 |
|
|
Convert a binary file which contains 16-bit numbers in little-endian format |
383 |
|
|
to big-endian format (or vice-versa): |
384 |
|
|
|
385 |
|
|
[ 0 "file" |
386 |
|
|
yh 0 .-1 :>>8|:<<8 |
387 |
|
|
] 0 . "file" |
388 |
|
|
|
389 |
|
|
Load a BeBox boot ROM image and start disassembling the system reset handler: |
390 |
|
|
|
391 |
|
|
[ 0 "bootnub.image" |
392 |
|
|
d 100 |
393 |
|
|
|
394 |
|
|
|
395 |
cebix |
1.9 |
Using cxmon in your own programs |
396 |
|
|
-------------------------------- |
397 |
|
|
|
398 |
|
|
cxmon provides a simple interface for integration in other programs. It can, |
399 |
|
|
for example, be used as a monitor/debugger for an emulator (it is used in |
400 |
|
|
Basilisk II in this way). |
401 |
|
|
|
402 |
|
|
Here's how to do it (all functions are defined in the mon.h header file): |
403 |
|
|
|
404 |
|
|
1. Link all the cxmon object files, except main.o, to your program. |
405 |
|
|
2. In your program, call mon_init() before using any other cxmon functions. |
406 |
|
|
3. After calling mon_init(), set the mon_read_byte and mon_write_byte |
407 |
|
|
function pointers to the routines used for accessing memory. |
408 |
|
|
4. You can use mon_add_command() to add new commands to cxmon by specifying |
409 |
|
|
the command name, function and help text. From within your command |
410 |
|
|
function, you can use mon_get_token() and mon_expression() to parse the |
411 |
|
|
arguments and the mon_read/write_*() functions to access memory. |
412 |
|
|
5. To enter cxmon, call the mon() function like this: |
413 |
|
|
|
414 |
|
|
char *args[3] = {"mon", "-r", NULL}; |
415 |
|
|
mon(2, args); |
416 |
|
|
|
417 |
|
|
6. If you're done with cxmon, call mon_exit(). |
418 |
|
|
|
419 |
|
|
|
420 |
cebix |
1.1 |
History |
421 |
|
|
------- |
422 |
|
|
|
423 |
cebix |
1.2 |
Please consult the file "ChangeLog" for the release history. |
424 |
cebix |
1.1 |
|
425 |
|
|
|
426 |
|
|
Christian Bauer |
427 |
cebix |
1.2 |
<Christian.Bauer@uni-mainz.de> |
428 |
cebix |
1.1 |
|
429 |
|
|
Marc Hellwig |
430 |
cebix |
1.2 |
<Marc.Hellwig@uni-mainz.de> |