summaryrefslogtreecommitdiffstats
path: root/lzip.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lzip.h61
1 files changed, 45 insertions, 16 deletions
diff --git a/lzip.h b/lzip.h
index 985417a..ed57aa2 100644
--- a/lzip.h
+++ b/lzip.h
@@ -1,5 +1,5 @@
/* Lziprecover - Data recovery tool for the lzip format
- Copyright (C) 2009-2016 Antonio Diaz Diaz.
+ Copyright (C) 2009-2017 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
@@ -30,8 +30,11 @@ public:
static const int next[states] = { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 };
st = next[st];
}
- void set_char1() { st -= ( st < 4 ) ? st : 3; } // for st < 7
- void set_char2() { st -= ( st < 10 ) ? 3 : 6; } // for st >= 7
+ bool is_char_set_char()
+ {
+ if( st < 7 ) { st -= ( st < 4 ) ? st : 3; return true; }
+ else { st -= ( st < 10 ) ? 3 : 6; return false; }
+ }
void set_match() { st = ( st < 7 ) ? 7 : 10; }
void set_rep() { st = ( st < 7 ) ? 8 : 11; }
void set_short_rep() { st = ( st < 7 ) ? 9 : 11; }
@@ -168,8 +171,10 @@ public:
void update_buf( uint32_t & crc, const uint8_t * const buffer,
const int size ) const
{
+ uint32_t c = crc;
for( int i = 0; i < size; ++i )
- crc = data[(crc^buffer[i])&0xFF] ^ ( crc >> 8 );
+ c = data[(c^buffer[i])&0xFF] ^ ( c >> 8 );
+ crc = c;
}
};
@@ -227,7 +232,7 @@ struct File_header
{
const unsigned base_size = 1 << data[5];
const unsigned fraction = base_size / 16;
- for( int i = 7; i >= 1; --i )
+ for( unsigned i = 7; i >= 1; --i )
if( base_size - ( i * fraction ) >= sz )
{ data[5] |= ( i << 5 ); break; }
}
@@ -276,6 +281,23 @@ struct File_trailer
};
+struct Bad_byte
+ {
+ enum Mode { literal, delta, flip };
+ long long pos;
+ Mode mode;
+ uint8_t value;
+
+ Bad_byte() : pos( -1 ), mode( literal ), value( 0 ) {}
+ uint8_t operator()( const uint8_t old_value ) const
+ {
+ if( mode == delta ) return old_value + value;
+ if( mode == flip ) return old_value ^ value;
+ return value;
+ }
+ };
+
+
struct Error
{
const char * const msg;
@@ -288,6 +310,10 @@ inline unsigned long long positive_diff( const unsigned long long x,
{ return ( ( x > y ) ? x - y : 0 ); }
+const char * const bad_magic_msg = "Bad magic number (file not in lzip format).";
+const char * const bad_dict_msg = "Invalid dictionary size in member header.";
+const char * const trailing_msg = "Trailing data not allowed.";
+
// defined in alone_to_lz.cc
int alone_to_lz( const int infd, const Pretty_print & pp );
@@ -299,10 +325,17 @@ long writeblock( const int fd, const uint8_t * const buf, const long size );
int seek_read( const int fd, uint8_t * const buf, const int size,
const long long pos );
+// defined in list.cc
+int list_files( const std::vector< std::string > & filenames,
+ const int verbosity, const bool ignore_trailing );
+
// defined in main.cc
extern std::string output_filename; // global vars for output file
extern int outfd;
-
+struct stat;
+const char * bad_version( const unsigned version );
+const char * format_ds( const unsigned dictionary_size );
+void show_header( const unsigned dictionary_size, const int vlevel = 3 );
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,
@@ -311,9 +344,10 @@ bool file_exists( const std::string & filename );
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 show_file_error( const char * const filename, const char * const msg,
+ const int errcode = 0 );
void internal_error( const char * const msg );
void show_error2( const char * const msg1, const char * const name,
const char * const msg2 );
@@ -330,22 +364,17 @@ int merge_files( const std::vector< std::string > & filenames,
const int verbosity, const bool force );
// defined in range_dec.cc
-const char * format_num( unsigned long long num,
- unsigned long long limit = -1ULL,
- const int set_prefix = 0 );
bool safe_seek( const int fd, const long long pos );
-int list_files( const std::vector< std::string > & filenames,
- const int verbosity );
// defined in repair.cc
int repair_file( const std::string & input_filename,
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_repair( const std::string & input_filename,
+ const Bad_byte & bad_byte, const int verbosity );
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 );
+ const Bad_byte & bad_byte, const int verbosity,
+ const bool show_packets );
// defined in split.cc
bool verify_header( const File_header & header, const Pretty_print & pp );