diff --git a/EncFSy_gui/MainForm.Designer.cs b/EncFSy_gui/MainForm.Designer.cs index 1d2341e..b318a60 100644 --- a/EncFSy_gui/MainForm.Designer.cs +++ b/EncFSy_gui/MainForm.Designer.cs @@ -39,6 +39,7 @@ private void InitializeComponent() this.Volume = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.altStreamCheckBox = new System.Windows.Forms.CheckBox(); this.reverseCheckBox = new System.Windows.Forms.CheckBox(); + this.mountManagerCheckBox = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // selectDirectoryButton @@ -131,18 +132,32 @@ private void InitializeComponent() // reverseCheckBox // this.reverseCheckBox.AutoSize = true; - this.reverseCheckBox.Location = new System.Drawing.Point(119, 214); + this.reverseCheckBox.Location = new System.Drawing.Point(252, 214); this.reverseCheckBox.Name = "reverseCheckBox"; this.reverseCheckBox.Size = new System.Drawing.Size(66, 17); this.reverseCheckBox.TabIndex = 11; this.reverseCheckBox.Text = "Reverse"; this.reverseCheckBox.UseVisualStyleBackColor = true; // + // mountManagerCheckBox + // + this.mountManagerCheckBox.AutoSize = true; + this.mountManagerCheckBox.Checked = true; + this.mountManagerCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; + this.mountManagerCheckBox.Location = new System.Drawing.Point(117, 214); + this.mountManagerCheckBox.Name = "mountManagerCheckBox"; + this.mountManagerCheckBox.Size = new System.Drawing.Size(101, 17); + this.mountManagerCheckBox.TabIndex = 12; + this.mountManagerCheckBox.Text = "Mount Manager"; + this.mountManagerCheckBox.UseVisualStyleBackColor = true; + this.mountManagerCheckBox.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged_1); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(330, 269); + this.Controls.Add(this.mountManagerCheckBox); this.Controls.Add(this.reverseCheckBox); this.Controls.Add(this.altStreamCheckBox); this.Controls.Add(this.driveListView); @@ -174,6 +189,7 @@ private void InitializeComponent() private System.Windows.Forms.ColumnHeader Volume; private System.Windows.Forms.CheckBox altStreamCheckBox; private System.Windows.Forms.CheckBox reverseCheckBox; + private System.Windows.Forms.CheckBox mountManagerCheckBox; } } diff --git a/EncFSy_gui/MainForm.cs b/EncFSy_gui/MainForm.cs index 600a6b9..2b9409b 100644 --- a/EncFSy_gui/MainForm.cs +++ b/EncFSy_gui/MainForm.cs @@ -84,6 +84,10 @@ private void mount_Click(object sender, EventArgs e) { args += " --alt-stream"; } + if (this.mountManagerCheckBox.Checked) + { + args += " --dokan-mount-manager"; + } if (this.reverseCheckBox.Checked) { args += " --reverse"; @@ -219,5 +223,10 @@ private void checkBox1_CheckedChanged(object sender, EventArgs e) { } + + private void checkBox1_CheckedChanged_1(object sender, EventArgs e) + { + + } } } \ No newline at end of file diff --git a/EncFSy_lib/EncFSFile.cpp b/EncFSy_lib/EncFSFile.cpp index 92730be..8d713e5 100644 --- a/EncFSy_lib/EncFSFile.cpp +++ b/EncFSy_lib/EncFSFile.cpp @@ -151,7 +151,7 @@ namespace EncFS { SetLastError(ERROR_FILE_CORRUPT); return -1; } - //printf("write %d %ld %d %d\n", fileSize, fileIv, off, len); + // wprintf(L"Write %s %ld %ld\n", FileName, off, len); if (off > fileSize) { // Expand file. @@ -336,6 +336,9 @@ namespace EncFS { return false; } size_t fileSize = encfs.toDecodedLength(encodedFileSize.QuadPart); + if (fileSize == length) { + return true; + } return this->_setLength(FileName, fileSize, length); } @@ -359,7 +362,7 @@ namespace EncFS { // 境界部分をデコード size_t blockHeaderSize = encfs.getHeaderSize(); size_t blockDataSize = encfs.getBlockSize() - blockHeaderSize; - size_t shift = 0; + size_t shift; size_t blockNum; size_t blocksOffset; LARGE_INTEGER distanceToMove; @@ -368,7 +371,7 @@ namespace EncFS { shift = length % blockDataSize; blockNum = length / blockDataSize; } - else if (length > fileSize) { + else { // 拡大 shift = fileSize % blockDataSize; blockNum = fileSize / blockDataSize; @@ -378,6 +381,7 @@ namespace EncFS { return false; } if (shift != 0) { + // 境界部分をデコード blocksOffset = blockNum * encfs.getBlockSize(); if (encfs.isUniqueIV()) { blocksOffset += EncFS::EncFSVolume::HEADER_SIZE; @@ -407,8 +411,8 @@ namespace EncFS { } this->lastBlockNum = -1; - // 境界部分をエンコード if (shift != 0) { + // 境界部分をエンコード size_t blockDataLen = length - blockNum * blockDataSize; if (blockDataLen > blockDataSize) { blockDataLen = blockDataSize; @@ -437,7 +441,7 @@ namespace EncFS { blockNum = length / blockDataSize; this->decodeBuffer.assign(shift, (char)0); this->encodeBuffer.clear(); - encfs.encodeBlock(fileIv, blockNum, this->decodeBuffer, this->encodeBuffer); + encfs.encodeBlock(fileIv, this->lastBlockNum = blockNum, this->decodeBuffer, this->encodeBuffer); distanceToMove.QuadPart = -(int64_t)shift - (int64_t)blockHeaderSize; if (!SetFilePointerEx(this->handle, distanceToMove, NULL, FILE_END)) { return false; diff --git a/EncFSy_lib/EncFSVolume.cpp b/EncFSy_lib/EncFSVolume.cpp index f8afc3e..ec9d32f 100644 --- a/EncFSy_lib/EncFSVolume.cpp +++ b/EncFSy_lib/EncFSVolume.cpp @@ -348,8 +348,8 @@ R"( } // getPaddedDecFilename - int padBytesSize = 16; - int padLen = padBytesSize - (plainFileName.size() % padBytesSize); + size_t padBytesSize = 16; + size_t padLen = padBytesSize - (plainFileName.size() % padBytesSize); if (padLen == 0) { padLen = padBytesSize; } @@ -366,7 +366,7 @@ R"( string paddedFileName(plainFileName); char iv[2]; - for (int i = 0; i < padLen; ++i) { + for (size_t i = 0; i < padLen; ++i) { paddedFileName += (char)padLen; } if (this->chainedNameIV) { @@ -450,7 +450,7 @@ R"( } } - int padLen = plainFileName[plainFileName.size() - 1]; + size_t padLen = plainFileName[plainFileName.size() - 1]; for (size_t i = 0; i < padLen; ++i) { if (plainFileName[plainFileName.size() - padLen + i] != padLen) { throw EncFSInvalidBlockException(); @@ -603,7 +603,7 @@ R"( // 證怜捷蛹 if (this->allowHoles && srcBlock.size() + headerSize == this->blockSize) { bool zeroBlock = true; - for (int i = 0; i < srcBlock.size(); ++i) { + for (size_t i = 0; i < srcBlock.size(); ++i) { if (srcBlock[i] != 0) { zeroBlock = false; break; @@ -623,7 +623,7 @@ R"( string mac; mac.resize(this->blockMACBytes); mac64(this->volumeHmac, this->hmacLock, (const byte*)srcBlock.data(), srcBlock.size(), &mac[0]); - for (int i = 0; i < this->blockMACBytes; i++) { + for (size_t i = 0; i < this->blockMACBytes; i++) { block[i] = mac[7 - i]; } @@ -641,7 +641,7 @@ R"( // 蠕ゥ蜿キ if (this->allowHoles && srcBlock.size() == this->blockSize) { bool zeroBlock = true; - for (int i = 0; i < srcBlock.size(); ++i) { + for (size_t i = 0; i < srcBlock.size(); ++i) { if (srcBlock[i] != 0) { zeroBlock = false; break; @@ -667,7 +667,7 @@ R"( string mac; mac.resize(this->blockMACBytes); mac64(this->volumeHmac, this->hmacLock, (const byte*)destBlock.data() + this->blockMACBytes, destBlock.size() - this->blockMACBytes, &mac[0]); - for (int i = 0; i < this->blockMACBytes; i++) { + for (size_t i = 0; i < this->blockMACBytes; i++) { if (destBlock[i] != mac[7 - i]) { valid = false; break; @@ -680,5 +680,4 @@ R"( destBlock.assign(destBlock.data() + headerSize, destBlock.size() - headerSize); } } - } diff --git a/EncFSy_lib/EncFSy.cpp b/EncFSy_lib/EncFSy.cpp index bde077c..3706775 100644 --- a/EncFSy_lib/EncFSy.cpp +++ b/EncFSy_lib/EncFSy.cpp @@ -212,7 +212,7 @@ EncFSCreateFile(LPCWSTR FileName, PDOKAN_IO_SECURITY_CONTEXT SecurityContext, GetFilePath(filePath, DOKAN_MAX_PATH, FileName); - DbgPrint(L"CreateFile : %s\n", FileName); + DbgPrint(L"CreateFile : %s ; %s\n", FileName, filePath); //PrintF(L"CreateFile : %s\n%s\n", FileName, filePath); PrintUserName(DokanFileInfo); @@ -536,7 +536,7 @@ static void DOKAN_CALLBACK EncFSCloseFile(LPCWSTR FileName, WCHAR filePath[DOKAN_MAX_PATH]; GetFilePath(filePath, DOKAN_MAX_PATH, FileName); if (DokanFileInfo->Context) { - DbgPrint(L"CloseFile: %s %s\n", FileName, filePath); + DbgPrint(L"CloseFile: %s ; %s\n", FileName, filePath); DbgPrint(L"\terror : not cleanuped file\n\n"); EncFS::EncFSFile* encfsFile = (EncFS::EncFSFile*)DokanFileInfo->Context; // CleanupとCloseFileが同時に実行されるとDokanFileInfoが別々でDokanFileInfo->Contextが同じになってしまう現象が起こる HACK @@ -558,7 +558,7 @@ static void DOKAN_CALLBACK EncFSCleanup(LPCWSTR FileName, WCHAR filePath[DOKAN_MAX_PATH]; GetFilePath(filePath, DOKAN_MAX_PATH, FileName); if (DokanFileInfo->Context) { - DbgPrint(L"Cleanup: %s %s\n", FileName, filePath); + DbgPrint(L"Cleanup: %s ; %s\n", FileName, filePath); EncFS::EncFSFile* encfsFile = (EncFS::EncFSFile*)DokanFileInfo->Context; DokanFileInfo->Context = 0; //printf("delB %x %x %x\n", encfsFile, DokanFileInfo->ProcessId, DokanFileInfo); @@ -624,7 +624,7 @@ static NTSTATUS DOKAN_CALLBACK EncFSReadFile(LPCWSTR FileName, LPVOID Buffer, encfsFile = (EncFS::EncFSFile*)DokanFileInfo->Context; } - DbgPrint(L"ReadFile : %s, handle = %ld\n", FileName, encfsFile->getHandle()); + DbgPrint(L"ReadFile : %s ; %s, handle = %ld\n", FileName, filePath, encfsFile->getHandle()); int32_t readLen; if (encfs.isReverse()) { @@ -684,7 +684,7 @@ static NTSTATUS DOKAN_CALLBACK EncFSWriteFile(LPCWSTR FileName, LPCVOID Buffer, GetFilePath(filePath, DOKAN_MAX_PATH, FileName); - DbgPrint(L"WriteFile : %s, offset %I64d, length %d\n", filePath, Offset, + DbgPrint(L"WriteFile : %s ; %s, offset %I64d, length %d\n", FileName, filePath, Offset, NumberOfBytesToWrite); // reopen the file @@ -787,7 +787,7 @@ EncFSFindFiles(LPCWSTR FileName, GetFilePath(filePath, DOKAN_MAX_PATH, FileName); - DbgPrint(L"FindFiles : %s\n", filePath); + DbgPrint(L"FindFiles : %s ; %s\n", FileName, filePath); fileLen = wcslen(filePath); if (filePath[fileLen - 1] != L'\\') { @@ -875,7 +875,7 @@ EncFSDeleteDirectory(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) { ZeroMemory(filePath, sizeof(filePath)); GetFilePath(filePath, DOKAN_MAX_PATH, FileName); - DbgPrint(L"DeleteDirectory %s - %d\n", filePath, + DbgPrint(L"DeleteDirectory %s ; %s - %d\n", FileName, filePath, DokanFileInfo->DeleteOnClose); if (!DokanFileInfo->DeleteOnClose) @@ -931,7 +931,7 @@ static NTSTATUS changeIVRecursive(LPCWSTR newFilePath, const string cOldPlainDir WCHAR newPath[DOKAN_MAX_PATH]; wcscpy_s(newPath, oldPath); - DbgPrint(L"ChangeIV: %s %s\n", cOldPlainDirPath, cNewPlainDirPath); + DbgPrint(L"ChangeIV: %s -> %s ; %s -> %s\n", cOldPlainDirPath, cNewPlainDirPath, newPath, oldPath); WIN32_FIND_DATAW find; ZeroMemory(&find, sizeof(WIN32_FIND_DATAW)); @@ -1020,11 +1020,11 @@ EncFSMoveFile(LPCWSTR FileName, // existing file name GetFilePath(filePath, DOKAN_MAX_PATH, FileName); GetFilePath(newFilePath, DOKAN_MAX_PATH, NewFileName); - DbgPrint(L"MoveFile %s -> %s\n\n", filePath, newFilePath); + DbgPrint(L"MoveFile %s -> %s ; %s -> %s\n", FileName, NewFileName, filePath, newFilePath); //PrintF(L"MoveFile %s -> %s\n", filePath, newFilePath); if (!DokanFileInfo->Context) { - DbgPrint(L"\tinvalid handle\n\n"); + DbgPrint(L"\tinvalid handle\n"); return STATUS_INVALID_HANDLE; } EncFS::EncFSFile* encfsFile = (EncFS::EncFSFile*)DokanFileInfo->Context; @@ -1114,7 +1114,7 @@ static NTSTATUS DOKAN_CALLBACK EncFSLockFile(LPCWSTR FileName, GetFilePath(filePath, DOKAN_MAX_PATH, FileName); - DbgPrint(L"LockFile %s\n", filePath); + DbgPrint(L"LockFile %s ; %s\n", FileName, filePath); if (!DokanFileInfo->Context) { DbgPrint(L"\tinvalid handle\n\n"); @@ -1202,7 +1202,7 @@ EncFSFlushFileBuffers(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) { GetFilePath(filePath, DOKAN_MAX_PATH, FileName); - DbgPrint(L"FlushFileBuffers : %s\n", filePath); + DbgPrint(L"FlushFileBuffers: %s ; %s\n", FileName, filePath); if (!DokanFileInfo->Context) { DbgPrint(L"\tinvalid handle\n\n"); @@ -1227,7 +1227,7 @@ static NTSTATUS DOKAN_CALLBACK EncFSSetEndOfFile( GetFilePath(filePath, DOKAN_MAX_PATH, FileName); - DbgPrint(L"SetEndOfFile %s, %I64d\n", filePath, ByteOffset); + DbgPrint(L"SetEndOfFile %s ; %s, %I64d\n", FileName, filePath, ByteOffset); if (!DokanFileInfo->Context) { DbgPrint(L"\tinvalid handle\n\n"); @@ -1252,7 +1252,7 @@ static NTSTATUS DOKAN_CALLBACK EncFSGetFileInformation( GetFilePath(filePath, DOKAN_MAX_PATH, FileName); - DbgPrint(L"GetFileInfo : %s\n", filePath); + DbgPrint(L"GetFileInfo : %s ; %s\n", FileName, filePath); EncFS::EncFSFile* encfsFile; BOOL opened = FALSE; @@ -1309,12 +1309,14 @@ static NTSTATUS DOKAN_CALLBACK EncFSGetFileInformation( HandleFileInformation->nFileSizeLow); } - // Caluclate file size - int64_t size = (HandleFileInformation->nFileSizeHigh * ((int64_t)MAXDWORD + 1)) + HandleFileInformation->nFileSizeLow; - size = encfs.isReverse() ? encfs.toEncodedLength(size) : encfs.toDecodedLength(size); - HandleFileInformation->nFileSizeLow = size & MAXDWORD; - HandleFileInformation->nFileSizeHigh = (size >> 32) & MAXDWORD; - DbgPrint(L"\tVirtualFileSize = %d\n", + if (!DokanFileInfo->IsDirectory) { + // Caluclate file size + int64_t size = (HandleFileInformation->nFileSizeHigh * ((int64_t)MAXDWORD + 1)) + HandleFileInformation->nFileSizeLow; + size = encfs.isReverse() ? encfs.toEncodedLength(size) : encfs.toDecodedLength(size); + HandleFileInformation->nFileSizeLow = size & MAXDWORD; + HandleFileInformation->nFileSizeHigh = (size >> 32) & MAXDWORD; + } + DbgPrint(L"\tLogical file size = %d\n", HandleFileInformation->nFileSizeLow); DbgPrint(L"FILE ATTRIBUTE = %d\n", HandleFileInformation->dwFileAttributes); @@ -1331,7 +1333,7 @@ EncFSDeleteFile(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) { WCHAR filePath[DOKAN_MAX_PATH]; GetFilePath(filePath, DOKAN_MAX_PATH, FileName); - DbgPrint(L"DeleteFile %s - %d\n", filePath, DokanFileInfo->DeleteOnClose); + DbgPrint(L"DeleteFile %s ; %s - %d\n", FileName, filePath, DokanFileInfo->DeleteOnClose); DWORD dwAttrib = GetFileAttributesW(filePath); @@ -1354,28 +1356,28 @@ EncFSDeleteFile(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) { static NTSTATUS DOKAN_CALLBACK EncFSSetAllocationSize( LPCWSTR FileName, LONGLONG AllocSize, PDOKAN_FILE_INFO DokanFileInfo) { WCHAR filePath[DOKAN_MAX_PATH]; - LARGE_INTEGER fileSize; GetFilePath(filePath, DOKAN_MAX_PATH, FileName); - DbgPrint(L"SetAllocationSize %s, %I64d\n", filePath, AllocSize); - //printf("AllocSize %d\n", AllocSize); + DbgPrint(L"SetAllocationSize %s ; %s, %I64d\n", FileName, filePath, AllocSize); - int64_t encodedLength = encfs.toEncodedLength(AllocSize); if (!DokanFileInfo->Context) { - DbgPrint(L"\tinvalid handle\n\n"); + DbgPrint(L"\tinvalid handle\n"); return STATUS_INVALID_HANDLE; } EncFS::EncFSFile* encfsFile = (EncFS::EncFSFile*)DokanFileInfo->Context; - if (GetFileSizeEx(encfsFile->getHandle(), &fileSize)) { - if (encodedLength < fileSize.QuadPart) { + LARGE_INTEGER encodedFileSize; + if (GetFileSizeEx(encfsFile->getHandle(), &encodedFileSize)) { + size_t decodedFileSize = encfs.toDecodedLength(encodedFileSize.QuadPart); + if (decodedFileSize < AllocSize) { if (!encfsFile->setLength(FileName, AllocSize)) { DWORD error = GetLastError(); - DbgPrint(L"\tSetFilePointer error: %d, offset = %I64d\n\n", error, + DbgPrint(L"\tSetFilePointer error: %d, offset = %I64d\n", error, AllocSize); return DokanNtStatusFromWin32(error); } + DbgPrint(L"Logical file size extended from %I64d to %I64d", decodedFileSize, AllocSize); } } else { @@ -1394,7 +1396,7 @@ static NTSTATUS DOKAN_CALLBACK EncFSSetFileAttributes( GetFilePath(filePath, DOKAN_MAX_PATH, FileName); - DbgPrint(L"SetFileAttributes %s 0x%x\n", filePath, FileAttributes); + DbgPrint(L"SetFileAttributes %s ; %s 0x%x\n", FileName, filePath, FileAttributes); if (FileAttributes != 0) { if (!SetFileAttributesW(filePath, FileAttributes)) { @@ -1423,7 +1425,7 @@ EncFSSetFileTime(LPCWSTR FileName, CONST FILETIME *CreationTime, GetFilePath(filePath, DOKAN_MAX_PATH, FileName); - DbgPrint(L"SetFileTime %s\n", filePath); + DbgPrint(L"SetFileTime %s ; %s\n", FileName, filePath); if (!DokanFileInfo->Context) { DbgPrint(L"\tinvalid handle\n\n"); @@ -1450,7 +1452,7 @@ EncFSUnlockFile(LPCWSTR FileName, LONGLONG ByteOffset, LONGLONG Length, GetFilePath(filePath, DOKAN_MAX_PATH, FileName); - DbgPrint(L"UnlockFile %s\n", filePath); + DbgPrint(L"UnlockFile %s ; %s\n", FileName, filePath); if (!DokanFileInfo->Context) { DbgPrint(L"\tinvalid handle\n\n"); @@ -1484,7 +1486,7 @@ static NTSTATUS DOKAN_CALLBACK EncFSGetFileSecurity( GetFilePath(filePath, DOKAN_MAX_PATH, FileName); - DbgPrint(L"GetFileSecurity %s\n", filePath); + DbgPrint(L"GetFileSecurity %s ; %s\n", FileName, filePath); EncFSCheckFlag(*SecurityInformation, FILE_SHARE_READ); EncFSCheckFlag(*SecurityInformation, OWNER_SECURITY_INFORMATION); @@ -1565,7 +1567,7 @@ static NTSTATUS DOKAN_CALLBACK EncFSSetFileSecurity( GetFilePath(filePath, DOKAN_MAX_PATH, FileName); - DbgPrint(L"SetFileSecurity %s\n", filePath); + DbgPrint(L"SetFileSecurity %s ; %s\n", FileName, filePath); if (!DokanFileInfo->Context) { DbgPrint(L"\tinvalid handle\n\n"); @@ -1599,8 +1601,8 @@ static NTSTATUS DOKAN_CALLBACK EncFSGetVolumeInformation( wcscpy_s(VolumeNameBuffer, VolumeNameSize, L"EncFS"); - if (VolumeSerialNumber) - *VolumeSerialNumber = 0x19831116; + // if (VolumeSerialNumber) + // *VolumeSerialNumber = 0x19831116; if (MaximumComponentLength) *MaximumComponentLength = 255; if (FileSystemFlags) @@ -1613,7 +1615,7 @@ static NTSTATUS DOKAN_CALLBACK EncFSGetVolumeInformation( volumeRoot[2] = '\\'; volumeRoot[3] = '\0'; - if (GetVolumeInformationW(volumeRoot, NULL, 0, NULL, MaximumComponentLength, + if (GetVolumeInformationW(volumeRoot, NULL, 0, VolumeSerialNumber, MaximumComponentLength, &fsFlags, FileSystemNameBuffer, FileSystemNameSize)) { @@ -1719,7 +1721,7 @@ EncFSFindStreams(LPCWSTR FileName, PFillFindStreamData FillFindStreamData, GetFilePath(filePath, DOKAN_MAX_PATH, FileName); - DbgPrint(L"FindStreams :%s\n", filePath); + DbgPrint(L"FindStreams :%s ; %s\n", FileName, filePath); hFind = FindFirstStreamW(filePath, FindStreamInfoStandard, &findData, 0); @@ -1767,9 +1769,11 @@ static NTSTATUS DOKAN_CALLBACK EncFSMounted(LPCWSTR MountPoint, DbgPrint(L"Mounted as %s\n", MountPoint); - wchar_t buff[20]; - swprintf(buff, sizeof(buff), L"%s:\\", MountPoint); - ShellExecute(NULL, NULL, buff, NULL, NULL, SW_SHOWNORMAL); + if (!g_efo.g_DebugMode) { + wchar_t buff[20]; + swprintf(buff, sizeof(buff), L"%s:\\", MountPoint); + ShellExecute(NULL, NULL, buff, NULL, NULL, SW_SHOWNORMAL); + } return STATUS_SUCCESS; } diff --git a/EncFSy_test/main.cpp b/EncFSy_test/main.cpp index 4cec02d..e17eae8 100644 --- a/EncFSy_test/main.cpp +++ b/EncFSy_test/main.cpp @@ -10,8 +10,31 @@ int main() { //const WCHAR* drive = L"G:\\"; //const WCHAR* file = L"G:\\Dokan\\TEST_FILE.txt"; - const WCHAR* drive = L"M:\\"; - const WCHAR* file = L"M:\\TEST_FILE.txt"; + const WCHAR* drive = L"O:\\"; + const WCHAR* file = L"O:\\TEST_FILE.txt"; + + // file information + { + DWORD dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; + DWORD dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; + DWORD dwCreationDisposition = OPEN_ALWAYS; + DWORD dwFlagsAndAttribute = FILE_ATTRIBUTE_NORMAL; + HANDLE h = CreateFileW(file, dwDesiredAccess, dwShareMode, NULL, + dwCreationDisposition, dwFlagsAndAttribute, NULL); + if (h == INVALID_HANDLE_VALUE) { + DWORD lastError = GetLastError(); + printf("CreateFileW ERROR: %d\n", lastError); + return -1; + } + TCHAR name[255]; + if (!GetFinalPathNameByHandle(h, name, 255, FILE_NAME_NORMALIZED)) { + DWORD lastError = GetLastError(); + printf("GetFinalPathNameByHandle ERROR: %d\n", lastError); + return -1; + } + wprintf(L"%s\n", name); + CloseHandle(h); + } // buffer mode { @@ -145,9 +168,122 @@ int main() if (!ReadFile(h, buff, SecBytes - 1, &readLen, NULL)) { DWORD lastError = GetLastError(); - printf("ReadFile error: %d\n", lastError); + printf("ReadFile error (normal): %d\n", lastError); + } + free(buff); + + CloseHandle(h); + } + + // expand shrink + { + DWORD dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; + DWORD dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; + DWORD dwCreationDisposition = CREATE_ALWAYS; + DWORD dwFlagsAndAttribute = FILE_ATTRIBUTE_NORMAL; + HANDLE h = CreateFileW(file, dwDesiredAccess, dwShareMode, NULL, + dwCreationDisposition, dwFlagsAndAttribute, NULL); + if (h == INVALID_HANDLE_VALUE) { + DWORD lastError = GetLastError(); + printf("CreateFileW ERROR: %d\n", lastError); + return -1; + } + + LARGE_INTEGER distanceToMove; + + // expand + distanceToMove.QuadPart = 3686L; + if (!SetFilePointerEx(h, distanceToMove, NULL, FILE_BEGIN)) { + DWORD lastError = GetLastError(); + printf("SetFilePointerEx ERROR: %d\n", lastError); + return -1; + } + if (!SetEndOfFile(h)) { + DWORD lastError = GetLastError(); + printf("SetEndOfFile ERROR: %d\n", lastError); + return -1; + } + + // expand + distanceToMove.QuadPart = 5529L; + if (!SetFilePointerEx(h, distanceToMove, NULL, FILE_BEGIN)) { + DWORD lastError = GetLastError(); + printf("SetFilePointerEx ERROR: %d\n", lastError); + return -1; + } + if (!SetEndOfFile(h)) { + DWORD lastError = GetLastError(); + printf("SetEndOfFile ERROR: %d\n", lastError); + return -1; + } + + // write + distanceToMove.QuadPart = 3686L; + if (!SetFilePointerEx(h, distanceToMove, NULL, FILE_BEGIN)) { + DWORD lastError = GetLastError(); + printf("SetFilePointerEx ERROR: %d\n", lastError); + return -1; + } + { + DWORD size = 4; + char* buff = (char*)malloc(size); + memset(buff, 'A', size); + DWORD readLen; + if (!WriteFile(h, buff, size, &readLen, NULL)) { + DWORD lastError = GetLastError(); + printf("WriteFile ERROR: %d\n", lastError); + return -1; + } + free(buff); } + // same size + distanceToMove.QuadPart = 5529L; + if (!SetFilePointerEx(h, distanceToMove, NULL, FILE_BEGIN)) { + DWORD lastError = GetLastError(); + printf("SetFilePointerEx ERROR: %d\n", lastError); + return -1; + } + if (!SetEndOfFile(h)) { + DWORD lastError = GetLastError(); + printf("SetEndOfFile ERROR: %d\n", lastError); + return -1; + } + + // shrink + distanceToMove.QuadPart = 4505L; + if (!SetFilePointerEx(h, distanceToMove, NULL, FILE_BEGIN)) { + DWORD lastError = GetLastError(); + printf("SetFilePointerEx ERROR: %d\n", lastError); + return -1; + } + if (!SetEndOfFile(h)) { + DWORD lastError = GetLastError(); + printf("SetEndOfFile ERROR: %d\n", lastError); + return -1; + } + + // write + distanceToMove.QuadPart = 3686L; + if (!SetFilePointerEx(h, distanceToMove, NULL, FILE_BEGIN)) { + DWORD lastError = GetLastError(); + printf("SetFilePointerEx ERROR: %d\n", lastError); + return -1; + } + { + DWORD size = 108; + char* buff = (char*)malloc(size); + memset(buff, 'A', size); + DWORD readLen; + if (!WriteFile(h, buff, size, &readLen, NULL)) { + DWORD lastError = GetLastError(); + printf("WriteFile ERROR: %d\n", lastError); + return -1; + } + free(buff); + } + + CloseHandle(h); } } diff --git a/installer/installer.nsi b/installer/installer.nsi index 6bdafd9..213b708 100644 --- a/installer/installer.nsi +++ b/installer/installer.nsi @@ -1,4 +1,4 @@ -!define VERSION "0.16" +!define VERSION "0.17" !include LogicLib.nsh !include x64.nsh