ghidra icon indicating copy to clipboard operation
ghidra copied to clipboard

The CParser script chokes on character literals with \x escape sequences in it.

Open tfinnegan937 opened this issue 5 months ago • 0 comments

Describe the bug I was attempting to parse the headers for SDL2 using the parser tool. I updated the Visual Studio 2022 profile with my SDL2 headers and include directories, and then manually included all of the headers and include directories that the SDL2 windows solution would normally use.

The script crashes on SDL_keycode.h, in particular in parsing the SDL_Keycode enumeration struct. The enumeration value for the escape character is defined as such:

typedef enum
{
    SDLK_UNKNOWN = 0,

    SDLK_RETURN = '\r',
    SDLK_ESCAPE = '\x1B'

The parser would crash every time when parsing SDLK_ESCAPE unless I manually went into the header and replaced '\x1B' with the actual ASCII keycode, 0x1B in hex.

To Reproduce Steps to reproduce the behavior:

  1. Import a DLL for SDL2.
  2. Create a visual studio 2022 import profile for the headers
  3. Run the C Source Parser
  4. It will crash on any line containing a \x escape sequence in a character literal

Expected behavior The sources get imported successfully

Screenshots SDL2_VisualStudio2022_Local.txt

Attachments If applicable, please attach any files that caused problems or log files generated by the software.

Environment (please complete the following information):

  • OS: Windows 11
  • Java Version: 17.04
  • Ghidra Version: 11.01
  • Ghidra Origin: Official Github release

Additional context If I replace the offending character codes with raw hexadecimal literals, the parser completes successfully.

tfinnegan937 avatar Mar 15 '24 23:03 tfinnegan937