From 6ba3b08f86ee40db330d010f215533033693c816 Mon Sep 17 00:00:00 2001 From: ViR Dash Date: Sun, 12 Jun 2016 19:16:15 -0500 Subject: [PATCH] Yu Yuphoria support and misc changes Yu Yuphoria supported libsuperuser project referenced as submodule Randomize function now changes only last 6 hex digits to preserve OUI --- .gitmodules | 3 ++ libsuperuser | 1 + nMAC.sln | 6 ++++ nMAC/Devices/YuYuphoria.cs | 50 +++++++++++++++++++++++++++++ nMAC/MACFunctions.cs | 14 ++++---- nMAC/MainActivity.cs | 13 +++----- nMAC/Properties/AndroidManifest.xml | 2 +- nMAC/nMAC.csproj | 14 +++++--- 8 files changed, 81 insertions(+), 22 deletions(-) create mode 100644 .gitmodules create mode 160000 libsuperuser create mode 100644 nMAC/Devices/YuYuphoria.cs diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..aba2976 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libsuperuser"] + path = libsuperuser + url = https://github.com/ViRb3/libsuperuser diff --git a/libsuperuser b/libsuperuser new file mode 160000 index 0000000..1cf006a --- /dev/null +++ b/libsuperuser @@ -0,0 +1 @@ +Subproject commit 1cf006a3e79b1d9359c321de2126b1b3e75459a8 diff --git a/nMAC.sln b/nMAC.sln index 7cae0bb..4f66594 100644 --- a/nMAC.sln +++ b/nMAC.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 14.0.25123.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nMAC", "nMAC\nMAC.csproj", "{DBF37831-A238-44E2-AA06-A22F173FC396}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "libsuperuser", "libsuperuser\libsuperuser\libsuperuser.csproj", "{7F7C56A6-5A62-469C-B6F0-187CC8801CB0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -17,6 +19,10 @@ Global {DBF37831-A238-44E2-AA06-A22F173FC396}.Release|Any CPU.ActiveCfg = Release|Any CPU {DBF37831-A238-44E2-AA06-A22F173FC396}.Release|Any CPU.Build.0 = Release|Any CPU {DBF37831-A238-44E2-AA06-A22F173FC396}.Release|Any CPU.Deploy.0 = Release|Any CPU + {7F7C56A6-5A62-469C-B6F0-187CC8801CB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7F7C56A6-5A62-469C-B6F0-187CC8801CB0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7F7C56A6-5A62-469C-B6F0-187CC8801CB0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7F7C56A6-5A62-469C-B6F0-187CC8801CB0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/nMAC/Devices/YuYuphoria.cs b/nMAC/Devices/YuYuphoria.cs new file mode 100644 index 0000000..30a8958 --- /dev/null +++ b/nMAC/Devices/YuYuphoria.cs @@ -0,0 +1,50 @@ +using System.Text.RegularExpressions; + +namespace nMAC.Devices +{ + class YuYuphoria : DeviceModel + { + internal YuYuphoria() + { + this.Path = "/sys/devices/soc.0/a000000.qcom,wcnss-wlan/wcnss_mac_addr"; + this.FileSyntax = new Regex(@"^([0-9a-f]{2}[:]){5}([0-9a-f]{2})\n*$"); + } + + internal override bool CheckFile(string content) + { + if (this.FileSyntax.IsMatch(content)) + return true; + + return false; + } + + internal override string ExtractMACFromFile(string content) + { + return content.Replace(":", string.Empty); + } + + internal override void WriteMAC(ref string content, string MAC) + { + MAC = MAC.ToLower(); + string formattedMAC = string.Empty; + + int @break = 0; + for (int i = 0; i < MAC.Length;) + { + if (@break < 2) + { + formattedMAC += MAC[i]; + @break++; + i++; + } + else + { + @break = 0; + formattedMAC += ":"; + } + } + + content = formattedMAC; + } + } +} \ No newline at end of file diff --git a/nMAC/MACFunctions.cs b/nMAC/MACFunctions.cs index 8bc987a..1543f5f 100644 --- a/nMAC/MACFunctions.cs +++ b/nMAC/MACFunctions.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.IO; -using System.Text.RegularExpressions; using System.Threading.Tasks; using Android.Content; using EU.Chainfire.Libsuperuser; @@ -39,12 +38,13 @@ internal static async Task AssignPaths(Context context) private static async Task DetectDevice() { - List devices = new List() + List devices = new List() // Priority, 1 is highest { - new Nexus5(), - new Nexus5X(), - new Samsung(), - new OnePlusOne() // must be after Nexus5X due to conflict + new Nexus5(), // 100 + new Nexus5X(), //100 + new Samsung(), // 100 + new YuYuphoria(), //100 + new OnePlusOne() // 1000 - conflict - N5X }; IList result = null; @@ -84,7 +84,7 @@ internal static string ReadMAC(Context context) return null; } - return Device.ExtractMACFromFile(content); + return Device.ExtractMACFromFile(content).ToUpper(); } internal static void WriteMAC(ref byte[] content, string MAC) diff --git a/nMAC/MainActivity.cs b/nMAC/MainActivity.cs index aa59d37..b686444 100644 --- a/nMAC/MainActivity.cs +++ b/nMAC/MainActivity.cs @@ -111,9 +111,9 @@ private async void BtnChange_Click(object sender, EventArgs e) private void BtnRandomize_Click(object sender, EventArgs e) { - int MAC1 = _random.Next(0x111111, 0xffffff); - int MAC2 = _random.Next(0x111111, 0xffffff); - SetMACViewsForRandom(MAC1.ToString("X") + MAC2.ToString("X")); + int MAC1 = _random.Next(0x111111, 0xffffff); // 6/12 + int MAC2 = _random.Next(0x111111, 0xffffff); // 12/12 + SetMACViews(MAC1.ToString("X") + MAC2.ToString("X"), true); } private void ToggleViews(bool state) @@ -204,7 +204,7 @@ private void SetMACViews(string MAC, bool excludeFirst = false) RelativeLayout layoutMAC = this.FindViewById(Resource.Id.layoutMAC); - for (int i = excludeFirst ? 1 : 0; i < layoutMAC.ChildCount; i++) + for (int i = excludeFirst ? 3 : 0; i < layoutMAC.ChildCount; i++) { EditText editMAC = (EditText)layoutMAC.GetChildAt(i); editMAC.Text = MACArray[i]; @@ -212,11 +212,6 @@ private void SetMACViews(string MAC, bool excludeFirst = false) } } - private void SetMACViewsForRandom(string MAC) - { - SetMACViews(MAC, true); - } - private string GetMACFromViews() { RelativeLayout layoutMAC = this.FindViewById(Resource.Id.layoutMAC); diff --git a/nMAC/Properties/AndroidManifest.xml b/nMAC/Properties/AndroidManifest.xml index fed2a23..50525ac 100644 --- a/nMAC/Properties/AndroidManifest.xml +++ b/nMAC/Properties/AndroidManifest.xml @@ -1,5 +1,5 @@  - + diff --git a/nMAC/nMAC.csproj b/nMAC/nMAC.csproj index 8b69588..3108957 100644 --- a/nMAC/nMAC.csproj +++ b/nMAC/nMAC.csproj @@ -64,9 +64,7 @@ False - - ..\..\libsuperuser\libsuperuser\bin\Release\libsuperuser.dll - + @@ -76,6 +74,7 @@ + @@ -102,7 +101,12 @@ - + + + {7f7c56a6-5a62-469c-b6f0-187cc8801cb0} + libsuperuser + + @@ -126,4 +130,4 @@ --> - + \ No newline at end of file