private PrintWarning ( String InMessage ) : void | ||
InMessage | String | |
Résultat | void |
public static int Main(String inParam) { if (inParam == null) { return(0); } var ptr = (IntPtr)Int64.Parse(inParam, NumberStyles.HexNumber); var connection = HostConnectionData.LoadData(ptr); if (connection.State != HostConnectionData.ConnectionState.Valid) { return((int)connection.State); } // Adjust host PID in case of WOW64 bypass and service help... connection.UnmanagedInfo.m_HostPID = connection.RemoteInfo.HostPID; try { // Prepare parameter array. var paramArray = new object[1 + connection.RemoteInfo.UserParams.Length]; // The next type cast is not redundant because the object needs to be an explicit IContext // when passed as a parameter to the IEntryPoint constructor and Run() methods. paramArray[0] = (RemoteHooking.IContext)connection.UnmanagedInfo; for (var i = 0; i < connection.RemoteInfo.UserParams.Length; i++) { paramArray[i + 1] = connection.RemoteInfo.UserParams[i]; } // Note: at this point all but the first parameter are still binary encoded. // Load the user library and initialize the IEntryPoint. return(LoadUserLibrary(connection.RemoteInfo.UserLibraryName, connection.RemoteInfo.UserLibrary, paramArray, connection.HelperInterface)); } catch (Exception ExtInfo) { Config.PrintWarning(ExtInfo.ToString()); return(-1); } finally { if (_connectedChannels.Contains(connection.RemoteInfo.ChannelName)) { _connectedChannels.Remove(connection.RemoteInfo.ChannelName); } } }
public static int Main(String InParam) { HelperServiceInterface Interface; String[] Params; String HostChannel; Assembly UserAssembly = null; Type EntryPoint = null; if (InParam == null) { return(-1); } /* * We will now connect to our hooking host. This is to provide extensive * error information. */ try { Params = InParam.Split('|'); if (Params.Length != 4) { return(-1); } HostChannel = Params[0]; Interface = RemoteHooking.IpcConnectClient <HelperServiceInterface>(HostChannel); // ensure connection... Interface.Ping(); if (!ConnectedChannels.Contains(HostChannel)) { ConnectedChannels.Add(HostChannel); return(0); } } catch (Exception ExtInfo) { Config.PrintError(ExtInfo.ToString()); return(-2); } try { /* * After this we are ready to load the user supplied library. */ String UserLibrary = Params[1]; String InfoPtr = Params[3]; List <Object> UserParams = new List <object>(); Object Instance = null; RemoteHooking.SetWakeUpThreadID(Int32.Parse(Params[2])); try { UserAssembly = Assembly.LoadWithPartialName(UserLibrary); // search for user library entry point... Type[] ExportedTypes = UserAssembly.GetExportedTypes(); for (int iType = 0; iType < ExportedTypes.Length; iType++) { EntryPoint = ExportedTypes[iType]; if (EntryPoint.GetInterface("EasyHook.IEntryPoint") != null) { break; } EntryPoint = null; } if (EntryPoint == null) { throw new EntryPointNotFoundException("The given user library does not export a proper type implementing the 'IEasyHookInjection' interface."); } // parse injection information (should work always as there is nothing tricky about it)... RemoteHooking.IContext Context = RemoteHooking.QueryContext(InfoPtr); // assemble user parameters and initialize library... BinaryFormatter Format = new BinaryFormatter(); UserParams.Add(Context); try { UserParams.AddRange((Object[])Format.Deserialize(new MemoryStream(Context.UserData))); } catch (Exception ExtInfo) { throw new ArgumentException("Unable to deserialize user supplied argument list.", ExtInfo); } Instance = EntryPoint.InvokeMember(null, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, UserParams.ToArray()); // notify the host about successful injection... Interface.InjectionCompleted(RemoteHooking.GetCurrentProcessId()); } catch (Exception ExtInfo) { // we will now get extensive error information on host side... try { Interface.InjectionException(RemoteHooking.GetCurrentProcessId(), ExtInfo); } finally { Instance = null; Release(EntryPoint); } return(-1); } try { /* * After this it is safe to enter the main method, which will block until assembly unloading... * From now on the user library has to take care about error reporting! */ EntryPoint.InvokeMember("Run", BindingFlags.Public | BindingFlags.Instance | BindingFlags.ExactBinding | BindingFlags.InvokeMethod, null, Instance, UserParams.ToArray()); } finally { Instance = null; Release(EntryPoint); } } catch (Exception ExtInfo) { Config.PrintWarning(ExtInfo.ToString()); return(-1); } finally { if (ConnectedChannels.Contains(HostChannel)) { ConnectedChannels.Remove(HostChannel); } } return(0); }
#pragma warning disable 0028 public static int Main(String InParam) { HelperServiceInterface Interface; Assembly UserAssembly = null; Type EntryPoint = null; ManagedRemoteInfo RemoteInfo; REMOTE_ENTRY_INFO UnmanagedInfo = new REMOTE_ENTRY_INFO(); if (InParam == null) { return(0); } /* * We will now connect to our hooking host. This is to provide extensive * error information. */ try { Marshal.PtrToStructure( (IntPtr)Int64.Parse(InParam, System.Globalization.NumberStyles.HexNumber), UnmanagedInfo); Byte[] PassThruBytes = new Byte[UnmanagedInfo.UserDataSize]; MemoryStream PassThruStream = new MemoryStream(); BinaryFormatter Format = new BinaryFormatter(); // Workaround for deserialization when not using GAC registration Format.Binder = new AllowAllAssemblyVersionsDeserializationBinder(); Marshal.Copy(UnmanagedInfo.UserData, PassThruBytes, 0, UnmanagedInfo.UserDataSize); PassThruStream.Write(PassThruBytes, 0, PassThruBytes.Length); PassThruStream.Position = 0; RemoteInfo = (ManagedRemoteInfo)Format.Deserialize(PassThruStream); Interface = RemoteHooking.IpcConnectClient <HelperServiceInterface>(RemoteInfo.ChannelName); // ensure connection... Interface.Ping(); if (!ConnectedChannels.Contains(RemoteInfo.ChannelName)) { ConnectedChannels.Add(RemoteInfo.ChannelName); return(1); } } catch (Exception ExtInfo) { Config.PrintError(ExtInfo.ToString()); return(0); } try { // adjust host PID in case of WOW64 bypass and service help... UnmanagedInfo.m_HostPID = RemoteInfo.HostPID; // prepare parameter array Object[] ParamArray = new Object[1 + RemoteInfo.UserParams.Length]; ParamArray[0] = (RemoteHooking.IContext)UnmanagedInfo; for (int i = 0; i < RemoteInfo.UserParams.Length; i++) { ParamArray[i + 1] = RemoteInfo.UserParams[i]; } /* * After this we are ready to load the user supplied library. */ Object Instance = null; try { // First attempt to load the library using its full name (e.g. strong name) if (!String.IsNullOrEmpty(RemoteInfo.UserLibraryName)) { try { UserAssembly = Assembly.Load(RemoteInfo.UserLibraryName); Config.PrintComment("SUCCESS: Assembly.Load({0})", RemoteInfo.UserLibraryName); } catch (Exception e) { Config.PrintWarning("FAIL: Assembly.Load({0}) - {1}", RemoteInfo.UserLibraryName, e.ToString()); } } // If loading by strong name failed, attempt to load the assembly from its file location if (UserAssembly == null) { try { UserAssembly = Assembly.LoadFrom(RemoteInfo.UserLibrary); Config.PrintComment("SUCCESS: Assembly.LoadFrom({0})", RemoteInfo.UserLibrary); } catch (Exception e) { Config.PrintWarning("FAIL: Assembly.LoadFrom({0}) - {1}", RemoteInfo.UserLibrary, e.ToString()); } } if (UserAssembly == null) { Config.PrintError("Could not load assembly {0}, {1}", RemoteInfo.UserLibrary, RemoteInfo.UserLibraryName); return(0); } // Only attempt to deserialise parameters after we have loaded the UserAssembly // this allows types from the UserAssembly to be passed as parameters BinaryFormatter format = new BinaryFormatter(); format.Binder = new AllowAllAssemblyVersionsDeserializationBinder(UserAssembly); for (int i = 1; i < ParamArray.Length; i++) { using (MemoryStream ms = new MemoryStream((byte[])ParamArray[i])) { ParamArray[i] = format.Deserialize(ms); } } // search for user library entry point... Type[] ExportedTypes = UserAssembly.GetExportedTypes(); for (int iType = 0; iType < ExportedTypes.Length; iType++) { EntryPoint = ExportedTypes[iType]; if (EntryPoint.GetInterface("EasyHook.IEntryPoint") != null) { break; } EntryPoint = null; } if (EntryPoint == null) { throw new EntryPointNotFoundException("The given user library does not export a proper type implementing the 'EasyHook.IEntryPoint' interface."); } // test for strictly typed Run() method MethodInfo Run = EntryPoint.GetMethod("Run", BindingFlags.Public | BindingFlags.Instance); if (Run != null) { if (ParamArray.Length != Run.GetParameters().Length) { throw new MissingMethodException("The given user library does export a Run() method in the 'EasyHook.IEntryPoint' interface, but the parameter count does not match!"); } for (int i = 0; i < ParamArray.Length; i++) { var param = Run.GetParameters()[i]; if (param.ParameterType.IsByRef && ParamArray[i] == null) // allow null parameter values { continue; } if (!param.ParameterType.IsInstanceOfType(ParamArray[i])) { Config.PrintError("Run() parameter {0} type {1}, does not match input parameter type {2}", i, param.ParameterType.AssemblyQualifiedName, ParamArray[i].GetType().AssemblyQualifiedName); throw new MissingMethodException( "The given user library does export a Run() method in the 'EasyHook.IEntryPoint' interface, but the parameter types do not match!"); } } } else { throw new MissingMethodException("The given user library does not export a proper Run() method in the 'EasyHook.IEntryPoint' interface."); } // assemble user parameters and initialize library... Instance = EntryPoint.InvokeMember(null, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, ParamArray); // notify the host about successful injection... Interface.InjectionCompleted(RemoteHooking.GetCurrentProcessId()); } catch (Exception ExtInfo) { // we will now get extensive error information on host side... try { Interface.InjectionException(RemoteHooking.GetCurrentProcessId(), ExtInfo); } finally { Instance = null; Release(EntryPoint); } return(-1); } try { /* * After this it is safe to enter the main method, which will block until assembly unloading... * From now on the user library has to take care about error reporting! */ EntryPoint.InvokeMember("Run", BindingFlags.Public | BindingFlags.Instance | BindingFlags.ExactBinding | BindingFlags.InvokeMethod, null, Instance, ParamArray); } finally { Instance = null; Release(EntryPoint); } } catch (Exception ExtInfo) { Config.PrintWarning(ExtInfo.ToString()); return(-1); } finally { if (ConnectedChannels.Contains(RemoteInfo.ChannelName)) { ConnectedChannels.Remove(RemoteInfo.ChannelName); } } return(0); }
#pragma warning disable 0028 public static int Main(String InParam) { HelperServiceInterface Interface; Assembly UserAssembly = null; Type EntryPoint = null; ManagedRemoteInfo RemoteInfo; REMOTE_ENTRY_INFO UnmanagedInfo = new REMOTE_ENTRY_INFO(); if (InParam == null) { return(0); } /* * We will now connect to our hooking host. This is to provide extensive * error information. */ try { Marshal.PtrToStructure( (IntPtr)Int64.Parse(InParam, System.Globalization.NumberStyles.HexNumber), UnmanagedInfo); Byte[] PassThruBytes = new Byte[UnmanagedInfo.UserDataSize]; MemoryStream PassThruStream = new MemoryStream(); BinaryFormatter Format = new BinaryFormatter(); Marshal.Copy(UnmanagedInfo.UserData, PassThruBytes, 0, UnmanagedInfo.UserDataSize); PassThruStream.Write(PassThruBytes, 0, PassThruBytes.Length); PassThruStream.Position = 0; RemoteInfo = (ManagedRemoteInfo)Format.Deserialize(PassThruStream); Interface = RemoteHooking.IpcConnectClient <HelperServiceInterface>(RemoteInfo.ChannelName); // ensure connection... Interface.Ping(); if (!ConnectedChannels.Contains(RemoteInfo.ChannelName)) { ConnectedChannels.Add(RemoteInfo.ChannelName); return(1); } } catch (Exception ExtInfo) { Config.PrintError(ExtInfo.ToString()); return(0); } try { // adjust host PID in case of WOW64 bypass and service help... UnmanagedInfo.m_HostPID = RemoteInfo.HostPID; // prepare parameter array Object[] ParamArray = new Object[1 + RemoteInfo.UserParams.Length]; ParamArray[0] = (RemoteHooking.IContext)UnmanagedInfo; for (int i = 0; i < RemoteInfo.UserParams.Length; i++) { ParamArray[i + 1] = RemoteInfo.UserParams[i]; } /* * After this we are ready to load the user supplied library. */ Object Instance = null; try { UserAssembly = Assembly.LoadWithPartialName(RemoteInfo.UserLibrary); // search for user library entry point... Type[] ExportedTypes = UserAssembly.GetExportedTypes(); for (int iType = 0; iType < ExportedTypes.Length; iType++) { EntryPoint = ExportedTypes[iType]; if (EntryPoint.GetInterface("EasyHook.IEntryPoint") != null) { break; } EntryPoint = null; } if (EntryPoint == null) { throw new EntryPointNotFoundException("The given user library does not export a proper type implementing the 'EasyHook.IEntryPoint' interface."); } // test for strictly typed Run() method MethodInfo Run = EntryPoint.GetMethod("Run", BindingFlags.Public | BindingFlags.Instance); if (Run != null) { if (ParamArray.Length != Run.GetParameters().Length) { throw new MissingMethodException("The given user library does export a Run() method in the 'EasyHook.IEntryPoint' interface, but the parameter count does not match!"); } for (int i = 0; i < ParamArray.Length; i++) { if (!Run.GetParameters()[i].ParameterType.IsInstanceOfType(ParamArray[i])) { throw new MissingMethodException("The given user library does export a Run() method in the 'EasyHook.IEntryPoint' interface, but the parameter types do not match!"); } } } else { throw new MissingMethodException("The given user library does not export a proper Run() method in the 'EasyHook.IEntryPoint' interface."); } // assemble user parameters and initialize library... Instance = EntryPoint.InvokeMember(null, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, ParamArray); // notify the host about successful injection... Interface.InjectionCompleted(RemoteHooking.GetCurrentProcessId()); } catch (Exception ExtInfo) { // we will now get extensive error information on host side... try { Interface.InjectionException(RemoteHooking.GetCurrentProcessId(), ExtInfo); } finally { Instance = null; Release(EntryPoint); } return(-1); } try { /* * After this it is safe to enter the main method, which will block until assembly unloading... * From now on the user library has to take care about error reporting! */ EntryPoint.InvokeMember("Run", BindingFlags.Public | BindingFlags.Instance | BindingFlags.ExactBinding | BindingFlags.InvokeMethod, null, Instance, ParamArray); } finally { Instance = null; Release(EntryPoint); } } catch (Exception ExtInfo) { Config.PrintWarning(ExtInfo.ToString()); return(-1); } finally { if (ConnectedChannels.Contains(RemoteInfo.ChannelName)) { ConnectedChannels.Remove(RemoteInfo.ChannelName); } } return(0); }