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

Creating New DataTypes from a Script #1986

Closed
jarodcsaxberg opened this issue Jun 14, 2020 · 1 comment
Closed

Creating New DataTypes from a Script #1986

jarodcsaxberg opened this issue Jun 14, 2020 · 1 comment

Comments

@jarodcsaxberg
Copy link

jarodcsaxberg commented Jun 14, 2020

Is there a way to create a new DataType from a script? Basically using the DataTypeManager's addDataType() function with a custom DataType that's created in the script, attempting to replicate the Data Type Manager -> New -> Typedef... from the GUI. I am working with an InternetOpenW function that is not recognized by ghidra, so it decompiles to undefined InternetOpenW(void). The goal is to be able to replicate the process of updating the function signature from a script through the use of custom DataTypes for any that Ghidra doesn't recognize, and the Function class's updateFunction() function. For example, creating the type HINTERNET that refers to void*

@jarodcsaxberg
Copy link
Author

Solved this by referencing #1916 and #993. Sample python code below.

from ghidra.app.util.cparser.C import CParser
from ghidra.program.model.data import DataTypeConflictHandler

dtm = currentProgram.getDataTypeManager()
parser = CParser(dtm)

new_dt = parser.parse("typedef void* HINTERNET;")

transaction = dtm.startTransaction("Adding new data")
dtm.addDataType(new_dt, None)
dtm.endTransaction(transaction, True)

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

No branches or pull requests

1 participant