ホーム › System.ApplicationInstallationAndServicing › ApplyPatchToFileByBuffers
ApplyPatchToFileByBuffers
関数メモリバッファ上で旧ファイルにパッチを適用し新ファイルを生成する。
シグネチャ
// mspatcha.dll
#include <windows.h>
BOOL ApplyPatchToFileByBuffers(
BYTE* PatchFileMapped,
DWORD PatchFileSize,
BYTE* OldFileMapped, // optional
DWORD OldFileSize,
BYTE** NewFileBuffer,
DWORD NewFileBufferSize,
DWORD* NewFileActualSize, // optional
FILETIME* NewFileTime, // optional
DWORD ApplyOptionFlags,
PPATCH_PROGRESS_CALLBACK ProgressCallback, // optional
void* CallbackContext // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| PatchFileMapped | BYTE* | in | メモリマップされたパッチデータへのポインタ。読み取り専用で参照される。 |
| PatchFileSize | DWORD | in | PatchFileMapped のサイズ。バイト数で指定する。 |
| OldFileMapped | BYTE* | inoptional | メモリマップされた旧ファイルデータへのポインタ。読み取り専用で参照される。 |
| OldFileSize | DWORD | in | OldFileMapped のサイズ。バイト数で指定する。 |
| NewFileBuffer | BYTE** | inout | 新ファイルを格納するバッファへのポインタを受け取る出力。API 側で割り当てた場合は DeltaFree 等で解放する。 |
| NewFileBufferSize | DWORD | in | 呼び出し側が事前確保した出力バッファのサイズ。バイト数で指定する。 |
| NewFileActualSize | DWORD* | outoptional | 生成された新ファイルの実サイズを受け取る出力ポインタ。 |
| NewFileTime | FILETIME* | outoptional | 新ファイルに設定するタイムスタンプを受け取る FILETIME ポインタ。NULL 可。 |
| ApplyOptionFlags | DWORD | in | 適用動作を制御するフラグ。APPLY_OPTION_* の組み合わせを指定する。 |
| ProgressCallback | PPATCH_PROGRESS_CALLBACK | inoptional | 進捗を通知するコールバック関数。不要なら NULL を指定する。 |
| CallbackContext | void* | inoptional | コールバックへ渡されるユーザー定義のコンテキストポインタ。NULL 可。 |
戻り値の型: BOOL
各言語での呼び出し定義
// mspatcha.dll
#include <windows.h>
BOOL ApplyPatchToFileByBuffers(
BYTE* PatchFileMapped,
DWORD PatchFileSize,
BYTE* OldFileMapped, // optional
DWORD OldFileSize,
BYTE** NewFileBuffer,
DWORD NewFileBufferSize,
DWORD* NewFileActualSize, // optional
FILETIME* NewFileTime, // optional
DWORD ApplyOptionFlags,
PPATCH_PROGRESS_CALLBACK ProgressCallback, // optional
void* CallbackContext // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mspatcha.dll", ExactSpelling = true)]
static extern bool ApplyPatchToFileByBuffers(
IntPtr PatchFileMapped, // BYTE*
uint PatchFileSize, // DWORD
IntPtr OldFileMapped, // BYTE* optional
uint OldFileSize, // DWORD
IntPtr NewFileBuffer, // BYTE** in/out
uint NewFileBufferSize, // DWORD
IntPtr NewFileActualSize, // DWORD* optional, out
IntPtr NewFileTime, // FILETIME* optional, out
uint ApplyOptionFlags, // DWORD
IntPtr ProgressCallback, // PPATCH_PROGRESS_CALLBACK optional
IntPtr CallbackContext // void* optional
);<DllImport("mspatcha.dll", ExactSpelling:=True)>
Public Shared Function ApplyPatchToFileByBuffers(
PatchFileMapped As IntPtr, ' BYTE*
PatchFileSize As UInteger, ' DWORD
OldFileMapped As IntPtr, ' BYTE* optional
OldFileSize As UInteger, ' DWORD
NewFileBuffer As IntPtr, ' BYTE** in/out
NewFileBufferSize As UInteger, ' DWORD
NewFileActualSize As IntPtr, ' DWORD* optional, out
NewFileTime As IntPtr, ' FILETIME* optional, out
ApplyOptionFlags As UInteger, ' DWORD
ProgressCallback As IntPtr, ' PPATCH_PROGRESS_CALLBACK optional
CallbackContext As IntPtr ' void* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' PatchFileMapped : BYTE*
' PatchFileSize : DWORD
' OldFileMapped : BYTE* optional
' OldFileSize : DWORD
' NewFileBuffer : BYTE** in/out
' NewFileBufferSize : DWORD
' NewFileActualSize : DWORD* optional, out
' NewFileTime : FILETIME* optional, out
' ApplyOptionFlags : DWORD
' ProgressCallback : PPATCH_PROGRESS_CALLBACK optional
' CallbackContext : void* optional
Declare PtrSafe Function ApplyPatchToFileByBuffers Lib "mspatcha" ( _
ByVal PatchFileMapped As LongPtr, _
ByVal PatchFileSize As Long, _
ByVal OldFileMapped As LongPtr, _
ByVal OldFileSize As Long, _
ByVal NewFileBuffer As LongPtr, _
ByVal NewFileBufferSize As Long, _
ByVal NewFileActualSize As LongPtr, _
ByVal NewFileTime As LongPtr, _
ByVal ApplyOptionFlags As Long, _
ByVal ProgressCallback As LongPtr, _
ByVal CallbackContext As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ApplyPatchToFileByBuffers = ctypes.windll.mspatcha.ApplyPatchToFileByBuffers
ApplyPatchToFileByBuffers.restype = wintypes.BOOL
ApplyPatchToFileByBuffers.argtypes = [
ctypes.POINTER(ctypes.c_ubyte), # PatchFileMapped : BYTE*
wintypes.DWORD, # PatchFileSize : DWORD
ctypes.POINTER(ctypes.c_ubyte), # OldFileMapped : BYTE* optional
wintypes.DWORD, # OldFileSize : DWORD
ctypes.c_void_p, # NewFileBuffer : BYTE** in/out
wintypes.DWORD, # NewFileBufferSize : DWORD
ctypes.POINTER(wintypes.DWORD), # NewFileActualSize : DWORD* optional, out
ctypes.c_void_p, # NewFileTime : FILETIME* optional, out
wintypes.DWORD, # ApplyOptionFlags : DWORD
ctypes.c_void_p, # ProgressCallback : PPATCH_PROGRESS_CALLBACK optional
ctypes.POINTER(None), # CallbackContext : void* optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('mspatcha.dll')
ApplyPatchToFileByBuffers = Fiddle::Function.new(
lib['ApplyPatchToFileByBuffers'],
[
Fiddle::TYPE_VOIDP, # PatchFileMapped : BYTE*
-Fiddle::TYPE_INT, # PatchFileSize : DWORD
Fiddle::TYPE_VOIDP, # OldFileMapped : BYTE* optional
-Fiddle::TYPE_INT, # OldFileSize : DWORD
Fiddle::TYPE_VOIDP, # NewFileBuffer : BYTE** in/out
-Fiddle::TYPE_INT, # NewFileBufferSize : DWORD
Fiddle::TYPE_VOIDP, # NewFileActualSize : DWORD* optional, out
Fiddle::TYPE_VOIDP, # NewFileTime : FILETIME* optional, out
-Fiddle::TYPE_INT, # ApplyOptionFlags : DWORD
Fiddle::TYPE_VOIDP, # ProgressCallback : PPATCH_PROGRESS_CALLBACK optional
Fiddle::TYPE_VOIDP, # CallbackContext : void* optional
],
Fiddle::TYPE_INT)#[link(name = "mspatcha")]
extern "system" {
fn ApplyPatchToFileByBuffers(
PatchFileMapped: *mut u8, // BYTE*
PatchFileSize: u32, // DWORD
OldFileMapped: *mut u8, // BYTE* optional
OldFileSize: u32, // DWORD
NewFileBuffer: *mut *mut u8, // BYTE** in/out
NewFileBufferSize: u32, // DWORD
NewFileActualSize: *mut u32, // DWORD* optional, out
NewFileTime: *mut FILETIME, // FILETIME* optional, out
ApplyOptionFlags: u32, // DWORD
ProgressCallback: *const core::ffi::c_void, // PPATCH_PROGRESS_CALLBACK optional
CallbackContext: *mut () // void* optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mspatcha.dll")]
public static extern bool ApplyPatchToFileByBuffers(IntPtr PatchFileMapped, uint PatchFileSize, IntPtr OldFileMapped, uint OldFileSize, IntPtr NewFileBuffer, uint NewFileBufferSize, IntPtr NewFileActualSize, IntPtr NewFileTime, uint ApplyOptionFlags, IntPtr ProgressCallback, IntPtr CallbackContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mspatcha_ApplyPatchToFileByBuffers' -Namespace Win32 -PassThru
# $api::ApplyPatchToFileByBuffers(PatchFileMapped, PatchFileSize, OldFileMapped, OldFileSize, NewFileBuffer, NewFileBufferSize, NewFileActualSize, NewFileTime, ApplyOptionFlags, ProgressCallback, CallbackContext)#uselib "mspatcha.dll"
#func global ApplyPatchToFileByBuffers "ApplyPatchToFileByBuffers" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; ApplyPatchToFileByBuffers varptr(PatchFileMapped), PatchFileSize, varptr(OldFileMapped), OldFileSize, varptr(NewFileBuffer), NewFileBufferSize, varptr(NewFileActualSize), varptr(NewFileTime), ApplyOptionFlags, ProgressCallback, CallbackContext ; 戻り値は stat
; PatchFileMapped : BYTE* -> "sptr"
; PatchFileSize : DWORD -> "sptr"
; OldFileMapped : BYTE* optional -> "sptr"
; OldFileSize : DWORD -> "sptr"
; NewFileBuffer : BYTE** in/out -> "sptr"
; NewFileBufferSize : DWORD -> "sptr"
; NewFileActualSize : DWORD* optional, out -> "sptr"
; NewFileTime : FILETIME* optional, out -> "sptr"
; ApplyOptionFlags : DWORD -> "sptr"
; ProgressCallback : PPATCH_PROGRESS_CALLBACK optional -> "sptr"
; CallbackContext : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "mspatcha.dll" #cfunc global ApplyPatchToFileByBuffers "ApplyPatchToFileByBuffers" var, int, var, int, var, int, var, var, int, sptr, sptr ; res = ApplyPatchToFileByBuffers(PatchFileMapped, PatchFileSize, OldFileMapped, OldFileSize, NewFileBuffer, NewFileBufferSize, NewFileActualSize, NewFileTime, ApplyOptionFlags, ProgressCallback, CallbackContext) ; PatchFileMapped : BYTE* -> "var" ; PatchFileSize : DWORD -> "int" ; OldFileMapped : BYTE* optional -> "var" ; OldFileSize : DWORD -> "int" ; NewFileBuffer : BYTE** in/out -> "var" ; NewFileBufferSize : DWORD -> "int" ; NewFileActualSize : DWORD* optional, out -> "var" ; NewFileTime : FILETIME* optional, out -> "var" ; ApplyOptionFlags : DWORD -> "int" ; ProgressCallback : PPATCH_PROGRESS_CALLBACK optional -> "sptr" ; CallbackContext : void* optional -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "mspatcha.dll" #cfunc global ApplyPatchToFileByBuffers "ApplyPatchToFileByBuffers" sptr, int, sptr, int, sptr, int, sptr, sptr, int, sptr, sptr ; res = ApplyPatchToFileByBuffers(varptr(PatchFileMapped), PatchFileSize, varptr(OldFileMapped), OldFileSize, varptr(NewFileBuffer), NewFileBufferSize, varptr(NewFileActualSize), varptr(NewFileTime), ApplyOptionFlags, ProgressCallback, CallbackContext) ; PatchFileMapped : BYTE* -> "sptr" ; PatchFileSize : DWORD -> "int" ; OldFileMapped : BYTE* optional -> "sptr" ; OldFileSize : DWORD -> "int" ; NewFileBuffer : BYTE** in/out -> "sptr" ; NewFileBufferSize : DWORD -> "int" ; NewFileActualSize : DWORD* optional, out -> "sptr" ; NewFileTime : FILETIME* optional, out -> "sptr" ; ApplyOptionFlags : DWORD -> "int" ; ProgressCallback : PPATCH_PROGRESS_CALLBACK optional -> "sptr" ; CallbackContext : void* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL ApplyPatchToFileByBuffers(BYTE* PatchFileMapped, DWORD PatchFileSize, BYTE* OldFileMapped, DWORD OldFileSize, BYTE** NewFileBuffer, DWORD NewFileBufferSize, DWORD* NewFileActualSize, FILETIME* NewFileTime, DWORD ApplyOptionFlags, PPATCH_PROGRESS_CALLBACK ProgressCallback, void* CallbackContext) #uselib "mspatcha.dll" #cfunc global ApplyPatchToFileByBuffers "ApplyPatchToFileByBuffers" var, int, var, int, var, int, var, var, int, intptr, intptr ; res = ApplyPatchToFileByBuffers(PatchFileMapped, PatchFileSize, OldFileMapped, OldFileSize, NewFileBuffer, NewFileBufferSize, NewFileActualSize, NewFileTime, ApplyOptionFlags, ProgressCallback, CallbackContext) ; PatchFileMapped : BYTE* -> "var" ; PatchFileSize : DWORD -> "int" ; OldFileMapped : BYTE* optional -> "var" ; OldFileSize : DWORD -> "int" ; NewFileBuffer : BYTE** in/out -> "var" ; NewFileBufferSize : DWORD -> "int" ; NewFileActualSize : DWORD* optional, out -> "var" ; NewFileTime : FILETIME* optional, out -> "var" ; ApplyOptionFlags : DWORD -> "int" ; ProgressCallback : PPATCH_PROGRESS_CALLBACK optional -> "intptr" ; CallbackContext : void* optional -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL ApplyPatchToFileByBuffers(BYTE* PatchFileMapped, DWORD PatchFileSize, BYTE* OldFileMapped, DWORD OldFileSize, BYTE** NewFileBuffer, DWORD NewFileBufferSize, DWORD* NewFileActualSize, FILETIME* NewFileTime, DWORD ApplyOptionFlags, PPATCH_PROGRESS_CALLBACK ProgressCallback, void* CallbackContext) #uselib "mspatcha.dll" #cfunc global ApplyPatchToFileByBuffers "ApplyPatchToFileByBuffers" intptr, int, intptr, int, intptr, int, intptr, intptr, int, intptr, intptr ; res = ApplyPatchToFileByBuffers(varptr(PatchFileMapped), PatchFileSize, varptr(OldFileMapped), OldFileSize, varptr(NewFileBuffer), NewFileBufferSize, varptr(NewFileActualSize), varptr(NewFileTime), ApplyOptionFlags, ProgressCallback, CallbackContext) ; PatchFileMapped : BYTE* -> "intptr" ; PatchFileSize : DWORD -> "int" ; OldFileMapped : BYTE* optional -> "intptr" ; OldFileSize : DWORD -> "int" ; NewFileBuffer : BYTE** in/out -> "intptr" ; NewFileBufferSize : DWORD -> "int" ; NewFileActualSize : DWORD* optional, out -> "intptr" ; NewFileTime : FILETIME* optional, out -> "intptr" ; ApplyOptionFlags : DWORD -> "int" ; ProgressCallback : PPATCH_PROGRESS_CALLBACK optional -> "intptr" ; CallbackContext : void* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mspatcha = windows.NewLazySystemDLL("mspatcha.dll")
procApplyPatchToFileByBuffers = mspatcha.NewProc("ApplyPatchToFileByBuffers")
)
// PatchFileMapped (BYTE*), PatchFileSize (DWORD), OldFileMapped (BYTE* optional), OldFileSize (DWORD), NewFileBuffer (BYTE** in/out), NewFileBufferSize (DWORD), NewFileActualSize (DWORD* optional, out), NewFileTime (FILETIME* optional, out), ApplyOptionFlags (DWORD), ProgressCallback (PPATCH_PROGRESS_CALLBACK optional), CallbackContext (void* optional)
r1, _, err := procApplyPatchToFileByBuffers.Call(
uintptr(PatchFileMapped),
uintptr(PatchFileSize),
uintptr(OldFileMapped),
uintptr(OldFileSize),
uintptr(NewFileBuffer),
uintptr(NewFileBufferSize),
uintptr(NewFileActualSize),
uintptr(NewFileTime),
uintptr(ApplyOptionFlags),
uintptr(ProgressCallback),
uintptr(CallbackContext),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction ApplyPatchToFileByBuffers(
PatchFileMapped: Pointer; // BYTE*
PatchFileSize: DWORD; // DWORD
OldFileMapped: Pointer; // BYTE* optional
OldFileSize: DWORD; // DWORD
NewFileBuffer: Pointer; // BYTE** in/out
NewFileBufferSize: DWORD; // DWORD
NewFileActualSize: Pointer; // DWORD* optional, out
NewFileTime: Pointer; // FILETIME* optional, out
ApplyOptionFlags: DWORD; // DWORD
ProgressCallback: Pointer; // PPATCH_PROGRESS_CALLBACK optional
CallbackContext: Pointer // void* optional
): BOOL; stdcall;
external 'mspatcha.dll' name 'ApplyPatchToFileByBuffers';result := DllCall("mspatcha\ApplyPatchToFileByBuffers"
, "Ptr", PatchFileMapped ; BYTE*
, "UInt", PatchFileSize ; DWORD
, "Ptr", OldFileMapped ; BYTE* optional
, "UInt", OldFileSize ; DWORD
, "Ptr", NewFileBuffer ; BYTE** in/out
, "UInt", NewFileBufferSize ; DWORD
, "Ptr", NewFileActualSize ; DWORD* optional, out
, "Ptr", NewFileTime ; FILETIME* optional, out
, "UInt", ApplyOptionFlags ; DWORD
, "Ptr", ProgressCallback ; PPATCH_PROGRESS_CALLBACK optional
, "Ptr", CallbackContext ; void* optional
, "Int") ; return: BOOL●ApplyPatchToFileByBuffers(PatchFileMapped, PatchFileSize, OldFileMapped, OldFileSize, NewFileBuffer, NewFileBufferSize, NewFileActualSize, NewFileTime, ApplyOptionFlags, ProgressCallback, CallbackContext) = DLL("mspatcha.dll", "bool ApplyPatchToFileByBuffers(void*, dword, void*, dword, void*, dword, void*, void*, dword, void*, void*)")
# 呼び出し: ApplyPatchToFileByBuffers(PatchFileMapped, PatchFileSize, OldFileMapped, OldFileSize, NewFileBuffer, NewFileBufferSize, NewFileActualSize, NewFileTime, ApplyOptionFlags, ProgressCallback, CallbackContext)
# PatchFileMapped : BYTE* -> "void*"
# PatchFileSize : DWORD -> "dword"
# OldFileMapped : BYTE* optional -> "void*"
# OldFileSize : DWORD -> "dword"
# NewFileBuffer : BYTE** in/out -> "void*"
# NewFileBufferSize : DWORD -> "dword"
# NewFileActualSize : DWORD* optional, out -> "void*"
# NewFileTime : FILETIME* optional, out -> "void*"
# ApplyOptionFlags : DWORD -> "dword"
# ProgressCallback : PPATCH_PROGRESS_CALLBACK optional -> "void*"
# CallbackContext : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mspatcha" fn ApplyPatchToFileByBuffers(
PatchFileMapped: [*c]u8, // BYTE*
PatchFileSize: u32, // DWORD
OldFileMapped: [*c]u8, // BYTE* optional
OldFileSize: u32, // DWORD
NewFileBuffer: [*c][*c]u8, // BYTE** in/out
NewFileBufferSize: u32, // DWORD
NewFileActualSize: [*c]u32, // DWORD* optional, out
NewFileTime: [*c]FILETIME, // FILETIME* optional, out
ApplyOptionFlags: u32, // DWORD
ProgressCallback: ?*anyopaque, // PPATCH_PROGRESS_CALLBACK optional
CallbackContext: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;proc ApplyPatchToFileByBuffers(
PatchFileMapped: ptr uint8, # BYTE*
PatchFileSize: uint32, # DWORD
OldFileMapped: ptr uint8, # BYTE* optional
OldFileSize: uint32, # DWORD
NewFileBuffer: ptr uint8, # BYTE** in/out
NewFileBufferSize: uint32, # DWORD
NewFileActualSize: ptr uint32, # DWORD* optional, out
NewFileTime: ptr FILETIME, # FILETIME* optional, out
ApplyOptionFlags: uint32, # DWORD
ProgressCallback: pointer, # PPATCH_PROGRESS_CALLBACK optional
CallbackContext: pointer # void* optional
): int32 {.importc: "ApplyPatchToFileByBuffers", stdcall, dynlib: "mspatcha.dll".}pragma(lib, "mspatcha");
extern(Windows)
int ApplyPatchToFileByBuffers(
ubyte* PatchFileMapped, // BYTE*
uint PatchFileSize, // DWORD
ubyte* OldFileMapped, // BYTE* optional
uint OldFileSize, // DWORD
ubyte** NewFileBuffer, // BYTE** in/out
uint NewFileBufferSize, // DWORD
uint* NewFileActualSize, // DWORD* optional, out
FILETIME* NewFileTime, // FILETIME* optional, out
uint ApplyOptionFlags, // DWORD
void* ProgressCallback, // PPATCH_PROGRESS_CALLBACK optional
void* CallbackContext // void* optional
);ccall((:ApplyPatchToFileByBuffers, "mspatcha.dll"), stdcall, Int32,
(Ptr{UInt8}, UInt32, Ptr{UInt8}, UInt32, Ptr{UInt8}, UInt32, Ptr{UInt32}, Ptr{FILETIME}, UInt32, Ptr{Cvoid}, Ptr{Cvoid}),
PatchFileMapped, PatchFileSize, OldFileMapped, OldFileSize, NewFileBuffer, NewFileBufferSize, NewFileActualSize, NewFileTime, ApplyOptionFlags, ProgressCallback, CallbackContext)
# PatchFileMapped : BYTE* -> Ptr{UInt8}
# PatchFileSize : DWORD -> UInt32
# OldFileMapped : BYTE* optional -> Ptr{UInt8}
# OldFileSize : DWORD -> UInt32
# NewFileBuffer : BYTE** in/out -> Ptr{UInt8}
# NewFileBufferSize : DWORD -> UInt32
# NewFileActualSize : DWORD* optional, out -> Ptr{UInt32}
# NewFileTime : FILETIME* optional, out -> Ptr{FILETIME}
# ApplyOptionFlags : DWORD -> UInt32
# ProgressCallback : PPATCH_PROGRESS_CALLBACK optional -> Ptr{Cvoid}
# CallbackContext : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t ApplyPatchToFileByBuffers(
uint8_t* PatchFileMapped,
uint32_t PatchFileSize,
uint8_t* OldFileMapped,
uint32_t OldFileSize,
uint8_t** NewFileBuffer,
uint32_t NewFileBufferSize,
uint32_t* NewFileActualSize,
void* NewFileTime,
uint32_t ApplyOptionFlags,
void* ProgressCallback,
void* CallbackContext);
]]
local mspatcha = ffi.load("mspatcha")
-- mspatcha.ApplyPatchToFileByBuffers(PatchFileMapped, PatchFileSize, OldFileMapped, OldFileSize, NewFileBuffer, NewFileBufferSize, NewFileActualSize, NewFileTime, ApplyOptionFlags, ProgressCallback, CallbackContext)
-- PatchFileMapped : BYTE*
-- PatchFileSize : DWORD
-- OldFileMapped : BYTE* optional
-- OldFileSize : DWORD
-- NewFileBuffer : BYTE** in/out
-- NewFileBufferSize : DWORD
-- NewFileActualSize : DWORD* optional, out
-- NewFileTime : FILETIME* optional, out
-- ApplyOptionFlags : DWORD
-- ProgressCallback : PPATCH_PROGRESS_CALLBACK optional
-- CallbackContext : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('mspatcha.dll');
const ApplyPatchToFileByBuffers = lib.func('__stdcall', 'ApplyPatchToFileByBuffers', 'int32_t', ['uint8_t *', 'uint32_t', 'uint8_t *', 'uint32_t', 'uint8_t *', 'uint32_t', 'uint32_t *', 'void *', 'uint32_t', 'void *', 'void *']);
// ApplyPatchToFileByBuffers(PatchFileMapped, PatchFileSize, OldFileMapped, OldFileSize, NewFileBuffer, NewFileBufferSize, NewFileActualSize, NewFileTime, ApplyOptionFlags, ProgressCallback, CallbackContext)
// PatchFileMapped : BYTE* -> 'uint8_t *'
// PatchFileSize : DWORD -> 'uint32_t'
// OldFileMapped : BYTE* optional -> 'uint8_t *'
// OldFileSize : DWORD -> 'uint32_t'
// NewFileBuffer : BYTE** in/out -> 'uint8_t *'
// NewFileBufferSize : DWORD -> 'uint32_t'
// NewFileActualSize : DWORD* optional, out -> 'uint32_t *'
// NewFileTime : FILETIME* optional, out -> 'void *'
// ApplyOptionFlags : DWORD -> 'uint32_t'
// ProgressCallback : PPATCH_PROGRESS_CALLBACK optional -> 'void *'
// CallbackContext : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("mspatcha.dll", {
ApplyPatchToFileByBuffers: { parameters: ["pointer", "u32", "pointer", "u32", "pointer", "u32", "pointer", "pointer", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.ApplyPatchToFileByBuffers(PatchFileMapped, PatchFileSize, OldFileMapped, OldFileSize, NewFileBuffer, NewFileBufferSize, NewFileActualSize, NewFileTime, ApplyOptionFlags, ProgressCallback, CallbackContext)
// PatchFileMapped : BYTE* -> "pointer"
// PatchFileSize : DWORD -> "u32"
// OldFileMapped : BYTE* optional -> "pointer"
// OldFileSize : DWORD -> "u32"
// NewFileBuffer : BYTE** in/out -> "pointer"
// NewFileBufferSize : DWORD -> "u32"
// NewFileActualSize : DWORD* optional, out -> "pointer"
// NewFileTime : FILETIME* optional, out -> "pointer"
// ApplyOptionFlags : DWORD -> "u32"
// ProgressCallback : PPATCH_PROGRESS_CALLBACK optional -> "pointer"
// CallbackContext : void* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ApplyPatchToFileByBuffers(
uint8_t* PatchFileMapped,
uint32_t PatchFileSize,
uint8_t* OldFileMapped,
uint32_t OldFileSize,
uint8_t** NewFileBuffer,
uint32_t NewFileBufferSize,
uint32_t* NewFileActualSize,
void* NewFileTime,
uint32_t ApplyOptionFlags,
void* ProgressCallback,
void* CallbackContext);
C, "mspatcha.dll");
// $ffi->ApplyPatchToFileByBuffers(PatchFileMapped, PatchFileSize, OldFileMapped, OldFileSize, NewFileBuffer, NewFileBufferSize, NewFileActualSize, NewFileTime, ApplyOptionFlags, ProgressCallback, CallbackContext);
// PatchFileMapped : BYTE*
// PatchFileSize : DWORD
// OldFileMapped : BYTE* optional
// OldFileSize : DWORD
// NewFileBuffer : BYTE** in/out
// NewFileBufferSize : DWORD
// NewFileActualSize : DWORD* optional, out
// NewFileTime : FILETIME* optional, out
// ApplyOptionFlags : DWORD
// ProgressCallback : PPATCH_PROGRESS_CALLBACK optional
// CallbackContext : void* 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);
boolean ApplyPatchToFileByBuffers(
byte[] PatchFileMapped, // BYTE*
int PatchFileSize, // DWORD
byte[] OldFileMapped, // BYTE* optional
int OldFileSize, // DWORD
Pointer NewFileBuffer, // BYTE** in/out
int NewFileBufferSize, // DWORD
IntByReference NewFileActualSize, // DWORD* optional, out
Pointer NewFileTime, // FILETIME* optional, out
int ApplyOptionFlags, // DWORD
Callback ProgressCallback, // PPATCH_PROGRESS_CALLBACK optional
Pointer CallbackContext // void* optional
);
}@[Link("mspatcha")]
lib Libmspatcha
fun ApplyPatchToFileByBuffers = ApplyPatchToFileByBuffers(
PatchFileMapped : UInt8*, # BYTE*
PatchFileSize : UInt32, # DWORD
OldFileMapped : UInt8*, # BYTE* optional
OldFileSize : UInt32, # DWORD
NewFileBuffer : UInt8**, # BYTE** in/out
NewFileBufferSize : UInt32, # DWORD
NewFileActualSize : UInt32*, # DWORD* optional, out
NewFileTime : FILETIME*, # FILETIME* optional, out
ApplyOptionFlags : UInt32, # DWORD
ProgressCallback : Void*, # PPATCH_PROGRESS_CALLBACK optional
CallbackContext : Void* # void* optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ApplyPatchToFileByBuffersNative = Int32 Function(Pointer<Uint8>, Uint32, Pointer<Uint8>, Uint32, Pointer<Uint8>, Uint32, Pointer<Uint32>, Pointer<Void>, Uint32, Pointer<Void>, Pointer<Void>);
typedef ApplyPatchToFileByBuffersDart = int Function(Pointer<Uint8>, int, Pointer<Uint8>, int, Pointer<Uint8>, int, Pointer<Uint32>, Pointer<Void>, int, Pointer<Void>, Pointer<Void>);
final ApplyPatchToFileByBuffers = DynamicLibrary.open('mspatcha.dll')
.lookupFunction<ApplyPatchToFileByBuffersNative, ApplyPatchToFileByBuffersDart>('ApplyPatchToFileByBuffers');
// PatchFileMapped : BYTE* -> Pointer<Uint8>
// PatchFileSize : DWORD -> Uint32
// OldFileMapped : BYTE* optional -> Pointer<Uint8>
// OldFileSize : DWORD -> Uint32
// NewFileBuffer : BYTE** in/out -> Pointer<Uint8>
// NewFileBufferSize : DWORD -> Uint32
// NewFileActualSize : DWORD* optional, out -> Pointer<Uint32>
// NewFileTime : FILETIME* optional, out -> Pointer<Void>
// ApplyOptionFlags : DWORD -> Uint32
// ProgressCallback : PPATCH_PROGRESS_CALLBACK optional -> Pointer<Void>
// CallbackContext : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ApplyPatchToFileByBuffers(
PatchFileMapped: Pointer; // BYTE*
PatchFileSize: DWORD; // DWORD
OldFileMapped: Pointer; // BYTE* optional
OldFileSize: DWORD; // DWORD
NewFileBuffer: Pointer; // BYTE** in/out
NewFileBufferSize: DWORD; // DWORD
NewFileActualSize: Pointer; // DWORD* optional, out
NewFileTime: Pointer; // FILETIME* optional, out
ApplyOptionFlags: DWORD; // DWORD
ProgressCallback: Pointer; // PPATCH_PROGRESS_CALLBACK optional
CallbackContext: Pointer // void* optional
): BOOL; stdcall;
external 'mspatcha.dll' name 'ApplyPatchToFileByBuffers';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ApplyPatchToFileByBuffers"
c_ApplyPatchToFileByBuffers :: Ptr Word8 -> Word32 -> Ptr Word8 -> Word32 -> Ptr Word8 -> Word32 -> Ptr Word32 -> Ptr () -> Word32 -> Ptr () -> Ptr () -> IO CInt
-- PatchFileMapped : BYTE* -> Ptr Word8
-- PatchFileSize : DWORD -> Word32
-- OldFileMapped : BYTE* optional -> Ptr Word8
-- OldFileSize : DWORD -> Word32
-- NewFileBuffer : BYTE** in/out -> Ptr Word8
-- NewFileBufferSize : DWORD -> Word32
-- NewFileActualSize : DWORD* optional, out -> Ptr Word32
-- NewFileTime : FILETIME* optional, out -> Ptr ()
-- ApplyOptionFlags : DWORD -> Word32
-- ProgressCallback : PPATCH_PROGRESS_CALLBACK optional -> Ptr ()
-- CallbackContext : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let applypatchtofilebybuffers =
foreign "ApplyPatchToFileByBuffers"
((ptr uint8_t) @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint32_t) @-> (ptr void) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* PatchFileMapped : BYTE* -> (ptr uint8_t) *)
(* PatchFileSize : DWORD -> uint32_t *)
(* OldFileMapped : BYTE* optional -> (ptr uint8_t) *)
(* OldFileSize : DWORD -> uint32_t *)
(* NewFileBuffer : BYTE** in/out -> (ptr uint8_t) *)
(* NewFileBufferSize : DWORD -> uint32_t *)
(* NewFileActualSize : DWORD* optional, out -> (ptr uint32_t) *)
(* NewFileTime : FILETIME* optional, out -> (ptr void) *)
(* ApplyOptionFlags : DWORD -> uint32_t *)
(* ProgressCallback : PPATCH_PROGRESS_CALLBACK optional -> (ptr void) *)
(* CallbackContext : void* 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 ("ApplyPatchToFileByBuffers" apply-patch-to-file-by-buffers :convention :stdcall) :int32
(patch-file-mapped :pointer) ; BYTE*
(patch-file-size :uint32) ; DWORD
(old-file-mapped :pointer) ; BYTE* optional
(old-file-size :uint32) ; DWORD
(new-file-buffer :pointer) ; BYTE** in/out
(new-file-buffer-size :uint32) ; DWORD
(new-file-actual-size :pointer) ; DWORD* optional, out
(new-file-time :pointer) ; FILETIME* optional, out
(apply-option-flags :uint32) ; DWORD
(progress-callback :pointer) ; PPATCH_PROGRESS_CALLBACK optional
(callback-context :pointer)) ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ApplyPatchToFileByBuffers = Win32::API::More->new('mspatcha',
'BOOL ApplyPatchToFileByBuffers(LPVOID PatchFileMapped, DWORD PatchFileSize, LPVOID OldFileMapped, DWORD OldFileSize, LPVOID NewFileBuffer, DWORD NewFileBufferSize, LPVOID NewFileActualSize, LPVOID NewFileTime, DWORD ApplyOptionFlags, LPVOID ProgressCallback, LPVOID CallbackContext)');
# my $ret = $ApplyPatchToFileByBuffers->Call($PatchFileMapped, $PatchFileSize, $OldFileMapped, $OldFileSize, $NewFileBuffer, $NewFileBufferSize, $NewFileActualSize, $NewFileTime, $ApplyOptionFlags, $ProgressCallback, $CallbackContext);
# PatchFileMapped : BYTE* -> LPVOID
# PatchFileSize : DWORD -> DWORD
# OldFileMapped : BYTE* optional -> LPVOID
# OldFileSize : DWORD -> DWORD
# NewFileBuffer : BYTE** in/out -> LPVOID
# NewFileBufferSize : DWORD -> DWORD
# NewFileActualSize : DWORD* optional, out -> LPVOID
# NewFileTime : FILETIME* optional, out -> LPVOID
# ApplyOptionFlags : DWORD -> DWORD
# ProgressCallback : PPATCH_PROGRESS_CALLBACK optional -> LPVOID
# CallbackContext : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。