Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
Yu Yuphoria support and misc changes
Browse files Browse the repository at this point in the history
Yu Yuphoria supported
libsuperuser project referenced as submodule
Randomize function now changes only last 6 hex digits to preserve OUI
  • Loading branch information
ViRb3 committed Jun 13, 2016
1 parent 3c5849e commit 6ba3b08
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "libsuperuser"]
path = libsuperuser
url = https://github.com/ViRb3/libsuperuser
1 change: 1 addition & 0 deletions libsuperuser
Submodule libsuperuser added at 1cf006
6 changes: 6 additions & 0 deletions nMAC.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
50 changes: 50 additions & 0 deletions nMAC/Devices/YuYuphoria.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
14 changes: 7 additions & 7 deletions nMAC/MACFunctions.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -39,12 +38,13 @@ internal static async Task AssignPaths(Context context)

private static async Task<DeviceModel> DetectDevice()
{
List<DeviceModel> devices = new List<DeviceModel>()
List<DeviceModel> devices = new List<DeviceModel>() // 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<string> result = null;
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 4 additions & 9 deletions nMAC/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -204,19 +204,14 @@ private void SetMACViews(string MAC, bool excludeFirst = false)

RelativeLayout layoutMAC = this.FindViewById<RelativeLayout>(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];
editMAC.Hint = MACArray[i];
}
}

private void SetMACViewsForRandom(string MAC)
{
SetMACViews(MAC, true);
}

private string GetMACFromViews()
{
RelativeLayout layoutMAC = this.FindViewById<RelativeLayout>(Resource.Id.layoutMAC);
Expand Down
2 changes: 1 addition & 1 deletion nMAC/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="virb3e.nMAC" android:versionCode="6" android:versionName="1.105" android:installLocation="auto">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="virb3e.nMAC" android:versionCode="8" android:versionName="1.106" android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Expand Down
14 changes: 9 additions & 5 deletions nMAC/nMAC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@
<DebugSymbols>False</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="libsuperuser">
<HintPath>..\..\libsuperuser\libsuperuser\bin\Release\libsuperuser.dll</HintPath>
</Reference>
<Reference Include="Java.Interop" />
<Reference Include="Mono.Android" />
<Reference Include="mscorlib" />
<Reference Include="System" />
Expand All @@ -76,6 +74,7 @@
<Compile Include="DeviceModel.cs" />
<Compile Include="Devices\Nexus5.cs" />
<Compile Include="Devices\Samsung.cs" />
<Compile Include="Devices\YuYuphoria.cs" />
<Compile Include="MACFunctions.cs" />
<Compile Include="Helpers.cs" />
<Compile Include="Logger.cs" />
Expand All @@ -102,7 +101,12 @@
<ItemGroup>
<None Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<ProjectReference Include="..\libsuperuser\libsuperuser\libsuperuser.csproj">
<Project>{7f7c56a6-5a62-469c-b6f0-187cc8801cb0}</Project>
<Name>libsuperuser</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\mipmap-hdpi\ic_launcher.png" />
</ItemGroup>
Expand All @@ -126,4 +130,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

0 comments on commit 6ba3b08

Please sign in to comment.