标签: binaryfiles

如何处理固定长度记录的二进制文件,中间没有换行符?

我有一个文本文件,它由固定长度的记录组成,但都在一行中,两者之间没有换行符.在Perl中处理它的最佳方法是什么?谢谢!

perl binaryfiles

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

巨大的二进制文件几乎100%收缩?

我创建了一个包含4,000,000个"double"值的二进制文件(总共32MB).然后,我将其压缩,令我惊讶的是,文件仅缩小到46KB.

这差不多是百分之百!这是真的吗?或者我在这里遗失了什么?

linux ubuntu binaryfiles binary-data

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

查找二进制文件的版本

有谁知道我怎么能找到传递给我的函数的二进制文件的版本?

我从这个页面得到以下代码:

def version(fpath):
    f = open(fpath, 'rb')

    s = f.read(1024)
    print s

    f.close()
Run Code Online (Sandbox Code Playgroud)

但是,这并没有给我任何类似于上述网站显示的有用输出.

编辑:@BoazYaniv告诉我文件格式在这个问题中起着重要作用.这是一个Windows EXE文件

python binaryfiles version

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

在c#中读取exe文件作为二进制文件

我想在我的c#代码中读取exe文件,然后解码为base64.

我这样做

FileStream fr = new FileStream(@"c:\1.exe", FileMode.Open, FileAccess.Read, FileShare.Read);
StreamReader sr = new StreamReader(fr);
fr.Read(data, 0, count);
Run Code Online (Sandbox Code Playgroud)

但问题是,当我写这个文件时,写入的文件被破坏了.在十六进制车间分析代码值十六进制中的值被替换为0.

现在请建议解决方案.谢谢

c# exe binaryfiles

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

二进制文件大小不一致(C/C++)

我在编写和读取二进制文件中的双精度数组时遇到了问题.在某些情况下,文件的大小大于预期.以下代码:

int main()
{
    int i, j, size=13;
    FILE *fid = fopen("C:\\Group0\\Night0\\Imanti\\test.dat", "w");
    double *arr = (double *)malloc(sizeof(double)* size);

    for (i = 0; i < size; i++) {
        arr[i] = size / (i + 1.0);
        printf("%f\n", arr[i]);
    }

    fwrite(arr, sizeof(double), size, fid);
    free(arr);
    fclose(fid);
    printf("\n\n");

    fid = fopen("C:\\Group0\\Night0\\Imanti\\test.dat", "r");
    arr = (double *)malloc(sizeof(double)* size);
    fread(arr, sizeof(double), size, fid);

    for (i = 0; i < size; i++) {
        printf("%f\n", arr[i]);
    }

    free(arr);
    fclose(fid);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

显示了我的问题的一个简单示例.例如size = 10,如果我用它运行它,文件的大小是80字节,写入和读取时的数字是相同的.如果我运行它 …

c c++ double binaryfiles

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

以编程方式告诉c ++中的文件类型

有什么方法可以以编程方式查看文件并告诉它是什么类型的文件,例如mp3,txt,binary,photoshop等?我不认为STL中会有任何内容(除了尝试打开文本文件并将其读入).

如何尝试告诉您真正处理的文件类型?我的意思是我可以将.mp3扩展名放在一个真正不是mp3文件的文件上.

c++ file-io binaryfiles file

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

二进制文件中cut和dd的结果不同

我的环境:

CentOS 6.5
Run Code Online (Sandbox Code Playgroud)

我需要提取ELF文件的一些部分.

当我使用dd如下命令时,我没有问题:

$dd if=a.out of=a.cut1 bs=1 skip=16    
Run Code Online (Sandbox Code Playgroud)

另一方面,当我cut按如下方式使用命令时,创建的文件的大小比我预期的要小得多:

$cut --bytes=16- a.out > a.cut2
Run Code Online (Sandbox Code Playgroud)


例如,我通过使用gcc(v.4.4.7)编译以下示例c程序来创建a.out:

#include <stdio.h>

int main()
{
    printf("Hello world\n");
}
Run Code Online (Sandbox Code Playgroud)

然后,我按上述执行ddcut命令,我有以下大小的文件:

a.out - 6415 bytes
a.cut1 - 6399 bytes
a.cut2 - 6356 bytes
Run Code Online (Sandbox Code Playgroud)

我想知道为什么cut命令减小了比我指定的更多的大小.

linux cut binaryfiles dd elf

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

使用ostream :: write将char*写入二进制文件

我正在尝试将char*写入二进制文件.

这就是我现在拥有的.

void Write(char* fileName, char* pData)
{

    ofstream binFile (fileName, ios::out | ios::binary);
    if (binFile.open())
    {
        binFile.write((char*)&pData,         sizeof(pData));
        binFile.close();
    }
}


void Read(char* fileName, char* pData)
{
    ifstream binFile(fileName, ios::in | ios::binary);
    if(binFile.open())
    {
        binFile.read(char*)&pData, sizeof(pData));
        binFile.close
    }
}

int main()
{
    char* testData = "ABCdEFG"; // not real data
    char* getTestData;
    char* file = "C:\\testData.dat";
    Write(file, testData);
    Read(file, getTestData);
}
Run Code Online (Sandbox Code Playgroud)

测试数据的长度未知.可能并不总是一样的.

当我运行程序一次,并写和读.我可以找回测试数据.

但是当我停止程序并再次运行时,这次没有写入.只是阅读,我无法取回测试数据.

我真的不明白这里发生了什么.有人可以向我解释一下吗?

c++ binaryfiles ofstream

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

如何按指令读取二进制可执行文件?

有没有办法以编程方式从x86架构上的二进制可执行文件中读取给定数量的指令?

如果我有一个简单的C程序的二进制文件hello.c:

#include <stdio.h>

int main(){
    printf("Hello world\n");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在使用编译后gcc,反汇编函数main如下所示:

000000000000063a <main>:
 63a:   55                      push   %rbp
 63b:   48 89 e5                mov    %rsp,%rbp
 63e:   48 8d 3d 9f 00 00 00    lea    0x9f(%rip),%rdi        # 6e4 <_IO_stdin_used+0x4>
 645:   e8 c6 fe ff ff          callq  510 <puts@plt>
 64a:   b8 00 00 00 00          mov    $0x0,%eax
 64f:   5d                      pop    %rbp
 650:   c3                      retq   
 651:   66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1)
 658:   00 00 …
Run Code Online (Sandbox Code Playgroud)

c assembly binaryfiles instructions

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

如何使用二进制文件.覆盖特定字节

我正在用python编写程序,并希望能够写入二进制文件中的特定字节.我尝试在shell中使用包含数字0到15的小二进制文件来执行此操作,但我无法弄清楚如何执行此操作.下面是我刚刚在shell中输入的代码,其中包含用于演示我要执行的操作的注释:

>>> File=open("TEST","wb") # Opens the file for writing.
>>> File.write(bytes(range(16))) # Writes the numbers 0 through 15 to the file.
16
>>> File.close() # Closes the file.
>>> File=open("TEST","rb") # Opens the file for reading, so that we can test that its contents are correct.
>>> tuple(File.read()) # Expected output: (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, …
Run Code Online (Sandbox Code Playgroud)

python binaryfiles file python-3.x

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

标签 统计

binaryfiles ×10

c++ ×3

c ×2

file ×2

linux ×2

python ×2

assembly ×1

binary-data ×1

c# ×1

cut ×1

dd ×1

double ×1

elf ×1

exe ×1

file-io ×1

instructions ×1

ofstream ×1

perl ×1

python-3.x ×1

ubuntu ×1

version ×1