Use int as basis for CvdumpTypeKey#315
Merged
disinvite merged 34 commits intoisledecomp:masterfrom Feb 13, 2026
Merged
Conversation
Fix tests to account for this (including INT types using 'i' for struct unpack)
jonschz
approved these changes
Feb 8, 2026
Collaborator
jonschz
left a comment
There was a problem hiding this comment.
Looks very good, this is a big improvement to the code quality!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #211.
This is a huge change and it could easily be split into a few smaller ones if needed.
Intro
Type keys are used throughout the
TYPESsection of cvdump, along with other sections that refer to a type, such asSYMBOLSandGLOBALS. They come in three forms:T_NOTYPE(0000)???(047C)0x1234Until now we have used a string representation for this key, but the use of upper or lower-case hex digits is not consistent. We use the
normalize_type_idfunction to handle this, but also manually convert usingstr.lower()in many spots. #203 added theCvdumpTypeKeyannotation but this was just an alias forstrso it was not checked withmypy.The obvious improvement is to exploit the fact that scalar types occupy the range from
0x0000to0x1000, so the key could just be anint. The obstacle there is that we depend on the string version of theT_*scalar types to decide the type's footprint and other attributes.cvinfo.hcontains bit-shifting macros that do this using integers. Considering that the range of scalar types is only 10% full (about 300 total) it is reasonable to use const data for this instead of calculating it on the fly.This change
All scalar types now have
CvInfoTypetuples in a new filecvinfo.py, which includes the type's size and format chars forstruct.unpack.CvdumpTypeKeyis now a class that extendsintsomypywill type check it. We need to make sure it is anintwhen storing in the Entity DB and convert back toCvdumpTypeKeywhen reading data back. For now, this happens automatically, but we could use conversion methods too.The parametrized tests in
test_cvdump.pymay not have much value now that we store the type attributes directly incvinfo.py. One change to test data is thatfloatanddoubleare now considered unsigned to matchcvinfo.h. The only impact was the choice of format char, but we now store this directly rather than computing it.On the topic of
struct.unpackformat chars, I decided to usei/Ifor theINTtypes andl/LforLONG. We had previously usedl/Lfor any 4-byte integer. This is more of a style thing and I don't expect any practical difference.CvdumpTypeKey.from_str()replacesnormalize_type_idand it's used everywhere we need to convert a type key. Similarly, theis_scalar()function replaces magic string checks for the"T_"prefix.Because
CvdumpTypeKeyis now a class, we need to use it to initialize anyintvariable that will serve as a type key. This change is most prevalent in unit tests.Similarly, whenever we need to refer to a specific type, there is an
Enumbased onCvdumpTypeKey. This is created dynamically withtypes.new_classto save space.The Ghidra scripts use the string representation of scalar types to decide which Ghidra primitive to use, and to add a
*for pointers. We can access theT_string in theCvInfoTypetuple so the conversion should be the same.I fixed a bug with
LF_ENUMwhere forward refs were not followed. Forward refs have an underlying type ofT_NOTYPE(0000)but this slipped by unnoticed because we assumed a size of 4 most types.Fixed another bug: we did not correctly handle type keys larger than
0xffffbecause they use more characters than expected.Future
Some types might be handled incorrectly in the new system, but we won't know for sure until we see them in a PDB. I marked most scalar types with a
weirdattribute and the logger will display an info message if we see any.It is probably time to separate cvdump text parsing from the general type database.
Not all data is exposed through the
get()API and we need to access thekeysdict directly. e.g. We don't store modifiers likeconstorvolatileor the destination type of pointers. See #106.test_cvdump_types.pyis now over 1000 lines, so I added thepylint:disableoption for now. The problem is that we need the huge blocks of text to set up the parser, but this could probably be broken out into tests for each leaf type.