Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace Radeon_HD_7000_BIOS_Editor
- {
- public partial class MainForm : Form
- {
- public MainForm()
- {
- InitializeComponent();
- }
- #region Variables Initialization
- public static string filePath;
- public static byte[] searchStringPL;
- public static int position;
- public static string selectedLimit;
- #endregion
- #region Open File Dialog
- private void openBiosItem_Click(object sender, EventArgs e)
- {
- if (openFileDialog1.ShowDialog() == DialogResult.OK)
- {
- filePath = openFileDialog1.FileName;
- BiosRW.readToString(filePath);
- if (comboBoxVga.Text != null)
- {
- IndexOf(BiosRW.bios, searchStringPL);
- }
- }
- }
- #endregion
- #region Exit
- private void exitItem_Click(object sender, EventArgs e)
- {
- Close();
- }
- #endregion
- #region Search strings for Power Limit
- private void comboBoxVga_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (comboBoxVga.Text == "Radeon HD 7700")
- {
- searchStringPL = new byte[] { 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04 };
- }
- if (comboBoxVga.Text == "Radeon HD 7800")
- {
- searchStringPL = new byte[] { 0x00, 0x00, 0x14, 0x00, 0x4B, 0x00, 0x04 };
- }
- if (comboBoxVga.Text == "Radeon HD 7900")
- {
- searchStringPL = new byte[] { 0x00, 0x00, 0x14, 0x00, 0x40, 0x00, 0x04 };
- }
- if (filePath != null) IndexOf(BiosRW.bios, searchStringPL);
- }
- #endregion
- #region Searching Position in File
- public void IndexOf(byte[] ByteArrayToSearch, byte[] ByteArrayToFind)
- {
- if (BiosRW.bios != null && searchStringPL != null)
- {
- ByteArrayToFind[2] = 0x14;
- for (int i = 0; i < 2; i++)
- {
- Encoding encoding = Encoding.GetEncoding(1252);
- string toSearch = encoding.GetString(ByteArrayToSearch, 0, ByteArrayToSearch.Length);
- string toFind = encoding.GetString(ByteArrayToFind, 0, ByteArrayToFind.Length);
- position = toSearch.IndexOf(toFind, StringComparison.Ordinal);
- if (position != -1) break;
- if (ByteArrayToFind[2] == 0x14) ByteArrayToFind[2] = 0x32;
- }
- if (position == -1)
- {
- FormReset();
- MessageBox.Show("Check if your BIOS and VGA match.", "Can't Patch!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- else
- {
- RefreshForm();
- }
- }
- }
- #endregion
- #region Resetting Form values
- public void FormReset()
- {
- labelPL.Text = "Current Power Limit: N/A";
- btnPatch.Enabled = false;
- radioBtnPl20.Checked = false;
- radioBtnPl50.Checked = false;
- }
- #endregion
- #region Patch Button Click
- private void btnPatch_Click(object sender, EventArgs e)
- {
- if (BiosRW.bios == null && searchStringPL == null)
- {
- MessageBox.Show("Select any BIOS file and your VGA model!", "Can't Patch!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- if (BiosRW.bios == null && searchStringPL != null)
- {
- MessageBox.Show("Select any BIOS file!.", "Can't Patch!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- if (BiosRW.bios != null && searchStringPL == null)
- {
- MessageBox.Show("Select your VGA model!", "Can't Patch!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- if (selectedLimit != Convert.ToString(BiosRW.bios[position + 2]))
- {
- BiosRW.editBios();
- BiosRW.writeToFile();
- MessageBox.Show("Patched succesfully!", "Congratulations!", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- MessageBox.Show("You haven't selected any changes!", "Nothing to patch!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- #endregion
- #region Form Values Refreshing
- private void RefreshForm()
- {
- labelPL.Text = "Current Power Limit: ±" + (Convert.ToString(BiosRW.bios[position + 2])) + "%";
- if ((Convert.ToString(BiosRW.bios[position + 2])) == "20")
- {
- radioBtnPl20.Checked = true;
- }
- if ((Convert.ToString(BiosRW.bios[position + 2])) == "50")
- {
- radioBtnPl50.Checked = true;
- }
- btnPatch.Enabled = true;
- }
- #endregion
- #region Opening Help Forms
- private void aboutItem_Click(object sender, EventArgs e)
- {
- AboutForm aboutform = new AboutForm();
- aboutform.Owner = this;
- aboutform.ShowDialog();
- }
- private void helpItem_Click(object sender, EventArgs e)
- {
- HelpForm helpform = new HelpForm();
- helpform.Owner = this;
- helpform.Show();
- }
- #endregion
- #region Selected Power Limit Changes Event
- private void radioBtnPl20_CheckedChanged(object sender, EventArgs e)
- {
- if (radioBtnPl20.Checked == true) selectedLimit = "20";
- }
- private void radioBtnPl50_CheckedChanged(object sender, EventArgs e)
- {
- if (radioBtnPl50.Checked == true) selectedLimit = "50";
- }
- #endregion
- }
- }
- //
- //
- //
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- namespace Radeon_HD_7000_BIOS_Editor
- {
- public static class BiosRW
- {
- public static byte[] bios;
- public static byte[] modBios;
- public static void readToString(string filePath)
- {
- FileStream fs = new FileStream(filePath, FileMode.Open);
- BinaryReader br = new BinaryReader(fs);
- {
- bios = br.ReadBytes(Convert.ToInt32(fs.Length));
- }
- br.Close();
- fs.Close();
- }
- public static void editBios()
- {
- modBios = bios;
- modBios[MainForm.position + 2] = Convert.ToByte(MainForm.selectedLimit);
- }
- public static void writeToFile()
- {
- string newpath = "";
- string[] path = MainForm.filePath.Split('\\');
- for (int i=0; i < path.Length -1; i++)
- {
- newpath += path[i];
- }
- FileStream fs = new FileStream(newpath + "\\_NewBios.rom", FileMode.Create);
- BinaryWriter bw = new BinaryWriter(fs);
- bw.Write(modBios);
- bw.Close();
- fs.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement