mirror of
https://github.com/avast/retdec.git
synced 2024-11-27 14:50:48 +00:00
deps/openssl: remove, require it as a prerequisite.
Also refactor (i.e. remove) RetDec's Crypto library.
This commit is contained in:
parent
33f77f7171
commit
6745288227
@ -6,6 +6,7 @@
|
||||
* Enhancement: YARA updated to version 4.0.1 ([#758](https://github.com/avast/retdec/issues/758)), fixed Mach-O parsing issue ([#283](https://github.com/avast/retdec/issues/283)).
|
||||
* Enhancement: Improved detection of many packers/installers/compilers in `retdec-fileinfo`, including Armadillo ([#733](https://github.com/avast/retdec/pull/733)), VMProtect ([#734](https://github.com/avast/retdec/pull/734), [#778](https://github.com/avast/retdec/pull/778)), Petite ([#735](https://github.com/avast/retdec/pull/735)), Enigma ([#741](https://github.com/avast/retdec/pull/741)), ASPack ([#743](https://github.com/avast/retdec/pull/743)), Eziriz ([#746](https://github.com/avast/retdec/pull/746)), PyInstaller ([#748](https://github.com/avast/retdec/pull/748)), Astrum InstallWizard ([#753](https://github.com/avast/retdec/pull/753)), AutoHotKey ([#756](https://github.com/avast/retdec/pull/756)), AutoIt ([#757](https://github.com/avast/retdec/pull/757)), BAT to PE-EXE script compilers ([#761](https://github.com/avast/retdec/pull/761)), Bero ([#764](https://github.com/avast/retdec/pull/764)), CExe ([#781](https://github.com/avast/retdec/pull/781)).
|
||||
* Enhancement: Enable .NET module in RetDec's YARA ([#747](https://github.com/avast/retdec/issues/747)).
|
||||
* Enhancement: Require OpenSSL as a prerequisite. It is no longer built by RetDec.
|
||||
* Fix: Fixed build on some systems by adding missing includes of `<limits>` into `retdec-fileinfo` ([#745](https://github.com/avast/retdec/pull/745)).
|
||||
* Fix: Fixed two type errors in `scripts/retdec-archive-decompiler.py` ([#759](https://github.com/avast/retdec/pull/759)).
|
||||
|
||||
|
@ -9,7 +9,6 @@ RUN apt-get -y update && \
|
||||
build-essential \
|
||||
cmake \
|
||||
git \
|
||||
perl \
|
||||
python3 \
|
||||
doxygen \
|
||||
graphviz \
|
||||
|
@ -9,7 +9,6 @@ RUN apt-get -y update && \
|
||||
build-essential \
|
||||
cmake \
|
||||
git \
|
||||
perl \
|
||||
python3 \
|
||||
doxygen \
|
||||
graphviz \
|
||||
|
@ -11,14 +11,13 @@ RetDec uses the following third-party libraries or other resources:
|
||||
3) Google Test: https://github.com/avast/googletest
|
||||
4) Keystone Engine: http://www.keystone-engine.org/
|
||||
5) LLVM: https://llvm.org/
|
||||
6) OpenSSL: https://www.openssl.org/
|
||||
7) RapidJSON: https://github.com/Tencent/rapidjson
|
||||
8) TinyXML-2: https://github.com/leethomason/tinyxml2
|
||||
9) whereami: https://github.com/gpakosz/whereami
|
||||
10) yara: https://virustotal.github.io/yara/
|
||||
11) yaramod: https://github.com/avast/yaramod
|
||||
12) Eigen: http://eigen.tuxfamily.org/index.php?title=Main_Page
|
||||
13) cmake-modules: https://github.com/rpavlik/cmake-modules
|
||||
6) RapidJSON: https://github.com/Tencent/rapidjson
|
||||
7) TinyXML-2: https://github.com/leethomason/tinyxml2
|
||||
8) whereami: https://github.com/gpakosz/whereami
|
||||
9) yara: https://virustotal.github.io/yara/
|
||||
10) yaramod: https://github.com/avast/yaramod
|
||||
11) Eigen: http://eigen.tuxfamily.org/index.php?title=Main_Page
|
||||
12) cmake-modules: https://github.com/rpavlik/cmake-modules
|
||||
|
||||
These third-party libraries or other resources are licensed under the
|
||||
following licenses:
|
||||
@ -517,137 +516,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
|
||||
SOFTWARE.
|
||||
|
||||
===============================================================================
|
||||
6) OpenSSL
|
||||
===============================================================================
|
||||
|
||||
LICENSE ISSUES
|
||||
==============
|
||||
|
||||
The OpenSSL toolkit stays under a dual license, i.e. both the conditions of
|
||||
the OpenSSL License and the original SSLeay license apply to the toolkit.
|
||||
See below for the actual license texts. Actually both licenses are BSD-style
|
||||
Open Source licenses. In case of any license issues related to OpenSSL
|
||||
please contact openssl-core@openssl.org.
|
||||
|
||||
OpenSSL License
|
||||
---------------
|
||||
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided 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.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED 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 OpenSSL PROJECT OR
|
||||
* ITS 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
Original SSLeay License
|
||||
-----------------------
|
||||
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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 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.
|
||||
*
|
||||
* The licence and distribution terms for any publicly available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
===============================================================================
|
||||
7) RapidJSON
|
||||
6) RapidJSON
|
||||
===============================================================================
|
||||
|
||||
Tencent is pleased to support the open source community by making RapidJSON available.
|
||||
@ -707,7 +576,7 @@ The above copyright notice and this permission notice shall be included in all c
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
===============================================================================
|
||||
8) TinyXML-2
|
||||
7) TinyXML-2
|
||||
===============================================================================
|
||||
|
||||
TinyXML-2 is released under the zlib license:
|
||||
@ -721,7 +590,7 @@ Permission is granted to anyone to use this software for any purpose, including
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
===============================================================================
|
||||
9) whereami
|
||||
8) whereami
|
||||
===============================================================================
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
@ -741,7 +610,7 @@ Permission is granted to anyone to use this software for any purpose, including
|
||||
2. Montesqieu et camembert, vive la France, zut alors!
|
||||
|
||||
===============================================================================
|
||||
10) YARA
|
||||
9) YARA
|
||||
===============================================================================
|
||||
|
||||
Copyright (c) 2007-2016. The YARA Authors. All Rights Reserved.
|
||||
@ -772,7 +641,7 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
===============================================================================
|
||||
11) yaramod
|
||||
10) yaramod
|
||||
===============================================================================
|
||||
|
||||
The MIT License (MIT)
|
||||
@ -796,3 +665,37 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
===============================================================================
|
||||
11) Eigen
|
||||
===============================================================================
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
===============================================================================
|
||||
12) cmake-modules
|
||||
===============================================================================
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
15
README.md
15
README.md
@ -144,7 +144,7 @@ This section describes a local build and installation of RetDec. Instructions fo
|
||||
* A C++ compiler and standard C++ library supporting C++17 (e.g. GCC >= 7)
|
||||
* [CMake](https://cmake.org/) (version >= 3.6)
|
||||
* [Git](https://git-scm.com/)
|
||||
* [Perl](https://www.perl.org/)
|
||||
* [OpenSSL](https://www.openssl.org/) (version >= 1.0.1)
|
||||
* [Python](https://www.python.org/) (version >= 3.4)
|
||||
* [autotools](https://en.wikipedia.org/wiki/GNU_Build_System) ([autoconf](https://www.gnu.org/software/autoconf/autoconf.html), [automake](https://www.gnu.org/software/automake/), and [libtool](https://www.gnu.org/software/libtool/))
|
||||
* [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/)
|
||||
@ -155,19 +155,19 @@ This section describes a local build and installation of RetDec. Instructions fo
|
||||
On Debian-based distributions (e.g. Ubuntu), the required packages can be installed with `apt-get`:
|
||||
|
||||
```sh
|
||||
sudo apt-get install build-essential cmake git perl python3 autoconf automake libtool pkg-config m4 zlib1g-dev upx doxygen graphviz
|
||||
sudo apt-get install build-essential cmake git openssl python3 autoconf automake libtool pkg-config m4 zlib1g-dev upx doxygen graphviz
|
||||
```
|
||||
|
||||
On RPM-based distributions (e.g. Fedora), the required packages can be installed with `dnf`:
|
||||
|
||||
```sh
|
||||
sudo dnf install gcc gcc-c++ cmake make git perl python3 autoconf automake libtool pkg-config m4 zlib-devel upx doxygen graphviz
|
||||
sudo dnf install gcc gcc-c++ cmake make git openssl python3 autoconf automake libtool pkg-config m4 zlib-devel upx doxygen graphviz
|
||||
```
|
||||
|
||||
On Arch Linux, the required packages can be installed with `pacman`:
|
||||
|
||||
```sh
|
||||
sudo pacman --needed -S base-devel cmake git perl python3 autoconf automake libtool pkg-config m4 zlib upx doxygen graphviz
|
||||
sudo pacman --needed -S base-devel cmake git openssl python3 autoconf automake libtool pkg-config m4 zlib upx doxygen graphviz
|
||||
```
|
||||
|
||||
#### Windows
|
||||
@ -175,7 +175,7 @@ sudo pacman --needed -S base-devel cmake git perl python3 autoconf automake libt
|
||||
* Microsoft Visual C++ (version >= Visual Studio 2017 version 15.7)
|
||||
* [CMake](https://cmake.org/) (version >= 3.6)
|
||||
* [Git](https://git-scm.com/)
|
||||
* [Active Perl](https://www.activestate.com/activeperl). It needs to be the first Perl in `PATH`, or it has to be provided to CMake using `CMAKE_PROGRAM_PATH` variable, e.g. `-DCMAKE_PROGRAM_PATH=/c/perl/bin`. Does NOT work with Strawberry Perl or MSYS2 Perl (you would have to install a pre-built version of OpenSSL, see below).
|
||||
* [OpenSSL](https://www.openssl.org/) (version >= 1.0.1)
|
||||
* [Python](https://www.python.org/) (version >= 3.4)
|
||||
* Optional: [Doxygen](http://ftp.stack.nl/pub/users/dimitri/doxygen-1.8.13-setup.exe) and [Graphviz](https://graphviz.gitlab.io/_pages/Download/windows/graphviz-2.38.msi) for generating API documentation
|
||||
|
||||
@ -187,7 +187,7 @@ Packages should be preferably installed via [Homebrew](https://brew.sh).
|
||||
* Full Xcode installation ([including command-line tools](https://github.com/frida/frida/issues/338#issuecomment-426777849), see [#425](https://github.com/avast/retdec/issues/425) and [#433](https://github.com/avast/retdec/issues/433))
|
||||
* [CMake](https://cmake.org/) (version >= 3.6)
|
||||
* [Git](https://git-scm.com/)
|
||||
* [Perl](https://www.perl.org/)
|
||||
* [OpenSSL](https://www.openssl.org/) (version >= 1.0.1)
|
||||
* [Python](https://www.python.org/) (version >= 3.4)
|
||||
* [autotools](https://en.wikipedia.org/wiki/GNU_Build_System) ([autoconf](https://www.gnu.org/software/autoconf/autoconf.html), [automake](https://www.gnu.org/software/automake/), and [libtool](https://www.gnu.org/software/libtool/))
|
||||
* Optional: [Doxygen](http://www.stack.nl/~dimitri/doxygen/) and [Graphviz](http://www.graphviz.org/) for generating API documentation
|
||||
@ -239,7 +239,7 @@ Note: Although RetDec now supports a system-wide installation ([#94](https://git
|
||||
* `cd retdec`
|
||||
* `mkdir build && cd build`
|
||||
* ```sh
|
||||
# FreeBSD (and other BSDs) do need cmake, python3, git, autotools. Perl is pre-installed in the OS but check its version.
|
||||
# FreeBSD (and other BSDs) do need cmake, python3, git, autotools. OpenSSL is pre-installed in the OS but check its version.
|
||||
# Later versions may be available for each of the packages.
|
||||
# See what is installed:
|
||||
sudo pkg info cmake python37 autotools
|
||||
@ -260,7 +260,6 @@ You can pass the following additional parameters to `cmake`:
|
||||
* `-DRETDEC_DEV_TOOLS=ON` to build with development tools (disabled by default).
|
||||
* `-DRETDEC_COMPILE_YARA=OFF` to disable YARA rules compilation at installation step (enabled by default).
|
||||
* `-DCMAKE_BUILD_TYPE=Debug` to build with debugging information, which is useful during development. By default, the project is built in the `Release` mode. This has no effect on Windows, but the same thing can be achieved by running `cmake --build .` with the `--config Debug` parameter.
|
||||
* `-DCMAKE_PROGRAM_PATH=<path>` to use Perl at `<path>` (probably useful only on Windows).
|
||||
* `-D<dep>_LOCAL_DIR=<path>` where `<dep>` is from `{CAPSTONE, GOOGLETEST, KEYSTONE, LLVM, YARA, YARAMOD}` (e.g. `-DCAPSTONE_LOCAL_DIR=<path>`), to use the local repository clone at `<path>` for RetDec dependency instead of downloading a fresh copy at build time. Multiple such options may be used at the same time.
|
||||
* `-DRETDEC_ENABLE_<component>=ON` to build only the specified component(s) (multiple such options can be used at once), and its (theirs) dependencies. By default, all the components are built. If at least one component is enabled via this mechanism, all the other components that were not explicitly enabled (and are not needed as dependencies of enabled components) are not built. See [cmake/options.cmake](https://github.com/avast/retdec/blob/master/cmake/options.cmake) for all the available component options.
|
||||
* `-DRETDEC_ENABLE_ALL=ON` can be used to (re-)enable all the components.
|
||||
|
@ -35,16 +35,6 @@ set(LLVM_ARCHIVE_SHA256
|
||||
CACHE INTERNAL ""
|
||||
)
|
||||
|
||||
# Commit for tag 1.1.1c
|
||||
set(OPENSSL_URL
|
||||
"https://github.com/openssl/openssl/archive/97ace46e11dba4c4c2b7cb67140b6ec152cfaaf4.zip"
|
||||
CACHE INTERNAL "URL of OpenSSL archive to use."
|
||||
)
|
||||
set(OPENSSL_ARCHIVE_SHA256
|
||||
"f093df5cfd7521d8f6a09f250d7e69159d1001c47419130e806488de8a6312d8"
|
||||
CACHE INTERNAL ""
|
||||
)
|
||||
|
||||
set(YARA_URL
|
||||
"https://github.com/VirusTotal/yara/archive/v4.0.1.zip"
|
||||
CACHE INTERNAL "URL of Yara archive to use."
|
||||
|
@ -18,7 +18,6 @@ option(RETDEC_ENABLE_CAPSTONE2LLVMIRTOOL "" OFF)
|
||||
option(RETDEC_ENABLE_COMMON "" OFF)
|
||||
option(RETDEC_ENABLE_CONFIG "" OFF)
|
||||
option(RETDEC_ENABLE_CPDETECT "" OFF)
|
||||
option(RETDEC_ENABLE_CRYPTO "" OFF)
|
||||
option(RETDEC_ENABLE_CTYPES "" OFF)
|
||||
option(RETDEC_ENABLE_CTYPESPARSER "" OFF)
|
||||
option(RETDEC_ENABLE_DEBUGFORMAT "" OFF)
|
||||
@ -76,7 +75,6 @@ foreach(t ${RETDEC_ENABLE})
|
||||
set_if_equal(${t} "common" RETDEC_ENABLE_COMMON)
|
||||
set_if_equal(${t} "config" RETDEC_ENABLE_CONFIG)
|
||||
set_if_equal(${t} "cpdetect" RETDEC_ENABLE_CPDETECT)
|
||||
set_if_equal(${t} "crypto" RETDEC_ENABLE_CRYPTO)
|
||||
set_if_equal(${t} "ctypes" RETDEC_ENABLE_CTYPES)
|
||||
set_if_equal(${t} "ctypesparser" RETDEC_ENABLE_CTYPESPARSER)
|
||||
set_if_equal(${t} "debugformat" RETDEC_ENABLE_DEBUGFORMAT)
|
||||
@ -120,7 +118,6 @@ if (RETDEC_ENABLE_AR_EXTRACTOR
|
||||
OR RETDEC_ENABLE_COMMON
|
||||
OR RETDEC_ENABLE_CONFIG
|
||||
OR RETDEC_ENABLE_CPDETECT
|
||||
OR RETDEC_ENABLE_CRYPTO
|
||||
OR RETDEC_ENABLE_CTYPES
|
||||
OR RETDEC_ENABLE_CTYPESPARSER
|
||||
OR RETDEC_ENABLE_DEBUGFORMAT
|
||||
@ -332,10 +329,6 @@ set_if_at_least_one_set(RETDEC_ENABLE_PELIB
|
||||
RETDEC_ENABLE_FILEFORMAT
|
||||
RETDEC_ENABLE_UNPACKERTOOL)
|
||||
|
||||
set_if_at_least_one_set(RETDEC_ENABLE_CRYPTO
|
||||
RETDEC_ENABLE_ALL
|
||||
RETDEC_ENABLE_FILEFORMAT)
|
||||
|
||||
set_if_at_least_one_set(RETDEC_ENABLE_LLVM_SUPPORT
|
||||
RETDEC_ENABLE_ALL
|
||||
RETDEC_ENABLE_BIN2LLVMIR
|
||||
@ -373,7 +366,6 @@ set_if_at_least_one_set(RETDEC_ENABLE_UTILS
|
||||
RETDEC_ENABLE_CAPSTONE2LLVMIRTOOL
|
||||
RETDEC_ENABLE_CONFIG
|
||||
RETDEC_ENABLE_COMMON
|
||||
RETDEC_ENABLE_CRYPTO
|
||||
RETDEC_ENABLE_CTYPES
|
||||
RETDEC_ENABLE_CTYPESPARSER
|
||||
RETDEC_ENABLE_FILEFORMAT
|
||||
@ -485,9 +477,6 @@ set_if_at_least_one_set(RETDEC_ENABLE_LLVM
|
||||
RETDEC_ENABLE_CPDETECT
|
||||
RETDEC_ENABLE_DEBUGFORMAT)
|
||||
|
||||
set_if_at_least_one_set(RETDEC_ENABLE_OPENSLL
|
||||
RETDEC_ENABLE_CRYPTO)
|
||||
|
||||
set_if_at_least_one_set(RETDEC_ENABLE_RAPIDJSON
|
||||
RETDEC_ENABLE_AR_EXTRACTOR
|
||||
RETDEC_ENABLE_AR_EXTRACTORTOOL
|
||||
|
1
deps/CMakeLists.txt
vendored
1
deps/CMakeLists.txt
vendored
@ -19,7 +19,6 @@ cond_add_subdirectory(elfio RETDEC_ENABLE_ELFIO)
|
||||
cond_add_subdirectory(googletest RETDEC_ENABLE_GOOGLETEST)
|
||||
cond_add_subdirectory(keystone RETDEC_ENABLE_KEYSTONE)
|
||||
cond_add_subdirectory(llvm RETDEC_ENABLE_LLVM)
|
||||
cond_add_subdirectory(openssl RETDEC_ENABLE_OPENSLL)
|
||||
cond_add_subdirectory(rapidjson RETDEC_ENABLE_RAPIDJSON)
|
||||
cond_add_subdirectory(tinyxml2 RETDEC_ENABLE_TINYXML2)
|
||||
cond_add_subdirectory(whereami RETDEC_ENABLE_WHEREAMI)
|
||||
|
229
deps/openssl/CMakeLists.txt
vendored
229
deps/openssl/CMakeLists.txt
vendored
@ -1,229 +0,0 @@
|
||||
|
||||
find_package(Perl REQUIRED)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
# Detect architecture.
|
||||
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
|
||||
set(ARCH_X64 1)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
|
||||
set(ARCH_X86 1)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm.*")
|
||||
string(REGEX REPLACE "armv([0-9]+).*" "\\1" ARM_VERSION "${CMAKE_SYSTEM_PROCESSOR}")
|
||||
if(${ARM_VERSION} LESS 8)
|
||||
set(ARCH_ARM32 1)
|
||||
else()
|
||||
set(ARCH_ARM64 1)
|
||||
endif()
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "aarch64")
|
||||
set(ARCH_ARM64 1)
|
||||
else()
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
set(ARCH_GENERIC32 1)
|
||||
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(ARCH_GENERIC64 1)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Detect OS.
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
set(OS_WINDOWS 1)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
set(OS_LINUX 1)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||
set(OS_DARWIN 1)
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported system. Supported: Windows, Linux, macOS.")
|
||||
endif()
|
||||
|
||||
# Detect compiler.
|
||||
if(OS_WINDOWS)
|
||||
if(MSVC)
|
||||
set(COMPILER_MSVC 1)
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported compiler. Supported: MSVC.")
|
||||
endif()
|
||||
elseif(OS_LINUX)
|
||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
set(COMPILER_GCC 1)
|
||||
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
set(COMPILER_CLANG 1)
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported compiler. Supported: GCC, Clang.")
|
||||
endif()
|
||||
elseif(OS_DARWIN)
|
||||
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
|
||||
message(FATAL_ERROR "Unsupported compiler. Supported: AppleClang.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Prepare configuration option for OpenSSL.
|
||||
if(OS_WINDOWS)
|
||||
if(COMPILER_MSVC)
|
||||
set(OPENSSL_MAKE "nmake")
|
||||
if(ARCH_X86)
|
||||
set(OPENSSL_CONFIGURE_ARCH "VC-WIN32")
|
||||
elseif(ARCH_X64)
|
||||
set(OPENSSL_CONFIGURE_ARCH "VC-WIN64A")
|
||||
elseif(ARCH_ARM32)
|
||||
set(OPENSSL_CONFIGURE_ARCH "VC-WIN32-ARM")
|
||||
elseif(ARCH_ARM64)
|
||||
set(OPENSSL_CONFIGURE_ARCH "VC-WIN64-ARM")
|
||||
endif()
|
||||
endif()
|
||||
elseif(OS_LINUX)
|
||||
set(OPENSSL_MAKE make -j${CPUS})
|
||||
if(ARCH_X86)
|
||||
if(COMPILER_GCC)
|
||||
set(OPENSSL_CONFIGURE_ARCH "linux-x86")
|
||||
elseif(COMPILER_CLANG)
|
||||
set(OPENSSL_CONFIGURE_ARCH "linux-x86-clang")
|
||||
endif()
|
||||
elseif(ARCH_X64)
|
||||
if(COMPILER_GCC)
|
||||
set(OPENSSL_CONFIGURE_ARCH "linux-x86_64")
|
||||
elseif(COMPILER_CLANG)
|
||||
set(OPENSSL_CONFIGURE_ARCH "linux-x86_64-clang")
|
||||
endif()
|
||||
elseif(ARCH_ARM32)
|
||||
set(OPENSSL_CONFIGURE_ARCH "linux-armv4")
|
||||
elseif(ARCH_ARM64)
|
||||
set(OPENSSL_CONFIGURE_ARCH "linux-aarch64")
|
||||
elseif(ARCH_GENERIC32)
|
||||
set(OPENSSL_CONFIGURE_ARCH "linux-generic32")
|
||||
elseif(ARCH_GENERIC64)
|
||||
set(OPENSSL_CONFIGURE_ARCH "linux-generic64")
|
||||
endif()
|
||||
elseif(OS_DARWIN)
|
||||
execute_process(
|
||||
COMMAND xcrun --show-sdk-path
|
||||
OUTPUT_VARIABLE MACOS_SDK_PATH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
set(OPENSSL_MAKE make SDKROOT=${MACOS_SDK_PATH} -j${CPUS})
|
||||
if(ARCH_X86)
|
||||
set(OPENSSL_CONFIGURE_ARCH "darwin-i386-cc")
|
||||
elseif(ARCH_X64)
|
||||
set(OPENSSL_CONFIGURE_ARCH "darwin64-x86_64-cc")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Unrecognized architecture.
|
||||
if(NOT DEFINED OPENSSL_CONFIGURE_ARCH)
|
||||
message(FATAL_ERROR "Unsupported architecture. Supported: x86, x86-64, ARM, generic 32-bit (Linux only), generic 64-bit (Linux only).")
|
||||
endif()
|
||||
|
||||
set(OPENSSL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/openssl")
|
||||
set(OPENSSL_SRC_DIR "${OPENSSL_PREFIX}/src/openssl")
|
||||
set(OPENSSL_INSTALL_DIR "${OPENSSL_PREFIX}/src/openssl-install")
|
||||
set(OPENSSL_VERSION "1.1.1c")
|
||||
set(OPENSSL_DOWNLOAD_NAME "openssl.tar.gz")
|
||||
|
||||
set(OPENSSL_CONFIGURE_OPTIONS
|
||||
no-shared
|
||||
no-asm
|
||||
--prefix=${OPENSSL_INSTALL_DIR}
|
||||
--openssldir=${OPENSSL_INSTALL_DIR}
|
||||
)
|
||||
|
||||
ExternalProject_Add(openssl
|
||||
PREFIX ${OPENSSL_PREFIX}
|
||||
URL ${OPENSSL_URL}
|
||||
URL_HASH SHA256=${OPENSSL_ARCHIVE_SHA256}
|
||||
DOWNLOAD_NAME ${OPENSSL_DOWNLOAD_NAME}
|
||||
CONFIGURE_COMMAND
|
||||
${PERL_EXECUTABLE}
|
||||
${OPENSSL_SRC_DIR}/Configure
|
||||
${OPENSSL_CONFIGURE_OPTIONS}
|
||||
${OPENSSL_CONFIGURE_ARCH}
|
||||
BUILD_IN_SOURCE 1
|
||||
BUILD_COMMAND
|
||||
${OPENSSL_MAKE}
|
||||
INSTALL_COMMAND
|
||||
# Install only the software parts (libraries and includes), not
|
||||
# e.g. documentation and manual pages.
|
||||
${OPENSSL_MAKE} install_sw
|
||||
LOG_DOWNLOAD 1
|
||||
LOG_BUILD 1
|
||||
LOG_CONFIGURE 1
|
||||
LOG_INSTALL 1
|
||||
)
|
||||
|
||||
set(OPENSSL_CRYPTO_LIB_NAME libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||
set(OPENSSL_CRYPTO_LIB_PNAME libretdec-openssl-crypto${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||
set(OPENSSL_CRYPTO_LIB ${OPENSSL_INSTALL_DIR}/lib/${OPENSSL_CRYPTO_LIB_NAME})
|
||||
|
||||
# Create target.
|
||||
add_library(openssl-crypto INTERFACE)
|
||||
add_library(retdec::deps::openssl-crypto ALIAS openssl-crypto)
|
||||
add_dependencies(openssl-crypto openssl)
|
||||
|
||||
target_include_directories(openssl-crypto
|
||||
SYSTEM INTERFACE
|
||||
$<BUILD_INTERFACE:${OPENSSL_INSTALL_DIR}/include>
|
||||
$<INSTALL_INTERFACE:${RETDEC_INSTALL_DEPS_INCLUDE_DIR}>
|
||||
)
|
||||
|
||||
target_link_libraries(openssl-crypto
|
||||
INTERFACE
|
||||
$<BUILD_INTERFACE:${OPENSSL_CRYPTO_LIB}>
|
||||
$<INSTALL_INTERFACE:retdec::deps::openssl-crypto-libs>
|
||||
Threads::Threads
|
||||
)
|
||||
if(MSVC)
|
||||
target_link_libraries(openssl-crypto
|
||||
INTERFACE
|
||||
ws2_32
|
||||
gdi32
|
||||
advapi32
|
||||
crypt32
|
||||
user32
|
||||
)
|
||||
elseif(UNIX)
|
||||
target_link_libraries(openssl-crypto
|
||||
INTERFACE
|
||||
${CMAKE_DL_LIBS}
|
||||
)
|
||||
endif()
|
||||
|
||||
# Install includes.
|
||||
install(
|
||||
DIRECTORY ${OPENSSL_INSTALL_DIR}/include/
|
||||
DESTINATION ${RETDEC_INSTALL_DEPS_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
# Install libs.
|
||||
install(
|
||||
FILES ${OPENSSL_CRYPTO_LIB}
|
||||
DESTINATION ${RETDEC_INSTALL_LIB_DIR}
|
||||
RENAME ${OPENSSL_CRYPTO_LIB_PNAME}
|
||||
)
|
||||
|
||||
# Install targets.
|
||||
install(TARGETS openssl-crypto
|
||||
EXPORT openssl-crypto-targets
|
||||
)
|
||||
|
||||
# Export targets.
|
||||
install(EXPORT openssl-crypto-targets
|
||||
FILE "retdec-openssl-crypto-targets.cmake"
|
||||
NAMESPACE retdec::deps::
|
||||
DESTINATION ${RETDEC_INSTALL_CMAKE_DIR}
|
||||
)
|
||||
|
||||
# Configure config file.
|
||||
set(OPENSSL_CRYPTO_LIB_INSTALLED "${RETDEC_INSTALL_LIB_DIR_ABS}/${OPENSSL_CRYPTO_LIB_PNAME}")
|
||||
configure_package_config_file(
|
||||
"retdec-openssl-crypto-config.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/retdec-openssl-crypto-config.cmake"
|
||||
INSTALL_DESTINATION ${RETDEC_INSTALL_CMAKE_DIR}
|
||||
PATH_VARS
|
||||
OPENSSL_CRYPTO_LIB_INSTALLED
|
||||
)
|
||||
|
||||
# Install CMake files.
|
||||
install(
|
||||
FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/retdec-openssl-crypto-config.cmake"
|
||||
DESTINATION
|
||||
"${RETDEC_INSTALL_CMAKE_DIR}"
|
||||
)
|
13
deps/openssl/retdec-openssl-crypto-config.cmake
vendored
13
deps/openssl/retdec-openssl-crypto-config.cmake
vendored
@ -1,13 +0,0 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
if(NOT TARGET retdec::deps::openssl-crypto-libs)
|
||||
add_library(retdec::deps::openssl-crypto-libs STATIC IMPORTED)
|
||||
set_target_properties(retdec::deps::openssl-crypto-libs PROPERTIES
|
||||
IMPORTED_LOCATION @PACKAGE_OPENSSL_CRYPTO_LIB_INSTALLED@
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT TARGET retdec::deps::openssl-crypto)
|
||||
find_package(Threads REQUIRED)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/retdec-openssl-crypto-targets.cmake)
|
||||
endif()
|
@ -1,51 +0,0 @@
|
||||
/**
|
||||
* @file include/retdec/crypto/hash_context.h
|
||||
* @brief Declaration of class HashContext.
|
||||
* @copyright (c) 2017 Avast Software, licensed under the MIT license
|
||||
*/
|
||||
|
||||
#ifndef RETDEC_CRYPTO_HASH_CONTEXT_H
|
||||
#define RETDEC_CRYPTO_HASH_CONTEXT_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Forward declare OpenSSL structures used in this header.
|
||||
typedef struct evp_md_ctx_st EVP_MD_CTX;
|
||||
typedef struct evp_md_st EVP_MD;
|
||||
|
||||
namespace retdec {
|
||||
namespace crypto {
|
||||
|
||||
enum class HashAlgorithm
|
||||
{
|
||||
Sha1,
|
||||
Sha256,
|
||||
Md5
|
||||
};
|
||||
|
||||
/**
|
||||
* This class represents continuous hashing of data from multiple sources.
|
||||
*/
|
||||
class HashContext
|
||||
{
|
||||
public:
|
||||
HashContext();
|
||||
~HashContext();
|
||||
|
||||
bool init(HashAlgorithm algorithm);
|
||||
bool addData(const std::uint8_t* data, std::size_t size);
|
||||
bool addData(const std::vector<std::uint8_t>& data);
|
||||
std::string getHash();
|
||||
|
||||
private:
|
||||
EVP_MD_CTX* _ctx; ///< OpenSSL envelope message digest context.
|
||||
|
||||
const EVP_MD* _currentAlgo; ///< Internal. Currently used message digest algorithm.
|
||||
};
|
||||
|
||||
} // namespace crypto
|
||||
} // namespace retdec
|
||||
|
||||
#endif
|
@ -7,7 +7,6 @@
|
||||
#ifndef RETDEC_FILEFORMAT_FILE_FORMAT_PE_PE_FORMAT_H
|
||||
#define RETDEC_FILEFORMAT_FILE_FORMAT_PE_PE_FORMAT_H
|
||||
|
||||
#include "retdec/crypto/hash_context.h"
|
||||
#include "retdec/fileformat/file_format/file_format.h"
|
||||
#include "retdec/fileformat/file_format/pe/pe_format_parser/pe_format_parser.h"
|
||||
#include "retdec/fileformat/types/dotnet_headers/blob_stream.h"
|
||||
@ -21,6 +20,7 @@
|
||||
|
||||
// Forward declare OpenSSL structures used in this header.
|
||||
typedef struct pkcs7_st PKCS7;
|
||||
typedef struct evp_md_st EVP_MD;
|
||||
|
||||
namespace retdec {
|
||||
namespace fileformat {
|
||||
@ -86,7 +86,7 @@ class PeFormat : public FileFormat
|
||||
/// @{
|
||||
bool verifySignature(PKCS7 *p7);
|
||||
std::vector<std::tuple<const std::uint8_t*, std::size_t>> getDigestRanges() const;
|
||||
std::string calculateDigest(retdec::crypto::HashAlgorithm hashType) const;
|
||||
std::string calculateDigest(const EVP_MD* algorithm) const;
|
||||
/// @}
|
||||
|
||||
/// @name .NET methods
|
||||
|
@ -1,25 +1,24 @@
|
||||
/**
|
||||
* @file include/retdec/crypto/crypto.h
|
||||
* @brief Cryptography-related functions.
|
||||
* @copyright (c) 2017 Avast Software, licensed under the MIT license
|
||||
*/
|
||||
* @file include/retdec/fileformat/utils/crypto.h
|
||||
* @brief Crypto functions.
|
||||
* @copyright (c) 2020 Avast Software, licensed under the MIT license
|
||||
*/
|
||||
|
||||
#ifndef RETDEC_CRYPTO_CRYPTO_H
|
||||
#define RETDEC_CRYPTO_CRYPTO_H
|
||||
#ifndef RETDEC_FILEFORMAT_UTILS_CRYPTO_H
|
||||
#define RETDEC_FILEFORMAT_UTILS_CRYPTO_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace retdec {
|
||||
namespace crypto {
|
||||
namespace fileformat {
|
||||
|
||||
std::uint64_t getCrc16(const unsigned char *data, std::uint64_t length);
|
||||
std::string getCrc32(const unsigned char *data, std::uint64_t length);
|
||||
std::string getMd5(const unsigned char *data, std::uint64_t length);
|
||||
std::string getSha1(const unsigned char *data, std::uint64_t length);
|
||||
std::string getSha256(const unsigned char *data, std::uint64_t length);
|
||||
|
||||
} // namespace crypto
|
||||
} // namespace fileformat
|
||||
} // namespace retdec
|
||||
|
||||
#endif
|
||||
#endif
|
@ -9,8 +9,8 @@
|
||||
// and conform to the coding standards of the RetDec project.
|
||||
// !!!
|
||||
|
||||
#ifndef RETDEC_CRYPTO_CRC32_H
|
||||
#define RETDEC_CRYPTO_CRC32_H
|
||||
#ifndef RETDEC_UTILS_CRC32_H
|
||||
#define RETDEC_UTILS_CRC32_H
|
||||
|
||||
//#include "hash.h"
|
||||
#include <string>
|
||||
@ -25,6 +25,9 @@ using uint32_t = unsigned __int32;
|
||||
#include <cstdint>
|
||||
#endif
|
||||
|
||||
namespace retdec {
|
||||
namespace utils {
|
||||
|
||||
/// compute CRC32 hash, based on Intel's Slicing-by-8 algorithm
|
||||
/** Usage:
|
||||
CRC32 crc32;
|
||||
@ -73,4 +76,7 @@ private:
|
||||
uint32_t m_hash;
|
||||
};
|
||||
|
||||
} // namespace utils
|
||||
} // namespace retdec
|
||||
|
||||
#endif
|
@ -7,7 +7,6 @@ cond_add_subdirectory(capstone2llvmirtool RETDEC_ENABLE_CAPSTONE2LLVMIRTOOL)
|
||||
cond_add_subdirectory(common RETDEC_ENABLE_COMMON)
|
||||
cond_add_subdirectory(config RETDEC_ENABLE_CONFIG)
|
||||
cond_add_subdirectory(cpdetect RETDEC_ENABLE_CPDETECT)
|
||||
cond_add_subdirectory(crypto RETDEC_ENABLE_CRYPTO)
|
||||
cond_add_subdirectory(ctypes RETDEC_ENABLE_CTYPES)
|
||||
cond_add_subdirectory(ctypesparser RETDEC_ENABLE_CTYPESPARSER)
|
||||
cond_add_subdirectory(debugformat RETDEC_ENABLE_DEBUGFORMAT)
|
||||
|
@ -1,60 +0,0 @@
|
||||
|
||||
add_library(crypto STATIC
|
||||
crc32.cpp
|
||||
crypto.cpp
|
||||
hash_context.cpp
|
||||
)
|
||||
add_library(retdec::crypto ALIAS crypto)
|
||||
|
||||
target_compile_features(crypto PUBLIC cxx_std_17)
|
||||
|
||||
target_include_directories(crypto
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${RETDEC_INCLUDE_DIR}>
|
||||
$<INSTALL_INTERFACE:${RETDEC_INSTALL_INCLUDE_DIR}>
|
||||
)
|
||||
|
||||
target_link_libraries(crypto
|
||||
PUBLIC
|
||||
retdec::deps::openssl-crypto
|
||||
PRIVATE
|
||||
retdec::utils
|
||||
)
|
||||
|
||||
set_target_properties(crypto
|
||||
PROPERTIES
|
||||
OUTPUT_NAME "retdec-crypto"
|
||||
)
|
||||
|
||||
# Install includes.
|
||||
install(
|
||||
DIRECTORY ${RETDEC_INCLUDE_DIR}/retdec/crypto
|
||||
DESTINATION ${RETDEC_INSTALL_INCLUDE_DIR}/retdec
|
||||
)
|
||||
|
||||
# Install libs.
|
||||
install(TARGETS crypto
|
||||
EXPORT crypto-targets
|
||||
ARCHIVE DESTINATION ${RETDEC_INSTALL_LIB_DIR}
|
||||
LIBRARY DESTINATION ${RETDEC_INSTALL_LIB_DIR}
|
||||
)
|
||||
|
||||
# Export targets.
|
||||
install(EXPORT crypto-targets
|
||||
FILE "retdec-crypto-targets.cmake"
|
||||
NAMESPACE retdec::
|
||||
DESTINATION ${RETDEC_INSTALL_CMAKE_DIR}
|
||||
)
|
||||
|
||||
# Install CMake files.
|
||||
configure_file(
|
||||
"retdec-crypto-config.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/retdec-crypto-config.cmake"
|
||||
@ONLY
|
||||
)
|
||||
install(
|
||||
FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/retdec-crypto-config.cmake"
|
||||
DESTINATION
|
||||
"${RETDEC_INSTALL_CMAKE_DIR}"
|
||||
)
|
@ -1,108 +0,0 @@
|
||||
/**
|
||||
* @file src/crypto/hash_context.cpp
|
||||
* @brief Implementation of class HashContext.
|
||||
* @copyright (c) 2017 Avast Software, licensed under the MIT license
|
||||
*/
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#include "retdec/crypto/hash_context.h"
|
||||
#include "retdec/utils/container.h"
|
||||
#include "retdec/utils/conversion.h"
|
||||
|
||||
namespace retdec {
|
||||
namespace crypto {
|
||||
|
||||
namespace {
|
||||
|
||||
const std::unordered_map<HashAlgorithm, const EVP_MD*, retdec::utils::EnumClassKeyHash> opensslAlgos =
|
||||
{
|
||||
{ HashAlgorithm::Sha1, EVP_sha1() },
|
||||
{ HashAlgorithm::Sha256, EVP_sha256() },
|
||||
{ HashAlgorithm::Md5, EVP_md5() }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
HashContext::HashContext() : _ctx(EVP_MD_CTX_create()), _currentAlgo(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
HashContext::~HashContext()
|
||||
{
|
||||
EVP_MD_CTX_destroy(_ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes hashing context with specified algorithm.
|
||||
* This method should be called whenever we start to hash
|
||||
* new set of data.
|
||||
*
|
||||
* @param algorithm Hashing algorithm to use.
|
||||
*
|
||||
* @return @c true if success, otherwise @c false.
|
||||
*/
|
||||
bool HashContext::init(HashAlgorithm algorithm)
|
||||
{
|
||||
auto itr = opensslAlgos.find(algorithm);
|
||||
if (itr == opensslAlgos.end())
|
||||
return false;
|
||||
|
||||
_currentAlgo = itr->second;
|
||||
return EVP_DigestInit(_ctx, _currentAlgo) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the new data to hash.
|
||||
*
|
||||
* @param data Pointer to the start of data.
|
||||
* @param size Size of data.
|
||||
*
|
||||
* @return @c true if success, otherwise @c false.
|
||||
*/
|
||||
bool HashContext::addData(const std::uint8_t* data, std::size_t size)
|
||||
{
|
||||
return EVP_DigestUpdate(_ctx, data, size) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the new data to hash.
|
||||
*
|
||||
* @param data Data to hash.
|
||||
*
|
||||
* @return @c true if success, otherwise @c false.
|
||||
*/
|
||||
bool HashContext::addData(const std::vector<std::uint8_t>& data)
|
||||
{
|
||||
return addData(data.data(), data.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the final hash of all added data.
|
||||
*
|
||||
* @return The final hash of the algorithm. Empty string in case of an error.
|
||||
*/
|
||||
std::string HashContext::getHash()
|
||||
{
|
||||
if (_currentAlgo == nullptr)
|
||||
return {};
|
||||
|
||||
std::vector<std::uint8_t> hash(EVP_MD_size(_currentAlgo));
|
||||
if (EVP_DigestFinal(_ctx, hash.data(), nullptr) != 1)
|
||||
return {};
|
||||
|
||||
std::string ret;
|
||||
retdec::utils::bytesToHexString(hash, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace crypto
|
||||
} // namespace retdec
|
@ -1,12 +0,0 @@
|
||||
|
||||
if(NOT TARGET retdec::crypto)
|
||||
find_package(Threads REQUIRED)
|
||||
find_package(retdec @PROJECT_VERSION@
|
||||
REQUIRED
|
||||
COMPONENTS
|
||||
utils
|
||||
openssl-crypto
|
||||
)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/retdec-crypto-targets.cmake)
|
||||
endif()
|
@ -1,8 +1,11 @@
|
||||
|
||||
find_package(OpenSSL 1.0.1 REQUIRED)
|
||||
|
||||
add_library(fileformat STATIC
|
||||
utils/format_detection.cpp
|
||||
utils/byte_array_buffer.cpp
|
||||
utils/conversions.cpp
|
||||
utils/crypto.cpp
|
||||
utils/other.cpp
|
||||
utils/asn1.cpp
|
||||
utils/file_io.cpp
|
||||
@ -87,12 +90,13 @@ target_include_directories(fileformat
|
||||
|
||||
target_link_libraries(fileformat
|
||||
PUBLIC
|
||||
retdec::crypto
|
||||
retdec::common
|
||||
retdec::utils
|
||||
retdec::pelib
|
||||
retdec::deps::elfio
|
||||
retdec::deps::llvm
|
||||
PRIVATE
|
||||
OpenSSL::Crypto
|
||||
)
|
||||
|
||||
set_target_properties(fileformat
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "retdec/crypto/crypto.h"
|
||||
#include "retdec/utils/conversion.h"
|
||||
#include "retdec/utils/file_io.h"
|
||||
#include "retdec/utils/string.h"
|
||||
@ -23,6 +22,7 @@
|
||||
#include "retdec/fileformat/file_format/raw_data/raw_data_format.h"
|
||||
#include "retdec/fileformat/types/strings/character_iterator.h"
|
||||
#include "retdec/fileformat/utils/conversions.h"
|
||||
#include "retdec/fileformat/utils/crypto.h"
|
||||
#include "retdec/fileformat/utils/file_io.h"
|
||||
#include "retdec/fileformat/utils/other.h"
|
||||
#include "retdec/pelib/PeLibInc.h"
|
||||
@ -197,9 +197,9 @@ void FileFormat::init()
|
||||
}
|
||||
else
|
||||
{
|
||||
crc32 = retdec::crypto::getCrc32(bytes.data(), bytes.size());
|
||||
md5 = retdec::crypto::getMd5(bytes.data(), bytes.size());
|
||||
sha256 = retdec::crypto::getSha256(bytes.data(), bytes.size());
|
||||
crc32 = retdec::fileformat::getCrc32(bytes.data(), bytes.size());
|
||||
md5 = retdec::fileformat::getMd5(bytes.data(), bytes.size());
|
||||
sha256 = retdec::fileformat::getSha256(bytes.data(), bytes.size());
|
||||
}
|
||||
initStream();
|
||||
}
|
||||
@ -314,9 +314,9 @@ void FileFormat::computeSectionTableHashes()
|
||||
|
||||
if(!data.empty())
|
||||
{
|
||||
sectionCrc32 = retdec::crypto::getCrc32(data.data(), data.size());
|
||||
sectionMd5 = retdec::crypto::getMd5(data.data(), data.size());
|
||||
sectionSha256 = retdec::crypto::getSha256(data.data(), data.size());
|
||||
sectionCrc32 = retdec::fileformat::getCrc32(data.data(), data.size());
|
||||
sectionMd5 = retdec::fileformat::getMd5(data.data(), data.size());
|
||||
sectionSha256 = retdec::fileformat::getSha256(data.data(), data.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#include "retdec/utils/container.h"
|
||||
#include "retdec/utils/conversion.h"
|
||||
@ -28,8 +29,8 @@
|
||||
#include "retdec/fileformat/types/visual_basic/visual_basic_structures.h"
|
||||
#include "retdec/fileformat/utils/asn1.h"
|
||||
#include "retdec/fileformat/utils/conversions.h"
|
||||
#include "retdec/fileformat/utils/crypto.h"
|
||||
#include "retdec/fileformat/utils/file_io.h"
|
||||
#include "retdec/crypto/crypto.h"
|
||||
|
||||
using namespace retdec::utils;
|
||||
using namespace PeLib;
|
||||
@ -2147,13 +2148,13 @@ bool PeFormat::verifySignature(PKCS7 *p7)
|
||||
|
||||
auto digestAlgoOIDStr = std::static_pointer_cast<Asn1Object>(digestAlgoOID)->getIdentifier();
|
||||
|
||||
retdec::crypto::HashAlgorithm algorithm;
|
||||
const EVP_MD* algorithm = nullptr;
|
||||
if (digestAlgoOIDStr == DigestAlgorithmOID_Sha1)
|
||||
algorithm = retdec::crypto::HashAlgorithm::Sha1;
|
||||
algorithm = EVP_sha1();
|
||||
else if (digestAlgoOIDStr == DigestAlgorithmOID_Sha256)
|
||||
algorithm = retdec::crypto::HashAlgorithm::Sha256;
|
||||
algorithm = EVP_sha256();
|
||||
else if (digestAlgoOIDStr == DigestAlgorithmOID_Md5)
|
||||
algorithm = retdec::crypto::HashAlgorithm::Md5;
|
||||
algorithm = EVP_md5();
|
||||
else
|
||||
{
|
||||
EVP_cleanup();
|
||||
@ -2234,14 +2235,17 @@ std::vector<std::tuple<const std::uint8_t*, std::size_t>> PeFormat::getDigestRan
|
||||
|
||||
/**
|
||||
* Calculates the digest using selected hash algorithm.
|
||||
* @param hashType Algorithm to use.
|
||||
* @param algorithm Algorithm to use.
|
||||
* @return Hex string of hash.
|
||||
*/
|
||||
std::string PeFormat::calculateDigest(retdec::crypto::HashAlgorithm hashType) const
|
||||
std::string PeFormat::calculateDigest(const EVP_MD* algorithm) const
|
||||
{
|
||||
retdec::crypto::HashContext hashCtx;
|
||||
if (!hashCtx.init(hashType))
|
||||
EVP_MD_CTX* ctx = EVP_MD_CTX_create();
|
||||
|
||||
if (EVP_DigestInit(ctx, algorithm) != 1) // 1 == success
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
auto digestRanges = getDigestRanges();
|
||||
for (const auto& range : digestRanges)
|
||||
@ -2249,11 +2253,23 @@ std::string PeFormat::calculateDigest(retdec::crypto::HashAlgorithm hashType) co
|
||||
const std::uint8_t* data = std::get<0>(range);
|
||||
std::size_t size = std::get<1>(range);
|
||||
|
||||
if (!hashCtx.addData(data, size))
|
||||
if (EVP_DigestUpdate(ctx, data, size) != 1) // 1 == success
|
||||
{
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
return hashCtx.getHash();
|
||||
std::vector<std::uint8_t> hash(EVP_MD_size(algorithm));
|
||||
if (EVP_DigestFinal(ctx, hash.data(), nullptr) != 1)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
EVP_MD_CTX_destroy(ctx);
|
||||
|
||||
std::string ret;
|
||||
retdec::utils::bytesToHexString(hash, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2933,9 +2949,9 @@ void PeFormat::computeTypeRefHashes()
|
||||
}
|
||||
}
|
||||
|
||||
typeRefHashCrc32 = retdec::crypto::getCrc32(typeRefHashBytes.data(), typeRefHashBytes.size());
|
||||
typeRefHashMd5 = retdec::crypto::getMd5(typeRefHashBytes.data(), typeRefHashBytes.size());
|
||||
typeRefHashSha256 = retdec::crypto::getSha256(typeRefHashBytes.data(), typeRefHashBytes.size());
|
||||
typeRefHashCrc32 = retdec::fileformat::getCrc32(typeRefHashBytes.data(), typeRefHashBytes.size());
|
||||
typeRefHashMd5 = retdec::fileformat::getMd5(typeRefHashBytes.data(), typeRefHashBytes.size());
|
||||
typeRefHashSha256 = retdec::fileformat::getSha256(typeRefHashBytes.data(), typeRefHashBytes.size());
|
||||
}
|
||||
|
||||
retdec::utils::Endianness PeFormat::getEndianness() const
|
||||
|
@ -4,10 +4,10 @@
|
||||
* @copyright (c) 2017 Avast Software, licensed under the MIT license
|
||||
*/
|
||||
|
||||
#include "retdec/crypto/crypto.h"
|
||||
#include "retdec/utils/string.h"
|
||||
#include "retdec/utils/conversion.h"
|
||||
#include "retdec/fileformat/types/export_table/export_table.h"
|
||||
#include "retdec/fileformat/utils/crypto.h"
|
||||
|
||||
using namespace retdec::utils;
|
||||
|
||||
@ -163,9 +163,9 @@ void ExportTable::computeHashes()
|
||||
}
|
||||
}
|
||||
|
||||
expHashCrc32 = retdec::crypto::getCrc32(expHashBytes.data(), expHashBytes.size());
|
||||
expHashMd5 = retdec::crypto::getMd5(expHashBytes.data(), expHashBytes.size());
|
||||
expHashSha256 = retdec::crypto::getSha256(expHashBytes.data(), expHashBytes.size());
|
||||
expHashCrc32 = getCrc32(expHashBytes.data(), expHashBytes.size());
|
||||
expHashMd5 = getMd5(expHashBytes.data(), expHashBytes.size());
|
||||
expHashSha256 = getSha256(expHashBytes.data(), expHashBytes.size());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,10 +4,10 @@
|
||||
* @copyright (c) 2017 Avast Software, licensed under the MIT license
|
||||
*/
|
||||
|
||||
#include "retdec/crypto/crypto.h"
|
||||
#include "retdec/utils/container.h"
|
||||
#include "retdec/utils/conversion.h"
|
||||
#include "retdec/utils/string.h"
|
||||
#include "retdec/fileformat/utils/crypto.h"
|
||||
#include "retdec/fileformat/types/import_table/import_table.h"
|
||||
|
||||
using namespace retdec::utils;
|
||||
@ -813,9 +813,9 @@ void ImportTable::computeHashes()
|
||||
return;
|
||||
}
|
||||
|
||||
impHashCrc32 = retdec::crypto::getCrc32(impHashBytes.data(), impHashBytes.size());
|
||||
impHashMd5 = retdec::crypto::getMd5(impHashBytes.data(), impHashBytes.size());
|
||||
impHashSha256 = retdec::crypto::getSha256(impHashBytes.data(), impHashBytes.size());
|
||||
impHashCrc32 = getCrc32(impHashBytes.data(), impHashBytes.size());
|
||||
impHashMd5 = getMd5(impHashBytes.data(), impHashBytes.size());
|
||||
impHashSha256 = getSha256(impHashBytes.data(), impHashBytes.size());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,11 +6,11 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "retdec/crypto/crypto.h"
|
||||
#include "retdec/utils/conversion.h"
|
||||
#include "retdec/fileformat/file_format/file_format.h"
|
||||
#include "retdec/fileformat/types/resource_table/resource.h"
|
||||
#include "retdec/fileformat/utils/conversions.h"
|
||||
#include "retdec/fileformat/utils/crypto.h"
|
||||
#include "retdec/fileformat/utils/file_io.h"
|
||||
#include "retdec/fileformat/utils/other.h"
|
||||
|
||||
@ -428,9 +428,9 @@ void Resource::load(const FileFormat *rOwner)
|
||||
|
||||
if (!(rOwner->getLoadFlags() & LoadFlags::NO_VERBOSE_HASHES))
|
||||
{
|
||||
crc32 = retdec::crypto::getCrc32(origBytes, bytes.size());
|
||||
md5 = retdec::crypto::getMd5(origBytes, bytes.size());
|
||||
sha256 = retdec::crypto::getSha256(origBytes, bytes.size());
|
||||
crc32 = retdec::fileformat::getCrc32(origBytes, bytes.size());
|
||||
md5 = retdec::fileformat::getMd5(origBytes, bytes.size());
|
||||
sha256 = retdec::fileformat::getSha256(origBytes, bytes.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,11 +7,11 @@
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "retdec/crypto/crypto.h"
|
||||
#include "retdec/utils/conversion.h"
|
||||
#include "retdec/utils/dynamic_buffer.h"
|
||||
#include "retdec/utils/string.h"
|
||||
#include "retdec/utils/alignment.h"
|
||||
#include "retdec/fileformat/utils/crypto.h"
|
||||
#include "retdec/fileformat/utils/other.h"
|
||||
#include "retdec/fileformat/types/resource_table/resource_table.h"
|
||||
#include "retdec/fileformat/types/resource_table/bitmap_image.h"
|
||||
@ -411,9 +411,9 @@ void ResourceTable::computeIconHashes()
|
||||
return;
|
||||
}
|
||||
|
||||
iconHashCrc32 = retdec::crypto::getCrc32(iconHashBytes.data(), iconHashBytes.size());
|
||||
iconHashMd5 = retdec::crypto::getMd5(iconHashBytes.data(), iconHashBytes.size());
|
||||
iconHashSha256 = retdec::crypto::getSha256(iconHashBytes.data(), iconHashBytes.size());
|
||||
iconHashCrc32 = getCrc32(iconHashBytes.data(), iconHashBytes.size());
|
||||
iconHashMd5 = getMd5(iconHashBytes.data(), iconHashBytes.size());
|
||||
iconHashSha256 = getSha256(iconHashBytes.data(), iconHashBytes.size());
|
||||
iconPerceptualAvgHash = computePerceptualAvgHash(*priorIcon);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "retdec/crypto/crypto.h"
|
||||
#include "retdec/utils/conversion.h"
|
||||
#include "retdec/utils/string.h"
|
||||
#include "retdec/fileformat/file_format/file_format.h"
|
||||
@ -14,6 +13,7 @@
|
||||
#include "retdec/fileformat/utils/conversions.h"
|
||||
#include "retdec/fileformat/utils/file_io.h"
|
||||
#include "retdec/fileformat/utils/other.h"
|
||||
#include "retdec/fileformat/utils/crypto.h"
|
||||
|
||||
using namespace retdec::utils;
|
||||
using namespace llvm;
|
||||
@ -27,9 +27,9 @@ namespace fileformat {
|
||||
void SecSeg::computeHashes()
|
||||
{
|
||||
const auto *hashData = reinterpret_cast<const unsigned char*>(bytes.data());
|
||||
crc32 = retdec::crypto::getCrc32(hashData, bytes.size());
|
||||
md5 = retdec::crypto::getMd5(hashData, bytes.size());
|
||||
sha256 = retdec::crypto::getSha256(hashData, bytes.size());
|
||||
crc32 = retdec::fileformat::getCrc32(hashData, bytes.size());
|
||||
md5 = retdec::fileformat::getMd5(hashData, bytes.size());
|
||||
sha256 = retdec::fileformat::getSha256(hashData, bytes.size());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,10 +4,10 @@
|
||||
* @copyright (c) 2017 Avast Software, licensed under the MIT license
|
||||
*/
|
||||
|
||||
#include "retdec/crypto/crypto.h"
|
||||
#include "retdec/utils/string.h"
|
||||
#include "retdec/utils/system.h"
|
||||
#include "retdec/utils/conversion.h"
|
||||
#include "retdec/fileformat/utils/crypto.h"
|
||||
#include "retdec/fileformat/types/visual_basic/visual_basic_info.h"
|
||||
|
||||
using namespace retdec::utils;
|
||||
@ -684,9 +684,9 @@ void VisualBasicInfo::computeExternTableHashes()
|
||||
}
|
||||
}
|
||||
|
||||
externTableHashCrc32 = retdec::crypto::getCrc32(hashBytes.data(), hashBytes.size());
|
||||
externTableHashMd5 = retdec::crypto::getMd5(hashBytes.data(), hashBytes.size());
|
||||
externTableHashSha256 = retdec::crypto::getSha256(hashBytes.data(), hashBytes.size());
|
||||
externTableHashCrc32 = getCrc32(hashBytes.data(), hashBytes.size());
|
||||
externTableHashMd5 = getMd5(hashBytes.data(), hashBytes.size());
|
||||
externTableHashSha256 = getSha256(hashBytes.data(), hashBytes.size());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -726,9 +726,9 @@ void VisualBasicInfo::computeObjectTableHashes()
|
||||
}
|
||||
}
|
||||
|
||||
objectTableHashCrc32 = retdec::crypto::getCrc32(hashBytes.data(), hashBytes.size());
|
||||
objectTableHashMd5 = retdec::crypto::getMd5(hashBytes.data(), hashBytes.size());
|
||||
objectTableHashSha256 = retdec::crypto::getSha256(hashBytes.data(), hashBytes.size());
|
||||
objectTableHashCrc32 = getCrc32(hashBytes.data(), hashBytes.size());
|
||||
objectTableHashMd5 = getMd5(hashBytes.data(), hashBytes.size());
|
||||
objectTableHashSha256 = getSha256(hashBytes.data(), hashBytes.size());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**
|
||||
* @file src/crypto/crypto.cpp
|
||||
* @brief Implementation of the cryptography-related functions.
|
||||
* @copyright (c) 2017 Avast Software, licensed under the MIT license
|
||||
*/
|
||||
* @file src/fileformat/utils/crypto.cpp
|
||||
* @brief Crypto functions.
|
||||
* @copyright (c) 2020 Avast Software, licensed under the MIT license
|
||||
*/
|
||||
|
||||
#include <climits>
|
||||
#include <cmath>
|
||||
@ -11,60 +11,12 @@
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#include "retdec/crypto/crc32.h"
|
||||
#include "retdec/crypto/crypto.h"
|
||||
#include "retdec/fileformat/utils/crypto.h"
|
||||
#include "retdec/utils/conversion.h"
|
||||
#include "retdec/utils/crc32.h"
|
||||
|
||||
namespace retdec {
|
||||
namespace crypto {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr auto CRC16_POLY = 0x8408U;
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
/**
|
||||
* @brief This is the CCITT CRC 16 CRC16_POLYnomial X^16 + X^12 + X^5 + 1.
|
||||
* This works out to be 0x1021, but the way the algorithm works lets us use
|
||||
* 0x8408 (the reverse of the bit pattern). The high bit is always assumed to
|
||||
* be set, thus we only use 16 bits to represent the 17 bit value.
|
||||
* @param[in] data Data to calculate the CRC checksum for.
|
||||
* @param[in] length Length of the input data.
|
||||
* @return CRC16 checksum.
|
||||
*/
|
||||
std::uint64_t getCrc16(const unsigned char *data, std::uint64_t length)
|
||||
{
|
||||
if (!data || !length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int actData;
|
||||
unsigned int crc = 0xFFFF;
|
||||
|
||||
do
|
||||
{
|
||||
actData = *data++;
|
||||
for (auto i = 0; i < 8; ++i)
|
||||
{
|
||||
if ((crc ^ actData) & 1)
|
||||
{
|
||||
crc = (crc >> 1) ^ CRC16_POLY;
|
||||
}
|
||||
else
|
||||
{
|
||||
crc >>= 1;
|
||||
}
|
||||
actData >>= 1;
|
||||
}
|
||||
} while (--length);
|
||||
|
||||
crc = ~crc;
|
||||
actData = crc;
|
||||
crc = (crc << 8) | ((actData >> 8) & 0xff);
|
||||
const std::uint64_t max = std::pow(2, 16) - 1;
|
||||
return crc & max;
|
||||
}
|
||||
namespace fileformat {
|
||||
|
||||
/**
|
||||
* @brief Count CRC32 of @a data.
|
||||
@ -74,7 +26,7 @@ std::uint64_t getCrc16(const unsigned char *data, std::uint64_t length)
|
||||
*/
|
||||
std::string getCrc32(const unsigned char *data, std::uint64_t length)
|
||||
{
|
||||
CRC32 crc;
|
||||
retdec::utils::CRC32 crc;
|
||||
return crc(data, length);
|
||||
}
|
||||
|
||||
@ -126,5 +78,5 @@ std::string getSha256(const unsigned char *data, std::uint64_t length)
|
||||
return sha;
|
||||
}
|
||||
|
||||
} // namespace crypto
|
||||
} // namespace fileformat
|
||||
} // namespace retdec
|
@ -4,6 +4,7 @@ add_library(utils STATIC
|
||||
byte_value_storage.cpp
|
||||
binary_path.cpp
|
||||
conversion.cpp
|
||||
crc32.cpp
|
||||
dynamic_buffer.cpp
|
||||
file_io.cpp
|
||||
filesystem_path.cpp
|
||||
|
@ -9,7 +9,10 @@
|
||||
// and conform to the coding standards of the RetDec project.
|
||||
// !!!
|
||||
|
||||
#include "retdec/crypto/crc32.h"
|
||||
#include "retdec/utils/crc32.h"
|
||||
|
||||
namespace retdec {
|
||||
namespace utils {
|
||||
|
||||
/// same as reset()
|
||||
CRC32::CRC32()
|
||||
@ -423,3 +426,6 @@ std::string CRC32::operator()(const std::string& text)
|
||||
add(text.c_str(), text.size());
|
||||
return getHash();
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
} // namespace retdec
|
Loading…
Reference in New Issue
Block a user