Skip to content

Commit

Permalink
First changes of librarization of the ancient: namespacing and api-he…
Browse files Browse the repository at this point in the history
…aders
  • Loading branch information
temisu committed May 7, 2021
1 parent db332a6 commit 85de2c8
Show file tree
Hide file tree
Showing 147 changed files with 855 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
VPATH := src src/Lzh src/Zip src/common fuzzing

CXX ?= c++
COMMONFLAGS = -Os -Wall -Wsign-compare -Wnarrowing -Wno-error=multichar -Wno-multichar -Isrc
COMMONFLAGS = -Os -Wall -Wsign-compare -Wnarrowing -Wno-error=multichar -Wno-multichar -Isrc -Iapi
CFLAGS = $(COMMONFLAGS)
CXXFLAGS = $(COMMONFLAGS) -std=c++17 -fno-rtti

Expand Down
5 changes: 5 additions & 0 deletions src/common/Buffer.hpp → api/Buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

#include <exception>

namespace ancient
{

class Buffer
{
protected:
Expand Down Expand Up @@ -71,4 +74,6 @@ class Buffer
uint8_t read8(size_t offset) const;
};

}

#endif
11 changes: 7 additions & 4 deletions src/Decompressor.hpp → api/Decompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@

#include <string>
#include <memory>
#include <vector>

#include "common/Common.hpp"
#include "common/Buffer.hpp"
#include "Buffer.hpp"

namespace ancient
{

class Decompressor
{
Expand Down Expand Up @@ -88,7 +91,7 @@ class Decompressor
// This does not guarantee the data is decompressable though, only signature is read
static bool detect(const Buffer &packedData) noexcept;

// Registering new decompressors, not really part of public API
protected:
template<class T>
class Registry
{
Expand All @@ -104,7 +107,6 @@ class Decompressor
}
};

protected:
virtual void decompressImpl(Buffer &rawData,bool verify)=0;

private:
Expand All @@ -113,5 +115,6 @@ class Decompressor
static std::vector<std::pair<bool(*)(uint32_t),std::unique_ptr<Decompressor>(*)(const Buffer&,bool,bool)>> *_decompressors;
};

}

#endif
2 changes: 2 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "common/StaticBuffer.hpp"
#include "Decompressor.hpp"

using namespace ancient;

std::unique_ptr<Buffer> readFile(const std::string &fileName)
{

Expand Down
7 changes: 7 additions & 0 deletions src/ACCADecompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#include "ACCADecompressor.hpp"
#include "InputStream.hpp"
#include "OutputStream.hpp"
#include "common/Common.hpp"


namespace ancient
{

bool ACCADecompressor::detectHeaderXPK(uint32_t hdr) noexcept
{
Expand Down Expand Up @@ -105,3 +110,5 @@ void ACCADecompressor::decompressImpl(Buffer &rawData,const Buffer &previousData
}

XPKDecompressor::Registry<ACCADecompressor> ACCADecompressor::_XPKregistration;

}
5 changes: 5 additions & 0 deletions src/ACCADecompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#include "XPKDecompressor.hpp"

namespace ancient
{

class ACCADecompressor : public XPKDecompressor
{
public:
Expand All @@ -25,4 +28,6 @@ class ACCADecompressor : public XPKDecompressor
static XPKDecompressor::Registry<ACCADecompressor> _XPKregistration;
};

}

#endif
7 changes: 7 additions & 0 deletions src/ARTMDecompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#include "RangeDecoder.hpp"
#include "InputStream.hpp"
#include "OutputStream.hpp"
#include "common/Common.hpp"


namespace ancient
{

bool ARTMDecompressor::detectHeaderXPK(uint32_t hdr) noexcept
{
Expand Down Expand Up @@ -115,3 +120,5 @@ void ARTMDecompressor::decompressImpl(Buffer &rawData,const Buffer &previousData
}

XPKDecompressor::Registry<ARTMDecompressor> ARTMDecompressor::_XPKregistration;

}
5 changes: 5 additions & 0 deletions src/ARTMDecompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#include "XPKDecompressor.hpp"

namespace ancient
{

class ARTMDecompressor : public XPKDecompressor
{
public:
Expand All @@ -25,4 +28,6 @@ class ARTMDecompressor : public XPKDecompressor
static XPKDecompressor::Registry<ARTMDecompressor> _XPKregistration;
};

}

#endif
7 changes: 7 additions & 0 deletions src/BLZWDecompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#include "BLZWDecompressor.hpp"
#include "InputStream.hpp"
#include "OutputStream.hpp"
#include "common/Common.hpp"


namespace ancient
{

bool BLZWDecompressor::detectHeaderXPK(uint32_t hdr)
{
Expand Down Expand Up @@ -120,3 +125,5 @@ void BLZWDecompressor::decompressImpl(Buffer &rawData,const Buffer &previousData
}

XPKDecompressor::Registry<BLZWDecompressor> BLZWDecompressor::_XPKregistration;

}
5 changes: 5 additions & 0 deletions src/BLZWDecompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#include "XPKDecompressor.hpp"

namespace ancient
{

class BLZWDecompressor : public XPKDecompressor
{
public:
Expand All @@ -28,4 +31,6 @@ class BLZWDecompressor : public XPKDecompressor
static XPKDecompressor::Registry<BLZWDecompressor> _XPKregistration;
};

}

#endif
7 changes: 7 additions & 0 deletions src/BZIP2Decompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include "OutputStream.hpp"
#include "common/MemoryBuffer.hpp"
#include "common/CRC32.hpp"
#include "common/Common.hpp"


namespace ancient
{

bool BZIP2Decompressor::detectHeader(uint32_t hdr) noexcept
{
Expand Down Expand Up @@ -393,3 +398,5 @@ void BZIP2Decompressor::decompressImpl(Buffer &rawData,const Buffer &previousDat

Decompressor::Registry<BZIP2Decompressor> BZIP2Decompressor::_registration;
XPKDecompressor::Registry<BZIP2Decompressor> BZIP2Decompressor::_XPKregistration;

}
5 changes: 5 additions & 0 deletions src/BZIP2Decompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include "Decompressor.hpp"
#include "XPKDecompressor.hpp"

namespace ancient
{

class BZIP2Decompressor : public Decompressor, public XPKDecompressor
{
public:
Expand Down Expand Up @@ -39,4 +42,6 @@ class BZIP2Decompressor : public Decompressor, public XPKDecompressor
static XPKDecompressor::Registry<BZIP2Decompressor> _XPKregistration;
};

}

#endif
7 changes: 7 additions & 0 deletions src/CBR0Decompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#include "CBR0Decompressor.hpp"
#include "InputStream.hpp"
#include "OutputStream.hpp"
#include "common/Common.hpp"


namespace ancient
{

bool CBR0Decompressor::detectHeaderXPK(uint32_t hdr) noexcept
{
Expand Down Expand Up @@ -57,3 +62,5 @@ void CBR0Decompressor::decompressImpl(Buffer &rawData,const Buffer &previousData
}

XPKDecompressor::Registry<CBR0Decompressor> CBR0Decompressor::_XPKregistration;

}
5 changes: 5 additions & 0 deletions src/CBR0Decompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#include "XPKDecompressor.hpp"

namespace ancient
{

class CBR0Decompressor : public XPKDecompressor
{
public:
Expand All @@ -26,4 +29,6 @@ class CBR0Decompressor : public XPKDecompressor
static XPKDecompressor::Registry<CBR0Decompressor> _XPKregistration;
};

}

#endif
7 changes: 7 additions & 0 deletions src/CRMDecompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#include "InputStream.hpp"
#include "OutputStream.hpp"
#include "common/OverflowCheck.hpp"
#include "common/Common.hpp"


namespace ancient
{

bool CRMDecompressor::detectHeader(uint32_t hdr) noexcept
{
Expand Down Expand Up @@ -239,3 +244,5 @@ void CRMDecompressor::decompressImpl(Buffer &rawData,const Buffer &previousData,

Decompressor::Registry<CRMDecompressor> CRMDecompressor::_registration;
XPKDecompressor::Registry<CRMDecompressor> CRMDecompressor::_XPKregistration;

}
5 changes: 5 additions & 0 deletions src/CRMDecompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include "Decompressor.hpp"
#include "XPKDecompressor.hpp"

namespace ancient
{

class CRMDecompressor : public Decompressor, public XPKDecompressor
{
public:
Expand Down Expand Up @@ -41,4 +44,6 @@ class CRMDecompressor : public Decompressor, public XPKDecompressor
static XPKDecompressor::Registry<CRMDecompressor> _XPKregistration;
};

}

#endif
7 changes: 7 additions & 0 deletions src/CYB2Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#include "common/SubBuffer.hpp"
#include "CYB2Decoder.hpp"
#include "XPKMain.hpp"
#include "common/Common.hpp"


namespace ancient
{

bool CYB2Decoder::detectHeaderXPK(uint32_t hdr) noexcept
{
Expand Down Expand Up @@ -55,3 +60,5 @@ void CYB2Decoder::decompressImpl(Buffer &rawData,const Buffer &previousData,bool
}

XPKDecompressor::Registry<CYB2Decoder> CYB2Decoder::_XPKregistration;

}
5 changes: 5 additions & 0 deletions src/CYB2Decoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#include "XPKDecompressor.hpp"

namespace ancient
{

class CYB2Decoder : public XPKDecompressor
{
public:
Expand All @@ -27,4 +30,6 @@ class CYB2Decoder : public XPKDecompressor
static XPKDecompressor::Registry<CYB2Decoder> _XPKregistration;
};

}

#endif
7 changes: 7 additions & 0 deletions src/DEFLATEDecompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include "OutputStream.hpp"
#include "common/CRC32.hpp"
#include "common/OverflowCheck.hpp"
#include "common/Common.hpp"


namespace ancient
{

static uint32_t Adler32(const Buffer &buffer,size_t offset,size_t len)
{
Expand Down Expand Up @@ -380,3 +385,5 @@ void DEFLATEDecompressor::decompressImpl(Buffer &rawData,const Buffer &previousD

Decompressor::Registry<DEFLATEDecompressor> DEFLATEDecompressor::_registration;
XPKDecompressor::Registry<DEFLATEDecompressor> DEFLATEDecompressor::_XPKregistration;

}
5 changes: 5 additions & 0 deletions src/DEFLATEDecompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include "Decompressor.hpp"
#include "XPKDecompressor.hpp"

namespace ancient
{

class DEFLATEDecompressor : public Decompressor, public XPKDecompressor
{
public:
Expand Down Expand Up @@ -52,4 +55,6 @@ class DEFLATEDecompressor : public Decompressor, public XPKDecompressor
static XPKDecompressor::Registry<DEFLATEDecompressor> _XPKregistration;
};

}

#endif
6 changes: 6 additions & 0 deletions src/DLTADecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
#include "DLTADecode.hpp"

#include "common/OverflowCheck.hpp"
#include "common/Common.hpp"


namespace ancient
{

bool DLTADecode::detectHeaderXPK(uint32_t hdr) noexcept
{
return hdr==FourCC("DLTA");
Expand Down Expand Up @@ -56,3 +60,5 @@ void DLTADecode::decompressImpl(Buffer &rawData,const Buffer &previousData,bool
}

XPKDecompressor::Registry<DLTADecode> DLTADecode::_XPKregistration;

}
6 changes: 6 additions & 0 deletions src/DLTADecode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

#include "XPKDecompressor.hpp"

namespace ancient
{


class DLTADecode : public XPKDecompressor
{
public:
Expand All @@ -28,4 +32,6 @@ class DLTADecode : public XPKDecompressor
static XPKDecompressor::Registry<DLTADecode> _XPKregistration;
};

}

#endif
Loading

0 comments on commit 85de2c8

Please sign in to comment.