keystone-engine / keystone

Keystone assembler framework: Core (Arm, Arm64, Hexagon, Mips, PowerPC, Sparc, SystemZ & X86) + bindings
http://www.keystone-engine.org
GNU General Public License v2.0
2.31k stars 459 forks source link

MASM Support #319

Open ericmichael opened 7 years ago

ericmichael commented 7 years ago

Is MASM support a coming feature? In the code it is mentioned but currently unsupported.

This would be a great feature since many universities use the "Assembly Language for x86 Processors, 7th edition" textbook which is written for MASM syntax.

With this support many great education tools could exist (in combination with Unicorn) to benefit students.

mrfearless commented 7 years ago

I created a while ago some include files for use with masm x86 and for jwasm/uasm x64 assemblers. Ive updated them and done a pull request to include bindings/masm folder with them inside it, hopefully that will help.

Additionally I couldnt see a way of compiling the keystone dll to x64, maybe needs an additional target under the llvm to support that. In the past I took the x86 and x64 dll and lib files for keystone from the x64dbg snapshots and used them.

ericmichael commented 7 years ago

I’m still new to this project. Barely stumbled upon it recently.

Is your PR adding bindings so that the keystone engine can be called from MASM and other assemblers?

What I was wondering about initially was whether the engine supported compilation of assembly (with MASM syntax)?

Sorry if my terminology isn’t very clear (new to this software).

mrfearless commented 7 years ago

Yes @ericmichael, the include files will allow you to use the keystone with masm and other assemblers, here is a basic example of usage using the ks_version function:

Include keystone_x86.inc ; keystone include file
Includelib keystone_x86.lib ; keystone library file (requires keystone.dll)

Invoke ks_version, NULL, NULL ; returns version in eax
mrfearless commented 7 years ago

I found an issue with using the masm x86 binding with keystone.

I was getting an access violation with some sample code using ks_asm. I found that if the address parameter is changed to size_t instead of unit64_t for ks_asm and recompiled (changing the keystone.h definition and the ks_priv.cpp paramters) then calling ks_asm with x86 assembler (masm) worked fine. Not sure the correct way of handling that to accommodate both x86 and x64 as c/c++ isnt my main language.

mrfearless commented 7 years ago

I have updated the keystone_x86.inc to handle the third parameter of ks_asm as a qword sized parameter now, and updated KSExample_x86 to show how this is handled.