Advertisement
can1456

Untitled

Nov 4th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 16.55 KB | None | 0 0
  1. // PROFILER
  2.  
  3. using Microsoft.Win32;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Diagnostics;
  9. using System.Drawing;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Windows.Forms;
  14.  
  15. namespace Osu__Profiler
  16. {
  17.     public partial class Profiler : Form
  18.     {
  19.        
  20.         Form1 b;
  21.         public Profiler(Form1 a)
  22.         {
  23.             b=a;
  24.             b.Hide();
  25.             InitializeComponent();
  26.         }
  27.         public static bool show = false;
  28.         protected override void OnVisibleChanged(EventArgs e)
  29.         {
  30.             base.OnVisibleChanged(e);
  31.             this.Visible = show;
  32.         }
  33.         private static NetworkDevice networkDevice;
  34.         public static int hdd;
  35.         public static string defMac, defUID, defUninstallId;
  36.         public void reCreate()
  37.         {
  38.             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);
  39.             if (dialogResult == DialogResult.Yes)
  40.             {
  41.                 if (File.Exists("default.cfg"))
  42.                     File.Delete("default.cfg");
  43.                 File.Create("default.cfg").Close();
  44.                 string[] l = new string[] { readMACSafe(networkDevice.UID), readUID(hdd), ReadUninstallId() };
  45.                 File.WriteAllLines("default.cfg", l);
  46.                 defMac = l[0];
  47.                 defUID = l[1];
  48.                 defUninstallId = l[2];
  49.                    
  50.             }
  51.             else if (dialogResult == DialogResult.No)
  52.             {
  53.                 show = false;
  54.                 this.Hide();
  55.                 Application.Exit();
  56.             }
  57.         }
  58.         public void initProfiler(NetworkDevice n, int hddNo)
  59.         {
  60.            
  61.             networkDevice = n;
  62.             hdd = hddNo;
  63.             if (File.Exists("default.cfg"))
  64.             {
  65.                 string[] l = File.ReadAllLines("default.cfg");
  66.                 if (l.Length < 3)
  67.                 {
  68.                     reCreate();
  69.                     // FILE IS WRONGLY WRITTEN
  70.                 }
  71.                 else
  72.                 {
  73.                     if (l[0] == null || l[1] == null || l[2] == null || l[0] == "" || l[1] == "" || l[2] == "") reCreate();
  74.                     else
  75.                     {
  76.                         defMac = l[0];
  77.                         defUID = l[1];
  78.                         defUninstallId = l[2];
  79.                     }
  80.                 }
  81.             }
  82.             else
  83.             {
  84.                 // FILE DOESNT EXISTS
  85.                 reCreate();
  86.             }
  87.             textBox1.Text = defMac;
  88.             textBox2.Text = defUID;
  89.             textBox3.Text = defUninstallId;
  90.             NEW_UNID.MaxLength = defUninstallId.Length;
  91.             shouldbe_ = -defUninstallId.Replace("-", "").Length + defUninstallId.Length;
  92.             timer1_Tick(null, null);
  93.             timer1.Start();
  94.         }
  95.         public int shouldbe_ = 0;
  96.         private string readUID(int diskId)
  97.         {
  98.             Process p = new Process();
  99.             p.StartInfo.CreateNoWindow = true;
  100.             p.StartInfo.UseShellExecute = false;
  101.             p.StartInfo.RedirectStandardOutput = true;
  102.             p.StartInfo.FileName = "diskpart.exe";
  103.             p.StartInfo.RedirectStandardInput = true;
  104.             p.Start();
  105.             p.StandardInput.WriteLine("select disk " + diskId);
  106.             p.StandardInput.WriteLine("uniqueid disk");
  107.             p.StandardInput.WriteLine("exit");
  108.             p.WaitForExit();
  109.             string output = p.StandardOutput.ReadToEnd();
  110.             List<String> s = new List<String>();
  111.             using (StringReader reader = new StringReader(output))
  112.             {
  113.  
  114.                 string line = string.Empty;
  115.                 do
  116.                 {
  117.                     line = reader.ReadLine();
  118.                     if (line != null)
  119.                     {
  120.                         s.Add(line);
  121.                     }
  122.  
  123.  
  124.                 } while (line != null);
  125.             }
  126.             return s[s.Count - 4].Split(':')[1].Replace(" ", "");
  127.         }
  128.         private void setUID(string uid, int diskId)
  129.         {
  130.             Process p = new Process();
  131.             p.StartInfo.CreateNoWindow = true;
  132.             p.StartInfo.UseShellExecute = false;
  133.             p.StartInfo.RedirectStandardOutput = true;
  134.             p.StartInfo.FileName = "diskpart.exe";
  135.             p.StartInfo.RedirectStandardInput = true;
  136.             p.Start();
  137.             p.StandardInput.WriteLine("select disk " + diskId);
  138.             p.StandardInput.WriteLine("uniqueid disk ID=" + uid);
  139.             p.StandardInput.WriteLine("exit");
  140.             p.WaitForExit();
  141.         }
  142.         public string ReadUninstallId()
  143.         {
  144.             RegistryKey sk1 = Registry.CurrentUser.CreateSubKey("SOFTWARE\\" + "osu!");
  145.             if (sk1 == null)
  146.             {
  147.                 return null;
  148.             }
  149.             else
  150.             {
  151.                 try
  152.                 {
  153.  
  154.                     string s = (string)sk1.GetValue("UninstallID".ToUpper()); sk1.Close();
  155.                     return s;
  156.                 }
  157.                 catch (Exception e)
  158.                 {
  159.                     sk1.Close();
  160.                     MessageBox.Show("Reading registry " + "UninstallID".ToUpper());
  161.                     return null;
  162.                 }
  163.             }
  164.         }
  165.         public bool setUninstallId(string Value)
  166.         {
  167.             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)
  168.             {
  169.                 MessageBox.Show("You may only use A-F, 0-9. You have extra charachters.");
  170.                 return false;
  171.             }
  172.             try
  173.             {
  174.                 RegistryKey sk1 = Registry.CurrentUser.CreateSubKey("SOFTWARE\\" + "osu!");
  175.                 sk1.SetValue("UninstallID".ToUpper(), Value);
  176.                 sk1.Close();
  177.                 return true;
  178.             }
  179.             catch (Exception e)
  180.             {
  181.                 MessageBox.Show("Writing registry " + "UninstallID".ToUpper());
  182.                 return false;
  183.             }
  184.         }
  185.         public string readMACSafe(string UID)
  186.         {
  187.             string MAC = readMAC(UID);
  188.             if (MAC == null) MAC = readOriginalMAC(UID).Replace("-", "");
  189.             return MAC;
  190.         }
  191.         public string readMAC(string UID)
  192.         {
  193.             string MAC = "";
  194.             RegistryKey rkey;
  195.             rkey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\" + UID, true); //--->this is the string to change
  196.             MAC = (string)rkey.GetValue("NetworkAddress");
  197.             rkey.Close();
  198.            
  199.             return MAC;
  200.         }
  201.         public string readOriginalMAC(string UID)
  202.         {
  203.             string MAC = "";
  204.             RegistryKey rkey;
  205.             rkey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\" + UID, true); //--->this is the string to change
  206.             MAC = (string)rkey.GetValue("OriginalNetworkAddress");
  207.             rkey.Close();
  208.             return MAC;
  209.         }
  210.         public void setMAC(string UID, string val)
  211.         {
  212.             RegistryKey rkey;
  213.             rkey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\" + UID, true); //--->this is the string to change
  214.             if (readMAC(UID) == null) rkey.CreateSubKey("NetworkAddress");
  215.             if (val == null) rkey.DeleteValue("NetworkAddress"); else
  216.             rkey.SetValue("NetworkAddress", val);
  217.             rkey.Close();
  218.         }
  219.         private void Profiler_Load(object sender, EventArgs e)
  220.         {
  221.             Form1.ProfilerOpened = true;
  222.         }
  223.  
  224.  
  225.         static Random random = new Random();
  226.         public static string GetRandomHexNumber(int digits)
  227.         {
  228.             byte[] buffer = new byte[digits / 2];
  229.             random.NextBytes(buffer);
  230.             string result = String.Concat(buffer.Select(x => x.ToString("X2")).ToArray());
  231.             if (digits % 2 == 0)
  232.                 return result;
  233.             return result + random.Next(16).ToString("X");
  234.         }
  235.  
  236.  
  237.         bool macc = false, uidc = false, uniidc = false;
  238.         private void NEW_MAC_TextChanged(object sender, EventArgs e)
  239.         {
  240.             macc = true;
  241.             if (NEW_MAC.Text.Length != 12) macc = false;
  242.             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;
  243.             if(wc!=0)macc=false;
  244.             NEW_MAC.ForeColor = macc?Color.Green:Color.Red;
  245.             if (macc && uidc && uniidc) button1.Enabled = button2.Enabled = true; else button1.Enabled = button2.Enabled = false;
  246.         }
  247.  
  248.         private void NEW_UID_TextChanged(object sender, EventArgs e)
  249.         {
  250.             uidc = true;
  251.             if (NEW_UID.Text.Length != 8) uidc = false;
  252.             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;
  253.             if (wc != 0) uidc = false;
  254.             NEW_UID.ForeColor = uidc ? Color.Green : Color.Red;
  255.             if (macc && uidc && uniidc) button1.Enabled = button2.Enabled = true; else button1.Enabled = button2.Enabled = false;
  256.         }
  257.  
  258.         private void NEW_UNID_TextChanged(object sender, EventArgs e)
  259.         {
  260.            
  261.             uniidc = true;
  262.             if (NEW_UNID.Text.Length-NEW_UNID.Text.Replace("-", "").Length != shouldbe_) uniidc = false;
  263.             if (NEW_UNID.Text.Length != NEW_UNID.MaxLength) uniidc = false;
  264.             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;
  265.             if (wc != 0) uniidc = false;
  266.             NEW_UNID.ForeColor = uniidc ? Color.Green : Color.Red;
  267.             if (macc && uidc && uniidc) button1.Enabled = button2.Enabled = true; else button1.Enabled = button2.Enabled = false;
  268.         }
  269.  
  270.         private void label1_Click(object sender, EventArgs e)
  271.         {
  272.  
  273.         }
  274.  
  275.         private void button1_Click(object sender, EventArgs e)
  276.         {
  277.             if(saveFileDialog1.ShowDialog() == DialogResult.OK){
  278.                 File.Create(saveFileDialog1.FileName).Close();
  279.                 string[] l = new string[] { NEW_MAC.Text, NEW_UID.Text, NEW_UNID.Text };
  280.                 File.WriteAllLines(saveFileDialog1.FileName, l);
  281.             }
  282.            
  283.         }
  284.  
  285.         private void button4_Click(object sender, EventArgs e)
  286.         {
  287.            
  288.             if (openFileDialog1.ShowDialog() == DialogResult.OK)
  289.             {
  290.                 string[] l = File.ReadAllLines(openFileDialog1.FileName);
  291.                 if (l.Length >= 3 && !(l[0] == null || l[1] == null || l[2] == null || l[0] == "" || l[1] == "" || l[2] == ""))
  292.                 {
  293.                     NEW_MAC.Text = l[0];
  294.                     NEW_UID.Text = l[1];
  295.                     NEW_UNID.Text = l[2];
  296.                     NEW_UNID_TextChanged(null, null);
  297.                     NEW_UID_TextChanged(null, null);
  298.                     NEW_MAC_TextChanged(null, null);
  299.                 }
  300.             }
  301.         }
  302.  
  303.         private void button3_Click(object sender, EventArgs e)
  304.         {
  305.             NEW_MAC.Text = defMac;
  306.             NEW_UID.Text = defUID;
  307.             NEW_UNID.Text = defUninstallId;
  308.         }
  309.  
  310.         private void button2_Click(object sender, EventArgs e)
  311.         {
  312.             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.");
  313.             setMAC(networkDevice.UID, NEW_MAC.Text);
  314.             setUID(NEW_UID.Text, hdd);
  315.             setUninstallId(NEW_UNID.Text);
  316.             networkDevice.restart();
  317.             timer1_Tick(null, null);
  318.         }
  319.  
  320.         private void timer1_Tick(object sender, EventArgs e)
  321.         {
  322.             timer1.Enabled = Profiler.show;
  323.             textBox6.Text = readMACSafe(networkDevice.UID);
  324.             textBox5.Text = readUID(hdd);
  325.             textBox4.Text = ReadUninstallId();
  326.         }
  327.  
  328.         private void button5_Click(object sender, EventArgs e)
  329.         {
  330.             NEW_MAC.Text = "02" + GetRandomHexNumber(NEW_MAC.MaxLength - 2);
  331.             NEW_UID.Text = GetRandomHexNumber(NEW_UID.MaxLength);
  332.             NEW_UNID.Text = System.Guid.NewGuid().ToString();
  333.         }
  334.     }
  335. }
  336.  
  337.  
  338.  
  339.  
  340.  
  341. // NetworkDevice
  342. using Microsoft.Win32;
  343. using ROOT.CIMV2.Win32;
  344. using System;
  345. using System.Collections.Generic;
  346. using System.Linq;
  347. using System.Management;
  348. using System.Text;
  349.  
  350. namespace Osu__Profiler
  351. {
  352.     public class NetworkDevice
  353.     {
  354.         public string UID = "";
  355.         public NetworkAdapter realAdapter;
  356.         public string DESC = "";
  357.         public NetworkDevice(NetworkAdapter adapter)
  358.         {
  359.  
  360.             int idx = Int32.Parse(adapter.DeviceID);
  361.             string id = "";
  362.             if (idx < 10) id = "000" + idx;
  363.             else if (idx < 100) id = "00" + idx;
  364.             else if (idx < 1000) id = "0" + idx;
  365.             else id = "" + idx;
  366.             UID = id;
  367.             DESC = adapter.Description;
  368.             realAdapter = adapter;
  369.         }
  370.         public override string ToString() { return DESC; }
  371.         public static NetworkDevice[] returnArray()
  372.         {
  373.             List<NetworkDevice> l = new List<NetworkDevice>();
  374.             SelectQuery query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus=2");
  375.             ManagementObjectSearcher search = new ManagementObjectSearcher(query);
  376.             foreach (ManagementObject result in search.Get())
  377.             {
  378.                 NetworkAdapter adapter = new NetworkAdapter(result);
  379.                 l.Add(new NetworkDevice(adapter));
  380.             }
  381.             return l.ToArray();
  382.         }
  383.         public NetworkDevice(int i)
  384.         {
  385.             NetworkAdapter adapter = null;
  386.             SelectQuery query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus=2");
  387.             ManagementObjectSearcher search = new ManagementObjectSearcher(query);
  388.             foreach (ManagementObject result in search.Get())
  389.             {
  390.                 NetworkAdapter adaptery = new NetworkAdapter(result);
  391.                 if (Int32.Parse(adaptery.DeviceID) == i)
  392.                     adapter = adaptery;
  393.             }
  394.            
  395.             int idx = Int32.Parse(adapter.DeviceID);
  396.             string id = "";
  397.             if (idx < 10) id = "000" + idx;
  398.             else if (idx < 100) id = "00" + idx;
  399.             else if (idx < 1000) id = "0" + idx;
  400.             else id = "" + idx;
  401.             UID = id;
  402.             DESC = adapter.Description;
  403.             realAdapter = adapter;
  404.         }
  405.         public static NetworkDevice[] returnConnectedArray()
  406.         {
  407.             List<NetworkDevice> l = new List<NetworkDevice>();
  408.             SelectQuery query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus=2");
  409.             ManagementObjectSearcher search = new ManagementObjectSearcher(query);
  410.             foreach (ManagementObject result in search.Get())
  411.             {
  412.                 NetworkAdapter adapter = new NetworkAdapter(result);
  413.                 if (adapter.NetEnabled)
  414.                 {
  415.                     l.Add(new NetworkDevice(adapter));
  416.                 }
  417.             }
  418.             return l.ToArray();
  419.         }
  420.         public void restart()
  421.         {
  422.             realAdapter.Disable();
  423.             realAdapter.Enable();
  424.         }
  425.        
  426.     }
  427. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement