首页 \ 问答 \ 深入理解二进制文件(In-depth understanding of binary files)

深入理解二进制文件(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.flush() 实际上你必须打电话给它。 但是,在这种情况下,数据会在整个事务提交之前保存到数据库中。 这是错误的:数据被同步到数据库,但事务仍未提交,除非您手动提交并控制数据库。 如果您没有在EJB中配置任何内容,并且您的持久性单元是JTA(请参阅带有注释的此问题 ),那么只有在方法从EJB层返回后才会提交事务。 我认为操作顺序与添加到事务中的操作顺序相同。 从我的例子可以看出事实并非如此。 不,JPA规范不强制实现这样做。 这就是为什么有一个flush()操作 ...
  • 使用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++) { // Do ...
  • 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) 不需要自己动手。 请注意我对with ...
  • 从里到外。 传递给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 the val ...
  • 这根本不是编码问题,这是公式的一个问题。 你需要研究科学记数法 。 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 should ...
  • 这就是POSIX要求编写的内容 : 在成功返回常规文件的write()之后: 从该写入修改的文件中的每个字节位置的任何成功read()都将返回该位置的write()指定的数据,直到再次修改这些字节位置。 对文件中相同字节位置的任何后续成功write()都将覆盖该文件数据。 这并不能保证您的数据完全按照该顺序命中磁盘。 只要应用程序“看到”与上述两个语句一致,实现就可以重新排序所需的物理写入。 实际上,内核,甚至磁盘子系统(例如SAN)都可以重新排序写入(通常是出于性能原因)。 因此,您不能依赖写入调用的顺序 ...
  • 给这个镜头: // 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 codepip ...
  • 是的,第二个代码块等同于第一个代码块。 根据文档 , 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', 'Que ...
  • 我认为没有理由为什么NSManagedObjectContext不会在内部使用GCD,而GCD队列是严格的FIFO。 当然我没有证据证明这一点,但它对我来说非常有意义,因为performBlock的目标是线程安全,并且在给定的上下文中一次只执行一个操作,为什么Apple要从头开始编写系统当一个功能完善的(GCD)已经存在时。 I see no reason why NSManagedObjectContext wouldn't use GCD internally, and GCD queues are s ...
  • 对于每个时间步,执行顺序如下: NET_RECEIVE :如果net_send()是一个以此机制为目标的事件,则首先执行此处的行。 否则跳过。 BREAKPOINT中的行:SOLVE ... METHOD行被忽略。 执行SOLVE后的所有行。 使用printf()语句,您将看到两个调用。 但是,其中一个调用实际上并未设置任何状态变量。 它用于计算衍生物。 最后, DERIVATIVE块:计算导数( X' = ... )的值。 请记住,要获得状态变量实际更改的值,请乘以dt 。 For every time- ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)