diff --git a/CHANGELOG.md b/CHANGELOG.md index da81ff39c6..1897b2ad20 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 "DiskSerialNumberValueX"(Fill number 0-9 to 'X') to set Disk Serial Number for indivdal box. + + + ## [1.14.10 / 5.69.10] - 2024-10-03 ### Added diff --git a/Sandboxie/core/dll/kernel.c b/Sandboxie/core/dll/kernel.c index 3305ba5fb7..f17bff2f8e 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" @@ -517,10 +519,67 @@ _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'; + } +} +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*)Dll_Alloc(length + 1); + if (!cleanedHexString) { + return 0; + } + + int j = 0; + for (int i = 0; i < lstrlen(hexString); ++i) { + if (hexString[i] != L'-') { + cleanedHexString[j++] = hexString[i]; + } + } + cleanedHexString[j] = L'\0'; + unsigned long ulongValue = wcstoul(cleanedHexString, NULL, 16); + + Dll_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) { @@ -533,8 +592,28 @@ _FX BOOL Kernel_GetVolumeInformationByHandleW(HANDLE hFile, LPWSTR lpVolumeNameB *lpVolumeSerialNumber = *lpCachedSerialNumber; else { - *lpVolumeSerialNumber = Dll_rand(); - + 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 }, handleName2[23 + 1] = { 0 }; + DWORD dWroteNum = 0; + Obj_GetObjectName(hFile, handleName, &dWroteNum); + 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(); + 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)); }