Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PROFILER
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace Osu__Profiler
- {
- public partial class Profiler : Form
- {
- Form1 b;
- public Profiler(Form1 a)
- {
- b=a;
- b.Hide();
- InitializeComponent();
- }
- public static bool show = false;
- protected override void OnVisibleChanged(EventArgs e)
- {
- base.OnVisibleChanged(e);
- this.Visible = show;
- }
- private static NetworkDevice networkDevice;
- public static int hdd;
- public static string defMac, defUID, defUninstallId;
- public void reCreate()
- {
- DialogResult dialogResult = MessageBox.Show("Defaults (Mac, hwid, uninstallid) cannot be find or corrupt. Do you want to recreate the file and assign current system info?", "", MessageBoxButtons.YesNo);
- if (dialogResult == DialogResult.Yes)
- {
- if (File.Exists("default.cfg"))
- File.Delete("default.cfg");
- File.Create("default.cfg").Close();
- string[] l = new string[] { readMACSafe(networkDevice.UID), readUID(hdd), ReadUninstallId() };
- File.WriteAllLines("default.cfg", l);
- defMac = l[0];
- defUID = l[1];
- defUninstallId = l[2];
- }
- else if (dialogResult == DialogResult.No)
- {
- show = false;
- this.Hide();
- Application.Exit();
- }
- }
- public void initProfiler(NetworkDevice n, int hddNo)
- {
- networkDevice = n;
- hdd = hddNo;
- if (File.Exists("default.cfg"))
- {
- string[] l = File.ReadAllLines("default.cfg");
- if (l.Length < 3)
- {
- reCreate();
- // FILE IS WRONGLY WRITTEN
- }
- else
- {
- if (l[0] == null || l[1] == null || l[2] == null || l[0] == "" || l[1] == "" || l[2] == "") reCreate();
- else
- {
- defMac = l[0];
- defUID = l[1];
- defUninstallId = l[2];
- }
- }
- }
- else
- {
- // FILE DOESNT EXISTS
- reCreate();
- }
- textBox1.Text = defMac;
- textBox2.Text = defUID;
- textBox3.Text = defUninstallId;
- NEW_UNID.MaxLength = defUninstallId.Length;
- shouldbe_ = -defUninstallId.Replace("-", "").Length + defUninstallId.Length;
- timer1_Tick(null, null);
- timer1.Start();
- }
- public int shouldbe_ = 0;
- private string readUID(int diskId)
- {
- Process p = new Process();
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.UseShellExecute = false;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.FileName = "diskpart.exe";
- p.StartInfo.RedirectStandardInput = true;
- p.Start();
- p.StandardInput.WriteLine("select disk " + diskId);
- p.StandardInput.WriteLine("uniqueid disk");
- p.StandardInput.WriteLine("exit");
- p.WaitForExit();
- string output = p.StandardOutput.ReadToEnd();
- List<String> s = new List<String>();
- using (StringReader reader = new StringReader(output))
- {
- string line = string.Empty;
- do
- {
- line = reader.ReadLine();
- if (line != null)
- {
- s.Add(line);
- }
- } while (line != null);
- }
- return s[s.Count - 4].Split(':')[1].Replace(" ", "");
- }
- private void setUID(string uid, int diskId)
- {
- Process p = new Process();
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.UseShellExecute = false;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.FileName = "diskpart.exe";
- p.StartInfo.RedirectStandardInput = true;
- p.Start();
- p.StandardInput.WriteLine("select disk " + diskId);
- p.StandardInput.WriteLine("uniqueid disk ID=" + uid);
- p.StandardInput.WriteLine("exit");
- p.WaitForExit();
- }
- public string ReadUninstallId()
- {
- RegistryKey sk1 = Registry.CurrentUser.CreateSubKey("SOFTWARE\\" + "osu!");
- if (sk1 == null)
- {
- return null;
- }
- else
- {
- try
- {
- string s = (string)sk1.GetValue("UninstallID".ToUpper()); sk1.Close();
- return s;
- }
- catch (Exception e)
- {
- sk1.Close();
- MessageBox.Show("Reading registry " + "UninstallID".ToUpper());
- return null;
- }
- }
- }
- public bool setUninstallId(string Value)
- {
- if (Value.ToLower().Replace("a", "").Replace("b", "").Replace("c", "").Replace("d", "").Replace("e", "").Replace("f", "").Replace("-", "").Replace("1", "").Replace("2", "").Replace("0", "").Replace("3", "").Replace("4", "").Replace("5", "").Replace("6", "").Replace("7", "").Replace("8", "").Replace("9", "").Length != 0)
- {
- MessageBox.Show("You may only use A-F, 0-9. You have extra charachters.");
- return false;
- }
- try
- {
- RegistryKey sk1 = Registry.CurrentUser.CreateSubKey("SOFTWARE\\" + "osu!");
- sk1.SetValue("UninstallID".ToUpper(), Value);
- sk1.Close();
- return true;
- }
- catch (Exception e)
- {
- MessageBox.Show("Writing registry " + "UninstallID".ToUpper());
- return false;
- }
- }
- public string readMACSafe(string UID)
- {
- string MAC = readMAC(UID);
- if (MAC == null) MAC = readOriginalMAC(UID).Replace("-", "");
- return MAC;
- }
- public string readMAC(string UID)
- {
- string MAC = "";
- RegistryKey rkey;
- rkey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\" + UID, true); //--->this is the string to change
- MAC = (string)rkey.GetValue("NetworkAddress");
- rkey.Close();
- return MAC;
- }
- public string readOriginalMAC(string UID)
- {
- string MAC = "";
- RegistryKey rkey;
- rkey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\" + UID, true); //--->this is the string to change
- MAC = (string)rkey.GetValue("OriginalNetworkAddress");
- rkey.Close();
- return MAC;
- }
- public void setMAC(string UID, string val)
- {
- RegistryKey rkey;
- rkey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\" + UID, true); //--->this is the string to change
- if (readMAC(UID) == null) rkey.CreateSubKey("NetworkAddress");
- if (val == null) rkey.DeleteValue("NetworkAddress"); else
- rkey.SetValue("NetworkAddress", val);
- rkey.Close();
- }
- private void Profiler_Load(object sender, EventArgs e)
- {
- Form1.ProfilerOpened = true;
- }
- static Random random = new Random();
- public static string GetRandomHexNumber(int digits)
- {
- byte[] buffer = new byte[digits / 2];
- random.NextBytes(buffer);
- string result = String.Concat(buffer.Select(x => x.ToString("X2")).ToArray());
- if (digits % 2 == 0)
- return result;
- return result + random.Next(16).ToString("X");
- }
- bool macc = false, uidc = false, uniidc = false;
- private void NEW_MAC_TextChanged(object sender, EventArgs e)
- {
- macc = true;
- if (NEW_MAC.Text.Length != 12) macc = false;
- int wc = NEW_MAC.Text.ToLower().Replace("a", "").Replace("b", "").Replace("c", "").Replace("d", "").Replace("e", "").Replace("f", "").Replace("1", "").Replace("2", "").Replace("0", "").Replace("3", "").Replace("4", "").Replace("5", "").Replace("6", "").Replace("7", "").Replace("8", "").Replace("9", "").Length;
- if(wc!=0)macc=false;
- NEW_MAC.ForeColor = macc?Color.Green:Color.Red;
- if (macc && uidc && uniidc) button1.Enabled = button2.Enabled = true; else button1.Enabled = button2.Enabled = false;
- }
- private void NEW_UID_TextChanged(object sender, EventArgs e)
- {
- uidc = true;
- if (NEW_UID.Text.Length != 8) uidc = false;
- int wc = NEW_UID.Text.ToLower().Replace("a", "").Replace("b", "").Replace("c", "").Replace("d", "").Replace("e", "").Replace("f", "").Replace("1", "").Replace("2", "").Replace("0", "").Replace("3", "").Replace("4", "").Replace("5", "").Replace("6", "").Replace("7", "").Replace("8", "").Replace("9", "").Length;
- if (wc != 0) uidc = false;
- NEW_UID.ForeColor = uidc ? Color.Green : Color.Red;
- if (macc && uidc && uniidc) button1.Enabled = button2.Enabled = true; else button1.Enabled = button2.Enabled = false;
- }
- private void NEW_UNID_TextChanged(object sender, EventArgs e)
- {
- uniidc = true;
- if (NEW_UNID.Text.Length-NEW_UNID.Text.Replace("-", "").Length != shouldbe_) uniidc = false;
- if (NEW_UNID.Text.Length != NEW_UNID.MaxLength) uniidc = false;
- int wc = NEW_UNID.Text.ToLower().Replace("-", "").Replace("a", "").Replace("b", "").Replace("c", "").Replace("d", "").Replace("e", "").Replace("f", "").Replace("1", "").Replace("2", "").Replace("0", "").Replace("3", "").Replace("4", "").Replace("5", "").Replace("6", "").Replace("7", "").Replace("8", "").Replace("9", "").Length;
- if (wc != 0) uniidc = false;
- NEW_UNID.ForeColor = uniidc ? Color.Green : Color.Red;
- if (macc && uidc && uniidc) button1.Enabled = button2.Enabled = true; else button1.Enabled = button2.Enabled = false;
- }
- private void label1_Click(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if(saveFileDialog1.ShowDialog() == DialogResult.OK){
- File.Create(saveFileDialog1.FileName).Close();
- string[] l = new string[] { NEW_MAC.Text, NEW_UID.Text, NEW_UNID.Text };
- File.WriteAllLines(saveFileDialog1.FileName, l);
- }
- }
- private void button4_Click(object sender, EventArgs e)
- {
- if (openFileDialog1.ShowDialog() == DialogResult.OK)
- {
- string[] l = File.ReadAllLines(openFileDialog1.FileName);
- if (l.Length >= 3 && !(l[0] == null || l[1] == null || l[2] == null || l[0] == "" || l[1] == "" || l[2] == ""))
- {
- NEW_MAC.Text = l[0];
- NEW_UID.Text = l[1];
- NEW_UNID.Text = l[2];
- NEW_UNID_TextChanged(null, null);
- NEW_UID_TextChanged(null, null);
- NEW_MAC_TextChanged(null, null);
- }
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- NEW_MAC.Text = defMac;
- NEW_UID.Text = defUID;
- NEW_UNID.Text = defUninstallId;
- }
- private void button2_Click(object sender, EventArgs e)
- {
- MessageBox.Show("Please remember to set back to original profile before shutting your computer down. Also this operation will restart your network connection so pause any active downloads.");
- setMAC(networkDevice.UID, NEW_MAC.Text);
- setUID(NEW_UID.Text, hdd);
- setUninstallId(NEW_UNID.Text);
- networkDevice.restart();
- timer1_Tick(null, null);
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- timer1.Enabled = Profiler.show;
- textBox6.Text = readMACSafe(networkDevice.UID);
- textBox5.Text = readUID(hdd);
- textBox4.Text = ReadUninstallId();
- }
- private void button5_Click(object sender, EventArgs e)
- {
- NEW_MAC.Text = "02" + GetRandomHexNumber(NEW_MAC.MaxLength - 2);
- NEW_UID.Text = GetRandomHexNumber(NEW_UID.MaxLength);
- NEW_UNID.Text = System.Guid.NewGuid().ToString();
- }
- }
- }
- // NetworkDevice
- using Microsoft.Win32;
- using ROOT.CIMV2.Win32;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Management;
- using System.Text;
- namespace Osu__Profiler
- {
- public class NetworkDevice
- {
- public string UID = "";
- public NetworkAdapter realAdapter;
- public string DESC = "";
- public NetworkDevice(NetworkAdapter adapter)
- {
- int idx = Int32.Parse(adapter.DeviceID);
- string id = "";
- if (idx < 10) id = "000" + idx;
- else if (idx < 100) id = "00" + idx;
- else if (idx < 1000) id = "0" + idx;
- else id = "" + idx;
- UID = id;
- DESC = adapter.Description;
- realAdapter = adapter;
- }
- public override string ToString() { return DESC; }
- public static NetworkDevice[] returnArray()
- {
- List<NetworkDevice> l = new List<NetworkDevice>();
- SelectQuery query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus=2");
- ManagementObjectSearcher search = new ManagementObjectSearcher(query);
- foreach (ManagementObject result in search.Get())
- {
- NetworkAdapter adapter = new NetworkAdapter(result);
- l.Add(new NetworkDevice(adapter));
- }
- return l.ToArray();
- }
- public NetworkDevice(int i)
- {
- NetworkAdapter adapter = null;
- SelectQuery query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus=2");
- ManagementObjectSearcher search = new ManagementObjectSearcher(query);
- foreach (ManagementObject result in search.Get())
- {
- NetworkAdapter adaptery = new NetworkAdapter(result);
- if (Int32.Parse(adaptery.DeviceID) == i)
- adapter = adaptery;
- }
- int idx = Int32.Parse(adapter.DeviceID);
- string id = "";
- if (idx < 10) id = "000" + idx;
- else if (idx < 100) id = "00" + idx;
- else if (idx < 1000) id = "0" + idx;
- else id = "" + idx;
- UID = id;
- DESC = adapter.Description;
- realAdapter = adapter;
- }
- public static NetworkDevice[] returnConnectedArray()
- {
- List<NetworkDevice> l = new List<NetworkDevice>();
- SelectQuery query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus=2");
- ManagementObjectSearcher search = new ManagementObjectSearcher(query);
- foreach (ManagementObject result in search.Get())
- {
- NetworkAdapter adapter = new NetworkAdapter(result);
- if (adapter.NetEnabled)
- {
- l.Add(new NetworkDevice(adapter));
- }
- }
- return l.ToArray();
- }
- public void restart()
- {
- realAdapter.Disable();
- realAdapter.Enable();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement