解决用十六进制修改文件的问题 全部送出
http://www.fs2you.com/files/9b9aa754-2f31-11dd-a8dc-00142218fc6e/文件在这里。
--------------------编程问答-------------------- 不好意思。,。
///实现修改一个存档文件 十六进制搜索FF 01 EB 读取后面6个字节 比如01 50 65(好像这样是3个字节)
///然后实现01和65互换位置 就成了65 50 01 然后写进ff 01 eb 后面替换掉原来的01 50 65文件中
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
namespace fairytalefornbalive05
{
public partial class frmdynasty : Form
{
public frmdynasty()
{
InitializeComponent();
}
OpenFileDialog ofDlg = new OpenFileDialog();
private bool isfinish = false;
string st = null;
string newstring;
string path="";
byte[] by;
private void btnopen_Click(object sender, EventArgs e)
{
ofDlg.Filter = "存档(*.dat)|*.dat|All Files (*.*)|*.*";
if (ofDlg.ShowDialog() == DialogResult.OK)
{
try
{
Thread objth = new Thread(getwage);
objth.Priority = ThreadPriority.BelowNormal;
objth.Start();
if (isfinish == false)
{
int j = 0;
for (; j < progressBar1.Maximum; j++)
{
j++;
progressBar1.Value = j;
}
toolStripStatusLabel1.Text = "查找地址Ing,请耐心等待";
}
else
progressBar1.Value = progressBar1.Maximum;
}
catch (Exception ee) {
Console.WriteLine(ee);
}
}
}
private void getwage() {
FileStream fs = new FileStream(ofDlg.FileName, FileMode.Open);
txtpath.Text = ofDlg.FileName;
by = new byte[fs.Length];
fs.Read(by, 0, by.Length);
for (int i = 0; i < by.Length; i++)
{
st += by[i].ToString("X2");
}
string total = st.Substring(st.ToUpper().LastIndexOf("FF01EB") + 6, 6);
string firststring = total.Substring(0, 2);
string secondstring = total.Substring(2, 2);
string thirdstring = total.Substring(4, 2);
newstring = thirdstring + secondstring + firststring;
while ("0" == newstring[0].ToString())
{
newstring = newstring.Remove(0, 1);
Console.WriteLine(newstring);
}
int wages = Convert.ToInt32(newstring, 16) / 1000;
txtwage.Text = wages.ToString();
isfinish = true;
toolStripStatusLabel1.Text = "查找成功";
fs.Close();
}
private void btnedit_Click(object sender, EventArgs e)
{//18a88
//888a01
string getwage = Convert.ToString(int.Parse(txtwage.Text.Trim()) * 1000, 16);
string firststring1;
string secondstring1;
string thirdstring1;
string newstring1="";
switch (getwage.Length) {
case 7:
MessageBox.Show("数值太大", "发生错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
break;
case 6:
firststring1 = getwage.Substring(0, 2);
secondstring1 = getwage.Substring(2, 2);
thirdstring1 = getwage.Substring(4, 2);
newstring1 = thirdstring1 + secondstring1 + firststring1;
break;
case 5:
getwage = "0" + getwage;
firststring1 = getwage.Substring(0, 2);
secondstring1 = getwage.Substring(2, 2);
thirdstring1 = getwage.Substring(4, 2);
newstring1 = thirdstring1 + secondstring1 + firststring1;
break;
case 4:
getwage = getwage + "00";
firststring1 = getwage.Substring(0, 2);
secondstring1 = getwage.Substring(2, 2);
thirdstring1 = getwage.Substring(4, 2);
newstring1 = thirdstring1 + secondstring1 + firststring1;
break;
default:
MessageBox.Show("地址错误", "发生错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
break;
}
st.Replace(newstring1, newstring);
byte[] info = Encoding.Unicode.GetBytes(st);
FileStream fs1 = File.Open(txtpath.Text, FileMode.Truncate);
BinaryWriter bitwter = new BinaryWriter(fs1);
fs1.Write(info, 0, info.Length);
fs1.Close();
bitwter.Close();
}
}
}
忘记写分了。。
解决了另开一贴给分 --------------------编程问答-------------------- 没人帮忙?
很急又不知道怎么做。
来个人帮忙吧 --------------------编程问答-------------------- 顶到有人帮忙为止
补充:.NET技术 , C#