深入理解二进制文件(In-depth understanding of binary files)

我正在学习C ++,特别是关于二进制文件结构/操作,因为我对二进制文件,位,咬和十六进制数的主题完全不熟悉,所以我决定向后退一步,对主题建立一个扎实的理解。

在下面我已经包含的图片中,我在.txt文件中写了两个单词( blue thief )。

在这里输入图像描述

原因是,当我使用hexeditor解码文件时,我想了解信息是如何以十六进制格式存储的。 现在,不要误解我的意思,我并不是试图通过整天阅读十六进制格式来谋生,而只是对二进制文件组合的基本知识有最低限度的理解。 我也知道所有文件都有不同的结构,但只是为了理解,我想知道,“蓝贼”和单个' ' (空格)这些词是如何被转换成这些字符的。

还有一件事是,我听说二进制文件包含三种类型的信息:

headerftm &和data ! 那只关注音频,视频等多媒体文件吗? 因为,除了它看起来只是这个文件中的data块之外,我似乎看不到任何东西。


I am learning C++ specially about binary file structure/manipulation, and since I am totally new to the subject of binary files, bits, bites & hexadecimal numbers, I decided to take one step backward and establish a solid understanding on the subjects.

In the picture I have included below, I wrote two words (blue thief) in a .txt file.

enter image description here

The reason for this, is when I decode the file using a hexeditor, I wanted to understand how the information is really stored in hex format. Now, don't get me wrong, I am not trying to make a living out of reading hex formats all day, but only to have a minimum level of understanding the basics of a binary file's composition. I also, know all files have different structures, but just for the sake of understanding, I wanted to know, how exactly the words "blue thief" and a single ' ' (space) were converted into those characters.

One more thing, is that, I have heard that binary files contain three types of information:

header, ftm & and the data! is that only concerned with multimedia files like audios, videos? because, I can't seem to see anything, other than what it looks like a the data chunk in this file only.


原文:https://stackoverflow.com/questions/17156522
2023-06-05 11:06

满意答案

这就是POSIX要求编写的内容

在成功返回常规文件的write()之后:

  • 从该写入修改的文件中的每个字节位置的任何成功read()都将返回该位置的write()指定的数据,直到再次修改这些字节位置。

  • 对文件中相同字节位置的任何后续成功write()都将覆盖该文件数据。

这并不能保证您的数据完全按照该顺序命中磁盘。 只要应用程序“看到”与上述两个语句一致,实现就可以重新排序所需的物理写入。

实际上,内核,甚至磁盘子系统(例如SAN)都可以重新排序写入(通常是出于性能原因)。

因此,您不能依赖写入调用的顺序来保持一致性。 你需要f[data]sync

PostgreSQL邮件列表中有趣的电子邮件线程: POSIX文件更新 。 阅读数据库如何处理I / O是了解此类问题的好方法。

(对不起,在这方面不了解Windows。)


This is what POSIX mandates for write:

After a write() to a regular file has successfully returned:

  • Any successful read() from each byte position in the file that was modified by that write shall return the data specified by the write() for that position until such byte positions are again modified.

  • Any subsequent successful write() to the same byte position in the file shall overwrite that file data.

This does not provide you with a guarantee that your data will hit the disk in that order at all. The implementation can re-order physical writes all it wants as long is what the applications "see" is consistent with the above two statements.

In practice, the kernel, and even the disk subsystem (think SANs for instance) can re-order writes (for performance reasons usually).

So you can't rely on the order of your write calls for consistency. You'll need f[data]syncs.

Interesting email thread on the PostgreSQL mailing list: POSIX file updates. Reading on how databases handle I/O is a great way to learn about this type of issue.

(Sorry, don't know about Windows in this respect.)

相关问答

更多

EntityManager操作顺序(EntityManager operations order)

显然,我可以调用entityManager.flush() 实际上你必须打电话给它。 但是,在这种情况下,数据会在整个事务提交之前保存到数据库中。 这是错误的:数据被同步到数据库,但事务仍未提交,除非您手动提交并控制数据库。 如果您没有在EJB中配置任何内容,并且您的持久性单元是JTA(请参阅带有注释的此问题 ),那么只有在方法从EJB层返回后才会提交事务。 我认为操作顺序与添加到事务中的操作顺序相同。 从我的例子可以看出事实并非如此。 不,JPA规范不强制实现这样做。 这就是为什么有一个flus...

Java中的文件操作(File Operations in Java)

使用java.io.File 列出目录中的所有文件 http://www.javaprogrammingforums.com/java-code-snippets-tutorials/3-how-list-all-files-directory.html File folder = new File(path); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { ...

麻烦的Python操作/循环顺序(Trouble with Python order of operations/loop)

csv模块包含写入和读取的方法,这使得这非常简单: import csv with open("test.csv") as file, open("test_tab.csv", "w") as out: reader = csv.reader(file) writer = csv.writer(out, dialect=csv.excel_tab) for row in reader: writer.writerow(row) 不需要自己动手。 请注意我...

PHP操作顺序(PHP Order of operations)

从里到外。 传递给PHP中的函数的东西称为“表达式”。 将表达式作为参数传递时,实际传递的是该表达式的值。 为此,表达式在传入之前进行求值。 更多关于PHP手册中的表达式。 From the inside out. The things passed into a function in PHP are called "expressions". When you pass an expression as a parameter, what you're really passing is th...

运营顺序(Order of Operations)

这根本不是编码问题,这是公式的一个问题。 你需要研究科学记数法 。 0.000683783应为0.00683783(6.83783x10 -3 ) 0.005481717应该是0.05481717(-5.481717x10 -2 ) 等等 见配方 。 It's not a coding problem at all, it's an issue with the formula. You need to study up on scientific notation. 0.000683783 sh...

保证文件操作的顺序(Guarantees of order of the operations on file)

这就是POSIX要求编写的内容 : 在成功返回常规文件的write()之后: 从该写入修改的文件中的每个字节位置的任何成功read()都将返回该位置的write()指定的数据,直到再次修改这些字节位置。 对文件中相同字节位置的任何后续成功write()都将覆盖该文件数据。 这并不能保证您的数据完全按照该顺序命中磁盘。 只要应用程序“看到”与上述两个语句一致,实现就可以重新排序所需的物理写入。 实际上,内核,甚至磁盘子系统(例如SAN)都可以重新排序写入(通常是出于性能原因)。 因此,您不能依赖写入...

NodeJS Lambda问题与操作顺序(NodeJS Lambda issue with order of operations)

给这个镜头: // dependencies const AWS = require('aws-sdk') const unzip = require('unzip') // global process variable is still accessible process.env['PATH'] = process.env['PATH'] + ':' + process.env['/tmp'] // get reference to CodePipeline client const co...

“和”和“或”的操作顺序是什么?(What is the order of operations for 'and' and 'or'?)

是的,第二个代码块等同于第一个代码块。 根据文档 , or比and优先级低。 这意味着if语句被评估为 if ((hand[0] in winning_cards and hand[1] == 'Ace') or (hand[0] == 'Ace' and hand[1] in winning_cards)): 这是你想要的。 您可以返回该布尔表达式的结果来缩短代码: def blackjack_check(hand): winning_cards = [10, 'Jack',...

NSManagedObjectContext的performBlock方法是否保证了操作的顺序?(Does NSManagedObjectContext's performBlock method guarantee the order of operations?)

我认为没有理由为什么NSManagedObjectContext不会在内部使用GCD,而GCD队列是严格的FIFO。 当然我没有证据证明这一点,但它对我来说非常有意义,因为performBlock的目标是线程安全,并且在给定的上下文中一次只执行一个操作,为什么Apple要从头开始编写系统当一个功能完善的(GCD)已经存在时。 I see no reason why NSManagedObjectContext wouldn't use GCD internally, and GCD queues ...

在NEURON .MOD文件中,这些部分的操作顺序是什么?(In NEURON .MOD files what is the order of operations of the sections?)

对于每个时间步,执行顺序如下: NET_RECEIVE :如果net_send()是一个以此机制为目标的事件,则首先执行此处的行。 否则跳过。 BREAKPOINT中的行:SOLVE ... METHOD行被忽略。 执行SOLVE后的所有行。 使用printf()语句,您将看到两个调用。 但是,其中一个调用实际上并未设置任何状态变量。 它用于计算衍生物。 最后, DERIVATIVE块:计算导数( X' = ... )的值。 请记住,要获得状态变量实际更改的值,请乘以dt 。 For every ...

相关文章

更多

elasticsearch too many open files

详细解法见:http://www.elasticsearch.org/tutorials/too-ma ...

Hadoop Java程序-files功能测试

之前一直用Hadoop streaming方式,-file功能非常实用,可以动态上传文件,例如一些配置 ...

flume写入Hadoop hdfs报错 Too many open files

故障现象: [Hadoop@dtydb6 logs]$ vi hadoop-hadoop-datano ...

深入理解Android:卷2.pdf电子书下载

深入理解ANDROID 卷2 PDF的内容摘要:内容简介发售日期: 2012年8月20日 《深入理解A ...

HttpClient 上传文件

我们使用MultipartEntityBuilder创建一个HttpEntity。 当创建构建器时,添 ...

Hadoop HDFS 文件与分块理解

Hadoop fsck / -files -blocks 会告诉集群中块的分配情况 当集群中的data ...

深入理解Magento -前言

深入理解Magento 作者:Alan Storm 翻译:Hailong Zhang 前言 我从2 ...

Storm Topology的并发度

Understanding the parallelism of a Storm topology h ...

memcached全面剖析–3.memcached的删除机制和发展方向

memcached是缓存,所以数据不会永久保存在服务器上,这是向系统中引入memcached的前提。 ...

深入理解Hadoop集群和网络 PDF

Hadoop主要的任务部署分为3个部分,分别是:Client机器,主节点和从节点。主节点主要负责Had ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本