nlib
nn::nlib::oss Namespace Reference

Implements a library for open-source software (OSS), code derived from OSS, and for accessing OSS. More...

Classes

class  Lz4InputStream
 The stream class to read data according to the LZ4 frame format. More...
 
class  Lz4InputStreamSettings
 The class to obtain and configure the Lz4InputStream settings. As of now this class is empty. More...
 
class  Lz4OutputStream
 The stream class to write data according to the LZ4 frame format. More...
 
class  Lz4OutputStreamSettings
 The class to obtain and configure the Lz4OutputStream settings. More...
 

Functions

errno_t BsDiffZ (OutputStream *patch, void *old_data, size_t old_size, void *new_data, size_t new_size) noexcept
 Creates a patch to update from the old data to the new data. More...
 
errno_t BsPatchZ (OutputStream *new_stream, void *old_data, size_t old_size, void *patch_data, size_t patch_size) noexcept
 Creates new data from the old data and the patch data. More...
 

Detailed Description

Implements a library for open-source software (OSS), code derived from OSS, and for accessing OSS.

Description
This library is category I, so be sure to follow the necessary procedures when using it.
Note that the heap library must be linked in addition to the misc library because the code included in each oss library internally uses nmalloc/nfree. nmalloc and nfree are used because there is a risk of denial of service attacks that use fragmentation when you use the default SDK functions malloc and free.
Included Programs
This library contains the following components.
bsdiff
bsdiff contains the library modified to use zlib rather than bzlib2. In addition, bsdiff_z.exe and bspatch_z.exe are provided as command-line programs.
Note the license for bsdiff.
Copyright 2003-2005 Colin Percival
All rights reserved
Redistribution and use in source and binary forms, with or without
modification, are permitted providing that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
SQLite3
Includes SQLite3 modified to run on the nlib I/F.
The library supports multithreading, but a database cannot be accessed from multiple threads (because files are not locked). For the debug build, SQLITE_DEBUG_OS_TRACE is enabled during compilation. The command-line shell is sqlite3_nlib.exe.
SQLite3 is in the public domain.
When modifying code, script the parts corresponding to mem1.c, os_win.c, and mutex_w32.c as independent code that uses nLib.
The other SQLite3 compile settings are configured as follows.
#define SQLITE_OMIT_COMPILEOPTION_DIAGS
#define SQLITE_OMIT_DEPRECATED
#define SQLITE_OMIT_LOAD_EXTENSION
#define SQLITE_OMIT_LOCALTIME
#define SQLITE_OMIT_TCL_VARIABLE
#define SQLITE_OMIT_TRACE
#define SQLITE_OMIT_WAL
#define SQLITE_ENABLE_ATOMIC_WRITE 1
#define SQLITE_ENABLE_COLUMN_METADATA 1
#define SQLITE_ENABLE_EXPENSIVE_ASSERT 1
#define SQLITE_ENABLE_FTS3 1
#define SQLITE_ENABLE_FTS3_PARENTHESIS 1
#define SQLITE_ENABLE_FTS4 1
#define SQLITE_ENABLE_FTS4_UNICODE61 1
#define SQLITE_ENABLE_LOCKING_STYLE 2
#define SQLITE_ENABLE_MEMORY_MANAGEMENT 1
#define SQLITE_ENABLE_OVERSIZE_CELL_CHECK 1
#define SQLITE_ENABLE_RTREE 1
#define SQLITE_ENABLE_STAT3 1
#define SQLITE_ENABLE_TREE_EXPLAIN 1
#define SQLITE_ENABLE_UNLOCK_NOTIFY 1
#define SQLITE_ENABLE_UPDATE_DELETE_LIMIT 1
LZ4
Includes the LZ4 library that is a high-speed compression/decompression algorithm.. Does not include an LZ4 command-line program.
Note the license for LZ4.
LZ4 - Fast LZ compression algorithm
Header File
Copyright (C) 2011-2015, Yann Collet.
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
You can contact the author at :
- LZ4 source repository : https://github.com/Cyan4973/lz4
- LZ4 public forum :https://groups.google.com/forum/#!forum/lz4c
See also
http://www.daemonology.net/bsdiff/ (bsdiff)
https://www.sqlite.org/ (SQLite3)
https://github.com/Cyan4973/lz4 (LZ4)

Function Documentation

§ BsDiffZ()

nn::nlib::oss::BsDiffZ ( OutputStream patch,
void *  old_data,
size_t  old_size,
void *  new_data,
size_t  new_size 
)
noexcept

Creates a patch to update from the old data to the new data.

Parameters
[in]patchThe stream where patch data is written to.
[in]old_dataPointer to the old binary data that needs to be updated.
[in]old_sizeThe size of the old binary data.
[in]new_dataPointer to the new binary data.
[in]new_sizeThe size of the new binary data.
Returns
Returns 0 on success.
Description
bsdiff and bspatch are widely used for creating and applying patches to binary data. In this library, a library conversion is run so that bsdiff and bspatch use zlib rather than bzlib2 as the method of data compression.
Note that because zlib is used rather than bzlib2, the data created by bsdiff is different. The header signature is changed from BSDIFF40 to bsdiff40. You can also use the command-line program bsdiff_z to execute this function.
Examples:
oss/binarypatch/binarypatch.cpp.

§ BsPatchZ()

nn::nlib::oss::BsPatchZ ( OutputStream new_stream,
void *  old_data,
size_t  old_size,
void *  patch_data,
size_t  patch_size 
)
noexcept

Creates new data from the old data and the patch data.

Parameters
[in]new_streamThe stream that the new data should be written into.
[in]old_dataPointer to the old binary data that needs to be updated.
[in]old_sizeThe size of the old binary data.
[in]patch_dataPointer to the patch data.
[in]patch_sizeThe size of the patch data.
Returns
Returns 0 on success.
Description
Use this to apply the patch created using the BsDiffZ function and to get new data from the old data. You can also use the command-line program bspatch_z to execute this function.
Examples:
oss/binarypatch/binarypatch.cpp.