Open brendabrandy opened 5 years ago
If you take a look at the C example on http://www.keystone-engine.org/ towards the bottom you'll see it mention You can either separate assembly instructions in this string by “;” or “\n”.
so I believe this is the intended behavior. I'm not a project member but I agree a patch to enable comments with a semicolon would be pretty useful.
@zeroSteiner commented on Feb 6, 2019:
I agree a patch to enable comments with a semicolon would be pretty useful.
+1
This is clearly a problem. Here is a python3 method that allow you to deal with this:
def clean_assembly_code(asm_code: str) -> str:
"""
Cleans assembly code by stripping comments and unnecessary semicolons, while preserving indentation and line breaks.
Args:
asm_code (str): The original assembly code as a string.
Returns:
str: The cleaned assembly code with indentation preserved.
"""
cleaned_lines = []
for line in asm_code.splitlines():
# Split line at first semicolon (for comments) and keep only the instruction part
code = line.split(";", 1)[
0
].rstrip() # Strip trailing spaces from the code part
if code: # Only include non-empty lines
cleaned_lines.append(code)
# Join cleaned lines, preserving original newlines and indentation
return "\n".join(cleaned_lines)
When I use kstool to assemble the following instruction with a comment, I got an error:
but it worked properly without a comment:
Is there an expected syntax for commenting for keystone, or keystone cannot differentiate between comments and operands of an instruction? If so, I'd like to submit a patch to support inline comments.