我正在学习VB.NET编程,并尝试操作一个可执行文件。
我的项目要求我将一个字节变量(由File.ReadAllBytes
获取)分成两部分,然后才能将它们“粘”在代码的另一部分中。
我考虑将我的字节数组转换为字符串,然后使用.Split进行拆分,最后再将其转换为字节数组,但是我的可执行文件不再起作用:转换为字符串会杀死可执行文件中的某些字符,使其过时。
我发现了这篇文章:Split a byte array at a delimiter
..但问题在于他使用C#进行操作,而我难以将其代码转换为VB.NET。
总之,以下是我的程序步骤:
- 通过
File.ReadAllBytes
读取所有字节 - 定期拆分该字节数组。分隔符不是字符串,而是数组的一半。
- 对渠道进行分组并执行
我尝试将可执行文件拆分为两个字节变量,但我被卡住了:
Bytes_Executable = IO.File.ReadAllBytes(File1)
Dim Separator As Integer = Bytes_Executable.Length / 2
MsgBox(Separator)
Dim Sortie = {}
Dim Sortie2 = {}
Array.Copy(Bytes_Executable, 0, Sortie, 0, Separator)
Array.Copy(Bytes_Executable, Separator, Sortie2, 0, Bytes_Executable.Length)
实际上,我遇到了这个错误:目标表不够长。请检查destIndex和长度,以及数组下限。
这个错误指向以下代码行:
Array.Copy(Bytes_Executable, Separator, Sortie2, 0, Bytes_Executable.Length)
非常感谢您提前的支持!
Dim arr As Integer() = someListOfInteger.ToArray()
或= SomeFunctionThatReturnsAnArray()
),则不需要设置长度。然而,如果你要填充数组(Array.Copy()
是一种填充数组的方式),则必须设置长度。祝你好运 :) - 41686d6564 stands w. Palestine