diff options
| author | Rusty Wagner <rusty@vector35.com> | 2015-02-13 01:07:43 -0500 |
|---|---|---|
| committer | Rusty Wagner <rusty@vector35.com> | 2015-02-13 01:07:43 -0500 |
| commit | 8a839248af8084c90ad14fabb5d5f7863ac146c0 (patch) | |
| tree | 0f2a06a20450b0fa49d278c0839e33ae89e838d0 | |
| parent | 83b01dd50407731d14938ac96894c3a4d9065295 (diff) | |
Add basic clipboard operations
| -rw-r--r-- | binaryninjaapi.h | 5 | ||||
| -rw-r--r-- | databuffer.cpp | 27 |
2 files changed, 32 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 590202a6..0c226b50 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -130,6 +130,7 @@ namespace BinaryNinja public: DataBuffer(); DataBuffer(size_t len); + DataBuffer(const void* data, size_t len); DataBuffer(const DataBuffer& buf); DataBuffer(BNDataBuffer* buf); ~DataBuffer(); @@ -146,11 +147,15 @@ namespace BinaryNinja void SetSize(size_t len); void Append(const void* data, size_t len); void Append(const DataBuffer& buf); + void AppendByte(uint8_t val); DataBuffer GetSlice(size_t start, size_t len); uint8_t& operator[](size_t offset); const uint8_t& operator[](size_t offset) const; + + std::string ToEscapedString() const; + static DataBuffer FromEscapedString(const std::string& src); }; class NavigationHandler diff --git a/databuffer.cpp b/databuffer.cpp index dcc94f90..0e11de8e 100644 --- a/databuffer.cpp +++ b/databuffer.cpp @@ -16,6 +16,12 @@ DataBuffer::DataBuffer(size_t len) } +DataBuffer::DataBuffer(const void* data, size_t len) +{ + m_buffer = BNCreateDataBuffer(data, len); +} + + DataBuffer::DataBuffer(const DataBuffer& buf) { m_buffer = BNDuplicateDataBuffer(buf.m_buffer); @@ -84,6 +90,12 @@ void DataBuffer::Append(const DataBuffer& buf) } +void DataBuffer::AppendByte(uint8_t val) +{ + Append(&val, 1); +} + + DataBuffer DataBuffer::GetSlice(size_t start, size_t len) { BNDataBuffer* result = BNGetDataBufferSlice(m_buffer, start, len); @@ -101,3 +113,18 @@ const uint8_t& DataBuffer::operator[](size_t offset) const { return ((const uint8_t*)GetData())[offset]; } + + +string DataBuffer::ToEscapedString() const +{ + char* str = BNDataBufferToEscapedString(m_buffer); + string result = str; + BNFreeString(str); + return result; +} + + +DataBuffer DataBuffer::FromEscapedString(const string& src) +{ + return DataBuffer(BNDecodeEscapedString(src.c_str())); +} |
