public Main() { InitializeComponent(); checkBox1.CheckedChanged += (s, e) => { comboBox1.Enabled = checkBox1.Checked; comboBox2.Enabled = checkBox1.Checked; comboBox3.Enabled = checkBox1.Checked; comboBox4.Enabled = checkBox1.Checked; comboBox1.Update(); comboBox2.Update(); comboBox3.Update(); comboBox4.Update(); }; blankMenuItem.Click += (s, e) => { Blank(); }; generateMenuItem.Click += (s, e) => { Generate(); }; openFileMenuItem.Click += (s, e) => { using (var dialog = new OpenFileDialog()) { dialog.Title = "Open XBL Account File"; dialog.Filter = "All Files (*.*)|*.*"; dialog.Multiselect = false; dialog.CheckFileExists = true; dialog.CheckPathExists = true; dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); dialog.RestoreDirectory = true; if (dialog.ShowDialog(this) == DialogResult.OK) { var file = new FileInfo(dialog.FileName); if (file.Length != 0x6C) { MessageBox.Show(this, "Selected file is not a valid Xbox LIVE account file", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var buffer = new byte[0x6C]; using (var stream = file.OpenRead()) { stream.Read(buffer, 0, 0x6C); } var account = buffer.Deserialize <API.XOnline.ONLINE_USER_ACCOUNT_STRUCT>(); if (!API.XOnline.VerifyOnlineUserSignature(account)) { MessageBox.Show(this, "Selected file is not a valid Xbox LIVE account file", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } LoadAccountToUI(account); } } }; saveFileMenuItem.Click += (s, e) => { //check xuid if (string.IsNullOrEmpty(textBox1.Text) || textBox1.Text.Length != 16 || !textBox1.Text.IsHex()) { MessageBox.Show(this, "XUID must be 8 bytes in length (16 hexadecimal characters)\n\nIt's safe to set the XUID to all zeroes", "Invalid XUID", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //check gamertag if (string.IsNullOrEmpty(textBox2.Text) || !textBox2.Text.IsASCII()) { MessageBox.Show(this, "Gamertag must be at least 1 character in length. Only ASCII characters are valid", "Invalid Gamertag", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } using (var dialog = new SaveFileDialog()) { dialog.Title = "Save XBL Account File"; dialog.Filter = "All Files (*.*)|*.*"; dialog.CheckPathExists = true; dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); dialog.RestoreDirectory = true; dialog.OverwritePrompt = true; if (dialog.ShowDialog(this) == DialogResult.OK) { var account = UnloadAccountFromUI(); if (!API.XOnline.SignOnlineUserSignature(ref account)) { //this shouldnt fail but we'll handle it anyway MessageBox.Show(this, "Failed to encrypt and sign account data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var buffer = account.Serialize(); using (var stream = File.Open(dialog.FileName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) { stream.Write(buffer, 0, 0x6C); stream.Flush(); } MessageBox.Show(this, "Account data was written successfully", "Account saved", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }; openDeviceMenuItem.Click += (s, e) => { using (var deviceDialog = new DeviceDialog(false)) { if (deviceDialog.ShowDialog(this) == DialogResult.OK) { LoadAccountToUI(deviceDialog.Account); } } }; saveDeviceMenuItem.Click += (s, e) => { //check xuid if (string.IsNullOrEmpty(textBox1.Text) || textBox1.Text.Length != 16 || !textBox1.Text.IsHex()) { MessageBox.Show(this, "XUID must be 8 bytes in length (16 hexadecimal characters)\n\nIt's safe to set the XUID to all zeroes", "Invalid XUID", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //check gamertag if (string.IsNullOrEmpty(textBox2.Text) || !textBox2.Text.IsASCII()) { MessageBox.Show(this, "Gamertag must be at least 1 character in length. Only ASCII characters are valid", "Invalid Gamertag", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } using (var deviceDialog = new DeviceDialog(true)) { deviceDialog.Account = UnloadAccountFromUI(); deviceDialog.ShowDialog(this); } }; openDeviceImageMenuItem.Click += (s, e) => { using (var dialog = new OpenFileDialog()) { dialog.Title = "Open Device Image Backup"; dialog.Filter = "All Files (*.*)|*.*"; dialog.Multiselect = false; dialog.CheckFileExists = true; dialog.CheckPathExists = true; dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); dialog.RestoreDirectory = true; if (dialog.ShowDialog(this) == DialogResult.OK) { var file = dialog.FileName; if (!CheckDeviceImageFile(file)) { MessageBox.Show(this, "Selected file is not a valid Xbox memory card or harddrive image", "Invalid FATX Image", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } API.XOnline.ONLINE_USER_ACCOUNT_STRUCT account; IDrive image = new DriveImage(file); using (var accountDialog = new AccountDialog(ref image, false)) { if (accountDialog.ShowDialog(this) == DialogResult.OK) { account = accountDialog.Account; LoadAccountToUI(account); } } image.Dispose(); } } }; saveDeviceImageMenuItem.Click += (s, e) => { //check xuid if (string.IsNullOrEmpty(textBox1.Text) || textBox1.Text.Length != 16 || !textBox1.Text.IsHex()) { MessageBox.Show(this, "XUID must be 8 bytes in length (16 hexadecimal characters)\n\nIt's safe to set the XUID to all zeroes", "Invalid XUID", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //check gamertag if (string.IsNullOrEmpty(textBox2.Text) || !textBox2.Text.IsASCII()) { MessageBox.Show(this, "Gamertag must be at least 1 character in length. Only ASCII characters are valid", "Invalid Gamertag", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } using (var dialog = new OpenFileDialog()) { dialog.Title = "Open Device Image Backup"; dialog.Filter = "All Files (*.*)|*.*"; dialog.Multiselect = false; dialog.CheckFileExists = true; dialog.CheckPathExists = true; dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); dialog.RestoreDirectory = true; if (dialog.ShowDialog(this) == DialogResult.OK) { var file = dialog.FileName; if (!CheckDeviceImageFile(file)) { MessageBox.Show(this, "Selected file is not a valid Xbox memory card or harddrive image", "Invalid FATX Image", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } API.XOnline.ONLINE_USER_ACCOUNT_STRUCT account = UnloadAccountFromUI(); IDrive image = new DriveImage(file); using (var accountDialog = new AccountDialog(ref image, true)) { accountDialog.Account = account; accountDialog.ShowDialog(this); } image.Dispose(); } } }; Generate(); }
public DeviceDialog(bool saving) { InitializeComponent(); DialogResult = DialogResult.Cancel; Shown += (s, e) => { ListDrives(); }; deviceList.SelectedIndexChanged += (s, e) => { if (deviceList.SelectedIndices == null || deviceList.SelectedIndices.Count == 0) { openButton.Enabled = false; openButton.Update(); } else { openButton.Enabled = true; openButton.Update(); } }; deviceList.DoubleClick += (s, e) => { openButton.PerformClick(); }; FormClosing += (s, e) => { ClearDrives(); }; refreshButton.Click += (s, e) => { ListDrives(); }; openButton.Click += (s, e) => { if (deviceList.SelectedIndices == null || deviceList.SelectedIndices.Count != 1) { return; } var drive = loadedDrives[deviceList.SelectedIndices[0]]; using (var accountDialog = new AccountDialog(ref drive, saving)) { if (saving) { accountDialog.Account = Account; if (accountDialog.ShowDialog(this) == DialogResult.OK) { Close(); } else { ListDrives(); //refresh } } else { if (accountDialog.ShowDialog(this) == DialogResult.OK) { Account = accountDialog.Account; DialogResult = DialogResult.OK; Close(); } else { ListDrives(); //refresh } } } }; cancelButton.Click += (s, e) => { Close(); }; }