Skip to content

Commit a7fd2f8

Browse files
committed
Add md1rom binary view with pure Rust lzma implementation
1 parent 0205628 commit a7fd2f8

File tree

9 files changed

+705
-2
lines changed

9 files changed

+705
-2
lines changed

binaryninjaapi.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,6 +2114,33 @@ namespace BinaryNinja {
21142114
\returns Whether decompression was successful
21152115
*/
21162116
bool ZlibDecompress(DataBuffer& output) const;
2117+
2118+
/*! Decompress the contents of this buffer via LZMA compression
2119+
2120+
@threadunsafe
2121+
2122+
\param[out] output Output DataBuffer the decompressed contents will be stored in.
2123+
\returns Whether decompression was successful
2124+
*/
2125+
bool LzmaDecompress(DataBuffer& output) const;
2126+
2127+
/*! Decompress the contents of this buffer via LZMA2 compression
2128+
2129+
@threadunsafe
2130+
2131+
\param[out] output Output DataBuffer the decompressed contents will be stored in.
2132+
\returns Whether decompression was successful
2133+
*/
2134+
bool Lzma2Decompress(DataBuffer& output) const;
2135+
2136+
/*! Decompress the contents of this buffer via XZ compression
2137+
2138+
@threadunsafe
2139+
2140+
\param[out] output Output DataBuffer the decompressed contents will be stored in.
2141+
\returns Whether decompression was successful
2142+
*/
2143+
bool XzDecompress(DataBuffer& output) const;
21172144
};
21182145

21192146
/*! TemporaryFile is used for creating temporary files, stored (temporarily) in the system's default temporary file

binaryninjacore.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3323,6 +3323,9 @@ extern "C"
33233323

33243324
BINARYNINJACOREAPI BNDataBuffer* BNZlibCompress(BNDataBuffer* buf);
33253325
BINARYNINJACOREAPI BNDataBuffer* BNZlibDecompress(BNDataBuffer* buf);
3326+
BINARYNINJACOREAPI BNDataBuffer* BNLzmaDecompress(BNDataBuffer* buf);
3327+
BINARYNINJACOREAPI BNDataBuffer* BNLzma2Decompress(BNDataBuffer* buf);
3328+
BINARYNINJACOREAPI BNDataBuffer* BNXzDecompress(BNDataBuffer* buf);
33263329

33273330
// Save settings
33283331
BINARYNINJACOREAPI BNSaveSettings* BNCreateSaveSettings(void);

databuffer.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ DataBuffer DataBuffer::FromBase64(const string& src)
222222

223223
bool DataBuffer::ZlibCompress(DataBuffer& output) const
224224
{
225-
BNDataBuffer* result = BNZlibCompress(output.m_buffer);
225+
BNDataBuffer* result = BNZlibCompress(m_buffer);
226226
if (!result)
227227
return false;
228228
output = DataBuffer(result);
@@ -232,7 +232,37 @@ bool DataBuffer::ZlibCompress(DataBuffer& output) const
232232

233233
bool DataBuffer::ZlibDecompress(DataBuffer& output) const
234234
{
235-
BNDataBuffer* result = BNZlibDecompress(output.m_buffer);
235+
BNDataBuffer* result = BNZlibDecompress(m_buffer);
236+
if (!result)
237+
return false;
238+
output = DataBuffer(result);
239+
return true;
240+
}
241+
242+
243+
bool DataBuffer::LzmaDecompress(DataBuffer& output) const
244+
{
245+
BNDataBuffer* result = BNLzmaDecompress(m_buffer);
246+
if (!result)
247+
return false;
248+
output = DataBuffer(result);
249+
return true;
250+
}
251+
252+
253+
bool DataBuffer::Lzma2Decompress(DataBuffer& output) const
254+
{
255+
BNDataBuffer* result = BNLzma2Decompress(m_buffer);
256+
if (!result)
257+
return false;
258+
output = DataBuffer(result);
259+
return true;
260+
}
261+
262+
263+
bool DataBuffer::XzDecompress(DataBuffer& output) const
264+
{
265+
BNDataBuffer* result = BNXzDecompress(m_buffer);
236266
if (!result)
237267
return false;
238268
output = DataBuffer(result);

docs/about/open-source.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ The previous tools are used in the generation of our documentation, but are not
7070
- [core-foundation-sys] ([core-foundation-sys license] - APACHE 2.0 / MIT)
7171
- [core-foundation] ([core-foundation license] - APACHE 2.0 / MIT)
7272
- [cpufeatures] ([cpufeatures license] - APACHE 2.0 / MIT)
73+
- [crc] ([crc license] - APACHE 2.0 / MIT)
74+
- [crc-catalog] ([crc-catalog license] - APACHE 2.0 / MIT)
7375
- [crc32fast] ([crc32fast license] - APACHE 2.0 / MIT)
7476
- [crypto-common] ([crypto-common license] - APACHE 2.0 / MIT)
7577
- [ctr] ([ctr license] - APACHE 2.0 / MIT)
@@ -126,6 +128,7 @@ The previous tools are used in the generation of our documentation, but are not
126128
- [libloading] ([libloading license] - ISC)
127129
- [libz-sys] ([libz-sys license] - APACHE 2.0 / MIT)
128130
- [log] ([log license] - APACHE 2.0 / MIT)
131+
- [lzma-rs] ([lzma-rs license] - MIT)
129132
- [lzxd] ([lzxd license] - APACHE 2.0 / MIT)
130133
- [machine-uid] ([machine-uid license] - MIT)
131134
- [markdown] ([markdown license] - MIT)
@@ -416,6 +419,10 @@ Please note that we offer no support for running Binary Ninja with modified Qt l
416419
[core-foundation license]: https://github.com/servo/core-foundation-rs/blob/master/LICENSE-MIT
417420
[cpufeatures]: https://github.com/RustCrypto/utils/tree/master/cpufeatures
418421
[cpufeatures license]: https://github.com/RustCrypto/utils/blob/master/cpufeatures/LICENSE-MIT
422+
[crc]: https://github.com/mrhooray/crc-rs
423+
[crc license]: https://github.com/mrhooray/crc-rs/blob/master/LICENSE-MIT
424+
[crc-catalog]: https://github.com/akhilles/crc-catalog
425+
[crc-catalog license]: https://github.com/akhilles/crc-catalog/blob/master/LICENSES/MIT.txt
419426
[crc32fast]: https://github.com/srijs/rust-crc32fast
420427
[crc32fast license]: https://github.com/srijs/rust-crc32fast/blob/master/LICENSE-MIT
421428
[crypto-common]: https://github.com/RustCrypto/traits/tree/master/crypto-common
@@ -530,6 +537,8 @@ Please note that we offer no support for running Binary Ninja with modified Qt l
530537
[libz-sys license]: https://github.com/rust-lang/libz-sys/blob/main/LICENSE-MIT
531538
[log]: https://github.com/rust-lang/log
532539
[log license]: https://github.com/rust-lang/log/blob/master/LICENSE-MIT
540+
[lzma-rs]: https://github.com/gendx/lzma-rs
541+
[lzma-rs license]: https://github.com/gendx/lzma-rs/blob/master/LICENSE
533542
[lzxd]: https://github.com/Lonami/lzxd
534543
[lzxd license]: https://github.com/Lonami/lzxd/blob/master/LICENSE-MIT
535544
[machine-uid]: https://github.com/Hanaasagi/machine-uid

view/md1rom/CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
2+
3+
project(view_md1rom)
4+
5+
if(NOT BN_INTERNAL_BUILD)
6+
add_subdirectory(${PROJECT_SOURCE_DIR}/../.. ${PROJECT_BINARY_DIR}/api)
7+
endif()
8+
9+
file(GLOB SOURCES
10+
*.cpp
11+
*.h)
12+
13+
if(DEMO)
14+
add_library(view_md1rom STATIC ${SOURCES})
15+
else()
16+
add_library(view_md1rom SHARED ${SOURCES})
17+
endif()
18+
19+
target_link_libraries(view_md1rom binaryninjaapi)
20+
21+
set_target_properties(view_md1rom PROPERTIES
22+
CXX_STANDARD 17
23+
CXX_VISIBILITY_PRESET hidden
24+
CXX_STANDARD_REQUIRED ON
25+
VISIBILITY_INLINES_HIDDEN ON
26+
POSITION_INDEPENDENT_CODE ON)
27+
28+
if(BN_INTERNAL_BUILD)
29+
plugin_rpath(view_md1rom)
30+
set_target_properties(view_md1rom PROPERTIES
31+
LIBRARY_OUTPUT_DIRECTORY ${BN_CORE_PLUGIN_DIR}
32+
RUNTIME_OUTPUT_DIRECTORY ${BN_CORE_PLUGIN_DIR})
33+
endif()

view/md1rom/LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2021-2024 Vector 35 Inc.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

view/md1rom/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# view-md1rom
2+
This is the md1rom view plugin that ships with Binary Ninja.
3+
4+
## Building
5+
6+
Building the architecture plugin requires `cmake` 3.9 or above. You will also need the
7+
[Binary Ninja API source](https://github.com/Vector35/binaryninja-api).
8+
9+
Run `cmake`. This can be done either from a separate build directory or from the source
10+
directory. Once that is complete, run `make` in the build directory to compile the plugin.
11+
12+
The plugin can be found in the root of the build directory as `libview_md1rom.so`,
13+
`libview_md1rom.dylib` or `view_md1rom.dll` depending on your platform.
14+
15+
To install the plugin, first launch Binary Ninja and uncheck the "Md1rom view plugin"
16+
option in the "Core Plugins" section. This will cause Binary Ninja to stop loading the
17+
bundled plugin so that its replacement can be loaded. Once this is complete, you can copy
18+
the plugin into the user plugins directory (you can locate this by using the "Open Plugin Folder"
19+
option in the Binary Ninja UI).
20+
21+
**Do not replace the view plugin in the Binary Ninja install directory. This will be overwritten
22+
every time there is a Binary Ninja update. Use the above process to ensure that updates do not
23+
automatically uninstall your custom build.**

0 commit comments

Comments
 (0)