public RemoteMemoryProtection(RemoteProcess process, IntPtr pointer, int size, Natives.Enumerations.MemoryProtectionFlags newProtection) : base(process, pointer) { NewProtection = newProtection; Size = size; Natives.Enumerations.MemoryProtectionFlags oldProtection; Natives.Syscall.ProtectVirtualMemory(Process.ProcessHandle, Pointer, Size, NewProtection, out oldProtection); OldProtection = oldProtection; }
static void Main(string[] args) { Console.Title = "[MyMemory x64 Tester]"; Trace.Listeners.Add(new ConsoleTraceListener()); process = new RemoteProcess(); var processes = Process.GetProcessesByName("explorer"); if (processes.Length == 0) { Console.WriteLine("No explorer.exe found, wtf ?"); Console.ReadKey(); return; } var winProcess = processes.First(); Console.WriteLine("Using process \"{0}\" with PID {1}", winProcess.ProcessName, winProcess.Id); Console.WriteLine("Press any key to start testing ..." + Environment.NewLine); Console.ReadKey(); Console.WriteLine("+ - - - - - - - - - - - - - - - -"); Console.WriteLine("| Process manipulation"); Console.WriteLine("+ - - - - - - - - - - - - - - - -"); Console.WriteLine(); if (Program.process.Open((uint)winProcess.Id)) { Console.WriteLine("OpenProcess ... [SUCCESS]"); Console.WriteLine("ProcessHandle : 0x{0}", process.ProcessHandle.ToString("X")); Console.WriteLine("ImageBase : 0x{0}", process.ImageBase.ToString("X")); Console.WriteLine("ProcessEnvironmentBlock : 0x{0}", process.ProcessEnvironmentBlock.Pointer.ToString("X")); BasicMemoryTests(); BasicThreadsTests(); } else { Console.WriteLine("OpenProcess ... [FAIL]"); } Console.WriteLine(Environment.NewLine + "Press any key to exit"); Console.ReadKey(); }
/// <summary> /// Get File Content /// (Note that file path must be absolute path) /// (Note that file path should not have double quote in general, but it has escaped the double quote to be convenient). /// </summary> /// <param name="filePath">File Path</param> /// <param name="collectedData">Collected Result.</param> /// <returns></returns> private ResultCodes GetFileContent(string filePath, out string collectedData) { collectedData = string.Empty; ResultCodes resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_ACCESS_FILE_PROPERTY; if (!m_connection.ContainsKey(@"TemporaryDirectory")) { m_connection[@"TemporaryDirectory"] = @"%TMP%"; } else { if (!m_connection[@"TemporaryDirectory"].Equals(@"%TMP%")) { if (!Lib.ValidateDirectory(m_taskId, m_connection[@"TemporaryDirectory"].ToString(), m_cimvScope)) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Temporary directory {1} is not valid.", m_taskId, m_connection[@"TemporaryDirectory"].ToString()); resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; //@TODO: change to RC_TEMP_DIRECTORY_NOT_EXIST } else { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: User specified temp directory has been validated.", m_taskId); } } } if (filePath.EndsWith("\"") && filePath.StartsWith("\"")) { filePath = filePath.Substring(1, filePath.Length - 2); } if (Lib.ValidateFile(m_taskId, filePath, m_cimvScope)) { using (IRemoteProcess rp = RemoteProcess.GetRemoteFile(m_taskId, m_cimvScope, filePath, m_connection, m_tftpPath, m_tftpPath_login, m_tftpPath_password, m_tftpDispatcher)) { // // Launch the remote process. // This method will block until the entire remote process operation completes. resultCode = rp.Launch(); Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Remote file retrieval operation completed with result code {1}.", m_taskId, resultCode.ToString()); collectedData = rp.Stdout.ToString(); } } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: filepath: {1} does not exist.", m_taskId, filePath); } return(resultCode); }
public MarshalledValue(RemoteProcess process, T value) { m_Process = process; Value = value; Marshal(); }
public RemoteDebugger(RemoteProcess process) { Contract.Requires(process != null); this.process = process; }
/// <summary> /// Perform collection task specific processing. /// </summary> /// /// <param name="taskId">Database assigned task Id.</param> /// <param name="cleId">Database Id of owning Collection Engine.</param> /// <param name="elementId">Database Id of element being collected.</param> /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param> /// <param name="localTimestamp">Local task dispatch timestamp.</param> /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param> /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param> /// <param name="connection">Connection script results (null if this script does not /// require a remote host connection).</param> /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param> /// <returns>Collection results.</returns> public CollectionScriptResults ExecuteTask(long taskId, long cleId, long elementId, long databaseTimestamp, long localTimestamp, IDictionary <string, string> attributes, IDictionary <string, string> scriptParameters, IDictionary <string, object> connection, string tftpPath, string tftpPath_login, string tftpPath_password, ITftpDispatcher tftpDispatcher) { m_taskId = taskId.ToString(); m_cleId = cleId; m_elementId = elementId; m_databaseTimestamp = databaseTimestamp; m_localTimestamp = localTimestamp; m_attributes = attributes; m_scriptParameters = scriptParameters; m_tftpDispatcher = tftpDispatcher; m_tftpPath = tftpPath; m_tftpPath_login = tftpPath_login; m_tftpPath_password = tftpPath_password; m_connection = connection; m_executionTimer = Stopwatch.StartNew(); ResultCodes resultCode = ResultCodes.RC_SUCCESS; Lib.Logger.TraceEvent(TraceEventType.Start, 0, "Task Id {0}: Collection script MSVirtualServerVMConfigFileContentScript.", m_taskId); try { // Check ManagementScope CIMV if (connection == null) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection object passed to MSVirtualServerVMConfigFileContentScript is null.", m_taskId); } else if (!connection.ContainsKey("cimv2")) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Management scope for CIMV namespace is not present in connection object.", m_taskId); } else { m_cimvScope = connection[@"cimv2"] as ManagementScope; if (!m_cimvScope.IsConnected) { resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection to CIMV namespace failed", m_taskId); } } //Check VM Config File Path attribute if (scriptParameters.ContainsKey("vmcFile")) { m_vmcFilePath = scriptParameters[@"vmcFile"]; } else { resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing parameter VM Config File Path attribute.", m_taskId); } // Check Remote Process Temp Directory if (!m_connection.ContainsKey(@"TemporaryDirectory")) { m_connection[@"TemporaryDirectory"] = @"%TMP%"; } else { if (!m_connection[@"TemporaryDirectory"].Equals(@"%TMP%")) { if (!Lib.ValidateDirectory(m_taskId, m_connection[@"TemporaryDirectory"].ToString(), m_cimvScope)) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Temporary directory {1} is not valid.", m_taskId, m_connection[@"TemporaryDirectory"].ToString()); resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; //@TODO: change to RC_TEMP_DIRECTORY_NOT_EXIST } else { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: User specified temp directory has been validated.", m_taskId); } } } if (resultCode == ResultCodes.RC_SUCCESS) { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Attempting to retrieve file {1}.", m_taskId, m_vmcFilePath); StringBuilder fileContent = new StringBuilder(); if (Lib.ValidateFile(m_taskId, m_vmcFilePath, m_cimvScope)) { using (IRemoteProcess rp = RemoteProcess.GetRemoteFile(m_taskId, m_cimvScope, m_vmcFilePath, m_connection, m_tftpPath, m_tftpPath_login, m_tftpPath_password, m_tftpDispatcher)) { // // Launch the remote process. // This method will block until the entire remote process operation completes. rp.Encoding = Encoding.Unicode; resultCode = rp.Launch(); Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Remote file retrieval operation completed with result code {1}.", m_taskId, resultCode.ToString()); fileContent.Append(rp.Stdout); } //Console.WriteLine(fileContent.ToString()); string formattedFile = fileContent.ToString().Substring(1); StringBuilder fileData = getVMData(formattedFile); this.BuildDataRow(@"vmcFileData", fileData.ToString()); } else { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: VM Config file {1} does not exist.", m_taskId, m_vmcFilePath); resultCode = ResultCodes.RC_SUCCESS; //@TODO: change to RC_REMOTE_FILE_NOT_EXISTED //resultCode = ResultCodes.RC_PROCESSING_EXCEPTION; //@TODO: change to RC_REMOTE_FILE_NOT_EXISTED } } } catch (Exception ex) { if (ResultCodes.RC_SUCCESS == resultCode) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in MSVirtualServerVMConfigFileContentScript. Elapsed time {1}.\n{2}Result code changed to RC_PROCESSING_EXECEPTION.", m_taskId, m_executionTimer.Elapsed.ToString(), ex.ToString()); resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_READ_REMOTE_FILE; } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in MSVirtualServerVMConfigFileContentScript. Elapsed time {1}.\n{2}", m_taskId, m_executionTimer.Elapsed.ToString(), ex.ToString()); } } Lib.Logger.TraceEvent(TraceEventType.Stop, 0, "Task Id {0}: Collection script MSVirtualServerVMConfigFileContentScript. Elapsed time {1}. Result code {2}.", m_taskId, m_executionTimer.Elapsed.ToString(), resultCode.ToString()); return(new CollectionScriptResults (resultCode, 0, null, null, null, false, m_dataRow.ToString())); }
/// <summary> /// Perform collection task specific processing. /// </summary> /// /// <param name="taskId">Database assigned task Id.</param> /// <param name="cleId">Database Id of owning Collection Engine.</param> /// <param name="elementId">Database Id of element being collected.</param> /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param> /// <param name="localTimestamp">Local task dispatch timestamp.</param> /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param> /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param> /// <param name="connection">Connection script results (null if this script does not /// require a remote host connection).</param> /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param> /// <returns>Collection results.</returns> public CollectionScriptResults ExecuteTask(long taskId, long cleId, long elementId, long databaseTimestamp, long localTimestamp, IDictionary <string, string> attributes, IDictionary <string, string> scriptParameters, IDictionary <string, object> connection, string tftpPath, string tftpPath_login, string tftpPath_password, ITftpDispatcher tftpDispatcher) { m_taskId = taskId.ToString(); m_cleId = cleId; m_elementId = elementId; m_databaseTimestamp = databaseTimestamp; m_localTimestamp = localTimestamp; m_attributes = attributes; m_scriptParameters = scriptParameters; m_tftpDispatcher = tftpDispatcher; m_tftpPath = tftpPath; m_tftpPath_login = tftpPath_login; m_tftpPath_password = tftpPath_password; m_connection = connection; m_executionTimer = Stopwatch.StartNew(); ResultCodes resultCode = ResultCodes.RC_SUCCESS; Lib.Logger.TraceEvent(TraceEventType.Start, 0, "Task Id {0}: Collection script WinFileContentScript.", m_taskId); try { // Check ManagementScope CIMV if (connection == null) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection object passed to VMWareVMXConfigFileContentScript is null.", m_taskId); } else if (!connection.ContainsKey("cimv2")) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Management scope for CIMV namespace is not present in connection object.", m_taskId); } else { m_cimvScope = connection[@"cimv2"] as ManagementScope; if (!m_cimvScope.IsConnected) { resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection to CIMV namespace failed", m_taskId); } } string filePath = string.Empty; foreach (KeyValuePair <string, string> kvp in scriptParameters) { string key = kvp.Key; if (key.Contains(":")) { int i = key.IndexOf(':'); key = key.Substring(i + 1); } if (key == @"filePath") { filePath = kvp.Value; } } if (string.IsNullOrEmpty(filePath)) { resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task id {0}: Missing file path parameter.", m_taskId); } // Check Remote Process Temp Directory if (!m_connection.ContainsKey(@"TemporaryDirectory")) { m_connection[@"TemporaryDirectory"] = @"%TMP%"; } else { if (!m_connection[@"TemporaryDirectory"].Equals(@"%TMP%")) { if (!Lib.ValidateDirectory(m_taskId, m_connection[@"TemporaryDirectory"].ToString(), m_cimvScope)) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Temporary directory {1} is not valid.", m_taskId, m_connection[@"TemporaryDirectory"].ToString()); resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; //@TODO: change to RC_TEMP_DIRECTORY_NOT_EXIST } else { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: User specified temp directory has been validated.", m_taskId); } } } if (resultCode == ResultCodes.RC_SUCCESS) { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Attempting to retrieve file {1}.", m_taskId, m_FilePath); StringBuilder fileContent = new StringBuilder(); if (Lib.ValidateFile(m_taskId, filePath, m_cimvScope)) { using (IRemoteProcess rp = RemoteProcess.GetRemoteFile(m_taskId, m_cimvScope, filePath, m_connection, m_tftpPath, m_tftpPath_login, m_tftpPath_password, m_tftpDispatcher)) { // // Launch the remote process. // This method will block until the entire remote process operation completes. resultCode = rp.Launch(); Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Remote file retrieval operation completed with result code {1}.", m_taskId, resultCode.ToString()); fileContent.Append(rp.Stdout); } this.BuildDataRow(@"fileContent", fileContent.ToString()); } else { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: file {1} does not exist.", m_taskId, filePath); //resultCode = ResultCodes.RC_SUCCESS; } } } catch (ManagementException me) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Insufficient privilege to read file.\nMessage: {1}", m_taskId, me.Message); if (me.InnerException != null) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Inner Exception Message: {1}.", m_taskId, me.InnerException.Message); } resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_READ_REMOTE_FILE; } catch (COMException ce) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Not enough privilege to access run WMI query.\nMessage: {1}.", m_taskId, ce.Message); if (ce.InnerException != null) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Inner Exception Message: {1}.", m_taskId, ce.InnerException.Message); } resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_RUN_WMI_QUERY; } catch (Exception ex) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in WinFileContentScript. Elapsed time {1}.\n{2}", m_taskId, m_executionTimer.Elapsed.ToString(), ex.ToString()); resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_READ_REMOTE_FILE; } Lib.Logger.TraceEvent(TraceEventType.Stop, 0, "Task Id {0}: Collection script VMWareVMXConfigFileContentScript. Elapsed time {1}. Result code {2}.", m_taskId, m_executionTimer.Elapsed.ToString(), resultCode.ToString()); return(new CollectionScriptResults (resultCode, 0, null, null, null, false, m_dataRow.ToString())); }
/// <summary> /// Constructor with module base address /// </summary> /// <param name="process"></param> /// <param name="baseAddress"></param> public RemoteModule(RemoteProcess process, IntPtr baseAddress) : base(process, baseAddress) { ModuleInfo = process.ProcessEnvironmentBlock.GetModule(baseAddress); }
/// <summary> /// Perform collection task specific processing. /// </summary> /// /// <param name="taskId">Database assigned task Id.</param> /// <param name="cleId">Database Id of owning Collection Engine.</param> /// <param name="elementId">Database Id of element being collected.</param> /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param> /// <param name="localTimestamp">Local task dispatch timestamp.</param> /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param> /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param> /// <param name="connection">Connection script results (null if this script does not /// require a remote host connection).</param> /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param> /// /// <returns>Collection results.</returns> public CollectionScriptResults ExecuteTask( long taskId, long cleId, long elementId, long databaseTimestamp, long localTimestamp, IDictionary <string, string> attributes, IDictionary <string, string> scriptParameters, IDictionary <string, object> connection, string tftpPath, string tftpPath_login, string tftpPath_password, ITftpDispatcher tftpDispatcher) { m_executionTimer = Stopwatch.StartNew(); m_taskId = taskId.ToString(); m_cleId = cleId; m_elementId = elementId; m_databaseTimestamp = databaseTimestamp; m_localTimestamp = localTimestamp; m_attributes = attributes; m_scriptParameters = scriptParameters; ResultCodes resultCode = ResultCodes.RC_SUCCESS; Lib.Logger.TraceEvent(TraceEventType.Start, 0, "Task Id {0}: Collection script WindowsWASIsInstanceRunningScript.", m_taskId); try { // Check ManagementScope CIMV ManagementScope cimvScope = null; if (connection == null) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection object passed to WindowsWASIsInstanceRunningScript is null.", m_taskId); } else if (!connection.ContainsKey("cimv2")) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Management scope for CIMV namespace is not present in connection object.", m_taskId); } else { cimvScope = connection[@"cimv2"] as ManagementScope; if (!cimvScope.IsConnected) { resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection to CIMV namespace failed.", m_taskId); } } //Check WAS Profile path attribute if (!scriptParameters.ContainsKey("installDirectory")) { resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing Profile Path Script parameter.", m_taskId); } else { m_installHome = scriptParameters[@"installDirectory"]; } //Check Server Name attribute if (!scriptParameters.ContainsKey("appsrv_Name")) { resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing Server Name script parameter.", m_taskId); } else { m_server = scriptParameters[@"appsrv_Name"]; } // Check Remote Process Temp Directory if (!connection.ContainsKey(@"TemporaryDirectory")) { connection[@"TemporaryDirectory"] = @"%TMP%"; } else { if (!connection[@"TemporaryDirectory"].Equals(@"%TMP%")) { if (!Lib.ValidateDirectory(m_taskId, connection[@"TemporaryDirectory"].ToString(), cimvScope)) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Temporary directory {1} is not valid.", m_taskId, connection[@"TemporaryDirectory"].ToString()); resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; //@TODO: change to RC_TEMP_DIRECTORY_NOT_EXIST } else { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Temporary directory {1} has been validated.", m_taskId, connection[@"TemporaryDirectory"].ToString()); } } } if (resultCode == ResultCodes.RC_SUCCESS) { // EXTRA code for wsadmin string strTempDir = connection["TemporaryDirectory"].ToString().Trim(); if (strTempDir.EndsWith(@"\")) { strTempDir = strTempDir.Substring(0, strTempDir.Length - 1); } string running = "False"; //string batchFile = m_profilePath.Trim() + @"\bin\serverStatus.bat " + m_server + @" -user bdna -password bdna"; string s1 = m_installHome.Trim(); string s2 = s1.Replace(" ", "^ "); string batchFile = s2 + @"\bin\serverStatus.bat " + m_server; //Console.WriteLine(batchFile); using (IRemoteProcess rp = RemoteProcess.ExecuteBatchFile(m_taskId, cimvScope, batchFile.ToString(), connection, tftpPath, tftpPath_login, tftpPath_password, tftpDispatcher)) { //This method will block until the entire remote process operation completes. resultCode = rp.Launch(); Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Remote process operation completed with result code {1}.", m_taskId, resultCode.ToString()); string[] arrOutputLine = rp.Stdout.ToString().Split("\r\n".ToCharArray()); for (int i = 0; i < arrOutputLine.Length; i++) { string output = arrOutputLine[i]; if (s_instanceRegex.IsMatch(output)) { Match match = s_instanceRegex.Match(output); string name = match.Groups["server"].ToString(); if (string.Equals(m_server, name)) { running = "True"; } } } } //Console.WriteLine(running); m_dataRow.Append(m_elementId).Append(',') .Append(m_attributes["appSrv_isRunning"]).Append(',') .Append(m_scriptParameters["CollectorId"]).Append(',') .Append(m_taskId).Append(',') .Append(m_databaseTimestamp + m_executionTimer.ElapsedMilliseconds).Append(',') .Append("appSrv_isRunning").Append(',') .Append(BdnaDelimiters.BEGIN_TAG).Append(running).Append(BdnaDelimiters.END_TAG); } } catch (Exception ex) { if (ResultCodes.RC_SUCCESS == resultCode) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in WindowsWASIsInstanceRunningScript. Elapsed time {1}.\n{2}\nResult code changed to RC_PROCESSING_EXCEPTION.", m_taskId, m_executionTimer.Elapsed.ToString(), ex.ToString()); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in WindowsWASIsInstanceRunningScript. Elapsed time {1}.\n{2}", m_taskId, m_executionTimer.Elapsed.ToString(), ex.ToString()); } } Lib.Logger.TraceEvent(TraceEventType.Stop, 0, "Task Id {0}: Collection script WindowsWASIsInstanceRunningScript. Elapsed time {1}. Result code {2}.", m_taskId, m_executionTimer.Elapsed.ToString(), resultCode.ToString()); return(new CollectionScriptResults(resultCode, 0, null, null, null, false, m_dataRow.ToString())); }
/// <summary> /// Spawn a remote process to execute the L3 validation /// batch file and process the results. /// </summary> /// /// <param name="scope">WMI connection to target host.</param> /// <param name="batchFile">Batch file contents to execute.</param> /// <param name="schemaName">Schema name to validate.</param> /// <param name="scriptParameters">Script parameters to use (contains temporary directory /// parameter).</param> /// <param name="tftpDispatcher">TFTP dispatcher singleton.</param> /// /// <returns>Operation result code.</returns> private ResultCodes ExecuteRemoteProcess( ManagementScope scope, string batchFile, string schemaName, IDictionary <string, object> scriptParameters, string tftpPath, string tftpPath_login, string tftpPath_password, ITftpDispatcher tftpDispatcher) { ResultCodes resultCode = ResultCodes.RC_SUCCESS; string stdout = String.Empty; Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Attempt to establish L3 connection using {1}.", m_taskId, schemaName); using (IRemoteProcess rp = RemoteProcess.ExecuteBatchFile(m_taskId, scope, batchFile, scriptParameters, tftpPath, tftpPath_login, tftpPath_password, tftpDispatcher)) { Stopwatch sw = Stopwatch.StartNew(); resultCode = rp.Launch(); Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Remote process operation completed with result code {1}. Elapsed time {2}.", m_taskId, resultCode.ToString(), sw.Elapsed.ToString()); stdout = rp.Stdout.ToString(); if (ResultCodes.RC_SUCCESS == resultCode) { if (null != stdout && 0 < stdout.Length) { if (stdout.Contains("ORA-01017")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Oracle L3 credential invalid.\nResult code changed to RC_PROCESSING_EXCEPTION.\nSTDOUT/STDERR:\n{1}", m_taskId, stdout); resultCode = ResultCodes.RC_HOST_CONNECT_FAILED; } else if (stdout.Contains("ERROR-")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Batch file execution exception.\nResult code changed to RC_PROCESSING_EXCEPTION.\nSTDOUT/STDERR:\n{1}", m_taskId, stdout); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; } else if (!stdout.Contains(@"BDNA")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: SQLPLUS exception, no proper data returned.\nResult code changed to RC_PROCESSING_EXCEPTION.\nSTDOUT/STDERR:\n{1}", m_taskId, stdout); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; } else if (!stdout.Contains(@"Execution completed")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Exception with batch file return data.\nData returned is shorter than expected, possibly due to transfer failure.\nResult code changed to RC_PROCESSING_EXCEPTION.", m_taskId); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; } } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: No data returned.\nResult code changed to RC_PROCESSING_EXCEPTION.", m_taskId); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; } } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Remote execution error.\n{1}", m_taskId, stdout); } } if (ResultCodes.RC_SUCCESS == resultCode) { // // If we didn't get the output expected from execution // of the batch file. Force the result code to some // error value so that we try the next credential set. if (0 >= stdout.Length || !s_bdnaRegex.IsMatch(stdout)) { resultCode = ResultCodes.RC_LOGIN_FAILED; // @todo Did login really fail? Perhaps this s/b processing exception } } return(resultCode); }
/// <summary> /// Constructor with internal ModuleInfo structure /// </summary> /// <param name="process"></param> /// <param name="moduleInfo"></param> public RemoteModule(RemoteProcess process, ModuleInfo moduleInfo) : base(process, moduleInfo.BaseAddress) { ModuleInfo = moduleInfo; }
private static int ForceProcessKill(RemoteProcess process) { Console.Error.WriteLine("Killing applicationon {0} in the emulator...", process.FileName); process.Kill(); return EmulatorProcessKilled; }
private static int WaitToFinishOrTimeout(RemoteProcess process, TimeSpan timeout) { Stopwatch timer = new Stopwatch(); timer.Start(); while (!process.HasExited() && timer.Elapsed < timeout) { Thread.Sleep(2000); } return !process.HasExited() ? ForceProcessKill(process) : process.GetExitCode(); }
public RemoteAllocatedMemory(RemoteProcess memory, IntPtr pointer, int size) : base(memory, pointer) { Size = size; }
public bool Set(RemoteProcess process) { Contract.Requires(process != null); throw new NotImplementedException(); }
/// <summary> /// Execute an arbitrary command remotely. /// </summary> /// /// <param name="taskId">Database assigned task Id.</param> /// <param name="cleId">Database Id of owning Collection Engine.</param> /// <param name="elementId">Database Id of element being collected.</param> /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param> /// <param name="localTimestamp">Local task dispatch timestamp.</param> /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param> /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param> /// <param name="connection">Connection script results (null if this script does not /// require a remote host connection).</param> /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param> /// <returns>Collection results.</returns> public CollectionScriptResults ExecuteTask( long taskId, long cleId, long elementId, long databaseTimestamp, long localTimestamp, IDictionary <string, string> attributes, IDictionary <string, string> scriptParameters, IDictionary <string, object> connection, string tftpPath, string tftpPath_login, string tftpPath_password, ITftpDispatcher tftpDispatcher) { m_taskId = taskId.ToString(); m_executionTimer = Stopwatch.StartNew(); string commandLine = string.Empty; //string returnAttribute = null; string returnAttribute = string.Empty; ResultCodes resultCode = ResultCodes.RC_PROCESSING_EXCEPTION; Lib.Logger.TraceEvent(TraceEventType.Start, 0, "Task Id {0}: Collection script NTPTimeServerCollectionScript.", m_taskId); try { // Check ManagementScope CIMV ManagementScope cimvScope = null; if (connection == null) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection object passed to NTPTimeServerCollectionScript is null.", m_taskId); } else if (!connection.ContainsKey("cimv2")) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Management scope for CIMV namespace is not present in connection object.", m_taskId); } else { cimvScope = connection[@"cimv2"] as ManagementScope; if (!cimvScope.IsConnected) { resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection to CIMV namespace failed", m_taskId); } // We have to massage the script parameter set, replace // any keys with a colon by just the part after the colon. Dictionary <string, string> d = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> kvp in scriptParameters) { string[] sa = kvp.Key.Split(s_collectionParameterSetDelimiter, StringSplitOptions.RemoveEmptyEntries); Debug.Assert(sa.Length > 0); d[sa[sa.Length - 1]] = kvp.Value; } scriptParameters = d; //Check input parameter and set what output attribute to return if (scriptParameters.ContainsKey("ntpW32tmCmd")) { commandLine = scriptParameters[@"ntpW32tmCmd"]; returnAttribute = "ntpServer"; } else { resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing script parameter.", m_taskId); } //Check commandLine parameter if (string.IsNullOrEmpty(commandLine)) { resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing command Line parameter.", m_taskId); } else { // Check working and temporary directory parameter if (!connection.ContainsKey(@"WorkingDirectory") || string.IsNullOrEmpty(connection[@"WorkingDirectory"].ToString())) { connection[@"WorkingDirectory"] = @"%TMP%"; } if (!connection.ContainsKey(@"TemporaryDirectory") || string.IsNullOrEmpty(connection[@"TemporaryDirectory"].ToString())) { connection[@"TemporaryDirectory"] = @"%TMP%"; } Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Attempting to retrieve command output {1}.", m_taskId, commandLine); String batchFileContent = this.BuildBatchFile(connection[@"WorkingDirectory"].ToString(), commandLine); String collectedData = ""; using (IRemoteProcess rp = RemoteProcess.ExecuteBatchFile( m_taskId, // Task Id to log against. cimvScope, // assuming Remote process uses cimv2 management scope batchFileContent, // batch file connection, // connection dictionary. tftpPath, tftpPath_login, tftpPath_password, tftpDispatcher)) { //This method will block until the entire remote process operation completes. resultCode = rp.Launch(); Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Batch file executed completed with result code {1}.", m_taskId, resultCode.ToString()); if (resultCode == ResultCodes.RC_SUCCESS) { collectedData = rp.Stdout.ToString(); if (string.IsNullOrEmpty(collectedData)) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Script completed sucessfully with no data to return.", m_taskId); resultCode = ResultCodes.RC_PROCESSING_EXCEPTION; } else if (!collectedData.Contains(@"Execution completed")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Exception with batch file return data.\nData returned is shorter than expected, possibly due to transfer failure.\nResult code changed to RC_REMOTE_COMMAND_EXECUTION_ERROR. Partial result: {1}", m_taskId, collectedData); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; } else { collectedData = collectedData.Substring(0, collectedData.Length - @"Execution completed.\r\n".Length); string strFormattedString = this.formatCommandResult(collectedData.ToString()); m_outputData.Append(elementId).Append(',') .Append(attributes[returnAttribute]).Append(',') .Append(scriptParameters[@"CollectorId"]).Append(',') .Append(m_taskId).Append(',') .Append(databaseTimestamp + m_executionTimer.ElapsedMilliseconds).Append(',') .Append(returnAttribute).Append(',') //.Append(BdnaDelimiters.BEGIN_TAG).Append(collectedData).Append(BdnaDelimiters.END_TAG); .Append(BdnaDelimiters.BEGIN_TAG).Append(strFormattedString).Append(BdnaDelimiters.END_TAG); } } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Error during command execution. Elapsed time {1}. Result code {2}.", m_taskId, m_executionTimer.Elapsed.ToString(), resultCode); } } } } } catch (Exception ex) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in NTPTimeServerCollectionScript. Elapsed time {1}.\n{2}", m_taskId, m_executionTimer.Elapsed.ToString(), ex.ToString()); } Lib.Logger.TraceEvent(TraceEventType.Stop, 0, "Task Id {0}: Collection script NTPTimeServerCollectionScript. Elapsed time {1}. Result code {2}.", m_taskId, m_executionTimer.Elapsed.ToString(), resultCode); return(new CollectionScriptResults (resultCode, 0, null, null, null, false, m_outputData.ToString())); }
public ImageExportDirectory(RemoteProcess process, IntPtr address) : base(process, address) { }
/// <summary> /// Perform collection task specific processing. /// </summary> /// /// <param name="taskId">Database assigned task Id.</param> /// <param name="cleId">Database Id of owning Collection Engine.</param> /// <param name="elementId">Database Id of element being collected.</param> /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param> /// <param name="localTimestamp">Local task dispatch timestamp.</param> /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param> /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param> /// <param name="connection">Connection script results (null if this script does not /// require a remote host connection).</param> /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param> /// /// <returns>Collection results.</returns> public CollectionScriptResults ExecuteTask( long taskId, long cleId, long elementId, long databaseTimestamp, long localTimestamp, IDictionary <string, string> attributes, IDictionary <string, string> scriptParameters, IDictionary <string, object> connection, string tftpPath, string tftpPath_login, string tftpPath_password, ITftpDispatcher tftpDispatcher) { m_taskId = taskId.ToString(); m_cleId = cleId; m_elementId = elementId; m_databaseTimestamp = databaseTimestamp; m_localTimestamp = localTimestamp; m_attributes = attributes; m_scriptParameters = scriptParameters; m_connection = connection; string strHostName = null, strDBName = null, strOracleHome = null, strSchemaName = null, strSchemaPassword = null; m_executionTimer = Stopwatch.StartNew(); ResultCodes resultCode = ResultCodes.RC_SUCCESS; Lib.Logger.TraceEvent(TraceEventType.Start, 0, "Task Id {0}: Collection script WindowsOracleInstanceLMSOptions7StaticScript.", m_taskId); try { // Check ManagementScope CIMV ManagementScope cimvScope = null; if (connection == null) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection object passed to WindowsOracleInstanceLMSOptions7StaticScript is null.", m_taskId); } else if (!connection.ContainsKey("cimv2")) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Management scope for CIMV namespace is not present in connection object.", m_taskId); } else { cimvScope = connection[@"cimv2"] as ManagementScope; if (!cimvScope.IsConnected) { resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection to CIMV namespace failed", m_taskId); } } if (!scriptParameters.ContainsKey("version")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing script parameter \"version\".", m_taskId); resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; } else { m_strVersion = scriptParameters["version"].Trim(); } if (!scriptParameters.ContainsKey("OracleHome")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing script parameter \"OracleHome\".", m_taskId); resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; } else { strOracleHome = scriptParameters["OracleHome"].Trim(); if (strOracleHome.EndsWith(@"\")) { strOracleHome = strOracleHome.Substring(0, strOracleHome.Length - 1); } } if (!connection.ContainsKey("schemaName")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing script parameter \"schemaName\".", m_taskId); resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; } else { strSchemaName = connection["schemaName"].ToString().Trim(); } if (!connection.ContainsKey("schemaPassword")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing script parameter \"schemaPassword\".", m_taskId); resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; } else { strSchemaPassword = connection["schemaPassword"].ToString().Trim(); } if (ResultCodes.RC_SUCCESS == resultCode) { // Check Remote Process Temp Directory if (!connection.ContainsKey("TemporaryDirectory")) { connection["TemporaryDirectory"] = @"%TMP%"; } else { if (!m_connection[@"TemporaryDirectory"].Equals(@"%TMP%")) { if (!Lib.ValidateDirectory(m_taskId, m_connection[@"TemporaryDirectory"].ToString(), cimvScope)) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Temporary directory {1} is not valid.", m_taskId, connection[@"TemporaryDirectory"].ToString()); resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; //@TODO: change to RC_TEMP_DIRECTORY_NOT_EXIST } else { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Temporary directory {1} has been validated.", m_taskId, connection[@"TemporaryDirectory"].ToString()); } } } } if (resultCode == ResultCodes.RC_SUCCESS) { string strTempDir = connection["TemporaryDirectory"].ToString().Trim(); if (strTempDir.EndsWith(@"\")) { strTempDir = strTempDir.Substring(0, strTempDir.Length - 1); } Console.WriteLine("Temp directory is " + strTempDir); string strBatchFileContent = buildBatchFile(strTempDir, strHostName, strDBName, strOracleHome, strSchemaName, strSchemaPassword); StringBuilder stdoutData = new StringBuilder(); using (IRemoteProcess rp = RemoteProcess.ExecuteBatchFile (m_taskId, cimvScope, strBatchFileContent, connection, tftpPath, tftpPath_login, tftpPath_password, tftpDispatcher)) { //This method will block until the entire remote process operation completes. resultCode = rp.Launch(); Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Remote process operation completed with result code {1}.", m_taskId, resultCode.ToString()); if (resultCode == ResultCodes.RC_SUCCESS) { stdoutData.Append(rp.Stdout); if (rp.Stdout != null && rp.Stdout.Length > 0) { if (rp.Stdout.ToString().Contains("ORA-01017")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Oracle L3 credential is invalid.\nResult code changed to RC_PROCESSING_EXCEPTION.\nSTDOUT/STDERR:\n{1}", m_taskId, rp.Stdout.ToString()); resultCode = ResultCodes.RC_HOST_CONNECT_FAILED; } else if (rp.Stdout.ToString().Contains("ERROR-")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Batch file execution exception.\nResult code changed to RC_PROCESSING_EXCEPTION.\nSTDOUT/STDERR:\n{1}", m_taskId, rp.Stdout.ToString()); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; //} else if (!rp.Stdout.ToString().Contains(@"BDNA")) { // Lib.Logger.TraceEvent(TraceEventType.Error, // 0, // "Task Id {0}: SQLPLUS exception, no proper data returned.\nResult code changed to RC_PROCESSING_EXCEPTION.\nSTDOUT/STDERR:\n{1}", // m_taskId, // rp.Stdout.ToString()); // resultCode = ResultCodes.RC_PROCESSING_EXCEPTION; } else if (!rp.Stdout.ToString().Contains(@"Execution completed")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Exception with batch return data.\nData returned is shorter than expected, possibly due to transfer failure.\nResult code changed to RC_PROCESSING_EXCEPTION.", m_taskId); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; } } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: No data returned.\nResult code changed to RC_PROCESSING_EXCEPTION.", m_taskId); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; } } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Remote execution error.\nSTDOUT.STDERR:\n{1}", m_taskId, rp.Stdout.ToString()); } } if (resultCode == ResultCodes.RC_SUCCESS && stdoutData.Length > 0) { foreach (KeyValuePair <string, QueryTableEntry> entry in s_queryTable) { entry.Value.ResultHandler(this, entry.Key, stdoutData.ToString()); } foreach (KeyValuePair <string, string> kvp in m_collectedData) { this.BuildDataRow(kvp.Key, kvp.Value); } //Console.WriteLine(CollectedData[@"owbInstalled"]); } } } catch (Exception ex) { if (ResultCodes.RC_SUCCESS == resultCode) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in WindowsOracleInstanceLMSOptions7StaticScript. Elapsed time {1}.\n{2}\nResult code changed to RC_PROCESSING_EXCEPTION.", m_taskId, m_executionTimer.Elapsed.ToString(), ex.ToString()); resultCode = ResultCodes.RC_PROCESSING_EXCEPTION; } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in WindowsOracleInstanceLMSOptions7StaticScript. Elapsed time {1}.\n{2}", m_taskId, m_executionTimer.Elapsed.ToString(), ex.ToString()); } } resultCode = ResultCodes.RC_SUCCESS; Lib.Logger.TraceEvent(TraceEventType.Stop, 0, "Task Id {0}: Collection script WindowsOracleInstanceLMSOptions7StaticScript. Elapsed time {1}. Result code {2}.", m_taskId, m_executionTimer.Elapsed.ToString(), resultCode.ToString()); return(new CollectionScriptResults(resultCode, 0, null, null, null, false, m_dataRow.ToString())); }
/// <summary> /// Perform collection task specific processing. /// </summary> /// /// <param name="taskId">Database assigned task Id.</param> /// <param name="cleId">Database Id of owning Collection Engine.</param> /// <param name="elementId">Database Id of element being collected.</param> /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param> /// <param name="localTimestamp">Local task dispatch timestamp.</param> /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param> /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param> /// <param name="connection">Connection script results (null if this script does not /// require a remote host connection).</param> /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param> /// /// <returns>Collection results.</returns> public CollectionScriptResults ExecuteTask( long taskId, long cleId, long elementId, long databaseTimestamp, long localTimestamp, IDictionary <string, string> attributes, IDictionary <string, string> scriptParameters, IDictionary <string, object> connection, string tftpPath, string tftpPath_login, string tftpPath_password, ITftpDispatcher tftpDispatcher) { m_executionTimer = Stopwatch.StartNew(); m_taskId = taskId.ToString(); m_cleId = cleId; m_elementId = elementId; m_databaseTimestamp = databaseTimestamp; m_localTimestamp = localTimestamp; m_attributes = attributes; m_scriptParameters = scriptParameters; ResultCodes resultCode = ResultCodes.RC_SUCCESS; Lib.Logger.TraceEvent(TraceEventType.Start, 0, "Task Id {0}: Collection script WindowsWASGetFileScript.", m_taskId); try { ManagementScope cimvScope = null; ManagementScope defaultScope = null; // Check ManagementScope CIMV if (null == connection) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection object passed to WindowsWASGetFileScript is null.", m_taskId); } else if (!connection.ContainsKey(@"cimv2")) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Management scope for CIMV namespace is not present in connection object.", m_taskId); } else if (!connection.ContainsKey(@"default")) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Management scope for Default namespace is not present in connection object.", m_taskId); } else { cimvScope = connection[@"cimv2"] as ManagementScope; defaultScope = connection[@"default"] as ManagementScope; if (!cimvScope.IsConnected) { resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection to CIMV namespace failed.", m_taskId); } else if (!defaultScope.IsConnected) { resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection to Default namespace failed.", m_taskId); } } //Check Script Variables if (resultCode.Equals(ResultCodes.RC_SUCCESS)) { // // We have to massage the script parameter set, replace // any keys with a colon by just the part after the colon. // We should probably narrow this to just the registryKey // and registryRoot entries... Dictionary <string, string> d = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> kvp in scriptParameters) { string[] sa = kvp.Key.Split(s_collectionParameterSetDelimiter, StringSplitOptions.RemoveEmptyEntries); Debug.Assert(sa.Length > 0); d[sa[sa.Length - 1]] = kvp.Value; } scriptParameters = d; if (scriptParameters.ContainsKey("profRegPath")) { m_filePath = scriptParameters[@"profRegPath"]; } else if (scriptParameters.ContainsKey("cellPath")) { m_filePath = scriptParameters[@"cellPath"]; } else if (scriptParameters.ContainsKey("nodeVarPath")) { m_filePath = scriptParameters[@"nodeVarPath"]; } else if (scriptParameters.ContainsKey("rsrcFilePath")) { m_filePath = scriptParameters[@"rsrcFilePath"]; } else if (scriptParameters.ContainsKey("svrCfgPath")) { m_filePath = scriptParameters[@"svrCfgPath"]; } else if (scriptParameters.ContainsKey("virtHostsFilePath")) { m_filePath = scriptParameters[@"virtHostsFilePath"]; } else { resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing parameter WAS Script parameter.", m_taskId); } } // Check Remote Process Temp Directory if (resultCode.Equals(ResultCodes.RC_SUCCESS)) { if (!connection.ContainsKey(@"TemporaryDirectory")) { connection[@"TemporaryDirectory"] = @"%TMP%"; } else { if (!connection[@"TemporaryDirectory"].Equals(@"%TMP%")) { if (!Lib.ValidateDirectory(m_taskId, connection[@"TemporaryDirectory"].ToString(), cimvScope)) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Temporary directory {1} is not valid.", m_taskId, connection[@"TemporaryDirectory"].ToString()); resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; //@TODO: change to RC_TEMP_DIRECTORY_NOT_EXIST } else { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: User specified temp directory has been validated.", m_taskId); } } } } if (resultCode == ResultCodes.RC_SUCCESS) { StringBuilder fileContent = new StringBuilder(); StringBuilder fileName = new StringBuilder(); string[] fileData = m_filePath.Split('='); fileName.Append(fileData[0]); Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Attempting to retrieve file {1}.", m_taskId, fileName.ToString()); if (Lib.ValidateFile(m_taskId, fileName.ToString(), cimvScope)) { using (IRemoteProcess rp = RemoteProcess.GetRemoteFile(m_taskId, cimvScope, fileName.ToString(), connection, tftpPath, tftpPath_login, tftpPath_password, tftpDispatcher)) { // Launch the remote process. // This method will block until the entire remote process operation completes. resultCode = rp.Launch(); Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Remote file retrieval operation completed with result code {1}.", m_taskId, resultCode.ToString()); fileContent.Append(rp.Stdout); } m_dataRow.Append(m_elementId).Append(',') .Append(m_attributes[fileData[1]]).Append(',') .Append(m_scriptParameters[@"CollectorId"]).Append(',') .Append(m_taskId).Append(',') .Append(m_databaseTimestamp + m_executionTimer.ElapsedMilliseconds).Append(',') .Append(fileData[1]).Append(',') .Append(BdnaDelimiters.BEGIN_TAG).Append(fileContent).Append(BdnaDelimiters.END_TAG); } else { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: WAS Config file: {1} does not exist.", m_taskId, fileName.ToString()); resultCode = ResultCodes.RC_SUCCESS; } } } catch (Exception ex) { Lib.LogException(m_taskId, m_executionTimer, "Unhandled exception in WindowsWASGetFileScript", ex); resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_READ_REMOTE_FILE; } CollectionScriptResults result = new CollectionScriptResults(resultCode, 0, null, null, null, false, m_dataRow.ToString()); Lib.Logger.TraceEvent(TraceEventType.Stop, 0, "Task Id {0}: Collection script WindowsWASGetFileScript. Elapsed time {1}. Result code {2}.", m_taskId, m_executionTimer.Elapsed.ToString(), result.ResultCode.ToString()); return(result); }
public RemoteThread(RemoteProcess process, IntPtr threadHandle) { Process = process; ThreadHandle = threadHandle; ThreadId = Methods.GetThreadId(ThreadHandle); }
public ImageDataDirectories(RemoteProcess process, IntPtr address) : base(process, address) { }
public RemotePointer(RemoteProcess process, IntPtr address) { m_Process = process; BaseAddress = address; }
public void WaitForExit() { RemoteProcess.WaitForExit(); }
private void RemoteProcessOnProcessClosing(RemoteProcess remoteProcess) { Reset(); firstScanButton.Enabled = nextScanButton.Enabled = flowLayoutPanel.Enabled = false; }
public void Kill() { RemoteProcess?.Kill(); }
public static MarshalledValue <T> Marshal <T>(RemoteProcess proc, T value) { return(new MarshalledValue <T>(proc, value)); }
public ImageDosHeader(RemoteProcess process, IntPtr address) : base(process, address) { }
/// <summary> /// Execute command /// (Note that file path must be absolute path) /// </summary> /// <param name="filePath">File Path</param> /// <param name="collectedData">Collected Result.</param> /// <returns></returns> private ResultCodes ExecuteCommand(string userCommandLine, out string collectedData) { ResultCodes resultCode = ResultCodes.RC_SUCCESS; collectedData = string.Empty; if (!m_connection.ContainsKey(@"TemporaryDirectory")) { m_connection[@"TemporaryDirectory"] = @"%TMP%"; } else { if (!m_connection[@"TemporaryDirectory"].Equals(@"%TMP%")) { if (!Lib.ValidateDirectory(m_taskId, m_connection[@"TemporaryDirectory"].ToString(), m_cimvScope)) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Temporary directory {1} is not valid.", m_taskId, m_connection[@"TemporaryDirectory"].ToString()); resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; //@TODO: change to RC_TEMP_DIRECTORY_NOT_EXIST } else { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Temporary directory {1} has been validated.", m_taskId, m_connection[@"TemporaryDirectory"].ToString()); } } } if (resultCode == ResultCodes.RC_SUCCESS) { string strTempDir = m_connection["TemporaryDirectory"].ToString().Trim(); if (strTempDir.EndsWith(@"\")) { strTempDir = strTempDir.Substring(0, strTempDir.Length - 1); } string strBatchFileContent = buildBatchFile(userCommandLine); StringBuilder stdoutData = new StringBuilder(); using (IRemoteProcess rp = RemoteProcess.ExecuteBatchFile (m_taskId, m_cimvScope, strBatchFileContent, m_connection, m_tftpPath, m_tftpPath_login, m_tftpPath_password, m_tftpDispatcher)) { //This method will block until the entire remote process operation completes. resultCode = rp.Launch(); Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Remote process operation completed with result code {1}.", m_taskId, resultCode.ToString()); if (rp != null && rp.Stdout != null && resultCode == ResultCodes.RC_SUCCESS) { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Remote processExec completed with result <{1}>.", m_taskId, rp.Stdout.ToString()); collectedData = rp.Stdout.ToString(); //string output = rp.Stdout.ToString(); //if (output.IndexOf(s_endTag) != -1) { // collectedData = output.Substring(0, output.Length - s_endTag.Length - 2); //} else { // resultCode = ResultCodes.RC_PROCESS_EXEC_FAILED; // Lib.Logger.TraceEvent(TraceEventType.Error, // 0, // "Task Id {0}: Remote execution error.\nSTDOUT.STDERR:\n{1}", // m_taskId, // rp.Stdout.ToString()); //} } else { resultCode = ResultCodes.RC_PROCESS_EXEC_FAILED; } } } return(resultCode); }
public RemoteFunction(RemoteProcess process, IntPtr address, string name) : base(process, address) { Name = name; }
/// <summary> /// Perform collection task specific processing. /// </summary> /// /// <param name="taskId">Database assigned task Id.</param> /// <param name="cleId">Database Id of owning Collection Engine.</param> /// <param name="elementId">Database Id of element being collected.</param> /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param> /// <param name="localTimestamp">Local task dispatch timestamp.</param> /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param> /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param> /// <param name="connection">Connection script results (null if this script does not /// require a remote host connection).</param> /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param> /// <returns>Collection results.</returns> public CollectionScriptResults ExecuteTask(long taskId, long cleId, long elementId, long databaseTimestamp, long localTimestamp, IDictionary <string, string> attributes, IDictionary <string, string> scriptParameters, IDictionary <string, object> connection, string tftpPath, string tftpPath_login, string tftpPath_password, ITftpDispatcher tftpDispatcher) { m_taskId = taskId.ToString(); m_cleId = cleId; m_elementId = elementId; m_databaseTimestamp = databaseTimestamp; m_localTimestamp = localTimestamp; m_attributes = attributes; m_scriptParameters = scriptParameters; m_tftpPath = tftpPath; m_tftpPath_login = tftpPath_login; m_tftpPath_password = tftpPath_password; m_tftpDispatcher = tftpDispatcher; m_connection = connection; m_executionTimer = Stopwatch.StartNew(); ResultCodes resultCode = ResultCodes.RC_SUCCESS; Lib.Logger.TraceEvent(TraceEventType.Start, 0, "Task Id {0}: Collection script VMwareVMLSConfigFileContentScript.", m_taskId); try { // Check ManagementScope CIMV if (connection == null) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection object passed to VMwareVMLSConfigFileContentScript is null.", m_taskId); } else if (!connection.ContainsKey("cimv2")) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Management scope for CIMV namespace is not present in connection object.", m_taskId); } else { m_cimvScope = connection[@"cimv2"] as ManagementScope; if (!m_cimvScope.IsConnected) { resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection to CIMV namespace failed.", m_taskId); } } //Check VMLSFilePath attribute if (scriptParameters.ContainsKey("VMLSFilePath")) { m_vmlsFilePath = scriptParameters[@"VMLSFilePath"]; } else { resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing parameter VMLSFilePath attribute.", m_taskId); } // Check Remote Process Temp Directory if (!m_connection.ContainsKey(@"TemporaryDirectory")) { m_connection[@"TemporaryDirectory"] = @"%TMP%"; } else { if (!m_connection[@"TemporaryDirectory"].Equals(@"%TMP%")) { if (!Lib.ValidateDirectory(m_taskId, m_connection[@"TemporaryDirectory"].ToString(), m_cimvScope)) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Temporary directory {1} is not valid.", m_taskId, m_connection[@"TemporaryDirectory"].ToString()); resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; //@TODO: change to RC_TEMP_DIRECTORY_NOT_EXIST } else { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: User specified temp directory has been validated.", m_taskId); } } } // DEBUG-- to be removed #region DEBUG StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, string> kvp in m_attributes) { sb.Append(@"Attribute[").Append((string)kvp.Key).Append(@"]=").AppendLine((string)kvp.Value); } Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Attribute dictionary contents:\n{1}", m_taskId, sb.ToString()); #endregion // DEBUG if (resultCode == ResultCodes.RC_SUCCESS) { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Attempting to retrieve file {1}.", m_taskId, m_vmlsFilePath); StringBuilder fileContent = new StringBuilder(); if (Lib.ValidateFile(m_taskId, m_vmlsFilePath, m_cimvScope)) { using (IRemoteProcess rp = RemoteProcess.GetRemoteFile(m_taskId, m_cimvScope, m_vmlsFilePath, m_connection, m_tftpPath, m_tftpPath_login, m_tftpPath_password, m_tftpDispatcher)) { // // Launch the remote process. // This method will block until the entire remote process operation completes. resultCode = rp.Launch(); Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Remote file retrieval operation completed with result code {1}.", m_taskId, resultCode.ToString()); fileContent.Append(rp.Stdout); } // Format file content to format: name=value string strFormattedString = this.formatFileContent(fileContent.ToString()); this.BuildDataRow(@"VMLSFileContent", strFormattedString); } else { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: VMLS file {1} does not exist.", m_taskId, m_vmlsFilePath); resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_READ_REMOTE_FILE; } } } catch (Exception ex) { if (ResultCodes.RC_SUCCESS == resultCode) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in VMwareVMLSConfigFileContentScript. Elapsed time {1}.\n{2}\nResult code changed to RC_PROCESSING_EXCEPTION.", m_taskId, m_executionTimer.Elapsed.ToString(), ex.ToString()); resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_READ_REMOTE_FILE; } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in VMwareVMLSConfigFileContentScript. Elapsed time {1}.\n{2}", m_taskId, m_executionTimer.Elapsed.ToString(), ex.ToString()); } } Lib.Logger.TraceEvent(TraceEventType.Stop, 0, "Task Id {0}: Collection script VMwareVMLSConfigFileContentScript. Elapsed time {1}. Result code {2}.", m_taskId, m_executionTimer.Elapsed.ToString(), resultCode.ToString()); return(new CollectionScriptResults (resultCode, 0, null, null, null, false, m_dataRow.ToString())); }
internal PatchManager(RemoteProcess process) { m_Process = process; m_RemotePatches = new HashSet <RemotePatch>(); }
private void OnProcessAttached(RemoteProcess process) { process.UpdateProcessInformations(); resolver = null; var processName = Path.GetFileName(process.UnderlayingProcess.Path).ToLower(); var settings = Applications.FirstOrDefault(s => s.ProcessName == processName); if (settings != null) { var moduleName = string.IsNullOrEmpty(settings.PatternModule) ? settings.ProcessName : settings.PatternModule; var namesArrayPtr = PatternScanner.FindPattern( BytePattern.Parse(settings.Pattern), process, process.GetModuleByName(moduleName) ); if (!namesArrayPtr.IsNull()) { switch (settings.PatternMethod) { case PatternMethod.Direct: namesArrayPtr = process.ReadRemoteIntPtr(namesArrayPtr + settings.PatternOffset); break; case PatternMethod.Derefence: var temp = process.ReadRemoteIntPtr(namesArrayPtr + settings.PatternOffset); namesArrayPtr = process.ReadRemoteIntPtr(temp); break; } if (namesArrayPtr.MayBeValid()) { switch (settings.Version) { case UnrealEngineVersion.UE1: resolver = new UnrealEngine1NameResolver(process, new UnrealEngine1Config(settings) { GlobalArrayPtr = namesArrayPtr }); break; case UnrealEngineVersion.UE2: resolver = new UnrealEngine2NameResolver(process, new UnrealEngine2Config(settings) { GlobalArrayPtr = namesArrayPtr }); break; case UnrealEngineVersion.UE3: resolver = new UnrealEngine3NameResolver(process, new UnrealEngine3Config(settings) { GlobalArrayPtr = namesArrayPtr }); break; case UnrealEngineVersion.UE4: resolver = new UnrealEngine4NameResolver(process, new UnrealEngine4Config(settings) { GlobalArrayPtr = namesArrayPtr }); break; default: throw new ArgumentOutOfRangeException(); } } } } }
static int Main(string[] args) { Arguments arguments = new Arguments(args); string targetFrameworkVersion = arguments["version"]; if (targetFrameworkVersion == null) { targetFrameworkVersion = "2.0"; } string db4oDistPath = arguments["dir.dll.compact"]; if (db4oDistPath == null) { Help(); return(InvalidProgramParameters); } string cfAppName = arguments["app.name"]; if (string.IsNullOrEmpty(cfAppName)) { Help(); return(InvalidProgramParameters); } string deployFileFilter = AppendExtraFilterForDeploy(arguments["deploy.extra.files"]); int ret; try { Console.Error.WriteLine("CompactFrameworkTestHelper v1.2 - Copyright (C) 2009 Versant Inc.\r\n"); Console.Error.WriteLine("\tCF App: {0}", cfAppName); Console.Error.WriteLine("\tCF Target Version: {0}", targetFrameworkVersion); Console.Error.WriteLine("\tFolder: {0}", db4oDistPath); Console.Error.WriteLine("\tDeployed File Types: {0}", deployFileFilter); Console.Error.WriteLine("\tArguments: {0}", arguments["app.args"] ?? "no argument"); ConfigureEmulator(arguments["dir.storagecard"]); Device device = EmulatorHelper.GetDevice(); device.Connect(); DeployDotNetFramework(device, targetFrameworkVersion); try { EmulatorHelper.CopyFiles(device.GetFileDeployer(), Path.Combine(db4oDistPath, "*"), DeviceTestPath, deployFileFilter); RemoteProcess process = device.GetRemoteProcess(); if (process.Start(DeviceTestPath + cfAppName, "\"" + arguments["app.args"] ?? String.Empty + "\"")) { ret = WaitToFinishOrTimeout(process, new TimeSpan(0, 5, 0, 0)); EmulatorHelper.PublishTestLog(device.GetFileDeployer(), db4oDistPath); if (ret != 0) { Console.Error.WriteLine("{0} returned: {1}", cfAppName, ret); } } else { Console.Error.WriteLine("Failled to start application '{0}' in emulator", cfAppName); ret = FailedLaunchingTests; } } finally { device.Disconnect(); IDeviceEmulatorManagerVMID virtualDevice = EmulatorHelper.GetVirtualDevice(); virtualDevice.Shutdown(DoNotSaveState); } } catch (Exception ex) { Console.Error.WriteLine("Error running {0}\r\n{1}", cfAppName, ex); ret = ExceptionRunningTests; } return(ret); }
/// <summary> /// Perform collection task specific processing. /// </summary> /// /// <param name="taskId">Database assigned task Id.</param> /// <param name="cleId">Database Id of owning Collection Engine.</param> /// <param name="elementId">Database Id of element being collected.</param> /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param> /// <param name="localTimestamp">Local task dispatch timestamp.</param> /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param> /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param> /// <param name="connection">Connection script results (null if this script does not /// require a remote host connection).</param> /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param> /// /// <returns>Collection results.</returns> public CollectionScriptResults ExecuteTask( long taskId, long cleId, long elementId, long databaseTimestamp, long localTimestamp, IDictionary <string, string> attributes, IDictionary <string, string> scriptParameters, IDictionary <string, object> connection, string tftpPath, string tftpPath_login, string tftpPath_password, ITftpDispatcher tftpDispatcher) { m_taskId = taskId.ToString(); Stopwatch executionTimer = Stopwatch.StartNew(); ResultCodes resultCode = ResultCodes.RC_SUCCESS; StringBuilder dataRow = new StringBuilder(); Lib.Logger.TraceEvent(TraceEventType.Start, 0, "Task Id {0}: Collection script WindowsSiebelServerDataCollectionScript.", m_taskId); try { // // Check ManagementScope CIMV ManagementScope cimvScope = null; if (connection == null) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection object passed to WindowsSiebelServerDataCollectionScript is null.", m_taskId); } else if (!connection.ContainsKey("cimv2")) { resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Management scope for CIMV namespace is not present in connection object.", m_taskId); } else { cimvScope = connection[@"cimv2"] as ManagementScope; if (!cimvScope.IsConnected) { resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Connection to CIMV namespace failed.", m_taskId); } } // // Check Siebel Credential if (resultCode == ResultCodes.RC_SUCCESS) { string[] connectionVariables = new String[] { @"SiebelUserName", @"SiebelUserPassword", @"TemporaryDirectory", @"siebelSrvrmgrPath" }; resultCode = this.ValidateConnectionParameters(connection, connectionVariables); } // // Check Parameter variables. if (resultCode == ResultCodes.RC_SUCCESS) { string[] paramVariables = new String[] { @"installDirectory", @"gatewayServerName", @"serverName", @"enterpriseName", @"siebelServerCommand" }; resultCode = this.ValidateScriptParameters(scriptParameters, paramVariables); } // // Check Temporary Directory string tempDir = connection[@"TemporaryDirectory"].ToString(); resultCode = this.ValidateTemporaryDirectory(cimvScope, ref tempDir); // Execute Siebel Command string strBatchFileContent = BuildBatchFile(connection[@"siebelSrvrmgrPath"].ToString(), scriptParameters[@"gatewayServerName"], scriptParameters[@"serverName"], scriptParameters[@"enterpriseName"], connection[@"SiebelUserName"].ToString(), connection[@"SiebelUserPassword"].ToString(), scriptParameters[@"siebelServerCommand"], scriptParameters[@"outputDisplayColumns"]); string stdout = null; using (IRemoteProcess rp = RemoteProcess.ExecuteBatchFile (taskId.ToString(), cimvScope, strBatchFileContent, connection, tftpPath, tftpPath_login, tftpPath_password, tftpDispatcher)) { // //This method will block until the entire remote process operation completes. resultCode = rp.Launch(); Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Remote process operation completed with result code {1}.", m_taskId, resultCode.ToString()); if (resultCode == ResultCodes.RC_SUCCESS) { if (rp.Stdout != null && rp.Stdout.Length > 0) { stdout = rp.Stdout.ToString(); string commandOutput = null; if (!stdout.Contains(@"Execution completed")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Data returned is shorter than expected, possibly due to transfer failure.\nResult code changed to RC_PROCESSING_EXCEPTION.", m_taskId); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; } else { // // package command output result. if (ResultCodes.RC_SUCCESS == ParseCommandOutput(stdout, scriptParameters[@"siebelServerCommand"], scriptParameters[@"outputDisplayColumns"], out commandOutput)) { if (!attributes.ContainsKey(s_returnAttribute)) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Attribute \"{1}\" missing from attributeSet.", m_taskId, s_returnAttribute); } else { dataRow.Append(elementId).Append(',') .Append(attributes[s_returnAttribute]).Append(',') .Append(scriptParameters[@"CollectorId"]).Append(',') .Append(taskId).Append(',') .Append(databaseTimestamp + executionTimer.ElapsedMilliseconds).Append(',') .Append(s_returnAttribute).Append(',') .Append(BdnaDelimiters.BEGIN_TAG).Append(commandOutput).Append(BdnaDelimiters.END_TAG); } } } } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: No data returned.\nResult code changed to RC_PROCESSING_EXCEPTION.", taskId.ToString()); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; } } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Remote execution error.\nSTDOUT.STDERR:\n{1}", m_taskId, rp.Stdout.ToString()); } } //// post processing?? //if (resultCode == ResultCodes.RC_SUCCESS && string.IsNullOrEmpty( > 0) { // //foreach (KeyValuePair<string, QueryTableEntry> entry in s_queryTable) { // // entry.Value.ResultHandler(this, entry.Key, stdoutData.ToString()); // //} //} } catch (Exception ex) { if (ResultCodes.RC_SUCCESS == resultCode) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in WindowsSiebelServerDataCollectionScript. Elapsed time {1}.\n{2}\nResult code changed to RC_PROCESSING_EXCEPTION.", m_taskId, executionTimer.Elapsed.ToString(), ex.ToString()); resultCode = ResultCodes.RC_PROCESSING_EXCEPTION; } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in WindowsSiebelServerDataCollectionScript. Elapsed time {1}.\n{2}", m_taskId, executionTimer.Elapsed.ToString(), ex.ToString()); } } Lib.Logger.TraceEvent(TraceEventType.Stop, 0, "Task Id {0}: Collection script WindowsSiebelServerDataCollectionScript. Elapsed time {1}. Result code {2}.", m_taskId, executionTimer.Elapsed.ToString(), resultCode.ToString()); return(new CollectionScriptResults(resultCode, 0, null, null, null, false, dataRow.ToString())); }
public ModuleManager(RemoteProcess process) { m_Process = process; }
public UnrealEngine1NameResolver(RemoteProcess process, UnrealEngine1Config config) : base(process, config) { Contract.Requires(process != null); Contract.Requires(config != null); }
public RemoteThread(RemoteProcess process, uint threadId) { Process = process; ThreadId = threadId; ThreadHandle = Syscall.OpenThread(Enumerations.ThreadAccessFlags.AllAccess, ThreadId); }
public RemoteProcessEnvironmentBlock(RemoteProcess memory, IntPtr pointer) : base(memory, pointer) { }