Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Windows.Forms;
- using System.IO;
- using System.Diagnostics;
- namespace ChangeValue
- {
- public partial class FrmMain : Form
- {
- public FrmMain()
- {
- InitializeComponent();
- }
- OpenFileDialog ofd = new OpenFileDialog();
- private void BtnLoad1_Click(object sender, EventArgs e)
- {
- ofd.Filter = "Videos files (*.png *.jpg) | *.png; *.jpg; | All files (*.*) | *.*";
- DialogResult result = ofd.ShowDialog();
- if (result == DialogResult.OK)
- {
- path1.Text = ofd.FileName;
- }
- }
- private void BtnLoad2_Click(object sender, EventArgs e)
- {
- ofd.Filter = "Videos files (*.png *.jpg) | *.png; *.jpg; | All files (*.*) | *.*";
- DialogResult result = ofd.ShowDialog();
- if (result == DialogResult.OK)
- {
- path2.Text = ofd.FileName;
- BtnStart.Enabled = true;
- }
- }
- private void BtnStart_Click(object sender, EventArgs e)
- {
- byte[] image1 = File.ReadAllBytes(path1.Text);
- string hex1 = Bytes2HexString(image1);
- // search the value from hex1
- string copyFromhex1 = "";
- string pattern = @"(?<=\w{60})\w{4}";
- Match match1 = Regex.Match(hex1, pattern);
- if (match1.Success)
- {
- copyFromhex1 = match1.Value;
- }
- byte[] image2 = File.ReadAllBytes(path2.Text);
- string hex2 = Bytes2HexString(image2);
- // search the value from hex2
- pattern = @"(?<=\w{60})\w{4}";
- Match match2 = Regex.Match(hex1, pattern);
- if (match2.Success)
- {
- hex2.Replace(match2.Value,copyFromhex1);
- }
- image2 = HexString2Bytes(hex2);
- File.WriteAllBytes(path2.Text, image2);
- //Process.Start(path2.Text);
- MessageBox.Show("Success");
- }
- private static byte[] HexString2Bytes(string hexString)
- {
- int bytesCount = (hexString.Length) / 2;
- byte[] bytes = new byte[bytesCount];
- for (int x = 0; x < bytesCount; ++x)
- {
- bytes[x] = Convert.ToByte(hexString.Substring(x * 2, 2), 16);
- }
- return bytes;
- }
- private static string Bytes2HexString(byte[] buffer)
- {
- var hex = new StringBuilder(buffer.Length * 2);
- foreach (byte b in buffer)
- {
- hex.AppendFormat("{0:x2}", b);
- }
- return hex.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement