Browse Source

Merge branch 'master' into coverity_scan

coverity_scan
Daniel Scharrer 8 years ago
parent
commit
8cd60cea5b
  1. 2
      doc/Doxyfile.in
  2. 6
      src/cli/extract.cpp
  3. 22
      src/cli/extract.hpp
  4. 32
      src/cli/gog.cpp
  5. 17
      src/cli/main.cpp
  6. 22
      src/crypto/adler32.cpp
  7. 6
      src/crypto/arc4.cpp
  8. 2
      src/crypto/arc4.hpp
  9. 12
      src/crypto/checksum.cpp
  10. 19
      src/crypto/crc32.cpp
  11. 15
      src/crypto/hasher.cpp
  12. 1
      src/crypto/hasher.hpp
  13. 52
      src/crypto/iteratedhash.hpp
  14. 168
      src/crypto/md5.cpp
  15. 3
      src/crypto/md5.hpp
  16. 72
      src/crypto/sha1.cpp
  17. 2
      src/crypto/sha1.hpp
  18. 14
      src/loader/exereader.cpp
  19. 2
      src/loader/offsets.cpp
  20. 2
      src/setup/data.cpp
  21. 10
      src/setup/expression.cpp
  22. 12
      src/setup/filename.cpp
  23. 56
      src/setup/info.cpp
  24. 4
      src/setup/permission.cpp
  25. 18
      src/setup/version.cpp
  26. 33
      src/setup/windows.cpp
  27. 4
      src/setup/windows.hpp
  28. 2
      src/stream/block.hpp
  29. 1
      src/stream/checksum.hpp
  30. 2
      src/stream/chunk.hpp
  31. 6
      src/stream/exefilter.hpp
  32. 2
      src/stream/lzma.hpp
  33. 2
      src/stream/slice.hpp
  34. 3
      src/util/console.cpp
  35. 4
      src/util/console.hpp
  36. 95
      src/util/encoding.cpp
  37. 9
      src/util/flags.hpp
  38. 4
      src/util/log.hpp
  39. 4
      src/util/math.hpp
  40. 2
      src/util/output.hpp
  41. 2
      src/util/storedenum.hpp
  42. 10
      src/util/time.cpp

2
doc/Doxyfile.in

@ -1512,7 +1512,7 @@ INCLUDE_FILE_PATTERNS =
# undefined via #undef or recursively expanded use the := operator
# instead of the = operator.
PREDEFINED = INNOEXTRACT_HAVE_LZMA
PREDEFINED = INNOEXTRACT_HAVE_ARC4 INNOEXTRACT_HAVE_LZMA
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
# this tag can be used to specify a list of macro names that should be expanded.

6
src/cli/extract.cpp

@ -288,7 +288,7 @@ void print_filter_info(const setup::item & item, bool temp) {
bool first = true;
if(!item.languages.empty()) {
std::cout << (first ? " [" : ", ");
std::cout << " [";
first = false;
std::cout << color::green << item.languages << color::reset;
}
@ -303,6 +303,7 @@ void print_filter_info(const setup::item & item, bool temp) {
if(!first) {
std::cout << "]";
}
}
void print_filter_info(const setup::file_entry & file) {
@ -917,9 +918,8 @@ void process_file(const fs::path & file, const extract_options & o) {
if(checksum.finalize() != info.header.password) {
if(o.check_password) {
throw std::runtime_error("Incorrect password provided");
} else {
log_error << "Incorrect password provided";
}
log_error << "Incorrect password provided";
password.clear();
}
}

22
src/cli/extract.hpp

@ -82,6 +82,28 @@ struct extract_options {
boost::filesystem::path output_dir;
extract_options()
: quiet(false)
, silent(false)
, warn_unused(false)
, data_version(false)
, list(false)
, test(false)
, extract(false)
, list_languages(false)
, gog_game_id(false)
, show_password(false)
, check_password(false)
, preserve_file_times(false)
, local_timestamps(false)
, gog(false)
, gog_galaxy(false)
, extract_unknown(false)
, extract_temp(false)
, language_only(false)
, collisions(OverwriteCollisions)
{ }
};
void process_file(const boost::filesystem::path & file, const extract_options & o);

32
src/cli/gog.cpp

@ -27,7 +27,9 @@
#include <iostream>
#include <signal.h>
#include <boost/cstdint.hpp>
#include <boost/foreach.hpp>
#include <boost/noncopyable.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem/operations.hpp>
@ -102,8 +104,7 @@ void quit_handler(int /* ignored */) {
quit_requested = 1;
}
bool process_file_unrar(const fs::path & file, const extract_options & o,
const std::string & password) {
bool process_file_unrar(const std::string & file, const extract_options & o, const std::string & password) {
std::vector<const char *> args;
args.push_back("unrar");
@ -151,8 +152,7 @@ bool process_file_unrar(const fs::path & file, const extract_options & o,
args.push_back("--");
std::string filename = file.string();
args.push_back(filename.c_str());
args.push_back(file.c_str());
std::string dir = o.output_dir.string();
if(!dir.empty()) {
@ -178,15 +178,13 @@ bool process_file_unrar(const fs::path & file, const extract_options & o,
}
if(ret > 0) {
throw std::runtime_error("Could not " + get_verb(o) + " \"" + file.string()
+ "\": unrar failed");
throw std::runtime_error("Could not " + get_verb(o) + " \"" + file + "\": unrar failed");
}
return true;
}
bool process_file_unar(const fs::path & file, const extract_options & o,
const std::string & password) {
bool process_file_unar(const std::string & file, const extract_options & o, const std::string & password) {
std::string dir = o.output_dir.string();
@ -222,8 +220,7 @@ bool process_file_unar(const fs::path & file, const extract_options & o,
args.push_back("--");
std::string filename = file.string();
args.push_back(filename.c_str());
args.push_back(file.c_str());
args.push_back(NULL);
@ -233,14 +230,13 @@ bool process_file_unar(const fs::path & file, const extract_options & o,
}
if(ret > 0) {
throw std::runtime_error("Could not " + get_verb(o) + " \"" + file.string()
+ "\": unar failed");
throw std::runtime_error("Could not " + get_verb(o) + " \"" + file + "\": unar failed");
}
return true;
}
bool process_rar_file(const fs::path & file, const extract_options & o, const std::string & password) {
bool process_rar_file(const std::string & file, const extract_options & o, const std::string & password) {
return process_file_unrar(file, o, password) || process_file_unar(file, o, password);
}
@ -252,7 +248,7 @@ char hex_char(int c) {
}
}
class temporary_directory {
class temporary_directory : private boost::noncopyable {
fs::path path;
@ -305,8 +301,8 @@ void process_rar_files(const std::vector<fs::path> & files,
md5.finalize(hash);
password.resize(size_t(boost::size(hash) * 2));
for(size_t i = 0; i < size_t(boost::size(hash)); i++) {
password[2 * i + 0] = hex_char(((unsigned char)hash[i]) / 16);
password[2 * i + 1] = hex_char(((unsigned char)hash[i]) % 16);
password[2 * i + 0] = hex_char(boost::uint8_t(hash[i]) / 16);
password[2 * i + 1] = hex_char(boost::uint8_t(hash[i]) % 16);
}
}
@ -316,7 +312,7 @@ void process_rar_files(const std::vector<fs::path> & files,
bool ok = true;
BOOST_FOREACH(const fs::path & file, files) {
if(!process_rar_file(file, o, password)) {
if(!process_rar_file(file.string(), o, password)) {
ok = false;
}
}
@ -382,7 +378,7 @@ void process_rar_files(const std::vector<fs::path> & files,
+ "\": unable to create .r?? symlinks");
}
if(process_rar_file(first_file, o, password)) {
if(process_rar_file(first_file.string(), o, password)) {
return;
}

17
src/cli/main.cpp

@ -416,9 +416,12 @@ int main(int argc, char * argv[]) {
o.gog_galaxy = (options.count("no-gog-galaxy") == 0);
o.data_version = (options.count("data-version") != 0);
if(o.data_version && explicit_action) {
log_error << "Combining --data-version with other options is not allowed";
return ExitUserError;
if(o.data_version) {
logger::quiet = true;
if(explicit_action) {
log_error << "Combining --data-version with other options is not allowed";
return ExitUserError;
}
}
o.extract_unknown = (options.count("no-extract-unknown") == 0);
@ -456,9 +459,7 @@ int main(int argc, char * argv[]) {
if(!logger::quiet || logger::total_errors || logger::total_warnings) {
progress::clear();
std::ostream & os = logger::quiet ? std::cerr : std::cout;
if(!o.data_version || logger::total_errors || logger::total_warnings) {
os << color::green << "Done" << color::reset << std::dec;
}
os << color::green << "Done" << color::reset << std::dec;
if(logger::total_errors || logger::total_warnings) {
os << " with ";
if(logger::total_errors) {
@ -475,9 +476,7 @@ int main(int argc, char * argv[]) {
<< color::reset;
}
}
if(logger::total_errors) {
os << '.' << std::endl;
}
os << '.' << std::endl;
}
return logger::total_errors == 0 ? ExitSuccess : ExitDataError;

22
src/crypto/adler32.cpp

@ -25,7 +25,7 @@
namespace crypto {
void adler32::update(const char * input, size_t length) {
void adler32::update(const char * data, size_t length) {
const boost::uint_fast32_t base = 65521;
@ -35,7 +35,7 @@ void adler32::update(const char * input, size_t length) {
if(length % 8 != 0) {
do {
s1 += boost::uint8_t(*input++);
s1 += boost::uint8_t(*data++);
s2 += s1;
length--;
} while(length % 8 != 0);
@ -49,17 +49,17 @@ void adler32::update(const char * input, size_t length) {
while(length > 0) {
s1 += boost::uint8_t(input[0]), s2 += s1;
s1 += boost::uint8_t(input[1]), s2 += s1;
s1 += boost::uint8_t(input[2]), s2 += s1;
s1 += boost::uint8_t(input[3]), s2 += s1;
s1 += boost::uint8_t(input[4]), s2 += s1;
s1 += boost::uint8_t(input[5]), s2 += s1;
s1 += boost::uint8_t(input[6]), s2 += s1;
s1 += boost::uint8_t(input[7]), s2 += s1;
s1 += boost::uint8_t(data[0]), s2 += s1;
s1 += boost::uint8_t(data[1]), s2 += s1;
s1 += boost::uint8_t(data[2]), s2 += s1;
s1 += boost::uint8_t(data[3]), s2 += s1;
s1 += boost::uint8_t(data[4]), s2 += s1;
s1 += boost::uint8_t(data[5]), s2 += s1;
s1 += boost::uint8_t(data[6]), s2 += s1;
s1 += boost::uint8_t(data[7]), s2 += s1;
length -= 8;
input += 8;
data += 8;
if(s1 >= base) {
s1 -= base;

6
src/crypto/arc4.cpp

@ -31,12 +31,12 @@ void arc4::init(const char * key, size_t length) {
a = b = 0;
for(size_t i = 0; i < sizeof(state); i++){
state[i] = (unsigned char)i;
state[i] = boost::uint8_t(i);
}
size_t j = 0;
for(size_t i = 0; i < sizeof(state); i++) {
j = (j + state[i] + (unsigned char)key[i % length]) % sizeof(state);
j = (j + state[i] + boost::uint8_t(key[i % length])) % sizeof(state);
std::swap(state[i], state[j]);
}
@ -63,7 +63,7 @@ void arc4::crypt(const char * in, char * out, size_t length) {
for(size_t i = 0; i < length; i++) {
update();
out[i] = char(state[size_t(state[a] + state[b]) % sizeof(state)] ^ (unsigned char)in[i]);
out[i] = char(state[size_t(state[a] + state[b]) % sizeof(state)] ^ boost::uint8_t(in[i]));
}
}

2
src/crypto/arc4.hpp

@ -49,7 +49,7 @@ private:
void update();
unsigned char state[256];
boost::uint8_t state[256];
size_t a, b;
};

12
src/crypto/checksum.cpp

@ -29,18 +29,18 @@
namespace crypto {
bool checksum::operator==(const checksum & o) const {
bool checksum::operator==(const checksum & other) const {
if(o.type != type) {
if(other.type != type) {
return false;
}
switch(type) {
case None: return true;
case Adler32: return (adler32 == o.adler32);
case CRC32: return (crc32 == o.crc32);
case MD5: return !memcmp(md5, o.md5, sizeof(md5));
case SHA1: return !memcmp(sha1, o.sha1, sizeof(sha1));
case Adler32: return (adler32 == other.adler32);
case CRC32: return (crc32 == other.crc32);
case MD5: return !memcmp(md5, other.md5, sizeof(md5));
case SHA1: return !memcmp(sha1, other.sha1, sizeof(sha1));
default: return false;
};
}

19
src/crypto/crc32.cpp

@ -91,25 +91,26 @@ static boost::uint32_t crc32_shifted(boost::uint32_t crc) {
return crc >> 8;
}
void crc32::update(const char * s, size_t n) {
void crc32::update(const char * data, size_t length) {
for(; (size_t(s) % 4 != 0) && n > 0; n--) {
crc = crc32_table[crc32_index(crc) ^ boost::uint8_t(*s++)] ^ crc32_shifted(crc);
for(; (size_t(data) % 4 != 0) && length > 0; length--) {
crc = crc32_table[crc32_index(crc) ^ boost::uint8_t(*data++)] ^ crc32_shifted(crc);
}
while(n >= 4) {
crc ^= util::little_endian::load<boost::uint32_t>(s);
while(length >= 4) {
crc ^= util::little_endian::load<boost::uint32_t>(data);
crc = crc32_table[crc32_index(crc)] ^ crc32_shifted(crc);
crc = crc32_table[crc32_index(crc)] ^ crc32_shifted(crc);
crc = crc32_table[crc32_index(crc)] ^ crc32_shifted(crc);
crc = crc32_table[crc32_index(crc)] ^ crc32_shifted(crc);
n -= 4;
s += 4;
length -= 4;
data += 4;
}
while(n--) {
crc = crc32_table[crc32_index(crc) ^ boost::uint8_t(*s++)] ^ crc32_shifted(crc);
while(length--) {
crc = crc32_table[crc32_index(crc) ^ boost::uint8_t(*data++)] ^ crc32_shifted(crc);
}
}
} // namespace crypto

15
src/crypto/hasher.cpp

@ -22,19 +22,6 @@
namespace crypto {
hasher::hasher(const hasher & o) {
type = o.type;
switch(type) {
case crypto::None: break;
case crypto::Adler32: adler32 = o.adler32; break;
case crypto::CRC32: crc32 = o.crc32; break;
case crypto::MD5: md5 = o.md5; break;
case crypto::SHA1: sha1 = o.sha1; break;
};
}
hasher::hasher(checksum_type type) : type(type) {
switch(type) {
@ -44,6 +31,7 @@ hasher::hasher(checksum_type type) : type(type) {
case crypto::MD5: md5.init(); break;
case crypto::SHA1: sha1.init(); break;
};
}
void hasher::update(const char * data, size_t size) {
@ -55,6 +43,7 @@ void hasher::update(const char * data, size_t size) {
case crypto::MD5: md5.update(data, size); break;
case crypto::SHA1: sha1.update(data, size); break;
};
}
checksum hasher::finalize() {

1
src/crypto/hasher.hpp

@ -42,7 +42,6 @@ class hasher : checksum_base<hasher> {
public:
explicit hasher(checksum_type type);
hasher(const hasher & o);
void update(const char * data, size_t size);

52
src/crypto/iteratedhash.hpp

@ -68,7 +68,7 @@ private:
}
hash_word bit_count_lo() const { return count_lo << 3; }
char data[block_size];
char buffer[block_size];
hash_word state[hash_size];
hash_word count_lo, count_hi;
@ -76,40 +76,40 @@ private:
};
template <class T>
void iterated_hash<T>::update(const char * input, size_t len) {
void iterated_hash<T>::update(const char * data, size_t length) {
hash_word old_count_lo = count_lo;
if((count_lo = old_count_lo + hash_word(len)) < old_count_lo) {
if((count_lo = old_count_lo + hash_word(length)) < old_count_lo) {
count_hi++; // carry from low to high
}
count_hi += hash_word(util::safe_right_shift<8 * sizeof(hash_word)>(len));
count_hi += hash_word(util::safe_right_shift<8 * sizeof(hash_word)>(length));
size_t num = util::mod_power_of_2(old_count_lo, size_t(block_size));
if(num != 0) { // process left over data
if(num + len >= block_size) {
std::memcpy(data + num, input, block_size-num);
hash(data, block_size);
input += (block_size - num);
len -= (block_size - num);
if(num + length >= block_size) {
std::memcpy(buffer + num, data, block_size-num);
hash(buffer, block_size);
data += (block_size - num);
length -= (block_size - num);
// drop through and do the rest
} else {
std::memcpy(data + num, input, len);
std::memcpy(buffer + num, data, length);
return;
}
}
// now process the input data in blocks of BlockSize bytes and save the leftovers to m_data
if(len >= block_size) {
size_t leftOver = hash(input, len);
input += (len - leftOver);
len = leftOver;
if(length >= block_size) {
size_t left_over = hash(data, length);
data += (length - left_over);
length = left_over;
}
if(len) {
memcpy(data, input, len);
if(length) {
memcpy(buffer, data, length);
}
}
@ -151,30 +151,30 @@ void iterated_hash<T>::pad(size_t last_block_size, char pad_first) {
size_t num = util::mod_power_of_2(count_lo, size_t(block_size));
data[num++] = pad_first;
buffer[num++] = pad_first;
if(num <= last_block_size) {
memset(data + num, 0, last_block_size - num);
memset(buffer + num, 0, last_block_size - num);
} else {
memset(data + num, 0, block_size - num);
hash(data, block_size);
memset(data, 0, last_block_size);
memset(buffer + num, 0, block_size - num);
hash(buffer, block_size);
memset(buffer, 0, last_block_size);
}
}
template <class T>
void iterated_hash<T>::finalize(char * digest) {
void iterated_hash<T>::finalize(char * result) {
size_t order = transform::offset * sizeof(hash_word);
size_t size = block_size - 2 * sizeof(hash_word);
pad(size);
byte_order::store(bit_count_lo(), data + size + order);
byte_order::store(bit_count_hi(), data + size + sizeof(hash_word) - order);
byte_order::store(bit_count_lo(), buffer + size + order);
byte_order::store(bit_count_hi(), buffer + size + sizeof(hash_word) - order);
hash(data, block_size);
hash(buffer, block_size);
byte_order::store(state, hash_size, digest);
byte_order::store(state, hash_size, result);
}

168
src/crypto/md5.cpp

@ -35,101 +35,101 @@ void md5_transform::init(hash_word * state) {
state[3] = 0x10325476L;
}
void md5_transform::transform(hash_word * digest, const hash_word * in) {
void md5_transform::transform(hash_word * state, const hash_word * data) {
#define F1(x, y, z) (z ^ (x & (y ^ z)))
#define F2(x, y, z) F1(z, x, y)
#define F3(x, y, z) (x ^ y ^ z)
#define F4(x, y, z) (y ^ (x | ~z))
#define F1(x, y, z) (z ^ (x & (y ^ z)))
#define F2(x, y, z) F1(z, x, y)
#define F3(x, y, z) (x ^ y ^ z)
#define F4(x, y, z) (y ^ (x | ~z))
#define MD5STEP(f, w, x, y, z, data, s) \
w = util::rotl_fixed(w + f(x, y, z) + data, s) + x
#define MD5STEP(f, w, x, y, z, word, s) \
w = util::rotl_fixed(w + f(x, y, z) + word, s) + x
hash_word a, b, c, d;
a = digest[0];
b = digest[1];
c = digest[2];
d = digest[3];
a = state[0];
b = state[1];
c = state[2];
d = state[3];
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
MD5STEP(F1, a, b, c, d, data[0] + 0xd76aa478, 7);
MD5STEP(F1, d, a, b, c, data[1] + 0xe8c7b756, 12);
MD5STEP(F1, c, d, a, b, data[2] + 0x242070db, 17);
MD5STEP(F1, b, c, d, a, data[3] + 0xc1bdceee, 22);
MD5STEP(F1, a, b, c, d, data[4] + 0xf57c0faf, 7);
MD5STEP(F1, d, a, b, c, data[5] + 0x4787c62a, 12);
MD5STEP(F1, c, d, a, b, data[6] + 0xa8304613, 17);
MD5STEP(F1, b, c, d, a, data[7] + 0xfd469501, 22);
MD5STEP(F1, a, b, c, d, data[8] + 0x698098d8, 7);
MD5STEP(F1, d, a, b, c, data[9] + 0x8b44f7af, 12);
MD5STEP(F1, c, d, a, b, data[10] + 0xffff5bb1, 17);
MD5STEP(F1, b, c, d, a, data[11] + 0x895cd7be, 22);
MD5STEP(F1, a, b, c, d, data[12] + 0x6b901122, 7);
MD5STEP(F1, d, a, b, c, data[13] + 0xfd987193, 12);
MD5STEP(F1, c, d, a, b, data[14] + 0xa679438e, 17);
MD5STEP(F1, b, c, d, a, data[15] + 0x49b40821, 22);
MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
MD5STEP(F2, a, b, c, d, data[1] + 0xf61e2562, 5);
MD5STEP(F2, d, a, b, c, data[6] + 0xc040b340, 9);
MD5STEP(F2, c, d, a, b, data[11] + 0x265e5a51, 14);
MD5STEP(F2, b, c, d, a, data[0] + 0xe9b6c7aa, 20);
MD5STEP(F2, a, b, c, d, data[5] + 0xd62f105d, 5);
MD5STEP(F2, d, a, b, c, data[10] + 0x02441453, 9);
MD5STEP(F2, c, d, a, b, data[15] + 0xd8a1e681, 14);
MD5STEP(F2, b, c, d, a, data[4] + 0xe7d3fbc8, 20);
MD5STEP(F2, a, b, c, d, data[9] + 0x21e1cde6, 5);
MD5STEP(F2, d, a, b, c, data[14] + 0xc33707d6, 9);
MD5STEP(F2, c, d, a, b, data[3] + 0xf4d50d87, 14);
MD5STEP(F2, b, c, d, a, data[8] + 0x455a14ed, 20);
MD5STEP(F2, a, b, c, d, data[13] + 0xa9e3e905, 5);
MD5STEP(F2, d, a, b, c, data[2] + 0xfcefa3f8, 9);
MD5STEP(F2, c, d, a, b, data[7] + 0x676f02d9, 14);
MD5STEP(F2, b, c, d, a, data[12] + 0x8d2a4c8a, 20);
MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
MD5STEP(F3, a, b, c, d, data[5] + 0xfffa3942, 4);
MD5STEP(F3, d, a, b, c, data[8] + 0x8771f681, 11);
MD5STEP(F3, c, d, a, b, data[11] + 0x6d9d6122, 16);
MD5STEP(F3, b, c, d, a, data[14] + 0xfde5380c, 23);
MD5STEP(F3, a, b, c, d, data[1] + 0xa4beea44, 4);
MD5STEP(F3, d, a, b, c, data[4] + 0x4bdecfa9, 11);
MD5STEP(F3, c, d, a, b, data[7] + 0xf6bb4b60, 16);
MD5STEP(F3, b, c, d, a, data[10] + 0xbebfbc70, 23);
MD5STEP(F3, a, b, c, d, data[13] + 0x289b7ec6, 4);
MD5STEP(F3, d, a, b, c, data[0] + 0xeaa127fa, 11);
MD5STEP(F3, c, d, a, b, data[3] + 0xd4ef3085, 16);
MD5STEP(F3, b, c, d, a, data[6] + 0x04881d05, 23);
MD5STEP(F3, a, b, c, d, data[9] + 0xd9d4d039, 4);
MD5STEP(F3, d, a, b, c, data[12] + 0xe6db99e5, 11);
MD5STEP(F3, c, d, a, b, data[15] + 0x1fa27cf8, 16);
MD5STEP(F3, b, c, d, a, data[2] + 0xc4ac5665, 23);
MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
MD5STEP(F4, a, b, c, d, data[0] + 0xf4292244, 6);
MD5STEP(F4, d, a, b, c, data[7] + 0x432aff97, 10);
MD5STEP(F4, c, d, a, b, data[14] + 0xab9423a7, 15);
MD5STEP(F4, b, c, d, a, data[5] + 0xfc93a039, 21);
MD5STEP(F4, a, b, c, d, data[12] + 0x655b59c3, 6);
MD5STEP(F4, d, a, b, c, data[3] + 0x8f0ccc92, 10);
MD5STEP(F4, c, d, a, b, data[10] + 0xffeff47d, 15);
MD5STEP(F4, b, c, d, a, data[1] + 0x85845dd1, 21);
MD5STEP(F4, a, b, c, d, data[8] + 0x6fa87e4f, 6);
MD5STEP(F4, d, a, b, c, data[15] + 0xfe2ce6e0, 10);
MD5STEP(F4, c, d, a, b, data[6] + 0xa3014314, 15);
MD5STEP(F4, b, c, d, a, data[13] + 0x4e0811a1, 21);
MD5STEP(F4, a, b, c, d, data[4] + 0xf7537e82, 6);
MD5STEP(F4, d, a, b, c, data[11] + 0xbd3af235, 10);
MD5STEP(F4, c, d, a, b, data[2] + 0x2ad7d2bb, 15);
MD5STEP(F4, b, c, d, a, data[9] + 0xeb86d391, 21);
digest[0] += a;
digest[1] += b;
digest[2] += c;
digest[3] += d;
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
#undef MD5STEP
#undef F4
#undef F3
#undef F2
#undef F1
#undef MD5STEP
#undef F4
#undef F3
#undef F2
#undef F1
}

3
src/crypto/md5.hpp

@ -45,7 +45,8 @@ public:
static void init(hash_word * state);
static void transform(hash_word * digest, const hash_word * data);
static void transform(hash_word * state, const hash_word * data);
};
typedef iterated_hash<md5_transform> md5;

72
src/crypto/sha1.cpp

@ -37,31 +37,31 @@ void sha1_transform::init(hash_word * state) {
void sha1_transform::transform(hash_word * state, const hash_word * data) {
#define blk0(i) (W[i] = data[i])
#define blk1(i) (W[i & 15] = util::rotl_fixed(W[(i + 13) & 15] ^ W[(i + 8) & 15] \
^ W[(i + 2) & 15] ^ W[i & 15], 1))
#define f1(x, y, z) (z ^ (x & (y ^ z)))
#define f2(x, y, z) (x ^ y ^ z)
#define f3(x, y, z) ((x & y) | (z & (x | y)))
#define f4(x, y, z) (x ^ y ^ z)
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
#define R0(v, w, x, y, z, i) \
z += f1(w, x, y) + blk0(i) + 0x5A827999 + util::rotl_fixed(v, 5); \
w = util::rotl_fixed(w, 30);
#define R1(v, w, x, y, z, i) \
z += f1(w, x, y) + blk1(i) + 0x5A827999 + util::rotl_fixed(v, 5); \
w = util::rotl_fixed(w, 30);
#define R2(v, w, x, y, z, i) \
z += f2(w, x, y) + blk1(i) + 0x6ED9EBA1 + util::rotl_fixed(v, 5); \
w = util::rotl_fixed(w, 30);
#define R3(v, w, x, y, z, i) \
z += f3(w, x, y) + blk1(i) + 0x8F1BBCDC + util::rotl_fixed(v, 5); \
w = util::rotl_fixed(w, 30);
#define R4(v, w, x, y, z, i) \
z += f4(w, x, y) + blk1(i) + 0xCA62C1D6 + util::rotl_fixed(v, 5); \
w = util::rotl_fixed(w, 30);
#define blk0(i) (W[i] = data[i])
#define blk1(i) (W[i & 15] = util::rotl_fixed(W[(i + 13) & 15] ^ W[(i + 8) & 15] \
^ W[(i + 2) & 15] ^ W[i & 15], 1))
#define f1(x, y, z) (z ^ (x & (y ^ z)))
#define f2(x, y, z) (x ^ y ^ z)
#define f3(x, y, z) ((x & y) | (z & (x | y)))
#define f4(x, y, z) (x ^ y ^ z)
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
#define R0(v, w, x, y, z, i) \
z += f1(w, x, y) + blk0(i) + 0x5A827999 + util::rotl_fixed(v, 5); \
w = util::rotl_fixed(w, 30);
#define R1(v, w, x, y, z, i) \
z += f1(w, x, y) + blk1(i) + 0x5A827999 + util::rotl_fixed(v, 5); \
w = util::rotl_fixed(w, 30);
#define R2(v, w, x, y, z, i) \
z += f2(w, x, y) + blk1(i) + 0x6ED9EBA1 + util::rotl_fixed(v, 5); \
w = util::rotl_fixed(w, 30);
#define R3(v, w, x, y, z, i) \
z += f3(w, x, y) + blk1(i) + 0x8F1BBCDC + util::rotl_fixed(v, 5); \
w = util::rotl_fixed(w, 30);
#define R4(v, w, x, y, z, i) \
z += f4(w, x, y) + blk1(i) + 0xCA62C1D6 + util::rotl_fixed(v, 5); \
w = util::rotl_fixed(w, 30);
hash_word W[16];
@ -181,19 +181,19 @@ void sha1_transform::transform(hash_word * state, const hash_word * data) {
state[3] += d;
state[4] += e;
#undef R4
#undef R3
#undef R2
#undef R1
#undef R0
#undef R4
#undef R3
#undef R2
#undef R1
#undef R0
#undef f4
#undef f3
#undef f2
#undef f1
#undef f4
#undef f3
#undef f2
#undef f1
#undef blk1
#undef blk0
#undef blk1
#undef blk0
}

2
src/crypto/sha1.hpp

@ -45,7 +45,7 @@ public:
static void init(hash_word * state);
static void transform(hash_word * digest, const hash_word * data);
static void transform(hash_word * state, const hash_word * data);
};
typedef iterated_hash<sha1_transform> sha1;

14
src/loader/exereader.cpp

@ -45,7 +45,7 @@ enum BinaryType {
PEMagic2 = 0x0000, // "\0\0"
};
static BinaryType determine_binary_type(std::istream & is) {
BinaryType determine_binary_type(std::istream & is) {
boost::uint16_t dos_magic = util::load<boost::uint16_t>(is.seekg(0));
if(is.fail() || dos_magic != DOSMagic) {
@ -365,7 +365,7 @@ bool pe_reader::get_resource_table(boost::uint32_t & entry, boost::uint32_t offs
return is_table;
}
boost::uint32_t pe_reader::find_resource_entry(std::istream & is, boost::uint32_t needle) {
boost::uint32_t pe_reader::find_resource_entry(std::istream & is, boost::uint32_t id) {
// skip: characteristics + timestamp + major version + minor version
if(is.seekg(4 + 4 + 2 + 2, std::ios_base::cur).fail()) {
@ -378,7 +378,7 @@ boost::uint32_t pe_reader::find_resource_entry(std::istream & is, boost::uint32_
// Number of id resource entries.
boost::uint16_t nbids = util::load<boost::uint16_t>(is);
if(needle == Default) {
if(id == Default) {
boost::uint32_t offset = util::load<boost::uint32_t>(is.seekg(4, std::ios_base::cur));
return is.fail() ? 0 : offset;
}
@ -391,14 +391,14 @@ boost::uint32_t pe_reader::find_resource_entry(std::istream & is, boost::uint32_
for(size_t i = 0; i < nbids; i++) {
boost::uint32_t id = util::load<boost::uint32_t>(is);
boost::uint32_t offset = util::load<boost::uint32_t>(is);
boost::uint32_t entry_id = util::load<boost::uint32_t>(is);
boost::uint32_t entry_offset = util::load<boost::uint32_t>(is);
if(is.fail()) {
return 0;
}
if(id == needle) {
return offset;
if(entry_id == id) {
return entry_offset;
}
}

2
src/loader/offsets.cpp

@ -47,7 +47,7 @@ struct setup_loader_version {
};
static const setup_loader_version known_setup_loader_versions[] = {
const setup_loader_version known_setup_loader_versions[] = {
{ { 'r', 'D', 'l', 'P', 't', 'S', '0', '2', 0x87, 'e', 'V', 'x' }, INNO_VERSION(1, 2, 10) },
{ { 'r', 'D', 'l', 'P', 't', 'S', '0', '4', 0x87, 'e', 'V', 'x' }, INNO_VERSION(4, 0, 0) },
{ { 'r', 'D', 'l', 'P', 't', 'S', '0', '5', 0x87, 'e', 'V', 'x' }, INNO_VERSION(4, 0, 3) },

2
src/setup/data.cpp

@ -80,7 +80,7 @@ void data_entry::load(std::istream & is, const version & version) {
boost::uint16_t time = util::load<boost::uint16_t>(is);
boost::uint16_t date = util::load<boost::uint16_t>(is);
struct tm t;
struct tm t = { };
t.tm_sec = util::get_bits(time, 0, 4) * 2; // [0, 58]
t.tm_min = util::get_bits(time, 5, 10); // [0, 59]
t.tm_hour = util::get_bits(time, 11, 15); // [0, 23]

10
src/setup/expression.cpp

@ -31,11 +31,11 @@ namespace setup {
namespace {
static bool is_identifier_start(char c) {
bool is_identifier_start(char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '-';
}
static bool is_identifier(char c) {
bool is_identifier(char c) {
return is_identifier_start(c) || (c >= '0' && c <= '9') || c == '\\';
}
@ -150,11 +150,11 @@ struct evaluator {
} // anonymous namespace
bool expression_match(const std::string & test, const std::string & expr) {
bool expression_match(const std::string & test, const std::string & expression) {
try {
return evaluator(expr, test).eval();
return evaluator(expression, test).eval();
} catch(const std::runtime_error & error) {
log_warning << "Error evaluating \"" << expr << "\": " << error.what();
log_warning << "Error evaluating \"" << expression << "\": " << error.what();
return true;
}
}

12
src/setup/filename.cpp

@ -53,7 +53,7 @@ struct is_unsafe_path_char {
}
};
static std::string replace_unsafe_chars(const std::string & str) {
std::string replace_unsafe_chars(const std::string & str) {
std::string result;
result.resize(str.size());
std::replace_copy_if(str.begin(), str.end(), result.begin(), is_unsafe_path_char(), '$');
@ -160,20 +160,20 @@ std::string filename_map::shorten_path(const std::string & path) const {
return result;
}
std::string filename_map::convert(std::string input) const {
std::string filename_map::convert(std::string path) const {
// Convert paths to lower-case if requested
if(lowercase) {
std::transform(input.begin(), input.end(), input.begin(), ::tolower);
std::transform(path.begin(), path.end(), path.begin(), ::tolower);
}
// Don't expand variables if requested
if(!expand) {
return input;
return path;
}
it begin = input.begin();
std::string expanded = expand_variables(begin, input.end());
it begin = path.begin();
std::string expanded = expand_variables(begin, path.end());
return shorten_path(expanded);
}

56
src/setup/info.cpp

@ -162,50 +162,50 @@ void check_is_end(stream::block_reader::pointer & is, const char * what) {
} // anonymous namespace
void info::load(std::istream & ifs, entry_types e, const setup::version & v) {
void info::load(std::istream & is, entry_types entries, const setup::version & version) {
if(e & (Messages | NoSkip)) {
e |= Languages;
if(entries & (Messages | NoSkip)) {
entries |= Languages;
}
stream::block_reader::pointer is = stream::block_reader::get(ifs, v);
stream::block_reader::pointer reader = stream::block_reader::get(is, version);
header.load(*is, v);
header.load(*reader, version);
load_entries(*is, v, e, header.language_count, languages, Languages);
load_entries(*reader, version, entries, header.language_count, languages, Languages);
if(v < INNO_VERSION(4, 0, 0)) {
load_wizard_and_decompressor(*is, v, header, *this, e);
if(version < INNO_VERSION(4, 0, 0)) {
load_wizard_and_decompressor(*reader, version, header, *this, entries);
}
load_entries(*is, v, e, header.message_count, messages, Messages, languages);
load_entries(*is, v, e, header.permission_count, permissions, Permissions);
load_entries(*is, v, e, header.type_count, types, Types);
load_entries(*is, v, e, header.component_count, components, Components);
load_entries(*is, v, e, header.task_count, tasks, Tasks);
load_entries(*is, v, e, header.directory_count, directories, Directories);
load_entries(*is, v, e, header.file_count, files, Files);
load_entries(*is, v, e, header.icon_count, icons, Icons);
load_entries(*is, v, e, header.ini_entry_count, ini_entries, IniEntries);
load_entries(*is, v, e, header.registry_entry_count, registry_entries, RegistryEntries);
load_entries(*is, v, e, header.delete_entry_count, delete_entries, DeleteEntries);
load_entries(*is, v, e, header.uninstall_delete_entry_count, uninstall_delete_entries,
load_entries(*reader, version, entries, header.message_count, messages, Messages, languages);
load_entries(*reader, version, entries, header.permission_count, permissions, Permissions);
load_entries(*reader, version, entries, header.type_count, types, Types);
load_entries(*reader, version, entries, header.component_count, components, Components);
load_entries(*reader, version, entries, header.task_count, tasks, Tasks);
load_entries(*reader, version, entries, header.directory_count, directories, Directories);
load_entries(*reader, version, entries, header.file_count, files, Files);
load_entries(*reader, version, entries, header.icon_count, icons, Icons);
load_entries(*reader, version, entries, header.ini_entry_count, ini_entries, IniEntries);
load_entries(*reader, version, entries, header.registry_entry_count, registry_entries, RegistryEntries);
load_entries(*reader, version, entries, header.delete_entry_count, delete_entries, DeleteEntries);
load_entries(*reader, version, entries, header.uninstall_delete_entry_count, uninstall_delete_entries,
UninstallDeleteEntries);
load_entries(*is, v, e, header.run_entry_count, run_entries, RunEntries);
load_entries(*is, v, e, header.uninstall_run_entry_count, uninstall_run_entries,
load_entries(*reader, version, entries, header.run_entry_count, run_entries, RunEntries);
load_entries(*reader, version, entries, header.uninstall_run_entry_count, uninstall_run_entries,
UninstallRunEntries);
if(v >= INNO_VERSION(4, 0, 0)) {
load_wizard_and_decompressor(*is, v, header, *this, e);
if(version >= INNO_VERSION(4, 0, 0)) {
load_wizard_and_decompressor(*reader, version, header, *this, entries);
}
// restart the compression stream
check_is_end(is, "unknown data at end of primary header stream");
is = stream::block_reader::get(ifs, v);
check_is_end(reader, "unknown data at end of primary header stream");
reader = stream::block_reader::get(is, version);
load_entries(*is, v, e, header.data_entry_count, data_entries, DataEntries);
load_entries(*reader, version, entries, header.data_entry_count, data_entries, DataEntries);
check_is_end(is, "unknown data at end of secondary header stream");
check_is_end(reader, "unknown data at end of secondary header stream");
}
void info::load(std::istream & is, entry_types entries) {

4
src/setup/permission.cpp

@ -25,9 +25,9 @@
namespace setup {
void permission_entry::load(std::istream & is, const version & v) {
void permission_entry::load(std::istream & is, const version & version) {
(void)v;
(void)version;
is >> util::binary_string(permissions); // an array of TGrantPermissionEntry's

18
src/setup/version.cpp

@ -53,7 +53,7 @@ struct known_legacy_version {
};
static const known_legacy_version legacy_versions[] = {
const known_legacy_version legacy_versions[] = {
{ "i1.2.10--16\x1a", INNO_VERSION(1, 2, 10), 16 },
{ "i1.2.10--32\x1a", INNO_VERSION(1, 2, 10), 32 },
};
@ -71,7 +71,7 @@ struct known_version {
};
static const known_version versions[] = {
const known_version versions[] = {
{ "Inno Setup Setup Data (1.3.21)", INNO_VERSION_EXT(1, 3, 21, 0), false },
{ "Inno Setup Setup Data (1.3.25)", INNO_VERSION_EXT(1, 3, 25, 0), false },
{ "Inno Setup Setup Data (2.0.0)", INNO_VERSION_EXT(2, 0, 0, 0), false },
@ -157,19 +157,19 @@ static const known_version versions[] = {
} // anonymous namespace
std::ostream & operator<<(std::ostream & os, const version & v) {
std::ostream & operator<<(std::ostream & os, const version & version) {
os << v.a() << '.' << v.b() << '.' << v.c();
if(v.d()) {
os << '.' << v.d();
os << version.a() << '.' << version.b() << '.' << version.c();
if(version.d()) {
os << '.' << version.d();
}
if(v.unicode) {
if(version.unicode) {
os << " (unicode)";
}
if(v.bits != 32) {
os << " (" << int(v.bits) << "-bit)";
if(version.bits != 32) {
os << " (" << int(version.bits) << "-bit)";
}
return os;

33
src/setup/windows.cpp

@ -95,7 +95,10 @@ windows_version_name windows_nt_version_names[] = {
{ "Windows XP", { 5, 1, 2600 } },
{ "Windows XP x64", { 5, 2, 3790 } },
{ "Windows Vista", { 6, 0, 6000 } },
{ "Windows 7", { 6, 1, 7600 } }
{ "Windows 7", { 6, 1, 7600 } },
{ "Windows 8", { 6, 2, 0 } },
{ "Windows 8.1", { 6, 3, 0 } },
{ "Windows 10", { 10, 0, 0 } },
};
const char * get_version_name(const windows_version::data & version, bool nt = false) {
@ -120,23 +123,23 @@ const char * get_version_name(const windows_version::data & version, bool nt = f
} // anonymous namespace
std::ostream & operator<<(std::ostream & os, const windows_version::data & v) {
os << v.major << '.' << v.minor;
if(v.build) {
os << v.build;
std::ostream & operator<<(std::ostream & os, const windows_version::data & version) {
os << version.major << '.' << version.minor;
if(version.build) {
os << version.build;
}
return os;
}
std::ostream & operator<<(std::ostream & os, const windows_version & v) {
std::ostream & operator<<(std::ostream & os, const windows_version & version) {
os << v.win_version;
if(v.nt_version != v.win_version) {
os << " nt " << v.nt_version;
os << version.win_version;
if(version.nt_version != version.win_version) {
os << " nt " << version.nt_version;
}
const char * win_name = get_version_name(v.win_version);
const char * nt_name = get_version_name(v.nt_version, true);
const char * win_name = get_version_name(version.win_version);
const char * nt_name = get_version_name(version.nt_version, true);
if(win_name || nt_name) {
os << " (";
@ -152,10 +155,10 @@ std::ostream & operator<<(std::ostream & os, const windows_version & v) {
os << ')';
}
if(v.nt_service_pack.major || v.nt_service_pack.minor) {
os << " service pack " << v.nt_service_pack.major;
if(v.nt_service_pack.minor) {
os << '.' << v.nt_service_pack.minor;
if(version.nt_service_pack.major || version.nt_service_pack.minor) {
os << " service pack " << version.nt_service_pack.major;
if(version.nt_service_pack.minor) {
os << '.' << version.nt_service_pack.minor;
}
}

4
src/setup/windows.hpp

@ -97,8 +97,8 @@ struct windows_version_range {
};
std::ostream & operator<<(std::ostream & os, const windows_version::data & svd);
std::ostream & operator<<(std::ostream & os, const windows_version & svd);
std::ostream & operator<<(std::ostream & os, const windows_version::data & version);
std::ostream & operator<<(std::ostream & os, const windows_version & version);
} // namespace setup

2
src/stream/block.hpp

@ -41,7 +41,7 @@ namespace stream {
//! Error thrown by \ref chunk_reader::get or the returned stream if there was a problem.
struct block_error : public std::ios_base::failure {
explicit block_error(std::string msg) : std::ios_base::failure(msg) { }
explicit block_error(const std::string & msg) : std::ios_base::failure(msg) { }
};

1
src/stream/checksum.hpp

@ -59,7 +59,6 @@ public:
: hasher(type)
, output(output)
{ }
checksum_filter(const checksum_filter & o) : hasher(o.hasher), output(o.output) { }
template <typename Source>
std::streamsize read(Source & src, char * dest, std::streamsize n) {

2
src/stream/chunk.hpp

@ -47,7 +47,7 @@ class slice_reader;
//! Error thrown by \ref chunk_reader::get if there was a problem.
struct chunk_error : public std::ios_base::failure {
explicit chunk_error(std::string msg) : std::ios_base::failure(msg) { }
explicit chunk_error(const std::string & msg) : std::ios_base::failure(msg) { }
};

6
src/stream/exefilter.hpp

@ -63,8 +63,8 @@ public:
template <typename Source>
void close(const Source &) {
addr_bytes_left = 0, addr_offset = 5;
void close(const Source & /* source */) {
addr = 0, addr_bytes_left = 0, addr_offset = 5;
}
private:
@ -103,7 +103,7 @@ public:
std::streamsize read(Source & src, char * dest, std::streamsize n);
template <typename Source>
void close(const Source &) {
void close(const Source & /* source */) {
offset = 0, flush_bytes = 0;
}

2
src/stream/lzma.hpp

@ -41,7 +41,7 @@ namespace stream {
//! Error thrown if there was en error in an LZMA stream
struct lzma_error : public std::ios_base::failure {
lzma_error(std::string msg, int code)
lzma_error(const std::string & msg, int code)
: std::ios_base::failure(msg), error_code(code) { }
//! \return the liblzma code for the error.

2
src/stream/slice.hpp

@ -39,7 +39,7 @@ namespace stream {
//! Error thrown by \ref slice_reader if there was a problem.
struct slice_error : public std::ios_base::failure {
explicit slice_error(std::string msg) : std::ios_base::failure(msg) { }
explicit slice_error(const std::string & msg) : std::ios_base::failure(msg) { }
};

3
src/util/console.cpp

@ -357,12 +357,13 @@ bool progress::update(boost::uint64_t delta, bool force) {
}
}
boost::uint64_t time = last_time;
boost::uint64_t time;
try {
boost::posix_time::ptime now(boost::posix_time::microsec_clock::universal_time());
time = boost::uint64_t((now - start_time).total_microseconds());
} catch(...) {
// this shouldn't happen, assume no time has passed
time = last_time;
}
#if defined(_WIN32)

4
src/util/console.hpp

@ -118,10 +118,6 @@ public:
* \param show_rate Display the rate at which the progress changes.
*/
progress(boost::uint64_t max = 0, bool show_rate = true);
progress(const progress & o)
: max(o.max), value(o.value), show_rate(o.show_rate), start_time(o.start_time),
last_status(o.last_status), last_time(o.last_time),
last_rate(o.last_rate), label(o.label.str()) { }
/*!
* Update the progress bar.

95
src/util/encoding.cpp

@ -89,7 +89,7 @@ enum known_codepages {
namespace {
//! Get names for encodings where iconv doesn't have the codepage alias
static const char * get_encoding_name(codepage_id codepage) {
const char * get_encoding_name(codepage_id codepage) {
switch(codepage) {
case 708: return "ISO-8859-6";
case 936: return "GBK";
@ -161,11 +161,11 @@ static const char * get_encoding_name(codepage_id codepage) {
}
}
static const char replacement_char = '_';
typedef boost::uint32_t unicode_char;
static size_t get_encoding_size(codepage_id codepage) {
const unicode_char replacement_char = '_';
size_t get_encoding_size(codepage_id codepage) {
switch(codepage) {
case 1200: return 2u; // UTF-16LE
case 1201: return 2u; // UTF-16BE
@ -176,12 +176,12 @@ static size_t get_encoding_size(codepage_id codepage) {
}
//! Fallback conversion that will at least work for ASCII characters
static void to_utf8_fallback(const std::string & from, std::string & to, codepage_id cp) {
void to_utf8_fallback(const std::string & from, std::string & to, codepage_id codepage) {
size_t skip = get_encoding_size(cp);
size_t skip = get_encoding_size(codepage);
size_t shift = 0;
switch(cp) {
switch(codepage) {
case 1201: shift = 1u * 8u; break; // UTF-16BE
case 12001: shift = 3u * 8u; break; // UTF-32BE
default: break;
@ -204,14 +204,14 @@ static void to_utf8_fallback(const std::string & from, std::string & to, codepag
// replace non-ASCII characters with underscores
if((unicode_char(ascii) << shift) != unicode) {
warn = true;
ascii = replacement_char;
ascii = char(replacement_char);
}
to.push_back(ascii);
}
if(warn) {
log_warning << "Unknown data while converting from CP" << cp << " to UTF-8.";
log_warning << "Unknown data while converting from CP" << codepage << " to UTF-8.";
}
}
@ -221,7 +221,7 @@ bool is_utf8_continuation_byte(unicode_char chr) {
}
template <typename In>
unicode_char utf8_read(In & it, In end, unicode_char replacement = unicode_char(replacement_char)) {
unicode_char utf8_read(In & it, In end, unicode_char replacement = replacement_char) {
if(it == end) {
return unicode_char(-1);
@ -270,15 +270,20 @@ unicode_char utf8_read(In & it, In end, unicode_char replacement = unicode_char(
return chr;
}
static size_t utf8_length(unicode_char chr) {
if (chr < 0x80) return 1;
else if(chr < 0x800) return 2;
else if(chr < 0x10000) return 3;
else if(chr <= 0x0010ffff) return 4;
size_t utf8_length(unicode_char chr) {
if(chr < 0x80) {
return 1;
} else if(chr < 0x800) {
return 2;
} else if(chr < 0x10000) {
return 3;
} else if(chr <= 0x0010ffff) {
return 4;
}
return 1;
}
static void utf8_write(std::string & to, unicode_char chr) {
void utf8_write(std::string & to, unicode_char chr) {
static const boost::uint8_t first_bytes[7] = {
0x00, 0x00, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc
@ -310,16 +315,16 @@ static void utf8_write(std::string & to, unicode_char chr) {
}
//! \return true c is is the first part of an UTF-16 surrogate pair
static bool is_utf16_high_surrogate(unicode_char chr) {
bool is_utf16_high_surrogate(unicode_char chr) {
return chr >= 0xd800 && chr <= 0xdbff;
}
//! \return true c is is the second part of an UTF-16 surrogate pair
static bool is_utf16_low_surrogate(unicode_char chr) {
bool is_utf16_low_surrogate(unicode_char chr) {
return chr >= 0xdc00 && chr <= 0xdfff;
}
static void utf16le_to_utf8(const std::string & from, std::string & to) {
void utf16le_to_utf8(const std::string & from, std::string & to) {
if(from.size() % 2 != 0) {
log_warning << "Unexpected trailing byte in UTF-16 string.";
@ -414,7 +419,7 @@ void utf8_to_utf16le(const std::string & from, std::string & to) {
}
static unicode_char windows1252_replacements[] = {
unicode_char windows1252_replacements[] = {
0x20ac, replacement_char, 0x201a, 0x192, 0x201e, 0x2026, 0x2020, 0x2021, 0x2c6,
0x2030, 0x160, 0x2039, 0x152, replacement_char, 0x17d, replacement_char,
replacement_char, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x2dc,
@ -423,7 +428,7 @@ static unicode_char windows1252_replacements[] = {
BOOST_STATIC_ASSERT(sizeof(windows1252_replacements) == (160 - 128) * sizeof(*windows1252_replacements));
static void windows1252_to_utf8(const std::string & from, std::string & to) {
void windows1252_to_utf8(const std::string & from, std::string & to) {
to.clear();
to.reserve(from.size()); // optimistically, most strings only have ASCII characters
@ -436,7 +441,7 @@ static void windows1252_to_utf8(const std::string & from, std::string & to) {
unicode_char chr = boost::uint8_t(c);
if(chr >= 128 && chr < 160) {
chr = windows1252_replacements[chr - 128];
warn = warn || (chr == unicode_char(replacement_char));
warn = warn || chr == replacement_char;
}
utf8_write(to, chr);
@ -448,7 +453,7 @@ static void windows1252_to_utf8(const std::string & from, std::string & to) {
}
static void utf8_to_windows1252(const std::string & from, std::string & to) {
void utf8_to_windows1252(const std::string & from, std::string & to) {
to.clear();
to.reserve(from.size()); // optimistically, most strings only have ASCII characters
@ -462,12 +467,12 @@ static void utf8_to_windows1252(const std::string & from, std::string & to) {
// Windows-1252 maps almost directly to Unicode - yay!
if(chr >= 256 || (chr >= 128 && chr < 160)) {
size_t i = 0;
for(; i < boost::size(windows1252_replacements); i++) {
for(; i < size_t(boost::size(windows1252_replacements)); i++) {
if(chr == windows1252_replacements[i] && windows1252_replacements[i] != replacement_char) {
break;
}
}
if(i < boost::size(windows1252_replacements)) {
if(i < size_t(boost::size(windows1252_replacements))) {
chr = unicode_char(128 + i);
} else {
chr = replacement_char;
@ -487,9 +492,9 @@ static void utf8_to_windows1252(const std::string & from, std::string & to) {
#if INNOEXTRACT_HAVE_ICONV
typedef boost::unordered_map<codepage_id, iconv_t> converter_map;
static converter_map converters;
converter_map converters;
static iconv_t get_converter(codepage_id codepage) {
iconv_t get_converter(codepage_id codepage) {
// Try to reuse an existing converter if possible
converter_map::const_iterator i = converters.find(codepage);
@ -524,9 +529,9 @@ static iconv_t get_converter(codepage_id codepage) {
return converters[codepage] = handle;
}
static bool to_utf8_iconv(const std::string & from, std::string & to, codepage_id cp) {
bool to_utf8_iconv(const std::string & from, std::string & to, codepage_id codepage) {
iconv_t converter = get_converter(cp);
iconv_t converter = get_converter(codepage);
if(converter == iconv_t(-1)) {
return false;
}
@ -549,7 +554,7 @@ static bool to_utf8_iconv(const std::string & from, std::string & to, codepage_i
iconv(converter, NULL, NULL, NULL, NULL);
size_t skip = get_encoding_size(cp);
size_t skip = get_encoding_size(codepage);
bool warn = false;
@ -567,9 +572,9 @@ static bool to_utf8_iconv(const std::string & from, std::string & to, codepage_i
} else if(/*errno == EILSEQ &&*/ insize >= 2) {
// invalid byte (sequence) - add a replacement char and try the next byte
if(outsize == 0) {
to.push_back(replacement_char);
to.push_back(char(replacement_char));
} else {
*outbuf = replacement_char;
*outbuf = char(replacement_char);
outsize--;
}
inbuf.buf += skip;
@ -586,7 +591,7 @@ static bool to_utf8_iconv(const std::string & from, std::string & to, codepage_i
}
if(warn) {
log_warning << "Unexpected data while converting from CP" << cp << " to UTF-8.";
log_warning << "Unexpected data while converting from CP" << codepage << " to UTF-8.";
}
to.resize(outbase);
@ -598,7 +603,7 @@ static bool to_utf8_iconv(const std::string & from, std::string & to, codepage_i
#if INNOEXTRACT_HAVE_WIN32_CONV
static std::string windows_error_string(DWORD code) {
std::string windows_error_string(DWORD code) {
char * error;
DWORD n = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL, code, 0, reinterpret_cast<char *>(&error), 0,
@ -615,7 +620,7 @@ static std::string windows_error_string(DWORD code) {
}
}
static bool to_utf8_win32(const std::string & from, std::string & to, codepage_id cp) {
bool to_utf8_win32(const std::string & from, std::string & to, codepage_id codepage) {
int ret = 0;
@ -623,18 +628,18 @@ static bool to_utf8_win32(const std::string & from, std::string & to, codepage_i
const WCHAR * utf16;
int utf16_size;
std::vector<WCHAR> buffer;
if(cp == cp_utf16le) {
if(codepage == cp_utf16le) {
utf16 = reinterpret_cast<const WCHAR *>(from.data());
utf16_size = int(from.size()) / 2;
} else {
utf16_size = MultiByteToWideChar(cp, 0, from.data(), int(from.length()), NULL, 0);
utf16_size = MultiByteToWideChar(codepage, 0, from.data(), int(from.length()), NULL, 0);
if(utf16_size > 0) {
buffer.resize(size_t(utf16_size));
ret = MultiByteToWideChar(cp, 0, from.data(), int(from.length()),
ret = MultiByteToWideChar(codepage, 0, from.data(), int(from.length()),
&buffer.front(), utf16_size);
}
if(utf16_size <= 0 || ret <= 0) {
log_warning << "Error while converting from CP" << cp << " to UTF-16: "
log_warning << "Error while converting from CP" << codepage << " to UTF-16: "
<< windows_error_string(GetLastError());
return false;
}
@ -661,19 +666,19 @@ static bool to_utf8_win32(const std::string & from, std::string & to, codepage_i
} // anonymous namespace
void to_utf8(const std::string & from, std::string & to, codepage_id cp) {
void to_utf8(const std::string & from, std::string & to, codepage_id codepage) {
if(from.empty()) {
to.clear();
return;
}
if(cp == cp_utf8 || cp == cp_ascii) {
if(codepage == cp_utf8 || codepage == cp_ascii) {
to = from;
return;
}
switch(cp) {
switch(codepage) {
case cp_utf16le: utf16le_to_utf8(from, to); return;
case cp_windows1252: windows1252_to_utf8(from, to); return;
case cp_iso_8859_1: windows1252_to_utf8(from, to); return;
@ -681,18 +686,18 @@ void to_utf8(const std::string & from, std::string & to, codepage_id cp) {
}
#if INNOEXTRACT_HAVE_ICONV
if(to_utf8_iconv(from, to, cp)) {
if(to_utf8_iconv(from, to, codepage)) {
return;
}
#endif
#if INNOEXTRACT_HAVE_WIN32_CONV
if(to_utf8_win32(from, to, cp)) {
if(to_utf8_win32(from, to, codepage)) {
return;
}
#endif
to_utf8_fallback(from, to, cp);
to_utf8_fallback(from, to, codepage);
}

9
src/util/flags.hpp

@ -63,9 +63,7 @@ public:
/* implicit */ inline flags(enum_type flag) : _flags(Type().set(size_t(flag))) { }
/* implicit */ inline flags(Zero = 0) : _flags() { }
flags(const flags & o) : _flags(o._flags) { }
/* implicit */ inline flags(Zero /* zero */ = 0) : _flags() { }
static flags load(Type _flags) {
return flags(_flags, true);
@ -144,11 +142,6 @@ public:
return operator^=(flag);
}
flags & operator=(flags o) {
_flags = o._flags;
return *this;
}
//! Get a set of flags with all possible values set.
static flags all() {
return flags(Type().flip());

4
src/util/log.hpp

@ -29,6 +29,8 @@
#include <sstream>
#include <string>
#include <boost/noncopyable.hpp>
#ifdef DEBUG
#define debug(...) \
if(::logger::debug) \
@ -46,7 +48,7 @@
/*!
* logger class that allows longging via the stream operator.
*/
class logger {
class logger : private boost::noncopyable {
public:

4
src/util/math.hpp

@ -56,12 +56,12 @@ template <bool overflow>
struct safe_shifter {
template <class T>
static T right_shift(T, unsigned int) {
static T right_shift(T /* value */, unsigned int /* bits */) {
return 0;
}
template <class T>
static T left_shift(T, unsigned int) {
static T left_shift(T /* value */, unsigned int /* bits */) {
return 0;
}

2
src/util/output.hpp

@ -46,7 +46,7 @@ inline std::ostream & operator<<(std::ostream & os, const quoted & q) {
color::shell_command prev = color::current;
os << '"' << color::green;
for(std::string::const_iterator i = q.str.begin(); i != q.str.end(); ++i) {
unsigned char c = (unsigned char)*i;
boost::uint8_t c = boost::uint8_t(*i);
if(c < ' ' && c != '\t' && c != '\r' && c != '\n') {
std::ios_base::fmtflags old = os.flags();
os << color::red << '<' << std::hex << std::setfill('0') << std::setw(2)

2
src/util/storedenum.hpp

@ -219,7 +219,7 @@ private:
public:
explicit stored_flag_reader(std::istream & _is, size_t pad_bits = 32)
: pad_bits(pad_bits), is(_is), pos(0), result(0), bytes(0) { }
: pad_bits(pad_bits), is(_is), pos(0), buffer(0), result(0), bytes(0) { }
//! Declare the next possible flag.
void add(enum_type flag) {

10
src/util/time.cpp

@ -258,7 +258,7 @@ extern "C" typedef int (*utimensat_proc)
(int fd, const char *path, const struct timespec times[2], int flag);
#endif
bool set_file_time(const boost::filesystem::path & path, time t, boost::uint32_t nsec) {
bool set_file_time(const boost::filesystem::path & path, time sec, boost::uint32_t nsec) {
#if (INNOEXTRACT_HAVE_DYNAMIC_UTIMENSAT || INNOEXTRACT_HAVE_UTIMENSAT) \
&& INNOEXTRACT_HAVE_AT_FDCWD
@ -266,7 +266,7 @@ bool set_file_time(const boost::filesystem::path & path, time t, boost::uint32_t
// nanosecond precision, for Linux and POSIX.1-2008+ systems
struct timespec timens[2];
timens[0].tv_sec = to_time_t<time_t>(t, path.string().c_str());
timens[0].tv_sec = to_time_t<time_t>(sec, path.string().c_str());
timens[0].tv_nsec = boost::int32_t(nsec);
timens[1] = timens[0];
@ -298,7 +298,7 @@ bool set_file_time(const boost::filesystem::path & path, time t, boost::uint32_t
return false;
}
FILETIME filetime = to_filetime(t, nsec);
FILETIME filetime = to_filetime(sec, nsec);
bool ret = (SetFileTime(handle, &filetime, &filetime, &filetime) != 0);
CloseHandle(handle);
@ -310,7 +310,7 @@ bool set_file_time(const boost::filesystem::path & path, time t, boost::uint32_t
// microsecond precision, for older POSIX systems (4.3BSD, POSIX.1-2001)
struct timeval times[2];
times[0].tv_sec = to_time_t<time_t>(t, path.string().c_str());
times[0].tv_sec = to_time_t<time_t>(sec, path.string().c_str());
times[0].tv_usec = boost::int32_t(nsec / 1000);
times[1] = times[0];
@ -322,7 +322,7 @@ bool set_file_time(const boost::filesystem::path & path, time t, boost::uint32_t
try {
(void)nsec; // sub-second precision not supported by Boost
std::time_t tt = to_time_t<std::time_t>(t, path.string().c_str());
std::time_t tt = to_time_t<std::time_t>(sec, path.string().c_str());
boost::filesystem::last_write_time(path, tt);
return true;
} catch(...) {

Loading…
Cancel
Save