ホーム › System.ApplicationInstallationAndServicing › NormalizeFileForPatchSignature
NormalizeFileForPatchSignature
関数パッチ署名計算のためにファイルを正規化する。
シグネチャ
// mspatcha.dll
#include <windows.h>
INT NormalizeFileForPatchSignature(
void* FileBuffer,
DWORD FileSize,
DWORD OptionFlags,
PATCH_OPTION_DATA* OptionData, // optional
DWORD NewFileCoffBase,
DWORD NewFileCoffTime,
DWORD IgnoreRangeCount,
PATCH_IGNORE_RANGE* IgnoreRangeArray, // optional
DWORD RetainRangeCount,
PATCH_RETAIN_RANGE* RetainRangeArray // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| FileBuffer | void* | inout | 正規化対象のファイルデータを格納したバッファ。内容が書き換えられる。 |
| FileSize | DWORD | in | FileBuffer のサイズ。バイト数で指定する。 |
| OptionFlags | DWORD | in | 正規化動作を制御するフラグ。PATCH_OPTION_* を指定する。 |
| OptionData | PATCH_OPTION_DATA* | inoptional | 詳細オプションを指定する PATCH_OPTION_DATA 構造体へのポインタ。NULL 可。 |
| NewFileCoffBase | DWORD | in | 正規化に用いる COFF イメージのベースアドレス値。PE 再配置の基準とする。 |
| NewFileCoffTime | DWORD | in | 正規化に用いる COFF タイムスタンプ値。PE ヘッダー比較の基準とする。 |
| IgnoreRangeCount | DWORD | in | IgnoreRangeArray の要素数。正規化で無視する範囲の個数。 |
| IgnoreRangeArray | PATCH_IGNORE_RANGE* | inoptional | 正規化時に無視するバイト範囲の配列(PATCH_IGNORE_RANGE)。NULL 可。 |
| RetainRangeCount | DWORD | in | RetainRangeArray の要素数。保持する範囲の個数。 |
| RetainRangeArray | PATCH_RETAIN_RANGE* | inoptional | 正規化時に保持するバイト範囲の配列(PATCH_RETAIN_RANGE)。NULL 可。 |
戻り値の型: INT
各言語での呼び出し定義
// mspatcha.dll
#include <windows.h>
INT NormalizeFileForPatchSignature(
void* FileBuffer,
DWORD FileSize,
DWORD OptionFlags,
PATCH_OPTION_DATA* OptionData, // optional
DWORD NewFileCoffBase,
DWORD NewFileCoffTime,
DWORD IgnoreRangeCount,
PATCH_IGNORE_RANGE* IgnoreRangeArray, // optional
DWORD RetainRangeCount,
PATCH_RETAIN_RANGE* RetainRangeArray // optional
);[DllImport("mspatcha.dll", ExactSpelling = true)]
static extern int NormalizeFileForPatchSignature(
IntPtr FileBuffer, // void* in/out
uint FileSize, // DWORD
uint OptionFlags, // DWORD
IntPtr OptionData, // PATCH_OPTION_DATA* optional
uint NewFileCoffBase, // DWORD
uint NewFileCoffTime, // DWORD
uint IgnoreRangeCount, // DWORD
IntPtr IgnoreRangeArray, // PATCH_IGNORE_RANGE* optional
uint RetainRangeCount, // DWORD
IntPtr RetainRangeArray // PATCH_RETAIN_RANGE* optional
);<DllImport("mspatcha.dll", ExactSpelling:=True)>
Public Shared Function NormalizeFileForPatchSignature(
FileBuffer As IntPtr, ' void* in/out
FileSize As UInteger, ' DWORD
OptionFlags As UInteger, ' DWORD
OptionData As IntPtr, ' PATCH_OPTION_DATA* optional
NewFileCoffBase As UInteger, ' DWORD
NewFileCoffTime As UInteger, ' DWORD
IgnoreRangeCount As UInteger, ' DWORD
IgnoreRangeArray As IntPtr, ' PATCH_IGNORE_RANGE* optional
RetainRangeCount As UInteger, ' DWORD
RetainRangeArray As IntPtr ' PATCH_RETAIN_RANGE* optional
) As Integer
End Function' FileBuffer : void* in/out
' FileSize : DWORD
' OptionFlags : DWORD
' OptionData : PATCH_OPTION_DATA* optional
' NewFileCoffBase : DWORD
' NewFileCoffTime : DWORD
' IgnoreRangeCount : DWORD
' IgnoreRangeArray : PATCH_IGNORE_RANGE* optional
' RetainRangeCount : DWORD
' RetainRangeArray : PATCH_RETAIN_RANGE* optional
Declare PtrSafe Function NormalizeFileForPatchSignature Lib "mspatcha" ( _
ByVal FileBuffer As LongPtr, _
ByVal FileSize As Long, _
ByVal OptionFlags As Long, _
ByVal OptionData As LongPtr, _
ByVal NewFileCoffBase As Long, _
ByVal NewFileCoffTime As Long, _
ByVal IgnoreRangeCount As Long, _
ByVal IgnoreRangeArray As LongPtr, _
ByVal RetainRangeCount As Long, _
ByVal RetainRangeArray As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
NormalizeFileForPatchSignature = ctypes.windll.mspatcha.NormalizeFileForPatchSignature
NormalizeFileForPatchSignature.restype = ctypes.c_int
NormalizeFileForPatchSignature.argtypes = [
ctypes.POINTER(None), # FileBuffer : void* in/out
wintypes.DWORD, # FileSize : DWORD
wintypes.DWORD, # OptionFlags : DWORD
ctypes.c_void_p, # OptionData : PATCH_OPTION_DATA* optional
wintypes.DWORD, # NewFileCoffBase : DWORD
wintypes.DWORD, # NewFileCoffTime : DWORD
wintypes.DWORD, # IgnoreRangeCount : DWORD
ctypes.c_void_p, # IgnoreRangeArray : PATCH_IGNORE_RANGE* optional
wintypes.DWORD, # RetainRangeCount : DWORD
ctypes.c_void_p, # RetainRangeArray : PATCH_RETAIN_RANGE* optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('mspatcha.dll')
NormalizeFileForPatchSignature = Fiddle::Function.new(
lib['NormalizeFileForPatchSignature'],
[
Fiddle::TYPE_VOIDP, # FileBuffer : void* in/out
-Fiddle::TYPE_INT, # FileSize : DWORD
-Fiddle::TYPE_INT, # OptionFlags : DWORD
Fiddle::TYPE_VOIDP, # OptionData : PATCH_OPTION_DATA* optional
-Fiddle::TYPE_INT, # NewFileCoffBase : DWORD
-Fiddle::TYPE_INT, # NewFileCoffTime : DWORD
-Fiddle::TYPE_INT, # IgnoreRangeCount : DWORD
Fiddle::TYPE_VOIDP, # IgnoreRangeArray : PATCH_IGNORE_RANGE* optional
-Fiddle::TYPE_INT, # RetainRangeCount : DWORD
Fiddle::TYPE_VOIDP, # RetainRangeArray : PATCH_RETAIN_RANGE* optional
],
Fiddle::TYPE_INT)#[link(name = "mspatcha")]
extern "system" {
fn NormalizeFileForPatchSignature(
FileBuffer: *mut (), // void* in/out
FileSize: u32, // DWORD
OptionFlags: u32, // DWORD
OptionData: *mut PATCH_OPTION_DATA, // PATCH_OPTION_DATA* optional
NewFileCoffBase: u32, // DWORD
NewFileCoffTime: u32, // DWORD
IgnoreRangeCount: u32, // DWORD
IgnoreRangeArray: *mut PATCH_IGNORE_RANGE, // PATCH_IGNORE_RANGE* optional
RetainRangeCount: u32, // DWORD
RetainRangeArray: *mut PATCH_RETAIN_RANGE // PATCH_RETAIN_RANGE* optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("mspatcha.dll")]
public static extern int NormalizeFileForPatchSignature(IntPtr FileBuffer, uint FileSize, uint OptionFlags, IntPtr OptionData, uint NewFileCoffBase, uint NewFileCoffTime, uint IgnoreRangeCount, IntPtr IgnoreRangeArray, uint RetainRangeCount, IntPtr RetainRangeArray);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mspatcha_NormalizeFileForPatchSignature' -Namespace Win32 -PassThru
# $api::NormalizeFileForPatchSignature(FileBuffer, FileSize, OptionFlags, OptionData, NewFileCoffBase, NewFileCoffTime, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray)#uselib "mspatcha.dll"
#func global NormalizeFileForPatchSignature "NormalizeFileForPatchSignature" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; NormalizeFileForPatchSignature FileBuffer, FileSize, OptionFlags, varptr(OptionData), NewFileCoffBase, NewFileCoffTime, IgnoreRangeCount, varptr(IgnoreRangeArray), RetainRangeCount, varptr(RetainRangeArray) ; 戻り値は stat
; FileBuffer : void* in/out -> "sptr"
; FileSize : DWORD -> "sptr"
; OptionFlags : DWORD -> "sptr"
; OptionData : PATCH_OPTION_DATA* optional -> "sptr"
; NewFileCoffBase : DWORD -> "sptr"
; NewFileCoffTime : DWORD -> "sptr"
; IgnoreRangeCount : DWORD -> "sptr"
; IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> "sptr"
; RetainRangeCount : DWORD -> "sptr"
; RetainRangeArray : PATCH_RETAIN_RANGE* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "mspatcha.dll" #cfunc global NormalizeFileForPatchSignature "NormalizeFileForPatchSignature" sptr, int, int, var, int, int, int, var, int, var ; res = NormalizeFileForPatchSignature(FileBuffer, FileSize, OptionFlags, OptionData, NewFileCoffBase, NewFileCoffTime, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray) ; FileBuffer : void* in/out -> "sptr" ; FileSize : DWORD -> "int" ; OptionFlags : DWORD -> "int" ; OptionData : PATCH_OPTION_DATA* optional -> "var" ; NewFileCoffBase : DWORD -> "int" ; NewFileCoffTime : DWORD -> "int" ; IgnoreRangeCount : DWORD -> "int" ; IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> "var" ; RetainRangeCount : DWORD -> "int" ; RetainRangeArray : PATCH_RETAIN_RANGE* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "mspatcha.dll" #cfunc global NormalizeFileForPatchSignature "NormalizeFileForPatchSignature" sptr, int, int, sptr, int, int, int, sptr, int, sptr ; res = NormalizeFileForPatchSignature(FileBuffer, FileSize, OptionFlags, varptr(OptionData), NewFileCoffBase, NewFileCoffTime, IgnoreRangeCount, varptr(IgnoreRangeArray), RetainRangeCount, varptr(RetainRangeArray)) ; FileBuffer : void* in/out -> "sptr" ; FileSize : DWORD -> "int" ; OptionFlags : DWORD -> "int" ; OptionData : PATCH_OPTION_DATA* optional -> "sptr" ; NewFileCoffBase : DWORD -> "int" ; NewFileCoffTime : DWORD -> "int" ; IgnoreRangeCount : DWORD -> "int" ; IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> "sptr" ; RetainRangeCount : DWORD -> "int" ; RetainRangeArray : PATCH_RETAIN_RANGE* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT NormalizeFileForPatchSignature(void* FileBuffer, DWORD FileSize, DWORD OptionFlags, PATCH_OPTION_DATA* OptionData, DWORD NewFileCoffBase, DWORD NewFileCoffTime, DWORD IgnoreRangeCount, PATCH_IGNORE_RANGE* IgnoreRangeArray, DWORD RetainRangeCount, PATCH_RETAIN_RANGE* RetainRangeArray) #uselib "mspatcha.dll" #cfunc global NormalizeFileForPatchSignature "NormalizeFileForPatchSignature" intptr, int, int, var, int, int, int, var, int, var ; res = NormalizeFileForPatchSignature(FileBuffer, FileSize, OptionFlags, OptionData, NewFileCoffBase, NewFileCoffTime, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray) ; FileBuffer : void* in/out -> "intptr" ; FileSize : DWORD -> "int" ; OptionFlags : DWORD -> "int" ; OptionData : PATCH_OPTION_DATA* optional -> "var" ; NewFileCoffBase : DWORD -> "int" ; NewFileCoffTime : DWORD -> "int" ; IgnoreRangeCount : DWORD -> "int" ; IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> "var" ; RetainRangeCount : DWORD -> "int" ; RetainRangeArray : PATCH_RETAIN_RANGE* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT NormalizeFileForPatchSignature(void* FileBuffer, DWORD FileSize, DWORD OptionFlags, PATCH_OPTION_DATA* OptionData, DWORD NewFileCoffBase, DWORD NewFileCoffTime, DWORD IgnoreRangeCount, PATCH_IGNORE_RANGE* IgnoreRangeArray, DWORD RetainRangeCount, PATCH_RETAIN_RANGE* RetainRangeArray) #uselib "mspatcha.dll" #cfunc global NormalizeFileForPatchSignature "NormalizeFileForPatchSignature" intptr, int, int, intptr, int, int, int, intptr, int, intptr ; res = NormalizeFileForPatchSignature(FileBuffer, FileSize, OptionFlags, varptr(OptionData), NewFileCoffBase, NewFileCoffTime, IgnoreRangeCount, varptr(IgnoreRangeArray), RetainRangeCount, varptr(RetainRangeArray)) ; FileBuffer : void* in/out -> "intptr" ; FileSize : DWORD -> "int" ; OptionFlags : DWORD -> "int" ; OptionData : PATCH_OPTION_DATA* optional -> "intptr" ; NewFileCoffBase : DWORD -> "int" ; NewFileCoffTime : DWORD -> "int" ; IgnoreRangeCount : DWORD -> "int" ; IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> "intptr" ; RetainRangeCount : DWORD -> "int" ; RetainRangeArray : PATCH_RETAIN_RANGE* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mspatcha = windows.NewLazySystemDLL("mspatcha.dll")
procNormalizeFileForPatchSignature = mspatcha.NewProc("NormalizeFileForPatchSignature")
)
// FileBuffer (void* in/out), FileSize (DWORD), OptionFlags (DWORD), OptionData (PATCH_OPTION_DATA* optional), NewFileCoffBase (DWORD), NewFileCoffTime (DWORD), IgnoreRangeCount (DWORD), IgnoreRangeArray (PATCH_IGNORE_RANGE* optional), RetainRangeCount (DWORD), RetainRangeArray (PATCH_RETAIN_RANGE* optional)
r1, _, err := procNormalizeFileForPatchSignature.Call(
uintptr(FileBuffer),
uintptr(FileSize),
uintptr(OptionFlags),
uintptr(OptionData),
uintptr(NewFileCoffBase),
uintptr(NewFileCoffTime),
uintptr(IgnoreRangeCount),
uintptr(IgnoreRangeArray),
uintptr(RetainRangeCount),
uintptr(RetainRangeArray),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction NormalizeFileForPatchSignature(
FileBuffer: Pointer; // void* in/out
FileSize: DWORD; // DWORD
OptionFlags: DWORD; // DWORD
OptionData: Pointer; // PATCH_OPTION_DATA* optional
NewFileCoffBase: DWORD; // DWORD
NewFileCoffTime: DWORD; // DWORD
IgnoreRangeCount: DWORD; // DWORD
IgnoreRangeArray: Pointer; // PATCH_IGNORE_RANGE* optional
RetainRangeCount: DWORD; // DWORD
RetainRangeArray: Pointer // PATCH_RETAIN_RANGE* optional
): Integer; stdcall;
external 'mspatcha.dll' name 'NormalizeFileForPatchSignature';result := DllCall("mspatcha\NormalizeFileForPatchSignature"
, "Ptr", FileBuffer ; void* in/out
, "UInt", FileSize ; DWORD
, "UInt", OptionFlags ; DWORD
, "Ptr", OptionData ; PATCH_OPTION_DATA* optional
, "UInt", NewFileCoffBase ; DWORD
, "UInt", NewFileCoffTime ; DWORD
, "UInt", IgnoreRangeCount ; DWORD
, "Ptr", IgnoreRangeArray ; PATCH_IGNORE_RANGE* optional
, "UInt", RetainRangeCount ; DWORD
, "Ptr", RetainRangeArray ; PATCH_RETAIN_RANGE* optional
, "Int") ; return: INT●NormalizeFileForPatchSignature(FileBuffer, FileSize, OptionFlags, OptionData, NewFileCoffBase, NewFileCoffTime, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray) = DLL("mspatcha.dll", "int NormalizeFileForPatchSignature(void*, dword, dword, void*, dword, dword, dword, void*, dword, void*)")
# 呼び出し: NormalizeFileForPatchSignature(FileBuffer, FileSize, OptionFlags, OptionData, NewFileCoffBase, NewFileCoffTime, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray)
# FileBuffer : void* in/out -> "void*"
# FileSize : DWORD -> "dword"
# OptionFlags : DWORD -> "dword"
# OptionData : PATCH_OPTION_DATA* optional -> "void*"
# NewFileCoffBase : DWORD -> "dword"
# NewFileCoffTime : DWORD -> "dword"
# IgnoreRangeCount : DWORD -> "dword"
# IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> "void*"
# RetainRangeCount : DWORD -> "dword"
# RetainRangeArray : PATCH_RETAIN_RANGE* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mspatcha" fn NormalizeFileForPatchSignature(
FileBuffer: ?*anyopaque, // void* in/out
FileSize: u32, // DWORD
OptionFlags: u32, // DWORD
OptionData: [*c]PATCH_OPTION_DATA, // PATCH_OPTION_DATA* optional
NewFileCoffBase: u32, // DWORD
NewFileCoffTime: u32, // DWORD
IgnoreRangeCount: u32, // DWORD
IgnoreRangeArray: [*c]PATCH_IGNORE_RANGE, // PATCH_IGNORE_RANGE* optional
RetainRangeCount: u32, // DWORD
RetainRangeArray: [*c]PATCH_RETAIN_RANGE // PATCH_RETAIN_RANGE* optional
) callconv(std.os.windows.WINAPI) i32;proc NormalizeFileForPatchSignature(
FileBuffer: pointer, # void* in/out
FileSize: uint32, # DWORD
OptionFlags: uint32, # DWORD
OptionData: ptr PATCH_OPTION_DATA, # PATCH_OPTION_DATA* optional
NewFileCoffBase: uint32, # DWORD
NewFileCoffTime: uint32, # DWORD
IgnoreRangeCount: uint32, # DWORD
IgnoreRangeArray: ptr PATCH_IGNORE_RANGE, # PATCH_IGNORE_RANGE* optional
RetainRangeCount: uint32, # DWORD
RetainRangeArray: ptr PATCH_RETAIN_RANGE # PATCH_RETAIN_RANGE* optional
): int32 {.importc: "NormalizeFileForPatchSignature", stdcall, dynlib: "mspatcha.dll".}pragma(lib, "mspatcha");
extern(Windows)
int NormalizeFileForPatchSignature(
void* FileBuffer, // void* in/out
uint FileSize, // DWORD
uint OptionFlags, // DWORD
PATCH_OPTION_DATA* OptionData, // PATCH_OPTION_DATA* optional
uint NewFileCoffBase, // DWORD
uint NewFileCoffTime, // DWORD
uint IgnoreRangeCount, // DWORD
PATCH_IGNORE_RANGE* IgnoreRangeArray, // PATCH_IGNORE_RANGE* optional
uint RetainRangeCount, // DWORD
PATCH_RETAIN_RANGE* RetainRangeArray // PATCH_RETAIN_RANGE* optional
);ccall((:NormalizeFileForPatchSignature, "mspatcha.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, UInt32, Ptr{PATCH_OPTION_DATA}, UInt32, UInt32, UInt32, Ptr{PATCH_IGNORE_RANGE}, UInt32, Ptr{PATCH_RETAIN_RANGE}),
FileBuffer, FileSize, OptionFlags, OptionData, NewFileCoffBase, NewFileCoffTime, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray)
# FileBuffer : void* in/out -> Ptr{Cvoid}
# FileSize : DWORD -> UInt32
# OptionFlags : DWORD -> UInt32
# OptionData : PATCH_OPTION_DATA* optional -> Ptr{PATCH_OPTION_DATA}
# NewFileCoffBase : DWORD -> UInt32
# NewFileCoffTime : DWORD -> UInt32
# IgnoreRangeCount : DWORD -> UInt32
# IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> Ptr{PATCH_IGNORE_RANGE}
# RetainRangeCount : DWORD -> UInt32
# RetainRangeArray : PATCH_RETAIN_RANGE* optional -> Ptr{PATCH_RETAIN_RANGE}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t NormalizeFileForPatchSignature(
void* FileBuffer,
uint32_t FileSize,
uint32_t OptionFlags,
void* OptionData,
uint32_t NewFileCoffBase,
uint32_t NewFileCoffTime,
uint32_t IgnoreRangeCount,
void* IgnoreRangeArray,
uint32_t RetainRangeCount,
void* RetainRangeArray);
]]
local mspatcha = ffi.load("mspatcha")
-- mspatcha.NormalizeFileForPatchSignature(FileBuffer, FileSize, OptionFlags, OptionData, NewFileCoffBase, NewFileCoffTime, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray)
-- FileBuffer : void* in/out
-- FileSize : DWORD
-- OptionFlags : DWORD
-- OptionData : PATCH_OPTION_DATA* optional
-- NewFileCoffBase : DWORD
-- NewFileCoffTime : DWORD
-- IgnoreRangeCount : DWORD
-- IgnoreRangeArray : PATCH_IGNORE_RANGE* optional
-- RetainRangeCount : DWORD
-- RetainRangeArray : PATCH_RETAIN_RANGE* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('mspatcha.dll');
const NormalizeFileForPatchSignature = lib.func('__stdcall', 'NormalizeFileForPatchSignature', 'int32_t', ['void *', 'uint32_t', 'uint32_t', 'void *', 'uint32_t', 'uint32_t', 'uint32_t', 'void *', 'uint32_t', 'void *']);
// NormalizeFileForPatchSignature(FileBuffer, FileSize, OptionFlags, OptionData, NewFileCoffBase, NewFileCoffTime, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray)
// FileBuffer : void* in/out -> 'void *'
// FileSize : DWORD -> 'uint32_t'
// OptionFlags : DWORD -> 'uint32_t'
// OptionData : PATCH_OPTION_DATA* optional -> 'void *'
// NewFileCoffBase : DWORD -> 'uint32_t'
// NewFileCoffTime : DWORD -> 'uint32_t'
// IgnoreRangeCount : DWORD -> 'uint32_t'
// IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> 'void *'
// RetainRangeCount : DWORD -> 'uint32_t'
// RetainRangeArray : PATCH_RETAIN_RANGE* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("mspatcha.dll", {
NormalizeFileForPatchSignature: { parameters: ["pointer", "u32", "u32", "pointer", "u32", "u32", "u32", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.NormalizeFileForPatchSignature(FileBuffer, FileSize, OptionFlags, OptionData, NewFileCoffBase, NewFileCoffTime, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray)
// FileBuffer : void* in/out -> "pointer"
// FileSize : DWORD -> "u32"
// OptionFlags : DWORD -> "u32"
// OptionData : PATCH_OPTION_DATA* optional -> "pointer"
// NewFileCoffBase : DWORD -> "u32"
// NewFileCoffTime : DWORD -> "u32"
// IgnoreRangeCount : DWORD -> "u32"
// IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> "pointer"
// RetainRangeCount : DWORD -> "u32"
// RetainRangeArray : PATCH_RETAIN_RANGE* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t NormalizeFileForPatchSignature(
void* FileBuffer,
uint32_t FileSize,
uint32_t OptionFlags,
void* OptionData,
uint32_t NewFileCoffBase,
uint32_t NewFileCoffTime,
uint32_t IgnoreRangeCount,
void* IgnoreRangeArray,
uint32_t RetainRangeCount,
void* RetainRangeArray);
C, "mspatcha.dll");
// $ffi->NormalizeFileForPatchSignature(FileBuffer, FileSize, OptionFlags, OptionData, NewFileCoffBase, NewFileCoffTime, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray);
// FileBuffer : void* in/out
// FileSize : DWORD
// OptionFlags : DWORD
// OptionData : PATCH_OPTION_DATA* optional
// NewFileCoffBase : DWORD
// NewFileCoffTime : DWORD
// IgnoreRangeCount : DWORD
// IgnoreRangeArray : PATCH_IGNORE_RANGE* optional
// RetainRangeCount : DWORD
// RetainRangeArray : PATCH_RETAIN_RANGE* optional
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Mspatcha extends StdCallLibrary {
Mspatcha INSTANCE = Native.load("mspatcha", Mspatcha.class);
int NormalizeFileForPatchSignature(
Pointer FileBuffer, // void* in/out
int FileSize, // DWORD
int OptionFlags, // DWORD
Pointer OptionData, // PATCH_OPTION_DATA* optional
int NewFileCoffBase, // DWORD
int NewFileCoffTime, // DWORD
int IgnoreRangeCount, // DWORD
Pointer IgnoreRangeArray, // PATCH_IGNORE_RANGE* optional
int RetainRangeCount, // DWORD
Pointer RetainRangeArray // PATCH_RETAIN_RANGE* optional
);
}@[Link("mspatcha")]
lib Libmspatcha
fun NormalizeFileForPatchSignature = NormalizeFileForPatchSignature(
FileBuffer : Void*, # void* in/out
FileSize : UInt32, # DWORD
OptionFlags : UInt32, # DWORD
OptionData : PATCH_OPTION_DATA*, # PATCH_OPTION_DATA* optional
NewFileCoffBase : UInt32, # DWORD
NewFileCoffTime : UInt32, # DWORD
IgnoreRangeCount : UInt32, # DWORD
IgnoreRangeArray : PATCH_IGNORE_RANGE*, # PATCH_IGNORE_RANGE* optional
RetainRangeCount : UInt32, # DWORD
RetainRangeArray : PATCH_RETAIN_RANGE* # PATCH_RETAIN_RANGE* optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef NormalizeFileForPatchSignatureNative = Int32 Function(Pointer<Void>, Uint32, Uint32, Pointer<Void>, Uint32, Uint32, Uint32, Pointer<Void>, Uint32, Pointer<Void>);
typedef NormalizeFileForPatchSignatureDart = int Function(Pointer<Void>, int, int, Pointer<Void>, int, int, int, Pointer<Void>, int, Pointer<Void>);
final NormalizeFileForPatchSignature = DynamicLibrary.open('mspatcha.dll')
.lookupFunction<NormalizeFileForPatchSignatureNative, NormalizeFileForPatchSignatureDart>('NormalizeFileForPatchSignature');
// FileBuffer : void* in/out -> Pointer<Void>
// FileSize : DWORD -> Uint32
// OptionFlags : DWORD -> Uint32
// OptionData : PATCH_OPTION_DATA* optional -> Pointer<Void>
// NewFileCoffBase : DWORD -> Uint32
// NewFileCoffTime : DWORD -> Uint32
// IgnoreRangeCount : DWORD -> Uint32
// IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> Pointer<Void>
// RetainRangeCount : DWORD -> Uint32
// RetainRangeArray : PATCH_RETAIN_RANGE* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function NormalizeFileForPatchSignature(
FileBuffer: Pointer; // void* in/out
FileSize: DWORD; // DWORD
OptionFlags: DWORD; // DWORD
OptionData: Pointer; // PATCH_OPTION_DATA* optional
NewFileCoffBase: DWORD; // DWORD
NewFileCoffTime: DWORD; // DWORD
IgnoreRangeCount: DWORD; // DWORD
IgnoreRangeArray: Pointer; // PATCH_IGNORE_RANGE* optional
RetainRangeCount: DWORD; // DWORD
RetainRangeArray: Pointer // PATCH_RETAIN_RANGE* optional
): Integer; stdcall;
external 'mspatcha.dll' name 'NormalizeFileForPatchSignature';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "NormalizeFileForPatchSignature"
c_NormalizeFileForPatchSignature :: Ptr () -> Word32 -> Word32 -> Ptr () -> Word32 -> Word32 -> Word32 -> Ptr () -> Word32 -> Ptr () -> IO Int32
-- FileBuffer : void* in/out -> Ptr ()
-- FileSize : DWORD -> Word32
-- OptionFlags : DWORD -> Word32
-- OptionData : PATCH_OPTION_DATA* optional -> Ptr ()
-- NewFileCoffBase : DWORD -> Word32
-- NewFileCoffTime : DWORD -> Word32
-- IgnoreRangeCount : DWORD -> Word32
-- IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> Ptr ()
-- RetainRangeCount : DWORD -> Word32
-- RetainRangeArray : PATCH_RETAIN_RANGE* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let normalizefileforpatchsignature =
foreign "NormalizeFileForPatchSignature"
((ptr void) @-> uint32_t @-> uint32_t @-> (ptr void) @-> uint32_t @-> uint32_t @-> uint32_t @-> (ptr void) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* FileBuffer : void* in/out -> (ptr void) *)
(* FileSize : DWORD -> uint32_t *)
(* OptionFlags : DWORD -> uint32_t *)
(* OptionData : PATCH_OPTION_DATA* optional -> (ptr void) *)
(* NewFileCoffBase : DWORD -> uint32_t *)
(* NewFileCoffTime : DWORD -> uint32_t *)
(* IgnoreRangeCount : DWORD -> uint32_t *)
(* IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> (ptr void) *)
(* RetainRangeCount : DWORD -> uint32_t *)
(* RetainRangeArray : PATCH_RETAIN_RANGE* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library mspatcha (t "mspatcha.dll"))
(cffi:use-foreign-library mspatcha)
(cffi:defcfun ("NormalizeFileForPatchSignature" normalize-file-for-patch-signature :convention :stdcall) :int32
(file-buffer :pointer) ; void* in/out
(file-size :uint32) ; DWORD
(option-flags :uint32) ; DWORD
(option-data :pointer) ; PATCH_OPTION_DATA* optional
(new-file-coff-base :uint32) ; DWORD
(new-file-coff-time :uint32) ; DWORD
(ignore-range-count :uint32) ; DWORD
(ignore-range-array :pointer) ; PATCH_IGNORE_RANGE* optional
(retain-range-count :uint32) ; DWORD
(retain-range-array :pointer)) ; PATCH_RETAIN_RANGE* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $NormalizeFileForPatchSignature = Win32::API::More->new('mspatcha',
'int NormalizeFileForPatchSignature(LPVOID FileBuffer, DWORD FileSize, DWORD OptionFlags, LPVOID OptionData, DWORD NewFileCoffBase, DWORD NewFileCoffTime, DWORD IgnoreRangeCount, LPVOID IgnoreRangeArray, DWORD RetainRangeCount, LPVOID RetainRangeArray)');
# my $ret = $NormalizeFileForPatchSignature->Call($FileBuffer, $FileSize, $OptionFlags, $OptionData, $NewFileCoffBase, $NewFileCoffTime, $IgnoreRangeCount, $IgnoreRangeArray, $RetainRangeCount, $RetainRangeArray);
# FileBuffer : void* in/out -> LPVOID
# FileSize : DWORD -> DWORD
# OptionFlags : DWORD -> DWORD
# OptionData : PATCH_OPTION_DATA* optional -> LPVOID
# NewFileCoffBase : DWORD -> DWORD
# NewFileCoffTime : DWORD -> DWORD
# IgnoreRangeCount : DWORD -> DWORD
# IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> LPVOID
# RetainRangeCount : DWORD -> DWORD
# RetainRangeArray : PATCH_RETAIN_RANGE* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。