Skip to content

Conversation

@Schamper
Copy link
Member

@Schamper Schamper commented Jul 18, 2025

Fixes #132.

Allows more easy copy/pasting from Microsoft and other structure definitions such as:

typedef struct _IMAGE_DATA_DIRECTORY {
    DWORD VirtualAddress;
    DWORD Size;
} IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;

With this PR it correctly parses IMAGE_DATA_DIRECTORY and *PIMAGE_DATA_DIRECTORY.

@codecov
Copy link

codecov bot commented Jul 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.74%. Comparing base (df4b134) to head (70898f7).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #131   +/-   ##
=======================================
  Coverage   92.73%   92.74%           
=======================================
  Files          21       21           
  Lines        2381     2384    +3     
=======================================
+ Hits         2208     2211    +3     
  Misses        173      173           
Flag Coverage Δ
unittests 92.74% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Miauwkeru
Copy link
Contributor

With the example you gave, this change will create the following stubfile:

# Generated by cstruct-stubgen
from typing import BinaryIO, Literal, overload

import dissect.cstruct as __cs__
from typing_extensions import TypeAlias

class _c_func(__cs__.cstruct):
    class _IMAGE_DATA_DIRECTORY(__cs__.Structure):
        VirtualAddress: _c_func.uint32
        Size: _c_func.uint32
        @overload
        def __init__(self, VirtualAddress: _c_func.uint32 | None = ..., Size: _c_func.uint32 | None = ...): ...
        @overload
        def __init__(self, fh: bytes | memoryview | bytearray | BinaryIO, /): ...

    IMAGE_DATA_DIRECTORY: TypeAlias = _IMAGE_DATA_DIRECTORY
    class _IMAGE_DATA_DIRECTORY*(__cs__.Pointer): ...

# Technically `c_func` is an instance of `_c_func`, but then we can't use it in type hints
c_func: TypeAlias = _c_func

I would expect something like the following instead.

PIMAGE_DATA_DIRECTORY: TypeAlias = Pointer[_IMAGE_DATA_DIRECTORY]

Could you fix this and add a test for it?

@Schamper Schamper requested a review from Miauwkeru July 30, 2025 09:22
@Schamper Schamper merged commit 01afa28 into main Jul 30, 2025
25 checks passed
@Schamper Schamper deleted the typedef-pointer branch July 30, 2025 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Combined name and pointer typedef doesn't work

3 participants