-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cs
executable file
·227 lines (187 loc) · 7.29 KB
/
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
using System.Text;
using System.Diagnostics;
using System.Windows.Automation;
using System.Reflection;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
/*Future tasks:
-connect error labeling json for specific error codes + messages on try/catch
-Fix label boxes to accomodate long item names
-finish the hotkey logic to save itemdetail page to database.
-Add tooltips to confusing controls
-VERYVERYVERYEND: keygen/obfuscator
*
*
*
Glitches/ errors to catch:
* mousebox should always be on top, and not minimize with main form
* try/catch the initial webresponse for the just added page
* try/catch the label updating code
* try/catch the tektek data generator in case link changes or user has no internet
*/
namespace windowHandler
{
public class Singleton
{
private Singleton() { }
public static init Instance{get;set;}
}
public class init
{
public IntPtr handle { get; set; }
public string handlePlatform { get; set; }
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", SetLastError = true)]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
//
public init()
{
uint temp;
handle = GetForegroundWindow();
uint temp2 = GetWindowThreadProcessId(handle,out temp);
handlePlatform = Process.GetProcessById(Convert.ToInt32(temp)).ProcessName;
Program.GUIref.Invoke((MethodInvoker)delegate
{
Program.GUIref.textBox1.Text = handlePlatform;
});
}
}
public class urlHandler
{
public static ManualResetEvent MRE {get; set;}
public static bool handleChange = false;
string urlGen;
MethodInfo mi;
public void platformSorter()
{
MRE = new ManualResetEvent(false);
MRE.WaitOne();
try
{
string method = "Get" + Singleton.Instance.handlePlatform + "Url";
mi = this.GetType().GetMethod(method);
}
catch
{
}
this.parseLoop();
}
public void parseLoop()
{
// string urlParse;
string compareUrl = "";
while (true)
{
if (handleChange)
{
Singleton.Instance.handle = init.GetForegroundWindow();
uint temp;
uint temp2 = init.GetWindowThreadProcessId(Singleton.Instance.handle, out temp);
Singleton.Instance.handlePlatform = Process.GetProcessById(Convert.ToInt32(temp)).ProcessName;
try
{
Program.GUIref.Invoke((MethodInvoker)delegate
{
Program.GUIref.textBox1.Text = Singleton.Instance.handlePlatform;
});
}
catch { }
}
string method = "Get" + Singleton.Instance.handlePlatform + "Url";
mi = this.GetType().GetMethod(method);
try { urlGen = (string)mi.Invoke(this, null); }
catch
{
try
{
Program.GUIref.Invoke((MethodInvoker)delegate
{
Program.GUIref.textBox2.Text = "";
});
}
catch { }
}
// urlParse = urlGen.Substring(urlGen.IndexOf("?id=") + 4);
if (compareUrl != urlGen)
{
Program.GUIref.Invoke((MethodInvoker)delegate
{
Program.GUIref.textBox2.Text = urlGen;
});
}
compareUrl = urlGen;
Thread.Sleep(200);
}
}
public string GetoperaUrl()
{
AutomationElement element;
try
{
element = AutomationElement.FromHandle(Singleton.Instance.handle);
}
catch { return " "; }
if (element == null)
return " ";
AutomationElement edit = element.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
try { return ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string; }
catch { return ""; }
}
public string GetchromeUrl()
{
AutomationElement element = null;
try { element = AutomationElement.FromHandle(Singleton.Instance.handle); }
catch { }
if (element == null)
return " ";
AutomationElement edit = element.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
try { return ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string; }
catch { return ""; }
}
public string GetiexploreUrl()
{
AutomationElement element = AutomationElement.FromHandle(Singleton.Instance.handle);
if (element == null)
return " ";
AutomationElement rebar = element.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "ReBarWindow32"));
if (rebar == null)
return " ";
AutomationElement edit = rebar.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
return ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;
}
public string GetfirefoxUrl()
{
AutomationElement element = AutomationElement.FromHandle(Singleton.Instance.handle);
if (element == null)
return " ";
AutomationElement doc = element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document));
if (doc == null)
return " ";
return ((ValuePattern)doc.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;
}
}
public static class Program
{
public static GUI GUIref;
public static Form4 GUIref4;
public static Form2 Formref;
public static Form3 Formrefer;
[STAThread]
static void Main()
{
urlHandler urlh = new urlHandler();
Thread url = new Thread(urlh.platformSorter);
url.IsBackground = true;
url.Start();
InterceptMouse.entry();
}
}
}