0

我正在用 C# 编写一个程序来修改和操作用于汽车计算的二进制文件...当我只是尝试向用户显示某个地址的十六进制值时遇到了一个问题(我已经让程序修改该文件是必要的,现在我正试图让它对用户更加友好)我已经让程序以十六进制将整个文件写入文本框,但由于某种原因,我在尝试显示一个值时遇到了问题。这是代码,你可以看到我已经注释掉了用于显示整个文件的部分......

// Opens the stream, notice that this case only has.Read appended to it, we
// don't want to harm the original binary file
using (FileStream stream = new FileStream(chosenFile, FileMode.Open, FileAccess.Read))
{
    // returns the number of bytes in the file...
    size = (int)stream.Length; 
    // Initializes the array in which to store the data bytes...
    data = new byte[size];
    // Writes the binary data to a particular file...
    // In this case the data[] array
    stream.Read(data, 0, size); 
    progressBar1.Maximum = size;

    // Prints the original binary file...
    while (printCount < size) 
    {
        int i = data[printCount];
        // Formats the data to the same format as the hex editor...
        // not sure exactly why it works...
        // string h = i.ToString("x2"); 
        // richTextBox1.Text += h + "-";

        if (printCount1 == 15)
        {
            // richTextBox1.AppendText(Environment.NewLine);
            printCount1 = 0;
        }
        if (stream.Position == 32)
        {
            pinByte1 = i.ToString("x2");
        }
        if (stream.Position == 33)
        {

            pinByte2 = i.ToString();
            // Now stores the reversed location of the two,
            // convert to decimal for pin...
            pin = pinByte2 + pinByte1;

        }

        printCount++;
        printCount1++;
        progressBar1.Increment(1);

        textBox1.Text = "Please wait, reading original BIN...";
    }
    textBox1.Clear();
    textBox1.Text = "Your file has been read, proceed to unlock...";
    textBox2.Text += pinByte1;
    textBox3.Text += pinByte2;
    textBox6.Text += pin;
}
4

0 回答 0