MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / main

Function main

view/sharedcache/api/python/generator.cpp:240–617  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

238
239
240int main(int argc, char* argv[])
241{
242 if (argc < 5)
243 {
244 fprintf(stderr, "Usage: generator <header> <output> <output_template> <output_enum>\n");
245 return 1;
246 }
247
248 // Parse API header to get type and function information
249 map<QualifiedName, Ref<Type>> types, vars, funcs;
250 string errors;
251 auto arch = new CoreArchitecture(BNGetNativeTypeParserArchitecture());
252
253 // Enable ephemeral settings
254 Settings::Instance()->LoadSettingsFile("");
255 Settings::Instance()->Set("analysis.types.parserName", "ClangTypeParser");
256 bool ok = arch->GetStandalonePlatform()->ParseTypesFromSourceFile(argv[1], types, vars, funcs, errors);
257
258 if (!ok)
259 {
260 fprintf(stderr, "Errors: %s\n", errors.c_str());
261 return 1;
262 }
263
264 FILE* out = fopen(argv[2], "w");
265 FILE* out_template = fopen(argv[3], "r");
266 FILE* enums = fopen(argv[4], "w");
267
268 fprintf(enums, "import enum\n");
269
270 // Copy the content of the template to the output file
271 int c;
272 while((c = fgetc(out_template)) != EOF)
273 fputc(c, out);
274
275 // Create type objects
276 fprintf(out, "# Type definitions\n");
277 for (auto& i : types)
278 {
279 string name;
280 if (i.first.size() != 1)
281 continue;
282 name = i.first[0];
283 if (name == "BNBinaryView")
284 {
285 fprintf(out, "from binaryninja._binaryninjacore import BNBinaryView, BNBinaryViewHandle\n");
286 continue;
287 }
288 if (i.second->GetClass() == StructureTypeClass)
289 {
290 fprintf(out, "class %s(ctypes.Structure):\n", name.c_str());
291
292 // python uses str's, C uses byte-arrays
293 bool stringField = false;
294 for (auto& arg : i.second->GetStructure()->GetMembers())
295 {
296 if ((arg.type->GetClass() == PointerTypeClass) &&
297 (arg.type->GetChildType()->GetWidth() == 1) &&

Callers

nothing calls this directly

Calls 15

LoadSettingsFileMethod · 0.80
GetStandalonePlatformMethod · 0.80
c_strMethod · 0.80
GetClassMethod · 0.80
GetMembersMethod · 0.80
GetStructureMethod · 0.80
GetChildTypeMethod · 0.80
IsSignedMethod · 0.80
GetEnumerationMethod · 0.80
GetNamedTypeReferenceMethod · 0.80
GetTypeReferenceClassMethod · 0.80
findMethod · 0.80

Tested by

no test coverage detected