Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
remittor committed Dec 9, 2019
2 parents 255573f + 8511f76 commit f76c8d5
Show file tree
Hide file tree
Showing 42 changed files with 2,305 additions and 1,404 deletions.
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[submodule "extlibs/lz4"]
path = extlibs/lz4
url = https://github.com/lz4/lz4.git
branch = master
[submodule "extlibs/zstd"]
path = extlibs/zstd
url = https://github.com/facebook/zstd.git
branch = master
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
[![Github All Releases](https://img.shields.io/github/downloads/remittor/paxz.wcx/total.svg)](https://www.github.com/remittor/paxz.wcx/releases/latest)
[![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/remittor/paxz.wcx?include_prereleases)](https://www.github.com/remittor/paxz.wcx/releases)

Supported formats: **PAX , LZ4**
Supported formats for decompression: `pax`, `lz4`, `pax.lz4`, `zst`, `paxz`

Custom formats: **PAX.LZ4**
Supported formats for compression: `pax`, `pax.lz4`, `paxz`

Files packed in a custom format can be unpacked with free cross-platform utilities: lz4/zstd, pax/gnutar.
File format `paxz` equivalent for `pax.zst`.

## Tasks list:
- [ ] Add support for Zstandard and custom format PAXZ.
- [ ] Add support for inserting and deleting files.
- [ ] Add support for cipher ChaCha20.
All files created by this plugin can be unpacked with free cross-platform utilities: `lz4`/`zstd`, `pax`/`gnutar`.

## Tasks list
- [ ] Zstandard and custom format PAXZ.
- [ ] Inserting and deleting files.
- [ ] Cipher ChaCha20.
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ init:
# clone directory
clone_folder: c:\projects\paxz-wcx

# fetch repository as zip archive
shallow_clone: true
# clone only last commit history
clone_depth: 1

environment:
matrix:
Expand All @@ -37,7 +37,7 @@ matrix:
install:
- call build\appveyor\get-version.bat
- call build\appveyor\set-env.bat
- call build\appveyor\install.bat
- git submodule update --depth 1 --init --recursive

#---------------------------------#
# build configuration #
Expand Down
5 changes: 0 additions & 5 deletions build/appveyor/install.bat

This file was deleted.

1 change: 1 addition & 0 deletions extlibs/lz4
Submodule lz4 added at 3d6767
4 changes: 4 additions & 0 deletions extlibs/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This should be the sources of the following projects: LZ4, Zstd

git clone https://github.com/lz4/lz4.git -b master lz4
git clone https://github.com/facebook/zstd.git -b master zstd
1 change: 1 addition & 0 deletions extlibs/zstd
Submodule zstd added at 10f0e6
3 changes: 0 additions & 3 deletions lz4/readme.txt

This file was deleted.

4 changes: 2 additions & 2 deletions out/pluginst.inf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[plugininstall]
description=PAXZ packer plugin (PAX/LZ4)
description=PAXZ packer plugin (PAX/LZ4/Zstd)
type=wcx
file=paxz.wcx
defaultdir=paxz
defaultextension=pax,lz4
defaultextension=pax,lz4,paxz
58 changes: 29 additions & 29 deletions paths.VS2008.vsprops
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="paths"
IntermediateDirectory="$(SolutionDir)\.itermediates\$(ProjectName)\$(ConfigurationName)_$(PlatformName)\"
>
<UserMacro
Name="LibDir"
Value="$(SolutionDir)lib\"
/>
<UserMacro
Name="fakeNtdllDir"
Value="$(SolutionDir)fake_ntdll\"
/>
<UserMacro
Name="fakeNtdllOut"
Value="$(LibDir)\fake_ntdll\$(ConfigurationName)_$(PlatformName)"
/>
<UserMacro
Name="paxzSrcPath"
Value="$(SolutionDir)src\"
/>
<UserMacro
Name="paxzOutPath"
Value="$(SolutionDir)out\"
/>
<UserMacro
Name="paxzOutDir"
Value="$(paxzOutPath)\$(ConfigurationName)_$(PlatformName)"
/>
ProjectType="Visual C++"
Version="8.00"
Name="paths"
IntermediateDirectory="$(SolutionDir)\.itermediates\$(ProjectName)\$(ConfigurationName)_$(PlatformName)\"
>
<UserMacro
Name="LibDir"
Value="$(SolutionDir)lib\"
/>
<UserMacro
Name="fakeNtdllDir"
Value="$(SolutionDir)fake_ntdll\"
/>
<UserMacro
Name="fakeNtdllOut"
Value="$(LibDir)\fake_ntdll\$(ConfigurationName)_$(PlatformName)"
/>
<UserMacro
Name="paxzSrcPath"
Value="$(SolutionDir)src\"
/>
<UserMacro
Name="paxzOutPath"
Value="$(SolutionDir)out\"
/>
<UserMacro
Name="paxzOutDir"
Value="$(paxzOutPath)\$(ConfigurationName)_$(PlatformName)"
/>
</VisualStudioPropertySheet>
42 changes: 17 additions & 25 deletions src/bst/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class string_base
set_defaults();
va_list argptr;
va_start(argptr, fmt);
assign_va_internal(fmt.c_str(), argptr);
assign_fmt_internal(fmt.c_str(), argptr);
va_end(argptr);
}

Expand Down Expand Up @@ -167,7 +167,7 @@ class string_base
destroy();
return true;
}
if (is_buffer == false)
if (!is_buffer)
if ((SSIZE_T)len <= 0)
len = get_length(s);

Expand All @@ -180,7 +180,7 @@ class string_base
return false;

memcpy(m_buf, s, len * sizeof(CharT));
if (is_buffer == false)
if (!is_buffer)
m_buf[len] = 0;

m_len = len;
Expand Down Expand Up @@ -315,7 +315,7 @@ class string_base
if (!s)
return *this;

if (is_buffer == false)
if (!is_buffer)
if ((SSIZE_T)slen <= 0)
slen = get_length(s);

Expand All @@ -329,7 +329,7 @@ class string_base
if (len > m_len) {
memcpy(&m_buf[m_len], s, (len - m_len) * sizeof(CharT));
m_len = len;
if (is_buffer == false)
if (!is_buffer)
m_buf[m_len] = 0;
}
return *this;
Expand All @@ -351,7 +351,7 @@ class string_base

if (len > 0) {
memcpy(s, &m_buf[pos], len * sizeof(CharT));
if (is_buffer == false)
if (!is_buffer)
s[len] = 0;
}
return len;
Expand Down Expand Up @@ -416,15 +416,12 @@ class string_base
m_last_error = e_out_of_memory;
return false;
}
buf[0] = 0;
if (m_buf) {
if (m_len && save_data) {
memcpy(buf, m_buf, (m_len + 1) * sizeof(CharT));
} else {
buf[0] = 0;
}
bst::free(m_buf);
} else {
buf[0] = 0;
}
m_buf = buf;
m_capacity = new_capacity;
Expand All @@ -434,11 +431,8 @@ class string_base

size_t resize_internal(size_t len, bool fill, CharT c)
{
if (len == m_len)
return len;

if (len < m_len) {
if (is_buffer == false)
if (len <= m_len) {
if (!is_buffer && m_buf)
m_buf[len] = 0;
m_len = len;
return len;
Expand All @@ -452,7 +446,7 @@ class string_base
m_buf[i] = c;
}
}
if (is_buffer == false)
if (!is_buffer)
m_buf[len] = 0;

m_len = len;
Expand Down Expand Up @@ -527,11 +521,10 @@ class string_base

size_t res;
if (_case == case_sensitive) {
if (is_wstring) {
if (is_wstring)
res = (size_t)StrRChrW((LPCWSTR)m_buf, (LPCWSTR)end, (WCHAR)c);
} else {
else
res = (size_t)StrRChrA((LPCSTR)m_buf, (LPCSTR)end, (CHAR)c);
}
} else {
if (is_wstring)
res = (size_t)StrRChrIW((LPCWSTR)m_buf, (LPCWSTR)end, (WCHAR)c);
Expand Down Expand Up @@ -611,11 +604,10 @@ class string_base

size_t res;
if (_case == case_sensitive) {
if (is_wstring) {
if (is_wstring)
res = (size_t)StrChrW((LPCWSTR)m_buf + pos, (WCHAR)c);
} else {
else
res = (size_t)StrChrA((LPCSTR)m_buf + pos, (CHAR)c);
}
} else {
if (is_wstring)
res = (size_t)StrChrIW((LPCWSTR)m_buf + pos, (WCHAR)c);
Expand All @@ -639,7 +631,7 @@ class string_base
protected:
string_base & insert_internal(size_t pos, const CharT * s, size_t slen)
{
if (is_buffer == false)
if (!is_buffer)
if ((SSIZE_T)slen <= 0)
slen = get_length(s);

Expand All @@ -654,7 +646,7 @@ class string_base
memmove(m_buf + pos + slen, m_buf + pos, m_len - pos + 1);

memcpy(m_buf + pos, s, slen);
if (is_buffer == false)
if (!is_buffer)
m_buf[len] = 0;

m_len = len;
Expand Down Expand Up @@ -774,7 +766,7 @@ class prealloc_string : public string_base<CharT>

bool reserve(size_t len)
{
return (len < PreAllocLen) ? true : false;
return (len <= PreAllocLen) ? true : false;
}

bool is_null() const
Expand Down
55 changes: 30 additions & 25 deletions src/lz4lib.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "stdafx.h"
#include "lz4lib.h"

#include "..\lz4\lib\lz4frame.c"
#include "lz4\lib\lz4frame.c"

namespace lz4 {

Expand All @@ -16,7 +16,6 @@ Format check_frame_magic(DWORD magic)
int check_file_header(HANDLE hFile, UINT64 file_size)
{
int hr = -1;
DWORD dw;
LARGE_INTEGER pos;
BOOL x;
union {
Expand All @@ -31,8 +30,8 @@ int check_file_header(HANDLE hFile, UINT64 file_size)
}
FIN_IF(file_size < LZ4F_HEADER_SIZE_MIN, -3);
pos.QuadPart = 0;
dw = SetFilePointerEx(hFile, pos, NULL, FILE_BEGIN);
FIN_IF(dw == INVALID_SET_FILE_POINTER, -4);
BOOL xp = SetFilePointerEx(hFile, pos, NULL, FILE_BEGIN);
FIN_IF(xp == FALSE, -4);

x = ReadFile(hFile, &header.magic, sizeof(header.magic), &dwRead, NULL);
FIN_IF(!x, -5);
Expand Down Expand Up @@ -66,39 +65,45 @@ int check_file_header(LPCWSTR filename)
// =========================================================================================

/* return error or data_offset */
int get_frame_info(LPCVOID buf, size_t bufsize, frame_info * finfo)
int frame_info::init(LPCVOID buf, size_t bufsize)
{
int hr = 0;
size_t offset = bufsize;
struct LZ4F_dctx_s dctx;

header_size = 0;
data_offset = 0;
memset(&dctx, 0, sizeof(dctx));
dctx.version = LZ4F_VERSION;
dctx.dStage = dstage_getFrameHeader;
LZ4F_errorCode_t sz = LZ4F_getFrameInfo(&dctx, finfo->get_ptr(), buf, &offset);
if (LZ4F_isError(sz))
return -2;
if (sz == 0)
return -3;
if (offset + 4 > bufsize)
return -4;
finfo->frame_size = offset;
UINT32 data_size = *(PUINT32)((PBYTE)buf + offset);
if (finfo->frameType == LZ4F_skippableFrame) {
finfo->is_compressed = false;
finfo->data_size = data_size;
LZ4F_errorCode_t ret = LZ4F_getFrameInfo(&dctx, get_ptr(), buf, &offset);
FIN_IF(LZ4F_isError(ret), -2);
FIN_IF(ret == 0, -3);
FIN_IF(offset + 4 > bufsize, -4);
header_size = offset;
UINT32 blk_size = *(PUINT32)((PBYTE)buf + offset);
if (frameType == LZ4F_skippableFrame) {
is_compressed = false;
data_size = blk_size;
contentSize = blk_size;
offset += 4;
} else {
if (data_size & LZ4F_BLOCKUNCOMPRESSED_FLAG) {
finfo->is_compressed = false;
finfo->data_size = data_size & (~LZ4F_BLOCKUNCOMPRESSED_FLAG);
if (blk_size & LZ4F_BLOCKUNCOMPRESSED_FLAG) {
is_compressed = false;
data_size = blk_size & (~LZ4F_BLOCKUNCOMPRESSED_FLAG);
} else {
finfo->is_compressed = true;
finfo->data_size = data_size;
is_compressed = true;
data_size = blk_size;
}
offset += 4;
if (contentSize == 0) /* unknown content size */
contentSize = (data_size == 0) ? 0 : CONTENTSIZE_UNKNOWN;
offset += 4;
}
finfo->data_offset = offset;
return (int)offset;
data_offset = offset;
hr = (int)offset;

fin:
return hr;
}

int decode_data_partial(LPCVOID src, size_t srcSize, LPVOID dst, size_t dstSize, size_t dstCapacity)
Expand Down
Loading

0 comments on commit f76c8d5

Please sign in to comment.