给移动飞信弄个小外挂

通过winsiggen.exe制作的API声明:

[System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.StdCall)]
    public delegate int WNDENUMPROC(System.IntPtr param0, System.IntPtr param1);

    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
    public struct HWND__
    {
        public int unused;
    }

 

    public partial class NativeConstants
    {
        /// WM_PASTE -> 0x0302
        public const int WM_PASTE = 770;

        /// WM_LBUTTONDOWN -> 0x0201
        public const int WM_LBUTTONDOWN = 513;

        /// WM_LBUTTONUP -> 0x0202
        public const int WM_LBUTTONUP = 514;

        /// BM_SETSTATE -> 0x00F3
        public const int BM_SETSTATE = 243;

        /// MK_LBUTTON -> 0x0001
        public const int MK_LBUTTON = 1;
    }

 

    public partial class NativeMethods
    {
        [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "FindWindowW")]
        public static extern System.IntPtr FindWindowW([System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)] string lpClassName, [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)] string lpWindowName);

 

        [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "EnumChildWindows")]
        [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
       
//public static extern bool EnumChildWindows([System.Runtime.InteropServices.InAttribute()] System.IntPtr hWndParent, WNDENUMPROC lpEnumFunc, [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.SysInt)] int lParam);
        public static extern bool EnumChildWindows([System.Runtime.InteropServices.InAttribute()] System.IntPtr hWndParent, WNDENUMPROC lpEnumFunc, int lParam);

       

        [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "GetClassNameW")]
        public static extern int GetClassNameW([System.Runtime.InteropServices.InAttribute()] System.IntPtr hWnd, [System.Runtime.InteropServices.OutAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)] System.Text.StringBuilder lpClassName, int nMaxCount);

       

        [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "SendMessageW")]
        //[return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.SysInt)]
        //public static extern int SendMessageW([System.Runtime.InteropServices.InAttribute()] System.IntPtr hWnd, uint Msg, [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.SysUInt)] uint wParam, [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.SysInt)] int lParam);
        public static extern int SendMessageW([System.Runtime.InteropServices.InAttribute()] System.IntPtr hWnd, uint Msg, uint wParam, int lParam);

       

        [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "GetWindowTextW")]
        public static extern int GetWindowTextW([System.Runtime.InteropServices.InAttribute()] System.IntPtr hWnd, [System.Runtime.InteropServices.OutAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)] System.Text.StringBuilder lpString, int nMaxCount);

     

        [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "SetActiveWindow")]
        public static extern System.IntPtr SetActiveWindow([System.Runtime.InteropServices.InAttribute()] System.IntPtr hWnd);

红色的代码在运行中会抛出什么封送错误,干脆化繁为简,去掉那些自动生成的前缀,到也OK。

 

实际代码:

private void button1_Click(object sender, EventArgs e)
{
       System.IntPtr hWnd;

       hWnd = NativeMethods.FindWindowW("WindowsForms10.Window.8.app.0.378734a", "某某某");
       if (hWnd.ToString() == "0")
           MessageBox.Show("No found!");
       else
       {

          

           WNDENUMPROC settextproc = new WNDENUMPROC(SetText);
           NativeMethods.EnumChildWindows(hWnd, settextproc, 0);

          Thread.Sleep(100);

        

           要模拟鼠标按键的话,目标窗口必须是活动的

           NativeMethods.SetActiveWindow(hWnd); 

           WNDENUMPROC sendproc= new WNDENUMPROC(Send);
           NativeMethods.EnumChildWindows(hWnd, sendproc, 0);  
       }
  }

  

int SetText(System.IntPtr param0, System.IntPtr param1)
{
    StringBuilder s = new StringBuilder(256);
    NativeMethods.GetClassNameW(param0, s, s.Capacity );

    if (s.ToString().Trim() == "WindowsForms10.RichEdit20W.app.0.378734a")
          NativeMethods.SendMessageW(param0, NativeConstants.WM_PASTE, 0, 0);

     return 1;
 }

飞信程序拦截了其他进程向输入框发送修改文本的消息,只能改用黏贴剪贴板上内容的方法,也挺有趣 

 

int Send(System.IntPtr param0, System.IntPtr param1)
{
    StringBuilder s = new StringBuilder(256);

    NativeMethods.GetWindowTextW(param0, s, s.Capacity);
    if (s.ToString().Trim() == "发送")
    {
        NativeMethods.SendMessageW(param0, NativeConstants.WM_LBUTTONDOWN, NativeConstants.MK_LBUTTON, 0);
        NativeMethods.SendMessageW(param0, NativeConstants.BM_SETSTATE, 1, 0);
        NativeMethods.SendMessageW(param0, NativeConstants.WM_LBUTTONUP, NativeConstants.MK_LBUTTON, 0);
        NativeMethods.SendMessageW(param0, NativeConstants.BM_SETSTATE, 0, 0);
        return 0;
    }

    return 1;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值