yashsingh1/xdaforums huggingface dataset:
[Android Software/Hacking General [Developers Only]] k1ll3r8e:
Hey there,

thx mate ;)

i like urs too, nice and clean ;)

i just got the problem solved its in the erroroutput ;( here are my modified function ;)

# EDIT:

just saw it now^^ - c# isnt my strongest lang too^^ just begun with c# with reading the article ;) im only a webdev php, sql, etc.

///<summary>
/// Launch hidden CMD and pass given commands to it
///</summary>
///<param name="cmd">Command to execute</param>
private void RunCMD(string cmd)
{
ProcessStartInfo StartInfo = new System.Diagnostics.ProcessStartInfo();
StartInfo.FileName = Main.FBT;
StartInfo.Arguments = cmd;
StartInfo.CreateNoWindow = true;
StartInfo.RedirectStandardOutput = true;
StartInfo.RedirectStandardError = true;
StartInfo.UseShellExecute = false;

System.Windows.Application.Current.Dispatcher.Invoke(new info.msgCallback(info.msg), new object[] { String.Join(" ", "fastboot", cmd) });

Process proc = new System.Diagnostics.Process();
proc.OutputDataReceived += (s, e) =>
{
if (String.IsNullOrEmpty(e.Data) == false)
{
System.Windows.Application.Current.Dispatcher.Invoke(new info.msgCallback(info.msg), new object[] { e.Data });
}
};
proc.ErrorDataReceived += (s, e) =>
{
if (String.IsNullOrEmpty(e.Data) == false)
{
System.Windows.Application.Current.Dispatcher.Invoke(new info.msgCallback(info.msg), new object[] { e.Data });
}
};
proc.StartInfo = StartInfo;
proc.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
while (proc.HasExited == false)
{

}
if (proc.HasExited)
{
is_exited = true;
}
}
[Android Software/Hacking General [Developers Only]] squabbi:
Heheh. ;) I just get confused with different terms. :P I'll try to interpret the code! :)

---------- Post added at 03:41 PM ---------- Previous post was at 02:46 PM ----------

@k1ll3r8e

Ok, so I've decided to go simple.. I have the adb shell cmd window up. What would I have to do if i wanted to add lines to it?

Thanks,

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

uhmm... to add lines to running cmd i dun know how or if it is able to do so...

but, you can get my class working in your project. with the "new" written function you can send 1 - xxx commands to my class and execute them in the given sequence, after the command work is done u can send the next sequence and so on...

coz i tried yesterday night to open a cmd and hold it open for command sending but after ending the given command the cmd closed up...

(if you want you can try it to launch your command in cmd with the...

/K = after command ends let cmd instance open

modifier instead of

/C = after command ends close cmd instance

...

then u have to make process static that u can send to it from ur class instance and add a new function which sends to the process via...

process.StandardInput.WriteLine(COMMAND YOU WANT TO EXECUTE);

...

"untested but think it can work^^"

) ^^

...so i had to open a new 1... but i

think

if u are in 1 instance of adb.exe you can send shell commands from where u want they will end in the same shell instance (!?)...

coz in my .bat files i set the shell commands also each line 1 command and all works fine :)

Hope this helps u ;)

# Edit:

In the attachment are my adb and fastboot class it might help ;)
[Android Software/Hacking General [Developers Only]] squabbi:
Thanks your class files are a huge help! I'm hoping you can give me an example of using multiple adb commands using one button if you can? :)

I also get an error that the : Type or namespace 'Application' does not exist in the namespace 'system.windows'. But I have added all the references from you class files. I'll try have a look! :)

Thanks ! :good:
[Android Software/Hacking General [Developers Only]] k1ll3r8e:
Np :) - i try to help where i can ;)

if i understand u right this is what u looking for:

private void ADB_reboot_Click(object sender, RoutedEventArgs e)
{
adbi.Start() <= Set the "start-server" command
adbi.Reboot(); <= Set the "reboot" command
adbi.WaitForDevice(); <= Set the "wait-for-device" command
adbi.Pull("/data/media/", "c:\backup\media-backup"); <= Set "pull /data/media/ c:\backup\media-backup" command
adbi.Run(); <= Initiate the command work ;)
}

hope that was what u looking for ;)

Regards,

Sebastian
[Android Software/Hacking General [Developers Only]] squabbi:
I can't seem to get C# to recognise some of the references in the class files. I'm on my phone at the moment so I'll repost in the morning.

Cheers,

Jay
[Android Software/Hacking General [Developers Only]] k1ll3r8e:
Hey Jay, ;)

uhmm...

1. is ur project NET Framework 4 Client based?

2. is ur project a WPF project or a Windows Forms project?

3. have u used the instance of my adb class?

(Adb adbi = Adb.Instance; set this on each file beginning where u want to call the Adb instance)

for example:

public partial class Main : Window

{

Adb adbi = Adb.Instance;

public yourClass(){

...

}

...

}

or does u mean for example...

System.Windows.Application.Current.Dispatcher.Invoke(new info.msgCallback(info.msg), new object[] { String.Join(" ", "adb", cmd) });

this could not referenced? If so, just create a class called info and add for example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

...

class info{

/// <summary>
/// Print msg
/// </summary>
public static void msg(string msg)
{
Main mainWin = (Main)App.Current.MainWindow;
mainWin.INFO_box.AppendText(String.Join("", "\n", String.Join(" ", DateTime.Now.ToString("HH:mm:ss"), msg)));
mainWin.INFO_box.ScrollToEnd();
}

public delegate void msgCallback(string msg);

...
}

Regards,

Sebastian
[Android Software/Hacking General [Developers Only]] squabbi:
Thanks Seb.

I'll try it in the morning. :)

Cheers,

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

Do I need to specify what "bar" is? I'm guessing its a progress bar.

System.Windows.Application.Current.Dispatcher.Invoke(new info.bar_addCallback(info.bar_add), new object[] { stepv });

Also I get this error: Namespace Main could not be found.

public static void msg(string msg)
{
Main mainWin = (Main)App.Current.MainWindow;

Thanks for your help!

Squabbi
[Android Software/Hacking General [Developers Only]] k1ll3r8e:
hey there,

u can just delete the lines which updates the progessbar ;)

-

Main mainWin = (Main)App.Current.MainWindow;

this defines YOUR main window class, just replace "Main" with the name of ur main window class ;)

-

Np, do my best ;)

# Edit:

if u launch a process and in the output are some crazy syms try this...

...

StartInfo.StandardOutputEncoding = System.Text.Encoding.GetEncoding(437);

StartInfo.StandardErrorEncoding = System.Text.Encoding.GetEncoding(437);

...

it helped me in coz of german (ÖÄÜöäü)^^

# Edit 2:

I have linked u my actual cmd interface (script + ui) in attchment
[Android Software/Hacking General [Developers Only]] squabbi:
[MENTION=3753223]k1ll3r8e[/MENTION]

Thanks for the hints!

StartInfo.FileName = MainWindow.FBT;

Is FBT a button? I believe its connected to fastboot.

Also, is:

StartInfo.Arguments = cmd;

cmd is a textbox?

-

What's KIT mean? Is it also a button?

System.Windows.Application.Current.Dispatcher.Invoke(new MsgCallback(Msg), new object[] { String.Join("", MainWindow.KIT.Substring(0,3), "HTC-Tool-Kit>", command) });

Thanks!

Squabbi
[Android Software/Hacking General [Developers Only]] k1ll3r8e:
Hey Jay :),

Here are my base variables (in my main window):

Adb adbi = Adb.Instance;
Fbt fbti = Fbt.Instance;
public static string KIT = System.AppDomain.CurrentDomain.BaseDirectory;
public static string ADB = Path.Combine(KIT, "adb", "adb.exe");
public static string APT = Path.Combine(KIT, "adb", "aapt.exe");
public static string FBT = Path.Combine(KIT, "adb", "fastboot.exe");
public static output outputwindow = new output();

"cmd" is the given command to execute, a textbox or a list item depends on the class ;)

PS: Im just working on multilang support, if need infos about it let me know ;)
[Android Software/Hacking General [Developers Only]] squabbi:
[MENTION=3753223]k1ll3r8e[/MENTION]

Hey there!

I'll take a look at the live cmd output. :)

After I added the base variables I get these errors:

public static string ADB = Path.Combine(KIT, "adb", "adb.exe");

I get that System.Windows.Shapes.Path does not contain a definition for 'Combine' I think I'm missing a reference or a class.

-

public static output outputwindow = new output();

I also think I'm missing a reference here.

-

Thanks again! :) :good:
[Android Software/Hacking General [Developers Only]] k1ll3r8e:
Heyho,

u have to replace "System.Windows.Shapes" with System.IO then it will work ;)

the "public static output outputwindow = new output();" u can still remove its only my extra output window to show the logs ;)

Regards,

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

Okeydoke! Nevermind about the not found thing. Just had to make a folder called 'adb' and place the files there!

Now I have a button that tells the ADB version in the 'INFO_box'

This is the code for the button:

adbi.Start();
adbi.Version();
adbi.Run();

The output tells me:

Also I've noticed every other command doesn't work and doesn't show in the console.

eg. In your projects you shared with me, it shows me all the commands the buttons do at the bottom. It also works fine! :)

But does not tell the the version in the info_box.

Any ideas?

Thanks again for the help! :good: :highfive:
[Android Software/Hacking General [Developers Only]] k1ll3r8e:
Hey there, :)

thats a bit crazy... i cant reproduce the bug :(

see the attched img...

have u also the line for error output included in your process call?

...
ProcessStartInfo StartInfo = new System.Diagnostics.ProcessStartInfo();
StartInfo.FileName = Main.ADB; //the path to ADB or any other process u want to launch
StartInfo.Arguments = "version"; //arguments u want to give to the process
StartInfo.CreateNoWindow = true;
StartInfo.RedirectStandardOutput = true;
[B]StartInfo.RedirectStandardError = true;[/B]
StartInfo.StandardOutputEncoding = System.Text.Encoding.GetEncoding(437); //defines the current output encoding
[B]StartInfo.StandardErrorEncoding = System.Text.Encoding.GetEncoding(437); //defines the current error output encoding[/B]
StartInfo.UseShellExecute = false;

Process proc = new System.Diagnostics.Process();
proc.OutputDataReceived += (s, e) =>
{
if (String.IsNullOrEmpty(e.Data) == false)
{
//what u want to do if an output recieved
//e.Data hold the text sting

Thread.Sleep(50); //give the ui a few ms to refresh
}
};
[B]proc.ErrorDataReceived += (s, e) =>
{
if (String.IsNullOrEmpty(e.Data) == false)
{
//what u want to do if an error output recieved
//e.Data hold the text sting

Thread.Sleep(50); //give the ui a few ms to refresh
}
};[/B]
proc.StartInfo = StartInfo;
proc.Start();
proc.BeginOutputReadLine();
[B]proc.BeginErrorReadLine();[/B]
while (proc.HasExited == false)
{

}
if (proc.HasExited)
{

}
...

Hope this helps u :), otherwise for better communication u can add me in skype (s.grinke) if u want.

Regards,

Sebastian

# Edit:

Line markup for better understanding ;)

Also i have found out the following...

if u have defined "using NAMESPACE.Properties;" in your "main window" then u can't write in the "main window" it will occure a app crash...

btw.

if u use user settings in ur project act like the following...

in visual studio 2012 (open project)

(Right hand) "Project explorer (tab)" => Properties => settings.settings (double click)

enter ur vars u want the user to change and the system vars u want to use...

Get them with string YOUR_var = Properties.Settings.Default["YOUR_var"];

Set them with Properties.Settings.Default["YOUR_var"] = YOUR_var;

after u set some vars u have to call "Properties.Settings.Default.Save();" ! IMPORTENT

if u set there some path vars, dun forget to re-set them after saving ;)
[Android Software/Hacking General [Developers Only]] badtoy1986:
You may find this helpful...

http://www.developerfusion.com/tools/convert/vb-to-csharp/
[Android Software/Hacking General [Developers Only]] squabbi:
[MENTION=3753223]k1ll3r8e[/MENTION]

Thanks!

I have now included a snapshot of what happens.

(In the Attachments) :)

There is no error that shows up in visual C# but I then cannot do another command.

eg. Pressing the same button gain.

Any ideas?

Thanks!

(PS: I've added you on skype ;) )
[Android Software/Hacking General [Developers Only]] squabbi:
[MENTION=3753223]k1ll3r8e[/MENTION]

Hehe, you wern't on Skype so I'll just post it here then. :)

I have a button that flashes CWM. I'm using the fbti.Flash();

I'm not too sure how to use it. Could you show me?

Thanks!
[Android Software/Hacking General [Developers Only]] k1ll3r8e:
Hey Jay :),

np ;)

...
///<summary>
/// Flash boot + recovery + system
///</summary>
///<param name="partition">Partition to flash</param>
///<param name="file">File path</param>
public void Flash(string partition, string file)
{
AddCMD(String.Join(" ", "flash", partition, file));
}
...

fbti.Flash("recovery", "c:\twrp.img");

Hope this helps ;)

Regards,

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

Hallo! :)

I have tried to implement your live CMD in my project.

MainWindow mainWin = (MainWindow)App.Current.MainWindow;
mainWin.KIT_terminal.IsEnabled = true;

I get this as an error:

What do I have to specify in my mainWindow class?

Thanks!

Jay :)
[Android Software/Hacking General [Developers Only]] k1ll3r8e:
Hey Jay :),

U can delete the both lines ;)

its only to enable the button which is disabled on start of my cmd, so u cant open it twice.

Regards,

Sebastian
[Android Software/Hacking General [Developers Only]] squabbi:
Ah. Ok, thanks! :)
[Android Software/Hacking General [Developers Only]] dancer_69:
Hello,

I haven't any previous knowledge in c#(or any other c) and visual studio, but I'm learning android developement and java. So all these are very new to me and I haven't much experience in programming generally.

With the help of OP tutorial though I've managed to make an app with reboot commands, install apk and push pull files with drag and drop also.

The next thing I want to add is an adb shell as a form' s control, but from what I've read here I cannot understand how to do it.

Can you please help me on this?

Thanks in advance.
[Android Software/Hacking General [Developers Only]] dancer_69:
Thanks a lot.

I never used WPF project also, so I'll try and I'll post if need more help.
[Android Software/Hacking General [Developers Only]] dancer_69:
I tried this code and I get 1 error on xaml and 2 on CS.

On XAML I get an error on "DynamicResource", which I solved(I think) by changing the title as "Window_ADB_shell"

On CS I get errors on "Main". I deleted the 2 lines as you said on a previous post, but I also get error on:

StartInfo.FileName = Main.ADB;

what is this main?

And also how to connect this WPF project with my Windows Forms project with all other stuff? Do I need rewrite it and put all controls and code to the MainWindow.cs?
[Android Software/Hacking General [Developers Only]] k1ll3r8e:
Hey there,

public static string ADB = String.Empty;
public static string APT = String.Empty;
public static string FBT = String.Empty;
public static string KIT = System.AppDomain.CurrentDomain.BaseDirectory;
public static output outputwindow = new output();

this are my GLOBAL definded vars...in my (Main) window... i get them in every window i open ;)

The Main.ADB hold the path to adb.exe, Main.APT hold the path to aapt,exe, Main.ABThold the path to fastboot,exe

Main.KIT = hold the app path

Main.outputwindow = my outputwindow with 3 differend output boxes (All, Command sequence, filtered command sequence for copy actions)

-

About the winforms to wpf, i can only say the same as "DeepUnknown" - the winform CS code is in most parts like wpf CS code...

But yes u have to rewrite it if u want to use full wpf functions... But u can work in windows u dun need to put all in the main window... its a bit confusing to write in differend windows but if u got out how, it is really easy.

Hope it helps u ;)

Regards,

Sebastian
[Android Software/Hacking General [Developers Only]] dancer_69:
Thanks for trying to help, but I have problem with Main, not with the variable. The Main doesn't recognized(what is?).

As for rewriting my windows forms code, I already start to do it, just seems more complicated from windows forms.
[Android Software/Hacking General [Developers Only]] k1ll3r8e:
Main is my main window class the class of the 1st window u see if u launch ur app ;)

namespace HTC_Sensation_Tool_Kit
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class Main : Window
{
...
}
}
[Android Software/Hacking General [Developers Only]] dancer_69:
Thank's for this, I rename shell with Main and now seems fine, but I still get the above error when trying to run it:

Additional information: 'The call to the type of construction 'AdbCommands.Main', which match the limitations presented connection set an exception.' Line number '3' and row position '9'.

If there is a handler for this exception, the program may be safely continued.
[Android Software/Hacking General [Developers Only]] k1ll3r8e:
Hey there,

i think its the same issue as by squabbi...

try to replace this line...

cmdinfo = FindResource("TOOL_TERMINAL_cmd_box").ToString();

with

cmdinfo = "Enter ur command here and press Enter";

Explain:

this line sets a default msg in the command inputbox so that the user see there is a textbox ;)
[Android Software/Hacking General [Developers Only]] dancer_69:
Thanks, that was the problem. Now I get another error though:

An unhandled exception of type 'System.InvalidOperationException' occurred in System.dll

Additional information: Cannot start the process because Unable to start the process because it has given filename.

EDIT:

Probably this happens because it doesn't find adb?

Anyway I replaced with

StartInfo.FileName = "cmd.exe";

StartInfo.Arguments = "adb shell";

and seems that now runs fine.

EDIT2:

Spoke too fast.

The console loads but I get error on console:

'id' is not recognized as an internal or external command,

and "adb shell" doesn't start.

EDIT3:

I've replace "id" with "adb shell" and now shell runs.
[Android Software/Hacking General [Developers Only]] k1ll3r8e:
Hey there,

you can also try...

public static string KIT = System.AppDomain.CurrentDomain.BaseDirectory;

StartInfo.FileName = Path.Combine(KIT,"adb","adb.exe"); //if adb is in ur app directory in a subfolder called "adb"

StartInfo.Arguments = "shell"; //pass the shell argument to adb and launch it :) so start directly adb shell without extra cmd ;)
[Android Software/Hacking General [Developers Only]] dancer_69:
This works perfect, thanks.
[Android Software/Hacking General [Developers Only]] k1ll3r8e:
Hey all together,

yesterday night i found out somehting really usefull stuff,

if u want to implement "Flash Rom /-Update" in your project try something like:

(for this feature u need an recovery installed which supports openrecoveryscript)

Explain:
ADB_FLASH_ROM_path = is a textbox
ADB_FLASH_ROM_copy_to_device = is a checkbox
ADB_FLASH_ROM_wipe_data = is a checkbox
ADB_FLASH_ROM_wipe_cache = is a checkbox
ADB_FLASH_ROM_wipe_dalvik = is a checkbox

adbi.XXXX = represent the adb commands to use, i put them in a single class

private void ADB_FLASH_ROM_flash_Click(object sender, RoutedEventArgs e)
{
string rom = ADB_FLASH_ROM_path.Text;
if (String.IsNullOrEmpty(rom) == false)
{
string path = "sdcard";
string update = "tmp_rom_update.zip";
string orsf = "/cache/recovery/openrecoveryscript";
adbi.Root();
adbi.WaitForDevice();
if (ADB_FLASH_ROM_copy_to_device.IsChecked == true)
{
path = "data";
}
adbi.Push(rom, String.Join("", "/", path, "/", update));
adbi.Shell(String.Join("", "chmod 777 ", String.Join("", "/", path, "/", update)));
if (ADB_FLASH_ROM_wipe_data.IsChecked == true)
{
adbi.Shell(String.Join("", "echo wipe data >> ", orsf));
}
if (ADB_FLASH_ROM_wipe_cache.IsChecked == true)
{
adbi.Shell(String.Join("", "echo wipe cache >> ", orsf));
}
if (ADB_FLASH_ROM_wipe_dalvik.IsChecked == true)
{
adbi.Shell(String.Join("", "echo wipe dalvik >> ", orsf));
}
adbi.Shell(String.Join("", "echo install ", String.Join("", "/", path, "/", update), " >> ", orsf));
adbi.Shell(String.Join("", "echo cmd rm ", String.Join("", "/", path, "/", update), " >> ", orsf));
adbi.Shell(String.Join("", "chmod 0777 ", orsf));
adbi.Reboot("recovery");
adbi.Run();
ADB_FLASH_ROM_path.Text = String.Empty;
ADB_FLASH_ROM_wipe_cache.IsChecked = true;
ADB_FLASH_ROM_wipe_dalvik.IsChecked = true;
ADB_FLASH_ROM_wipe_data.IsChecked = false;
}
}

i hope i have all unknown variables explained...

Regards,

Sebastian
[Android Software/Hacking General [Developers Only]] Cheaptrix:
You'll want to use RedirectStandardOutput.

http://msdn.microsoft.com/en-us/lib....processstartinfo.redirectstandardoutput.aspx

Edit...didn't notice this was already answered...

Throwing them in the deep end with threading...sink or swim! :)
[Android Software/Hacking General [Developers Only]] squabbi:
Hey guys! I'm hoping someone knows this:

I have a combobox with a list of recoveries for 3 different models. ( ATT, TMoblie, Int. ) I have given a name for each recovery entry in the combobox.

How can I use this in an if statement.

example.

if ATTCWM is selected it displays a messagebox saying "ATT CWM FLASH" but i have more of these...

Any ideas?

Thanks!

[MENTION=3753223]k1ll3r8e[/MENTION]
[Android Software/Hacking General [Developers Only]] Android-Andi:
Hey i need some help...

Button1 (= Start Logcat)

var process = Process.Start("CMD.exe", "/c adb logcat *:E > logcat.txt);
process.WaitForExit();

How to hide the cmd window? I need to Stop the Logcat using:

Button2 (= Stop Logcat)

var process = Process.Start("CMD.exe", "/c adb kill-server);
process.WaitForExit();

Next i need will be a little tricky (maybe not :D i don´t know):

Screenshot

I need this commands

(%extpath% should be "/sdcard" ; if checkbox is checked it should be the text entered in the textbox)

adb.exe shell mkdir %extpath%/fb2png
adb.exe shell mkdir %extpath%/fb2png/tool
adb.exe shell rm -rf %extpath%/fb2png/screens
adb.exe shell mkdir %extpath%/fb2png/screens
adb.exe push fb2png %extpath%/fb2png/tool/
adb.exe shell chmod 755 %extpath%/fb2png/tool/fb2png
adb.exe shell %extpath%/fb2png/tool/fb2png %extpath%/fb2png/screens/fbdump.png
adb.exe pull %extpath%/fb2png/screens/fbdump.png screenshots
adb.exe shell rm %extpath%/fb2png/screens/fbdump.png

And last but not least... how to add a console into my Windows Forms Application?

I hope somebody can help me :)

Edit: I found out how to add Time&Date to "Logcat.txt"

public Form1()
{
InitializeComponent();
Timer timer = new Timer();
timer.Enabled = true;
timer.Interval = 500;
timer.Tick += new EventHandler(tick);
}

private void tick(object sender, EventArgs e)
{
label3.Text = "Zeit: " + DateTime.Now.ToString("HH:mm:ss");
label4.Text = "Datum: " + DateTime.Now.ToString("dd.MM.yyyy");
[COLOR="PaleGreen"] label5.Text = DateTime.Now.ToString("yyyy.MM.dd") + "_" + DateTime.Now.ToString("HH-mm-ss") + "_Logcat.txt";[/COLOR]
label6.Text = DateTime.Now.ToString("yyyy.MM.dd") + "_" + DateTime.Now.ToString("HH-mm-ss") + "_dmesg.txt";

}

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("To Stop Logcat Press CTRL+C", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
var process = Process.Start("CMD.exe", "/c adb logcat *:E > " [COLOR="PaleGreen"]+ label5.Text);[/COLOR]
process.WaitForExit();
}
[Android Software/Hacking General [Developers Only]] Android-Andi:
Ok, i got it work :)