Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitwiser73/65 windows #67

Closed
wants to merge 11 commits into from
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.sh eol=lf
Testing/example_data/*.txt binary
12 changes: 8 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
language: cpp

compiler:
- gcc
matrix:
include:
- os: linux
compiler: gcc
- os: osx
compiler: clang
- os: windows

script:
- ./make.sh
script: ./make.sh || cat CMakeOutput.log
106 changes: 53 additions & 53 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,73 +51,79 @@
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 2.8)

project(TLSH)

set(VERSION_MAJOR 3)
set(VERSION_MINOR 13)
set(VERSION_PATCH 1)

# Standard shared library flag is supported, enable to build a shared library
#set(BUILD_SHARED_LIBS OFF)

# Edit those values or call cmake with options defined below
set(TLSH_BUCKETS_DEFAULT "TLSH_BUCKETS_128")
set(TLSH_CHECKSUM_DEFAULT "TLSH_CHECKSUM_1B")

# TLSH uses only half the counting buckets.
# It can use all the buckets now.
set(TLSH_BUCKETS_128 1)
if(TLSH_BUCKETS_48 EQUAL 1)
set(TLSH_HASH "min hash")
add_definitions(-DBUCKETS_48)
option(TLSH_BUCKETS_48 "Use 48 bits buckets" OFF)
option(TLSH_BUCKETS_128 "Use 128 bits buckets" OFF)
option(TLSH_BUCKETS_256 "Use 256 bits buckets" OFF)

if(NOT TLSH_BUCKETS_48 AND NOT TLSH_BUCKETS_128 AND NOT TLSH_BUCKETS_256)
set(${TLSH_BUCKETS_DEFAULT} ON)
endif()
if(TLSH_BUCKETS_128 EQUAL 1)

if(TLSH_BUCKETS_48)
set(TLSH_HASH "min hash")
set(TLSH_BUCKETS_SIZE "BUCKETS_48")
elseif(TLSH_BUCKETS_128)
set(TLSH_HASH "compact hash")
add_definitions(-DBUCKETS_128)
endif()
if(TLSH_BUCKETS_256 EQUAL 1)
set(TLSH_BUCKETS_SIZE "BUCKETS_128")
elseif(TLSH_BUCKETS_256)
set(TLSH_HASH "full hash")
add_definitions(-DBUCKETS_256)
set(TLSH_BUCKETS_SIZE "BUCKETS_256")
endif()

# TLSH uses 1 byte checksum. The collision rate is 1 in 24.
# It can use 3 bytes checksum now. That collision rate in 1 in 5800.
set(TLSH_CHECKSUM_1B 1)
message(STATUS "Hash type: ${TLSH_HASH}")

if(TLSH_CHECKSUM_0B EQUAL 1)
set(TLSH_CHECKSUM "no checksum")
add_definitions(-DCHECKSUM_0B)
option(TLSH_CHECKSUM_0B "Do not use checksum" OFF)
option(TLSH_CHECKSUM_1B "Use 1 byte checksum (collision rate: 1/24)" OFF)
option(TLSH_CHECKSUM_3B "Use 3 bytes checksum (collision rate: 1/5000)" OFF)

if(NOT TLSH_CHECKSUM_0B AND NOT TLSH_CHECKSUM_1B AND NOT TLSH_CHECKSUM_3B)
set(${TLSH_CHECKSUM_DEFAULT} ON)
endif()
if(TLSH_CHECKSUM_1B EQUAL 1)

if(TLSH_CHECKSUM_0B)
set(TLSH_CHECKSUM "no checksum")
set(TLSH_CHECKSUM_TYPE "CHECKSUM_0B")
elseif(TLSH_CHECKSUM_1B)
set(TLSH_CHECKSUM "1 byte checksum")
endif()
if(TLSH_CHECKSUM_3B EQUAL 1)
set(TLSH_CHECKSUM_TYPE "CHECKSUM_1B")
elseif(TLSH_CHECKSUM_3B)
set(TLSH_CHECKSUM "3 bytes checksum")
add_definitions(-DCHECKSUM_3B)
set(TLSH_CHECKSUM_TYPE "CHECKSUM_3B")
endif()

# setting TLSH_DISTANCE_PARAMETERS to 1 allows you to set command line arguments
# to set - and hence experiment with the distance parameters
# by default this is zero
set(TLSH_DISTANCE_PARAMETERS 0)

# write a file with the VERSION information
file(REMOVE VERSION)
file(WRITE VERSION
"// This file is generated by cmake. Modify\n"
"// CMakeLists.txt to change the VERSION numbers\n"
"TLSH version: ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} ${TLSH_HASH}, ${TLSH_CHECKSUM}\n")

file(REMOVE include/version.h)
file(WRITE include/version.h
"/****************************************************\n"
" * This file is generated by cmake. Modify the top\n"
" * level CMakeLists.txt to change the VERSION numbers\n"
" ****************************************************/\n\n"
"#define VERSION_MAJOR ${VERSION_MAJOR}\n"
"#define VERSION_MINOR ${VERSION_MINOR}\n"
"#define VERSION_PATCH ${VERSION_PATCH}\n"
"#define TLSH_HASH \"${TLSH_HASH}\"\n"
"#define TLSH_CHECKSUM \"${TLSH_CHECKSUM}\"\n")
if(TLSH_DISTANCE_PARAMETERS EQUAL 1)
file(APPEND include/version.h
"#define TLSH_DISTANCE_PARAMETERS ${TLSH_DISTANCE_PARAMETERS}\n")
endif()
message(STATUS "Checksum: ${TLSH_CHECKSUM}")

# setting TLSH_DISTANCE_PARAMETERS to 'ON' allows you to set command line
# arguments to set - and hence experiment with the distance parameters
option(TLSH_DISTANCE_PARAMETERS "Enable cli control of the distance parameters" OFF)

configure_file(cmake/VERSION.in ${CMAKE_CURRENT_SOURCE_DIR}/VERSION)
configure_file(cmake/version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/include/version.h)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${TLSH_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${TLSH_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${TLSH_SOURCE_DIR}/bin)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${TLSH_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${TLSH_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${TLSH_SOURCE_DIR}/lib)

if (CMAKE_BUILD_TYPE STREQUAL Debug)
if(CMAKE_COMPILER_IS_GNUCXX)
Expand All @@ -132,11 +138,6 @@ else(CMAKE_BUILD_TYPE STREQUAL Debug)
endif()
endif(CMAKE_BUILD_TYPE STREQUAL Debug)

if(MSVC)
add_definitions(-DWINDOWS -DTLSH_LIB)
include_directories(Windows)
endif()

# user can override CXX; make sure tests link and load properly regardless of LD_LIBRARY_PATH
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc")
Expand All @@ -145,7 +146,6 @@ endif()

enable_testing()

include_directories(include)
add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(utils)
Expand Down
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ git checkout master

Edit [CMakeLists.txt](CMakeLists.txt) to build TLSH with different options.

- TLSH_BUCKETS: determines using 128 or 256 buckets
- TLSH_BUCKETS_DEFAULT: determines using 128 or 256 buckets
use the default 128 buckets unless you are an expert and know you need 256 buckets
- TLSH_CHECKSUM_1B: determines checksum length, longer means less collision
- TLSH_CHECKSUM_DEFAULT: determines checksum length, longer means less collision
use the default 1 byte unless you are an expert and know you need a larger checksum

Alternatively, those values can be set from usual cmake options if you are not using the provided build script (see TLSH_BUCKETS_128 )

## Linux

Execute:
Expand All @@ -86,14 +88,29 @@ make.sh
`make` the project, so the build will fail if `cmake` is not installed.*


## Windows (Visual Studio)
## Windows

### Visual Studio versioned .sln
Use the version-specific tlsh solution files ([tlsh.VC2005.sln](Windows/tlsh.VC2005.sln),
[tlsh.VC2008.sln](Windows/tlsh.VC2008.sln), ...) under the Windows directory.

See [tlsh.h](include/tlsh.h) for the tlsh library interface and [tlsh_unittest.cpp](test/tlsh_unittest.cpp) and
[simple_unittest.cpp](test/simple_unittest.cpp) under the `test` directory for example code.

**Note:** *It is also possible to generate .sln files using cmake*
```
mkdir build
cd build
cmake ..
```

### Visual Studio and WSL or Git Bash
Within WSL's bash shell or Git Bash's execute:

```bash
./make.sh
```

## Python Extension

There is a README.python with notes about the python version
Expand Down
6 changes: 3 additions & 3 deletions Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# set(CTEST_OUTPUT_ON_FAILURE true)
# cmake bug - the above does not work, call "make test --output-on-failure"
# instead
add_test(tlsh_unittest_len "${CMAKE_SOURCE_DIR}/Testing/test.sh")
add_test(tlsh_unittest_xlen "${CMAKE_SOURCE_DIR}/Testing/test.sh" "-xlen")
add_test(tlsh_unittest_len "bash" "${TLSH_SOURCE_DIR}/Testing/test.sh")
add_test(tlsh_unittest_xlen "bash" "${TLSH_SOURCE_DIR}/Testing/test.sh" "-xlen")
if(CMAKE_HOST_UNIX)
if(CMAKE_SHARED_LIBRARY EQUAL 1)
if(BUILD_SHARED_LIBS)
set_tests_properties(tlsh_unittest_len tlsh_unittest_xlen PROPERTIES ENVIRONMENT "LD_PRELOAD=${CMAKE_SOURCE_DIR}/lib/libtlsh.so.0")
endif()
endif()
19 changes: 12 additions & 7 deletions Testing/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@ export LD_LIBRARY_PATH=../lib:$LD_LIBRARY_PATH
BASEDIR=$(dirname $0)
pushd $BASEDIR > /dev/null

# Check Windows typical env variable to add extension for git bash
if [ ! -z "${WINDIR}" ]; then
EXT=".exe"
fi

TMP="tmp"
HASH=`../bin/tlsh_version | head -1 | cut -f1`
CHKSUM=`../bin/tlsh_version | tail -1 | cut -f1`
HASH=`../bin/tlsh_version${EXT} | head -1 | cut -f1`
CHKSUM=`../bin/tlsh_version${EXT} | tail -1 | cut -f1`
echo "HASH is $HASH"
echo "CHKSUM is $CHKSUM"

if test ! -f ../bin/tlsh
if test ! -f ../bin/tlsh${EXT}
then
echoerr "error: (127), you must compile tlsh"
popd > /dev/null
exit 127
fi

if test ! -f ../bin/simple_unittest
if test ! -f ../bin/simple_unittest${EXT}
then
echoerr "error: (127), you must compile ../bin/simple_unittest"
popd > /dev/null
Expand Down Expand Up @@ -51,10 +56,10 @@ runit() {
fi
if test "$1" = "-tlsh_c"
then
TLSH_PROG="tlsh_c"
TLSH_PROG="tlsh_c${EXT}"
echo "Scenario: tlsh_c (c standalone version)..."
else
TLSH_PROG="tlsh"
TLSH_PROG="tlsh${EXT}"
echo "Scenario: tlsh (c++ standard version)..."
fi

Expand Down Expand Up @@ -274,7 +279,7 @@ echo "passed"

echo
echo "Running simple_unittest"
../bin/simple_unittest > $TMP/simple_unittest.out
../bin/simple_unittest${EXT} > $TMP/simple_unittest.out
diff --ignore-all-space $TMP/simple_unittest.out exp/simple_unittest_EXP > /dev/null 2>/dev/null
if [ $? -ne 0 ]; then
echoerr "error: diff $TMP/simple_unittest.out exp/simple_unittest_EXP"
Expand Down
7 changes: 6 additions & 1 deletion Testing/testlen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ fi

rm -f testlen.txt

# Check Windows typical env variable to add extension for git bash
if [ ! -z "${WINDIR}" ]; then
EXT=".exe"
fi

echo "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()" > testlen.txt
echo "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()" >> testlen.txt
cat testlen.txt testlen.txt > testlen2.txt

for x in `seq 1 $HIGH_SEQ` ; do
echo "iter $x"
wc -c testlen2.txt
../bin/tlsh -f testlen2.txt
../bin/tlsh${EXT} -f testlen2.txt
#
# grow the size of the file according to the Fibonacci sequence
#
Expand Down
94 changes: 94 additions & 0 deletions Windows/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# TLSH is provided for use under two licenses: Apache OR BSD.
# Users may opt to use either license depending on the license
# restictions of the systems with which they plan to integrate
# the TLSH code.
#
# ==============
# Apache License
# ==============
# Copyright 2013 Trend Micro Incorporated
#
# 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.
#
# ===========
# BSD License
# ===========
# Copyright (c) 2013, Trend Micro Incorporated
# 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. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# 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 HOLDER 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.

add_library(winfunc STATIC
WinFunctions.h
WinFunctions.cpp
)

target_compile_definitions(winfunc
PUBLIC
-DWINDOWS
-D${TLSH_BUCKETS_SIZE}
-D${TLSH_CHECKSUM_TYPE}
)

if(BUILD_SHARED_LIBS)
target_compile_definitions(winfunc PRIVATE -DTLSH_EXPORTS)
else()
target_compile_definitions(winfunc PUBLIC -DTLSH_LIB)
endif()

# Disable unwanted microsoft warnings
target_compile_options(winfunc
PUBLIC
/wd4477
/wd4267
/wd4996
/EHsc
)

target_include_directories(winfunc
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)

if(NOT BUILD_SHARED_LIBS)
install(
TARGETS winfunc
EXPORT tlsh-export
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
endif()
Loading