ユーザーが任意のディレクトリのファイルを削除したときに、必要な API 関数をフックして、メッセージボックスで単純なブール値の質問をすることでインターセプトしReally Would you like to Delete this file?
たいと考えています。ファイルを削除するか、削除を防止するために、ファイルを制御します。
私のOSはWindows 8 x64
.
この SO の質問では、名前付きの WinAPI 関数とインターフェイスが存在することを確認した方法で、NtSetFileInformation
関数Intercept FIleSytemCall for Deletionをフックすることが最善の選択であると読みましたが、これらの違いはわかりませんが、とにかく、これを始める方法が本当にわかりません...DeleteFile
ICopyHook
私は VBNET ソリューションを探していることを明確にしたいと思います。Google を介したこれらの API フック ライブラリからの VBNET コードの例がなく、複雑なコードが関与。
編集:私のニーズにぴったりと思われるEasyHook
ライブラリの例を見つけましたが、それは C# コードであり、成功せずに翻訳しようとしました: EasyHook を使用して ntdll.dll から NtCreateFile API をフックする (c#)NtSetFileInformation
だから、私はDeviare
ライブラリ2.6でこれを試しましたが、何もしません:
Public Class Form1
Private _mgr As Deviare2.NktSpyMgr = Nothing
Private WithEvents _hook As Deviare2.NktHook = Nothing
Private _proc As Deviare2.INktProcess = Nothing
Private Shadows Sub Shown() Handles MyBase.Shown
_mgr = New Deviare2.NktSpyMgr()
_hook = _mgr.CreateHook("ntdll.dll!NtSetFileInformation", Nothing)
_hook.Hook()
End Sub
Private Sub OnFunctionCalled(ByVal proc As Deviare2.INktProcess,
ByVal callInfo As Deviare2.INktHookCallInfo,
ByVal rCall As Deviare.IRemoteCall) Handles _hook.OnFunctionCalled
MsgBox("Caught function call in " & proc.Name)
End Sub
End Class
基本的に、上記のコードは、vb.net で別のプログラムの winapi 関数への呼び出しをフック@mazoula
するここで回答されたものと同じです。命令で例外。_hook.Attach(_mgr.Processes)
また、ライブラリでこれを試しましたEasyHook
が、Explorer.exe または CMD からファイルを削除しても何もしません。コードはこの C# コードの翻訳ですhttp://www.codeproject.com/Questions/528094/DeleteFileplushookingpluswithplusEasyHookplussucce :
Imports System.Runtime.InteropServices
Imports EasyHook
Public Class Form1
<DllImport("kernel32.dll", CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.StdCall)>
Private Shared Function DeleteFile(filename As String) As Integer
End Function
<UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet:=CharSet.Unicode)>
Private Delegate Function DeleteFileHandler(filename As String) As Integer
Private Shared deleted As Boolean = False
public Function DeleteFileHookInstance(filename As String) As Integer
MsgBox("works?")
If deleted Then
deleted = False
Return 1
End If
If MessageBox.Show((Convert.ToString("Do you really want to delete file ") & filename) + "?", "Confirm delete file", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
deleted = True
Return DeleteFile(filename)
Else
Return 1
End If
'Assume the call is successfull
End Function
Public Sub Run()
Dim hook As EasyHook.LocalHook
Try
MsgBox("Creating...")
hook = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "DeleteFileW"), New DeleteFileHandler(AddressOf DeleteFileHookInstance), Me)
'It stops here, the main interface receives the reported status 'Creating...' seemly forever, I understand that is for the unexpected restarting of explorer.exe
MsgBox("Completing...")
hook.ThreadACL.SetExclusiveACL(New Integer() {0})
RemoteHooking.WakeUpProcess()
MsgBox("OK")
Catch ex As Exception
MsgBox("CreateHook failed: " + ex.Message)
System.Diagnostics.Process.GetCurrentProcess().Kill()
End Try
While True
Application.DoEvents()
End While
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Run()
End Sub
End Class