Skip to content

Commit

Permalink
Add support for subfolders
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Mar 28, 2022
1 parent 93d7666 commit b675014
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
40 changes: 31 additions & 9 deletions Encryption.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2019 NeuShield Inc.
* Copyright (C) 2022 NeuShield Inc.
*
* This software is provided 'as-is', without any express or implied warranty. In no event will the
* authors be held liable for any damages arising from the use of this software.
Expand All @@ -22,6 +22,7 @@
#include <vector>
#include <algorithm>
#include <iterator>
#include <shlwapi.h>
#include "NeuEncrypt.h"
#include "Encryption.h"

Expand Down Expand Up @@ -64,7 +65,7 @@ bool IsFileExist(const wchar_t *fileName)

void ReadDirectory(const std::wstring& name, const std::wstring& ext, wstringvec& v)
{
std::wstring pattern(name + L"\\*" + ext);
std::wstring pattern(name + L"\\*");

WIN32_FIND_DATA data;
HANDLE hFind = FindFirstFile(pattern.c_str(), &data);
Expand All @@ -75,7 +76,28 @@ void ReadDirectory(const std::wstring& name, const std::wstring& ext, wstringvec
{
if ((data.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM)) == 0)
{
v.push_back(data.cFileName);
WCHAR combinedPath[MAX_PATH] = { 0 };

if (PathCombine(combinedPath, name.c_str(), data.cFileName))
{
if (ext.empty() || wcscmp(PathFindExtension(data.cFileName), ext.c_str()) == 0)
{
v.push_back(combinedPath);
}
}
}
else if ((data.cFileName[0] == L'.' && data.cFileName[1] == L'\0') || (data.cFileName[0] == L'.' && data.cFileName[1] == L'.' && data.cFileName[2] == L'\0'))
{
continue;
}
else if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && ((data.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) == 0))
{
WCHAR combinedPath[MAX_PATH] = { 0 };

if (PathCombine(combinedPath, name.c_str(), data.cFileName))
{
ReadDirectory(combinedPath, ext, v);
}
}
} while (FindNextFile(hFind, &data));

Expand Down Expand Up @@ -193,9 +215,9 @@ void EncryptFiles()
std::wstring encryptName(originalName + encryptExt);

// Rename and encrypt file
RenameFile(encryptPath, originalName.c_str(), tempName.c_str());
EncryptSingleFile(encryptPath, tempName.c_str());
RenameFile(encryptPath, tempName.c_str(), encryptName.c_str());
RenameFile(LR"(\\?)", originalName.c_str(), tempName.c_str());
EncryptSingleFile(LR"(\\?)", tempName.c_str());
RenameFile(LR"(\\?)", tempName.c_str(), encryptName.c_str());
}

// Update GUI buttons
Expand All @@ -220,9 +242,9 @@ void DecryptFiles()
std::wstring encryptName(originalName + encryptExt);

// Rename and encrypt file
RenameFile(encryptPath, encryptName.c_str(), tempName.c_str());
EncryptSingleFile(encryptPath, tempName.c_str());
RenameFile(encryptPath, tempName.c_str(), originalName.c_str());
RenameFile(LR"(\\?)", encryptName.c_str(), tempName.c_str());
EncryptSingleFile(LR"(\\?)", tempName.c_str());
RenameFile(LR"(\\?)", tempName.c_str(), originalName.c_str());
}

// Update GUI buttons
Expand Down
2 changes: 1 addition & 1 deletion License.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2019 NeuShield Inc.
* Copyright (C) 2022 NeuShield Inc.
*
* This software is provided 'as-is', without any express or implied warranty. In no event will the
* authors be held liable for any damages arising from the use of this software.
Expand Down
5 changes: 2 additions & 3 deletions NeuEncrypt.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2019 NeuShield Inc.
* Copyright (C) 2022 NeuShield Inc.
*
* This software is provided 'as-is', without any express or implied warranty. In no event will the
* authors be held liable for any damages arising from the use of this software.
Expand Down Expand Up @@ -241,7 +241,6 @@ void OpenDialog()
if (folder_name)
{
UpdateEncryptFolder(folder_name);
SetEncryptFolderText();
SetButtonStatus();
CoTaskMemFree(folder_name);
folder_name = nullptr;
Expand All @@ -258,9 +257,9 @@ void InitDialog()
SendMessage(hwDlg, WM_SETICON, ICON_SMALL, (LPARAM)hCustomIcon);
}
CenterWindow(hwDlg);
LoadSettings();
SetButtonStatus();
SetEncryptFolderText();
LoadSettings();
}

// Message handler for about box.
Expand Down
Binary file modified NeuEncrypt.rc
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ No uninstallation is needed.
No configuration required.

### License
Copyright (C) 2019 NeuShield Inc.
Copyright (C) 2022 NeuShield Inc.

This software is provided 'as-is', without any express or implied warranty. In no event will the author(s) be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

Expand Down
4 changes: 2 additions & 2 deletions Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
// Main resource file details
#define APP_NAME "NeuEncrypt"
#define APP_MAJOR 1
#define APP_MINOR 0
#define APP_MINOR 1
#define APP_BUILDNUMBER 0
#define APP_REVISION 0
#define APP_COMPANYNAME "NeuShield Inc."
#define APP_DESCRPTION "Simulates ransomware encrypting a folder."
#define APP_COPYRIGHT "Copyright (C) 2019 NeuShield Inc."
#define APP_COPYRIGHT "Copyright (C) 2022 NeuShield Inc."
#define APP_ORIGINALVERSION "NeuEncrypt.exe"
#define APP_INTERNALNAME "NeuEncrypt"

Expand Down

0 comments on commit b675014

Please sign in to comment.