使用 chiitrans 的方式 https://github.com/alexbft/chiitrans ,将Textractor的CLI改为dll,供.Net使用

代码放github了 https://github.com/lgztx96/texthost ,没有qt,只取了必要部分编译为dll

也没啥好说的,直接导出就行,不过函数名总是有奇奇怪怪的前缀后缀,加了个.def文件解决。

最后直接调用就行了,一些无符号数可以改为有符号数,需要Textractor的texthook.dll放同一目录,使用剪贴板监视需要传递一个窗口句柄。移钩子的功能挺好用的,不然可能有很多没用的钩子

//用于搜索钩子的结构体参数,32bit size=608 ,64bit size=632
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    internal struct SearchParam
    {
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
        public Byte[] pattern;

        public Int32 Length;
        public Int32 Offset;
        public Int32 SearchTime;
        public Int32 MaxRecords;
        public Int32 Codepage;

        [MarshalAs(UnmanagedType.SysUInt)]
        public IntPtr Padding;

        [MarshalAs(UnmanagedType.SysUInt)]
        public IntPtr MinAddress;

        [MarshalAs(UnmanagedType.SysUInt)]
        public IntPtr MaxAddress;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 120)]
        public String BoundaryModule;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 120)]
        public String ExportModule;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 30)]
        public String Text;

        public IntPtr HookPostProcessor;
    };
    #region 回调委托
    internal delegate void ProcessCallback(uint processId);

    internal delegate void OnCreateThread(        
        long threadId,
        uint processId,
        ulong address,
        ulong context,
        ulong subcontext,
        [MarshalAs(UnmanagedType.LPWStr)] string name,
        [MarshalAs(UnmanagedType.LPWStr)] string hookCode
        );

    internal delegate void OnRemoveThread(long threadId);

    internal delegate void OnOutputText(long threadId,[MarshalAs(UnmanagedType.LPWStr)] string text);
    #endregion

    internal class TextHostLib
    {
        [DllImport("texthost.dll")]
        internal static extern int TextHostInit(     
            ProcessCallback OnConnect,
            ProcessCallback OnDisconnect,
            OnCreateThread OnCreateThread,
            OnRemoveThread OnRemoveThread,
            OnOutputText OnOutputText
            );

        [DllImport("texthost.dll")]
        internal static extern int InsertHook(     
            uint processId,
            [MarshalAs(UnmanagedType.LPWStr)] string hookCode
            );

        [DllImport("texthost.dll")]
        internal static extern int RemoveHook(uint processId, ulong address);

        [DllImport("texthost.dll")]
        internal extern static int InjectProcess(uint processId);

        [DllImport("texthost.dll")]
        internal extern static int DetachProcess(uint processId);

        [DllImport("texthost.dll")]  
        internal extern static int AddClipboardThread(IntPtr windowHandle);
    }

这样造个自己的vnr就很容易了。正在龟速进行自己的vnr计划


一沙一世界,一花一天堂。君掌盛无边,刹那成永恒。