Win32 API 日本語リファレンス
ホームSystem.Antimalware › AmsiNotifyOperation

AmsiNotifyOperation

関数
操作内容をAMSIへ通知し脅威判定を受ける。
DLLAmsi.dll呼出規約winapi

シグネチャ

// Amsi.dll
#include <windows.h>

HRESULT AmsiNotifyOperation(
    HAMSICONTEXT amsiContext,
    void* buffer,
    DWORD length,
    LPCWSTR contentName,   // optional
    AMSI_RESULT* result
);

パラメーター

名前方向
amsiContextHAMSICONTEXTin
buffervoid*in
lengthDWORDin
contentNameLPCWSTRinoptional
resultAMSI_RESULT*out

戻り値の型: HRESULT

各言語での呼び出し定義

// Amsi.dll
#include <windows.h>

HRESULT AmsiNotifyOperation(
    HAMSICONTEXT amsiContext,
    void* buffer,
    DWORD length,
    LPCWSTR contentName,   // optional
    AMSI_RESULT* result
);
[DllImport("Amsi.dll", ExactSpelling = true)]
static extern int AmsiNotifyOperation(
    IntPtr amsiContext,   // HAMSICONTEXT
    IntPtr buffer,   // void*
    uint length,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string contentName,   // LPCWSTR optional
    out int result   // AMSI_RESULT* out
);
<DllImport("Amsi.dll", ExactSpelling:=True)>
Public Shared Function AmsiNotifyOperation(
    amsiContext As IntPtr,   ' HAMSICONTEXT
    buffer As IntPtr,   ' void*
    length As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> contentName As String,   ' LPCWSTR optional
    <Out> ByRef result As Integer   ' AMSI_RESULT* out
) As Integer
End Function
' amsiContext : HAMSICONTEXT
' buffer : void*
' length : DWORD
' contentName : LPCWSTR optional
' result : AMSI_RESULT* out
Declare PtrSafe Function AmsiNotifyOperation Lib "amsi" ( _
    ByVal amsiContext As LongPtr, _
    ByVal buffer As LongPtr, _
    ByVal length As Long, _
    ByVal contentName As LongPtr, _
    ByRef result As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

AmsiNotifyOperation = ctypes.windll.amsi.AmsiNotifyOperation
AmsiNotifyOperation.restype = ctypes.c_int
AmsiNotifyOperation.argtypes = [
    wintypes.HANDLE,  # amsiContext : HAMSICONTEXT
    ctypes.POINTER(None),  # buffer : void*
    wintypes.DWORD,  # length : DWORD
    wintypes.LPCWSTR,  # contentName : LPCWSTR optional
    ctypes.c_void_p,  # result : AMSI_RESULT* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('Amsi.dll')
AmsiNotifyOperation = Fiddle::Function.new(
  lib['AmsiNotifyOperation'],
  [
    Fiddle::TYPE_VOIDP,  # amsiContext : HAMSICONTEXT
    Fiddle::TYPE_VOIDP,  # buffer : void*
    -Fiddle::TYPE_INT,  # length : DWORD
    Fiddle::TYPE_VOIDP,  # contentName : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # result : AMSI_RESULT* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "amsi")]
extern "system" {
    fn AmsiNotifyOperation(
        amsiContext: *mut core::ffi::c_void,  // HAMSICONTEXT
        buffer: *mut (),  // void*
        length: u32,  // DWORD
        contentName: *const u16,  // LPCWSTR optional
        result: *mut i32  // AMSI_RESULT* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("Amsi.dll")]
public static extern int AmsiNotifyOperation(IntPtr amsiContext, IntPtr buffer, uint length, [MarshalAs(UnmanagedType.LPWStr)] string contentName, out int result);
"@
$api = Add-Type -MemberDefinition $sig -Name 'Amsi_AmsiNotifyOperation' -Namespace Win32 -PassThru
# $api::AmsiNotifyOperation(amsiContext, buffer, length, contentName, result)
#uselib "Amsi.dll"
#func global AmsiNotifyOperation "AmsiNotifyOperation" sptr, sptr, sptr, sptr, sptr
; AmsiNotifyOperation amsiContext, buffer, length, contentName, result   ; 戻り値は stat
; amsiContext : HAMSICONTEXT -> "sptr"
; buffer : void* -> "sptr"
; length : DWORD -> "sptr"
; contentName : LPCWSTR optional -> "sptr"
; result : AMSI_RESULT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "Amsi.dll"
#cfunc global AmsiNotifyOperation "AmsiNotifyOperation" sptr, sptr, int, wstr, int
; res = AmsiNotifyOperation(amsiContext, buffer, length, contentName, result)
; amsiContext : HAMSICONTEXT -> "sptr"
; buffer : void* -> "sptr"
; length : DWORD -> "int"
; contentName : LPCWSTR optional -> "wstr"
; result : AMSI_RESULT* out -> "int"
; HRESULT AmsiNotifyOperation(HAMSICONTEXT amsiContext, void* buffer, DWORD length, LPCWSTR contentName, AMSI_RESULT* result)
#uselib "Amsi.dll"
#cfunc global AmsiNotifyOperation "AmsiNotifyOperation" intptr, intptr, int, wstr, int
; res = AmsiNotifyOperation(amsiContext, buffer, length, contentName, result)
; amsiContext : HAMSICONTEXT -> "intptr"
; buffer : void* -> "intptr"
; length : DWORD -> "int"
; contentName : LPCWSTR optional -> "wstr"
; result : AMSI_RESULT* out -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	amsi = windows.NewLazySystemDLL("Amsi.dll")
	procAmsiNotifyOperation = amsi.NewProc("AmsiNotifyOperation")
)

// amsiContext (HAMSICONTEXT), buffer (void*), length (DWORD), contentName (LPCWSTR optional), result (AMSI_RESULT* out)
r1, _, err := procAmsiNotifyOperation.Call(
	uintptr(amsiContext),
	uintptr(buffer),
	uintptr(length),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(contentName))),
	uintptr(result),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function AmsiNotifyOperation(
  amsiContext: THandle;   // HAMSICONTEXT
  buffer: Pointer;   // void*
  length: DWORD;   // DWORD
  contentName: PWideChar;   // LPCWSTR optional
  result: Pointer   // AMSI_RESULT* out
): Integer; stdcall;
  external 'Amsi.dll' name 'AmsiNotifyOperation';
result := DllCall("Amsi\AmsiNotifyOperation"
    , "Ptr", amsiContext   ; HAMSICONTEXT
    , "Ptr", buffer   ; void*
    , "UInt", length   ; DWORD
    , "WStr", contentName   ; LPCWSTR optional
    , "Ptr", result   ; AMSI_RESULT* out
    , "Int")   ; return: HRESULT
●AmsiNotifyOperation(amsiContext, buffer, length, contentName, result) = DLL("Amsi.dll", "int AmsiNotifyOperation(void*, void*, dword, char*, void*)")
# 呼び出し: AmsiNotifyOperation(amsiContext, buffer, length, contentName, result)
# amsiContext : HAMSICONTEXT -> "void*"
# buffer : void* -> "void*"
# length : DWORD -> "dword"
# contentName : LPCWSTR optional -> "char*"
# result : AMSI_RESULT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。