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

PDB Can create DataVariable to types which don't exist #4235

Closed
NeoQuix opened this issue Apr 18, 2023 · 8 comments
Closed

PDB Can create DataVariable to types which don't exist #4235

NeoQuix opened this issue Apr 18, 2023 · 8 comments
Assignees
Labels
Component: DebugInfo Issue requires changes to the DebugInfo API DebugInfo: PDB Related to parsing PDB files Effort: Low Issue should take < 1 week Impact: Medium Issue is impactful with a bad, or no, workaround Type: Bug Issue is a non-crashing bug with repro steps
Milestone

Comments

@NeoQuix
Copy link

NeoQuix commented Apr 18, 2023

Version and Platform (required):

  • Binary Ninja Version: 3.4.4231-dev
  • OS: Arch Linux
  • OS Version: -
  • CPU Architecture: x64

Bug Description:
Can't access value property of an DataVariable because of ValueError: Couldn't find target for type.
Type is enum HRTType.

Steps To Reproduce:
With a python shell:

Python 3.10.10 (main, Mar  5 2023, 22:26:53) [GCC 12.2.1 20230201] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from binaryninja import BinaryViewType
>>> bv = BinaryViewType.get_view_of_file("esentutl.exe")
>>> dv = bv.get_data_var_at(0x140056c08)
>>> dv.value
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/.../BinaryNinja/python/binaryninja/binaryview.py", line 9228, in value
    return self._accessor.value
  File "/.../BinaryNinja/python/binaryninja/binaryview.py", line 9081, in value
    return self._value_helper(self.type, self.view.read(self.address, len(self.type)))
  File "/.../BinaryNinja/python/binaryninja/binaryview.py", line 9121, in _value_helper
    raise ValueError("Couldn't find target for type")
ValueError: Couldn't find target for type

Expected Behavior:
Access value of DataVariable

Additional Information:
Binary which produces errror: esentutl.tar.gz

@plafosse plafosse added the State: Intended Issue is actually intended behavior label May 30, 2023
@plafosse
Copy link
Member

The problem here is that the type at the DataVariable in question is a NamedTypeReference which points to a type which doesn't exist. I don't know how you got into this state but the code above is working as intended. This would be equivalent to a compiler error like if you had done:

typedef enum foobar HRTType;

and tried to compile it. You'd get a 'foobar' is not defined. My assumption is that you wrote a script to define this type and perhaps made a mistake. If however you were able to create this though the UI this would be a bug though not in the area that is pointed out in the code above.

@NeoQuix
Copy link
Author

NeoQuix commented Jul 11, 2023

Sry! Forgot to answer.

I get your point and it's totally valid if the type was set by a custom script.
But here the type HRTType is set by binary ninja itself, using the PDB debug information provided by microsoft.
If you have PDB enabled, even the GUI does not know the value of the variable at 0x140056c08.

grafik

@plafosse
Copy link
Member

Ah yes you're right then this is a bug. I've ran into this too. I thought there was already an issue for this bug but it looks like there isn't.

@plafosse plafosse reopened this Jul 11, 2023
@plafosse plafosse added Effort: Low Issue should take < 1 week Impact: Medium Issue is impactful with a bad, or no, workaround DebugInfo: PDB Related to parsing PDB files Component: DebugInfo Issue requires changes to the DebugInfo API and removed State: Intended Issue is actually intended behavior labels Jul 11, 2023
@plafosse plafosse added this to the Coruscant milestone Jul 11, 2023
@plafosse plafosse changed the title ValueError accessing DataVariable.value PDB Can create DataVariable to types which don't exist Jul 11, 2023
@fuzyll fuzyll added the Type: Bug Issue is a non-crashing bug with repro steps label Jul 12, 2023
@CouleeApps
Copy link
Member

CouleeApps commented Aug 8, 2023

This is the fault of the name demangler. The symbol hrtt aka ?hrtt@@3W4HRTType@@A has a raw name that demangles to HRTType hrtt, but the PDB does not contain the type HRTType and the demangler does not create an empty type on the view for it either.

Looks like there is no main issue for this (all of the ones i can find are specific to other weird cases). I'll go make one for it, I guess. Relevant: #3062 #2757

@CouleeApps
Copy link
Member

Potential solutions here are:

  1. Leave the broken demangler alone and make the PDB loader handle it
  2. Fix the demanglers and make them actually create used types (PDB will then need to detect this and overwrite with the real type if it gets one)

For the purposes of this issue, option 1 would solve it fastest. Option 2 is the longer term correct solution, though.

@CouleeApps
Copy link
Member

I've made #4551 to track the main issue for this. I'll leave this open as a band-aid solution for PDB is probably higher value-for-time than fixing the real problem right now.

@CouleeApps
Copy link
Member

This is being addressed for PDBs specifically in build >= 3.5.4455-dev. Referenced missing types will have empty structures and enums created when loading a PDB. The general issue #4551 remains open for now though.

@ccarpenter04
Copy link

Is there any chance the same solution could be implemented for DWARF debug data?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: DebugInfo Issue requires changes to the DebugInfo API DebugInfo: PDB Related to parsing PDB files Effort: Low Issue should take < 1 week Impact: Medium Issue is impactful with a bad, or no, workaround Type: Bug Issue is a non-crashing bug with repro steps
Projects
None yet
Development

No branches or pull requests

5 participants