问题标签 [binary]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
8 回答
286835 浏览

python - 你如何在 Python 中表达二进制文字?

如何使用 Python 文字将整数表示为二进制数?

我很容易找到十六进制的答案:

和八进制:

如何在 Python 中使用文字来表达二进制?


答案摘要

  • Python 2.5 及更早版本:可以使用int('01010101111',2)但不能使用文字来表示二进制。
  • Python 2.5 及更早版本:无法表达二进制文字。
  • Python 2.6 beta:你可以这样做:0b11001110B1100111.
  • Python 2.6 beta:也将允许0o270O27(第二个字符是字母 O)表示八进制。
  • Python 3.0 beta:与 2.6 相同,但不再允许使用旧027的八进制语法。
0 投票
1 回答
1054 浏览

language-agnostic - 二进制文件布局参考

关于二进制文件布局结构的一些好的信息来源在哪里?

如果我想提取BTrieve索引文件、解析MP3标题等。从哪里获得可靠的信息?

0 投票
11 回答
270821 浏览

c - C中的移位运算符(<<,>>)是算术还是逻辑?

在 C 中,移位运算符 ( <<, >>) 是算术还是逻辑?

0 投票
12 回答
114084 浏览

java - 如何在 XML 中嵌入二进制数据?

我有两个用 Java 编写的应用程序,它们通过网络使用 XML 消息相互通信。我在接收端使用 SAX 解析器从消息中取回数据。要求之一是在 XML 消息中嵌入二进制数据,但 SAX 不喜欢这样。有谁知道如何做到这一点?

更新:我从apache commons codec library得到了这个使用Base64类,以防其他人尝试类似的东西。

0 投票
3 回答
57982 浏览

python - Python中的二进制缓冲区

在 Python 中,您可以使用StringIO作为字符数据的类似文件的缓冲区。内存映射文件基本上对二进制数据做类似的事情,但它需要一个文件作为基础。Python 是否有一个用于二进制数据并且仅是内存的文件对象,相当于 Java 的ByteArrayOutputStream

我的用例是我想在内存中创建一个 ZIP 文件,而ZipFile需要一个类似文件的对象。

0 投票
2 回答
5203 浏览

asp.net - 用于预览的 SharePoint 流文件

我希望将 SharePoint 2003 文档库中的文件流式传输到浏览器。基本上,这个想法是将文件作为流打开,然后将文件流“写入”到响应中,指定内容类型和内容处置标头。内容配置用于保存文件名,内容类型当然是为了提示浏览器打开什么应用程序来查看文件。

这在开发环境和 UAT 环境中运行良好。但是,在生产环境中,事情并不总是按预期工作,但仅限于 IE6/IE7。FF 适用于所有环境。

请注意,在生产环境中启用并通常使用 SSL。(当生产环境中不使用 SSL 时,文件流,按预期命名,并正确显示。)

这是一个代码片段:

就像我说的,这个代码片段在开发机器和 UAT 环境中运行良好。将打开一个对话框并要求保存、查看或取消 Testme.doc。但仅在生产中使用 SSL 时,IE 6 和 IE7 不使用附件名称。相反,它使用发送流的页面名称 testheader.apx,然后引发错误。

IE 确实提供了高级设置“不要将加密的页面保存到磁盘”。

我怀疑这是问题的一部分,服务器告诉浏览器不要缓存文件,而 IE 启用了“不要将加密的页面保存到磁盘”。

是的,我知道对于较大的文件,上面的代码片段将是内存的主要拖累,并且这种实现将是有问题的。因此,真正的最终解决方案不会将整个文件打开为单个字节数组,而是将文件作为流打开,然后将文件以一口大小的块(例如大约 10K 大小)发送到客户端。

其他任何人都有类似的通过 ssl“流式传输”二进制文件的经验吗?有什么建议或建议吗?

0 投票
6 回答
7208 浏览

linux - 我需要一个 Win/Linux 的二进制比较工具

首先,我不需要文本比较,所以 Beyond Compare 不能满足我的需要。

我正在寻找一个可以在字节级别报告两个文件之间差异的实用程序。最低限度是需要查看文件中的百分比变化,或有关受影响字节/扇区的报告。

有什么可以让我免于自己做这件事的麻烦吗?

0 投票
6 回答
1147 浏览

security - Self validating binaries?

My question is pretty straightforward: You are an executable file that outputs "Access granted" or "Access denied" and evil persons try to understand your algorithm or patch your innards in order to make you say "Access granted" all the time.

After this introduction, you might be heavily wondering what I am doing. Is he going to crack Diablo3 once it is out? I can pacify your worries, I am not one of those crackers. My goal are crackmes.

Crackmes can be found on - for example - www.crackmes.de. A Crackme is a little executable that (most of the time) contains a little algorithm to verify a serial and output "Access granted" or "Access denied" depending on the serial. The goal is to make this executable output "Access granted" all the time. The methods you are allowed to use might be restricted by the author - no patching, no disassembling - or involve anything you can do with a binary, objdump and a hex editor. Cracking crackmes is one part of the fun, definately, however, as a programmer, I am wondering how you can create crackmes that are difficult.

Basically, I think the crackme consists of two major parts: a certain serial verification and the surrounding code.

Making the serial verification hard to track just using assembly is very possible, for example, I have the idea to take the serial as an input for a simulated microprocessor that must end up in a certain state in order to get the serial accepted. On the other hand, one might grow cheap and learn more about cryptographically strong ways to secure this part. Thus, making this hard enough to make the attacker try to patch the executable should not be tha t hard.

However, the more difficult part is securing the binary. Let us assume a perfectly secure serial verification that cannot be reversed somehow (of course I know it can be reversed, in doubt, you rip parts out of the binary you try to crack and throw random serials at it until it accepts). How can we prevent an attacker from just overriding jumps in the binary in order to make our binary accept anything?

I have been searching on this topic a bit, but most results on binary security, self verifying binaries and such things end up in articles that try to prevent attacks on an operating system using compromised binaries. by signing certain binaries and validate those signatures with the kernel.

My thoughts currently consist of:

  • checking explicit locations in the binary to be jumps.
  • checksumming parts of the binary and compare checksums computed at runtime with those.
  • have positive and negative runtime-checks for your functions in the code. With side-effects on the serial verification. :)

Are you able to think of more ways to annoy a possible attacker longer? (of course, you cannot keep him away forever, somewhen, all checks will be broken, unless you managed to break a checksum-generator by being able to embed the correct checksum for a program in the program itself, hehe)

0 投票
10 回答
18859 浏览

binary - 一个半字节有多少位?

二进制问题:)

0 投票
4 回答
18388 浏览

ruby - 您如何在 ruby​​ 中编写二进制文字?

大多数语言(包括 Ruby)允许以至少三种基数编写数字文字:十进制、八进制和十六进制。以十进制为基数的数字是通常的事情,并且写成(大多数)人自然写数字,96 写成96。以零为前缀的数字通常被解释为基于八进制:96 将被写为0140. 基于十六进制的数字通常带有前缀0x: 96 将被写为0x60.

问题是:我可以在 Ruby 中将数字写成二进制文字吗?如何?