Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proof of concept of refreshing tokens from battle.net #11

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 60 additions & 59 deletions ExamplePlugin/ExamplePlugin.csproj
Original file line number Diff line number Diff line change
@@ -1,60 +1,61 @@
<?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>{F4082EAF-1C0B-42C8-8859-B4CF3055677E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ExamplePlugin</RootNamespace>
<AssemblyName>ExamplePlugin</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<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="ExamplePlugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MultiInstanceManager\MultiInstanceManager.csproj">
<Project>{992169F7-40F2-49FF-9F74-75463C30740F}</Project>
<Name>MultiInstanceManager</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>if $(ConfigurationName)==Debug (
<?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>{F4082EAF-1C0B-42C8-8859-B4CF3055677E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ExamplePlugin</RootNamespace>
<AssemblyName>ExamplePlugin</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<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="ExamplePlugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MultiInstanceManager\MultiInstanceManager.csproj">
<Project>{992169F7-40F2-49FF-9F74-75463C30740F}</Project>
<Name>MultiInstanceManager</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>if not exist "$(TargetDir)\plugins" mkdir "$(TargetDir)\plugins"
if $(ConfigurationName)==Debug (
echo "Copying to Debug"
if exist "$(TargetDir)\..\\..\\..\\..\\MultiInstanceManager\\bin\\x64\\Debug\\plugins\\ExamplePlugin.dll" ( Del "$(TargetDir)\..\\..\\..\\..\\MultiInstanceManager\\bin\\x64\\Debug\\plugins\\ExamplePlugin.dll" )
copy /Y "$(TargetDir)\\ExamplePlugin.dll" "$(TargetDir)\\..\\..\\..\\..\\MultiInstanceManager\\bin\\x64\\Debug\\plugins\\"
Expand All @@ -63,6 +64,6 @@ echo "Copying to Release"
if exist "$(TargetDir)\..\\..\\..\\MultiInstanceManager\\bin\\x64\\Release\\plugins\\ExamplePlugin.dll" ( Del "$(TargetDir)\..\\..\\..\\MultiInstanceManager\\bin\\x64\\Release\\plugins\\ExamplePlugin.dll" )
copy /Y "$(TargetDir)\\ExamplePlugin.dll" "$(TargetDir)\..\\..\\..\\MultiInstanceManager\\bin\\x64\\Release\\plugins\\"
)
</PostBuildEvent>
</PropertyGroup>
</PostBuildEvent>
</PropertyGroup>
</Project>
41 changes: 30 additions & 11 deletions MultiInstanceManager/Modules/MultiHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand Down Expand Up @@ -124,6 +126,31 @@ public ActiveWindow SwapFocus(Profile account)
}
return activeWindow;
}

private static readonly byte[] Entropy = { 0xc8, 0x76, 0xf4, 0xae, 0x4c, 0x95, 0x2e, 0xfe, 0xf2, 0xfa, 0x0f, 0x54, 0x19, 0xc0, 0x9c, 0x43 };

public bool SetupWithBrowser(string displayName = "")
{
Log.Clear();
if (displayName.Length == 0)
{
displayName = Prompt.ShowDialog("Enter desired displayname for this account:", "Add Account");
}
RefreshAccountToken refresher = new RefreshAccountToken();
var result = refresher.ShowDialog();
if (result == DialogResult.OK)
{
//this is what we store in WEB_TOKEN
byte[] protectedKey = ProtectedData.Protect(Encoding.UTF8.GetBytes(refresher.Token), Entropy, DataProtectionScope.CurrentUser);
File.WriteAllBytes($"{displayName}.bin", protectedKey);
}
else
{
MessageBox.Show("No login token found.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
return result == DialogResult.OK;
}

public bool Setup(string displayName = "", Boolean killProcessesWhenDone = true)
{
Log.Clear();
Expand Down Expand Up @@ -232,7 +259,7 @@ public bool Setup(string displayName = "", Boolean killProcessesWhenDone = true)
freneticClickingCTS.Dispose();
}
// Export the received key using the name of the recipient
ExportToken(displayName + ".bin");
//ExportToken(displayName + ".bin");
Log.Debug("Successfully saved new token for " + displayName);

Log.Debug("Closing launcher and client mutex handles");
Expand Down Expand Up @@ -377,7 +404,7 @@ public async Task LaunchWithAccount(string accountName, string cmdArgs = "")
{
WindowHelper.SetWindowPosition(process.MainWindowHandle, profile.LaunchOptions.WindowX, profile.LaunchOptions.WindowY);
}
ExportToken(accountName + ".bin");
//ExportToken(accountName + ".bin");
// Log.Debug("Closing mutex handles");
activeWindows?.Add(new ActiveWindow { Process = process, Profile = profile });
// ProcessManager.CloseExternalHandles(process.ProcessName); // kill all D2R mutex handles
Expand Down Expand Up @@ -585,15 +612,7 @@ private void WaitForNewToken(Process process, Boolean timeout = false)
Log.Debug("Token remains the same");
}
}
public void DumpCurrentRegKey()
{
ExportToken("dump.bin");
}
private void ExportToken(string fileName)
{
Log.Debug("Writing to file: " + fileName);
File.WriteAllBytes(fileName, (byte[])Registry.GetValue(Constants.accountRegKey[0], Constants.accountRegKey[1], ""));
}

private void UseAccountToken(string accountName)
{
Log.Debug("Reading from file: " + accountName + ".bin");
Expand Down
10 changes: 5 additions & 5 deletions MultiInstanceManager/MultiInstanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,14 @@ public void forceExit_Changed(object sender, EventArgs e)
}
private void dumpRegKeyButton_Click(object sender, EventArgs e)
{
MH.DumpCurrentRegKey();
//MH.DumpCurrentRegKey();
}
private async void addAccountButton_Click(object sender, EventArgs e)
{
DisableButtons();
var task = Task.Factory.StartNew(() => MH.Setup());
var result = await task;
//var task = Task.Factory.StartNew(() => MH.Setup());
//var result = await task;
MH.SetupWithBrowser();
EnableButtons();
MH.LoadProfiles();
}
Expand Down Expand Up @@ -319,8 +320,7 @@ private async void refreshButton_Click(object sender, System.EventArgs e)
{
var checkedItem = accountList.CheckedItems[x].ToString().Split('|');
DisableButtons();
var task = Task.Factory.StartNew(() => MH.Setup(checkedItem[0].Trim(' '), true));
var result = await task;
MH.SetupWithBrowser(checkedItem[0].Trim(' '));
EnableButtons();
}
catch (Exception ex)
Expand Down
Loading