From 9397116241069777614336493120489779020689 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Fri, 12 Dec 2025 02:14:32 -0500 Subject: Generator: Detect flag enums and use IntFlag instead Made possible by the new attributes in binja's type system. --- binaryninjacore.h | 5 ++++- 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()) -- cgit v1.3.1