Advertisement
Dragonheart91

Untitled

May 1st, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10.  
  11. namespace Radeon_HD_7000_BIOS_Editor
  12. {
  13.     public partial class MainForm : Form
  14.     {
  15.         public MainForm()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         #region Variables Initialization
  21.  
  22.         public static string filePath;
  23.         public static byte[] searchStringPL;
  24.         public static int position;
  25.         public static string selectedLimit;
  26.  
  27.         #endregion
  28.  
  29.         #region Open File Dialog
  30.         private void openBiosItem_Click(object sender, EventArgs e)
  31.         {
  32.             if (openFileDialog1.ShowDialog() == DialogResult.OK)
  33.             {
  34.                 filePath = openFileDialog1.FileName;
  35.                 BiosRW.readToString(filePath);
  36.                 if (comboBoxVga.Text != null)
  37.                 {
  38.                     IndexOf(BiosRW.bios, searchStringPL);
  39.                 }
  40.             }
  41.         }
  42.  
  43.         #endregion
  44.  
  45.         #region Exit
  46.  
  47.         private void exitItem_Click(object sender, EventArgs e)
  48.         {
  49.             Close();
  50.         }
  51.  
  52.         #endregion
  53.  
  54.         #region Search strings for Power Limit
  55.  
  56.         private void comboBoxVga_SelectedIndexChanged(object sender, EventArgs e)
  57.         {
  58.             if (comboBoxVga.Text == "Radeon HD 7700")
  59.             {
  60.                 searchStringPL = new byte[] { 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04 };
  61.             }
  62.  
  63.             if (comboBoxVga.Text == "Radeon HD 7800")
  64.             {
  65.                 searchStringPL = new byte[] { 0x00, 0x00, 0x14, 0x00, 0x4B, 0x00, 0x04 };
  66.             }
  67.  
  68.             if (comboBoxVga.Text == "Radeon HD 7900")
  69.             {
  70.                 searchStringPL = new byte[] { 0x00, 0x00, 0x14, 0x00, 0x40, 0x00, 0x04 };
  71.             }
  72.  
  73.             if (filePath != null) IndexOf(BiosRW.bios, searchStringPL);
  74.         }
  75.  
  76.         #endregion
  77.  
  78.         #region Searching Position in File
  79.  
  80.         public void IndexOf(byte[] ByteArrayToSearch, byte[] ByteArrayToFind)
  81.         {
  82.             if (BiosRW.bios != null && searchStringPL != null)
  83.             {
  84.                 ByteArrayToFind[2] = 0x14;
  85.                 for (int i = 0; i < 2; i++)
  86.                 {
  87.                     Encoding encoding = Encoding.GetEncoding(1252);
  88.  
  89.                     string toSearch = encoding.GetString(ByteArrayToSearch, 0, ByteArrayToSearch.Length);
  90.                     string toFind = encoding.GetString(ByteArrayToFind, 0, ByteArrayToFind.Length);
  91.                     position = toSearch.IndexOf(toFind, StringComparison.Ordinal);
  92.                     if (position != -1) break;
  93.                     if (ByteArrayToFind[2] == 0x14) ByteArrayToFind[2] = 0x32;
  94.                 }
  95.                 if (position == -1)
  96.                 {
  97.                     FormReset();
  98.                     MessageBox.Show("Check if your BIOS and VGA match.", "Can't Patch!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  99.                 }
  100.                 else
  101.                 {
  102.                     RefreshForm();
  103.                 }
  104.             }
  105.         }
  106.  
  107.         #endregion
  108.  
  109.         #region Resetting Form values
  110.  
  111.         public void FormReset()
  112.         {
  113.             labelPL.Text = "Current Power Limit: N/A";
  114.             btnPatch.Enabled = false;
  115.             radioBtnPl20.Checked = false;
  116.             radioBtnPl50.Checked = false;
  117.         }
  118.  
  119.         #endregion
  120.  
  121.         #region Patch Button Click
  122.  
  123.         private void btnPatch_Click(object sender, EventArgs e)
  124.         {
  125.             if (BiosRW.bios == null && searchStringPL == null)
  126.             {
  127.                 MessageBox.Show("Select any BIOS file and your VGA model!", "Can't Patch!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  128.             }
  129.            
  130.             if (BiosRW.bios == null && searchStringPL != null)
  131.             {
  132.                 MessageBox.Show("Select any BIOS file!.", "Can't Patch!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  133.             }
  134.  
  135.             if (BiosRW.bios != null && searchStringPL == null)
  136.             {
  137.                 MessageBox.Show("Select your VGA model!", "Can't Patch!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  138.             }
  139.  
  140.             if (selectedLimit != Convert.ToString(BiosRW.bios[position + 2]))
  141.             {
  142.                 BiosRW.editBios();
  143.                 BiosRW.writeToFile();
  144.                 MessageBox.Show("Patched succesfully!", "Congratulations!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  145.             }
  146.             else
  147.             {
  148.                 MessageBox.Show("You haven't selected any changes!", "Nothing to patch!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  149.             }
  150.         }
  151.  
  152.         #endregion
  153.  
  154.         #region Form Values Refreshing
  155.  
  156.         private void RefreshForm()
  157.         {
  158.             labelPL.Text = "Current Power Limit: ±" + (Convert.ToString(BiosRW.bios[position + 2])) + "%";
  159.             if ((Convert.ToString(BiosRW.bios[position + 2])) == "20")
  160.             {
  161.                 radioBtnPl20.Checked = true;
  162.             }
  163.             if ((Convert.ToString(BiosRW.bios[position + 2])) == "50")
  164.             {
  165.                 radioBtnPl50.Checked = true;
  166.             }
  167.             btnPatch.Enabled = true;
  168.         }
  169.  
  170.         #endregion
  171.  
  172.         #region Opening Help Forms
  173.  
  174.         private void aboutItem_Click(object sender, EventArgs e)
  175.         {
  176.             AboutForm aboutform = new AboutForm();
  177.             aboutform.Owner = this;
  178.             aboutform.ShowDialog();
  179.         }
  180.  
  181.         private void helpItem_Click(object sender, EventArgs e)
  182.         {
  183.             HelpForm helpform = new HelpForm();
  184.             helpform.Owner = this;
  185.             helpform.Show();
  186.         }
  187.  
  188.         #endregion
  189.  
  190.         #region Selected Power Limit Changes Event
  191.  
  192.         private void radioBtnPl20_CheckedChanged(object sender, EventArgs e)
  193.         {
  194.             if (radioBtnPl20.Checked == true) selectedLimit = "20";
  195.         }
  196.  
  197.         private void radioBtnPl50_CheckedChanged(object sender, EventArgs e)
  198.         {
  199.             if (radioBtnPl50.Checked == true) selectedLimit = "50";
  200.         }
  201.  
  202.         #endregion
  203.  
  204.     }
  205. }
  206.  
  207. //
  208. //
  209. //
  210.  
  211. using System;
  212. using System.Collections.Generic;
  213. using System.Linq;
  214. using System.Text;
  215. using System.IO;
  216.  
  217. namespace Radeon_HD_7000_BIOS_Editor
  218. {
  219.     public static class BiosRW
  220.     {
  221.         public static byte[] bios;
  222.         public static byte[] modBios;
  223.  
  224.         public static void readToString(string filePath)
  225.         {
  226.             FileStream fs = new FileStream(filePath, FileMode.Open);
  227.             BinaryReader br = new BinaryReader(fs);
  228.             {
  229.                 bios = br.ReadBytes(Convert.ToInt32(fs.Length));
  230.             }
  231.             br.Close();
  232.             fs.Close();
  233.         }
  234.  
  235.         public static void editBios()
  236.         {
  237.             modBios = bios;
  238.             modBios[MainForm.position + 2] = Convert.ToByte(MainForm.selectedLimit);
  239.         }
  240.  
  241.         public static void writeToFile()
  242.         {
  243.             string newpath = "";
  244.             string[] path = MainForm.filePath.Split('\\');
  245.             for (int i=0; i < path.Length -1; i++)
  246.             {
  247.                 newpath += path[i];
  248.             }
  249.             FileStream fs = new FileStream(newpath + "\\_NewBios.rom", FileMode.Create);
  250.             BinaryWriter bw = new BinaryWriter(fs);
  251.             bw.Write(modBios);
  252.             bw.Close();
  253.             fs.Close();
  254.         }
  255.     }
  256. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement