summaryrefslogtreecommitdiffstats
path: root/lzip.h
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2016-05-20 06:54:36 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2016-05-20 06:54:36 +0000
commite6759ba4e68c66f0927bb89bfb87215eb29016ae (patch)
treef35bf07aaaf1ad2d1bfc0eced16ff820f1193cd5 /lzip.h
parentAdding upstream version 1.18~pre2. (diff)
downloadlziprecover-e6759ba4e68c66f0927bb89bfb87215eb29016ae.tar.xz
lziprecover-e6759ba4e68c66f0927bb89bfb87215eb29016ae.zip
Adding upstream version 1.18.upstream/1.18
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'lzip.h')
-rw-r--r--lzip.h71
1 files changed, 45 insertions, 26 deletions
diff --git a/lzip.h b/lzip.h
index 3bdc27c..985417a 100644
--- a/lzip.h
+++ b/lzip.h
@@ -1,5 +1,5 @@
/* Lziprecover - Data recovery tool for the lzip format
- Copyright (C) 2009-2015 Antonio Diaz Diaz.
+ Copyright (C) 2009-2016 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -45,6 +45,7 @@ enum {
max_dictionary_size = 1 << max_dictionary_bits,
min_member_size = 36,
literal_context_bits = 3,
+ literal_pos_state_bits = 0, // not used
pos_state_bits = 2,
pos_states = 1 << pos_state_bits,
pos_state_mask = pos_states - 1,
@@ -175,6 +176,11 @@ public:
extern const CRC32 crc32;
+inline bool isvalid_ds( const unsigned dictionary_size )
+ { return ( dictionary_size >= min_dictionary_size &&
+ dictionary_size <= max_dictionary_size ); }
+
+
inline int real_bits( unsigned value )
{
int bits = 0;
@@ -195,6 +201,12 @@ struct File_header
void set_magic() { std::memcpy( data, magic_string, 4 ); data[4] = 1; }
bool verify_magic() const
{ return ( std::memcmp( data, magic_string, 4 ) == 0 ); }
+ bool verify_prefix( const int size ) const // detect truncated header
+ {
+ for( int i = 0; i < size && i < 4; ++i )
+ if( data[i] != magic_string[i] ) return false;
+ return ( size > 0 );
+ }
uint8_t version() const { return data[4]; }
bool verify_version() const { return ( data[4] == 1 ); }
@@ -209,20 +221,17 @@ struct File_header
bool dictionary_size( const unsigned sz )
{
- if( sz >= min_dictionary_size && sz <= max_dictionary_size )
+ if( !isvalid_ds( sz ) ) return false;
+ data[5] = real_bits( sz - 1 );
+ if( sz > min_dictionary_size )
{
- data[5] = real_bits( sz - 1 );
- if( sz > min_dictionary_size )
- {
- const unsigned base_size = 1 << data[5];
- const unsigned fraction = base_size / 16;
- for( int i = 7; i >= 1; --i )
- if( base_size - ( i * fraction ) >= sz )
- { data[5] |= ( i << 5 ); break; }
- }
- return true;
+ const unsigned base_size = 1 << data[5];
+ const unsigned fraction = base_size / 16;
+ for( int i = 7; i >= 1; --i )
+ if( base_size - ( i * fraction ) >= sz )
+ { data[5] |= ( i << 5 ); break; }
}
- return false;
+ return true;
}
};
@@ -279,36 +288,46 @@ inline unsigned long long positive_diff( const unsigned long long x,
{ return ( ( x > y ) ? x - y : 0 ); }
+// defined in alone_to_lz.cc
+int alone_to_lz( const int infd, const Pretty_print & pp );
+
// defined in decoder.cc
long readblock( const int fd, uint8_t * const buf, const long size );
-int writeblock( const int fd, const uint8_t * const buf, const int size );
+long writeblock( const int fd, const uint8_t * const buf, const long size );
// defined in file_index.cc
int seek_read( const int fd, uint8_t * const buf, const int size,
const long long pos );
// defined in main.cc
+extern std::string output_filename; // global vars for output file
+extern int outfd;
+
int open_instream( const char * const name, struct stat * const in_statsp,
const bool no_ofile, const bool reg_only = false );
+bool open_outstream( const bool force, const bool from_stdin,
+ const bool rw = false, const bool skipping = true );
bool file_exists( const std::string & filename );
-int open_outstream_rw( const std::string & output_filename, const bool force );
+void cleanup_and_fail( const int retval );
+int close_outstream( const struct stat * const in_statsp );
+std::string insert_fixed( std::string name );
void show_header( const unsigned dictionary_size, const int vlevel = 3 );
void show_error( const char * const msg, const int errcode = 0,
const bool help = false );
void internal_error( const char * const msg );
void show_error2( const char * const msg1, const char * const name,
const char * const msg2 );
+void show_error4( const char * const msg1, const char * const name1,
+ const char * const name2, const char * const msg2 );
// defined in merge.cc
-void cleanup_and_fail( const std::string & output_filename,
- const int outfd, const int retval );
bool copy_file( const int infd, const int outfd,
const long long max_size = -1 );
-bool try_decompress_member( const int fd, const unsigned long long msize,
- long long * failure_posp = 0 );
+bool test_member_from_file( const int infd, const unsigned long long msize,
+ long long * const failure_posp = 0 );
int merge_files( const std::vector< std::string > & filenames,
- const std::string & output_filename, const int verbosity,
- const bool force );
+ const std::string & default_output_filename,
+ const int verbosity, const bool force );
// defined in range_dec.cc
const char * format_num( unsigned long long num,
@@ -320,13 +339,13 @@ int list_files( const std::vector< std::string > & filenames,
// defined in repair.cc
int repair_file( const std::string & input_filename,
- const std::string & output_filename, const int verbosity,
- const bool force );
+ const std::string & default_output_filename,
+ const int verbosity, const bool force );
int debug_repair( const std::string & input_filename, const long long bad_pos,
const int verbosity, const uint8_t bad_value );
-int debug_show_packets( const std::string & input_filename,
- const long long bad_pos, const int verbosity,
- const uint8_t bad_value );
+int debug_decompress( const std::string & input_filename,
+ const long long bad_pos, const int verbosity,
+ const uint8_t bad_value, const bool show_packets );
// defined in split.cc
bool verify_header( const File_header & header, const Pretty_print & pp );