Easyhook 调试出错误,求用过的前辈指教,长期在线等答案。

问题描述

看了Easyhook的教程中的监控进程写文件的例子程序。想改写一下,但是调试总是不通。求用过easyhook的前辈帮我看下是代码的问题,还是可能是引用库不全的问题。困扰好久了,求解答。这是更换API的代码几乎没动因为想先调通这个例子的代码,再改变成我想要的hook操作。usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Threading;usingSystem.Runtime.InteropServices;usingSystem.Runtime.Remoting;usingEasyHook;usingFileMon;namespaceFileMonInject{publicclassMain:EasyHook.IEntryPoint{FileMon.FileMonInterfaceInterface;LocalHookCreateFileHook;Stack<String>Queue=newStack<String>();publicMain(RemoteHooking.IContextInContext,StringInChannelName){//connecttohost...Interface=RemoteHooking.IpcConnectClient<FileMon.FileMonInterface>(InChannelName);}publicvoidRun(RemoteHooking.IContextInContext,StringInChannelName){//installhook...try{//LocalHook.Create:创建一个托管/非托管hook,之后需要用设置ThreadACL属性来激活它。CreateFileHook=LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll","CreateFileW"),newDCreateFile(CreateFile_Hooked),this);CreateFileHook.ThreadACL.SetExclusiveACL(newInt32[]{0});}catch(ExceptionExtInfo){Interface.ReportException(ExtInfo);return;}Interface.IsInstalled(RemoteHooking.GetCurrentProcessId());//等待host进程结束...RemoteHooking.WakeUpProcess();//newaddtry{while(true){Thread.Sleep(500);//传送最新监视到的文件访问...if(Queue.Count>0){String[]Package=null;lock(Queue){Package=Queue.ToArray();Queue.Clear();}Interface.OnCreateFile(RemoteHooking.GetCurrentProcessId(),Package);}elseInterface.Ping();}}catch{//NETRemotingwillraiseanexceptionifhostisunreachable}}[UnmanagedFunctionPointer(CallingConvention.StdCall,CharSet=CharSet.Unicode,SetLastError=true)]delegateIntPtrDCreateFile(StringInFileName,UInt32InDesiredAccess,UInt32InShareMode,IntPtrInSecurityAttributes,UInt32InCreationDisposition,UInt32InFlagsAndAttributes,IntPtrInTemplateFile);//justuseaP-InvokeimplementationtogetnativeAPIaccess//fromC#(thisstepisnotnecessaryforC++.NET)[DllImport("kernel32.dll",CharSet=CharSet.Unicode,SetLastError=true,CallingConvention=CallingConvention.StdCall)]//在托管代码中定义非托管函数的申明staticexternIntPtrCreateFile(StringInFileName,UInt32InDesiredAccess,UInt32InShareMode,IntPtrInSecurityAttributes,UInt32InCreationDisposition,UInt32InFlagsAndAttributes,IntPtrInTemplateFile);//thisiswhereweareinterceptingallfileaccesses!staticIntPtrCreateFile_Hooked(StringInFileName,UInt32InDesiredAccess,UInt32InShareMode,IntPtrInSecurityAttributes,UInt32InCreationDisposition,UInt32InFlagsAndAttributes,IntPtrInTemplateFile){try{MainThis=(Main)HookRuntimeInfo.Callback;lock(This.Queue){This.Queue.Push(InFileName);}}catch{}//calloriginalAPI...returnCreateFile(InFileName,InDesiredAccess,InShareMode,InSecurityAttributes,InCreationDisposition,InFlagsAndAttributes,InTemplateFile);}}}

下面是另一篇代码usingSystem;usingSystem.Collections.Generic;usingSystem.Runtime.Remoting;usingSystem.Text;usingEasyHook;usingSystem.Windows.Forms;namespaceFileMon{publicclassFileMonInterface:MarshalByRefObject{publicvoidIsInstalled(Int32InClientPID){Console.WriteLine("FileMonhasbeeninstalledintarget{0}.rn",InClientPID);}publicvoidOnCreateFile(Int32InClientPID,String[]InFileNames){for(inti=0;i<InFileNames.Length;i++){Console.WriteLine(InFileNames[i]);}}publicvoidReportException(ExceptionInInfo){Console.WriteLine("Thetargetprocesshasreported"+"anerror:rn"+InInfo.ToString());}publicvoidPing(){}}classProgram{staticStringChannelName=null;staticvoidMain(string[]args){#regionLoadtheTargetExeNameStringProName="null";//要监控的exe名字ProNameConsole.WriteLine("Pleaseinputthetargetexename:");ProName=Console.ReadLine();intpid=Moniter.Exe_Pid(ProName);Console.WriteLine("TheTargetPIDis:{0}",pid);Console.ReadKey();#endregionInt32TargetPID=pid;try{try{Config.Register("AFileMonlikedemoapplication.","FileMon.exe","FileMonInject.dll");//Config.Registr:InstallsEasyHookandallgivenuserNETassembliesintotheGACandensuresthatallreferencesarecleanedupiftheinstallingapplicationisshutdown.//Cleanupdoesnotdependonthecallingapplication...}catch(ApplicationExceptionex){MessageBox.Show("Thisisanadministrativetask!"+ex.Message,"Permissiondenied...",MessageBoxButtons.OK);System.Diagnostics.Process.GetCurrentProcess().Kill();}RemoteHooking.IpcCreateServer<FileMonInterface>(refChannelName,WellKnownObjectMode.SingleCall);//IpcCreateServer:Createsagloballyreachable,managedIPC-PortRemoteHooking.Inject(TargetPID,"FileMonInject.dll","FileMonInject.dll",ChannelName);//RemoteHooking.Inject:Injectsthegivenuserlibraryintothetargetprocess.//Inject的参数应与Run的参数精准匹配。ChannelName匹配Run()中inChannerName位置置位符Console.ReadLine();}catch(ExceptionExtInfo){Console.WriteLine("Therewasanerrorwhileconnecting"+"totarget:rn{0}",ExtInfo.ToString());}}}}

以及一篇自己写的用来告诉easyhookhook哪个进程的类,比如输入QQ,会返回QQ的PID传入给hookusingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Diagnostics;namespaceFileMon{//StringProName="ConsoleApplication1";//intpid=Exe_Pid(ProName);//Console.WriteLine(pid);//Console.ReadKey();publicclassMoniter{publicstaticintExe_Pid(stringExe_Name){intpid=-1;Process[]p=Process.GetProcessesByName(Exe_Name);//该进程名称是进程的友好名称,如Outlook,不包括.exe扩展名或路径。for(inti=0;i<p.Length;i++){if(p[i].ProcessName==Exe_Name){pid=p[i].Id;//这个就是进程的ID}}returnpid;}}}

编译生成都没问题,但是调试时候会出现错误:System.ApplicationException:Unabletowaitforserviceapplicationduetotimeout

解决方案

时间: 2024-09-20 00:43:25

Easyhook 调试出错误,求用过的前辈指教,长期在线等答案。的相关文章

vs2012打开mvc时弹出错误 求怎么解决啊

问题描述 未能将网站http://localhost:28637/配置为使用ASP.NET4.5.为了使此网站正确运行,您必须将它手动配置为使用ASP.NET4.5.ASP.NET4.0尚未在Web服务器上注册.为了使您的网站正常运行,您需要为ASP.NET4.0手动配置您的Web服务器.原本装的是2015社区版后来卸载装了2012旗舰版装完2012打开mvc4就有这个提示了求如何解决呢系统是win8的百度说是要配置iis管理器但是没找到在哪求如何解决谢谢 解决方案 解决方案二:自己顶一下.

Teechart在vs2015c#中引用时弹出错误

问题描述 Teechart在vs2015c#中引用时弹出错误 求大神指点迷津!谢谢

swing-一段代码,调试很久没调试出来,求帮忙,哪里出了问题

问题描述 一段代码,调试很久没调试出来,求帮忙,哪里出了问题 一段代码,调试很久没调试出来,求帮忙,哪里出了问题,代码贴在下面 解决方案 import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.Resul

android 编译通过了但调试出了问题 求大神帮忙 非常感谢

问题描述 android 编译通过了但调试出了问题 求大神帮忙 非常感谢 这是java文件 package com.src;import java.text.NumberFormat;import java.util.Calendar;import android.app.Activity;import android.content.SharedPreferences;import android.content.SharedPreferences.Editor;import android.

真机调试-真机测试出错误 在线等待大神

问题描述 真机测试出错误 在线等待大神 真机调试错误 No provisioning profiles found: No non–expired provisioning profiles were found. CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 8.1' 怎么回事?公司分了一个开发小组成员给我证书什么的也都是按教程来的 但是就是一真机调试就是这个. 运行一下提

源代码-寻求帮助!C++程序,无法通过编译,我没检查出错误,求高手相助!

问题描述 寻求帮助!C++程序,无法通过编译,我没检查出错误,求高手相助! C++ primer plus 6th edition 课后编程联系,p163页,第一题. 题目要求输入两个整数,并输出这两个整数之间所有整数值的和. #include int main() { using namespace std; cout << "PLEASE ENTER 2 NUMBERS: "; //声明两个整数变量,用来保存输入的值 int number1, number2; //wh

c-我刚刚入门,写一个一元多项式的简单计算,求帮忙解决这个加减问题,代码如下,帮忙找出错误,急急急

问题描述 我刚刚入门,写一个一元多项式的简单计算,求帮忙解决这个加减问题,代码如下,帮忙找出错误,急急急 #include #include typedef struct node { float c; int e; struct node * next; }lnode,*plnode; void insert_menu(); void insert_pol(plnode &l); void output_pol(plnode &l); void add_pol(plnode list1,

数据结构 运行不了,求找出错误

问题描述 数据结构 运行不了,求找出错误 #include "stdafx.h" #define Maxsize 100 include typedef int datatype; typedef struct { int stack[Maxsize]; int top; }SeqStack; SeqStack*InitStack() { SeqStack * S; S=(SeqStack *)(sizeof(SeqStack)); if(!S) { printf("空间不足

js-JS做迷宫,人物的方块动不了,求找出错误

问题描述 JS做迷宫,人物的方块动不了,求找出错误 这个是CSS:.gz { width: 30px;height: 30px; position: absolute;} .rw { width: 30px;height: 30px; position: absolute;z-index: 100;} 这个是JS: window.onload = function () { var arr = new Array(); arr = [ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1,