标签: binaryfiles

从c中的二进制文件中读取双精度

任何人都可以展示如何在 C 中正确地将二进制表示的数据转换为双精度值。例如,我有 8 个无符号字符值要转换为双精度值(让我们将其命名为缓冲区)。所以buffer[0]的0位是LSB,buffer[7]的7位是MSB。预先非常感谢!

c binary binaryfiles binary-data

4
推荐指数
1
解决办法
6872
查看次数

C# 加载二进制文件

请告诉我最好/最快的方法:

1)将非常小的二进制文件加载到内存中。例如图标;

2) 加载/读取大小为 512Mb+ 的非常大的二进制文件。

3)当您不想考虑大小/速度而只需要做一件事时,您的常见选择:将所有字节读入内存?

谢谢你!!!

PS 抱歉,可能是一个微不足道的问题。请不要关闭它;)

PS2。Java模拟题镜像;

c# io binaryfiles

4
推荐指数
2
解决办法
1万
查看次数

如何在VBscript中使用ADODB.stream连接二进制文件

嗨,伙计们,我必须将3个二进制文件连接成一个,但我得到一个错误,而我在这里尝试它是我的代码

' This is a simple example of managing binary files in
' vbscript using the ADODB object
dim inStream,outStream
const adTypeText=2
const adTypeBinary=1

' We can create the scream object directly, it does not
' need to be built from a record set or anything like that
set inStream=WScript.CreateObject("ADODB.Stream")

' We call open on the stream with no arguments.  This makes
' the stream become an empty container which can be then
' used for what operations we want …
Run Code Online (Sandbox Code Playgroud)

vbscript binaryfiles

4
推荐指数
1
解决办法
1万
查看次数

无法读取midi文件?[扩展规格?]

我正在尝试用C++读取midi文件而且我遇到了一个错误,这个错误似乎是标准midi规范中未定义的事件(从许多网站中检索到,包括:http://www.sonicspot.com/ guide/midifiles.html)

我在HEX编辑器中打开了midi并确定了错误.它发生在第一个"注意事件"事件之前.该文件是使用Sibelius 6软件生成的,我想知道如果我在这里发布文件部分,有人会帮我解决这个问题.

这是第三首曲目的开头:

4D 54 72 6B (MTrk magic number)
00 00 1F F5 (track size in bytes - 8181)
00 FF 03 04 (4 bytes follows) (track sequence name)
00 FF 04 0B (11 bytes follows) (instrument name)
00 C0 34 (program change event)
00 B0 79 00 (controller event)
00 5B <- (what the heck is that?!)
Run Code Online (Sandbox Code Playgroud)

它不能是delta刻度,因为第一个值是00(没有MSB设置为1),它也不是可识别的事件.10个字节后,我认识到"注意事件"事件它会:

00 5B 30 00 40 00 00 07 64 00 0A 10 00 90 …

c++ midi binaryfiles

4
推荐指数
1
解决办法
544
查看次数

基本的二进制阅读

我正在尝试使用读取文件BinaryReader.但是,我在检索预期的值时遇到问题.

using (BinaryReader b = new BinaryReader(File.Open("file.dat", FileMode.Open)))
{
    int result = b.ReadInt32(); //expected to be 2051
}
Run Code Online (Sandbox Code Playgroud)

"file.dat" 是以下......

00 00 08 03 00 00 EA 60
Run Code Online (Sandbox Code Playgroud)

预期的结果应该是2051,但它得到的东西完全无关紧要.请注意,我每次得到的结果都是一样的.

问题是什么?

c# binaryfiles binary-data

4
推荐指数
2
解决办法
261
查看次数

使用Python修改二进制文件

我正在尝试修补hex文件.我有两个名为"patch 1"和"patch 2"的补丁文件(hex)

要修补的文件是一个名为"file.bin"的16 MB文件.

在过去的6或7个小时里,我尝试了许多不同的方法来弄清楚如何去做.我可以整天写一个字符串到一个文件,但我想尝试执行以下操作:

打开patch1.bin,读取字节打开patch2.bin,读取字节打开file.bin,写入字节

我想寻找位置0xc0010和0x7c0010,并应用patch1.bin然后我想寻求0x040000并应用patch2.bin

总而言之,我将应用3个补丁,然后关闭"file.bin"

如果有人给我一个例子,我会非常感激:)

我先尝试过这个:

patch1 = open("patch1", "r");
patch2 = open("patch2", "r");
main = open("file.bin", "w");

main.seek(0xC0010);
main.write(patch1);
main.seek(0x7C0010);
main.write(patch1);
main.seek(0x40000);
main.write(patch2);
main.close();
Run Code Online (Sandbox Code Playgroud)

但被告知我正在尝试将字符串写入文件,当它确实不是我想要的时候,大声笑然后我试过这个:

infile1 = open("patch1.bin", "rb") 
new_pos1 = int("0x00", 16)
infile1.seek(new_pos1, 0)
infile2 = open('file.bin', 'wb')
new_pos2 = int('0xc0010', 16)
infile2.seek(new_pos2, 0xc0010)
chunk1 = int("6FFFE0", 16)         #this is how long patch1 file is
data1 = infile1.read(chunk1)
with open("file.bin", "a") as outfile:
    outfile.write(data1)
Run Code Online (Sandbox Code Playgroud)

但它也没有用,因为无论我怎样尝试,我都无法用正确的偏移来写数据.

我确实管理了几次将patch1写入file.bin,但它没有在正确的偏移处进行修补,事实上它删除了file.bin并且只是将patch1复制到了它的位置.哪个是错的.

我必须提醒你我是python和编程的新手,但我真的想深入研究它并学习,所以任何好的例子都会被检查,希望对我来说是一个很好的学习课:)

谢谢你们和gals帮助我弄清楚我做错了什么:)

python file-io binaryfiles

4
推荐指数
1
解决办法
1万
查看次数

Delphi如何更快地搜索二进制文件?

我有一个二进制文件(2.5 MB),我想找到这个字节序列的位置:CD 09 D9 F5.然后我想在这个位置后写一些数据,并用零覆盖旧数据(4 KB).

这是我现在的方式,但它有点慢.

ProcessFile(dataToWrite: string);
var
  fileContent: string;
  f: file of char;
  c: char;
  n, i, startIndex, endIndex: integer;
begin
  AssignFile(f, 'file.bin');
  reset(f);
  n := FileSize(f);
  while n > 0 do
  begin
    Read(f, c);
    fileContent := fileContent + c;
    dec(n);
  end;
  CloseFile(f);

  startindex := Pos(Char($CD)+Char($09)+Char($D9)+Char($F5), fileContent) + 4;
  endIndex := startIndex + 4088;

  Seek(f, startIndex);

  for i := 1 to length(dataToWrite) do
    Write(f, dataToWrite[i]);

  c := #0;
  while (i < endIndex) do
  begin
    Write(f, c); inc(i); …
Run Code Online (Sandbox Code Playgroud)

delphi binaryfiles delphi-7

4
推荐指数
1
解决办法
3403
查看次数

如何根据实模式偏移和寻址确定x86机器操作码值?

我试图将原始机器代码字节写为0和1到文本文件中,并通过BIOS执行它.

然而,我有一些问题需要理解寻址,乘法,偏移,寻址,操作数和指令在组合安排中的作用,即MOV AL, 07和之间的区别MOV BL, AL.

我的意思是它在Assembly中是有意义的,但在机器代码中,获取参数的想法变得非常困难.

所以我想知道的是:我怎样才能更好地理解这一点?我发现没有教程可以准确地解释/描述组合相关中的指令或数据传递,MMIO,寻址模式,算术等之间的连接中的0和1.

在这个网站http://ref.x86asm.net/coder32.html#x00它尝试,但我不明白这一点.

示例:假设我想将5移入AL ...我是否将二进制文件中的文字'5'指定为使用AL/MOV指令链接的二进制前缀中的操作码的一部分,或者我是否每个都有一个固定的二进制代码教学,无论价值多少?这就是我想知道的...如何解释如何编写机器代码.

binary assembly binaryfiles opcode offset

4
推荐指数
1
解决办法
3617
查看次数

为什么git索引文件是二进制文件?

我的Git目录中的大多数文件都是纯文本文件(压缩的松散对象和packfiles除外).这样我就可以猫和编辑文件,如.git/HEAD或.git/refs/heads/master与检查库,如果它被破坏.

但这.git/index是一个二进制文件.纯文本文件不是更有用,因为它可以很容易地手工修改吗?

Scott Chacon在他的演讲中展示了以下图片(幻灯片278): Scott Chacon指数

在我看来,这很容易被放到一个纯文本文件中.

那么为什么它是二进制文件而不是纯文本文件?

git binaryfiles git-index

4
推荐指数
1
解决办法
1109
查看次数

从二进制文件中读取 unsigned long

我正在尝试unsigned long从二进制文件中读取一个数字。
我是这样做的:

    infile.open("file.bin", std::ios::in | std::ios::binary);
    char* U=new char[sizeof(unsigned long)];
    unsigned long out=0;
    infile.read(U, sizeof(unsigned long));
    out=static_cast<unsigned long>(*U);
    delete[] U;
    U=NULL;
    infile.close();
Run Code Online (Sandbox Code Playgroud)

但结果不正确。
我的数据是6A F2 6B 58 00 00 00 00女巫应该被读取,1483469418但106在我的代码中它只是数据的第一个字节

问题是什么?
我应该如何正确读取unsigned long来自文件的内容?

c++ binaryfiles readfile

4
推荐指数
1
解决办法
1207
查看次数

标签 统计

binaryfiles ×10

binary ×2

binary-data ×2

c# ×2

c++ ×2

assembly ×1

c ×1

delphi ×1

delphi-7 ×1

file-io ×1

git ×1

git-index ×1

io ×1

midi ×1

offset ×1

opcode ×1

python ×1

readfile ×1

vbscript ×1