[Android Software/Hacking General [Developers Only]] k1ll3r8e:
[MENTION=4752144]squabbi[/MENTION]

Got now REAL realtime cmd ;)

here the code:

UI xaml

<Window x:Class="HTC_Sensation_Tool_Kit.cmd"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{DynamicResource ResourceKey=WINDOW_cmd}" Height="372" Width="586" ResizeMode="NoResize">
<Grid>
<TextBox x:Name="CMD_input" HorizontalAlignment="Left" Height="23" TextWrapping="NoWrap" Text="" VerticalAlignment="Top" Width="580" Margin="0,319,0,0" KeyDown="CMD_input_KeyDown" GotFocus="CMD_input_GotFocus" LostFocus="CMD_input_LostFocus"/>
<RichTextBox x:Name="CMD_output" HorizontalAlignment="Left" Height="314" VerticalAlignment="Top" Width="580" IsReadOnly="True" IsEnabled="True" ScrollViewer.VerticalScrollBarVisibility="Auto" IsDocumentEnabled="True" UndoLimit="0">
<RichTextBox.Resources>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0,2,0,0"/>
<Setter Property="Background" Value="White"/>
</Style>
<Style TargetType="{x:Type Run}">
<Setter Property="Background" Value="White"/>
</Style>
</RichTextBox.Resources>
</RichTextBox>
</Grid>
</Window>

Code in background:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace HTC_Sensation_Tool_Kit
{
/// <summary>
/// Interaktionslogik für cmd.xaml
/// </summary>
public partial class cmd : Window
{
private static Process proc = null;
private static bool exited = true;
private string cmdinfo = String.Empty;

public cmd()
{
InitializeComponent();
CMD_output.Document.Blocks.Clear();
proc = new System.Diagnostics.Process();
cmdinfo = FindResource("TOOL_TERMINAL_cmd_box").ToString();
CMD_input.Text = cmdinfo;
Thread run_processes = new Thread(StartCMD);
run_processes.Start();
this.Closing += WindowClosing;
}

///<summary>
/// Clean exit
///</summary>
private void WindowClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (proc.HasExited == false)
{
proc.StandardInput.WriteLine("exit");
if (proc.HasExited == false)
{
proc.StandardInput.WriteLine("exit");
}
}
Main mainWin = (Main)App.Current.MainWindow;
mainWin.KIT_terminal.IsEnabled = true;
}

private void RunCMD(string cmd)
{
if (exited == false)
{
proc.StandardInput.WriteLine(cmd);
CMD_input.Text = String.Empty;
}
}

private void StartCMD()
{
exited = false;
ProcessStartInfo StartInfo = new System.Diagnostics.ProcessStartInfo();
StartInfo.FileName = "cmd.exe";
StartInfo.Arguments = String.Join(" ", "/Q/K", "cmd");
StartInfo.CreateNoWindow = true;
StartInfo.RedirectStandardInput = true;
StartInfo.RedirectStandardOutput = true;
StartInfo.RedirectStandardError = true;
StartInfo.StandardOutputEncoding = System.Text.Encoding.GetEncoding(437);
StartInfo.StandardErrorEncoding = System.Text.Encoding.GetEncoding(437);
StartInfo.UseShellExecute = false;

proc.OutputDataReceived += (s, e) =>
{
if (String.IsNullOrEmpty(e.Data) == false)
{
System.Windows.Application.Current.Dispatcher.Invoke(new MsgCallback(Msg), new object[] { e.Data });
Thread.Sleep(50);
}
};
proc.ErrorDataReceived += (s, e) =>
{
if (String.IsNullOrEmpty(e.Data) == false)
{
System.Windows.Application.Current.Dispatcher.Invoke(new MsgCallback(Msg), new object[] { e.Data });
Thread.Sleep(50);
}
};
proc.StartInfo = StartInfo;
proc.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
while(proc.HasExited == false)
{

}
if (proc.HasExited)
{
exited = true;
}
}

private void CMD_input_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key.ToString().CompareTo("Return") == 0)
{
e.Handled = true;
RunCMD(CMD_input.Text);
}
}

private void CMD_input_GotFocus(object sender, RoutedEventArgs e)
{
if (CMD_input.Text.CompareTo(cmdinfo) == 0)
{
CMD_input.Text = String.Empty;
}
}

private void CMD_input_LostFocus(object sender, RoutedEventArgs e)
{
if (CMD_input.Text.CompareTo("") == 0)
{
CMD_input.Text = cmdinfo;
}
}

public void Msg(string msg)
{
msg = msg.Replace(Main.KIT.Substring(0, Main.KIT.Length - 1), String.Join("", Main.KIT.Substring(0, 3), "HTC-Tool-Kit"));
CMD_output.Document.Blocks.Add(new Paragraph(new Run(msg)));
CMD_output.ScrollToEnd();
}

public delegate void MsgCallback(string msg);
}
}

This will also work with adb shell ;)

cheers,

Sebastian