Skip to content

Commit

Permalink
Add md1rom binary view with pure Rust lzma implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
D0ntPanic committed Apr 1, 2024
1 parent 0205628 commit a7fd2f8
Show file tree
Hide file tree
Showing 9 changed files with 705 additions and 2 deletions.
27 changes: 27 additions & 0 deletions binaryninjaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,33 @@ namespace BinaryNinja {
\returns Whether decompression was successful
*/
bool ZlibDecompress(DataBuffer& output) const;

/*! Decompress the contents of this buffer via LZMA compression

@threadunsafe

\param[out] output Output DataBuffer the decompressed contents will be stored in.
\returns Whether decompression was successful
*/
bool LzmaDecompress(DataBuffer& output) const;

/*! Decompress the contents of this buffer via LZMA2 compression

@threadunsafe

\param[out] output Output DataBuffer the decompressed contents will be stored in.
\returns Whether decompression was successful
*/
bool Lzma2Decompress(DataBuffer& output) const;

/*! Decompress the contents of this buffer via XZ compression

@threadunsafe

\param[out] output Output DataBuffer the decompressed contents will be stored in.
\returns Whether decompression was successful
*/
bool XzDecompress(DataBuffer& output) const;
};

/*! TemporaryFile is used for creating temporary files, stored (temporarily) in the system's default temporary file
Expand Down
3 changes: 3 additions & 0 deletions binaryninjacore.h
Original file line number Diff line number Diff line change
Expand Up @@ -3323,6 +3323,9 @@ extern "C"

BINARYNINJACOREAPI BNDataBuffer* BNZlibCompress(BNDataBuffer* buf);
BINARYNINJACOREAPI BNDataBuffer* BNZlibDecompress(BNDataBuffer* buf);
BINARYNINJACOREAPI BNDataBuffer* BNLzmaDecompress(BNDataBuffer* buf);
BINARYNINJACOREAPI BNDataBuffer* BNLzma2Decompress(BNDataBuffer* buf);
BINARYNINJACOREAPI BNDataBuffer* BNXzDecompress(BNDataBuffer* buf);

// Save settings
BINARYNINJACOREAPI BNSaveSettings* BNCreateSaveSettings(void);
Expand Down
34 changes: 32 additions & 2 deletions databuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ DataBuffer DataBuffer::FromBase64(const string& src)

bool DataBuffer::ZlibCompress(DataBuffer& output) const
{
BNDataBuffer* result = BNZlibCompress(output.m_buffer);
BNDataBuffer* result = BNZlibCompress(m_buffer);
if (!result)
return false;
output = DataBuffer(result);
Expand All @@ -232,7 +232,37 @@ bool DataBuffer::ZlibCompress(DataBuffer& output) const

bool DataBuffer::ZlibDecompress(DataBuffer& output) const
{
BNDataBuffer* result = BNZlibDecompress(output.m_buffer);
BNDataBuffer* result = BNZlibDecompress(m_buffer);
if (!result)
return false;
output = DataBuffer(result);
return true;
}


bool DataBuffer::LzmaDecompress(DataBuffer& output) const
{
BNDataBuffer* result = BNLzmaDecompress(m_buffer);
if (!result)
return false;
output = DataBuffer(result);
return true;
}


bool DataBuffer::Lzma2Decompress(DataBuffer& output) const
{
BNDataBuffer* result = BNLzma2Decompress(m_buffer);
if (!result)
return false;
output = DataBuffer(result);
return true;
}


bool DataBuffer::XzDecompress(DataBuffer& output) const
{
BNDataBuffer* result = BNXzDecompress(m_buffer);
if (!result)
return false;
output = DataBuffer(result);
Expand Down
9 changes: 9 additions & 0 deletions docs/about/open-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ The previous tools are used in the generation of our documentation, but are not
- [core-foundation-sys] ([core-foundation-sys license] - APACHE 2.0 / MIT)
- [core-foundation] ([core-foundation license] - APACHE 2.0 / MIT)
- [cpufeatures] ([cpufeatures license] - APACHE 2.0 / MIT)
- [crc] ([crc license] - APACHE 2.0 / MIT)
- [crc-catalog] ([crc-catalog license] - APACHE 2.0 / MIT)
- [crc32fast] ([crc32fast license] - APACHE 2.0 / MIT)
- [crypto-common] ([crypto-common license] - APACHE 2.0 / MIT)
- [ctr] ([ctr license] - APACHE 2.0 / MIT)
Expand Down Expand Up @@ -126,6 +128,7 @@ The previous tools are used in the generation of our documentation, but are not
- [libloading] ([libloading license] - ISC)
- [libz-sys] ([libz-sys license] - APACHE 2.0 / MIT)
- [log] ([log license] - APACHE 2.0 / MIT)
- [lzma-rs] ([lzma-rs license] - MIT)
- [lzxd] ([lzxd license] - APACHE 2.0 / MIT)
- [machine-uid] ([machine-uid license] - MIT)
- [markdown] ([markdown license] - MIT)
Expand Down Expand Up @@ -416,6 +419,10 @@ Please note that we offer no support for running Binary Ninja with modified Qt l
[core-foundation license]: https://github.com/servo/core-foundation-rs/blob/master/LICENSE-MIT
[cpufeatures]: https://github.com/RustCrypto/utils/tree/master/cpufeatures
[cpufeatures license]: https://github.com/RustCrypto/utils/blob/master/cpufeatures/LICENSE-MIT
[crc]: https://github.com/mrhooray/crc-rs
[crc license]: https://github.com/mrhooray/crc-rs/blob/master/LICENSE-MIT
[crc-catalog]: https://github.com/akhilles/crc-catalog
[crc-catalog license]: https://github.com/akhilles/crc-catalog/blob/master/LICENSES/MIT.txt
[crc32fast]: https://github.com/srijs/rust-crc32fast
[crc32fast license]: https://github.com/srijs/rust-crc32fast/blob/master/LICENSE-MIT
[crypto-common]: https://github.com/RustCrypto/traits/tree/master/crypto-common
Expand Down Expand Up @@ -530,6 +537,8 @@ Please note that we offer no support for running Binary Ninja with modified Qt l
[libz-sys license]: https://github.com/rust-lang/libz-sys/blob/main/LICENSE-MIT
[log]: https://github.com/rust-lang/log
[log license]: https://github.com/rust-lang/log/blob/master/LICENSE-MIT
[lzma-rs]: https://github.com/gendx/lzma-rs
[lzma-rs license]: https://github.com/gendx/lzma-rs/blob/master/LICENSE
[lzxd]: https://github.com/Lonami/lzxd
[lzxd license]: https://github.com/Lonami/lzxd/blob/master/LICENSE-MIT
[machine-uid]: https://github.com/Hanaasagi/machine-uid
Expand Down
33 changes: 33 additions & 0 deletions view/md1rom/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)

project(view_md1rom)

if(NOT BN_INTERNAL_BUILD)
add_subdirectory(${PROJECT_SOURCE_DIR}/../.. ${PROJECT_BINARY_DIR}/api)
endif()

file(GLOB SOURCES
*.cpp
*.h)

if(DEMO)
add_library(view_md1rom STATIC ${SOURCES})
else()
add_library(view_md1rom SHARED ${SOURCES})
endif()

target_link_libraries(view_md1rom binaryninjaapi)

set_target_properties(view_md1rom PROPERTIES
CXX_STANDARD 17
CXX_VISIBILITY_PRESET hidden
CXX_STANDARD_REQUIRED ON
VISIBILITY_INLINES_HIDDEN ON
POSITION_INDEPENDENT_CODE ON)

if(BN_INTERNAL_BUILD)
plugin_rpath(view_md1rom)
set_target_properties(view_md1rom PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${BN_CORE_PLUGIN_DIR}
RUNTIME_OUTPUT_DIRECTORY ${BN_CORE_PLUGIN_DIR})
endif()
13 changes: 13 additions & 0 deletions view/md1rom/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2021-2024 Vector 35 Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
23 changes: 23 additions & 0 deletions view/md1rom/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# view-md1rom
This is the md1rom view plugin that ships with Binary Ninja.

## Building

Building the architecture plugin requires `cmake` 3.9 or above. You will also need the
[Binary Ninja API source](https://github.com/Vector35/binaryninja-api).

Run `cmake`. This can be done either from a separate build directory or from the source
directory. Once that is complete, run `make` in the build directory to compile the plugin.

The plugin can be found in the root of the build directory as `libview_md1rom.so`,
`libview_md1rom.dylib` or `view_md1rom.dll` depending on your platform.

To install the plugin, first launch Binary Ninja and uncheck the "Md1rom view plugin"
option in the "Core Plugins" section. This will cause Binary Ninja to stop loading the
bundled plugin so that its replacement can be loaded. Once this is complete, you can copy
the plugin into the user plugins directory (you can locate this by using the "Open Plugin Folder"
option in the Binary Ninja UI).

**Do not replace the view plugin in the Binary Ninja install directory. This will be overwritten
every time there is a Binary Ninja update. Use the above process to ensure that updates do not
automatically uninstall your custom build.**
Loading

0 comments on commit a7fd2f8

Please sign in to comment.