Code Monkey home page Code Monkey logo

Comments (22)

aquynh avatar aquynh commented on July 17, 2024

On Thu, Dec 12, 2013 at 8:29 AM, radare [email protected] wrote:

capstone disassembles 74/75 opcode as 'je/jne' while other disassemblers
use 'jz/jnz'. In fact, both mnemonics are assembled as the same
instruction, so that's just an aesthetical issue.

I personally prefer the 'jz/jnz' form, should we change this? What's your
preference?

no difference, it is all the same to me. we might put this as one option
like CS_OPT* next version?

thanks,
Q

β€”

Reply to this email directly or view it on GitHubhttps://github.com//issues/36
.

from capstone.

radare avatar radare commented on July 17, 2024

Yep. if that’s not making the code much more complex that can be an option.

On 12 Dec 2013, at 02:19, Nguyen Anh Quynh [email protected] wrote:

no difference, it is all the same to me. we might put this as one option
like CS_OPT* next version?

from capstone.

mrexodia avatar mrexodia commented on July 17, 2024

In that case you should also take a look at the following jump mnemonics (this is taken from BeaEngine Update:

enum BRANCH_TYPE
{
    //JO vs JNO
    JO = 1,
    JNO = -1,
    //JC=JB=JNAE vs JNC=JNB=JAE
    JC = 2,
    JB = 2,
    JNAE = 2,
    JNC = -2,
    JNB = -2,
    JAE = -2,
    //JE=JZ vs JNE=JNZ
    JE = 3,
    JZ = 3,
    JNE = -3,
    JNZ = -3,
    //JA=JNBE vs JNA=JBE
    JA = 4,
    JNBE = 4,
    JNA = -4,
    JBE = -4,
    //JP=JPE vs JNP=JPO
    JP = 6,
    JPE = 6,
    JNP = -6,
    JPO = -6,
    //JL=JNGE vs JNL=JGE
    JL = 7,
    JNGE = 7,
    JNL = -7,
    JGE = -7,
    //JG=JNLE vs JNG=JLE
    JG = 8,
    JNLE = 8,
    JNG = -8,
    JLE = -8,
};

from capstone.

learn-more avatar learn-more commented on July 17, 2024

How would this be implemented?
An option per instruction, or one option to toggle all instructions to alternate names?
And how to handle the case of one instruction with 3 alternate names?

from capstone.

aquynh avatar aquynh commented on July 17, 2024

this can be done via the cs_option() API.

the idea is to define a new option (like CS_OPT_INSN_NAME), then let user pass the instruction ID & instruction name to it. then at run time, the printer will use this name for the corresponding instruction ID.

the implementation should not be too complicated.

from capstone.

mrexodia avatar mrexodia commented on July 17, 2024

Keep in mind that there should be like 10 options then, jz vs je is not the
only thing.
On 23 Apr 2015 15:30, "Nguyen Anh Quynh" [email protected] wrote:

this can be done via cs_option API.

the idea is to define a new option (like CS_OPT_INSN_NAME), then let
user pass the instruction ID & instruction name to it. then at run
time, the printer will use this name for the corresponding instruction.

the implementation should not be too complicated.

Reply to this email directly or view it on GitHub
#36 (comment).

from capstone.

aquynh avatar aquynh commented on July 17, 2024

surely yes, but then we run cs_option() 10 times, one for each of these instructions.

from capstone.

mrexodia avatar mrexodia commented on July 17, 2024

True, or maybe use a bit field?
On 23 Apr 2015 17:35, "Nguyen Anh Quynh" [email protected] wrote:

surely yes, but then we run cs_option() 10 times, one for each of these
instructions.

Reply to this email directly or view it on GitHub
#36 (comment).

from capstone.

aquynh avatar aquynh commented on July 17, 2024

Why? This is at the setup stage, so i dont see any issue calling this API even hundreds times. That does not affect performance or anything, so lets keep it simple.

from capstone.

mrexodia avatar mrexodia commented on July 17, 2024

Okay :)
On 23 Apr 2015 17:47, "Nguyen Anh Quynh" [email protected] wrote:

Why? This is at the setup stage, so i dont see any issue calling this API
even hundreds times. That does not affect performance or anything, so lets
keep it simple.

Reply to this email directly or view it on GitHub
#36 (comment).

from capstone.

learn-more avatar learn-more commented on July 17, 2024

yeah, my idea was to pass a struct that has the id & name the user wants for it then.
capstone will alloc it's own private copy of the struct, not sure where to store it yet, but ill find a nice place.

from capstone.

aquynh avatar aquynh commented on July 17, 2024

you can look at how the option CS_OPT_SKIPDATA_SETUP was implemented.

for keeping data, that should be inside the struct cs_struct (see file cs_priv.h).

thanks.

from capstone.

learn-more avatar learn-more commented on July 17, 2024

I was thinking of storing it somewhere in the internal lookup tables,
but that would mean it would have to be done for all arches separately.

In case that it's stored in the cs_struct, it would mean that when a few are selected, they would have to be iterated trough for each instruction.

from capstone.

aquynh avatar aquynh commented on July 17, 2024

lets consider this case: you create 2 engines (of X86), and each engine has different setups.
so cs_struct is the only place to keep them independent.

from capstone.

aquynh avatar aquynh commented on July 17, 2024

to replace the original mnemonic with the one you want, a good place is to do that in fill_insn() function in cs.c. this code works for all archs, so you do not need to do that separately.

from capstone.

aquynh avatar aquynh commented on July 17, 2024

so i implemented a new option CS_OPT_MNEMONIC to customize instruction mnemonic at run-time. this should support all 8 architectures Capstone has at the moment.

this code is now available in the mnem branch at https://github.com/aquynh/capstone/tree/mnem.

you can find how to use this option in the new test code test_customized_mnem.c at https://github.com/aquynh/capstone/blob/mnem/tests/test_customized_mnem.c.

below is the output of test_customized_mnem, which is intuitive & self explanatory.

Disassemble X86 code with default instruction mnemonic
75 01       jne 0x1003

Now customize engine to change mnemonic from 'JNE' to 'JNZ'
75 01       jnz 0x1003

Reset engine to use the default mnemonic
75 01       jne 0x1003

of course you should be able to run cs_option(CS_OPT_MNEMONIC) as many times as you want - so there is no limitation on the number of instructions you can customize.

let me know if you guys have any comment, thanks.

from capstone.

mrexodia avatar mrexodia commented on July 17, 2024

awesome solution! I think you can mark this issue as resolved πŸ‘

from capstone.

aquynh avatar aquynh commented on July 17, 2024

thanks. lets see if there are more comments before this is merged into the "next".

@mrexodia btw, can you answer my question on the issue #335? how did you create ".a" file for MingW?

from capstone.

radare avatar radare commented on July 17, 2024

Awesome! Will test it asap. I was also missing the jz namings..

On 26 Apr 2015, at 17:02, Nguyen Anh Quynh [email protected] wrote:

so i implemented a new option CS_OPT_MNEMONIC to customize instruction mnemonic at run-time. this should support all 8 architectures Capstone has at the moment.

this code is now available in the mnem branch at https://github.com/aquynh/capstone/tree/mnem.

you can find how to use this option in the new test code test_customized_mnem.c at https://github.com/aquynh/capstone/blob/mnem/tests/test_customized_mnem.c.

below is the output of test_customized_mnem, which is intuitive & self explanatory.

Disassemble X86 code with default instruction mnemonic
75 01 jne 0x1003

Now customize engine to change mnemonic from 'JNE' to 'JNZ'
75 01 jnz 0x1003

Reset engine to use the default mnemonic
75 01 jne 0x1003
of course you should be able to run cs_option(CS_OPT_MNEMONIC) as many times as you want - so there is no limit on how many instructions you can customize.

let me know if you guys have any comment, thanks.

β€”
Reply to this email directly or view it on GitHub.

from capstone.

aquynh avatar aquynh commented on July 17, 2024

i merged this "mnem" branch into the "next" branch.

Python binding support for new option CS_OPT_MNEMONIC is now ready: see sample code https://github.com/aquynh/capstone/blob/next/bindings/python/test_customized_mnem.py.

the "mnem" branch will be deleted.

from capstone.

aquynh avatar aquynh commented on July 17, 2024

some docs for this new option: http://capstone-engine.org/mnemonic.html

from capstone.

aquynh avatar aquynh commented on July 17, 2024

can you guys please join this related discussion: #342 ?

thanks.

from capstone.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.