This commit is contained in:
DavidXanatos 2023-08-24 18:39:00 +02:00
parent 7e24d544ce
commit 11f95c3ecb
139 changed files with 33288 additions and 758 deletions

View File

@ -7,6 +7,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [1.11.0 / 5.66.0] - 2023-08-??
### Added
- added ImDisk driver integration, allowing to create boxes residing in a ramdisk
- added Encrypted Sandbox support, with this feature you can create confidential boxes not leaking data to the host pc
- Using the ImDisk Driver and a new ImBox component utilizing the cryptographic implementation from [DiskCryptor](https://diskcryptor.org/) the sandbox root fodler is stored in an encrypted container file.
- Using the SbieDrv to prevent processes not belonging to the sandbox from accessing a encrypted sandboxes root folder
- With the ConfidentialBox=y option host process read acess to sandboxed processes is blocked
- added certificate info to the about dialog
- added support for new more flexible certificate style
- added option for business customers to retrieve hardware-bound certificates from a serial number

View File

@ -30,6 +30,7 @@
#include "apps/common/RunBrowser.h"
#include "common/win32_ntddk.h"
#include "core/drv/api_defs.h"
#include "core/drv/verify.h"
//---------------------------------------------------------------------------
@ -156,14 +157,13 @@ BOOL CAboutDialog::OnInitDialog()
text.Format(L"%S\r\n%S", MY_COPYRIGHT_STRING, MY_COPYRIGHT_STRING_OLD);
GetDlgItem(ID_ABOUT_COPYRIGHT)->SetWindowText(text);
ULONG64 CertInfo = 0;
SCertInfo CertInfo = { 0 };
SbieApi_Call(API_QUERY_DRIVER_INFO, 3, -1, (ULONG_PTR)&CertInfo, sizeof(CertInfo));
if (CertInfo & 1) // valid
if (CertInfo.active)
GetDlgItem(ID_ABOUT_INFO)->SetWindowText(CMyMsg(MSG_7988));
else if (CertInfo & 2) // expired
else if (CertInfo.expired) // expired && !active -> outdated
GetDlgItem(ID_ABOUT_INFO)->SetWindowText(CMyMsg(MSG_7989));
GetDlgItem(IDOK)->SetWindowText(CMyMsg(MSG_3001));
return TRUE;

View File

@ -37,6 +37,7 @@
#include "core/drv/api_defs.h"
#include <time.h>
#include "core/svc/InteractiveWire.h"
#include "core/drv/verify.h"
@ -283,10 +284,9 @@ bool DoAboutDialog(bool bReminder)
if (g_bReminder) {
ULONG64 CertInfo = 0;
SCertInfo CertInfo = { 0 };
SbieApi_Call(API_QUERY_DRIVER_INFO, 3, -1, (ULONG_PTR)&CertInfo, sizeof(CertInfo));
if (CertInfo & 1) // valid
if (CertInfo.active)
return true;
time_t InstallDate = 0;

View File

@ -49,6 +49,7 @@
void List_Process_Ids(void);
int Terminate_All_Processes(BOOL all_boxes);
int Unmount_All_Boxes(BOOL all_boxes);
int Delete_All_Sandboxes();
extern WCHAR *DoRunDialog(HINSTANCE hInstance);
@ -77,6 +78,7 @@ extern "C" {
WCHAR BoxName[BOXNAME_COUNT];
WCHAR BoxKey[128+1];
PWSTR ChildCmdLine = NULL;
BOOL run_mail_agent = FALSE;
@ -607,6 +609,71 @@ BOOL Parse_Command_Line(void)
} else if (_wcsnicmp(cmd, L"terminate", 9) == 0) {
return die(Terminate_All_Processes(FALSE));
//
// Command line switch /unmount, /unmount_all
//
} else if (_wcsnicmp(cmd, L"unmount_all", 11) == 0) {
Terminate_All_Processes(TRUE);
return die(Unmount_All_Boxes(TRUE));
} else if (_wcsnicmp(cmd, L"unmount", 7) == 0) {
Terminate_All_Processes(FALSE);
return die(Unmount_All_Boxes(FALSE));
//
// Command line switch /key:[box password] /mount
//
} else if (_wcsnicmp(cmd, L"key:", 4) == 0) {
cmd += 4;
tmp = cmd;
//
// parameter specifies boxkey
//
WCHAR end = L' ';
if (*tmp == L'\"') {
++tmp;
++cmd;
end = L'\"';
}
while (*cmd && *cmd != end) {
++cmd;
}
if (tmp == cmd || (cmd - tmp > ARRAYSIZE(BoxKey)-1)) {
if (run_silent)
ExitProcess(ERROR_UNKNOWN_PROPERTY);
SetLastError(0);
Show_Error(SbieDll_FormatMessage1(MSG_3202, tmp));
return FALSE;
}
memzero(BoxKey, sizeof(BoxKey));
wcsncpy(BoxKey, tmp, (cmd - tmp));
if (end == L'\"')
++cmd;
} else if (_wcsnicmp(cmd, L"mount", 5) == 0) {
Validate_Box_Name();
return die(SbieDll_Mount(BoxName, BoxKey, FALSE) ? EXIT_SUCCESS : EXIT_FAILURE);
} else if (_wcsnicmp(cmd, L"mount_protected", 15) == 0) {
Validate_Box_Name();
return die(SbieDll_Mount(BoxName, BoxKey, TRUE) ? EXIT_SUCCESS : EXIT_FAILURE);
//
// Command line switch /listpids
@ -999,6 +1066,33 @@ int Terminate_All_Processes(BOOL all_boxes)
}
//---------------------------------------------------------------------------
// Unmount_All_Boxes
//---------------------------------------------------------------------------
int Unmount_All_Boxes(BOOL all_boxes)
{
if (all_boxes) {
int index = -1;
while (1) {
index = SbieApi_EnumBoxes(index, BoxName);
if (index == -1)
break;
SbieDll_Unmount(BoxName);
}
} else {
Validate_Box_Name();
SbieDll_Unmount(BoxName);
}
return EXIT_SUCCESS;
}
//---------------------------------------------------------------------------
// Program_Start
//---------------------------------------------------------------------------

View File

@ -91,11 +91,11 @@
#define SPOOLER_PORT_ID L"PrintSpooler"
#define WPAD_PORT_ID L"WPAD"
#define GAME_CONFIG_STORE_PORT_ID L"GamePort"
#define SMART_CARD_PORT_ID L"SmartCard"
#define BT_PORT_ID L"bthserv"
#define SSDP_PORT_ID L"ssdpsrv"
//#define WPAD_PORT_ID L"WPAD"
//#define GAME_CONFIG_STORE_PORT_ID L"GamePort"
//#define SMART_CARD_PORT_ID L"SmartCard"
//#define BT_PORT_ID L"bthserv"
//#define SSDP_PORT_ID L"ssdpsrv"
//---------------------------------------------------------------------------

View File

@ -228,8 +228,6 @@ typedef struct __PUBLIC_OBJECT_TYPE_INFORMATION {
ULONG Reserved [22]; // reserved for internal use
BYTE ExtraPadding[48]; // NtQueryObject often requires more space than MSDN says
} PUBLIC_OBJECT_TYPE_INFORMATION, *PPUBLIC_OBJECT_TYPE_INFORMATION;
__declspec(dllimport) NTSTATUS __stdcall

View File

@ -105,6 +105,9 @@ SbieDll_AssocQueryProgram=_SbieDll_AssocQueryProgram@4
SbieDll_KillAll=_SbieDll_KillAll@8
SbieDll_KillOne=_SbieDll_KillOne@4
SbieDll_Mount=_SbieDll_Mount@12
SbieDll_Unmount=_SbieDll_Unmount@4
SbieDll_RegisterDllCallback=_SbieDll_RegisterDllCallback@4
SbieDll_RunFromHome=_SbieDll_RunFromHome@16
SbieDll_RunSandboxed=_SbieDll_RunSandboxed@24

View File

@ -423,7 +423,7 @@ _FX NTSTATUS File_MigrateFile(
WCHAR size_str[32];
Sbie_snwprintf(size_str, 32, L"%I64u", file_size);
const WCHAR* strings[] = { Dll_BoxName, TruePath, size_str, NULL };
SbieApi_LogMsgExt(2198, strings);
SbieApi_LogMsgExt(-1, 2198, strings);
}
}

View File

@ -585,7 +585,7 @@ _FX void File_DoAutoRecover_2(BOOLEAN force, ULONG ticks)
status = File_GetName(NULL, &uni, &TruePath, &CopyPath, NULL);
const WCHAR* strings[] = { Dll_BoxName, rec->path, CopyPath, NULL };
SbieApi_LogMsgExt(2199, strings);
SbieApi_LogMsgExt(-1, 2199, strings);
}
List_Remove(&File_RecPaths, rec);
}

View File

@ -426,6 +426,7 @@ _FX LONG SbieApi_LogMsgEx(
_FX LONG SbieApi_LogMsgExt(
ULONG session_id,
ULONG msgid,
const WCHAR** strings)
{
@ -446,7 +447,7 @@ _FX LONG SbieApi_LogMsgExt(
temp += len;
}
status = SbieApi_LogMsgEx(-1, msgid, buff, (USHORT)size);
status = SbieApi_LogMsgEx(session_id, msgid, buff, (USHORT)size);
Dll_Free(buff);

View File

@ -88,7 +88,7 @@ SBIEAPI_EXPORT LONG SbieApi_LogMsgEx(
ULONG session_id, ULONG msgid, const WCHAR* msg_data, USHORT msg_len);
SBIEAPI_EXPORT LONG SbieApi_LogMsgExt(
ULONG msgid, const WCHAR** strings);
ULONG session_id, ULONG msgid, const WCHAR** strings);
SBIEAPI_EXPORT
LONG SbieApi_GetHomePath(

View File

@ -102,6 +102,10 @@ SBIEDLL_EXPORT BOOLEAN SbieDll_KillOne(ULONG ProcessId);
SBIEDLL_EXPORT BOOLEAN SbieDll_KillAll(
ULONG SessionId, const WCHAR *BoxName);
SBIEDLL_EXPORT BOOLEAN SbieDll_Mount(const WCHAR *BoxName, const WCHAR * BoxKey, BOOLEAN Protect);
SBIEDLL_EXPORT BOOLEAN SbieDll_Unmount(const WCHAR *BoxName);
SBIEDLL_EXPORT ULONG SbieDll_GetTokenElevationType(void);
SBIEDLL_EXPORT WCHAR *SbieDll_FormatMessage(ULONG code, const WCHAR **ins);
@ -233,6 +237,8 @@ SBIEDLL_EXPORT BOOLEAN SbieDll_GetBorderColor(const WCHAR* box_name, COLORREF*
SBIEDLL_EXPORT BOOLEAN SbieDll_IsReservedFileName(const WCHAR* name);
SBIEDLL_EXPORT PSECURITY_DESCRIPTOR SbieDll_GetPublicSD();
SBIEDLL_EXPORT const WCHAR* SbieDll_FindArgumentEnd(const WCHAR* arguments);
SBIEDLL_EXPORT void DbgPrint(const char* format, ...);

View File

@ -357,6 +357,20 @@ void Secure_InitSecurityDescriptors(void)
}
//---------------------------------------------------------------------------
// SbieDll_GetPublicSD
//---------------------------------------------------------------------------
_FX PSECURITY_DESCRIPTOR SbieDll_GetPublicSD()
{
if (!Secure_EveryoneSD)
Secure_InitSecurityDescriptors();
return Secure_EveryoneSD;
}
//---------------------------------------------------------------------------
// Secure_Init
//---------------------------------------------------------------------------

View File

@ -31,6 +31,8 @@
#include "core/svc/msgids.h"
#include "core/svc/SbieIniWire.h"
#include "core/svc/ProcessWire.h"
#include "core/drv/api_defs.h"
#include "core/svc/MountManagerWire.h"
#include "common/my_version.h"
@ -378,6 +380,80 @@ _FX BOOLEAN SbieDll_KillAll(ULONG SessionId, const WCHAR *BoxName)
}
//---------------------------------------------------------------------------
// SbieDll_Mount
//---------------------------------------------------------------------------
_FX BOOLEAN SbieDll_Mount(const WCHAR* BoxName, const WCHAR* BoxKey, BOOLEAN Protect)
{
ULONG req_len;
IMBOX_MOUNT_REQ* req;
MSG_HEADER *rpl = NULL;
ULONG file_path_len = 0;
ULONG reg_path_len;
BOOLEAN ok = FALSE;
if (!NT_SUCCESS(SbieApi_QueryBoxPath(BoxName, NULL, NULL, NULL, &file_path_len, NULL, NULL)))
return FALSE;
req_len = sizeof(IMBOX_MOUNT_REQ) + file_path_len;
req = Dll_Alloc(req_len);
req->h.length = req_len;
req->h.msgid = MSGID_IMBOX_MOUNT;
wcscpy(req->password, BoxKey);
req->protect_root = Protect;
req->auto_unmount = FALSE;
reg_path_len = MAX_REG_ROOT_LEN;
if (NT_SUCCESS(SbieApi_QueryBoxPath(BoxName, req->file_root, req->reg_root, NULL, &file_path_len, &reg_path_len, NULL))) {
rpl = SbieDll_CallServer(&req->h);
}
Dll_Free(req);
if (rpl) {
if (rpl->status == 0)
ok = TRUE;
Dll_Free(rpl);
}
return ok;
}
//---------------------------------------------------------------------------
// SbieDll_Unmount
//---------------------------------------------------------------------------
_FX BOOLEAN SbieDll_Unmount(const WCHAR *BoxName)
{
IMBOX_UNMOUNT_REQ req;
MSG_HEADER *rpl;
BOOLEAN ok = FALSE;
req.h.length = sizeof(IMBOX_UNMOUNT_REQ);
req.h.msgid = MSGID_IMBOX_UNMOUNT;
ULONG reg_len = MAX_REG_ROOT_LEN;
if (!NT_SUCCESS(SbieApi_QueryBoxPath(BoxName, NULL, req.reg_root, NULL, NULL, &reg_len, NULL)))
return FALSE;
rpl = SbieDll_CallServer(&req.h);
if (rpl) {
if (rpl->status == 0)
ok = TRUE;
Dll_Free(rpl);
}
return ok;
}
//---------------------------------------------------------------------------
// Dll_SidStringToSid
//---------------------------------------------------------------------------

View File

@ -613,8 +613,8 @@ _FX NTSTATUS Api_LogMessage(PROCESS *proc, ULONG64 *parms)
msgid = MSG_1314;
else if (msgid == 1307)
msgid = MSG_1307;
else if (msgid == 6004)
msgid = MSG_6004;
else if (msgid == 6004 || msgid == 6008 || msgid == 6009)
msgid = msgid - 6001 + MSG_6001;
else
msgid = MSG_2301; // unknown message

View File

@ -758,9 +758,9 @@ _FX NTSTATUS KphValidateCertificate()
expiration_date.QuadPart = cert_date.QuadPart + KphGetDateInterval((CSHORT)(level ? _wtoi(level) : 7), 0, 0); // x days, default 7
Verify_CertInfo.level = eCertAdvanced;
}
else if (level && _wcsicmp(type, L"STANDARD") == 0)
else if (level && _wcsicmp(level, L"STANDARD") == 0)
Verify_CertInfo.level = eCertStandard;
else if (level && _wcsicmp(type, L"ADVANCED") == 0)
else if (level && _wcsicmp(level, L"ADVANCED") == 0)
Verify_CertInfo.level = eCertAdvanced;
// scheme 1.1 >>>
else if (CERT_IS_TYPE(Verify_CertInfo, eCertPersonal) || CERT_IS_TYPE(Verify_CertInfo, eCertPatreon))

View File

@ -82,10 +82,10 @@ enum ECertLevel {
eCertMaxLevel = 0b111,
};
#define CERT_IS_TYPE(cert,t) ((cert.type & 0b11100) == t)
#define CERT_IS_TYPE(cert,t) ((cert.type & 0b11100) == (unsigned long)(t))
#define CERT_IS_SUBSCRIPTION(cert) (CERT_IS_TYPE(cert, eCertBusiness) || CERT_IS_TYPE(cert, eCertSubscription) || cert.type == eCertEntryPatreon || CERT_IS_TYPE(cert, eCertEvaluation))
#define CERT_IS_INSIDER(cert) (CERT_IS_TYPE(cert, eCertEternal) || cert.type == eCertGreatPatreon)
#define CERT_IS_LEVEL(cert,l) (cert.active && cert.level >= l)
#define CERT_IS_LEVEL(cert,l) (cert.active && cert.level >= (unsigned long)(l))
#ifdef KERNEL_MODE
extern SCertInfo Verify_CertInfo;

View File

@ -35,6 +35,7 @@
#include "core/dll/sbiedll.h"
#include "core/drv/api_defs.h"
#include "sbieiniserver.h"
#include "MountManager.h"
//---------------------------------------------------------------------------
// Variables
@ -290,7 +291,7 @@ void DriverAssist::MsgWorkerThread(void *MyMsg)
}
else if (msgid == SVC_MOUNTED_HIVE) {
MountedHive(data_ptr);
HiveMounted(data_ptr);
}
else if (msgid == SVC_UNMOUNT_HIVE) {
@ -583,40 +584,66 @@ BOOL VolHas8dot3Support(WCHAR* path)
//---------------------------------------------------------------------------
// MountedHive
// HiveMounted
//---------------------------------------------------------------------------
void DriverAssist::MountedHive(void *_msg)
void DriverAssist::HiveMounted(void *_msg)
{
SVC_REGHIVE_MSG *msg = (SVC_REGHIVE_MSG *)_msg;
ULONG errlvl = 0;
WCHAR* file_root_path = NULL;
WCHAR* reg_root_path = NULL;
ULONG file_len = 0;
ULONG reg_len = 0;
if (!NT_SUCCESS(SbieApi_QueryProcessPath((HANDLE)msg->process_id, NULL, NULL, NULL, &file_len, &reg_len, NULL))) {
errlvl = 0x12;
goto finish;
}
file_root_path = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, file_len + 16);
reg_root_path = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, reg_len + 16);
if (!file_root_path || !reg_root_path) {
errlvl = 0x13;
goto finish;
}
if (!NT_SUCCESS(SbieApi_QueryProcessPath((HANDLE)msg->process_id, file_root_path, reg_root_path, NULL, &file_len, &reg_len, NULL))) {
errlvl = 0x14;
goto finish;
}
//
// lock box root if present
//
MountManager::GetInstance()->LockBoxRoot(reg_root_path, msg->session_id);
//
// check if the box is located on a volume without 8.3 naming
// as this may cause issues with old installers
//
if (SbieApi_QueryConfBool(msg->boxname, L"EnableVerboseChecks", FALSE)) {
NTSTATUS status;
ULONG len = 0;
WCHAR* path;
if (SbieDll_TranslateNtToDosPath(reg_root_path)) { // wcslen(reg_root_path) > 22 &&
status = SbieApi_QueryBoxPath(msg->boxname, NULL, NULL, NULL, &len, NULL, NULL);
if (status != 0) return;
if (!VolHas8dot3Support(reg_root_path)) {
path = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, len + 16);
if (!path) return;
status = SbieApi_QueryBoxPath(msg->boxname, path, NULL, NULL, &len, NULL, NULL);
if (status == 0 && wcslen(path) > 22) {
if (SbieDll_TranslateNtToDosPath(path)) {
if (!VolHas8dot3Support(path)) {
SbieApi_LogEx(msg->session_id, 2227, L"%S (%S)", msg->boxname, path);
}
SbieApi_LogEx(msg->session_id, 2227, L"%S (%S)", msg->boxname, reg_root_path);
}
}
HeapFree(GetProcessHeap(), 0, path);
}
//
// finish
//
finish:
if (file_root_path)
HeapFree(GetProcessHeap(), 0, file_root_path);
if (reg_root_path)
HeapFree(GetProcessHeap(), 0, reg_root_path);
}
@ -697,7 +724,7 @@ void DriverAssist::UnmountHive(void *_msg)
while (ShouldUnmount) {
WCHAR root_path[256];
WCHAR root_path[MAX_REG_ROOT_LEN];
UNICODE_STRING root_uni;
OBJECT_ATTRIBUTES root_objattrs;
HANDLE root_key;
@ -726,6 +753,15 @@ void DriverAssist::UnmountHive(void *_msg)
NtClose(root_key);
}
if (rc == 0) {
//
// unmount box container if present
//
MountManager::GetInstance()->ReleaseBoxRoot(root_path, false, msg->session_id);
}
if (rc != 0)
SbieApi_LogEx(msg->session_id, 2208, L"[%08X]", rc);

View File

@ -91,7 +91,7 @@ private:
// mounted registry hive
//
void MountedHive(void *_msg);
void HiveMounted(void *_msg);
//
// unmount registry hive

View File

@ -57,7 +57,9 @@ void DriverAssist::InjectLow(void *_msg)
NTSTATUS status = 0;
ULONG errlvl = 0;
UCHAR SandboxieLogonSid[SECURITY_MAX_SID_SIZE] = { 0 };
WCHAR* file_root_path = NULL;
WCHAR* reg_root_path = NULL;
//
// open new process and verify process creation time
//
@ -70,10 +72,36 @@ void DriverAssist::InjectLow(void *_msg)
}
WCHAR boxname[BOXNAME_COUNT];
WCHAR exename[99];
errlvl = SbieApi_QueryProcessEx2((HANDLE)msg->process_id, 96, boxname, exename, NULL, NULL, NULL);
if (errlvl != 0)
goto finish;
if (!NT_SUCCESS(SbieApi_QueryProcessEx2((HANDLE)msg->process_id, 0, boxname, NULL, NULL, NULL, NULL))) {
errlvl = 0x11;
goto finish;
}
ULONG file_len = 0;
ULONG reg_len = 0;
if (!NT_SUCCESS(SbieApi_QueryProcessPath((HANDLE)msg->process_id, NULL, NULL, NULL, &file_len, &reg_len, NULL))) {
errlvl = 0x12;
goto finish;
}
file_root_path = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, file_len + 16);
reg_root_path = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, reg_len + 16);
if (!file_root_path || !reg_root_path) {
errlvl = 0x13;
goto finish;
}
if (!NT_SUCCESS(SbieApi_QueryProcessPath((HANDLE)msg->process_id, file_root_path, reg_root_path, NULL, &file_len, &reg_len, NULL))) {
errlvl = 0x14;
goto finish;
}
//
// notify the box manager about a new process
//
//BOOLEAN IsFirst = FALSE;
//if (!msg->bHostInject) {
// IsFirst = BoxManager::GetInstance()->ProcessCreated(msg->process_id, boxname, reg_root_path, msg->session_id);
//}
//
// inject the lowlevel.dll into the target process
@ -91,6 +119,7 @@ void DriverAssist::InjectLow(void *_msg)
// NoSbieCons BEGIN
sbieLow.bNoConsole = SbieApi_QueryConfBool(boxname, L"NoSecurityIsolation", FALSE) || SbieApi_QueryConfBool(boxname, L"NoSandboxieConsole", FALSE);
// NoSbieCons END
//sbieLow.bIsFirst = IsFirst;
errlvl = SbieDll_InjectLow(hProcess, sbieLow.init_flags, TRUE);
if(errlvl != 0)
@ -114,6 +143,17 @@ void DriverAssist::InjectLow(void *_msg)
}
}
//
// mount box container if needed
//
//if (IsFirst) {
if (!MountManager::GetInstance()->AcquireBoxRoot(boxname, reg_root_path, file_root_path, msg->session_id)) {
errlvl = 0xAA;
goto finish;
}
//}
//
// notify driver that we successfully injected the lowlevel code
//
@ -133,6 +173,10 @@ void DriverAssist::InjectLow(void *_msg)
//
finish:
if (file_root_path)
HeapFree(GetProcessHeap(), 0, file_root_path);
if (reg_root_path)
HeapFree(GetProcessHeap(), 0, reg_root_path);
#ifdef _M_ARM64
if (errlvl == -1)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,99 @@
/*
* Copyright 2023 David Xanatos, xanasoft.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Mount Manager
//---------------------------------------------------------------------------
#ifndef _MY_MOUNTMANAGER_H
#define _MY_MOUNTMANAGER_H
#include <windows.h>
#include "common/win32_ntddk.h"
#include "common/list.h"
#include "common/map.h"
#include "common/pool.h"
#include "PipeServer.h"
#include <string>
#include <map>
#include <list>
#include <vector>
#include <memory>
struct BOX_MOUNT;
struct BOX_ROOT;
class MountManager
{
public:
MountManager(PipeServer *pipeServer);
static MountManager *GetInstance();
static void Shutdown();
bool AcquireBoxRoot(const WCHAR* boxname, const WCHAR* reg_root, const WCHAR* file_root, ULONG session_id);
void LockBoxRoot(const WCHAR* reg_root, ULONG session_id);
void ReleaseBoxRoot(const WCHAR* reg_root, bool force, ULONG session_id);
protected:
static MSG_HEADER *Handler(void *_this, MSG_HEADER *msg);
MSG_HEADER *CreateHandler(MSG_HEADER *msg);
MSG_HEADER *MountHandler(MSG_HEADER *msg);
MSG_HEADER *UnmountHandler(MSG_HEADER *msg);
MSG_HEADER *EnumHandler(MSG_HEADER *msg);
MSG_HEADER *QueryHandler(MSG_HEADER *msg);
MSG_HEADER *UpdateHandler(MSG_HEADER *msg);
//static DWORD CleanUp(LPVOID lpThreadParameter);
void UnmountAll();
std::shared_ptr<BOX_ROOT> GetBoxRootLocked(const WCHAR* reg_root, bool bCanAdd, ULONG session_id = -1);
std::wstring GetImageFileName(const WCHAR* file_root);
std::wstring GetProxyName(const std::wstring& ImageFile);
HANDLE OpenOrCreateNtFolder(const WCHAR* NtPath);
int CreateJunction(const std::wstring& TargetNtPath, const std::wstring& FileRootPath, ULONG session_id);
bool RemoveJunction(const std::wstring& FileRootPath, ULONG session_id);
std::shared_ptr<BOX_MOUNT> FindImDisk(const std::wstring& ImageFile, ULONG session_id);
std::shared_ptr<BOX_MOUNT> MountImDisk(const std::wstring& ImageFile, const wchar_t* pPassword, ULONG64 sizeKb, ULONG session_id);
static bool TryUnmountImDisk(const std::wstring& Device, HANDLE hProcess, int iMode = 0);
static bool UnmountImDisk(const std::wstring& Device, HANDLE hProcess);
bool UnmountImDiskLocked(const std::shared_ptr<BOX_MOUNT>& pToUnMount, ULONG session_id);
std::shared_ptr<BOX_MOUNT> GetRamDisk(ULONG session_id);
CRITICAL_SECTION m_CritSec;
std::shared_ptr<BOX_MOUNT> m_RamDisk;
std::map<std::wstring, std::shared_ptr<BOX_ROOT> > m_RootMap;
//HANDLE m_hCleanUpThread;
static MountManager* m_instance;
};
#endif /* _MY_MOUNTMANAGER_H */

View File

@ -0,0 +1,394 @@
/*
* Copyright 2023 David Xanatos, xanasoft.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Mount Manager Helpers
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "common/win32_ntddk.h"
#include <winioctl.h>
#include <string>
#include <map>
#include <list>
#include <vector>
#include <memory>
std::wstring GetVolumeLabel(const std::wstring &NtPath)
{
std::wstring Label;
HANDLE handle;
IO_STATUS_BLOCK iosb;
UNICODE_STRING objname;
RtlInitUnicodeString(&objname, NtPath.c_str());
OBJECT_ATTRIBUTES objattrs;
InitializeObjectAttributes(
&objattrs, &objname, OBJ_CASE_INSENSITIVE, NULL, NULL);
ULONG OldMode;
RtlSetThreadErrorMode(0x10u, &OldMode);
NTSTATUS status = NtCreateFile(
&handle, GENERIC_READ | SYNCHRONIZE, &objattrs,
&iosb, NULL, 0, FILE_SHARE_VALID_FLAGS,
FILE_OPEN,
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT,
NULL, 0);
RtlSetThreadErrorMode(OldMode, 0i64);
if (NT_SUCCESS(status))
{
union {
FILE_FS_VOLUME_INFORMATION volumeInfo;
BYTE volumeInfoBuff[64];
} u;
if (NT_SUCCESS(NtQueryVolumeInformationFile(handle, &iosb, &u.volumeInfo, sizeof(u), FileFsVolumeInformation)))
Label = std::wstring(u.volumeInfo.VolumeLabel, u.volumeInfo.VolumeLabelLength / sizeof(WCHAR));
NtClose(handle);
}
return Label;
}
extern "C" {
// ImDisk
// Base names for device objects created in \Device
#define IMDISK_DEVICE_DIR_NAME L"\\Device"
#define IMDISK_DEVICE_BASE_NAME IMDISK_DEVICE_DIR_NAME L"\\ImDisk"
#define IMDISK_CTL_DEVICE_NAME IMDISK_DEVICE_BASE_NAME L"Ctl"
#define IMDISK_DRIVER_VERSION 0x0103
// Base value for the IOCTL's.
#define FILE_DEVICE_IMDISK 0x8372
#define IOCTL_IMDISK_QUERY_VERSION ((ULONG) CTL_CODE(FILE_DEVICE_IMDISK, 0x800, METHOD_BUFFERED, 0))
#define IOCTL_IMDISK_CREATE_DEVICE ((ULONG) CTL_CODE(FILE_DEVICE_IMDISK, 0x801, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS))
#define IOCTL_IMDISK_QUERY_DEVICE ((ULONG) CTL_CODE(FILE_DEVICE_IMDISK, 0x802, METHOD_BUFFERED, 0))
#define IOCTL_IMDISK_QUERY_DRIVER ((ULONG) CTL_CODE(FILE_DEVICE_IMDISK, 0x803, METHOD_BUFFERED, 0))
#define IOCTL_IMDISK_REFERENCE_HANDLE ((ULONG) CTL_CODE(FILE_DEVICE_IMDISK, 0x804, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS))
#define IOCTL_IMDISK_SET_DEVICE_FLAGS ((ULONG) CTL_CODE(FILE_DEVICE_IMDISK, 0x805, METHOD_BUFFERED, 0))
#define IOCTL_IMDISK_REMOVE_DEVICE ((ULONG) CTL_CODE(FILE_DEVICE_IMDISK, 0x806, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS))
#define IOCTL_IMDISK_IOCTL_PASS_THROUGH ((ULONG) CTL_CODE(FILE_DEVICE_IMDISK, 0x807, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS))
#define IOCTL_IMDISK_FSCTL_PASS_THROUGH ((ULONG) CTL_CODE(FILE_DEVICE_IMDISK, 0x808, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS))
#define IOCTL_IMDISK_GET_REFERENCED_HANDLE ((ULONG) CTL_CODE(FILE_DEVICE_IMDISK, 0x809, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS))
typedef struct _IMDISK_CREATE_DATA
{
/// On create this can be set to IMDISK_AUTO_DEVICE_NUMBER
ULONG DeviceNumber;
/// Total size in bytes (in the Cylinders field) and virtual geometry.
DISK_GEOMETRY DiskGeometry;
/// The byte offset in the image file where the virtual disk begins.
LARGE_INTEGER ImageOffset;
/// Creation flags. Type of device and type of connection.
ULONG Flags;
/// Drive letter (if used, otherwise zero).
WCHAR DriveLetter;
/// Length in bytes of the FileName member.
USHORT FileNameLength;
/// Dynamically-sized member that specifies the image file name.
WCHAR FileName[1];
} IMDISK_CREATE_DATA, *PIMDISK_CREATE_DATA;
/// Virtual disk is backed by image file
#define IMDISK_TYPE_FILE 0x00000100
/// Virtual disk is backed by virtual memory
#define IMDISK_TYPE_VM 0x00000200
/// Virtual disk is backed by proxy connection
#define IMDISK_TYPE_PROXY 0x00000300
/// Extracts the IMDISK_TYPE_xxx from flags
#define IMDISK_TYPE(x) ((ULONG)(x) & 0x00000F00)
HANDLE WINAPI ImDiskOpenDeviceByName(PUNICODE_STRING FileName, DWORD AccessMode)
{
NTSTATUS status;
HANDLE handle;
OBJECT_ATTRIBUTES object_attrib;
IO_STATUS_BLOCK io_status;
InitializeObjectAttributes(&object_attrib,
FileName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
status = NtOpenFile(&handle,
SYNCHRONIZE | AccessMode,
&object_attrib,
&io_status,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT);
if (!NT_SUCCESS(status))
{
SetLastError(RtlNtStatusToDosError(status));
return INVALID_HANDLE_VALUE;
}
return handle;
}
//HANDLE WINAPI ImDiskOpenDeviceByNumber(DWORD DeviceNumber, DWORD AccessMode)
//{
// WCHAR device_path[_countof(IMDISK_DEVICE_BASE_NAME) + 16];
//
// UNICODE_STRING file_name;
//
// // Build device path, e.g. \Device\ImDisk2
// _snwprintf_s(device_path, ARRAYSIZE(device_path), _countof(device_path),
// IMDISK_DEVICE_BASE_NAME L"%u", DeviceNumber);
// device_path[_countof(device_path) - 1] = 0;
//
// RtlInitUnicodeString(&file_name, device_path);
//
// return ImDiskOpenDeviceByName(&file_name, AccessMode);
//}
HANDLE WINAPI ImDiskOpenDeviceByMountPoint(LPCWSTR MountPoint, DWORD AccessMode)
{
UNICODE_STRING DeviceName;
WCHAR DriveLetterPath[] = L"\\DosDevices\\ :";
PREPARSE_DATA_BUFFER ReparseData = NULL;
HANDLE h;
if ((MountPoint[0] != 0) &&
((wcscmp(MountPoint + 1, L":") == 0) ||
(wcscmp(MountPoint + 1, L":\\") == 0)))
{
DriveLetterPath[12] = MountPoint[0];
RtlInitUnicodeString(&DeviceName, DriveLetterPath);
}
else if (((wcsncmp(MountPoint, L"\\\\?\\", 4) == 0) ||
(wcsncmp(MountPoint, L"\\\\.\\", 4) == 0)) &&
(wcschr(MountPoint + 4, L'\\') == NULL))
{
return CreateFile(MountPoint, AccessMode,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
}
else
{
HANDLE hDir;
DWORD dw;
DWORD buffer_size =
FIELD_OFFSET(REPARSE_DATA_BUFFER, MountPointReparseBuffer) +
MAXIMUM_REPARSE_DATA_BUFFER_SIZE;
hDir = CreateFile(MountPoint, GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS |
FILE_FLAG_OPEN_REPARSE_POINT, NULL);
if (hDir == INVALID_HANDLE_VALUE)
return INVALID_HANDLE_VALUE;
ReparseData = (PREPARSE_DATA_BUFFER)HeapAlloc(GetProcessHeap(),
HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY,
buffer_size);
if (!DeviceIoControl(hDir, FSCTL_GET_REPARSE_POINT,
NULL, 0,
ReparseData, buffer_size,
&dw, NULL))
{
DWORD last_error = GetLastError();
CloseHandle(hDir);
HeapFree(GetProcessHeap(), 0, ReparseData);
SetLastError(last_error);
return INVALID_HANDLE_VALUE;
}
CloseHandle(hDir);
if (ReparseData->ReparseTag != IO_REPARSE_TAG_MOUNT_POINT)
{
HeapFree(GetProcessHeap(), 0, ReparseData);
SetLastError(ERROR_NOT_A_REPARSE_POINT);
return INVALID_HANDLE_VALUE;
}
DeviceName.Length =
ReparseData->MountPointReparseBuffer.SubstituteNameLength;
DeviceName.Buffer = (PWSTR)
((PUCHAR)ReparseData->MountPointReparseBuffer.PathBuffer +
ReparseData->MountPointReparseBuffer.SubstituteNameOffset);
DeviceName.MaximumLength = DeviceName.Length;
}
if (DeviceName.Buffer[(DeviceName.Length >> 1) - 1] == L'\\')
{
DeviceName.Buffer[(DeviceName.Length >> 1) - 1] = 0;
DeviceName.Length -= 2;
}
h = ImDiskOpenDeviceByName(&DeviceName, AccessMode);
if (ReparseData != NULL)
HeapFree(GetProcessHeap(), 0, ReparseData);
return h;
}
BOOL WINAPI IsImDiskDriverReady()
{
BOOL bRet = FALSE;
UNICODE_STRING objname;
RtlInitUnicodeString(&objname, IMDISK_CTL_DEVICE_NAME);
HANDLE Device = ImDiskOpenDeviceByName(&objname, GENERIC_READ | GENERIC_WRITE);
if (Device != INVALID_HANDLE_VALUE)
{
DWORD VersionCheck;
DWORD BytesReturned;
if (DeviceIoControl(Device, IOCTL_IMDISK_QUERY_VERSION, NULL, 0, &VersionCheck, sizeof VersionCheck, &BytesReturned, NULL))
{
if (BytesReturned >= sizeof(VersionCheck))
bRet = (VersionCheck == IMDISK_DRIVER_VERSION);
}
CloseHandle(Device);
}
return bRet;
}
BOOL WINAPI ImDiskGetDeviceListEx(IN ULONG ListLength, OUT ULONG *DeviceList)
{
UNICODE_STRING file_name;
HANDLE driver;
ULONG dw;
RtlInitUnicodeString(&file_name, IMDISK_CTL_DEVICE_NAME);
driver = ImDiskOpenDeviceByName(&file_name, GENERIC_READ);
if (driver == INVALID_HANDLE_VALUE)
return 0;
if (!DeviceIoControl(driver,
IOCTL_IMDISK_QUERY_DRIVER,
NULL, 0,
DeviceList, ListLength << 2,
&dw, NULL))
{
DWORD dwLastError = GetLastError();
NtClose(driver);
SetLastError(dwLastError);
return FALSE;
}
NtClose(driver);
if ((dw == sizeof(ULONG)) &
(*DeviceList > 0))
{
SetLastError(ERROR_MORE_DATA);
return FALSE;
}
SetLastError(NO_ERROR);
return TRUE;
}
WCHAR WINAPI ImDiskFindFreeDriveLetter()
{
DWORD logical_drives = GetLogicalDrives();
WCHAR search;
for (search = L'Z'; search >= L'I'; search--)
{
if ((logical_drives & (1 << (search - L'A'))) == 0)
{
return search;
}
}
return 0;
}
}
std::wstring ImDiskQueryDeviceProxy(const std::wstring& FileName)
{
std::wstring proxy;
UNICODE_STRING file_name;
RtlInitUnicodeString(&file_name, (WCHAR*)FileName.c_str());
HANDLE device = ImDiskOpenDeviceByName(&file_name, FILE_READ_ATTRIBUTES);
if (device != INVALID_HANDLE_VALUE)
{
union {
IMDISK_CREATE_DATA create_data;
BYTE buffer[sizeof(IMDISK_CREATE_DATA) + MAX_PATH * 4];
}u;
DWORD dw;
if (DeviceIoControl(device, IOCTL_IMDISK_QUERY_DEVICE, NULL, 0, &u.create_data, sizeof(u.buffer), &dw, NULL))
{
if (IMDISK_TYPE(u.create_data.Flags) == IMDISK_TYPE_PROXY)
proxy = std::wstring(u.create_data.FileName, u.create_data.FileNameLength / sizeof(wchar_t));
}
NtClose(device);
}
return proxy;
}
ULONGLONG ImDiskQueryDeviceSize(const std::wstring& FileName)
{
ULONGLONG size;
UNICODE_STRING file_name;
RtlInitUnicodeString(&file_name, (WCHAR*)FileName.c_str());
HANDLE device = ImDiskOpenDeviceByName(&file_name, FILE_READ_ATTRIBUTES);
if (device != INVALID_HANDLE_VALUE)
{
union {
IMDISK_CREATE_DATA create_data;
BYTE buffer[sizeof(IMDISK_CREATE_DATA) + MAX_PATH * 4];
}u;
DWORD dw;
if (DeviceIoControl(device, IOCTL_IMDISK_QUERY_DEVICE, NULL, 0, &u.create_data, sizeof(u.buffer), &dw, NULL))
{
if (IMDISK_TYPE(u.create_data.Flags) == IMDISK_TYPE_PROXY)
size = u.create_data.DiskGeometry.Cylinders.QuadPart;
}
NtClose(device);
}
return size;
}

View File

@ -0,0 +1,160 @@
/*
* Copyright 2023 David Xanatos, xanasoft.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Mount Manager Server -- using PipeServer
//---------------------------------------------------------------------------
#ifndef _MY_MOUNTMANAGERWIRE_H
#define _MY_MOUNTMANAGERWIRE_H
//---------------------------------------------------------------------------
// Mount Manager - Create encrypted box image
//---------------------------------------------------------------------------
struct tagIMBOX_CREATE_REQ
{
MSG_HEADER h;
ULONG64 image_size;
WCHAR password[128 + 1];
WCHAR file_root[1];
};
struct tagIMBOX_CREATE_RPL
{
MSG_HEADER h;
};
typedef struct tagIMBOX_CREATE_REQ IMBOX_CREATE_REQ;
typedef struct tagIMBOX_CREATE_RPL IMBOX_CREATE_RPL;
//---------------------------------------------------------------------------
// Mount Manager - Mount box root
//---------------------------------------------------------------------------
struct tagIMBOX_MOUNT_REQ
{
MSG_HEADER h;
WCHAR password[128 + 1];
BOOL protect_root;
BOOL auto_unmount;
WCHAR reg_root[MAX_REG_ROOT_LEN];
WCHAR file_root[1];
};
struct tagIMBOX_MOUNT_RPL
{
MSG_HEADER h;
};
typedef struct tagIMBOX_MOUNT_REQ IMBOX_MOUNT_REQ;
typedef struct tagIMBOX_MOUNT_RPL IMBOX_MOUNT_RPL;
//---------------------------------------------------------------------------
// Mount Manager - Unmount box root
//---------------------------------------------------------------------------
struct tagIMBOX_UNMOUNT_REQ
{
MSG_HEADER h;
WCHAR reg_root[MAX_REG_ROOT_LEN];
};
struct tagIMBOX_UNMOUNT_RPL
{
MSG_HEADER h;
};
typedef struct tagIMBOX_UNMOUNT_REQ IMBOX_UNMOUNT_REQ;
typedef struct tagIMBOX_UNMOUNT_RPL IMBOX_UNMOUNT_RPL;
//---------------------------------------------------------------------------
// Mount Manager - Enum box roots
//---------------------------------------------------------------------------
struct tagIMBOX_ENUM_REQ
{
MSG_HEADER h;
};
struct tagIMBOX_ENUM_RPL
{
MSG_HEADER h;
WCHAR reg_roots[1];
};
typedef struct tagIMBOX_ENUM_REQ IMBOX_ENUM_REQ;
typedef struct tagIMBOX_ENUM_RPL IMBOX_ENUM_RPL;
//---------------------------------------------------------------------------
// Mount Manager - Query box root
//---------------------------------------------------------------------------
struct tagIMBOX_QUERY_REQ
{
MSG_HEADER h;
WCHAR reg_root[MAX_REG_ROOT_LEN];
};
struct tagIMBOX_QUERY_RPL
{
MSG_HEADER h;
//WCHAR boxname[BOXNAME_COUNT];
ULONG64 disk_size;
ULONG64 used_size;
WCHAR disk_root[1];
};
typedef struct tagIMBOX_QUERY_REQ IMBOX_QUERY_REQ;
typedef struct tagIMBOX_QUERY_RPL IMBOX_QUERY_RPL;
//---------------------------------------------------------------------------
// Mount Manager - Update box image proeprties
//---------------------------------------------------------------------------
struct tagIMBOX_UPDATE_REQ
{
MSG_HEADER h;
WCHAR password[128 + 1];
WCHAR new_password[128 + 1];
ULONG64 new_image_size;
WCHAR file_root[1];
};
struct tagIMBOX_UPDATE_RPL
{
MSG_HEADER h;
};
typedef struct tagIMBOX_UPDATE_REQ IMBOX_UPDATE_REQ;
typedef struct tagIMBOX_UPDATE_RPL IMBOX_UPDATE_RPL;
#endif // _MY_MOUNTMANAGERWIRE_H

View File

@ -494,6 +494,8 @@
<ClCompile Include="includes.cpp" />
<ClCompile Include="iphlpserver.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="MountManager.cpp" />
<ClCompile Include="MountManagerHelpers.cpp" />
<ClCompile Include="namedpipeserver.cpp" />
<ClCompile Include="netapiserver.cpp" />
<ClCompile Include="pipeserver.cpp" />
@ -581,6 +583,8 @@
<ClInclude Include="iphlpserver.h" />
<ClInclude Include="iphlpwire.h" />
<ClInclude Include="misc.h" />
<ClInclude Include="MountManager.h" />
<ClInclude Include="MountManagerWire.h" />
<ClInclude Include="msgids.h" />
<ClInclude Include="namedpipeserver.h" />
<ClInclude Include="namedpipewire.h" />

View File

@ -78,6 +78,12 @@
<ClCompile Include="DriverAssistSid.cpp">
<Filter>DriverAssist</Filter>
</ClCompile>
<ClCompile Include="MountManager.cpp">
<Filter>MountManager</Filter>
</ClCompile>
<ClCompile Include="MountManagerHelpers.cpp">
<Filter>MountManager</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="misc.h" />
@ -144,6 +150,12 @@
<ClInclude Include="..\..\common\ini.h">
<Filter>common</Filter>
</ClInclude>
<ClInclude Include="MountManagerWire.h">
<Filter>MountManager</Filter>
</ClInclude>
<ClInclude Include="MountManager.h">
<Filter>MountManager</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc" />
@ -164,5 +176,8 @@
<Filter Include="NetProxy">
<UniqueIdentifier>{64abb84f-3356-45fc-a1ee-bbce8eaa90cd}</UniqueIdentifier>
</Filter>
<Filter Include="MountManager">
<UniqueIdentifier>{4c490d1f-52cb-4e6b-be53-6b120e0d271a}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>

View File

@ -22,6 +22,7 @@
#include "stdafx.h"
#include <Sddl.h>
#include "MountManager.h"
#include "DriverAssist.h"
#include "PipeServer.h"
#include "GuiServer.h"
@ -233,6 +234,7 @@ DWORD InitializePipe(void)
new IpHlpServer(pipeServer);
new NetApiServer(pipeServer);
new QueueServer(pipeServer);
new MountManager(pipeServer);
new EpMapperServer(pipeServer);
if (! pipeServer->Start())
@ -286,6 +288,8 @@ DWORD WINAPI ServiceHandlerEx(
DriverAssist::Shutdown();
MountManager::Shutdown();
} else if (dwControl != SERVICE_CONTROL_INTERROGATE)
return ERROR_CALL_NOT_IMPLEMENTED;

View File

@ -123,6 +123,14 @@
#define MSGID_IPHLP_SEND_ECHO 0x1C03
#define MSGID_IPHLP_NOTIFICATION 0x1CFF
#define MSGID_IMBOX 0x1D00
#define MSGID_IMBOX_CREATE 0x1D01
#define MSGID_IMBOX_MOUNT 0x1D02
#define MSGID_IMBOX_UNMOUNT 0x1D03
#define MSGID_IMBOX_ENUM 0x1D04
#define MSGID_IMBOX_QUERY 0x1D05
#define MSGID_IMBOX_UPDATE 0x1D06
#define MSGID_QUEUE 0x1E00
#define MSGID_QUEUE_CREATE 0x1E01
#define MSGID_QUEUE_GETREQ 0x1E02

View File

@ -22,6 +22,8 @@
#pragma once
#define _HAS_EXCEPTIONS 0 // we dont have exception support enabled
#include <ntstatus.h>
#define WIN32_NO_STATUS
typedef long NTSTATUS;

View File

@ -528,7 +528,8 @@ MSG_HEADER *TerminalServer::GetUserToken(MSG_HEADER *msg)
} else {
WCHAR boxname[48] = { 0 };
WCHAR boxname[BOXNAME_COUNT];
boxname[0] = L'\0';
SbieApi_QueryProcess(idProcess, boxname, NULL, NULL, NULL);
HANDLE hCallerProcess = OpenProcess(PROCESS_DUP_HANDLE, FALSE, (ULONG)(ULONG_PTR)idProcess);

View File

@ -541,6 +541,73 @@ SBIE2226 Process failed to start due to missing elevation, to resolve add "Apply
SBIE2227 '%2' is located on a volume which does not support 8.3 naming. This can cause issues with older applications and installers.
.
#----------------------------------------------------------------------------
2230;pop;wrn;01
SBIE2230 Failed to mount root for %2
.
2231;pop;wrn;01
SBIE2231 Junction Target missmatch %2
.
2232;pop;wrn;01
SBIE2232 The ImDisk Driver is not loaded
.
2233;pop;wrn;01
SBIE2233 Cannot control the ImDisk Driver: %2
.
2234;pop;wrn;01
SBIE2234 No free Drive letter found for temporary mount
.
2235;pop;wrn;01
SBIE2235 Error undefining temporary drive letter: "%2"
.
2236;pop;wrn;01
SBIE2236 %2 could not be invoked (perhaps it is not installed?)
.
2237;pop;wrn;01
SBIE2237 Failed to unmount root %2
.
2238;pop;wrn;01
SBIE2238 Ram Disk size is not configured, or to small, set RamDiskSizeKb=1048576 (1GB in Kilobytes) in the [GlobalSettings] ini section.
.
2239;pop;wrn;01
SBIE2239 The root folder of sandbox %2 must be empty in order to mount a volume to it.
.
2240;pop;wrn;01
SBIE2240 Timeout when trying to mount ImDisk volume %2
.
2241;pop;wrn;01
SBIE2241 Box image file %2 could not be opened
.
2242;pop;wrn;01
SBIE2242 Failed to mount box image, The specified cipher is not supported
.
2243;pop;wrn;01
SBIE2243 Failed to mount box image, Wrong password
.
2244;pop;wrn;01
SBIE2244 Failed to mount box image, Password required
.
2246;pop;wrn;01
SBIE2245 Failed to mount box image, ImBox error %2
.
#----------------------------------------------------------------------------
# SbieDrv
#
@ -3616,6 +3683,14 @@ Sandboxie Plus offers enhanced privacy protection by switching the old behavior
The legacy UI of Sandboxie classic does not implement support for this mode of operation. Although it can be configured using the ini file, it is recommended to use the modern Sandboxie-Plus UI (SandMan.exe) if you want to use privacy enhanced boxes.
.
6008;pop;err;01
The configuration %3 of box %2 requires a supporter certificate and can not be used without it.
.
6009;pop;err;01
The configuration %3 of box %2 requires a advanced supporter certificate.
.
6010;txt;01
You have installed Sandboxie more than %2 days ago.

View File

@ -125,6 +125,13 @@ CSandBox::~CSandBox()
void CSandBox::UpdateDetails()
{
auto res = m_pAPI->ImBoxQuery(m_RegPath);
if (res.IsError()) {
m_Mount.clear();
return;
}
QVariantMap Info = res.GetValue();
m_Mount = Info["DiskRoot"].toString();
}
void CSandBox::SetBoxPaths(const QString& FilePath, const QString& RegPath, const QString& IpcPath)
@ -774,3 +781,18 @@ SB_STATUS CSandBox::SetSnapshotInfo(const QString& ID, const QString& Name, cons
return SB_OK;
}
SB_STATUS CSandBox::ImBoxCreate(quint64 uSizeKb, const QString& Password)
{
return m_pAPI->ImBoxCreate(this, uSizeKb, Password);
}
SB_STATUS CSandBox::ImBoxMount(const QString& Password, bool bProtect, bool bAutoUnmount)
{
return m_pAPI->ImBoxMount(this, Password, bProtect, bAutoUnmount);
}
SB_STATUS CSandBox::ImBoxUnmount()
{
return m_pAPI->ImBoxUnmount(this);
}

View File

@ -46,6 +46,7 @@ public:
virtual QString GetFileRoot() const { return m_FilePath; }
virtual QString GetRegRoot() const { return m_RegPath; }
virtual QString GetIpcRoot() const { return m_IpcPath; }
virtual QString GetMountRoot() const { return m_Mount; }
virtual QMap<quint32, CBoxedProcessPtr> GetProcessList() const { return m_ProcessList; }
@ -77,6 +78,11 @@ public:
virtual SB_PROGRESS SelectSnapshot(const QString& ID);
virtual SB_STATUS SetSnapshotInfo(const QString& ID, const QString& Name, const QString& Description = QString());
// Mount Manager
virtual SB_STATUS ImBoxCreate(quint64 uSizeKb, const QString& Password = QString());
virtual SB_STATUS ImBoxMount(const QString& Password = QString(), bool bProtect = false, bool bAutoUnmount = false);
virtual SB_STATUS ImBoxUnmount();
class CSbieAPI* Api() { return m_pAPI; }
protected:
@ -91,6 +97,7 @@ protected:
QString m_FilePath;
QString m_RegPath;
QString m_IpcPath;
QString m_Mount;
bool m_IsEnabled;

View File

@ -42,6 +42,7 @@ typedef long NTSTATUS;
#include "..\..\Sandboxie\core\svc\sbieiniwire.h"
#include "..\..\Sandboxie\core\svc\QueueWire.h"
#include "..\..\Sandboxie\core\svc\InteractiveWire.h"
#include "..\..\Sandboxie\core\svc\MountManagerWire.h"
int _SB_STATUS_type = qRegisterMetaType<SB_STATUS>("SB_STATUS");
@ -2362,6 +2363,149 @@ bool CSbieAPI::AreForceProcessDisabled()
return uOldState != FALSE;
}
///////////////////////////////////////////////////////////////////////////////
// Mount Manager
//
SB_STATUS CSbieAPI::ImBoxCreate(CSandBox* pBox, quint64 uSizeKb, const QString& Password)
{
std::wstring file_root = L"\\??\\" + pBox->GetFileRoot().toStdWString();
std::wstring password = Password.toStdWString();
if(password.length() > 128)
return SB_ERR(ERROR_INVALID_PARAMETER);
ULONG req_len = sizeof(IMBOX_CREATE_REQ);
req_len += file_root.length() * sizeof(wchar_t);
SScoped<IMBOX_CREATE_REQ> req(malloc(req_len));
req->h.length = req_len;
req->h.msgid = MSGID_IMBOX_CREATE;
req->image_size = uSizeKb;
wcscpy(req->password, password.c_str());
wcscpy(req->file_root, file_root.c_str());
SScoped<IMBOX_CREATE_RPL> rpl;
SB_STATUS Status = CallServer(&req->h, &rpl);
m_bBoxesDirty = true;
if (!Status)
return Status;
if (!rpl)
return SB_ERR(ERROR_SERVER_DISABLED);
if (rpl->h.status != 0)
return SB_ERR(rpl->h.status);
return SB_OK;
}
SB_STATUS CSbieAPI::ImBoxMount(CSandBox* pBox, const QString& Password, bool bProtect, bool bAutoUnmount)
{
std::wstring root = pBox->GetRegRoot().toStdWString();
if(root.length() >= MAX_REG_ROOT_LEN)
return SB_ERR(ERROR_INVALID_PARAMETER);
std::wstring file_root = L"\\??\\" + pBox->GetFileRoot().toStdWString();
std::wstring password = Password.toStdWString();
if(password.length() > 128)
return SB_ERR(ERROR_INVALID_PARAMETER);
ULONG req_len = sizeof(IMBOX_MOUNT_REQ);
req_len += file_root.length() * sizeof(wchar_t);
SScoped<IMBOX_MOUNT_REQ> req(malloc(req_len));
req->h.length = req_len;
req->h.msgid = MSGID_IMBOX_MOUNT;
wcscpy(req->password, password.c_str());
req->protect_root = bProtect;
req->auto_unmount = bAutoUnmount;
wcscpy(req->reg_root, root.c_str());
wcscpy(req->file_root, file_root.c_str());
SScoped<IMBOX_MOUNT_RPL> rpl;
SB_STATUS Status = CallServer(&req->h, &rpl);
m_bBoxesDirty = true;
if (!Status)
return Status;
if (!rpl)
return SB_ERR(ERROR_SERVER_DISABLED);
if (rpl->h.status != 0)
return SB_ERR(rpl->h.status);
return SB_OK;
}
SB_STATUS CSbieAPI::ImBoxUnmount(CSandBox* pBox)
{
std::wstring root = pBox->GetRegRoot().toStdWString();
IMBOX_UNMOUNT_REQ req;
req.h.length = sizeof(IMBOX_UNMOUNT_REQ);
req.h.msgid = MSGID_IMBOX_UNMOUNT;
wcscpy(req.reg_root, root.c_str());
SScoped<IMBOX_UNMOUNT_RPL> rpl;
SB_STATUS Status = CallServer(&req.h, &rpl);
m_bBoxesDirty = true;
if (!Status)
return Status;
if (!rpl)
return SB_ERR(ERROR_SERVER_DISABLED);
if (rpl->h.status != 0)
return SB_ERR(rpl->h.status);
return SB_OK;
}
SB_RESULT(QStringList) CSbieAPI::ImBoxEnum()
{
IMBOX_ENUM_REQ req;
req.h.length = sizeof(IMBOX_ENUM_REQ);
req.h.msgid = MSGID_IMBOX_ENUM;
SScoped<IMBOX_ENUM_RPL> rpl;
SB_STATUS Status = CallServer(&req.h, &rpl);
if (!Status)
return Status;
if (!rpl)
return SB_ERR(ERROR_SERVER_DISABLED);
if (rpl->h.status != 0)
return SB_ERR(rpl->h.status);
QStringList Roots;
wchar_t* reg_roots = rpl->reg_roots;
while (*reg_roots) {
size_t len = wcslen(reg_roots);
Roots.append(QString::fromWCharArray(reg_roots, len));
reg_roots += len + 1;
}
return CSbieResult(Roots);
}
SB_RESULT(QVariantMap) CSbieAPI::ImBoxQuery(const QString& Root)
{
std::wstring root = Root.toStdWString();
IMBOX_QUERY_REQ req;
req.h.length = sizeof(IMBOX_QUERY_REQ);
req.h.msgid = MSGID_IMBOX_QUERY;
wcscpy(req.reg_root, root.c_str());
SScoped<IMBOX_QUERY_RPL> rpl;
SB_STATUS Status = CallServer(&req.h, &rpl);
if (!Status)
return Status;
if (!rpl)
return SB_ERR(ERROR_SERVER_DISABLED);
if (rpl->h.status != 0)
return SB_ERR(rpl->h.status);
QVariantMap Info;
Info["DiskSize"] = rpl->disk_size;
Info["UsedSize"] = rpl->used_size;
Info["DiskRoot"] = QString::fromWCharArray(rpl->disk_root);
return CSbieResult(Info);
}
///////////////////////////////////////////////////////////////////////////////
// Monitor
//

View File

@ -128,6 +128,14 @@ public:
virtual SB_STATUS DisableForceProcess(bool Set, int Seconds = 0);
virtual bool AreForceProcessDisabled();
// Mount Manager
virtual SB_STATUS ImBoxCreate(CSandBox* pBox, quint64 uSizeKb, const QString& Password = QString());
virtual SB_STATUS ImBoxMount(CSandBox* pBox, const QString& Password = QString(), bool bProtect = false, bool bAutoUnmount = false);
virtual SB_STATUS ImBoxUnmount(CSandBox* pBox);
virtual SB_RESULT(QStringList) ImBoxEnum();
virtual SB_RESULT(QVariantMap) ImBoxQuery(const QString& Root = QString());
//virtual SB_STATUS ImBoxUpdate( // todo
// Monitor
virtual SB_STATUS EnableMonitor(bool Enable);
virtual bool IsMonitoring();

View File

@ -0,0 +1,175 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BoxImageWindow</class>
<widget class="QWidget" name="BoxImageWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>518</width>
<height>268</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>500</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="5" column="3">
<widget class="QLabel" name="lblImageSizeKb">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>kilobytes</string>
</property>
</widget>
</item>
<item row="2" column="2" colspan="3">
<widget class="QLineEdit" name="txtNewPassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="3" column="2" colspan="3">
<widget class="QLineEdit" name="txtRepeatPassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="7" column="2" colspan="3">
<widget class="QCheckBox" name="chkProtect">
<property name="text">
<string>Protect Box Root from access by unsandboxed processes</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QLineEdit" name="txtImageSize">
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="8" column="0" colspan="5">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="6" column="2" colspan="2">
<widget class="QComboBox" name="cmbCipher"/>
</item>
<item row="1" column="2" colspan="3">
<widget class="QLineEdit" name="txtPassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblIcon">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="4" column="4">
<widget class="QCheckBox" name="chkShow">
<property name="text">
<string>Show Password</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="lblPassword">
<property name="text">
<string>Enter Password</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="lblNewPassword">
<property name="text">
<string>New Password</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="lblRepeatPassword">
<property name="text">
<string>Repeat Password</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QLabel" name="lblImageSize">
<property name="text">
<string>Disk Image Size</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QLabel" name="lblCipher">
<property name="text">
<string>Encryption Cipher</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1" colspan="4">
<widget class="QLabel" name="lblInfo">
<property name="text">
<string>TextLabel</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

File diff suppressed because it is too large Load Diff

View File

@ -1260,6 +1260,100 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tabAddonConfig">
<attribute name="title">
<string>Addon Configuration</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_40">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_39">
<item row="2" column="4">
<widget class="QLineEdit" name="txtRamLimit">
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QCheckBox" name="chkRamDisk">
<property name="text">
<string>Enable Ram Disk creation</string>
</property>
</widget>
</item>
<item row="2" column="5">
<widget class="QLabel" name="lblRamLimit">
<property name="text">
<string>kilobytes</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblDiskImage">
<property name="font">
<font>
<bold>true</bold>
<kerning>true</kerning>
</font>
</property>
<property name="text">
<string>Disk Image Support</string>
</property>
</widget>
</item>
<item row="3" column="1">
<spacer name="verticalSpacer_13">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="3">
<widget class="QLabel" name="lblRamDisk">
<property name="text">
<string>RAM Limit</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="2" colspan="4">
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1" colspan="5">
<widget class="QLabel" name="lblImDisk">
<property name="text">
<string>&lt;a href=&quot;addon://ImDisk&quot;&gt;Install ImDisk&lt;/a&gt; driver to enable Ram Disk and Disk Image support.</string>
</property>
<property name="openExternalLinks">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>

View File

@ -235,6 +235,15 @@ QList<QVariant> CSbieModel::Sync(const QMap<QString, CSandBoxPtr>& BoxList, cons
bool boxDel = pBoxEx->IsAutoDelete();
bool boxNoForce = pBoxEx->IsForceDisabled();
int boxColor = pBoxEx->GetColor();
SSandBoxNode::EMountState mountState = SSandBoxNode::eNone;
if (pBoxEx->UseRamDisk())
mountState = SSandBoxNode::eRamDisk;
else if (pBoxEx->UseImageFile()) {
if(pBoxEx->GetMountRoot().isEmpty())
mountState = SSandBoxNode::eUnmounted;
else
mountState = SSandBoxNode::eMounted;
}
QIcon Icon;
QString BoxIcon = pBox->GetText("BoxIcon");
@ -256,7 +265,8 @@ QList<QVariant> CSbieModel::Sync(const QMap<QString, CSandBoxPtr>& BoxList, cons
pNode->boxColor != boxColor ||
pNode->boxDel != boxDel ||
pNode->boxNoForce != boxNoForce ||
!pNode->BoxIcon.isEmpty()
!pNode->BoxIcon.isEmpty() ||
pNode->MountState != mountState
)
{
pNode->inUse = inUse;
@ -270,6 +280,7 @@ QList<QVariant> CSbieModel::Sync(const QMap<QString, CSandBoxPtr>& BoxList, cons
else
Icon = theGUI->GetBoxIcon(boxType, inUse);
pNode->BoxIcon.clear();
pNode->MountState = mountState;
}
if (!Icon.isNull())
@ -283,6 +294,12 @@ QList<QVariant> CSbieModel::Sync(const QMap<QString, CSandBoxPtr>& BoxList, cons
{
if(boxNoForce)
Icon = theGUI->IconAddOverlay(Icon, ":/IconDFP");
else if(mountState == SSandBoxNode::eRamDisk)
Icon = theGUI->IconAddOverlay(Icon, ":/Actions/RamDisk.png");
else if(mountState == SSandBoxNode::eMounted)
Icon = theGUI->IconAddOverlay(Icon, ":/Actions/LockOpen.png");
else if(mountState == SSandBoxNode::eUnmounted)
Icon = theGUI->IconAddOverlay(Icon, ":/Actions/LockClosed.png");
else if (boxDel && !bVintage)
Icon = theGUI->IconAddOverlay(Icon, ":/Boxes/AutoDel");
}

View File

@ -67,11 +67,19 @@ protected:
struct SSandBoxNode: STreeNode
{
SSandBoxNode(CTreeItemModel* pModel, const QVariant& Id) : STreeNode(pModel, Id) { inUse = false; bOpen = false; busyState = 0; boxType = -1; boxDel = false; boxNoForce = false; boxColor = 0; OrderNumber = 0; }
SSandBoxNode(CTreeItemModel* pModel, const QVariant& Id) : STreeNode(pModel, Id) {
inUse = false;
busyState = 0;
boxType = -1;
boxDel = false;
boxNoForce = false;
boxColor = 0;
OrderNumber = 0;
MountState = eNone;
}
CSandBoxPtr pBox;
bool inUse;
bool bOpen;
int busyState;
int boxType;
bool boxDel;
@ -79,6 +87,12 @@ protected:
int boxColor;
int OrderNumber;
QString BoxIcon;
enum EMountState{
eNone = 0,
eMounted,
eUnmounted,
eRamDisk
} MountState;
CBoxedProcessPtr pProcess;
};

View File

@ -36,6 +36,7 @@
#include "Helpers/FullScreen.h"
#include "Helpers/WinHelper.h"
#include "../QSbieAPI/Helpers/DbgHelper.h"
#include "Windows/BoxImageWindow.h"
#include "Wizards/BoxAssistant.h"
#include "Engine/BoxEngine.h"
#include "Engine/ScriptManager.h"
@ -172,6 +173,8 @@ CSandMan::CSandMan(QWidget *parent)
m_bExit = false;
m_ImDiskReady = true;
theAPI = new CSbiePlusAPI(this);
connect(theAPI, SIGNAL(StatusChanged()), this, SLOT(OnStatusChanged()));
@ -194,8 +197,6 @@ CSandMan::CSandMan(QWidget *parent)
m_SbieTemplates = new CSbieTemplatesEx(theAPI, this);
m_SbieScripts = new CScriptManager(this);
m_bConnectPending = false;
m_bStopPending = false;
@ -203,6 +204,8 @@ CSandMan::CSandMan(QWidget *parent)
m_pUpdater = new COnlineUpdater(this);
m_SbieScripts = new CScriptManager(this);
m_AddonManager = new CAddonManager(this);
@ -227,6 +230,7 @@ CSandMan::CSandMan(QWidget *parent)
m_pDisabledForce = new QLabel();
m_pDisabledRecovery = new QLabel();
m_pDisabledMessages = new QLabel();
m_pRamDiskInfo = NULL;
statusBar()->addPermanentWidget(m_pTraceInfo);
statusBar()->addPermanentWidget(m_pDisabledForce);
statusBar()->addPermanentWidget(m_pDisabledRecovery);
@ -247,6 +251,7 @@ CSandMan::CSandMan(QWidget *parent)
m_BoxColors[CSandBoxPlus::eAppBox] = qRgb(0,253,0);
m_BoxColors[CSandBoxPlus::eInsecure] = qRgb(244,3,244);
m_BoxColors[CSandBoxPlus::eOpen] = qRgb(255,255,255);
m_BoxColors[CSandBoxPlus::ePrivate] = qRgb(56,56,56);
CreateTrayIcon();
@ -436,6 +441,21 @@ void CSandMan::CreateMaintenanceMenu()
m_pStartSvc = m_pMaintenanceItems->addAction(tr("Start Service"), this, SLOT(OnMaintenance()));
m_pStopSvc = m_pMaintenanceItems->addAction(tr("Stop Service"), this, SLOT(OnMaintenance()));
m_pUninstallSvc = m_pMaintenanceItems->addAction(tr("Uninstall Service"), this, SLOT(OnMaintenance()));
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QString ImDiskCpl = env.value("SystemRoot") + "\\system32\\imdisk.cpl";
if (QFile::exists(ImDiskCpl)) {
m_pImDiskCpl = m_pMaintenance->addAction(LoadWindowsIcon(ImDiskCpl, 0), tr("Virtual Disks"), this, [ImDiskCpl]() {
std::wstring imDiskCpl = ImDiskCpl.toStdWString();
SHELLEXECUTEINFO si = { 0 };
si.cbSize = sizeof(SHELLEXECUTEINFO);
si.lpVerb = L"runas";
si.lpFile = imDiskCpl.c_str();
si.nShow = SW_SHOW;
ShellExecuteEx(&si);
});
}
m_pMaintenance->addSeparator();
m_pSetupWizard = m_pMaintenance->addAction(CSandMan::GetIcon("Wizard"), tr("Setup Wizard"), this, SLOT(OnMaintenance()));
//m_pUpdateCore = m_pMaintenance->addAction(CSandMan::GetIcon("Install"), tr("Update Core Files"), this, SLOT(OnMaintenance()));
@ -488,6 +508,7 @@ void CSandMan::CreateMenus(bool bAdvanced)
m_pMenuFile->addSeparator();
m_pRunBoxed = m_pMenuFile->addAction(CSandMan::GetIcon("Run"), tr("Run Sandboxed"), this, SLOT(OnSandBoxAction()));
m_pEmptyAll = m_pMenuFile->addAction(CSandMan::GetIcon("EmptyAll"), tr("Terminate All Processes"), this, SLOT(OnEmptyAll()));
m_pLockAll = m_pMenuFile->addAction(CSandMan::GetIcon("LockClosed"), tr("Lock All Encrypted Boxes"), this, SLOT(OnLockAll()));
m_pMenuFile->addSeparator();
m_pWndFinder = m_pMenuFile->addAction(CSandMan::GetIcon("finder"), tr("Is Window Sandboxed?"), this, SLOT(OnWndFinder()));
@ -629,6 +650,7 @@ void CSandMan::CreateOldMenus()
m_pMenuFile = m_pMenuBar->addMenu(tr("&File"));
m_pRunBoxed = m_pMenuFile->addAction(CSandMan::GetIcon("Run"), tr("Run Sandboxed"), this, SLOT(OnSandBoxAction()));
m_pEmptyAll = m_pMenuFile->addAction(CSandMan::GetIcon("EmptyAll"), tr("Terminate All Processes"), this, SLOT(OnEmptyAll()));
m_pLockAll = m_pMenuFile->addAction(CSandMan::GetIcon("LockClosed"), tr("Lock All Encrypted Boxes"), this, SLOT(OnLockAll()));
m_pDisableForce = m_pMenuFile->addAction(CSandMan::GetIcon("PauseForce"), tr("Pause Forcing Programs"), this, SLOT(OnDisableForce()));
m_pDisableForce->setCheckable(true);
m_pDisableForce2 = new QAction(CSandMan::GetIcon("PauseForce"), tr("Pause Forcing Programs"));
@ -805,6 +827,7 @@ QList<ToolBarAction> CSandMan::GetAvailableToolBarActions()
ToolBarAction{ "RunBoxed", m_pRunBoxed },
ToolBarAction{ "IsBoxed", m_pWndFinder },
ToolBarAction{ "TerminateAll", m_pEmptyAll },
ToolBarAction{ "LockAll", m_pLockAll },
ToolBarAction{ "", nullptr }, // separator
ToolBarAction{ "CleanUpMenu", nullptr, tr("Cleanup") }, //tr: Name of button in toolbar for cleanup-all action
ToolBarAction{ "KeepTerminated", m_pKeepTerminated },
@ -1401,13 +1424,18 @@ QIcon CSandMan::GetColorIcon(QColor boxColor, bool inUse/*, bool bOut*/)
my_rgb rgb1 = { (double)qRed(rgb), (double)qGreen(rgb), (double)qBlue(rgb) };
my_hsv hsv = rgb2hsv(rgb1);
if((hsv.h >= 30 && hsv.h < 150) || (hsv.h >= 210 && hsv.h < 330)) hsv.h -= 60;
else if(hsv.h >= 150 && hsv.h < 210) hsv.h += 120;
else if((hsv.h >= 330 && hsv.h < 360) || (hsv.h >= 0 && hsv.h < 30)) hsv.h -= 240;
if (hsv.s > 0) {
if ((hsv.h >= 30 && hsv.h < 150) || (hsv.h >= 210 && hsv.h < 330)) hsv.h -= 60;
else if (hsv.h >= 150 && hsv.h < 210) hsv.h += 120;
else if ((hsv.h >= 330 && hsv.h < 360) || (hsv.h >= 0 && hsv.h < 30)) hsv.h -= 240;
}
if (hsv.h < 0) hsv.h += 360;
else if (hsv.h >= 360) hsv.h -= 360;
hsv.s = 1; // make the content always fully saturated
if(hsv.v < 64)
hsv.v = 255;
else
hsv.s = 1; // make the content always fully saturated
my_rgb rgb2 = hsv2rgb(hsv);
rgb = qRgb(rgb2.r, rgb2.g, rgb2.b);
@ -1472,6 +1500,9 @@ QString CSandMan::GetBoxDescription(int boxType)
case CSandBoxPlus::eAppBox:
Info = tr("This box does not enforce isolation, it is intended to be used as an <a href=\"sbie://docs/compartment-mode\">application compartment</a> for software virtualization only.");
break;
case CSandBoxPlus::ePrivate:
Info = tr("This box will be <a href=\"sbie://docs/boxencryption\">encrypted</a> and <a href=\"sbie://docs/black-box\">access to sandboxed processes will be guarded</a>.");
break;
}
if(boxType == CSandBoxPlus::eHardenedPlus || boxType == CSandBoxPlus::eDefaultPlus || boxType == CSandBoxPlus::eAppBoxPlus)
@ -1605,10 +1636,32 @@ bool CSandMan::RunSandboxed(const QStringList& Commands, QString BoxName, const
SB_RESULT(quint32) CSandMan::RunStart(const QString& BoxName, const QString& Command, bool Elevated, const QString& WorkingDir, QProcess* pProcess)
{
auto pBoxEx = theAPI->GetBoxByName(BoxName).objectCast<CSandBoxPlus>();
if (pBoxEx && pBoxEx->UseImageFile() && pBoxEx->GetMountRoot().isEmpty()){
SB_STATUS Status = ImBoxMount(pBoxEx, true);
if (Status.IsError())
return Status;
}
return theAPI->RunStart(BoxName, Command, Elevated, WorkingDir, pProcess);
}
SB_STATUS CSandMan::ImBoxMount(const CSandBoxPtr& pBox, bool bAutoUnmount)
{
auto pBoxEx = pBox.objectCast<CSandBoxPlus>();
if (!QFile::exists(pBoxEx->GetBoxImagePath())) {
CBoxImageWindow window(CBoxImageWindow::eNew, this);
if (theGUI->SafeExec(&window) != 1)
return SB_ERR(SB_Canceled);
pBoxEx->ImBoxCreate(window.GetImageSize() / 1024, window.GetPassword());
}
CBoxImageWindow window(CBoxImageWindow::eMount, this);
if (theGUI->SafeExec(&window) != 1)
return SB_ERR(SB_Canceled);
return pBox->ImBoxMount(window.GetPassword(), window.UseProtection(), bAutoUnmount);
}
void CSandMan::dropEvent(QDropEvent* e)
{
QStringList Commands;
@ -1668,6 +1721,21 @@ void CSandMan::timerEvent(QTimerEvent* pEvent)
ActiveProcesses = Processes.count();
SB_RESULT(QVariantMap) ImBox = theAPI->ImBoxQuery();
m_ImDiskReady = ImBox.GetStatus() != ERROR_DEVICE_NOT_AVAILABLE;
if (!ImBox.IsError()) {
if (!m_pRamDiskInfo) {
m_pRamDiskInfo = new QLabel();
statusBar()->addPermanentWidget(m_pRamDiskInfo);
}
m_pRamDiskInfo->setText(FormatSize(ImBox.GetValue().value("UsedSize").toULongLong()) + "/" + FormatSize(ImBox.GetValue().value("DiskSize").toULongLong()));
}
else if (m_pRamDiskInfo) {
m_pRamDiskInfo->deleteLater();
m_pRamDiskInfo = NULL;
}
if (theAPI->IsBusy() || m_iDeletingContent > 0)
bIconBusy = true;
@ -1792,6 +1860,21 @@ SB_STATUS CSandMan::DeleteBoxContent(const CSandBoxPtr& pBox, EDelMode Mode, boo
auto pBoxEx = pBox.objectCast<CSandBoxPlus>();
if (pBoxEx->UseImageFile()) {
if (pBoxEx->GetMountRoot().isEmpty()) {
if (Mode != eForDelete)
return CSbieStatus(SB_DeleteNoMount);
if(QFile::exists(pBoxEx->GetBoxImagePath()) && !QFile::remove(pBoxEx->GetBoxImagePath()))
return SB_ERR(SB_DeleteFailed, QVariantList() << pBoxEx->GetName() << pBoxEx->GetBoxImagePath());
if(QDir().exists(pBoxEx->GetFileRoot()) && !QDir().rmdir(pBoxEx->GetFileRoot()))
return SB_ERR(SB_DeleteFailed, QVariantList() << pBoxEx->GetName() << pBoxEx->GetFileRoot());
return Ret;
}
}
if (Mode != eForDelete) {
//
@ -2274,6 +2357,7 @@ void CSandMan::UpdateState()
m_pNewGroup->setEnabled(isConnected);
m_pImportBox->setEnabled(isConnected);
m_pEmptyAll->setEnabled(isConnected);
m_pLockAll->setEnabled(isConnected);
m_pDisableForce->setEnabled(isConnected);
m_pDisableForce2->setEnabled(isConnected);
@ -2479,19 +2563,40 @@ void CSandMan::OnLogSbieMessage(quint32 MsgCode, const QStringList& MsgData, qui
m_MissingTemplates.append(MsgData[2]);
}
if ((MsgCode & 0xFFFF) == 6004) // certificate error
if ((MsgCode & 0xFFFF) == 6004 || (MsgCode & 0xFFFF) == 6008 || (MsgCode & 0xFFFF) == 6009) // certificate error
{
static quint64 iLastCertWarning = 0;
if (iLastCertWarning + 60 < QDateTime::currentDateTime().toSecsSinceEpoch()) { // reset after 60 seconds
iLastCertWarning = QDateTime::currentDateTime().toSecsSinceEpoch();
QString Message;
if (!MsgData[2].isEmpty())
Message = tr("The program %1 started in box %2 will be terminated in 5 minutes because the box was configured to use features exclusively available to project supporters.").arg(MsgData[2]).arg(MsgData[1]);
else
Message = tr("The box %1 is configured to use features exclusively available to project supporters, these presets will be ignored.").arg(MsgData[1]);
QString Message;
if ((MsgCode & 0xFFFF) == 6008)
{
Message = tr("The box %1 is configured to use features exclusively available to project supporters.").arg(MsgData[1]);
Message.append(tr("<br /><a href=\"https://sandboxie-plus.com/go.php?to=sbie-get-cert\">Become a project supporter</a>, and receive a <a href=\"https://sandboxie-plus.com/go.php?to=sbie-cert\">supporter certificate</a>"));
}
else if ((MsgCode & 0xFFFF) == 6009)
{
Message = tr("The box %1 is configured to use features which require an <b>advanced</b> supporter certificate.").arg(MsgData[1]);
if(g_CertInfo.active)
Message.append(tr("<br /><a href=\"https://sandboxie-plus.com/go.php?to=sbie-upgrade-cert\">Upgrade your Certificate</a> to unlock advanced features."));
else
Message.append(tr("<br /><a href=\"https://sandboxie-plus.com/go.php?to=sbie-get-cert\">Become a project supporter</a>, and receive a <a href=\"https://sandboxie-plus.com/go.php?to=sbie-cert\">supporter certificate</a>"));
}
else
{
static quint64 iLastCertWarning = 0;
if (iLastCertWarning + 60 < QDateTime::currentDateTime().toSecsSinceEpoch()) { // reset after 60 seconds
iLastCertWarning = QDateTime::currentDateTime().toSecsSinceEpoch();
if (!MsgData[2].isEmpty())
Message = tr("The program %1 started in box %2 will be terminated in 5 minutes because the box was configured to use features exclusively available to project supporters.").arg(MsgData[2]).arg(MsgData[1]);
else
Message = tr("The box %1 is configured to use features exclusively available to project supporters, these presets will be ignored.").arg(MsgData[1]);
Message.append(tr("<br /><a href=\"https://sandboxie-plus.com/go.php?to=sbie-get-cert\">Become a project supporter</a>, and receive a <a href=\"https://sandboxie-plus.com/go.php?to=sbie-cert\">supporter certificate</a>"));
//bCertWarning = false;
}
}
if (!Message.isEmpty())
{
QMessageBox msgBox(this);
msgBox.setTextFormat(Qt::RichText);
msgBox.setIcon(QMessageBox::Critical);
@ -2503,8 +2608,6 @@ void CSandMan::OnLogSbieMessage(quint32 MsgCode, const QStringList& MsgData, qui
if (msgBox.exec() == QDialogButtonBox::Yes) {
OpenUrl(QUrl("https://sandboxie-plus.com/go.php?to=sbie-get-cert"));
}*/
//bCertWarning = false;
}
// return;
}
@ -2543,22 +2646,34 @@ void CSandMan::SaveMessageLog(QIODevice* pFile)
pFile->write((Msg.TimeStamp.toString("hh:mm:ss.zzz") + "\t" + FormatSbieMessage(Msg.MsgCode, Msg.MsgData, Msg.ProcessName)).toLatin1() + "\n");
}
bool CSandMan::CheckCertificate(QWidget* pWidget)
bool CSandMan::CheckCertificate(QWidget* pWidget, bool bAdvanced)
{
if (g_CertInfo.active)
return true;
QString Message;
if (bAdvanced)
{
if (CERT_IS_LEVEL(g_CertInfo, eCertAdvanced))
return true;
//if ((g_FeatureFlags & CSbieAPI::eSbieFeatureCert) == 0) {
// OnLogMessage(tr("The supporter certificate is expired"));
// return false;
//}
Message = tr("The selected feature requires an <b>advanced</b> supporter certificate.");
if(g_CertInfo.active)
Message.append(tr("<br /><a href=\"https://sandboxie-plus.com/go.php?to=sbie-upgrade-cert\">Upgrade your Certificate</a> to unlock advanced features."));
else
Message.append(tr("<br /><a href=\"https://sandboxie-plus.com/go.php?to=sbie-get-cert\">Become a project supporter</a>, and receive a <a href=\"https://sandboxie-plus.com/go.php?to=sbie-cert\">supporter certificate</a>"));
}
else
{
if (g_CertInfo.active)
return true;
Message = tr("The selected feature set is only available to project supporters. Processes started in a box with this feature set enabled without a supporter certificate will be terminated after 5 minutes.<br />"
"<a href=\"https://sandboxie-plus.com/go.php?to=sbie-get-cert\">Become a project supporter</a>, and receive a <a href=\"https://sandboxie-plus.com/go.php?to=sbie-cert\">supporter certificate</a>");
}
QMessageBox msgBox(pWidget);
msgBox.setTextFormat(Qt::RichText);
msgBox.setIcon(QMessageBox::Information);
msgBox.setWindowTitle("Sandboxie-Plus");
msgBox.setText(tr("The selected feature set is only available to project supporters. Processes started in a box with this feature set enabled without a supporter certificate will be terminated after 5 minutes.<br />"
"<a href=\"https://sandboxie-plus.com/go.php?to=sbie-get-cert\">Become a project supporter</a>, and receive a <a href=\"https://sandboxie-plus.com/go.php?to=sbie-cert\">supporter certificate</a>"));
msgBox.setText(Message);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
/*msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
@ -2753,7 +2868,7 @@ void CSandMan::OnSandBoxAction()
RunSandboxed(QStringList() << "run_dialog");
}
void CSandMan::OnEmptyAll()
void CSandMan::TerminateAll(bool bUnmount)
{
if (theConf->GetInt("Options/WarnTerminateAll", -1) == -1)
{
@ -2767,6 +2882,14 @@ void CSandMan::OnEmptyAll()
}
theAPI->TerminateAll();
if (bUnmount) {
QMap<QString, CSandBoxPtr> Boxes = theAPI->GetAllBoxes();
foreach(const CSandBoxPtr & pBox, Boxes) {
if (!pBox->GetMountRoot().isEmpty())
pBox->ImBoxUnmount();
}
}
}
void CSandMan::OnDisableForce()
@ -3174,6 +3297,7 @@ void CSandMan::OnResetMsgs()
if (Ret == QMessageBox::Yes)
{
theConf->DelValue("Options/WarnDeleteV2");
theConf->DelValue("Options/WarnBoxCrypto");
theConf->DelValue("Options/PortableStop");
theConf->DelValue("Options/PortableStart");

View File

@ -49,6 +49,8 @@ public:
static QString GetVersion();
bool IsImDiskReady() const { return m_ImDiskReady; }
bool IsWFPEnabled() const;
SB_PROGRESS RecoverFiles(const QString& BoxName, const QList<QPair<QString, QString>>& FileList, QWidget* pParent, int Action = 0);
@ -89,6 +91,7 @@ public:
bool RunSandboxed(const QStringList& Commands, QString BoxName = QString(), const QString& WrkDir = QString());
SB_RESULT(quint32) RunStart(const QString& BoxName, const QString& Command, bool Elevated = false, const QString& WorkingDir = QString(), QProcess* pProcess = NULL);
SB_STATUS ImBoxMount(const CSandBoxPtr& pBox, bool bAutoUnmount = false);
void EditIni(const QString& IniPath, bool bPlus = false);
@ -99,7 +102,7 @@ public:
QIcon IconAddOverlay(const QIcon& Icon, const QString& Name, int Size = 24);
QString GetBoxDescription(int boxType);
bool CheckCertificate(QWidget* pWidget);
bool CheckCertificate(QWidget* pWidget, bool bAdvanced = false);
void UpdateTheme();
void UpdateTitleTheme(const HWND& hwnd);
@ -240,7 +243,8 @@ private slots:
void OnSandBoxAction();
void OnSettingsAction();
void OnEmptyAll();
void OnEmptyAll() { TerminateAll(false); }
void OnLockAll() { TerminateAll(true); }
void OnWndFinder();
void OnBoxAssistant();
void OnDisableForce();
@ -300,6 +304,8 @@ private:
void HandleMaintenance(SB_RESULT(void*) Status);
void TerminateAll(bool bUnmount);
void LoadState(bool bFull = true);
void StoreState();
@ -359,6 +365,7 @@ private:
QAction* m_pNewGroup;
QAction* m_pImportBox;
QAction* m_pEmptyAll;
QAction* m_pLockAll;
QAction* m_pWndFinder;
QAction* m_pDisableForce;
QAction* m_pDisableForce2;
@ -378,6 +385,7 @@ private:
QAction* m_pStopSvc;
QAction* m_pUninstallSvc;
QAction* m_pStopAll;
QAction* m_pImDiskCpl;
QAction* m_pUninstallAll;
QAction* m_pSetupWizard;
QAction* m_pExit;
@ -430,6 +438,7 @@ private:
QLabel* m_pDisabledForce;
QLabel* m_pDisabledRecovery;
QLabel* m_pDisabledMessages;
QLabel* m_pRamDiskInfo;
// for old menu
QMenu* m_pSandbox;

View File

@ -35,6 +35,7 @@ HEADERS += ./stdafx.h \
./Wizards/TemplateWizard.h \
./Wizards/SetupWizard.h \
./Wizards/BoxAssistant.h \
./Windows/BoxImageWindow.h \
./Engine/BoxEngine.h \
./Engine/ScriptManager.h \
./Engine/BoxObject.h \
@ -82,6 +83,7 @@ SOURCES += ./main.cpp \
./Wizards/TemplateWizard.cpp \
./Wizards/SetupWizard.cpp \
./Wizards/BoxAssistant.cpp \
./Windows/BoxImageWindow.cpp \
./Engine/BoxEngine.cpp \
./Engine/ScriptManager.cpp \
./Engine/BoxObject.cpp \
@ -96,7 +98,8 @@ FORMS += ./Forms/SelectBoxWindow.ui \
./Forms/PopUpWindow.ui \
./Forms/RecoveryWindow.ui \
./Forms/SettingsWindow.ui \
./Forms/SnapshotsWindow.ui
./Forms/SnapshotsWindow.ui \
./Forms/BoxImageWindow.ui
TRANSLATIONS += sandman_de.ts \
sandman_en.ts \

View File

@ -428,6 +428,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="Windows\OptionsWindow.cpp" />
<ClCompile Include="Windows\BoxImageWindow.cpp" />
<ClCompile Include="Windows\PopUpWindow.cpp" />
<ClCompile Include="Windows\RecoveryWindow.cpp" />
<ClCompile Include="Windows\SelectBoxWindow.cpp" />
@ -441,6 +442,7 @@
</ItemGroup>
<ItemGroup>
<QtMoc Include="Wizards\BoxAssistant.h" />
<QtMoc Include="Windows\BoxImageWindow.h" />
<QtMoc Include="Views\StackView.h" />
<QtMoc Include="Wizards\TemplateWizard.h" />
<QtMoc Include="Wizards\NewBoxWizard.h" />
@ -471,6 +473,7 @@
<QtMoc Include="Engine\WizardObject.h" />
<QtMoc Include="Engine\JSEngineExt.h" />
<QtMoc Include="Engine\ScriptManager.h" />
<ClInclude Include="CustomStyles.h" />
<ClInclude Include="Engine\V4ScriptDebuggerApi.h" />
<ClInclude Include="Helpers\FindTool.h" />
<ClInclude Include="Helpers\FullScreen.h" />
@ -495,6 +498,7 @@
<Image Include="Resources\SandMan.ico" />
</ItemGroup>
<ItemGroup>
<QtUic Include="Forms\BoxImageWindow.ui" />
<QtUic Include="Forms\OptionsWindow.ui" />
<QtUic Include="Forms\PopUpWindow.ui" />
<QtUic Include="Forms\RecoveryWindow.ui" />

View File

@ -52,6 +52,9 @@
<Filter Include="Engine">
<UniqueIdentifier>{7f2e2eea-0d08-44d4-af39-01390e441438}</UniqueIdentifier>
</Filter>
<Filter Include="Issues">
<UniqueIdentifier>{db551bfd-c355-40b8-a6db-516e75998d94}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
@ -192,6 +195,9 @@
<ClCompile Include="Views\StackView.cpp">
<Filter>Views</Filter>
</ClCompile>
<ClCompile Include="Windows\BoxImageWindow.cpp">
<Filter>Windows</Filter>
</ClCompile>
<ClCompile Include="Wizards\BoxAssistant.cpp">
<Filter>Wizards</Filter>
</ClCompile>
@ -257,6 +263,9 @@
<ClInclude Include="Engine\V4ScriptDebuggerApi.h">
<Filter>Engine</Filter>
</ClInclude>
<ClInclude Include="CustomStyles.h">
<Filter>SandMan</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<QtMoc Include="SandMan.h">
@ -331,6 +340,9 @@
<QtMoc Include="Views\StackView.h">
<Filter>Views</Filter>
</QtMoc>
<QtMoc Include="Windows\BoxImageWindow.h">
<Filter>Windows</Filter>
</QtMoc>
<QtMoc Include="Wizards\BoxAssistant.h">
<Filter>Wizards</Filter>
</QtMoc>
@ -397,6 +409,9 @@
<QtUic Include="Forms\SelectBoxWindow.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="Forms\BoxImageWindow.ui">
<Filter>Form Files</Filter>
</QtUic>
</ItemGroup>
<ItemGroup>
<None Include="sandman_de.ts">

View File

@ -98,6 +98,7 @@ void CSandMan::CreateTrayMenu()
m_pTrayMenu->addSeparator();
m_pTrayMenu->addAction(m_pEmptyAll);
m_pTrayMenu->addAction(m_pLockAll);
m_pTrayMenu->addSeparator();
m_pTrayMenu->addAction(m_pDisableForce2);
if(m_pDisableRecovery) m_pTrayMenu->addAction(m_pDisableRecovery);

View File

@ -126,11 +126,14 @@ CSandBoxPlus::CSandBoxPlus(const QString& BoxName, class CSbieAPI* pAPI) : CSand
m_bSharesAllowed = false;
m_bDropRights = false;
m_bRamDisk = false;
m_bImageFile = false;
m_bSecurityEnhanced = false;
m_bPrivacyEnhanced = false;
m_bApplicationCompartment = false;
m_iUnsecureDebugging = 0;
m_bEncryptedAndConfidential = false;
m_bRootAccessOpen = false;
m_TotalSize = theConf->GetValue("SizeCache/" + m_Name, -1).toLongLong();
@ -186,7 +189,7 @@ protected:
CArchive* m_pArchive;
};
void CSandBoxPlus::ExportBoxAsync(const CSbieProgressPtr& pProgress, const QString& ExportPath, const QString& RootPath, const QString& Section)
void CSandBoxPlus::ExportBoxAsync(const CSbieProgressPtr& pProgress, const QString& ExportPath, const QString& RootPath, const QString& Section, const QString& Password)
{
//CArchive Archive(ExportPath + ".tmp");
CArchive Archive(ExportPath);
@ -226,6 +229,9 @@ void CSandBoxPlus::ExportBoxAsync(const CSbieProgressPtr& pProgress, const QStri
// this file is already present in the archive, this should not happen !!!
}
if (!Password.isEmpty())
Archive.SetPassword(Password);
SB_STATUS Status = SB_OK;
if (!Archive.Update(&Files, true, theConf->GetInt("Options/ExportCompression", 3))) // 0, 1 - 9
Status = SB_ERR((ESbieMsgCodes)SBX_7zCreateFailed);
@ -240,7 +246,7 @@ void CSandBoxPlus::ExportBoxAsync(const CSbieProgressPtr& pProgress, const QStri
pProgress->Finish(Status);
}
SB_PROGRESS CSandBoxPlus::ExportBox(const QString& FileName)
SB_PROGRESS CSandBoxPlus::ExportBox(const QString& FileName, const QString& Password)
{
if (!CArchive::IsInit())
return SB_ERR((ESbieMsgCodes)SBX_7zNotReady);
@ -254,14 +260,17 @@ SB_PROGRESS CSandBoxPlus::ExportBox(const QString& FileName)
QString Section = theAPI->SbieIniGetEx(m_Name, "");
CSbieProgressPtr pProgress = CSbieProgressPtr(new CSbieProgress());
QtConcurrent::run(CSandBoxPlus::ExportBoxAsync, pProgress, FileName, m_FilePath, Section);
QtConcurrent::run(CSandBoxPlus::ExportBoxAsync, pProgress, FileName, m_FilePath, Section, Password);
return SB_PROGRESS(OP_ASYNC, pProgress);
}
void CSandBoxPlus::ImportBoxAsync(const CSbieProgressPtr& pProgress, const QString& ImportPath, const QString& RootPath, const QString& BoxName)
void CSandBoxPlus::ImportBoxAsync(const CSbieProgressPtr& pProgress, const QString& ImportPath, const QString& RootPath, const QString& BoxName, const QString& Password)
{
CArchive Archive(ImportPath);
if (!Password.isEmpty())
Archive.SetPassword(Password);
if (Archive.Open() != ERR_7Z_OK) {
pProgress->Finish(SB_ERR((ESbieMsgCodes)SBX_7zOpenFailed));
return;
@ -308,13 +317,13 @@ void CSandBoxPlus::ImportBoxAsync(const CSbieProgressPtr& pProgress, const QStri
pProgress->Finish(Status);
}
SB_PROGRESS CSandBoxPlus::ImportBox(const QString& FileName)
SB_PROGRESS CSandBoxPlus::ImportBox(const QString& FileName, const QString& Password)
{
if (!CArchive::IsInit())
return SB_ERR((ESbieMsgCodes)SBX_7zNotReady);
CSbieProgressPtr pProgress = CSbieProgressPtr(new CSbieProgress());
QtConcurrent::run(CSandBoxPlus::ImportBoxAsync, pProgress, FileName, m_FilePath, m_Name);
QtConcurrent::run(CSandBoxPlus::ImportBoxAsync, pProgress, FileName, m_FilePath, m_Name, Password);
return SB_PROGRESS(OP_ASYNC, pProgress);
}
@ -349,6 +358,14 @@ void CSandBoxPlus::UpdateDetails()
m_bDropRights = GetBool("DropAdminRights", false);
m_bRamDisk = GetBool("UseRamDisk", false);
m_bImageFile = GetBool("UseFileImage", false);
QStringList DenyHostAccess = GetTextList("DenyHostAccess", true, false, true);
//bool bIsPrivate = DenyHostAccess.contains("y", Qt::CaseInsensitive) || DenyHostAccess.contains("yes", Qt::CaseInsensitive)
// || DenyHostAccess.contains("*,y", Qt::CaseInsensitive) || DenyHostAccess.contains("*,yes", Qt::CaseInsensitive);
m_bEncryptedAndConfidential = m_bImageFile && GetBool("ConfidentialBox", false, true, true); // && bIsPrivate;
m_bRootAccessOpen = false;
foreach(const QString& Setting, QString("OpenFilePath|OpenKeyPath|OpenPipePath|OpenConfPath").split("|")) {
foreach(const QString& Entry, GetTextList(Setting, false)) {
@ -587,8 +604,19 @@ void CSandBoxPlus::UpdateSize(bool bReset)
if(bReset)
m_TotalSize = -1;
m_bImageFile = GetBool("UseFileImage", false);
m_IsEmpty = IsEmpty();
if (m_bImageFile) {
LARGE_INTEGER liSparseFileCompressedSize;
liSparseFileCompressedSize.LowPart = GetCompressedFileSize(GetBoxImagePath().toStdWString().c_str(), (LPDWORD)&liSparseFileCompressedSize.HighPart);
m_TotalSize = liSparseFileCompressedSize.QuadPart;
}
if (m_bImageFile && m_Mount.isEmpty())
return;
if(theConf->GetBool("Options/WatchBoxSize", false) && m_TotalSize == -1)
((CSbiePlusAPI*)theAPI)->m_BoxMonitor->ScanBox(this);
}
@ -633,8 +661,18 @@ SB_STATUS CSandBoxPlus::RenameBox(const QString& NewName)
BeginModifyingBox();
QString OldBoxImagePath = GetBoxImagePath();
SB_STATUS Status = CSandBox::RenameBox(NewName);
if (!Status.IsError() && QFile::exists(OldBoxImagePath)) {
((CSbiePlusAPI*)m_pAPI)->UpdateBoxPaths(this);
if(!QFile::rename(OldBoxImagePath, GetBoxImagePath()))
Status = SB_ERR(SB_FailedMoveImage, QVariantList() <<OldBoxImagePath << GetBoxImagePath(), 0xC0000001 /*STATUS_UNSUCCESSFUL*/);
}
ConnectEndSlot(Status);
return Status;
@ -680,6 +718,8 @@ bool CSandBoxPlus::IsEmpty() const
{
if (!CSandBox::IsEmpty())
return false;
if(m_bImageFile && QFile::exists(GetBoxImagePath()))
return false;
return true;
}
@ -752,6 +792,9 @@ CSandBoxPlus::EBoxTypes CSandBoxPlus::GetTypeImpl() const
if (m_bRootAccessOpen)
return eOpen;
if (m_bEncryptedAndConfidential)
return ePrivate;
if (m_bApplicationCompartment && m_bPrivacyEnhanced)
return eAppBoxPlus;
if (m_bApplicationCompartment)

View File

@ -72,8 +72,8 @@ public:
CSandBoxPlus(const QString& BoxName, class CSbieAPI* pAPI);
virtual ~CSandBoxPlus();
SB_PROGRESS ExportBox(const QString& FileName);
SB_PROGRESS ImportBox(const QString& FileName);
SB_PROGRESS ExportBox(const QString& FileName, const QString& Password = "");
SB_PROGRESS ImportBox(const QString& FileName, const QString& Password = "");
virtual void UpdateDetails();
@ -91,10 +91,14 @@ public:
virtual SB_PROGRESS RemoveSnapshot(const QString& ID) { BeginModifyingBox(); SB_PROGRESS Status = CSandBox::RemoveSnapshot(ID); ConnectEndSlot(Status); return Status; }
virtual SB_PROGRESS SelectSnapshot(const QString& ID) { BeginModifyingBox(); SB_PROGRESS Status = CSandBox::SelectSnapshot(ID); ConnectEndSlot(Status); return Status; }
virtual SB_STATUS ImBoxMount(const QString& Password = QString(), bool bProtect = false, bool bAutoUnmount = false) { BeginModifyingBox(); SB_STATUS Status = CSandBox::ImBoxMount(Password, bProtect, bAutoUnmount); ConnectEndSlot(Status); return Status; }
virtual SB_STATUS ImBoxUnmount() { BeginModifyingBox(); SB_STATUS Status = CSandBox::ImBoxUnmount(); if(!Status.IsError()) m_Mount.clear(); ConnectEndSlot(Status); return Status; }
virtual bool IsEmpty() const;
virtual QString GetStatusStr() const;
virtual QString GetBoxImagePath() const { return m_FilePath + ".box"; }
virtual void SetINetBlock(bool bEnable);
virtual bool IsINetBlocked() const { return m_bINetBlocked; }
@ -105,6 +109,9 @@ public:
virtual void SetDropRights(bool bEnable);
virtual bool IsDropRights() const { return m_bDropRights; }
virtual bool UseRamDisk() const { return m_bRamDisk; }
virtual bool UseImageFile() const { return m_bImageFile; }
virtual bool IsUnsecureDebugging() const { return m_iUnsecureDebugging != 0; }
virtual void BlockProgram(const QString& ProgName);
@ -143,9 +150,13 @@ public:
eDefault,
eAppBoxPlus,
eAppBox,
eInsecure,
eOpen,
ePrivatePlus,
ePrivate,
eUnknown
};
@ -209,8 +220,8 @@ protected:
void AddJobToQueue(CBoxJob* pJob);
void StartNextJob();
static void ExportBoxAsync(const CSbieProgressPtr& pProgress, const QString& ExportPath, const QString& RootPath, const QString& Section);
static void ImportBoxAsync(const CSbieProgressPtr& pProgress, const QString& ImportPath, const QString& RootPath, const QString& BoxName);
static void ExportBoxAsync(const CSbieProgressPtr& pProgress, const QString& ExportPath, const QString& RootPath, const QString& Section, const QString& Password = "");
static void ImportBoxAsync(const CSbieProgressPtr& pProgress, const QString& ImportPath, const QString& RootPath, const QString& BoxName, const QString& Password = "");
bool IsFileDeleted(const QString& RealPath, const QString& Snapshot, const QStringList& SnapshotList, const QMap<QString, QList<QString>>& DeletedPaths);
@ -221,10 +232,14 @@ protected:
bool m_bSharesAllowed;
bool m_bDropRights;
bool m_bRamDisk;
bool m_bImageFile;
bool m_bSecurityEnhanced;
bool m_bPrivacyEnhanced;
bool m_bApplicationCompartment;
int m_iUnsecureDebugging;
bool m_bEncryptedAndConfidential;
bool m_bRootAccessOpen;
quint64 m_TotalSize;

View File

@ -13,6 +13,7 @@
#include "../Views/FileView.h"
#include "../Wizards/NewBoxWizard.h"
#include "../Helpers/WinHelper.h"
#include "../Windows/BoxImageWindow.h"
#include "../MiscHelpers/Archive/Archive.h"
#include "../Windows/SettingsWindow.h"
@ -204,6 +205,8 @@ void CSbieView::CreateMenu()
m_pMenuExplore = m_pMenuContent->addAction(CSandMan::GetIcon("Explore"), tr("Explore Content"), this, SLOT(OnSandBoxAction()));
m_pMenuRegEdit = m_pMenuContent->addAction(CSandMan::GetIcon("RegEdit"), tr("Open Registry"), this, SLOT(OnSandBoxAction()));
m_pMenuSnapshots = m_pMenuBox->addAction(CSandMan::GetIcon("Snapshots"), tr("Snapshots Manager"), this, SLOT(OnSandBoxAction()));
m_pMenuMount = m_pMenuBox->addAction(CSandMan::GetIcon("LockOpen"), tr("Mount Box Image"), this, SLOT(OnSandBoxAction()));
m_pMenuUnmount = m_pMenuBox->addAction(CSandMan::GetIcon("LockClosed"), tr("Unmount Box Image"), this, SLOT(OnSandBoxAction()));
m_pMenuRecover = m_pMenuBox->addAction(CSandMan::GetIcon("Recover"), tr("Recover Files"), this, SLOT(OnSandBoxAction()));
m_pMenuCleanUp = m_pMenuBox->addAction(CSandMan::GetIcon("Erase"), tr("Delete Content"), this, SLOT(OnSandBoxAction()));
m_pMenuBox->addSeparator();
@ -284,6 +287,7 @@ void CSbieView::CreateOldMenu()
m_pNewBox = m_pMenu->addAction(CSandMan::GetIcon("NewBox"), tr("Create New Box"), this, SLOT(OnGroupAction()));
m_pAddGroupe = m_pMenu->addAction(CSandMan::GetIcon("Group"), tr("Create Box Group"), this, SLOT(OnGroupAction()));
m_pImportBox = m_pMenu->addAction(CSandMan::GetIcon("UnPackBox"), tr("Import Box"), this, SLOT(OnGroupAction()));
m_pImportBox->setEnabled(CArchive::IsInit());
m_pMenuBox = new QMenu();
@ -322,6 +326,8 @@ void CSbieView::CreateOldMenu()
m_pMenuBox->addSeparator();
m_pMenuEmptyBox = m_pMenuBox->addAction(CSandMan::GetIcon("EmptyAll"), tr("Terminate Programs"), this, SLOT(OnSandBoxAction()));
m_pMenuMount = m_pMenuBox->addAction(CSandMan::GetIcon("LockOpen"), tr("Mount Box Image"), this, SLOT(OnSandBoxAction()));
m_pMenuUnmount = m_pMenuBox->addAction(CSandMan::GetIcon("LockClosed"), tr("Unmount Box Image"), this, SLOT(OnSandBoxAction()));
m_pMenuRecover = m_pMenuBox->addAction(CSandMan::GetIcon("Recover"), tr("Quick Recover"), this, SLOT(OnSandBoxAction()));
m_pMenuCleanUp = m_pMenuBox->addAction(CSandMan::GetIcon("Erase"), tr("Delete Content"), this, SLOT(OnSandBoxAction()));
m_pMenuExplore = m_pMenuBox->addAction(CSandMan::GetIcon("Explore"), tr("Explore Content"), this, SLOT(OnSandBoxAction()));
@ -540,6 +546,8 @@ void CSbieView::OnToolTipCallback(const QVariant& ID, QString& ToolTip)
ToolTip += tr(" File root: %1\n").arg(pBoxEx->GetFileRoot());
ToolTip += tr(" Registry root: %1\n").arg(pBoxEx->GetRegRoot());
ToolTip += tr(" IPC root: %1\n").arg(pBoxEx->GetIpcRoot());
if(!pBoxEx->GetMountRoot().isEmpty())
ToolTip += tr(" Disk root: %1\n").arg(pBoxEx->GetMountRoot());
ToolTip += tr("Options:\n ");
ToolTip += pBoxEx->GetStatusStr().replace(", ", "\n ");
@ -572,30 +580,48 @@ void CSbieView::OnCustomSortByColumn(int column)
}
}
bool CSbieView::UpdateMenu(bool bAdvanced, const CSandBoxPtr &pBox, int iSandBoxeCount, bool bBoxBusy)
bool CSbieView::UpdateMenu(bool bAdvanced, const CSandBoxPtr &pBox, int iSandBoxeCount, bool bBoxBusy, bool bBoxNotMounted)
{
QList<QAction*> MenuActions = m_pMenu->actions();
m_pStopAsync->setVisible(bBoxBusy);
m_pMenuRun->setEnabled(iSandBoxeCount == 1);
auto pBoxEx = pBox.objectCast<CSandBoxPlus>();
m_pStopAsync->setVisible(bBoxBusy);
m_pMenuMount->setVisible(bBoxNotMounted);
m_pMenuMount->setEnabled(iSandBoxeCount == 1);
if (bBoxBusy)
iSandBoxeCount = 0;
m_pMenuRun->setEnabled(iSandBoxeCount == 1);
if(iSandBoxeCount == 1)
UpdateRunMenu(pBox);
m_pMenuRename->setEnabled(iSandBoxeCount == 1 && pBoxEx->GetMountRoot().isEmpty());
if (bBoxNotMounted)
iSandBoxeCount = 0;
m_pMenuMkLink->setEnabled(iSandBoxeCount == 1);
m_pMenuTools->setEnabled(iSandBoxeCount == 1);
m_pMenuRename->setEnabled(iSandBoxeCount == 1);
m_pMenuUnmount->setVisible(pBoxEx && pBoxEx->UseImageFile() && !pBoxEx->GetMountRoot().isEmpty());
m_pMenuRecover->setEnabled(iSandBoxeCount == 1);
m_pMenuCleanUp->setEnabled(iSandBoxeCount > 0);
if (m_pMenuContent) m_pMenuContent->setEnabled(iSandBoxeCount > 0);
m_pMenuEmptyBox->setEnabled(iSandBoxeCount > 0);
if (m_pMenuPresets) {
m_pMenuPresets->setEnabled(iSandBoxeCount == 1);
m_pMenuPresetsShowUAC->setChecked(pBox && !pBox->GetBool("DropAdminRights", false) && !pBox->GetBool("FakeAdminRights", false));
m_pMenuPresetsNoAdmin->setChecked(pBox && pBox->GetBool("DropAdminRights", false) && !pBox->GetBool("FakeAdminRights", false));
m_pMenuPresetsFakeAdmin->setChecked(pBox && pBox->GetBool("DropAdminRights", false) && pBox->GetBool("FakeAdminRights", false));
m_pMenuPresetsINet->setChecked(pBox && pBox.objectCast<CSandBoxPlus>()->IsINetBlocked());
m_pMenuPresetsShares->setChecked(pBox && pBox.objectCast<CSandBoxPlus>()->HasSharesAccess());
m_pMenuPresetsRecovery->setChecked(pBox && pBox->GetBool("AutoRecover", false));
m_pMenuPresetsForce->setChecked(pBox && pBox->GetBool("DisableForceRules", false));
if (iSandBoxeCount == 1) {
m_pMenuPresetsShowUAC->setChecked(pBox && !pBox->GetBool("DropAdminRights", false) && !pBox->GetBool("FakeAdminRights", false));
m_pMenuPresetsNoAdmin->setChecked(pBox && pBox->GetBool("DropAdminRights", false) && !pBox->GetBool("FakeAdminRights", false));
m_pMenuPresetsFakeAdmin->setChecked(pBox && pBox->GetBool("DropAdminRights", false) && pBox->GetBool("FakeAdminRights", false));
m_pMenuPresetsINet->setChecked(pBox && pBox.objectCast<CSandBoxPlus>()->IsINetBlocked());
m_pMenuPresetsShares->setChecked(pBox && pBox.objectCast<CSandBoxPlus>()->HasSharesAccess());
m_pMenuPresetsRecovery->setChecked(pBox && pBox->GetBool("AutoRecover", false));
m_pMenuPresetsForce->setChecked(pBox && pBox->GetBool("DisableForceRules", false));
}
}
m_pMenuBrowse->setEnabled(iSandBoxeCount == 1);
@ -655,6 +681,7 @@ bool CSbieView::UpdateMenu()
CSandBoxPtr pBox;
bool bBoxBusy = false;
bool bBoxNotMounted = false;
CBoxedProcessPtr pProcess;
int iProcessCount = 0;
int iSandBoxeCount = 0;
@ -684,18 +711,18 @@ bool CSbieView::UpdateMenu()
iSandBoxeCount = -1;
else if (iSandBoxeCount != -1)
iSandBoxeCount++;
auto pBoxEx = pBox.objectCast<CSandBoxPlus>();
if(pBoxEx->IsBoxBusy())
bBoxBusy = true;
if (pBoxEx->UseImageFile() && pBoxEx->GetMountRoot().isEmpty())
bBoxNotMounted = true;
}
else
iGroupe++;
}
}
if (bBoxBusy) {
iSandBoxeCount = 0;
iGroupe = 0;
}
bool bAdvanced = theConf->GetInt("Options/ViewMode", 1) == 1
|| (QGuiApplication::queryKeyboardModifiers() & Qt::ControlModifier) != 0;
@ -705,7 +732,7 @@ bool CSbieView::UpdateMenu()
if (!pProcess.isNull())
UpdateProcMenu(pProcess, iProcessCount, iSuspendedCount);
return UpdateMenu(bAdvanced, pBox, iSandBoxeCount, bBoxBusy);
return UpdateMenu(bAdvanced, pBox, iSandBoxeCount, bBoxBusy, bBoxNotMounted);
}
void CSbieView::OnMenu(const QPoint& Point)
@ -1006,11 +1033,38 @@ QString CSbieView::AddNewBox(bool bAlowTemp)
QString CSbieView::ImportSandbox()
{
QString Value = QFileDialog::getOpenFileName(this, tr("Select file name"), "", tr("7-zip Archive (*.7z)"));
if (Value.isEmpty())
QString Path = QFileDialog::getOpenFileName(this, tr("Select file name"), "", tr("7-zip Archive (*.7z)"));
if (Path.isEmpty())
return "";
StrPair PathName = Split2(Value, "/", true);
QString Password;
quint64 ImageSize = 0;
CArchive Archive(Path);
int Ret = Archive.Open();
if (Ret == ERR_7Z_PASSWORD_REQUIRED) {
for (;;) {
CBoxImageWindow window(CBoxImageWindow::eImport, this);
if (!theGUI->SafeExec(&window) == 1)
return "";
Archive.SetPassword(window.GetPassword());
Ret = Archive.Open();
if (Ret != ERR_7Z_OK) {
QMessageBox::critical(this, "Sandboxie-Plus", tr("Failed to open archive, wrong password?"));
continue;
}
Password = window.GetPassword();
ImageSize = window.GetImageSize();
break;
}
}
if (Ret != ERR_7Z_OK) {
QMessageBox::critical(this, "Sandboxie-Plus", tr("Failed to open archive (%1)!").arg(Ret));
return "";
}
Archive.Close();
StrPair PathName = Split2(Path, "/", true);
StrPair NameEx = Split2(PathName.second, ".", true);
QString Name = NameEx.first;
@ -1029,11 +1083,19 @@ QString CSbieView::ImportSandbox()
pBox = theAPI->GetBoxByName(Name);
if (pBox) {
auto pBoxEx = pBox.objectCast<CSandBoxPlus>();
Status = pBoxEx->ImportBox(Value);
if (!Password.isEmpty()) {
Status = pBoxEx->ImBoxCreate(ImageSize / 1024, Password);
if (!Status.IsError())
Status = pBoxEx->ImBoxMount(Password, true, true);
}
if (!Status.IsError())
Status = pBoxEx->ImportBox(Path, Password);
}
}
if (Status.GetStatus() == OP_ASYNC) {
Status = theGUI->AddAsyncOp(Status.GetValue(), true, tr("Importing: %1").arg(Value));
Status = theGUI->AddAsyncOp(Status.GetValue(), true, tr("Importing: %1").arg(Path));
if (Status.IsError()) {
theGUI->DeleteBoxContent(pBox, CSandMan::eForDelete);
pBox->RemoveBox();
@ -1316,15 +1378,24 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList<CSandBoxPtr>& SandB
}
else if (Action == m_pMenuExport)
{
QString Value = QFileDialog::getSaveFileName(this, tr("Select file name"), SandBoxes.first()->GetName() + ".7z", tr("7-zip Archive (*.7z)"));
if (Value.isEmpty())
return;
CSandBoxPtr pBox = SandBoxes.first();
auto pBoxEx = pBox.objectCast<CSandBoxPlus>();
SB_PROGRESS Status = pBoxEx->ExportBox(Value);
QString Path = QFileDialog::getSaveFileName(this, tr("Select file name"), SandBoxes.first()->GetName() + ".7z", tr("7-zip Archive (*.7z)"));
if (Path.isEmpty())
return;
QString Password;
if (pBoxEx->UseImageFile()) {
CBoxImageWindow window(CBoxImageWindow::eExport, this);
if (!theGUI->SafeExec(&window) == 1)
return;
Password = window.GetPassword();
}
SB_PROGRESS Status = pBoxEx->ExportBox(Path, Password);
if (Status.GetStatus() == OP_ASYNC)
theGUI->AddAsyncOp(Status.GetValue(), false, tr("Exporting: %1").arg(Value));
theGUI->AddAsyncOp(Status.GetValue(), false, tr("Exporting: %1").arg(Path));
else
Results.append(Status);
}
@ -1346,6 +1417,18 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList<CSandBoxPtr>& SandB
}
Results.append(Status);
}
else if (Action == m_pMenuMount)
{
Results.append(theGUI->ImBoxMount(SandBoxes.first()));
}
else if (Action == m_pMenuUnmount)
{
foreach(const CSandBoxPtr& pBox, SandBoxes) {
auto pBoxEx = pBox.objectCast<CSandBoxPlus>();
pBoxEx->TerminateAll();
Results.append(pBox->ImBoxUnmount());
}
}
else if (Action == m_pMenuRecover)
{
theGUI->ShowRecovery(SandBoxes.first());
@ -1358,6 +1441,10 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList<CSandBoxPtr>& SandB
bool bChanged = false;
foreach(const CSandBoxPtr& pBox, SandBoxes)
{
auto pBoxPlus = pBox.objectCast<CSandBoxPlus>();
if (pBoxPlus->UseImageFile() && !pBoxPlus->GetMountRoot().isEmpty())
pBoxPlus->ImBoxUnmount();
SB_STATUS Status = SB_OK;
if (!pBox->GetBool("IsShadow")) {

View File

@ -123,8 +123,8 @@ private:
void CreateGroupMenu();
void CreateTrayMenu();
bool UpdateMenu(bool bAdvanced, const CSandBoxPtr &pBox, int iSandBoxeCount = 1, bool bBoxBusy = false);
void UpdateProcMenu(const CBoxedProcessPtr &pProcess = CBoxedProcessPtr(), int iProcessCount = 0, int iSuspendedCount = 0);
bool UpdateMenu(bool bAdvanced, const CSandBoxPtr &pBox, int iSandBoxeCount = 1, bool bBoxBusy = false, bool bBoxNotMounted = false);
void UpdateProcMenu(const CBoxedProcessPtr &pProcess, int iProcessCount = 0, int iSuspendedCount = 0);
bool UpdateMenu();
void UpdateMoveMenu();
void RenameGroup(const QString OldName, const QString NewName);
@ -191,6 +191,8 @@ private:
QAction* m_pMenuBrowse;
QAction* m_pMenuRefresh;
QAction* m_pMenuRegEdit;
QAction* m_pMenuMount;
QAction* m_pMenuUnmount;
QAction* m_pMenuRecover;
QAction* m_pMenuCleanUp;
QAction* m_pMenuRemove;

View File

@ -378,7 +378,7 @@ void CTraceView::SetEnabled(bool bSet)
void CTraceView::OnShowStack()
{
if (!theGUI->GetAddonManager()->GetAddon("DbgHelp", CAddonManager::eInstalled).isNull())
if (m_pShowStack->isChecked() && !theGUI->GetAddonManager()->GetAddon("DbgHelp", CAddonManager::eInstalled).isNull())
theGUI->GetAddonManager()->TryInstallAddon("DbgHelp", this, tr("To use the stack traces feature the DbgHelp.dll and SymSrv.dll are required, do you want to download and install them?"));
theAPI->GetGlobalSettings()->SetBool("MonitorStackTrace", m_pShowStack->isChecked());
m_pTrace->m_pStackView->setVisible(m_pShowStack->isChecked());

View File

@ -0,0 +1,152 @@
#include "stdafx.h"
#include "BoxImageWindow.h"
#include "SandMan.h"
#include "../MiscHelpers/Common/Settings.h"
#include "../MiscHelpers/Common/Common.h"
CBoxImageWindow::CBoxImageWindow(EAction Action, QWidget *parent)
: QDialog(parent)
{
Qt::WindowFlags flags = windowFlags();
flags |= Qt::CustomizeWindowHint;
//flags &= ~Qt::WindowContextHelpButtonHint;
//flags &= ~Qt::WindowSystemMenuHint;
//flags &= ~Qt::WindowMinMaxButtonsHint;
//flags |= Qt::WindowMinimizeButtonHint;
//flags &= ~Qt::WindowCloseButtonHint;
flags &= ~Qt::WindowContextHelpButtonHint;
//flags &= ~Qt::WindowSystemMenuHint;
setWindowFlags(flags);
ui.setupUi(this);
this->setWindowTitle(tr("Sandboxie-Plus - Password Entry"));
m_Action = Action;
connect(ui.chkShow, SIGNAL(clicked(bool)), this, SLOT(OnShowPassword()));
connect(ui.txtImageSize, SIGNAL(textChanged(const QString&)), this, SLOT(OnImageSize()));
connect(ui.buttonBox, SIGNAL(accepted()), SLOT(CheckPassword()));
connect(ui.buttonBox, SIGNAL(rejected()), SLOT(reject()));
switch (m_Action)
{
case eNew:
ui.lblInfo->setText(tr("Creating new box image, please enter a secure password, and choose a disk image size."));
ui.lblIcon->setPixmap(QPixmap::fromImage(QImage(":/Actions/LockClosed.png")));
break;
case eMount:
ui.lblInfo->setText(tr("Enter Box Image password:"));
ui.lblIcon->setPixmap(QPixmap::fromImage(QImage(":/Actions/LockOpen.png")));
break;
case eChange:
ui.lblInfo->setText(tr("Enter Box Image passwords:"));
ui.lblIcon->setPixmap(QPixmap::fromImage(QImage(":/Actions/LockClosed.png")));
case eExport:
ui.lblInfo->setText(tr("Enter Encryption passwords for archive export:"));
ui.lblIcon->setPixmap(QPixmap::fromImage(QImage(":/Actions/LockClosed.png")));
case eImport:
ui.lblInfo->setText(tr("Enter Encryption passwords for archive import:"));
ui.lblIcon->setPixmap(QPixmap::fromImage(QImage(":/Actions/LockOpen.png")));
break;
}
if (m_Action == eNew || m_Action == eExport)
ui.txtNewPassword->setFocus();
else
ui.txtPassword->setFocus();
if (m_Action == eNew || m_Action == eImport)
ui.txtImageSize->setText(QString::number(2 * 1024 * 1024)); // suggest 2GB
else {
ui.lblImageSize->setVisible(false);
ui.txtImageSize->setVisible(false);
ui.lblImageSizeKb->setVisible(false);
}
if (m_Action == eNew || m_Action == eExport) {
ui.lblPassword->setVisible(false);
ui.txtPassword->setVisible(false);
}
if (m_Action == eMount || m_Action == eImport){
ui.lblNewPassword->setVisible(false);
ui.txtNewPassword->setVisible(false);
ui.lblRepeatPassword->setVisible(false);
ui.txtRepeatPassword->setVisible(false);
}
//if (!bNew) {
ui.lblCipher->setVisible(false);
ui.cmbCipher->setVisible(false);
//}
ui.cmbCipher->addItem("AES", 0);
ui.cmbCipher->addItem("Twofish", 1);
ui.cmbCipher->addItem("Serpent", 2);
ui.cmbCipher->addItem("AES-Twofish", 3);
ui.cmbCipher->addItem("Twofish-Serpent", 4);
ui.cmbCipher->addItem("Serpent-AES", 5);
ui.cmbCipher->addItem("AES-Twofish-Serpent", 6);
if (m_Action != eMount)
ui.chkProtect->setVisible(false);
//restoreGeometry(theConf->GetBlob("BoxImageWindow/Window_Geometry"));
}
CBoxImageWindow::~CBoxImageWindow()
{
//theConf->SetBlob("BoxImageWindow/Window_Geometry", saveGeometry());
}
void CBoxImageWindow::OnShowPassword()
{
ui.txtPassword->setEchoMode(ui.chkShow->isChecked() ? QLineEdit::Normal : QLineEdit::Password);
ui.txtNewPassword->setEchoMode(ui.chkShow->isChecked() ? QLineEdit::Normal : QLineEdit::Password);
ui.txtRepeatPassword->setEchoMode(ui.chkShow->isChecked() ? QLineEdit::Normal : QLineEdit::Password);
}
void CBoxImageWindow::OnImageSize()
{
ui.lblImageSizeKb->setText(tr("kilobytes (%1)").arg(FormatSize(GetImageSize())));
}
void CBoxImageWindow::CheckPassword()
{
if (m_Action == eMount || m_Action == eImport) {
m_Password = ui.txtPassword->text();
}
else {
if (ui.txtNewPassword->text() != ui.txtRepeatPassword->text()) {
QMessageBox::critical(this, "Sandboxie-Plus", tr("Passwords don't match!!!"));
return;
}
if (ui.txtNewPassword->text().length() < 20) {
if (QMessageBox::warning(this, "Sandboxie-Plus", tr("WARNING: Short passwords are easy to crack using brute force techniques!\n\n"
"It is recommended to choose a password consisting of 20 or more characters. Are you sure you want to use a short password?")
, QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes)
return;
}
if (m_Action == eNew || m_Action == eExport)
m_Password = ui.txtNewPassword->text();
else if (m_Action == eChange) {
m_Password = ui.txtPassword->text();
m_NewPassword = ui.txtNewPassword->text();
}
}
if (m_Action == eNew || m_Action == eImport) {
if (GetImageSize() < 128 * 1024 * 1024) { // ask for 256 mb but silently accept >= 128 mb
QMessageBox::critical(this, "Sandboxie-Plus", tr("The Box Disk Image must be at least 256 MB in size, 2GB are recommended."));
SetImageSize(256 * 1024 * 1024);
return;
}
}
accept();
}

View File

@ -0,0 +1,40 @@
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_BoxImageWindow.h"
#include "SbiePlusAPI.h"
class CBoxImageWindow : public QDialog
{
Q_OBJECT
public:
enum EAction {
eNew,
eMount,
eChange,
eExport,
eImport
};
CBoxImageWindow(EAction Action, QWidget *parent = Q_NULLPTR);
~CBoxImageWindow();
QString GetPassword() const { return m_Password; }
QString GetNewPassword() const { return m_NewPassword; }
void SetImageSize(quint64 uSize) const { return ui.txtImageSize->setText(QString::number(uSize / 1024)); }
quint64 GetImageSize() const { return ui.txtImageSize->text().toULongLong() * 1024; }
bool UseProtection() const { return ui.chkProtect->isChecked(); }
private slots:
void OnShowPassword();
void OnImageSize();
void CheckPassword();
private:
Ui::BoxImageWindow ui;
EAction m_Action;
QString m_Password;
QString m_NewPassword;
};

View File

@ -94,14 +94,16 @@ void COptionsWindow::CreateAdvanced()
connect(ui.btnDelProcess, SIGNAL(clicked(bool)), this, SLOT(OnDelProcess()));
connect(ui.chkShowHiddenProcTmpl, SIGNAL(clicked(bool)), this, SLOT(OnShowHiddenProcTmpl()));
connect(ui.btnAddHostProcess, SIGNAL(clicked(bool)), this, SLOT(OnAddHostProcess()));
connect(ui.btnHostProcessAllow, SIGNAL(clicked(bool)), this, SLOT(OnHostProcessAllow()));
connect(ui.btnHostProcessDeny, SIGNAL(clicked(bool)), this, SLOT(OnHostProcessDeny()));
connect(ui.btnDelHostProcess, SIGNAL(clicked(bool)), this, SLOT(OnDelHostProcess()));
connect(ui.chkShowHostProcTmpl, SIGNAL(clicked(bool)), this, SLOT(OnShowHostProcTmpl()));
connect(ui.chkConfidential, SIGNAL(clicked(bool)), this, SLOT(OnAdvancedChanged())); // todo notify premium feature
connect(ui.chkConfidential, SIGNAL(clicked(bool)), this, SLOT(OnAdvancedChanged())); // todo norify premium feaure
connect(ui.chkNotifyProtect, SIGNAL(clicked(bool)), this, SLOT(OnAdvancedChanged()));
connect(ui.treeInjectDll, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(OnToggleInjectDll(QTreeWidgetItem *, int)));
connect(ui.treeInjectDll, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(OnDblClickInjedtDll(QTreeWidgetItem*, int)));
connect(ui.chkHostProtect, SIGNAL(clicked(bool)), this, SLOT(OnHostProtectChanged()));
connect(ui.chkHostProtectMsg, SIGNAL(clicked(bool)), this, SLOT(OnAdvancedChanged()));
@ -189,6 +191,7 @@ void COptionsWindow::LoadAdvanced()
}
}
ui.chkHostProtect->setChecked(m_pBox->GetBool("ProtectHostImages", false));
ui.chkHostProtectMsg->setEnabled(ui.chkHostProtect->isChecked());
ui.chkHostProtectMsg->setChecked(m_pBox->GetBool("NotifyImageLoadDenied", true));
@ -236,11 +239,16 @@ void COptionsWindow::LoadAdvanced()
ui.treeHostProc->clear();
foreach(const QString & Value, m_pBox->GetTextList("DenyHostAccess", m_Template)) {
StrPair NameVal = Split2(Value, ",");
AddHostProcEntry(NameVal.first, NameVal.second.left(0).toLower() != "y");
if (NameVal.second.isEmpty()) {
NameVal.second = NameVal.first;
NameVal.first = "*";
}
AddHostProcEntry(NameVal.first, NameVal.second.left(1).toLower() == "y");
}
ShowHostProcTmpl();
ui.chkConfidential->setChecked(m_pBox->GetBool("ConfidentialBox", false));
ui.chkNotifyProtect->setChecked(m_pBox->GetBool("NotifyBoxProtected", false));
QStringList Users = m_pBox->GetText("Enabled").split(",");
@ -430,12 +438,12 @@ void COptionsWindow::SaveAdvanced()
int Type = pItem->data(0, Qt::UserRole).toInt();
if (Type == -1)
continue; // entry from template
DenyHostProcesses.append(pItem->text(0) + "," + (pItem->data(1, Qt::UserRole).toBool() ? "n" : "y"));
DenyHostProcesses.append(pItem->text(0) + "," + (pItem->data(1, Qt::UserRole).toBool() ? "y" : "n"));
}
WriteTextList("DenyHostAccess", DenyHostProcesses);
WriteAdvancedCheck(ui.chkConfidential, "ConfidentialBox", "y", "");
WriteAdvancedCheck(ui.chkNotifyProtect, "NotifyBoxProtected", "y", "");
QStringList Users;
for (int i = 0; i < ui.lstUsers->count(); i++)
@ -931,13 +939,25 @@ void COptionsWindow::OnDelProcess()
OnOptChanged();
}
void COptionsWindow::OnAddHostProcess()
void COptionsWindow::OnHostProcessAllow()
{
QString Process = QInputDialog::getText(this, "Sandboxie-Plus", tr("Please enter a program file name"));
QString Process = QInputDialog::getText(this, "Sandboxie-Plus", tr("Please enter a program file name to allow access to this sandbox"));
if (Process.isEmpty())
return;
AddHostProcEntry(Process);
AddHostProcEntry(Process, false);
m_AdvancedChanged = true;
OnOptChanged();
}
void COptionsWindow::OnHostProcessDeny()
{
QString Process = QInputDialog::getText(this, "Sandboxie-Plus", tr("Please enter a program file name to deny access to this sandbox"));
if (Process.isEmpty())
return;
AddHostProcEntry(Process, true);
m_AdvancedChanged = true;
OnOptChanged();
@ -983,7 +1003,7 @@ void COptionsWindow::ShowHostProcTmpl(bool bUpdate)
{
foreach(const QString & Value, m_pBox->GetTextListTmpl("DenyHostAccess", Template)) {
StrPair NameVal = Split2(Value, ",");
AddHostProcEntry(NameVal.first, NameVal.second.left(0).toLower() != "y", Template);
AddHostProcEntry(NameVal.first, NameVal.second.left(1).toLower() == "y", Template);
}
}
}
@ -1010,13 +1030,13 @@ void COptionsWindow::AddHiddenProcEntry(const QString& Name, const QString& Temp
ui.treeHideProc->addTopLevelItem(pItem);
}
void COptionsWindow::AddHostProcEntry(const QString& Name, bool Value, const QString& Template)
void COptionsWindow::AddHostProcEntry(const QString& Name, bool Deny, const QString& Template)
{
QTreeWidgetItem* pItem = new QTreeWidgetItem();
pItem->setText(0, Name + (Template.isEmpty() ? "" : " (" + Template + ")"));
pItem->setData(0, Qt::UserRole, Template.isEmpty() ? 0 : -1);
pItem->setText(1, Value ? tr("Deny") : tr("Allow"));
pItem->setData(1, Qt::UserRole, Value);
pItem->setText(1, Deny ? tr("Deny") : tr("Allow"));
pItem->setData(1, Qt::UserRole, Deny);
ui.treeHostProc->addTopLevelItem(pItem);
}

View File

@ -8,36 +8,42 @@
#include "../MiscHelpers/Common/SettingsWidgets.h"
#include "Helpers/WinAdmin.h"
#include "Helpers/WinHelper.h"
#include "Windows/BoxImageWindow.h"
#include "AddonManager.h"
#include "../../../SandboxieTools/ImBox/ImBox.h"
class CCertBadge: public QLabel
{
public:
CCertBadge(QWidget* parent = NULL): QLabel(parent)
CCertBadge(bool bAdvanced, QWidget* parent = NULL): QLabel(parent)
{
m_bAdvanced = bAdvanced;
setPixmap(QPixmap(":/Actions/Cert.png").scaled(16, 16, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
if (!g_CertInfo.active) {
if(bAdvanced)
setToolTip(COptionsWindow::tr("This option requires an active <b>advanced</b> supporter certificate"));
else
setToolTip(COptionsWindow::tr("This option requires an active supporter certificate"));
setCursor(Qt::PointingHandCursor);
} else {
setToolTip(COptionsWindow::tr("Supporter exclusive option"));
}
setCursor(Qt::PointingHandCursor);
}
protected:
void mousePressEvent(QMouseEvent* event)
{
if(!g_CertInfo.active)
if(m_bAdvanced && g_CertInfo.active)
theGUI->OpenUrl(QUrl("https://sandboxie-plus.com/go.php?to=sbie-upgrade-cert"));
else
theGUI->OpenUrl(QUrl("https://sandboxie-plus.com/go.php?to=sbie-get-cert"));
}
bool m_bAdvanced;
};
void COptionsWindow__AddCertIcon(QWidget* pOriginalWidget)
void COptionsWindow__AddCertIcon(QWidget* pOriginalWidget, bool bAdvanced = false)
{
QWidget* pWidget = new QWidget();
QHBoxLayout* pLayout = new QHBoxLayout(pWidget);
pLayout->setContentsMargins(0, 0, 0, 0);
pLayout->setSpacing(0);
pLayout->addWidget(new CCertBadge());
pLayout->addWidget(new CCertBadge(bAdvanced));
pLayout->setAlignment(Qt::AlignLeft);
pOriginalWidget->parentWidget()->layout()->replaceWidget(pOriginalWidget, pWidget);
pLayout->insertWidget(0, pOriginalWidget);
@ -60,7 +66,7 @@ void COptionsWindow::CreateGeneral()
ui.cmbBoxType->addItem(theGUI->GetBoxIcon(CSandBoxPlus::eDefault), tr("Standard Isolation Sandbox (Default)"), (int)CSandBoxPlus::eDefault);
//ui.cmbBoxType->addItem(theGUI->GetBoxIcon(CSandBoxPlus::eInsecure), tr("INSECURE Configuration (please change)"), (int)CSandBoxPlus::eInsecure);
ui.cmbBoxType->addItem(theGUI->GetBoxIcon(CSandBoxPlus::eAppBoxPlus), tr("Application Compartment with Data Protection"), (int)CSandBoxPlus::eAppBoxPlus);
ui.cmbBoxType->addItem(theGUI->GetBoxIcon(CSandBoxPlus::eAppBox), tr("Application Compartment (NO Isolation)"), (int)CSandBoxPlus::eAppBox);
ui.cmbBoxType->addItem(theGUI->GetBoxIcon(CSandBoxPlus::eAppBox), tr("Application Compartment"), (int)CSandBoxPlus::eAppBox);
connect(ui.lblBoxInfo, SIGNAL(linkActivated(const QString&)), theGUI, SLOT(OpenUrl(const QString&)));
@ -88,6 +94,9 @@ void COptionsWindow::CreateGeneral()
for (QWidget** ExWidget = ExWidgets; *ExWidget != NULL; ExWidget++)
COptionsWindow__AddCertIcon(*ExWidget);
}
if (!CERT_IS_LEVEL(g_CertInfo, eCertAdvanced)) {
COptionsWindow__AddCertIcon(ui.chkEncrypt, true);
}
m_HoldBoxType = false;
@ -174,6 +183,25 @@ void COptionsWindow::CreateGeneral()
connect(ui.chkSeparateUserFolders, SIGNAL(clicked(bool)), this, SLOT(OnGeneralChanged()));
connect(ui.chkUseVolumeSerialNumbers, SIGNAL(clicked(bool)), this, SLOT(OnGeneralChanged()));
connect(ui.chkRamBox, SIGNAL(clicked(bool)), this, SLOT(OnDiskChanged()));
connect(ui.chkEncrypt, SIGNAL(clicked(bool)), this, SLOT(OnDiskChanged()));
connect(ui.btnPassword, SIGNAL(clicked(bool)), this, SLOT(OnSetPassword()));
bool bImDiskReady = theGUI->IsImDiskReady();
ui.lblImDisk->setVisible(!bImDiskReady);
connect(ui.lblImDisk, SIGNAL(linkActivated(const QString&)), theGUI, SLOT(OpenUrl(const QString&)));
QObject::connect(theGUI->GetAddonManager(), &CAddonManager::AddonInstalled, this, [=] {
if (!theGUI->GetAddonManager()->GetAddon("ImDisk", CAddonManager::eInstalled).isNull()) {
ui.lblImDisk->setVisible(false);
ui.chkRamBox->setEnabled(bEmpty);
ui.chkEncrypt->setEnabled(bEmpty);
ui.lblCrypto->setEnabled(true);
}
});
ui.chkRamBox->setEnabled(bImDiskReady && bEmpty);
ui.chkEncrypt->setEnabled(bImDiskReady && bEmpty);
ui.lblCrypto->setEnabled(bImDiskReady);
connect(ui.txtCopyLimit, SIGNAL(textChanged(const QString&)), this, SLOT(OnGeneralChanged()));
connect(ui.chkCopyLimit, SIGNAL(clicked(bool)), this, SLOT(OnGeneralChanged()));
connect(ui.chkCopyPrompt, SIGNAL(clicked(bool)), this, SLOT(OnGeneralChanged()));
@ -293,6 +321,15 @@ void COptionsWindow::LoadGeneral()
ReadGlobalCheck(ui.chkSeparateUserFolders, "SeparateUserFolders", theAPI->GetGlobalSettings()->GetBool("SeparateUserFolders", true));
ReadGlobalCheck(ui.chkUseVolumeSerialNumbers, "UseVolumeSerialNumbers", theAPI->GetGlobalSettings()->GetBool("UseVolumeSerialNumbers", false));
ui.chkRamBox->setChecked(m_pBox->GetBool("UseRamDisk", false));
ui.chkEncrypt->setChecked(m_pBox->GetBool("UseFileImage", false));
if (ui.chkRamBox->isEnabled())
ui.chkEncrypt->setEnabled(!ui.chkRamBox->isChecked());
CSandBoxPlus* pBoxEx = qobject_cast<CSandBoxPlus*>(m_pBox.data());
if (pBoxEx && QFile::exists(pBoxEx->GetBoxImagePath()))
ui.btnPassword->setText(tr("Change Password"));
ui.btnPassword->setEnabled(!ui.chkRamBox->isChecked() && ui.chkEncrypt->isChecked() && pBoxEx && pBoxEx->GetMountRoot().isEmpty());
int iLimit = m_pBox->GetNum("CopyLimitKb", 80 * 1024);
ui.chkCopyLimit->setChecked(iLimit != -1);
ui.txtCopyLimit->setText(QString::number(iLimit > 0 ? iLimit : 80 * 1024));
@ -406,6 +443,9 @@ void COptionsWindow::SaveGeneral()
WriteGlobalCheck(ui.chkSeparateUserFolders, "SeparateUserFolders", true);
WriteGlobalCheck(ui.chkUseVolumeSerialNumbers, "UseVolumeSerialNumbers", false);
WriteAdvancedCheck(ui.chkRamBox, "UseRamDisk", "y", "");
WriteAdvancedCheck(ui.chkEncrypt, "UseFileImage", "y", "");
}
int iLimit = ui.chkCopyLimit->isChecked() ? ui.txtCopyLimit->text().toInt() : -1;
@ -1057,3 +1097,62 @@ void COptionsWindow::OnVmRead()
m_AdvancedChanged = true;
OnOptChanged();
}
void COptionsWindow::OnDiskChanged()
{
if (sender() == ui.chkEncrypt) {
if (ui.chkEncrypt->isChecked())
theGUI->CheckCertificate(this, true);
}
if (ui.chkRamBox->isChecked()) {
ui.chkEncrypt->setEnabled(false);
ui.chkEncrypt->setChecked(false);
ui.btnPassword->setEnabled(false);
}
else {
ui.chkEncrypt->setEnabled(true);
CSandBoxPlus* pBoxEx = qobject_cast<CSandBoxPlus*>(m_pBox.data());
ui.btnPassword->setEnabled(ui.chkEncrypt->isChecked() && pBoxEx && pBoxEx->GetMountRoot().isEmpty());
}
OnGeneralChanged();
}
void COptionsWindow::OnSetPassword()
{
CSandBoxPlus* pBoxEx = qobject_cast<CSandBoxPlus*>(m_pBox.data());
bool bNew = !QFile::exists(pBoxEx->GetBoxImagePath());
CBoxImageWindow window(bNew ? CBoxImageWindow::eNew : CBoxImageWindow::eChange, this);
if (bNew) window.SetImageSize(m_ImageSize);
if (theGUI->SafeExec(&window) == 1) {
m_Password = window.GetPassword();
if (bNew) {
m_ImageSize = window.GetImageSize();
OnGeneralChanged();
}
else {
QString m_NewPassword = window.GetNewPassword();
QStringList Arguments;
Arguments.append("type=image");
Arguments.append("image=" + pBoxEx->GetBoxImagePath());
Arguments.append("key=" + m_Password);
Arguments.append("new_key=" + m_NewPassword);
QProcess Process;
Process.start(theAPI->GetSbiePath() + "\\ImBox.exe", Arguments);
Process.waitForFinished();
int ret = Process.exitCode();
if (ret != ERR_OK) {
QString Message;
switch (ret) {
case ERR_FILE_NOT_OPENED: Message = tr("The image file does not exist"); break;
case ERR_WRONG_PASSWORD: Message = tr("The password is wrong"); break;
default: Message = tr("Unexpected error: %1").arg(ret); break;
}
QMessageBox::critical(this, "Sandboxie-Plus", Message);
}
}
}
}

View File

@ -160,6 +160,8 @@ COptionsWindow::COptionsWindow(const QSharedPointer<CSbieIni>& pBox, const QStri
m_HoldChange = false;
m_ImageSize = 2ull*1024*1024*1024;
QSharedPointer<CSandBoxPlus> pBoxPlus = m_pBox.objectCast<CSandBoxPlus>();
if (!pBoxPlus.isNull())
m_Programs = pBoxPlus->GetRecentPrograms();
@ -207,7 +209,7 @@ COptionsWindow::COptionsWindow(const QSharedPointer<CSbieIni>& pBox, const QStri
ui.tabsSecurity->setCurrentIndex(0);
ui.tabsSecurity->setTabIcon(0, CSandMan::GetIcon("Shield7"));
ui.tabsSecurity->setTabIcon(1, CSandMan::GetIcon("Fence"));
ui.tabsSecurity->setTabIcon(2, CSandMan::GetIcon("Shield2"));
ui.tabsSecurity->setTabIcon(2, CSandMan::GetIcon("Shield15"));
ui.tabsSecurity->setTabIcon(3, CSandMan::GetIcon("Shield12"));
ui.tabsForce->setCurrentIndex(0);
@ -221,8 +223,6 @@ COptionsWindow::COptionsWindow(const QSharedPointer<CSbieIni>& pBox, const QStri
ui.tabsInternet->setCurrentIndex(0);
ui.tabsInternet->setTabIcon(0, CSandMan::GetIcon("Program"));
ui.tabsInternet->setTabIcon(1, CSandMan::GetIcon("Wall"));
ui.tabsInternet->setTabIcon(2, CSandMan::GetIcon("DNS"));
ui.tabsInternet->setTabIcon(3, CSandMan::GetIcon("Proxy"));
ui.tabsAccess->setCurrentIndex(0);
ui.tabsAccess->setTabIcon(0, CSandMan::GetIcon("Folder"));
@ -237,14 +237,17 @@ COptionsWindow::COptionsWindow(const QSharedPointer<CSbieIni>& pBox, const QStri
ui.tabsRecovery->setTabIcon(0, CSandMan::GetIcon("QuickRecovery"));
ui.tabsRecovery->setTabIcon(1, CSandMan::GetIcon("ImmidiateRecovery"));
ui.tabsOther->setCurrentIndex(0);
ui.tabsOther->setTabIcon(0, CSandMan::GetIcon("Presets"));
ui.tabsOther->setTabIcon(1, CSandMan::GetIcon("Dll"));
ui.tabsAdvanced->setCurrentIndex(0);
ui.tabsAdvanced->setTabIcon(0, CSandMan::GetIcon("Presets"));
ui.tabsAdvanced->setTabIcon(1, CSandMan::GetIcon("Trigger"));
ui.tabsAdvanced->setTabIcon(2, CSandMan::GetIcon("Anon"));
ui.tabsAdvanced->setTabIcon(3, CSandMan::GetIcon("Users"));
ui.tabsAdvanced->setTabIcon(4, CSandMan::GetIcon("Presets"));
ui.tabsAdvanced->setTabIcon(5, CSandMan::GetIcon("SetLogging"));
ui.tabsAdvanced->setTabIcon(6, CSandMan::GetIcon("Bug"));
ui.tabsAdvanced->setTabIcon(4, CSandMan::GetIcon("SetLogging"));
ui.tabsAdvanced->setTabIcon(5, CSandMan::GetIcon("Bug"));
ui.tabsTemplates->setCurrentIndex(0);
ui.tabsTemplates->setTabIcon(0, CSandMan::GetIcon("Template"));
@ -262,8 +265,6 @@ COptionsWindow::COptionsWindow(const QSharedPointer<CSbieIni>& pBox, const QStri
QWidget* pDummy = new QWidget(this);
pDummy->setVisible(false);
ui.tabs->removeTab(9); // remove unused variouse options tab
// merge recovery tabs
QWidget* pWidget3 = new QWidget();
pWidget3->setLayout(ui.gridLayout_10);
@ -355,6 +356,7 @@ COptionsWindow::COptionsWindow(const QSharedPointer<CSbieIni>& pBox, const QStri
AddIconToLabel(ui.lblRawDisk, CSandMan::GetIcon("Disk").pixmap(size,size));
AddIconToLabel(ui.lblSecurity, CSandMan::GetIcon("Shield5").pixmap(size,size));
AddIconToLabel(ui.lblElevation, CSandMan::GetIcon("Shield9").pixmap(size,size));
AddIconToLabel(ui.lblBoxProtection, CSandMan::GetIcon("BoxConfig").pixmap(size,size));
AddIconToLabel(ui.lblNetwork, CSandMan::GetIcon("Network").pixmap(size,size));
AddIconToLabel(ui.lblPrinting, CSandMan::GetIcon("Printer").pixmap(size,size));
AddIconToLabel(ui.lblOther, CSandMan::GetIcon("NoAccess").pixmap(size,size));
@ -954,7 +956,7 @@ void COptionsWindow::SaveConfig()
}
catch (SB_STATUS Status)
{
theGUI->CheckResults(QList<SB_STATUS>() << Status, this);
theGUI->CheckResults(QList<SB_STATUS>() << Status, theGUI);
}
m_pBox->SetRefreshOnChange(true);
@ -964,11 +966,11 @@ void COptionsWindow::SaveConfig()
TriggerPathReload();
}
void COptionsWindow::apply()
bool COptionsWindow::apply()
{
if (m_pBox->GetText("Enabled").isEmpty() && !(m_Template && m_pBox->GetName().mid(9, 6).compare("Local_", Qt::CaseInsensitive) == 0)) {
QMessageBox::critical(this, "Sandboxie-Plus", tr("This sandbox has been deleted hence configuration can not be saved."));
return;
return false;
}
CloseINetEdit();
@ -979,7 +981,20 @@ void COptionsWindow::apply()
if (!ui.btnEditIni->isEnabled())
SaveIniSection();
else
{
if (m_GeneralChanged) {
CSandBoxPlus* pBoxEx = qobject_cast<CSandBoxPlus*>(m_pBox.data());
if (ui.chkEncrypt->isChecked() && !QFile::exists(pBoxEx->GetBoxImagePath())) {
if (m_Password.isEmpty())
OnSetPassword();
if (m_Password.isEmpty())
return false;
pBoxEx->ImBoxCreate(m_ImageSize / 1024, m_Password);
}
}
SaveConfig();
}
LoadConfig();
@ -988,13 +1003,14 @@ void COptionsWindow::apply()
//emit OptionsChanged();
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
return true;
}
void COptionsWindow::ok()
{
apply();
this->close();
if(apply())
close();
}
void COptionsWindow::reject()

View File

@ -38,7 +38,7 @@ signals:
public slots:
void ok();
void apply();
bool apply();
void showTab(const QString& Name);
@ -72,6 +72,9 @@ private slots:
void OnVmRead();
void OnDiskChanged();
void OnSetPassword();
void OnAddGroup();
void OnAddProg();
void OnDelProg();
@ -190,7 +193,8 @@ private slots:
void OnDelProcess();
void OnShowHiddenProcTmpl() { ShowHiddenProcTmpl(true); }
void OnAddHostProcess();
void OnHostProcessAllow();
void OnHostProcessDeny();
void OnDelHostProcess();
void OnShowHostProcTmpl() { ShowHostProcTmpl(true); }
@ -315,6 +319,7 @@ public:
eReadOnly,
eBoxOnly,
eIgnoreUIPI,
eMaxAccessMode
};
@ -326,6 +331,13 @@ public:
eDeleteCmd
};
static QString AccessTypeToName(EAccessEntry Type);
static QPair<EAccessType, EAccessMode> SplitAccessType(EAccessEntry Type);
static QString GetAccessTypeStr(EAccessType Type);
static QString GetAccessModeStr(EAccessMode Mode);
static QString GetAccessModeTip(EAccessMode Mode);
protected:
void SetBoxColor(const QColor& color);
void UpdateBoxColor();
@ -414,13 +426,9 @@ protected:
// access
void CreateAccess();
QString AccessTypeToName(EAccessEntry Type);
void LoadAccessList();
void LoadAccessListTmpl(bool bUpdate = false);
void LoadAccessListTmpl(EAccessType Type, bool bChecked, bool bUpdate = false);
QString GetAccessTypeStr(EAccessType Type);
QString GetAccessModeStr(EAccessMode Mode);
QString GetAccessModeTip(EAccessMode Mode);
void ParseAndAddAccessEntry(EAccessEntry EntryType, const QString& Value, bool disabled = false, const QString& Template = QString());
void ParseAndAddAccessEntry(EAccessType Type, EAccessMode Mode, const QString& Value, bool disabled = false, const QString& Template = QString());
QString ExpandPath(EAccessType Type, const QString& Path);
@ -455,7 +463,7 @@ protected:
void ShowHiddenProcTmpl(bool bUpdate = false);
void ShowHostProcTmpl(bool bUpdate = false);
void AddHiddenProcEntry(const QString& Name, const QString& Template = QString());
void AddHostProcEntry(const QString& Name, bool Value = true, const QString& Template = QString());
void AddHostProcEntry(const QString& Name, bool Deny, const QString& Template = QString());
void CheckOpenCOM();
//
@ -541,6 +549,9 @@ protected:
QMap<QString, SAdvOption> m_AdvOptions;
QString m_Password;
quint64 m_ImageSize;
private:
void ReadAdvancedCheck(const QString& Name, QCheckBox* pCheck, const QString& Value = "y");

View File

@ -88,7 +88,7 @@ quint32 g_FeatureFlags = 0;
QByteArray g_Certificate;
SCertInfo g_CertInfo = { 0 };
void COptionsWindow__AddCertIcon(QWidget* pOriginalWidget);
void COptionsWindow__AddCertIcon(QWidget* pOriginalWidget, bool bAdvanced = false);
CSettingsWindow::CSettingsWindow(QWidget* parent)
: CConfigDialog(parent)
@ -142,7 +142,7 @@ CSettingsWindow::CSettingsWindow(QWidget* parent)
ui.tabsAddons->setCurrentIndex(0);
ui.tabsAddons->setTabIcon(0, CSandMan::GetIcon("Plugin"));
//ui.tabsAddons->setTabIcon(1, CSandMan::GetIcon("Qube"));
ui.tabsAddons->setTabIcon(1, CSandMan::GetIcon("Qube"));
ui.tabsSupport->setCurrentIndex(0);
ui.tabsSupport->setTabIcon(0, CSandMan::GetIcon("Cert"));
@ -180,6 +180,8 @@ CSettingsWindow::CSettingsWindow(QWidget* parent)
AddIconToLabel(ui.lblDisplay, CSandMan::GetIcon("Advanced").pixmap(size,size));
AddIconToLabel(ui.lblIni, CSandMan::GetIcon("EditIni").pixmap(size,size));
AddIconToLabel(ui.lblDiskImage, CSandMan::GetIcon("Disk").pixmap(size,size));
AddIconToLabel(ui.lblBoxRoot, CSandMan::GetIcon("Sandbox").pixmap(size,size));
AddIconToLabel(ui.lblBoxFeatures, CSandMan::GetIcon("Miscellaneous").pixmap(size,size));
@ -364,6 +366,16 @@ CSettingsWindow::CSettingsWindow(QWidget* parent)
theGUI->GetAddonManager()->UpdateAddons();
});
connect(ui.chkRamDisk, SIGNAL(stateChanged(int)), this, SLOT(OnRamDiskChange()));
connect(ui.lblImDisk, SIGNAL(linkActivated(const QString&)), theGUI, SLOT(OpenUrl(const QString&)));
QObject::connect(theGUI->GetAddonManager(), &CAddonManager::AddonInstalled, this, [=] {
if (!theGUI->GetAddonManager()->GetAddon("ImDisk", CAddonManager::eInstalled).isNull()) {
ui.lblImDisk->setVisible(false);
ui.chkRamDisk->setEnabled(true);
OnRamDiskChange();
}
});
connect(ui.txtRamLimit, SIGNAL(textChanged(const QString&)), this, SLOT(OnRamDiskChange()));
//
// Advanced Config
@ -880,6 +892,9 @@ void CSettingsWindow::LoadSettings()
OnLoadAddon();
bool bImDiskReady = theGUI->IsImDiskReady();
ui.lblImDisk->setVisible(!bImDiskReady);
if (theAPI->IsConnected())
{
ui.treeMessages->clear();
@ -912,6 +927,14 @@ void CSettingsWindow::LoadSettings()
ui.regRoot->setText(theAPI->GetGlobalSettings()->GetText("KeyRootPath", KeyRootPath_Default));
ui.ipcRoot->setText(theAPI->GetGlobalSettings()->GetText("IpcRootPath", IpcRootPath_Default));
ui.chkRamDisk->setEnabled(bImDiskReady);
quint32 uDiskLimit = theAPI->GetGlobalSettings()->GetNum64("RamDiskSizeKb");
ui.chkRamDisk->setChecked(uDiskLimit > 0);
if(uDiskLimit > 0) ui.txtRamLimit->setText(QString::number(uDiskLimit));
m_HoldChange = true;
OnRamDiskChange();
m_HoldChange = false;
ui.chkWFP->setChecked(theAPI->GetGlobalSettings()->GetBool("NetworkEnableWFP", false));
ui.chkObjCb->setChecked(theAPI->GetGlobalSettings()->GetBool("EnableObjectFiltering", true));
ui.chkWin32k->setChecked(theAPI->GetGlobalSettings()->GetBool("EnableWin32kHooks", true));
@ -955,6 +978,9 @@ void CSettingsWindow::LoadSettings()
ui.chkSbieLogon->setEnabled(false);
ui.regRoot->setEnabled(false);
ui.ipcRoot->setEnabled(false);
ui.chkRamDisk->setEnabled(false);
ui.txtRamLimit->setEnabled(false);
ui.lblRamLimit->setEnabled(false);
ui.chkAdminOnly->setEnabled(false);
ui.chkPassRequired->setEnabled(false);
ui.chkAdminOnlyFP->setEnabled(false);
@ -1018,11 +1044,25 @@ void CSettingsWindow::LoadSettings()
ui.chkUpdateIssues->setEnabled(g_CertInfo.active && !g_CertInfo.expired);
}
void CSettingsWindow::OnRamDiskChange()
{
if (ui.chkRamDisk->isChecked() && ui.txtRamLimit->text().isEmpty())
ui.txtRamLimit->setText(QString::number(2 * 1024 * 1024));
bool bEnabled = ui.chkRamDisk->isChecked() && ui.chkRamDisk->isEnabled();
ui.lblRamDisk->setEnabled(bEnabled);
ui.txtRamLimit->setEnabled(bEnabled);
ui.lblRamLimit->setEnabled(bEnabled);
ui.lblRamLimit->setText(tr("kilobytes (%1)").arg(FormatSize(ui.txtRamLimit->text().toULongLong() * 1024)));
OnGeneralChanged();
}
void CSettingsWindow::UpdateCert()
{
ui.lblCertExp->setVisible(false);
//ui.lblCertLevel->setVisible(!g_Certificate.isEmpty());
if (!g_Certificate.isEmpty())
if (!g_Certificate.isEmpty())
{
ui.txtCertificate->setPlainText(g_Certificate);
//ui.lblSupport->setVisible(false);
@ -1035,26 +1075,25 @@ void CSettingsWindow::UpdateCert()
QString infoMsg = tr("This supporter certificate has expired, please <a href=\"https://sandboxie-plus.com/go.php?to=sbie-renew-cert\">get an updated certificate</a>.");
if (g_CertInfo.active) {
if (g_CertInfo.grace_period)
infoMsg.append(tr("<br /><font color='red'>Plus features will be disabled in %1 days.</font>").arg((g_CertInfo.expirers_in_sec + 30 * 60 * 60 * 24) / (60 * 60 * 24)));
infoMsg.append(tr("<br /><font color='red'>Plus features will be disabled in %1 days.</font>").arg((g_CertInfo.expirers_in_sec + 30*60*60*24) / (60*60*24)));
else if (!g_CertInfo.outdated) // must be an expiren medium or large cert on an old build
infoMsg.append(tr("<br /><font color='red'>For the current build Plus features remain enabled</font>, but you no longer have access to Sandboxie-Live services, including compatibility updates and the troubleshooting database."));
}
else
} else
infoMsg.append(tr("<br />Plus features are no longer enabled."));
ui.lblCertExp->setText(infoMsg);
ui.lblCertExp->setVisible(true);
}
else {
if (g_CertInfo.expirers_in_sec > 0 && g_CertInfo.expirers_in_sec < (60 * 60 * 24 * 30)) {
ui.lblCertExp->setText(tr("This supporter certificate will <font color='red'>expire in %1 days</font>, please <a href=\"https://sandboxie-plus.com/go.php?to=sbie-renew-cert\">get an updated certificate</a>.").arg(g_CertInfo.expirers_in_sec / (60 * 60 * 24)));
ui.lblCertExp->setText(tr("This supporter certificate will <font color='red'>expire in %1 days</font>, please <a href=\"https://sandboxie-plus.com/go.php?to=sbie-renew-cert\">get an updated certificate</a>.").arg(g_CertInfo.expirers_in_sec / (60*60*24)));
ui.lblCertExp->setVisible(true);
}
/*#ifdef _DEBUG
else {
ui.lblCertExp->setText(tr("This supporter certificate is valid, <a href=\"https://sandboxie-plus.com/go.php?to=sbie-renew-cert\">check for an updated certificate</a>."));
ui.lblCertExp->setVisible(true);
}
#endif*/
/*#ifdef _DEBUG
else {
ui.lblCertExp->setText(tr("This supporter certificate is valid, <a href=\"https://sandboxie-plus.com/go.php?to=sbie-renew-cert\">check for an updated certificate</a>."));
ui.lblCertExp->setVisible(true);
}
#endif*/
palette.setColor(QPalette::Base, QColor(192, 255, 192));
}
ui.txtCertificate->setPalette(palette);
@ -1396,6 +1435,8 @@ void CSettingsWindow::SaveSettings()
WriteText("KeyRootPath", ui.regRoot->text()); //ui.regRoot->setText("\\REGISTRY\\USER\\Sandbox_%USER%_%SANDBOX%");
WriteText("IpcRootPath", ui.ipcRoot->text()); //ui.ipcRoot->setText("\\Sandbox\\%USER%\\%SANDBOX%\\Session_%SESSION%");
WriteText("RamDiskSizeKb", ui.chkRamDisk->isChecked() ? ui.txtRamLimit->text() : "");
WriteAdvancedCheck(ui.chkWFP, "NetworkEnableWFP", "y", "");
WriteAdvancedCheck(ui.chkObjCb, "EnableObjectFiltering", "", "n");
WriteAdvancedCheck(ui.chkWin32k, "EnableWin32kHooks", "", "n");

View File

@ -98,6 +98,8 @@ private slots:
void OnBrowse();
void OnRamDiskChange();
void OnProtectionChange();
void OnSetPassword();

View File

@ -226,7 +226,10 @@ CBeginPage::CBeginPage(QWidget *parent)
: QWizardPage(parent)
{
setTitle(tr("Troubleshooting Wizard"));
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
if (theGUI->m_DarkTheme)
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogoDM.png"));
else
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
int row = 0;
m_pLayout = new QGridLayout;
@ -325,7 +328,10 @@ CGroupPage::CGroupPage(QWidget *parent)
: QWizardPage(parent)
{
setTitle(tr("Select issue from group"));
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
if (theGUI->m_DarkTheme)
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogoDM.png"));
else
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
int row = 0;
m_pLayout = new QGridLayout;
@ -445,7 +451,10 @@ CListPage::CListPage(QWidget *parent)
: QWizardPage(parent)
{
setTitle(tr("Select issue from full list"));
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
if (theGUI->m_DarkTheme)
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogoDM.png"));
else
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
int row = 0;
m_pLayout = new QGridLayout;
@ -798,7 +807,10 @@ CSubmitPage::CSubmitPage(QWidget *parent)
: QWizardPage(parent)
{
setTitle(tr("Submit Issue Report"));
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
if (theGUI->m_DarkTheme)
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogoDM.png"));
else
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
int row = 0;
QGridLayout* pLayout = new QGridLayout;
@ -1048,7 +1060,10 @@ CCompletePage::CCompletePage(QWidget *parent)
: QWizardPage(parent)
{
setTitle(tr("Troubleshooting Completed"));
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
if (theGUI->m_DarkTheme)
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogoDM.png"));
else
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
QVBoxLayout *pLayout = new QVBoxLayout;

View File

@ -9,6 +9,8 @@
#include "../QSbieAPI/SbieUtils.h"
#include "../Views/SbieView.h"
#include "../MiscHelpers/Common/CheckableMessageBox.h"
#include "../Windows/BoxImageWindow.h"
#include "../AddonManager.h"
CNewBoxWizard::CNewBoxWizard(bool bAlowTemp, QWidget *parent)
@ -54,6 +56,35 @@ SB_STATUS CNewBoxWizard::TryToCreateBox()
BoxName.replace(" ", "_");
int BoxType = field("boxType").toInt();
QString Password;
quint64 ImageSize = 0;
if (BoxType == CSandBoxPlus::ePrivate) {
CBoxImageWindow window(CBoxImageWindow::eNew, this);
if (theGUI->SafeExec(&window) == 1) {
Password = window.GetPassword();
ImageSize = window.GetImageSize();
if (theConf->GetBool("Options/WarnBoxCrypto", true)) {
bool State = false;
if(CCheckableMessageBox::question(this, "Sandboxie-Plus",
tr("This sandbox content will be placed in an encrypted container file, "
"please note that any corruption of the container's header will render all its content permanently innaccessible. "
"Corruption can occur as a result of a BSOD, a storage hadrware failure, or a maliciouse application overwriting random files. "
"This feature is provided under a strickt <b>No Backup No Mercy</b> policy, YOU the user are responsible for the data you put into an encrypted box. "
"<br /><br />"
"IF YOU AGREE TO TAKE FULL RESPONSIBILITY FOR YOUR DATA PRESS [YES], OTHERWISE PRESS [NO].")
, tr("Don't show this message again."), &State, QDialogButtonBox::Yes | QDialogButtonBox::No, QDialogButtonBox::No, QMessageBox::Warning) != QDialogButtonBox::Yes)
return SB_ERR(SB_Canceled);
if (State)
theConf->SetValue("Options/WarnBoxCrypto", false);
}
}
else
return SB_ERR(SB_Canceled);
}
SB_STATUS Status = theAPI->CreateBox(BoxName, true);
if (!Status.IsError())
@ -80,6 +111,12 @@ SB_STATUS CNewBoxWizard::TryToCreateBox()
//pBox->InsertText("Template", "NoUACProxy"); // proxy is always needed for exes in the box
pBox->InsertText("Template", "RpcPortBindingsExt");
break;
case CSandBoxPlus::ePrivate: {
pBox->SetBool("UseFileImage", true);
pBox->SetBool("ConfidentialBox", true);
break;
}
}
QRgb rgb = theGUI->GetBoxColor(BoxType);
@ -133,6 +170,9 @@ SB_STATUS CNewBoxWizard::TryToCreateBox()
if(field("imagesProtection").toBool())
pBox->SetBool("ProtectHostImages", true);
if (!Password.isEmpty())
pBox->ImBoxCreate(ImageSize / 1024, Password);
if (field("boxVersion").toInt() == 1) {
if (theConf->GetBool("Options/WarnDeleteV2", true)) {
bool State = false;
@ -266,6 +306,11 @@ CBoxTypePage::CBoxTypePage(bool bAlowTemp, QWidget *parent)
tr("This box type prioritizes compatibility while still providing a good level of isolation. It is designed for running trusted applications within separate compartments. \n"
"While the level of isolation is reduced compared to other box types, it offers improved compatibility with a wide range of applications, ensuring smooth operation within the sandboxed environment."));
AddBoxType(tr("<a href=\"sbie://docs/boxencryption\">Encrypted</a> <a href=\"sbie://docs/black-box\">Confidential</a> Box"), (int)CSandBoxPlus::ePrivate,
tr("In this box type the sandbox uses an encrypted disk image as its root folder. This provides an additional layer of privacy and security. \n"
"Access to the virtual disk when mounted is restricted to programs running within the sandbox. Sandboxie prevents other processes on the host system from accessing the sandboxed processes. \n"
"This ensures the utmost level of privacy and data protection within the confidential sandbox environment."));//, true);
connect(m_TypeGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SIGNAL(typeChanged()));
registerField("boxType", this, "currentType", "typeChanged");
@ -287,6 +332,7 @@ CBoxTypePage::CBoxTypePage(bool bAlowTemp, QWidget *parent)
//m_pBoxType->addItem(theGUI->GetBoxIcon(CSandBoxPlus::eInsecure), tr("INSECURE Configuration (please change)"), (int)CSandBoxPlus::eInsecure);
if (bAll) m_pBoxType->addItem(theGUI->GetBoxIcon(CSandBoxPlus::eAppBoxPlus), tr("Application Compartment with Data Protection"), (int)CSandBoxPlus::eAppBoxPlus);
m_pBoxType->addItem(theGUI->GetBoxIcon(CSandBoxPlus::eAppBox), tr("Application Compartment Box"), (int)CSandBoxPlus::eAppBox);
m_pBoxType->addItem(theGUI->GetBoxIcon(CSandBoxPlus::ePrivate), tr("Confidential Encrypted Box"), (int)CSandBoxPlus::ePrivate);
connect(m_pBoxType, SIGNAL(currentIndexChanged(int)), this, SLOT(OnBoxTypChanged()));
layout->addWidget(m_pBoxType, row++, 1, 1, 2);
registerField("boxType", m_pBoxType, "currentData", "currentIndexChanged");
@ -311,6 +357,12 @@ CBoxTypePage::CBoxTypePage(bool bAlowTemp, QWidget *parent)
registerField("autoRemove", pTemp);
m_pAdvanced = new QCheckBox(tr("Configure advanced options"));
if (theGUI->m_DarkTheme) {
QPalette palette = QApplication::palette();
palette.setColor(QPalette::Base, Qt::white);
palette.setColor(QPalette::Text, Qt::black);
m_pAdvanced->setPalette(palette);
}
m_pAdvanced->setChecked(theConf->GetBool("Options/AdvancedBoxWizard", false));
layout->addWidget(m_pAdvanced, row++, 2, 1, 1);
connect(m_pAdvanced, SIGNAL(toggled(bool)), this, SLOT(OnAdvanced()));
@ -340,7 +392,7 @@ void CBoxTypePage::OnBoxTypChanged()
#endif
if(BoxType != CSandBoxPlus::eDefault)
theGUI->CheckCertificate(this);
theGUI->CheckCertificate(this, BoxType == CSandBoxPlus::ePrivate);
emit completeChanged();
}
@ -385,6 +437,17 @@ bool CBoxTypePage::validatePage()
if (!theGUI->GetBoxView()->TestNameAndWarn(BoxName))
return false;
#ifndef USE_COMBO
int BoxType = m_TypeGroup->checkedId();
#else
int BoxType = m_pBoxType->currentData().toInt();
#endif
if ((BoxType == CSandBoxPlus::ePrivate || BoxType == CSandBoxPlus::ePrivatePlus) && !theGUI->IsImDiskReady()) {
theGUI->GetAddonManager()->TryInstallAddon("ImDisk", this, tr("To use ancrypted boxes you need to install the ImDisk driver, do you want to download and install it?"));
return false;
}
if (m_bInstant && !m_pAdvanced->isChecked())
return !((CNewBoxWizard*)wizard())->TryToCreateBox().IsError();

View File

@ -156,7 +156,10 @@ CIntroPage::CIntroPage(QWidget *parent)
: QWizardPage(parent)
{
setTitle(tr("Introduction"));
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
if (theGUI->m_DarkTheme)
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogoDM.png"));
else
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
QVBoxLayout *layout = new QVBoxLayout;
QLabel* pTopLabel = new QLabel(tr("Welcome to the Setup Wizard. This wizard will help you to configure your copy of <b>Sandboxie-Plus</b>. "
@ -706,7 +709,10 @@ CFinishPage::CFinishPage(QWidget *parent)
: QWizardPage(parent)
{
setTitle(tr("Complete your configuration"));
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
if (theGUI->m_DarkTheme)
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogoDM.png"));
else
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
QVBoxLayout *layout = new QVBoxLayout;

View File

@ -256,7 +256,10 @@ CTemplateTypePage::CTemplateTypePage(QWidget *parent)
: QWizardPage(parent)
{
setTitle(tr("Create new Template"));
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
if (theGUI->m_DarkTheme)
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogoDM.png"));
else
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
int row = 0;
QGridLayout *layout = new QGridLayout;
@ -934,7 +937,10 @@ CFinishTemplatePage::CFinishTemplatePage(QWidget *parent)
: QWizardPage(parent)
{
setTitle(tr("Create Web Browser Template"));
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
if (theGUI->m_DarkTheme)
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogoDM.png"));
else
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/SideLogo.png"));
int row = 0;
QGridLayout *layout = new QGridLayout;

View File

@ -0,0 +1,18 @@
#pragma once
class CAbstractIO
{
public:
virtual ~CAbstractIO() {}
virtual ULONG64 GetAllocSize() const = 0;
virtual ULONG64 GetDiskSize() const = 0;
virtual bool CanBeFormated() const = 0;
virtual int Init() = 0;
virtual void PrepViewOfFile(BYTE*) = 0;
virtual bool DiskWrite(void* buf, int size, __int64 offset) = 0;
virtual bool DiskRead(void* buf, int size, __int64 offset) = 0;
virtual void TrimProcess(DEVICE_DATA_SET_RANGE* range, int n) = 0;
};

View File

@ -0,0 +1,366 @@
#include "framework.h"
#include <bcrypt.h>
#include "CryptoIO.h"
#include "ImBox.h"
#include "..\Common\helpers.h"
extern "C" {
#include ".\dc\include\boot\dc_header.h"
#include ".\dc\crypto_fast\crc32.h"
#include ".\dc\crypto_fast\sha512_pkcs5_2.h"
}
void make_rand(void* ptr, size_t size)
{
BCryptGenRandom(NULL, (BYTE*)ptr, size, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
}
template <class T>
struct SSecureBuffer
{
SSecureBuffer() { alloc(sizeof(T)); }
SSecureBuffer(ULONG length) { alloc(length); }
~SSecureBuffer() { free(); }
void alloc(ULONG length)
{
// on 32 bit system xts_key must be located in executable memory
// x64 does not require this
#ifdef _M_IX86
ptr = (T*)VirtualAlloc(NULL, length, MEM_COMMIT + MEM_RESERVE, PAGE_EXECUTE_READWRITE);
#else
ptr = (T*)VirtualAlloc(NULL, length, MEM_COMMIT+MEM_RESERVE, PAGE_READWRITE);
#endif
if(ptr)
VirtualLock(ptr, length);
}
void free()
{
if (!ptr)
return;
MEMORY_BASIC_INFORMATION mbi;
if ( (VirtualQuery(ptr, &mbi, sizeof(mbi)) == sizeof(mbi) && mbi.BaseAddress == ptr && mbi.AllocationBase == ptr) )
{
RtlSecureZeroMemory(ptr, mbi.RegionSize);
VirtualUnlock(ptr, mbi.RegionSize);
}
VirtualFree(ptr, 0, MEM_RELEASE);
ptr = NULL;
}
T* operator ->() { return ptr; }
explicit operator bool() { return ptr != NULL; }
T* ptr;
};
struct SCryptoIO
{
std::wstring Cipher;
bool AllowFormat;
SSecureBuffer<dc_pass> password;
xts_key benc_k;
};
CCryptoIO::CCryptoIO(CAbstractIO* pIO, const WCHAR* pKey, const std::wstring& Cipher)
{
m = new SCryptoIO;
m->Cipher = Cipher;
m->AllowFormat = false;
if (m->password) {
m->password->size = wcslen(pKey) * sizeof(wchar_t);
if (m->password->size > MAX_PASSWORD * sizeof(wchar_t))
m->password->size = MAX_PASSWORD * sizeof(wchar_t);
memcpy(m->password->pass, pKey, m->password->size);
}
m_pIO = pIO;
xts_init(1);
}
CCryptoIO::~CCryptoIO()
{
delete m;
}
ULONG64 CCryptoIO::GetDiskSize() const
{
ULONG64 uSize = m_pIO->GetDiskSize();
if (uSize < DC_AREA_SIZE)
return 0;
return uSize - DC_AREA_SIZE;
}
bool CCryptoIO::CanBeFormated() const
{
return m->AllowFormat;
}
int CCryptoIO::InitCrypto()
{
if (DC_AREA_SIZE != sizeof dc_header) {
DbgPrint(L"dc_header struct invalid!\n");
return ERR_INTERNAL;
}
if (!m->password)
return ERR_KEY_REQUIRED;
int cipher;
if (m->Cipher.empty() || _wcsicmp(m->Cipher.c_str(), L"AES") == 0 || _wcsicmp(m->Cipher.c_str(), L"Rijndael") == 0)
cipher = CF_AES;
else if (_wcsicmp(m->Cipher.c_str(), L"TWOFISH") == 0)
cipher = CF_TWOFISH;
else if (_wcsicmp(m->Cipher.c_str(), L"SERPENT") == 0)
cipher = CF_SERPENT;
else if (_wcsicmp(m->Cipher.c_str(), L"AES-TWOFISH") == 0)
cipher = CF_AES_TWOFISH;
else if (_wcsicmp(m->Cipher.c_str(), L"TWOFISH-SERPENT") == 0)
cipher = CF_TWOFISH_SERPENT;
else if (_wcsicmp(m->Cipher.c_str(), L"SERPENT-AES") == 0)
cipher = CF_SERPENT_AES;
else if (_wcsicmp(m->Cipher.c_str(), L"AES-TWOFISH-SERPENT") == 0)
cipher = CF_AES_TWOFISH_SERPENT;
else {
DbgPrint(L"Unknown Cipher.\n");
return ERR_UNKNOWN_CIPHER;
}
m->AllowFormat = m_pIO->CanBeFormated();
if (m->AllowFormat) {
DbgPrint(L"Creating DC header\n");
SSecureBuffer<dc_header> header;
if (!header) {
DbgPrint(L"Malloc Failed\n");
return ERR_MALLOC_ERROR;
}
// create the volume header
memset((BYTE*)header.ptr, 0, sizeof(dc_header));
make_rand(&header->disk_id, sizeof(header->disk_id));
make_rand(header->key_1, sizeof(header->key_1));
header->sign = DC_VOLUME_SIGN;
header->version = DC_HDR_VERSION;
header->flags = VF_NO_REDIR;
header->alg_1 = cipher;
header->data_off = sizeof(dc_header);
header->hdr_crc = crc32((const unsigned char*)&header->version, DC_CRC_AREA_SIZE);
WriteHeader(header.ptr);
}
DbgPrint(L"Trying to decrypt header...");
SSecureBuffer<dc_header> header;
if (!header) {
DbgPrint(L"Malloc Failed\n");
return ERR_MALLOC_ERROR;
}
m_pIO->DiskRead(header.ptr, sizeof(dc_header), 0);
int ret = dc_decrypt_header(header.ptr, m->password.ptr) ? ERR_OK : (m->AllowFormat ? ERR_INTERNAL : ERR_WRONG_PASSWORD);
if (ret == ERR_OK) {
xts_set_key(header->key_1, header->alg_1, &m->benc_k);
DbgPrint(L" SUCCESS.\n");
}
else
DbgPrint(L" FAILED.\n");
return ret;
}
int CCryptoIO::Init()
{
int ret = m_pIO ? m_pIO->Init() : ERR_UNKNOWN_TYPE;
if (ret == ERR_OK)
ret = InitCrypto();
m->password.free();
return ret;
}
int CCryptoIO::WriteHeader(struct _dc_header* header)
{
SSecureBuffer<xts_key> header_key;
UCHAR salt[PKCS5_SALT_SIZE];
SSecureBuffer<UCHAR> dk(DISKKEY_SIZE);
// allocate required memory
if (!header_key || !dk)
{
DbgPrint(L"Malloc Failed\n");
return ERR_MALLOC_ERROR;
}
make_rand(salt, PKCS5_SALT_SIZE);
// derive the header key
sha512_pkcs5_2(1000, m->password->pass, m->password->size, salt, PKCS5_SALT_SIZE, dk.ptr, PKCS_DERIVE_MAX);
// initialize encryption keys
xts_set_key(dk.ptr, header->alg_1, header_key.ptr);
// encrypt the volume header
xts_encrypt((const unsigned char*)header, (unsigned char*)header, sizeof(dc_header), 0, header_key.ptr);
// save salt
memcpy(header->salt, salt, PKCS5_SALT_SIZE);
// write volume header to output file
m_pIO->DiskWrite(header, sizeof(dc_header), 0);
return ERR_OK;
}
int CCryptoIO::ChangePassword(const WCHAR* pNewKey)
{
int ret = m_pIO ? m_pIO->Init() : ERR_UNKNOWN_TYPE;
if (ret != ERR_OK)
return ret;
SSecureBuffer<dc_header> header;
if (!header) {
DbgPrint(L"Malloc Failed\n");
return ERR_MALLOC_ERROR;
}
m_pIO->DiskRead(header.ptr, sizeof(dc_header), 0);
ret = dc_decrypt_header(header.ptr, m->password.ptr) ? ERR_OK : ERR_WRONG_PASSWORD;
if (ret != ERR_OK)
return ret;
if (m->password) {
m->password->size = wcslen(pNewKey) * sizeof(wchar_t);
if (m->password->size > MAX_PASSWORD * sizeof(wchar_t))
m->password->size = MAX_PASSWORD * sizeof(wchar_t);
memcpy(m->password->pass, pNewKey, m->password->size);
}
ret = WriteHeader(header.ptr);
return ret;
}
bool CCryptoIO::DiskWrite(void* buf, int size, __int64 offset)
{
#ifdef _DEBUG
if ((offset & 0x1FF) || (size & 0x1FF))
DbgPrint(L"DiskWrite not full sector\n");
#endif
xts_encrypt((BYTE*)buf, (BYTE*)buf, size, offset, &m->benc_k);
bool ret = m_pIO->DiskWrite(buf, size, offset + DC_AREA_SIZE);
//xts_decrypt((BYTE*)buf, (BYTE*)buf, size, offset, &m->benc_k); // restore buffer - not needed
return ret;
}
bool CCryptoIO::DiskRead(void* buf, int size, __int64 offset)
{
#ifdef _DEBUG
if ((offset & 0x1FF) || (size & 0x1FF))
DbgPrint(L"DiskRead not full sector\n");
#endif
bool ret = m_pIO->DiskRead(buf, size, offset + DC_AREA_SIZE);
if (ret)
xts_decrypt((BYTE*)buf, (BYTE*)buf, size, offset, &m->benc_k);
return ret;
}
void CCryptoIO::TrimProcess(DEVICE_DATA_SET_RANGE* range, int n)
{
for (DEVICE_DATA_SET_RANGE* range2 = range; range2 < range + n; range2++) {
range2->StartingOffset += DC_AREA_SIZE;
#ifdef _DEBUG
if (range2->StartingOffset & 0x1FF || range2->LengthInBytes & 0x1FF)
DbgPrint(L"TrimProcess not full sector\n");
#endif
}
m_pIO->TrimProcess(range, n);
}
int CCryptoIO::BackupHeader(CAbstractIO* pIO, const std::wstring& Path)
{
int ret = pIO->Init();
if (ret != ERR_OK)
return ret;
SSecureBuffer<dc_header> header;
if (!header) {
DbgPrint(L"Malloc Failed\n");
return ERR_MALLOC_ERROR;
}
if (!pIO->DiskRead(header.ptr, sizeof(dc_header), 0))
ret = ERR_FILE_NOT_OPENED;
if (ret != ERR_OK)
return ret;
HANDLE hFile = CreateFile(Path.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
if (!WriteFile(hFile, header.ptr, sizeof(dc_header), NULL, NULL)) {
ret = ERR_FILE_NOT_OPENED;
}
CloseHandle(hFile);
} else
ret = ERR_FILE_NOT_OPENED;
return ret;
}
int CCryptoIO::RestoreHeader(CAbstractIO* pIO, const std::wstring& Path)
{
int ret = pIO->Init();
if (ret != ERR_OK)
return ret;
SSecureBuffer<dc_header> header;
if (!header) {
DbgPrint(L"Malloc Failed\n");
return ERR_MALLOC_ERROR;
}
HANDLE hFile = CreateFile(Path.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
if (!ReadFile(hFile, header.ptr, sizeof(dc_header), NULL, NULL)) {
ret = ERR_FILE_NOT_OPENED;
}
CloseHandle(hFile);
} else
ret = ERR_FILE_NOT_OPENED;
if (ret != ERR_OK)
return ret;
if (!pIO->DiskWrite(header.ptr, sizeof(dc_header), 0))
ret = ERR_FILE_NOT_OPENED;
return ret;
}

View File

@ -0,0 +1,34 @@
#pragma once
#include "AbstractIO.h"
class CCryptoIO : public CAbstractIO
{
public:
CCryptoIO(CAbstractIO* pIO, const WCHAR* pKey, const std::wstring& Cipher = std::wstring());
virtual ~CCryptoIO();
virtual ULONG64 GetAllocSize() const { return m_pIO->GetAllocSize(); }
virtual ULONG64 GetDiskSize() const;
virtual bool CanBeFormated() const;
virtual int Init();
virtual void PrepViewOfFile(BYTE* p) { m_pIO->PrepViewOfFile(p); }
virtual int ChangePassword(const WCHAR* pNewKey);
virtual bool DiskWrite(void* buf, int size, __int64 offset);
virtual bool DiskRead(void* buf, int size, __int64 offset);
virtual void TrimProcess(DEVICE_DATA_SET_RANGE* range, int n);
static int BackupHeader(CAbstractIO* pIO, const std::wstring& Path);
static int RestoreHeader(CAbstractIO* pIO, const std::wstring& Path);
protected:
virtual int InitCrypto();
virtual int WriteHeader(struct _dc_header* header);
struct SCryptoIO* m;
public:
CAbstractIO* m_pIO;
};

View File

@ -0,0 +1,337 @@
/*
* Copyright 2023 David Xanatos, xanasoft.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "framework.h"
#include <shellapi.h>
#include "ImBox.h"
#include "ImDiskIO.h"
#include "VirtualMemoryIO.h"
#include "PhysicalMemoryIO.h"
#include "ImageFileIO.h"
#include "CryptoIO.h"
#include "..\Common\helpers.h"
bool HasFlag(const std::vector<std::wstring>& arguments, std::wstring name)
{
return std::find(arguments.begin(), arguments.end(), name) != arguments.end();
}
std::wstring GetArgument(const std::vector<std::wstring>& arguments, std::wstring name)
{
std::wstring prefix = name + L"=";
for (size_t i = 0; i < arguments.size(); i++) {
if (_wcsicmp(arguments[i].substr(0, prefix.length()).c_str(), prefix.c_str()) == 0) {
return arguments[i].substr(prefix.length());
}
}
return L"";
}
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
int nArgs = 0;
LPWSTR* szArglist = CommandLineToArgvW(lpCmdLine, &nArgs);
std::vector<std::wstring> arguments;
for (int i = 0; i < nArgs; i++)
arguments.push_back(szArglist[i]);
LocalFree(szArglist);
// type=image image="c:\temp\test.img" mount=Z: format=ntfs:Test key=test
// image="c:\temp\test.img" key=test new_key=123
//bool bCreate = HasFlag(arguments, L"create");
//bool bUpdate = HasFlag(arguments, L"update");
std::wstring mount = GetArgument(arguments, L"mount");
std::wstring type = GetArgument(arguments, L"type");
std::wstring size = GetArgument(arguments, L"size");
std::wstring image = GetArgument(arguments, L"image");
std::wstring key = GetArgument(arguments, L"key");
std::wstring cipher = GetArgument(arguments, L"cipher");
std::wstring format = GetArgument(arguments, L"format");
std::wstring params = GetArgument(arguments, L"params");
std::wstring new_key = GetArgument(arguments, L"new_key");
std::wstring backup = GetArgument(arguments, L"backup");
std::wstring restore = GetArgument(arguments, L"restore");
std::wstring proxy = GetArgument(arguments, L"proxy");
std::wstring event = GetArgument(arguments, L"event");
std::wstring section = GetArgument(arguments, L"section");
ULONG64 uSize = 0;
if(size.empty())
uSize = 2ull * (1024 * 1024 * 1024); // 2GB;
else
uSize = _wtoi64(size.c_str());
//
// perpare disk IO
//
CAbstractIO* pIO = NULL;
if (_wcsicmp(type.c_str(), L"virtual") == 0 || _wcsicmp(type.c_str(), L"ram") == 0)
pIO = new CVirtualMemoryIO(uSize);
else if (_wcsicmp(type.c_str(), L"physical") == 0 || _wcsicmp(type.c_str(), L"awe") == 0)
pIO = new CPhysicalMemoryIO(uSize);
else if (_wcsicmp(type.c_str(), L"image") == 0 || _wcsicmp(type.c_str(), L"img") == 0)
pIO = new CImageFileIO(image, uSize);
else {
DbgPrint(L"Invalid disk type.\n");
return -1;
}
if (!backup.empty())
return CCryptoIO::BackupHeader(pIO, backup);
if (!restore.empty())
return CCryptoIO::RestoreHeader(pIO, restore);
HANDLE hMapping = NULL;
WCHAR* pSection = NULL;
if (!section.empty()) {
HANDLE hMapping = OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE, FALSE, section.c_str());
if (hMapping)
pSection = (WCHAR *)MapViewOfFile(hMapping, FILE_MAP_WRITE, 0, 0, 0x1000);
}
if (!key.empty() || !cipher.empty()) {
if (key.empty()) {
if (!pSection)
return ERR_KEY_REQUIRED;
pIO = new CCryptoIO(pIO, pSection, cipher);
memset(pSection, 0, 0x1000);
}
else
pIO = new CCryptoIO(pIO, key.c_str(), cipher);
if (!new_key.empty()) {
return ((CCryptoIO*)pIO)->ChangePassword(new_key.c_str());
}
}
int ret = pIO ? pIO->Init() : ERR_UNKNOWN_TYPE;
if (ret)
return ret;
CImDiskIO* pImDisk = new CImDiskIO(pIO, mount, format, params);
if (!proxy.empty())
pImDisk->SetProxyName(proxy);
if (!event.empty()) {
HANDLE hEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, event.c_str());
if(hEvent)
pImDisk->SetMountEvent(hEvent);
}
if (pSection)
pImDisk->SetMountSection(hMapping, pSection);
//
// defien shutdown behavioure
//
SetProcessShutdownParameters(0x100, 0);
//
// start processing IO Requests
//
return pImDisk->DoComm();
}
#if 0
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: Place code here.
// Initialize global strings
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW(hInstance, IDC_IMBOX, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_IMBOX));
MSG msg;
// Main message loop:
while (GetMessage(&msg, nullptr, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEXW wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_IMBOX));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_IMBOX);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassExW(&wcex);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // Store instance handle in our global variable
HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code that uses hdc here...
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
#endif

View File

@ -0,0 +1,18 @@
#pragma once
#include "resource.h"
#define ERR_OK 0
#define ERR_UNKNOWN_TYPE 1
#define ERR_FILE_NOT_OPENED 2
#define ERR_UNKNOWN_CIPHER 3
#define ERR_WRONG_PASSWORD 4
#define ERR_KEY_REQUIRED 5
#define ERR_PRIVILEGE 6
#define ERR_INTERNAL 7
#define ERR_FILE_MAPPING 8
#define ERR_CREATE_EVENT 9
#define ERR_IMDISK_FAILED 10
#define ERR_IMDISK_TIMEOUT 11
#define ERR_UNKNOWN_COMMAND 12
#define ERR_MALLOC_ERROR 13

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

View File

@ -0,0 +1,597 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM64">
<Configuration>Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{96bca164-bcd0-4839-b9fe-da7e557481db}</ProjectGuid>
<RootNamespace>ImBox</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ntdll.lib;Wtsapi32.lib;Advapi32.lib;Bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ntdll.lib;Wtsapi32.lib;Advapi32.lib;Bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ntdll.lib;Wtsapi32.lib;Advapi32.lib;Bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ntdll.lib;Wtsapi32.lib;Advapi32.lib;Bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ntdll.lib;Wtsapi32.lib;Advapi32.lib;Bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ntdll.lib;Wtsapi32.lib;Advapi32.lib;Bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\Common\dirent.h" />
<ClInclude Include="..\Common\helpers.h" />
<ClInclude Include="AbstractIO.h" />
<ClInclude Include="CryptoIO.h" />
<ClInclude Include="dc\crypto_fast\aes_asm.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_fast\aes_key.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_fast\aes_padlock.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_fast\crc32.h" />
<ClInclude Include="dc\crypto_fast\serpent.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_fast\sha512.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_fast\sha512_hmac.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_fast\sha512_hmac_drbg.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_fast\sha512_pkcs5_2.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_fast\twofish.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_fast\xts_aes_ni.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_fast\xts_fast.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_fast\xts_serpent_avx.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_fast\xts_serpent_sse2.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_small\aes_small.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_small\serpent_small.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_small\sha512_pkcs5_2_small.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_small\sha512_small.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_small\twofish_small.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\crypto_small\xts_small.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="dc\include\boot\dc_header.h" />
<ClInclude Include="dc\include\defines.h" />
<ClInclude Include="dc\include\volume.h" />
<ClInclude Include="framework.h" />
<ClInclude Include="ImageFileIO.h" />
<ClInclude Include="ImBox.h" />
<ClInclude Include="ImDiskIO.h" />
<ClInclude Include="PhysicalMemoryIO.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="VirtualMemoryIO.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\Common\helpers.cpp" />
<ClCompile Include="CryptoIO.cpp" />
<ClCompile Include="dc\crypto_fast\aes_key.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="dc\crypto_fast\crc32.c" />
<ClCompile Include="dc\crypto_fast\serpent.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="dc\crypto_fast\sha512.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="dc\crypto_fast\sha512_hmac.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="dc\crypto_fast\sha512_hmac_drbg.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="dc\crypto_fast\sha512_pkcs5_2.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="dc\crypto_fast\twofish.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="dc\crypto_fast\xts_fast.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="dc\crypto_fast\xts_serpent_sse2.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="dc\crypto_small\aes_small.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="dc\crypto_small\serpent_small.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="dc\crypto_small\sha512_pkcs5_2_small.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="dc\crypto_small\sha512_small.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="dc\crypto_small\twofish_small.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="dc\crypto_small\xts_small.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="dc\dc_header.c" />
<ClCompile Include="ImageFileIO.cpp" />
<ClCompile Include="ImBox.cpp" />
<ClCompile Include="ImDiskIO.cpp" />
<ClCompile Include="PhysicalMemoryIO.cpp" />
<ClCompile Include="VirtualMemoryIO.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ImBox.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="ImBox.ico" />
<Image Include="small.ico" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="dc\crypto_fast\amd64\aes_amd64.asm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -m amd64 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -m amd64 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\amd64\aes_padlock_amd64.asm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -m amd64 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -m amd64 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\amd64\twofish_amd64.asm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -m amd64 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -m amd64 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\amd64\xts_aes_ni_amd64.asm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -m amd64 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -m amd64 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\amd64\xts_serpent_avx_amd64.asm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -m amd64 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -m amd64 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\amd64\xts_serpent_sse2_amd64.asm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -m amd64 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -m amd64 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\i386\aes_i386.asm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\i386\aes_padlock_i386.asm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\i386\twofish_i386.asm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\i386\xts_aes_ni_i386.asm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\i386\xts_serpent_avx_i386.asm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\i386\xts_serpent_sse2_i386.asm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(ProjectDir)dc\tools\yasm\yasm.exe" -Xvc -f win32 -o "$(OutDir)obj\$(ProjectName)\%(Filename).obj" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)obj\$(ProjectName)\%(Filename).obj</Outputs>
</CustomBuild>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,279 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="DiskIO">
<UniqueIdentifier>{18b6bd43-6b61-479c-9521-c11f258edab7}</UniqueIdentifier>
</Filter>
<Filter Include="Common">
<UniqueIdentifier>{bc7ffeb4-7f05-4d22-8bac-4a4c52e81c2f}</UniqueIdentifier>
</Filter>
<Filter Include="ImBox">
<UniqueIdentifier>{1b77499d-b9bc-4ca2-bfeb-67178cf2173b}</UniqueIdentifier>
</Filter>
<Filter Include="DC">
<UniqueIdentifier>{05763154-ad55-4f59-8814-cc99a34a789f}</UniqueIdentifier>
</Filter>
<Filter Include="DC\crypto_fast">
<UniqueIdentifier>{a1453092-4131-47d9-af56-b1bdbd2dc74a}</UniqueIdentifier>
</Filter>
<Filter Include="DC\crypto_small">
<UniqueIdentifier>{542a7728-d999-4765-8d9b-10fb136d8c1f}</UniqueIdentifier>
</Filter>
<Filter Include="DC\crypto_fast\amd64">
<UniqueIdentifier>{463611fd-0b3f-48b3-a144-80ded44f16ec}</UniqueIdentifier>
</Filter>
<Filter Include="DC\crypto_fast\i386">
<UniqueIdentifier>{193ce094-ad88-4876-959c-a69daf6f3d2f}</UniqueIdentifier>
</Filter>
<Filter Include="DC\include">
<UniqueIdentifier>{5a9d2681-b190-4507-8415-79b235d0f8a1}</UniqueIdentifier>
</Filter>
<Filter Include="DC\include\boot">
<UniqueIdentifier>{28dac04f-502a-448f-83b8-db10b2a77c4f}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="framework.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AbstractIO.h">
<Filter>DiskIO</Filter>
</ClInclude>
<ClInclude Include="ImageFileIO.h">
<Filter>DiskIO</Filter>
</ClInclude>
<ClInclude Include="PhysicalMemoryIO.h">
<Filter>DiskIO</Filter>
</ClInclude>
<ClInclude Include="VirtualMemoryIO.h">
<Filter>DiskIO</Filter>
</ClInclude>
<ClInclude Include="..\Common\dirent.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\Common\helpers.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="ImBox.h">
<Filter>ImBox</Filter>
</ClInclude>
<ClInclude Include="ImDiskIO.h">
<Filter>ImBox</Filter>
</ClInclude>
<ClInclude Include="CryptoIO.h">
<Filter>ImBox</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_fast\aes_asm.h">
<Filter>DC\crypto_fast</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_fast\aes_key.h">
<Filter>DC\crypto_fast</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_fast\aes_padlock.h">
<Filter>DC\crypto_fast</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_fast\crc32.h">
<Filter>DC\crypto_fast</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_fast\serpent.h">
<Filter>DC\crypto_fast</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_fast\sha512.h">
<Filter>DC\crypto_fast</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_fast\sha512_hmac.h">
<Filter>DC\crypto_fast</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_fast\sha512_hmac_drbg.h">
<Filter>DC\crypto_fast</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_fast\sha512_pkcs5_2.h">
<Filter>DC\crypto_fast</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_fast\twofish.h">
<Filter>DC\crypto_fast</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_fast\xts_aes_ni.h">
<Filter>DC\crypto_fast</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_fast\xts_fast.h">
<Filter>DC\crypto_fast</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_fast\xts_serpent_avx.h">
<Filter>DC\crypto_fast</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_fast\xts_serpent_sse2.h">
<Filter>DC\crypto_fast</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_small\aes_small.h">
<Filter>DC\crypto_small</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_small\serpent_small.h">
<Filter>DC\crypto_small</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_small\sha512_pkcs5_2_small.h">
<Filter>DC\crypto_small</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_small\sha512_small.h">
<Filter>DC\crypto_small</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_small\twofish_small.h">
<Filter>DC\crypto_small</Filter>
</ClInclude>
<ClInclude Include="dc\crypto_small\xts_small.h">
<Filter>DC\crypto_small</Filter>
</ClInclude>
<ClInclude Include="dc\include\volume.h">
<Filter>DC\include</Filter>
</ClInclude>
<ClInclude Include="dc\include\boot\dc_header.h">
<Filter>DC\include\boot</Filter>
</ClInclude>
<ClInclude Include="dc\include\defines.h">
<Filter>DC\include</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ImageFileIO.cpp">
<Filter>DiskIO</Filter>
</ClCompile>
<ClCompile Include="PhysicalMemoryIO.cpp">
<Filter>DiskIO</Filter>
</ClCompile>
<ClCompile Include="VirtualMemoryIO.cpp">
<Filter>DiskIO</Filter>
</ClCompile>
<ClCompile Include="..\Common\helpers.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="ImDiskIO.cpp">
<Filter>ImBox</Filter>
</ClCompile>
<ClCompile Include="ImBox.cpp">
<Filter>ImBox</Filter>
</ClCompile>
<ClCompile Include="CryptoIO.cpp">
<Filter>ImBox</Filter>
</ClCompile>
<ClCompile Include="dc\crypto_fast\aes_key.c">
<Filter>DC\crypto_fast</Filter>
</ClCompile>
<ClCompile Include="dc\crypto_fast\crc32.c">
<Filter>DC\crypto_fast</Filter>
</ClCompile>
<ClCompile Include="dc\crypto_fast\serpent.c">
<Filter>DC\crypto_fast</Filter>
</ClCompile>
<ClCompile Include="dc\crypto_fast\sha512.c">
<Filter>DC\crypto_fast</Filter>
</ClCompile>
<ClCompile Include="dc\crypto_fast\sha512_hmac.c">
<Filter>DC\crypto_fast</Filter>
</ClCompile>
<ClCompile Include="dc\crypto_fast\sha512_hmac_drbg.c">
<Filter>DC\crypto_fast</Filter>
</ClCompile>
<ClCompile Include="dc\crypto_fast\sha512_pkcs5_2.c">
<Filter>DC\crypto_fast</Filter>
</ClCompile>
<ClCompile Include="dc\crypto_fast\twofish.c">
<Filter>DC\crypto_fast</Filter>
</ClCompile>
<ClCompile Include="dc\crypto_fast\xts_fast.c">
<Filter>DC\crypto_fast</Filter>
</ClCompile>
<ClCompile Include="dc\crypto_fast\xts_serpent_sse2.c">
<Filter>DC\crypto_fast</Filter>
</ClCompile>
<ClCompile Include="dc\crypto_small\aes_small.c">
<Filter>DC\crypto_small</Filter>
</ClCompile>
<ClCompile Include="dc\crypto_small\serpent_small.c">
<Filter>DC\crypto_small</Filter>
</ClCompile>
<ClCompile Include="dc\crypto_small\sha512_pkcs5_2_small.c">
<Filter>DC\crypto_small</Filter>
</ClCompile>
<ClCompile Include="dc\crypto_small\sha512_small.c">
<Filter>DC\crypto_small</Filter>
</ClCompile>
<ClCompile Include="dc\crypto_small\twofish_small.c">
<Filter>DC\crypto_small</Filter>
</ClCompile>
<ClCompile Include="dc\crypto_small\xts_small.c">
<Filter>DC\crypto_small</Filter>
</ClCompile>
<ClCompile Include="dc\dc_header.c">
<Filter>DC</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ImBox.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="ImBox.ico">
<Filter>Resource Files</Filter>
</Image>
<Image Include="small.ico">
<Filter>Header Files</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="dc\crypto_fast\amd64\aes_amd64.asm">
<Filter>DC\crypto_fast\amd64</Filter>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\amd64\aes_padlock_amd64.asm">
<Filter>DC\crypto_fast\amd64</Filter>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\amd64\twofish_amd64.asm">
<Filter>DC\crypto_fast\amd64</Filter>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\amd64\xts_aes_ni_amd64.asm">
<Filter>DC\crypto_fast\amd64</Filter>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\amd64\xts_serpent_avx_amd64.asm">
<Filter>DC\crypto_fast\amd64</Filter>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\amd64\xts_serpent_sse2_amd64.asm">
<Filter>DC\crypto_fast\amd64</Filter>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\i386\aes_i386.asm">
<Filter>DC\crypto_fast\i386</Filter>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\i386\aes_padlock_i386.asm">
<Filter>Source Files</Filter>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\i386\twofish_i386.asm">
<Filter>Source Files</Filter>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\i386\xts_aes_ni_i386.asm">
<Filter>Source Files</Filter>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\i386\xts_serpent_avx_i386.asm">
<Filter>Source Files</Filter>
</CustomBuild>
<CustomBuild Include="dc\crypto_fast\i386\xts_serpent_sse2_i386.asm">
<Filter>Source Files</Filter>
</CustomBuild>
</ItemGroup>
</Project>

View File

@ -0,0 +1,764 @@
#include "framework.h"
#include <stdio.h>
#include "..\Common\helpers.h"
#include "..\ImDisk\inc\imdproxy.h"
#include "..\ImDisk\inc\imdisk.h"
#include "ImDiskIO.h"
#include "ImBox.h"
extern "C" {
#define ObjectNameInformation 1
typedef struct _OBJECT_NAME_INFORMATION {
UNICODE_STRING Name;
} OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION;
#define FILE_SHARE_VALID_FLAGS 0x00000007
#define IO_REPARSE_TAG_SYMLINK (0xA000000CL)
#define SYMLINK_FLAG_RELATIVE 1
typedef struct _REPARSE_DATA_BUFFER {
ULONG ReparseTag;
USHORT ReparseDataLength;
USHORT Reserved;
union {
struct {
USHORT SubstituteNameOffset;
USHORT SubstituteNameLength;
USHORT PrintNameOffset;
USHORT PrintNameLength;
ULONG Flags;
WCHAR PathBuffer[1];
} SymbolicLinkReparseBuffer;
struct {
USHORT SubstituteNameOffset;
USHORT SubstituteNameLength;
USHORT PrintNameOffset;
USHORT PrintNameLength;
WCHAR PathBuffer[1];
} MountPointReparseBuffer;
struct {
UCHAR DataBuffer[1];
} GenericReparseBuffer;
};
} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
typedef enum _FSINFOCLASS {
FileFsVolumeInformation = 1, // FILE_FS_VOLUME_INFORMATION
FileFsLabelInformation, // 2
FileFsSizeInformation, // 3
FileFsDeviceInformation, // 4
FileFsAttributeInformation, // 5 // FILE_FS_ATTRIBUTE_INFORMATION
FileFsControlInformation, // 6
FileFsFullSizeInformation, // 7
FileFsObjectIdInformation, // 8
FileFsDriverPathInformation, // 9
FileFsMaximumInformation
} FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS;
NTSYSCALLAPI NTSTATUS NTAPI NtQueryVolumeInformationFile(
IN HANDLE FileHandle,
OUT PIO_STATUS_BLOCK IoStatusBlock,
OUT PVOID FsInformation,
IN ULONG Length,
IN ULONG FsInformationClass
);
typedef struct _FILE_FS_VOLUME_INFORMATION {
LARGE_INTEGER VolumeCreationTime;
ULONG VolumeSerialNumber;
ULONG VolumeLabelLength;
BOOLEAN SupportsObjects;
WCHAR VolumeLabel[1];
} FILE_FS_VOLUME_INFORMATION, *PFILE_FS_VOLUME_INFORMATION;
typedef struct _FILE_FS_ATTRIBUTE_INFORMATION {
ULONG FileSystemAttributes;
LONG MaximumComponentNameLength;
ULONG FileSystemNameLength;
WCHAR FileSystemName[1];
} FILE_FS_ATTRIBUTE_INFORMATION, *PFILE_FS_ATTRIBUTE_INFORMATION;
NTSTATUS NTAPI RtlSetThreadErrorMode(IN ULONG NewMode, OUT PULONG OldMode);
bool IsVolumeUnRecognized(std::wstring NtPath);
bool FormatVolume(LPCWSTR root, LPCWSTR fs, LPCWSTR label);
WCHAR WINAPI MyImDiskFindFreeDriveLetter();
HANDLE WINAPI MyImDiskOpenDeviceByMountPoint(LPCWSTR MountPoint, DWORD AccessMode);
BOOL WINAPI MyImDiskCliValidateDriveLetterTarget(LPCWSTR DriveLetter, LPCWSTR ValidTargetPath);
}
struct SImDiskIO
{
std::wstring Mount;
std::wstring Format;
std::wstring Params;
HANDLE hImDisk;
std::wstring Proxy;
HANDLE hEvent;
HANDLE hMapping;
WCHAR* pSection;
};
CImDiskIO::CImDiskIO(CAbstractIO* pIO, const std::wstring& Mount, const std::wstring& Format, const std::wstring& Params)
{
m = new SImDiskIO;
m->Mount = Mount;
m->Format = Format;
m->Params = Params;
m->hImDisk = INVALID_HANDLE_VALUE;
m->hEvent = NULL;
m->hMapping = NULL;
m->pSection = NULL;
m_pIO = pIO;
m_hThread = INVALID_HANDLE_VALUE;
}
CImDiskIO::~CImDiskIO()
{
if (m_hThread != INVALID_HANDLE_VALUE) {
if (WaitForSingleObject(m_hThread, 60 * 1000) == WAIT_TIMEOUT)
TerminateThread(m_hThread, -1);
CloseHandle(m_hThread);
}
if(m) delete m;
}
void CImDiskIO::SetProxyName(const std::wstring& Name)
{
if (m) m->Proxy = Name;
}
void CImDiskIO::SetMountEvent(HANDLE hEvent)
{
if (m) m->hEvent = hEvent;
}
void CImDiskIO::SetMountSection(HANDLE hMapping, WCHAR* pSection)
{
if (m) m->hMapping = hMapping;
if (m) m->pSection = pSection;
}
DWORD WINAPI CImDiskIO_Thread(LPVOID lpThreadParameter)
{
//
// !!! NOTE !!! After this thread was created the rest of the code does not touch
// the m members which we use here so we dont bother with explicite synchronization
// hence this thread is responsible freeing m
//
SImDiskIO* m = ((SImDiskIO*)lpThreadParameter);
std::wstring Device;
DWORD exit_code;
do {
Sleep(100);
HANDLE handle = (HANDLE)MyImDiskOpenDeviceByMountPoint(m->Mount.c_str(), 0);
if (handle != INVALID_HANDLE_VALUE) {
BYTE buffer[MAX_PATH];
DWORD length = sizeof(buffer);
if (NT_SUCCESS(NtQueryObject(handle, (OBJECT_INFORMATION_CLASS)ObjectNameInformation, buffer, length, &length))) {
UNICODE_STRING* uni = &((OBJECT_NAME_INFORMATION*)buffer)->Name;
length = uni->Length / sizeof(WCHAR);
if (uni->Buffer) {
uni->Buffer[length] = 0;
Device = uni->Buffer;
}
}
CloseHandle(handle);
break;
}
GetExitCodeProcess(m->hImDisk, &exit_code);
} while (exit_code == STILL_ACTIVE);
CloseHandle(m->hImDisk); m->hImDisk = INVALID_HANDLE_VALUE;
if (!Device.empty() && !m->Format.empty()) {
std::wstring Drive;
if (!IsVolumeUnRecognized(Device)) {
DbgPrint(L"The volume: %s was recognized, format skipped.\n", Device.c_str());
}
else
if ((m->Mount.length() == 2 && m->Mount[1] == L':') // check if mount is a drive letter
|| (m->Mount.length() == 3 && m->Mount[1] == L':' && m->Mount[2] == L'\\')) {
Drive = m->Mount;
}
else {
WCHAR drive = MyImDiskFindFreeDriveLetter();
if (!drive) {
DbgPrint(L"No free drive letter found.\n");
}
else {
Drive = L" :";
Drive[0] = drive;
}
if (!DefineDosDevice(DDD_RAW_TARGET_PATH, Drive.c_str(), Device.c_str())) {
DbgPrint(L"Failed to Mount drive letter.\n");
Drive.clear();
}
}
if (!Drive.empty()) {
if (MyImDiskCliValidateDriveLetterTarget(Drive.c_str(), Device.c_str())) {
LPCWSTR fs = m->Format.c_str();
LPCWSTR label = wcschr(fs, L':');
if (!label) label = L"";
else *(*(LPWSTR*)&label)++ = L'\0';
//for (int i = 0; i < 3; i++) {
if (FormatVolume(Drive.c_str(), fs, label)) {
if (!IsVolumeUnRecognized(Device)) // check success
DbgPrint(L"Successfully Formated: %s\n", m->Mount.c_str());
else {
DbgPrint(L"Failed to Format: %s\n", m->Mount.c_str());
// Sleep(1000);
// continue; // retry
}
}
else // fails only when lib is not available
DbgPrint(L"Can not Format: %s\n", m->Mount.c_str());
// break;
//}
}
if (Drive != m->Mount) {
if (!DefineDosDevice(DDD_REMOVE_DEFINITION | DDD_EXACT_MATCH_ON_REMOVE | DDD_RAW_TARGET_PATH, Drive.c_str(), Device.c_str())) {
DbgPrint(L"Failed to Unmount drive letter.\n");
}
}
}
}
if (m->pSection) {
wmemcpy(m->pSection, Device.c_str(), Device.length() + 1);
UnmapViewOfFile(m->pSection);
}
if(m->hMapping)
CloseHandle(m->hMapping);
if (m->hEvent) {
SetEvent(m->hEvent);
CloseHandle(m->hEvent);
}
delete m;
return 0;
}
int CImDiskIO::DoComm()
{
HANDLE hFileMap;
ULARGE_INTEGER map_size;
BYTE *shm_view, *main_buf;
struct s_req_block {unsigned char request_code, pad[7]; ULONGLONG offset; ULONGLONG length;} *req_block;
struct s_resp_block {unsigned char errorno, pad[7]; ULONGLONG length;} *resp_block;
struct s_trim_block {unsigned char request_code, pad[7]; unsigned int length;} *trim_block;
HANDLE shm_request_event, shm_response_event;
if (m->Proxy.empty()){
#ifdef _M_ARM64
ULONG64 ctr = _ReadStatusReg(ARM64_CNTVCT));
#else
ULONG64 ctr = __rdtsc();
#endif
m->Proxy = L"ImBox" + std::to_wstring(ctr);
}
map_size.QuadPart = DEF_BUFFER_SIZE + IMDPROXY_HEADER_SIZE;
if (!(hFileMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE | SEC_COMMIT, map_size.HighPart, map_size.LowPart, (L"Global\\" + m->Proxy).c_str())))
return ERR_FILE_MAPPING;
if (!(shm_view = (BYTE*)MapViewOfFile(hFileMap, FILE_MAP_WRITE, 0, 0, 0)))
return ERR_FILE_MAPPING;
m_pIO->PrepViewOfFile(shm_view);
main_buf = shm_view + IMDPROXY_HEADER_SIZE;
req_block = (s_req_block*)shm_view;
resp_block = (s_resp_block*)shm_view;
trim_block = (s_trim_block*)shm_view;
if (!(shm_request_event = CreateEvent(NULL, FALSE, FALSE, (L"Global\\" + m->Proxy + L"_Request").c_str())) || GetLastError() == ERROR_ALREADY_EXISTS)
return ERR_CREATE_EVENT;
if (!(shm_response_event = CreateEvent(NULL, FALSE, FALSE, (L"Global\\" + m->Proxy + L"_Response").c_str())))
return ERR_CREATE_EVENT;
STARTUPINFO si = {sizeof si};
PROCESS_INFORMATION pi;
std::wstring cmd = L"imdisk -a -t proxy -o shm -f " + m->Proxy;
if (!m->Mount.empty()) cmd += L" -m \"" + m->Mount + L"\"";
if (!m->Params.empty())cmd += L" " + m->Params;
if (!CreateProcess(NULL, (WCHAR*)cmd.c_str(), NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) {
DbgPrint(L"Failed to run imdisk.exe.\n");
return ERR_IMDISK_FAILED;
}
NtClose(pi.hThread);
if (!m->Mount.empty()) {
//
// clear format directive if formating is not allowed for this disk e.g. non empty image file
// to force format you can use imdisk: params="-p \"/fs:ntfs /q /y\""
//
if (!m_pIO->CanBeFormated())
m->Format.clear();
m->hImDisk = pi.hProcess;
m_hThread = CreateThread(NULL, 0, CImDiskIO_Thread, m, 0, NULL);
m = NULL;
}
else {
NtClose(pi.hProcess);
}
LARGE_INTEGER t;
t.QuadPart = -100000000; // A negative value specifies an interval relative to the current time in units of 100 nanoseconds.
if (NtWaitForSingleObject(shm_request_event, FALSE, &t) != STATUS_SUCCESS || req_block->request_code != IMDPROXY_REQ_INFO)
return ERR_IMDISK_TIMEOUT;
IMDPROXY_INFO_RESP proxy_info = {0};
proxy_info.file_size = m_pIO->GetDiskSize();
proxy_info.req_alignment = 1;
proxy_info.flags = IMDPROXY_FLAG_SUPPORTS_UNMAP; // TRIM
memcpy(shm_view, &proxy_info, sizeof proxy_info);
for (;;) {
NtSignalAndWaitForSingleObject(shm_response_event, shm_request_event, FALSE, NULL);
if (req_block->request_code == IMDPROXY_REQ_READ) {
if (!m_pIO->DiskRead(main_buf, req_block->length, req_block->offset)) {
DbgPrint(L"DiskRead error.\n");
}
}
else if (req_block->request_code == IMDPROXY_REQ_WRITE) {
if (!m_pIO->DiskWrite(main_buf, req_block->length, req_block->offset)) {
DbgPrint(L"DiskWrite error, SOME DATA WILL BE LOST.");
}
}
else if (req_block->request_code == IMDPROXY_REQ_UNMAP) {
m_pIO->TrimProcess((DEVICE_DATA_SET_RANGE*)main_buf, trim_block->length / sizeof(DEVICE_DATA_SET_RANGE));
}
else if (req_block->request_code == IMDPROXY_REQ_CLOSE) {
return ERR_OK;
}
else { // unknown command
DbgPrint(L"Unknown Command: %d\n", req_block->request_code);
return ERR_UNKNOWN_COMMAND;
}
resp_block->errorno = 0;
resp_block->length = req_block->length;
}
}
//static void disp_message(WCHAR *disp_text, WCHAR *arg, BOOL wait)
//{
// DWORD dw;
//
// _snwprintf(txt, _countof(txt) - 1, disp_text, arg);
// WTSSendMessage(WTS_CURRENT_SERVER_HANDLE, WTSGetActiveConsoleSessionId(), L"ImDisk", 14, txt, (wcslen(txt) + 1) * sizeof(WCHAR), MB_OK | MB_ICONERROR, 0, &dw, wait);
//}
//
//static void disp_err_mem()
//{
// if (GetTickCount() - err_time >= 10000) {
// disp_message(L"Not enough memory to write data into %s.\nSome data will be lost.", drive_arg, TRUE);
// err_time = GetTickCount();
// }
//}
extern "C" {
bool IsVolumeUnRecognized(std::wstring NtPath)
{
if (NtPath.back() != L'\\') NtPath.push_back(L'\\');
HANDLE handle;
IO_STATUS_BLOCK iosb;
UNICODE_STRING objname;
RtlInitUnicodeString(&objname, NtPath.c_str());
OBJECT_ATTRIBUTES objattrs;
InitializeObjectAttributes(
&objattrs, &objname, OBJ_CASE_INSENSITIVE, NULL, NULL);
ULONG OldMode;
RtlSetThreadErrorMode(0x10u, &OldMode);
NTSTATUS status = NtCreateFile(
&handle, GENERIC_READ | SYNCHRONIZE, &objattrs,
&iosb, NULL, 0, FILE_SHARE_VALID_FLAGS,
FILE_OPEN,
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT,
NULL, 0);
RtlSetThreadErrorMode(OldMode, 0i64);
if (NT_SUCCESS(status))
{
union {
FILE_FS_ATTRIBUTE_INFORMATION fsInfo;
BYTE fsInfoBuff[64];
} u;
if (NT_SUCCESS(NtQueryVolumeInformationFile(handle, &iosb, &u.fsInfo, sizeof(u), FileFsAttributeInformation))) {
u.fsInfo.FileSystemName[u.fsInfo.FileSystemNameLength / sizeof(wchar_t)] = 0;
DbgPrint(L"Recognized FileSystem: %s\n", u.fsInfo.FileSystemName);
}
NtClose(handle);
}
if (status == STATUS_UNRECOGNIZED_VOLUME)
return true;
if (!NT_SUCCESS(status))
DbgPrint(L"NtQueryVolumeInformationFile failed 0x%08X.\n", status);
return false;
}
// types from winfile
typedef BOOLEAN(WINAPI *FMIFS_CALLBACK)(ULONG PacketType, ULONG PacketLength, PVOID PacketData);
typedef void (WINAPI* PFORMAT) (PWSTR DriveName, ULONG MediaType, PWSTR FileSystemName, PWSTR Label, BOOLEAN Quick, FMIFS_CALLBACK Callback);
static BOOLEAN WINAPI my_format_callback(ULONG PacketType, ULONG PacketLength, PVOID PacketData) {
return 1;
}
bool FormatVolume(LPCWSTR root, LPCWSTR fs, LPCWSTR label)
{
bool ret = false;
HMODULE fmifs = LoadLibrary(L"fmifs");
if (fmifs != NULL) {
PFORMAT Format = (PFORMAT)GetProcAddress(fmifs, "Format");
if (Format != NULL) {
Format((PWSTR)root, 0, (PWSTR)fs, (PWSTR)label, TRUE, my_format_callback);
ret = true;
}
FreeLibrary(fmifs);
}
return ret;
}
// ImDisk
HANDLE WINAPI MyImDiskOpenDeviceByName(PUNICODE_STRING FileName, DWORD AccessMode)
{
NTSTATUS status;
HANDLE handle;
OBJECT_ATTRIBUTES object_attrib;
IO_STATUS_BLOCK io_status;
InitializeObjectAttributes(&object_attrib,
FileName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
status = NtOpenFile(&handle,
SYNCHRONIZE | AccessMode,
&object_attrib,
&io_status,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT);
if (!NT_SUCCESS(status))
{
SetLastError(RtlNtStatusToDosError(status));
return INVALID_HANDLE_VALUE;
}
return handle;
}
HANDLE WINAPI MyImDiskOpenDeviceByNumber(DWORD DeviceNumber, DWORD AccessMode)
{
WCHAR device_path[_countof(IMDISK_DEVICE_BASE_NAME) + 16];
UNICODE_STRING file_name;
// Build device path, e.g. \Device\ImDisk2
_snwprintf_s(device_path, ARRAYSIZE(device_path), _countof(device_path),
IMDISK_DEVICE_BASE_NAME L"%u", DeviceNumber);
device_path[_countof(device_path) - 1] = 0;
RtlInitUnicodeString(&file_name, device_path);
return MyImDiskOpenDeviceByName(&file_name, AccessMode);
}
HANDLE WINAPI MyImDiskOpenDeviceByMountPoint(LPCWSTR MountPoint, DWORD AccessMode)
{
UNICODE_STRING DeviceName;
WCHAR DriveLetterPath[] = L"\\DosDevices\\ :";
PREPARSE_DATA_BUFFER ReparseData = NULL;
HANDLE h;
if ((MountPoint[0] != 0) &&
((wcscmp(MountPoint + 1, L":") == 0) ||
(wcscmp(MountPoint + 1, L":\\") == 0)))
{
DriveLetterPath[12] = MountPoint[0];
RtlInitUnicodeString(&DeviceName, DriveLetterPath);
}
else if (((wcsncmp(MountPoint, L"\\\\?\\", 4) == 0) ||
(wcsncmp(MountPoint, L"\\\\.\\", 4) == 0)) &&
(wcschr(MountPoint + 4, L'\\') == NULL))
{
return CreateFile(MountPoint, AccessMode,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
}
else
{
HANDLE hDir;
DWORD dw;
DWORD buffer_size =
FIELD_OFFSET(REPARSE_DATA_BUFFER, MountPointReparseBuffer) +
MAXIMUM_REPARSE_DATA_BUFFER_SIZE;
hDir = CreateFile(MountPoint, GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS |
FILE_FLAG_OPEN_REPARSE_POINT, NULL);
if (hDir == INVALID_HANDLE_VALUE)
return INVALID_HANDLE_VALUE;
ReparseData = (PREPARSE_DATA_BUFFER)HeapAlloc(GetProcessHeap(),
HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY,
buffer_size);
if (!DeviceIoControl(hDir, FSCTL_GET_REPARSE_POINT,
NULL, 0,
ReparseData, buffer_size,
&dw, NULL))
{
DWORD last_error = GetLastError();
CloseHandle(hDir);
HeapFree(GetProcessHeap(), 0, ReparseData);
SetLastError(last_error);
return INVALID_HANDLE_VALUE;
}
CloseHandle(hDir);
if (ReparseData->ReparseTag != IO_REPARSE_TAG_MOUNT_POINT)
{
HeapFree(GetProcessHeap(), 0, ReparseData);
SetLastError(ERROR_NOT_A_REPARSE_POINT);
return INVALID_HANDLE_VALUE;
}
DeviceName.Length =
ReparseData->MountPointReparseBuffer.SubstituteNameLength;
DeviceName.Buffer = (PWSTR)
((PUCHAR)ReparseData->MountPointReparseBuffer.PathBuffer +
ReparseData->MountPointReparseBuffer.SubstituteNameOffset);
DeviceName.MaximumLength = DeviceName.Length;
}
if (DeviceName.Buffer[(DeviceName.Length >> 1) - 1] == L'\\')
{
DeviceName.Buffer[(DeviceName.Length >> 1) - 1] = 0;
DeviceName.Length -= 2;
}
h = MyImDiskOpenDeviceByName(&DeviceName, AccessMode);
if (ReparseData != NULL)
HeapFree(GetProcessHeap(), 0, ReparseData);
return h;
}
BOOL WINAPI MyImDiskCliValidateDriveLetterTarget(LPCWSTR DriveLetter, LPCWSTR ValidTargetPath)
{
WCHAR target[MAX_PATH];
if (QueryDosDevice(DriveLetter, target, _countof(target)))
{
if (wcscmp(target, ValidTargetPath) == 0)
{
return TRUE;
}
DbgPrint(L"Drive letter %s points to %s instead of expected %s.\n", DriveLetter, target, ValidTargetPath);
}
else if (GetLastError() != ERROR_FILE_NOT_FOUND)
{
DbgPrint(L"Error verifying temporary drive letter:");
}
return FALSE;
}
//BOOL WINAPI MyImDiskGetDeviceListEx(IN ULONG ListLength, OUT ULONG *DeviceList)
//{
// UNICODE_STRING file_name;
// HANDLE driver;
// ULONG dw;
//
// RtlInitUnicodeString(&file_name, IMDISK_CTL_DEVICE_NAME);
//
// driver = MyImDiskOpenDeviceByName(&file_name, GENERIC_READ);
// if (driver == INVALID_HANDLE_VALUE)
// return 0;
//
// if (!DeviceIoControl(driver,
// IOCTL_IMDISK_QUERY_DRIVER,
// NULL, 0,
// DeviceList, ListLength << 2,
// &dw, NULL))
// {
// DWORD dwLastError = GetLastError();
// NtClose(driver);
// SetLastError(dwLastError);
// return FALSE;
// }
//
// NtClose(driver);
//
// if ((dw == sizeof(ULONG)) &
// (*DeviceList > 0))
// {
// SetLastError(ERROR_MORE_DATA);
// return FALSE;
// }
//
// SetLastError(NO_ERROR);
// return TRUE;
//}
WCHAR WINAPI MyImDiskFindFreeDriveLetter()
{
DWORD logical_drives = GetLogicalDrives();
WCHAR search;
for (search = L'Z'; search >= L'I'; search--)
{
if ((logical_drives & (1 << (search - L'A'))) == 0)
{
return search;
}
}
return 0;
}
}
#include <intrin.h>
#ifndef _M_ARM64
#include <emmintrin.h>
#endif
bool data_search_std(void *_ptr, int size)
{
unsigned char* ptr = (unsigned char*)_ptr;
long *scan_ptr;
if (!size) return FALSE;
scan_ptr = (long*)ptr;
ptr = (BYTE*)ptr + size - sizeof(long);
if (*(long*)ptr) return TRUE; // check if the last long not 0
*(long*)ptr = 1; // set last long to 1 to ensure termination
while (!*(scan_ptr++));
*(long*)ptr = 0; // restore last long to 0
return --scan_ptr != (long*)ptr;
}
#ifdef _M_ARM64
bool (*data_search)(void* ptr, int size) = data_search_std;
#else
bool data_search_sse2(void *_ptr, int size)
{
unsigned char* ptr = (unsigned char*)_ptr;
unsigned char *end_ptr;
__m128i zero;
if (!size) return FALSE;
zero = _mm_setzero_si128();
end_ptr = ptr + size - sizeof(__m128i);
if ((unsigned short)_mm_movemask_epi8(_mm_cmpeq_epi8(*(__m128i*)end_ptr, zero)) != 0xffff) return TRUE;
*end_ptr = 1;
while ((unsigned short)_mm_movemask_epi8(_mm_cmpeq_epi8(*(__m128i*)ptr, zero)) == 0xffff) ptr += sizeof(__m128i);
*end_ptr = 0;
return ptr != end_ptr;
}
bool data_search_avx(void *_ptr, int size)
{
unsigned char* ptr = (unsigned char*)_ptr;
unsigned char *end_ptr;
__m256i one;
if (!size) return FALSE;
one = _mm256_set1_epi8(0xff);
end_ptr = ptr + size - sizeof(__m256i);
if (!_mm256_testz_si256(*(__m256i*)end_ptr, one)) return TRUE;
*end_ptr = 1;
while (_mm256_testz_si256(*(__m256i*)ptr, one)) ptr += sizeof(__m256i);
*end_ptr = 0;
return ptr != end_ptr;
}
extern "C" {
void* pick_data_search()
{
bool (*ret)(void*, int);
int cpuInfo[4];
__cpuid(cpuInfo, 1);
#ifndef _WIN64
ret = data_search_std;
if (cpuInfo[3] & 0x4000000)
#endif
ret = data_search_sse2;
bool osUsesXSAVE_XRSTORE = cpuInfo[2] & (1 << 27);
bool cpuAVXSuport = cpuInfo[2] & (1 << 28);
if (osUsesXSAVE_XRSTORE && cpuAVXSuport) {
unsigned long long xcrFeatureMask = _xgetbv(_XCR_XFEATURE_ENABLED_MASK);
if ((xcrFeatureMask & 0x6) == 0x6)
ret = data_search_avx;
}
return ret;
}
}
bool (*data_search)(void* ptr, int size) = (bool (*)(void*, int))pick_data_search();
#endif

View File

@ -0,0 +1,28 @@
#pragma once
#include "AbstractIO.h"
#define DEF_BUFFER_SIZE (1 << 20)
#define MINIMAL_MEM (100 << 20)
class CImDiskIO
{
public:
CImDiskIO(CAbstractIO* pIO, const std::wstring& Mount, const std::wstring& Format, const std::wstring& Params = L"");
~CImDiskIO();
void SetProxyName(const std::wstring& Name);
void SetMountEvent(HANDLE hEvent);
void SetMountSection(HANDLE hMapping, WCHAR* pSection);
int DoComm();
protected:
struct SImDiskIO* m;
CAbstractIO* m_pIO;
HANDLE m_hThread;
};
void disp_err_mem();
extern bool (*data_search)(void *ptr, int size);

View File

@ -0,0 +1,210 @@
#include "framework.h"
#include "ImageFileIO.h"
#include "ImBox.h"
#include "..\Common\helpers.h"
BOOL GetSparseRanges(HANDLE hFile);
struct SImageFileIO
{
std::wstring FilePath;
ULONG64 uSize = 0;
HANDLE Handle = INVALID_HANDLE_VALUE;
};
CImageFileIO::CImageFileIO(std::wstring& FilePath, ULONG64 uSize)
{
m = new SImageFileIO;
m->FilePath = FilePath;
m->uSize = uSize;
}
CImageFileIO::~CImageFileIO()
{
if (m->Handle != INVALID_HANDLE_VALUE)
CloseHandle(m->Handle);
delete m;
}
ULONG64 CImageFileIO::GetDiskSize() const
{
return m->uSize;
}
ULONG64 CImageFileIO::GetAllocSize() const
{
LARGE_INTEGER liSparseFileCompressedSize;
liSparseFileCompressedSize.LowPart = GetCompressedFileSize(m->FilePath.c_str(), (LPDWORD)&liSparseFileCompressedSize.HighPart);
return liSparseFileCompressedSize.QuadPart;
}
bool CImageFileIO::CanBeFormated() const
{
if (m->Handle == INVALID_HANDLE_VALUE)
return false;
ULONGLONG uSize;
GetFileSizeEx(m->Handle, (LARGE_INTEGER*)&uSize);
return (uSize == 0);
}
int CImageFileIO::Init()
{
//
// !!! WARNING !!!
//
// Without disabling tile caching ImDisk will cause a deadlock in
// ntoskrnl.exe!CcCanIWrite
// Ntfs.sys!NtfsCopyWriteA
//
// This issue also affects DiscUtilsDevio.exe
//
m->Handle = CreateFile(m->FilePath.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, NULL);
if (m->Handle == INVALID_HANDLE_VALUE) {
//
// Create new image, but only if a size was specified
//
if(m->uSize)
m->Handle = CreateFile(m->FilePath.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, NULL);
if (m->Handle == INVALID_HANDLE_VALUE)
return ERR_FILE_NOT_OPENED;
}
else {
//
// check if the image is not empty, and take its size
//
ULONGLONG uSize;
GetFileSizeEx(m->Handle, (LARGE_INTEGER*)&uSize);
if (uSize != 0)
m->uSize = uSize;
}
//
// make file sparse if it is not yet already
//
DWORD dwVolFlags;
GetVolumeInformation(m->FilePath.substr(0, 3).c_str(), NULL, MAX_PATH, NULL, NULL, &dwVolFlags, NULL, MAX_PATH);
if (!(dwVolFlags & FILE_SUPPORTS_SPARSE_FILES)) {
DbgPrint(L"Volume %s does not support sparse files.\n", m->FilePath.substr(0, 3).c_str());
}
else {
BY_HANDLE_FILE_INFORMATION bhfi;
GetFileInformationByHandle(m->Handle, &bhfi);
if ((bhfi.dwFileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
// Use the DeviceIoControl function with the FSCTL_SET_SPARSE control
// code to mark the file as sparse. If you don't mark the file as sparse,
// the FSCTL_SET_ZERO_DATA control code will actually write zero bytes to
// the file instead of marking the region as sparse zero area.
DWORD dwTemp;
if (!DeviceIoControl(m->Handle, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &dwTemp, NULL)) {
DbgPrint(L"Failed to make image file sparse: %s\n", m->FilePath.c_str());
}
}
//else {
// GetSparseRanges(m->Handle);
//}
}
return ERR_OK;
}
bool CImageFileIO::DiskWrite(void* buf, int size, __int64 offset)
{
SetFilePointerEx(m->Handle, *(LARGE_INTEGER*)&offset, NULL, FILE_BEGIN);
return !!WriteFile(m->Handle, buf, size, NULL, NULL);
}
bool CImageFileIO::DiskRead(void* buf, int size, __int64 offset)
{
SetFilePointerEx(m->Handle, *(LARGE_INTEGER*)&offset, NULL, FILE_BEGIN);
return !!ReadFile(m->Handle, buf, size, NULL, NULL);
}
void CImageFileIO::TrimProcess(DEVICE_DATA_SET_RANGE* range, int n)
{
while (n) {
// Specify the starting and the ending address (not the size) of the sparse zero block
FILE_ZERO_DATA_INFORMATION fzdi;
fzdi.FileOffset.QuadPart = range->StartingOffset;
fzdi.BeyondFinalZero.QuadPart = range->StartingOffset + range->LengthInBytes;
DWORD dwTemp;
DeviceIoControl(m->Handle, FSCTL_SET_ZERO_DATA, &fzdi, sizeof(fzdi), NULL, 0, &dwTemp, NULL);
range++;
n--;
}
}
BOOL GetSparseRanges(HANDLE hFile)
{
LARGE_INTEGER liFileSize;
GetFileSizeEx(hFile, &liFileSize);
// Range to be examined (the whole file)
FILE_ALLOCATED_RANGE_BUFFER queryRange;
queryRange.FileOffset.QuadPart = 0;
queryRange.Length = liFileSize;
// Allocated areas info
FILE_ALLOCATED_RANGE_BUFFER allocRanges[1024];
DWORD nbytes;
BOOL fFinished;
DbgPrint(L"\nAllocated ranges in the file:");
do
{
fFinished = DeviceIoControl(hFile,
FSCTL_QUERY_ALLOCATED_RANGES,
&queryRange,
sizeof(queryRange),
allocRanges,
sizeof(allocRanges),
&nbytes,
NULL);
if (!fFinished)
{
DWORD dwError = GetLastError();
// ERROR_MORE_DATA is the only error that is normal
if (dwError != ERROR_MORE_DATA)
{
DbgPrint(L"DeviceIoControl failed w/err 0x%08lx\n", dwError);
CloseHandle(hFile);
return FALSE;
}
}
// Calculate the number of records returned
DWORD dwAllocRangeCount = nbytes / sizeof(FILE_ALLOCATED_RANGE_BUFFER);
// Print each allocated range
for (DWORD i = 0; i < dwAllocRangeCount; i++)
{
DbgPrint(L"allocated range: [%I64u] [%I64u]\n",
allocRanges[i].FileOffset.QuadPart,
allocRanges[i].Length.QuadPart);
}
// Set starting address and size for the next query
if (!fFinished && dwAllocRangeCount > 0)
{
queryRange.FileOffset.QuadPart = allocRanges[dwAllocRangeCount - 1].FileOffset.QuadPart +
allocRanges[dwAllocRangeCount - 1].Length.QuadPart;
queryRange.Length.QuadPart = liFileSize.QuadPart - queryRange.FileOffset.QuadPart;
}
} while (!fFinished);
return TRUE;
}

View File

@ -0,0 +1,24 @@
#pragma once
#include "AbstractIO.h"
class CImageFileIO : public CAbstractIO
{
public:
CImageFileIO(std::wstring& FilePath, ULONG64 uSize = 0);
virtual ~CImageFileIO();
virtual ULONG64 GetDiskSize() const;
virtual ULONG64 GetAllocSize() const;
virtual bool CanBeFormated() const;
virtual int Init();
virtual void PrepViewOfFile(BYTE*) {}
virtual bool DiskWrite(void* buf, int size, __int64 offset);
virtual bool DiskRead(void* buf, int size, __int64 offset);
virtual void TrimProcess(DEVICE_DATA_SET_RANGE* range, int n);
protected:
struct SImageFileIO* m;
};

View File

@ -0,0 +1,240 @@
#include "framework.h"
#include "ImDiskIO.h"
#include "ImBox.h"
#include "PhysicalMemoryIO.h"
#include "..\Common\helpers.h"
#include "..\ImDisk\inc\imdproxy.h"
#include "..\ImDisk\inc\imdisk.h"
struct SPhysicalMemory
{
ULONG64 uSize;
int mem_block_size, mem_block_size_mask, mem_block_size_shift;
size_t table_size;
void *virtual_mem_ptr = NULL;
bool *allocated_block = NULL;
HANDLE current_process;
ULONG_PTR n_pages, *pfn = NULL;
volatile size_t n_block = 0;
};
CPhysicalMemoryIO::CPhysicalMemoryIO(ULONG64 uSize, int BlockSize)
{
m = new SPhysicalMemory;
memset(m, 0, sizeof SPhysicalMemory);
m->uSize = uSize;
m->mem_block_size_shift = BlockSize;
if (m->mem_block_size_shift < 12) m->mem_block_size_shift = 12;
if (m->mem_block_size_shift > 30) m->mem_block_size_shift = 30;
m->mem_block_size = 1 << m->mem_block_size_shift;
m->mem_block_size_mask = m->mem_block_size - 1;
}
CPhysicalMemoryIO::~CPhysicalMemoryIO()
{
delete m;
}
ULONG64 CPhysicalMemoryIO::GetDiskSize() const
{
return m->uSize;
}
ULONG64 CPhysicalMemoryIO::GetAllocSize() const
{
return (ULONG64)m->n_block * m->mem_block_size;
}
int CPhysicalMemoryIO::Init()
{
TOKEN_PRIVILEGES tok_priv;
tok_priv.PrivilegeCount = 1;
tok_priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
m->current_process = GetCurrentProcess();
HANDLE token;
if (!OpenProcessToken(m->current_process, TOKEN_ADJUST_PRIVILEGES, &token) ||
!LookupPrivilegeValueA(NULL, "SeLockMemoryPrivilege", &tok_priv.Privileges[0].Luid) ||
!AdjustTokenPrivileges(token, FALSE, &tok_priv, 0, NULL, NULL) ||
GetLastError() != ERROR_SUCCESS)
return ERR_PRIVILEGE;
NtClose(token);
SYSTEM_INFO sys;
GetSystemInfo(&sys);
if (!(m->n_pages = m->mem_block_size / sys.dwPageSize))
return ERR_INTERNAL;
m->table_size = (m->uSize + m->mem_block_size_mask) / m->mem_block_size;
SIZE_T alloc_size = m->n_pages * m->table_size * sizeof(size_t);
NtAllocateVirtualMemory(NtCurrentProcess(), (void**)&m->pfn, 0, &alloc_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
alloc_size = m->table_size * sizeof(bool);
NtAllocateVirtualMemory(NtCurrentProcess(), (void**)&m->allocated_block, 0, &alloc_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
alloc_size = m->mem_block_size;
NtAllocateVirtualMemory(NtCurrentProcess(), &m->virtual_mem_ptr, 0, &alloc_size, MEM_RESERVE | MEM_PHYSICAL, PAGE_READWRITE);
return ERR_OK;
}
void CPhysicalMemoryIO::Expand(ULONG64 uSize)
{
if (uSize <= m->uSize)
return;
m->uSize = uSize;
SIZE_T old_size = m->table_size;
ULONG_PTR* old_pfn = m->pfn;
bool* old_block = m->allocated_block;
m->table_size = (m->uSize + m->mem_block_size_mask) / m->mem_block_size;
m->pfn = NULL;
SIZE_T alloc_size = m->n_pages * m->table_size * sizeof(size_t);
NtAllocateVirtualMemory(NtCurrentProcess(), (void**)&m->pfn, 0, &alloc_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
m->allocated_block = NULL;
alloc_size = m->table_size * sizeof(bool);
NtAllocateVirtualMemory(NtCurrentProcess(), (void**)&m->allocated_block, 0, &alloc_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
memcpy(m->pfn, old_pfn, m->n_pages * old_size * sizeof(size_t));
memcpy(m->allocated_block, old_block, old_size * sizeof(bool));
old_size = 0;
NtFreeVirtualMemory(NtCurrentProcess(), (void**)&old_pfn, &old_size, MEM_RELEASE);
old_size = 0;
NtFreeVirtualMemory(NtCurrentProcess(), (void**)&old_block, &old_size, MEM_RELEASE);
DbgPrint(L"Physical RAM Disk resized\n");
}
void CPhysicalMemoryIO::PrepViewOfFile(BYTE* shm_view)
{
SIZE_T min_working_set, max_working_set;
GetProcessWorkingSetSize(m->current_process, &min_working_set, &max_working_set);
min_working_set += DEF_BUFFER_SIZE + IMDPROXY_HEADER_SIZE;
max_working_set += DEF_BUFFER_SIZE + IMDPROXY_HEADER_SIZE;
SetProcessWorkingSetSize(m->current_process, min_working_set, max_working_set);
VirtualLock(shm_view, DEF_BUFFER_SIZE + IMDPROXY_HEADER_SIZE);
}
bool CPhysicalMemoryIO::DiskWrite(void* buf, int size, __int64 offset)
{
bool ret = true;
size_t index = offset >> m->mem_block_size_shift;
int current_size;
int block_offset = offset & m->mem_block_size_mask;
bool data;
ULONG_PTR allocated_pages, *pfn_ptr;
MEMORYSTATUSEX mem_stat;
mem_stat.dwLength = sizeof mem_stat;
do {
if (index >= m->table_size)
Expand(offset + size);
current_size = min(size + block_offset, m->mem_block_size) - block_offset;
data = data_search(buf, current_size);
if (m->allocated_block[index]) {
MapUserPhysicalPages(m->virtual_mem_ptr, m->n_pages, m->pfn + index * m->n_pages);
if (data)
memcpy((BYTE*)m->virtual_mem_ptr + block_offset, buf, current_size);
else if (data_search(m->virtual_mem_ptr, block_offset) || data_search((BYTE*)m->virtual_mem_ptr + block_offset + current_size, m->mem_block_size - block_offset - current_size))
ZeroMemory((BYTE*)m->virtual_mem_ptr + block_offset, current_size);
else {
allocated_pages = m->n_pages;
FreeUserPhysicalPages(m->current_process, &allocated_pages, m->pfn + index * m->n_pages);
m->allocated_block[index] = FALSE;
m->n_block--;
}
}
else if (data) {
GlobalMemoryStatusEx(&mem_stat);
if (mem_stat.ullAvailPageFile < MINIMAL_MEM) {
ret = false;
}
else {
allocated_pages = m->n_pages;
pfn_ptr = m->pfn + index * m->n_pages;
if (!AllocateUserPhysicalPages(m->current_process, &allocated_pages, pfn_ptr)) {
ret = false;
}
else if (allocated_pages != m->n_pages) {
FreeUserPhysicalPages(m->current_process, &allocated_pages, pfn_ptr);
ret = false;
} else {
MapUserPhysicalPages(m->virtual_mem_ptr, m->n_pages, pfn_ptr);
memcpy((BYTE*)m->virtual_mem_ptr + block_offset, buf, current_size);
m->allocated_block[index] = TRUE;
m->n_block++;
}
}
}
block_offset = 0;
buf = (BYTE*)buf + current_size;
index++;
size -= current_size;
} while (size > 0);
return ret;
}
bool CPhysicalMemoryIO::DiskRead(void* buf, int size, __int64 offset)
{
size_t index = offset >> m->mem_block_size_shift;
int current_size;
int block_offset = offset & m->mem_block_size_mask;
do {
if (index >= m->table_size)
Expand(offset + size);
current_size = min(size + block_offset, m->mem_block_size) - block_offset;
if (m->allocated_block[index]) {
MapUserPhysicalPages(m->virtual_mem_ptr, m->n_pages, m->pfn + index * m->n_pages);
memcpy(buf, (BYTE*)m->virtual_mem_ptr + block_offset, current_size);
} else
ZeroMemory(buf, current_size);
block_offset = 0;
buf = (BYTE*)buf + current_size;
index++;
size -= current_size;
} while (size > 0);
return true;
}
void CPhysicalMemoryIO::TrimProcess(DEVICE_DATA_SET_RANGE* range, int n)
{
size_t index;
int current_size, block_offset;
__int64 size;
ULONG_PTR allocated_pages;
while (n) {
index = range->StartingOffset >> m->mem_block_size_shift;
block_offset = range->StartingOffset & m->mem_block_size_mask;
for (size = range->LengthInBytes; size > 0; size -= current_size) {
if (index >= m->table_size)
break;
current_size = min(size + block_offset, (__int64)m->mem_block_size) - block_offset;
if (m->allocated_block[index]) {
MapUserPhysicalPages(m->virtual_mem_ptr, m->n_pages, m->pfn + index * m->n_pages);
if (data_search(m->virtual_mem_ptr, block_offset) || data_search((BYTE*)m->virtual_mem_ptr + block_offset + current_size, m->mem_block_size - block_offset - current_size))
ZeroMemory((BYTE*)m->virtual_mem_ptr + block_offset, current_size);
else {
allocated_pages = m->n_pages;
FreeUserPhysicalPages(m->current_process, &allocated_pages, m->pfn + index * m->n_pages);
m->allocated_block[index] = FALSE;
m->n_block--;
}
}
block_offset = 0;
index++;
}
range++;
n--;
}
}

View File

@ -0,0 +1,26 @@
#pragma once
#include "AbstractIO.h"
class CPhysicalMemoryIO : public CAbstractIO
{
public:
CPhysicalMemoryIO(ULONG64 uSize, int BlockSize = 20);
virtual ~CPhysicalMemoryIO();
virtual ULONG64 GetDiskSize() const;
virtual ULONG64 GetAllocSize() const;
virtual bool CanBeFormated() const { return true; }
virtual int Init();
virtual void PrepViewOfFile(BYTE*);
virtual bool DiskWrite(void* buf, int size, __int64 offset);
virtual bool DiskRead(void* buf, int size, __int64 offset);
virtual void TrimProcess(DEVICE_DATA_SET_RANGE* range, int n);
protected:
void Expand(ULONG64 uSize);
struct SPhysicalMemory* m;
};

View File

@ -0,0 +1,30 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by ImBox.rc
#define IDS_APP_TITLE 103
#define IDR_MAINFRAME 128
#define IDD_IMBOX_DIALOG 102
#define IDD_ABOUTBOX 103
#define IDM_ABOUT 104
#define IDM_EXIT 105
#define IDI_IMBOX 107
#define IDI_SMALL 108
#define IDC_IMBOX 109
#define IDC_MYICON 2
#ifndef IDC_STATIC
#define IDC_STATIC -1
#endif
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 130
#define _APS_NEXT_RESOURCE_VALUE 129
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 110
#endif
#endif

View File

@ -0,0 +1,183 @@
#include "framework.h"
#include "ImDiskIO.h"
#include "ImBox.h"
#include "VirtualMemoryIO.h"
#include "..\Common\helpers.h"
struct SVirtualMemory
{
ULONG64 uSize;
int mem_block_size, mem_block_size_mask, mem_block_size_shift;
size_t table_size;
void **ptr_table;
volatile size_t n_block = 0;
};
CVirtualMemoryIO::CVirtualMemoryIO(ULONG64 uSize, int BlockSize)
{
m = new SVirtualMemory;
memset(m, 0, sizeof SVirtualMemory);
m->uSize = uSize;
m->mem_block_size_shift = BlockSize;
if (m->mem_block_size_shift < 12) m->mem_block_size_shift = 12;
if (m->mem_block_size_shift > 30) m->mem_block_size_shift = 30;
m->mem_block_size = 1 << m->mem_block_size_shift;
m->mem_block_size_mask = m->mem_block_size - 1;
}
CVirtualMemoryIO::~CVirtualMemoryIO()
{
delete m;
}
ULONG64 CVirtualMemoryIO::GetDiskSize() const
{
return m->uSize;
}
ULONG64 CVirtualMemoryIO::GetAllocSize() const
{
return (ULONG64)m->n_block * m->mem_block_size;
}
int CVirtualMemoryIO::Init()
{
m->table_size = (m->uSize + m->mem_block_size_mask) / m->mem_block_size;
SIZE_T alloc_size = m->table_size * sizeof(size_t);
NtAllocateVirtualMemory(NtCurrentProcess(), (void**)&m->ptr_table, 0, &alloc_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
return ERR_OK;
}
void CVirtualMemoryIO::Expand(ULONG64 uSize)
{
if (uSize <= m->uSize)
return;
m->uSize = uSize;
SIZE_T old_size = m->table_size;
void** old_table = m->ptr_table;
m->table_size = (m->uSize + m->mem_block_size_mask) / m->mem_block_size;
m->ptr_table = NULL;
SIZE_T alloc_size = m->table_size * sizeof(size_t);
NtAllocateVirtualMemory(NtCurrentProcess(), (void**)&m->ptr_table, 0, &alloc_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
memcpy(m->ptr_table, old_table, old_size * sizeof(size_t));
old_size = 0;
NtFreeVirtualMemory(NtCurrentProcess(), (void**)&old_table, &old_size, MEM_RELEASE);
DbgPrint(L"Virtual RAM Disk resized\n");
}
bool CVirtualMemoryIO::DiskWrite(void* buf, int size, __int64 offset)
{
bool ret = true;
size_t index = offset >> m->mem_block_size_shift;
int current_size;
int block_offset = offset & m->mem_block_size_mask;
void *ptr;
bool data;
SIZE_T alloc_size;
MEMORYSTATUSEX mem_stat;
mem_stat.dwLength = sizeof mem_stat;
do {
if (index >= m->table_size)
Expand(offset + size);
current_size = min(size + block_offset, m->mem_block_size) - block_offset;
data = data_search(buf, current_size);
if ((ptr = m->ptr_table[index])) {
if (data)
memcpy((BYTE*)ptr + block_offset, buf, current_size);
else if (data_search(ptr, block_offset) || data_search((BYTE*)ptr + block_offset + current_size, m->mem_block_size - block_offset - current_size))
ZeroMemory((BYTE*)ptr + block_offset, current_size);
else {
alloc_size = 0;
NtFreeVirtualMemory(NtCurrentProcess(), &ptr, &alloc_size, MEM_RELEASE);
m->ptr_table[index] = NULL;
m->n_block--;
}
}
else if (data) {
GlobalMemoryStatusEx(&mem_stat);
alloc_size = m->mem_block_size;
if (mem_stat.ullAvailPageFile >= MINIMAL_MEM && (NtAllocateVirtualMemory(NtCurrentProcess(), &m->ptr_table[index], 0, &alloc_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) == STATUS_SUCCESS)) {
memcpy((BYTE*)m->ptr_table[index] + block_offset, buf, current_size);
m->n_block++;
}
else {
ret = false;
}
}
block_offset = 0;
buf = (BYTE*)buf + current_size;
index++;
size -= current_size;
} while (size > 0);
return ret;
}
bool CVirtualMemoryIO::DiskRead(void* buf, int size, __int64 offset)
{
size_t index = offset >> m->mem_block_size_shift;
int current_size;
int block_offset = offset & m->mem_block_size_mask;
do {
if (index >= m->table_size)
Expand(offset + size);
current_size = min(size + block_offset, m->mem_block_size) - block_offset;
if (m->ptr_table[index])
memcpy(buf, (BYTE*)m->ptr_table[index] + block_offset, current_size);
else
ZeroMemory(buf, current_size);
block_offset = 0;
buf = (BYTE*)buf + current_size;
index++;
size -= current_size;
} while (size > 0);
return true;
}
void CVirtualMemoryIO::TrimProcess(DEVICE_DATA_SET_RANGE* range, int n)
{
size_t index;
int current_size, block_offset;
__int64 size;
void *ptr;
SIZE_T alloc_size;
while (n) {
index = range->StartingOffset >> m->mem_block_size_shift;
block_offset = range->StartingOffset & m->mem_block_size_mask;
for (size = range->LengthInBytes; size > 0; size -= current_size) {
if (index >= m->table_size)
break;
current_size = min(size + block_offset, (__int64)m->mem_block_size) - block_offset;
if ((ptr = m->ptr_table[index])) {
if (data_search(ptr, block_offset) || data_search((BYTE*)ptr + block_offset + current_size, m->mem_block_size - block_offset - current_size))
ZeroMemory((BYTE*)ptr + block_offset, current_size);
else {
alloc_size = 0;
NtFreeVirtualMemory(NtCurrentProcess(), &ptr, &alloc_size, MEM_RELEASE);
m->ptr_table[index] = NULL;
m->n_block--;
}
}
block_offset = 0;
index++;
}
range++;
n--;
}
}

View File

@ -0,0 +1,26 @@
#pragma once
#include "AbstractIO.h"
class CVirtualMemoryIO : public CAbstractIO
{
public:
CVirtualMemoryIO(ULONG64 uSize, int BlockSize = 20);
virtual ~CVirtualMemoryIO();
virtual ULONG64 GetDiskSize() const;
virtual ULONG64 GetAllocSize() const;
virtual bool CanBeFormated() const { return true; }
virtual int Init();
virtual void PrepViewOfFile(BYTE*) {}
virtual bool DiskWrite(void* buf, int size, __int64 offset);
virtual bool DiskRead(void* buf, int size, __int64 offset);
virtual void TrimProcess(DEVICE_DATA_SET_RANGE* range, int n);
protected:
void Expand(ULONG64 uSize);
struct SVirtualMemory* m;
};

View File

@ -0,0 +1,14 @@
#ifndef _AES_ASM_H_
#define _AES_ASM_H_
#include "aes_key.h"
#ifdef _M_IX86
void _stdcall aes256_asm_set_key(const unsigned char *key, aes256_key *skey);
#else
#define aes256_asm_set_key aes256_set_key
#endif
void _stdcall aes256_asm_encrypt(const unsigned char *in, unsigned char *out, aes256_key *key);
void _stdcall aes256_asm_decrypt(const unsigned char *in, unsigned char *out, aes256_key *key);
#endif

View File

@ -0,0 +1,642 @@
/*
*
* DiskCryptor - open source partition encryption tool
* Copyright (c) 2007-2012
* ntldr <ntldr@diskcryptor.net> PGP key ID - 0x1B6A24550F33E44A
* based on rijndael-alg-fst.c
* @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
* @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
* @author Paulo Barreto <paulo.barreto@terra.com.br>
*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <memory.h>
#include <intrin.h>
#include "aes_key.h"
__declspec(align(16)) const unsigned long Te0[256] = {
0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6, 0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591,
0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56, 0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec,
0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa, 0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb,
0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45, 0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b,
0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c, 0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83,
0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9, 0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a,
0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d, 0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f,
0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df, 0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea,
0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34, 0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b,
0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d, 0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413,
0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1, 0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6,
0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972, 0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85,
0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed, 0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511,
0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe, 0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b,
0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05, 0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1,
0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142, 0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf,
0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3, 0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e,
0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a, 0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6,
0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3, 0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b,
0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428, 0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad,
0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14, 0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8,
0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4, 0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2,
0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda, 0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949,
0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf, 0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810,
0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c, 0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697,
0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e, 0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f,
0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc, 0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c,
0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969, 0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27,
0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122, 0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433,
0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9, 0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5,
0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a, 0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0,
0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e, 0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c
};
__declspec(align(16)) const unsigned long Te1[256] = {
0x6363c6a5, 0x7c7cf884, 0x7777ee99, 0x7b7bf68d, 0xf2f2ff0d, 0x6b6bd6bd, 0x6f6fdeb1, 0xc5c59154,
0x30306050, 0x01010203, 0x6767cea9, 0x2b2b567d, 0xfefee719, 0xd7d7b562, 0xabab4de6, 0x7676ec9a,
0xcaca8f45, 0x82821f9d, 0xc9c98940, 0x7d7dfa87, 0xfafaef15, 0x5959b2eb, 0x47478ec9, 0xf0f0fb0b,
0xadad41ec, 0xd4d4b367, 0xa2a25ffd, 0xafaf45ea, 0x9c9c23bf, 0xa4a453f7, 0x7272e496, 0xc0c09b5b,
0xb7b775c2, 0xfdfde11c, 0x93933dae, 0x26264c6a, 0x36366c5a, 0x3f3f7e41, 0xf7f7f502, 0xcccc834f,
0x3434685c, 0xa5a551f4, 0xe5e5d134, 0xf1f1f908, 0x7171e293, 0xd8d8ab73, 0x31316253, 0x15152a3f,
0x0404080c, 0xc7c79552, 0x23234665, 0xc3c39d5e, 0x18183028, 0x969637a1, 0x05050a0f, 0x9a9a2fb5,
0x07070e09, 0x12122436, 0x80801b9b, 0xe2e2df3d, 0xebebcd26, 0x27274e69, 0xb2b27fcd, 0x7575ea9f,
0x0909121b, 0x83831d9e, 0x2c2c5874, 0x1a1a342e, 0x1b1b362d, 0x6e6edcb2, 0x5a5ab4ee, 0xa0a05bfb,
0x5252a4f6, 0x3b3b764d, 0xd6d6b761, 0xb3b37dce, 0x2929527b, 0xe3e3dd3e, 0x2f2f5e71, 0x84841397,
0x5353a6f5, 0xd1d1b968, 0x00000000, 0xededc12c, 0x20204060, 0xfcfce31f, 0xb1b179c8, 0x5b5bb6ed,
0x6a6ad4be, 0xcbcb8d46, 0xbebe67d9, 0x3939724b, 0x4a4a94de, 0x4c4c98d4, 0x5858b0e8, 0xcfcf854a,
0xd0d0bb6b, 0xefefc52a, 0xaaaa4fe5, 0xfbfbed16, 0x434386c5, 0x4d4d9ad7, 0x33336655, 0x85851194,
0x45458acf, 0xf9f9e910, 0x02020406, 0x7f7ffe81, 0x5050a0f0, 0x3c3c7844, 0x9f9f25ba, 0xa8a84be3,
0x5151a2f3, 0xa3a35dfe, 0x404080c0, 0x8f8f058a, 0x92923fad, 0x9d9d21bc, 0x38387048, 0xf5f5f104,
0xbcbc63df, 0xb6b677c1, 0xdadaaf75, 0x21214263, 0x10102030, 0xffffe51a, 0xf3f3fd0e, 0xd2d2bf6d,
0xcdcd814c, 0x0c0c1814, 0x13132635, 0xececc32f, 0x5f5fbee1, 0x979735a2, 0x444488cc, 0x17172e39,
0xc4c49357, 0xa7a755f2, 0x7e7efc82, 0x3d3d7a47, 0x6464c8ac, 0x5d5dbae7, 0x1919322b, 0x7373e695,
0x6060c0a0, 0x81811998, 0x4f4f9ed1, 0xdcdca37f, 0x22224466, 0x2a2a547e, 0x90903bab, 0x88880b83,
0x46468cca, 0xeeeec729, 0xb8b86bd3, 0x1414283c, 0xdedea779, 0x5e5ebce2, 0x0b0b161d, 0xdbdbad76,
0xe0e0db3b, 0x32326456, 0x3a3a744e, 0x0a0a141e, 0x494992db, 0x06060c0a, 0x2424486c, 0x5c5cb8e4,
0xc2c29f5d, 0xd3d3bd6e, 0xacac43ef, 0x6262c4a6, 0x919139a8, 0x959531a4, 0xe4e4d337, 0x7979f28b,
0xe7e7d532, 0xc8c88b43, 0x37376e59, 0x6d6ddab7, 0x8d8d018c, 0xd5d5b164, 0x4e4e9cd2, 0xa9a949e0,
0x6c6cd8b4, 0x5656acfa, 0xf4f4f307, 0xeaeacf25, 0x6565caaf, 0x7a7af48e, 0xaeae47e9, 0x08081018,
0xbaba6fd5, 0x7878f088, 0x25254a6f, 0x2e2e5c72, 0x1c1c3824, 0xa6a657f1, 0xb4b473c7, 0xc6c69751,
0xe8e8cb23, 0xdddda17c, 0x7474e89c, 0x1f1f3e21, 0x4b4b96dd, 0xbdbd61dc, 0x8b8b0d86, 0x8a8a0f85,
0x7070e090, 0x3e3e7c42, 0xb5b571c4, 0x6666ccaa, 0x484890d8, 0x03030605, 0xf6f6f701, 0x0e0e1c12,
0x6161c2a3, 0x35356a5f, 0x5757aef9, 0xb9b969d0, 0x86861791, 0xc1c19958, 0x1d1d3a27, 0x9e9e27b9,
0xe1e1d938, 0xf8f8eb13, 0x98982bb3, 0x11112233, 0x6969d2bb, 0xd9d9a970, 0x8e8e0789, 0x949433a7,
0x9b9b2db6, 0x1e1e3c22, 0x87871592, 0xe9e9c920, 0xcece8749, 0x5555aaff, 0x28285078, 0xdfdfa57a,
0x8c8c038f, 0xa1a159f8, 0x89890980, 0x0d0d1a17, 0xbfbf65da, 0xe6e6d731, 0x424284c6, 0x6868d0b8,
0x414182c3, 0x999929b0, 0x2d2d5a77, 0x0f0f1e11, 0xb0b07bcb, 0x5454a8fc, 0xbbbb6dd6, 0x16162c3a
};
__declspec(align(16)) const unsigned long Te2[256] = {
0x63c6a563, 0x7cf8847c, 0x77ee9977, 0x7bf68d7b, 0xf2ff0df2, 0x6bd6bd6b, 0x6fdeb16f, 0xc59154c5,
0x30605030, 0x01020301, 0x67cea967, 0x2b567d2b, 0xfee719fe, 0xd7b562d7, 0xab4de6ab, 0x76ec9a76,
0xca8f45ca, 0x821f9d82, 0xc98940c9, 0x7dfa877d, 0xfaef15fa, 0x59b2eb59, 0x478ec947, 0xf0fb0bf0,
0xad41ecad, 0xd4b367d4, 0xa25ffda2, 0xaf45eaaf, 0x9c23bf9c, 0xa453f7a4, 0x72e49672, 0xc09b5bc0,
0xb775c2b7, 0xfde11cfd, 0x933dae93, 0x264c6a26, 0x366c5a36, 0x3f7e413f, 0xf7f502f7, 0xcc834fcc,
0x34685c34, 0xa551f4a5, 0xe5d134e5, 0xf1f908f1, 0x71e29371, 0xd8ab73d8, 0x31625331, 0x152a3f15,
0x04080c04, 0xc79552c7, 0x23466523, 0xc39d5ec3, 0x18302818, 0x9637a196, 0x050a0f05, 0x9a2fb59a,
0x070e0907, 0x12243612, 0x801b9b80, 0xe2df3de2, 0xebcd26eb, 0x274e6927, 0xb27fcdb2, 0x75ea9f75,
0x09121b09, 0x831d9e83, 0x2c58742c, 0x1a342e1a, 0x1b362d1b, 0x6edcb26e, 0x5ab4ee5a, 0xa05bfba0,
0x52a4f652, 0x3b764d3b, 0xd6b761d6, 0xb37dceb3, 0x29527b29, 0xe3dd3ee3, 0x2f5e712f, 0x84139784,
0x53a6f553, 0xd1b968d1, 0x00000000, 0xedc12ced, 0x20406020, 0xfce31ffc, 0xb179c8b1, 0x5bb6ed5b,
0x6ad4be6a, 0xcb8d46cb, 0xbe67d9be, 0x39724b39, 0x4a94de4a, 0x4c98d44c, 0x58b0e858, 0xcf854acf,
0xd0bb6bd0, 0xefc52aef, 0xaa4fe5aa, 0xfbed16fb, 0x4386c543, 0x4d9ad74d, 0x33665533, 0x85119485,
0x458acf45, 0xf9e910f9, 0x02040602, 0x7ffe817f, 0x50a0f050, 0x3c78443c, 0x9f25ba9f, 0xa84be3a8,
0x51a2f351, 0xa35dfea3, 0x4080c040, 0x8f058a8f, 0x923fad92, 0x9d21bc9d, 0x38704838, 0xf5f104f5,
0xbc63dfbc, 0xb677c1b6, 0xdaaf75da, 0x21426321, 0x10203010, 0xffe51aff, 0xf3fd0ef3, 0xd2bf6dd2,
0xcd814ccd, 0x0c18140c, 0x13263513, 0xecc32fec, 0x5fbee15f, 0x9735a297, 0x4488cc44, 0x172e3917,
0xc49357c4, 0xa755f2a7, 0x7efc827e, 0x3d7a473d, 0x64c8ac64, 0x5dbae75d, 0x19322b19, 0x73e69573,
0x60c0a060, 0x81199881, 0x4f9ed14f, 0xdca37fdc, 0x22446622, 0x2a547e2a, 0x903bab90, 0x880b8388,
0x468cca46, 0xeec729ee, 0xb86bd3b8, 0x14283c14, 0xdea779de, 0x5ebce25e, 0x0b161d0b, 0xdbad76db,
0xe0db3be0, 0x32645632, 0x3a744e3a, 0x0a141e0a, 0x4992db49, 0x060c0a06, 0x24486c24, 0x5cb8e45c,
0xc29f5dc2, 0xd3bd6ed3, 0xac43efac, 0x62c4a662, 0x9139a891, 0x9531a495, 0xe4d337e4, 0x79f28b79,
0xe7d532e7, 0xc88b43c8, 0x376e5937, 0x6ddab76d, 0x8d018c8d, 0xd5b164d5, 0x4e9cd24e, 0xa949e0a9,
0x6cd8b46c, 0x56acfa56, 0xf4f307f4, 0xeacf25ea, 0x65caaf65, 0x7af48e7a, 0xae47e9ae, 0x08101808,
0xba6fd5ba, 0x78f08878, 0x254a6f25, 0x2e5c722e, 0x1c38241c, 0xa657f1a6, 0xb473c7b4, 0xc69751c6,
0xe8cb23e8, 0xdda17cdd, 0x74e89c74, 0x1f3e211f, 0x4b96dd4b, 0xbd61dcbd, 0x8b0d868b, 0x8a0f858a,
0x70e09070, 0x3e7c423e, 0xb571c4b5, 0x66ccaa66, 0x4890d848, 0x03060503, 0xf6f701f6, 0x0e1c120e,
0x61c2a361, 0x356a5f35, 0x57aef957, 0xb969d0b9, 0x86179186, 0xc19958c1, 0x1d3a271d, 0x9e27b99e,
0xe1d938e1, 0xf8eb13f8, 0x982bb398, 0x11223311, 0x69d2bb69, 0xd9a970d9, 0x8e07898e, 0x9433a794,
0x9b2db69b, 0x1e3c221e, 0x87159287, 0xe9c920e9, 0xce8749ce, 0x55aaff55, 0x28507828, 0xdfa57adf,
0x8c038f8c, 0xa159f8a1, 0x89098089, 0x0d1a170d, 0xbf65dabf, 0xe6d731e6, 0x4284c642, 0x68d0b868,
0x4182c341, 0x9929b099, 0x2d5a772d, 0x0f1e110f, 0xb07bcbb0, 0x54a8fc54, 0xbb6dd6bb, 0x162c3a16
};
__declspec(align(16)) const unsigned long Te3[256] = {
0xc6a56363, 0xf8847c7c, 0xee997777, 0xf68d7b7b, 0xff0df2f2, 0xd6bd6b6b, 0xdeb16f6f, 0x9154c5c5,
0x60503030, 0x02030101, 0xcea96767, 0x567d2b2b, 0xe719fefe, 0xb562d7d7, 0x4de6abab, 0xec9a7676,
0x8f45caca, 0x1f9d8282, 0x8940c9c9, 0xfa877d7d, 0xef15fafa, 0xb2eb5959, 0x8ec94747, 0xfb0bf0f0,
0x41ecadad, 0xb367d4d4, 0x5ffda2a2, 0x45eaafaf, 0x23bf9c9c, 0x53f7a4a4, 0xe4967272, 0x9b5bc0c0,
0x75c2b7b7, 0xe11cfdfd, 0x3dae9393, 0x4c6a2626, 0x6c5a3636, 0x7e413f3f, 0xf502f7f7, 0x834fcccc,
0x685c3434, 0x51f4a5a5, 0xd134e5e5, 0xf908f1f1, 0xe2937171, 0xab73d8d8, 0x62533131, 0x2a3f1515,
0x080c0404, 0x9552c7c7, 0x46652323, 0x9d5ec3c3, 0x30281818, 0x37a19696, 0x0a0f0505, 0x2fb59a9a,
0x0e090707, 0x24361212, 0x1b9b8080, 0xdf3de2e2, 0xcd26ebeb, 0x4e692727, 0x7fcdb2b2, 0xea9f7575,
0x121b0909, 0x1d9e8383, 0x58742c2c, 0x342e1a1a, 0x362d1b1b, 0xdcb26e6e, 0xb4ee5a5a, 0x5bfba0a0,
0xa4f65252, 0x764d3b3b, 0xb761d6d6, 0x7dceb3b3, 0x527b2929, 0xdd3ee3e3, 0x5e712f2f, 0x13978484,
0xa6f55353, 0xb968d1d1, 0x00000000, 0xc12ceded, 0x40602020, 0xe31ffcfc, 0x79c8b1b1, 0xb6ed5b5b,
0xd4be6a6a, 0x8d46cbcb, 0x67d9bebe, 0x724b3939, 0x94de4a4a, 0x98d44c4c, 0xb0e85858, 0x854acfcf,
0xbb6bd0d0, 0xc52aefef, 0x4fe5aaaa, 0xed16fbfb, 0x86c54343, 0x9ad74d4d, 0x66553333, 0x11948585,
0x8acf4545, 0xe910f9f9, 0x04060202, 0xfe817f7f, 0xa0f05050, 0x78443c3c, 0x25ba9f9f, 0x4be3a8a8,
0xa2f35151, 0x5dfea3a3, 0x80c04040, 0x058a8f8f, 0x3fad9292, 0x21bc9d9d, 0x70483838, 0xf104f5f5,
0x63dfbcbc, 0x77c1b6b6, 0xaf75dada, 0x42632121, 0x20301010, 0xe51affff, 0xfd0ef3f3, 0xbf6dd2d2,
0x814ccdcd, 0x18140c0c, 0x26351313, 0xc32fecec, 0xbee15f5f, 0x35a29797, 0x88cc4444, 0x2e391717,
0x9357c4c4, 0x55f2a7a7, 0xfc827e7e, 0x7a473d3d, 0xc8ac6464, 0xbae75d5d, 0x322b1919, 0xe6957373,
0xc0a06060, 0x19988181, 0x9ed14f4f, 0xa37fdcdc, 0x44662222, 0x547e2a2a, 0x3bab9090, 0x0b838888,
0x8cca4646, 0xc729eeee, 0x6bd3b8b8, 0x283c1414, 0xa779dede, 0xbce25e5e, 0x161d0b0b, 0xad76dbdb,
0xdb3be0e0, 0x64563232, 0x744e3a3a, 0x141e0a0a, 0x92db4949, 0x0c0a0606, 0x486c2424, 0xb8e45c5c,
0x9f5dc2c2, 0xbd6ed3d3, 0x43efacac, 0xc4a66262, 0x39a89191, 0x31a49595, 0xd337e4e4, 0xf28b7979,
0xd532e7e7, 0x8b43c8c8, 0x6e593737, 0xdab76d6d, 0x018c8d8d, 0xb164d5d5, 0x9cd24e4e, 0x49e0a9a9,
0xd8b46c6c, 0xacfa5656, 0xf307f4f4, 0xcf25eaea, 0xcaaf6565, 0xf48e7a7a, 0x47e9aeae, 0x10180808,
0x6fd5baba, 0xf0887878, 0x4a6f2525, 0x5c722e2e, 0x38241c1c, 0x57f1a6a6, 0x73c7b4b4, 0x9751c6c6,
0xcb23e8e8, 0xa17cdddd, 0xe89c7474, 0x3e211f1f, 0x96dd4b4b, 0x61dcbdbd, 0x0d868b8b, 0x0f858a8a,
0xe0907070, 0x7c423e3e, 0x71c4b5b5, 0xccaa6666, 0x90d84848, 0x06050303, 0xf701f6f6, 0x1c120e0e,
0xc2a36161, 0x6a5f3535, 0xaef95757, 0x69d0b9b9, 0x17918686, 0x9958c1c1, 0x3a271d1d, 0x27b99e9e,
0xd938e1e1, 0xeb13f8f8, 0x2bb39898, 0x22331111, 0xd2bb6969, 0xa970d9d9, 0x07898e8e, 0x33a79494,
0x2db69b9b, 0x3c221e1e, 0x15928787, 0xc920e9e9, 0x8749cece, 0xaaff5555, 0x50782828, 0xa57adfdf,
0x038f8c8c, 0x59f8a1a1, 0x09808989, 0x1a170d0d, 0x65dabfbf, 0xd731e6e6, 0x84c64242, 0xd0b86868,
0x82c34141, 0x29b09999, 0x5a772d2d, 0x1e110f0f, 0x7bcbb0b0, 0xa8fc5454, 0x6dd6bbbb, 0x2c3a1616
};
__declspec(align(16)) const unsigned long Te4_0[256] = {
0x00000063, 0x0000007c, 0x00000077, 0x0000007b, 0x000000f2, 0x0000006b, 0x0000006f, 0x000000c5,
0x00000030, 0x00000001, 0x00000067, 0x0000002b, 0x000000fe, 0x000000d7, 0x000000ab, 0x00000076,
0x000000ca, 0x00000082, 0x000000c9, 0x0000007d, 0x000000fa, 0x00000059, 0x00000047, 0x000000f0,
0x000000ad, 0x000000d4, 0x000000a2, 0x000000af, 0x0000009c, 0x000000a4, 0x00000072, 0x000000c0,
0x000000b7, 0x000000fd, 0x00000093, 0x00000026, 0x00000036, 0x0000003f, 0x000000f7, 0x000000cc,
0x00000034, 0x000000a5, 0x000000e5, 0x000000f1, 0x00000071, 0x000000d8, 0x00000031, 0x00000015,
0x00000004, 0x000000c7, 0x00000023, 0x000000c3, 0x00000018, 0x00000096, 0x00000005, 0x0000009a,
0x00000007, 0x00000012, 0x00000080, 0x000000e2, 0x000000eb, 0x00000027, 0x000000b2, 0x00000075,
0x00000009, 0x00000083, 0x0000002c, 0x0000001a, 0x0000001b, 0x0000006e, 0x0000005a, 0x000000a0,
0x00000052, 0x0000003b, 0x000000d6, 0x000000b3, 0x00000029, 0x000000e3, 0x0000002f, 0x00000084,
0x00000053, 0x000000d1, 0x00000000, 0x000000ed, 0x00000020, 0x000000fc, 0x000000b1, 0x0000005b,
0x0000006a, 0x000000cb, 0x000000be, 0x00000039, 0x0000004a, 0x0000004c, 0x00000058, 0x000000cf,
0x000000d0, 0x000000ef, 0x000000aa, 0x000000fb, 0x00000043, 0x0000004d, 0x00000033, 0x00000085,
0x00000045, 0x000000f9, 0x00000002, 0x0000007f, 0x00000050, 0x0000003c, 0x0000009f, 0x000000a8,
0x00000051, 0x000000a3, 0x00000040, 0x0000008f, 0x00000092, 0x0000009d, 0x00000038, 0x000000f5,
0x000000bc, 0x000000b6, 0x000000da, 0x00000021, 0x00000010, 0x000000ff, 0x000000f3, 0x000000d2,
0x000000cd, 0x0000000c, 0x00000013, 0x000000ec, 0x0000005f, 0x00000097, 0x00000044, 0x00000017,
0x000000c4, 0x000000a7, 0x0000007e, 0x0000003d, 0x00000064, 0x0000005d, 0x00000019, 0x00000073,
0x00000060, 0x00000081, 0x0000004f, 0x000000dc, 0x00000022, 0x0000002a, 0x00000090, 0x00000088,
0x00000046, 0x000000ee, 0x000000b8, 0x00000014, 0x000000de, 0x0000005e, 0x0000000b, 0x000000db,
0x000000e0, 0x00000032, 0x0000003a, 0x0000000a, 0x00000049, 0x00000006, 0x00000024, 0x0000005c,
0x000000c2, 0x000000d3, 0x000000ac, 0x00000062, 0x00000091, 0x00000095, 0x000000e4, 0x00000079,
0x000000e7, 0x000000c8, 0x00000037, 0x0000006d, 0x0000008d, 0x000000d5, 0x0000004e, 0x000000a9,
0x0000006c, 0x00000056, 0x000000f4, 0x000000ea, 0x00000065, 0x0000007a, 0x000000ae, 0x00000008,
0x000000ba, 0x00000078, 0x00000025, 0x0000002e, 0x0000001c, 0x000000a6, 0x000000b4, 0x000000c6,
0x000000e8, 0x000000dd, 0x00000074, 0x0000001f, 0x0000004b, 0x000000bd, 0x0000008b, 0x0000008a,
0x00000070, 0x0000003e, 0x000000b5, 0x00000066, 0x00000048, 0x00000003, 0x000000f6, 0x0000000e,
0x00000061, 0x00000035, 0x00000057, 0x000000b9, 0x00000086, 0x000000c1, 0x0000001d, 0x0000009e,
0x000000e1, 0x000000f8, 0x00000098, 0x00000011, 0x00000069, 0x000000d9, 0x0000008e, 0x00000094,
0x0000009b, 0x0000001e, 0x00000087, 0x000000e9, 0x000000ce, 0x00000055, 0x00000028, 0x000000df,
0x0000008c, 0x000000a1, 0x00000089, 0x0000000d, 0x000000bf, 0x000000e6, 0x00000042, 0x00000068,
0x00000041, 0x00000099, 0x0000002d, 0x0000000f, 0x000000b0, 0x00000054, 0x000000bb, 0x00000016
};
__declspec(align(16)) const unsigned long Te4_1[256] = {
0x00006300, 0x00007c00, 0x00007700, 0x00007b00, 0x0000f200, 0x00006b00, 0x00006f00, 0x0000c500,
0x00003000, 0x00000100, 0x00006700, 0x00002b00, 0x0000fe00, 0x0000d700, 0x0000ab00, 0x00007600,
0x0000ca00, 0x00008200, 0x0000c900, 0x00007d00, 0x0000fa00, 0x00005900, 0x00004700, 0x0000f000,
0x0000ad00, 0x0000d400, 0x0000a200, 0x0000af00, 0x00009c00, 0x0000a400, 0x00007200, 0x0000c000,
0x0000b700, 0x0000fd00, 0x00009300, 0x00002600, 0x00003600, 0x00003f00, 0x0000f700, 0x0000cc00,
0x00003400, 0x0000a500, 0x0000e500, 0x0000f100, 0x00007100, 0x0000d800, 0x00003100, 0x00001500,
0x00000400, 0x0000c700, 0x00002300, 0x0000c300, 0x00001800, 0x00009600, 0x00000500, 0x00009a00,
0x00000700, 0x00001200, 0x00008000, 0x0000e200, 0x0000eb00, 0x00002700, 0x0000b200, 0x00007500,
0x00000900, 0x00008300, 0x00002c00, 0x00001a00, 0x00001b00, 0x00006e00, 0x00005a00, 0x0000a000,
0x00005200, 0x00003b00, 0x0000d600, 0x0000b300, 0x00002900, 0x0000e300, 0x00002f00, 0x00008400,
0x00005300, 0x0000d100, 0x00000000, 0x0000ed00, 0x00002000, 0x0000fc00, 0x0000b100, 0x00005b00,
0x00006a00, 0x0000cb00, 0x0000be00, 0x00003900, 0x00004a00, 0x00004c00, 0x00005800, 0x0000cf00,
0x0000d000, 0x0000ef00, 0x0000aa00, 0x0000fb00, 0x00004300, 0x00004d00, 0x00003300, 0x00008500,
0x00004500, 0x0000f900, 0x00000200, 0x00007f00, 0x00005000, 0x00003c00, 0x00009f00, 0x0000a800,
0x00005100, 0x0000a300, 0x00004000, 0x00008f00, 0x00009200, 0x00009d00, 0x00003800, 0x0000f500,
0x0000bc00, 0x0000b600, 0x0000da00, 0x00002100, 0x00001000, 0x0000ff00, 0x0000f300, 0x0000d200,
0x0000cd00, 0x00000c00, 0x00001300, 0x0000ec00, 0x00005f00, 0x00009700, 0x00004400, 0x00001700,
0x0000c400, 0x0000a700, 0x00007e00, 0x00003d00, 0x00006400, 0x00005d00, 0x00001900, 0x00007300,
0x00006000, 0x00008100, 0x00004f00, 0x0000dc00, 0x00002200, 0x00002a00, 0x00009000, 0x00008800,
0x00004600, 0x0000ee00, 0x0000b800, 0x00001400, 0x0000de00, 0x00005e00, 0x00000b00, 0x0000db00,
0x0000e000, 0x00003200, 0x00003a00, 0x00000a00, 0x00004900, 0x00000600, 0x00002400, 0x00005c00,
0x0000c200, 0x0000d300, 0x0000ac00, 0x00006200, 0x00009100, 0x00009500, 0x0000e400, 0x00007900,
0x0000e700, 0x0000c800, 0x00003700, 0x00006d00, 0x00008d00, 0x0000d500, 0x00004e00, 0x0000a900,
0x00006c00, 0x00005600, 0x0000f400, 0x0000ea00, 0x00006500, 0x00007a00, 0x0000ae00, 0x00000800,
0x0000ba00, 0x00007800, 0x00002500, 0x00002e00, 0x00001c00, 0x0000a600, 0x0000b400, 0x0000c600,
0x0000e800, 0x0000dd00, 0x00007400, 0x00001f00, 0x00004b00, 0x0000bd00, 0x00008b00, 0x00008a00,
0x00007000, 0x00003e00, 0x0000b500, 0x00006600, 0x00004800, 0x00000300, 0x0000f600, 0x00000e00,
0x00006100, 0x00003500, 0x00005700, 0x0000b900, 0x00008600, 0x0000c100, 0x00001d00, 0x00009e00,
0x0000e100, 0x0000f800, 0x00009800, 0x00001100, 0x00006900, 0x0000d900, 0x00008e00, 0x00009400,
0x00009b00, 0x00001e00, 0x00008700, 0x0000e900, 0x0000ce00, 0x00005500, 0x00002800, 0x0000df00,
0x00008c00, 0x0000a100, 0x00008900, 0x00000d00, 0x0000bf00, 0x0000e600, 0x00004200, 0x00006800,
0x00004100, 0x00009900, 0x00002d00, 0x00000f00, 0x0000b000, 0x00005400, 0x0000bb00, 0x00001600
};
__declspec(align(16)) const unsigned long Te4_2[256] = {
0x00630000, 0x007c0000, 0x00770000, 0x007b0000, 0x00f20000, 0x006b0000, 0x006f0000, 0x00c50000,
0x00300000, 0x00010000, 0x00670000, 0x002b0000, 0x00fe0000, 0x00d70000, 0x00ab0000, 0x00760000,
0x00ca0000, 0x00820000, 0x00c90000, 0x007d0000, 0x00fa0000, 0x00590000, 0x00470000, 0x00f00000,
0x00ad0000, 0x00d40000, 0x00a20000, 0x00af0000, 0x009c0000, 0x00a40000, 0x00720000, 0x00c00000,
0x00b70000, 0x00fd0000, 0x00930000, 0x00260000, 0x00360000, 0x003f0000, 0x00f70000, 0x00cc0000,
0x00340000, 0x00a50000, 0x00e50000, 0x00f10000, 0x00710000, 0x00d80000, 0x00310000, 0x00150000,
0x00040000, 0x00c70000, 0x00230000, 0x00c30000, 0x00180000, 0x00960000, 0x00050000, 0x009a0000,
0x00070000, 0x00120000, 0x00800000, 0x00e20000, 0x00eb0000, 0x00270000, 0x00b20000, 0x00750000,
0x00090000, 0x00830000, 0x002c0000, 0x001a0000, 0x001b0000, 0x006e0000, 0x005a0000, 0x00a00000,
0x00520000, 0x003b0000, 0x00d60000, 0x00b30000, 0x00290000, 0x00e30000, 0x002f0000, 0x00840000,
0x00530000, 0x00d10000, 0x00000000, 0x00ed0000, 0x00200000, 0x00fc0000, 0x00b10000, 0x005b0000,
0x006a0000, 0x00cb0000, 0x00be0000, 0x00390000, 0x004a0000, 0x004c0000, 0x00580000, 0x00cf0000,
0x00d00000, 0x00ef0000, 0x00aa0000, 0x00fb0000, 0x00430000, 0x004d0000, 0x00330000, 0x00850000,
0x00450000, 0x00f90000, 0x00020000, 0x007f0000, 0x00500000, 0x003c0000, 0x009f0000, 0x00a80000,
0x00510000, 0x00a30000, 0x00400000, 0x008f0000, 0x00920000, 0x009d0000, 0x00380000, 0x00f50000,
0x00bc0000, 0x00b60000, 0x00da0000, 0x00210000, 0x00100000, 0x00ff0000, 0x00f30000, 0x00d20000,
0x00cd0000, 0x000c0000, 0x00130000, 0x00ec0000, 0x005f0000, 0x00970000, 0x00440000, 0x00170000,
0x00c40000, 0x00a70000, 0x007e0000, 0x003d0000, 0x00640000, 0x005d0000, 0x00190000, 0x00730000,
0x00600000, 0x00810000, 0x004f0000, 0x00dc0000, 0x00220000, 0x002a0000, 0x00900000, 0x00880000,
0x00460000, 0x00ee0000, 0x00b80000, 0x00140000, 0x00de0000, 0x005e0000, 0x000b0000, 0x00db0000,
0x00e00000, 0x00320000, 0x003a0000, 0x000a0000, 0x00490000, 0x00060000, 0x00240000, 0x005c0000,
0x00c20000, 0x00d30000, 0x00ac0000, 0x00620000, 0x00910000, 0x00950000, 0x00e40000, 0x00790000,
0x00e70000, 0x00c80000, 0x00370000, 0x006d0000, 0x008d0000, 0x00d50000, 0x004e0000, 0x00a90000,
0x006c0000, 0x00560000, 0x00f40000, 0x00ea0000, 0x00650000, 0x007a0000, 0x00ae0000, 0x00080000,
0x00ba0000, 0x00780000, 0x00250000, 0x002e0000, 0x001c0000, 0x00a60000, 0x00b40000, 0x00c60000,
0x00e80000, 0x00dd0000, 0x00740000, 0x001f0000, 0x004b0000, 0x00bd0000, 0x008b0000, 0x008a0000,
0x00700000, 0x003e0000, 0x00b50000, 0x00660000, 0x00480000, 0x00030000, 0x00f60000, 0x000e0000,
0x00610000, 0x00350000, 0x00570000, 0x00b90000, 0x00860000, 0x00c10000, 0x001d0000, 0x009e0000,
0x00e10000, 0x00f80000, 0x00980000, 0x00110000, 0x00690000, 0x00d90000, 0x008e0000, 0x00940000,
0x009b0000, 0x001e0000, 0x00870000, 0x00e90000, 0x00ce0000, 0x00550000, 0x00280000, 0x00df0000,
0x008c0000, 0x00a10000, 0x00890000, 0x000d0000, 0x00bf0000, 0x00e60000, 0x00420000, 0x00680000,
0x00410000, 0x00990000, 0x002d0000, 0x000f0000, 0x00b00000, 0x00540000, 0x00bb0000, 0x00160000
};
__declspec(align(16)) const unsigned long Te4_3[256] = {
0x63000000, 0x7c000000, 0x77000000, 0x7b000000, 0xf2000000, 0x6b000000, 0x6f000000, 0xc5000000,
0x30000000, 0x01000000, 0x67000000, 0x2b000000, 0xfe000000, 0xd7000000, 0xab000000, 0x76000000,
0xca000000, 0x82000000, 0xc9000000, 0x7d000000, 0xfa000000, 0x59000000, 0x47000000, 0xf0000000,
0xad000000, 0xd4000000, 0xa2000000, 0xaf000000, 0x9c000000, 0xa4000000, 0x72000000, 0xc0000000,
0xb7000000, 0xfd000000, 0x93000000, 0x26000000, 0x36000000, 0x3f000000, 0xf7000000, 0xcc000000,
0x34000000, 0xa5000000, 0xe5000000, 0xf1000000, 0x71000000, 0xd8000000, 0x31000000, 0x15000000,
0x04000000, 0xc7000000, 0x23000000, 0xc3000000, 0x18000000, 0x96000000, 0x05000000, 0x9a000000,
0x07000000, 0x12000000, 0x80000000, 0xe2000000, 0xeb000000, 0x27000000, 0xb2000000, 0x75000000,
0x09000000, 0x83000000, 0x2c000000, 0x1a000000, 0x1b000000, 0x6e000000, 0x5a000000, 0xa0000000,
0x52000000, 0x3b000000, 0xd6000000, 0xb3000000, 0x29000000, 0xe3000000, 0x2f000000, 0x84000000,
0x53000000, 0xd1000000, 0x00000000, 0xed000000, 0x20000000, 0xfc000000, 0xb1000000, 0x5b000000,
0x6a000000, 0xcb000000, 0xbe000000, 0x39000000, 0x4a000000, 0x4c000000, 0x58000000, 0xcf000000,
0xd0000000, 0xef000000, 0xaa000000, 0xfb000000, 0x43000000, 0x4d000000, 0x33000000, 0x85000000,
0x45000000, 0xf9000000, 0x02000000, 0x7f000000, 0x50000000, 0x3c000000, 0x9f000000, 0xa8000000,
0x51000000, 0xa3000000, 0x40000000, 0x8f000000, 0x92000000, 0x9d000000, 0x38000000, 0xf5000000,
0xbc000000, 0xb6000000, 0xda000000, 0x21000000, 0x10000000, 0xff000000, 0xf3000000, 0xd2000000,
0xcd000000, 0x0c000000, 0x13000000, 0xec000000, 0x5f000000, 0x97000000, 0x44000000, 0x17000000,
0xc4000000, 0xa7000000, 0x7e000000, 0x3d000000, 0x64000000, 0x5d000000, 0x19000000, 0x73000000,
0x60000000, 0x81000000, 0x4f000000, 0xdc000000, 0x22000000, 0x2a000000, 0x90000000, 0x88000000,
0x46000000, 0xee000000, 0xb8000000, 0x14000000, 0xde000000, 0x5e000000, 0x0b000000, 0xdb000000,
0xe0000000, 0x32000000, 0x3a000000, 0x0a000000, 0x49000000, 0x06000000, 0x24000000, 0x5c000000,
0xc2000000, 0xd3000000, 0xac000000, 0x62000000, 0x91000000, 0x95000000, 0xe4000000, 0x79000000,
0xe7000000, 0xc8000000, 0x37000000, 0x6d000000, 0x8d000000, 0xd5000000, 0x4e000000, 0xa9000000,
0x6c000000, 0x56000000, 0xf4000000, 0xea000000, 0x65000000, 0x7a000000, 0xae000000, 0x08000000,
0xba000000, 0x78000000, 0x25000000, 0x2e000000, 0x1c000000, 0xa6000000, 0xb4000000, 0xc6000000,
0xe8000000, 0xdd000000, 0x74000000, 0x1f000000, 0x4b000000, 0xbd000000, 0x8b000000, 0x8a000000,
0x70000000, 0x3e000000, 0xb5000000, 0x66000000, 0x48000000, 0x03000000, 0xf6000000, 0x0e000000,
0x61000000, 0x35000000, 0x57000000, 0xb9000000, 0x86000000, 0xc1000000, 0x1d000000, 0x9e000000,
0xe1000000, 0xf8000000, 0x98000000, 0x11000000, 0x69000000, 0xd9000000, 0x8e000000, 0x94000000,
0x9b000000, 0x1e000000, 0x87000000, 0xe9000000, 0xce000000, 0x55000000, 0x28000000, 0xdf000000,
0x8c000000, 0xa1000000, 0x89000000, 0x0d000000, 0xbf000000, 0xe6000000, 0x42000000, 0x68000000,
0x41000000, 0x99000000, 0x2d000000, 0x0f000000, 0xb0000000, 0x54000000, 0xbb000000, 0x16000000
};
__declspec(align(16)) const unsigned long Td0[256] = {
0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a, 0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b,
0x55fa3020, 0xf66d76ad, 0x9176cc88, 0x254c02f5, 0xfcd7e54f, 0xd7cb2ac5, 0x80443526, 0x8fa362b5,
0x495ab1de, 0x671bba25, 0x980eea45, 0xe1c0fe5d, 0x02752fc3, 0x12f04c81, 0xa397468d, 0xc6f9d36b,
0xe75f8f03, 0x959c9215, 0xeb7a6dbf, 0xda595295, 0x2d83bed4, 0xd3217458, 0x2969e049, 0x44c8c98e,
0x6a89c275, 0x78798ef4, 0x6b3e5899, 0xdd71b927, 0xb64fe1be, 0x17ad88f0, 0x66ac20c9, 0xb43ace7d,
0x184adf63, 0x82311ae5, 0x60335197, 0x457f5362, 0xe07764b1, 0x84ae6bbb, 0x1ca081fe, 0x942b08f9,
0x58684870, 0x19fd458f, 0x876cde94, 0xb7f87b52, 0x23d373ab, 0xe2024b72, 0x578f1fe3, 0x2aab5566,
0x0728ebb2, 0x03c2b52f, 0x9a7bc586, 0xa50837d3, 0xf2872830, 0xb2a5bf23, 0xba6a0302, 0x5c8216ed,
0x2b1ccf8a, 0x92b479a7, 0xf0f207f3, 0xa1e2694e, 0xcdf4da65, 0xd5be0506, 0x1f6234d1, 0x8afea6c4,
0x9d532e34, 0xa055f3a2, 0x32e18a05, 0x75ebf6a4, 0x39ec830b, 0xaaef6040, 0x069f715e, 0x51106ebd,
0xf98a213e, 0x3d06dd96, 0xae053edd, 0x46bde64d, 0xb58d5491, 0x055dc471, 0x6fd40604, 0xff155060,
0x24fb9819, 0x97e9bdd6, 0xcc434089, 0x779ed967, 0xbd42e8b0, 0x888b8907, 0x385b19e7, 0xdbeec879,
0x470a7ca1, 0xe90f427c, 0xc91e84f8, 0x00000000, 0x83868009, 0x48ed2b32, 0xac70111e, 0x4e725a6c,
0xfbff0efd, 0x5638850f, 0x1ed5ae3d, 0x27392d36, 0x64d90f0a, 0x21a65c68, 0xd1545b9b, 0x3a2e3624,
0xb1670a0c, 0x0fe75793, 0xd296eeb4, 0x9e919b1b, 0x4fc5c080, 0xa220dc61, 0x694b775a, 0x161a121c,
0x0aba93e2, 0xe52aa0c0, 0x43e0223c, 0x1d171b12, 0x0b0d090e, 0xadc78bf2, 0xb9a8b62d, 0xc8a91e14,
0x8519f157, 0x4c0775af, 0xbbdd99ee, 0xfd607fa3, 0x9f2601f7, 0xbcf5725c, 0xc53b6644, 0x347efb5b,
0x7629438b, 0xdcc623cb, 0x68fcedb6, 0x63f1e4b8, 0xcadc31d7, 0x10856342, 0x40229713, 0x2011c684,
0x7d244a85, 0xf83dbbd2, 0x1132f9ae, 0x6da129c7, 0x4b2f9e1d, 0xf330b2dc, 0xec52860d, 0xd0e3c177,
0x6c16b32b, 0x99b970a9, 0xfa489411, 0x2264e947, 0xc48cfca8, 0x1a3ff0a0, 0xd82c7d56, 0xef903322,
0xc74e4987, 0xc1d138d9, 0xfea2ca8c, 0x360bd498, 0xcf81f5a6, 0x28de7aa5, 0x268eb7da, 0xa4bfad3f,
0xe49d3a2c, 0x0d927850, 0x9bcc5f6a, 0x62467e54, 0xc2138df6, 0xe8b8d890, 0x5ef7392e, 0xf5afc382,
0xbe805d9f, 0x7c93d069, 0xa92dd56f, 0xb31225cf, 0x3b99acc8, 0xa77d1810, 0x6e639ce8, 0x7bbb3bdb,
0x097826cd, 0xf418596e, 0x01b79aec, 0xa89a4f83, 0x656e95e6, 0x7ee6ffaa, 0x08cfbc21, 0xe6e815ef,
0xd99be7ba, 0xce366f4a, 0xd4099fea, 0xd67cb029, 0xafb2a431, 0x31233f2a, 0x3094a5c6, 0xc066a235,
0x37bc4e74, 0xa6ca82fc, 0xb0d090e0, 0x15d8a733, 0x4a9804f1, 0xf7daec41, 0x0e50cd7f, 0x2ff69117,
0x8dd64d76, 0x4db0ef43, 0x544daacc, 0xdf0496e4, 0xe3b5d19e, 0x1b886a4c, 0xb81f2cc1, 0x7f516546,
0x04ea5e9d, 0x5d358c01, 0x737487fa, 0x2e410bfb, 0x5a1d67b3, 0x52d2db92, 0x335610e9, 0x1347d66d,
0x8c61d79a, 0x7a0ca137, 0x8e14f859, 0x893c13eb, 0xee27a9ce, 0x35c961b7, 0xede51ce1, 0x3cb1477a,
0x59dfd29c, 0x3f73f255, 0x79ce1418, 0xbf37c773, 0xeacdf753, 0x5baafd5f, 0x146f3ddf, 0x86db4478,
0x81f3afca, 0x3ec468b9, 0x2c342438, 0x5f40a3c2, 0x72c31d16, 0x0c25e2bc, 0x8b493c28, 0x41950dff,
0x7101a839, 0xdeb30c08, 0x9ce4b4d8, 0x90c15664, 0x6184cb7b, 0x70b632d5, 0x745c6c48, 0x4257b8d0
};
__declspec(align(16)) const unsigned long Td1[256] = {
0xa7f45150, 0x65417e53, 0xa4171ac3, 0x5e273a96, 0x6bab3bcb, 0x459d1ff1, 0x58faacab, 0x03e34b93,
0xfa302055, 0x6d76adf6, 0x76cc8891, 0x4c02f525, 0xd7e54ffc, 0xcb2ac5d7, 0x44352680, 0xa362b58f,
0x5ab1de49, 0x1bba2567, 0x0eea4598, 0xc0fe5de1, 0x752fc302, 0xf04c8112, 0x97468da3, 0xf9d36bc6,
0x5f8f03e7, 0x9c921595, 0x7a6dbfeb, 0x595295da, 0x83bed42d, 0x217458d3, 0x69e04929, 0xc8c98e44,
0x89c2756a, 0x798ef478, 0x3e58996b, 0x71b927dd, 0x4fe1beb6, 0xad88f017, 0xac20c966, 0x3ace7db4,
0x4adf6318, 0x311ae582, 0x33519760, 0x7f536245, 0x7764b1e0, 0xae6bbb84, 0xa081fe1c, 0x2b08f994,
0x68487058, 0xfd458f19, 0x6cde9487, 0xf87b52b7, 0xd373ab23, 0x024b72e2, 0x8f1fe357, 0xab55662a,
0x28ebb207, 0xc2b52f03, 0x7bc5869a, 0x0837d3a5, 0x872830f2, 0xa5bf23b2, 0x6a0302ba, 0x8216ed5c,
0x1ccf8a2b, 0xb479a792, 0xf207f3f0, 0xe2694ea1, 0xf4da65cd, 0xbe0506d5, 0x6234d11f, 0xfea6c48a,
0x532e349d, 0x55f3a2a0, 0xe18a0532, 0xebf6a475, 0xec830b39, 0xef6040aa, 0x9f715e06, 0x106ebd51,
0x8a213ef9, 0x06dd963d, 0x053eddae, 0xbde64d46, 0x8d5491b5, 0x5dc47105, 0xd406046f, 0x155060ff,
0xfb981924, 0xe9bdd697, 0x434089cc, 0x9ed96777, 0x42e8b0bd, 0x8b890788, 0x5b19e738, 0xeec879db,
0x0a7ca147, 0x0f427ce9, 0x1e84f8c9, 0x00000000, 0x86800983, 0xed2b3248, 0x70111eac, 0x725a6c4e,
0xff0efdfb, 0x38850f56, 0xd5ae3d1e, 0x392d3627, 0xd90f0a64, 0xa65c6821, 0x545b9bd1, 0x2e36243a,
0x670a0cb1, 0xe757930f, 0x96eeb4d2, 0x919b1b9e, 0xc5c0804f, 0x20dc61a2, 0x4b775a69, 0x1a121c16,
0xba93e20a, 0x2aa0c0e5, 0xe0223c43, 0x171b121d, 0x0d090e0b, 0xc78bf2ad, 0xa8b62db9, 0xa91e14c8,
0x19f15785, 0x0775af4c, 0xdd99eebb, 0x607fa3fd, 0x2601f79f, 0xf5725cbc, 0x3b6644c5, 0x7efb5b34,
0x29438b76, 0xc623cbdc, 0xfcedb668, 0xf1e4b863, 0xdc31d7ca, 0x85634210, 0x22971340, 0x11c68420,
0x244a857d, 0x3dbbd2f8, 0x32f9ae11, 0xa129c76d, 0x2f9e1d4b, 0x30b2dcf3, 0x52860dec, 0xe3c177d0,
0x16b32b6c, 0xb970a999, 0x489411fa, 0x64e94722, 0x8cfca8c4, 0x3ff0a01a, 0x2c7d56d8, 0x903322ef,
0x4e4987c7, 0xd138d9c1, 0xa2ca8cfe, 0x0bd49836, 0x81f5a6cf, 0xde7aa528, 0x8eb7da26, 0xbfad3fa4,
0x9d3a2ce4, 0x9278500d, 0xcc5f6a9b, 0x467e5462, 0x138df6c2, 0xb8d890e8, 0xf7392e5e, 0xafc382f5,
0x805d9fbe, 0x93d0697c, 0x2dd56fa9, 0x1225cfb3, 0x99acc83b, 0x7d1810a7, 0x639ce86e, 0xbb3bdb7b,
0x7826cd09, 0x18596ef4, 0xb79aec01, 0x9a4f83a8, 0x6e95e665, 0xe6ffaa7e, 0xcfbc2108, 0xe815efe6,
0x9be7bad9, 0x366f4ace, 0x099fead4, 0x7cb029d6, 0xb2a431af, 0x233f2a31, 0x94a5c630, 0x66a235c0,
0xbc4e7437, 0xca82fca6, 0xd090e0b0, 0xd8a73315, 0x9804f14a, 0xdaec41f7, 0x50cd7f0e, 0xf691172f,
0xd64d768d, 0xb0ef434d, 0x4daacc54, 0x0496e4df, 0xb5d19ee3, 0x886a4c1b, 0x1f2cc1b8, 0x5165467f,
0xea5e9d04, 0x358c015d, 0x7487fa73, 0x410bfb2e, 0x1d67b35a, 0xd2db9252, 0x5610e933, 0x47d66d13,
0x61d79a8c, 0x0ca1377a, 0x14f8598e, 0x3c13eb89, 0x27a9ceee, 0xc961b735, 0xe51ce1ed, 0xb1477a3c,
0xdfd29c59, 0x73f2553f, 0xce141879, 0x37c773bf, 0xcdf753ea, 0xaafd5f5b, 0x6f3ddf14, 0xdb447886,
0xf3afca81, 0xc468b93e, 0x3424382c, 0x40a3c25f, 0xc31d1672, 0x25e2bc0c, 0x493c288b, 0x950dff41,
0x01a83971, 0xb30c08de, 0xe4b4d89c, 0xc1566490, 0x84cb7b61, 0xb632d570, 0x5c6c4874, 0x57b8d042
};
__declspec(align(16)) const unsigned long Td2[256] = {
0xf45150a7, 0x417e5365, 0x171ac3a4, 0x273a965e, 0xab3bcb6b, 0x9d1ff145, 0xfaacab58, 0xe34b9303,
0x302055fa, 0x76adf66d, 0xcc889176, 0x02f5254c, 0xe54ffcd7, 0x2ac5d7cb, 0x35268044, 0x62b58fa3,
0xb1de495a, 0xba25671b, 0xea45980e, 0xfe5de1c0, 0x2fc30275, 0x4c8112f0, 0x468da397, 0xd36bc6f9,
0x8f03e75f, 0x9215959c, 0x6dbfeb7a, 0x5295da59, 0xbed42d83, 0x7458d321, 0xe0492969, 0xc98e44c8,
0xc2756a89, 0x8ef47879, 0x58996b3e, 0xb927dd71, 0xe1beb64f, 0x88f017ad, 0x20c966ac, 0xce7db43a,
0xdf63184a, 0x1ae58231, 0x51976033, 0x5362457f, 0x64b1e077, 0x6bbb84ae, 0x81fe1ca0, 0x08f9942b,
0x48705868, 0x458f19fd, 0xde94876c, 0x7b52b7f8, 0x73ab23d3, 0x4b72e202, 0x1fe3578f, 0x55662aab,
0xebb20728, 0xb52f03c2, 0xc5869a7b, 0x37d3a508, 0x2830f287, 0xbf23b2a5, 0x0302ba6a, 0x16ed5c82,
0xcf8a2b1c, 0x79a792b4, 0x07f3f0f2, 0x694ea1e2, 0xda65cdf4, 0x0506d5be, 0x34d11f62, 0xa6c48afe,
0x2e349d53, 0xf3a2a055, 0x8a0532e1, 0xf6a475eb, 0x830b39ec, 0x6040aaef, 0x715e069f, 0x6ebd5110,
0x213ef98a, 0xdd963d06, 0x3eddae05, 0xe64d46bd, 0x5491b58d, 0xc471055d, 0x06046fd4, 0x5060ff15,
0x981924fb, 0xbdd697e9, 0x4089cc43, 0xd967779e, 0xe8b0bd42, 0x8907888b, 0x19e7385b, 0xc879dbee,
0x7ca1470a, 0x427ce90f, 0x84f8c91e, 0x00000000, 0x80098386, 0x2b3248ed, 0x111eac70, 0x5a6c4e72,
0x0efdfbff, 0x850f5638, 0xae3d1ed5, 0x2d362739, 0x0f0a64d9, 0x5c6821a6, 0x5b9bd154, 0x36243a2e,
0x0a0cb167, 0x57930fe7, 0xeeb4d296, 0x9b1b9e91, 0xc0804fc5, 0xdc61a220, 0x775a694b, 0x121c161a,
0x93e20aba, 0xa0c0e52a, 0x223c43e0, 0x1b121d17, 0x090e0b0d, 0x8bf2adc7, 0xb62db9a8, 0x1e14c8a9,
0xf1578519, 0x75af4c07, 0x99eebbdd, 0x7fa3fd60, 0x01f79f26, 0x725cbcf5, 0x6644c53b, 0xfb5b347e,
0x438b7629, 0x23cbdcc6, 0xedb668fc, 0xe4b863f1, 0x31d7cadc, 0x63421085, 0x97134022, 0xc6842011,
0x4a857d24, 0xbbd2f83d, 0xf9ae1132, 0x29c76da1, 0x9e1d4b2f, 0xb2dcf330, 0x860dec52, 0xc177d0e3,
0xb32b6c16, 0x70a999b9, 0x9411fa48, 0xe9472264, 0xfca8c48c, 0xf0a01a3f, 0x7d56d82c, 0x3322ef90,
0x4987c74e, 0x38d9c1d1, 0xca8cfea2, 0xd498360b, 0xf5a6cf81, 0x7aa528de, 0xb7da268e, 0xad3fa4bf,
0x3a2ce49d, 0x78500d92, 0x5f6a9bcc, 0x7e546246, 0x8df6c213, 0xd890e8b8, 0x392e5ef7, 0xc382f5af,
0x5d9fbe80, 0xd0697c93, 0xd56fa92d, 0x25cfb312, 0xacc83b99, 0x1810a77d, 0x9ce86e63, 0x3bdb7bbb,
0x26cd0978, 0x596ef418, 0x9aec01b7, 0x4f83a89a, 0x95e6656e, 0xffaa7ee6, 0xbc2108cf, 0x15efe6e8,
0xe7bad99b, 0x6f4ace36, 0x9fead409, 0xb029d67c, 0xa431afb2, 0x3f2a3123, 0xa5c63094, 0xa235c066,
0x4e7437bc, 0x82fca6ca, 0x90e0b0d0, 0xa73315d8, 0x04f14a98, 0xec41f7da, 0xcd7f0e50, 0x91172ff6,
0x4d768dd6, 0xef434db0, 0xaacc544d, 0x96e4df04, 0xd19ee3b5, 0x6a4c1b88, 0x2cc1b81f, 0x65467f51,
0x5e9d04ea, 0x8c015d35, 0x87fa7374, 0x0bfb2e41, 0x67b35a1d, 0xdb9252d2, 0x10e93356, 0xd66d1347,
0xd79a8c61, 0xa1377a0c, 0xf8598e14, 0x13eb893c, 0xa9ceee27, 0x61b735c9, 0x1ce1ede5, 0x477a3cb1,
0xd29c59df, 0xf2553f73, 0x141879ce, 0xc773bf37, 0xf753eacd, 0xfd5f5baa, 0x3ddf146f, 0x447886db,
0xafca81f3, 0x68b93ec4, 0x24382c34, 0xa3c25f40, 0x1d1672c3, 0xe2bc0c25, 0x3c288b49, 0x0dff4195,
0xa8397101, 0x0c08deb3, 0xb4d89ce4, 0x566490c1, 0xcb7b6184, 0x32d570b6, 0x6c48745c, 0xb8d04257
};
__declspec(align(16)) const unsigned long Td3[256] = {
0x5150a7f4, 0x7e536541, 0x1ac3a417, 0x3a965e27, 0x3bcb6bab, 0x1ff1459d, 0xacab58fa, 0x4b9303e3,
0x2055fa30, 0xadf66d76, 0x889176cc, 0xf5254c02, 0x4ffcd7e5, 0xc5d7cb2a, 0x26804435, 0xb58fa362,
0xde495ab1, 0x25671bba, 0x45980eea, 0x5de1c0fe, 0xc302752f, 0x8112f04c, 0x8da39746, 0x6bc6f9d3,
0x03e75f8f, 0x15959c92, 0xbfeb7a6d, 0x95da5952, 0xd42d83be, 0x58d32174, 0x492969e0, 0x8e44c8c9,
0x756a89c2, 0xf478798e, 0x996b3e58, 0x27dd71b9, 0xbeb64fe1, 0xf017ad88, 0xc966ac20, 0x7db43ace,
0x63184adf, 0xe582311a, 0x97603351, 0x62457f53, 0xb1e07764, 0xbb84ae6b, 0xfe1ca081, 0xf9942b08,
0x70586848, 0x8f19fd45, 0x94876cde, 0x52b7f87b, 0xab23d373, 0x72e2024b, 0xe3578f1f, 0x662aab55,
0xb20728eb, 0x2f03c2b5, 0x869a7bc5, 0xd3a50837, 0x30f28728, 0x23b2a5bf, 0x02ba6a03, 0xed5c8216,
0x8a2b1ccf, 0xa792b479, 0xf3f0f207, 0x4ea1e269, 0x65cdf4da, 0x06d5be05, 0xd11f6234, 0xc48afea6,
0x349d532e, 0xa2a055f3, 0x0532e18a, 0xa475ebf6, 0x0b39ec83, 0x40aaef60, 0x5e069f71, 0xbd51106e,
0x3ef98a21, 0x963d06dd, 0xddae053e, 0x4d46bde6, 0x91b58d54, 0x71055dc4, 0x046fd406, 0x60ff1550,
0x1924fb98, 0xd697e9bd, 0x89cc4340, 0x67779ed9, 0xb0bd42e8, 0x07888b89, 0xe7385b19, 0x79dbeec8,
0xa1470a7c, 0x7ce90f42, 0xf8c91e84, 0x00000000, 0x09838680, 0x3248ed2b, 0x1eac7011, 0x6c4e725a,
0xfdfbff0e, 0x0f563885, 0x3d1ed5ae, 0x3627392d, 0x0a64d90f, 0x6821a65c, 0x9bd1545b, 0x243a2e36,
0x0cb1670a, 0x930fe757, 0xb4d296ee, 0x1b9e919b, 0x804fc5c0, 0x61a220dc, 0x5a694b77, 0x1c161a12,
0xe20aba93, 0xc0e52aa0, 0x3c43e022, 0x121d171b, 0x0e0b0d09, 0xf2adc78b, 0x2db9a8b6, 0x14c8a91e,
0x578519f1, 0xaf4c0775, 0xeebbdd99, 0xa3fd607f, 0xf79f2601, 0x5cbcf572, 0x44c53b66, 0x5b347efb,
0x8b762943, 0xcbdcc623, 0xb668fced, 0xb863f1e4, 0xd7cadc31, 0x42108563, 0x13402297, 0x842011c6,
0x857d244a, 0xd2f83dbb, 0xae1132f9, 0xc76da129, 0x1d4b2f9e, 0xdcf330b2, 0x0dec5286, 0x77d0e3c1,
0x2b6c16b3, 0xa999b970, 0x11fa4894, 0x472264e9, 0xa8c48cfc, 0xa01a3ff0, 0x56d82c7d, 0x22ef9033,
0x87c74e49, 0xd9c1d138, 0x8cfea2ca, 0x98360bd4, 0xa6cf81f5, 0xa528de7a, 0xda268eb7, 0x3fa4bfad,
0x2ce49d3a, 0x500d9278, 0x6a9bcc5f, 0x5462467e, 0xf6c2138d, 0x90e8b8d8, 0x2e5ef739, 0x82f5afc3,
0x9fbe805d, 0x697c93d0, 0x6fa92dd5, 0xcfb31225, 0xc83b99ac, 0x10a77d18, 0xe86e639c, 0xdb7bbb3b,
0xcd097826, 0x6ef41859, 0xec01b79a, 0x83a89a4f, 0xe6656e95, 0xaa7ee6ff, 0x2108cfbc, 0xefe6e815,
0xbad99be7, 0x4ace366f, 0xead4099f, 0x29d67cb0, 0x31afb2a4, 0x2a31233f, 0xc63094a5, 0x35c066a2,
0x7437bc4e, 0xfca6ca82, 0xe0b0d090, 0x3315d8a7, 0xf14a9804, 0x41f7daec, 0x7f0e50cd, 0x172ff691,
0x768dd64d, 0x434db0ef, 0xcc544daa, 0xe4df0496, 0x9ee3b5d1, 0x4c1b886a, 0xc1b81f2c, 0x467f5165,
0x9d04ea5e, 0x015d358c, 0xfa737487, 0xfb2e410b, 0xb35a1d67, 0x9252d2db, 0xe9335610, 0x6d1347d6,
0x9a8c61d7, 0x377a0ca1, 0x598e14f8, 0xeb893c13, 0xceee27a9, 0xb735c961, 0xe1ede51c, 0x7a3cb147,
0x9c59dfd2, 0x553f73f2, 0x1879ce14, 0x73bf37c7, 0x53eacdf7, 0x5f5baafd, 0xdf146f3d, 0x7886db44,
0xca81f3af, 0xb93ec468, 0x382c3424, 0xc25f40a3, 0x1672c31d, 0xbc0c25e2, 0x288b493c, 0xff41950d,
0x397101a8, 0x08deb30c, 0xd89ce4b4, 0x6490c156, 0x7b6184cb, 0xd570b632, 0x48745c6c, 0xd04257b8
};
__declspec(align(16)) const unsigned long Td4_0[256] = {
0x00000052, 0x00000009, 0x0000006a, 0x000000d5, 0x00000030, 0x00000036, 0x000000a5, 0x00000038,
0x000000bf, 0x00000040, 0x000000a3, 0x0000009e, 0x00000081, 0x000000f3, 0x000000d7, 0x000000fb,
0x0000007c, 0x000000e3, 0x00000039, 0x00000082, 0x0000009b, 0x0000002f, 0x000000ff, 0x00000087,
0x00000034, 0x0000008e, 0x00000043, 0x00000044, 0x000000c4, 0x000000de, 0x000000e9, 0x000000cb,
0x00000054, 0x0000007b, 0x00000094, 0x00000032, 0x000000a6, 0x000000c2, 0x00000023, 0x0000003d,
0x000000ee, 0x0000004c, 0x00000095, 0x0000000b, 0x00000042, 0x000000fa, 0x000000c3, 0x0000004e,
0x00000008, 0x0000002e, 0x000000a1, 0x00000066, 0x00000028, 0x000000d9, 0x00000024, 0x000000b2,
0x00000076, 0x0000005b, 0x000000a2, 0x00000049, 0x0000006d, 0x0000008b, 0x000000d1, 0x00000025,
0x00000072, 0x000000f8, 0x000000f6, 0x00000064, 0x00000086, 0x00000068, 0x00000098, 0x00000016,
0x000000d4, 0x000000a4, 0x0000005c, 0x000000cc, 0x0000005d, 0x00000065, 0x000000b6, 0x00000092,
0x0000006c, 0x00000070, 0x00000048, 0x00000050, 0x000000fd, 0x000000ed, 0x000000b9, 0x000000da,
0x0000005e, 0x00000015, 0x00000046, 0x00000057, 0x000000a7, 0x0000008d, 0x0000009d, 0x00000084,
0x00000090, 0x000000d8, 0x000000ab, 0x00000000, 0x0000008c, 0x000000bc, 0x000000d3, 0x0000000a,
0x000000f7, 0x000000e4, 0x00000058, 0x00000005, 0x000000b8, 0x000000b3, 0x00000045, 0x00000006,
0x000000d0, 0x0000002c, 0x0000001e, 0x0000008f, 0x000000ca, 0x0000003f, 0x0000000f, 0x00000002,
0x000000c1, 0x000000af, 0x000000bd, 0x00000003, 0x00000001, 0x00000013, 0x0000008a, 0x0000006b,
0x0000003a, 0x00000091, 0x00000011, 0x00000041, 0x0000004f, 0x00000067, 0x000000dc, 0x000000ea,
0x00000097, 0x000000f2, 0x000000cf, 0x000000ce, 0x000000f0, 0x000000b4, 0x000000e6, 0x00000073,
0x00000096, 0x000000ac, 0x00000074, 0x00000022, 0x000000e7, 0x000000ad, 0x00000035, 0x00000085,
0x000000e2, 0x000000f9, 0x00000037, 0x000000e8, 0x0000001c, 0x00000075, 0x000000df, 0x0000006e,
0x00000047, 0x000000f1, 0x0000001a, 0x00000071, 0x0000001d, 0x00000029, 0x000000c5, 0x00000089,
0x0000006f, 0x000000b7, 0x00000062, 0x0000000e, 0x000000aa, 0x00000018, 0x000000be, 0x0000001b,
0x000000fc, 0x00000056, 0x0000003e, 0x0000004b, 0x000000c6, 0x000000d2, 0x00000079, 0x00000020,
0x0000009a, 0x000000db, 0x000000c0, 0x000000fe, 0x00000078, 0x000000cd, 0x0000005a, 0x000000f4,
0x0000001f, 0x000000dd, 0x000000a8, 0x00000033, 0x00000088, 0x00000007, 0x000000c7, 0x00000031,
0x000000b1, 0x00000012, 0x00000010, 0x00000059, 0x00000027, 0x00000080, 0x000000ec, 0x0000005f,
0x00000060, 0x00000051, 0x0000007f, 0x000000a9, 0x00000019, 0x000000b5, 0x0000004a, 0x0000000d,
0x0000002d, 0x000000e5, 0x0000007a, 0x0000009f, 0x00000093, 0x000000c9, 0x0000009c, 0x000000ef,
0x000000a0, 0x000000e0, 0x0000003b, 0x0000004d, 0x000000ae, 0x0000002a, 0x000000f5, 0x000000b0,
0x000000c8, 0x000000eb, 0x000000bb, 0x0000003c, 0x00000083, 0x00000053, 0x00000099, 0x00000061,
0x00000017, 0x0000002b, 0x00000004, 0x0000007e, 0x000000ba, 0x00000077, 0x000000d6, 0x00000026,
0x000000e1, 0x00000069, 0x00000014, 0x00000063, 0x00000055, 0x00000021, 0x0000000c, 0x0000007d
};
__declspec(align(16)) const unsigned long Td4_1[256] = {
0x00005200, 0x00000900, 0x00006a00, 0x0000d500, 0x00003000, 0x00003600, 0x0000a500, 0x00003800,
0x0000bf00, 0x00004000, 0x0000a300, 0x00009e00, 0x00008100, 0x0000f300, 0x0000d700, 0x0000fb00,
0x00007c00, 0x0000e300, 0x00003900, 0x00008200, 0x00009b00, 0x00002f00, 0x0000ff00, 0x00008700,
0x00003400, 0x00008e00, 0x00004300, 0x00004400, 0x0000c400, 0x0000de00, 0x0000e900, 0x0000cb00,
0x00005400, 0x00007b00, 0x00009400, 0x00003200, 0x0000a600, 0x0000c200, 0x00002300, 0x00003d00,
0x0000ee00, 0x00004c00, 0x00009500, 0x00000b00, 0x00004200, 0x0000fa00, 0x0000c300, 0x00004e00,
0x00000800, 0x00002e00, 0x0000a100, 0x00006600, 0x00002800, 0x0000d900, 0x00002400, 0x0000b200,
0x00007600, 0x00005b00, 0x0000a200, 0x00004900, 0x00006d00, 0x00008b00, 0x0000d100, 0x00002500,
0x00007200, 0x0000f800, 0x0000f600, 0x00006400, 0x00008600, 0x00006800, 0x00009800, 0x00001600,
0x0000d400, 0x0000a400, 0x00005c00, 0x0000cc00, 0x00005d00, 0x00006500, 0x0000b600, 0x00009200,
0x00006c00, 0x00007000, 0x00004800, 0x00005000, 0x0000fd00, 0x0000ed00, 0x0000b900, 0x0000da00,
0x00005e00, 0x00001500, 0x00004600, 0x00005700, 0x0000a700, 0x00008d00, 0x00009d00, 0x00008400,
0x00009000, 0x0000d800, 0x0000ab00, 0x00000000, 0x00008c00, 0x0000bc00, 0x0000d300, 0x00000a00,
0x0000f700, 0x0000e400, 0x00005800, 0x00000500, 0x0000b800, 0x0000b300, 0x00004500, 0x00000600,
0x0000d000, 0x00002c00, 0x00001e00, 0x00008f00, 0x0000ca00, 0x00003f00, 0x00000f00, 0x00000200,
0x0000c100, 0x0000af00, 0x0000bd00, 0x00000300, 0x00000100, 0x00001300, 0x00008a00, 0x00006b00,
0x00003a00, 0x00009100, 0x00001100, 0x00004100, 0x00004f00, 0x00006700, 0x0000dc00, 0x0000ea00,
0x00009700, 0x0000f200, 0x0000cf00, 0x0000ce00, 0x0000f000, 0x0000b400, 0x0000e600, 0x00007300,
0x00009600, 0x0000ac00, 0x00007400, 0x00002200, 0x0000e700, 0x0000ad00, 0x00003500, 0x00008500,
0x0000e200, 0x0000f900, 0x00003700, 0x0000e800, 0x00001c00, 0x00007500, 0x0000df00, 0x00006e00,
0x00004700, 0x0000f100, 0x00001a00, 0x00007100, 0x00001d00, 0x00002900, 0x0000c500, 0x00008900,
0x00006f00, 0x0000b700, 0x00006200, 0x00000e00, 0x0000aa00, 0x00001800, 0x0000be00, 0x00001b00,
0x0000fc00, 0x00005600, 0x00003e00, 0x00004b00, 0x0000c600, 0x0000d200, 0x00007900, 0x00002000,
0x00009a00, 0x0000db00, 0x0000c000, 0x0000fe00, 0x00007800, 0x0000cd00, 0x00005a00, 0x0000f400,
0x00001f00, 0x0000dd00, 0x0000a800, 0x00003300, 0x00008800, 0x00000700, 0x0000c700, 0x00003100,
0x0000b100, 0x00001200, 0x00001000, 0x00005900, 0x00002700, 0x00008000, 0x0000ec00, 0x00005f00,
0x00006000, 0x00005100, 0x00007f00, 0x0000a900, 0x00001900, 0x0000b500, 0x00004a00, 0x00000d00,
0x00002d00, 0x0000e500, 0x00007a00, 0x00009f00, 0x00009300, 0x0000c900, 0x00009c00, 0x0000ef00,
0x0000a000, 0x0000e000, 0x00003b00, 0x00004d00, 0x0000ae00, 0x00002a00, 0x0000f500, 0x0000b000,
0x0000c800, 0x0000eb00, 0x0000bb00, 0x00003c00, 0x00008300, 0x00005300, 0x00009900, 0x00006100,
0x00001700, 0x00002b00, 0x00000400, 0x00007e00, 0x0000ba00, 0x00007700, 0x0000d600, 0x00002600,
0x0000e100, 0x00006900, 0x00001400, 0x00006300, 0x00005500, 0x00002100, 0x00000c00, 0x00007d00
};
__declspec(align(16)) const unsigned long Td4_2[256] = {
0x00520000, 0x00090000, 0x006a0000, 0x00d50000, 0x00300000, 0x00360000, 0x00a50000, 0x00380000,
0x00bf0000, 0x00400000, 0x00a30000, 0x009e0000, 0x00810000, 0x00f30000, 0x00d70000, 0x00fb0000,
0x007c0000, 0x00e30000, 0x00390000, 0x00820000, 0x009b0000, 0x002f0000, 0x00ff0000, 0x00870000,
0x00340000, 0x008e0000, 0x00430000, 0x00440000, 0x00c40000, 0x00de0000, 0x00e90000, 0x00cb0000,
0x00540000, 0x007b0000, 0x00940000, 0x00320000, 0x00a60000, 0x00c20000, 0x00230000, 0x003d0000,
0x00ee0000, 0x004c0000, 0x00950000, 0x000b0000, 0x00420000, 0x00fa0000, 0x00c30000, 0x004e0000,
0x00080000, 0x002e0000, 0x00a10000, 0x00660000, 0x00280000, 0x00d90000, 0x00240000, 0x00b20000,
0x00760000, 0x005b0000, 0x00a20000, 0x00490000, 0x006d0000, 0x008b0000, 0x00d10000, 0x00250000,
0x00720000, 0x00f80000, 0x00f60000, 0x00640000, 0x00860000, 0x00680000, 0x00980000, 0x00160000,
0x00d40000, 0x00a40000, 0x005c0000, 0x00cc0000, 0x005d0000, 0x00650000, 0x00b60000, 0x00920000,
0x006c0000, 0x00700000, 0x00480000, 0x00500000, 0x00fd0000, 0x00ed0000, 0x00b90000, 0x00da0000,
0x005e0000, 0x00150000, 0x00460000, 0x00570000, 0x00a70000, 0x008d0000, 0x009d0000, 0x00840000,
0x00900000, 0x00d80000, 0x00ab0000, 0x00000000, 0x008c0000, 0x00bc0000, 0x00d30000, 0x000a0000,
0x00f70000, 0x00e40000, 0x00580000, 0x00050000, 0x00b80000, 0x00b30000, 0x00450000, 0x00060000,
0x00d00000, 0x002c0000, 0x001e0000, 0x008f0000, 0x00ca0000, 0x003f0000, 0x000f0000, 0x00020000,
0x00c10000, 0x00af0000, 0x00bd0000, 0x00030000, 0x00010000, 0x00130000, 0x008a0000, 0x006b0000,
0x003a0000, 0x00910000, 0x00110000, 0x00410000, 0x004f0000, 0x00670000, 0x00dc0000, 0x00ea0000,
0x00970000, 0x00f20000, 0x00cf0000, 0x00ce0000, 0x00f00000, 0x00b40000, 0x00e60000, 0x00730000,
0x00960000, 0x00ac0000, 0x00740000, 0x00220000, 0x00e70000, 0x00ad0000, 0x00350000, 0x00850000,
0x00e20000, 0x00f90000, 0x00370000, 0x00e80000, 0x001c0000, 0x00750000, 0x00df0000, 0x006e0000,
0x00470000, 0x00f10000, 0x001a0000, 0x00710000, 0x001d0000, 0x00290000, 0x00c50000, 0x00890000,
0x006f0000, 0x00b70000, 0x00620000, 0x000e0000, 0x00aa0000, 0x00180000, 0x00be0000, 0x001b0000,
0x00fc0000, 0x00560000, 0x003e0000, 0x004b0000, 0x00c60000, 0x00d20000, 0x00790000, 0x00200000,
0x009a0000, 0x00db0000, 0x00c00000, 0x00fe0000, 0x00780000, 0x00cd0000, 0x005a0000, 0x00f40000,
0x001f0000, 0x00dd0000, 0x00a80000, 0x00330000, 0x00880000, 0x00070000, 0x00c70000, 0x00310000,
0x00b10000, 0x00120000, 0x00100000, 0x00590000, 0x00270000, 0x00800000, 0x00ec0000, 0x005f0000,
0x00600000, 0x00510000, 0x007f0000, 0x00a90000, 0x00190000, 0x00b50000, 0x004a0000, 0x000d0000,
0x002d0000, 0x00e50000, 0x007a0000, 0x009f0000, 0x00930000, 0x00c90000, 0x009c0000, 0x00ef0000,
0x00a00000, 0x00e00000, 0x003b0000, 0x004d0000, 0x00ae0000, 0x002a0000, 0x00f50000, 0x00b00000,
0x00c80000, 0x00eb0000, 0x00bb0000, 0x003c0000, 0x00830000, 0x00530000, 0x00990000, 0x00610000,
0x00170000, 0x002b0000, 0x00040000, 0x007e0000, 0x00ba0000, 0x00770000, 0x00d60000, 0x00260000,
0x00e10000, 0x00690000, 0x00140000, 0x00630000, 0x00550000, 0x00210000, 0x000c0000, 0x007d0000
};
__declspec(align(16)) const unsigned long Td4_3[256] = {
0x52000000, 0x09000000, 0x6a000000, 0xd5000000, 0x30000000, 0x36000000, 0xa5000000, 0x38000000,
0xbf000000, 0x40000000, 0xa3000000, 0x9e000000, 0x81000000, 0xf3000000, 0xd7000000, 0xfb000000,
0x7c000000, 0xe3000000, 0x39000000, 0x82000000, 0x9b000000, 0x2f000000, 0xff000000, 0x87000000,
0x34000000, 0x8e000000, 0x43000000, 0x44000000, 0xc4000000, 0xde000000, 0xe9000000, 0xcb000000,
0x54000000, 0x7b000000, 0x94000000, 0x32000000, 0xa6000000, 0xc2000000, 0x23000000, 0x3d000000,
0xee000000, 0x4c000000, 0x95000000, 0x0b000000, 0x42000000, 0xfa000000, 0xc3000000, 0x4e000000,
0x08000000, 0x2e000000, 0xa1000000, 0x66000000, 0x28000000, 0xd9000000, 0x24000000, 0xb2000000,
0x76000000, 0x5b000000, 0xa2000000, 0x49000000, 0x6d000000, 0x8b000000, 0xd1000000, 0x25000000,
0x72000000, 0xf8000000, 0xf6000000, 0x64000000, 0x86000000, 0x68000000, 0x98000000, 0x16000000,
0xd4000000, 0xa4000000, 0x5c000000, 0xcc000000, 0x5d000000, 0x65000000, 0xb6000000, 0x92000000,
0x6c000000, 0x70000000, 0x48000000, 0x50000000, 0xfd000000, 0xed000000, 0xb9000000, 0xda000000,
0x5e000000, 0x15000000, 0x46000000, 0x57000000, 0xa7000000, 0x8d000000, 0x9d000000, 0x84000000,
0x90000000, 0xd8000000, 0xab000000, 0x00000000, 0x8c000000, 0xbc000000, 0xd3000000, 0x0a000000,
0xf7000000, 0xe4000000, 0x58000000, 0x05000000, 0xb8000000, 0xb3000000, 0x45000000, 0x06000000,
0xd0000000, 0x2c000000, 0x1e000000, 0x8f000000, 0xca000000, 0x3f000000, 0x0f000000, 0x02000000,
0xc1000000, 0xaf000000, 0xbd000000, 0x03000000, 0x01000000, 0x13000000, 0x8a000000, 0x6b000000,
0x3a000000, 0x91000000, 0x11000000, 0x41000000, 0x4f000000, 0x67000000, 0xdc000000, 0xea000000,
0x97000000, 0xf2000000, 0xcf000000, 0xce000000, 0xf0000000, 0xb4000000, 0xe6000000, 0x73000000,
0x96000000, 0xac000000, 0x74000000, 0x22000000, 0xe7000000, 0xad000000, 0x35000000, 0x85000000,
0xe2000000, 0xf9000000, 0x37000000, 0xe8000000, 0x1c000000, 0x75000000, 0xdf000000, 0x6e000000,
0x47000000, 0xf1000000, 0x1a000000, 0x71000000, 0x1d000000, 0x29000000, 0xc5000000, 0x89000000,
0x6f000000, 0xb7000000, 0x62000000, 0x0e000000, 0xaa000000, 0x18000000, 0xbe000000, 0x1b000000,
0xfc000000, 0x56000000, 0x3e000000, 0x4b000000, 0xc6000000, 0xd2000000, 0x79000000, 0x20000000,
0x9a000000, 0xdb000000, 0xc0000000, 0xfe000000, 0x78000000, 0xcd000000, 0x5a000000, 0xf4000000,
0x1f000000, 0xdd000000, 0xa8000000, 0x33000000, 0x88000000, 0x07000000, 0xc7000000, 0x31000000,
0xb1000000, 0x12000000, 0x10000000, 0x59000000, 0x27000000, 0x80000000, 0xec000000, 0x5f000000,
0x60000000, 0x51000000, 0x7f000000, 0xa9000000, 0x19000000, 0xb5000000, 0x4a000000, 0x0d000000,
0x2d000000, 0xe5000000, 0x7a000000, 0x9f000000, 0x93000000, 0xc9000000, 0x9c000000, 0xef000000,
0xa0000000, 0xe0000000, 0x3b000000, 0x4d000000, 0xae000000, 0x2a000000, 0xf5000000, 0xb0000000,
0xc8000000, 0xeb000000, 0xbb000000, 0x3c000000, 0x83000000, 0x53000000, 0x99000000, 0x61000000,
0x17000000, 0x2b000000, 0x04000000, 0x7e000000, 0xba000000, 0x77000000, 0xd6000000, 0x26000000,
0xe1000000, 0x69000000, 0x14000000, 0x63000000, 0x55000000, 0x21000000, 0x0c000000, 0x7d000000,
};
static unsigned long key_mix(unsigned long t)
{
return Te4_0[(unsigned char)(t >> 8)] ^ Te4_1[(unsigned char)(t >> 16)] ^
Te4_2[(unsigned char)(t >> 24)] ^ Te4_3[(unsigned char)(t >> 0)];
}
static unsigned long key_mix2(unsigned long t)
{
return Td0[Te4_0[(unsigned char)(t >> 0)]] ^ Td1[Te4_0[(unsigned char)(t >> 8)]] ^
Td2[Te4_0[(unsigned char)(t >> 16)]] ^ Td3[Te4_0[(unsigned char)(t >> 24)]];
}
void _stdcall aes256_set_key(const unsigned char *key, aes256_key *skey)
{
unsigned long *ek, *dk;
int j, i;
unsigned long t, rcon;
ek = skey->enc_key;
i = 7; rcon = 1;
memcpy(ek, key, AES_KEY_SIZE);
do
{
ek[ 8] = ek[0] ^ key_mix(ek[7]) ^ rcon;
ek[ 9] = ek[1] ^ ek[ 8];
ek[10] = ek[2] ^ ek[ 9];
ek[11] = ek[3] ^ ek[10];
if (--i == 0) {
break;
};
ek[12] = ek[4] ^ key_mix(_rotr(ek[11], 24));
ek[13] = ek[5] ^ ek[12];
ek[14] = ek[6] ^ ek[13];
ek[15] = ek[7] ^ ek[14];
ek += 8; rcon <<= 1;
} while (1);
ek = skey->enc_key;
dk = skey->dec_key;
for (i = 0, j = 4*ROUNDS; i <= j; i += 4, j -= 4) {
t = ek[i ]; dk[i ] = ek[j ]; dk[j ] = t;
t = ek[i + 1]; dk[i + 1] = ek[j + 1]; dk[j + 1] = t;
t = ek[i + 2]; dk[i + 2] = ek[j + 2]; dk[j + 2] = t;
t = ek[i + 3]; dk[i + 3] = ek[j + 3]; dk[j + 3] = t;
}
i = (ROUNDS-1) * 4;
do {
dk[4] = key_mix2(dk[4]); dk++;
} while (--i);
}

View File

@ -0,0 +1,19 @@
#ifndef _AES_KEY_H_
#define _AES_KEY_H_
#define ROUNDS 14
#define AES_KEY_SIZE 32
#define AES_BLOCK_SIZE 16
typedef __declspec(align(16)) struct _aes256_key {
__declspec(align(16)) unsigned long enc_key[4 *(ROUNDS + 1)];
__declspec(align(16)) unsigned long dec_key[4 *(ROUNDS + 1)];
#ifdef _M_IX86
__declspec(align(16)) unsigned char ek_code[3072];
__declspec(align(16)) unsigned char dk_code[3072];
#endif
} aes256_key;
void _stdcall aes256_set_key(const unsigned char *key, aes256_key *skey);
#endif

View File

@ -0,0 +1,21 @@
#ifndef _AES_PADLOCK_H_
#define _AES_PADLOCK_H_
#include "aes_key.h"
#ifdef _M_IX86
static void __forceinline aes256_padlock_rekey() {
__asm {
pushfd
popfd
}
}
#else
#define aes256_padlock_rekey() __writeeflags(__readeflags())
#endif
int _stdcall aes256_padlock_available();
void _stdcall aes256_padlock_encrypt(const unsigned char *in, unsigned char *out, int n_blocks, aes256_key *key);
void _stdcall aes256_padlock_decrypt(const unsigned char *in, unsigned char *out, int n_blocks, aes256_key *key);
#endif

View File

@ -0,0 +1,886 @@
; ---------------------------------------------------------------------------
; Copyright (c) 1998-2007, Brian Gladman, Worcester, UK. All rights reserved.
;
; LICENSE TERMS
;
; The free distribution and use of this software is allowed (with or without
; changes) provided that:
;
; 1. source code distributions include the above copyright notice, this
; list of conditions and the following disclaimer;
;
; 2. binary distributions include the above copyright notice, this list
; of conditions and the following disclaimer in their documentation;
;
; 3. the name of the copyright holder is not used to endorse products
; built using this software without specific written permission.
;
; DISCLAIMER
;
; This software is provided 'as is' with no explicit or implied warranties
; in respect of its properties, including, but not limited to, correctness
; and/or fitness for purpose.
; ---------------------------------------------------------------------------
; Issue 20/12/2007
;
; I am grateful to Dag Arne Osvik for many discussions of the techniques that
; can be used to optimise AES assembler code on AMD64/EM64T architectures.
; Some of the techniques used in this implementation are the result of
; suggestions made by him for which I am most grateful.
; An AES implementation for AMD64 processors using the YASM assembler. This
; implemetation provides only encryption, decryption and hence requires key
; scheduling support in C. It uses 8k bytes of tables but its encryption and
; decryption performance is very close to that obtained using large tables.
; It can use either Windows or Gnu/Linux calling conventions, which are as
; follows:
; windows gnu/linux
;
; in_blk rcx rdi
; out_blk rdx rsi
; context (cx) r8 rdx
;
; preserved rsi - + rbx, rbp, rsp, r12, r13, r14 & r15
; registers rdi - on both
;
; destroyed - rsi + rax, rcx, rdx, r8, r9, r10 & r11
; registers - rdi on both
;
; The default convention is that for windows, the gnu/linux convention being
; used if __GNUC__ is defined.
;
; Define _SEH_ to include support for Win64 structured exception handling
; (this requires YASM version 0.6 or later).
;
; This code provides the standard AES block size (128 bits, 16 bytes) and the
; three standard AES key sizes (128, 192 and 256 bits). It has the same call
; interface as my C implementation. It uses the Microsoft C AMD64 calling
; conventions in which the three parameters are placed in rcx, rdx and r8
; respectively. The rbx, rsi, rdi, rbp and r12..r15 registers are preserved.
;
; AES_RETURN aes_encrypt(const unsigned char in_blk[],
; unsigned char out_blk[], const aes_encrypt_ctx cx[1]);
;
; AES_RETURN aes_decrypt(const unsigned char in_blk[],
; unsigned char out_blk[], const aes_decrypt_ctx cx[1]);
;
; AES_RETURN aes_encrypt_key<NNN>(const unsigned char key[],
; const aes_encrypt_ctx cx[1]);
;
; AES_RETURN aes_decrypt_key<NNN>(const unsigned char key[],
; const aes_decrypt_ctx cx[1]);
;
; AES_RETURN aes_encrypt_key(const unsigned char key[],
; unsigned int len, const aes_decrypt_ctx cx[1]);
;
; AES_RETURN aes_decrypt_key(const unsigned char key[],
; unsigned int len, const aes_decrypt_ctx cx[1]);
;
; where <NNN> is 128, 102 or 256. In the last two calls the length can be in
; either bits or bytes.
;
; Comment in/out the following lines to obtain the desired subroutines. These
; selections MUST match those in the C header file aes.h
;%define AES_128 ; define if AES with 128 bit keys is needed
;%define AES_192 ; define if AES with 192 bit keys is needed
%define AES_256 ; define if AES with 256 bit keys is needed
;%define AES_VAR ; define if a variable key size is needed
%define ENCRYPTION ; define if encryption is needed
%define DECRYPTION ; define if decryption is needed
%define AES_REV_DKS ; define if key decryption schedule is reversed
%define LAST_ROUND_TABLES ; define for the faster version using extra tables
; The encryption key schedule has the following in memory layout where N is the
; number of rounds (10, 12 or 14):
;
; lo: | input key (round 0) | ; each round is four 32-bit words
; | encryption round 1 |
; | encryption round 2 |
; ....
; | encryption round N-1 |
; hi: | encryption round N |
;
; The decryption key schedule is normally set up so that it has the same
; layout as above by actually reversing the order of the encryption key
; schedule in memory (this happens when AES_REV_DKS is set):
;
; lo: | decryption round 0 | = | encryption round N |
; | decryption round 1 | = INV_MIX_COL[ | encryption round N-1 | ]
; | decryption round 2 | = INV_MIX_COL[ | encryption round N-2 | ]
; .... ....
; | decryption round N-1 | = INV_MIX_COL[ | encryption round 1 | ]
; hi: | decryption round N | = | input key (round 0) |
;
; with rounds except the first and last modified using inv_mix_column()
; But if AES_REV_DKS is NOT set the order of keys is left as it is for
; encryption so that it has to be accessed in reverse when used for
; decryption (although the inverse mix column modifications are done)
;
; lo: | decryption round 0 | = | input key (round 0) |
; | decryption round 1 | = INV_MIX_COL[ | encryption round 1 | ]
; | decryption round 2 | = INV_MIX_COL[ | encryption round 2 | ]
; .... ....
; | decryption round N-1 | = INV_MIX_COL[ | encryption round N-1 | ]
; hi: | decryption round N | = | encryption round N |
;
; This layout is faster when the assembler key scheduling provided here
; is used.
;
; The DLL interface must use the _stdcall convention in which the number
; of bytes of parameter space is added after an @ to the sutine's name.
; We must also remove our parameters from the stack before return (see
; the do_exit macro). Define DLL_EXPORT for the Dynamic Link Library version.
;%define DLL_EXPORT
; End of user defines
%ifdef AES_VAR
%ifndef AES_128
%define AES_128
%endif
%ifndef AES_192
%define AES_192
%endif
%ifndef AES_256
%define AES_256
%endif
%endif
%ifdef AES_VAR
%define KS_LENGTH 60
%elifdef AES_256
%define KS_LENGTH 60
%elifdef AES_192
%define KS_LENGTH 52
%else
%define KS_LENGTH 44
%endif
%define r0 rax
%define r1 rdx
%define r2 rcx
%define r3 rbx
%define r4 rsi
%define r5 rdi
%define r6 rbp
%define r7 rsp
%define raxd eax
%define rdxd edx
%define rcxd ecx
%define rbxd ebx
%define rsid esi
%define rdid edi
%define rbpd ebp
%define rspd esp
%define raxb al
%define rdxb dl
%define rcxb cl
%define rbxb bl
%define rsib sil
%define rdib dil
%define rbpb bpl
%define rspb spl
%define r0h ah
%define r1h dh
%define r2h ch
%define r3h bh
%define r0d eax
%define r1d edx
%define r2d ecx
%define r3d ebx
; finite field multiplies by {02}, {04} and {08}
%define f2(x) ((x<<1)^(((x>>7)&1)*0x11b))
%define f4(x) ((x<<2)^(((x>>6)&1)*0x11b)^(((x>>6)&2)*0x11b))
%define f8(x) ((x<<3)^(((x>>5)&1)*0x11b)^(((x>>5)&2)*0x11b)^(((x>>5)&4)*0x11b))
; finite field multiplies required in table generation
%define f3(x) (f2(x) ^ x)
%define f9(x) (f8(x) ^ x)
%define fb(x) (f8(x) ^ f2(x) ^ x)
%define fd(x) (f8(x) ^ f4(x) ^ x)
%define fe(x) (f8(x) ^ f4(x) ^ f2(x))
; macro for expanding S-box data
%macro enc_vals 1
db %1(0x63),%1(0x7c),%1(0x77),%1(0x7b),%1(0xf2),%1(0x6b),%1(0x6f),%1(0xc5)
db %1(0x30),%1(0x01),%1(0x67),%1(0x2b),%1(0xfe),%1(0xd7),%1(0xab),%1(0x76)
db %1(0xca),%1(0x82),%1(0xc9),%1(0x7d),%1(0xfa),%1(0x59),%1(0x47),%1(0xf0)
db %1(0xad),%1(0xd4),%1(0xa2),%1(0xaf),%1(0x9c),%1(0xa4),%1(0x72),%1(0xc0)
db %1(0xb7),%1(0xfd),%1(0x93),%1(0x26),%1(0x36),%1(0x3f),%1(0xf7),%1(0xcc)
db %1(0x34),%1(0xa5),%1(0xe5),%1(0xf1),%1(0x71),%1(0xd8),%1(0x31),%1(0x15)
db %1(0x04),%1(0xc7),%1(0x23),%1(0xc3),%1(0x18),%1(0x96),%1(0x05),%1(0x9a)
db %1(0x07),%1(0x12),%1(0x80),%1(0xe2),%1(0xeb),%1(0x27),%1(0xb2),%1(0x75)
db %1(0x09),%1(0x83),%1(0x2c),%1(0x1a),%1(0x1b),%1(0x6e),%1(0x5a),%1(0xa0)
db %1(0x52),%1(0x3b),%1(0xd6),%1(0xb3),%1(0x29),%1(0xe3),%1(0x2f),%1(0x84)
db %1(0x53),%1(0xd1),%1(0x00),%1(0xed),%1(0x20),%1(0xfc),%1(0xb1),%1(0x5b)
db %1(0x6a),%1(0xcb),%1(0xbe),%1(0x39),%1(0x4a),%1(0x4c),%1(0x58),%1(0xcf)
db %1(0xd0),%1(0xef),%1(0xaa),%1(0xfb),%1(0x43),%1(0x4d),%1(0x33),%1(0x85)
db %1(0x45),%1(0xf9),%1(0x02),%1(0x7f),%1(0x50),%1(0x3c),%1(0x9f),%1(0xa8)
db %1(0x51),%1(0xa3),%1(0x40),%1(0x8f),%1(0x92),%1(0x9d),%1(0x38),%1(0xf5)
db %1(0xbc),%1(0xb6),%1(0xda),%1(0x21),%1(0x10),%1(0xff),%1(0xf3),%1(0xd2)
db %1(0xcd),%1(0x0c),%1(0x13),%1(0xec),%1(0x5f),%1(0x97),%1(0x44),%1(0x17)
db %1(0xc4),%1(0xa7),%1(0x7e),%1(0x3d),%1(0x64),%1(0x5d),%1(0x19),%1(0x73)
db %1(0x60),%1(0x81),%1(0x4f),%1(0xdc),%1(0x22),%1(0x2a),%1(0x90),%1(0x88)
db %1(0x46),%1(0xee),%1(0xb8),%1(0x14),%1(0xde),%1(0x5e),%1(0x0b),%1(0xdb)
db %1(0xe0),%1(0x32),%1(0x3a),%1(0x0a),%1(0x49),%1(0x06),%1(0x24),%1(0x5c)
db %1(0xc2),%1(0xd3),%1(0xac),%1(0x62),%1(0x91),%1(0x95),%1(0xe4),%1(0x79)
db %1(0xe7),%1(0xc8),%1(0x37),%1(0x6d),%1(0x8d),%1(0xd5),%1(0x4e),%1(0xa9)
db %1(0x6c),%1(0x56),%1(0xf4),%1(0xea),%1(0x65),%1(0x7a),%1(0xae),%1(0x08)
db %1(0xba),%1(0x78),%1(0x25),%1(0x2e),%1(0x1c),%1(0xa6),%1(0xb4),%1(0xc6)
db %1(0xe8),%1(0xdd),%1(0x74),%1(0x1f),%1(0x4b),%1(0xbd),%1(0x8b),%1(0x8a)
db %1(0x70),%1(0x3e),%1(0xb5),%1(0x66),%1(0x48),%1(0x03),%1(0xf6),%1(0x0e)
db %1(0x61),%1(0x35),%1(0x57),%1(0xb9),%1(0x86),%1(0xc1),%1(0x1d),%1(0x9e)
db %1(0xe1),%1(0xf8),%1(0x98),%1(0x11),%1(0x69),%1(0xd9),%1(0x8e),%1(0x94)
db %1(0x9b),%1(0x1e),%1(0x87),%1(0xe9),%1(0xce),%1(0x55),%1(0x28),%1(0xdf)
db %1(0x8c),%1(0xa1),%1(0x89),%1(0x0d),%1(0xbf),%1(0xe6),%1(0x42),%1(0x68)
db %1(0x41),%1(0x99),%1(0x2d),%1(0x0f),%1(0xb0),%1(0x54),%1(0xbb),%1(0x16)
%endmacro
%macro dec_vals 1
db %1(0x52),%1(0x09),%1(0x6a),%1(0xd5),%1(0x30),%1(0x36),%1(0xa5),%1(0x38)
db %1(0xbf),%1(0x40),%1(0xa3),%1(0x9e),%1(0x81),%1(0xf3),%1(0xd7),%1(0xfb)
db %1(0x7c),%1(0xe3),%1(0x39),%1(0x82),%1(0x9b),%1(0x2f),%1(0xff),%1(0x87)
db %1(0x34),%1(0x8e),%1(0x43),%1(0x44),%1(0xc4),%1(0xde),%1(0xe9),%1(0xcb)
db %1(0x54),%1(0x7b),%1(0x94),%1(0x32),%1(0xa6),%1(0xc2),%1(0x23),%1(0x3d)
db %1(0xee),%1(0x4c),%1(0x95),%1(0x0b),%1(0x42),%1(0xfa),%1(0xc3),%1(0x4e)
db %1(0x08),%1(0x2e),%1(0xa1),%1(0x66),%1(0x28),%1(0xd9),%1(0x24),%1(0xb2)
db %1(0x76),%1(0x5b),%1(0xa2),%1(0x49),%1(0x6d),%1(0x8b),%1(0xd1),%1(0x25)
db %1(0x72),%1(0xf8),%1(0xf6),%1(0x64),%1(0x86),%1(0x68),%1(0x98),%1(0x16)
db %1(0xd4),%1(0xa4),%1(0x5c),%1(0xcc),%1(0x5d),%1(0x65),%1(0xb6),%1(0x92)
db %1(0x6c),%1(0x70),%1(0x48),%1(0x50),%1(0xfd),%1(0xed),%1(0xb9),%1(0xda)
db %1(0x5e),%1(0x15),%1(0x46),%1(0x57),%1(0xa7),%1(0x8d),%1(0x9d),%1(0x84)
db %1(0x90),%1(0xd8),%1(0xab),%1(0x00),%1(0x8c),%1(0xbc),%1(0xd3),%1(0x0a)
db %1(0xf7),%1(0xe4),%1(0x58),%1(0x05),%1(0xb8),%1(0xb3),%1(0x45),%1(0x06)
db %1(0xd0),%1(0x2c),%1(0x1e),%1(0x8f),%1(0xca),%1(0x3f),%1(0x0f),%1(0x02)
db %1(0xc1),%1(0xaf),%1(0xbd),%1(0x03),%1(0x01),%1(0x13),%1(0x8a),%1(0x6b)
db %1(0x3a),%1(0x91),%1(0x11),%1(0x41),%1(0x4f),%1(0x67),%1(0xdc),%1(0xea)
db %1(0x97),%1(0xf2),%1(0xcf),%1(0xce),%1(0xf0),%1(0xb4),%1(0xe6),%1(0x73)
db %1(0x96),%1(0xac),%1(0x74),%1(0x22),%1(0xe7),%1(0xad),%1(0x35),%1(0x85)
db %1(0xe2),%1(0xf9),%1(0x37),%1(0xe8),%1(0x1c),%1(0x75),%1(0xdf),%1(0x6e)
db %1(0x47),%1(0xf1),%1(0x1a),%1(0x71),%1(0x1d),%1(0x29),%1(0xc5),%1(0x89)
db %1(0x6f),%1(0xb7),%1(0x62),%1(0x0e),%1(0xaa),%1(0x18),%1(0xbe),%1(0x1b)
db %1(0xfc),%1(0x56),%1(0x3e),%1(0x4b),%1(0xc6),%1(0xd2),%1(0x79),%1(0x20)
db %1(0x9a),%1(0xdb),%1(0xc0),%1(0xfe),%1(0x78),%1(0xcd),%1(0x5a),%1(0xf4)
db %1(0x1f),%1(0xdd),%1(0xa8),%1(0x33),%1(0x88),%1(0x07),%1(0xc7),%1(0x31)
db %1(0xb1),%1(0x12),%1(0x10),%1(0x59),%1(0x27),%1(0x80),%1(0xec),%1(0x5f)
db %1(0x60),%1(0x51),%1(0x7f),%1(0xa9),%1(0x19),%1(0xb5),%1(0x4a),%1(0x0d)
db %1(0x2d),%1(0xe5),%1(0x7a),%1(0x9f),%1(0x93),%1(0xc9),%1(0x9c),%1(0xef)
db %1(0xa0),%1(0xe0),%1(0x3b),%1(0x4d),%1(0xae),%1(0x2a),%1(0xf5),%1(0xb0)
db %1(0xc8),%1(0xeb),%1(0xbb),%1(0x3c),%1(0x83),%1(0x53),%1(0x99),%1(0x61)
db %1(0x17),%1(0x2b),%1(0x04),%1(0x7e),%1(0xba),%1(0x77),%1(0xd6),%1(0x26)
db %1(0xe1),%1(0x69),%1(0x14),%1(0x63),%1(0x55),%1(0x21),%1(0x0c),%1(0x7d)
%endmacro
%define u8(x) f2(x), x, x, f3(x), f2(x), x, x, f3(x)
%define v8(x) fe(x), f9(x), fd(x), fb(x), fe(x), f9(x), fd(x), x
%define w8(x) x, 0, 0, 0, x, 0, 0, 0
%define tptr rbp ; table pointer
%define kptr r8 ; key schedule pointer
%define fofs 128 ; adjust offset in key schedule to keep |disp| < 128
%define fk_ref(x,y) [kptr-16*x+fofs+4*y]
%ifdef AES_REV_DKS
%define rofs 128
%define ik_ref(x,y) [kptr-16*x+rofs+4*y]
%else
%define rofs -128
%define ik_ref(x,y) [kptr+16*x+rofs+4*y]
%endif
%define tab_0(x) [tptr+8*x]
%define tab_1(x) [tptr+8*x+3]
%define tab_2(x) [tptr+8*x+2]
%define tab_3(x) [tptr+8*x+1]
%define tab_f(x) byte [tptr+8*x+1]
%define tab_i(x) byte [tptr+8*x+7]
%define t_ref(x,r) tab_ %+ x(r)
%macro ff_rnd 5 ; normal forward round
mov %1d, fk_ref(%5,0)
mov %2d, fk_ref(%5,1)
mov %3d, fk_ref(%5,2)
mov %4d, fk_ref(%5,3)
movzx esi, al
movzx edi, ah
shr eax, 16
xor %1d, t_ref(0,rsi)
xor %4d, t_ref(1,rdi)
movzx esi, al
movzx edi, ah
xor %3d, t_ref(2,rsi)
xor %2d, t_ref(3,rdi)
movzx esi, bl
movzx edi, bh
shr ebx, 16
xor %2d, t_ref(0,rsi)
xor %1d, t_ref(1,rdi)
movzx esi, bl
movzx edi, bh
xor %4d, t_ref(2,rsi)
xor %3d, t_ref(3,rdi)
movzx esi, cl
movzx edi, ch
shr ecx, 16
xor %3d, t_ref(0,rsi)
xor %2d, t_ref(1,rdi)
movzx esi, cl
movzx edi, ch
xor %1d, t_ref(2,rsi)
xor %4d, t_ref(3,rdi)
movzx esi, dl
movzx edi, dh
shr edx, 16
xor %4d, t_ref(0,rsi)
xor %3d, t_ref(1,rdi)
movzx esi, dl
movzx edi, dh
xor %2d, t_ref(2,rsi)
xor %1d, t_ref(3,rdi)
mov eax,%1d
mov ebx,%2d
mov ecx,%3d
mov edx,%4d
%endmacro
%ifdef LAST_ROUND_TABLES
%macro fl_rnd 5 ; last forward round
add tptr, 2048
mov %1d, fk_ref(%5,0)
mov %2d, fk_ref(%5,1)
mov %3d, fk_ref(%5,2)
mov %4d, fk_ref(%5,3)
movzx esi, al
movzx edi, ah
shr eax, 16
xor %1d, t_ref(0,rsi)
xor %4d, t_ref(1,rdi)
movzx esi, al
movzx edi, ah
xor %3d, t_ref(2,rsi)
xor %2d, t_ref(3,rdi)
movzx esi, bl
movzx edi, bh
shr ebx, 16
xor %2d, t_ref(0,rsi)
xor %1d, t_ref(1,rdi)
movzx esi, bl
movzx edi, bh
xor %4d, t_ref(2,rsi)
xor %3d, t_ref(3,rdi)
movzx esi, cl
movzx edi, ch
shr ecx, 16
xor %3d, t_ref(0,rsi)
xor %2d, t_ref(1,rdi)
movzx esi, cl
movzx edi, ch
xor %1d, t_ref(2,rsi)
xor %4d, t_ref(3,rdi)
movzx esi, dl
movzx edi, dh
shr edx, 16
xor %4d, t_ref(0,rsi)
xor %3d, t_ref(1,rdi)
movzx esi, dl
movzx edi, dh
xor %2d, t_ref(2,rsi)
xor %1d, t_ref(3,rdi)
%endmacro
%else
%macro fl_rnd 5 ; last forward round
mov %1d, fk_ref(%5,0)
mov %2d, fk_ref(%5,1)
mov %3d, fk_ref(%5,2)
mov %4d, fk_ref(%5,3)
movzx esi, al
movzx edi, ah
shr eax, 16
movzx esi, t_ref(f,rsi)
movzx edi, t_ref(f,rdi)
xor %1d, esi
rol edi, 8
xor %4d, edi
movzx esi, al
movzx edi, ah
movzx esi, t_ref(f,rsi)
movzx edi, t_ref(f,rdi)
rol esi, 16
rol edi, 24
xor %3d, esi
xor %2d, edi
movzx esi, bl
movzx edi, bh
shr ebx, 16
movzx esi, t_ref(f,rsi)
movzx edi, t_ref(f,rdi)
xor %2d, esi
rol edi, 8
xor %1d, edi
movzx esi, bl
movzx edi, bh
movzx esi, t_ref(f,rsi)
movzx edi, t_ref(f,rdi)
rol esi, 16
rol edi, 24
xor %4d, esi
xor %3d, edi
movzx esi, cl
movzx edi, ch
movzx esi, t_ref(f,rsi)
movzx edi, t_ref(f,rdi)
shr ecx, 16
xor %3d, esi
rol edi, 8
xor %2d, edi
movzx esi, cl
movzx edi, ch
movzx esi, t_ref(f,rsi)
movzx edi, t_ref(f,rdi)
rol esi, 16
rol edi, 24
xor %1d, esi
xor %4d, edi
movzx esi, dl
movzx edi, dh
movzx esi, t_ref(f,rsi)
movzx edi, t_ref(f,rdi)
shr edx, 16
xor %4d, esi
rol edi, 8
xor %3d, edi
movzx esi, dl
movzx edi, dh
movzx esi, t_ref(f,rsi)
movzx edi, t_ref(f,rdi)
rol esi, 16
rol edi, 24
xor %2d, esi
xor %1d, edi
%endmacro
%endif
%macro ii_rnd 5 ; normal inverse round
mov %1d, ik_ref(%5,0)
mov %2d, ik_ref(%5,1)
mov %3d, ik_ref(%5,2)
mov %4d, ik_ref(%5,3)
movzx esi, al
movzx edi, ah
shr eax, 16
xor %1d, t_ref(0,rsi)
xor %2d, t_ref(1,rdi)
movzx esi, al
movzx edi, ah
xor %3d, t_ref(2,rsi)
xor %4d, t_ref(3,rdi)
movzx esi, bl
movzx edi, bh
shr ebx, 16
xor %2d, t_ref(0,rsi)
xor %3d, t_ref(1,rdi)
movzx esi, bl
movzx edi, bh
xor %4d, t_ref(2,rsi)
xor %1d, t_ref(3,rdi)
movzx esi, cl
movzx edi, ch
shr ecx, 16
xor %3d, t_ref(0,rsi)
xor %4d, t_ref(1,rdi)
movzx esi, cl
movzx edi, ch
xor %1d, t_ref(2,rsi)
xor %2d, t_ref(3,rdi)
movzx esi, dl
movzx edi, dh
shr edx, 16
xor %4d, t_ref(0,rsi)
xor %1d, t_ref(1,rdi)
movzx esi, dl
movzx edi, dh
xor %2d, t_ref(2,rsi)
xor %3d, t_ref(3,rdi)
mov eax,%1d
mov ebx,%2d
mov ecx,%3d
mov edx,%4d
%endmacro
%ifdef LAST_ROUND_TABLES
%macro il_rnd 5 ; last inverse round
add tptr, 2048
mov %1d, ik_ref(%5,0)
mov %2d, ik_ref(%5,1)
mov %3d, ik_ref(%5,2)
mov %4d, ik_ref(%5,3)
movzx esi, al
movzx edi, ah
shr eax, 16
xor %1d, t_ref(0,rsi)
xor %2d, t_ref(1,rdi)
movzx esi, al
movzx edi, ah
xor %3d, t_ref(2,rsi)
xor %4d, t_ref(3,rdi)
movzx esi, bl
movzx edi, bh
shr ebx, 16
xor %2d, t_ref(0,rsi)
xor %3d, t_ref(1,rdi)
movzx esi, bl
movzx edi, bh
xor %4d, t_ref(2,rsi)
xor %1d, t_ref(3,rdi)
movzx esi, cl
movzx edi, ch
shr ecx, 16
xor %3d, t_ref(0,rsi)
xor %4d, t_ref(1,rdi)
movzx esi, cl
movzx edi, ch
xor %1d, t_ref(2,rsi)
xor %2d, t_ref(3,rdi)
movzx esi, dl
movzx edi, dh
shr edx, 16
xor %4d, t_ref(0,rsi)
xor %1d, t_ref(1,rdi)
movzx esi, dl
movzx edi, dh
xor %2d, t_ref(2,rsi)
xor %3d, t_ref(3,rdi)
%endmacro
%else
%macro il_rnd 5 ; last inverse round
mov %1d, ik_ref(%5,0)
mov %2d, ik_ref(%5,1)
mov %3d, ik_ref(%5,2)
mov %4d, ik_ref(%5,3)
movzx esi, al
movzx edi, ah
movzx esi, t_ref(i,rsi)
movzx edi, t_ref(i,rdi)
shr eax, 16
xor %1d, esi
rol edi, 8
xor %2d, edi
movzx esi, al
movzx edi, ah
movzx esi, t_ref(i,rsi)
movzx edi, t_ref(i,rdi)
rol esi, 16
rol edi, 24
xor %3d, esi
xor %4d, edi
movzx esi, bl
movzx edi, bh
movzx esi, t_ref(i,rsi)
movzx edi, t_ref(i,rdi)
shr ebx, 16
xor %2d, esi
rol edi, 8
xor %3d, edi
movzx esi, bl
movzx edi, bh
movzx esi, t_ref(i,rsi)
movzx edi, t_ref(i,rdi)
rol esi, 16
rol edi, 24
xor %4d, esi
xor %1d, edi
movzx esi, cl
movzx edi, ch
movzx esi, t_ref(i,rsi)
movzx edi, t_ref(i,rdi)
shr ecx, 16
xor %3d, esi
rol edi, 8
xor %4d, edi
movzx esi, cl
movzx edi, ch
movzx esi, t_ref(i,rsi)
movzx edi, t_ref(i,rdi)
rol esi, 16
rol edi, 24
xor %1d, esi
xor %2d, edi
movzx esi, dl
movzx edi, dh
movzx esi, t_ref(i,rsi)
movzx edi, t_ref(i,rdi)
shr edx, 16
xor %4d, esi
rol edi, 8
xor %1d, edi
movzx esi, dl
movzx edi, dh
movzx esi, t_ref(i,rsi)
movzx edi, t_ref(i,rdi)
rol esi, 16
rol edi, 24
xor %2d, esi
xor %3d, edi
%endmacro
%endif
%ifdef ENCRYPTION
global aes256_asm_encrypt
%ifdef DLL_EXPORT
export aes256_asm_encrypt
%endif
section .data align=64
align 64
enc_tab:
enc_vals u8
%ifdef LAST_ROUND_TABLES
enc_vals w8
%endif
section .text align=16
align 16
%ifdef _SEH_
proc_frame aes256_asm_encrypt
alloc_stack 7*8 ; 7 to align stack to 16 bytes
save_reg rsi,4*8
save_reg rdi,5*8
save_reg rbx,1*8
save_reg rbp,2*8
save_reg r12,3*8
end_prologue
mov rdi, rcx ; input pointer
mov [rsp+0*8], rdx ; output pointer
%else
aes256_asm_encrypt:
%ifdef __GNUC__
sub rsp, 4*8 ; gnu/linux binary interface
mov [rsp+0*8], rsi ; output pointer
mov r8, rdx ; context
%else
sub rsp, 6*8 ; windows binary interface
mov [rsp+4*8], rsi
mov [rsp+5*8], rdi
mov rdi, rcx ; input pointer
mov [rsp+0*8], rdx ; output pointer
%endif
mov [rsp+1*8], rbx ; input pointer in rdi
mov [rsp+2*8], rbp ; output pointer in [rsp]
mov [rsp+3*8], r12 ; context in r8
%endif
lea tptr,[enc_tab wrt rip]
sub kptr, fofs
mov eax, [rdi+0*4]
mov ebx, [rdi+1*4]
mov ecx, [rdi+2*4]
mov edx, [rdi+3*4]
xor eax, [kptr+fofs]
xor ebx, [kptr+fofs+4]
xor ecx, [kptr+fofs+8]
xor edx, [kptr+fofs+12]
add kptr, 14*16
ff_rnd r9, r10, r11, r12, 13
ff_rnd r9, r10, r11, r12, 12
ff_rnd r9, r10, r11, r12, 11
ff_rnd r9, r10, r11, r12, 10
ff_rnd r9, r10, r11, r12, 9
ff_rnd r9, r10, r11, r12, 8
ff_rnd r9, r10, r11, r12, 7
ff_rnd r9, r10, r11, r12, 6
ff_rnd r9, r10, r11, r12, 5
ff_rnd r9, r10, r11, r12, 4
ff_rnd r9, r10, r11, r12, 3
ff_rnd r9, r10, r11, r12, 2
ff_rnd r9, r10, r11, r12, 1
fl_rnd r9, r10, r11, r12, 0
mov rbx, [rsp]
mov [rbx], r9d
mov [rbx+4], r10d
mov [rbx+8], r11d
mov [rbx+12], r12d
xor rax, rax
mov rbx, [rsp+1*8]
mov rbp, [rsp+2*8]
mov r12, [rsp+3*8]
%ifdef __GNUC__
add rsp, 4*8
ret
%else
mov rsi, [rsp+4*8]
mov rdi, [rsp+5*8]
%ifdef _SEH_
add rsp, 7*8
ret
endproc_frame
%else
add rsp, 6*8
ret
%endif
%endif
%endif
%ifdef DECRYPTION
global aes256_asm_decrypt
%ifdef DLL_EXPORT
export aes256_asm_decrypt
%endif
section .data
align 64
dec_tab:
dec_vals v8
%ifdef LAST_ROUND_TABLES
dec_vals w8
%endif
section .text
align 16
%ifdef _SEH_
proc_frame aes256_asm_decrypt
alloc_stack 7*8 ; 7 to align stack to 16 bytes
save_reg rsi,4*8
save_reg rdi,5*8
save_reg rbx,1*8
save_reg rbp,2*8
save_reg r12,3*8
end_prologue
mov rdi, rcx ; input pointer
mov [rsp+0*8], rdx ; output pointer
%else
aes256_asm_decrypt:
%ifdef __GNUC__
sub rsp, 4*8 ; gnu/linux binary interface
mov [rsp+0*8], rsi ; output pointer
mov r8, rdx ; context
%else
sub rsp, 6*8 ; windows binary interface
mov [rsp+4*8], rsi
mov [rsp+5*8], rdi
mov rdi, rcx ; input pointer
mov [rsp+0*8], rdx ; output pointer
%endif
mov [rsp+1*8], rbx ; input pointer in rdi
mov [rsp+2*8], rbp ; output pointer in [rsp]
mov [rsp+3*8], r12 ; context in r8
%endif
add kptr, 4*KS_LENGTH
lea tptr,[dec_tab wrt rip]
sub kptr, rofs
mov eax, [rdi+0*4]
mov ebx, [rdi+1*4]
mov ecx, [rdi+2*4]
mov edx, [rdi+3*4]
%ifdef AES_REV_DKS
mov rdi, kptr
add kptr, 14*16
%else
add rdi, 14*16
%endif
xor eax, [rdi+rofs]
xor ebx, [rdi+rofs+4]
xor ecx, [rdi+rofs+8]
xor edx, [rdi+rofs+12]
ii_rnd r9, r10, r11, r12, 13
ii_rnd r9, r10, r11, r12, 12
ii_rnd r9, r10, r11, r12, 11
ii_rnd r9, r10, r11, r12, 10
ii_rnd r9, r10, r11, r12, 9
ii_rnd r9, r10, r11, r12, 8
ii_rnd r9, r10, r11, r12, 7
ii_rnd r9, r10, r11, r12, 6
ii_rnd r9, r10, r11, r12, 5
ii_rnd r9, r10, r11, r12, 4
ii_rnd r9, r10, r11, r12, 3
ii_rnd r9, r10, r11, r12, 2
ii_rnd r9, r10, r11, r12, 1
il_rnd r9, r10, r11, r12, 0
mov rbx, [rsp]
mov [rbx], r9d
mov [rbx+4], r10d
mov [rbx+8], r11d
mov [rbx+12], r12d
xor rax, rax
mov rbx, [rsp+1*8]
mov rbp, [rsp+2*8]
mov r12, [rsp+3*8]
%ifdef __GNUC__
add rsp, 4*8
ret
%else
mov rsi, [rsp+4*8]
mov rdi, [rsp+5*8]
%ifdef _SEH_
add rsp, 7*8
ret
endproc_frame
%else
add rsp, 6*8
ret
%endif
%endif
%endif
end

View File

@ -0,0 +1,91 @@
;
; *
; * Copyright (c) 2009-2010
; * ntldr <ntldr@diskcryptor.net> PGP key ID - 0x1B6A24550F33E44A
; *
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License version 3 as
; published by the Free Software Foundation.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
;
%define NEH_LOAD_KEY 00000080h ; load schedule from memory
%define NEH_ENCRYPT 00000000h ; encryption
%define NEH_DECRYPT 00000200h ; decryption
%define NEH_KEY128 00000000h+0ah ; 128 bit key
%define NEH_KEY192 00000400h+0ch ; 192 bit key
%define NEH_KEY256 00000800h+0eh ; 256 bit key
%define NEH_ENC_LOAD (NEH_ENCRYPT | NEH_LOAD_KEY)
%define NEH_DEC_LOAD (NEH_DECRYPT | NEH_LOAD_KEY)
align 16
enc_cwd dd (NEH_ENC_LOAD | NEH_KEY256), 0, 0
align 16
dec_cwd dd (NEH_DEC_LOAD | NEH_KEY256), 0, 0
global aes256_padlock_available
global aes256_padlock_encrypt
global aes256_padlock_decrypt
aes256_padlock_available:
push rbx
; test for VIA CPU
mov eax, 0C0000000h
cpuid
cmp eax, 0C0000001h
jb no_ace
; read VIA flags
mov eax, 0C0000001h
cpuid
and edx, 0C0h ; ACE_MASK,CPUID EDX code for ACE
cmp edx, 0C0h ; ACE_MASK,CPUID EDX code for ACE
jnz no_ace
; ACE present
xor rax, rax
inc eax
jmp end_ace
no_ace:
xor rax, rax
end_ace:
pop rbx
ret
align 16
aes256_padlock_encrypt:
push rbx
push rsi
push rdi
mov rsi, rcx ; in
mov rdi, rdx ; out
mov rcx, r8 ; n_blocks
mov rbx, r9 ; key
lea rdx, [rel enc_cwd]
xcryptecb
pop rdi
pop rsi
pop rbx
ret
align 16
aes256_padlock_decrypt:
push rbx
push rsi
push rdi
mov rsi, rcx ; in
mov rdi, rdx ; out
mov rcx, r8 ; n_blocks
lea rbx, [r9+4*15*4] ; key
lea rdx, [rel dec_cwd]
xcryptecb
pop rdi
pop rsi
pop rbx
ret

View File

@ -0,0 +1,320 @@
;***************************************************************************
;* Copyright (C) 2006 by Joachim Fritschi, <jfritschi@freenet.de> *
;* adapted for DiskCryptor by ntldr <ntldr@diskcryptor.net> *
;* PGP key ID - 0x1B6A24550F33E44A *
;* *
;* This program is free software; you can redistribute it and/or modify *
;* it under the terms of the GNU General Public License as published by *
;* the Free Software Foundation; either version 2 of the License, or *
;* (at your option) any later version. *
;* *
;* This program is distributed in the hope that it will be useful, *
;* but WITHOUT ANY WARRANTY; without even the implied warranty of *
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
;* GNU General Public License for more details. *
;* *
;* You should have received a copy of the GNU General Public License *
;* along with this program; if not, write to the *
;* Free Software Foundation, Inc., *
;* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
;***************************************************************************
%define a_offset 0
%define b_offset 4
%define c_offset 8
%define d_offset 12
; Structure of the crypto context struct
%define s0 0 ; S0 Array 256 Words each
%define s1 1024 ; S1 Array
%define s2 2048 ; S2 Array
%define s3 3072 ; S3 Array
%define w 4096 ; 8 whitening keys (word)
%define k 4128 ; key 1-32 ( word )
; define a few register aliases to allow macro substitution
%define R0Q rax
%define R0D eax
%define R0B al
%define R0H ah
%define R1Q rbx
%define R1D ebx
%define R1B bl
%define R1H bh
%define R2Q rcx
%define R2D ecx
%define R2B cl
%define R2H ch
%define R3Q rdx
%define R3D edx
%define R3B dl
%define R3H dh
; performs input whitening
%macro input_whitening 3
xor %1, [w+(%2)+%3]
%endmacro
; performs input whitening
%macro output_whitening 3
xor %1, [w+16+(%2)+%3]
%endmacro
; * a input register containing a (rotated 16)
; * b input register containing b
; * c input register containing c
; * d input register containing d (already rol $1)
; * operations on a and b are interleaved to increase performance
%macro encrypt_round 5
movzx edi, %2B
mov r11d, [r8+rdi*4+s1]
movzx edi, %1B
mov r9d, [r8+rdi*4+s2]
movzx edi, %2H
ror %2D, 16
xor r11d, [r8+rdi*4+s2]
movzx edi, %1H
ror %1D, 16
xor r9d, [r8+rdi*4+s3]
movzx edi, %2B
xor r11d, [r8+rdi*4+s3]
movzx edi, %1B
xor r9d, [r8+rdi*4]
movzx edi, %2H
ror %2D, 15
xor r11d, [r8+rdi*4]
movzx edi, %1H
xor r9d, [r8+rdi*4+s1]
add r9d, r11d
add r11d, r9d
add r9d, [r8+k+%5]
xor %3D, r9d
rol %3D, 15
add r11d, [r8+k+4+%5]
xor %4D, r11d
%endmacro
; * a input register containing a(rotated 16)
; * b input register containing b
; * c input register containing c
; * d input register containing d (already rol $1)
; * operations on a and b are interleaved to increase performance
; * during the %5 a and b are prepared for the output whitening
%macro encrypt_last_round 5
mov r10d, %2D
shl r10, 32
movzx edi, %2B
mov r11d, [r8+rdi*4+s1]
movzx edi, %1B
mov r9d, [r8+rdi*4+s2]
movzx edi, %2H
ror %2D, 16
xor r11d, [r8+rdi*4+s2]
movzx edi, %1H
ror %1D, 16
xor r9d, [r8+rdi*4+s3]
movzx edi, %2B
xor r11d, [r8+rdi*4+s3]
movzx edi, %1B
xor r9d, [r8+rdi*4]
xor r10, %1Q
movzx edi, %2H
xor r11d, [r8+rdi*4]
movzx edi, %1H
xor r9d, [r8+rdi*4+s1]
add r9d, r11d
add r11d, r9d
add r9d, [r8+k+%5]
xor %3D, r9d
ror %3D, 1
add r11d, [r8+k+4+%5]
xor %4D, r11d
%endmacro
; * a input register containing a
; * b input register containing b (rotated 16)
; * c input register containing c (already rol $1)
; * d input register containing d
; * operations on a and b are interleaved to increase performance
%macro decrypt_round 5
movzx edi, %1B
mov r9d, [r8+rdi*4]
movzx edi, %2B
mov r11d, [r8+rdi*4+s3]
movzx edi, %1H
ror %1D, 16
xor r9d, [r8+rdi*4+s1]
movzx edi, %2H
ror %2D, 16
xor r11d, [r8+rdi*4]
movzx edi, %1B
xor r9d, [r8+rdi*4+s2]
movzx edi, %2B
xor r11d, [r8+rdi*4+s1]
movzx edi, %1H
ror %1D, 15
xor r9d, [r8+rdi*4+s3]
movzx edi, %2H
xor r11d, [r8+rdi*4+s2]
add r9d, r11d
add r11d, r9d
add r9d, [r8+k+%5]
xor %3D, r9d
add r11d, [r8+k+4+%5]
xor %4D, r11d
rol %4D, 15
%endmacro
; * a input register containing a
; * b input register containing b
; * c input register containing c (already rol $1)
; * d input register containing d
; * operations on a and b are interleaved to increase performance
; * during the %5 a and b are prepared for the output whitening
%macro decrypt_last_round 5
movzx edi, %1B
mov r9d, [r8+rdi*4]
movzx edi, %2B
mov r11d, [r8+rdi*4+s3]
movzx edi, %2H
ror %2D, 16
xor r11d, [r8+rdi*4]
movzx edi, %1H
mov r10d, %2D
shl r10, 32
xor r10, %1Q
ror %1D, 16
xor r9d, [r8+rdi*4+s1]
movzx edi, %2B
xor r11d, [r8+rdi*4+s1]
movzx edi, %1B
xor r9d, [r8+rdi*4+s2]
movzx edi, %2H
xor r11d, [r8+rdi*4+s2]
movzx edi, %1H
xor r9d, [r8+rdi*4+s3]
add r9d, r11d
add r11d, r9d
add r9d, [r8+k+%5]
xor %3D, r9d
add r11d, [r8+k+4+%5]
xor %4D, r11d
ror %4D, 1
%endmacro
global twofish256_encrypt
global twofish256_decrypt
align 16
twofish256_encrypt:
push R1Q
push rsi
push rdi
; r8 contains the crypto tfm adress
; rdx contains the output adress
; rcx contains the input adress
mov rsi, rdx
mov R1Q, [rcx]
mov R3Q, [rcx+8]
input_whitening R1Q, r8, a_offset
input_whitening R3Q, r8, c_offset
mov R0D, R1D
rol R0D, 16
shr R1Q, 32
mov R2D, R3D
shr R3Q, 32
rol R3D, 1
encrypt_round R0,R1,R2,R3,0
encrypt_round R2,R3,R0,R1,8
encrypt_round R0,R1,R2,R3,2*8
encrypt_round R2,R3,R0,R1,3*8
encrypt_round R0,R1,R2,R3,4*8
encrypt_round R2,R3,R0,R1,5*8
encrypt_round R0,R1,R2,R3,6*8
encrypt_round R2,R3,R0,R1,7*8
encrypt_round R0,R1,R2,R3,8*8
encrypt_round R2,R3,R0,R1,9*8
encrypt_round R0,R1,R2,R3,10*8
encrypt_round R2,R3,R0,R1,11*8
encrypt_round R0,R1,R2,R3,12*8
encrypt_round R2,R3,R0,R1,13*8
encrypt_round R0,R1,R2,R3,14*8
encrypt_last_round R2,R3,R0,R1,15*8
output_whitening r10, r8, a_offset
mov [rsi], r10
shl R1Q, 32
xor R1Q, R0Q
output_whitening R1Q, r8, c_offset
mov [rsi+8], R1Q
pop rdi
pop rsi
pop R1Q
ret
align 16
twofish256_decrypt:
push R1Q
push rsi
push rdi
; r8 contains the crypto tfm adress
; rdx contains the output adress
; rcx contains the input adress
mov rsi, rdx
mov R1Q, [rcx]
mov R3Q, [rcx+8]
output_whitening R1Q, r8, a_offset
output_whitening R3Q, r8, c_offset
mov R0D, R1D
shr R1Q, 32
rol R1D, 16
mov R2D, R3D
shr R3Q, 32
rol R2D, 1
decrypt_round R0,R1,R2,R3,15*8
decrypt_round R2,R3,R0,R1,14*8
decrypt_round R0,R1,R2,R3,13*8
decrypt_round R2,R3,R0,R1,12*8
decrypt_round R0,R1,R2,R3,11*8
decrypt_round R2,R3,R0,R1,10*8
decrypt_round R0,R1,R2,R3,9*8
decrypt_round R2,R3,R0,R1,8*8
decrypt_round R0,R1,R2,R3,7*8
decrypt_round R2,R3,R0,R1,6*8
decrypt_round R0,R1,R2,R3,5*8
decrypt_round R2,R3,R0,R1,4*8
decrypt_round R0,R1,R2,R3,3*8
decrypt_round R2,R3,R0,R1,2*8
decrypt_round R0,R1,R2,R3,1*8
decrypt_last_round R2,R3,R0,R1,0
input_whitening r10, r8, a_offset
mov [rsi], r10
shl R1Q, 32
xor R1Q, R0Q
input_whitening R1Q, r8, c_offset
mov [rsi+8], R1Q
pop rdi
pop rsi
pop R1Q
ret

View File

@ -0,0 +1,242 @@
;
; *
; * Copyright (c) 2010
; * ntldr <ntldr@diskcryptor.net> PGP key ID - 0x1B6A24550F33E44A
; *
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License version 3 as
; published by the Free Software Foundation.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
;
%macro aesxor_4 6 ; B0, B1, B2, B3, key, round
movdqa tt, [%5+(%6*10h)]
pxor %1, tt
pxor %2, tt
pxor %3, tt
pxor %4, tt
%endmacro
%macro aesenc_4 6 ; B0, B1, B2, B3, key, round
movdqa tt, [%5+(%6*10h)]
aesenc %1, tt
aesenc %2, tt
aesenc %3, tt
aesenc %4, tt
%endmacro
%macro aesdec_4 6 ; B0, B1, B2, B3, key, round
movdqa tt, [%5+(%6*10h)]
aesdec %1, tt
aesdec %2, tt
aesdec %3, tt
aesdec %4, tt
%endmacro
%macro aesenclast_4 6 ; B0, B1, B2, B3, key, round
movdqa tt, [%5+(%6*10h)]
aesenclast %1, tt
aesenclast %2, tt
aesenclast %3, tt
aesenclast %4, tt
%endmacro
%macro aesdeclast_4 6 ; B0, B1, B2, B3, key, round
movdqa tt, [%5+(%6*10h)]
aesdeclast %1, tt
aesdeclast %2, tt
aesdeclast %3, tt
aesdeclast %4, tt
%endmacro
%macro aes_encrypt_1 2 ; XMMn, key
pxor %1, [%2]
aesenc %1, [%2+010h]
aesenc %1, [%2+020h]
aesenc %1, [%2+030h]
aesenc %1, [%2+040h]
aesenc %1, [%2+050h]
aesenc %1, [%2+060h]
aesenc %1, [%2+070h]
aesenc %1, [%2+080h]
aesenc %1, [%2+090h]
aesenc %1, [%2+0A0h]
aesenc %1, [%2+0B0h]
aesenc %1, [%2+0C0h]
aesenc %1, [%2+0D0h]
aesenclast %1, [%2+0E0h]
%endmacro
%macro aes_encrypt_4 5 ; B0, B1, B2, B3, key
aesxor_4 %1, %2, %3, %4, %5, 0
aesenc_4 %1, %2, %3, %4, %5, 1
aesenc_4 %1, %2, %3, %4, %5, 2
aesenc_4 %1, %2, %3, %4, %5, 3
aesenc_4 %1, %2, %3, %4, %5, 4
aesenc_4 %1, %2, %3, %4, %5, 5
aesenc_4 %1, %2, %3, %4, %5, 6
aesenc_4 %1, %2, %3, %4, %5, 7
aesenc_4 %1, %2, %3, %4, %5, 8
aesenc_4 %1, %2, %3, %4, %5, 9
aesenc_4 %1, %2, %3, %4, %5, 10
aesenc_4 %1, %2, %3, %4, %5, 11
aesenc_4 %1, %2, %3, %4, %5, 12
aesenc_4 %1, %2, %3, %4, %5, 13
aesenclast_4 %1, %2, %3, %4, %5, 14
%endmacro
%macro aes_decrypt_4 5 ; B0, B1, B2, B3, key
aesxor_4 %1, %2, %3, %4, %5, 0
aesdec_4 %1, %2, %3, %4, %5, 1
aesdec_4 %1, %2, %3, %4, %5, 2
aesdec_4 %1, %2, %3, %4, %5, 3
aesdec_4 %1, %2, %3, %4, %5, 4
aesdec_4 %1, %2, %3, %4, %5, 5
aesdec_4 %1, %2, %3, %4, %5, 6
aesdec_4 %1, %2, %3, %4, %5, 7
aesdec_4 %1, %2, %3, %4, %5, 8
aesdec_4 %1, %2, %3, %4, %5, 9
aesdec_4 %1, %2, %3, %4, %5, 10
aesdec_4 %1, %2, %3, %4, %5, 11
aesdec_4 %1, %2, %3, %4, %5, 12
aesdec_4 %1, %2, %3, %4, %5, 13
aesdeclast_4 %1, %2, %3, %4, %5, 14
%endmacro
%macro next_tweak 2 ; new, old
movdqa tt, %2
psraw tt, 8
psrldq tt, 15
pand tt, POLY
movdqa t2, %2
pslldq t2, 8
psrldq t2, 7
psrlq t2, 7
movdqa %1, %2
psllq %1, 1
por %1, t2
pxor %1, tt
%endmacro
%macro tweak_block_4 0
pxor B0, T0
pxor B1, T1
pxor B2, T2
pxor B3, T3
%endmacro
%macro load_block_4 1
movdqu B0, [%1+00h]
movdqu B1, [%1+10h]
movdqu B2, [%1+20h]
movdqu B3, [%1+30h]
%endmacro
%macro save_block_4 1
movdqu [%1+00h], B0
movdqu [%1+10h], B1
movdqu [%1+20h], B2
movdqu [%1+30h], B3
%endmacro
%macro aes_xts_process 2
; rcx = in, rdx = out, r8 = len, r9 = offset, [rsp+28h] = key
sub rsp, 58h
; save nonvolatile XMM registers
movaps [rsp+40h], xmm6
movaps [rsp+30h], xmm7
movaps [rsp+20h], xmm8
movaps [rsp+10h], xmm9
movaps [rsp+00h], xmm10
; load XTS tweak polynomial
mov eax, 135
movd POLY, eax
; load pointers of keys
mov rax, [rsp+28h+58h]
lea r11, [rax+tweak_k] ; r11 - tweak key
%if %2 != 0
add rax, %2 ; rax - encryption key
%endif
shr r9, 9 ; idx = offset / XTS_SECTOR_SIZE
shr r8, 9 ; len /= XTS_SECTOR_SIZE
%%xts_loop:
inc r9 ; idx++
movq T0, r9
aes_encrypt_1 T0, r11
mov r10d, 8 ; XTS_BLOCKS_IN_SECTOR / 4
%%blocks_loop:
; calc tweaks
next_tweak T1, T0
next_tweak T2, T1
next_tweak T3, T2
; load blocks
load_block_4 rcx
add rcx, 64 ; in += XTS_BLOCK_SIZE*4
align 16
; input tweak
tweak_block_4
; encrypt / decrypt
%1 B0, B1, B2, B3, rax
; output tweak
tweak_block_4
; save blocks
save_block_4 rdx
dec r10d
jz %%block_done
next_tweak T0, T3
add rdx, 64 ; out += XTS_BLOCK_SIZE*4
jmp %%blocks_loop
%%block_done:
add rdx, 64 ; out += XTS_BLOCK_SIZE*4
dec r8
jnz %%xts_loop
; restore nonvolatile XMM registers
movaps xmm6, [rsp+40h]
movaps xmm7, [rsp+30h]
movaps xmm8, [rsp+20h]
movaps xmm9, [rsp+10h]
movaps xmm10, [rsp+00h]
add rsp, 58h
ret
%endmacro
%define B0 xmm0
%define B1 xmm1
%define B2 xmm2
%define B3 xmm3
%define T0 xmm4
%define T1 xmm5
%define T2 xmm6
%define T3 xmm7
%define tt xmm8
%define t2 xmm9
%define POLY xmm10
%define tweak_k 5264
%define enc_key 0
%define dec_key 4*15*4
global xts_aes_ni_encrypt
global xts_aes_ni_decrypt
xts_aes_ni_encrypt:
aes_xts_process aes_encrypt_4, enc_key
align 16
xts_aes_ni_decrypt:
aes_xts_process aes_decrypt_4, dec_key

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,86 @@
/*
*
* DiskCryptor - open source partition encryption tool
* Copyright (c) 2007
* ntldr <ntldr@diskcryptor.net> PGP key ID - 0x1B6A24550F33E44A
*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "crc32.h"
static const unsigned long crc32_tab[] = {
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
0x2d02ef8dL
};
unsigned long _stdcall crc32(const unsigned char *p, unsigned long len)
{
unsigned long i;
unsigned long crc = 0xFFFFFFFF;
for (i = 0; i < len; i++) {
crc = crc32_tab[(unsigned char)(crc ^ p[i])] ^ (crc >> 8);
}
return ~crc;
}

View File

@ -0,0 +1,6 @@
#ifndef _CRC32_H_
#define _CRC32_H_
unsigned long _stdcall crc32(const unsigned char *p, unsigned long len);
#endif

View File

@ -0,0 +1,368 @@
; ---------------------------------------------------------------------------
; Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.
; Copyright (c) 2010, ntldr <ntldr@diskcryptor.net> PGP key ID - 0x1B6A24550F33E44A
;
; LICENSE TERMS
;
; The redistribution and use of this software (with or without changes)
; is allowed without the payment of fees or royalties provided that:
;
; 1. source code distributions include the above copyright notice, this
; list of conditions and the following disclaimer;
;
; 2. binary distributions include the above copyright notice, this list
; of conditions and the following disclaimer in their documentation;
;
; 3. the name of the copyright holder is not used to endorse products
; built using this software without specific written permission.
;
; DISCLAIMER
;
; This software is provided 'as is' with no explicit or implied warranties
; in respect of its properties, including, but not limited to, correctness
; and/or fitness for purpose.
; ---------------------------------------------------------------------------
; offsets to parameters
in_blk equ 4 ; input byte array address parameter
out_blk equ 8 ; output byte array address parameter
stk_spc equ 16 ; stack space
parms equ 12 ; parameter space on stack
extern _Te0, _Te1, _Te2, _Te3, _Te4_0, _Te4_1, _Te4_2, _Te4_3
extern _Td0, _Td1, _Td2, _Td3, _Td4_0, _Td4_1, _Td4_2, _Td4_3
extern _aes256_set_key@8
global _aes256_asm_set_key@8
global _aes256_asm_encrypt@12
global _aes256_asm_decrypt@12
; ROUND FUNCTION. Build column[2] on ESI and column[3] on EDI that have the
; round keys pre-loaded. Build column[0] in EBP and column[1] in EBX.
;
; Input:
;
; EAX column[0]
; EBX column[1]
; ECX column[2]
; EDX column[3]
; ESI column key[round][2]
; EDI column key[round][3]
; EBP scratch
;
; Output:
;
; EBP column[0] unkeyed
; EBX column[1] unkeyed
; ESI column[2] keyed
; EDI column[3] keyed
; EAX scratch
; ECX scratch
; EDX scratch
%macro rnd_fun 2
rol ebx,16
%1 esi, cl, 0, ebp
%1 esi, dh, 1, ebp
%1 esi, bh, 3, ebp
%1 edi, dl, 0, ebp
%1 edi, ah, 1, ebp
%1 edi, bl, 2, ebp
%2 ebp, al, 0, ebp
shr ebx,16
and eax,0xffff0000
or eax,ebx
shr edx,16
%1 ebp, ah, 1, ebx
%1 ebp, dh, 3, ebx
%2 ebx, dl, 2, ebx
%1 ebx, ch, 1, edx
%1 ebx, al, 0, edx
shr eax,16
shr ecx,16
%1 ebp, cl, 2, edx
%1 edi, ch, 3, edx
%1 esi, al, 2, edx
%1 ebx, ah, 3, edx
%endmacro
; Basic MOV and XOR Operations for normal rounds
%macro nr_xor 4
movzx %4, %2
xor %1, [_Te%3+4*%4]
%endmacro
%macro nr_mov 4
movzx %4, %2
mov %1, [_Te%3+4*%4]
%endmacro
; Basic MOV and XOR Operations for last round
%macro lr_xor 4
movzx %4, %2
xor %1, [_Te4_%3+4*%4]
%endmacro
%macro lr_mov 4
movzx %4, %2
mov %1, [_Te4_%3+4*%4]
%endmacro
%macro enc_round 4
mov esi, %3
mov edi, %4
rnd_fun nr_xor, nr_mov
mov eax, ebp
mov ecx, esi
mov edx, edi
xor eax, %1
xor ebx, %2
%endmacro
%macro enc_last_round 4
mov esi, %3
mov edi, %4
rnd_fun lr_xor, lr_mov
mov eax, ebp
xor eax, %1
xor ebx, %2
%endmacro
%macro irn_fun 2
rol eax,16
%1 esi, cl, 0, ebp
%1 esi, bh, 1, ebp
%1 esi, al, 2, ebp
%1 edi, dl, 0, ebp
%1 edi, ch, 1, ebp
%1 edi, ah, 3, ebp
%2 ebp, bl, 0, ebp
shr eax,16
and ebx,0xffff0000
or ebx,eax
shr ecx,16
%1 ebp, bh, 1, eax
%1 ebp, ch, 3, eax
%2 eax, cl, 2, ecx
%1 eax, bl, 0, ecx
%1 eax, dh, 1, ecx
shr ebx,16
shr edx,16
%1 esi, dh, 3, ecx
%1 ebp, dl, 2, ecx
%1 eax, bh, 3, ecx
%1 edi, bl, 2, ecx
%endmacro
; Basic MOV and XOR Operations for normal rounds
%macro ni_xor 4
movzx %4, %2
xor %1, [_Td%3+4*%4]
%endmacro
%macro ni_mov 4
movzx %4, %2
mov %1, [_Td%3+4*%4]
%endmacro
; Basic MOV and XOR Operations for last round
%macro li_xor 4
movzx %4, %2
xor %1, [_Td4_%3+4*%4]
%endmacro
%macro li_mov 4
movzx %4, %2
mov %1, [_Td4_%3+4*%4]
%endmacro
%macro dec_round 4
mov esi, %3
mov edi, %4
irn_fun ni_xor, ni_mov
mov ebx, ebp
mov ecx, esi
mov edx, edi
xor eax, %1
xor ebx, %2
%endmacro
%macro dec_last_round 4
mov esi, %3
mov edi, %4
irn_fun li_xor, li_mov
mov ebx, ebp
xor eax, %1
xor ebx, %2
%endmacro
%assign i 0
%rep 60
RK_ %+ i equ (12340000h | i)
%assign i i+1
%endrep
section .text align=32
; AES Encryption Subroutine
aes256_encrypt_code:
sub esp, stk_spc
mov [esp+12], ebp
mov [esp+ 8], ebx
mov [esp+ 4], esi
mov [esp+ 0], edi
mov esi, [esp+in_blk+stk_spc] ; input pointer
mov eax, [esi+ 0]
mov ebx, [esi+ 4]
mov ecx, [esi+ 8]
mov edx, [esi+12]
xor eax, RK_0
xor ebx, RK_1
xor ecx, RK_2
xor edx, RK_3
enc_round RK_4, RK_5, RK_6, RK_7
enc_round RK_8, RK_9, RK_10, RK_11
enc_round RK_12, RK_13, RK_14, RK_15
enc_round RK_16, RK_17, RK_18, RK_19
enc_round RK_20, RK_21, RK_22, RK_23
enc_round RK_24, RK_25, RK_26, RK_27
enc_round RK_28, RK_29, RK_30, RK_31
enc_round RK_32, RK_33, RK_34, RK_35
enc_round RK_36, RK_37, RK_38, RK_39
enc_round RK_40, RK_41, RK_42, RK_43
enc_round RK_44, RK_45, RK_46, RK_47
enc_round RK_48, RK_49, RK_50, RK_51
enc_round RK_52, RK_53, RK_54, RK_55
enc_last_round RK_56, RK_57, RK_58, RK_59
mov edx, [esp+out_blk+stk_spc]
mov [edx+ 0], eax
mov [edx+ 4], ebx
mov [edx+ 8], esi
mov [edx+12], edi
mov ebp, [esp+12]
mov ebx, [esp+ 8]
mov esi, [esp+ 4]
mov edi, [esp+ 0]
add esp, stk_spc
retn 0Ch
aes256_encrypt_size equ $-aes256_encrypt_code
aes256_decrypt_code:
sub esp, stk_spc
mov [esp+12],ebp
mov [esp+ 8],ebx
mov [esp+ 4],esi
mov [esp+ 0],edi
; input four columns and xor in first round key
mov esi,[esp+in_blk+stk_spc] ; input pointer
mov eax,[esi ]
mov ebx,[esi+ 4]
mov ecx,[esi+ 8]
mov edx,[esi+12]
xor eax, RK_0
xor ebx, RK_1
xor ecx, RK_2
xor edx, RK_3
dec_round RK_4, RK_5, RK_6, RK_7
dec_round RK_8, RK_9, RK_10, RK_11
dec_round RK_12, RK_13, RK_14, RK_15
dec_round RK_16, RK_17, RK_18, RK_19
dec_round RK_20, RK_21, RK_22, RK_23
dec_round RK_24, RK_25, RK_26, RK_27
dec_round RK_28, RK_29, RK_30, RK_31
dec_round RK_32, RK_33, RK_34, RK_35
dec_round RK_36, RK_37, RK_38, RK_39
dec_round RK_40, RK_41, RK_42, RK_43
dec_round RK_44, RK_45, RK_46, RK_47
dec_round RK_48, RK_49, RK_50, RK_51
dec_round RK_52, RK_53, RK_54, RK_55
dec_last_round RK_56, RK_57, RK_58, RK_59
; move final values to the output array.
mov ebp,[esp+out_blk+stk_spc]
mov [ebp],eax
mov [ebp+4],ebx
mov [ebp+8],esi
mov [ebp+12],edi
mov ebp,[esp+12]
mov ebx,[esp+ 8]
mov esi,[esp+ 4]
mov edi,[esp+ 0]
add esp,stk_spc
retn 0Ch
aes256_decrypt_size equ $-aes256_decrypt_code
align 32
_aes256_asm_encrypt@12:
mov eax, [esp+12] ; key
add eax, 480 ; ek_code
jmp eax
align 32
_aes256_asm_decrypt@12:
mov eax, [esp+12] ; key
add eax, 3552 ; dk_code
jmp eax
aes256_patch_code: ; ebp - round keys, ebx - code buff, ecx - code size
pushad
sub ecx, 4
patch_loop:
mov eax, [ebx]
mov edx, eax
shr edx, 16
cmp edx, 1234h
jnz no_patch
movzx edx, ax
mov eax, [ebp+edx*4]
mov [ebx], eax
no_patch:
inc ebx
loop patch_loop
popad
retn
_aes256_asm_set_key@8:
pushad
mov ebp, [esp+28h] ; skey
mov eax, [esp+24h] ; key
push ebp
push eax
call _aes256_set_key@8
lea ebx, [ebp+480] ; ek_code
mov esi, aes256_encrypt_code
mov edi, ebx
mov ecx, aes256_encrypt_size
push ecx
rep movsb
pop ecx
call aes256_patch_code
lea ebx, [ebp+3552] ; dk_code
add ebp, 240 ; dec_key
mov esi, aes256_decrypt_code
mov edi, ebx
mov ecx, aes256_decrypt_size
push ecx
rep movsb
pop ecx
call aes256_patch_code
popad
retn 08h

View File

@ -0,0 +1,93 @@
;
; *
; * Copyright (c) 2009-2010
; * ntldr <ntldr@diskcryptor.net> PGP key ID - 0x1B6A24550F33E44A
; *
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License version 3 as
; published by the Free Software Foundation.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
;
%define NEH_LOAD_KEY 00000080h ; load schedule from memory
%define NEH_ENCRYPT 00000000h ; encryption
%define NEH_DECRYPT 00000200h ; decryption
%define NEH_KEY128 00000000h+0ah ; 128 bit key
%define NEH_KEY192 00000400h+0ch ; 192 bit key
%define NEH_KEY256 00000800h+0eh ; 256 bit key
%define NEH_ENC_LOAD (NEH_ENCRYPT | NEH_LOAD_KEY)
%define NEH_DEC_LOAD (NEH_DECRYPT | NEH_LOAD_KEY)
align 16
enc_cwd dd (NEH_ENC_LOAD | NEH_KEY256), 0, 0
align 16
dec_cwd dd (NEH_DEC_LOAD | NEH_KEY256), 0, 0
global _aes256_padlock_available@0
global _aes256_padlock_encrypt@16
global _aes256_padlock_decrypt@16
_aes256_padlock_available@0:
push ebx
; test for VIA CPU
mov eax, 0C0000000h
cpuid
cmp eax, 0C0000001h
jb no_ace
; read VIA flags
mov eax, 0C0000001h
cpuid
and edx, 0C0h ; ACE_MASK,CPUID EDX code for ACE
cmp edx, 0C0h ; ACE_MASK,CPUID EDX code for ACE
jnz no_ace
; ACE present
xor eax, eax
inc eax
jmp end_ace
no_ace:
xor eax, eax
end_ace:
pop ebx
ret
align 16
_aes256_padlock_encrypt@16:
push ebx
push esi
push edi
mov esi, [esp+10h] ; in
mov edi, [esp+14h] ; out
mov ecx, [esp+18h] ; n_blocks
mov ebx, [esp+1Ch] ; key
mov edx, enc_cwd
xcryptecb
pop edi
pop esi
pop ebx
retn 10h
align 16
_aes256_padlock_decrypt@16
push ebx
push esi
push edi
mov esi, [esp+10h] ; in
mov edi, [esp+14h] ; out
mov ecx, [esp+18h] ; n_blocks
mov ebx, [esp+1Ch] ; key
add ebx, 4*15*4
mov edx, dec_cwd
xcryptecb
pop edi
pop esi
pop ebx
retn 10h

View File

@ -0,0 +1,321 @@
;***************************************************************************
;* Copyright (C) 2006 by Joachim Fritschi, <jfritschi@freenet.de> *
;* adapted for DiskCryptor by ntldr <ntldr@diskcryptor.net> *
;* PGP key ID - 0x1B6A24550F33E44A *
;* *
;* This program is free software; you can redistribute it and/or modify *
;* it under the terms of the GNU General Public License as published by *
;* the Free Software Foundation; either version 2 of the License, or *
;* (at your option) any later version. *
;* *
;* This program is distributed in the hope that it will be useful, *
;* but WITHOUT ANY WARRANTY; without even the implied warranty of *
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
;* GNU General Public License for more details. *
;* *
;* You should have received a copy of the GNU General Public License *
;* along with this program; if not, write to the *
;* Free Software Foundation, Inc., *
;* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
;***************************************************************************
%define in_blk 4 ; input byte array address parameter
%define out_blk 8 ; output byte array address parameter
%define tfm 12 ; Twofish context structure
%define a_offset 0
%define b_offset 4
%define c_offset 8
%define d_offset 12
; Structure of the crypto context struct
%define s0 0 ; S0 Array 256 Words each
%define s1 1024 ; S1 Array
%define s2 2048 ; S2 Array
%define s3 3072 ; S3 Array
%define w 4096 ; 8 whitening keys (word)
%define k 4128 ; key 1-32 ( word )
; define a few register aliases to allow macro substitution
%define R0D eax
%define R0B al
%define R0H ah
%define R1D ebx
%define R1B bl
%define R1H bh
%define R2D ecx
%define R2B cl
%define R2H ch
%define R3D edx
%define R3B dl
%define R3H dh
; performs input whitening
%macro input_whitening 3
xor %1, [w+(%2)+%3]
%endmacro
; performs input whitening
%macro output_whitening 3
xor %1, [w+16+(%2)+%3]
%endmacro
;
; * a input register containing a (rotated 16)
; * b input register containing b
; * c input register containing c
; * d input register containing d (already rol $1)
; * operations on a and b are interleaved to increase performance
%macro encrypt_round 5
push %4D
movzx edi, %2B
mov %4D, [ebp+edi*4+s1]
movzx edi, %1B
mov esi, [ebp+edi*4+s2]
movzx edi, %2H
ror %2D, 16
xor %4D, [ebp+edi*4+s2]
movzx edi, %1H
ror %1D, 16
xor esi, [ebp+edi*4+s3]
movzx edi, %2B
xor %4D, [ebp+edi*4+s3]
movzx edi, %1B
xor esi, [ebp+edi*4]
movzx edi, %2H
ror %2D, 15
xor %4D, [ebp+edi*4]
movzx edi, %1H
xor esi, [ebp+edi*4+s1]
pop edi
add esi, %4D
add %4D, esi
add esi, [ebp+k+%5]
xor %3D, esi
rol %3D, 15
add %4D, [ebp+k+4+%5]
xor %4D, edi
%endmacro
; * a input register containing a (rotated 16)
; * b input register containing b
; * c input register containing c
; * d input register containing d (already rol $1)
; * operations on a and b are interleaved to increase performance
; * last round has different rotations for the output preparation
%macro encrypt_last_round 5
push %4D
movzx edi, %2B
mov %4D, [ebp+edi*4+s1]
movzx edi, %1B
mov esi, [ebp+edi*4+s2]
movzx edi, %2H
ror %2D, 16
xor %4D, [ebp+edi*4+s2]
movzx edi, %1H
ror %1D, 16
xor esi, [ebp+edi*4+s3]
movzx edi, %2B
xor %4D, [ebp+edi*4+s3]
movzx edi, %1B
xor esi, [ebp+edi*4]
movzx edi, %2H
ror %2D, 16
xor %4D, [ebp+edi*4]
movzx edi, %1H
xor esi, [ebp+edi*4+s1]
pop edi
add esi, %4D
add %4D, esi
add esi, [ebp+k+%5]
xor %3D, esi
ror %3D, 1
add %4D, [ebp+k+4+%5]
xor %4D, edi
%endmacro
; * a input register containing a
; * b input register containing b (rotated 16)
; * c input register containing c
; * d input register containing d (already rol $1)
; * operations on a and b are interleaved to increase performance
%macro decrypt_round 5
push %3D
movzx edi, %1B
mov %3D, [ebp+edi*4]
movzx edi, %2B
mov esi, [ebp+edi*4+s3]
movzx edi, %1H
ror %1D, 16
xor %3D, [ebp+edi*4+s1]
movzx edi, %2H
ror %2D, 16
xor esi, [ebp+edi*4]
movzx edi, %1B
xor %3D, [ebp+edi*4+s2]
movzx edi, %2B
xor esi, [ebp+edi*4+s1]
movzx edi, %1H
ror %1D, 15
xor %3D, [ebp+edi*4+s3]
movzx edi, %2H
xor esi, [ebp+edi*4+s2]
pop edi
add %3D, esi
add esi, %3D
add %3D, [ebp+k+%5]
xor %3D, edi
add esi, [ebp+k+4+%5]
xor %4D, esi
rol %4D, 15
%endmacro
; * a input register containing a
; * b input register containing b (rotated 16)
; * c input register containing c
; * d input register containing d (already rol $1)
; * operations on a and b are interleaved to increase performance
; * last round has different rotations for the output preparation
%macro decrypt_last_round 5
push %3D
movzx edi, %1B
mov %3D, [ebp+edi*4]
movzx edi, %2B
mov esi, [ebp+edi*4+s3]
movzx edi, %1H
ror %1D, 16
xor %3D, [ebp+edi*4+s1]
movzx edi, %2H
ror %2D, 16
xor esi, [ebp+edi*4]
movzx edi, %1B
xor %3D, [ebp+edi*4+s2]
movzx edi, %2B
xor esi, [ebp+edi*4+s1]
movzx edi, %1H
ror %1D, 16
xor %3D, [ebp+edi*4+s3]
movzx edi, %2H
xor esi, [ebp+edi*4+s2]
pop edi
add %3D, esi
add esi, %3D
add %3D, [ebp+k+%5]
xor %3D, edi
add esi, [ebp+k+4+%5]
xor %4D, esi
ror %4D, 1
%endmacro
global _twofish256_encrypt@12
global _twofish256_decrypt@12
_twofish256_encrypt@12:
push ebp ; save registers according to calling convention
push ebx
push esi
push edi
mov ebp, [tfm + 16+esp] ; abuse the base pointer: set new base bointer to the crypto tfm
mov edi, [in_blk+16+esp] ; input adress in edi
mov eax, [edi]
mov ebx, [b_offset+edi]
mov ecx, [c_offset+edi]
mov edx, [d_offset+edi]
input_whitening eax, ebp, a_offset
ror eax, 16
input_whitening ebx, ebp, b_offset
input_whitening ecx, ebp, c_offset
input_whitening edx, ebp, d_offset
rol edx, 1
encrypt_round R0,R1,R2,R3,0
encrypt_round R2,R3,R0,R1,8
encrypt_round R0,R1,R2,R3,2*8
encrypt_round R2,R3,R0,R1,3*8
encrypt_round R0,R1,R2,R3,4*8
encrypt_round R2,R3,R0,R1,5*8
encrypt_round R0,R1,R2,R3,6*8
encrypt_round R2,R3,R0,R1,7*8
encrypt_round R0,R1,R2,R3,8*8
encrypt_round R2,R3,R0,R1,9*8
encrypt_round R0,R1,R2,R3,10*8
encrypt_round R2,R3,R0,R1,11*8
encrypt_round R0,R1,R2,R3,12*8
encrypt_round R2,R3,R0,R1,13*8
encrypt_round R0,R1,R2,R3,14*8
encrypt_last_round R2,R3,R0,R1,15*8
output_whitening eax, ebp, c_offset
output_whitening ebx, ebp, d_offset
output_whitening ecx, ebp, a_offset
output_whitening edx, ebp, b_offset
mov edi, [out_blk+16+esp]
mov [c_offset+edi], eax
mov [d_offset+edi], ebx
mov [edi], ecx
mov [b_offset+edi], edx
pop edi
pop esi
pop ebx
pop ebp
retn 0Ch
_twofish256_decrypt@12:
push ebp ; save registers according to calling convention*/
push ebx
push esi
push edi
mov ebp, [tfm + 16+esp] ; abuse the base pointer: set new base bointer to the crypto tfm
mov edi, [in_blk + 16+esp] ; input adress in edi
mov eax, [edi]
mov ebx, [b_offset+edi]
mov ecx, [c_offset+edi]
mov edx, [d_offset+edi]
output_whitening eax, ebp, a_offset
output_whitening ebx, ebp, b_offset
ror ebx, 16
output_whitening ecx, ebp, c_offset
output_whitening edx, ebp, d_offset
rol ecx, 1
decrypt_round R0,R1,R2,R3,15*8
decrypt_round R2,R3,R0,R1,14*8
decrypt_round R0,R1,R2,R3,13*8
decrypt_round R2,R3,R0,R1,12*8
decrypt_round R0,R1,R2,R3,11*8
decrypt_round R2,R3,R0,R1,10*8
decrypt_round R0,R1,R2,R3,9*8
decrypt_round R2,R3,R0,R1,8*8
decrypt_round R0,R1,R2,R3,7*8
decrypt_round R2,R3,R0,R1,6*8
decrypt_round R0,R1,R2,R3,5*8
decrypt_round R2,R3,R0,R1,4*8
decrypt_round R0,R1,R2,R3,3*8
decrypt_round R2,R3,R0,R1,2*8
decrypt_round R0,R1,R2,R3,1*8
decrypt_last_round R2,R3,R0,R1,0
input_whitening eax, ebp, c_offset
input_whitening ebx, ebp, d_offset
input_whitening ecx, ebp, a_offset
input_whitening edx, ebp, b_offset
mov edi, [out_blk + 16+esp]
mov [c_offset+edi], eax
mov [d_offset+edi], ebx
mov [edi], ecx
mov [b_offset+edi], edx
pop edi
pop esi
pop ebx
pop ebp
retn 0Ch

View File

@ -0,0 +1,206 @@
;
; *
; * Copyright (c) 2010
; * ntldr <ntldr@diskcryptor.net> PGP key ID - 0x1B6A24550F33E44A
; *
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License version 3 as
; published by the Free Software Foundation.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
;
%macro aesxor_2 4 ; B0, B1, key, round
movdqa tt, [%3+(%4*10h)]
pxor %1, tt
pxor %2, tt
%endmacro
%macro aesenc_2 4 ; B0, B1, key, round
movdqa tt, [%3+(%4*10h)]
aesenc %1, tt
aesenc %2, tt
%endmacro
%macro aesdec_2 4 ; B0, B1, key, round
movdqa tt, [%3+(%4*10h)]
aesdec %1, tt
aesdec %2, tt
%endmacro
%macro aesenclast_2 4 ; B0, B1, key, round
movdqa tt, [%3+(%4*10h)]
aesenclast %1, tt
aesenclast %2, tt
%endmacro
%macro aesdeclast_2 4 ; B0, B1, key, round
movdqa tt, [%3+(%4*10h)]
aesdeclast %1, tt
aesdeclast %2, tt
%endmacro
%macro aes_encrypt_1 2 ; XMMn, key
pxor %1, [%2]
aesenc %1, [%2+010h]
aesenc %1, [%2+020h]
aesenc %1, [%2+030h]
aesenc %1, [%2+040h]
aesenc %1, [%2+050h]
aesenc %1, [%2+060h]
aesenc %1, [%2+070h]
aesenc %1, [%2+080h]
aesenc %1, [%2+090h]
aesenc %1, [%2+0A0h]
aesenc %1, [%2+0B0h]
aesenc %1, [%2+0C0h]
aesenc %1, [%2+0D0h]
aesenclast %1, [%2+0E0h]
%endmacro
%macro aes_encrypt_2 3 ; B0, B1, key
aesxor_2 %1, %2, %3, 0
aesenc_2 %1, %2, %3, 1
aesenc_2 %1, %2, %3, 2
aesenc_2 %1, %2, %3, 3
aesenc_2 %1, %2, %3, 4
aesenc_2 %1, %2, %3, 5
aesenc_2 %1, %2, %3, 6
aesenc_2 %1, %2, %3, 7
aesenc_2 %1, %2, %3, 8
aesenc_2 %1, %2, %3, 9
aesenc_2 %1, %2, %3, 10
aesenc_2 %1, %2, %3, 11
aesenc_2 %1, %2, %3, 12
aesenc_2 %1, %2, %3, 13
aesenclast_2 %1, %2, %3, 14
%endmacro
%macro aes_decrypt_2 3 ; B0, B1, key
aesxor_2 %1, %2, %3, 0
aesdec_2 %1, %2, %3, 1
aesdec_2 %1, %2, %3, 2
aesdec_2 %1, %2, %3, 3
aesdec_2 %1, %2, %3, 4
aesdec_2 %1, %2, %3, 5
aesdec_2 %1, %2, %3, 6
aesdec_2 %1, %2, %3, 7
aesdec_2 %1, %2, %3, 8
aesdec_2 %1, %2, %3, 9
aesdec_2 %1, %2, %3, 10
aesdec_2 %1, %2, %3, 11
aesdec_2 %1, %2, %3, 12
aesdec_2 %1, %2, %3, 13
aesdeclast_2 %1, %2, %3, 14
%endmacro
%macro next_tweak 2 ; new, old
movdqa tt, %2
psraw tt, 8
psrldq tt, 15
pand tt, POLY
movdqa t2, %2
pslldq t2, 8
psrldq t2, 7
psrlq t2, 7
movdqa %1, %2
psllq %1, 1
por %1, t2
pxor %1, tt
%endmacro
%macro aes_xts_process 2
push esi
push edi
; load XTS tweak polynomial
mov eax, 135
movd POLY, eax
mov eax, [esp+1Ch] ;
shrd [esp+18h], eax, 9 ; idx.a = offset / XTS_SECTOR_SIZE
shr eax, 9 ;
mov [esp+1Ch], eax ;
mov esi, [esp+0Ch] ; esi = in
mov edi, [esp+10h] ; edi = out
mov eax, [esp+20h] ; eax = crypt key
lea edx, [eax+tweak_k] ; edx = tweak key
%if %2 != 0
add eax, %2 ; eax = decryption key
%endif
%%xts_loop:
add dword [esp+18h], 1 ; idx.a++
adc dword [esp+1Ch], 0 ;
movq T0, [esp+18h]
aes_encrypt_1 T0, edx
mov ecx, 16 ; ecx = XTS_BLOCKS_IN_SECTOR
%%blocks_loop:
next_tweak T1, T0
; load two blocks
movdqu B0, [esi+00h]
movdqu B1, [esi+10h]
; input tweak
pxor B0, T0
pxor B1, T1
; encrypt / decrypt
%1 B0, B1, eax
; output tweak
pxor B0, T0
pxor B1, T1
; save two blocks
movdqu [edi+00h], B0
movdqu [edi+10h], B1
add esi, 32 ; in += XTS_BLOCK_SIZE*2
add edi, 32 ; out += XTS_BLOCK_SIZE*2
dec ecx
jz %%block_done
next_tweak T0, T1
jmp %%blocks_loop
%%block_done:
sub dword [esp+14h], 512 ; len -= XTS_SECTOR_SIZE
jnz %%xts_loop
pop edi
pop esi
retn 18h
%endmacro
; =========================================
%define B0 xmm0
%define B1 xmm1
%define T0 xmm2
%define T1 xmm3
%define tt xmm4
%define t2 xmm5
%define POLY xmm6
%define tweak_k 11408
%define enc_key 0
%define dec_key 4*15*4
; =========================================
global _xts_aes_ni_encrypt@24
global _xts_aes_ni_decrypt@24
align 16
_xts_aes_ni_encrypt@24:
aes_xts_process aes_encrypt_2, enc_key
align 16
_xts_aes_ni_decrypt@24:
aes_xts_process aes_decrypt_2, dec_key

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,424 @@
/*
* Cryptographic API.
*
* Serpent Cipher Algorithm.
*
* Copyright (C) 2002 Dag Arne Osvik <osvik@ii.uib.no>
* 2003 Herbert Valerio Riedel <hvr@gnu.org>
Wei Dai
*
* Added tnepres support: Ruben Jesus Garcia Hernandez <ruben@ugr.es>, 18.10.2004
* Based on code by hvr
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <memory.h>
#include <intrin.h>
#include "serpent.h"
/* Key is padded to the maximum of 256 bits before round key generation.
* Any key length <= 256 bits (32 bytes) is allowed by the algorithm.
*/
#define PHI 0x9e3779b9UL
#define keyiter(a,b,c,d,i,j) \
b ^= d; b ^= c; b ^= a; b ^= PHI ^ i; b = _rotl(b,11); k[j] = b;
#define loadkeys(x0,x1,x2,x3,i) \
x0=k[i]; x1=k[i+1]; x2=k[i+2]; x3=k[i+3];
#define storekeys(x0,x1,x2,x3,i) \
k[i]=x0; k[i+1]=x1; k[i+2]=x2; k[i+3]=x3;
#define K(x0,x1,x2,x3,i) \
x3 ^= k[4*(i)+3]; x2 ^= k[4*(i)+2]; \
x1 ^= k[4*(i)+1]; x0 ^= k[4*(i)+0];
#define LK(x0,x1,x2,x3,x4,i) \
x0=_rotl(x0,13);\
x2=_rotl(x2,3); x1 ^= x0; x4 = x0 << 3; \
x3 ^= x2; x1 ^= x2; \
x1=_rotl(x1,1); x3 ^= x4; \
x3=_rotl(x3,7); x4 = x1; \
x0 ^= x1; x4 <<= 7; x2 ^= x3; \
x0 ^= x3; x2 ^= x4; x3 ^= k[4*i+3]; \
x1 ^= k[4*i+1]; x0=_rotl(x0,5); x2=_rotl(x2,22);\
x0 ^= k[4*i+0]; x2 ^= k[4*i+2];
#define KL(x0,x1,x2,x3,x4,i) \
x0 ^= k[4*i+0]; x1 ^= k[4*i+1]; x2 ^= k[4*i+2]; \
x3 ^= k[4*i+3]; x0=_rotr(x0,5); x2=_rotr(x2,22);\
x4 = x1; x2 ^= x3; x0 ^= x3; \
x4 <<= 7; x0 ^= x1; x1=_rotr(x1,1); \
x2 ^= x4; x3=_rotr(x3,7); x4 = x0 << 3; \
x1 ^= x0; x3 ^= x4; x0=_rotr(x0,13);\
x1 ^= x2; x3 ^= x2; x2=_rotr(x2,3);
#define S0(x0,x1,x2,x3,x4) \
x4 = x3; \
x3 |= x0; x0 ^= x4; x4 ^= x2; \
x4 =~ x4; x3 ^= x1; x1 &= x0; \
x1 ^= x4; x2 ^= x0; x0 ^= x3; \
x4 |= x0; x0 ^= x2; x2 &= x1; \
x3 ^= x2; x1 =~ x1; x2 ^= x4; \
x1 ^= x2;
#define S1(x0,x1,x2,x3,x4) \
x4 = x1; \
x1 ^= x0; x0 ^= x3; x3 =~ x3; \
x4 &= x1; x0 |= x1; x3 ^= x2; \
x0 ^= x3; x1 ^= x3; x3 ^= x4; \
x1 |= x4; x4 ^= x2; x2 &= x0; \
x2 ^= x1; x1 |= x0; x0 =~ x0; \
x0 ^= x2; x4 ^= x1;
#define S2(x0,x1,x2,x3,x4) \
x3 =~ x3; \
x1 ^= x0; x4 = x0; x0 &= x2; \
x0 ^= x3; x3 |= x4; x2 ^= x1; \
x3 ^= x1; x1 &= x0; x0 ^= x2; \
x2 &= x3; x3 |= x1; x0 =~ x0; \
x3 ^= x0; x4 ^= x0; x0 ^= x2; \
x1 |= x2;
#define S3(x0,x1,x2,x3,x4) \
x4 = x1; \
x1 ^= x3; x3 |= x0; x4 &= x0; \
x0 ^= x2; x2 ^= x1; x1 &= x3; \
x2 ^= x3; x0 |= x4; x4 ^= x3; \
x1 ^= x0; x0 &= x3; x3 &= x4; \
x3 ^= x2; x4 |= x1; x2 &= x1; \
x4 ^= x3; x0 ^= x3; x3 ^= x2;
#define S4(x0,x1,x2,x3,x4) \
x4 = x3; \
x3 &= x0; x0 ^= x4; \
x3 ^= x2; x2 |= x4; x0 ^= x1; \
x4 ^= x3; x2 |= x0; \
x2 ^= x1; x1 &= x0; \
x1 ^= x4; x4 &= x2; x2 ^= x3; \
x4 ^= x0; x3 |= x1; x1 =~ x1; \
x3 ^= x0;
#define S5(x0,x1,x2,x3,x4) \
x4 = x1; x1 |= x0; \
x2 ^= x1; x3 =~ x3; x4 ^= x0; \
x0 ^= x2; x1 &= x4; x4 |= x3; \
x4 ^= x0; x0 &= x3; x1 ^= x3; \
x3 ^= x2; x0 ^= x1; x2 &= x4; \
x1 ^= x2; x2 &= x0; \
x3 ^= x2;
#define S6(x0,x1,x2,x3,x4) \
x4 = x1; \
x3 ^= x0; x1 ^= x2; x2 ^= x0; \
x0 &= x3; x1 |= x3; x4 =~ x4; \
x0 ^= x1; x1 ^= x2; \
x3 ^= x4; x4 ^= x0; x2 &= x0; \
x4 ^= x1; x2 ^= x3; x3 &= x1; \
x3 ^= x0; x1 ^= x2;
#define S7(x0,x1,x2,x3,x4) \
x1 =~ x1; \
x4 = x1; x0 =~ x0; x1 &= x2; \
x1 ^= x3; x3 |= x4; x4 ^= x2; \
x2 ^= x3; x3 ^= x0; x0 |= x1; \
x2 &= x0; x0 ^= x4; x4 ^= x3; \
x3 &= x0; x4 ^= x1; \
x2 ^= x4; x3 ^= x1; x4 |= x0; \
x4 ^= x1;
#define SI0(x0,x1,x2,x3,x4) \
x4 = x3; x1 ^= x0; \
x3 |= x1; x4 ^= x1; x0 =~ x0; \
x2 ^= x3; x3 ^= x0; x0 &= x1; \
x0 ^= x2; x2 &= x3; x3 ^= x4; \
x2 ^= x3; x1 ^= x3; x3 &= x0; \
x1 ^= x0; x0 ^= x2; x4 ^= x3;
#define SI1(x0,x1,x2,x3,x4) \
x1 ^= x3; x4 = x0; \
x0 ^= x2; x2 =~ x2; x4 |= x1; \
x4 ^= x3; x3 &= x1; x1 ^= x2; \
x2 &= x4; x4 ^= x1; x1 |= x3; \
x3 ^= x0; x2 ^= x0; x0 |= x4; \
x2 ^= x4; x1 ^= x0; \
x4 ^= x1;
#define SI2(x0,x1,x2,x3,x4) \
x2 ^= x1; x4 = x3; x3 =~ x3; \
x3 |= x2; x2 ^= x4; x4 ^= x0; \
x3 ^= x1; x1 |= x2; x2 ^= x0; \
x1 ^= x4; x4 |= x3; x2 ^= x3; \
x4 ^= x2; x2 &= x1; \
x2 ^= x3; x3 ^= x4; x4 ^= x0;
#define SI3(x0,x1,x2,x3,x4) \
x2 ^= x1; \
x4 = x1; x1 &= x2; \
x1 ^= x0; x0 |= x4; x4 ^= x3; \
x0 ^= x3; x3 |= x1; x1 ^= x2; \
x1 ^= x3; x0 ^= x2; x2 ^= x3; \
x3 &= x1; x1 ^= x0; x0 &= x2; \
x4 ^= x3; x3 ^= x0; x0 ^= x1;
#define SI4(x0,x1,x2,x3,x4) \
x2 ^= x3; x4 = x0; x0 &= x1; \
x0 ^= x2; x2 |= x3; x4 =~ x4; \
x1 ^= x0; x0 ^= x2; x2 &= x4; \
x2 ^= x0; x0 |= x4; \
x0 ^= x3; x3 &= x2; \
x4 ^= x3; x3 ^= x1; x1 &= x0; \
x4 ^= x1; x0 ^= x3;
#define SI5(x0,x1,x2,x3,x4) \
x4 = x1; x1 |= x2; \
x2 ^= x4; x1 ^= x3; x3 &= x4; \
x2 ^= x3; x3 |= x0; x0 =~ x0; \
x3 ^= x2; x2 |= x0; x4 ^= x1; \
x2 ^= x4; x4 &= x0; x0 ^= x1; \
x1 ^= x3; x0 &= x2; x2 ^= x3; \
x0 ^= x2; x2 ^= x4; x4 ^= x3;
#define SI6(x0,x1,x2,x3,x4) \
x0 ^= x2; \
x4 = x0; x0 &= x3; x2 ^= x3; \
x0 ^= x2; x3 ^= x1; x2 |= x4; \
x2 ^= x3; x3 &= x0; x0 =~ x0; \
x3 ^= x1; x1 &= x2; x4 ^= x0; \
x3 ^= x4; x4 ^= x2; x0 ^= x1; \
x2 ^= x0;
#define SI7(x0,x1,x2,x3,x4) \
x4 = x3; x3 &= x0; x0 ^= x2; \
x2 |= x4; x4 ^= x1; x0 =~ x0; \
x1 |= x3; x4 ^= x0; x0 &= x2; \
x0 ^= x1; x1 &= x2; x3 ^= x2; \
x4 ^= x3; x2 &= x3; x3 |= x0; \
x1 ^= x4; x3 ^= x4; x4 &= x0; \
x4 ^= x2;
void _stdcall serpent256_set_key(const unsigned char *key, serpent256_key *skey)
{
unsigned long *k = skey->expkey;
unsigned long r0,r1,r2,r3,r4;
/* Copy key, add padding */
memcpy(k, key, SERPENT_KEY_SIZE);
/* Expand key using polynomial */
r0 = k[3]; r1 = k[4]; r2 = k[5];
r3 = k[6]; r4 = k[7];
keyiter(k[0],r0,r4,r2,0,0);
keyiter(k[1],r1,r0,r3,1,1);
keyiter(k[2],r2,r1,r4,2,2);
keyiter(k[3],r3,r2,r0,3,3);
keyiter(k[4],r4,r3,r1,4,4);
keyiter(k[5],r0,r4,r2,5,5);
keyiter(k[6],r1,r0,r3,6,6);
keyiter(k[7],r2,r1,r4,7,7);
keyiter(k[ 0],r3,r2,r0, 8, 8); keyiter(k[ 1],r4,r3,r1, 9, 9);
keyiter(k[ 2],r0,r4,r2, 10, 10); keyiter(k[ 3],r1,r0,r3, 11, 11);
keyiter(k[ 4],r2,r1,r4, 12, 12); keyiter(k[ 5],r3,r2,r0, 13, 13);
keyiter(k[ 6],r4,r3,r1, 14, 14); keyiter(k[ 7],r0,r4,r2, 15, 15);
keyiter(k[ 8],r1,r0,r3, 16, 16); keyiter(k[ 9],r2,r1,r4, 17, 17);
keyiter(k[ 10],r3,r2,r0, 18, 18); keyiter(k[ 11],r4,r3,r1, 19, 19);
keyiter(k[ 12],r0,r4,r2, 20, 20); keyiter(k[ 13],r1,r0,r3, 21, 21);
keyiter(k[ 14],r2,r1,r4, 22, 22); keyiter(k[ 15],r3,r2,r0, 23, 23);
keyiter(k[ 16],r4,r3,r1, 24, 24); keyiter(k[ 17],r0,r4,r2, 25, 25);
keyiter(k[ 18],r1,r0,r3, 26, 26); keyiter(k[ 19],r2,r1,r4, 27, 27);
keyiter(k[ 20],r3,r2,r0, 28, 28); keyiter(k[ 21],r4,r3,r1, 29, 29);
keyiter(k[ 22],r0,r4,r2, 30, 30); keyiter(k[ 23],r1,r0,r3, 31, 31);
k += 50;
keyiter(k[-26],r2,r1,r4, 32,-18); keyiter(k[-25],r3,r2,r0, 33,-17);
keyiter(k[-24],r4,r3,r1, 34,-16); keyiter(k[-23],r0,r4,r2, 35,-15);
keyiter(k[-22],r1,r0,r3, 36,-14); keyiter(k[-21],r2,r1,r4, 37,-13);
keyiter(k[-20],r3,r2,r0, 38,-12); keyiter(k[-19],r4,r3,r1, 39,-11);
keyiter(k[-18],r0,r4,r2, 40,-10); keyiter(k[-17],r1,r0,r3, 41, -9);
keyiter(k[-16],r2,r1,r4, 42, -8); keyiter(k[-15],r3,r2,r0, 43, -7);
keyiter(k[-14],r4,r3,r1, 44, -6); keyiter(k[-13],r0,r4,r2, 45, -5);
keyiter(k[-12],r1,r0,r3, 46, -4); keyiter(k[-11],r2,r1,r4, 47, -3);
keyiter(k[-10],r3,r2,r0, 48, -2); keyiter(k[ -9],r4,r3,r1, 49, -1);
keyiter(k[ -8],r0,r4,r2, 50, 0); keyiter(k[ -7],r1,r0,r3, 51, 1);
keyiter(k[ -6],r2,r1,r4, 52, 2); keyiter(k[ -5],r3,r2,r0, 53, 3);
keyiter(k[ -4],r4,r3,r1, 54, 4); keyiter(k[ -3],r0,r4,r2, 55, 5);
keyiter(k[ -2],r1,r0,r3, 56, 6); keyiter(k[ -1],r2,r1,r4, 57, 7);
keyiter(k[ 0],r3,r2,r0, 58, 8); keyiter(k[ 1],r4,r3,r1, 59, 9);
keyiter(k[ 2],r0,r4,r2, 60, 10); keyiter(k[ 3],r1,r0,r3, 61, 11);
keyiter(k[ 4],r2,r1,r4, 62, 12); keyiter(k[ 5],r3,r2,r0, 63, 13);
keyiter(k[ 6],r4,r3,r1, 64, 14); keyiter(k[ 7],r0,r4,r2, 65, 15);
keyiter(k[ 8],r1,r0,r3, 66, 16); keyiter(k[ 9],r2,r1,r4, 67, 17);
keyiter(k[ 10],r3,r2,r0, 68, 18); keyiter(k[ 11],r4,r3,r1, 69, 19);
keyiter(k[ 12],r0,r4,r2, 70, 20); keyiter(k[ 13],r1,r0,r3, 71, 21);
keyiter(k[ 14],r2,r1,r4, 72, 22); keyiter(k[ 15],r3,r2,r0, 73, 23);
keyiter(k[ 16],r4,r3,r1, 74, 24); keyiter(k[ 17],r0,r4,r2, 75, 25);
keyiter(k[ 18],r1,r0,r3, 76, 26); keyiter(k[ 19],r2,r1,r4, 77, 27);
keyiter(k[ 20],r3,r2,r0, 78, 28); keyiter(k[ 21],r4,r3,r1, 79, 29);
keyiter(k[ 22],r0,r4,r2, 80, 30); keyiter(k[ 23],r1,r0,r3, 81, 31);
k += 50;
keyiter(k[-26],r2,r1,r4, 82,-18); keyiter(k[-25],r3,r2,r0, 83,-17);
keyiter(k[-24],r4,r3,r1, 84,-16); keyiter(k[-23],r0,r4,r2, 85,-15);
keyiter(k[-22],r1,r0,r3, 86,-14); keyiter(k[-21],r2,r1,r4, 87,-13);
keyiter(k[-20],r3,r2,r0, 88,-12); keyiter(k[-19],r4,r3,r1, 89,-11);
keyiter(k[-18],r0,r4,r2, 90,-10); keyiter(k[-17],r1,r0,r3, 91, -9);
keyiter(k[-16],r2,r1,r4, 92, -8); keyiter(k[-15],r3,r2,r0, 93, -7);
keyiter(k[-14],r4,r3,r1, 94, -6); keyiter(k[-13],r0,r4,r2, 95, -5);
keyiter(k[-12],r1,r0,r3, 96, -4); keyiter(k[-11],r2,r1,r4, 97, -3);
keyiter(k[-10],r3,r2,r0, 98, -2); keyiter(k[ -9],r4,r3,r1, 99, -1);
keyiter(k[ -8],r0,r4,r2,100, 0); keyiter(k[ -7],r1,r0,r3,101, 1);
keyiter(k[ -6],r2,r1,r4,102, 2); keyiter(k[ -5],r3,r2,r0,103, 3);
keyiter(k[ -4],r4,r3,r1,104, 4); keyiter(k[ -3],r0,r4,r2,105, 5);
keyiter(k[ -2],r1,r0,r3,106, 6); keyiter(k[ -1],r2,r1,r4,107, 7);
keyiter(k[ 0],r3,r2,r0,108, 8); keyiter(k[ 1],r4,r3,r1,109, 9);
keyiter(k[ 2],r0,r4,r2,110, 10); keyiter(k[ 3],r1,r0,r3,111, 11);
keyiter(k[ 4],r2,r1,r4,112, 12); keyiter(k[ 5],r3,r2,r0,113, 13);
keyiter(k[ 6],r4,r3,r1,114, 14); keyiter(k[ 7],r0,r4,r2,115, 15);
keyiter(k[ 8],r1,r0,r3,116, 16); keyiter(k[ 9],r2,r1,r4,117, 17);
keyiter(k[ 10],r3,r2,r0,118, 18); keyiter(k[ 11],r4,r3,r1,119, 19);
keyiter(k[ 12],r0,r4,r2,120, 20); keyiter(k[ 13],r1,r0,r3,121, 21);
keyiter(k[ 14],r2,r1,r4,122, 22); keyiter(k[ 15],r3,r2,r0,123, 23);
keyiter(k[ 16],r4,r3,r1,124, 24); keyiter(k[ 17],r0,r4,r2,125, 25);
keyiter(k[ 18],r1,r0,r3,126, 26); keyiter(k[ 19],r2,r1,r4,127, 27);
keyiter(k[ 20],r3,r2,r0,128, 28); keyiter(k[ 21],r4,r3,r1,129, 29);
keyiter(k[ 22],r0,r4,r2,130, 30); keyiter(k[ 23],r1,r0,r3,131, 31);
/* Apply S-boxes */
S3(r3,r4,r0,r1,r2); storekeys(r1,r2,r4,r3, 28); loadkeys(r1,r2,r4,r3, 24);
S4(r1,r2,r4,r3,r0); storekeys(r2,r4,r3,r0, 24); loadkeys(r2,r4,r3,r0, 20);
S5(r2,r4,r3,r0,r1); storekeys(r1,r2,r4,r0, 20); loadkeys(r1,r2,r4,r0, 16);
S6(r1,r2,r4,r0,r3); storekeys(r4,r3,r2,r0, 16); loadkeys(r4,r3,r2,r0, 12);
S7(r4,r3,r2,r0,r1); storekeys(r1,r2,r0,r4, 12); loadkeys(r1,r2,r0,r4, 8);
S0(r1,r2,r0,r4,r3); storekeys(r0,r2,r4,r1, 8); loadkeys(r0,r2,r4,r1, 4);
S1(r0,r2,r4,r1,r3); storekeys(r3,r4,r1,r0, 4); loadkeys(r3,r4,r1,r0, 0);
S2(r3,r4,r1,r0,r2); storekeys(r2,r4,r3,r0, 0); loadkeys(r2,r4,r3,r0, -4);
S3(r2,r4,r3,r0,r1); storekeys(r0,r1,r4,r2, -4); loadkeys(r0,r1,r4,r2, -8);
S4(r0,r1,r4,r2,r3); storekeys(r1,r4,r2,r3, -8); loadkeys(r1,r4,r2,r3,-12);
S5(r1,r4,r2,r3,r0); storekeys(r0,r1,r4,r3,-12); loadkeys(r0,r1,r4,r3,-16);
S6(r0,r1,r4,r3,r2); storekeys(r4,r2,r1,r3,-16); loadkeys(r4,r2,r1,r3,-20);
S7(r4,r2,r1,r3,r0); storekeys(r0,r1,r3,r4,-20); loadkeys(r0,r1,r3,r4,-24);
S0(r0,r1,r3,r4,r2); storekeys(r3,r1,r4,r0,-24); loadkeys(r3,r1,r4,r0,-28);
k -= 50;
S1(r3,r1,r4,r0,r2); storekeys(r2,r4,r0,r3, 22); loadkeys(r2,r4,r0,r3, 18);
S2(r2,r4,r0,r3,r1); storekeys(r1,r4,r2,r3, 18); loadkeys(r1,r4,r2,r3, 14);
S3(r1,r4,r2,r3,r0); storekeys(r3,r0,r4,r1, 14); loadkeys(r3,r0,r4,r1, 10);
S4(r3,r0,r4,r1,r2); storekeys(r0,r4,r1,r2, 10); loadkeys(r0,r4,r1,r2, 6);
S5(r0,r4,r1,r2,r3); storekeys(r3,r0,r4,r2, 6); loadkeys(r3,r0,r4,r2, 2);
S6(r3,r0,r4,r2,r1); storekeys(r4,r1,r0,r2, 2); loadkeys(r4,r1,r0,r2, -2);
S7(r4,r1,r0,r2,r3); storekeys(r3,r0,r2,r4, -2); loadkeys(r3,r0,r2,r4, -6);
S0(r3,r0,r2,r4,r1); storekeys(r2,r0,r4,r3, -6); loadkeys(r2,r0,r4,r3,-10);
S1(r2,r0,r4,r3,r1); storekeys(r1,r4,r3,r2,-10); loadkeys(r1,r4,r3,r2,-14);
S2(r1,r4,r3,r2,r0); storekeys(r0,r4,r1,r2,-14); loadkeys(r0,r4,r1,r2,-18);
S3(r0,r4,r1,r2,r3); storekeys(r2,r3,r4,r0,-18); loadkeys(r2,r3,r4,r0,-22);
k -= 50;
S4(r2,r3,r4,r0,r1); storekeys(r3,r4,r0,r1, 28); loadkeys(r3,r4,r0,r1, 24);
S5(r3,r4,r0,r1,r2); storekeys(r2,r3,r4,r1, 24); loadkeys(r2,r3,r4,r1, 20);
S6(r2,r3,r4,r1,r0); storekeys(r4,r0,r3,r1, 20); loadkeys(r4,r0,r3,r1, 16);
S7(r4,r0,r3,r1,r2); storekeys(r2,r3,r1,r4, 16); loadkeys(r2,r3,r1,r4, 12);
S0(r2,r3,r1,r4,r0); storekeys(r1,r3,r4,r2, 12); loadkeys(r1,r3,r4,r2, 8);
S1(r1,r3,r4,r2,r0); storekeys(r0,r4,r2,r1, 8); loadkeys(r0,r4,r2,r1, 4);
S2(r0,r4,r2,r1,r3); storekeys(r3,r4,r0,r1, 4); loadkeys(r3,r4,r0,r1, 0);
S3(r3,r4,r0,r1,r2); storekeys(r1,r2,r4,r3, 0);
}
void _stdcall serpent256_encrypt(const unsigned char *in, unsigned char *out, serpent256_key *key)
{
unsigned long *k = key->expkey;
unsigned long r0, r1, r2, r3, r4;
r0 = ((unsigned long*)in)[0]; r1 = ((unsigned long*)in)[1];
r2 = ((unsigned long*)in)[2]; r3 = ((unsigned long*)in)[3];
K(r0,r1,r2,r3,0);
S0(r0,r1,r2,r3,r4); LK(r2,r1,r3,r0,r4,1);
S1(r2,r1,r3,r0,r4); LK(r4,r3,r0,r2,r1,2);
S2(r4,r3,r0,r2,r1); LK(r1,r3,r4,r2,r0,3);
S3(r1,r3,r4,r2,r0); LK(r2,r0,r3,r1,r4,4);
S4(r2,r0,r3,r1,r4); LK(r0,r3,r1,r4,r2,5);
S5(r0,r3,r1,r4,r2); LK(r2,r0,r3,r4,r1,6);
S6(r2,r0,r3,r4,r1); LK(r3,r1,r0,r4,r2,7);
S7(r3,r1,r0,r4,r2); LK(r2,r0,r4,r3,r1,8);
S0(r2,r0,r4,r3,r1); LK(r4,r0,r3,r2,r1,9);
S1(r4,r0,r3,r2,r1); LK(r1,r3,r2,r4,r0,10);
S2(r1,r3,r2,r4,r0); LK(r0,r3,r1,r4,r2,11);
S3(r0,r3,r1,r4,r2); LK(r4,r2,r3,r0,r1,12);
S4(r4,r2,r3,r0,r1); LK(r2,r3,r0,r1,r4,13);
S5(r2,r3,r0,r1,r4); LK(r4,r2,r3,r1,r0,14);
S6(r4,r2,r3,r1,r0); LK(r3,r0,r2,r1,r4,15);
S7(r3,r0,r2,r1,r4); LK(r4,r2,r1,r3,r0,16);
S0(r4,r2,r1,r3,r0); LK(r1,r2,r3,r4,r0,17);
S1(r1,r2,r3,r4,r0); LK(r0,r3,r4,r1,r2,18);
S2(r0,r3,r4,r1,r2); LK(r2,r3,r0,r1,r4,19);
S3(r2,r3,r0,r1,r4); LK(r1,r4,r3,r2,r0,20);
S4(r1,r4,r3,r2,r0); LK(r4,r3,r2,r0,r1,21);
S5(r4,r3,r2,r0,r1); LK(r1,r4,r3,r0,r2,22);
S6(r1,r4,r3,r0,r2); LK(r3,r2,r4,r0,r1,23);
S7(r3,r2,r4,r0,r1); LK(r1,r4,r0,r3,r2,24);
S0(r1,r4,r0,r3,r2); LK(r0,r4,r3,r1,r2,25);
S1(r0,r4,r3,r1,r2); LK(r2,r3,r1,r0,r4,26);
S2(r2,r3,r1,r0,r4); LK(r4,r3,r2,r0,r1,27);
S3(r4,r3,r2,r0,r1); LK(r0,r1,r3,r4,r2,28);
S4(r0,r1,r3,r4,r2); LK(r1,r3,r4,r2,r0,29);
S5(r1,r3,r4,r2,r0); LK(r0,r1,r3,r2,r4,30);
S6(r0,r1,r3,r2,r4); LK(r3,r4,r1,r2,r0,31);
S7(r3,r4,r1,r2,r0); K(r0,r1,r2,r3,32);
((unsigned long*)out)[0] = r0; ((unsigned long*)out)[1] = r1;
((unsigned long*)out)[2] = r2; ((unsigned long*)out)[3] = r3;
}
void _stdcall serpent256_decrypt(const unsigned char *in, unsigned char *out, serpent256_key *key)
{
unsigned long *k = key->expkey;
unsigned long r0, r1, r2, r3, r4;
r0 = ((unsigned long*)in)[0]; r1 = ((unsigned long*)in)[1];
r2 = ((unsigned long*)in)[2]; r3 = ((unsigned long*)in)[3];
K(r0,r1,r2,r3,32);
SI7(r0,r1,r2,r3,r4); KL(r1,r3,r0,r4,r2,31);
SI6(r1,r3,r0,r4,r2); KL(r0,r2,r4,r1,r3,30);
SI5(r0,r2,r4,r1,r3); KL(r2,r3,r0,r4,r1,29);
SI4(r2,r3,r0,r4,r1); KL(r2,r0,r1,r4,r3,28);
SI3(r2,r0,r1,r4,r3); KL(r1,r2,r3,r4,r0,27);
SI2(r1,r2,r3,r4,r0); KL(r2,r0,r4,r3,r1,26);
SI1(r2,r0,r4,r3,r1); KL(r1,r0,r4,r3,r2,25);
SI0(r1,r0,r4,r3,r2); KL(r4,r2,r0,r1,r3,24);
SI7(r4,r2,r0,r1,r3); KL(r2,r1,r4,r3,r0,23);
SI6(r2,r1,r4,r3,r0); KL(r4,r0,r3,r2,r1,22);
SI5(r4,r0,r3,r2,r1); KL(r0,r1,r4,r3,r2,21);
SI4(r0,r1,r4,r3,r2); KL(r0,r4,r2,r3,r1,20);
SI3(r0,r4,r2,r3,r1); KL(r2,r0,r1,r3,r4,19);
SI2(r2,r0,r1,r3,r4); KL(r0,r4,r3,r1,r2,18);
SI1(r0,r4,r3,r1,r2); KL(r2,r4,r3,r1,r0,17);
SI0(r2,r4,r3,r1,r0); KL(r3,r0,r4,r2,r1,16);
SI7(r3,r0,r4,r2,r1); KL(r0,r2,r3,r1,r4,15);
SI6(r0,r2,r3,r1,r4); KL(r3,r4,r1,r0,r2,14);
SI5(r3,r4,r1,r0,r2); KL(r4,r2,r3,r1,r0,13);
SI4(r4,r2,r3,r1,r0); KL(r4,r3,r0,r1,r2,12);
SI3(r4,r3,r0,r1,r2); KL(r0,r4,r2,r1,r3,11);
SI2(r0,r4,r2,r1,r3); KL(r4,r3,r1,r2,r0,10);
SI1(r4,r3,r1,r2,r0); KL(r0,r3,r1,r2,r4,9);
SI0(r0,r3,r1,r2,r4); KL(r1,r4,r3,r0,r2,8);
SI7(r1,r4,r3,r0,r2); KL(r4,r0,r1,r2,r3,7);
SI6(r4,r0,r1,r2,r3); KL(r1,r3,r2,r4,r0,6);
SI5(r1,r3,r2,r4,r0); KL(r3,r0,r1,r2,r4,5);
SI4(r3,r0,r1,r2,r4); KL(r3,r1,r4,r2,r0,4);
SI3(r3,r1,r4,r2,r0); KL(r4,r3,r0,r2,r1,3);
SI2(r4,r3,r0,r2,r1); KL(r3,r1,r2,r0,r4,2);
SI1(r3,r1,r2,r0,r4); KL(r4,r1,r2,r0,r3,1);
SI0(r4,r1,r2,r0,r3); K(r2,r3,r1,r4,0);
((unsigned long*)out)[0] = r2; ((unsigned long*)out)[1] = r3;
((unsigned long*)out)[2] = r1; ((unsigned long*)out)[3] = r4;
}

Some files were not shown because too many files have changed in this diff Show More