Skip to content

Commit 9fa1663

Browse files
committed
Added an opportunity to get asterisk passwords for x32 and x64 apps together.
1 parent b02b490 commit 9fa1663

File tree

9 files changed

+148
-12
lines changed

9 files changed

+148
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
WindowTextExtractor
22
=============
33

4-
WindowTextExtractor allows you to get a text from any window of an operating system including microsoft office programs, console windows and any window with support of Microsoft UI Automation (UIA). Password windows are being developed.
4+
WindowTextExtractor allows you to get a text from any window of an operating system including microsoft office programs, console windows, asterisk passwords and any window with support of Microsoft UI Automation (UIA).
55

66
Requirements
77
--------------------

WindowTextExtractor.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Global
3232
{5A4E4384-EF85-4E57-BFD6-ED0F99386E34}.Debug|Any CPU.ActiveCfg = Debug|Win32
3333
{5A4E4384-EF85-4E57-BFD6-ED0F99386E34}.Debug|x64.ActiveCfg = Debug|x64
3434
{5A4E4384-EF85-4E57-BFD6-ED0F99386E34}.Debug|x64.Build.0 = Debug|x64
35-
{5A4E4384-EF85-4E57-BFD6-ED0F99386E34}.Debug|x86.ActiveCfg = Debug|Win32
36-
{5A4E4384-EF85-4E57-BFD6-ED0F99386E34}.Debug|x86.Build.0 = Debug|Win32
35+
{5A4E4384-EF85-4E57-BFD6-ED0F99386E34}.Debug|x86.ActiveCfg = Debug|x64
36+
{5A4E4384-EF85-4E57-BFD6-ED0F99386E34}.Debug|x86.Build.0 = Debug|x64
3737
{5A4E4384-EF85-4E57-BFD6-ED0F99386E34}.Release|Any CPU.ActiveCfg = Release|Win32
3838
{5A4E4384-EF85-4E57-BFD6-ED0F99386E34}.Release|x64.ActiveCfg = Release|x64
3939
{5A4E4384-EF85-4E57-BFD6-ED0F99386E34}.Release|x64.Build.0 = Release|x64
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Diagnostics;
3+
4+
namespace WindowTextExtractor.Extensions
5+
{
6+
public static class ProcessExtensions
7+
{
8+
public static bool IsWow64Process(this Process process)
9+
{
10+
if ((Environment.OSVersion.Version.Major > 5) || ((Environment.OSVersion.Version.Major == 5) && (Environment.OSVersion.Version.Minor >= 1)))
11+
{
12+
bool retVal;
13+
return NativeMethods.IsWow64Process(process.Handle, out retVal) && retVal;
14+
}
15+
16+
return false;
17+
}
18+
}
19+
}

WindowTextExtractor/Forms/MainForm.cs

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using System.Diagnostics;
44
using System.Windows.Automation;
55
using System.Runtime.InteropServices;
6+
using System.IO;
67
using WindowTextExtractor.Extensions;
8+
using WindowTextExtractor.Utils;
79

810
namespace WindowTextExtractor.Forms
911
{
@@ -15,6 +17,9 @@ public partial class MainForm : Form, IMessageFilter
1517
private bool _isButtonTargetPasswordMouseDown;
1618
private Cursor _targetTextCursor;
1719
private Cursor _targetPasswordCursor;
20+
#if WIN32
21+
private string _64BitFilePath;
22+
#endif
1823

1924
public MainForm()
2025
{
@@ -31,12 +36,48 @@ protected override void OnLoad(EventArgs e)
3136
{
3237
base.OnLoad(e);
3338
Application.AddMessageFilter(this);
39+
40+
#if WIN32
41+
if (Environment.Is64BitOperatingSystem)
42+
{
43+
var resourceName = "WindowTextExtractor.WindowTextExtractor64.exe";
44+
var fileName = "WindowTextExtractor64.exe";
45+
var directoryName = Path.GetDirectoryName(AssemblyUtils.AssemblyLocation);
46+
_64BitFilePath = Path.Combine(directoryName, fileName);
47+
try
48+
{
49+
if (!File.Exists(_64BitFilePath))
50+
{
51+
AssemblyUtils.ExtractFileFromAssembly(resourceName, _64BitFilePath);
52+
}
53+
}
54+
catch
55+
{
56+
var message = string.Format("Failed to load {0} process!", fileName);
57+
MessageBox.Show(message, AssemblyUtils.AssemblyTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
58+
Close();
59+
}
60+
}
61+
#endif
3462
}
3563

3664
protected override void OnClosed(EventArgs e)
3765
{
3866
base.OnClosed(e);
3967
Application.RemoveMessageFilter(this);
68+
69+
#if WIN32
70+
if (Environment.Is64BitOperatingSystem && File.Exists(_64BitFilePath))
71+
{
72+
try
73+
{
74+
File.Delete(_64BitFilePath);
75+
}
76+
catch
77+
{
78+
}
79+
}
80+
#endif
4081
}
4182

4283
private void btnTargetText_MouseDown(object sender, MouseEventArgs e)
@@ -150,9 +191,23 @@ public bool PreFilterMessage(ref Message m)
150191
if (element.Current.IsPassword && _isButtonTargetPasswordMouseDown)
151192
{
152193
var elementHandle = new IntPtr(element.Current.NativeWindowHandle);
153-
NativeMethods.SetHook(Handle, elementHandle, _messageId);
154-
NativeMethods.QueryPasswordEdit();
155-
NativeMethods.UnsetHook(Handle, elementHandle);
194+
int processId;
195+
NativeMethods.GetWindowThreadProcessId(elementHandle, out processId);
196+
var process = Process.GetProcessById(processId);
197+
if (Environment.Is64BitOperatingSystem && !process.HasExited && !process.IsWow64Process())
198+
{
199+
Process.Start(new ProcessStartInfo
200+
{
201+
FileName = _64BitFilePath,
202+
Arguments = string.Format("{0} {1} {2}", Handle.ToInt32(), element.Current.NativeWindowHandle, _messageId)
203+
});
204+
}
205+
else
206+
{
207+
NativeMethods.SetHook(Handle, elementHandle, _messageId);
208+
NativeMethods.QueryPasswordEdit();
209+
NativeMethods.UnsetHook(Handle, elementHandle);
210+
}
156211
}
157212

158213
if (!element.Current.IsPassword && _isButtonTargetTextMouseDown)

WindowTextExtractor/NativeMethods.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,29 @@ static class NativeMethods
2929
[DllImport("user32.dll")]
3030
public static extern IntPtr SetCursor(IntPtr handle);
3131

32-
[DllImport("WindowTextExtractorHook.dll", SetLastError = true)]
32+
[DllImport("user32.dll")]
33+
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);
34+
35+
[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
36+
[return: MarshalAs(UnmanagedType.Bool)]
37+
internal static extern bool IsWow64Process([In] IntPtr process, [Out] out bool wow64Process);
38+
39+
[DllImport("WindowTextExtractorHook.dll")]
3340
public static extern bool SetHook(IntPtr hwndCaller, IntPtr hwndTarget, int msg);
3441

3542
[DllImport("WindowTextExtractorHook.dll")]
3643
public static extern bool UnsetHook(IntPtr hwndCaller, IntPtr hwndTarget);
3744

3845
[DllImport("WindowTextExtractorHook.dll")]
3946
public static extern bool QueryPasswordEdit();
47+
48+
[DllImport("WindowTextExtractorHook64.dll", EntryPoint = "SetHook")]
49+
public static extern bool SetHook64(IntPtr hwndCaller, IntPtr hwndTarget, int msg);
50+
51+
[DllImport("WindowTextExtractorHook64.dll", EntryPoint = "UnsetHook")]
52+
public static extern bool UnsetHook64(IntPtr hwndCaller, IntPtr hwndTarget);
53+
54+
[DllImport("WindowTextExtractorHook64.dll", EntryPoint = "QueryPasswordEdit")]
55+
public static extern bool QueryPasswordEdit64();
4056
}
4157
}

WindowTextExtractor/Program.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
42
using System.Windows.Forms;
53
using WindowTextExtractor.Forms;
64

@@ -12,11 +10,25 @@ static class Program
1210
/// The main entry point for the application.
1311
/// </summary>
1412
[STAThread]
15-
static void Main()
13+
static void Main(string[] args)
1614
{
15+
#if WIN32
1716
Application.EnableVisualStyles();
1817
Application.SetCompatibleTextRenderingDefault(false);
1918
Application.Run(new MainForm());
19+
#else
20+
var hwndCaller = 0;
21+
var hwndTarget = 0;
22+
var messageId = 0;
23+
if (args != null && args.Length > 2 && int.TryParse(args[0], out hwndCaller) && int.TryParse(args[1], out hwndTarget) && int.TryParse(args[2], out messageId))
24+
{
25+
var hwndCallerPtr = new IntPtr(hwndCaller);
26+
var hwndTargetPtr = new IntPtr(hwndTarget);
27+
NativeMethods.SetHook64(hwndCallerPtr, hwndTargetPtr, messageId);
28+
NativeMethods.QueryPasswordEdit64();
29+
NativeMethods.UnsetHook64(hwndCallerPtr, hwndTargetPtr);
30+
}
31+
#endif
2032
}
2133
}
22-
}
34+
}

WindowTextExtractor/Utils/AssemblyUtils.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,15 @@ public static string AssemblyDirectoryName
7777
return location;
7878
}
7979
}
80+
81+
public static void ExtractFileFromAssembly(string resourceName, string path)
82+
{
83+
Assembly currentAssembly = Assembly.GetExecutingAssembly();
84+
FileStream outputFileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
85+
Stream resouceStream = currentAssembly.GetManifestResourceStream(resourceName);
86+
resouceStream.CopyTo(outputFileStream);
87+
resouceStream.Close();
88+
outputFileStream.Close();
89+
}
8090
}
8191
}

WindowTextExtractor/WindowTextExtractor.csproj

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,29 @@
1111
<AssemblyName>WindowTextExtractor</AssemblyName>
1212
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14+
<PublishUrl>publish\</PublishUrl>
15+
<Install>true</Install>
16+
<InstallFrom>Disk</InstallFrom>
17+
<UpdateEnabled>false</UpdateEnabled>
18+
<UpdateMode>Foreground</UpdateMode>
19+
<UpdateInterval>7</UpdateInterval>
20+
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
21+
<UpdatePeriodically>false</UpdatePeriodically>
22+
<UpdateRequired>false</UpdateRequired>
23+
<MapFileExtensions>true</MapFileExtensions>
24+
<ApplicationRevision>0</ApplicationRevision>
25+
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
26+
<IsWebBootstrapper>false</IsWebBootstrapper>
27+
<UseApplicationTrust>false</UseApplicationTrust>
28+
<BootstrapperEnabled>true</BootstrapperEnabled>
1429
</PropertyGroup>
1530
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1631
<PlatformTarget>x86</PlatformTarget>
1732
<DebugSymbols>true</DebugSymbols>
1833
<DebugType>full</DebugType>
1934
<Optimize>false</Optimize>
2035
<OutputPath>bin\Debug\</OutputPath>
21-
<DefineConstants>DEBUG;TRACE</DefineConstants>
36+
<DefineConstants>TRACE;DEBUG;WIN32</DefineConstants>
2237
<ErrorReport>prompt</ErrorReport>
2338
<WarningLevel>4</WarningLevel>
2439
</PropertyGroup>
@@ -53,6 +68,7 @@
5368
</ItemGroup>
5469
<ItemGroup>
5570
<Compile Include="Extensions\AutomationElementExtensions.cs" />
71+
<Compile Include="Extensions\ProcessExtensions.cs" />
5672
<Compile Include="Extensions\TextBoxExtensions.cs" />
5773
<Compile Include="Forms\AboutForm.cs">
5874
<SubType>Form</SubType>
@@ -107,6 +123,14 @@
107123
<Content Include="TargetPassword_x24.png" />
108124
<Content Include="WindowTextExtractor.ico" />
109125
<Content Include="WindowTextExtractor.png" />
126+
<EmbeddedResource Include="WindowTextExtractor64.exe" />
127+
</ItemGroup>
128+
<ItemGroup>
129+
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
130+
<Visible>False</Visible>
131+
<ProductName>.NET Framework 3.5 SP1</ProductName>
132+
<Install>false</Install>
133+
</BootstrapperPackage>
110134
</ItemGroup>
111135
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
112136
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
527 KB
Binary file not shown.

0 commit comments

Comments
 (0)