Add function signature reconstruction for Issue #14#79
Conversation
- Parse FuncType metadata to extract input/output parameter types - Build C-style function pointer typedefs with proper signatures - Handle variadic functions and multiple return values - Add infrastructure in IDA script to receive function types - Emit CReconstructed field for Func types in JSON output This enables IDA to import function signatures as types, laying groundwork for applying types to function arguments/locals.
|
@stevemk14ebr Hello based on your review, here is the remaining checklist for the next commit. let me know if I missed anything.
|
|
I like where this is going! We can do better with the arg type and return type parsing though. Checkout this case This function takes 2 inputs, has 1 output, and the types of all 3 are present. Our reconstructed typedef is I'd expect the CStr to be So there's some formatting issues with the reconstruction, but the raw parsing logic seems mostly working! I agree with all the follow on work points, especially about tests. For multiple return values we can use either structures or tuples, the project uses structures now, but IDA recently added tuples for Go so lets prefer those for this function type work. https://hex-rays.com/blog/stop-guessing-and-start-going Actually applying these signatures via IDA scripting can be quite tricky since the types recursively depend on other types. I am completely ok with not having the IDA script implemented for now. I care most about reasonable and correct symbol recovery. We can do the IDA script work later. |
Fix param array offset from baseSize+4 to baseSize+ptrSize to account for struct padding on 64-bit. Add tflagUncommon handling (+16 bytes). Reformat CStr as "returnType (params)", add Reconstructed with Go syntax, fix CReconstructed with actual parsed types and clean funcptr name. Collect both Go and C type names during param parsing.
|
The CStr output formatting is inconsistent. See this case: The type recovery indicates 2 output arguments, but the CStr reconstruction is |
Handle multiple returns using tuple syntax in CStr field. For func() (int, bool), CStr now shows 'tuple(int32, bool) (void)' instead of incorrectly showing 'void (void)'.
|
@stevemk14ebr Hello, just dropping by to remind you about the pr. |
|
Hi, have other work taking priority I will review when able, thanks! |
|
@stevemk14ebr Hello dropping by again for review whenever convenient |
|
@stevemk14ebr Hello can you please review this as well? |
|
I'm aware of this, this one's a bit bigger so I have to set aside some time to review with the focus needed |
|
Hello @kami922 and @stevemk14ebr, I was reading through this PR and noticed one issue that doesn't appear to have been addressed yet. However, origCStr is captured after the fallback (_type).CStr = "void" at the top of the Func case, but before the real CStr is computed. This means origCStr is always "void*", so every func typedef ends up named void_funcptr regardless of its actual signature — rather than something like func_unsafe_Pointer__unsafe_Pointer_bool_funcptr as shown in @stevemk14ebr's review example. The name should be derived from _type.Str (sanitized) instead. |
…pply-structs merging latest changes
Test CStr output for multi-return function types using naturally occurring types from stdlib (io.Writer, fmt package usage): - func([]uint8) (int, error) asserts tuple(int, error) format - func() (int, bool) asserts tuple( syntax for multi-return Verified passing across all 22 Go versions (1.5-1.26)
|
@stevemk14ebr I have added tests. these are for I had planned for implementing variadic function but I don't think they occur in test binaries. |
|
Some minor adjustments I'd like:
It would be better if our tests were more complete, and looking for more than just the presence of some correct types, but I recognize this is a difficult thing to test so I will not require more precise tests for this feature. |
- Remove trailing whitespace in objfile.go (gofmt lint fix) - Add test assertions for Func types containing unsafe_Pointer and _ptr_ in CStr to catch breakage in recursive type parsing
|
@stevemk14ebr Hello addressed in new commit let me know what to do next. |
|
@kami922 please either complete |
closes #14