-
Notifications
You must be signed in to change notification settings - Fork 6k
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
C Parser Does Not Parse A Simple Struct #1069
Comments
If you look in the CParserPlugin.out file, what is around line 392, and is there an actual definition for __uinit32_t before that use? |
@emteere Sure, the line 392 is the last line of the following snippet ("};")
I attached here the CParserPlugin.out as well (< 500 lines actually): |
The problem seems to be that
fails. But
parses successfully. The CParser seems to need lots of work. I'm not sure that you can get away with one grammar. As different compiler extensions use different keywords and language extensions, which in other dialects are not keywords and can be used as identifiers. EDIT: You can workaround the issue but adding @raymontag: If I have time I can try adding the XNU data types to my repo: https://github.com/0x6d696368/ghidra-data/tree/master/typeinfo |
Thanks for the workaround, worked! Unfortunetaly there are many more quirks, probably because XNU uses a lot of GCC extensions. @0x6d696368 At the moment, I try to parse everything from iokit/ (which involves most of the kernel code, though...) |
I actually already had the XNU source and now remember what the problem with it was back then: It is mostly C++ or ObjC. So can not be parsed with the CParser at all. You could parse the headers that declare |
@raymontag I recently learned you can populate a Data Type Archive from DWARF debug information. So you could try getting XNU DWARF info (e.g. https://github.com/argp/xnu cites it in the README) and generate the Data Type Archive this way ... even for C++ code. EDIT: It is a bit backwards to first build the whole XNU kernel to extract the Data Type info, but it's the only workaround I could come up with. Hope that helps. |
@0x6d696368 Thx, that sounds like a neat workaround! |
I would rate the CParserPlugin as nearly unusable. I was trying to generate headers for lua 5.3.5 and found whether I used VS or gcc for standard includes, it could not parse seemingly quite basic ifdef/end pairs (this is documented in other open issues for CParserPlugin) I did find a workaround. I created a custom header file that when parsed with gcc generates a pre-parsed header file that ghidra can consume successfully. gcc -E -dU -P -I".\src" -o luaTypes.gcc-E-dU.parsed.5.3.5.h luaTypes.gcc-E-dD.5.3.5.h Creating the custom header file is a little like porting to a new platform. I eliminated as many dependencies and unneeded attributes with strategic defines: #define __stdcall typedef void * va_list; /* platform independnt va_list / #include <stdarg.h> #define LUA_COMPAT_5_2 #include "lprefix.h" This was a giant pain, but I was able to produce a type archive with exactly what I needed in it. |
Describe the bug
I tried recently to parse certain data structures from the XNU kernel. I encountered a simple struct that could not be parsed.
The struct is defined in a XNU header file. All data types are of type
__uint32_t
which is atypedef
forunsigned int
.Interestingly, the parsing works if the type in the struct definition is changed to
unsigned int
. Therefore, I guess the parser cannot parse the type definition for some reason.More interestingly, the parser recognizes the the
__uint32_t
as valid.I tried this with 9.0.4 and 9.1-BETA.
Lines mentioned in the screenshot:
To Reproduce
Steps to reproduce the behavior:
xnu-4903.241.1/osfmk/mach/arm/_structs.h
3.1. You need to download the whole XNU tree from https://opensource.apple.com/tarballs/xnu/xnu-4903.241.1.tar.gz
Expected behavior
The header is parsed and added to the data type library.
Screenshots
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: