Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DiskSerialNumber fixed #4248

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
83 changes: 81 additions & 2 deletions Sandboxie/core/dll/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
//#include <windows.h>
//#include "common/win32_ntddk.h"
#include "dll.h"
#include "obj.h"
#include <wchar.h>

#include "common/pool.h"
#include "common/map.h"
Expand Down Expand Up @@ -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) {

Expand All @@ -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));
}

Expand Down