diff --git a/.github/workflows/build-x86.yml b/.github/workflows/build-x86.yml index 0e561f0..00208fe 100644 --- a/.github/workflows/build-x86.yml +++ b/.github/workflows/build-x86.yml @@ -9,7 +9,7 @@ jobs: build-linux-i386: # Build / test on a 32 bit container container: i386/ubuntu:18.04 - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v1 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 254d809..8dbb9ea 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,12 +7,12 @@ on: jobs: build-linux: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Install build dependencies - run: sudo apt install -y libmhash-dev libmcrypt-dev libjpeg62-dev zlib1g-dev build-essential cmake + run: sudo apt install -y libmhash-dev libmcrypt-dev libjpeg-dev zlib1g-dev build-essential cmake - name: Compile project run: | mkdir -p build @@ -24,12 +24,8 @@ jobs: - name: Run (legacy) system tests run: cd tests/steghide && ./systemtests.pl - # Get a recent python3 version to run the test script - - uses: actions/setup-python@v2 - with: - python-version: '3.8' - name: Run cracker tests - run: cd tests/stegseek && python test.py + run: cd tests/stegseek && python3.8 test.py - name: Create a .deb package run: bash package/package.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 9bb968f..791217d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,9 +2,12 @@ cmake_minimum_required(VERSION 3.5) project(stegseek VERSION 0.6) -if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # Update if necessary set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long") +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + # enforce modern C++, will not compile otherwise + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17") endif() add_subdirectory("src") diff --git a/src/Arguments.cc b/src/Arguments.cc index 860aeb1..a03876d 100644 --- a/src/Arguments.cc +++ b/src/Arguments.cc @@ -146,7 +146,7 @@ void Arguments::parse_Positional(std::vector positionalArgs) { switch (Command.getValue()) { case CRACK: { ArgString *posPtr[]{&StgFn, &WordlistFn, &ExtFn}; - for (int i = 0; i < 3 && i < positionalArgs.size(); i++) { + for (size_t i = 0; i < 3 && i < positionalArgs.size(); i++) { if (!posPtr[i]->is_set()) posPtr[i]->setValue(positionalArgs[i]); } @@ -154,7 +154,7 @@ void Arguments::parse_Positional(std::vector positionalArgs) { case SEED_CRACK: { // Extract this file into that file ArgString *posPtr[]{&StgFn, &ExtFn}; - for (int i = 0; i < 2 && i < positionalArgs.size(); i++) { + for (size_t i = 0; i < 2 && i < positionalArgs.size(); i++) { if (!posPtr[i]->is_set()) posPtr[i]->setValue(positionalArgs[i]); } @@ -162,7 +162,7 @@ void Arguments::parse_Positional(std::vector positionalArgs) { case EMBED: { // Embed this in that and output there ArgString *posPtr[]{&EmbFn, &CvrFn, &StgFn}; - for (int i = 0; i < 3 && i < positionalArgs.size(); i++) { + for (size_t i = 0; i < 3 && i < positionalArgs.size(); i++) { if (!posPtr[i]->is_set()) posPtr[i]->setValue(positionalArgs[i]); } @@ -170,7 +170,7 @@ void Arguments::parse_Positional(std::vector positionalArgs) { case EXTRACT: { // Extract this file into that file ArgString *posPtr[]{&StgFn, &ExtFn}; - for (int i = 0; i < 2 && i < positionalArgs.size(); i++) { + for (size_t i = 0; i < 2 && i < positionalArgs.size(); i++) { if (!posPtr[i]->is_set()) posPtr[i]->setValue(positionalArgs[i]); } diff --git a/src/AuFile.cc b/src/AuFile.cc index d412d4d..ea372a3 100644 --- a/src/AuFile.cc +++ b/src/AuFile.cc @@ -95,7 +95,7 @@ void AuFile::read(BinaryIO *io) { break; }; Header.encoding = (ENCODING)encoding; - } catch (BinaryInputError e) { + } catch (BinaryInputError &e) { switch (e.getType()) { case BinaryInputError::FILE_ERR: { throw SteghideError( @@ -152,7 +152,7 @@ void AuFile::write() { for (unsigned long i = 0; i < Infofield.size(); i++) { getBinIO()->write8(Infofield[i]); } - } catch (BinaryOutputError e) { + } catch (BinaryOutputError &e) { switch (e.getType()) { case BinaryOutputError::FILE_ERR: { throw SteghideError( diff --git a/src/AudioData.h b/src/AudioData.h index e9b84e1..29cda69 100644 --- a/src/AudioData.h +++ b/src/AudioData.h @@ -41,6 +41,8 @@ class AudioData : public CvrStgObject { virtual void read(BinaryIO *io, UWORD32 n = NoLimit) = 0; virtual void write(BinaryIO *io, UWORD32 n = NoLimit) = 0; + + virtual ~AudioData(void){}; }; /** @@ -52,7 +54,6 @@ template ::read(BinaryIO *io, UWORD32 Data[i] = readValue(io); } } - } catch (BinaryInputError e) { + } catch (BinaryInputError &e) { switch (e.getType()) { case BinaryInputError::FILE_ERR: { throw SteghideError( @@ -124,7 +125,7 @@ void AudioDataImpl::write(BinaryIO *io, UWORD3 for (UWORD32 i = 0; i < n; i++) { writeValue(io, Data[i]); } - } catch (BinaryOutputError e) { + } catch (BinaryOutputError &e) { switch (e.getType()) { case BinaryOutputError::FILE_ERR: { throw SteghideError( diff --git a/src/AudioSampleValue.h b/src/AudioSampleValue.h index 62d707b..c589599 100644 --- a/src/AudioSampleValue.h +++ b/src/AudioSampleValue.h @@ -121,7 +121,7 @@ SampleValue *AudioSampleValue::getNearestTargetSampleValue(EmbV template std::string AudioSampleValue::getName(void) const { char buf[128]; - sprintf(buf, "%ld", (long)Value); + snprintf(buf, sizeof(buf), "%ld", (long)Value); return std::string(buf); } diff --git a/src/BmpFile.cc b/src/BmpFile.cc index 3a4beae..5a5dbc9 100644 --- a/src/BmpFile.cc +++ b/src/BmpFile.cc @@ -433,7 +433,7 @@ void BmpFile::readheaders() { break; } } - } catch (BinaryInputError e) { + } catch (BinaryInputError &e) { switch (e.getType()) { case BinaryInputError::FILE_ERR: { throw SteghideError( @@ -688,7 +688,7 @@ void BmpFile::writeheaders() { break; } } - } catch (BinaryOutputError e) { + } catch (BinaryOutputError &e) { switch (e.getType()) { case BinaryOutputError::FILE_ERR: { throw SteghideError( @@ -810,7 +810,7 @@ void BmpFile::readdata() { while (!getBinIO()->eof()) { atend.push_back(getBinIO()->read8()); } - } catch (BinaryInputError e) { + } catch (BinaryInputError &e) { switch (e.getType()) { case BinaryInputError::FILE_ERR: { throw SteghideError( @@ -865,7 +865,7 @@ void BmpFile::writedata() { for (std::vector::iterator i = atend.begin(); i != atend.end(); i++) { getBinIO()->write8(*i); } - } catch (BinaryOutputError e) { + } catch (BinaryOutputError &e) { switch (e.getType()) { case BinaryOutputError::FILE_ERR: { throw SteghideError( diff --git a/src/BmpPaletteSampleValue.cc b/src/BmpPaletteSampleValue.cc index a71a73f..30374e2 100644 --- a/src/BmpPaletteSampleValue.cc +++ b/src/BmpPaletteSampleValue.cc @@ -53,6 +53,6 @@ SampleValue *BmpPaletteSampleValue::getNearestTargetSampleValue(EmbValue t) cons std::string BmpPaletteSampleValue::getName() const { char buf[128]; - sprintf(buf, "i%ur%ug%ub%u", getIndex(), getRed(), getGreen(), getBlue()); + snprintf(buf, sizeof(buf), "i%ur%ug%ub%u", getIndex(), getRed(), getGreen(), getBlue()); return std::string(buf); } diff --git a/src/BmpRGBSampleValue.cc b/src/BmpRGBSampleValue.cc index 4dec5a4..05c7551 100644 --- a/src/BmpRGBSampleValue.cc +++ b/src/BmpRGBSampleValue.cc @@ -123,7 +123,7 @@ void BmpRGBSampleValue::addNTSVCandidates(std::vector &cands, const B std::string BmpRGBSampleValue::getName() const { char buf[128]; - sprintf(buf, "r%ug%ub%u", getRed(), getGreen(), getBlue()); + snprintf(buf, sizeof(buf), "r%ug%ub%u", getRed(), getGreen(), getBlue()); return std::string(buf); } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 70f54b7..f8b389a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,7 @@ add_definitions(-DHAVE_DEV_URANDOM) add_definitions(-DHAVE_DEV_RANDOM) add_definitions(-DHAVE_TERMIOS_H) -add_definitions(-DVERSION="0.6") +add_definitions(-DSTEGSEEK_VERSION="0.6") add_definitions(-DSTEGHIDE_VERSION="0.5.1") set (sources @@ -67,6 +67,8 @@ file(GLOB headers ) add_library(stegseek_lib ${sources} ${headers}) +find_path(MCRYPT_INCLUDE_PATH mcrypt.h) +target_include_directories(stegseek_lib PUBLIC ${MCRYPT_INCLUDE_PATH}) set(CMAKE_CXX_FLAGS_RELEASE "-O2") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s") @@ -75,4 +77,7 @@ add_executable(stegseek main.cc) install(TARGETS stegseek EXPORT stegseek DESTINATION bin) -target_link_libraries(stegseek PRIVATE stegseek_lib PUBLIC -lpthread -lz -lmcrypt -lmhash -ljpeg) +find_library(MCRYPT_LIBRARY mcrypt) +find_library(MHASH_LIBRARY mhash) +find_library(JPEG_LIBRARY jpeg) +target_link_libraries(stegseek PRIVATE stegseek_lib PUBLIC -lpthread -lz ${MCRYPT_LIBRARY} ${MHASH_LIBRARY} ${JPEG_LIBRARY}) diff --git a/src/EmbData.cc b/src/EmbData.cc index c3f347d..1bf9a79 100644 --- a/src/EmbData.cc +++ b/src/EmbData.cc @@ -101,7 +101,7 @@ void EmbData::addBits(BitString addbits) { throw CorruptDataError( _("attempting to read an embedding of version %d but steghide %s " "only supports embeddings of version %d."), - Version, VERSION, CodeVersion); + Version, STEGHIDE_VERSION, CodeVersion); } NumBitsNeeded = EncryptionAlgorithm::IRep_size + EncryptionMode::IRep_size; NumBitsRequested = AUtils::bminus(NumBitsNeeded, Reservoir.getLength()); diff --git a/src/Embedder.cc b/src/Embedder.cc index 94f9d86..43e5fc3 100644 --- a/src/Embedder.cc +++ b/src/Embedder.cc @@ -154,7 +154,8 @@ void Embedder::embed() { cvrstring = "\"" + Args.CvrFn.getValue() + "\""; } char buf[200]; - sprintf(buf, _("embedding %s in %s..."), embstring.c_str(), cvrstring.c_str()); + snprintf(buf, sizeof(buf), _("embedding %s in %s..."), embstring.c_str(), + cvrstring.c_str()); prout = new ProgressOutput(std::string(buf)); } else if (Args.Verbosity.getValue() == VERBOSE) { diff --git a/src/Extractor.h b/src/Extractor.h index 1e09335..f680706 100644 --- a/src/Extractor.h +++ b/src/Extractor.h @@ -36,8 +36,8 @@ class Extractor { private: std::string StegoFileName; std::string Passphrase; - bool passphraseSet; UWORD32 seed; + bool passphraseSet; }; #endif // ndef SH_EXTRACTOR_H diff --git a/src/JpegFile.cc b/src/JpegFile.cc index 37821d2..39f74da 100644 --- a/src/JpegFile.cc +++ b/src/JpegFile.cc @@ -218,7 +218,7 @@ void JpegFile::printFrequencies(const std::map &freqs) for (std::map::const_iterator pit = freqs.begin(); pit->first < 2147483648UL /* 2^31 */; pit++) { char buf[30]; - sprintf(buf, "%ld: %lu", (long)pit->first, pit->second); + snprintf(buf, sizeof(buf), "%ld: %lu", (long)pit->first, pit->second); output.push_back(std::string(buf)); } @@ -226,7 +226,7 @@ void JpegFile::printFrequencies(const std::map &freqs) for (std::map::const_reverse_iterator nit = freqs.rbegin(); nit->first > 2147483648UL /* 2^31 */; nit++) { char buf[30]; - sprintf(buf, "%ld: %lu", (long)nit->first, nit->second); + snprintf(buf, sizeof(buf), "%ld: %lu", (long)nit->first, nit->second); output.push_front(std::string(buf)); } diff --git a/src/JpegSampleValue.cc b/src/JpegSampleValue.cc index a1e7205..3220d93 100644 --- a/src/JpegSampleValue.cc +++ b/src/JpegSampleValue.cc @@ -83,6 +83,6 @@ UWORD32 JpegSampleValue::calcDistance(const SampleValue *s) const { std::string JpegSampleValue::getName(void) const { char buf[128]; - sprintf(buf, "%d", DctCoeff); + snprintf(buf, sizeof(buf), "%d", DctCoeff); return std::string(buf); } diff --git a/src/RandomSource.cc b/src/RandomSource.cc index 4c0ffab..1085325 100644 --- a/src/RandomSource.cc +++ b/src/RandomSource.cc @@ -46,7 +46,7 @@ RandomSource::RandomSource() { #endif } -RandomSource::~RandomSource() { +RandomSource::~RandomSource() noexcept(false) { if (RandomInput != NULL) { if (fclose(RandomInput) != 0) { throw SteghideError(_("could not close random input file.")); diff --git a/src/RandomSource.h b/src/RandomSource.h index f763da0..ebb4b1c 100644 --- a/src/RandomSource.h +++ b/src/RandomSource.h @@ -33,7 +33,7 @@ class BitString; class RandomSource { public: RandomSource(void); - ~RandomSource(void); + ~RandomSource(void) noexcept(false); /** * get a random byte diff --git a/src/SampleValue.h b/src/SampleValue.h index f362b74..4470065 100644 --- a/src/SampleValue.h +++ b/src/SampleValue.h @@ -145,15 +145,15 @@ class SampleValue { UWORD32 *NumEdges; }; -struct SampleValuesEqual : public std::binary_function { +struct SampleValuesEqual { bool operator()(const SampleValue *s1, const SampleValue *s2) const { return (*s1 == *s2); } }; -struct SampleValuesLess : public std::binary_function { +struct SampleValuesLess { bool operator()(const SampleValue *s1, const SampleValue *s2) const { return (*s1 < *s2); } }; -struct SampleValueHash : public std::unary_function { +struct SampleValueHash { size_t operator()(const SampleValue *s) const { std::hash h; return h(s->getKey()); diff --git a/src/Session.cc b/src/Session.cc index 43c24d2..0230549 100644 --- a/src/Session.cc +++ b/src/Session.cc @@ -246,7 +246,7 @@ void Session::printEncInfo() { } void Session::printVersion() { - fprintf(stderr, "StegSeek %s - https://github.com/RickdeJager/StegSeek\n", VERSION); + fprintf(stderr, "StegSeek %s - https://github.com/RickdeJager/StegSeek\n", STEGSEEK_VERSION); if (Args.Verbosity.getValue() == VERBOSE) { printSteghideVersion(); } diff --git a/src/Utils.cc b/src/Utils.cc index 28ac036..d9dbeac 100644 --- a/src/Utils.cc +++ b/src/Utils.cc @@ -40,12 +40,12 @@ std::string Utils::formatHRSize(unsigned long size) { } char buf[15]; - sprintf(buf, "%.1f %s", s, unit.c_str()); + snprintf(buf, sizeof(buf), "%.1f %s", s, unit.c_str()); return std::string(buf); } std::string Utils::stripDir(std::string s) { - unsigned int start = 0; + size_t start = 0; if ((start = s.find_last_of("/\\")) == std::string::npos) { start = 0; } else { diff --git a/src/WKSConstructionHeuristic.h b/src/WKSConstructionHeuristic.h index 5dc8a3e..65be2ab 100644 --- a/src/WKSConstructionHeuristic.h +++ b/src/WKSConstructionHeuristic.h @@ -69,7 +69,7 @@ class WKSConstructionHeuristic : public MatchingAlgorithm { * If both v1 and v2 have degree 0, then the vertex with the greater label * is defined to have the "longer shortest edge". **/ - class LongerShortestEdge : public std::binary_function { + class LongerShortestEdge { public: bool operator()(const Vertex *v1, const Vertex *v2); }; diff --git a/src/WavFile.cc b/src/WavFile.cc index 3ccd4db..cc1e88a 100644 --- a/src/WavFile.cc +++ b/src/WavFile.cc @@ -225,7 +225,7 @@ void WavFile::readdata(void) { while (!getBinIO()->eof()) { UnusedAfterData.push_back(getBinIO()->read8()); } - } catch (BinaryInputError e) { + } catch (BinaryInputError &e) { switch (e.getType()) { case BinaryInputError::FILE_ERR: { throw SteghideError( @@ -285,7 +285,7 @@ void WavFile::writedata(void) { it != UnusedAfterData.end(); it++) { getBinIO()->write8(*it); } - } catch (BinaryOutputError e) { + } catch (BinaryOutputError &e) { switch (e.getType()) { case BinaryOutputError::FILE_ERR: { throw SteghideError( @@ -330,7 +330,7 @@ void WavFile::readheaders() { } datachhdr = chhdr; - } catch (BinaryInputError e) { + } catch (BinaryInputError &e) { switch (e.getType()) { case BinaryInputError::FILE_ERR: { throw SteghideError( @@ -378,7 +378,7 @@ void WavFile::writeheaders() { } datachhdr->write(getBinIO()); - } catch (BinaryOutputError e) { + } catch (BinaryOutputError &e) { switch (e.getType()) { case BinaryOutputError::FILE_ERR: { throw SteghideError( diff --git a/src/WavPCMSampleValue.cc b/src/WavPCMSampleValue.cc index fd5db8a..ad16368 100644 --- a/src/WavPCMSampleValue.cc +++ b/src/WavPCMSampleValue.cc @@ -109,6 +109,6 @@ UWORD32 WavPCMSampleValue::calcDistance(const SampleValue *s) const { std::string WavPCMSampleValue::getName() const { char buf[128]; - sprintf(buf, "%d", Value); + snprintf(buf, sizeof(buf), "%d", Value); return std::string(buf); } diff --git a/src/WavPCMSampleValue.h b/src/WavPCMSampleValue.h index 1142467..3b3f9fa 100644 --- a/src/WavPCMSampleValue.h +++ b/src/WavPCMSampleValue.h @@ -45,7 +45,7 @@ class WavPCMSampleValue : public SampleValue { EmbValue calcEValue(int v) const { return (v & 1); } }; -class WavPCMSmaller : public std::binary_function { +class WavPCMSmaller { public: bool operator()(const WavPCMSampleValue *v, const WavPCMSampleValue *w) { return v->getValue() < w->getValue(); diff --git a/tests/steghide/CMakeLists.txt b/tests/steghide/CMakeLists.txt index f8de4a1..9a8772f 100644 --- a/tests/steghide/CMakeLists.txt +++ b/tests/steghide/CMakeLists.txt @@ -10,7 +10,7 @@ add_definitions(-DHAVE_TERMIOS_H) add_executable(teststeghide ${sources}) include_directories(teststeghide ${CMAKE_SOURCE_DIR}/src) -target_link_libraries(teststeghide PRIVATE stegseek_lib PUBLIC -lpthread -lz -lmcrypt -lmhash -ljpeg) +target_link_libraries(teststeghide PRIVATE stegseek_lib PUBLIC -lpthread -lz ${MCRYPT_LIBRARY} ${MHASH_LIBRARY} ${JPEG_LIBRARY}) add_test(NAME LegacySteghideUnitTests COMMAND ${CMAKE_BINARY_DIR}/tests/steghide/teststeghide WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests/steghide) diff --git a/tests/steghide/CvrStgFileTest.cc b/tests/steghide/CvrStgFileTest.cc index 3e1fa9f..83db6ba 100644 --- a/tests/steghide/CvrStgFileTest.cc +++ b/tests/steghide/CvrStgFileTest.cc @@ -177,19 +177,19 @@ bool CvrStgFileTest::genericTestEmbeddedValue(const CvrStgFile *f) const { bool CvrStgFileTest::areEqual(const std::string &fn1, const std::string &fn2) const { char command[256]; - sprintf(command, "%s %s %s", COMPARE, fn1.c_str(), fn2.c_str()); + snprintf(command, sizeof(command), "%s %s %s", COMPARE, fn1.c_str(), fn2.c_str()); return (system(command) ? false : true); } void CvrStgFileTest::removeFile(const std::string &fn) const { char command[256]; - sprintf(command, "%s %s", REMOVE, fn.c_str()); + snprintf(command, sizeof(command), "%s %s", REMOVE, fn.c_str()); system(command); } void CvrStgFileTest::copyFile(const std::string &src, const std::string &dest) const { char command[256]; - sprintf(command, "%s %s %s", COPY, src.c_str(), dest.c_str()); + snprintf(command, sizeof(command), "%s %s %s", COPY, src.c_str(), dest.c_str()); system(command); } diff --git a/tests/steghide/DummySampleValue.cc b/tests/steghide/DummySampleValue.cc index 6785b26..f6f01d4 100644 --- a/tests/steghide/DummySampleValue.cc +++ b/tests/steghide/DummySampleValue.cc @@ -54,6 +54,6 @@ SampleValue *DummySampleValue::getNearestTargetSampleValue(EmbValue t) const { std::string DummySampleValue::getName(void) const { char buf[128]; - sprintf(buf, "%d", Value); + snprintf(buf, sizeof(buf), "%d", Value); return std::string(buf); } diff --git a/tests/steghide/MCryptPPTest.cc b/tests/steghide/MCryptPPTest.cc index 0d6ecf6..85a6392 100644 --- a/tests/steghide/MCryptPPTest.cc +++ b/tests/steghide/MCryptPPTest.cc @@ -33,6 +33,7 @@ void MCryptPPTest::testDecryption(void) {} bool MCryptPPTest::genericTestEncryption() { // evaluate test vector + return true; } -bool MCryptPPTest::genericTestDecryption() {} +bool MCryptPPTest::genericTestDecryption() { return true; }