diff options
| author | Rusty Wagner <dontpanic@binaryninja.com> | 2015-03-21 03:51:23 -0400 |
|---|---|---|
| committer | Rusty Wagner <dontpanic@binaryninja.com> | 2015-03-21 03:51:23 -0400 |
| commit | c85cae0d74c2c32b23f5e1422f230bebd61f1b1e (patch) | |
| tree | db86059ab0816bc57c469fa72d144768711f9077 /architecture.cpp | |
| parent | e044ab55ef7204237507465074b54a113c8aae4d (diff) | |
Add assemble dialog and use nasm for x86/x86_64
Diffstat (limited to 'architecture.cpp')
| -rw-r--r-- | architecture.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/architecture.cpp b/architecture.cpp index eca3a9a6..fc5b0466 100644 --- a/architecture.cpp +++ b/architecture.cpp @@ -88,6 +88,19 @@ void Architecture::FreeInstructionTextCallback(BNInstructionTextToken* tokens, s } +bool Architecture::AssembleCallback(void* ctxt, const char* code, uint64_t addr, BNDataBuffer* result, char** errors) +{ + Architecture* arch = (Architecture*)ctxt; + DataBuffer buf; + string errorStr; + bool ok = arch->Assemble(code, addr, buf, errorStr); + + BNSetDataBufferContents(result, buf.GetData(), buf.GetLength()); + *errors = BNAllocString(errorStr.c_str()); + return ok; +} + + void Architecture::Register(Architecture* arch) { BNCustomArchitecture callbacks; @@ -95,6 +108,7 @@ void Architecture::Register(Architecture* arch) callbacks.getInstructionInfo = GetInstructionInfoCallback; callbacks.getInstructionText = GetInstructionTextCallback; callbacks.freeInstructionText = FreeInstructionTextCallback; + callbacks.assemble = AssembleCallback; arch->m_arch = BNRegisterArchitecture(arch->m_nameForRegister.c_str(), &callbacks); } @@ -156,3 +170,16 @@ bool CoreArchitecture::GetInstructionText(const uint8_t* data, uint64_t addr, si BNFreeInstructionText(tokens, count); return true; } + + +bool CoreArchitecture::Assemble(const string& code, uint64_t addr, DataBuffer& result, string& errors) +{ + char* errorStr = nullptr; + bool ok = BNAssemble(m_arch, code.c_str(), addr, result.GetBufferObject(), &errorStr); + if (errorStr) + { + errors = errorStr; + BNFreeString(errorStr); + } + return ok; +} |
