Skip to content

Add Patch Address bytecode #57

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ShallowFeather
Copy link

I notice that it can't patch the assembly, so I add it.
It can be used to deobfuscate some simple obfuscate, like the sample in

Apr.22.2025.mp4

Copy link
Owner

@mrexodia mrexodia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! Some changes will be necessary before merging.

@@ -915,7 +932,7 @@ def set_function_prototype(
raise IDAError(f"Failed to apply type")
refresh_decompiler_ctext(func.start_ea)
except Exception as e:
raise IDAError(f"Failed to parse prototype string: {prototype}")
raise IDAError(f"Failed to parse prototype string: {prototype}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary change

bytecode: Annotated[str, "Array of bytecode to patch the instruction with"],
) -> str:
"""Patch Address Assemble"""
ea = int(address, 16)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use parse_address like the other functions

@idawrite
def patch_address_bytecode(
address: Annotated[str, "Address of the instruction to patch"],
bytecode: Annotated[str, "Array of bytecode to patch the instruction with"],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The term bytecode is probably not the most descriptive. Better to write something like: Array of hex bytes (separated with spaces) to patch. Example: 11 22 33 44

@jsonrpc
@idawrite
def patch_address_bytecode(
address: Annotated[str, "Address of the instruction to patch"],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This address has nothing to do with instructions.

@mrexodia
Copy link
Owner

From watching the video it looks like this relies on the LLM to automagically generate instruction bytes. I am a bit hesitant to merge functionality like this, because it is prone to hallucinations. You would have to use another MCP to assemble using keystone and get the bytes that way.

@ShallowFeather
Copy link
Author

I'm not entirely sure if this project would want to introduce external libraries like Keystone for implementation, which is why I directly used bytecode as input. Initially, I was looking into whether IDApython had an interface to achieve this functionality, but I only found methods for patching by inputting bytecode.

@mrexodia
Copy link
Owner

No, the IDA plugin should not have any dependencies. I think it should be part of #54 as write_bytes, but the design is still a bit unclear to me…

Another option is to add keystone as a dependency to the MCP server itself, but I’m not the biggest fan of that either. Will think about it and get back to you!

In the meantime I suggest you code up a simple keystone-mcp, I can link it in the readme.

@williballenthin
Copy link
Contributor

williballenthin commented Apr 22, 2025

@ShallowFeather
Copy link
Author

Thanks @williballenthin, I edited it to patch_address_assemble
But I notice that the patch will not be only one line maybe have to add function for multiline patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants