00001 /* Copyright 2009 Andreas Gölzer 00002 00003 This file is part of readESM. 00004 00005 readESM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 00006 00007 readESM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 00008 00009 You should have received a copy of the GNU General Public License along with readESM. If not, see <http://www.gnu.org/licenses/>. */ 00010 #ifndef VUBLOCK_H 00011 #define VUBLOCK_H 00012 #include <string> 00013 #include "time.h" 00014 #include "crypto.h" 00015 #include "block.h" 00016 #include "readTypes.h" 00017 00018 00019 class vublock : public block { 00020 public: 00021 virtual string name() const = 0; 00022 vublock(iter nstart) : block(nstart), block_start(&nstart[2]), runningIndex(0) { 00023 hassignature = true; 00024 } 00025 virtual void Init(){ signature = start + size() - 128; } 00026 int getBEInt32(const unsigned char* start) const{ 00027 return (start[0] << 24) + (start[1] << 16) + (start[2] << 8) + start[3]; 00028 } 00029 Time readDate(const unsigned char* in) const{ 00030 return Time::fromBigEndianChars32(in); 00031 } 00032 00033 Time readDate(int start) const{ 00034 return readDate(&block_start[start]); 00035 } 00036 Time readDate() const{ 00037 runningIndex += 4; 00038 return readDate(runningIndex - 4); 00039 } 00040 string fixedString(int length) const{ 00041 runningIndex += length; 00042 return ::fixedString(start + 2 + runningIndex - length, length); 00043 } 00044 int IntByte(int start) const{ 00045 return int(block_start[start]); 00046 } 00047 int IntByte() const{ 00048 runningIndex += 1; 00049 return IntByte(runningIndex - 1); 00050 } 00051 int Int16(int start) const{ 00052 return (block_start[start] << 8)+ block_start[start+1]; 00053 } 00054 int Int16() const{ 00055 runningIndex += 2; 00056 return Int16(runningIndex - 2); 00057 } 00058 00059 int Odometer(int start) const{ 00060 return (block_start[start] << 16) + (block_start[start + 1] << 8) + block_start[start + 2]; 00061 } 00062 int Odometer() const{ 00063 runningIndex += 3; 00064 return Odometer(runningIndex - 3); 00065 } 00066 00067 string fixedString(int start, int length) const{ 00068 ostringstream o; 00069 //for(int j = start; j < start + length; ++j) if(block_start[j] >= 0x20 && block_start[j] < 127) 00070 //o << block_start[j]; 00071 for(int j = start; j < start + length; ++j) if(block_start[j] >= 0x20) o << block_start[j]; 00072 //files seem to be latin-1, watch out 00073 return o.str(); 00074 } 00075 const unsigned char* block_start; 00076 mutable int runningIndex; 00077 virtual int size() const = 0; 00078 virtual void CompleteReport(reporter& report) const = 0; 00079 virtual void BriefReport(reporter& report) const = 0; 00080 virtual void printOn(reporter& report) const{ 00081 if(report.verbose) CompleteReport(report); 00082 else BriefReport(report); 00083 } 00084 virtual bool checksig(const rsa& key){; 00085 validsignature = CheckSignature(start + 2 + nonhashedbytes(), size() - 128 - 2 - nonhashedbytes(), signature, 128, key); 00086 return validsignature; 00087 } 00088 virtual int nonhashedbytes() const{ return 0;} 00089 }; 00090 00091 #endif