private Boolean ProcessCommand(PipeMessage msg) { var exit = false; var msgType = msg.GetType(); if (msgType.Equals(Constants.Token, StringComparison.OrdinalIgnoreCase)) { _metadataToken = Int32.Parse(msg.GetData()); } else if (msgType.Equals(Constants.Assembly, StringComparison.OrdinalIgnoreCase)) { _assemblyBuffer = Convert.FromBase64String(msg.GetData()); } else if (msgType.Equals(Constants.Dependency, StringComparison.OrdinalIgnoreCase)) { try { var assemblyBuffer = Convert.FromBase64String(msg.GetData()); var assembly = Assembly.Load(assemblyBuffer); if (!_dependencies.ContainsKey(assembly.FullName)) { _dependencies.Add(assembly.FullName, assembly); } } catch { _lastError = InjectionResult.InvalidAssemblyDependencyBuffer; } } else if (msgType.Equals(Constants.File, StringComparison.OrdinalIgnoreCase)) { try { var data = msg.GetData(); var indexOfPipe = data.IndexOf("|"); var filenameLength = Int32.Parse(data.Substring(0, indexOfPipe)); var filename = data.Substring(indexOfPipe + 1, filenameLength); var fileContent = Convert.FromBase64String(data.Substring(indexOfPipe + 1 + filenameLength)); File.WriteAllBytes(filename, fileContent); } catch { _lastError = InjectionResult.InvalidFileBuffer; } } else if (msgType.Equals(Constants.Run, StringComparison.OrdinalIgnoreCase)) { if (_assemblyBuffer == null) { _lastError = InjectionResult.InvalidAssemblyBuffer; } else { ActivateDll(); } exit = true; } return(exit); }
private Boolean ProcessCommand(PipeMessage msg) { var exit = false; var msgType = msg.GetType(); if (msgType.Equals(Constants.Token, StringComparison.OrdinalIgnoreCase)) { _metadataToken = Int32.Parse(msg.GetData()); } else if (msgType.Equals(Constants.Assembly, StringComparison.OrdinalIgnoreCase)) { _assemblyBuffer = Convert.FromBase64String(msg.GetData()); } else if (msgType.Equals(Constants.Dependency, StringComparison.OrdinalIgnoreCase)) { try { var assemblyBuffer = Convert.FromBase64String(msg.GetData()); var assembly = Assembly.Load(assemblyBuffer); if (!_dependencies.ContainsKey(assembly.FullName)) { _dependencies.Add(assembly.FullName, assembly); } } catch (Exception e) { _lastError = InjectionResult.InvalidAssemblyDependencyBuffer; _lastErrorMessage = e.ToString(); } } else if (msgType.Equals(Constants.File, StringComparison.OrdinalIgnoreCase)) { try { var data = msg.GetData(); var indexOfPipe = data.IndexOf("|"); var filenameLength = Int32.Parse(data.Substring(0, indexOfPipe)); var filename = data.Substring(indexOfPipe + 1, filenameLength); var fileContent = Convert.FromBase64String(data.Substring(indexOfPipe + 1 + filenameLength)); File.WriteAllBytes(filename, fileContent); } catch (Exception e) { _lastError = InjectionResult.InvalidFileBuffer; _lastErrorMessage = e.ToString(); } } else if (msgType.Equals(Constants.Context, StringComparison.OrdinalIgnoreCase)) { try { var dataString = msg.GetData(); var data = Convert.FromBase64String(dataString); var formatter = new BinaryFormatter(); using (var memStream = new MemoryStream(data)) { _context = formatter.Deserialize(memStream); } } catch (SerializationException e) { _lastError = InjectionResult.ErrorInContextDeSerialization; _lastErrorMessage = e.ToString(); } catch (Exception e) { _lastError = InjectionResult.UnknownError; _lastErrorMessage = e.ToString(); } } else if (msgType.Equals(Constants.Run, StringComparison.OrdinalIgnoreCase)) { if (_assemblyBuffer == null) { _lastError = InjectionResult.InvalidAssemblyBuffer; _lastErrorMessage = "Assembly bytes to inject not received"; } else { ActivateDll(_context); } exit = true; } return(exit); }