Skip to content

Commit 9397116

Browse files
committed
Generator: Detect flag enums and use IntFlag instead
Made possible by the new attributes in binja's type system.
1 parent 0238488 commit 9397116

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

binaryninjacore.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@
8686
#endif
8787

8888
// Define attributes for enums based on compiler support
89-
#if __has_attribute(enum_extensibility)
89+
#if defined(BN_TYPE_PARSER)
90+
#define __BN_ENUM_ATTRIBUTES
91+
#define __BN_OPTIONS_ATTRIBUTES __attr("options")
92+
#elif __has_attribute(enum_extensibility)
9093
#define __BN_ENUM_ATTRIBUTES __attribute__((enum_extensibility(open)))
9194
#define __BN_OPTIONS_ATTRIBUTES __attribute__((flag_enum, enum_extensibility(open)))
9295
#else

python/generator.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,11 @@ int main(int argc, char* argv[])
381381
}
382382
fprintf(out, "%sEnum = %s\n", name.c_str(), ctypesType);
383383

384-
fprintf(enums, "\n\nclass %s(enum.IntEnum):\n", name.c_str());
384+
if (i.second->GetAttribute("options").has_value())
385+
fprintf(enums, "\n\nclass %s(enum.IntFlag):\n", name.c_str());
386+
else
387+
fprintf(enums, "\n\nclass %s(enum.IntEnum):\n", name.c_str());
388+
385389
for (auto& j : i.second->GetEnumeration()->GetMembers())
386390
{
387391
if (i.second->IsSigned())

0 commit comments

Comments
 (0)