Skip to content

Commit

Permalink
Merge branch 'main' into dissasm_view
Browse files Browse the repository at this point in the history
  • Loading branch information
rzaharia committed Oct 1, 2024
2 parents f29cccb + 9806549 commit 577d827
Show file tree
Hide file tree
Showing 33 changed files with 1,055 additions and 707 deletions.
128 changes: 66 additions & 62 deletions GViewCore/include/GView.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

// Version MUST be in the following format <Major>.<Minor>.<Patch>
#define GVIEW_VERSION "0.351.0"
#define GVIEW_VERSION "0.352.0"

#include <AppCUI/include/AppCUI.hpp>

Expand Down Expand Up @@ -34,20 +34,21 @@ struct CORE_EXPORT KeyboardControl {
const char* Explanation;
uint32 CommandId;
};
struct CORE_EXPORT KeyboardControlsInterface
{
struct CORE_EXPORT KeyboardControlsInterface {
virtual bool RegisterKey(KeyboardControl* key) = 0;
virtual ~KeyboardControlsInterface() = default;
virtual ~KeyboardControlsInterface() = default;
};
class CORE_EXPORT Object;
struct CORE_EXPORT TypeInterface {
Object* obj{ nullptr };

virtual std::string_view GetTypeName() = 0;
virtual void RunCommand(std::string_view commandName) = 0;
virtual std::string_view GetTypeName() = 0;
virtual void RunCommand(std::string_view commandName) = 0;
virtual bool UpdateKeys(KeyboardControlsInterface* interface) = 0;

virtual ~TypeInterface(){}
virtual ~TypeInterface()
{
}

struct SelectionZone {
uint64 start, end;
Expand Down Expand Up @@ -180,7 +181,7 @@ namespace Utils
Zone(uint64 low, uint64 high, ColorPair cp, std::string_view name) : interval{ low, high }, color(cp), name(name)
{
}
Zone() : interval{ INVALID_OFFSET, INVALID_OFFSET }, color(NoColorPair), name(){};
Zone() : interval{ INVALID_OFFSET, INVALID_OFFSET }, color(NoColorPair), name() {};
};

class CORE_EXPORT ZonesList
Expand Down Expand Up @@ -605,46 +606,68 @@ namespace Golang
CORE_EXPORT const char* GetNameForGoMagic(GoMagic magic);
} // namespace Golang

namespace ZLIB
namespace Decoding
{
CORE_EXPORT bool Decompress(const Buffer& input, uint64 inputSize, Buffer& output, uint64 outputSize);
}
namespace Base64
{
CORE_EXPORT void Encode(BufferView view, Buffer& output);
CORE_EXPORT bool Decode(BufferView view, Buffer& output, bool& hasWarning, String& warningMessage);
CORE_EXPORT bool Decode(BufferView view, Buffer& output);
} // namespace Base64

namespace ZIP
{
enum class EntryType { Unknown = 0, Directory = 1, Symlink = 2, File = 3 };
namespace LZXPRESS::Huffman
{
CORE_EXPORT bool Decompress(const BufferView& compressed, Buffer& uncompressed);
} // namespace LZXPRESS::Huffman

struct CORE_EXPORT Entry {
void* context{ nullptr };
namespace QuotedPrintable
{
CORE_EXPORT void Encode(BufferView view, Buffer& output);
CORE_EXPORT bool Decode(BufferView view, Buffer& output);
} // namespace QuotedPrintable

std::u8string_view GetFilename() const;
uint16 GetFlags() const;
std::string GetFlagNames() const;
int64 GetCompressedSize() const;
int64 GetUncompressedSize() const;
int64 GetCompressionMethod() const;
std::string GetCompressionMethodName() const;
uint32 GetDiskNumber() const;
int64 GetDiskOffset() const;
EntryType GetType() const;
std::string_view GetTypeName() const;
bool IsEncrypted() const;
};
namespace ZLIB
{
CORE_EXPORT bool Decompress(const Buffer& input, uint64 inputSize, Buffer& output, uint64 outputSize);
CORE_EXPORT bool DecompressStream(const BufferView& input, Buffer& output, String& message, uint64& sizeConsumed);
} // namespace ZLIB

struct CORE_EXPORT Info {
void* context{ nullptr };
namespace ZIP
{
enum class EntryType { Unknown = 0, Directory = 1, Symlink = 2, File = 3 };

struct CORE_EXPORT Entry {
void* context{ nullptr };

std::u8string_view GetFilename() const;
uint16 GetFlags() const;
std::string GetFlagNames() const;
int64 GetCompressedSize() const;
int64 GetUncompressedSize() const;
int64 GetCompressionMethod() const;
std::string GetCompressionMethodName() const;
uint32 GetDiskNumber() const;
int64 GetDiskOffset() const;
EntryType GetType() const;
std::string_view GetTypeName() const;
bool IsEncrypted() const;
};

uint32 GetCount() const;
bool GetEntry(uint32 index, Entry& entry) const;
bool Decompress(Buffer& output, uint32 index, const std::string& password) const;
bool Decompress(const BufferView& input, Buffer& output, uint32 index, const std::string& password) const;
struct CORE_EXPORT Info {
void* context{ nullptr };

Info();
~Info();
};
CORE_EXPORT bool GetInfo(std::u16string_view path, Info& info);
CORE_EXPORT bool GetInfo(Utils::DataCache& cache, Info& info);
} // namespace ZIP
uint32 GetCount() const;
bool GetEntry(uint32 index, Entry& entry) const;
bool Decompress(Buffer& output, uint32 index, const std::string& password) const;
bool Decompress(const BufferView& input, Buffer& output, uint32 index, const std::string& password) const;

Info();
~Info();
};
CORE_EXPORT bool GetInfo(std::u16string_view path, Info& info);
CORE_EXPORT bool GetInfo(Utils::DataCache& cache, Info& info);
} // namespace ZIP
} // namespace Decoding

namespace Dissasembly
{
Expand Down Expand Up @@ -720,11 +743,6 @@ namespace Dissasembly
};
} // namespace Dissasembly

namespace Compression::LZXPRESS::Huffman
{
CORE_EXPORT bool Decompress(const BufferView& compressed, Buffer& uncompressed);
} // namespace Compression::LZXPRESS::Huffman

namespace SQLite3
{
class CORE_EXPORT Column
Expand Down Expand Up @@ -787,6 +805,7 @@ namespace Regex
namespace Entropy
{
CORE_EXPORT double ShannonEntropy(const BufferView& buffer);
CORE_EXPORT double RenyiEntropy(const BufferView& buffer, double alpha);
} // namespace Entropy

/*
Expand Down Expand Up @@ -886,7 +905,7 @@ namespace View
virtual bool ShowGoToDialog() = 0;
virtual bool ShowFindDialog() = 0;
virtual bool ShowCopyDialog() = 0;
virtual bool UpdateKeys(KeyboardControlsInterface* interface)
virtual bool UpdateKeys(KeyboardControlsInterface*)
{
return true;
}
Expand Down Expand Up @@ -1504,21 +1523,6 @@ namespace App
uint32 CORE_EXPORT GetTypePluginsCount();

}; // namespace App

namespace Unpack
{
namespace Base64
{
CORE_EXPORT void Encode(BufferView view, Buffer& output);
CORE_EXPORT bool Decode(BufferView view, Buffer& output, bool& hasWarning, String& warningMessage);
CORE_EXPORT bool Decode(BufferView view, Buffer& output);
} // namespace Base64
namespace QuotedPrintable
{
CORE_EXPORT void Encode(BufferView view, Buffer& output);
CORE_EXPORT bool Decode(BufferView view, Buffer& output);
} // namespace QuotedPrintable
} // namespace Unpack
}; // namespace GView

ADD_FLAG_OPERATORS(GView::View::LexicalViewer::StringFormat, AppCUI::uint32);
Expand Down
5 changes: 1 addition & 4 deletions GViewCore/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ add_subdirectory(Utils)
add_subdirectory(View)
add_subdirectory(Hashes)
add_subdirectory(DigitalSignature)
add_subdirectory(Compression)
add_subdirectory(Decoding)
add_subdirectory(Go)
add_subdirectory(ZLIB)
add_subdirectory(Dissasembly)
add_subdirectory(ZIP)
add_subdirectory(SQLite3)
add_subdirectory(Regex)
add_subdirectory(Unpack)
add_subdirectory(Entropy)

if(NOT DEFINED CMAKE_TESTING_ENABLED)
Expand Down
3 changes: 0 additions & 3 deletions GViewCore/src/Compression/CMakeLists.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ constexpr char BASE64_DECODE_TABLE[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };

namespace GView::Unpack::Base64
namespace GView::Decoding::Base64
{

void Encode(BufferView view, Buffer& output)
{
uint32 sequence = 0;
Expand Down Expand Up @@ -62,7 +61,7 @@ bool Decode(BufferView view, Buffer& output, bool& hasWarning, String& warningMe
}

if (lastEncoded == '=' && sequenceIndex == 0) {
hasWarning = true;
hasWarning = true;
warningMessage = "Ignoring extra bytes after the end of buffer";
break;
}
Expand Down Expand Up @@ -110,4 +109,4 @@ bool Decode(BufferView view, Buffer& output)
return Decode(view, output, tempHasWarning, tempWarningMessage);
}

} // namespace GView::Unpack::Base64
} // namespace GView::Decoding::Base64
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
target_sources(GViewCore PRIVATE
Base64.cpp
LZXPRESS.cpp
QuotedPrintable.cpp
zip.cpp
zlib.cpp
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# undef GetObject
#endif

namespace GView::Compression::LZXPRESS::Huffman
namespace GView::Decoding::LZXPRESS::Huffman
{
constexpr uint32 MAX_BITS_COUNT = 32U;
constexpr uint32 UINT32_BITS_COUNT = 32U;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "Internal.hpp"

//TODO: THIS WAS NOT TESTED!
void GView::Unpack::QuotedPrintable::Encode(BufferView view, Buffer& output)
void GView::Decoding::QuotedPrintable::Encode(BufferView view, Buffer& output)
{
// Iterate over each character in the input buffer
for (size_t i = 0; i < view.GetLength(); i++) {
Expand Down Expand Up @@ -32,8 +32,12 @@ void GView::Unpack::QuotedPrintable::Encode(BufferView view, Buffer& output)
}

//TODO: Consider more testing!
bool GView::Unpack::QuotedPrintable::Decode(BufferView view, Buffer& output)
bool GView::Decoding::QuotedPrintable::Decode(BufferView view, Buffer& output)
{
CHECK(view.IsValid(), false, "");
CHECK(view.GetLength() >= 3, false, "");
CHECK(view.GetData()[0] == '=', false, "");

char temp_buffer[2] = {};
// Iterate over each character in the input buffer
for (size_t i = 0; i < view.GetLength(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <locale>
#include <codecvt>

namespace GView::ZIP
namespace GView::Decoding::ZIP
{
using mz_zip_reader_create_ptr = struct Reader
{
Expand Down
69 changes: 69 additions & 0 deletions GViewCore/src/Decoding/zlib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "../include/GView.hpp"
#include <zlib.h>

namespace GView::Decoding::ZLIB
{
bool Decompress(const Buffer& input, uint64 inputSize, Buffer& output, uint64 outputSize)
{
CHECK(input.IsValid(), false, "");
CHECK(inputSize > 0, false, "");
CHECK(outputSize > inputSize, false, "");

output.Resize(outputSize);

uint64 outputSizeCopy = outputSize;
int32 ret = uncompress(output.GetData(), (uLongf*) &outputSizeCopy, input.GetData(), static_cast<uLong>(inputSize));
CHECK(outputSize == outputSizeCopy, false, "ZLIB error: %d!", ret);
CHECK(ret == Z_OK, false, "ZLIB error: %d!", ret);

return true;
}

bool DecompressStream(const BufferView& input, Buffer& output, String& message, uint64& sizeConsumed)
{
CHECK(input.IsValid(), false, "");
CHECK(input.GetLength() > 0, false, "");
output.Resize(input.GetLength());
sizeConsumed = 0;

z_stream stream;
memset(&stream, Z_NULL, sizeof(stream));

stream.avail_in = static_cast<uInt>(input.GetLength());
stream.next_in = const_cast<Bytef*>(input.GetData());
stream.avail_out = static_cast<uInt>(input.GetLength());
stream.next_out = reinterpret_cast<Bytef*>(output.GetData());

int ret = inflateInit(&stream);
CHECK(ret == Z_OK, false, "");

struct ZWrapper {
z_stream& z;

ZWrapper(z_stream& z) : z(z)
{
}
~ZWrapper()
{
inflateEnd(&z);
}
} zWrapper(stream);

while (ret == Z_OK || ret == Z_BUF_ERROR) {
ret = inflate(&stream, Z_NO_FLUSH);
if (ret == Z_BUF_ERROR) {
output.Resize(stream.total_out * 2);
stream.avail_out = static_cast<uInt>(stream.total_out);
stream.next_out = reinterpret_cast<Bytef*>(output.GetData() + stream.total_out);
}
}

output.Resize(stream.total_out);
sizeConsumed = stream.total_in;
message.Format("Return code: %d with msg: %s", ret, stream.msg);

CHECK(ret == Z_OK || ret == Z_STREAM_END, false, "");

return true;
}
} // namespace GView::ZLIB
Loading

0 comments on commit 577d827

Please sign in to comment.