summaryrefslogtreecommitdiff
path: root/binarywriter.cpp
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2015-02-12 14:34:50 -0500
committerRusty Wagner <rusty@vector35.com>2015-02-12 14:34:50 -0500
commit83b01dd50407731d14938ac96894c3a4d9065295 (patch)
tree2e3ded7103b51aef0d5cd22434e35f4461aeaeba /binarywriter.cpp
parent6b431b32e32f00f9203ba2a4ca07cc962cdb22aa (diff)
Place API code with the associated class
Diffstat (limited to 'binarywriter.cpp')
-rw-r--r--binarywriter.cpp214
1 files changed, 214 insertions, 0 deletions
diff --git a/binarywriter.cpp b/binarywriter.cpp
new file mode 100644
index 00000000..808d0d5f
--- /dev/null
+++ b/binarywriter.cpp
@@ -0,0 +1,214 @@
+#include "binaryninjaapi.h"
+
+using namespace BinaryNinja;
+using namespace std;
+
+
+BinaryWriter::BinaryWriter(BinaryView* data, BNEndianness endian): m_view(data)
+{
+ m_stream = BNCreateBinaryWriter(data->GetViewObject());
+ BNSetBinaryWriterEndianness(m_stream, endian);
+}
+
+
+BinaryWriter::~BinaryWriter()
+{
+ BNFreeBinaryWriter(m_stream);
+}
+
+
+BNEndianness BinaryWriter::GetEndianness() const
+{
+ return BNGetBinaryWriterEndianness(m_stream);
+}
+
+
+void BinaryWriter::SetEndianness(BNEndianness endian)
+{
+ BNSetBinaryWriterEndianness(m_stream, endian);
+}
+
+
+void BinaryWriter::Write(const void* src, size_t len)
+{
+ if (!BNWriteData(m_stream, src, len))
+ throw WriteException();
+}
+
+
+void BinaryWriter::Write(const DataBuffer& buf)
+{
+ Write(buf.GetData(), buf.GetLength());
+}
+
+
+void BinaryWriter::Write(const string& str)
+{
+ Write(str.c_str(), str.size());
+}
+
+
+void BinaryWriter::Write8(uint8_t val)
+{
+ if (!BNWrite8(m_stream, val))
+ throw WriteException();
+}
+
+
+void BinaryWriter::Write16(uint16_t val)
+{
+ if (!BNWrite16(m_stream, val))
+ throw WriteException();
+}
+
+
+void BinaryWriter::Write32(uint32_t val)
+{
+ if (!BNWrite32(m_stream, val))
+ throw WriteException();
+}
+
+
+void BinaryWriter::Write64(uint64_t val)
+{
+ if (!BNWrite64(m_stream, val))
+ throw WriteException();
+}
+
+
+void BinaryWriter::WriteLE16(uint16_t val)
+{
+ if (!BNWriteLE16(m_stream, val))
+ throw WriteException();
+}
+
+
+void BinaryWriter::WriteLE32(uint32_t val)
+{
+ if (!BNWriteLE32(m_stream, val))
+ throw WriteException();
+}
+
+
+void BinaryWriter::WriteLE64(uint64_t val)
+{
+ if (!BNWriteLE64(m_stream, val))
+ throw WriteException();
+}
+
+
+void BinaryWriter::WriteBE16(uint16_t val)
+{
+ if (!BNWriteBE16(m_stream, val))
+ throw WriteException();
+}
+
+
+void BinaryWriter::WriteBE32(uint32_t val)
+{
+ if (!BNWriteBE32(m_stream, val))
+ throw WriteException();
+}
+
+
+void BinaryWriter::WriteBE64(uint64_t val)
+{
+ if (!BNWriteBE64(m_stream, val))
+ throw WriteException();
+}
+
+
+bool BinaryWriter::TryWrite(const void* src, size_t len)
+{
+ return BNWriteData(m_stream, src, len);
+}
+
+
+bool BinaryWriter::TryWrite(const DataBuffer& buf)
+{
+ return TryWrite(buf.GetData(), buf.GetLength());
+}
+
+
+bool BinaryWriter::TryWrite(const string& str)
+{
+ return TryWrite(str.c_str(), str.size());
+}
+
+
+bool BinaryWriter::TryWrite8(uint8_t val)
+{
+ return BNWrite8(m_stream, val);
+}
+
+
+bool BinaryWriter::TryWrite16(uint16_t val)
+{
+ return BNWrite16(m_stream, val);
+}
+
+
+bool BinaryWriter::TryWrite32(uint32_t val)
+{
+ return BNWrite32(m_stream, val);
+}
+
+
+bool BinaryWriter::TryWrite64(uint64_t val)
+{
+ return BNWrite64(m_stream, val);
+}
+
+
+bool BinaryWriter::TryWriteLE16(uint16_t val)
+{
+ return BNWriteLE16(m_stream, val);
+}
+
+
+bool BinaryWriter::TryWriteLE32(uint32_t val)
+{
+ return BNWriteLE32(m_stream, val);
+}
+
+
+bool BinaryWriter::TryWriteLE64(uint64_t val)
+{
+ return BNWriteLE64(m_stream, val);
+}
+
+
+bool BinaryWriter::TryWriteBE16(uint16_t val)
+{
+ return BNWriteBE16(m_stream, val);
+}
+
+
+bool BinaryWriter::TryWriteBE32(uint32_t val)
+{
+ return BNWriteBE32(m_stream, val);
+}
+
+
+bool BinaryWriter::TryWriteBE64(uint64_t val)
+{
+ return BNWriteBE64(m_stream, val);
+}
+
+
+uint64_t BinaryWriter::GetOffset() const
+{
+ return BNGetWriterPosition(m_stream);
+}
+
+
+void BinaryWriter::Seek(uint64_t offset)
+{
+ BNSeekBinaryWriter(m_stream, offset);
+}
+
+
+void BinaryWriter::SeekRelative(int64_t offset)
+{
+ BNSeekBinaryWriterRelative(m_stream, offset);
+}