Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
PROJECT(aff4-cpp-lite)

CMAKE_MINIMUM_REQUIRED(VERSION 3.0)

FIND_PACKAGE(Raptor2 REQUIRED)

FIND_PACKAGE(Snappy REQUIRED)

FIND_PACKAGE(ZLIB REQUIRED)

FIND_PACKAGE(OpenSSL REQUIRED)

FIND_PACKAGE(LZ4 REQUIRED)

add_definitions(-DUNICODE -DLIBAFF4_EXPORTS=0 -DRAPTOR_STATIC)

SET(SOURCES
win32/libaff4/aff4config.h
win32/libaff4/src/stdafx.h

src/aff4.cc
src/aff4-c.cc
src/AFF4Lexicon.cc
src/RDFValue.cc
src/AFF4Containers.cc

src/utils/StringUtil.cc src/utils/StringUtil.h
src/utils/FileUtil.h
src/utils/Cache.h
src/utils/PortableEndian.h
src/rdf/Model.cc src/rdf/Model.h
src/resource/AFF4Resource.cc src/resource/AFF4Resource.h
src/zip/Zip.cc src/zip/Zip.h
src/zip/ZipStream.cc src/zip/ZipStream.h
src/container/AFF4ZipContainer.cc src/container/AFF4ZipContainer.h
src/image/AFF4Image.cc src/image/AFF4Image.h
src/stream/ImageStreamFactory.cc src/stream/ImageStreamFactory.h
src/stream/RepeatedImageStream.cc src/stream/RepeatedImageStream.h
src/stream/SymbolicImageStream.cc src/stream/SymbolicImageStream.h
src/stream/ImageStream.cc src/stream/ImageStream.h
src/stream/MapStream.cc src/stream/MapStream.h
src/stream/struct/BevvyIndex.cc src/stream/struct/BevvyIndex.h
src/stream/struct/BevvyIndexLoader.cc src/stream/struct/BevvyIndexLoader.h
src/stream/struct/ChunkLoader.cc src/stream/struct/ChunkLoader.h
src/stream/struct/ImageStreamPoint.h
src/stream/struct/MapEntryPoint.h
src/map/AFF4Map.cc src/map/AFF4Map.h
src/codec/CompressionCodec.cc src/codec/CompressionCodec.h
src/codec/NullCompression.cc src/codec/NullCompression.h
src/codec/DeflateCompression.cc src/codec/DeflateCompression.h
src/codec/ZlibCompression.cc src/codec/ZlibCompression.h
src/codec/LZ4Compression.cc src/codec/LZ4Compression.h
src/codec/SnappyCompression.cc src/codec/SnappyCompression.h
src/resolver/LightResolver.cc src/resolver/LightResolver.h
)

ADD_LIBRARY(aff4-cpp-lite ${SOURCES})

target_include_directories(aff4-cpp-lite PUBLIC
win32/libaff4/src
win32/libaff4

src
src/codec
src/container
src/image
src/map
src/rdf
src/resolver
src/resource
src/stream
src/stream/struct
src/utils
src/zip
)

TARGET_LINK_LIBRARIES(aff4-cpp-lite PRIVATE Raptor2)
TARGET_LINK_LIBRARIES(aff4-cpp-lite PRIVATE Snappy)
TARGET_LINK_LIBRARIES(aff4-cpp-lite PRIVATE OpenSSL)
TARGET_LINK_LIBRARIES(aff4-cpp-lite PRIVATE ZLIB)
TARGET_LINK_LIBRARIES(aff4-cpp-lite PRIVATE LZ4::LZ4)

FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/libaff4.pc
"prefix=${CMAKE_INSTALL_PREFIX}
exec_prefix=\${prefix}
libdir=\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}
includedir=\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}

Name: aff4-cpp-lite library
Description: aff4-cpp-lite library
Version: ${VERSION}
Libs: -L\${libdir} -libaff4
Cflags: -I\${includedir}
")

SET(INSTALL_HEADERS
${CMAKE_CURRENT_BINARY_DIR}/src/aff4.h
${CMAKE_CURRENT_BINARY_DIR}/src/aff4-c.h
${CMAKE_CURRENT_BINARY_DIR}/src/AFF4Containers.h
${CMAKE_CURRENT_BINARY_DIR}/src/AFF4Defaults.h
${CMAKE_CURRENT_BINARY_DIR}/src/AFF4Lexicon.h
${CMAKE_CURRENT_BINARY_DIR}/src/IAFF4Container.h
${CMAKE_CURRENT_BINARY_DIR}/src/IAFF4Image.h
${CMAKE_CURRENT_BINARY_DIR}/src/IAFF4Map.h
${CMAKE_CURRENT_BINARY_DIR}/src/IAFF4Resolver.h
${CMAKE_CURRENT_BINARY_DIR}/src/IAFF4Resource.h
${CMAKE_CURRENT_BINARY_DIR}/src/IAFF4Stream.h
${CMAKE_CURRENT_BINARY_DIR}/src/RDFValue.h
)

if (WIN32)
SET(INSTALL_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/win32/libaff4/src/stdafx.h
${CMAKE_CURRENT_SOURCE_DIR}/win32/libaff4/src/targetver.h
${INSTALL_HEADERS}
)
endif()

INSTALL(FILES
${INSTALL_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

INSTALL(
TARGETS aff4-cpp-lite
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
32 changes: 16 additions & 16 deletions src/AFF4Containers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ namespace aff4 {
* @throws std::system_error If opening the file failed.
*/
std::shared_ptr<IAFF4Container> openContainer(const std::string& filename) noexcept {
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : %s \n", __FILE__, __LINE__, filename.c_str());
#endif
/*
* Does it exist and is a file?
*/
if (!aff4::util::isFile(filename)) {
// failed.
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : %s is NOT a file.\n", __FILE__, __LINE__, filename.c_str());
#endif
return nullptr;
Expand All @@ -67,7 +67,7 @@ namespace aff4 {
*/
if (!isAFF4Container(filename)) {
// failed.
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : %s does not have .af4 or .aff4 extension\n", __FILE__, __LINE__, filename.c_str());
#endif
return nullptr;
Expand All @@ -76,7 +76,7 @@ namespace aff4 {
std::string resource = getResourceID(filename);
if (resource.empty()) {
// No resource?
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : %s does not have a resource ID\n", __FILE__, __LINE__, filename.c_str());
#endif
return nullptr;
Expand All @@ -90,7 +90,7 @@ namespace aff4 {
* failed, actually, we should never see this, unless the file has been removed between the last
* getResourceID() call and reopening it here.
*/
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : %s has NO entries?\n", __FILE__, __LINE__, filename.c_str());
#endif
return nullptr;
Expand Down Expand Up @@ -129,15 +129,15 @@ namespace aff4 {
int fileHandle = ::open(filename.c_str(), O_RDONLY | O_LARGEFILE);
if (fileHandle == -1) {
// we failed, so return nothing. (error will be in errno).
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : Unable to open container : %s \n", __FILE__, __LINE__, filename.c_str());
#endif
return "";
}
int read = ::pread64(fileHandle, buffer.get(), AFF4_RESOURCE_BUFFER_SIZE, 0);
::close(fileHandle);
if (read != AFF4_RESOURCE_BUFFER_SIZE) {
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : Unable to read %d bytes from the container : %s = %d \n", __FILE__, __LINE__, AFF4_RESOURCE_BUFFER_SIZE, filename.c_str(), read);
#endif
return "";
Expand All @@ -150,7 +150,7 @@ namespace aff4 {
std::wstring wpath = aff4::util::s2ws(filename); // Convert the filename to UTF-16/WString for Win32 API
HANDLE fileHandle = CreateFile(wpath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);
if (fileHandle == INVALID_HANDLE_VALUE) {
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : Unable to open container : %s \n", __FILE__, __LINE__, filename.c_str());
#endif
return "";
Expand All @@ -159,7 +159,7 @@ namespace aff4 {
BOOL res = ReadFile(fileHandle, buffer.get(), AFF4_RESOURCE_BUFFER_SIZE, &read, NULL);
::CloseHandle(fileHandle);
if (res == FALSE || read != AFF4_RESOURCE_BUFFER_SIZE) {
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : Unable to read %d bytes from the container : %s = %d \n", __FILE__, __LINE__, AFF4_RESOURCE_BUFFER_SIZE, filename.c_str(), read);
#endif
return "";
Expand All @@ -174,19 +174,19 @@ namespace aff4 {
aff4::zip::structs::ZipFileHeader* header = (aff4::zip::structs::ZipFileHeader*)(buffer.get());
// Start sanity check.
if (header->magic != 0x4034b50) {
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : Invalid PKZIP Magic number : %s = 0x%x \n", __FILE__, __LINE__, filename.c_str(), header->magic);
#endif
return "";
}
if (header->compression_method != 0) {
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : Invalid PKZIP compression method : %s = %d \n", __FILE__, __LINE__, filename.c_str(), header->compression_method);
#endif
goto slowPath;
}
if (header->file_name_length != 0x15) { // 'container.description'
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : Invalid segment name length : %s = %d != 0x15\n", __FILE__, __LINE__, filename.c_str(), header->file_name_length);
#endif
goto slowPath;
Expand All @@ -195,7 +195,7 @@ namespace aff4 {
filenameLength = le16toh(header->file_name_length);
segmentName = std::string((char*)(buffer.get() + sizeof(aff4::zip::structs::ZipFileHeader)), filenameLength);
if (segmentName.compare(AFF4_FILEDESCRIPTOR) != 0) {
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : Invalid segment name : %s = %s\n", __FILE__, __LINE__, filename.c_str(), segmentName.c_str());
#endif
goto slowPath;
Expand Down Expand Up @@ -252,7 +252,7 @@ namespace aff4 {
if ((segmentEntrySize == 0) || //
(segmentEntrySize > (AFF4_RESOURCE_BUFFER_SIZE - (sizeof(aff4::zip::structs::ZipFileHeader) - header->file_name_length - header->extra_field_len)))) {
// Too large...
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : Segment appears too large for container.description? : %s \n", __FILE__, __LINE__, filename.c_str());
#endif
goto slowPath;
Expand Down Expand Up @@ -310,7 +310,7 @@ namespace aff4 {
}

aff4::IAFF4Resolver* createResolver(std::string path, bool scanSubFolders) noexcept {
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : Create Resolver : %s, %d \n", __FILE__, __LINE__, path.c_str(), scanSubFolders);
#endif
if (path.empty()) {
Expand All @@ -326,7 +326,7 @@ namespace aff4 {
* See if it exists.
*/
if (!aff4::util::fileExists(path)) {
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : Create Resolver Path doesn't exist? %s, %d \n", __FILE__, __LINE__, path.c_str(), scanSubFolders);
#endif
return nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/AFF4Lexicon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ std::string getLexiconString(aff4::Lexicon lexicon) noexcept {

aff4::Lexicon getLexicon(const std::string& lexicon) noexcept {
if (lexicon.length() == 0) {
#if DEBUG
#if DEBUG_VERBOSE
fprintf( aff4::getDebugOutput(), "%s[%d] : Unknown lexicon? %s\n", __FILE__, __LINE__, lexicon.c_str());
#endif
return Lexicon::UNKNOWN;
Expand All @@ -127,7 +127,7 @@ aff4::Lexicon getLexicon(const std::string& lexicon) noexcept {
return it->first;
}
}
#if DEBUG
#if DEBUG_VERBOSE
fprintf( aff4::getDebugOutput(), "%s[%d] : Unknown lexicon? %s\n", __FILE__, __LINE__,lexicon.c_str());
#endif
return Lexicon::UNKNOWN;
Expand Down
8 changes: 4 additions & 4 deletions src/RDFValue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static const std::map<std::string, aff4::Lexicon> aff4Mappings = { //
};

XSDType getType(const std::string& type) {
#if DEBUG
#if DEBUG_VERBOSE
fprintf( aff4::getDebugOutput(), "%s[%d] : Determine XSD type: %s\n", __FILE__, __LINE__, type.c_str());
#endif
if (type.empty()) {
Expand All @@ -70,7 +70,7 @@ XSDType getType(const std::string& type) {
}

aff4::Lexicon getAFF4Type(const std::string& type) {
#if DEBUG
#if DEBUG_VERBOSE
fprintf( aff4::getDebugOutput(), "%s[%d] : Determine AFF4 Data type: %s\n", __FILE__, __LINE__, type.c_str());
#endif
if (type.empty()) {
Expand All @@ -80,7 +80,7 @@ aff4::Lexicon getAFF4Type(const std::string& type) {
if (it != aff4Mappings.end()) {
return it->second;
}
#if DEBUG
#if DEBUG_VERBOSE
fprintf( aff4::getDebugOutput(), "%s[%d] : Unknown AFF4 type? %s\n", __FILE__, __LINE__, type.c_str());
#endif
// Default as unknown.
Expand Down Expand Up @@ -129,7 +129,7 @@ time_t my_timegm(register struct tm * t)
}

std::chrono::system_clock::time_point getTime(const std::string& value) {
#if DEBUG
#if DEBUG_VERBOSE
fprintf( aff4::getDebugOutput(), "%s[%d] : Convert XSDDateTime: %s\n", __FILE__, __LINE__, value.c_str());
#endif
// The time format should be RFC3339
Expand Down
12 changes: 6 additions & 6 deletions src/codec/CompressionCodec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,34 @@ std::shared_ptr<CompressionCodec> getCodec(aff4::Lexicon resource, uint32_t chun
switch (resource) {
case Lexicon::AFF4_IMAGE_COMPRESSION_SNAPPY:
case Lexicon::AFF4_IMAGE_COMPRESSION_SNAPPY2:
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : Create Snappy Decompressor \n", __FILE__, __LINE__);
#endif
return std::make_shared<SnappyCompression>(chunkSize);
case Lexicon::AFF4_IMAGE_COMPRESSION_LZ4:
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : Create LZ4 Decompressor \n", __FILE__, __LINE__);
#endif
return std::make_shared<LZ4Compression>(chunkSize);
case Lexicon::AFF4_IMAGE_COMPRESSION_DEFLATE:
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : Create Deflate Decompressor \n", __FILE__, __LINE__);
#endif
return std::make_shared<DeflateCompression>(chunkSize);
case Lexicon::AFF4_IMAGE_COMPRESSION_STORED:
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : Create Stored Decompressor \n", __FILE__, __LINE__);
#endif
return std::make_shared<NullCompression>(chunkSize);
case Lexicon::AFF4_IMAGE_COMPRESSION_ZLIB:
#if DEBUG
#if DEBUG_VERBOSE
fprintf(aff4::getDebugOutput(), "%s[%d] : Create ZLib Decompressor \n", __FILE__, __LINE__);
#endif
return std::make_shared<ZlibCompression>(chunkSize);
default:
break;
}
#if DEBUG
#if DEBUG_VERBOSE
fprintf( aff4::getDebugOutput(), "%s[%d] : Unknown Compression Codec : %s\n", __FILE__, __LINE__,
aff4::lexicon::getLexiconString(resource).c_str());
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/codec/SnappyCompression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ uint64_t SnappyCompression::decompress(void* source, uint64_t srcSize, void* des
if (snappy::RawUncompress((char*) source, srcSize, (char*) destination)) {
return destSize;
} else {
#if DEBUG
#if DEBUG_VERBOSE
fprintf( aff4::getDebugOutput(), "%s[%d] : Snappy decompression failure\n", __FILE__, __LINE__);
#endif
return 0;
Expand Down
Loading