BSOne.SFC/Tocsg.Module/UsbMon/Bs1FltCtrl.pas

230 lines
7.7 KiB
Plaintext

unit Bs1FltCtrl;
interface
uses
Windows, SysUtils, Classes;
const
PG_PID_ALLOW = 1;
type
enum_devicestate = (
dsEnable = 0,
dsDisable,
dsReadOnly
);
enum_devicetype = (
BDC_UNKNOWN_DEV = 0,
BDC_CDROM,
BDC_FLOOPY,
BDC_USB_DISK,
BDC_LOCAL_DISK,
BDC_NETWORKDRIVEOUT,
BDC_EXTERNALHDD,
BDC_NETWORKDRIVEIN,
BDC_NETWORKSHAREOUT,
BDC_MAX_DEVICE_TYPE
);
// 콜백 함수 타입 정의
TBs1FltCallback = function(Context: Pointer): DWORD; stdcall;
// 함수 포인터 타입 정의 (C++ typedef 대응)
TfpCleanup = function(): DWORD; stdcall;
TfpInit = function(lpcPath: PWideChar; logcb: TBs1FltCallback; opencb: TBs1FltCallback): DWORD; stdcall;
TfpSetPath = function(ulType: DWORD; lpcwPath: PWideChar): DWORD; stdcall;
TfpDelPath = function(ulType: DWORD; lpcwPath: PWideChar): DWORD; stdcall;
TfpSetProcessPath = function(dwType: DWORD; lpcwPath: PWideChar): DWORD; stdcall;
TfpSetFileName = function(dwType: DWORD; lpcwPath: PWideChar): DWORD; stdcall;
TfpBegin = function(bIsBegin: DWORD): DWORD; stdcall;
TfpSetPid = function(dwType: DWORD; dwPid: DWORD): DWORD; stdcall;
TfpDelPid = function(dwPid: DWORD): DWORD; stdcall;
TfpFolderProtectControl = function(bIsProtect: DWORD): DWORD; stdcall;
TfpStartShareWatch = function(bIsWatch: DWORD): DWORD; stdcall;
TfpDebug = function(flag: ULONG): DWORD; stdcall;
TfpDeleteFile = function(path: PWideChar): DWORD; stdcall;
TfpTerminateProcess = function(pid: DWORD): DWORD; stdcall;
TfpDelProcessPath = function(dwType: DWORD; lpcwPath: PWideChar): DWORD; stdcall;
TfpSetUsbHook = function(enable: BOOL): DWORD; stdcall;
TfpSetPolicy = function(device_type: DWORD; state: DWORD; islog: DWORD): DWORD; stdcall;
TfpProcessProtect = function(enable: DWORD): DWORD; stdcall;
TfpSetProcessProtectName = function(name: PWideChar): DWORD; stdcall;
TfpDelProcessProtectName = function(name: PWideChar): DWORD; stdcall;
TfpSetProcessProtectId = function(pid: DWORD): DWORD; stdcall;
TfpDelProcessProtectId = function(pid: DWORD): DWORD; stdcall;
TfpSetRegProtect = function(enable: DWORD): DWORD; stdcall;
TfpSetRegProtectName = function(regkey: PWideChar): DWORD; stdcall;
TfpDelRegProtectName = function(regkey: PWideChar): DWORD; stdcall;
TfpBs1fltSetDeviceProtect = function(enable: DWORD): DWORD; stdcall;
TfpBs1fltSetUsbException = function(vid: PWideChar; pid: PWideChar; productrevisionlevel: PWideChar; vendorspecific: PWideChar): DWORD; stdcall;
TBs1fltControl = class
private
FHandle: HMODULE;
FCurrentPath: string;
public
// 함수 포인터 멤버 변수
Bs1FltCleanup: TfpCleanup;
Bs1FltInit: TfpInit;
Bs1FltSetPath: TfpSetPath;
Bs1FltDelPath: TfpDelPath;
Bs1FltSetProcessPath: TfpSetProcessPath;
Bs1FltSetFileName: TfpSetFileName;
Bs1FltBegin: TfpBegin;
Bs1FltSetPid: TfpSetPid;
Bs1FltDelPid: TfpDelPid;
Bs1FltFolderProtectControl: TfpFolderProtectControl;
Bs1FltStartShareWatch: TfpStartShareWatch;
Bs1FltDebug: TfpDebug;
Bs1FltDeleteFile: TfpDeleteFile;
Bs1FltTerminateProcess: TfpTerminateProcess;
Bs1FltDelProcessPath: TfpDelProcessPath;
Bs1FltSetUsbHook: TfpSetUsbHook;
Bs1FltSetPolicy: TfpSetPolicy;
Bs1FltProcessProtect: TfpProcessProtect;
Bs1FltSetProcessProtectName: TfpSetProcessProtectName;
Bs1FltDelProcessProtectName: TfpDelProcessProtectName;
Bs1FltSetProcessProtectId: TfpSetProcessProtectId;
Bs1FltDelProcessProtectId: TfpDelProcessProtectId;
Bs1FltSetRegProtect: TfpSetRegProtect;
Bs1FltSetRegProtectName: TfpSetRegProtectName;
Bs1FltDelRegProtectName: TfpDelRegProtectName;
Bs1fltSetDeviceProtect: TfpBs1fltSetDeviceProtect;
Bs1fltSetUsbException: TfpBs1fltSetUsbException;
constructor Create;
destructor Destroy; override;
// 초기화 함수
function Init(const Path: string; LogCallback: TBs1FltCallback): DWORD;
end;
implementation
{ TBs1fltControl }
constructor TBs1fltControl.Create;
begin
FHandle := 0;
FCurrentPath := '';
end;
destructor TBs1fltControl.Destroy;
begin
if FHandle <> 0 then
begin
FreeLibrary(FHandle);
FHandle := 0;
end;
inherited;
end;
function TBs1fltControl.Init(const Path: string; LogCallback: TBs1FltCallback): DWORD;
var
DllPath: string;
FuncPtrs: array[0..26] of Pointer;
I: Integer;
begin
Result := 0;
FCurrentPath := Path;
if (Length(Path) > 0) and (Path[Length(Path)] <> '\') then
DllPath := Path + '\bs1fltctrl.dll'
else
DllPath := Path + 'bs1fltctrl.dll';
FHandle := LoadLibraryW(PWideChar(DllPath));
if FHandle = 0 then
begin
Result := 1;
Exit;
end;
Bs1FltCleanup := GetProcAddress(FHandle, PAnsiChar(1));
Bs1FltInit := GetProcAddress(FHandle, PAnsiChar(2));
Bs1FltSetPath := GetProcAddress(FHandle, PAnsiChar(3));
Bs1FltDelPath := GetProcAddress(FHandle, PAnsiChar(4));
Bs1FltBegin := GetProcAddress(FHandle, PAnsiChar(5));
Bs1FltSetPid := GetProcAddress(FHandle, PAnsiChar(6));
Bs1FltDelPid := GetProcAddress(FHandle, PAnsiChar(7));
Bs1FltDebug := GetProcAddress(FHandle, PAnsiChar(8));
Bs1FltSetProcessPath := GetProcAddress(FHandle, PAnsiChar(9));
Bs1FltDelProcessPath := GetProcAddress(FHandle, PAnsiChar(10));
Bs1FltFolderProtectControl := GetProcAddress(FHandle, PAnsiChar(11));
Bs1FltStartShareWatch := GetProcAddress(FHandle, PAnsiChar(12));
Bs1FltSetFileName := GetProcAddress(FHandle, PAnsiChar(13));
Bs1FltDeleteFile := GetProcAddress(FHandle, PAnsiChar(14));
Bs1FltTerminateProcess := GetProcAddress(FHandle, PAnsiChar(15));
Bs1FltSetUsbHook := GetProcAddress(FHandle, PAnsiChar(16));
Bs1FltSetPolicy := GetProcAddress(FHandle, PAnsiChar(17));
Bs1FltProcessProtect := GetProcAddress(FHandle, PAnsiChar(18));
Bs1FltSetProcessProtectName := GetProcAddress(FHandle, PAnsiChar(19));
Bs1FltDelProcessProtectName := GetProcAddress(FHandle, PAnsiChar(20));
Bs1FltSetProcessProtectId := GetProcAddress(FHandle, PAnsiChar(21));
Bs1FltDelProcessProtectId := GetProcAddress(FHandle, PAnsiChar(22));
Bs1FltSetRegProtect := GetProcAddress(FHandle, PAnsiChar(23));
Bs1FltSetRegProtectName := GetProcAddress(FHandle, PAnsiChar(24));
Bs1FltDelRegProtectName := GetProcAddress(FHandle, PAnsiChar(25));
Bs1fltSetDeviceProtect := GetProcAddress(FHandle, PAnsiChar(26));
Bs1fltSetUsbException := GetProcAddress(FHandle, PAnsiChar(27));
FuncPtrs[0] := @Bs1FltCleanup;
FuncPtrs[1] := @Bs1FltInit;
FuncPtrs[2] := @Bs1FltSetPath;
FuncPtrs[3] := @Bs1FltDelPath;
FuncPtrs[4] := @Bs1FltBegin;
FuncPtrs[5] := @Bs1FltSetPid;
FuncPtrs[6] := @Bs1FltDelPid;
FuncPtrs[7] := @Bs1FltDebug;
FuncPtrs[8] := @Bs1FltSetProcessPath;
FuncPtrs[9] := @Bs1FltDelProcessPath;
FuncPtrs[10] := @Bs1FltFolderProtectControl;
FuncPtrs[11] := @Bs1FltStartShareWatch;
FuncPtrs[12] := @Bs1FltSetFileName;
FuncPtrs[13] := @Bs1FltDeleteFile;
FuncPtrs[14] := @Bs1FltTerminateProcess;
FuncPtrs[15] := @Bs1FltSetUsbHook;
FuncPtrs[16] := @Bs1FltSetPolicy;
FuncPtrs[17] := @Bs1FltProcessProtect;
FuncPtrs[18] := @Bs1FltSetProcessProtectName;
FuncPtrs[19] := @Bs1FltDelProcessProtectName;
FuncPtrs[20] := @Bs1FltSetProcessProtectId;
FuncPtrs[21] := @Bs1FltDelProcessProtectId;
FuncPtrs[22] := @Bs1FltSetRegProtect;
FuncPtrs[23] := @Bs1FltSetRegProtectName;
FuncPtrs[24] := @Bs1FltDelRegProtectName;
FuncPtrs[25] := @Bs1fltSetDeviceProtect;
FuncPtrs[26] := @Bs1fltSetUsbException;
// 함수 포인터가 하나라도 NULL이면 실패 처리
for I := 0 to 26 do
begin
if not Assigned(PPointer(FuncPtrs[I])^) then
begin
Result := 2;
Exit;
end;
end;
Result := Bs1FltInit(PWideChar(Path), @LogCallback, nil);
if Result = 0 then // Init 성공 시
begin
Result := Bs1FltSetPid(PG_PID_ALLOW, GetCurrentProcessId());
end;
end;
end.