From df3c57d907cc994d8a660684428a75383f34c69a Mon Sep 17 00:00:00 2001 From: Xusheng Date: Fri, 17 May 2024 17:36:54 +0800 Subject: Update C++ example code to use BinaryNinja::Load to open a file. Fix https://github.com/Vector35/binaryninja-api/issues/5429 --- examples/enterprise_test/src/enterprise_test.cpp | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'examples/enterprise_test/src/enterprise_test.cpp') diff --git a/examples/enterprise_test/src/enterprise_test.cpp b/examples/enterprise_test/src/enterprise_test.cpp index 2a6b42c0..4297fc9f 100644 --- a/examples/enterprise_test/src/enterprise_test.cpp +++ b/examples/enterprise_test/src/enterprise_test.cpp @@ -43,30 +43,13 @@ int main(int argc, char* argv[]) SetBundledPluginDirectory(GetBundledPluginDirectory()); InitPlugins(); - Ref bd = BinaryData::CreateFromFilename(new FileMetadata(), argv[1]); - if (!bd) - { - fprintf(stderr, "Could not open input file.\n"); - return -1; - } - Ref bv; - for (auto type : BinaryViewType::GetViewTypes()) - { - if (type->IsTypeValidForData(bd) && type->GetName() != "Raw") - { - bv = type->Create(bd); - break; - } - } - + Ref bv = BinaryNinja::Load(fname); if (!bv || bv->GetTypeName() == "Raw") { - fprintf(stderr, "Input file does not appear to be an exectuable\n"); + fprintf(stderr, "Input file does not appear to be an executable\n"); return -1; } - bv->UpdateAnalysisAndWait(); - cout << "Target: " << fname << endl << endl; cout << "TYPE: " << bv->GetTypeName() << endl; cout << "START: 0x" << hex << bv->GetStart() << endl; @@ -99,6 +82,9 @@ int main(int argc, char* argv[]) break; } + // Close the file so that the resources can be freed + bv->GetFile()->Close(); + // Shutting down is required to allow for clean exit of the core BNShutdown(); -- cgit v1.3.1