diff options
| author | Glenn Smith <glenn@vector35.com> | 2025-12-12 02:14:32 -0500 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2025-12-12 15:26:24 -0500 |
| commit | 9397116241069777614336493120489779020689 (patch) | |
| tree | 15820c2f83ba8763680c153157c3ce680d1c617d | |
| parent | 0238488101541494701887783104734147250961 (diff) | |
Generator: Detect flag enums and use IntFlag instead
Made possible by the new attributes in binja's type system.
| -rw-r--r-- | binaryninjacore.h | 5 | ||||
| -rw-r--r-- | python/generator.cpp | 6 |
2 files changed, 9 insertions, 2 deletions
diff --git a/binaryninjacore.h b/binaryninjacore.h index f1f29cbe..8b26fb44 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -86,7 +86,10 @@ #endif // Define attributes for enums based on compiler support -#if __has_attribute(enum_extensibility) +#if defined(BN_TYPE_PARSER) + #define __BN_ENUM_ATTRIBUTES + #define __BN_OPTIONS_ATTRIBUTES __attr("options") +#elif __has_attribute(enum_extensibility) #define __BN_ENUM_ATTRIBUTES __attribute__((enum_extensibility(open))) #define __BN_OPTIONS_ATTRIBUTES __attribute__((flag_enum, enum_extensibility(open))) #else diff --git a/python/generator.cpp b/python/generator.cpp index 50cfe073..96b74d90 100644 --- a/python/generator.cpp +++ b/python/generator.cpp @@ -381,7 +381,11 @@ int main(int argc, char* argv[]) } fprintf(out, "%sEnum = %s\n", name.c_str(), ctypesType); - fprintf(enums, "\n\nclass %s(enum.IntEnum):\n", name.c_str()); + if (i.second->GetAttribute("options").has_value()) + fprintf(enums, "\n\nclass %s(enum.IntFlag):\n", name.c_str()); + else + fprintf(enums, "\n\nclass %s(enum.IntEnum):\n", name.c_str()); + for (auto& j : i.second->GetEnumeration()->GetMembers()) { if (i.second->IsSigned()) |
