EagleEye/Program.cs
2024-03-08 16:17:09 -07:00

156 lines
No EOL
5 KiB
C#
Executable file

using BitCoinSharp;
using NBitcoin;
using System.Numerics;
using System.Xml.Linq;
namespace EagleEye
{
internal class Program
{
public static string search;
public static BigInteger point = BigInteger.Zero;
public static Wallet wallet = null;
static void Main(string[] args)
{
//args = new string[] { "1HLoD9E4SDFFPDiYfNYnkBLQ85Y51J3Zb1" };
Console.WriteLine("\n \n* WELCOME TO EAGLE EYE *\n \n[ Checking for required parameters ]");
if(args.Length >= 1)
{
Console.WriteLine($"[ Scanning for {args[0]} ]");
search = args[0];
wallet = new Wallet(NetworkParameters.ProdNet());
}else
{
if (!File.Exists("resume.bin"))
{
Console.WriteLine($"[ Please provide the address to search for ]");
return;
}
else Load();
}
Key privkey = new();
//byte[] bits = new byte[32];
bool bSearch = true;
BigInteger big = point;
if(search != "")
{
args = new string[] { search };
}
Console.WriteLine();
Console.WriteLine();
Console.CancelKeyPress += Console_CancelKeyPress;
int lastSave = 0;
while (bSearch)
{
byte[] bits = big.ToByteArray();
Array.Resize<byte>(ref bits, 32);
Array.Reverse(bits);
big++;
point = big;
//big.ToByteArray().CopyTo(bits, 0);
try
{
privkey = new Key(bits);
}
catch
{
continue;
}
string hex = string.Join("", bits.Select(b => string.Format("{0:X2}", b)));
//privkey = Key.Parse(hex, Network.Main);
BitcoinSecret btcpriv = privkey.GetWif(Network.Main);
BitcoinAddress legacy = btcpriv.PubKey.GetAddress(ScriptPubKeyType.Legacy, Network.Main);
BitcoinAddress segwit = btcpriv.PubKey.GetAddress(ScriptPubKeyType.Segwit, Network.Main);
BitcoinAddress segwit2 = btcpriv.PubKey.GetAddress(ScriptPubKeyType.SegwitP2SH, Network.Main);
BitcoinAddress taproot = btcpriv.PubKey.GetAddress(ScriptPubKeyType.TaprootBIP86, Network.Main);
if (args[0] == legacy.ToString() || args[0] == segwit.ToString() || args[0] == segwit2.ToString() || args[0] == taproot.ToString())
{
Console.WriteLine($"\n\nPRIVATE KEY FOUND : {btcpriv}\n\n");
//bSearch = false;
Save();
}
else Console.Write($"\rSearching for private key [{btcpriv}] [{lastSave}] [{wallet.Keychain.Count}] \r");
if (lastSave >= 2000)
{
Save();
lastSave = 0;
}
else lastSave++;
try
{
Org.BouncyCastle.Math.BigInteger pk = new Org.BouncyCastle.Math.BigInteger(hex, 16);
wallet.AddKey(new EcKey(pk));
}
catch { }
}
}
private static void Console_CancelKeyPress(object? sender, ConsoleCancelEventArgs e)
{
Console.WriteLine("Saving state...");
Save();
Environment.Exit(0);
}
private static void Save()
{
try
{
Thread tx = new Thread(() =>
{
BinaryWriter bw = new BinaryWriter(new FileStream("resume.bin", FileMode.OpenOrCreate, FileAccess.ReadWrite));
bw.Write(search);
byte[] arr = point.ToByteArray();
bw.Write(arr.Length);
bw.Write(arr);
try
{
FileInfo fi = new FileInfo("wallet.dat");
wallet.SaveToFile(fi);
}
catch { }
bw.Close();
});
tx.Start();
}
catch { }
}
private static void Load()
{
BinaryReader br = new BinaryReader(new FileStream("resume.bin", FileMode.Open, FileAccess.Read));
search = br.ReadString();
point = new BigInteger(br.ReadBytes(br.ReadInt32()));
br.Close();
Console.WriteLine("[ Loaded saved state ]");
wallet = Wallet.LoadFromFile(new FileInfo("wallet.dat"));
}
}
}