/// <summary> /// Loads <see cref="ConnectionData"/> from the <see cref="IntPtr"/> specified. /// </summary> /// <param name="unmanagedInfoPointer"></param> /// <param name="formatter"></param> public static ConnectionData <T, U> LoadData( IntPtr unmanagedInfoPointer, IUserDataFormatter formatter) { var data = new ConnectionData <T, U> { State = ConnectionState.Valid, UnmanagedInfo = (T)Activator.CreateInstance(typeof(T)) }; try { // Get the unmanaged data containing the remote user parameters Marshal.PtrToStructure(unmanagedInfoPointer, data.UnmanagedInfo); // Deserialize user data class passed to CoreLoad data.RemoteInfo = formatter.Deserialize <U>( data.UnmanagedInfo.UserData, data.UnmanagedInfo.UserDataSize); } catch (Exception exception) { Debug.WriteLine(exception.ToString()); } return(data); }
/// <summary> /// Create the config class that is passed to the CLR bootstrap library to be loaded. /// The <paramref name="remoteInfo"/> holds information such as what hooking module to load. /// </summary> /// <param name="remoteInfo">The configuration that is serialized and passed to CoreLoad.</param> /// <param name="serializer">Serializes the <paramref name="remoteInfo"/> data.</param> /// <param name="library">The managed hooking library to be loaded and executed in the target process.</param> /// <param name="argumentsStream">The stream that holds the the serialized <paramref name="remoteInfo"/> class.</param> /// <param name="injectionPipeName">The pipe name used for notifying the host process that the hook plugin has been loaded in the target process.</param> private static void PrepareInjection( ManagedRemoteInfo remoteInfo, IUserDataFormatter serializer, ref string library, MemoryStream argumentsStream, string injectionPipeName) { if (string.IsNullOrWhiteSpace(library)) { throw new ArgumentException("The injection library was not valid"); } if ((library != null) && File.Exists(library)) { library = Path.GetFullPath(library); } remoteInfo.UserLibrary = library; if (File.Exists(remoteInfo.UserLibrary)) { remoteInfo.UserLibraryName = AssemblyName.GetAssemblyName(remoteInfo.UserLibrary).FullName; } else { throw new FileNotFoundException($"The given assembly could not be found: '{remoteInfo.UserLibrary}'", remoteInfo.UserLibrary); } remoteInfo.ChannelName = injectionPipeName; serializer.Serialize(argumentsStream, remoteInfo); }
public AddUserWithTemporaryPasswordCommandHandler( CofoundryDbContext dbContext, ICommandExecutor commandExecutor, IPasswordGenerationService passwordGenerationService, IMailService mailService, IQueryExecutor queryExecutor, IUserMailTemplateBuilderContextFactory userMailTemplateBuilderContextFactory, IUserMailTemplateBuilderFactory userMailTemplateBuilderFactory, IUserAreaDefinitionRepository userAreaDefinitionRepository, ITransactionScopeManager transactionScopeFactory, IUserDataFormatter userDataFormatter, IPasswordPolicyService passwordPolicyService ) { _dbContext = dbContext; _commandExecutor = commandExecutor; _passwordGenerationService = passwordGenerationService; _mailService = mailService; _queryExecutor = queryExecutor; _userMailTemplateBuilderContextFactory = userMailTemplateBuilderContextFactory; _userMailTemplateBuilderFactory = userMailTemplateBuilderFactory; _userAreaDefinitionRepository = userAreaDefinitionRepository; _transactionScopeFactory = transactionScopeFactory; _userDataFormatter = userDataFormatter; _passwordPolicyService = passwordPolicyService; }
/// <summary> /// Loads <see cref="PluginConfiguration{T,U}"/> from the <see cref="IntPtr"/> specified /// in <paramref name="unmanagedInfoPointer"/>. /// </summary> /// <param name="unmanagedInfoPointer">Pointer to the user arguments data.</param> /// <param name="formatter">Deserializer for the user arguments data.</param> public static PluginConfiguration <T, U> LoadData( IntPtr unmanagedInfoPointer, IUserDataFormatter formatter) { var data = new PluginConfiguration <T, U> { State = PluginInitializationState.Loading, UnmanagedInfo = (T)Activator.CreateInstance(typeof(T)) }; try { // Get the unmanaged data containing the remote user parameters Marshal.PtrToStructure(unmanagedInfoPointer, data.UnmanagedInfo); // Deserialize user data class passed to CoreLoad data.RemoteInfo = formatter.Deserialize <U>( data.UnmanagedInfo.UserData, data.UnmanagedInfo.UserDataSize); } catch (Exception e) { data.State = PluginInitializationState.Failed; Debug.WriteLine(e.ToString()); } return(data); }
/// <summary> /// Create the config class that is passed to the CLR bootstrap library to be loaded. /// The <paramref name="remoteInfo"/> holds information such as what hooking module to load. /// </summary> /// <param name="remoteInfo">The configuration that is serialized and passed to CoreLoad.</param> /// <param name="userDataFormatter">Serializes the <paramref name="remoteInfo"/> data.</param> /// <param name="pluginPath">The plugin to be loaded and executed in the target process.</param> /// <param name="argumentsStream">The stream that holds the the serialized <paramref name="remoteInfo"/> class.</param> /// <param name="injectionPipeName">The pipe name used for notifying the host process that the hook plugin has been loaded in the target process.</param> private static void CreatePluginArguments( ManagedRemoteInfo remoteInfo, IUserDataFormatter userDataFormatter, string pluginPath, Stream argumentsStream, string injectionPipeName) { if (string.IsNullOrWhiteSpace(pluginPath)) { throw new ArgumentException("The injection library was not valid"); } if (File.Exists(pluginPath)) { pluginPath = Path.GetFullPath(pluginPath); } remoteInfo.UserLibrary = pluginPath; if (File.Exists(remoteInfo.UserLibrary)) { remoteInfo.UserLibraryName = AssemblyName.GetAssemblyName(remoteInfo.UserLibrary).FullName; } else { throw new FileNotFoundException($"The given assembly could not be found: '{remoteInfo.UserLibrary}'", remoteInfo.UserLibrary); } remoteInfo.ChannelName = injectionPipeName; userDataFormatter.Serialize(argumentsStream, remoteInfo); }
public IsUserEmailAddressUniqueQueryHandler( CofoundryDbContext dbContext, IUserDataFormatter userDataFormatter ) { _dbContext = dbContext; _userDataFormatter = userDataFormatter; }
public void ShouldThrowNullExceptionWhenSerializingWithNullStreamAndNullObject() { IUserDataFormatter formatter = CreateFormatter(); Stream serializationStream = null; object objectToSerialize = null; Assert.Throws <ArgumentNullException>(() => formatter.Serialize(serializationStream, objectToSerialize)); }
public SearchUserSummariesQueryHandler( CofoundryDbContext dbContext, IUserSummaryMapper userSummaryMapper, IUserDataFormatter userDataFormatter ) { _dbContext = dbContext; _userSummaryMapper = userSummaryMapper; _userDataFormatter = userDataFormatter; }
public ValidateUserEmailAddressQueryHandler( IUserAreaDefinitionRepository userAreaDefinitionRepository, IUserDataFormatter userDataFormatter, IEmailAddressValidator emailAddressValidator ) { _userAreaDefinitionRepository = userAreaDefinitionRepository; _userDataFormatter = userDataFormatter; _emailAddressValidator = emailAddressValidator; }
/// <summary> /// Extract serialized parameters from a stream into a parameter list. /// </summary> /// <param name="paramArray">The list to store the extracted parameters to.</param> /// <param name="formatter">Extracts serialized objects into their original type.</param> private static void DeserializeParameters(object[] paramArray, IUserDataFormatter formatter) { for (int i = 1; i < paramArray.Length; ++i) { using (Stream ms = new MemoryStream((byte[])paramArray[i])) { paramArray[i] = formatter.Deserialize <object>(ms); } } }
public GetUserMicroSummaryByEmailQueryHandler( CofoundryDbContext dbContext, IUserMicroSummaryMapper userMicroSummaryMapper, IUserDataFormatter userDataFormatter ) { _dbContext = dbContext; _userMicroSummaryMapper = userMicroSummaryMapper; _userDataFormatter = userDataFormatter; }
public ValidateUsernameQueryHandler( IUserAreaDefinitionRepository userAreaDefinitionRepository, IUserDataFormatter userDataFormatter, IUsernameValidator usernameValidator ) { _userAreaDefinitionRepository = userAreaDefinitionRepository; _userDataFormatter = userDataFormatter; _usernameValidator = usernameValidator; }
public void ShouldSerializeClassToStream() { IUserDataFormatter formatter = CreateFormatter(); using (Stream serializationStream = new MemoryStream()) { var objectToSerialize = new UserDataFormatterTestClass { IntegerMember = 1 }; formatter.Serialize(serializationStream, objectToSerialize); Assert.NotEqual(0, serializationStream.Length); } }
public UserUpdateCommandHelper( IUserAreaDefinitionRepository userAreaRepository, IUserDataFormatter userDataFormatter, IUserStoredProcedures userStoredProcedures, IMessageAggregator messageAggregator, IEmailAddressValidator emailAddressValidator, IUsernameValidator usernameValidator ) { _userAreaRepository = userAreaRepository; _userDataFormatter = userDataFormatter; _userStoredProcedures = userStoredProcedures; _messageAggregator = messageAggregator; _emailAddressValidator = emailAddressValidator; _usernameValidator = usernameValidator; }
public AuthenticateUserCredentialsQueryHandler( ILogger <AuthenticateUserCredentialsQueryHandler> logger, CofoundryDbContext dbContext, IDomainRepository domainRepository, IUserAreaDefinitionRepository userAreaDefinitionRepository, UserAuthenticationHelper userAuthenticationHelper, IUserDataFormatter userDataFormatter, IPasswordUpdateCommandHelper passwordUpdateCommandHelper, IExecutionDurationRandomizerScopeManager executionDurationRandomizerScopeManager ) { _userAuthenticationHelper = userAuthenticationHelper; _logger = logger; _dbContext = dbContext; _domainRepository = domainRepository; _userAreaDefinitionRepository = userAreaDefinitionRepository; _userDataFormatter = userDataFormatter; _passwordUpdateCommandHelper = passwordUpdateCommandHelper; _executionDurationRandomizerScopeManager = executionDurationRandomizerScopeManager; }
public void ShouldSerializeAndDeserializeClassWithStream() { IUserDataFormatter formatter = CreateFormatter(); const int integerMemberValue = 1; using (Stream serializationStream = new MemoryStream()) { var objectToSerialize = new UserDataFormatterTestClass { IntegerMember = integerMemberValue }; formatter.Serialize(serializationStream, objectToSerialize); Assert.NotEqual(0, serializationStream.Length); serializationStream.Position = 0; var deserializedObject = formatter.Deserialize <UserDataFormatterTestClass>(serializationStream); Assert.NotNull(deserializedObject); Assert.Equal(integerMemberValue, deserializedObject.IntegerMember); } }
/// <summary> /// /// </summary> /// <param name="processId">The process ID of the local process that is injecting into another remote process.</param> /// <param name="formatter">Serializer for the user arguments passed to the plugin.</param> /// <param name="passThruArguments">The arguments passed to the plugin during initialization.</param> /// <returns></returns> private static ManagedRemoteInfo CreateRemoteInfo(int processId, IUserDataFormatter formatter, params object[] passThruArguments) { var remoteInfo = new ManagedRemoteInfo { RemoteProcessId = processId }; var arguments = new List <object>(); if (passThruArguments != null) { foreach (var arg in passThruArguments) { using (var ms = new MemoryStream()) { formatter.Serialize(ms, arg); arguments.Add(ms.ToArray()); } } } remoteInfo.UserParams = arguments.ToArray(); return(remoteInfo); }
public InitiateUserAccountRecoveryViaEmailCommandHandler( CofoundryDbContext dbContext, IDomainRepository domainRepository, IMailService mailService, IUserAreaDefinitionRepository userAreaDefinitionRepository, IUserMailTemplateBuilderContextFactory userMailTemplateBuilderContextFactory, IUserMailTemplateBuilderFactory userMailTemplateBuilderFactory, IUserDataFormatter userDataFormatter, IMessageAggregator messageAggregator, IExecutionDurationRandomizerScopeManager taskDurationRandomizerScopeManager, IUserSummaryMapper userSummaryMapper ) { _dbContext = dbContext; _domainRepository = domainRepository; _mailService = mailService; _userAreaDefinitionRepository = userAreaDefinitionRepository; _userMailTemplateBuilderContextFactory = userMailTemplateBuilderContextFactory; _userMailTemplateBuilderFactory = userMailTemplateBuilderFactory; _userDataFormatter = userDataFormatter; _messageAggregator = messageAggregator; _executionDurationRandomizerScopeManager = taskDurationRandomizerScopeManager; _userSummaryMapper = userSummaryMapper; }
private static void LoadUserLibrary(Assembly assembly, object[] paramArray, string helperPipeName, IUserDataFormatter formatter) { Type entryPoint = FindEntryPoint(assembly); for (int i = 1; i < paramArray.Length; ++i) { using (Stream ms = new MemoryStream((byte[])paramArray[i])) { paramArray[i] = formatter.Deserialize <object>(ms); } } MethodInfo runMethod = FindMatchingMethod(entryPoint, EntryPointMethodName, paramArray); if (runMethod == null) { throw new MissingMethodException($"Failed to find the function 'Run' in {assembly.FullName}"); } var instance = InitializeInstance(entryPoint, paramArray); if (instance == null) { throw new MissingMethodException($"Failed to find the constructor {entryPoint.Name} in {assembly.FullName}"); } SendInjectionComplete(helperPipeName, Process.GetCurrentProcess().Id); try { // Execute the CoreHook plugin entry point runMethod.Invoke(instance, BindingFlags.Public | BindingFlags.Instance | BindingFlags.ExactBinding | BindingFlags.InvokeMethod, null, paramArray, null); } finally { Release(entryPoint); } }
/// <summary> /// Initialize the plugin dependencies and execute its entry point. /// </summary> /// <param name="remoteParameters">Parameters containing the plugin to load /// and the parameters to pass to it's entry point.</param> /// <returns>A status code representing the plugin initialization state.</returns> public static int Load(IntPtr remoteParameters) { try { if (remoteParameters == IntPtr.Zero) { throw new ArgumentOutOfRangeException(nameof(remoteParameters), "Remote arguments address was zero"); } // Extract the plugin initialization information // from the remote host loader arguments. IUserDataFormatter remoteInfoFormatter = CreateRemoteDataFormatter(); var pluginConfig = PluginConfiguration <RemoteEntryInfo, ManagedRemoteInfo> .LoadData( remoteParameters, remoteInfoFormatter ); // Start the IPC message notifier with a connection to the host application. var hostNotifier = new NotificationHelper(pluginConfig.RemoteInfo.ChannelName); hostNotifier.Log($"Initializing plugin: {pluginConfig.RemoteInfo.UserLibrary}."); IDependencyResolver resolver = CreateDependencyResolver( pluginConfig.RemoteInfo.UserLibrary); // Construct the parameter array passed to the plugin initialization function. var pluginParameters = new object[1 + pluginConfig.RemoteInfo.UserParams.Length]; hostNotifier.Log($"Initializing plugin with {pluginParameters.Length} parameter(s)."); pluginParameters[0] = pluginConfig.UnmanagedInfo; for (var i = 0; i < pluginConfig.RemoteInfo.UserParams.Length; ++i) { pluginParameters[i + 1] = pluginConfig.RemoteInfo.UserParams[i]; } hostNotifier.Log("Deserializing parameters."); DeserializeParameters(pluginParameters, remoteInfoFormatter); hostNotifier.Log("Successfully deserialized parameters."); // Execute the plugin library's entry point and pass in the user arguments. pluginConfig.State = LoadPlugin( resolver.Assembly, pluginParameters, hostNotifier); return((int)pluginConfig.State); } catch (ArgumentOutOfRangeException outOfRangeEx) { Log(outOfRangeEx.ToString()); throw; } catch (Exception e) { Log(e.ToString()); } return((int)PluginInitializationState.Failed); }