├── bzscore ├── KEXT │ ├── stdafx.h │ ├── datetime.h │ ├── unicode.h │ ├── cmndef.h │ ├── SmartPointers.h │ └── kext_unicode.cpp ├── Posix │ ├── stdafx.h │ ├── socket.h │ ├── compat.h │ ├── longlong_compat.h │ ├── posix_path.cpp │ ├── guid_compat.h │ ├── path.h │ ├── DNS.h │ ├── kext.cpp │ ├── status_defs.h │ ├── UnixFileModes.h │ └── DNS.cpp ├── Win32 │ ├── stdafx.h │ ├── sock_defs.h │ ├── path.h │ ├── win32_status.cpp │ ├── path.cpp │ ├── win32_string.cpp │ └── registry_win32.cpp ├── WinKernel │ ├── stdafx.h │ ├── path.h │ ├── atomic.h │ ├── init.h │ ├── ntstatusdbg.h │ ├── memdbg.h │ ├── ntstatus.cpp │ ├── kmemory.h │ ├── ddk_string.cpp │ ├── memdbg.cpp │ ├── VisualDDKHelpers.h │ ├── string.h │ ├── status_defs.h │ ├── fileapi.h │ └── stlsup.cpp ├── tchar_compat.h ├── stdafx.cpp ├── minmax.h ├── stdafx.h ├── socket.h ├── assert.h ├── cfgstore.h ├── bzscore.h ├── fileflags.h ├── platform.h ├── filehlp.h ├── debug__kext_.mak ├── debug__posix_.mak ├── release__posix_.mak ├── sync.h ├── kext.mak ├── autolock.h ├── cmndef.h └── atomic.h ├── bzshlp ├── WinKernel │ ├── stdafx.h │ ├── SCSI │ │ ├── stdafx.h │ │ ├── scsidev.h │ │ ├── VirtualSCSIBus.h │ │ └── VirtualSCSICdrom.h │ ├── crossplatform │ │ ├── stdafx.h │ │ └── crossvol.h │ ├── undoc.h │ ├── registry.h │ ├── commondef.h │ ├── crossplatform.h │ ├── initguid.cpp │ ├── cmndef.h │ ├── trace.h │ ├── ioctldbg.h │ ├── devapi.cpp │ ├── filter.h │ ├── filter.cpp │ ├── AlertableQueue.cpp │ ├── VisualDDKHelpers.h │ ├── devapi.h │ ├── DeviceEnumerator.h │ ├── AlertableQueue.h │ ├── process.h │ └── DeviceEnumerator.cpp ├── cmndef.h ├── stdafx.cpp ├── alg.h ├── stdafx.h ├── algorithms │ └── memalgs.h ├── Win32 │ ├── cmndef.h │ ├── stdafx.h │ ├── HandleHolder.h │ ├── volmgr.h │ ├── wow64.h │ ├── bulkusbcmd.h │ ├── wow64.cpp │ ├── apicaller.h │ ├── bzsreg.h │ ├── LNGManager.h │ ├── bulkusb.h │ ├── display.h │ ├── RegistrySerializer.h │ ├── i18n.cpp │ └── cmdexec.h ├── logger.h ├── debug__posix_.mak ├── i18n.h ├── release__posix_.mak ├── bzsdisk.h ├── endian.h ├── bzsstream.h ├── MacOS │ ├── CFHandle.h │ ├── DeviceEnumerator.h │ ├── IOObject.h │ ├── IOService.h │ └── CFPluginWrapper.h ├── UserModeWorkerBackend.h ├── HandleHolder.h ├── ParsingLogger.h ├── uidpool.h ├── ratecalc.cpp └── gen_ser.pl ├── bzsnet ├── stdafx.h ├── stdafx.cpp ├── ReadMe.txt ├── base64.h ├── server.h ├── server.cpp └── bzsnet.vcxproj.filters ├── examples ├── WinKernel │ ├── FileDiskBus │ │ ├── stdafx.h │ │ ├── stdafx.cpp │ │ ├── VisualDDKHelpers.h │ │ ├── Filedisk.h │ │ ├── Filedisk.cpp │ │ ├── FileDiskBus.vcxproj.filters │ │ └── FileDiskBus.inf │ ├── RamDiskBus │ │ ├── stdafx.h │ │ ├── stdafx.cpp │ │ ├── VisualDDKHelpers.h │ │ ├── Ramdisk.h │ │ ├── RamDiskBus.vcxproj.filters │ │ ├── RamDiskBus.inf │ │ └── Ramdisk.cpp │ ├── SampleInstaller │ │ ├── SampleInstaller.h │ │ ├── res │ │ │ └── SampleInstaller.ico │ │ ├── ProjectDescription.h │ │ ├── stdafx.cpp │ │ ├── resource.h │ │ ├── stdafx.h │ │ ├── SampleInstaller.cpp │ │ ├── SampleInstaller.vcxproj.filters │ │ └── MainDlg.h │ ├── readme.txt │ ├── FileDiskBus Package │ │ └── FileDiskBus Package.vcxproj.filters │ └── RamDiskBus Package │ │ └── RamDiskBus Package.vcxproj.filters └── PortableThreadDemo │ ├── stdafx.cpp │ ├── targetver.h │ ├── stdafx.h │ ├── debug__posix_.mak │ ├── release__posix_.mak │ ├── ReadMe.txt │ └── PortableThreadDemo.vcxproj.filters ├── strgen.exe ├── tests ├── BigCrossPlatformTest │ ├── KernelMode │ │ ├── stdafx.cpp │ │ ├── KernelMode.reg │ │ ├── stdafx.h │ │ ├── VisualDDKHelpers.h │ │ └── KernelMode.vcxproj.filters │ ├── UserMode │ │ ├── stdafx.cpp │ │ ├── targetver.h │ │ ├── stdafx.h │ │ ├── debug__posix_.mak │ │ ├── UserMode.cpp │ │ └── UserMode.vcxproj.filters │ ├── AutoTestLib │ │ ├── stdafx.cpp │ │ ├── stdafx.h │ │ ├── targetver.h │ │ ├── TestPrint.h │ │ ├── MethodVerifier.h │ │ ├── debug__kext_.mak │ │ ├── debug__posix_.mak │ │ ├── AutoTests.cpp │ │ ├── WeakRefTest.cpp │ │ ├── cfgstore.cpp │ │ └── ReadMe.txt │ └── TestMacDriver │ │ ├── KEXT.c │ │ ├── TestMacDriver.h │ │ ├── debug__kext_.mak │ │ ├── debug__kext_.mak.old │ │ ├── TestMacDriver.cpp │ │ └── TestMacDriver.vcxproj.filters └── CommonFunctionalityTests │ ├── CommonFunctionalityTests.cpp │ ├── targetver.h │ ├── stdafx.cpp │ ├── stdafx.h │ ├── CommonFunctionalityTests.vcxproj.filters │ └── ReadMe.txt ├── footer.html ├── FindBazisLib.props ├── support └── strgen │ ├── stdafx.cpp │ ├── strgen_lng.h │ ├── stdafx.h │ ├── targetver.h │ ├── ReadMe.txt │ ├── StringManager.h │ └── strgen.vcxproj.filters ├── _installer ├── BazisLib.xit ├── main.xic ├── readme.txt └── __make.bat ├── BazisLibIncludes.props ├── .gitignore ├── header.html └── readme.md /bzscore/KEXT/stdafx.h: -------------------------------------------------------------------------------- 1 | #include "../stdafx.h" -------------------------------------------------------------------------------- /bzscore/Posix/stdafx.h: -------------------------------------------------------------------------------- 1 | #include "../stdafx.h" -------------------------------------------------------------------------------- /bzscore/Win32/stdafx.h: -------------------------------------------------------------------------------- 1 | #include "../stdafx.h" -------------------------------------------------------------------------------- /bzscore/WinKernel/stdafx.h: -------------------------------------------------------------------------------- 1 | #include "../stdafx.h" -------------------------------------------------------------------------------- /bzshlp/WinKernel/stdafx.h: -------------------------------------------------------------------------------- 1 | #include "../stdafx.h" -------------------------------------------------------------------------------- /bzshlp/WinKernel/SCSI/stdafx.h: -------------------------------------------------------------------------------- 1 | #include "../stdafx.h" -------------------------------------------------------------------------------- /bzshlp/WinKernel/crossplatform/stdafx.h: -------------------------------------------------------------------------------- 1 | #include "../stdafx.h" -------------------------------------------------------------------------------- /bzshlp/cmndef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../bzscore/cmndef.h" -------------------------------------------------------------------------------- /bzscore/WinKernel/path.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../Win32/path.h" -------------------------------------------------------------------------------- /bzshlp/WinKernel/undoc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "undoc/sysinfo.h" -------------------------------------------------------------------------------- /bzsnet/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../bzscore/stdafx.h" -------------------------------------------------------------------------------- /examples/WinKernel/FileDiskBus/stdafx.h: -------------------------------------------------------------------------------- 1 | #include -------------------------------------------------------------------------------- /examples/WinKernel/RamDiskBus/stdafx.h: -------------------------------------------------------------------------------- 1 | #include -------------------------------------------------------------------------------- /bzscore/Posix/socket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #undef BZSLIB_SOCKETS_AVAILABLE -------------------------------------------------------------------------------- /bzscore/WinKernel/atomic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../Win32/atomic.h" -------------------------------------------------------------------------------- /bzshlp/WinKernel/registry.h: -------------------------------------------------------------------------------- 1 | #include "../../bzscore/WinKernel/registry.h" -------------------------------------------------------------------------------- /strgen.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sysprogs/BazisLib/HEAD/strgen.exe -------------------------------------------------------------------------------- /bzshlp/WinKernel/commondef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../cmndef.h" 3 | 4 | -------------------------------------------------------------------------------- /examples/WinKernel/SampleInstaller/SampleInstaller.h: -------------------------------------------------------------------------------- 1 | // SampleInstaller.h 2 | -------------------------------------------------------------------------------- /bzshlp/stdafx.cpp: -------------------------------------------------------------------------------- 1 | //This file is used to build a precompiled header 2 | #include "stdafx.h" -------------------------------------------------------------------------------- /bzshlp/WinKernel/crossplatform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "commondef.h" 3 | #include "crossplatform/crossvol.h" -------------------------------------------------------------------------------- /bzshlp/WinKernel/initguid.cpp: -------------------------------------------------------------------------------- 1 | #define INITGUID 2 | 3 | #include "stdafx.h" 4 | #ifdef BZSLIB_WINKERNEL 5 | #endif -------------------------------------------------------------------------------- /examples/WinKernel/RamDiskBus/stdafx.cpp: -------------------------------------------------------------------------------- 1 | //This file is used to build a precompiled header 2 | #include "stdafx.h" -------------------------------------------------------------------------------- /examples/WinKernel/FileDiskBus/stdafx.cpp: -------------------------------------------------------------------------------- 1 | //This file is used to build a precompiled header 2 | #include "stdafx.h" -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/KernelMode/stdafx.cpp: -------------------------------------------------------------------------------- 1 | //This file is used to build a precompiled header 2 | #include "stdafx.h" -------------------------------------------------------------------------------- /bzscore/Posix/compat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define FIELD_OFFSET(type, field) ((int)(intptr_t)&(((type *)0)->field)) 4 | -------------------------------------------------------------------------------- /bzshlp/alg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cmndef.h" 3 | #include "algorithms/filealgs.h" 4 | #include "algorithms/memalgs.h" 5 | -------------------------------------------------------------------------------- /footer.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /bzscore/Posix/longlong_compat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | typedef uint64_t ULONGLONG; 5 | typedef int64_t LONGLONG; -------------------------------------------------------------------------------- /examples/WinKernel/SampleInstaller/res/SampleInstaller.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sysprogs/BazisLib/HEAD/examples/WinKernel/SampleInstaller/res/SampleInstaller.ico -------------------------------------------------------------------------------- /bzscore/WinKernel/init.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | NTSTATUS _stdcall CPPDriverEntry( 4 | IN OUT PDRIVER_OBJECT DriverObject, 5 | IN PUNICODE_STRING RegistryPath 6 | ); 7 | -------------------------------------------------------------------------------- /bzscore/Win32/sock_defs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BazisLib 4 | { 5 | namespace Network 6 | { 7 | typedef struct sockaddr_in _PlatformSpecificInternetAddress; 8 | } 9 | } -------------------------------------------------------------------------------- /bzscore/KEXT/datetime.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../string.h" 3 | #define BAZISLIB_NO_STRUCTURED_TIME 4 | 5 | #define gettimeofday(a,b) microtime(a) 6 | #include "../Posix/datetime.h" -------------------------------------------------------------------------------- /bzshlp/WinKernel/cmndef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define DISPATCH_ROUTINE_DECL __forceinline //Dramatically reduces stack frame depth 4 | #define DISPATCH_ROUTINE_OVERRIDE //override 5 | -------------------------------------------------------------------------------- /bzscore/WinKernel/ntstatusdbg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _DEBUG 4 | 5 | namespace BazisLib 6 | { 7 | namespace DDK 8 | { 9 | const wchar_t *MapNTStatus(NTSTATUS Status); 10 | } 11 | }; 12 | #endif -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/KernelMode/KernelMode.reg: -------------------------------------------------------------------------------- 1 | REGEDIT4 2 | 3 | [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\KernelMode] 4 | "ErrorControl"=dword:00000001 5 | "Start"=dword:00000001 6 | "Type"=dword:00000001 7 | -------------------------------------------------------------------------------- /bzsnet/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // bzsnet.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | -------------------------------------------------------------------------------- /bzshlp/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "../bzscore/stdafx.h" 9 | -------------------------------------------------------------------------------- /FindBazisLib.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildThisFileDirectory) 5 | 6 | -------------------------------------------------------------------------------- /bzscore/tchar_compat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __TCHAR_DEFINED 4 | #ifdef UNICODE 5 | #define __T(x) L ## x 6 | typedef wchar_t TCHAR; 7 | #else 8 | #define __T(x) x 9 | typedef char TCHAR; 10 | #endif 11 | 12 | #define _T(x) __T(x) 13 | #endif -------------------------------------------------------------------------------- /examples/WinKernel/SampleInstaller/ProjectDescription.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class ProjectDescription 5 | { 6 | public: 7 | BazisLib::String SampleName; 8 | BazisLib::String SampleDescription; 9 | BazisLib::String INFFile; 10 | }; -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/KernelMode/stdafx.h: -------------------------------------------------------------------------------- 1 | #ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later. 2 | #define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows. 3 | #endif 4 | 5 | #include -------------------------------------------------------------------------------- /bzscore/KEXT/unicode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../string.h" 3 | 4 | namespace BazisLib 5 | { 6 | namespace KEXT 7 | { 8 | DynamicStringA UTF16ToUTF8(const wchar16_t *pString, size_t length = -1); 9 | _DynamicStringT UTF8ToUTF16(const char *pString, size_t length = -1); 10 | } 11 | } -------------------------------------------------------------------------------- /bzscore/WinKernel/memdbg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BazisLib 4 | { 5 | namespace MemoryDebug 6 | { 7 | enum {MEMORY_DEBUG_SHIFT = 0}; 8 | 9 | void *OnMemoryAllocation(void *pBlock, size_t size); 10 | void *OnMemoryFree(void *pBlock); 11 | 12 | void OnProgramTermination(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /support/strgen/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // strgen.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /examples/PortableThreadDemo/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // PortableThreadDemo.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/UserMode/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // UserMode.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /bzscore/Posix/posix_path.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #ifdef BZSLIB_UNIXWORLD 3 | #include "../path.h" 4 | 5 | using namespace BazisLib; 6 | 7 | String Path::GetSpecialDirectoryLocation(SpecialDirectoryType dir) 8 | { 9 | switch(dir) 10 | { 11 | case dirTemp: 12 | return _T("/tmp"); 13 | default: 14 | return _T(""); 15 | } 16 | } 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /bzscore/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // bzscore.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/AutoTestLib/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // AutoTestLib.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/AutoTestLib/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | #include 8 | 9 | 10 | 11 | // TODO: reference additional headers your program requires here 12 | -------------------------------------------------------------------------------- /examples/PortableThreadDemo/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /examples/WinKernel/SampleInstaller/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // SampleInstaller.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | #if (_ATL_VER < 0x0700) 8 | #include 9 | #endif //(_ATL_VER < 0x0700) 10 | -------------------------------------------------------------------------------- /tests/CommonFunctionalityTests/CommonFunctionalityTests.cpp: -------------------------------------------------------------------------------- 1 | // CommonFunctionalityTests.cpp : Defines the entry point for the console application. 2 | // 3 | 4 | #include "stdafx.h" 5 | 6 | bool TestBufferedSockets(); 7 | 8 | int _tmain(int argc, _TCHAR* argv[]) 9 | { 10 | if (!TestBufferedSockets()) 11 | __asm int 3; 12 | 13 | 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/CommonFunctionalityTests/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /support/strgen/strgen_lng.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | //Generated by BazisLib STRGEN.EXE, http://bazislib.sysprogs.org/ 3 | 4 | #include 5 | #ifndef BAZISLIB_FIRST_LOCALIZABLE_STRING_ID 6 | #define BAZISLIB_FIRST_LOCALIZABLE_STRING_ID 0x1000 7 | #endif 8 | 9 | 10 | #define BAZISLIB_LAST_LOCALIZABLE_STRING_ID (BAZISLIB_FIRST_LOCALIZABLE_STRING_ID + 0xFFFFFFFF) 11 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/AutoTestLib/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/UserMode/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /bzscore/minmax.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BazisLib 4 | { 5 | template const _Ty &Min(const _Ty &a, const _Ty &b) 6 | { 7 | if (a < b) 8 | return a; 9 | else 10 | return b; 11 | } 12 | 13 | template const _Ty &Max(const _Ty &a, const _Ty &b) 14 | { 15 | if (a > b) 16 | return a; 17 | else 18 | return b; 19 | } 20 | } -------------------------------------------------------------------------------- /tests/CommonFunctionalityTests/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // CommonFunctionalityTests.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | #include -------------------------------------------------------------------------------- /bzscore/Posix/guid_compat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../bzscore/assert.h" 3 | 4 | #pragma pack(push, 1) 5 | typedef struct _GUID { 6 | unsigned int Data1; 7 | unsigned short Data2; 8 | unsigned short Data3; 9 | unsigned char Data4[ 8 ]; 10 | } GUID; 11 | #pragma pack(pop) 12 | 13 | C_ASSERT(sizeof(GUID) == 16); 14 | 15 | typedef GUID *LPGUID; 16 | typedef GUID *LPCGUID; 17 | -------------------------------------------------------------------------------- /tests/CommonFunctionalityTests/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | 10 | #include 11 | #include 12 | 13 | 14 | 15 | // TODO: reference additional headers your program requires here 16 | -------------------------------------------------------------------------------- /bzsnet/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | STATIC LIBRARY : bzsnet Project Overview 3 | ======================================================================== 4 | 5 | This library contains various network-based classes, such as HTTP client 6 | and multi-thread download manager 7 | 8 | ///////////////////////////////////////////////////////////////////////////// 9 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/AutoTestLib/TestPrint.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void TestPrint(const char *pFormat, ...); 4 | 5 | #ifdef _MSC_VER 6 | #define TEST_ASSERT(x) if (!(x)) {TestPrint("Test failed: %s [%s:%d]\n", #x, __FILE__, __LINE__); __debugbreak(); return false; } 7 | #else 8 | #define TEST_ASSERT(x) if (!(x)) {TestPrint("Test failed: %s [%s:%d]\n", #x, __FILE__, __LINE__); asm("int3"); return false; } 9 | #endif -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/UserMode/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include 9 | #ifdef BZS_POSIX 10 | #else 11 | #include 12 | #endif 13 | 14 | 15 | // TODO: reference additional headers your program requires here 16 | -------------------------------------------------------------------------------- /bzshlp/algorithms/memalgs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace BazisLib 3 | { 4 | namespace Algorithms 5 | { 6 | template void ZeroStruct(_Structure &object) 7 | { 8 | memset(&object, 0, sizeof(_Structure)); 9 | } 10 | 11 | template void CopyArray(char (&dest)[_ArraySize], const char (&source)[_ArraySize]) 12 | { 13 | memcpy(dest, source, _ArraySize); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /examples/PortableThreadDemo/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | #ifdef _MSC_VER 8 | #include "targetver.h" 9 | 10 | #include 11 | #include 12 | #endif 13 | 14 | 15 | // TODO: reference additional headers your program requires here 16 | -------------------------------------------------------------------------------- /support/strgen/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | 16 | 17 | // TODO: reference additional headers your program requires here 18 | -------------------------------------------------------------------------------- /examples/WinKernel/readme.txt: -------------------------------------------------------------------------------- 1 | This solution demonstrates two kernel-mode Windows virtual device drivers: 2 | * File disk 3 | * RAM disk 4 | 5 | To build it, follow the steps below: 6 | 1. Build the WinKernel.sln solution for your platform. 7 | 2. Build the SampleInstaller\SampleInstaller.sln solution. 8 | 3. Go to AllOutputs\ and run the SampleInstaller.exe/SampleInstaller64.exe on the machine where you want to deploy the drivers -------------------------------------------------------------------------------- /examples/WinKernel/FileDiskBus Package/FileDiskBus Package.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {8E41214B-6785-4CFE-B992-037D68949A14} 6 | inf;inv;inx;mof;mc; 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/WinKernel/RamDiskBus Package/RamDiskBus Package.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {8E41214B-6785-4CFE-B992-037D68949A14} 6 | inf;inv;inx;mof;mc; 7 | 8 | 9 | -------------------------------------------------------------------------------- /bzscore/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #if defined(_DEBUG) && defined(_NDEBUG) 9 | #error Both _DEBUG and _NDEBUG cannot be defined at the same time! 10 | #endif 11 | 12 | #include "cmndef.h" 13 | 14 | 15 | // TODO: reference additional headers your program requires here 16 | -------------------------------------------------------------------------------- /_installer/BazisLib.xit: -------------------------------------------------------------------------------- 1 | ;Predefined directory prefixes are $PROGRAMFILES$, $WINDIR$, 2 | ;$SYSDIR$, $WINDRIVE$, $CURDIR$, $TEMPDIR$ 3 | 4 | $general 5 | Readme readme.txt 6 | 7 | Defaultdir $WINDRIVE$\OpenSource\BazisLib 8 | Options SelectDir 9 | Components main 10 | RootComps main 11 | Version 1.00 12 | UID {AC904FEB-5CD6-4c56-8827-2AFD1CD8DBF1} 13 | Name BazisLib 14 | 15 | $main 16 | file main.xic 17 | options default 18 | ;requires none 19 | 20 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/AutoTestLib/MethodVerifier.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | template char _MethodVerifyHelper(_Ty); 4 | #define ENSURE_MEMBER_DECL(className, methodName, returnType, ...) typedef char __PROTOTYPE_VERIFIER__[sizeof(_MethodVerifyHelper(&className::methodName))] 5 | #define ENSURE_CONSTRUCTOR_DECL(className, ...) typedef char __PROTOTYPE_VERIFIER__[sizeof(_MethodVerifyHelper(className(__VA_ARGS__)))] 6 | -------------------------------------------------------------------------------- /bzscore/socket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define BZSLIB_SOCKETS_AVAILABLE 4 | 5 | #ifdef BZS_POSIX 6 | #include "Posix/socket.h" 7 | #elif defined (_WIN32) && !defined(_NTDDK_) && !defined(_KERNEL_MODE) 8 | #include "Win32/socket.h" 9 | #elif defined (BZSLIB_KEXT) 10 | #include "KEXT/socket.h" 11 | #else 12 | #undef BZSLIB_SOCKETS_AVAILABLE 13 | #ifndef BZSLIB_DISABLE_NO_SOCKET_ERROR 14 | #error Socket API is not defined for current platform. 15 | #endif 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/TestMacDriver/KEXT.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern kern_return_t _start(kmod_info_t *ki, void *data); 4 | extern kern_return_t _stop(kmod_info_t *ki, void *data); 5 | 6 | __attribute__((visibility("default"))) KMOD_EXPLICIT_DECL(com.sysprogs.TestMacDriver, "1.0.0d1", _start, _stop) 7 | __private_extern__ kmod_start_func_t *_realmain = 0; 8 | __private_extern__ kmod_stop_func_t *_antimain = 0; 9 | __private_extern__ int _kext_apple_cc = __APPLE_CC__ ; 10 | -------------------------------------------------------------------------------- /bzshlp/Win32/cmndef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if !defined(_WINDOWS_) && !defined(__WINDOWS__) 4 | #error You should include WINDOWS.H before including BZSWIN headers 5 | #endif 6 | 7 | namespace BazisLib 8 | { 9 | namespace Win32 10 | { 11 | using namespace BazisLib; 12 | } 13 | } 14 | 15 | #include "../../bzscore/cmndef.h" 16 | 17 | #ifdef UNDER_CE 18 | #define _sntprintf_s _sntprintf 19 | #define _stscanf_s _stscanf 20 | #define _sntprintf_s _sntprintf 21 | #define _tcsncat_s _tcsncat 22 | #endif -------------------------------------------------------------------------------- /bzscore/Posix/path.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BazisLib 4 | { 5 | class _PathPrivate 6 | { 7 | public: 8 | enum 9 | { 10 | _DirectorySeparatorChar = '/', 11 | _AltDirectorySeparatorChar = _DirectorySeparatorChar, 12 | _PathVariableSeparator = ':', 13 | }; 14 | 15 | static bool IsAbsolute(const String &path) 16 | { 17 | if (path.length() < 1) 18 | return false; 19 | return path[0] == '/'; 20 | } 21 | }; 22 | 23 | enum SpecialDirectoryType 24 | { 25 | dirTemp, 26 | }; 27 | } -------------------------------------------------------------------------------- /bzscore/WinKernel/ntstatus.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #ifdef BZSLIB_WINKERNEL 3 | #include "../status.h" 4 | #include "ntstatusdbg.h" 5 | 6 | using namespace BazisLib; 7 | 8 | String ActionStatus::FormatErrorCode(CommonErrorType code) 9 | { 10 | #ifdef _DEBUG 11 | const wchar_t *pwszStatus = BazisLib::DDK::MapNTStatus((NTSTATUS)code); 12 | if (pwszStatus) 13 | return pwszStatus; 14 | #endif 15 | wchar_t wsz[512]; 16 | _snwprintf(wsz, sizeof(wsz)/sizeof(wsz[0]), L"NTSTATUS code %08X", code); 17 | return wsz; 18 | } 19 | #endif -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/TestMacDriver/TestMacDriver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | class com_sysprogs_TestMacDriver : public IOService 6 | { 7 | OSDeclareDefaultStructors(com_sysprogs_TestMacDriver); 8 | private: 9 | typedef IOService super; 10 | 11 | public: 12 | virtual bool init(OSDictionary *dictionary = 0); 13 | virtual void free(void); 14 | virtual IOService *probe(IOService *provider, SInt32 *score); 15 | virtual bool start(IOService *provider); 16 | virtual void stop(IOService *provider); 17 | }; -------------------------------------------------------------------------------- /bzscore/KEXT/cmndef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | typedef intptr_t INT_PTR; 5 | typedef uintptr_t UINT_PTR; 6 | #define TRUE 1 7 | #define FALSE 0 8 | #define NULL 0 9 | 10 | #include "../Posix/compat.h" 11 | #include 12 | #include 13 | #include 14 | 15 | typedef uint16_t wchar16_t; 16 | 17 | typedef int64_t LONGLONG; 18 | typedef uint64_t ULONGLONG; 19 | 20 | typedef uuid_t GUID; 21 | 22 | __private_extern__ void* _realloc(void * _Memory, size_t _Size, size_t _OldSize); 23 | 24 | #define EXTENDED_REALLOC -------------------------------------------------------------------------------- /bzshlp/WinKernel/SCSI/scsidev.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../../bzscore/objmgr.h" 4 | #include "../../../bzscore/SCSI.h" 5 | extern "C" { 6 | #include 7 | #include 8 | } 9 | 10 | namespace BazisLib 11 | { 12 | namespace DDK 13 | { 14 | using namespace BazisLib::SCSI; 15 | 16 | namespace SCSI 17 | { 18 | namespace Requests 19 | { 20 | typedef _SCSIRequest Inquiry; 21 | typedef _SCSIRequest ReadTOC; 22 | } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /bzscore/assert.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "cmndef.h" 4 | #ifdef BZS_KEXT 5 | #include 6 | #else 7 | #include 8 | #endif 9 | 10 | #ifndef ASSERT 11 | #define ASSERT assert 12 | #endif 13 | 14 | #ifdef _AMD64_ 15 | #define ASSERT_32BIT(a) ASSERT(!((a) & 0xFFFFFFFF00000000)) 16 | #else 17 | #define ASSERT_32BIT(a) 18 | #endif 19 | 20 | #ifndef C_ASSERT 21 | #define C_ASSERT(e) typedef char __C_ASSERT__ [(e)?1:-1] 22 | #define C_ASSERT2(e) typedef char __C_ASSERT2__ [(e)?1:-1] 23 | #define C_ASSERT3(e) typedef char __C_ASSERT3__ [(e)?1:-1] 24 | #endif -------------------------------------------------------------------------------- /bzscore/cfgstore.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cmndef.h" 3 | 4 | #ifdef BZS_POSIX 5 | #include "Posix/cfgstore.h" 6 | #elif defined (BZSLIB_KEXT) 7 | #include "KEXT/cfgstore.h" 8 | #elif defined (BZSLIB_WINKERNEL) 9 | #include "WinKernel/registry.h" 10 | #include "Win32/cfgstore.h" 11 | #elif defined (_WIN32) 12 | #include "Win32/registry.h" 13 | #include "Win32/cfgstore.h" 14 | #else 15 | #error Status code mapping is not defined for current platform. 16 | #endif 17 | 18 | namespace BazisLib 19 | { 20 | using BazisLib::ConfigurationPath; 21 | using BazisLib::ConfigurationKey; 22 | } -------------------------------------------------------------------------------- /BazisLibIncludes.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | $(MSBuildThisFileDirectory);$(IncludePath) 7 | 8 | 9 | 10 | $(MSBuildThisFileDirectory) 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /bzscore/Posix/DNS.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "InternetAddress.h" 4 | #include 5 | 6 | namespace BazisLib 7 | { 8 | namespace Network 9 | { 10 | namespace Posix 11 | { 12 | class DNS 13 | { 14 | public: 15 | static Network::InternetAddress GetHostByName(const char *pHostName); 16 | 17 | enum AddrTypeFilter {kIPv4 = 0x01, kIPv6 = 0x02, kIPvAll = kIPv4 | kIPv6}; 18 | static std::vector GetAllHostAddresses(const char *pHostName, AddrTypeFilter filter = kIPvAll); 19 | }; 20 | } 21 | 22 | using Posix::DNS; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /bzshlp/WinKernel/trace.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../bzscore/WinKernel/ntstatusdbg.h" 4 | 5 | //The following trace constants are used by BazisLib::DDK itself: 6 | 7 | #define TRACE_DEVICE_REGISTRATION 0 8 | 9 | #define TRACE_PNP_EVENTS 0 10 | 11 | #define TRACE_PNP_DEVICE_DELETION TRACE_PNP_EVENTS 12 | #define TRACE_PNP_DEVICE_LIFECYCLE TRACE_PNP_EVENTS 13 | #define TRACE_PNP_DEVICE_STOPPING TRACE_PNP_EVENTS 14 | 15 | #ifdef _DEBUG 16 | 17 | #define DEBUG_TRACE(flag, data) ((void)(!(flag) || ((DbgPrint data), 1))) 18 | 19 | #else 20 | 21 | #define DEBUG_TRACE(flag, data) 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /_installer/main.xic: -------------------------------------------------------------------------------- 1 | $general 2 | caption BazisLib 3 | desc readme.txt 4 | archive main.bzz 5 | compression lzma23 6 | 7 | source bzslib 8 | 9 | ;If not defined, every file path in archive must begin with valid standard directory prefix 10 | forcedir $DESTDIR$\ 11 | 12 | version 1.00 13 | ;options over,shared,group 14 | 15 | 16 | $registry 17 | createkey HKLM\Software\BazisSoft\BazisLib 18 | setstrsubst Location $DESTDIR$ 19 | 20 | $startmenu 21 | deletegroup BazisLib 22 | creategroup BazisLib 23 | createitem "Reconfigure BazisLib" $DESTDIR$\BazisLibSetup.exe 24 | 25 | $postinstall 26 | exec $DESTDIR$\BazisLibSetup.exe -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | *.log 30 | *.tlog 31 | *.idb 32 | *.pdb 33 | *.lastbuildstate 34 | *.sdf 35 | *.suo 36 | *.ilk 37 | SourceCache.dat 38 | *.ipch 39 | Debug 40 | Release 41 | Win7Debug 42 | Debug (KEXT) 43 | Release (KEXT) 44 | CodeDB 45 | /support/strgen/Release 46 | *.opensdf 47 | -------------------------------------------------------------------------------- /bzshlp/WinKernel/ioctldbg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _DEBUG 4 | namespace BazisLib 5 | { 6 | namespace DDK 7 | { 8 | const char *MapDeviceControlCode(ULONG Code); 9 | 10 | //The format should contain %s for the control code! It will be automatically mapped to string. 11 | void DumpDeviceControlCode(const char *pszFormat, ULONG Code); 12 | 13 | void DumpBinaryBuffer(const void *pBuffer, int Size); 14 | void DumpInt32Buffer(const void *pBuffer, int Size); 15 | 16 | } 17 | } 18 | 19 | #define DUMP_DEVIOCTL(fmt, code) DumpDeviceControlCode((fmt), (code)) 20 | 21 | #else 22 | 23 | #define DUMP_DEVIOCTL(fmt, code) 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /bzscore/bzscore.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /*! \mainpage BazisLib framework 4 | 5 | \section intro_sec Introduction 6 | BazisLib is an library that accelerates the development of system-level applications and drivers. It consists of 2 main parts: 7 | * Core library (bzscore) that defines a platform-independent abstraction layer for various system API (e.g. file access) 8 | * Helper libraries 9 | * bzswin provides convenient C++ wrappers for various Win32 API calls 10 | 11 | \section platform_types The following platforms are supported by BazisLib: 12 | * User-mode Win32 (_WIN32) 13 | * Windows kernel-mode environment (_DDK_) 14 | */ 15 | 16 | #include "cmndef.h" -------------------------------------------------------------------------------- /bzshlp/WinKernel/devapi.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #ifdef BZSLIB_WINKERNEL 3 | #include "devapi.h" 4 | 5 | using namespace BazisLib::DDK; 6 | 7 | ExternalDeviceObjectReference::ExternalDeviceObjectReference(const wchar_t *pwszDevicePath, ACCESS_MASK AccessMask) : 8 | m_pDeviceObject(NULL), 9 | m_pFileObject(NULL) 10 | { 11 | UNICODE_STRING nameString; 12 | if (!pwszDevicePath) 13 | return; 14 | RtlInitUnicodeString(&nameString, pwszDevicePath); 15 | NTSTATUS st = IoGetDeviceObjectPointer(&nameString, AccessMask, &m_pFileObject, &m_pDeviceObject); 16 | if (!NT_SUCCESS(st)) 17 | { 18 | m_pDeviceObject = NULL; 19 | m_pFileObject = NULL; 20 | } 21 | } 22 | #endif -------------------------------------------------------------------------------- /bzshlp/logger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cmndef.h" 3 | #include "../bzscore/file.h" 4 | 5 | namespace BazisLib 6 | { 7 | //! Provides data logging functionality for debug purposes 8 | class SimpleLogger 9 | { 10 | private: 11 | File m_File; 12 | 13 | public: 14 | SimpleLogger(TCHAR *ptszFileName) 15 | : m_File(ptszFileName, FileModes::CreateOrOpenRW) 16 | { 17 | m_File.Seek(0, FileFlags::FileEnd); 18 | } 19 | 20 | void LogLineA(const char *pszFormat, ...) 21 | { 22 | va_list lst; 23 | va_start(lst, pszFormat); 24 | char tsz[1024]; 25 | vsnprintf(tsz, sizeof(tsz), pszFormat, lst); 26 | m_File.Write(tsz, strlen(tsz)); 27 | } 28 | }; 29 | } -------------------------------------------------------------------------------- /header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | $title 4 | 5 | 6 | 7 | 8 |
9 |
10 |
11 |
12 | 13 |
14 | -------------------------------------------------------------------------------- /bzscore/fileflags.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BazisLib 4 | { 5 | namespace FileFlags 6 | { 7 | enum FileAccess 8 | { 9 | QueryAccess = 0x000001, 10 | ReadAccess = 0x000002, 11 | WriteAccess = 0x000004, 12 | ReadWriteAccess = 0x000008, 13 | DeleteAccess = 0x000010, 14 | AllAccess = 0x000020, 15 | ReadSecurity = 0x000040, 16 | ModifySecurity = 0x000080, 17 | }; 18 | 19 | enum ShareMode 20 | { 21 | NoShare = 0, 22 | ShareRead = 0x01, 23 | ShareWrite = 0x02, 24 | ShareDelete = 0x04, 25 | ShareAll = 0x08, 26 | }; 27 | 28 | enum OpenMode 29 | { 30 | OpenExisting, 31 | OpenAlways, 32 | CreateAlways, 33 | CreateNew, 34 | }; 35 | } 36 | } -------------------------------------------------------------------------------- /bzscore/platform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _WIN32 4 | #define LINE_ENDING_SEQUENCE_A '\r\n' 5 | #define LINE_ENDING_SEQUENCE_W '\r\0\n\0' 6 | #define LINE_ENDING_SEQUENCE_LEN 2 7 | #define LINE_ENDING_STR_T _T("\r\n") 8 | 9 | #define LINE_ENDING_STR_A "\r\n" 10 | #define LINE_ENDING_STR_W L"\r\n" 11 | 12 | #define MAX_INTEGER_TEXT_REPRESENTATION_LEN 11 //Longest 32-bit integer: "-2147483648" 13 | 14 | 15 | #else 16 | #define LINE_ENDING_STR_T _T("\n") 17 | #define LINE_ENDING_STR_A "\n" 18 | #define LINE_ENDING_STR_W L"\n" 19 | #endif 20 | 21 | #if defined(_AMD64_) || defined (_WIN64) 22 | #define BAZISLIB_X64 23 | #endif 24 | 25 | #ifdef BZSLIB_WINKERNEL 26 | #define EXTENDED_REALLOC 27 | #endif 28 | -------------------------------------------------------------------------------- /bzshlp/Win32/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | #if defined(WIN32) && !defined(BZSLIB_WINKERNEL) 8 | 9 | #ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later. 10 | #define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows. 11 | #endif 12 | 13 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 14 | #define _CRT_SECURE_NO_WARNINGS 15 | 16 | #define _SECURE_ATL 1 17 | 18 | #include 19 | #include 20 | 21 | #endif -------------------------------------------------------------------------------- /bzscore/filehlp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace BazisLib 3 | { 4 | namespace FileHelpers 5 | { 6 | static inline LONGLONG DoSeek(ULONGLONG *RealOffset, ULONGLONG FileSize, LONGLONG Offset, FileFlags::SeekType seekType, bool CheckForEnd, ActionStatus *pStatus = NULL) 7 | { 8 | switch (seekType) 9 | { 10 | case FileFlags::FileBegin: 11 | *RealOffset = Offset; 12 | break; 13 | case FileFlags::FileCurrent: 14 | *RealOffset += Offset; 15 | break; 16 | case FileFlags::FileEnd: 17 | *RealOffset = FileSize + Offset; 18 | break; 19 | } 20 | if (CheckForEnd) 21 | { 22 | if (*RealOffset > FileSize) 23 | *RealOffset = FileSize; 24 | } 25 | ASSIGN_STATUS(pStatus, Success); 26 | return *RealOffset; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /support/strgen/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // The following macros define the minimum required platform. The minimum required platform 4 | // is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run 5 | // your application. The macros work by enabling all features available on platform versions up to and 6 | // including the version specified. 7 | 8 | // Modify the following defines if you have to target a platform prior to the ones specified below. 9 | // Refer to MSDN for the latest info on corresponding values for different platforms. 10 | #ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. 11 | #define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /bzshlp/Win32/HandleHolder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BazisLib 4 | { 5 | namespace Win32 6 | { 7 | class HandleHolder : public _HandleHolderT 8 | { 9 | public: 10 | explicit HandleHolder(HANDLE hInit = INVALID_HANDLE_VALUE) : _HandleHolderT(hInit) {} 11 | 12 | HANDLE Duplicate(HANDLE hDestProcess = GetCurrentProcess(), 13 | bool bInheritable = true, 14 | DWORD options = DUPLICATE_SAME_ACCESS, 15 | DWORD newAccess = 0) 16 | { 17 | HANDLE hRes = INVALID_HANDLE_VALUE; 18 | DuplicateHandle(GetCurrentProcess(), m_Handle, hDestProcess, &hRes, newAccess, bInheritable, options); 19 | return hRes; 20 | } 21 | 22 | _HandleHolderT &operator=(HANDLE hNew) { return __super::operator=(hNew); } 23 | 24 | }; 25 | } 26 | 27 | 28 | } -------------------------------------------------------------------------------- /examples/WinKernel/SampleInstaller/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by SampleInstaller.rc 4 | // 5 | #define IDR_MAINFRAME 128 6 | #define IDD_MAINDLG 129 7 | #define IDC_COMBO1 1000 8 | #define IDC_EDIT1 1001 9 | #define IDC_BUTTON1 1002 10 | #define IDC_BUTTON2 1003 11 | #define IDC_DRIVERSTATE 1004 12 | 13 | // Next default values for new objects 14 | // 15 | #ifdef APSTUDIO_INVOKED 16 | #ifndef APSTUDIO_READONLY_SYMBOLS 17 | #define _APS_NEXT_RESOURCE_VALUE 201 18 | #define _APS_NEXT_COMMAND_VALUE 32775 19 | #define _APS_NEXT_CONTROL_VALUE 1005 20 | #define _APS_NEXT_SYMED_VALUE 101 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/AutoTestLib/debug__kext_.mak: -------------------------------------------------------------------------------- 1 | #Generated by VisualGDB (http://visualgdb.com) 2 | #DO NOT EDIT THIS FILE MANUALLY UNLESS YOU ABSOLUTELY NEED TO 3 | #USE VISUALGDB PROJECT PROPERTIES DIALOG INSTEAD 4 | 5 | BINARYDIR := Debug__KEXT_ 6 | 7 | #Toolchain 8 | CC := gcc 9 | CXX := g++ 10 | LD := $(CXX) 11 | AR := ar 12 | OBJCOPY := objcopy 13 | 14 | #Additional flags 15 | PREPROCESSOR_MACROS := 16 | INCLUDE_DIRS := ../../.. ../../../../STLPort-Kernel/stlport 17 | LIBRARY_DIRS := 18 | LIBRARY_NAMES := 19 | ADDITIONAL_LINKER_INPUTS := 20 | MACOS_FRAMEWORKS := 21 | LINUX_PACKAGES := 22 | 23 | CFLAGS := -ggdb 24 | CXXFLAGS := -ggdb 25 | ASFLAGS := 26 | LDFLAGS := 27 | COMMONFLAGS := 28 | 29 | START_GROUP := 30 | END_GROUP := 31 | 32 | #Additional options detected from testing the toolchain 33 | IS_LINUX_PROJECT := 1 34 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/TestMacDriver/debug__kext_.mak: -------------------------------------------------------------------------------- 1 | #Generated by VisualGDB (http://visualgdb.com) 2 | #DO NOT EDIT THIS FILE MANUALLY UNLESS YOU ABSOLUTELY NEED TO 3 | #USE VISUALGDB PROJECT PROPERTIES DIALOG INSTEAD 4 | 5 | BINARYDIR := Debug__KEXT_ 6 | 7 | #Toolchain 8 | CC := gcc 9 | CXX := g++ 10 | LD := $(CXX) 11 | AR := ar 12 | OBJCOPY := objcopy 13 | 14 | #Additional flags 15 | PREPROCESSOR_MACROS := 16 | INCLUDE_DIRS := ../../.. ../../../../STLPort-Kernel/stlport 17 | LIBRARY_DIRS := 18 | LIBRARY_NAMES := 19 | ADDITIONAL_LINKER_INPUTS := 20 | MACOS_FRAMEWORKS := 21 | LINUX_PACKAGES := 22 | 23 | CFLAGS := -ggdb 24 | CXXFLAGS := -ggdb 25 | ASFLAGS := 26 | LDFLAGS := 27 | COMMONFLAGS := 28 | 29 | START_GROUP := 30 | END_GROUP := 31 | 32 | #Additional options detected from testing the toolchain 33 | IS_LINUX_PROJECT := 1 34 | -------------------------------------------------------------------------------- /bzscore/debug__kext_.mak: -------------------------------------------------------------------------------- 1 | #Generated by VisualGDB (http://visualgdb.com) 2 | #DO NOT EDIT THIS FILE MANUALLY UNLESS YOU ABSOLUTELY NEED TO 3 | #USE VISUALGDB PROJECT PROPERTIES DIALOG INSTEAD 4 | 5 | BINARYDIR := Debug__KEXT_ 6 | 7 | #Toolchain 8 | CC := gcc 9 | CXX := g++ 10 | LD := $(CXX) 11 | AR := ar 12 | OBJCOPY := objcopy 13 | 14 | #Additional flags 15 | PREPROCESSOR_MACROS := 16 | INCLUDE_DIRS := ../../STLPort-Kernel/stlport 17 | LIBRARY_DIRS := 18 | LIBRARY_NAMES := 19 | ADDITIONAL_LINKER_INPUTS := 20 | MACOS_FRAMEWORKS := 21 | LINUX_PACKAGES := 22 | 23 | CFLAGS := -ggdb 24 | CXXFLAGS := -ggdb 25 | ASFLAGS := 26 | LDFLAGS := 27 | COMMONFLAGS := 28 | 29 | START_GROUP := 30 | END_GROUP := 31 | 32 | #Additional options detected from testing the toolchain 33 | USE_DEL_TO_CLEAN := 1 34 | CP_NOT_AVAILABLE := 1 35 | IS_LINUX_PROJECT := 1 36 | -------------------------------------------------------------------------------- /bzscore/Win32/path.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BazisLib 4 | { 5 | class _PathPrivate 6 | { 7 | public: 8 | enum 9 | { 10 | _DirectorySeparatorChar = '\\', 11 | _AltDirectorySeparatorChar = '/', 12 | _PathVariableSeparator = ';', 13 | }; 14 | 15 | static bool IsAbsolute(const TempString &path) 16 | { 17 | if (path.length() < 2) 18 | return false; 19 | return path[1] == ':' || (path[0] == '\\' && path[1] == '\\'); 20 | } 21 | }; 22 | 23 | enum SpecialDirectoryType 24 | { 25 | #ifndef BZSLIB_WINKERNEL 26 | dirWindows = 0x8A000001, 27 | dirSystem, 28 | dirDrivers, 29 | dirTemp, 30 | #endif 31 | }; 32 | 33 | namespace Win32 34 | { 35 | #ifndef BZSLIB_WINKERNEL 36 | static inline SpecialDirectoryType SpecialDirFromCSIDL(int CSIDL) 37 | { 38 | return (SpecialDirectoryType)CSIDL; 39 | } 40 | #endif 41 | } 42 | } -------------------------------------------------------------------------------- /bzscore/WinKernel/kmemory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void * __cdecl npagednew(size_t size); 4 | 5 | #ifndef _KERNEL_MODE 6 | extern "C" { 7 | void __cdecl free(void * _Memory); 8 | void * __cdecl malloc(size_t _Size); 9 | void * __cdecl realloc(void * _Memory, size_t _Size); 10 | } 11 | #endif 12 | 13 | #define EXTENDED_REALLOC 14 | extern "C" void * __cdecl _realloc(void * _Memory, size_t _Size, size_t _OldSize); 15 | 16 | static inline void *bulk_malloc(size_t size) 17 | { 18 | return ExAllocatePool(PagedPool, size); 19 | } 20 | 21 | static inline void bulk_free(void *p, size_t) 22 | { 23 | if (p) 24 | ExFreePool(p); 25 | } 26 | 27 | namespace BazisLib 28 | { 29 | namespace DDK 30 | { 31 | class NonPagedObject 32 | { 33 | public: 34 | void *operator new(size_t size) 35 | { 36 | return npagednew(size); 37 | } 38 | }; 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /bzscore/debug__posix_.mak: -------------------------------------------------------------------------------- 1 | #Generated by VisualGDB (http://visualgdb.com) 2 | #DO NOT EDIT THIS FILE MANUALLY UNLESS YOU ABSOLUTELY NEED TO 3 | #USE VISUALGDB PROJECT PROPERTIES DIALOG INSTEAD 4 | 5 | BINARYDIR := Debug__Posix_ 6 | 7 | #Toolchain 8 | CC := gcc 9 | CXX := g++ 10 | LD := $(CXX) 11 | AR := ar 12 | OBJCOPY := objcopy 13 | 14 | #Additional flags 15 | PREPROCESSOR_MACROS := DEBUG BZS_POSIX 16 | INCLUDE_DIRS := 17 | LIBRARY_DIRS := 18 | LIBRARY_NAMES := 19 | ADDITIONAL_LINKER_INPUTS := 20 | MACOS_FRAMEWORKS := 21 | LINUX_PACKAGES := 22 | 23 | CFLAGS := -ggdb -ffunction-sections 24 | CXXFLAGS := -ggdb -ffunction-sections 25 | ASFLAGS := 26 | LDFLAGS := -Wl,-gc-sections 27 | COMMONFLAGS := 28 | 29 | START_GROUP := -Wl,--start-group 30 | END_GROUP := -Wl,--end-group 31 | 32 | #Additional options detected from testing the toolchain 33 | IS_LINUX_PROJECT := 1 34 | -------------------------------------------------------------------------------- /bzshlp/debug__posix_.mak: -------------------------------------------------------------------------------- 1 | #Generated by VisualGDB (http://visualgdb.com) 2 | #DO NOT EDIT THIS FILE MANUALLY UNLESS YOU ABSOLUTELY NEED TO 3 | #USE VISUALGDB PROJECT PROPERTIES DIALOG INSTEAD 4 | 5 | BINARYDIR := Debug__Posix_ 6 | 7 | #Toolchain 8 | CC := gcc 9 | CXX := g++ 10 | LD := $(CXX) 11 | AR := ar 12 | OBJCOPY := objcopy 13 | 14 | #Additional flags 15 | PREPROCESSOR_MACROS := BZS_POSIX 16 | INCLUDE_DIRS := .. 17 | LIBRARY_DIRS := 18 | LIBRARY_NAMES := 19 | ADDITIONAL_LINKER_INPUTS := 20 | MACOS_FRAMEWORKS := 21 | LINUX_PACKAGES := 22 | 23 | CFLAGS := -ggdb -ffunction-sections 24 | CXXFLAGS := -ggdb -ffunction-sections 25 | ASFLAGS := 26 | LDFLAGS := -Wl,-gc-sections 27 | COMMONFLAGS := 28 | 29 | START_GROUP := -Wl,--start-group 30 | END_GROUP := -Wl,--end-group 31 | 32 | #Additional options detected from testing the toolchain 33 | IS_LINUX_PROJECT := 1 34 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/TestMacDriver/debug__kext_.mak.old: -------------------------------------------------------------------------------- 1 | #Generated by VisualGDB (http://visualgdb.com) 2 | #DO NOT EDIT THIS FILE MANUALLY UNLESS YOU ABSOLUTELY NEED TO 3 | #USE VISUALGDB PROJECT PROPERTIES DIALOG INSTEAD 4 | 5 | BINARYDIR := Debug__KEXT_ 6 | 7 | #Toolchain 8 | CC := gcc 9 | CXX := g++ 10 | LD := $(CXX) 11 | AR := ar 12 | OBJCOPY := objcopy 13 | 14 | #Additional flags 15 | PREPROCESSOR_MACROS := 16 | INCLUDE_DIRS := 17 | LIBRARY_DIRS := 18 | LIBRARY_NAMES := 19 | ADDITIONAL_LINKER_INPUTS := 20 | MACOS_FRAMEWORKS := 21 | LINUX_PACKAGES := 22 | 23 | CFLAGS := -ggdb -ffunction-sections 24 | CXXFLAGS := -ggdb -ffunction-sections 25 | ASFLAGS := 26 | LDFLAGS := -Wl,-gc-sections 27 | COMMONFLAGS := 28 | 29 | START_GROUP := -Wl,--start-group 30 | END_GROUP := -Wl,--end-group 31 | 32 | #Additional options detected from testing the toolchain 33 | IS_LINUX_PROJECT := 1 34 | -------------------------------------------------------------------------------- /bzscore/release__posix_.mak: -------------------------------------------------------------------------------- 1 | #Generated by VisualGDB (http://visualgdb.com) 2 | #DO NOT EDIT THIS FILE MANUALLY UNLESS YOU ABSOLUTELY NEED TO 3 | #USE VISUALGDB PROJECT PROPERTIES DIALOG INSTEAD 4 | 5 | BINARYDIR := Release__Posix_ 6 | 7 | #Toolchain 8 | CC := gcc 9 | CXX := g++ 10 | LD := $(CXX) 11 | AR := ar 12 | OBJCOPY := objcopy 13 | 14 | #Additional flags 15 | PREPROCESSOR_MACROS := NDEBUG RELEASE BZS_POSIX 16 | INCLUDE_DIRS := 17 | LIBRARY_DIRS := 18 | LIBRARY_NAMES := 19 | ADDITIONAL_LINKER_INPUTS := 20 | MACOS_FRAMEWORKS := 21 | LINUX_PACKAGES := 22 | 23 | CFLAGS := -ggdb -ffunction-sections -O3 24 | CXXFLAGS := -ggdb -ffunction-sections -O3 25 | ASFLAGS := 26 | LDFLAGS := -Wl,-gc-sections 27 | COMMONFLAGS := 28 | 29 | START_GROUP := -Wl,--start-group 30 | END_GROUP := -Wl,--end-group 31 | 32 | #Additional options detected from testing the toolchain 33 | IS_LINUX_PROJECT := 1 34 | -------------------------------------------------------------------------------- /bzshlp/i18n.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cmndef.h" 3 | 4 | namespace BazisLib 5 | { 6 | struct StringIDRecord 7 | { 8 | unsigned ID; 9 | const TCHAR *pString; 10 | }; 11 | 12 | static inline const TCHAR *LookupLocalizedString(unsigned ID); 13 | 14 | #ifndef _DEBUG 15 | #ifndef BAZISLIB_DISABLE_LOCALIZATION 16 | #define BAZISLIB_LOCALIZATION_ENABLED 17 | #endif 18 | #endif 19 | 20 | 21 | #ifdef BAZISLIB_LOCALIZATION_ENABLED 22 | 23 | static inline const TCHAR * _tr_helper(unsigned ID, const TCHAR *pDefault) 24 | { 25 | const TCHAR *pStr = LookupLocalizedString(ID); 26 | return pStr ? pStr : pDefault; 27 | } 28 | 29 | #define _TR(id, str) BazisLib::_tr_helper((id), _T(str)) 30 | 31 | #else 32 | 33 | #define _TR(id, str) _T(str) 34 | #define LOCALIZE_DIALOG(strid, dlgid, hwnd) 35 | #define LOCALIZE_DLGITEM(strid, hwnd, item) 36 | 37 | #endif 38 | } -------------------------------------------------------------------------------- /bzshlp/release__posix_.mak: -------------------------------------------------------------------------------- 1 | #Generated by VisualGDB (http://visualgdb.com) 2 | #DO NOT EDIT THIS FILE MANUALLY UNLESS YOU ABSOLUTELY NEED TO 3 | #USE VISUALGDB PROJECT PROPERTIES DIALOG INSTEAD 4 | 5 | BINARYDIR := Release__Posix_ 6 | 7 | #Toolchain 8 | CC := gcc 9 | CXX := g++ 10 | LD := $(CXX) 11 | AR := ar 12 | OBJCOPY := objcopy 13 | 14 | #Additional flags 15 | PREPROCESSOR_MACROS := NDEBUG RELEASE BZS_POSIX 16 | INCLUDE_DIRS := .. 17 | LIBRARY_DIRS := 18 | LIBRARY_NAMES := 19 | ADDITIONAL_LINKER_INPUTS := 20 | MACOS_FRAMEWORKS := 21 | LINUX_PACKAGES := 22 | 23 | CFLAGS := -ggdb -ffunction-sections -O3 24 | CXXFLAGS := -ggdb -ffunction-sections -O3 25 | ASFLAGS := 26 | LDFLAGS := -Wl,-gc-sections 27 | COMMONFLAGS := 28 | 29 | START_GROUP := -Wl,--start-group 30 | END_GROUP := -Wl,--end-group 31 | 32 | #Additional options detected from testing the toolchain 33 | IS_LINUX_PROJECT := 1 34 | -------------------------------------------------------------------------------- /bzsnet/base64.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../bzscore/string.h" 3 | #include "../bzscore/buffer.h" 4 | 5 | namespace BazisLib 6 | { 7 | namespace Network 8 | { 9 | class Base64 10 | { 11 | public: 12 | //Maps [aaa] to [bbbb] according to BASE64 alphabet. [aa] will be mapped to [bbb=], [a] - to [bb==] 13 | static void Encode(const void *pPtr, unsigned Size, DynamicStringA &buffer); 14 | static void Encode(const void *pPtr, unsigned Size, DynamicStringW &buffer); 15 | 16 | static bool Decode(const _TempStringImplT &string, BasicBuffer &buffer); 17 | static bool Decode(const _TempStringImplT &string, BasicBuffer &buffer); 18 | public: 19 | 20 | static std::string EncodeANSIString(const std::string &str) 21 | { 22 | DynamicStringA result; 23 | Encode(str.c_str(), str.size(), result); 24 | return result.c_str(); 25 | } 26 | 27 | }; 28 | } 29 | } -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/AutoTestLib/debug__posix_.mak: -------------------------------------------------------------------------------- 1 | #Generated by VisualGDB (http://visualgdb.com) 2 | #DO NOT EDIT THIS FILE MANUALLY UNLESS YOU ABSOLUTELY NEED TO 3 | #USE VISUALGDB PROJECT PROPERTIES DIALOG INSTEAD 4 | 5 | BINARYDIR := Debug__Posix_ 6 | 7 | #Toolchain 8 | CC := gcc 9 | CXX := g++ 10 | LD := $(CXX) 11 | AR := ar 12 | OBJCOPY := objcopy 13 | 14 | #Additional flags 15 | PREPROCESSOR_MACROS := BZS_POSIX 16 | INCLUDE_DIRS := ../../.. 17 | LIBRARY_DIRS := 18 | LIBRARY_NAMES := 19 | ADDITIONAL_LINKER_INPUTS := 20 | MACOS_FRAMEWORKS := 21 | LINUX_PACKAGES := 22 | 23 | CFLAGS := -ggdb -ffunction-sections 24 | CXXFLAGS := -ggdb -ffunction-sections 25 | ASFLAGS := 26 | LDFLAGS := -Wl,-gc-sections 27 | COMMONFLAGS := 28 | 29 | START_GROUP := -Wl,--start-group 30 | END_GROUP := -Wl,--end-group 31 | 32 | #Additional options detected from testing the toolchain 33 | IS_LINUX_PROJECT := 1 34 | -------------------------------------------------------------------------------- /examples/PortableThreadDemo/debug__posix_.mak: -------------------------------------------------------------------------------- 1 | #Generated by VisualGDB (http://visualgdb.com) 2 | #DO NOT EDIT THIS FILE MANUALLY UNLESS YOU ABSOLUTELY NEED TO 3 | #USE VISUALGDB PROJECT PROPERTIES DIALOG INSTEAD 4 | 5 | BINARYDIR := Debug__Posix_ 6 | 7 | #Toolchain 8 | CC := gcc 9 | CXX := g++ 10 | LD := $(CXX) 11 | AR := ar 12 | OBJCOPY := objcopy 13 | 14 | #Additional flags 15 | PREPROCESSOR_MACROS := DEBUG BZS_POSIX 16 | INCLUDE_DIRS := ../.. 17 | LIBRARY_DIRS := 18 | LIBRARY_NAMES := pthread 19 | ADDITIONAL_LINKER_INPUTS := 20 | MACOS_FRAMEWORKS := 21 | LINUX_PACKAGES := 22 | 23 | CFLAGS := -ggdb -ffunction-sections -O0 24 | CXXFLAGS := -ggdb -ffunction-sections -O0 25 | ASFLAGS := 26 | LDFLAGS := -Wl,-gc-sections 27 | COMMONFLAGS := 28 | 29 | START_GROUP := -Wl,--start-group 30 | END_GROUP := -Wl,--end-group 31 | 32 | #Additional options detected from testing the toolchain 33 | IS_LINUX_PROJECT := 1 34 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/UserMode/debug__posix_.mak: -------------------------------------------------------------------------------- 1 | #Generated by VisualGDB (http://visualgdb.com) 2 | #DO NOT EDIT THIS FILE MANUALLY UNLESS YOU ABSOLUTELY NEED TO 3 | #USE VISUALGDB PROJECT PROPERTIES DIALOG INSTEAD 4 | 5 | BINARYDIR := Debug__Posix_ 6 | 7 | #Toolchain 8 | CC := gcc 9 | CXX := g++ 10 | LD := $(CXX) 11 | AR := ar 12 | OBJCOPY := objcopy 13 | 14 | #Additional flags 15 | PREPROCESSOR_MACROS := BZS_POSIX 16 | INCLUDE_DIRS := ../../.. 17 | LIBRARY_DIRS := 18 | LIBRARY_NAMES := pthread 19 | ADDITIONAL_LINKER_INPUTS := 20 | MACOS_FRAMEWORKS := 21 | LINUX_PACKAGES := 22 | 23 | CFLAGS := -ggdb -ffunction-sections 24 | CXXFLAGS := -ggdb -ffunction-sections 25 | ASFLAGS := 26 | LDFLAGS := -Wl,-gc-sections 27 | COMMONFLAGS := 28 | 29 | START_GROUP := -Wl,--start-group 30 | END_GROUP := -Wl,--end-group 31 | 32 | #Additional options detected from testing the toolchain 33 | IS_LINUX_PROJECT := 1 34 | -------------------------------------------------------------------------------- /examples/PortableThreadDemo/release__posix_.mak: -------------------------------------------------------------------------------- 1 | #Generated by VisualGDB (http://visualgdb.com) 2 | #DO NOT EDIT THIS FILE MANUALLY UNLESS YOU ABSOLUTELY NEED TO 3 | #USE VISUALGDB PROJECT PROPERTIES DIALOG INSTEAD 4 | 5 | BINARYDIR := Release__Posix_ 6 | 7 | #Toolchain 8 | CC := gcc 9 | CXX := g++ 10 | LD := $(CXX) 11 | AR := ar 12 | OBJCOPY := objcopy 13 | 14 | #Additional flags 15 | PREPROCESSOR_MACROS := NDEBUG RELEASE BZS_POSIX 16 | INCLUDE_DIRS := ../.. 17 | LIBRARY_DIRS := 18 | LIBRARY_NAMES := pthread 19 | ADDITIONAL_LINKER_INPUTS := 20 | MACOS_FRAMEWORKS := 21 | LINUX_PACKAGES := 22 | 23 | CFLAGS := -ggdb -ffunction-sections -O3 24 | CXXFLAGS := -ggdb -ffunction-sections -O3 25 | ASFLAGS := 26 | LDFLAGS := -Wl,-gc-sections 27 | COMMONFLAGS := 28 | 29 | START_GROUP := -Wl,--start-group 30 | END_GROUP := -Wl,--end-group 31 | 32 | #Additional options detected from testing the toolchain 33 | IS_LINUX_PROJECT := 1 34 | -------------------------------------------------------------------------------- /bzshlp/bzsdisk.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cmndef.h" 3 | #include "../bzscore/objmgr.h" 4 | #include "../bzscore/status.h" 5 | 6 | namespace BazisLib 7 | { 8 | class AIBasicBlockDevice : AUTO_INTERFACE 9 | { 10 | public: 11 | virtual unsigned GetSectorSize()=0; 12 | virtual ULONGLONG GetSectorCount()=0; 13 | virtual void Dispose()=0; 14 | 15 | virtual unsigned Read(ULONGLONG ByteOffset, void *pBuffer, unsigned Length)=0; 16 | virtual unsigned Write(ULONGLONG ByteOffset, const void *pBuffer, unsigned Length)=0; 17 | virtual bool DeviceControl(unsigned CtlCode, void *pBuffer, unsigned InSize, unsigned OutSize, unsigned *pBytesDone)=0; 18 | virtual ActionStatus Initialize()=0; 19 | 20 | virtual ~AIBasicBlockDevice() {} 21 | }; 22 | 23 | class AIBasicDisk : public AIBasicBlockDevice 24 | { 25 | public: 26 | virtual LPCGUID GetStableGuid()=0; 27 | virtual bool IsWritable()=0; 28 | 29 | virtual ~AIBasicDisk() {} 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/AutoTestLib/AutoTests.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | 4 | bool ObjectManagerTestEntry(bool runTestsCausingMemoryLeaks); 5 | bool TestPathAPI(); 6 | bool TestFileAPI(const BazisLib::String &tempPath); 7 | bool TestThreadAPI(); 8 | bool TestConfigurationStorageAPI(); 9 | 10 | bool TestAtomicAPI(); 11 | bool TestSyncAPI(); 12 | 13 | bool TestSocketAPI(); 14 | 15 | bool AutoTestEntry(bool runTestsCausingMemoryLeaks, const TCHAR *pTempDir) 16 | { 17 | if (!TestPathAPI()) 18 | return false; 19 | if (!TestAtomicAPI()) 20 | return false; 21 | if (!ObjectManagerTestEntry(runTestsCausingMemoryLeaks)) 22 | return false; 23 | if (!TestConfigurationStorageAPI()) 24 | return false; 25 | if (!TestFileAPI(pTempDir)) 26 | return false; 27 | if (!TestThreadAPI()) 28 | return false; 29 | if (!TestSyncAPI()) 30 | return false; 31 | if (!TestSocketAPI()) 32 | return false; 33 | 34 | return true; 35 | } -------------------------------------------------------------------------------- /bzscore/sync.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "autolock.h" 4 | #include "cmndef.h" 5 | 6 | namespace BazisLib 7 | { 8 | enum EventType 9 | { 10 | kManualResetEvent, 11 | kAutoResetEvent, 12 | }; 13 | } 14 | 15 | #ifdef BZSLIB_POSIX 16 | #include "Posix/sync.h" 17 | #elif defined (BZSLIB_KEXT) 18 | #include "KEXT/sync.h" 19 | #elif defined (BZSLIB_WINKERNEL) 20 | #include "WinKernel/sync.h" 21 | #elif defined (_WIN32) 22 | #include "Win32/sync.h" 23 | #else 24 | #error No synchronization classes defined for current platform 25 | #endif 26 | 27 | using BazisLib::Mutex; 28 | using BazisLib::Event; 29 | using BazisLib::Semaphore; 30 | using BazisLib::RWLock; 31 | 32 | namespace BazisLib 33 | { 34 | typedef FastLocker MutexLocker; 35 | typedef FastLocker MutexUnlocker; 36 | 37 | typedef _ReadLocker ReadLocker; 38 | typedef _WriteLocker WriteLocker; 39 | typedef _WriteFromReadLocker WriteFromReadLocker; 40 | } 41 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/UserMode/UserMode.cpp: -------------------------------------------------------------------------------- 1 | // UserMode.cpp : Defines the entry point for the console application. 2 | // 3 | #include "stdafx.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace BazisLib; 12 | 13 | bool AutoTestEntry(bool runTestsCausingMemoryLeaks, const TCHAR *pTempDir); 14 | 15 | void TestPrint(const char *pFormat, ...) 16 | { 17 | va_list lst; 18 | va_start(lst, pFormat); 19 | vprintf(pFormat, lst); 20 | va_end(lst); 21 | } 22 | 23 | #include 24 | 25 | int main(int argc, char* argv[]) 26 | { 27 | String tmp = Path::GetSpecialDirectoryLocation(dirTemp); 28 | if (!AutoTestEntry(false, tmp.c_str())) 29 | { 30 | printf("Automatic tests failed!\n"); 31 | return 1; 32 | } 33 | 34 | printf("Automatic tests succeeded!\n"); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /bzshlp/Win32/volmgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cmndef.h" 3 | #include "../../bzscore/string.h" 4 | #include "guid.h" 5 | #include 6 | 7 | #ifndef UNDER_CE 8 | 9 | namespace BazisLib 10 | { 11 | namespace Win32 12 | { 13 | class VolumeManager 14 | { 15 | public: 16 | VolumeManager(void); 17 | ~VolumeManager(void); 18 | 19 | public: 20 | static String GetVolumeNameForGuid(const Guid &guid); 21 | static String GetVolumeMountPointForGuid(const Guid &guid); 22 | static TCHAR GetDriveLetterForGuid(const Guid &guid); 23 | static ActionStatus ChangeVolumeLetter(TCHAR oldLetter, TCHAR newLetter, bool bForce); 24 | 25 | static ActionStatus DismountVolume(TCHAR driveLetter); 26 | 27 | struct MountedVolume 28 | { 29 | String DeviceName; 30 | String MainVolumeName; 31 | std::vector MountPoints; 32 | }; 33 | 34 | static std::vector GetAllMountedVolumes(); 35 | }; 36 | } 37 | } 38 | 39 | #endif -------------------------------------------------------------------------------- /bzscore/WinKernel/ddk_string.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #ifdef BZSLIB_WINKERNEL 3 | #include "../string.h" 4 | 5 | namespace BazisLib 6 | { 7 | String ANSIStringToString(const TempStringA &str) 8 | { 9 | ANSI_STRING srcString; 10 | str.FillNTString(&srcString); 11 | String ret; 12 | size_t newLen = RtlAnsiStringToUnicodeSize(&srcString) / sizeof(wchar_t); 13 | if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(ret.ToNTString(newLen), &srcString, FALSE))) 14 | ret.SetLength(0); 15 | else 16 | ret.UpdateLengthFromNTString(); 17 | return ret; 18 | } 19 | 20 | DynamicStringA StringToANSIString(const TempString &str) 21 | { 22 | UNICODE_STRING srcString; 23 | str.FillNTString(&srcString); 24 | DynamicStringA ret; 25 | size_t newLen = RtlUnicodeStringToAnsiSize(&srcString); 26 | if (!NT_SUCCESS(RtlUnicodeStringToAnsiString(ret.ToNTString(newLen), &srcString, FALSE))) 27 | ret.SetLength(0); 28 | else 29 | ret.UpdateLengthFromNTString(); 30 | return ret; 31 | } 32 | } 33 | 34 | #endif -------------------------------------------------------------------------------- /bzshlp/endian.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cmndef.h" 3 | 4 | namespace BazisLib 5 | { 6 | static inline unsigned short SwapByteOrder16(unsigned short val) 7 | { 8 | return ((val & 0xFF00) >> 8) | ((val & 0x00FF) << 8); 9 | } 10 | 11 | static inline unsigned SwapByteOrder32(unsigned val) 12 | { 13 | return ((val & 0xFF000000) >> 24) | ((val & 0x00FF0000) >> 8) | ((val & 0x0000FF00) << 8) | ((val & 0x000000FF) << 24); 14 | } 15 | 16 | static inline ULONGLONG SwapByteOrder64(ULONGLONG val) 17 | { 18 | return (((ULONGLONG)SwapByteOrder32((unsigned)val)) << 32) | SwapByteOrder32((unsigned)(val >> 32)); 19 | } 20 | 21 | static inline short SwapByteOrder(const unsigned short *pVal) {return SwapByteOrder16(*pVal);} 22 | static inline unsigned SwapByteOrder(const unsigned *pVal) {return SwapByteOrder32(*pVal);} 23 | static inline unsigned long SwapByteOrder(const unsigned long *pVal) {return SwapByteOrder32(*pVal);} 24 | static inline ULONGLONG SwapByteOrder(const ULONGLONG *pVal) {return SwapByteOrder64(*pVal);} 25 | } -------------------------------------------------------------------------------- /bzshlp/WinKernel/filter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "pnpdevice.h" 3 | #include "devapi.h" 4 | 5 | namespace BazisLib 6 | { 7 | namespace DDK 8 | { 9 | /* The Filter class is subclassed from PNPDevice because PnP IRPs are processed in filter-like manner. 10 | That allows using existing PNPDevice code for handling PnP events. 11 | */ 12 | class Filter : protected PNPDevice 13 | { 14 | private: 15 | ExternalDeviceObjectReference m_BaseDeviceReference; 16 | 17 | public: 18 | Filter(LPCWSTR pwszBaseDeviceName, 19 | bool bDeleteThisAfterRemoveRequest = false, 20 | LPCWSTR pwszFilterDeviceName = NULL, 21 | DEVICE_TYPE FilterDeviceType = FILE_DEVICE_UNKNOWN, 22 | ULONG DeviceCharacteristics = FILE_DEVICE_SECURE_OPEN, 23 | bool bExclusive = FALSE, 24 | ULONG AdditionalDeviceFlags = DO_POWER_PAGABLE); 25 | 26 | ~Filter(); 27 | 28 | bool Valid() {return __super::Valid();} 29 | 30 | NTSTATUS Register(Driver *pDriver, const GUID *pInterfaceGuid = NULL); 31 | 32 | }; 33 | } 34 | } -------------------------------------------------------------------------------- /bzscore/kext.mak: -------------------------------------------------------------------------------- 1 | #CC := llvm-gcc-4.2 2 | CC := llvm-gcc-4.2 3 | CXX := $(CC) 4 | LD := $(CC) 5 | 6 | KEXT_SDK := /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk 7 | 8 | KEXTFLAGS := -arch x86_64 -fmessage-length=0 -pipe -nostdinc -fno-builtin -Wno-trigraphs -fno-exceptions -force_cpusubtype_ALL -msoft-float -fno-common -mkernel -finline -fno-keep-inline-functions -Wmissing-prototypes -Wreturn-type -Wunused-variable -Wshorten-64-to-32 -DDEBUG=1 -DKERNEL -DKERNEL_PRIVATE -DDRIVER_PRIVATE -DAPPLE -DNeXT -isysroot $(KEXT_SDK) -fasm-blocks -mmacosx-version-min=10.7 -ggdb -I/System/Library/Frameworks/Kernel.framework/PrivateHeaders -I$(KEXT_SDK)/System/Library/Frameworks/Kernel.framework/Headers 9 | CXX_KEXTFLAGS := -fapple-kext -fcheck-new -fno-rtti 10 | 11 | CFLAGS += -x c $(KEXTFLAGS) 12 | CXXFLAGS += -x c++ $(KEXTFLAGS) $(CXX_KEXTFLAGS) 13 | LDFLAGS := -arch x86_64 -isysroot $(KEXT_SDK) -mmacosx-version-min=10.7 -lcpp_kext -Xlinker -kext -nostdlib -lkmodc++ -lkmod -lcc_kext 14 | PREPROCESSOR_MACROS := BZS_KEXT 15 | -------------------------------------------------------------------------------- /bzshlp/WinKernel/filter.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #ifdef BZSLIB_WINKERNEL 3 | #include "filter.h" 4 | 5 | using namespace BazisLib::DDK; 6 | 7 | Filter::Filter(LPCWSTR pwszBaseDeviceName, 8 | bool bDeleteThisAfterRemoveRequest, 9 | LPCWSTR pwszFilterDeviceName, 10 | DEVICE_TYPE FilterDeviceType, 11 | ULONG DeviceCharacteristics, 12 | bool bExclusive, 13 | ULONG AdditionalDeviceFlags) : 14 | PNPDevice(FilterDeviceType, bDeleteThisAfterRemoveRequest, DeviceCharacteristics, bExclusive, AdditionalDeviceFlags, pwszFilterDeviceName), 15 | m_BaseDeviceReference(pwszBaseDeviceName) 16 | { 17 | if (!m_BaseDeviceReference.Valid()) 18 | ReportInitializationError(STATUS_INVALID_DEVICE_OBJECT_PARAMETER); 19 | } 20 | 21 | Filter::~Filter() 22 | { 23 | } 24 | 25 | NTSTATUS Filter::Register(Driver *pDriver, const GUID *pInterfaceGuid) 26 | { 27 | if (!m_BaseDeviceReference.Valid()) 28 | return STATUS_INVALID_DEVICE_OBJECT_PARAMETER; 29 | return __super::AddDevice(pDriver, m_BaseDeviceReference.GetDeviceObject(), pInterfaceGuid); 30 | } 31 | #endif -------------------------------------------------------------------------------- /bzscore/WinKernel/memdbg.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #ifdef BZSLIB_WINKERNEL 3 | #include "memdbg.h" 4 | 5 | namespace BazisLib 6 | { 7 | namespace MemoryDebug 8 | { 9 | long AllocCount = 0; 10 | 11 | void *OnMemoryAllocation(void *pBlock, size_t size) 12 | { 13 | #ifdef _DEBUG 14 | if (pBlock) 15 | memset(pBlock, 0xCC, size); 16 | #endif 17 | InterlockedIncrement(&AllocCount); 18 | return pBlock; 19 | } 20 | 21 | void *OnMemoryFree(void *pBlock) 22 | { 23 | InterlockedDecrement(&AllocCount); 24 | return pBlock; 25 | } 26 | 27 | void OnProgramTermination() 28 | { 29 | if (AllocCount) 30 | { 31 | DbgPrint("*****************************************************\n"); 32 | DbgPrint("* WARNING *\n"); 33 | DbgPrint("* MEMORY LEAKS HAVE BEEN DETECTED IN THE DRIVER *\n"); 34 | DbgPrint("* %5d total memory allocations are not freed *\n", AllocCount); 35 | DbgPrint("*****************************************************\n"); 36 | } 37 | } 38 | } 39 | } 40 | #endif -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | BazisLib Overview 2 | ================= 3 | 4 | The BazisLib framework provides a convenient multi-platform abstraction layer for the following APIs: 5 | * Thread and synchronization API 6 | * File access API 7 | * Atomic operations 8 | * Reference counting 9 | * Sockets (Windows Kernel not supported) 10 | * FS path manipulation 11 | * Configuration storage 12 | 13 | BazisLib also provides some convenience classes that simplify driver development for Windows and MacOS in C++. 14 | 15 | BazisLib can be compiled for the following targets: 16 | * Windows user-mode using Visual Studio compiler 17 | * Windows kernel-mode using WDK 7.x or 8.x 18 | * Linux or MacOS user-mode using GCC or Clang 19 | * MacOS kernel-mode 20 | 21 | The best way to start exploring BazisLib is to open the tests\BigCrossPlatformTest\BigCrossPlatformTest.sln solution and try building/running the Windows configuration. Other configurations of the solution 22 | target POSIX user-mode, Windows kernel-mode and MacOS kernel-mode environments. The Examples folder contains some other sample projects using BazisLib. 23 | -------------------------------------------------------------------------------- /bzshlp/bzsstream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cmndef.h" 3 | 4 | namespace BazisLib 5 | { 6 | //The xxxStream interfaces are obsolette. When possible, use AIFile interface and BasicFileBase class 7 | //to implement custom files. Using a limited number of methods in a single interface produces less 8 | //overhead (less space is required for vtable and vcast pointers), while unused and unimplemented 9 | //AIFile methods produce completely no overhead. 10 | enum {STREAM_SIZE_UNKNOWN = -1LL}; 11 | 12 | class IInStream 13 | { 14 | public: 15 | virtual size_t Read(void *pBuffer, size_t size)=0; 16 | virtual LONGLONG GetSize()=0; 17 | virtual ~IInStream(){} 18 | }; 19 | 20 | class IOutStream 21 | { 22 | public: 23 | virtual size_t Write(const void *pBuffer, size_t size)=0; 24 | virtual ~IOutStream(){} 25 | }; 26 | 27 | class IPipe : public IInStream, public IOutStream 28 | { 29 | public: 30 | virtual bool SetTimeout(unsigned ReadTimeout, unsigned WriteTimeout)=0; 31 | virtual void Close()=0; 32 | virtual bool Valid()=0; 33 | virtual ~IPipe(){} 34 | }; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /bzscore/Posix/kext.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #ifdef BZSLIB_KEXT 3 | 4 | #include //Includes STLPort headers containing malloc() definition 5 | 6 | __private_extern__ void * _realloc(void * _Memory, size_t _Size, size_t _OldSize) 7 | { 8 | if (!_Memory) 9 | return malloc(_Size); 10 | if (!_Size) 11 | { 12 | free(_Memory); 13 | return NULL; 14 | } 15 | void *pMem = malloc(_Size); 16 | if (!pMem) 17 | { 18 | free(_Memory); 19 | return NULL; 20 | } 21 | size_t todo = _Size; 22 | if (_OldSize < todo) 23 | todo = _OldSize; 24 | 25 | memcpy(pMem, _Memory, todo); 26 | free(_Memory); 27 | return pMem; 28 | } 29 | 30 | /* 31 | 32 | static wchar_t wtolower(wchar_t ch) 33 | { 34 | if (ch >= 'A' && ch <= 'Z') 35 | ch |= 0x20; 36 | 37 | return ch; 38 | } 39 | 40 | __private_extern__ int wcscasecmp(const wchar_t *s1, const wchar_t *s2) 41 | { 42 | for (int i = 0; ; i++) 43 | { 44 | wchar_t c1 = wtolower(s1[i]); 45 | wchar_t c2 = wtolower(s2[i]); 46 | if (!c1 || (c1 != c2)) 47 | return c1 - c2; 48 | } 49 | } 50 | */ 51 | 52 | #include "../assert.h" 53 | 54 | #endif -------------------------------------------------------------------------------- /bzshlp/WinKernel/AlertableQueue.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #ifdef BZSLIB_WINKERNEL 3 | 4 | #include "AlertableQueue.h" 5 | 6 | using namespace BazisLib::DDK; 7 | 8 | AlertableQueue::~AlertableQueue() 9 | { 10 | //This auto-object is destroyed when no other references are available and thus no other method can be called 11 | while (!m_Queue.empty()) 12 | { 13 | delete m_Queue.front(); 14 | m_Queue.pop(); 15 | } 16 | } 17 | 18 | NTSTATUS BazisLib::DDK::AlertableQueue::WaitAndDequeue( Item **ppItem, ULONG Timeout) 19 | { 20 | NTSTATUS status; 21 | if (Timeout == ((ULONG)-1L)) 22 | status = m_Semaphore.WaitEx(UserRequest, UserMode); 23 | else 24 | status = m_Semaphore.WaitWithTimeoutEx(((ULONGLONG)Timeout) * 10000, UserRequest, UserMode); 25 | 26 | if (status == STATUS_SUCCESS) 27 | { 28 | if (_Shutdown) 29 | return STATUS_CANCELLED; 30 | 31 | FastMutexLocker lck(m_QueueMutex); 32 | ASSERT(!m_Queue.empty()); 33 | *ppItem = m_Queue.front(); 34 | m_Queue.pop(); 35 | return STATUS_SUCCESS; 36 | } 37 | ASSERT(status == STATUS_USER_APC); 38 | return status; 39 | } 40 | #endif -------------------------------------------------------------------------------- /bzshlp/MacOS/CFHandle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace BazisLib 5 | { 6 | namespace MacOS 7 | { 8 | template class CFHandle 9 | { 10 | private: 11 | _Type _TypeRef; 12 | 13 | public: 14 | CFHandle(_Type obj = 0) 15 | : _TypeRef(obj) 16 | { 17 | } 18 | 19 | ~CFHandle() 20 | { 21 | if (_TypeRef) 22 | CFRelease(_TypeRef); 23 | } 24 | 25 | CFHandle(const CFHandle &handle) 26 | : _TypeRef(handle._TypeRef) 27 | { 28 | if (_TypeRef) 29 | CFRetain(_TypeRef); 30 | } 31 | 32 | _Type get() const {return _TypeRef;} 33 | operator bool() {return _TypeRef != 0;} 34 | 35 | CFHandle &operator=(_Type obj) 36 | { 37 | if (_TypeRef) 38 | CFRelease(_TypeRef); 39 | _TypeRef = obj; 40 | if (_TypeRef) 41 | CFRetain(_TypeRef); 42 | return *this; 43 | } 44 | 45 | CFHandle &operator=(CFHandle &handle) 46 | { 47 | if (_TypeRef) 48 | CFRelease(_TypeRef); 49 | _TypeRef = handle._TypeRef; 50 | if (_TypeRef) 51 | CFRetain(_TypeRef); 52 | } 53 | 54 | }; 55 | } 56 | } -------------------------------------------------------------------------------- /bzscore/Win32/win32_status.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #ifdef BZSLIB_WINUSER 3 | #include "../status.h" 4 | 5 | using namespace BazisLib; 6 | 7 | String ActionStatus::FormatErrorCode(CommonErrorType code) 8 | { 9 | if (HRESULT_FACILITY(code) == FACILITY_ITF) 10 | { 11 | size_t idx = code & 0xFFFF; 12 | if (idx < _CustomStatusObjectsInternal.size()) 13 | return _CustomStatusObjectsInternal[idx]->GetStatusText(); 14 | } 15 | 16 | LPTSTR lpBuffer = NULL; 17 | FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 18 | NULL, 19 | (DWORD)code, 20 | 0, 21 | (LPTSTR)&lpBuffer, 22 | 0, 23 | NULL); 24 | if (!lpBuffer) 25 | { 26 | TCHAR tsz[512]; 27 | #ifdef UNDER_CE 28 | _sntprintf(tsz, sizeof(tsz)/sizeof(tsz[0]), _T("HRESULT code 0x%08X"), code); 29 | #else 30 | _sntprintf_s(tsz, sizeof(tsz)/sizeof(tsz[0]), _TRUNCATE, _T("HRESULT code 0x%08X"), code); 31 | #endif 32 | return tsz; 33 | } 34 | else 35 | { 36 | LPTSTR lpCrlf = _tcsstr(lpBuffer, _T("\r\n")); 37 | if (lpCrlf) 38 | lpCrlf[0] = 0; 39 | } 40 | String text = lpBuffer; 41 | LocalFree(lpBuffer); 42 | return text; 43 | } 44 | #endif -------------------------------------------------------------------------------- /bzscore/WinKernel/VisualDDKHelpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /*! \file 4 | \brief Contains definitions making handles and NTSTATUS variables recognizable by debugger 5 | This file contains definitions for special helper structures and enums, so NTSTATUS and HANDLE 6 | variables will not appear in debugger as "unsigned long" and "void *". 7 | 8 | Once the variable type is recognized correctly, VisualDDK can display additional information 9 | about this types, such as translated NTSTATUS code and object referenced by handle. 10 | */ 11 | 12 | #ifdef _DEBUG 13 | 14 | #include 15 | #include 16 | 17 | typedef enum NTSTATUS_VisualDDK_Helper {} NTSTATUS_VisualDDK_Helper_t; 18 | C_ASSERT(sizeof(NTSTATUS_VisualDDK_Helper) == sizeof(NTSTATUS)); 19 | 20 | #define NTSTATUS NTSTATUS_VisualDDK_Helper_t 21 | 22 | typedef struct HANDLE_VisualDDK_Helper *HANDLE_VisualDDK_Helper_t, **PHANDLE_VisualDDK_Helper_t; 23 | C_ASSERT(sizeof(HANDLE_VisualDDK_Helper_t) == sizeof(HANDLE)); 24 | C_ASSERT(sizeof(PHANDLE_VisualDDK_Helper_t) == sizeof(PHANDLE)); 25 | 26 | #define HANDLE HANDLE_VisualDDK_Helper_t 27 | #define PHANDLE PHANDLE_VisualDDK_Helper_t 28 | 29 | #endif -------------------------------------------------------------------------------- /bzshlp/WinKernel/VisualDDKHelpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /*! \file 4 | \brief Contains definitions making handles and NTSTATUS variables recognizable by debugger 5 | This file contains definitions for special helper structures and enums, so NTSTATUS and HANDLE 6 | variables will not appear in debugger as "unsigned long" and "void *". 7 | 8 | Once the variable type is recognized correctly, VisualDDK can display additional information 9 | about this types, such as translated NTSTATUS code and object referenced by handle. 10 | */ 11 | 12 | #ifdef _DEBUG 13 | 14 | #include 15 | #include 16 | 17 | typedef enum NTSTATUS_VisualDDK_Helper {} NTSTATUS_VisualDDK_Helper_t; 18 | C_ASSERT(sizeof(NTSTATUS_VisualDDK_Helper) == sizeof(NTSTATUS)); 19 | 20 | #define NTSTATUS NTSTATUS_VisualDDK_Helper_t 21 | 22 | typedef struct HANDLE_VisualDDK_Helper *HANDLE_VisualDDK_Helper_t, **PHANDLE_VisualDDK_Helper_t; 23 | C_ASSERT(sizeof(HANDLE_VisualDDK_Helper_t) == sizeof(HANDLE)); 24 | C_ASSERT(sizeof(PHANDLE_VisualDDK_Helper_t) == sizeof(PHANDLE)); 25 | 26 | #define HANDLE HANDLE_VisualDDK_Helper_t 27 | #define PHANDLE PHANDLE_VisualDDK_Helper_t 28 | 29 | #endif -------------------------------------------------------------------------------- /examples/WinKernel/FileDiskBus/VisualDDKHelpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /*! \file 4 | \brief Contains definitions making handles and NTSTATUS variables recognizable by debugger 5 | This file contains definitions for special helper structures and enums, so NTSTATUS and HANDLE 6 | variables will not appear in debugger as "unsigned long" and "void *". 7 | 8 | Once the variable type is recognized correctly, VisualDDK can display additional information 9 | about this types, such as translated NTSTATUS code and object referenced by handle. 10 | */ 11 | 12 | #ifdef _DEBUG 13 | 14 | #include 15 | #include 16 | 17 | typedef enum NTSTATUS_VisualDDK_Helper {} NTSTATUS_VisualDDK_Helper_t; 18 | C_ASSERT(sizeof(NTSTATUS_VisualDDK_Helper_t) == sizeof(NTSTATUS)); 19 | 20 | #define NTSTATUS NTSTATUS_VisualDDK_Helper_t 21 | 22 | typedef struct HANDLE_VisualDDK_Helper *HANDLE_VisualDDK_Helper_t, **PHANDLE_VisualDDK_Helper_t; 23 | C_ASSERT(sizeof(HANDLE_VisualDDK_Helper_t) == sizeof(HANDLE)); 24 | C_ASSERT(sizeof(PHANDLE_VisualDDK_Helper_t) == sizeof(PHANDLE)); 25 | 26 | #define HANDLE HANDLE_VisualDDK_Helper_t 27 | #define PHANDLE PHANDLE_VisualDDK_Helper_t 28 | 29 | #endif -------------------------------------------------------------------------------- /examples/WinKernel/RamDiskBus/VisualDDKHelpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /*! \file 4 | \brief Contains definitions making handles and NTSTATUS variables recognizable by debugger 5 | This file contains definitions for special helper structures and enums, so NTSTATUS and HANDLE 6 | variables will not appear in debugger as "unsigned long" and "void *". 7 | 8 | Once the variable type is recognized correctly, VisualDDK can display additional information 9 | about this types, such as translated NTSTATUS code and object referenced by handle. 10 | */ 11 | 12 | #ifdef _DEBUG 13 | 14 | #include 15 | #include 16 | 17 | typedef enum NTSTATUS_VisualDDK_Helper {} NTSTATUS_VisualDDK_Helper_t; 18 | C_ASSERT(sizeof(NTSTATUS_VisualDDK_Helper_t) == sizeof(NTSTATUS)); 19 | 20 | #define NTSTATUS NTSTATUS_VisualDDK_Helper_t 21 | 22 | typedef struct HANDLE_VisualDDK_Helper *HANDLE_VisualDDK_Helper_t, **PHANDLE_VisualDDK_Helper_t; 23 | C_ASSERT(sizeof(HANDLE_VisualDDK_Helper_t) == sizeof(HANDLE)); 24 | C_ASSERT(sizeof(PHANDLE_VisualDDK_Helper_t) == sizeof(PHANDLE)); 25 | 26 | #define HANDLE HANDLE_VisualDDK_Helper_t 27 | #define PHANDLE PHANDLE_VisualDDK_Helper_t 28 | 29 | #endif -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/KernelMode/VisualDDKHelpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /*! \file 4 | \brief Contains definitions making handles and NTSTATUS variables recognizable by debugger 5 | This file contains definitions for special helper structures and enums, so NTSTATUS and HANDLE 6 | variables will not appear in debugger as "unsigned long" and "void *". 7 | 8 | Once the variable type is recognized correctly, VisualDDK can display additional information 9 | about this types, such as translated NTSTATUS code and object referenced by handle. 10 | */ 11 | 12 | #ifdef _DEBUG 13 | 14 | #include 15 | #include 16 | 17 | typedef enum NTSTATUS_VisualDDK_Helper {} NTSTATUS_VisualDDK_Helper_t; 18 | C_ASSERT(sizeof(NTSTATUS_VisualDDK_Helper_t) == sizeof(NTSTATUS)); 19 | 20 | #define NTSTATUS NTSTATUS_VisualDDK_Helper_t 21 | 22 | typedef struct HANDLE_VisualDDK_Helper *HANDLE_VisualDDK_Helper_t, **PHANDLE_VisualDDK_Helper_t; 23 | C_ASSERT(sizeof(HANDLE_VisualDDK_Helper_t) == sizeof(HANDLE)); 24 | C_ASSERT(sizeof(PHANDLE_VisualDDK_Helper_t) == sizeof(PHANDLE)); 25 | 26 | #define HANDLE HANDLE_VisualDDK_Helper_t 27 | #define PHANDLE PHANDLE_VisualDDK_Helper_t 28 | 29 | #endif -------------------------------------------------------------------------------- /bzshlp/UserModeWorkerBackend.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace BazisLib 7 | { 8 | class UserModeWorkerBackend 9 | { 10 | private: 11 | bool _Cancelling; 12 | 13 | Event _RequestCompletedEvent; 14 | EventWithHandle _RequestReadyEvent; 15 | 16 | Mutex _RequestProcessMutex; 17 | Mutex _RequestFieldChangeMutex; 18 | CBuffer *m_pActiveInBuffer, *m_pActiveOutBuffer; 19 | 20 | public: 21 | UserModeWorkerBackend() 22 | : _Cancelling(false) 23 | , m_pActiveOutBuffer(NULL) 24 | , m_pActiveInBuffer(NULL) 25 | { 26 | } 27 | 28 | public: 29 | //Called from worker thread to submit a request to user-mode 30 | bool ProcessRequest(CBuffer &inputBuffer, CBuffer &outputBuffer); 31 | 32 | public: //Called from IOCTL handlers 33 | ActionStatus GetNextPendingRequest(void *pBuffer, IN OUT size_t *pBufferSize); 34 | ActionStatus SubmitReplyToRequest(const void *pBuffer, size_t replySize); 35 | size_t GetPendingRequestSize(); 36 | 37 | EventWithHandle &GetUserModeEvent() {return _RequestReadyEvent;} 38 | void Shutdown() {_Cancelling = true; _RequestReadyEvent.Set(); _RequestCompletedEvent.Set();} 39 | }; 40 | } -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/AutoTestLib/WeakRefTest.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | #include "TestPrint.h" 4 | 5 | using namespace BazisLib; 6 | 7 | class AutoObj1 : AUTO_OBJECT 8 | { 9 | public: 10 | void Test(){} 11 | }; 12 | 13 | 14 | bool TestWeakLinks() 15 | { 16 | ManagedPointer pObj = new AutoObj1(); 17 | 18 | WeakManagedPointer pWeak = pObj; 19 | 20 | ManagedPointer pObj2 = pWeak; 21 | if (pObj2 != pObj) 22 | { 23 | TestPrint("Opening weak reference failed!\n"); 24 | return false; 25 | } 26 | 27 | pObj = NULL; 28 | pObj2 = NULL; 29 | 30 | pObj2 = pWeak; 31 | if (pObj2) 32 | { 33 | TestPrint("Weak-referenced object was not deleted!\n"); 34 | return false; 35 | } 36 | 37 | pWeak = NULL; 38 | 39 | pObj = new AutoObj1(); 40 | pWeak = pObj; 41 | WeakManagedPointer pWeak2 = pWeak; 42 | pWeak = NULL; 43 | pWeak2 = NULL; 44 | pObj = NULL; 45 | 46 | pObj = new AutoObj1(); 47 | pWeak = pObj; 48 | pWeak = NULL; 49 | pWeak = pObj; 50 | pWeak2 = pWeak; 51 | pWeak = NULL; 52 | pObj2 = pWeak2; 53 | 54 | if (pObj2 != pObj) 55 | { 56 | TestPrint("Opening weak reference failed!\n"); 57 | return false; 58 | } 59 | 60 | return true; 61 | } -------------------------------------------------------------------------------- /bzscore/WinKernel/string.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace BazisLib 6 | { 7 | namespace DDK 8 | { 9 | class StaticString 10 | { 11 | private: 12 | UNICODE_STRING m_unicodeStr; 13 | 14 | private: 15 | void Initialize(const wchar_t *pwsz, unsigned allocLength = 0) 16 | { 17 | if (!pwsz) 18 | m_unicodeStr.Length = 0; 19 | else 20 | m_unicodeStr.Length = (USHORT)(wcslen(pwsz) * sizeof(wchar_t)); 21 | 22 | m_unicodeStr.MaximumLength =(USHORT)(allocLength ? (allocLength * sizeof(wchar_t)) : (m_unicodeStr.Length + sizeof(wchar_t))); 23 | m_unicodeStr.Buffer = new wchar_t[m_unicodeStr.MaximumLength]; 24 | if (m_unicodeStr.Length) 25 | memcpy(m_unicodeStr.Buffer, pwsz, (m_unicodeStr.Length + 1) * sizeof(wchar_t)); 26 | } 27 | 28 | public: 29 | StaticString(const wchar_t *pwsz, unsigned allocLength = 0) 30 | { 31 | Initialize(pwsz, allocLength); 32 | } 33 | 34 | StaticString(const String &str) 35 | { 36 | Initialize(str.c_str()); 37 | } 38 | 39 | ~StaticString() 40 | { 41 | if (m_unicodeStr.Buffer) 42 | delete m_unicodeStr.Buffer; 43 | } 44 | 45 | operator PUNICODE_STRING() 46 | { 47 | return &m_unicodeStr; 48 | } 49 | }; 50 | } 51 | } -------------------------------------------------------------------------------- /bzshlp/Win32/wow64.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cmndef.h" 3 | 4 | #ifndef UNDER_CE 5 | namespace BazisLib 6 | { 7 | class WOW64APIProvider 8 | { 9 | private: 10 | typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); 11 | typedef BOOL (WINAPI *LPFN_WOW64DISABLEREDIR) (PVOID *); 12 | typedef BOOL (WINAPI *LPFN_WOW64REVERTREDIR) (PVOID); 13 | 14 | LPFN_ISWOW64PROCESS m_fnIsWow64Process; 15 | LPFN_WOW64DISABLEREDIR m_fnDisableRedirection; 16 | LPFN_WOW64REVERTREDIR m_fnResumeRedirection; 17 | 18 | public: 19 | WOW64APIProvider(); 20 | ~WOW64APIProvider() 21 | { 22 | } 23 | 24 | bool IsWow64Process(unsigned PID = 0); 25 | bool DisableFSRedirection(PVOID *pContext); 26 | bool ResumeFSRedirection(PVOID pContext); 27 | 28 | public: 29 | static bool sIsWow64Process(unsigned PID = 0) 30 | { 31 | WOW64APIProvider prov; 32 | return prov.IsWow64Process(PID); 33 | } 34 | 35 | }; 36 | 37 | class WOW64FSRedirHolder 38 | { 39 | private: 40 | WOW64APIProvider m_Provider; 41 | PVOID m_pContext; 42 | 43 | public: 44 | WOW64FSRedirHolder() 45 | { 46 | m_Provider.DisableFSRedirection(&m_pContext); 47 | } 48 | 49 | ~WOW64FSRedirHolder() 50 | { 51 | m_Provider.ResumeFSRedirection(m_pContext); 52 | } 53 | }; 54 | } 55 | #endif -------------------------------------------------------------------------------- /bzscore/KEXT/SmartPointers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BazisLib 4 | { 5 | namespace KEXT 6 | { 7 | template class ObjectPointer 8 | { 9 | _Obj *m_pObj; 10 | 11 | public: 12 | ObjectPointer(_Obj *pObj = NULL, bool releaseOriginal = false) 13 | : m_pObj(pObj) 14 | { 15 | if (m_pObj && !releaseOriginal) 16 | m_pObj->retain(); 17 | } 18 | 19 | ~ObjectPointer() 20 | { 21 | if (m_pObj) 22 | m_pObj->release(); 23 | } 24 | 25 | void assign(_Obj *pObj) 26 | { 27 | if (m_pObj) 28 | m_pObj->release(); 29 | m_pObj = pObj; 30 | if (m_pObj) 31 | m_pObj->retain(); 32 | } 33 | 34 | ObjectPointer(const ObjectPointer<_Obj> &another) 35 | : m_pObj(another.m_pObj) 36 | { 37 | if (m_pObj) 38 | m_pObj->retain(); 39 | } 40 | 41 | ObjectPointer &operator=(const ObjectPointer<_Obj> &another) 42 | { 43 | assign(another.m_pObj); 44 | return *this; 45 | } 46 | 47 | ObjectPointer &operator=(_Obj *another) 48 | { 49 | assign(another); 50 | return *this; 51 | } 52 | 53 | _Obj *operator->() 54 | { 55 | return m_pObj; 56 | } 57 | 58 | operator bool() 59 | { 60 | return !!m_pObj; 61 | } 62 | 63 | _Obj *GetObjectForSingleUse() 64 | { 65 | return m_pObj; 66 | } 67 | }; 68 | } 69 | } -------------------------------------------------------------------------------- /bzshlp/Win32/bulkusbcmd.h: -------------------------------------------------------------------------------- 1 | /* 2 | Request format (name:bytecount): 3 | [RQTYPE:4] [RQCODE:4] [RQDATASIZE:4] [RQDATA] 4 | Result format: 5 | [RESTYPE:4] [STATUS:4] [RESDATASIZE:4] [RESDATA] 6 | 7 | Data size is in bytes. 8 | Minimal header size is 12 bytes with DATASIZE=0 9 | */ 10 | 11 | #define BULKUSB_RQTYPE_QUERY_PROTOVER 0x50BAC05A //Query current protocol version 12 | #define BULKUSB_RQTYPE_QUERY_MAX_SIZE 0x50BAC05B //Temp buffer size request 13 | #define BULKUSB_RQTYPE_USER 0x50BAC05C //Standard user request 14 | #define BULKUSB_RQTYPE_USERV 0x50BAC05D //User request with variable result size (see BULKUSB_RESTYPE_USERV) 15 | #define BULKUSB_RQTYPE_ENTERLDR 0x50BAC05E //Enter bootloader reques 16 | #define BULKUSB_RQTYPE_ENTER_RAWMODE 0x50BAC05F //Enter RAW read/write mode 17 | 18 | #define BULKUSB_RESTYPE_SYSTEM 0xA0BAC0AB //Reply to a system request 19 | #define BULKUSB_RESTYPE_USER 0xA0BAC0AC //Reply to a user request 20 | #define BULKUSB_RESTYPE_USERV 0xA0BAC0AD //Variable-size reply. The first frame contains only header, while 21 | //the next ones contain data. 22 | 23 | #define BULKUSB_STATUS_OK 0x00000000 24 | #define BULKUSB_STATUS_BADREQUEST 0x80070057L //E_INVALIDARG 25 | #define BULKUSB_STATUS_FAIL 0x80004005L //E_FAIL 26 | 27 | #define PROTOCOL_VERSION_CURRENT 0x0100 28 | 29 | #define BULKUSB_HEADER_SIZE 12 30 | -------------------------------------------------------------------------------- /bzscore/Win32/path.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #ifdef BZSLIB_WINUSER 3 | #include "../path.h" 4 | #include 5 | 6 | using namespace BazisLib; 7 | 8 | String Path::GetCurrentPath() 9 | { 10 | TCHAR tsz[MAX_PATH]; 11 | GetCurrentDirectory(sizeof(tsz)/sizeof(tsz[0]), tsz); 12 | return tsz; 13 | } 14 | 15 | String Path::GetSpecialDirectoryLocation(SpecialDirectoryType dir) 16 | { 17 | TCHAR tsz[MAX_PATH]; 18 | tsz[0] = 0; 19 | switch (dir) 20 | { 21 | case dirWindows: 22 | GetWindowsDirectory(tsz, __countof(tsz)); 23 | break; 24 | case dirSystem: 25 | GetSystemDirectory(tsz, __countof(tsz)); 26 | break; 27 | case dirDrivers: 28 | GetSystemDirectory(tsz, __countof(tsz)); 29 | _tcsncat_s(tsz, _T("\\drivers"), __countof(tsz)); 30 | break; 31 | case dirTemp: 32 | GetTempPath(__countof(tsz), tsz); 33 | break; 34 | default: 35 | SHGetSpecialFolderPath(HWND_DESKTOP, tsz, dir, TRUE); 36 | break; 37 | } 38 | return tsz; 39 | } 40 | 41 | static std::vector GetAllRootPaths() 42 | { 43 | std::vector allStrings; 44 | DWORD driveMask = GetLogicalDrives(); 45 | 46 | TCHAR tszRoot[] = _T("?:\\"); 47 | 48 | for (unsigned i = 0, j = (1 << (i - 'A')); i <= 'Z'; i++, j <<= 1) 49 | if (driveMask & j) 50 | { 51 | tszRoot[0] = i; 52 | allStrings.push_back(tszRoot); 53 | } 54 | return allStrings; 55 | } 56 | 57 | #endif -------------------------------------------------------------------------------- /bzscore/KEXT/kext_unicode.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #ifdef BZSLIB_KEXT 4 | #include "unicode.h" 5 | 6 | using namespace BazisLib; 7 | using namespace BazisLib::KEXT; 8 | 9 | #include 10 | 11 | BazisLib::DynamicStringA BazisLib::KEXT::UTF16ToUTF8( const wchar16_t *pString, size_t length /*= -1*/ ) 12 | { 13 | if (length == -1) 14 | { 15 | for (length = 0; pString[length]; length++); 16 | } 17 | 18 | DynamicStringA result; 19 | 20 | size_t size = utf8_encodelen(pString, length * 2, '/', 0); 21 | if (!size || size == -1) 22 | return result; 23 | 24 | size_t done = 0; 25 | char *pCharBuf = result.PreAllocate(size, false); 26 | utf8_encodestr(pString, length * 2, (uint8_t *)pCharBuf, &done, size + 1, '/', 0); 27 | result.SetLength(done); 28 | return result; 29 | } 30 | 31 | 32 | 33 | BazisLib::_DynamicStringT BazisLib::KEXT::UTF8ToUTF16( const char *pString, size_t length /*= -1*/ ) 34 | { 35 | if (length == -1) 36 | { 37 | for (length = 0; pString[length]; length++); 38 | } 39 | 40 | BazisLib::_DynamicStringT result; 41 | size_t done = 0; 42 | wchar16_t *pCharBuf = result.PreAllocate(length, false); 43 | utf8_decodestr((const uint8_t *)pString, length, pCharBuf, &done, (length + 1) * sizeof(pCharBuf[0]), '/', 0); 44 | result.SetLength(done / sizeof(pCharBuf[0])); 45 | return result; 46 | } 47 | 48 | 49 | #endif -------------------------------------------------------------------------------- /examples/WinKernel/RamDiskBus/Ramdisk.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __linux__ 4 | #include 5 | #else 6 | #include 7 | #endif 8 | 9 | #include 10 | #include 11 | 12 | #define RAMDISK_SECTOR_SIZE 512 13 | 14 | namespace BazisLib 15 | { 16 | class RamDisk : public AIBasicDisk, AUTO_OBJECT 17 | { 18 | protected: 19 | ULONGLONG m_SectorCount; 20 | ULONGLONG m_TotalSize; 21 | std::vector m_Buffers; 22 | 23 | unsigned DoTransfer(ULONGLONG ByteOffset, void *pBuffer, unsigned Length, bool read); 24 | 25 | 26 | public: 27 | unsigned GetSectorSize() {return RAMDISK_SECTOR_SIZE;} 28 | virtual void Dispose(){} 29 | 30 | RamDisk(unsigned MegabyteCount); 31 | ~RamDisk(); 32 | 33 | virtual ULONGLONG GetSectorCount() override; 34 | 35 | virtual unsigned Read(ULONGLONG ByteOffset, void *pBuffer, unsigned Length) override; 36 | virtual unsigned Write(ULONGLONG ByteOffset, const void *pBuffer, unsigned Length) override; 37 | virtual LPGUID GetStableGuid() override {return NULL;} 38 | 39 | virtual bool DeviceControl(unsigned CtlCode, void *pBuffer, unsigned InSize, unsigned OutSize, unsigned *pBytesDone) override {return false;} 40 | virtual ActionStatus Initialize() override {return MAKE_STATUS(Success);} 41 | virtual bool IsWritable() {return true;} 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /bzshlp/WinKernel/devapi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BazisLib 4 | { 5 | namespace DDK 6 | { 7 | /*! This class represents a device created by some other driver that is used by current driver 8 | for example (for attaching a filter). This class is CopyConstructor-aware. 9 | */ 10 | class ExternalDeviceObjectReference 11 | { 12 | PDEVICE_OBJECT m_pDeviceObject; 13 | PFILE_OBJECT m_pFileObject; 14 | 15 | public: 16 | ExternalDeviceObjectReference(const wchar_t *pwszDevicePath, ACCESS_MASK AccessMask = FILE_READ_ATTRIBUTES); 17 | 18 | ExternalDeviceObjectReference(const ExternalDeviceObjectReference &src) 19 | { 20 | m_pDeviceObject = src.m_pDeviceObject; 21 | m_pFileObject = src.m_pFileObject; 22 | if (m_pFileObject) 23 | ObReferenceObject(m_pFileObject); 24 | } 25 | 26 | ~ExternalDeviceObjectReference() 27 | { 28 | if (m_pFileObject) 29 | ObDereferenceObject(m_pFileObject); 30 | } 31 | 32 | bool Valid() 33 | { 34 | return m_pDeviceObject && m_pFileObject; 35 | } 36 | 37 | PDEVICE_OBJECT GetDeviceObject() {return m_pDeviceObject;} 38 | PFILE_OBJECT GetFileObject() {return m_pFileObject;} 39 | }; 40 | 41 | static inline INT_PTR GetObjectReferenceCount(PVOID pObject) {return ((INT_PTR *)pObject)[-6];} 42 | static inline INT_PTR GetObjectHandleCount(PVOID pObject) {return ((INT_PTR *)pObject)[-5];} 43 | } 44 | } -------------------------------------------------------------------------------- /support/strgen/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | CONSOLE APPLICATION : strgen Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this strgen application for you. 6 | 7 | This file contains a summary of what you will find in each of the files that 8 | make up your strgen application. 9 | 10 | 11 | strgen.vcproj 12 | This is the main project file for VC++ projects generated using an Application Wizard. 13 | It contains information about the version of Visual C++ that generated the file, and 14 | information about the platforms, configurations, and project features selected with the 15 | Application Wizard. 16 | 17 | strgen.cpp 18 | This is the main application source file. 19 | 20 | ///////////////////////////////////////////////////////////////////////////// 21 | Other standard files: 22 | 23 | StdAfx.h, StdAfx.cpp 24 | These files are used to build a precompiled header (PCH) file 25 | named strgen.pch and a precompiled types file named StdAfx.obj. 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | Other notes: 29 | 30 | AppWizard uses "TODO:" comments to indicate parts of the source code you 31 | should add to or customize. 32 | 33 | ///////////////////////////////////////////////////////////////////////////// 34 | -------------------------------------------------------------------------------- /support/strgen/StringManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | class LocalizableStringManager 7 | { 8 | private: 9 | struct DialogMember 10 | { 11 | BazisLib::String Name; 12 | bool Localized; 13 | bool Skipped; 14 | 15 | DialogMember() 16 | : Localized(false) 17 | , Skipped(false) 18 | { 19 | } 20 | }; 21 | 22 | struct DialogRecord 23 | { 24 | bool Localized; 25 | BazisLib::String Caption; 26 | std::map DialogMembers; 27 | 28 | BazisLib::String FileAndLine; 29 | BazisLib::String LocalizationFileAndLine; 30 | 31 | DialogRecord() 32 | : Localized(false) 33 | { 34 | } 35 | }; 36 | 37 | struct StringRecord 38 | { 39 | BazisLib::String Value; 40 | }; 41 | 42 | 43 | std::map m_Dialogs; 44 | std::map m_Strings; 45 | 46 | private: 47 | BazisLib::String FormatStringASCString(const BazisLib::TempString &str); 48 | 49 | public: 50 | bool ParseResourceFile(const BazisLib::String &fp); 51 | bool ParseSourceFile(const BazisLib::String &fp); 52 | 53 | void FindAndDisplayStructuralWarnings(); 54 | 55 | bool ProduceHeaderFile(const BazisLib::String &fp); 56 | bool ProduceLanguageFile(const BazisLib::String &fp); 57 | 58 | bool ProduceIDTableFile(const BazisLib::String &fp, const BazisLib::String &HeaderFileName); 59 | }; -------------------------------------------------------------------------------- /bzshlp/WinKernel/DeviceEnumerator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../bzscore/string.h" 3 | 4 | extern "C" POBJECT_TYPE *IoDriverObjectType; 5 | 6 | namespace BazisLib 7 | { 8 | namespace DDK 9 | { 10 | class DriverObjectFinder 11 | { 12 | private: 13 | PDRIVER_OBJECT m_pDriver; 14 | 15 | public: 16 | DriverObjectFinder(const wchar_t *pszDriverName, POBJECT_TYPE pDriverObjectType = *IoDriverObjectType); 17 | 18 | 19 | PDRIVER_OBJECT GetDriverObject() 20 | { 21 | return m_pDriver; 22 | } 23 | 24 | ~DriverObjectFinder() 25 | { 26 | Reset(); 27 | } 28 | 29 | bool Valid() 30 | { 31 | return m_pDriver != NULL; 32 | } 33 | 34 | void Reset() 35 | { 36 | if (m_pDriver) 37 | ObDereferenceObject(m_pDriver); 38 | m_pDriver = NULL; 39 | } 40 | }; 41 | 42 | class DeviceEnumerator : public DriverObjectFinder 43 | { 44 | private: 45 | PDEVICE_OBJECT *m_ppDevices; 46 | size_t m_DeviceObjectCount; 47 | 48 | public: 49 | 50 | DeviceEnumerator(const wchar_t *pszDriverName, POBJECT_TYPE pDriverObjectType = *IoDriverObjectType); 51 | ~DeviceEnumerator(); 52 | 53 | size_t DeviceCount() 54 | { 55 | return m_DeviceObjectCount; 56 | } 57 | 58 | PDEVICE_OBJECT GetDeviceByIndex(size_t index) 59 | { 60 | if (!m_ppDevices || (index >= m_DeviceObjectCount)) 61 | return NULL; 62 | return m_ppDevices[index]; 63 | } 64 | }; 65 | } 66 | } -------------------------------------------------------------------------------- /bzshlp/WinKernel/SCSI/VirtualSCSIBus.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BasicBlockDevice.h" 4 | #include "../bus.h" 5 | #include "VirtualSCSIPDO.h" 6 | #include 7 | 8 | namespace BazisLib 9 | { 10 | namespace DDK 11 | { 12 | class VirtualSCSIBus : public BusDevice 13 | { 14 | private: 15 | struct ConnectedDiskRecord 16 | { 17 | ManagedPointer pDisk; 18 | bool EmulateMBR; 19 | }; 20 | 21 | ConnectedDiskRecord m_Disk; 22 | 23 | public: 24 | VirtualSCSIBus(ManagedPointer pDisk, bool EmulateMBR = true, String BusPrefix = L"BazisLibSCSI") 25 | : BusDevice(BusPrefix, false, FILE_DEVICE_SECURE_OPEN, FALSE, DO_BUFFERED_IO) 26 | { 27 | m_Disk.pDisk = pDisk; 28 | m_Disk.EmulateMBR = EmulateMBR; 29 | } 30 | 31 | virtual NTSTATUS OnStartDevice(IN PCM_RESOURCE_LIST AllocatedResources, IN PCM_RESOURCE_LIST AllocatedResourcesTranslated) override 32 | { 33 | NTSTATUS st = __super::OnStartDevice(AllocatedResources, AllocatedResourcesTranslated); 34 | if (!NT_SUCCESS(st)) 35 | return st; 36 | SetNewPNPState(Started); 37 | 38 | if (m_Disk.EmulateMBR) 39 | AddPDO(new VirtualSCSIPDO(new _MBREmulatorT(m_Disk.pDisk))); 40 | else 41 | AddPDO(new VirtualSCSIPDO(new SCSI::BasicDiskToSCSIDiskAdapter(m_Disk.pDisk))); 42 | 43 | return STATUS_SUCCESS; 44 | } 45 | 46 | }; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /_installer/readme.txt: -------------------------------------------------------------------------------- 1 | BazisLib is an universal framework simplifying driver and application creation for 32-bit and 64-bit Windows. 2 | This installer will unpack all BazisLib sources, set all required environment variables and download all required libraries, such as STLPort. 3 | 4 | New in version 3.0.0: 5 | * Added support for MacOS kernel 6 | * Added new bzscore/bzshlp layout 7 | 8 | New in version 2.5.5: 9 | * Improved compatibility with Visual Studio 2010 10 | 11 | New in version 2.5.4: 12 | * Several minor fixes 13 | 14 | New in version 2.5.3: 15 | * Several minor fixes 16 | 17 | New in version 2.5.2: 18 | * Several minor fixes 19 | * Added integration with VisualDDK driver wizard 20 | 21 | New in version 2.5.1: 22 | * Several minor SCSI-related fixes 23 | 24 | New in version 2.5.0: 25 | * Security API now works both in User-mode and Kernel-mode 26 | * Several minor SCSI-related fixes 27 | 28 | New in version 2.4.2: 29 | * Several minor bugfixes and improvements 30 | 31 | New in version 2.4.1: 32 | * Several bugs fixed 33 | 34 | New in version 2.4.0: 35 | * Added support for virtual SCSI devices 36 | * Added support for localizing applications 37 | 38 | New in version 2.3.1: 39 | * Several bugs fixed 40 | * Fixed DDKPATH/WDKPATH bug in installer 41 | 42 | New features in version 2.3.0: 43 | * Win32 SECURITY_DESCRIPTOR manipulation 44 | * Convenient C++ WMI client 45 | * Convenient interface for Vista Boot Configuration Data -------------------------------------------------------------------------------- /bzsnet/server.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../bzscore/socket.h" 3 | #include "../bzscore/atomic.h" 4 | #include "../bzscore/sync.h" 5 | #include "../bzscore/thread.h" 6 | 7 | namespace BazisLib 8 | { 9 | namespace Network 10 | { 11 | class BasicTCPServer 12 | { 13 | private: 14 | TCPListener m_Listener; 15 | AtomicUInt32 m_ActiveThreadCount; 16 | Event m_LastThreadDone; 17 | 18 | private: 19 | class WorkerThread : public BazisLib::AutoDeletingThread 20 | { 21 | private: 22 | BasicTCPServer *m_pServer; 23 | 24 | protected: 25 | virtual int ThreadBody() override; 26 | 27 | public: 28 | WorkerThread(BasicTCPServer *pServer) : 29 | m_pServer(pServer) 30 | { 31 | } 32 | 33 | }; 34 | 35 | protected: 36 | void WaitForWorkerThreads(); 37 | 38 | public: 39 | BasicTCPServer(); 40 | ~BasicTCPServer(); 41 | 42 | //! Starts the server. If a server was already stopped, it cannot be restarted. 43 | ActionStatus Start(unsigned PortNumber); 44 | 45 | //! Stops the server. Once it is stopped, it cannot be started any more. 46 | void Stop(bool WaitForWorkerThreads = true); 47 | 48 | bool Valid() {return m_Listener.Valid();} 49 | 50 | void WaitForTermination() {WaitForWorkerThreads();} 51 | 52 | protected: 53 | //! An overrideable connection handler that is called from a separate thread for each connection 54 | virtual void ConnectionHandler(TCPSocket &socket, const InternetAddress &addr)=0; 55 | }; 56 | } 57 | } -------------------------------------------------------------------------------- /bzscore/Posix/status_defs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifdef BZS_KEXT 3 | #include 4 | #else 5 | #include 6 | #endif 7 | 8 | namespace BazisLib 9 | { 10 | enum CommonErrorType 11 | { 12 | Success = 0, 13 | UnknownError = ENODEV, 14 | InvalidParameter = EINVAL, 15 | InvalidPointer = EFAULT, 16 | InvalidHandle = EBADF, 17 | FileNotFound = ENOENT, 18 | PathNotFound = ENOENT, 19 | AccessDenied = EACCES, 20 | AlreadyExists = EEXIST, 21 | NoMemory = ENOMEM, 22 | NotImplemented = ENOSYS, 23 | NotSupported = EPERM, 24 | NotInitialized = ENXIO, 25 | InvalidState = ENXIO, 26 | // Pending = __HRESULT_FROM_WIN32(ERROR_IO_PENDING), 27 | // NoMoreData = __HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS), 28 | SeekError = EIO, 29 | ReadError = EIO, 30 | WriteError = EIO, 31 | OperationAborted = ECANCELED, 32 | TimeoutExpired = ETIME, 33 | 34 | // ConnectionDropped = __HRESULT_FROM_WIN32(ERROR_CONNECTION_ABORTED), 35 | // CannotConnect = __HRESULT_FROM_WIN32(ERROR_CONNECTION_REFUSED), 36 | // ProtocolError = RPC_E_INVALID_DATAPACKET, 37 | // RemoteFailure = RPC_E_CALL_REJECTED, 38 | 39 | // ParsingFailed = __HRESULT_FROM_WIN32(ERROR_INTERNAL_DB_CORRUPTION), 40 | // EndOfFile = __HRESULT_FROM_WIN32(ERROR_HANDLE_EOF), 41 | }; 42 | 43 | class PlatformStatusPolicy 44 | { 45 | public: 46 | static inline bool IsSuccessfulStatusCode(CommonErrorType code) 47 | { 48 | return ((int)code) == 0; 49 | } 50 | }; 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /examples/WinKernel/FileDiskBus/Filedisk.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __linux__ 4 | #include 5 | #else 6 | #include 7 | #endif 8 | 9 | #include 10 | #include 11 | 12 | namespace BazisLib 13 | { 14 | class FileDisk : public AIBasicDisk 15 | { 16 | protected: 17 | ManagedPointer m_pFile; 18 | ULONGLONG m_FileOffset; 19 | ULONGLONG m_SectorCount; 20 | unsigned m_SectorSize; 21 | unsigned m_MinMBCount; 22 | 23 | private: 24 | //Do not override this. Use constructor parameter instead 25 | virtual unsigned GetSectorSize() override; 26 | 27 | protected: 28 | unsigned SectorSize() {return m_SectorSize;} 29 | 30 | public: 31 | 32 | void Dispose(); 33 | 34 | FileDisk(ManagedPointer &pFile, ULONGLONG FileOffset = 0, unsigned SectorSize = 512, unsigned minMBCount = 0); 35 | ~FileDisk(); 36 | 37 | virtual ULONGLONG GetSectorCount() override; 38 | virtual bool IsWritable() override {return true;} 39 | 40 | virtual unsigned Read(ULONGLONG ByteOffset, void *pBuffer, unsigned Length) override; 41 | virtual unsigned Write(ULONGLONG ByteOffset, const void *pBuffer, unsigned Length) override; 42 | virtual LPGUID GetStableGuid() override {return NULL;} 43 | 44 | virtual bool DeviceControl(unsigned CtlCode, void *pBuffer, unsigned InSize, unsigned OutSize, unsigned *pBytesDone) override {return false;} 45 | 46 | virtual ActionStatus Initialize() override; 47 | }; 48 | } 49 | -------------------------------------------------------------------------------- /examples/WinKernel/SampleInstaller/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | // Change these values to use different versions 9 | #define WINVER 0x0500 10 | #define _WIN32_WINNT 0x0501 11 | #define _WIN32_IE 0x0501 12 | #define _RICHEDIT_VER 0x0200 13 | 14 | #include 15 | #include 16 | 17 | extern CAppModule _Module; 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #if defined _M_IX86 26 | #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 27 | #elif defined _M_IA64 28 | #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"") 29 | #elif defined _M_X64 30 | #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 31 | #else 32 | #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 33 | #endif 34 | -------------------------------------------------------------------------------- /bzshlp/WinKernel/SCSI/VirtualSCSICdrom.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "scsidev.h" 4 | #include "../../bzsdisk.h" 5 | #include "BasicBlockDevice.h" 6 | #include 7 | 8 | namespace BazisLib 9 | { 10 | namespace DDK 11 | { 12 | namespace SCSI 13 | { 14 | class VirtualSCSICdrom : public BasicSCSIBlockDevice 15 | { 16 | public: 17 | enum {CDROM_SECTOR_SIZE = 2048}; 18 | public: 19 | virtual SCSIResult ExecuteSCSIRequest(GenericSRB &request) override; 20 | 21 | protected: 22 | virtual SCSIResult OnReadTOC(Requests::ReadTOC &request); 23 | virtual SCSIResult OnLoadUnload(const _CDB::_LOAD_UNLOAD *pRequest) {return scsiGood;} 24 | //virtual SCSI_STATUS OnGetEventStatus(const _CDB::_GET_EVENT_STATUS_NOTIFICATION *pRequest, PNOTIFICATION_EVENT_STATUS_HEADER pReply, ULONG Size, ULONG *pDone); 25 | 26 | public: 27 | virtual unsigned GetSectorSize() {return CDROM_SECTOR_SIZE;} 28 | virtual bool IsWritable() {return false;} 29 | virtual UCHAR GetSCSIDeviceType() { return READ_ONLY_DIRECT_ACCESS_DEVICE; } 30 | virtual unsigned Write(ULONGLONG ByteOffset, const void *pBuffer, unsigned Length) {return 0;} 31 | 32 | public: //Unimplemented AIBasicDisk methods 33 | virtual ULONGLONG GetSectorCount()=0; 34 | virtual unsigned Read(ULONGLONG ByteOffset, void *pBuffer, unsigned Length)=0; 35 | 36 | public: //CDROM-specific methods 37 | virtual unsigned GetTrackCount()=0; 38 | virtual unsigned GetTrackEndSector(unsigned TrackIndex)=0; 39 | }; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/AutoTestLib/cfgstore.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "TestPrint.h" 3 | #include 4 | 5 | using namespace BazisLib; 6 | 7 | bool TestConfigurationStorageAPI() 8 | { 9 | #ifdef BZSLIB_WINKERNEL 10 | ConfigurationPath root = ConfigurationPath::FromNTRegistryPath(_T("\\Registry\\Machine\\SOFTWARE\\Sysprogs_BazisLibTest")); 11 | #elif defined(WIN32) 12 | ConfigurationPath root = ConfigurationPath::FromWin32RegistryPath(HKEY_CURRENT_USER, _T("SOFTWARE\\Sysprogs\\BazisLibTest")); 13 | #elif defined (BZSLIB_KEXT) 14 | ConfigurationPath root = ConfigurationPath::FromFSPath("/tmp/cfgtest.plist"); 15 | #else 16 | ConfigurationPath root = ConfigurationPath::FromFSPath("/tmp/cfgtest"); 17 | #endif 18 | ConfigurationKey rootKey(root, true); 19 | TEST_ASSERT(rootKey.Valid()); 20 | 21 | rootKey[_T("key1")] = _T("val1"); 22 | rootKey[_T("key2")] = 2; 23 | 24 | TEST_ASSERT((String)rootKey[_T("key1")] == _T("val1")); 25 | TEST_ASSERT((int)rootKey[_T("key2")] == 2); 26 | 27 | ConfigurationKey subkey = rootKey[_T("subkey1")]; 28 | TEST_ASSERT(subkey.Valid()); 29 | 30 | TEST_ASSERT((int)subkey[_T("DoesNotExist")] == 0); 31 | //TEST_ASSERT((int)subkey[_T("key2")] == 0); 32 | 33 | subkey[_T("key2")] = 7; 34 | TEST_ASSERT((int)subkey[_T("key2")] == 7); 35 | 36 | std::vector subkeys = rootKey.GetAllSubkeys(); 37 | TEST_ASSERT(subkeys.size() == 1); 38 | TEST_ASSERT(subkeys[0] == _T("subkey1")); 39 | 40 | #ifdef BZSLIB_KEXT 41 | TEST_ASSERT(rootKey.Save().Successful()); 42 | #endif 43 | 44 | return true; 45 | } 46 | -------------------------------------------------------------------------------- /bzshlp/HandleHolder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cmndef.h" 3 | 4 | namespace BazisLib 5 | { 6 | template class _HandleHolderT 7 | { 8 | protected: 9 | _HandleType m_Handle; 10 | 11 | private: 12 | _HandleHolderT &operator=(const _HandleHolderT &newHolder) 13 | { 14 | ASSERT(0); 15 | } 16 | 17 | _HandleHolderT(const _HandleHolderT &holder) 18 | { 19 | ASSERT(0) 20 | } 21 | 22 | public: 23 | explicit _HandleHolderT(_HandleType hInit = _ErrorValue) : m_Handle(hInit) {} 24 | 25 | _HandleType *operator&() 26 | { 27 | ASSERT(m_Handle == _ErrorValue); 28 | return &m_Handle; 29 | } 30 | 31 | ~_HandleHolderT () 32 | { 33 | if (m_Handle != _ErrorValue) 34 | _CloseHandle(m_Handle); 35 | } 36 | 37 | _HandleType Detach() 38 | { 39 | _HandleType r = m_Handle; 40 | m_Handle = _ErrorValue; 41 | return r; 42 | } 43 | 44 | _HandleType GetForSingleUse() const 45 | { 46 | return m_Handle; 47 | } 48 | 49 | _HandleHolderT &operator=(_HandleType hNew) 50 | { 51 | if (m_Handle == _ErrorValue) 52 | _CloseHandle(m_Handle); 53 | m_Handle = hNew; 54 | return *this; 55 | } 56 | 57 | bool Valid() const 58 | { 59 | return m_Handle != _ErrorValue; 60 | } 61 | 62 | }; 63 | 64 | } 65 | 66 | #if defined (BZSLIB_WINKERNEL) 67 | #include "WinKernel/HandleHolder.h" 68 | #elif defined (_WIN32) 69 | #include "Win32/HandleHolder.h" 70 | #else 71 | #error Handle holder not available on your platform 72 | #endif 73 | -------------------------------------------------------------------------------- /bzshlp/Win32/wow64.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #if defined(WIN32) && !defined(BZSLIB_WINKERNEL) 3 | #include "wow64.h" 4 | #include "../../bzscore/assert.h" 5 | 6 | #ifndef UNDER_CE 7 | 8 | using namespace BazisLib; 9 | 10 | WOW64APIProvider::WOW64APIProvider() 11 | { 12 | HMODULE hKernel32 = GetModuleHandle(_T("kernel32")); 13 | ASSERT(hKernel32); 14 | m_fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(hKernel32, "IsWow64Process"); 15 | m_fnDisableRedirection = (LPFN_WOW64DISABLEREDIR)GetProcAddress(hKernel32, "Wow64DisableWow64FsRedirection"); 16 | m_fnResumeRedirection = (LPFN_WOW64REVERTREDIR)GetProcAddress(hKernel32, "Wow64RevertWow64FsRedirection"); 17 | } 18 | 19 | bool WOW64APIProvider::IsWow64Process(unsigned PID) 20 | { 21 | if (!m_fnIsWow64Process) 22 | return false; 23 | 24 | BOOL bIsWow64 = FALSE; 25 | 26 | HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, PID ? PID : GetCurrentProcessId()); 27 | if (hProc == INVALID_HANDLE_VALUE) 28 | return false; 29 | if (!m_fnIsWow64Process(hProc, &bIsWow64)) 30 | { 31 | CloseHandle(hProc); 32 | return false; 33 | } 34 | CloseHandle(hProc); 35 | return (bIsWow64 != 0); 36 | } 37 | 38 | bool WOW64APIProvider::DisableFSRedirection(PVOID *pContext) 39 | { 40 | if (!m_fnDisableRedirection) 41 | return false; 42 | return m_fnDisableRedirection(pContext) != 0; 43 | } 44 | 45 | bool WOW64APIProvider::ResumeFSRedirection(PVOID pContext) 46 | { 47 | if (!m_fnDisableRedirection) 48 | return false; 49 | return m_fnResumeRedirection(pContext) != 0; 50 | } 51 | 52 | #endif 53 | #endif -------------------------------------------------------------------------------- /bzshlp/ParsingLogger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace BazisLib 5 | { 6 | enum Severity 7 | { 8 | sevUnknown = 0, 9 | sevDebug, 10 | sevInfo, 11 | sevWarning, 12 | sevError, 13 | }; 14 | 15 | class ParsingLogger 16 | { 17 | protected: 18 | virtual void DoLogLine(Severity severity, int additionalType, const String &message)=0; 19 | 20 | public: 21 | void LogLine(Severity severity, const String &message) 22 | { 23 | if (!this) 24 | return; 25 | DoLogLine(severity, 0, message); 26 | } 27 | 28 | void LogLine(Severity severity, const TCHAR *pFormat, ...) 29 | { 30 | if (!this) 31 | return; 32 | va_list lst, va2; 33 | va_start(lst, pFormat); 34 | va_start(va2, pFormat); 35 | String line; 36 | line.vFormat(pFormat, lst, va2); 37 | LogLine(severity, line); 38 | va_end(lst); 39 | va_end(va2); 40 | } 41 | 42 | ActionStatus LogAndReturnError(ActionStatus error, const TCHAR *pFormat, ...) 43 | { 44 | if (!this) 45 | return error; 46 | va_list lst, va2; 47 | va_start(lst, pFormat); 48 | va_start(va2, pFormat); 49 | String line; 50 | line.vFormat(pFormat, lst, va2); 51 | LogLine(sevError, line); 52 | va_end(lst); 53 | va_end(va2); 54 | return error; 55 | } 56 | }; 57 | 58 | class ParsingLoggerEx: public ParsingLogger 59 | { 60 | public: 61 | virtual void ReportProgress(ULONGLONG progress, ULONGLONG total) {} 62 | virtual void ReportAdvancedProgress(unsigned stage, unsigned totalStages, TempString &stageName, ULONGLONG stageProgress, ULONGLONG stageTotal) {} 63 | }; 64 | } -------------------------------------------------------------------------------- /bzshlp/Win32/apicaller.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BazisLib 4 | { 5 | namespace Win32 6 | { 7 | template class NewAPICaller2 8 | { 9 | private: 10 | typedef _R (_stdcall *FUNCPTR)(_T1, _T2); 11 | 12 | FUNCPTR m_pFunc; 13 | 14 | public: 15 | NewAPICaller2(const TCHAR *pDLLName, const char *pFuncName) 16 | : m_pFunc(NULL) 17 | { 18 | HMODULE hDll = GetModuleHandle(pDLLName); 19 | if (!hDll) 20 | return; 21 | m_pFunc = (FUNCPTR)GetProcAddress(hDll, pFuncName); 22 | } 23 | 24 | bool Valid() 25 | { 26 | return (m_pFunc != NULL); 27 | } 28 | 29 | _R operator()(_T1 p1, _T2 p2) 30 | { 31 | //Valid() should be called before 32 | ASSERT(m_pFunc); 33 | return m_pFunc(p1, p2); 34 | } 35 | }; 36 | 37 | template class NewAPICaller4 38 | { 39 | private: 40 | typedef _R (_stdcall *FUNCPTR)(_T1, _T2, _T3, _T4); 41 | 42 | FUNCPTR m_pFunc; 43 | 44 | public: 45 | NewAPICaller4(const TCHAR *pDLLName, const char *pFuncName) 46 | : m_pFunc(NULL) 47 | { 48 | HMODULE hDll = GetModuleHandle(pDLLName); 49 | if (!hDll) 50 | return; 51 | m_pFunc = (FUNCPTR)GetProcAddress(hDll, pFuncName); 52 | } 53 | 54 | bool Valid() 55 | { 56 | return (m_pFunc != NULL); 57 | } 58 | 59 | _R operator()(_T1 p1, _T2 p2, _T3 p3, _T4 p4) 60 | { 61 | //Valid() should be called before 62 | ASSERT(m_pFunc); 63 | return m_pFunc(p1, p2, p3, p4); 64 | } 65 | }; 66 | 67 | } 68 | } -------------------------------------------------------------------------------- /bzshlp/WinKernel/crossplatform/crossvol.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../bzsdisk.h" 4 | #include "../volume.h" 5 | 6 | namespace BazisLib 7 | { 8 | namespace DDK 9 | { 10 | class UniversalVolume : public BasicStorageVolume 11 | { 12 | private: 13 | ManagedPointer m_pDisk; 14 | char m_PartitionType; 15 | 16 | public: 17 | UniversalVolume(const ConstManagedPointer &pDisk, char PartitionType = PARTITION_FAT32); 18 | ~UniversalVolume(); 19 | 20 | protected: 21 | 22 | virtual unsigned GetSectorSize() override; 23 | virtual ULONGLONG GetTotalSize() override; 24 | virtual char GetPartitionType() override; 25 | 26 | virtual NTSTATUS Read(ULONGLONG ByteOffset, PVOID pBuffer, ULONG Length, PULONG_PTR pBytesDone) override; 27 | virtual NTSTATUS Write(ULONGLONG ByteOffset, PVOID pBuffer, ULONG Length, PULONG_PTR pBytesDone) override; 28 | virtual NTSTATUS OnGetStableGuid(LPGUID lpGuid) override; 29 | 30 | virtual NTSTATUS OnDeviceControl(ULONG ControlCode, bool IsInternal, void *pInOutBuffer, ULONG InputLength, ULONG OutputLength, PULONG_PTR pBytesDone) override; 31 | virtual NTSTATUS OnStartDevice(IN PCM_RESOURCE_LIST AllocatedResources, IN PCM_RESOURCE_LIST AllocatedResourcesTranslated) override; 32 | 33 | virtual NTSTATUS OnDiskIsWritable() override; 34 | 35 | 36 | /* virtual NTSTATUS DispatchPNP(IN IncomingIrp *Irp, IO_STACK_LOCATION *IrpSp) override 37 | { 38 | DbgPrint("CrossVol: %s\n", PnPMinorFunctionString(IrpSp->MinorFunction)); 39 | return __super::DispatchPNP(Irp, IrpSp); 40 | }*/ 41 | }; 42 | } 43 | } -------------------------------------------------------------------------------- /_installer/__make.bat: -------------------------------------------------------------------------------- 1 | REM @echo off 2 | set DEVENVPATH=%VS90COMNTOOLS%\..\IDE 3 | 4 | REM All sources and setup program binary should be placed into "bzslib" subdirectory. Then, the following command should be run: 5 | rmdir /s /q ..\..\bzslib.tmp2 6 | rmdir /s /q ..\..\bzslib.inst 7 | mkdir ..\..\bzslib.inst 8 | mkdir ..\..\bzslib.inst\bzslib 9 | 10 | cd ..\support\BazisLibSetup 11 | "%DEVENVPATH%\devenv" BazisLibSetup.sln /Build Release 12 | if not exist bin\Release\BazisLibSetup.exe goto error 13 | if not exist bin\Release\ICSharpCode.SharpZipLib.dll goto error 14 | copy /y bin\Release\BazisLibSetup.exe ..\..\..\bzslib.inst\bzslib\ 15 | copy /y bin\Release\ICSharpCode.SharpZipLib.dll ..\..\..\bzslib.inst\bzslib\ 16 | 17 | mkdir ..\..\..\bzslib.tmp2 18 | cd ..\..\..\bzslib.tmp2 19 | tortoiseproc /command:checkout /path:. /closeonend:1 /url:https://sys1:36841/svn/sysprogs/trunk/bzslib 20 | rmdir /s /q .svn 21 | cd ..\bzslib.inst 22 | xcopy /e ..\bzslib.tmp2\*.* bzslib\*.* 23 | xcopy ..\bzslib.tmp2\_installer\*.* . 24 | rmdir /s /q ..\bzslib.tmp2 25 | cd bzslib 26 | ..\..\utils\perl support\convert_vcproj.pl bzscmn\bzscmn.vcproj 27 | ..\..\utils\perl support\convert_vcproj.pl bzsddk\bzsddk.vcproj 28 | ..\..\utils\perl support\convert_vcproj.pl bzsnet\bzsnet.vcproj 29 | ..\..\utils\perl support\convert_vcproj.pl bzswin\bzswin.vcproj 30 | cd .. 31 | ..\utils\ssibuilder BazisLib.xit BazisLib.exe /LINKCABS /EXESTUB:\projects\svn\utils\ssisfx.exe 32 | cd bzslib 33 | ..\..\utils\zip ..\_BazisLib-PutToSysprogs.zip -r * 34 | cd .. 35 | goto end 36 | 37 | :error 38 | echo ERROR building BazisLib installer 39 | pause 40 | :end -------------------------------------------------------------------------------- /bzscore/autolock.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cmndef.h" 3 | 4 | namespace BazisLib 5 | { 6 | template class FastLocker 7 | { 8 | private: 9 | _T *m_pLockable; 10 | 11 | public: 12 | FastLocker(_T &pLockable) : m_pLockable(&pLockable) {if (m_pLockable) m_pLockable->Lock();} 13 | ~FastLocker() {if (m_pLockable) m_pLockable->Unlock();} 14 | }; 15 | 16 | template class FastUnlocker 17 | { 18 | private: 19 | _T *m_pLockable; 20 | 21 | public: 22 | FastUnlocker(_T &pLockable) : m_pLockable(&pLockable) {if (m_pLockable) m_pLockable->Unlock();} 23 | ~FastUnlocker() {if (m_pLockable) m_pLockable->Lock();} 24 | }; 25 | 26 | template class _ReadLocker 27 | { 28 | private: 29 | _T *m_pLockable; 30 | 31 | public: 32 | _ReadLocker(_T &pLockable) : m_pLockable(&pLockable) {if (m_pLockable) m_pLockable->LockRead();} 33 | ~_ReadLocker() {if (m_pLockable) m_pLockable->UnlockRead();} 34 | }; 35 | 36 | template class _WriteLocker 37 | { 38 | private: 39 | _T *m_pLockable; 40 | 41 | public: 42 | _WriteLocker(_T &pLockable) : m_pLockable(&pLockable) {if (m_pLockable) m_pLockable->LockWrite();} 43 | ~_WriteLocker() {if (m_pLockable) m_pLockable->UnlockWrite();} 44 | }; 45 | 46 | template class _WriteFromReadLocker 47 | { 48 | private: 49 | _T *m_pLockable; 50 | 51 | public: 52 | _WriteFromReadLocker(_T &pLockable) : m_pLockable(&pLockable) {if (m_pLockable) {m_pLockable->UnlockRead(); m_pLockable->LockWrite();}} 53 | ~_WriteFromReadLocker() {if (m_pLockable) {m_pLockable->UnlockWrite(); m_pLockable->LockRead();}} 54 | }; 55 | } -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/KernelMode/KernelMode.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {8E41214B-6785-4CFE-B992-037D68949A14} 18 | inf;inv;inx;mof;mc; 19 | 20 | 21 | 22 | 23 | Source Files 24 | 25 | 26 | Source Files 27 | 28 | 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | -------------------------------------------------------------------------------- /bzscore/WinKernel/status_defs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BazisLib 4 | { 5 | enum CommonErrorType 6 | { 7 | Success = STATUS_SUCCESS, 8 | UnknownError = STATUS_UNSUCCESSFUL, 9 | InvalidParameter = STATUS_INVALID_PARAMETER, 10 | InvalidPointer = STATUS_ACCESS_VIOLATION, 11 | InvalidHandle = STATUS_INVALID_HANDLE, 12 | FileNotFound = STATUS_OBJECT_NAME_NOT_FOUND, 13 | PathNotFound = STATUS_OBJECT_PATH_NOT_FOUND, 14 | AccessDenied = STATUS_ACCESS_DENIED, 15 | AlreadyExists = STATUS_OBJECT_NAME_COLLISION, 16 | NoMemory = STATUS_NO_MEMORY, 17 | NotImplemented = STATUS_NOT_IMPLEMENTED, 18 | NotSupported = STATUS_NOT_SUPPORTED, 19 | NotInitialized = STATUS_REINITIALIZATION_NEEDED, 20 | InvalidState = STATUS_INVALID_DEVICE_STATE, 21 | Pending = STATUS_PENDING, 22 | NoMoreData = STATUS_NO_MORE_ENTRIES, 23 | SeekError = STATUS_UNEXPECTED_IO_ERROR, 24 | ReadError = STATUS_UNEXPECTED_IO_ERROR, 25 | WriteError = STATUS_UNEXPECTED_IO_ERROR, 26 | OperationAborted = STATUS_ABANDONED, 27 | TimeoutExpired = STATUS_TIMEOUT, 28 | 29 | ConnectionDropped = STATUS_CONNECTION_ABORTED, 30 | CannotConnect = STATUS_CONNECTION_REFUSED, 31 | ProtocolError = STATUS_REMOTE_DISCONNECT, 32 | RemoteFailure = STATUS_REMOTE_DISCONNECT, 33 | 34 | ParsingFailed = STATUS_COULD_NOT_INTERPRET, 35 | EndOfFile = STATUS_END_OF_FILE, 36 | }; 37 | 38 | class PlatformStatusPolicy 39 | { 40 | public: 41 | static inline bool IsSuccessfulStatusCode(CommonErrorType code) 42 | { 43 | return NT_SUCCESS((NTSTATUS)code); 44 | } 45 | }; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /tests/CommonFunctionalityTests/CommonFunctionalityTests.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | 29 | 30 | Source Files 31 | 32 | 33 | Source Files 34 | 35 | 36 | Source Files 37 | 38 | 39 | -------------------------------------------------------------------------------- /bzshlp/Win32/bzsreg.h: -------------------------------------------------------------------------------- 1 | /* 2 | BZSREG.H - Fast registry access class. 3 | */ 4 | 5 | #pragma once 6 | 7 | #include "cmndef.h" 8 | #include 9 | #include 10 | #include "../../bzscore/string.h" 11 | 12 | #ifndef _BZSREG_CPP_ 13 | 14 | #define __STR2__(x) #x 15 | #define __STR1__(x) __STR2__(x) 16 | #define __LOC__ __FILE__ "("__STR1__(__LINE__)") : warning Msg: " 17 | 18 | #pragma message(__LOC__"The BZSREG.H interface is deprecated. include "../../bzscore/registry.h" instead.") 19 | 20 | #undef __STR2__ 21 | #undef __STR1__ 22 | #undef __LOC__ 23 | 24 | #endif //_BZSREG_CPP_ 25 | 26 | namespace BazisLib 27 | { 28 | 29 | class IRegistryParameters 30 | { 31 | public: 32 | virtual String GetString(LPCTSTR pszKey)=0; 33 | virtual int GetInteger(LPCTSTR pszKey) =0; 34 | virtual bool SetInteger(LPCTSTR pszKey, int Value)=0; 35 | virtual bool SetString(LPCTSTR pszKey, String &Value)=0; 36 | 37 | virtual bool LoadKey(LPCTSTR pszKey)=0; 38 | virtual bool SaveKey(LPCTSTR pszKey = 0)=0; 39 | virtual void Reset()=0; 40 | }; 41 | 42 | class CRegistryParameters 43 | { 44 | protected: 45 | std::map m_StringParams; 46 | std::map m_IntParams; 47 | String m_KeyName; 48 | 49 | public: 50 | CRegistryParameters(LPCTSTR pszKey); 51 | virtual String GetString(LPCTSTR pszKey); 52 | virtual int GetInteger(LPCTSTR pszKey); 53 | virtual bool SetInteger(LPCTSTR pszKey, int Value); 54 | virtual bool SetString(LPCTSTR pszKey, String &Value); 55 | 56 | virtual bool LoadKey(LPCTSTR pszKey); 57 | virtual bool SaveKey(LPCTSTR pszKey = 0); 58 | virtual void Reset(); 59 | }; 60 | 61 | } -------------------------------------------------------------------------------- /bzshlp/Win32/LNGManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "i18n.h" 3 | #include 4 | #include "../../bzscore/sync.h" 5 | 6 | namespace BazisLib 7 | { 8 | namespace TranslationSystem 9 | { 10 | class LNGManager 11 | { 12 | private: 13 | struct LanguageFileRecord 14 | { 15 | InstalledLanguage Lang; 16 | String FullLNGFilePath; 17 | StringTable *pLoadedTable; 18 | 19 | LanguageFileRecord() 20 | : pLoadedTable(NULL) 21 | { 22 | } 23 | }; 24 | 25 | std::map m_InstalledLanguages; 26 | Mutex m_LanguageListLock; 27 | 28 | private: 29 | static StringTable *ParseLNGFile(const String &fp, unsigned MinID, unsigned IDCount, const std::map &StringIDMap); 30 | static ActionStatus ReadLNGFileHeaders(const String &fp, InstalledLanguage *pLangInfo); 31 | 32 | public: 33 | StringTable *LoadStringTableForLanguage(unsigned LangID, StringIDRecord *pIDTable); 34 | 35 | LNGManager(Directory::FindFileParams fileList); 36 | 37 | ~LNGManager() 38 | { 39 | MutexLocker lck(m_LanguageListLock); 40 | for each(const std::pair &rec in m_InstalledLanguages) 41 | delete rec.second.pLoadedTable; 42 | } 43 | 44 | std::vector GetInstalledLanguageList() 45 | { 46 | std::vector ret; 47 | MutexLocker lck(m_LanguageListLock); 48 | ret.reserve(m_InstalledLanguages.size()); 49 | for each(const std::pair &kv in m_InstalledLanguages) 50 | ret.push_back(kv.second.Lang); 51 | return ret; 52 | } 53 | }; 54 | } 55 | } -------------------------------------------------------------------------------- /bzscore/Win32/win32_string.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #if defined(WIN32) && !defined(BZSLIB_WINKERNEL) 3 | #include "../../bzscore/string.h" 4 | 5 | namespace BazisLib 6 | { 7 | String ANSIStringToString(const TempStringA &str) 8 | { 9 | #ifdef UNICODE 10 | String ret; 11 | wchar_t *pwszStr = ret.PreAllocate(str.length(), false); 12 | if (!pwszStr) 13 | return ret; 14 | size_t done = MultiByteToWideChar(CP_ACP, 0, str.GetConstBuffer(), (unsigned)str.length(), pwszStr, (unsigned)str.length()); 15 | ret.SetLength(done); 16 | return ret; 17 | #else 18 | return str; 19 | #endif 20 | } 21 | 22 | DynamicStringA StringToANSIString(const TempString &str) 23 | { 24 | #ifdef UNICODE 25 | DynamicStringA ret; 26 | char *pszStr = ret.PreAllocate(str.length(), false); 27 | if (!pszStr) 28 | return ret; 29 | size_t done = WideCharToMultiByte(CP_ACP, 0, str.GetConstBuffer(), (unsigned)str.length(), pszStr, (unsigned)str.length(), "?", NULL); 30 | ret.SetLength(done); 31 | return ret; 32 | #else 33 | return str; 34 | #endif 35 | } 36 | 37 | //------------------------------------------------------------------------------------------------------------------------------------- 38 | 39 | String STLANSIStringToString(const std::string &str) 40 | { 41 | #ifdef UNICODE 42 | return ANSIStringToString(ConstStringA(str.c_str(), str.length())); 43 | #else 44 | return str.c_str(); 45 | #endif 46 | } 47 | 48 | std::string StringToANSISTLString(const TempString &str) 49 | { 50 | #ifdef UNICODE 51 | return StringToANSIString(str).c_str(); 52 | #else 53 | return std::string(str.GetTempPointer(), str.length()); 54 | #endif 55 | } 56 | } 57 | #endif -------------------------------------------------------------------------------- /support/strgen/strgen.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | 29 | 30 | Header Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | Header Files 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /bzscore/Win32/registry_win32.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #if defined(WIN32) && !defined(BZSLIB_WINKERNEL) 3 | #include "registry.h" 4 | 5 | BazisLib::ActionStatus BazisLib::DoDeleteSubkeyRecursive( HKEY hKey, LPCTSTR lpSubkey ) 6 | { 7 | DWORD i = 0; 8 | TCHAR tszSubkey[512]; 9 | HKEY hSubkey = 0; 10 | #ifdef UNDER_CE 11 | int err = RegOpenKeyEx(hKey, lpSubkey, 0, NULL, &hSubkey); 12 | #else 13 | int err = RegOpenKey(hKey, lpSubkey, &hSubkey); 14 | #endif 15 | if (err != ERROR_SUCCESS) 16 | return MAKE_STATUS(BazisLib::ActionStatus::FromWin32Error(err)); 17 | if (!hSubkey) 18 | return MAKE_STATUS(BazisLib::UnknownError); 19 | DWORD dwNameSize = __countof(tszSubkey); 20 | 21 | ActionStatus lastProblem = MAKE_STATUS(BazisLib::Success); 22 | 23 | #ifdef UNDER_CE 24 | while (!RegEnumKeyEx(hSubkey, i, tszSubkey, &dwNameSize, NULL, NULL, NULL, NULL)) 25 | #else 26 | while (!RegEnumKey(hSubkey, i, tszSubkey, dwNameSize)) 27 | #endif 28 | { 29 | //After deletion of a subkey, the subkey indexes are shifted. That way, normally, we should 30 | //allways delete subkey #0. However, in case of error, we skip it and try deleting next one. 31 | 32 | //Note that the correctness of this function strictly depends on whether it reports 33 | //deletion errors correctly. 34 | ActionStatus st = DoDeleteSubkeyRecursive(hSubkey, tszSubkey); 35 | if (!st.Successful()) 36 | i++; 37 | else 38 | lastProblem = st; 39 | dwNameSize = __countof(tszSubkey); 40 | } 41 | RegCloseKey(hSubkey); 42 | err = RegDeleteKey(hKey, lpSubkey); 43 | if (err == ERROR_SUCCESS) 44 | return lastProblem; 45 | else 46 | return MAKE_STATUS(BazisLib::ActionStatus::FromWin32Error(err)); 47 | } 48 | #endif -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/TestMacDriver/TestMacDriver.cpp: -------------------------------------------------------------------------------- 1 | #include "TestMacDriver.h" 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | // This required macro defines the class's constructor, destructor, 8 | // and several other methods I/O Kit requires. 9 | OSDefineMetaClassAndStructors(com_sysprogs_TestMacDriver, IOService) 10 | 11 | bool AutoTestEntry(bool runTestsCausingMemoryLeaks, const char *pTempDir); 12 | 13 | void TestPrint(const char *pFormat, ...) 14 | { 15 | va_list lst; 16 | va_start(lst, pFormat); 17 | vprintf(pFormat, lst); 18 | va_end(lst); 19 | } 20 | 21 | void sWorkerThreadBody( void *pArg, wait_result_t ) 22 | { 23 | IOLog("Starting tests...\n"); 24 | bool result = AutoTestEntry(false, "/tmp"); 25 | IOLog("Tests %s...\n", result ? "succeeded" : "failed"); 26 | 27 | thread_terminate(current_thread()); 28 | } 29 | 30 | bool com_sysprogs_TestMacDriver::init( OSDictionary *dictionary /*= 0*/ ) 31 | { 32 | thread_t _WorkerThread; 33 | kernel_thread_start(sWorkerThreadBody, this, &_WorkerThread); 34 | thread_deallocate(_WorkerThread); 35 | 36 | return super::init(dictionary); 37 | } 38 | 39 | void com_sysprogs_TestMacDriver::free( void ) 40 | { 41 | super::free(); 42 | } 43 | 44 | IOService * com_sysprogs_TestMacDriver::probe( IOService *provider, SInt32 *score ) 45 | { 46 | return super::probe(provider, score); 47 | } 48 | 49 | bool com_sysprogs_TestMacDriver::start( IOService *provider ) 50 | { 51 | if (!super::start(provider)) 52 | return false; 53 | 54 | registerService(kIOServiceSynchronous); 55 | return true; 56 | } 57 | 58 | void com_sysprogs_TestMacDriver::stop( IOService *provider ) 59 | { 60 | super::stop(provider); 61 | } 62 | -------------------------------------------------------------------------------- /bzshlp/WinKernel/AlertableQueue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace BazisLib 7 | { 8 | namespace DDK 9 | { 10 | //! A queue that owns enqueued items and frees them when aborted 11 | class AlertableQueue 12 | { 13 | public: 14 | class Item 15 | { 16 | public: 17 | virtual ~Item(){} 18 | }; 19 | 20 | private: 21 | Semaphore m_Semaphore; 22 | 23 | std::queue m_Queue; 24 | FastMutex m_QueueMutex; 25 | bool _Shutdown; 26 | 27 | private: 28 | //! Enqueues the item or destroys it if the queue is already shut down 29 | void DoEnqueueItem(Item *pItem); 30 | 31 | public: 32 | AlertableQueue() 33 | : _Shutdown(false) 34 | { 35 | } 36 | 37 | ~AlertableQueue(); 38 | 39 | void EnqueueItem(Item *pItem) 40 | { 41 | if (!pItem) 42 | return; 43 | FastMutexLocker lck(m_QueueMutex); 44 | m_Queue.push(pItem); 45 | m_Semaphore.Signal(); 46 | } 47 | 48 | //! Returns one of 3: STATUS_SUCCESS, STATUS_USER_APC, STATUS_CANCELLED 49 | NTSTATUS WaitAndDequeue(Item **ppItem, ULONG Timeout = (ULONG)-1L); 50 | 51 | void Shutdown() 52 | { 53 | _Shutdown = true; 54 | m_Semaphore.Signal(); 55 | } 56 | }; 57 | 58 | template class AlertableQueueEx : public AlertableQueue 59 | { 60 | public: 61 | void EnqeueItem(_Item *pItem) 62 | { 63 | __super::EnqueueItem(pItem); 64 | } 65 | 66 | NTSTATUS WaitAndDequeue(_Item **ppItem, ULONG Timeout = (ULONG)-1L) 67 | { 68 | Item *p = NULL; 69 | NTSTATUS st = __super::WaitAndDequeue(&p, Timeout); 70 | *ppItem = static_cast<_Item *>(p); 71 | return st; 72 | } 73 | }; 74 | } 75 | } -------------------------------------------------------------------------------- /bzsnet/server.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "server.h" 3 | 4 | using namespace BazisLib; 5 | using namespace BazisLib::Network; 6 | 7 | BasicTCPServer::BasicTCPServer() : 8 | m_ActiveThreadCount(0U), 9 | m_LastThreadDone(true) 10 | { 11 | } 12 | 13 | BasicTCPServer::~BasicTCPServer() 14 | { 15 | WaitForWorkerThreads(); 16 | } 17 | 18 | ActionStatus BasicTCPServer::Start(unsigned PortNumber) 19 | { 20 | if (m_ActiveThreadCount) 21 | return MAKE_STATUS(InvalidState); 22 | ActionStatus st = m_Listener.Listen(PortNumber); 23 | if (!st.Successful()) 24 | return st; 25 | m_LastThreadDone.Reset(); 26 | m_ActiveThreadCount++; 27 | 28 | WorkerThread *pThread = new WorkerThread(this); 29 | if (!pThread) 30 | return MAKE_STATUS(NoMemory); 31 | 32 | if (!pThread->Start()) 33 | { 34 | delete pThread; 35 | m_ActiveThreadCount--; 36 | return MAKE_STATUS(UnknownError); 37 | } 38 | return MAKE_STATUS(Success); 39 | } 40 | 41 | void BasicTCPServer::Stop(bool WaitForWorkerThreads) 42 | { 43 | m_Listener.Abort(); 44 | if (WaitForWorkerThreads) 45 | this->WaitForWorkerThreads(); 46 | } 47 | 48 | int BasicTCPServer::WorkerThread::ThreadBody() 49 | { 50 | InternetAddress addr; 51 | TCPSocket sock; 52 | ActionStatus st = m_pServer->m_Listener.Accept(&sock, &addr); 53 | if (st.Successful() && sock.Valid()) 54 | { 55 | m_pServer->m_ActiveThreadCount++; 56 | WorkerThread *pThread = new WorkerThread(m_pServer); 57 | if (!pThread || !pThread->Start()) 58 | delete pThread; 59 | m_pServer->ConnectionHandler(sock, addr); 60 | } 61 | if (!--m_pServer->m_ActiveThreadCount) 62 | m_pServer->m_LastThreadDone.Set(); 63 | return 0; 64 | } 65 | 66 | void BasicTCPServer::WaitForWorkerThreads() 67 | { 68 | m_LastThreadDone.Wait(); 69 | } 70 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/UserMode/UserMode.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {b0e25706-c6af-48b8-95ec-2c25a463cf38} 18 | *.mak 19 | 20 | 21 | 22 | 23 | 24 | Make files 25 | 26 | 27 | 28 | 29 | Header Files 30 | 31 | 32 | Header Files 33 | 34 | 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/TestMacDriver/TestMacDriver.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {7a25f089-2ac4-4966-a3b6-c8746972c439} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {a5b4d800-c1f1-430a-8313-8ed560844bec} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {c23b1134-e337-4f9e-989e-fd267f687fbb} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {f199dd76-023b-4ce6-968f-f1dfc4fd4132} 18 | *.mak 19 | 20 | 21 | 22 | 23 | Source files 24 | 25 | 26 | Source files 27 | 28 | 29 | 30 | 31 | 32 | Source files 33 | 34 | 35 | Make files 36 | 37 | 38 | 39 | 40 | Source files 41 | 42 | 43 | -------------------------------------------------------------------------------- /examples/WinKernel/FileDiskBus/Filedisk.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "filedisk.h" 3 | 4 | using namespace BazisLib; 5 | 6 | FileDisk::FileDisk(ManagedPointer &pFile, ULONGLONG FileOffset, unsigned SectorSize, unsigned minMBCount) : 7 | m_pFile(pFile), 8 | m_FileOffset(FileOffset), 9 | m_SectorSize(SectorSize), 10 | m_MinMBCount(minMBCount) 11 | { 12 | if (!m_pFile) 13 | return; 14 | m_SectorCount = m_pFile->GetSize() / SectorSize; 15 | } 16 | 17 | FileDisk::~FileDisk() 18 | { 19 | } 20 | 21 | unsigned FileDisk::GetSectorSize() 22 | { 23 | return m_SectorSize; 24 | } 25 | 26 | ULONGLONG FileDisk::GetSectorCount() 27 | { 28 | return m_SectorCount; 29 | } 30 | 31 | unsigned FileDisk::Read(ULONGLONG ByteOffset, void *pBuffer, unsigned Length) 32 | { 33 | if (!m_pFile || !pBuffer) 34 | return 0; 35 | m_pFile->Seek(m_FileOffset + ByteOffset, FileFlags::FileBegin); 36 | return m_pFile->Read(pBuffer, Length); 37 | } 38 | 39 | unsigned FileDisk::Write(ULONGLONG ByteOffset, const void *pBuffer, unsigned Length) 40 | { 41 | if (!m_pFile || !pBuffer) 42 | return 0; 43 | LONGLONG soff = m_pFile->Seek(m_FileOffset + ByteOffset, FileFlags::FileBegin); 44 | return m_pFile->Write(pBuffer, Length); 45 | } 46 | 47 | void FileDisk::Dispose() 48 | { 49 | m_pFile = NULL; 50 | } 51 | 52 | BazisLib::ActionStatus BazisLib::FileDisk::Initialize() 53 | { 54 | if (m_pFile->GetSize() < (m_MinMBCount * 1024 * 1024)) 55 | { 56 | DbgPrint("Preparing filedisk file..."); 57 | BasicBuffer buf(1024 * 1024); 58 | buf.Fill(); 59 | for(unsigned i = 0; i < m_MinMBCount; i++) 60 | m_pFile->Write(buf.GetData(), buf.GetAllocated()); 61 | DbgPrint("done\n"); 62 | } 63 | 64 | m_SectorCount = m_pFile->GetSize() / m_SectorSize; 65 | return MAKE_STATUS(Success); 66 | } 67 | -------------------------------------------------------------------------------- /tests/BigCrossPlatformTest/AutoTestLib/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | STATIC LIBRARY : AutoTestLib Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this AutoTestLib library project for you. 6 | 7 | This file contains a summary of what you will find in each of the files that 8 | make up your AutoTestLib application. 9 | 10 | 11 | AutoTestLib.vcxproj 12 | This is the main project file for VC++ projects generated using an Application Wizard. 13 | It contains information about the version of Visual C++ that generated the file, and 14 | information about the platforms, configurations, and project features selected with the 15 | Application Wizard. 16 | 17 | AutoTestLib.vcxproj.filters 18 | This is the filters file for VC++ projects generated using an Application Wizard. 19 | It contains information about the association between the files in your project 20 | and the filters. This association is used in the IDE to show grouping of files with 21 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 22 | "Source Files" filter). 23 | 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 27 | StdAfx.h, StdAfx.cpp 28 | These files are used to build a precompiled header (PCH) file 29 | named AutoTestLib.pch and a precompiled types file named StdAfx.obj. 30 | 31 | ///////////////////////////////////////////////////////////////////////////// 32 | Other notes: 33 | 34 | AppWizard uses "TODO:" comments to indicate parts of the source code you 35 | should add to or customize. 36 | 37 | ///////////////////////////////////////////////////////////////////////////// 38 | -------------------------------------------------------------------------------- /bzshlp/WinKernel/process.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #pragma region Undocumented API 5 | extern "C" 6 | { 7 | NTSTATUS __stdcall ZwQueryInformationProcess( 8 | __in HANDLE ProcessHandle, 9 | __in PROCESSINFOCLASS ProcessInformationClass, 10 | __out PVOID ProcessInformation, 11 | __in ULONG ProcessInformationLength, 12 | __out_opt PULONG ReturnLength 13 | ); 14 | } 15 | #pragma endregion 16 | 17 | namespace BazisLib 18 | { 19 | namespace DDK 20 | { 21 | class ProcessAccessor 22 | { 23 | private: 24 | HANDLE _hProcess; 25 | PKPROCESS _pProcess; 26 | 27 | public: 28 | //! This function accepts a process ID, not the process handle! 29 | ProcessAccessor(HANDLE ProcessID, ActionStatus *pStatus = NULL); 30 | ~ProcessAccessor(); 31 | 32 | bool Valid() { return _hProcess != 0; } 33 | ActionStatus Terminate(NTSTATUS exitCode) 34 | { 35 | NTSTATUS status = ZwTerminateProcess(_hProcess, exitCode); 36 | return MAKE_STATUS(ActionStatus::FromNTStatus(status)); 37 | } 38 | 39 | ActionStatus QueryBasicInfo(PROCESS_BASIC_INFORMATION *pInfo); 40 | 41 | ActionStatus ReadMemory(const void *pAddressInProcess, void *pSystemBuffer, size_t size); 42 | 43 | template ActionStatus ReadStruct(const void *pAddressInProcess, _Struct *pStruct) 44 | { 45 | return ReadMemory(pAddressInProcess, pStruct, sizeof(_Struct)); 46 | } 47 | 48 | struct StartInfo 49 | { 50 | String ImagePath; 51 | String CommandLine; 52 | 53 | bool Valid() {return !ImagePath.empty();} 54 | }; 55 | 56 | StartInfo QueryStartInfo(); 57 | 58 | private: 59 | ActionStatus DoQueryStartInfoFromProcessContext(PPROCESS_BASIC_INFORMATION pBasicInfo, StartInfo *pInfo); 60 | }; 61 | } 62 | } -------------------------------------------------------------------------------- /bzshlp/MacOS/DeviceEnumerator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "CFHandle.h" 6 | #include "IOService.h" 7 | #include 8 | #include "IORegistry.h" 9 | 10 | namespace BazisLib 11 | { 12 | namespace MacOS 13 | { 14 | class DeviceInformationSet 15 | { 16 | private: 17 | CFHandle _MatchingDict; 18 | 19 | public: 20 | enum MatchType 21 | { 22 | ServiceClass, 23 | ServiceName, 24 | BSDName, 25 | }; 26 | 27 | DeviceInformationSet(const char *pName, MatchType nameType = ServiceClass) 28 | { 29 | switch(nameType) 30 | { 31 | case ServiceName: 32 | _MatchingDict = IOServiceNameMatching(pName); 33 | break; 34 | case BSDName: 35 | _MatchingDict = IOBSDNameMatching(kIOMasterPortDefault, 0, pName); 36 | break; 37 | case ServiceClass: 38 | default: 39 | _MatchingDict = IOServiceMatching(pName); 40 | break; 41 | } 42 | } 43 | 44 | DeviceInformationSet(uint64_t entryID) 45 | { 46 | _MatchingDict = IORegistryEntryIDMatching(entryID); 47 | } 48 | 49 | class iterator : public _IOIteratorWrapper 50 | { 51 | private: 52 | typedef _IOIteratorWrapper super; 53 | 54 | public: 55 | iterator(const DeviceInformationSet &devs) 56 | : super(NULL) 57 | { 58 | IOServiceGetMatchingServices(kIOMasterPortDefault, devs._MatchingDict.get(), MakeWritablePointer()); 59 | if (!get()) 60 | return; 61 | Next(); 62 | } 63 | 64 | BazisLib::String GetServicePath() 65 | { 66 | return (*this)->GetRegistryPath(); 67 | } 68 | }; 69 | 70 | IOServiceWrapper GetFirstService() 71 | { 72 | return *iterator(*this); 73 | } 74 | }; 75 | } 76 | } -------------------------------------------------------------------------------- /bzscore/WinKernel/fileapi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #pragma region Imported FS-related functions 4 | #ifndef _NTIFS_INCLUDED_ 5 | extern "C" 6 | NTSTATUS 7 | ZwQueryDirectoryFile( 8 | IN HANDLE FileHandle, 9 | IN HANDLE Event OPTIONAL, 10 | IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, 11 | IN PVOID ApcContext OPTIONAL, 12 | OUT PIO_STATUS_BLOCK IoStatusBlock, 13 | OUT PVOID FileInformation, 14 | IN ULONG Length, 15 | IN FILE_INFORMATION_CLASS FileInformationClass, 16 | IN BOOLEAN ReturnSingleEntry, 17 | IN PUNICODE_STRING FileName OPTIONAL, 18 | IN BOOLEAN RestartScan 19 | ); 20 | 21 | extern "C" 22 | NTSYSAPI 23 | NTSTATUS 24 | NTAPI 25 | ZwDeviceIoControlFile(IN HANDLE FileHandle, 26 | IN HANDLE Event, 27 | IN PIO_APC_ROUTINE ApcRoutine, 28 | IN PVOID ApcContext, 29 | OUT PIO_STATUS_BLOCK IoStatusBlock, 30 | IN ULONG IoControlCode, 31 | IN PVOID InputBuffer, 32 | IN ULONG InputBufferLength, 33 | OUT PVOID OutputBuffer, 34 | IN ULONG OutputBufferLength 35 | ); 36 | 37 | typedef struct _FILE_RENAME_INFORMATION { 38 | BOOLEAN ReplaceIfExists; 39 | HANDLE RootDirectory; 40 | ULONG FileNameLength; 41 | WCHAR FileName[1]; 42 | } FILE_RENAME_INFORMATION, *PFILE_RENAME_INFORMATION; 43 | 44 | typedef struct _FILE_FULL_DIR_INFORMATION { 45 | ULONG NextEntryOffset; 46 | ULONG FileIndex; 47 | LARGE_INTEGER CreationTime; 48 | LARGE_INTEGER LastAccessTime; 49 | LARGE_INTEGER LastWriteTime; 50 | LARGE_INTEGER ChangeTime; 51 | LARGE_INTEGER EndOfFile; 52 | LARGE_INTEGER AllocationSize; 53 | ULONG FileAttributes; 54 | ULONG FileNameLength; 55 | ULONG EaSize; 56 | WCHAR FileName[1]; 57 | } FILE_FULL_DIR_INFORMATION, *PFILE_FULL_DIR_INFORMATION; 58 | #endif 59 | #pragma endregion -------------------------------------------------------------------------------- /bzshlp/MacOS/IOObject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace BazisLib 5 | { 6 | namespace MacOS 7 | { 8 | class IOObjectWrapper 9 | { 10 | private: 11 | io_object_t _Obj; 12 | 13 | public: 14 | IOObjectWrapper(io_object_t obj = 0) 15 | : _Obj(obj) 16 | { 17 | } 18 | 19 | ~IOObjectWrapper() 20 | { 21 | if (_Obj) 22 | IOObjectRelease(_Obj); 23 | } 24 | 25 | IOObjectWrapper(const IOObjectWrapper &obj) 26 | : _Obj(obj._Obj) 27 | { 28 | if (_Obj) 29 | IOObjectRetain(_Obj); 30 | } 31 | 32 | io_object_t get() const {return _Obj;} 33 | io_object_t RetainAndGet() {IOObjectRetain(_Obj); return _Obj;} 34 | 35 | io_object_t *MakeWritablePointer() 36 | { 37 | if (_Obj) 38 | { 39 | IOObjectRelease(_Obj); 40 | _Obj = NULL; 41 | } 42 | return &_Obj; 43 | } 44 | 45 | bool Valid() { return _Obj != 0;} 46 | operator bool() {return _Obj != 0;} 47 | 48 | IOObjectWrapper &operator=(IOObjectWrapper obj) 49 | { 50 | if (_Obj) 51 | IOObjectRelease(_Obj); 52 | _Obj = obj._Obj; 53 | if (_Obj) 54 | IOObjectRetain(_Obj); 55 | return *this; 56 | } 57 | 58 | IOObjectWrapper &operator=(io_object_t &obj) 59 | { 60 | if (_Obj) 61 | IOObjectRelease(_Obj); 62 | _Obj = obj; 63 | if (_Obj) 64 | IOObjectRetain(_Obj); 65 | } 66 | 67 | }; 68 | 69 | template class _IOObjectWrapperT : public IOObjectWrapper 70 | { 71 | public: 72 | _IOObjectWrapperT(_ObjType obj) 73 | : IOObjectWrapper(obj) 74 | { 75 | } 76 | 77 | _IOObjectWrapperT() 78 | { 79 | } 80 | 81 | _ObjType get() 82 | { 83 | return static_cast<_ObjType>(IOObjectWrapper::get()); 84 | } 85 | 86 | typedef _ObjType _RawObjectType; 87 | }; 88 | } 89 | } -------------------------------------------------------------------------------- /bzshlp/uidpool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../bzscore/sync.h" 3 | #include "cmndef.h" 4 | 5 | namespace BazisLib 6 | { 7 | /*! The UniqueIdPool class allows maintains a list of IDs allowing clients to allocate/release some of them. 8 | If you want to assign a locally unique ID to any newly created object, consider using this class. It has 9 | constant running time for both allocation and freeing operations. 10 | */ 11 | class UniqueIdPool 12 | { 13 | public: 14 | typedef INT_PTR _type; 15 | static const _type BadID = -1; 16 | 17 | private: 18 | _type *m_pValues; 19 | _type *m_pFirstFree; 20 | Mutex m_AccessLock; 21 | 22 | public: 23 | UniqueIdPool(unsigned MaxIDCount) 24 | { 25 | //If you got an error here, you're trying to compile this code while sizeof(ptr) is greater than sizeof(_type) 26 | //You should then change from int to some kind of INT_PTR 27 | static char __unused[sizeof(_type)-sizeof(_type *)+1]; 28 | 29 | m_pValues = new _type[MaxIDCount]; 30 | if (!m_pValues) 31 | return; 32 | for (unsigned i = 0; i < (MaxIDCount - 1); i++) 33 | ((_type **)m_pValues)[i] = &m_pValues[i+1]; 34 | m_pValues[MaxIDCount - 1] = 0; 35 | 36 | m_pFirstFree = m_pValues; 37 | } 38 | 39 | ~UniqueIdPool() 40 | { 41 | delete m_pValues; 42 | } 43 | 44 | _type AllocateID() 45 | { 46 | if (!m_pValues) 47 | return BadID; 48 | MutexLocker lck(m_AccessLock); 49 | if (!m_pFirstFree) 50 | return BadID; 51 | _type id = m_pFirstFree - m_pValues; 52 | m_pFirstFree = (_type *)*m_pFirstFree; 53 | return id; 54 | } 55 | 56 | void ReleaseID(_type ID) 57 | { 58 | if ((ID == BadID) || !m_pValues) 59 | return; 60 | MutexLocker lck(m_AccessLock); 61 | _type *pID = m_pValues + ID; 62 | *pID = (_type)m_pFirstFree; 63 | m_pFirstFree = pID; 64 | } 65 | }; 66 | } -------------------------------------------------------------------------------- /bzsnet/bzsnet.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | Header Files 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /examples/PortableThreadDemo/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | CONSOLE APPLICATION : PortableThreadDemo Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this PortableThreadDemo application for you. 6 | 7 | This file contains a summary of what you will find in each of the files that 8 | make up your PortableThreadDemo application. 9 | 10 | 11 | PortableThreadDemo.vcxproj 12 | This is the main project file for VC++ projects generated using an Application Wizard. 13 | It contains information about the version of Visual C++ that generated the file, and 14 | information about the platforms, configurations, and project features selected with the 15 | Application Wizard. 16 | 17 | PortableThreadDemo.vcxproj.filters 18 | This is the filters file for VC++ projects generated using an Application Wizard. 19 | It contains information about the association between the files in your project 20 | and the filters. This association is used in the IDE to show grouping of files with 21 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 22 | "Source Files" filter). 23 | 24 | PortableThreadDemo.cpp 25 | This is the main application source file. 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | Other standard files: 29 | 30 | StdAfx.h, StdAfx.cpp 31 | These files are used to build a precompiled header (PCH) file 32 | named PortableThreadDemo.pch and a precompiled types file named StdAfx.obj. 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | Other notes: 36 | 37 | AppWizard uses "TODO:" comments to indicate parts of the source code you 38 | should add to or customize. 39 | 40 | ///////////////////////////////////////////////////////////////////////////// 41 | -------------------------------------------------------------------------------- /examples/WinKernel/RamDiskBus/RamDiskBus.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {8E41214B-6785-4CFE-B992-037D68949A14} 18 | inf;inv;inx;mof;mc; 19 | 20 | 21 | 22 | 23 | Driver Files 24 | 25 | 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | -------------------------------------------------------------------------------- /examples/WinKernel/SampleInstaller/SampleInstaller.cpp: -------------------------------------------------------------------------------- 1 | // SampleInstaller.cpp : main source file for SampleInstaller.exe 2 | // 3 | 4 | #include "stdafx.h" 5 | 6 | #include "resource.h" 7 | 8 | #include "MainDlg.h" 9 | 10 | CAppModule _Module; 11 | 12 | int Run(LPTSTR /*lpstrCmdLine*/ = NULL, int nCmdShow = SW_SHOWDEFAULT) 13 | { 14 | // CMessageLoop theLoop; 15 | // _Module.AddMessageLoop(&theLoop); 16 | 17 | CMainDlg dlgMain; 18 | return dlgMain.DoModal(HWND_DESKTOP); 19 | 20 | // if(dlgMain.Create(NULL) == NULL) 21 | // { 22 | // ATLTRACE(_T("Main dialog creation failed!\n")); 23 | // return 0; 24 | // } 25 | // 26 | // dlgMain.ShowWindow(nCmdShow); 27 | // 28 | // int nRet = theLoop.Run(); 29 | // 30 | // _Module.RemoveMessageLoop(); 31 | // return nRet; 32 | } 33 | 34 | #include 35 | 36 | int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow) 37 | { 38 | if (BazisLib::Win32::WOW64APIProvider::sIsWow64Process()) 39 | { 40 | MessageBox(HWND_DESKTOP, L"On 64-bit operating systems please use the 64-bit version of the sample installer", NULL, MB_ICONWARNING); 41 | return 0; 42 | } 43 | 44 | HRESULT hRes = ::CoInitialize(NULL); 45 | // If you are running on NT 4.0 or higher you can use the following call instead to 46 | // make the EXE free threaded. This means that calls come in on a random RPC thread. 47 | // HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); 48 | ATLASSERT(SUCCEEDED(hRes)); 49 | 50 | // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used 51 | ::DefWindowProc(NULL, 0, 0, 0L); 52 | 53 | AtlInitCommonControls(ICC_BAR_CLASSES); // add flags to support other controls 54 | 55 | hRes = _Module.Init(NULL, hInstance); 56 | ATLASSERT(SUCCEEDED(hRes)); 57 | 58 | int nRet = Run(lpstrCmdLine, nCmdShow); 59 | 60 | _Module.Term(); 61 | ::CoUninitialize(); 62 | 63 | return nRet; 64 | } 65 | -------------------------------------------------------------------------------- /bzscore/Posix/UnixFileModes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BazisLib 4 | { 5 | namespace FileModes 6 | { 7 | enum {kDefaultFileMode = 0755}; 8 | 9 | static const FileMode CreateOrOpenRW = {O_CREAT | O_RDWR, kDefaultFileMode}; 10 | static const FileMode CreateOrTruncateRW = {O_CREAT | O_RDWR | O_TRUNC, kDefaultFileMode}; 11 | static const FileMode CreateNewRW = {O_CREAT | O_EXCL | O_RDWR, kDefaultFileMode}; 12 | static const FileMode OpenReadOnly = {O_RDONLY, kDefaultFileMode}; 13 | static const FileMode OpenReadWrite = {O_RDWR, kDefaultFileMode}; 14 | static const FileMode OpenForSecurityQuery = {O_RDONLY, kDefaultFileMode}; 15 | static const FileMode OpenForSecurityModify = {O_RDWR, kDefaultFileMode}; 16 | 17 | static inline FileMode FromFileFlags(FileFlags::FileAccess Access = FileFlags::ReadAccess, 18 | FileFlags::OpenMode OpenMode = FileFlags::OpenExisting, 19 | FileFlags::ShareMode ShareMode = FileFlags::ShareRead, 20 | FileFlags::FileAttribute Attributes = FileFlags::NormalFile) 21 | { 22 | FileMode mode = {0,}; 23 | #pragma region Set access mode 24 | if (Access & (FileFlags::ReadAccess | FileFlags::WriteAccess | FileFlags::ReadWriteAccess | FileFlags::DeleteAccess | FileFlags::ModifySecurity)) 25 | mode.Flags = O_RDWR; 26 | else if (Access & (FileFlags::ReadAccess | FileFlags::WriteAccess)) 27 | mode.Flags = O_RDONLY; 28 | #pragma endregion 29 | #pragma region Set share mode 30 | #pragma endregion 31 | #pragma region Set open mode 32 | switch(OpenMode) 33 | { 34 | case FileFlags::OpenExisting: 35 | break; 36 | case FileFlags::OpenAlways: 37 | mode.Flags |= O_CREAT; 38 | break; 39 | case FileFlags::CreateAlways: 40 | mode.Flags |= O_CREAT | O_TRUNC; 41 | break; 42 | case FileFlags::CreateNew: 43 | mode.Flags |= O_CREAT | O_EXCL; 44 | break; 45 | } 46 | #pragma endregion 47 | mode.AccessMask = kDefaultFileMode; 48 | return mode; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /examples/WinKernel/FileDiskBus/FileDiskBus.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {8E41214B-6785-4CFE-B992-037D68949A14} 18 | inf;inv;inx;mof;mc; 19 | 20 | 21 | 22 | 23 | Driver Files 24 | 25 | 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | -------------------------------------------------------------------------------- /bzscore/cmndef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if _WIN32 || _WIN64 4 | #if _WIN64 5 | #define BZSLIB64 6 | #endif 7 | #elif __GNUC__ 8 | #if __x86_64__ || __ppc64__ 9 | #define BZSLIB64 10 | #endif 11 | #else 12 | #error Cannot detect whether current target is 32-bit or 64-bit 13 | #endif 14 | 15 | #if defined(_DDK_) || (defined(_WIN32) && defined(_KERNEL_MODE)) 16 | #ifndef UNICODE 17 | #define UNICODE 18 | #endif 19 | 20 | #define BZSLIB_WINKERNEL 21 | 22 | extern "C" 23 | { 24 | #ifdef _ENABLE_VISUALDDK_HELPERS_ 25 | #include "WinKernel/VisualDDKHelpers.h" 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | } 32 | 33 | #if defined(DBG) && DBG && !defined(_DEBUG) 34 | #define _DEBUG 1 35 | #endif 36 | 37 | #elif defined(WIN32) 38 | #define BZSLIB_WINUSER 39 | #include 40 | #include 41 | #include 42 | #elif defined(BZS_POSIX) 43 | #define BZSLIB_POSIX 44 | #define BZSLIB_UNIXWORLD 45 | #ifdef DEBUG 46 | #define _DEBUG 1 47 | #endif 48 | typedef unsigned short wchar16_t; 49 | #include 50 | #include "Posix/compat.h" 51 | #include "Posix/guid_compat.h" 52 | #include "Posix/longlong_compat.h" 53 | typedef intptr_t INT_PTR; 54 | typedef uintptr_t UINT_PTR; 55 | #define TRUE 1 56 | #define FALSE 0 57 | #elif defined(BZS_KEXT) 58 | #define BZSLIB_KEXT 59 | #define BZSLIB_UNIXWORLD 60 | #ifdef DEBUG 61 | #define _DEBUG 1 62 | #endif 63 | #include "KEXT/cmndef.h" 64 | #else 65 | #error Unknown platform type 66 | #endif 67 | 68 | #ifndef _MSC_VER 69 | #define override 70 | #endif 71 | 72 | /*extern "C++" 73 | { 74 | template 75 | char (*__countof_helper(_CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray]; 76 | #define __countof(_Array) sizeof(*__countof_helper(_Array)) 77 | }*/ 78 | 79 | #define __countof(x) ((sizeof(x) / sizeof((x)[0]))) 80 | 81 | #include "platform.h" 82 | #include "tchar_compat.h" 83 | 84 | #define BAZISLIB_VERSION 0x0300 -------------------------------------------------------------------------------- /examples/PortableThreadDemo/PortableThreadDemo.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {b80f6e7d-1759-4613-a404-38a3db388e18} 18 | *.mak 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | Make files 27 | 28 | 29 | Make files 30 | 31 | 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | -------------------------------------------------------------------------------- /tests/CommonFunctionalityTests/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | CONSOLE APPLICATION : CommonFunctionalityTests Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this CommonFunctionalityTests application for you. 6 | 7 | This file contains a summary of what you will find in each of the files that 8 | make up your CommonFunctionalityTests application. 9 | 10 | 11 | CommonFunctionalityTests.vcxproj 12 | This is the main project file for VC++ projects generated using an Application Wizard. 13 | It contains information about the version of Visual C++ that generated the file, and 14 | information about the platforms, configurations, and project features selected with the 15 | Application Wizard. 16 | 17 | CommonFunctionalityTests.vcxproj.filters 18 | This is the filters file for VC++ projects generated using an Application Wizard. 19 | It contains information about the association between the files in your project 20 | and the filters. This association is used in the IDE to show grouping of files with 21 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 22 | "Source Files" filter). 23 | 24 | CommonFunctionalityTests.cpp 25 | This is the main application source file. 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | Other standard files: 29 | 30 | StdAfx.h, StdAfx.cpp 31 | These files are used to build a precompiled header (PCH) file 32 | named CommonFunctionalityTests.pch and a precompiled types file named StdAfx.obj. 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | Other notes: 36 | 37 | AppWizard uses "TODO:" comments to indicate parts of the source code you 38 | should add to or customize. 39 | 40 | ///////////////////////////////////////////////////////////////////////////// 41 | -------------------------------------------------------------------------------- /bzscore/Posix/DNS.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #if (defined(BZSLIB_UNIXWORLD) && !defined(BZSLIB_KEXT)) || (defined (WIN32) && !defined(_NTDDK_)) 3 | 4 | #include "DNS.h" 5 | 6 | #ifdef WIN32 7 | #include "../Win32/socket.h" 8 | #else 9 | #include 10 | #include 11 | #endif 12 | 13 | using namespace BazisLib; 14 | using namespace BazisLib::Network; 15 | 16 | InternetAddress BazisLib::Network::Posix::DNS::GetHostByName( const char *pHostName ) 17 | { 18 | #ifdef WIN32 19 | BazisLib::Win32::WinsockLoader winsock; 20 | #endif 21 | 22 | const char *p = strchr(pHostName, ':'); 23 | int port = 0; 24 | hostent *pHostEnt; 25 | if (!p) 26 | pHostEnt = gethostbyname(pHostName); 27 | else 28 | { 29 | pHostEnt = gethostbyname(DynamicStringA(pHostName, p - pHostName).c_str()); 30 | port = atoi(p + 1); 31 | } 32 | 33 | if (!pHostEnt) 34 | return InternetAddress(); 35 | 36 | char *pAddr0 = pHostEnt->h_addr_list[0]; 37 | return IP4Address(((unsigned *)pAddr0)[0], (unsigned short)port); 38 | } 39 | 40 | std::vector BazisLib::Network::Posix::DNS::GetAllHostAddresses( const char *pHostName, AddrTypeFilter filter /*= kIPvAll*/ ) 41 | { 42 | std::vector result; 43 | 44 | addrinfo *pFirst = NULL; 45 | getaddrinfo(pHostName , NULL, NULL, &pFirst); 46 | if (!pFirst) 47 | return result; 48 | 49 | int cnt = 0; 50 | for (addrinfo *pNode = pFirst; pNode ; pNode = pNode->ai_next) 51 | cnt++; 52 | 53 | result.reserve(cnt); 54 | 55 | for (addrinfo *pNode = pFirst; pNode ; pNode = pNode->ai_next) 56 | { 57 | switch(pNode->ai_family) 58 | { 59 | case AF_INET: 60 | if (filter & kIPv4) 61 | result.push_back(*reinterpret_cast(pNode->ai_addr)); 62 | break; 63 | case AF_INET6: 64 | if (filter & kIPv6) 65 | result.push_back(*reinterpret_cast(pNode->ai_addr)); 66 | break; 67 | } 68 | } 69 | 70 | freeaddrinfo(pFirst); 71 | return result; 72 | } 73 | #endif -------------------------------------------------------------------------------- /examples/WinKernel/SampleInstaller/SampleInstaller.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {0172d891-7032-4031-a52c-5f91f2fe3c04} 6 | cpp;c;cxx;def;odl;idl;hpj;bat;asm 7 | 8 | 9 | {fd23b421-5d0f-4155-89b0-70106a59df72} 10 | h;hpp;hxx;hm;inl;inc 11 | 12 | 13 | {8791a754-715d-4c61-babd-f1974b8834c9} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;jpg;jpeg;jpe;manifest 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | 29 | 30 | Header Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | Header Files 37 | 38 | 39 | Header Files 40 | 41 | 42 | 43 | 44 | Resource Files 45 | 46 | 47 | 48 | 49 | Resource Files 50 | 51 | 52 | -------------------------------------------------------------------------------- /examples/WinKernel/FileDiskBus/FileDiskBus.inf: -------------------------------------------------------------------------------- 1 | ; This sample driver creates two 128MB virtual disks mapped to files in C:\ 2 | ; 1. C:\test0.dsk - mapped to a 1-partition disk (appears as a drive letter) 3 | ; 2. C:\test1.dsk - mapped to an empty disk (appears in Disk Management) 4 | ; To test the driver, format one or both disks, copy some files to them, 5 | ; stop the device from Device Manager and start it again. 6 | ; 7 | ; If test0.dsk or test1.dsk does not exist, it will be initialized with 128MB of 8 | ; zeros. Otherwise, the file will be reused. 9 | 10 | [Version] 11 | Signature="$WINDOWS NT$" 12 | Class=HDC 13 | ClassGuid={4d36e96a-e325-11ce-bfc1-08002be10318} 14 | Provider=%BAZIS% 15 | DriverVer=01/01/2010, 1.00.0000 16 | CatalogFile=FileDiskBus.cat 17 | 18 | [DestinationDirs] 19 | DefaultDestDir = 12 20 | 21 | [SourceDisksNames] 22 | 1 = %DiskId1%,,, 23 | 24 | [SourceDisksFiles] 25 | FileDiskBus.sys = 1 26 | 27 | [Manufacturer] 28 | %BAZIS%=Standard, NTamd64 29 | 30 | [Standard] 31 | %FileDiskBus.DeviceDesc%=FileDiskBus_Device, root\FileDiskBus 32 | 33 | [Standard.NTamd64] 34 | %FileDiskBus.DeviceDesc%=FileDiskBus_Device, root\FileDiskBus 35 | 36 | [FileDiskBus_Device.NT] 37 | CopyFiles=Drivers_Dir 38 | 39 | [Drivers_Dir] 40 | FileDiskBus.sys,,,2 41 | 42 | ;-------------- Service installation 43 | [FileDiskBus_Device.NT.Services] 44 | AddService = FileDiskBus,%SPSVCINST_ASSOCSERVICE%, dev_Service_Inst 45 | 46 | ; -------------- busenum driver install sections 47 | [dev_Service_Inst] 48 | DisplayName = %dev.SVCDESC% 49 | ServiceType = 1 ; SERVICE_KERNEL_DRIVER 50 | StartType = 3 ; SERVICE_DEMAND_START 51 | ErrorControl = 1 ; SERVICE_ERROR_NORMAL 52 | ServiceBinary = %12%\FileDiskBus.sys 53 | LoadOrderGroup = Extended Base 54 | 55 | 56 | [Strings] 57 | SPSVCINST_ASSOCSERVICE= 0x00000002 58 | BAZIS = "BazisLib" 59 | DiskId1 = "FileDiskBus Installation Disk #1" 60 | FileDiskBus.DeviceDesc = "FileDiskBus device" 61 | dev.SVCDESC = "FileDiskBus driver" 62 | -------------------------------------------------------------------------------- /examples/WinKernel/RamDiskBus/RamDiskBus.inf: -------------------------------------------------------------------------------- 1 | ; This sample driver creates two RAM disks using 2 different modes: 2 | ; 1. A 16MB disk with a fixed partition table (gets a drive letter immediately) 3 | ; 2. A 32MB disk with no partition table (appears in Disk Management) 4 | ; To test the driver, format one or both disks and try copying files to and from 5 | ; the disks. 6 | 7 | ;Note that when you restart or reload the driver the contents of the disks will be reset. 8 | 9 | 10 | [Version] 11 | Signature="$WINDOWS NT$" 12 | Class=Volume 13 | ClassGuid= {71a27cdd-812a-11d0-bec7-08002be2092f} 14 | Provider=%BAZIS% 15 | DriverVer=01/01/2010, 1.00.0000 16 | CatalogFile=RamDiskBus.cat 17 | 18 | [DestinationDirs] 19 | DefaultDestDir = 12 20 | 21 | [SourceDisksNames.x86] 22 | 1 = %DiskId1%,,, 23 | 24 | [SourceDisksNames.amd64] 25 | 1 = %DiskId1%,,, 26 | 27 | [SourceDisksFiles.x86] 28 | RamDiskBus.sys = 1 29 | 30 | [SourceDisksFiles.amd64] 31 | RamDiskBus.sys = 1 32 | 33 | [Manufacturer] 34 | %BAZIS%=Standard, NTamd64 35 | 36 | [Standard] 37 | %RamDiskBus.DeviceDesc%=RamDiskBus_Device, root\RamDiskBus 38 | 39 | [Standard.NTamd64] 40 | %RamDiskBus.DeviceDesc%=RamDiskBus_Device, root\RamDiskBus 41 | 42 | [RamDiskBus_Device.NT] 43 | CopyFiles=Drivers_Dir 44 | 45 | [Drivers_Dir] 46 | RamDiskBus.sys,,,2 47 | 48 | ;-------------- Service installation 49 | [RamDiskBus_Device.NT.Services] 50 | AddService = RamDiskBus,%SPSVCINST_ASSOCSERVICE%, dev_Service_Inst 51 | 52 | ; -------------- busenum driver install sections 53 | [dev_Service_Inst] 54 | DisplayName = %dev.SVCDESC% 55 | ServiceType = 1 ; SERVICE_KERNEL_DRIVER 56 | StartType = 3 ; SERVICE_DEMAND_START 57 | ErrorControl = 1 ; SERVICE_ERROR_NORMAL 58 | ServiceBinary = %12%\RamDiskBus.sys 59 | LoadOrderGroup = Extended Base 60 | 61 | 62 | [Strings] 63 | SPSVCINST_ASSOCSERVICE= 0x00000002 64 | BAZIS = "BazisLib" 65 | DiskId1 = "RamDiskBus Installation Disk #1" 66 | RamDiskBus.DeviceDesc = "RamDiskBus device" 67 | dev.SVCDESC = "RamDiskBus driver" 68 | -------------------------------------------------------------------------------- /bzshlp/ratecalc.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #if !defined(BZSLIB_WINKERNEL) 4 | #include "ratecalc.h" 5 | 6 | using namespace BazisLib; 7 | 8 | RateCalculator::RateCalculator(unsigned AveragingTime) : 9 | m_AveragingTime(AveragingTime), 10 | m_DownloadedInLastPeriod(0), 11 | m_DownloadedTotal(0), 12 | m_CachedValue(0), 13 | m_RateFilter(EstimatedTimeRateFilteringCoef) 14 | { 15 | } 16 | 17 | void RateCalculator::UpdateAverage() 18 | { 19 | DateTime tm = DateTime::Now(); 20 | ULONGLONG msec = (tm - m_StartTime).GetTotalMilliseconds(); 21 | if (!msec) 22 | return; 23 | if (m_AveragingTime == -1) 24 | m_CachedValue = (unsigned)((m_DownloadedInLastPeriod * 1000) / msec); 25 | else if (msec >= m_AveragingTime) 26 | { 27 | m_CachedValue = (unsigned)((m_DownloadedInLastPeriod * 1000) / msec); 28 | m_DownloadedInLastPeriod = 0; 29 | m_StartTime = tm; 30 | } 31 | } 32 | 33 | void RateCalculator::ReportNewAbsoluteDone(ULONGLONG Done) 34 | { 35 | if (!m_DownloadedInLastPeriod) 36 | m_StartTime = DateTime::Now(); 37 | MutexLocker lck(m_Lock); 38 | m_DownloadedInLastPeriod = Done; 39 | m_DownloadedTotal = Done; 40 | UpdateAverage(); 41 | } 42 | 43 | void RateCalculator::ReportNewRelativeDone(ULONGLONG Done) 44 | { 45 | if (!m_DownloadedInLastPeriod) 46 | m_StartTime = DateTime::Now(); 47 | MutexLocker lck(m_Lock); 48 | m_DownloadedInLastPeriod += Done; 49 | m_DownloadedTotal += Done; 50 | UpdateAverage(); 51 | } 52 | 53 | unsigned RateCalculator::GetBytesPerSecond() 54 | { 55 | return m_CachedValue; 56 | } 57 | 58 | TimeSpan RateCalculator::GetExpectedRemainingTime(ULONGLONG TotalDownloadSize) 59 | { 60 | unsigned rate = m_CachedValue; 61 | if ((m_AveragingTime == -1) && ((DateTime::Now() - m_StartTime).GetTotalSeconds() < 5)) 62 | return TimeSpan(); 63 | if (!rate) 64 | return TimeSpan(); 65 | rate = (unsigned)m_RateFilter.UpdateValue(rate); 66 | LONGLONG left = TotalDownloadSize - m_DownloadedTotal; 67 | if (left <= 0) 68 | return TimeSpan(); 69 | return TimeSpan((10000000LL * left) / rate); 70 | } 71 | 72 | #endif -------------------------------------------------------------------------------- /bzshlp/Win32/bulkusb.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef UNDER_CE 3 | 4 | #include "cmndef.h" 5 | #include "../bzsstream.h" 6 | #include "../../bzscore/string.h" 7 | #include "bzsdev.h" 8 | #include 9 | #include 10 | 11 | static const GUID GUID_CLASS_I82930_BULK = {0x873fdf, 0x61a8, 0x11d1, 0xaa, 0x5e, 0x0, 0xc0, 0x4f, 0xb1, 0x72, 0x8b}; 12 | 13 | namespace BazisLib 14 | { 15 | namespace Win32 16 | { 17 | class IBulkPipe : public IPipe 18 | { 19 | public: 20 | virtual size_t ReadBulk(void *pBuffer, size_t Size)=0; 21 | virtual size_t WriteBulk(const void *pBuffer, size_t Size)=0; 22 | virtual ~IBulkPipe(){} 23 | }; 24 | 25 | class CBulkUsbPipe : public IBulkPipe 26 | { 27 | private: 28 | HANDLE m_hInPipe; 29 | HANDLE m_hOutPipe; 30 | 31 | public: 32 | CBulkUsbPipe(const String &devicePath, bool SwapPipes = false); 33 | 34 | public: 35 | static std::list EnumerateDevices(const GUID *pguidInterfaceType = NULL, PDEVICE_SN_FILTER Filter = 0, void *pContext = 0) 36 | { 37 | if (!pguidInterfaceType) 38 | pguidInterfaceType = &GUID_CLASS_I82930_BULK; 39 | return BazisLib::EnumerateDevicesByInterface(pguidInterfaceType, Filter, pContext); 40 | } 41 | 42 | static CBulkUsbPipe* OpenDevice(const BazisLib::String &DevicePath, bool SwapPipes); 43 | static CBulkUsbPipe* CreateDefault(const GUID *pguidInterfaceType = NULL, bool SwapPipes = false); 44 | 45 | public: 46 | virtual size_t Read(void *pBuffer, size_t Size); 47 | virtual size_t Write(const void *pBuffer, size_t Size); 48 | 49 | virtual size_t ReadBulk(void *pBuffer, size_t Size) {return Read(pBuffer, Size);} 50 | virtual size_t WriteBulk(const void *pBuffer, size_t Size) {return Write(pBuffer, Size);} 51 | 52 | virtual LONGLONG GetSize() {return 0;} 53 | virtual bool SetTimeout(unsigned ReadTimeout, unsigned WriteTimeout); 54 | virtual bool Valid() {return (m_hInPipe != INVALID_HANDLE_VALUE) && (m_hOutPipe != INVALID_HANDLE_VALUE);} 55 | virtual void Close(); 56 | virtual ~CBulkUsbPipe(); 57 | }; 58 | } 59 | } 60 | 61 | #endif -------------------------------------------------------------------------------- /bzshlp/gen_ser.pl: -------------------------------------------------------------------------------- 1 | #This file generates serializeable structure definition macros that should be placed inside serializer.h 2 | sub gen_def 3 | { 4 | my $x = $_[0]; 5 | my $init = $_[1]; 6 | my $i; 7 | my $it = ''; 8 | my $it1 = "__SERIALIZER_DEFAULT inline BazisLib::ActionStatus __SERIALIZER_ITERATE_MEMBERS(_Ty &ref, bool Save) \\\ 41 | { \\\ 42 | BazisLib::ActionStatus result;\\\n"; 43 | for ($i = 1; $i <= $x; $i++) 44 | {print F " if (!(result = ref._SerializerEntry(_T(#n$i), &n$i, Save)).Successful()) return result; \\\n";} 45 | print F " return MAKE_STATUS(BazisLib::Success); \\\ 46 | }\\\n};\\\n"; 47 | print F "static inline const TCHAR * __SERIALIZER_GET_TYPE_NAME(strucname *ptr) {return _T(# strucname);}\n\n"; 48 | } 49 | 50 | open F, ">ser_def.h"; 51 | print F "//This file was automatically generated by gen_ser.pl\n"; 52 | print F "//See serializer.h for details and comments\n\n"; 53 | for ($i = 1; $i <= 10; $i++) 54 | { 55 | gen_def($i, 0); 56 | } 57 | for ($i = 1; $i <= 10; $i++) 58 | { 59 | gen_def($i, 1); 60 | } 61 | close F; -------------------------------------------------------------------------------- /examples/WinKernel/RamDiskBus/Ramdisk.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "ramdisk.h" 3 | 4 | using namespace BazisLib; 5 | 6 | enum { kBufSize = 1024 * 1024 }; 7 | 8 | RamDisk::RamDisk(unsigned MegabyteCount) 9 | { 10 | __debugbreak(); 11 | int buffers = MegabyteCount / (kBufSize / 1024 / 1024); 12 | for (int i = 0; i < buffers; i++) 13 | { 14 | PHYSICAL_ADDRESS start, end; 15 | start.QuadPart = 0; 16 | end.QuadPart = -1; 17 | char *p = (char *)MmAllocateContiguousMemorySpecifyCache(kBufSize, start, end, start, MmCached); 18 | if (!p) 19 | break; 20 | m_Buffers.push_back(p); 21 | } 22 | 23 | buffers = m_Buffers.size(); 24 | m_TotalSize = buffers * (ULONGLONG)kBufSize; 25 | m_SectorCount = m_TotalSize / RAMDISK_SECTOR_SIZE; 26 | } 27 | 28 | RamDisk::~RamDisk() 29 | { 30 | for (char *p : m_Buffers) 31 | MmFreeContiguousMemory(p); 32 | } 33 | 34 | ULONGLONG RamDisk::GetSectorCount() 35 | { 36 | return m_SectorCount; 37 | } 38 | 39 | unsigned RamDisk::Read(ULONGLONG ByteOffset, void *pBuffer, unsigned Length) 40 | { 41 | unsigned done = 0; 42 | while (done < Length) 43 | { 44 | unsigned cdone = DoTransfer(ByteOffset + done, (char*)pBuffer + done, Length - done, true); 45 | if (!cdone) 46 | break; 47 | done += cdone; 48 | } 49 | 50 | return done; 51 | } 52 | 53 | unsigned RamDisk::Write(ULONGLONG ByteOffset, const void *pBuffer, unsigned Length) 54 | { 55 | unsigned done = 0; 56 | while (done < Length) 57 | { 58 | unsigned cdone = DoTransfer(ByteOffset + done, (char*)pBuffer + done, Length - done, false); 59 | if (!cdone) 60 | break; 61 | done += cdone; 62 | } 63 | 64 | return done; 65 | } 66 | 67 | unsigned BazisLib::RamDisk::DoTransfer(ULONGLONG ByteOffset, void *pBuffer, unsigned Length, bool read) 68 | { 69 | unsigned bufNum = (unsigned)(ByteOffset / kBufSize); 70 | if (bufNum >= m_Buffers.size() || !m_Buffers[bufNum]) 71 | return 0; 72 | unsigned bufOff = (ByteOffset % kBufSize); 73 | 74 | unsigned todo = min(Length, kBufSize - bufOff); 75 | if (!read) 76 | memcpy(m_Buffers[bufNum] + bufOff, pBuffer, todo); 77 | else 78 | memcpy(pBuffer, m_Buffers[bufNum] + bufOff, todo); 79 | return todo; 80 | } 81 | 82 | -------------------------------------------------------------------------------- /bzshlp/Win32/display.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "../../bzscore/status.h" 4 | #include "../../bzscore/buffer.h" 5 | 6 | namespace BazisLib 7 | { 8 | namespace Win32 9 | { 10 | class Display 11 | { 12 | public: 13 | class Mode 14 | { 15 | private: 16 | DEVMODE _DevMode; 17 | 18 | private: 19 | Mode(LPCTSTR lpDevName, DWORD iModeNum); 20 | friend class Display; 21 | 22 | public: 23 | PDEVMODE operator->() {return &_DevMode;} 24 | const DEVMODE *operator->() const {return &_DevMode;} 25 | 26 | bool Valid() {return _DevMode.dmSize != 0;} 27 | }; 28 | 29 | private: 30 | DISPLAY_DEVICE _Device; 31 | 32 | public: 33 | Display(LPCTSTR pszDeviceName, ActionStatus *pStatus = NULL) 34 | { 35 | if (EnumDisplayDevices(pszDeviceName, 0, &_Device, 0)) 36 | ASSIGN_STATUS(pStatus, Success); 37 | else 38 | ASSIGN_STATUS(pStatus, ActionStatus::FailFromLastError()); 39 | } 40 | 41 | Display(const DISPLAY_DEVICE &dev) 42 | : _Device(dev) 43 | { 44 | } 45 | 46 | typedef std::vector DisplayCollection; 47 | 48 | private: 49 | Display() 50 | { 51 | memset(&_Device, 0, sizeof(_Device)); 52 | } 53 | 54 | friend class DisplayCollection; 55 | 56 | public: 57 | enum DisplayEnumFilterKind 58 | { 59 | dfAll = 0, 60 | dfMirrors = 0x01, 61 | dfNonMirrors = 0x02, 62 | dfConnected = 0x04, 63 | dfDisconnected = 0x08, 64 | dfPrimaryOnly = 0x80000000 65 | }; 66 | 67 | static DisplayCollection EnumerateDiplays(DisplayEnumFilterKind filter = dfAll); 68 | 69 | Mode GetCurrentMode() {return Mode(_Device.DeviceName, ENUM_CURRENT_SETTINGS);} 70 | 71 | typedef std::vector ModeCollection; 72 | ModeCollection GetAllSupportedModes(); 73 | 74 | PDISPLAY_DEVICE operator->(){return &_Device;} 75 | bool Primary() {return !!(_Device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE);} 76 | bool Connected() {return !!(_Device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP);} 77 | 78 | bool MirroringDriver() {return !!(_Device.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER);} 79 | 80 | ActionStatus Disconnect(); 81 | }; 82 | 83 | } 84 | } -------------------------------------------------------------------------------- /bzshlp/MacOS/IOService.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "IORegistry.h" 3 | #include "IOConnect.h" 4 | #include 5 | #include 6 | 7 | namespace BazisLib 8 | { 9 | namespace MacOS 10 | { 11 | class IOServiceWrapper : public _IORegistryObjectWrapperT 12 | { 13 | protected: 14 | typedef _IORegistryObjectWrapperT super; 15 | 16 | public: 17 | IOServiceWrapper(io_service_t obj) 18 | : super(obj) 19 | { 20 | } 21 | 22 | IOServiceWrapper() 23 | { 24 | } 25 | 26 | IOConnectWrapper OpenService() 27 | { 28 | io_connect_t result = 0; 29 | IOServiceOpen(get(), mach_task_self(), 0, &result); 30 | return result; 31 | } 32 | 33 | IOServiceWrapper GetParentService() 34 | { 35 | return GetParent(); 36 | } 37 | 38 | IOServiceWrapper FindFirstMatchingChildRecursively(const char *pClassName); 39 | void FindAllMatchingChildrenRecursively(const char *pClassName, std::list &allServices, bool lookThroughChildrenOfMatched = false); 40 | }; 41 | 42 | typedef _IOIteratorWrapper IOServiceIteratorWrapper; 43 | 44 | inline BazisLib::MacOS::IOServiceWrapper IOServiceWrapper::FindFirstMatchingChildRecursively( const char *pClassName ) 45 | { 46 | for (IOServiceIteratorWrapper iter(GetChildren()); iter.Valid(); iter.Next()) 47 | { 48 | if (iter->IsAnInstanceOf(pClassName)) 49 | return *iter; 50 | IOServiceWrapper result = iter->FindFirstMatchingChildRecursively(pClassName); 51 | if (result.Valid()) 52 | return result; 53 | } 54 | return NULL; 55 | } 56 | 57 | inline void IOServiceWrapper::FindAllMatchingChildrenRecursively( const char *pClassName, std::list &allServices, bool lookThroughChildrenOfMatched ) 58 | { 59 | for (IOServiceIteratorWrapper iter(GetChildren()); iter.Valid(); iter.Next()) 60 | { 61 | if (iter->IsAnInstanceOf(pClassName)) 62 | { 63 | allServices.push_back(*iter); 64 | if (!lookThroughChildrenOfMatched) 65 | continue; 66 | } 67 | iter->FindAllMatchingChildrenRecursively(pClassName, allServices, lookThroughChildrenOfMatched); 68 | } 69 | } 70 | 71 | } 72 | } -------------------------------------------------------------------------------- /bzscore/atomic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cmndef.h" 3 | 4 | #ifdef BZSLIB_KEXT 5 | #include "KEXT/atomic.h" 6 | #elif defined (BZSLIB_POSIX) 7 | #include "Posix/atomic.h" 8 | #elif defined (BZSLIB_WINKERNEL) 9 | #include "WinKernel/atomic.h" 10 | #elif defined (_WIN32) 11 | #include "Win32/atomic.h" 12 | #else 13 | #error No atomic types defined for current platform 14 | #endif 15 | 16 | namespace BazisLib 17 | { 18 | #if defined(BZSLIB_NO_64BIT_ATOMIC_OPS) && defined(BZSLIB64) 19 | //No AtomicPointer available 20 | #else 21 | class AtomicPointer 22 | { 23 | protected: 24 | #ifdef BZSLIB64 25 | AtomicUInt64 _Value; 26 | typedef AtomicUInt64::_UnderlyingType _UnderlyingType; 27 | #else 28 | AtomicUInt32 _Value; 29 | typedef AtomicUInt32::_UnderlyingType _UnderlyingType; 30 | #endif 31 | 32 | C_ASSERT(sizeof(_UnderlyingType) == sizeof(void *)); 33 | 34 | private: 35 | void operator=(void *p) 36 | { 37 | _Value = (_UnderlyingType)p; 38 | } 39 | 40 | public: 41 | AtomicPointer(void *pVal = NULL) 42 | : _Value((_UnderlyingType)pVal) 43 | { 44 | } 45 | 46 | bool AssignIfNULL(void *pNewVal) 47 | { 48 | return _Value.CompareAndExchange((_UnderlyingType)NULL, (_UnderlyingType)pNewVal); 49 | } 50 | 51 | operator void *() 52 | { 53 | return (void *)(_UnderlyingType)_Value; 54 | } 55 | }; 56 | 57 | template class _AtomicPointerT 58 | { 59 | private: 60 | AtomicPointer _Pointer; 61 | 62 | void operator=(_Ty *p) 63 | { 64 | _Pointer = (void *)p; 65 | } 66 | 67 | public: 68 | _AtomicPointerT(_Ty *p = NULL) 69 | : _Pointer(p) 70 | { 71 | } 72 | 73 | bool AssignIfNULL(_Ty *pNewVal) 74 | { 75 | return _Pointer.AssignIfNULL(pNewVal); 76 | } 77 | 78 | void AssignIfNULLOrDeleteIfNot(_Ty *pNewVal) 79 | { 80 | if (!AssignIfNULL(pNewVal)) 81 | delete pNewVal; 82 | } 83 | 84 | operator _Ty *() 85 | { 86 | return (_Ty *)(void *)_Pointer; 87 | } 88 | 89 | _Ty * operator->() 90 | { 91 | return (_Ty *)(void *)_Pointer; 92 | } 93 | 94 | operator bool() 95 | { 96 | return (void *)_Pointer != 0; 97 | } 98 | }; 99 | #endif 100 | } -------------------------------------------------------------------------------- /bzshlp/WinKernel/DeviceEnumerator.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #ifdef BZSLIB_WINKERNEL 3 | #include "DeviceEnumerator.h" 4 | 5 | extern "C" NTSTATUS __stdcall ObReferenceObjectByName( 6 | PUNICODE_STRING Name, 7 | ULONG Attributes, 8 | PACCESS_STATE AccessState OPTIONAL, 9 | ACCESS_MASK Access, 10 | POBJECT_TYPE Type, 11 | KPROCESSOR_MODE bMode, 12 | ULONG Unknown OPTIONAL, 13 | PVOID *BodyPointer); 14 | 15 | extern "C" NTSTATUS 16 | IoEnumerateDeviceObjectList( 17 | IN PDRIVER_OBJECT DriverObject, 18 | IN PDEVICE_OBJECT *DeviceObjectList, 19 | IN ULONG DeviceObjectListSize, 20 | OUT PULONG ActualNumberDeviceObjects 21 | ); 22 | 23 | 24 | using namespace BazisLib::DDK; 25 | 26 | BazisLib::DDK::DriverObjectFinder::DriverObjectFinder(const wchar_t *pszDriverName, POBJECT_TYPE pDriverObjectType) 27 | : m_pDriver(NULL) 28 | { 29 | String strFullPath = L"\\Driver\\"; 30 | if (wcschr(pszDriverName, '\\')) 31 | strFullPath = L""; 32 | strFullPath += pszDriverName; 33 | NTSTATUS status = ObReferenceObjectByName(strFullPath.ToNTString(), OBJ_CASE_INSENSITIVE, NULL, 0, pDriverObjectType, KernelMode, 0, (PVOID *)&m_pDriver); 34 | if (!NT_SUCCESS(status)) 35 | return; 36 | } 37 | 38 | DeviceEnumerator::DeviceEnumerator(const wchar_t *pszDriverName, POBJECT_TYPE pDriverObjectType) 39 | : DriverObjectFinder(pszDriverName, pDriverObjectType) 40 | , m_ppDevices(NULL) 41 | , m_DeviceObjectCount(0) 42 | { 43 | if (!Valid()) 44 | return; 45 | 46 | ULONG actualCount = 0; 47 | NTSTATUS status = IoEnumerateDeviceObjectList(GetDriverObject(), NULL, 0, &actualCount); 48 | 49 | if (!actualCount) 50 | { 51 | Reset(); 52 | return; 53 | } 54 | 55 | m_DeviceObjectCount = actualCount; 56 | m_ppDevices = new PDEVICE_OBJECT[actualCount]; 57 | 58 | status = IoEnumerateDeviceObjectList(GetDriverObject(), m_ppDevices, actualCount * sizeof(PDEVICE_OBJECT), &actualCount); 59 | 60 | if (!NT_SUCCESS(status)) 61 | { 62 | Reset(); 63 | return; 64 | } 65 | } 66 | 67 | BazisLib::DDK::DeviceEnumerator::~DeviceEnumerator() 68 | { 69 | if (m_ppDevices) 70 | for (size_t i = 0; i < m_DeviceObjectCount; i++) 71 | ObDereferenceObject(m_ppDevices[i]); 72 | 73 | delete m_ppDevices; 74 | } 75 | #endif -------------------------------------------------------------------------------- /examples/WinKernel/SampleInstaller/MainDlg.h: -------------------------------------------------------------------------------- 1 | // MainDlg.h : interface of the CMainDlg class 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #pragma once 6 | #include 7 | #include "ProjectDescription.h" 8 | 9 | class CMainDlg : public CDialogImpl, public CUpdateUI, 10 | public CMessageFilter, public CIdleHandler 11 | { 12 | private: 13 | CComboBox m_ComboBox; 14 | 15 | std::vector m_Projects; 16 | 17 | public: 18 | enum { IDD = IDD_MAINDLG }; 19 | 20 | virtual BOOL PreTranslateMessage(MSG* pMsg); 21 | virtual BOOL OnIdle(); 22 | 23 | BEGIN_UPDATE_UI_MAP(CMainDlg) 24 | END_UPDATE_UI_MAP() 25 | 26 | BEGIN_MSG_MAP(CMainDlg) 27 | MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) 28 | MESSAGE_HANDLER(WM_CLOSE, OnClose) 29 | MESSAGE_HANDLER(WM_DESTROY, OnDestroy) 30 | COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnBnClickedCancel) 31 | COMMAND_HANDLER(IDC_COMBO1, CBN_SELCHANGE, OnCbnSelchangeCombo1) 32 | COMMAND_HANDLER(IDC_BUTTON1, BN_CLICKED, OnBnClickedButton1) 33 | COMMAND_HANDLER(IDC_BUTTON2, BN_CLICKED, OnBnClickedButton2) 34 | END_MSG_MAP() 35 | 36 | // Handler prototypes (uncomment arguments if needed): 37 | // LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) 38 | // LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) 39 | // LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/) 40 | 41 | LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); 42 | LRESULT OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); 43 | LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); 44 | 45 | void CloseDialog(int nVal); 46 | LRESULT OnBnClickedCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 47 | LRESULT OnCbnSelchangeCombo1(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 48 | LRESULT OnBnClickedButton1(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 49 | LRESULT OnBnClickedButton2(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 50 | }; 51 | -------------------------------------------------------------------------------- /bzshlp/Win32/RegistrySerializer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../serializer.h" 3 | #include "../../bzscore/Win32/registry.h" 4 | #include "../../bzscore/status.h" 5 | 6 | namespace BazisLib 7 | { 8 | namespace Win32 9 | { 10 | class RegistrySerializer 11 | { 12 | public: 13 | template static ActionStatus Serialize(Win32::RegistryKey &key, _Structure &value) 14 | { 15 | return value.__SERIALIZER_ITERATE_MEMBERS(Worker(key), true); 16 | } 17 | 18 | template static ActionStatus Deserialize(Win32::RegistryKey &key, _Structure &value, bool ignoreMissingValues = true) 19 | { 20 | return value.__SERIALIZER_ITERATE_MEMBERS(Worker(key, ignoreMissingValues), false); 21 | } 22 | 23 | private: 24 | class Worker 25 | { 26 | RegistryKey &Key; 27 | bool _IgnoreMissingValues; 28 | 29 | public: 30 | Worker(RegistryKey &key, bool ignoreMissingValues = true) 31 | : Key(key) 32 | , _IgnoreMissingValues(ignoreMissingValues) 33 | { 34 | } 35 | 36 | template ActionStatus inline _NestedSerializerHelper(TCHAR *pName, _Ty *pObject, bool save, void *) 37 | { 38 | if (save) 39 | return Key[pName].WriteValue(pObject); 40 | else 41 | { 42 | ActionStatus st = Key[pName].ReadValue(pObject); 43 | if (_IgnoreMissingValues) 44 | return MAKE_STATUS(Success); 45 | return st; 46 | } 47 | } 48 | 49 | template ActionStatus inline _NestedSerializerHelper(TCHAR *pName, _Ty *pObject, bool save, _SerializableStructBase *) 50 | { 51 | RegistryKey subKey(Key[pName], save); 52 | return pObject->__SERIALIZER_ITERATE_MEMBERS(Worker(subKey), save); 53 | } 54 | 55 | template ActionStatus inline _SerializerEntry(TCHAR *pName, _Ty *pObject, bool save) 56 | { 57 | //Will invoke the version with _SerializableStructBase if _Ty is a serializable object itself. 58 | //The last argument is not used by the function and is ALWAYS the same as the second one. 59 | //However, it's used by the compiler to determine which of the _NestedSerializerHelper versions is used. 60 | return _NestedSerializerHelper(pName, pObject, save, pObject); 61 | } 62 | }; 63 | }; 64 | } 65 | } -------------------------------------------------------------------------------- /bzshlp/Win32/i18n.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #if defined(WIN32) && !defined(BZSLIB_WINKERNEL) 3 | #include "i18n.h" 4 | #include "LNGManager.h" 5 | 6 | using namespace BazisLib; 7 | using namespace BazisLib::TranslationSystem; 8 | 9 | extern StringIDRecord g_StringIDs[]; 10 | 11 | static LNGManager *s_pLNGManager = NULL; 12 | 13 | StringTable *BazisLib::TranslationSystem::g_pCurrentLanguageStringTable; 14 | 15 | //Not reentrant 16 | BazisLib::ActionStatus BazisLib::InitializeLNGBasedTranslationEngine(LANGID PreferredLangID, const String &LNGDirectory /*= _T("langfiles")*/ , HMODULE hMainModule) 17 | { 18 | if (s_pLNGManager) 19 | return MAKE_STATUS(InvalidState); 20 | Directory::FindFileParams iter; 21 | if (Path::IsAbsolute(LNGDirectory)) 22 | iter = Directory(LNGDirectory).FindFirstFile(_T("*.lng")); 23 | else 24 | { 25 | TCHAR tsz[MAX_PATH] = { 0, }; 26 | GetModuleFileName(hMainModule, tsz, __countof(tsz)); 27 | iter = Directory(Path::Combine(Path::GetDirectoryName(TempStrPointerWrapper(tsz)), LNGDirectory)).FindFirstFile(_T("*.lng")); 28 | } 29 | 30 | s_pLNGManager = new LNGManager(iter); 31 | SelectLanguage(PreferredLangID ? PreferredLangID : GetUserDefaultLangID()); 32 | return MAKE_STATUS(Success); 33 | } 34 | 35 | //Not reentrant 36 | void BazisLib::ShutdownTranslationEngine() 37 | { 38 | g_pCurrentLanguageStringTable = NULL; 39 | delete s_pLNGManager; 40 | s_pLNGManager = NULL; 41 | } 42 | 43 | //Reentrant due to LNGManager synchronization 44 | BazisLib::ActionStatus BazisLib::SelectLanguage( LANGID LangID ) 45 | { 46 | if (!s_pLNGManager) 47 | return MAKE_STATUS(NotInitialized); 48 | g_pCurrentLanguageStringTable = s_pLNGManager->LoadStringTableForLanguage(LangID, g_StringIDs); 49 | return MAKE_STATUS(Success); 50 | } 51 | 52 | //Reentrant due to LNGManager synchronization 53 | std::vector BazisLib::GetInstalledLanguageList() 54 | { 55 | if (!s_pLNGManager) 56 | return std::vector(); 57 | return s_pLNGManager->GetInstalledLanguageList(); 58 | } 59 | 60 | //Reentrant 61 | LANGID BazisLib::GetCurrentLanguageId() 62 | { 63 | TranslationSystem::StringTable *pTable = TranslationSystem::g_pCurrentLanguageStringTable; 64 | if (!pTable) 65 | return 0; 66 | return pTable->LangID; 67 | } 68 | #endif -------------------------------------------------------------------------------- /bzshlp/Win32/cmdexec.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef UNDER_CE 3 | #include "cmndef.h" 4 | #include "bulkusb.h" 5 | 6 | namespace BazisLib 7 | { 8 | namespace Win32 9 | { 10 | class CCommandExecuteInterface 11 | { 12 | public: 13 | virtual bool Disconnect()=0; 14 | virtual bool SetTimeout(int ms)=0; 15 | 16 | virtual unsigned ExecuteCommand(int CmdCode, 17 | unsigned InputBufferSize, 18 | void *pInputBuffer, 19 | unsigned ResultBufferSize, 20 | void *pResultBuffer)=0; 21 | 22 | virtual bool IsConnected()=0; 23 | virtual ~CCommandExecuteInterface() {} 24 | 25 | unsigned ExecuteCommandWithStatus(int CmdCode, 26 | unsigned InputBufferSize = 0, 27 | void *pInputBuffer = NULL) 28 | { 29 | char status = -1; 30 | if (ExecuteCommand(CmdCode, InputBufferSize, pInputBuffer, 1, &status) != 1) 31 | return -1; 32 | return status; 33 | } 34 | }; 35 | 36 | class CBulkUsbCommandExecuteInterface : public CCommandExecuteInterface 37 | { 38 | private: 39 | CBulkUsbPipe *m_pPipe; 40 | void *m_pTransferBuffer; 41 | unsigned m_MaxTransferBufferSize; 42 | 43 | protected: 44 | bool InitializeDevice(); 45 | 46 | public: 47 | CBulkUsbCommandExecuteInterface(const TCHAR *pszSNMask = NULL); 48 | virtual ~CBulkUsbCommandExecuteInterface(); 49 | bool Disconnect(); 50 | virtual bool SetTimeout(int ms); 51 | 52 | virtual unsigned ExecuteCommand(int CmdCode, 53 | unsigned InputBufferSize, 54 | void *pInputBuffer, 55 | unsigned ResultBufferSize, 56 | void *pResultBuffer); 57 | 58 | virtual bool IsConnected(); 59 | 60 | CBulkUsbPipe *EnterRawMode(); 61 | }; 62 | 63 | class CBulkUsbBootloaderCommandExecuteInterface : public CCommandExecuteInterface 64 | { 65 | private: 66 | CBulkUsbPipe *m_pPipe; 67 | 68 | protected: 69 | bool InitializeDevice(); 70 | 71 | public: 72 | CBulkUsbBootloaderCommandExecuteInterface(const char *pszSNMask = NULL); 73 | virtual ~CBulkUsbBootloaderCommandExecuteInterface(); 74 | bool Disconnect(); 75 | virtual bool SetTimeout(int ms); 76 | 77 | virtual unsigned ExecuteCommand(int CmdCode, 78 | unsigned InputBufferSize, 79 | void *pInputBuffer, 80 | unsigned ResultBufferSize, 81 | void *pResultBuffer); 82 | 83 | virtual bool IsConnected(); 84 | }; 85 | } 86 | } 87 | 88 | #endif -------------------------------------------------------------------------------- /bzshlp/MacOS/CFPluginWrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "IOObject.h" 3 | #include 4 | 5 | namespace BazisLib 6 | { 7 | namespace MacOS 8 | { 9 | class CFPluginWrapper 10 | { 11 | private: 12 | IOCFPlugInInterface **_ppInterface; 13 | 14 | private: 15 | CFPluginWrapper(const CFPluginWrapper &) { } 16 | void operator=(const CFPluginWrapper &) { } 17 | 18 | public: 19 | CFPluginWrapper(const IOObjectWrapper &service, CFUUIDRef pluginType, CFUUIDRef interfaceType = kIOCFPlugInInterfaceID) 20 | : _ppInterface(NULL) 21 | { 22 | SInt32 score; 23 | IOCreatePlugInInterfaceForService(service.get(), pluginType, interfaceType, &_ppInterface, &score); 24 | } 25 | 26 | bool Valid() const 27 | { 28 | return _ppInterface != 0; 29 | } 30 | 31 | ~CFPluginWrapper() 32 | { 33 | if (_ppInterface) 34 | IODestroyPlugInInterface(_ppInterface); 35 | } 36 | 37 | template HRESULT QueryInterface(CFUUIDRef iid, _Iface ***ppv) const 38 | { 39 | if (!_ppInterface) 40 | return E_POINTER; 41 | return (*_ppInterface)->QueryInterface(_ppInterface, CFUUIDGetUUIDBytes(iid), (LPVOID *)ppv); 42 | } 43 | }; 44 | 45 | template class CFInterfaceWrapper 46 | { 47 | private: 48 | _Iface **_pIface; 49 | 50 | public: 51 | _Iface *operator->() 52 | { 53 | return *_pIface; 54 | } 55 | 56 | CFInterfaceWrapper(const CFPluginWrapper &plugin, CFUUIDRef interfaceID) 57 | : _pIface(NULL) 58 | { 59 | if (plugin.Valid()) 60 | plugin.QueryInterface(interfaceID, &_pIface); 61 | } 62 | 63 | bool Valid() {return _pIface != NULL;} 64 | 65 | CFInterfaceWrapper(_Iface **ppIface = NULL) 66 | : _pIface(ppIface) 67 | { 68 | } 69 | 70 | CFInterfaceWrapper(const CFInterfaceWrapper<_Iface> &wrapper) 71 | : _pIface(wrapper._pIface) 72 | { 73 | if (_pIface) 74 | (*_pIface)->AddRef(_pIface); 75 | } 76 | 77 | void operator=(const CFInterfaceWrapper<_Iface> &wrapper) 78 | { 79 | if (_pIface) 80 | (*_pIface)->Release(_pIface); 81 | _pIface = wrapper._pIface; 82 | if (_pIface) 83 | (*_pIface)->AddRef(_pIface); 84 | } 85 | 86 | operator void*(){return _pIface;} 87 | 88 | ~CFInterfaceWrapper() 89 | { 90 | if (_pIface) 91 | (*_pIface)->Release(_pIface); 92 | } 93 | }; 94 | 95 | } 96 | } -------------------------------------------------------------------------------- /bzscore/WinKernel/stlsup.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #ifdef BZSLIB_WINKERNEL 3 | #include "memdbg.h" 4 | #include "kmemory.h" 5 | 6 | using namespace BazisLib; 7 | 8 | void * __cdecl operator new(size_t size) 9 | { 10 | #ifdef BZSLIB_MEMORY_DEBUG_HOOKS 11 | return MemoryDebug::OnMemoryAllocation(ExAllocatePoolWithTag(PagedPool, size + MemoryDebug::MEMORY_DEBUG_SHIFT, 'WENB'), size); 12 | #else 13 | return ExAllocatePoolWithTag(PagedPool, size, 'WENB'); 14 | #endif 15 | } 16 | 17 | 18 | void * __cdecl npagednew(size_t size) 19 | { 20 | #ifdef BZSLIB_MEMORY_DEBUG_HOOKS 21 | return MemoryDebug::OnMemoryAllocation(ExAllocatePoolWithTag(NonPagedPool, size + MemoryDebug::MEMORY_DEBUG_SHIFT, 'LACB'), size); 22 | #else 23 | return ExAllocatePoolWithTag(NonPagedPool, size, 'WENB'); 24 | #endif 25 | } 26 | 27 | void __cdecl operator delete(void *ptr) 28 | { 29 | if (ptr != NULL) 30 | { 31 | #ifdef BZSLIB_MEMORY_DEBUG_HOOKS 32 | ExFreePoolWithTag(MemoryDebug::OnMemoryFree(ptr), 'WENB'); 33 | #else 34 | ExFreePoolWithTag(ptr, 'WENB'); 35 | #endif 36 | } 37 | } 38 | 39 | 40 | /* 41 | If you are getting errors due to a missing puts() or exit() function, please update your STLPort to the latest version from http://bazislib.sysprogs.org/ 42 | 43 | extern "C" int _cdecl puts(const char *p); 44 | int _cdecl puts(const char *p) 45 | { 46 | return 0; 47 | } 48 | 49 | void _cdecl exit(int _Code) 50 | { 51 | KeBugCheck(STATUS_INTERNAL_ERROR); 52 | } 53 | 54 | */ 55 | 56 | 57 | void * _cdecl malloc(size_t size) 58 | { 59 | #ifdef BZSLIB_MEMORY_DEBUG_HOOKS 60 | return MemoryDebug::OnMemoryAllocation(ExAllocatePoolWithTag(PagedPool, size + MemoryDebug::MEMORY_DEBUG_SHIFT, 'LACB'), size); 61 | #else 62 | return ExAllocatePoolWithTag(PagedPool, size, 'LACB'); 63 | #endif 64 | } 65 | 66 | //void * __cdecl realloc(void * _Memory, size_t _Size) 67 | void * __cdecl _realloc(void * _Memory, size_t _Size, size_t _OldSize) 68 | { 69 | if (!_Memory) 70 | return malloc(_Size); 71 | if (!_Size) 72 | { 73 | free(_Memory); 74 | return NULL; 75 | } 76 | void *pMem = malloc(_Size); 77 | if (!pMem) 78 | { 79 | free(_Memory); 80 | return NULL; 81 | } 82 | memcpy(pMem, _Memory, min(_Size, _OldSize)); 83 | free(_Memory); 84 | return pMem; 85 | } 86 | 87 | 88 | void _cdecl free(void *p) 89 | { 90 | #ifdef BZSLIB_MEMORY_DEBUG_HOOKS 91 | ExFreePoolWithTag(MemoryDebug::OnMemoryFree(p), 'LACB'); 92 | #else 93 | ExFreePoolWithTag(p, 'LACB'); 94 | #endif 95 | } 96 | 97 | #endif --------------------------------------------------------------------------------