我正在编写一个使用十六进制文件的应用程序,但不是所有的文件都是一个,而是只有这个具有指定的偏移量。到目前为止,我正在使用从这里获取的函数,但在我的情况下它不起作用。
public static string HexStr(byte[] p)
{
char[] c = new char[p.Length * 2 + 2];
byte b;
c[0] = '0'; c[1] = 'x';
for (int y = 0, x = 2; y < p.Length; ++y, ++x)
{
b = ((byte)(p[y] >> 4));
c[x] = (char)(b > 9 ? b + 0x37 : b + 0x30);
b = ((byte)(p[y] & 0xF));
c[++x] = (char)(b > 9 ? b + 0x37 : b + 0x30);
}
return new string(c);
}
byte[] byVal;
using (Stream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
BinaryReader brFile = new BinaryReader(fileStream);
fileStream.Position = key;
byte[] offsetByte = brFile.ReadBytes(0);
string offsetString = HexStr(offsetByte);
byVal = brFile.ReadBytes(16);
}
有人可以建议这个问题的任何其他解决方案吗?
PS此代码在指定偏移量上采用文件的十六进制(fileStream.Position=key
“key”是偏移量),这是我的弱点