Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DOS debug like program for 32-bit x86 assembly

Many of you may recall the old DOS program--debug. Though outdated in many respects, one of the nice things about it was that one could easily find the byte-sequence for a given instruction without having to go through the steps of writing a program, compiling, disassembling, examining the file contents, .... Enter the instruction, then dump the instruction address. 'debug' regrettably does not do 32 bit instructions.

Does anyone know of a tool that does something similar for 32-bit x86 instructions? I don't want to go through the whole compile process; I just need to be able to enter a couple of instructions and have it spew out the length of the instruction and its byte sequence.

like image 762
Sparky Avatar asked Jul 08 '10 17:07

Sparky


2 Answers

DOS debug was an interactive assembler as well as a debugger, entering assembly code resulted in that line being converted immediately to machine code - which is what you dumped out.

So all you need is to automate your favourite assembler with a script or batch-file.

Here's a bash function I came up with in a minute or two using the popular nasm assembler:

opcode() {
  echo $* > tmp.S && nasm tmp.S -o tmp.o && od -x tmp.o
  rm -f tmp.o tmp.S
}

Takes less than a second. Invocation looks like this:

$ opcode mov eax, [ebx]
0000000 6667 038b
0000004
$ opcode fadd st0,st1
0000000 c1d8
0000002

Not brilliant, but you can tweak od command-line for better output. This idea should work with any command-line assembler as long as you tell it to use a simple binary output format.

like image 173
Greg Avatar answered Oct 05 '22 23:10

Greg


There are a few simple, 32-bit command line debuggers to be found. Based on your description, OllyDbg might fit your needs well. At least some versions of Microsoft's Debugging Tools for Windows include one named CDB, which stands for Commandline DeBugger (though I haven't verified that the linked version includes it...)

like image 41
Jerry Coffin Avatar answered Oct 06 '22 00:10

Jerry Coffin