keystone icon indicating copy to clipboard operation
keystone copied to clipboard

option for default hex number parsing

Open mrexodia opened this issue 9 years ago • 40 comments

It would be great if there was an option/syntax to override number parsing. With this option all numbers are interpreted as hex (mov eax, 01334000 assembles to mov eax, 0x1334000 instead of mov eax, 0x5B800).

mrexodia avatar Apr 29 '16 05:04 mrexodia

sorry but i think input like what you want is really confused. you save 2 characters, but get back little.

would be better to force the input to be in a correct clean format

aquynh avatar Apr 29 '16 10:04 aquynh

It's not about saving characters. The reason is that x64dbg uses hex per default for everything (the only sensible option when dealing with assembly in my opinion) and I want to mimic that behavior without having to write a parser that converts everything manually. On Fri, 29 Apr 2016 at 12:20, Nguyen Anh Quynh [email protected] wrote:

sorry but i think input like what you want is really confused. you save 2 characters, but get back little.

would be better to force the input to be in a correct clean format

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/keystone-engine/beta/issues/11#issuecomment-215678201

mrexodia avatar Apr 29 '16 10:04 mrexodia

i see. lets see if other people also want this option.

aquynh avatar Apr 29 '16 16:04 aquynh

I'm not saying this should be implemented, but just for perspective / historical reference: Microsoft's masm assembler supported this using the .radix 16 directive, borland's turbo assembler used the radix 16 directive and the GNU GASP assembly preprocessor also seems to support .RADIX 16.

iksteen avatar May 07 '16 22:05 iksteen

Multiple people have requested this option in the x64dbg issue tracker now.

mrexodia avatar Sep 09 '16 07:09 mrexodia

is it possible for x64dbg to stick 0x in front of every immediate, before feeding assembly code to Keystone?

aquynh avatar Sep 09 '16 08:09 aquynh

Yes, but that would require x64dbg to parse assembly, which is undesired.

mrexodia avatar Sep 09 '16 08:09 mrexodia

will see when i can do this.

aquynh avatar Sep 09 '16 08:09 aquynh

what can be the name of this option, in the form of KS_OPT_SYNTAX_xxx?

aquynh avatar Sep 09 '16 08:09 aquynh

It could be a directive in the assembler like suggested, or a random option name. Maybe_RADIX16 On Fri, 9 Sep 2016 at 10:57, Nguyen Anh Quynh [email protected] wrote:

what can be the name of this option, in the form of KS_OPT_SYNTAX_xxx?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/keystone-engine/keystone/issues/11#issuecomment-245858190, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWCmeNEBRiAqxh7Rh43m-1NRtOWVB6gks5qoR9_gaJpZM4ISiej .

mrexodia avatar Sep 09 '16 09:09 mrexodia

what does RADIX stand for?

aquynh avatar Sep 09 '16 09:09 aquynh

Just the number base. On Fri, 9 Sep 2016 at 11:16, Nguyen Anh Quynh [email protected] wrote:

what does RADIX stand for?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/keystone-engine/keystone/issues/11#issuecomment-245862270, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWCmeu2BAUwoJQoyAp6JCk1RXDlPpYxks5qoSPVgaJpZM4ISiej .

mrexodia avatar Sep 09 '16 09:09 mrexodia

Ok, KS_OPT_SYNTAX_RADIX16 is a good name.

aquynh avatar Sep 09 '16 11:09 aquynh

done, see https://github.com/keystone-engine/keystone/commit/eac9cc9d6712c4417ce57cb0aedeb8f0a39667c5 (including some samples on KS_OPT_SYNTAX_RADIX16 in samples/sample.c)

aquynh avatar Sep 09 '16 18:09 aquynh

Okay, I will test it as soon as possible! On Fri, 9 Sep 2016 at 20:07, Nguyen Anh Quynh [email protected] wrote:

done, see eac9cc9 https://github.com/keystone-engine/keystone/commit/eac9cc9d6712c4417ce57cb0aedeb8f0a39667c5 (including some samples on KS_OPT_SYNTAX_RADIX16 in samples/sample.c)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/keystone-engine/keystone/issues/11#issuecomment-245992930, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWCmTBDgyHpNRxP0hV8DSOEwM56PfwKks5qoaBugaJpZM4ISiej .

mrexodia avatar Sep 09 '16 21:09 mrexodia

do you have any issues with this new option?

aquynh avatar Sep 23 '16 03:09 aquynh

No, I have been very busy with University. It's still on my backlog. On Fri, 23 Sep 2016 at 05:54, Nguyen Anh Quynh [email protected] wrote:

do you have any issues with this new option?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/keystone-engine/keystone/issues/11#issuecomment-249096484, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWCmWBtsGqtPJXc7cnN1Zvm6d8XrQt4ks5qs01jgaJpZM4ISiej .

mrexodia avatar Sep 23 '16 03:09 mrexodia

Okay, so I tested and it does work for decimal constants mov eax,123 assembles to mov eax,0x123 but you can still not use hexadecimal values in the constant, so mov eax,abc fails with error 144.

mrexodia avatar Sep 23 '16 22:09 mrexodia

Because in this case Keystone does not know abc is label, or constant.

aquynh avatar Sep 23 '16 23:09 aquynh

Well then what is the point of a radix16 option jf you cannot enter hex numbers? On Sat, 24 Sep 2016 at 01:14, Nguyen Anh Quynh [email protected] wrote:

Because in this case Keystone does not know abc is label, or constant.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/keystone-engine/keystone/issues/11#issuecomment-249323362, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWCmZ0HrpYGPZzvSPhRK18MXbOLoVkKks5qtF1AgaJpZM4ISiej .

mrexodia avatar Sep 23 '16 23:09 mrexodia

This case is ambigous: how do you know abc is label, or number??

aquynh avatar Sep 23 '16 23:09 aquynh

I don't know how keystone handles this but the radix16 option has to be requested so it's safe to assume that it's not a label. In x64dbg hex number have priority over labels, so a label beef will resolve to 0xBEEF and not the label address because that's the desired behavior.

mrexodia avatar Sep 23 '16 23:09 mrexodia

How masm & gas handle this case with radix16 directive?

aquynh avatar Sep 23 '16 23:09 aquynh

MASM requires a 0 in front of the number. I disagree with this though, my suggestion is to assume it is a number if it is a valid hex number sequence, or if that's too edgy, check if it's a label and change it to a number if assembling with that fails.

mrexodia avatar Sep 23 '16 23:09 mrexodia

Masm does it right: you must avoid ambiguous, dont confuse your users. So i would suggest you take the same approach for x64dbg

aquynh avatar Sep 24 '16 00:09 aquynh

I disagree, zero prefixed numbers are also used for octal. If you don't want to implement it, feel free to close the issue, but there is absolutely no ambiguity here there are no labels present in single instruction assembling. On Sat, 24 Sep 2016 at 02:12, Nguyen Anh Quynh [email protected] wrote:

Masm does it right: you must avoid ambiguous, dont confuse your users. So i would suggest you take the same approach for x64dbg

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/keystone-engine/keystone/issues/11#issuecomment-249330066, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWCmQx737CQhUdDJXNkHtEb3BuSFWF1ks5qtGsJgaJpZM4ISiej .

mrexodia avatar Sep 24 '16 00:09 mrexodia

Think about that: if in your code has a label "abc", then this instruction confuses your own user, no?

aquynh avatar Sep 25 '16 07:09 aquynh

External labels are not supported by keystone anyway right? And no it doesn't confuse users it has been the default behavior for three years. On Sun, 25 Sep 2016 at 09:58, Nguyen Anh Quynh [email protected] wrote:

Think about that: if in your code has a label "abc", then this instruction confuses your own user, no?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/keystone-engine/keystone/issues/11#issuecomment-249408462, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWCmZbEtGlyhQrhkEb_ycg-1HXSYz94ks5qtimZgaJpZM4ISiej .

mrexodia avatar Sep 25 '16 09:09 mrexodia

symbols will be supported with a new API, but that is another story.

in case the code has both label "abc" & "mov eax, abc", how do they know what this instruction mean?

aquynh avatar Sep 27 '16 00:09 aquynh

They don't, but since you explicitly choose for hexadecimal numbers you can safely assume that the user wants 0xabc when seeing "abc" On Tue, 27 Sep 2016 at 02:00, Nguyen Anh Quynh [email protected] wrote:

symbols will be supported with a new API, but that is another story.

in case the code has both label "abc" & "mov eax, abc", how do they know what this instruction mean?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/keystone-engine/keystone/issues/11#issuecomment-249731821, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWCmZOcpKOIcJ5rxx53sig7UnN1QAt-ks5quFywgaJpZM4ISiej .

mrexodia avatar Sep 27 '16 01:09 mrexodia