Skip to content

Commit

Permalink
Supports for Drombox alt stram attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
miyabe committed Jul 6, 2023
1 parent 16c040e commit 8c5f520
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 34 deletions.
3 changes: 2 additions & 1 deletion EncFSy_lib/EncFSFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ namespace EncFS {
return 0;
}

//printf("read %d %d %d %d\n", fileIv, this->lastBlockNum, off, len);
//string cFileName = this->strConv.to_bytes(wstring(FileName));
//printf("read %s %d %d %d %d\n", cFileName.c_str(), fileIv, this->lastBlockNum, off, len);

// Calculate block position.
const size_t blockSize = encfs.getBlockSize();
Expand Down
4 changes: 4 additions & 0 deletions EncFSy_lib/EncFSVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ R"(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
pos2 = srcFilePath.find(g_pathSeparator, pos1);
if (pos2 == string::npos) {
if (this->altStream) {
// use plain text for alt streams.
string::size_type altPos = srcFilePath.find(g_altSeparator, pos1);
if (altPos == string::npos) {
pos2 = srcFilePath.size();
Expand Down Expand Up @@ -660,17 +661,20 @@ R"(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
}

// チェックサム検証
//printf("Decode %d\n", blockNum);
bool valid = true;
string mac;
mac.resize(this->blockMACBytes);
mac64(this->volumeHmac, this->hmacLock, (const byte*)destBlock.data() + this->blockMACBytes, destBlock.size() - this->blockMACBytes, &mac[0]);
for (size_t i = 0; i < this->blockMACBytes; i++) {
//printf("destBlock %d\n", destBlock[i]);
if (destBlock[i] != mac[7 - i]) {
valid = false;
break;
}
}
if (!valid) {
//printf("Decode Error %d\n", valid);
throw EncFSInvalidBlockException();
}

Expand Down
114 changes: 82 additions & 32 deletions EncFSy_lib/EncFSy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,38 +721,55 @@ static NTSTATUS DOKAN_CALLBACK EncFSReadFile(LPCWSTR FileName, LPVOID Buffer,
DbgPrint(L"ReadFile : %s, handle = %ld\n", FileName, encfsFile->getHandle());

int32_t readLen;
if (encfs.isReverse()) {
WCHAR filePath[DOKAN_MAX_PATH];
GetFilePath(filePath, FileName, false);
size_t len = wcslen(filePath);
if (len >= 12 && wcscmp(filePath + len - 12, L"\\.encfs6.xml") == 0) {
LARGE_INTEGER distanceToMove;
distanceToMove.QuadPart = Offset;
if (!SetFilePointerEx(encfsFile->getHandle(), distanceToMove, NULL, FILE_BEGIN)) {
DWORD error = GetLastError();
DbgPrint(L"\tseek error, offset = %d\n\n", offset);
if (opened) {
delete encfsFile;
}
return DokanNtStatusFromWin32(error);
}
else if (!ReadFile(encfsFile->getHandle(), Buffer, BufferLength, ReadLength, NULL)) {
readLen = -1;

bool plain = false;
if (encfs.altStream) {
// exclude Dropbox attributes
const LPCWSTR suffix = L":com.dropbox.attrs:$DATA";
size_t str_len = wcslen(FileName);
size_t suffix_len = wcslen(suffix);
plain = str_len >= suffix_len &&
0 == wcscmp(FileName + str_len - suffix_len, suffix);
}

if (!plain) {
if (encfs.isReverse()) {
WCHAR filePath[DOKAN_MAX_PATH];
GetFilePath(filePath, FileName, false);
size_t len = wcslen(filePath);
if (len >= 12 && wcscmp(filePath + len - 12, L"\\.encfs6.xml") == 0) {
plain = true;
}
else {
readLen = *ReadLength;
readLen = encfsFile->reverseRead(FileName, (char*)Buffer, offset, BufferLength);
}
}
else {
readLen = encfsFile->reverseRead(FileName, (char*)Buffer, offset, BufferLength);
readLen = encfsFile->read(FileName, (char*)Buffer, offset, BufferLength);
}
}
else {
readLen = encfsFile->read(FileName, (char*)Buffer, offset, BufferLength);

if (plain) {
LARGE_INTEGER distanceToMove;
distanceToMove.QuadPart = Offset;
if (!SetFilePointerEx(encfsFile->getHandle(), distanceToMove, NULL, FILE_BEGIN)) {
DWORD error = GetLastError();
DbgPrint(L"\tseek error, offset = %d\n\n", offset);
if (opened) {
delete encfsFile;
}
return DokanNtStatusFromWin32(error);
}
else if (!ReadFile(encfsFile->getHandle(), Buffer, BufferLength, ReadLength, NULL)) {
readLen = -1;
}
else {
readLen = *ReadLength;
}
}
if (readLen == -1) {
DWORD error = GetLastError();
ErrorPrint(L"\tread error = %u, buffer length = %d, offset = %d\n\n",
ErrorPrint(L"\tRead error = %u, buffer length = %d, offset = %d\n\n",
error, BufferLength, offset);
if (opened) {
delete encfsFile;
Expand Down Expand Up @@ -844,19 +861,52 @@ static NTSTATUS DOKAN_CALLBACK EncFSWriteFile(LPCWSTR FileName, LPCVOID Buffer,
off = Offset;
}

int32_t writtenLen = encfsFile->write(FileName, fileSize, (char*)Buffer, off, NumberOfBytesToWrite);
if (writtenLen == -1) {
DWORD error = GetLastError();
ErrorPrint(L"\twrite error = %u, buffer length = %d, write length = %d\n",
error, NumberOfBytesToWrite, writtenLen);
if (opened) {
delete encfsFile;
}
return DokanNtStatusFromWin32(error);
bool plain = false;
if (encfs.altStream) {
// exclude Dropbox attributes
const LPCWSTR suffix = L":com.dropbox.attrs:$DATA";
size_t str_len = wcslen(FileName);
size_t suffix_len = wcslen(suffix);
plain = str_len >= suffix_len &&
0 == wcscmp(FileName + str_len - suffix_len, suffix);
}

int32_t writtenLen;
if (!plain) {
writtenLen = encfsFile->write(FileName, fileSize, (char*)Buffer, off, NumberOfBytesToWrite);
if (writtenLen == -1) {
DWORD error = GetLastError();
ErrorPrint(L"\twrite error = %u, buffer length = %d, write length = %d\n",
error, NumberOfBytesToWrite, writtenLen);
if (opened) {
delete encfsFile;
}
return DokanNtStatusFromWin32(error);

}
else {
DbgPrint(L"\twrite %d, offset %I64d\n\n", writtenLen, Offset);
}
}
else {
DbgPrint(L"\twrite %d, offset %I64d\n\n", writtenLen, Offset);
ULONG offset = (ULONG)Offset;
LARGE_INTEGER distanceToMove;
distanceToMove.QuadPart = Offset;
if (!SetFilePointerEx(encfsFile->getHandle(), distanceToMove, NULL, FILE_BEGIN)) {
DWORD error = GetLastError();
DbgPrint(L"\tseek error, offset = %d\n\n", offset);
if (opened) {
delete encfsFile;
}
return DokanNtStatusFromWin32(error);
}
else if (!WriteFile(encfsFile->getHandle(), Buffer, NumberOfBytesToWrite, NumberOfBytesWritten, NULL)) {
writtenLen = -1;
}
else {
writtenLen = *NumberOfBytesWritten;
}

}
*NumberOfBytesWritten = writtenLen;

Expand Down
2 changes: 1 addition & 1 deletion installer/installer.nsi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!define VERSION "1.0.2"
!define VERSION "1.0.3"

!include LogicLib.nsh
!include x64.nsh
Expand Down

0 comments on commit 8c5f520

Please sign in to comment.