mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
SU3 file parser
This commit is contained in:
parent
f9ec60265a
commit
af2a5b93f2
@ -34,6 +34,14 @@ uint16_t be16toh(uint16_t big16);
|
|||||||
uint32_t be32toh(uint32_t big32);
|
uint32_t be32toh(uint32_t big32);
|
||||||
uint64_t be64toh(uint64_t big64);
|
uint64_t be64toh(uint64_t big64);
|
||||||
|
|
||||||
|
// assume LittleEndine
|
||||||
|
#define htole16
|
||||||
|
#define htole32
|
||||||
|
#define htole64
|
||||||
|
#define le16toh
|
||||||
|
#define le32toh
|
||||||
|
#define le64toh
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // I2PENDIAN_H__
|
#endif // I2PENDIAN_H__
|
||||||
|
54
Reseed.cpp
54
Reseed.cpp
@ -2,6 +2,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <boost/regex.hpp>
|
#include <boost/regex.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <cryptopp/gzip.h>
|
||||||
#include "Reseed.h"
|
#include "Reseed.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@ -119,6 +120,59 @@ namespace data
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProcessSU3File (const char * filename)
|
||||||
|
{
|
||||||
|
static uint32_t headerSignature = htole32 (0x04044B50);
|
||||||
|
|
||||||
|
std::ifstream s(filename, std::ifstream::binary);
|
||||||
|
if (s.is_open ())
|
||||||
|
{
|
||||||
|
while (!s.eof ())
|
||||||
|
{
|
||||||
|
uint32_t signature;
|
||||||
|
s.read ((char *)&signature, 4);
|
||||||
|
if (signature == headerSignature)
|
||||||
|
{
|
||||||
|
// next local file
|
||||||
|
s.seekg (14, std::ios::cur); // skip field we don't care about
|
||||||
|
uint32_t compressedSize, uncompressedSize;
|
||||||
|
s.read ((char *)&compressedSize, 4);
|
||||||
|
compressedSize = le32toh (compressedSize);
|
||||||
|
s.read ((char *)&uncompressedSize, 4);
|
||||||
|
uncompressedSize = le32toh (uncompressedSize);
|
||||||
|
uint16_t fileNameLength, extraFieldLength;
|
||||||
|
s.read ((char *)&fileNameLength, 2);
|
||||||
|
fileNameLength = le32toh (fileNameLength);
|
||||||
|
s.read ((char *)&extraFieldLength, 2);
|
||||||
|
extraFieldLength = le32toh (extraFieldLength);
|
||||||
|
char localFileName[255];
|
||||||
|
s.read (localFileName, fileNameLength);
|
||||||
|
localFileName[fileNameLength] = 0;
|
||||||
|
s.seekg (extraFieldLength, std::ios::cur);
|
||||||
|
|
||||||
|
uint8_t * compressed = new uint8_t[compressedSize];
|
||||||
|
s.read ((char *)compressed, compressedSize);
|
||||||
|
CryptoPP::Gunzip decompressor;
|
||||||
|
decompressor.Put (compressed, compressedSize);
|
||||||
|
delete[] compressed;
|
||||||
|
if (decompressor.MaxRetrievable () <= uncompressedSize)
|
||||||
|
{
|
||||||
|
uint8_t * uncompressed = new uint8_t[uncompressedSize];
|
||||||
|
decompressor.Get (uncompressed, decompressor.MaxRetrievable ());
|
||||||
|
// TODO: save file
|
||||||
|
delete[] uncompressed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "Actual uncompressed size ", decompressor.MaxRetrievable (), " exceed ", uncompressedSize, " from header");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break; // no more files
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "Can't open file ", filename);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user