脚本 – 什么语言是二进制的,因为Perl是文本?

前端之家收集整理的这篇文章主要介绍了脚本 – 什么语言是二进制的,因为Perl是文本?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在寻找脚本(或更高级别的编程)语言(或者例如Python或类似语言的模块),以便轻松分析和操纵文件中的二进制数据(例如,核心转储),这很像Perl允许非常顺利地处理文本文件

我想做的事情包括以各种形式(二进制,十进制,十六进制)显示任意数据的数据块,将数据从一个字节转换为另一个,等等。也就是说,您通常会使用C或汇编的东西,但我寻找一种语言,允许非常快速地编写一小段代码,用于高度特定的一次性目的。

有什么建议么?

解决方法

Things I want to do include presenting arbitrary chunks of the data in varIoUs forms (binary,decimal,hex),convert data from one endianess to another,etc. That is,things you normally would use C or assembly for,but I’m looking for a language which allows for writing tiny pieces of code for highly specific,one-time purposes very quickly.

好吧,虽然看起来反直觉,我发现erlang非常适合这一点,即由于其对pattern matching的强大支持,甚至是字节和位(称为“Erlang Bit Syntax”)。这使得很容易创建甚至非常高级的程序,处理在字节甚至位置级别上检查和操作数据:

Since 2001,the functional language Erlang comes with a byte-oriented datatype (called binary) and with constructs to do pattern matching on a binary.

并引用informIT.com

(Erlang) Pattern matching really starts to get
fun when combined with the binary
type. Consider an application that
receives packets from a network and
then processes them. The four bytes in
a packet might be a network byte-order
packet type identifier. In Erlang,you
would just need a single processPacket
function that could convert this into
a data structure for internal
processing. It would look something
like this:

processPacket(<<1:32/big,RestOfPacket>>) ->
    % Process type one packets
    ...
;
processPacket(<<2:32/big,RestOfPacket>>) ->
    % Process type two packets
    ...

所以,erlang内置了对模式匹配的支持,它是一个功能性的语言是非常有表现力的,例如在erlang中实现ueencode:

uuencode(BitStr) ->
<< (X+32):8 || <<X:6>> <= BitStr >>.
uudecode(Text) ->
<< (X-32):6 || <<X:8>> <= Text >>.

有关介绍,请参阅Bitlevel Binaries and Generalized Comprehensions in Erlang.您可能还想查看以下一些指针:

> Parsing Binaries with erlang,lamers inside
> More File Processing with Erlang
> Learning Erlang and Adobe Flash format same time
> Large Binary Data is (not) a Weakness of Erlang
> Programming Efficiently with Binaries and Bit Strings
> Erlang bit syntax and network programming
> erlang,the language for network programming (1)
> Erlang,the language for network programming Issue 2: binary pattern matching
> An Erlang MIDI File Reader/Writer
> Erlang Bit Syntax
> Comprehending endianness
> Playing with Erlang
> Erlang: Pattern Matching Declarations vs Case Statements/Other
> A Stream Library using Erlang Binaries
> Bit-level Binaries and Generalized Comprehensions in Erlang
> Applications,Implementation and Performance Evaluation of Bit Stream Programming in Erlang

原文链接:https://www.f2er.com/Perl/173013.html

猜你在找的Perl相关文章