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();
- }
- //
- //Variables
- //
- #region Variables Initialization
- public static string filePath;
- public static byte[] searchStringPL;
- public static byte[] searchStringVolt;
- public static byte[] searchStringVoltNoRef;
- public static int positionPL;
- public static int positionVoltage;
- public static string selectedLimit;
- public static bool referenceCard = true;
- public static int numberOfStrings;
- public static byte[,] voltageStrings;
- #endregion
- //
- //Opening BIOS
- //
- #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)
- {
- ReadInfo();
- }
- }
- }
- #endregion
- //
- //Search strings updating
- //
- #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 };
- searchStringVolt = new byte[] { 0x28, 0x00, 0x03, 0x01 };
- searchStringVoltNoRef = new byte[] { 0x01, 0x11, 0x36, 0x00, 0x00, 0x07 };
- }
- if (comboBoxVga.Text == "Radeon HD 7800")
- {
- searchStringPL = new byte[] { 0x00, 0x00, 0x14, 0x00, 0x4B, 0x00, 0x04 };
- searchStringVolt = new byte[] { 0x4C, 0x00, 0x03, 0x01 };
- searchStringVoltNoRef = new byte[] { 0x04, 0x00, 0x24, 0x00, 0x00, 0x04 };
- }
- if (comboBoxVga.Text == "Radeon HD 7900")
- {
- searchStringPL = new byte[] { 0x00, 0x00, 0x14, 0x00, 0x40, 0x00, 0x04 };
- searchStringVolt = new byte[] { 0x40, 0x00, 0x03, 0x01 };
- searchStringVoltNoRef = new byte[] { 0x04, 0x00, 0x24, 0x00, 0x00, 0x04 };
- }
- if (filePath != null) ReadInfo();
- }
- #endregion
- //
- //Reading Power Limit info and Voltage Table
- //
- #region Reading all info
- public void ReadInfo()
- {
- IndexOfPL(BiosRW.bios, searchStringPL);
- IndexOfVoltage(BiosRW.bios, searchStringVolt);
- }
- #endregion
- //
- //Searching Positions
- //
- #region Searching Power Limit Position in File
- public void IndexOfPL(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);
- positionPL = toSearch.IndexOf(toFind, StringComparison.Ordinal);
- if (positionPL != -1) break;
- if (ByteArrayToFind[2] == 0x14) ByteArrayToFind[2] = 0x32;
- }
- if (positionPL == -1)
- {
- FormResetPowerLimit();
- MessageBox.Show("Can't find Power Limit value! Does current value differ from 20/50%?", "Check if your BIOS and VGA match.", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- else
- {
- FormRefreshPowerLimit();
- }
- }
- }
- #endregion
- #region Searching Voltage Table Position in File
- public void IndexOfVoltage(byte[] ByteArrayToSearch, byte[] ByteArrayToFind)
- {
- if (BiosRW.bios != null && searchStringVolt != null && searchStringVoltNoRef != null)
- {
- Encoding encoding = Encoding.GetEncoding(1252);
- string toSearch = encoding.GetString(ByteArrayToSearch, 0, ByteArrayToSearch.Length);
- string toFind = encoding.GetString(ByteArrayToFind, 0, ByteArrayToFind.Length);
- positionVoltage = toSearch.IndexOf(toFind, StringComparison.Ordinal);
- if (positionVoltage == -1)
- {
- FormResetVoltage();
- MessageBox.Show("Unable to find voltage table.", "Can't Patch!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- else
- {
- IfReference();
- }
- }
- }
- #endregion
- //
- //Checking BIOS
- //
- public void IfReference()
- {
- int newPositionVoltage = positionVoltage;
- int previous = Convert.ToInt32(BiosRW.bios[newPositionVoltage - 1]);
- numberOfStrings = 0;
- while (Convert.ToInt32(BiosRW.bios[newPositionVoltage - 1]) == previous || Convert.ToInt32(BiosRW.bios[newPositionVoltage - 1]) == previous - 1)
- {
- previous = Convert.ToInt32(BiosRW.bios[newPositionVoltage - 1]);
- if (BiosRW.bios[newPositionVoltage - 4] == 0x00)
- {
- referenceCard = false;
- break;
- }
- newPositionVoltage = newPositionVoltage - 6;
- numberOfStrings++;
- }
- if (referenceCard == false)
- {
- labelReference.Text = "Reference Card: No";
- MessageBox.Show("Your card is non reference, voltage control is impossible.", "Wait for the next version!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- else
- {
- labelReference.Text = "Reference Card: Yes";
- ReadVoltageTable();
- }
- }
- public void ReadVoltageTable()
- {
- voltageStrings = new byte[numberOfStrings,6];
- int newPositionVoltage = positionVoltage - 6*numberOfStrings;
- for (int i = 0; i < numberOfStrings; i++)
- {
- for (int y = 0; y < 6; y++)
- {
- voltageStrings[i,y] = BiosRW.bios[newPositionVoltage + y];
- }
- newPositionVoltage = newPositionVoltage + 6;
- }
- ShowVoltageTable();
- }
- public void ShowVoltageTable()
- {
- string[] vid = new string[3];
- for (int i = 0; i < numberOfStrings; i++)
- {
- for (int y = 0; y < 6; y = y + 2)
- {
- if (y == 0)
- {
- richTextBox1.Text += "VID: ";
- vid[0] = voltageStrings[i, y + 1].ToString("X");
- if (vid[0].Length == 1) vid[0] = 0 + vid[0];
- vid[1] = voltageStrings[i, y].ToString("X");
- if (vid[1].Length == 1) vid[1] = 0 + vid[1];
- vid[2] = vid[0] + vid[1];
- richTextBox1.Text += Convert.ToInt32(vid[2], 16).ToString() + " mV ";
- }
- if (y == 2)
- {
- richTextBox1.Text += "Signal: ";
- vid[0] = voltageStrings[i, y + 1].ToString("X");
- if (vid[0].Length == 1) vid[0] = 0 + vid[0];
- vid[1] = voltageStrings[i, y].ToString("X");
- if (vid[1].Length == 1) vid[1] = 0 + vid[1];
- vid[2] = vid[0] + vid[1];
- richTextBox1.Text += Convert.ToInt32(vid[2], 16).ToString() + " ";
- }
- if (y == 4)
- {
- richTextBox1.Text += "ASIC: ";
- vid[0] = voltageStrings[i, y + 1].ToString("X");
- if (vid[0].Length == 1) vid[0] = 0 + vid[0];
- vid[1] = voltageStrings[i, y].ToString("X");
- if (vid[1].Length == 1) vid[1] = 0 + vid[1];
- vid[2] = vid[0] + vid[1];
- richTextBox1.Text += Convert.ToInt32(vid[2], 16).ToString() + "\r\n";
- }
- }
- }
- }
- //
- //Resetting Form Values
- //
- #region Resetting Form Power Limit Values
- public void FormResetPowerLimit()
- {
- labelPL.Text = "Current Power Limit: N/A";
- btnPatch.Enabled = false;
- radioBtnPl20.Checked = false;
- radioBtnPl50.Checked = false;
- }
- #endregion
- #region Resetting Form Voltage Values
- public void FormResetVoltage()
- {
- labelReference.Text = "Reference Card: N/A";
- }
- #endregion
- //
- //Refreshing Form Values
- //
- #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
- #region Refreshing Form Power Limit Values
- private void FormRefreshPowerLimit()
- {
- labelPL.Text = "Current Power Limit: ±" + (Convert.ToString(BiosRW.bios[positionPL + 2])) + "%";
- if ((Convert.ToString(BiosRW.bios[positionPL + 2])) == "20")
- {
- radioBtnPl20.Checked = true;
- }
- if ((Convert.ToString(BiosRW.bios[positionPL + 2])) == "50")
- {
- radioBtnPl50.Checked = true;
- }
- btnPatch.Enabled = true;
- }
- #endregion
- #region Refreshing Form Voltage Values
- private void FormRefreshVoltage()
- {
- }
- #endregion
- //
- //Patching
- //
- #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[positionPL + 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
- //
- //Opening other forms
- //
- #region Opening other Forms and Exit
- private void exitItem_Click(object sender, EventArgs e)
- {
- Close();
- }
- 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
- }
- }
- 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.positionPL + 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