Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions arch/x86/arch_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string.h>
#include <sstream>
#include "binaryninjaapi.h"
#include "pathhelpers.h"
#include "il.h"
extern "C" {
#include "xed-interface.h"
Expand Down Expand Up @@ -2625,15 +2626,16 @@ bool X86CommonArchitecture::Assemble(const string& code, uint64_t addr, DataBuff
}

#ifdef WIN32
string yasmPath = GetPathRelativeToBundledPluginDirectory("yasm.exe");
auto yasmPath = GetPathRelativeToBundledPluginDirectory("yasm.exe");
#else
string yasmPath = GetPathRelativeToBundledPluginDirectory("yasm");
auto yasmPath = GetPathRelativeToBundledPluginDirectory("yasm");
#endif

string inputPath = inputFile->GetPath();
string outputPath = outputFile->GetPath();
string yasmPathString = Path::PathToUtf8String(yasmPath);
string inputPath = Path::PathToUtf8String(inputFile->GetPath());
string outputPath = Path::PathToUtf8String(outputFile->GetPath());

vector<string> args = vector<string> { yasmPath, "-fbin", "-w", "-Worphan-labels", "-Werror", "-o", outputPath, inputPath };
vector<string> args = vector<string> { yasmPathString, "-fbin", "-w", "-Worphan-labels", "-Werror", "-o", outputPath, inputPath };

string output;
bool ok = ExecuteWorkerProcess(yasmPath, args, DataBuffer(),
Expand All @@ -2649,7 +2651,7 @@ bool X86CommonArchitecture::Assemble(const string& code, uint64_t addr, DataBuff
OR the yasm process return code was nonzero */
if(errors.size() == 0)
{
errors = yasmPath + " returned nonzero\n";
errors = yasmPathString + " returned nonzero\n";
}
}
else
Expand Down
124 changes: 49 additions & 75 deletions binaryninjaapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// IN THE SOFTWARE.

#include "binaryninjaapi.h"
#include "pathhelpers.h"
#include <numeric>

using namespace BinaryNinja;
Expand Down Expand Up @@ -49,134 +50,106 @@ bool BinaryNinja::InitPlugins(bool allowUserPlugins)
}


string BinaryNinja::GetBundledPluginDirectory()
filesystem::path BinaryNinja::GetBundledPluginDirectory()
{
char* path = BNGetBundledPluginDirectory();
if (!path)
return string();
string result = path;
BNFreeString(path);
return result;
return Path::PathFromCore(BNGetBundledPluginDirectory());
}


std::string BinaryNinja::GetBundledScriptPluginDirectory()
filesystem::path BinaryNinja::GetBundledScriptPluginDirectory()
{
char* path = BNGetBundledScriptPluginDirectory();
if (!path)
return string();
std::string result = path;
BNFreeString(path);
return result;
return Path::PathFromCore(BNGetBundledScriptPluginDirectory());
}


void BinaryNinja::SetBundledPluginDirectory(const string& path)
void BinaryNinja::SetBundledPluginDirectory(const filesystem::path& path)
{
BNSetBundledPluginDirectory(path.c_str());
Path::APIObject corePath(path);
BNSetBundledPluginDirectory(corePath);
}


string BinaryNinja::GetUserDirectory(void)
void BinaryNinja::SetBundledScriptPluginDirectory(const filesystem::path& path)
{
char* dir = BNGetUserDirectory();
if (!dir)
return string();
string result(dir);
BNFreeString(dir);
return result;
Path::APIObject corePath(path);
BNSetBundledScriptPluginDirectory(corePath);
}


string BinaryNinja::GetSystemCacheDirectory()
filesystem::path BinaryNinja::GetUserDirectory(void)
{
char* dir = BNGetSystemCacheDirectory();
if (!dir)
return string();
std::string result(dir);
BNFreeString(dir);
return result;
return Path::PathFromCore(BNGetUserDirectory());
}


string BinaryNinja::GetSettingsFileName()
filesystem::path BinaryNinja::GetSystemCacheDirectory()
{
char* dir = BNGetSettingsFileName();
if (!dir)
return string();
string result(dir);
BNFreeString(dir);
return result;
return Path::PathFromCore(BNGetSystemCacheDirectory());
}


string BinaryNinja::GetRepositoriesDirectory()
filesystem::path BinaryNinja::GetSettingsFileName()
{
char* dir = BNGetRepositoriesDirectory();
if (!dir)
return string();
string result(dir);
BNFreeString(dir);
return result;
return Path::PathFromCore(BNGetSettingsFileName());
}


string BinaryNinja::GetInstallDirectory()
filesystem::path BinaryNinja::GetRepositoriesDirectory()
{
char* path = BNGetInstallDirectory();
if (!path)
return string();
string result = path;
BNFreeString(path);
return result;
return Path::PathFromCore(BNGetRepositoriesDirectory());
}


string BinaryNinja::GetUserPluginDirectory()
filesystem::path BinaryNinja::GetInstallDirectory()
{
char* path = BNGetUserPluginDirectory();
if (!path)
return string();
string result = path;
BNFreeString(path);
return result;
return Path::PathFromCore(BNGetInstallDirectory());
}


string BinaryNinja::GetPathRelativeToBundledPluginDirectory(const string& rel)
filesystem::path BinaryNinja::GetUserPluginDirectory()
{
char* path = BNGetPathRelativeToBundledPluginDirectory(rel.c_str());
return Path::PathFromCore(BNGetUserPluginDirectory());
}


filesystem::path BinaryNinja::GetPathRelativeToBundledPluginDirectory(const filesystem::path& rel)
{
Path::APIObject coreRel(rel);
BNPath* path = BNGetPathRelativeToBundledPluginDirectory(coreRel);
if (!path)
return rel;
string result = path;
BNFreeString(path);
return result;
return Path::PathFromCore(path);
}


string BinaryNinja::GetPathRelativeToUserPluginDirectory(const string& rel)
filesystem::path BinaryNinja::GetPathRelativeToUserPluginDirectory(const filesystem::path& rel)
{
char* path = BNGetPathRelativeToUserPluginDirectory(rel.c_str());
Path::APIObject coreRel(rel);
BNPath* path = BNGetPathRelativeToUserPluginDirectory(coreRel);
if (!path)
return rel;
string result = path;
BNFreeString(path);
return result;
return Path::PathFromCore(path);
}


string BinaryNinja::GetPathRelativeToUserDirectory(const string& rel)
filesystem::path BinaryNinja::GetPathRelativeToUserDirectory(const filesystem::path& rel)
{
char* path = BNGetPathRelativeToUserDirectory(rel.c_str());
Path::APIObject coreRel(rel);
BNPath* path = BNGetPathRelativeToUserDirectory(coreRel);
if (!path)
return rel;
string result = path;
BNFreeString(path);
return result;
return Path::PathFromCore(path);
}


bool BinaryNinja::IsDatabase(const filesystem::path& path)
{
Path::APIObject corePath(path);
return BNIsDatabase(corePath);
}


bool BinaryNinja::ExecuteWorkerProcess(const string& path, const vector<string>& args, const DataBuffer& input,
bool BinaryNinja::ExecuteWorkerProcess(const filesystem::path& path, const vector<string>& args, const DataBuffer& input,
string& output, string& errors, bool stdoutIsText, bool stderrIsText)
{
const char** argArray = new const char*[args.size() + 1];
Expand All @@ -186,8 +159,9 @@ bool BinaryNinja::ExecuteWorkerProcess(const string& path, const vector<string>&

char* outputStr;
char* errorStr;
Path::APIObject corePath(path);
bool result = BNExecuteWorkerProcess(
path.c_str(), argArray, input.GetBufferObject(), &outputStr, &errorStr, stdoutIsText, stderrIsText);
corePath, argArray, input.GetBufferObject(), &outputStr, &errorStr, stdoutIsText, stderrIsText);

output = outputStr;
errors = errorStr;
Expand Down
Loading
Loading