diff options
Diffstat (limited to 'server/Brokenithm-Evolved-iOS')
| -rw-r--r-- | server/Brokenithm-Evolved-iOS/App.config | 6 | ||||
| -rw-r--r-- | server/Brokenithm-Evolved-iOS/Brokenithm-Evolved-iOS.csproj | 108 | ||||
| -rw-r--r-- | server/Brokenithm-Evolved-iOS/Brokenithm.ico | bin | 0 -> 12862 bytes | |||
| -rw-r--r-- | server/Brokenithm-Evolved-iOS/Program.cs | 343 | ||||
| -rw-r--r-- | server/Brokenithm-Evolved-iOS/Properties/AssemblyInfo.cs | 36 | ||||
| -rw-r--r-- | server/Brokenithm-Evolved-iOS/packages.config | 4 |
6 files changed, 497 insertions, 0 deletions
diff --git a/server/Brokenithm-Evolved-iOS/App.config b/server/Brokenithm-Evolved-iOS/App.config new file mode 100644 index 0000000..ecdcf8a --- /dev/null +++ b/server/Brokenithm-Evolved-iOS/App.config @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <startup> + <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/> + </startup> +</configuration> diff --git a/server/Brokenithm-Evolved-iOS/Brokenithm-Evolved-iOS.csproj b/server/Brokenithm-Evolved-iOS/Brokenithm-Evolved-iOS.csproj new file mode 100644 index 0000000..9f5fe70 --- /dev/null +++ b/server/Brokenithm-Evolved-iOS/Brokenithm-Evolved-iOS.csproj @@ -0,0 +1,108 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{D127D9DF-1FB2-48F1-A8ED-F50D9852732A}</ProjectGuid> + <OutputType>Exe</OutputType> + <RootNamespace>Brokenithm_Evolved_iOS_Umi</RootNamespace> + <AssemblyName>Brokenithm-Evolved-iOS-Umi</AssemblyName> + <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> + <Deterministic>true</Deterministic> + <TargetFrameworkProfile /> + <NuGetPackageImportStamp> + </NuGetPackageImportStamp> + <IsWebBootstrapper>false</IsWebBootstrapper> + <PublishUrl>publish\</PublishUrl> + <Install>true</Install> + <InstallFrom>Disk</InstallFrom> + <UpdateEnabled>false</UpdateEnabled> + <UpdateMode>Foreground</UpdateMode> + <UpdateInterval>7</UpdateInterval> + <UpdateIntervalUnits>Days</UpdateIntervalUnits> + <UpdatePeriodically>false</UpdatePeriodically> + <UpdateRequired>false</UpdateRequired> + <MapFileExtensions>true</MapFileExtensions> + <AutorunEnabled>true</AutorunEnabled> + <ApplicationRevision>1</ApplicationRevision> + <ApplicationVersion>1.0.0.%2a</ApplicationVersion> + <UseApplicationTrust>false</UseApplicationTrust> + <PublishWizardCompleted>true</PublishWizardCompleted> + <BootstrapperEnabled>true</BootstrapperEnabled> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup> + <GenerateManifests>true</GenerateManifests> + </PropertyGroup> + <PropertyGroup> + <SignManifests>true</SignManifests> + </PropertyGroup> + <PropertyGroup> + <ApplicationIcon>Brokenithm.ico</ApplicationIcon> + </PropertyGroup> + <ItemGroup> + <Reference Include="iMobileDevice-net, Version=1.2.0.0, Culture=neutral, PublicKeyToken=040ae19651fac98a, processorArchitecture=MSIL"> + <HintPath>..\packages\iMobileDevice-net.1.2.186\lib\net45\iMobileDevice-net.dll</HintPath> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Net.Http" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Program.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="App.config" /> + <None Include="packages.config" /> + </ItemGroup> + <ItemGroup> + <BootstrapperPackage Include=".NETFramework,Version=v4.7.2"> + <Visible>False</Visible> + <ProductName>Microsoft .NET Framework 4.7.2 %28x86 和 x64%29</ProductName> + <Install>true</Install> + </BootstrapperPackage> + <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> + <Visible>False</Visible> + <ProductName>.NET Framework 3.5 SP1</ProductName> + <Install>false</Install> + </BootstrapperPackage> + </ItemGroup> + <ItemGroup> + <Content Include="Brokenithm.ico" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <Import Project="..\packages\iMobileDevice-net.1.2.186\build\net45\iMobileDevice-net.targets" Condition="Exists('..\packages\iMobileDevice-net.1.2.186\build\net45\iMobileDevice-net.targets')" /> + <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> + <PropertyGroup> + <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText> + </PropertyGroup> + <Error Condition="!Exists('..\packages\iMobileDevice-net.1.2.186\build\net45\iMobileDevice-net.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\iMobileDevice-net.1.2.186\build\net45\iMobileDevice-net.targets'))" /> + </Target> +</Project>
\ No newline at end of file diff --git a/server/Brokenithm-Evolved-iOS/Brokenithm.ico b/server/Brokenithm-Evolved-iOS/Brokenithm.ico Binary files differnew file mode 100644 index 0000000..8033b43 --- /dev/null +++ b/server/Brokenithm-Evolved-iOS/Brokenithm.ico diff --git a/server/Brokenithm-Evolved-iOS/Program.cs b/server/Brokenithm-Evolved-iOS/Program.cs new file mode 100644 index 0000000..f6785cb --- /dev/null +++ b/server/Brokenithm-Evolved-iOS/Program.cs @@ -0,0 +1,343 @@ +using iMobileDevice; +using iMobileDevice.iDevice; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO.MemoryMappedFiles; +using System.Linq; +using System.Security.Principal; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Brokenithm_Evolved_iOS +{ + class Program + { + public static Dictionary<string, iDeviceHandle> device_map = new Dictionary<string, iDeviceHandle>(); + public static Dictionary<string, Process> process_map = new Dictionary<string, Process>(); + public static Dictionary<string, iDeviceConnectionHandle> connection_map = new Dictionary<string, iDeviceConnectionHandle>(); + public static IiDeviceApi idevice; + public static MemoryMappedFile sharedBuffer; + public static MemoryMappedViewAccessor sharedBufferAccessor; + public static bool exiting = false; + public static iDeviceEventCallBack _eventCallback; + + static void Main(string[] args) + { + Console.Title = "Brokenithm-Evolved-iOS"; + Console.WriteLine("================================================="); + Console.WriteLine("= Brokenithm-Evolved-iOS (Umi) ="); + Console.WriteLine("= Brokenithm with full IO and USB connection ="); + Console.WriteLine("= v0.3 by esterTion ="); + Console.WriteLine("= Modified for Umiguri usage by Pinapelz ="); + Console.WriteLine("= Original: thebit.link ="); + Console.WriteLine("================================================="); + Console.WriteLine(""); + + NativeLibraries.Load(); + idevice = LibiMobileDevice.Instance.iDevice; + iDeviceError status; + _eventCallback = new iDeviceEventCallBack(eventCallback); + status = LibiMobileDevice.Instance.iDevice.idevice_event_subscribe(_eventCallback, IntPtr.Zero); + + MemoryMappedFileSecurity CustomSecurity = new MemoryMappedFileSecurity(); + SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null); + var acct = sid.Translate(typeof(NTAccount)) as NTAccount; + CustomSecurity.AddAccessRule(new System.Security.AccessControl.AccessRule<MemoryMappedFileRights>(acct.ToString(), MemoryMappedFileRights.FullControl, System.Security.AccessControl.AccessControlType.Allow)); + sharedBuffer = MemoryMappedFile.CreateOrOpen("Local\\BROKENITHM_SHARED_BUFFER", 1024, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, CustomSecurity, System.IO.HandleInheritability.Inheritable); + sharedBufferAccessor = sharedBuffer.CreateViewAccessor(); + + { + Thread ledThread = new Thread(new ThreadStart(outputLed)); + ledThread.Start(); + } + + Console.WriteLine("Waiting for device..."); + while (Console.ReadKey().Key != ConsoleKey.Q) { } + exiting = true; + } + + public static void eventCallback(ref iDeviceEvent e, IntPtr user_data) + { + iDeviceError status; + string udid = e.udidString; + switch (e.@event) + { + case iDeviceEventType.DeviceAdd: + { + Console.WriteLine(string.Format("device add\tudid: {0}", udid)); + if (device_map.ContainsKey(udid)) + { + return; + } + iDeviceHandle device; + status = idevice.idevice_new(out device, e.udidString); + if (status != iDeviceError.Success) + { + Console.WriteLine("Create device failed: {0}", status); + return; + } + device_map[udid] = device; + + Process process = new Process(); + process.StartInfo.FileName = @"umi-evolved\brokenithm-evolved-umi.exe"; + try + { + process.Start(); + + } + catch(Exception ex){ + Console.WriteLine("Unable to launch brokenithm-evolved-umi server. Is the .exe there?"); + Console.WriteLine("Current Directory: " + Environment.CurrentDirectory); + Console.WriteLine("Press Enter to continue..."); + Console.ReadLine(); + Environment.Exit(0); + } + process_map[udid] = process; + + Thread thread = new Thread(new ParameterizedThreadStart(connectDevice)); + thread.Start(udid); + break; + } + case iDeviceEventType.DevicePaired: + { + Console.WriteLine(string.Format("device paired\tudid: {0}", udid)); + break; + } + case iDeviceEventType.DeviceRemove: + { + Console.WriteLine(string.Format("device remove\tudid: {0}", udid)); + if (device_map.ContainsKey(udid)) + { + iDeviceHandle device = device_map[udid]; + device.Dispose(); + device_map.Remove(udid); + } + if (process_map.ContainsKey(udid)) + { + try + { + Process processToKill = process_map[udid]; + if (!processToKill.HasExited) + { + processToKill.Kill(); + } + processToKill.Dispose(); + process_map.Remove(udid); + } + catch (Exception ex) + { + Console.WriteLine($"Error killing process for device {udid}: {ex.Message}"); + } + } + break; + } + } + } + + public static void connectDevice(object arg) + { + string udid = (string)arg; + if (!device_map.ContainsKey(udid)) + { + return; + } + iDeviceHandle device = device_map[udid]; + iDeviceConnectionHandle conn; + iDeviceError status; + status = idevice.idevice_connect(device, 24864, out conn); + if (status != iDeviceError.Success) + { + //Console.WriteLine(string.Format("connect failed: {0}", status)); + Thread.Sleep(1000); + Thread thread = new Thread(new ParameterizedThreadStart(connectDevice)); + thread.Start(udid); + return; + } + + byte[] buf = new byte[256]; + uint read = 0; + status = idevice.idevice_connection_receive(conn, buf, 4, ref read); + if (status != iDeviceError.Success) + { + Console.WriteLine(string.Format("receive data failed: {0}", status)); + return; + } + if ( + buf[0] != 3 || + buf[1] != 'W' || + buf[2] != 'E' || + buf[3] != 'L' + ) + { + // welcome message + Console.WriteLine("received invalid data"); + conn.Dispose(); + return; + } + Console.WriteLine("connected to device"); + connection_map[udid] = conn; + { + Thread thread = new Thread(new ParameterizedThreadStart(readInputFromDevice)); + thread.Start(udid); + } + return; + } + public static void readInputFromDevice(object arg) + { + string udid = (string)arg; + if (!connection_map.ContainsKey(udid)) + { + return; + } + iDeviceConnectionHandle conn = connection_map[udid]; + iDeviceError status; + bool airEnabled = true; + + byte[] buf = new byte[256]; + uint read = 0; + while (true) + { + if (exiting) break; + status = idevice.idevice_connection_receive_timeout(conn, buf, 1, ref read, 5); + if (status != iDeviceError.Success) + { + if (status == iDeviceError.Timeout) + { + continue; + } + break; + } + byte len = buf[0]; + status = idevice.idevice_connection_receive_timeout(conn, buf, len, ref read, 5); + if (status != iDeviceError.Success) + { + break; + } + if (len >= 3+6+32 && + buf[0] == 'I' && + buf[1] == 'N' && + buf[2] == 'P') + { + // key input + if (airEnabled) + { + sharedBufferAccessor.WriteArray<byte>(0, buf, 3, 6 + 32); + } + else + { + sharedBufferAccessor.WriteArray<byte>(6, buf, 3 + 6, 32); + } + if (len > 3 + 6 + 32) + { + sharedBufferAccessor.WriteArray<byte>(6+32+96, buf, 3+6+32, len - (3 + 6 + 32)); + } + } + else if (len >= 4 && + buf[0] == 'A' && + buf[1] == 'I' && + buf[2] == 'R') + { + // air input control + airEnabled = buf[3] != 0; + Console.WriteLine(string.Format("Air input {0}", airEnabled ? "enabled" : "disabled")); + } + else if (len >= 4 && + buf[0] == 'F' && + buf[1] == 'N' && + buf[2] == 'C') + { + // function key + if (buf[3] == (byte)BNI_FUNCTION_KEYS.COIN) + { + sharedBufferAccessor.Write(6 + 32 + 96 + 2, 1); + } + else if (buf[3] == (byte)BNI_FUNCTION_KEYS.CARD) + { + sharedBufferAccessor.Write(6 + 32 + 96 + 3, 1); + } + } + else + { + if (len >= 3) + { + StringBuilder sb = new StringBuilder(); + sb.Append((char)buf[0]); + sb.Append((char)buf[1]); + sb.Append((char)buf[2]); + Console.WriteLine(string.Format("unknown packet: {0}", sb.ToString())); + } + else + { + Console.WriteLine("unknown packet"); + } + } + } + conn.Dispose(); + connection_map.Remove(udid); + Console.WriteLine("disconnected"); + if (exiting) return; + Thread.Sleep(1000); + { + Thread thread = new Thread(new ParameterizedThreadStart(connectDevice)); + thread.Start(udid); + } + } + + enum BNI_FUNCTION_KEYS { + COIN = 1, + CARD + }; + + private static byte[] prevLedRgb = new byte[32 * 3]; + private static int skipCount = 0; + public static void outputLed() + { + while (true) + { + if (exiting) break; + byte[] ledRgb = new byte[32 * 3]; + sharedBufferAccessor.ReadArray<byte>(6 + 32, ledRgb, 0, 32 * 3); + bool same = true; + for (int i = 0; i < 32 * 3; i++) + { + if (ledRgb[i] != prevLedRgb[i]) + { + same = false; + break; + } + } + if (!same) + { + BroadcastLEDStatus(ledRgb); + prevLedRgb = ledRgb; + skipCount = 0; + } + else + { + if (++skipCount > 50) + { + BroadcastLEDStatus(prevLedRgb); + skipCount = 0; + } + } + Thread.Sleep(10); + } + } + public static void BroadcastLEDStatus(byte[] led) + { + uint sent = 0; + byte[] head = { 99, (byte)'L', (byte)'E', (byte)'D' }; + foreach (var conn in connection_map) + { + try + { + idevice.idevice_connection_send(conn.Value, head, 4, ref sent); + idevice.idevice_connection_send(conn.Value, led, 96, ref sent); + } + catch (Exception e) { } + } + } + } +} diff --git a/server/Brokenithm-Evolved-iOS/Properties/AssemblyInfo.cs b/server/Brokenithm-Evolved-iOS/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0e57bf6 --- /dev/null +++ b/server/Brokenithm-Evolved-iOS/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Brokenithm-Evolved-iOS")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Brokenithm-Evolved-iOS")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("d127d9df-1fb2-48f1-a8ed-f50d9852732a")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/server/Brokenithm-Evolved-iOS/packages.config b/server/Brokenithm-Evolved-iOS/packages.config new file mode 100644 index 0000000..4266474 --- /dev/null +++ b/server/Brokenithm-Evolved-iOS/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="iMobileDevice-net" version="1.2.186" targetFramework="net472" /> +</packages>
\ No newline at end of file |
