阅读使用PowerShell /解析二进制文件 [英] Read/Parse Binary files with Powershell

查看:739
本文介绍了阅读使用PowerShell /解析二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图解析一个二进制文件,我需要去哪里一些帮助。我在网上找了解析二进制文件,读取二进制文件,阅读里面的二进制文件的文本,等等,我还没有任何运气。

I'm trying to parse a binary file, and I need some help on where to go. I've looking online for "parsing binary files", "reading binary files", "reading text inside binaries", etc. and I haven't had any luck.

例如,我将如何读了这篇课文出这个二进制文件?任何帮助将非常AP preciated。我使用PowerShell的。

For example, how would I read this text out of this binary file? Any help would be MUCH appreciated. I am using powershell.

推荐答案

看来你有一个固定的或可推论位置文本的二进制文件。 获取内容 威力帮助你,但...它会尝试将整个文件解析为一个字符串数组,从而创造垃圾的数组。此外,你不会不知道从什么文件位置的特定的字符绳子了。

It seems that you have a binary file with text on a fixed or otherwise deducible position. Get-Content might help you but... It'll try to parse the entire file to an array of strings and thus creating an array of "garbage". Also, you wouldn't know from what file position a particular "rope of characters" was.

您可以尝试.NET类 文件 阅读并 编码 脱code。这只是每个呼叫的一行:

You can try .NET classes File to read and Encoding to decode. It's just a line for each call:

# Read the entire file to an array of bytes.
$bytes = [System.IO.File]::ReadAllBytes("path_to_the_file")
# Decode first 12 bytes to a text assuming ASCII encoding.
$text = [System.Text.Encoding]::ASCII.GetString($bytes, 0, 12)

在您的实际情况下,你很可能经历的字节循环数组发现的开始和一个特定的字符串序列结束,并利用这些指标来指定字节的范围要由从提取文本< A HREF =htt​​p://msdn.microsoft.com/en-us/library/05cts4c3.aspx相对=nofollow> 的GetString

In your real case you'd probably go through the array of bytes in a loop finding the start and end of a particular string sequence and using those indices to specify the range of bytes you want to extract the text from by the GetString.

我所说的.NET方法在.NET Framework 2.0或更高可用。如果你安装了PowerShell 2.0你已经拥有它。

The .NET methods I mentioned are available in .NET Framework 2.0 or higher. If you installed PowerShell 2.0 you already have it.

这篇关于阅读使用PowerShell /解析二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆