Skip to content

Commit 3a5fb04

Browse files
Dan WagerDan Wager
authored andcommitted
Initial commit
0 parents  commit 3a5fb04

31 files changed

+3046
-0
lines changed

AndroidLib.sln

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual Studio 2010
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AndroidLib", "AndroidLib\AndroidLib.csproj", "{F5F92F16-C783-4B17-B725-B06F1D725B9C}"
5+
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{81125050-A4D2-4E28-B4BA-B94EE0F0D127}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FormTest", "FormTest\FormTest.csproj", "{A0D9E0FC-0D51-4FD3-95A7-F0A209EBED75}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Debug|Mixed Platforms = Debug|Mixed Platforms
14+
Debug|x86 = Debug|x86
15+
Release|Any CPU = Release|Any CPU
16+
Release|Mixed Platforms = Release|Mixed Platforms
17+
Release|x86 = Release|x86
18+
EndGlobalSection
19+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
20+
{F5F92F16-C783-4B17-B725-B06F1D725B9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{F5F92F16-C783-4B17-B725-B06F1D725B9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{F5F92F16-C783-4B17-B725-B06F1D725B9C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
23+
{F5F92F16-C783-4B17-B725-B06F1D725B9C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
24+
{F5F92F16-C783-4B17-B725-B06F1D725B9C}.Debug|x86.ActiveCfg = Debug|Any CPU
25+
{F5F92F16-C783-4B17-B725-B06F1D725B9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{F5F92F16-C783-4B17-B725-B06F1D725B9C}.Release|Any CPU.Build.0 = Release|Any CPU
27+
{F5F92F16-C783-4B17-B725-B06F1D725B9C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
28+
{F5F92F16-C783-4B17-B725-B06F1D725B9C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
29+
{F5F92F16-C783-4B17-B725-B06F1D725B9C}.Release|x86.ActiveCfg = Release|Any CPU
30+
{81125050-A4D2-4E28-B4BA-B94EE0F0D127}.Debug|Any CPU.ActiveCfg = Debug|x86
31+
{81125050-A4D2-4E28-B4BA-B94EE0F0D127}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
32+
{81125050-A4D2-4E28-B4BA-B94EE0F0D127}.Debug|Mixed Platforms.Build.0 = Debug|x86
33+
{81125050-A4D2-4E28-B4BA-B94EE0F0D127}.Debug|x86.ActiveCfg = Debug|x86
34+
{81125050-A4D2-4E28-B4BA-B94EE0F0D127}.Debug|x86.Build.0 = Debug|x86
35+
{81125050-A4D2-4E28-B4BA-B94EE0F0D127}.Release|Any CPU.ActiveCfg = Release|x86
36+
{81125050-A4D2-4E28-B4BA-B94EE0F0D127}.Release|Mixed Platforms.ActiveCfg = Release|x86
37+
{81125050-A4D2-4E28-B4BA-B94EE0F0D127}.Release|Mixed Platforms.Build.0 = Release|x86
38+
{81125050-A4D2-4E28-B4BA-B94EE0F0D127}.Release|x86.ActiveCfg = Release|x86
39+
{81125050-A4D2-4E28-B4BA-B94EE0F0D127}.Release|x86.Build.0 = Release|x86
40+
{A0D9E0FC-0D51-4FD3-95A7-F0A209EBED75}.Debug|Any CPU.ActiveCfg = Debug|x86
41+
{A0D9E0FC-0D51-4FD3-95A7-F0A209EBED75}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
42+
{A0D9E0FC-0D51-4FD3-95A7-F0A209EBED75}.Debug|Mixed Platforms.Build.0 = Debug|x86
43+
{A0D9E0FC-0D51-4FD3-95A7-F0A209EBED75}.Debug|x86.ActiveCfg = Debug|x86
44+
{A0D9E0FC-0D51-4FD3-95A7-F0A209EBED75}.Debug|x86.Build.0 = Debug|x86
45+
{A0D9E0FC-0D51-4FD3-95A7-F0A209EBED75}.Release|Any CPU.ActiveCfg = Release|x86
46+
{A0D9E0FC-0D51-4FD3-95A7-F0A209EBED75}.Release|Mixed Platforms.ActiveCfg = Release|x86
47+
{A0D9E0FC-0D51-4FD3-95A7-F0A209EBED75}.Release|Mixed Platforms.Build.0 = Release|x86
48+
{A0D9E0FC-0D51-4FD3-95A7-F0A209EBED75}.Release|x86.ActiveCfg = Release|x86
49+
{A0D9E0FC-0D51-4FD3-95A7-F0A209EBED75}.Release|x86.Build.0 = Release|x86
50+
EndGlobalSection
51+
GlobalSection(SolutionProperties) = preSolution
52+
HideSolutionNode = FALSE
53+
EndGlobalSection
54+
EndGlobal

AndroidLib/AndroidLib.csproj

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{F5F92F16-C783-4B17-B725-B06F1D725B9C}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>RegawMOD.Android</RootNamespace>
12+
<AssemblyName>AndroidLib</AssemblyName>
13+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
<TargetFrameworkProfile />
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
<DocumentationFile>bin\Debug\AndroidLib.XML</DocumentationFile>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
<DocumentationFile>bin\Release\AndroidLib.XML</DocumentationFile>
35+
<RegisterForComInterop>false</RegisterForComInterop>
36+
</PropertyGroup>
37+
<PropertyGroup>
38+
<SignAssembly>true</SignAssembly>
39+
</PropertyGroup>
40+
<PropertyGroup>
41+
<AssemblyOriginatorKeyFile>regaw_leinad.pfx</AssemblyOriginatorKeyFile>
42+
</PropertyGroup>
43+
<ItemGroup>
44+
<Reference Include="System" />
45+
<Reference Include="System.Core" />
46+
<Reference Include="System.Xml.Linq" />
47+
<Reference Include="System.Data.DataSetExtensions" />
48+
<Reference Include="System.Data" />
49+
<Reference Include="System.Xml" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<Compile Include="Classes\AndroidController\Adb.cs" />
53+
<Compile Include="Classes\AndroidController\BusyBox.cs" />
54+
<Compile Include="Classes\AndroidController\BatteryInfo.cs" />
55+
<Compile Include="Classes\AndroidController\Device.cs" />
56+
<Compile Include="Classes\AndroidController\AndroidController.cs" />
57+
<Compile Include="Classes\AndroidController\BuildProp.cs" />
58+
<Compile Include="Classes\Util\Extract.cs" />
59+
<Compile Include="Classes\Util\Hasher.cs" />
60+
<Compile Include="Classes\AndroidController\Fastboot.cs" />
61+
<Compile Include="Classes\AndroidController\FileSystem.cs" />
62+
<Compile Include="Classes\AndroidController\Enums.cs" />
63+
<Compile Include="Classes\AndroidController\Phone.cs" />
64+
<Compile Include="Classes\AndroidController\Exceptions.cs" />
65+
<Compile Include="Classes\Util\Java.cs" />
66+
<Compile Include="Properties\AssemblyInfo.cs" />
67+
<Compile Include="Classes\Util\Util.cs" />
68+
<Compile Include="Classes\Util\Command.cs" />
69+
<Compile Include="Classes\AndroidController\Su.cs" />
70+
<Compile Include="Classes\Signer\Signer.cs" />
71+
<Compile Include="Classes\Util\ResourceFolderManager.cs" />
72+
</ItemGroup>
73+
<ItemGroup>
74+
<EmbeddedResource Include="Resources\AndroidController\adb.exe" />
75+
<EmbeddedResource Include="Resources\AndroidController\AdbWinApi.dll" />
76+
<EmbeddedResource Include="Resources\AndroidController\AdbWinUsbApi.dll" />
77+
</ItemGroup>
78+
<ItemGroup />
79+
<ItemGroup>
80+
<EmbeddedResource Include="Resources\Signer\testkey.pk8" />
81+
<EmbeddedResource Include="Resources\Signer\testkey.x509.pem" />
82+
</ItemGroup>
83+
<ItemGroup>
84+
<EmbeddedResource Include="Resources\AndroidController\fastboot.exe" />
85+
<EmbeddedResource Include="Resources\Signer\signapk.jar" />
86+
</ItemGroup>
87+
<ItemGroup>
88+
<EmbeddedResource Include="Resources\Other\aapt.exe" />
89+
</ItemGroup>
90+
<ItemGroup>
91+
<None Include="regaw_leinad.pfx" />
92+
</ItemGroup>
93+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
94+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
95+
Other similar extension points exist, see Microsoft.Common.targets.
96+
<Target Name="BeforeBuild">
97+
</Target>
98+
<Target Name="AfterBuild">
99+
</Target>
100+
-->
101+
</Project>
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
/*
2+
* Adb.cs - Developed by Dan Wager for AndroidLib.dll
3+
*/
4+
5+
using System.IO;
6+
7+
namespace RegawMOD.Android
8+
{
9+
/// <summary>
10+
/// Holds formatted commands to execute through <see cref="Adb"/>
11+
/// </summary>
12+
/// <remarks><para>Can only be created with <c>Adb.FormAdbCommand()</c> or <c>Adb.FormAdbShellCommand()</c></para>
13+
/// <para>Can only be executed with <c>Adb.ExecuteAdbCommand()</c> or <c>Adb.ExecuteAdbCommandNoReturn()</c></para></remarks>
14+
public class AdbCommand
15+
{
16+
private string command;
17+
internal string Command { get { return this.command; } }
18+
internal AdbCommand(string command) { this.command = command; }
19+
}
20+
21+
/// <summary>
22+
/// Controls all commands sent to the currently running Android Debug Bridge Server
23+
/// </summary>
24+
public static class Adb
25+
{
26+
internal const string ADB = "adb";
27+
internal const string ADB_EXE = "adb.exe";
28+
29+
/// <summary>
30+
/// Forms an <see cref="AdbCommand"/> that is passed to <c>Adb.ExecuteAdbCommand()</c>
31+
/// </summary>
32+
/// <remarks><para>This should only be used for non device-specific Adb commands, such as <c>adb devices</c> or <c>adb version</c>.</para>
33+
/// <para>Never try to start/kill the running Adb Server, as the <see cref="AndroidController"/> type handles it internally.</para></remarks>
34+
/// <param name="command">The command to run on the Adb Server</param>
35+
/// <param name="args">Any arguments that need to be sent to <paramref name="command"/></param>
36+
/// <returns><see cref="AdbCommand"/> that contains formatted command information</returns>
37+
/// <example>This example demonstrates how to create an <see cref="AdbCommand"/>
38+
/// <code>
39+
/// //This example shows how to create an AdbCommand object to execute on the running server.
40+
/// //The command we will create is "adb devices".
41+
/// //Notice how in the formation, you don't supply the prefix "adb", because the method takes care of it for you.
42+
///
43+
/// AdbCommand adbCmd = Adb.FormAdbCommand("devices");
44+
///
45+
/// </code>
46+
/// </example>
47+
public static AdbCommand FormAdbCommand(string command, params object[] args)
48+
{
49+
string adbCommand = (args.Length > 0) ? command + " " : command;
50+
51+
for (int i = 0; i < args.Length; i++)
52+
adbCommand += args[i] + " ";
53+
54+
return new AdbCommand(adbCommand);
55+
}
56+
57+
/// <summary>
58+
/// Forms an <see cref="AdbCommand"/> that is passed to <c>Adb.ExecuteAdbCommand()</c>
59+
/// </summary>
60+
/// <remarks>This should only be used for device-specific Adb commands, such as <c>adb push</c> or <c>adb pull</c>.</remarks>
61+
/// <param name="device">Specific <see cref="Device"/> to run the command on</param>
62+
/// <param name="command">The command to run on the Adb Server</param>
63+
/// <param name="args">Any arguments that need to be sent to <paramref name="command"/></param>
64+
/// <returns><see cref="AdbCommand"/> that contains formatted command information</returns>
65+
/// <example>This example demonstrates how to create an <see cref="AdbCommand"/>
66+
/// <code>//This example shows how to create an AdbCommand object to execute on the running server.
67+
/// //The command we will create is "adb pull /system/app C:\".
68+
/// //Notice how in the formation, you don't supply the prefix "adb", because the method takes care of it for you.
69+
/// //This example also assumes you have a Device instance named device.
70+
///
71+
/// AdbCommand adbCmd = Adb.FormAdbCommand(device, "pull", "/system/app", @"C:\");
72+
///
73+
/// </code>
74+
/// </example>
75+
public static AdbCommand FormAdbCommand(Device device, string command, params object[] args)
76+
{
77+
return FormAdbCommand("-s " + device.SerialNumber + " " + command, args);
78+
}
79+
80+
/// <summary>
81+
/// Forms an <see cref="AdbCommand"/> that is passed to <c>Adb.ExecuteAdbCommand()</c>
82+
/// </summary>
83+
/// <param name="device">Specific <see cref="Device"/> to run the command on</param>
84+
/// <param name="rootShell">Specifies if you need <paramref name="executable"/> to run in a root shell</param>
85+
/// <param name="executable">Executable file on <paramref name="device"/> to execute</param>
86+
/// <param name="args">Any arguments that need to be sent to <paramref name="executable"/></param>
87+
/// <returns><see cref="AdbCommand"/> that contains formatted command information</returns>
88+
/// <remarks>This should only be used for Adb Shell commands, such as <c>adb shell getprop</c> or <c>adb shell dumpsys</c>.</remarks>
89+
/// <exception cref="DeviceHasNoRootException"> if <paramref name="device"/> does not have root</exception>
90+
/// <example>This example demonstrates how to create an <see cref="AdbCommand"/>
91+
/// <code>
92+
/// //This example shows how to create an AdbCommand object to execute on the running server.
93+
/// //The command we will create is "adb shell input keyevent KeyEventCode.HOME".
94+
/// //Notice how in the formation, you don't supply the prefix "adb", because the method takes care of it for you.
95+
/// //This example also assumes you have a Device instance named device.
96+
///
97+
/// AdbCommand adbCmd = Adb.FormAdbCommand(device, "input", "keyevent", (int)KeyEventCode.HOME);
98+
///
99+
/// </code>
100+
/// </example>
101+
public static AdbCommand FormAdbShellCommand(Device device, bool rootShell, string executable, params object[] args)
102+
{
103+
if (rootShell && !device.HasRoot)
104+
throw new DeviceHasNoRootException();
105+
106+
string shellCommand = string.Format("-s {0} shell \"", device.SerialNumber);
107+
108+
if (rootShell)
109+
shellCommand += "su -c \"";
110+
111+
shellCommand += executable;
112+
113+
for (int i = 0; i < args.Length; i++)
114+
shellCommand += " " + args[i];
115+
116+
if (rootShell)
117+
shellCommand += "\"";
118+
119+
shellCommand += "\"";
120+
121+
return new AdbCommand(shellCommand);
122+
}
123+
124+
/// <summary>
125+
/// Opens Adb Shell and allows input to be typed directly to the shell. Experimental!
126+
/// </summary>
127+
/// <remarks>Added specifically for RegawMOD CDMA Hero Rooter. Always remember to pass "exit" as the last command or it will not return!</remarks>
128+
/// <param name="device">Specific <see cref="Device"/> to run the command on</param>
129+
/// <param name="inputLines">Lines of commands to send to shell</param>
130+
public static void ExecuteAdbShellCommandInputString(Device device, params string[] inputLines)
131+
{
132+
Command.RunProcessWriteInput(AndroidController.Instance.ResourceDirectory + ADB_EXE, "shell", inputLines);
133+
}
134+
135+
/// <summary>
136+
/// Executes an <see cref="AdbCommand"/> on the running Adb Server
137+
/// </summary>
138+
/// <remarks>This should be used if you want the output of the command returned</remarks>
139+
/// <param name="command">Instance of <see cref="AdbCommand"/></param>
140+
/// <returns>Output of <paramref name="command"/> run on server</returns>
141+
public static string ExecuteAdbCommand(AdbCommand command)
142+
{
143+
return Command.RunProcessReturnOutput(AndroidController.Instance.ResourceDirectory + ADB_EXE, command.Command);
144+
}
145+
146+
/// <summary>
147+
/// Executes an <see cref="AdbCommand"/> on the running Adb Server
148+
/// </summary>
149+
/// <remarks>This should be used if you do not want the output of the command returned. Good for quick abd shell commands</remarks>
150+
/// <param name="command">Instance of <see cref="AdbCommand"/></param>
151+
/// <returns>Output of <paramref name="command"/> run on server</returns>
152+
public static void ExecuteAdbCommandNoReturn(AdbCommand command)
153+
{
154+
Command.RunProcessNoReturn(AndroidController.Instance.ResourceDirectory + ADB_EXE, command.Command);
155+
}
156+
157+
/// <summary>
158+
/// Gets a value indicating if an Android Debug Bridge Server is currently running.
159+
/// </summary>
160+
public static bool ServerRunning
161+
{
162+
get { return Command.IsProcessRunning(Adb.ADB); }
163+
}
164+
165+
internal static void StartServer()
166+
{
167+
ExecuteAdbCommandNoReturn(Adb.FormAdbCommand("start-server"));
168+
}
169+
170+
internal static void KillServer()
171+
{
172+
ExecuteAdbCommandNoReturn(Adb.FormAdbCommand("kill-server"));
173+
}
174+
175+
/// <summary>
176+
/// Forwards a port that remains until the current <see cref="AndroidController"/> instance is Disposed, or the device is unplugged
177+
/// </summary>
178+
/// <remarks>Only supports tcp: forward spec for now</remarks>
179+
/// <param name="device">Instance of <see cref="Device"/> to apply port forwarding to</param>
180+
/// <param name="localPort">Local port number</param>
181+
/// <param name="remotePort">Remote port number</param>
182+
/// <returns>True if successful, false if unsuccessful</returns>
183+
public static bool PortForward(Device device, int localPort, int remotePort)
184+
{
185+
bool success = false;
186+
187+
AdbCommand adbCmd = Adb.FormAdbCommand(device, "forward", "tcp:" + localPort, "tcp:" + remotePort);
188+
using (StringReader r = new StringReader(ExecuteAdbCommand(adbCmd)))
189+
{
190+
if (r.ReadToEnd().Trim() == "")
191+
success = true;
192+
}
193+
194+
return success;
195+
}
196+
}
197+
}

0 commit comments

Comments
 (0)