From 394d0f69ee0b0349399a34437ca2c01ea241e3d1 Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Tue, 17 Sep 2024 11:10:13 +0800 Subject: [PATCH 01/10] 1.14.9 --- CHANGELOG.md | 1 + Sandboxie/core/dll/kernel.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c970afea..bbff9f8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - \\??\\%SystemDrive%\\Sandbox\\%SANDBOX% - \\??\\%SystemDrive%\\Users\\%USER%\Sandbox\\%SANDBOX% - added Sandbox Import dialog +- added "DiskSerialNumberValue"(Number) to set Disk Serial Number for indivdal box. ### Changed - sandbox root selection in global settings is now a combo box diff --git a/Sandboxie/core/dll/kernel.c b/Sandboxie/core/dll/kernel.c index 3305ba5f..9471697b 100644 --- a/Sandboxie/core/dll/kernel.c +++ b/Sandboxie/core/dll/kernel.c @@ -533,7 +533,11 @@ _FX BOOL Kernel_GetVolumeInformationByHandleW(HANDLE hFile, LPWSTR lpVolumeNameB *lpVolumeSerialNumber = *lpCachedSerialNumber; else { - *lpVolumeSerialNumber = Dll_rand(); + DWORD conf = SbieApi_QueryConfNumber(NULL, L"DiskSerialNumberValue", 0); + if (conf == 0) + *lpVolumeSerialNumber = Dll_rand(); + else + *lpVolumeSerialNumber = conf; map_insert(&Kernel_DiskSN, key, lpVolumeSerialNumber, sizeof(DWORD)); } From 76c32a0704daababbabd568f5929b3031fa0e177 Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Fri, 4 Oct 2024 21:50:38 +0800 Subject: [PATCH 02/10] 1.14.11 --- Sandboxie/core/dll/kernel.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Sandboxie/core/dll/kernel.c b/Sandboxie/core/dll/kernel.c index 9471697b..5888b971 100644 --- a/Sandboxie/core/dll/kernel.c +++ b/Sandboxie/core/dll/kernel.c @@ -517,10 +517,24 @@ _FX LANGID Kernel_GetSystemDefaultLangID() //Kernel_GetVolumeInformationByHandleW //---------------------------------------------------------------------------- - +wchar_t itoa0(int num) { + switch (num) { + case 0:return L'0'; + case 1:return L'1'; + case 2:return L'2'; + case 3:return L'4'; + case 5:return L'5'; + case 6:return L'6'; + case 7:return L'7'; + case 8:return L'8'; + case 9:return L'9'; + default:return L'0'; + } +} _FX BOOL Kernel_GetVolumeInformationByHandleW(HANDLE hFile, LPWSTR lpVolumeNameBuffer, DWORD nVolumeNameSize, LPDWORD lpVolumeSerialNumber,LPDWORD lpMaximumComponentLength, LPDWORD lpFileSystemFlags, LPWSTR lpFileSystemNameBuffer, DWORD nFileSystemNameSize) { DWORD ourSerialNumber = 0; + static long num = 0; BOOL rtn = __sys_GetVolumeInformationByHandleW(hFile, lpVolumeNameBuffer, nVolumeNameSize, &ourSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize); if (lpVolumeSerialNumber != NULL) { @@ -533,12 +547,14 @@ _FX BOOL Kernel_GetVolumeInformationByHandleW(HANDLE hFile, LPWSTR lpVolumeNameB *lpVolumeSerialNumber = *lpCachedSerialNumber; else { - DWORD conf = SbieApi_QueryConfNumber(NULL, L"DiskSerialNumberValue", 0); + wchar_t KeyName[30] = { 0 }; + Sbie_snwprintf(KeyName, 30, L"%s%s", L"DiskSerialNumberValue", itoa0(num)); + DWORD conf = SbieApi_QueryConfNumber(NULL, KeyName, 0); if (conf == 0) *lpVolumeSerialNumber = Dll_rand(); else *lpVolumeSerialNumber = conf; - + num++; map_insert(&Kernel_DiskSN, key, lpVolumeSerialNumber, sizeof(DWORD)); } From 68484a72a28649f854968358ee794a45dd316ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=B1=E7=BC=96=E7=A8=8B=E7=9A=84=E5=8F=B6=E4=B8=80?= =?UTF-8?q?=E7=AC=91?= <92030377+love-code-yeyixiao@users.noreply.github.com> Date: Fri, 4 Oct 2024 21:56:12 +0800 Subject: [PATCH 03/10] Update CHANGELOG.md --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75fa0307..70c4d58e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [1.1x.xx / 5.xx.xx] - 2024-xx-xx + +### Added +- added "DiskSerialNumberValue"(Number) to set Disk Serial Number for indivdal box. + + + ## [1.14.10 / 5.69.10] - 2024-10-03 ### Added @@ -26,7 +33,6 @@ This project adheres to [Semantic Versioning](http://semver.org/). - \\??\\%SystemDrive%\\Sandbox\\%SANDBOX% - \\??\\%SystemDrive%\\Users\\%USER%\Sandbox\\%SANDBOX% - added Sandbox Import dialog -- added "DiskSerialNumberValue"(Number) to set Disk Serial Number for indivdal box. ### Changed - sandbox root selection in global settings is now a combo box From 762ae1ee792cf1f75236e983a5b35c70559ee9bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=B1=E7=BC=96=E7=A8=8B=E7=9A=84=E5=8F=B6=E4=B8=80?= =?UTF-8?q?=E7=AC=91?= <92030377+love-code-yeyixiao@users.noreply.github.com> Date: Fri, 4 Oct 2024 22:01:47 +0800 Subject: [PATCH 04/10] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70c4d58e..1897b2ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [1.1x.xx / 5.xx.xx] - 2024-xx-xx ### Added -- added "DiskSerialNumberValue"(Number) to set Disk Serial Number for indivdal box. +- added "DiskSerialNumberValueX"(Fill number 0-9 to 'X') to set Disk Serial Number for indivdal box. From ce39e3390a10c52f5efd442c6636563eded9f1b4 Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Sun, 6 Oct 2024 22:52:17 +0800 Subject: [PATCH 05/10] Update kernel.c --- Sandboxie/core/dll/kernel.c | 67 +++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/Sandboxie/core/dll/kernel.c b/Sandboxie/core/dll/kernel.c index 5888b971..67a3e9a0 100644 --- a/Sandboxie/core/dll/kernel.c +++ b/Sandboxie/core/dll/kernel.c @@ -23,6 +23,8 @@ //#include //#include "common/win32_ntddk.h" #include "dll.h" +#include "obj.h" +#include #include "common/pool.h" #include "common/map.h" @@ -531,10 +533,54 @@ wchar_t itoa0(int num) { default:return L'0'; } } +int IsValidHexString(const wchar_t* hexString) +{ + int length = lstrlen(hexString); + if (length != 9 || hexString[4] != L'-') + { + return 0; + } + for (int i = 0; i < length; i++) + { + if (i != 4 && !iswxdigit(hexString[i])) + { + return 0; + } + } + return 1; +} +unsigned long HexStringToULONG(const wchar_t* hexString) { + int length = lstrlen(hexString); + for (int i = 0; i < length; ++i) { + if (hexString[i] == L'-') { + length--; + } + } + + wchar_t* cleanedHexString = (wchar_t*)malloc(length + 1); + if (!cleanedHexString) { + return 0; + } + + int j = 0; + for (int i = 0; i < strlen(hexString); ++i) { + if (hexString[i] != L'-') { + cleanedHexString[j++] = hexString[i]; + } + } + cleanedHexString[j] = L'\0'; + unsigned long ulongValue = wcstoul(cleanedHexString, NULL, 16); + + free(cleanedHexString); + + return ulongValue; +} + _FX BOOL Kernel_GetVolumeInformationByHandleW(HANDLE hFile, LPWSTR lpVolumeNameBuffer, DWORD nVolumeNameSize, LPDWORD lpVolumeSerialNumber,LPDWORD lpMaximumComponentLength, LPDWORD lpFileSystemFlags, LPWSTR lpFileSystemNameBuffer, DWORD nFileSystemNameSize) { DWORD ourSerialNumber = 0; static long num = 0; + BOOL rtn = __sys_GetVolumeInformationByHandleW(hFile, lpVolumeNameBuffer, nVolumeNameSize, &ourSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize); if (lpVolumeSerialNumber != NULL) { @@ -547,13 +593,22 @@ _FX BOOL Kernel_GetVolumeInformationByHandleW(HANDLE hFile, LPWSTR lpVolumeNameB *lpVolumeSerialNumber = *lpCachedSerialNumber; else { - wchar_t KeyName[30] = { 0 }; - Sbie_snwprintf(KeyName, 30, L"%s%s", L"DiskSerialNumberValue", itoa0(num)); - DWORD conf = SbieApi_QueryConfNumber(NULL, KeyName, 0); - if (conf == 0) + wchar_t Value[30] = { 0 }; + //Sbie_snwprintf(KeyName, 30, L"%s%s", L"DiskSerialNumberValue", itoa0(num)); + //DWORD conf = SbieApi_QueryConfNumber(NULL, KeyName, 0); + wchar_t handleName[MAX_PATH] = { 0 }; + Obj_GetObjectName(hFile, handleName, MAX_PATH); + SbieDll_GetSettingsForName(NULL, L"DiskSerialNumber", handleName, Value, 30, L"0000-0000"); + if (!IsValidHexString(Value)) *lpVolumeSerialNumber = Dll_rand(); - else - *lpVolumeSerialNumber = conf; + else { + //*lpVolumeSerialNumber = conf; + DWORD conf=HexStringToULONG(Value); + if(conf==0) + *lpVolumeSerialNumber = Dll_rand(); + else + *lpVolumeSerialNumber = conf; + } num++; map_insert(&Kernel_DiskSN, key, lpVolumeSerialNumber, sizeof(DWORD)); } From 78c91cf29da6ebb8b5a2145b473f3b08285c9e64 Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Mon, 7 Oct 2024 20:04:09 +0800 Subject: [PATCH 06/10] Fix --- Sandboxie/core/dll/kernel.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Sandboxie/core/dll/kernel.c b/Sandboxie/core/dll/kernel.c index 67a3e9a0..ecd8e7b3 100644 --- a/Sandboxie/core/dll/kernel.c +++ b/Sandboxie/core/dll/kernel.c @@ -556,14 +556,13 @@ unsigned long HexStringToULONG(const wchar_t* hexString) { length--; } } - - wchar_t* cleanedHexString = (wchar_t*)malloc(length + 1); + wchar_t* cleanedHexString = (wchar_t*)Dll_Alloc(length + 1); if (!cleanedHexString) { return 0; } int j = 0; - for (int i = 0; i < strlen(hexString); ++i) { + for (int i = 0; i < lstrlen(hexString); ++i) { if (hexString[i] != L'-') { cleanedHexString[j++] = hexString[i]; } @@ -571,7 +570,7 @@ unsigned long HexStringToULONG(const wchar_t* hexString) { cleanedHexString[j] = L'\0'; unsigned long ulongValue = wcstoul(cleanedHexString, NULL, 16); - free(cleanedHexString); + Dll_Free(cleanedHexString); return ulongValue; } From 000c4fc5f2dfe4a6792832bb695392b0c3a8ad5f Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Mon, 7 Oct 2024 20:21:16 +0800 Subject: [PATCH 07/10] fix --- Sandboxie/core/dll/kernel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sandboxie/core/dll/kernel.c b/Sandboxie/core/dll/kernel.c index ecd8e7b3..31459990 100644 --- a/Sandboxie/core/dll/kernel.c +++ b/Sandboxie/core/dll/kernel.c @@ -596,7 +596,8 @@ _FX BOOL Kernel_GetVolumeInformationByHandleW(HANDLE hFile, LPWSTR lpVolumeNameB //Sbie_snwprintf(KeyName, 30, L"%s%s", L"DiskSerialNumberValue", itoa0(num)); //DWORD conf = SbieApi_QueryConfNumber(NULL, KeyName, 0); wchar_t handleName[MAX_PATH] = { 0 }; - Obj_GetObjectName(hFile, handleName, MAX_PATH); + DWORD dWroteNum = 0; + Obj_GetObjectName(hFile, handleName, &dWroteNum); SbieDll_GetSettingsForName(NULL, L"DiskSerialNumber", handleName, Value, 30, L"0000-0000"); if (!IsValidHexString(Value)) *lpVolumeSerialNumber = Dll_rand(); From 86a74ed6318e16679d84085f247628fc36f8a85b Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Mon, 7 Oct 2024 20:56:04 +0800 Subject: [PATCH 08/10] Update kernel.c --- Sandboxie/core/dll/kernel.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sandboxie/core/dll/kernel.c b/Sandboxie/core/dll/kernel.c index 31459990..e5f934ee 100644 --- a/Sandboxie/core/dll/kernel.c +++ b/Sandboxie/core/dll/kernel.c @@ -595,10 +595,14 @@ _FX BOOL Kernel_GetVolumeInformationByHandleW(HANDLE hFile, LPWSTR lpVolumeNameB wchar_t Value[30] = { 0 }; //Sbie_snwprintf(KeyName, 30, L"%s%s", L"DiskSerialNumberValue", itoa0(num)); //DWORD conf = SbieApi_QueryConfNumber(NULL, KeyName, 0); - wchar_t handleName[MAX_PATH] = { 0 }; + wchar_t handleName[MAX_PATH] = { 0 }, handleName2[23 + 1] = { 0 }; DWORD dWroteNum = 0; Obj_GetObjectName(hFile, handleName, &dWroteNum); - SbieDll_GetSettingsForName(NULL, L"DiskSerialNumber", handleName, Value, 30, L"0000-0000"); + if (dWroteNum > MAX_PATH) + ExitProcess(0); + strncpy_s(handleName2,24, handleName, 23); + + SbieDll_GetSettingsForName(NULL, L"DiskSerialNumber", handleName2, Value, 30, L"0000-0000"); if (!IsValidHexString(Value)) *lpVolumeSerialNumber = Dll_rand(); else { From a9ad9e6c1bec66a3afa8633196c6c3b632eac905 Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Mon, 7 Oct 2024 20:58:13 +0800 Subject: [PATCH 09/10] Log --- Sandboxie/core/dll/kernel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sandboxie/core/dll/kernel.c b/Sandboxie/core/dll/kernel.c index e5f934ee..51f71e46 100644 --- a/Sandboxie/core/dll/kernel.c +++ b/Sandboxie/core/dll/kernel.c @@ -601,7 +601,7 @@ _FX BOOL Kernel_GetVolumeInformationByHandleW(HANDLE hFile, LPWSTR lpVolumeNameB if (dWroteNum > MAX_PATH) ExitProcess(0); strncpy_s(handleName2,24, handleName, 23); - + MessageBox(NULL,handleName2,handleName2,MB_OK); SbieDll_GetSettingsForName(NULL, L"DiskSerialNumber", handleName2, Value, 30, L"0000-0000"); if (!IsValidHexString(Value)) *lpVolumeSerialNumber = Dll_rand(); From cafd6f7acc6e8e9241fcb4c5bb06630abb2f2449 Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Mon, 7 Oct 2024 21:06:53 +0800 Subject: [PATCH 10/10] fix --- Sandboxie/core/dll/kernel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sandboxie/core/dll/kernel.c b/Sandboxie/core/dll/kernel.c index 51f71e46..f17bff2f 100644 --- a/Sandboxie/core/dll/kernel.c +++ b/Sandboxie/core/dll/kernel.c @@ -601,7 +601,7 @@ _FX BOOL Kernel_GetVolumeInformationByHandleW(HANDLE hFile, LPWSTR lpVolumeNameB if (dWroteNum > MAX_PATH) ExitProcess(0); strncpy_s(handleName2,24, handleName, 23); - MessageBox(NULL,handleName2,handleName2,MB_OK); + //MessageBox(NULL,handleName2,handleName2,MB_OK); SbieDll_GetSettingsForName(NULL, L"DiskSerialNumber", handleName2, Value, 30, L"0000-0000"); if (!IsValidHexString(Value)) *lpVolumeSerialNumber = Dll_rand();