1

Is it possible to automatically translate x86 assembly code snippet (not full program) to corresponding binary machine code snippet?

For example:

xor eax, eax
mov [ebx + 12], eax

into:

31 c0
89 43 0c

I really need only corresponding set of bytes. Normally I would have to look into some instructions set reference and translate it manually, but I'm quite sure that there is some program that does it automatically.

If you know such tool, please tell me its name or share a link.

3
  • 1
    This makes little sense, an assembler takes opcode mnemonics, like your first snippet. And produces bytes. There is no product named "Visual Studio assembler". Commented Jan 24, 2014 at 19:21
  • Ok sorry, I meant that resulting code should be compatible with VS executable (can be injected for example), but of course there is only one translation from assembler to machine code. Commented Jan 24, 2014 at 19:30
  • Is dumppe.exe what you are looking for? using the methods i outline in my answer on this question? (i don't really want to write all that out because i i may be off the mark) Commented Jan 25, 2014 at 6:02

4 Answers 4

3

I did a workaround to my problem. It works on Windows platforms and uses ML64 assembler that goes with Visual Studio. I created a template.asm file with this template:

    .code

main proc
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop

; -------------------------------------------
; enter assembly code here
; -------------------------------------------

    mov [ebx + 12], eax
    xor eax, eax

; -------------------------------------------

    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
main endp

end

Then I have compiled it with:

ml64 /c template.asm

Knowing that nop instruction is translated to 0x90 I can write a program that searches for bytes between two blocks of 10 x 0x90 bytes.

Sign up to request clarification or add additional context in comments.

Comments

0

I know of two major assemblers: NASM and MASM

There are several notation variants of assembler, as far as I know MASM is more compatible with the VS syntax.

These generate machine code from assembly. If you want to view the Hex bytes, use your preferred hex editor.

I only worked with NASM under Windows so far, so I can't tell you anything about the VS integration, but generally an assembler should be the tool you're using.

1 Comment

Thanks for help. Your answer wasn't exactly what I was looking for, but it inspired me to compile code myself using assembler and add some code markers (nop instructions as stated in my answer) to easy find the code. Thanks!
0

I had a similar situation to this. My solution would only work with the gcc toolchain, though.

Let's say that you have your assembly in code.s, then the following would work:

$ gcc -c code.s && ld -o output.bin code.o --oformat=binary -Ttext=0 2>/dev/null && rm code.o

In output.bin you would have your assembled instructions. If you want them in hex format, you could do the following (only works for Linux, or systems with xxd):

$ xxd -p output.bin

Comments

0

You can use fasm for that. It can compile self-contained snippets of assembly code into binary file. Pretty useful.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.