Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to set/change default formatter options #488

Open
Symbai opened this issue Dec 3, 2023 · 2 comments
Open

Add a way to set/change default formatter options #488

Symbai opened this issue Dec 3, 2023 · 2 comments
Labels
C# enhancement New feature or request

Comments

@Symbai
Copy link
Contributor

Symbai commented Dec 3, 2023

Currently Instruction.ToString() formats the instruction with default formatter options. To customize we currently have to write many lines of code. Plus we have to create a custom FormatOutput class. While this can be useful in many cases its cumbersome when performance doesn't matter.

Alternatively a new method FormatToString() for the formatter classes which at least removes the step of creating a formatoutput class ourselves. Edit: To clarify we can use the StringOutput. But if you want to output multiple instructions from multiple places you would either have to call Reset all the time or create multiple StringOutput etc. which is what I meant with cumbersome

This request is for C#

@wtfsck
Copy link
Member

wtfsck commented Dec 5, 2023

Sounds reasonable. The Python code already supports this where you can pass in extra formatter args. A new ToString(string) method would be needed in C# to do something similar.

# ====== =============================================================================
# F-Spec Description
# ====== =============================================================================
# f      Fast formatter (masm-like syntax)
# g      GNU Assembler formatter
# i      Intel (XED) formatter
# m      masm formatter
# n      nasm formatter
# X      Uppercase hex numbers with ``0x`` prefix
# x      Lowercase hex numbers with ``0x`` prefix
# H      Uppercase hex numbers with ``h`` suffix
# h      Lowercase hex numbers with ``h`` suffix
# r      RIP-relative memory operands use RIP register instead of abs addr (``[rip+123h]`` vs ``[123456789ABCDEF0h]``)
# U      Uppercase everything except numbers and hex prefixes/suffixes (ignored by fast fmt)
# s      Add a space after the operand separator
# S      Always show the segment register (memory operands)
# B      Don't show the branch size (``SHORT`` or ``NEAR PTR``) (ignored by fast fmt)
# G      (GNU Assembler): Add mnemonic size suffix (eg. ``movl`` vs ``mov``)
# M      Always show the memory size (eg. ``BYTE PTR``) even when not needed
# _      Use digit separators (eg. ``0x12345678`` vs ``0x1234_5678``) (ignored by fast fmt)
# ====== =============================================================================

@wtfsck wtfsck added enhancement New feature or request C# labels Dec 5, 2023
@Symbai
Copy link
Contributor Author

Symbai commented Dec 8, 2023

new ToString method would be a solution but setting the default formatter allows things like binding in WPF without an additional property or custom converter.

Like a static property we can override:

Iced.Intel.Formatter.Default = new MasmFormatter(...)

and the existing ToString() just uses Iced.Intel.Formatter.Default then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants