2012-08-30 22:25:48 +0000 2012-08-30 22:25:48 +0000
37
37
Advertisement

如何在Windows 7中原生查看文件的二进制内容?(是否可以。)

Advertisement

我有一个文件,比500MB大一点,引起了一些问题。

我相信问题出在所使用的行尾(EOL)约定上。我想看看文件的未解释的原始形式(1),以确认文件的EOL约定。

我如何使用Windows 7内置的东西查看文件的 “二进制"?我希望避免下载任何额外的东西。

(1)我和我的同事用文本编辑器打开文件,它们显示的行数符合人们的期望。但是这两个文本编辑器都会用不同的EOL惯例打开文件,并自动解释它们。(TextEdit和Emacs 24.2。对于Emacs,我在linux盒子上用head -c4096创建了一个只有前4K字节的第二个文件,然后从我的windows盒子上打开它。

我试图在Emacs中使用hexl模式,但当我转到hexl模式又回到文本模式时,缓冲区的内容已经发生了变化,在每行末尾都增加了一个可见的^M,所以我现在不相信这个。

我相信问题可能出在行末字符的使用上。我和我的同事试过的编辑器(1)只是自动识别行尾约定,并显示行。而根据其他证据,我相信EOL约定是只回车。(2)只回车。

要想知道文件中的实际内容,我想看看文件的二进制内容,或者至少是文件的几千个字节,最好是十六进制,虽然我可以用十进制或八进制。仅仅是1和0就很难看了。

UPDATE

除了建议DEBUG的那个,下面所有的答案在某种程度上都能用。我已经给每一个都加了票,认为很有帮助。我的问题是不严谨的。在测试每个建议的解决方案时,我发现我真正想要的是十六进制和文本内容的并排查看,而且我希望当我把光标放在某个东西上时,无论是字节值还是文本字符,另一边匹配的东西会被突出显示。

当Emacs hexl-mode开始 "正确 "工作时,我实际上解决了我的问题。所以我最终没有使用这些答案,只是测试了一下(真的应该调查Emacs的奇怪行为,并提交一个bug-report)。

Advertisement
Advertisement

Respostas (11)

43
43
43
2017-09-06 05:04:26 +0000

如果你使用的是 powershell 5.0 或更高版本,你可以使用 powershell内置函数 Format-Hex

PS:21 C:\Temp >Format-Hex application.exe

            0 1 2 3 4 5 6 7 8 9 A B C D E F

00000000 42 4D 5E 00 00 00 00 00 00 00 36 00 00 00 28 00 BM^.......6...(. 
00000010 00 00 0A 00 00 00 01 00 00 00 01 00 20 00 00 00 ............ ... 
00000020 00 00 00 00 00 00 C4 0E 00 00 C4 0E 00 00 00 00 ......Ä...Ä..... 
00000030 00 00 00 00 00 00 B7 59 71 FF B7 59 71 FF B7 59 ......•Yq.•Yq.•Y 
00000040 71 FF B7 59 71 FF B7 59 71 FF B7 59 71 FF B7 59 q.•Yq.•Yq.•Yq.•Y 
00000050 71 FF B7 59 71 FF B7 59 71 FF B7 59 71 FF q.•Yq.•Yq.•Yq.
```。
26
26
26
2012-08-31 00:35:08 +0000

内置的,快速且肮脏的:启动powershell,执行。

gc -encoding byte -TotalCount 100 "your_file_path" |% {write-host ("{0:x}" -f $_) -noNewline " "}; write-host

TotalCount是你想从文件中读取的字节数。

Google ‘powerhell hexdump’ 可以得到更多的精炼/可行的版本。

如果你有 Windows Resource Kit Tools (不完全是内置的,但接近),你也可以使用一个叫 list.exe的 cmd line 工具。它是一个带有十六进制模式的小型编辑器。专门为处理大文件而设计。

List 文本文件工具(List)是一个命令行工具,可以显示和搜索一个或多个文本文件。与其他文本显示工具不同的是,当您打开文件时,List不会将整个文件读入内存。它允许用户以十六进制格式编辑文本文件。

List对于远程显示文本或日志文件很有用,对于管理员担心系统性能下降的服务器来说,它也很有用。

11
Advertisement
11
11
2012-08-31 00:05:36 +0000
Advertisement

你需要一个 “十六进制编辑器"。我使用 "十六进制编辑器Neo "多年,它非常好。它有 免费和付费版本 。我相信还有其他类似的工具可用)。

7
7
7
2018-09-06 00:15:24 +0000

这也适用于XP之后的所有系统。

certutil -encodehex MyProgram.exe MyProgram.txt

XP需要从这里下载Windows Server 2003管理工具包: https://www.microsoft.com/en-us/download/details.aspx?id=16770

6
Advertisement
6
6
2012-08-30 23:48:49 +0000
Advertisement

将文件复制到一个扩展名为.COM的名称,其中基本名称不超过8个字符.  运行

DEBUG your_filename

它会给出一个’-‘的提示.  键入

D 重复输入

d一次播放128个字节的文件。   键入

D address 输入

以显示从 address 开始的 128 个字节,必须输入十六进制,其中文件的开头是地址 100.  键入

D address1 address2 输入

以显示从 address1address2。   输入

D address Lnum 输入

显示从 address 开始的 num 字节(长度).  num 也以十六进制输入.  使用 Q 退出。

例如,

C:\Users\scott\Documents> debug thispost.com
-d
0BE4:0100 43 6F 70 79 20 74 68 65-20 66 69 6C 65 20 74 6F Copy the file to
0BE4:0110 20 61 20 6E 61 6D 65 20-77 69 74 68 20 61 20 2E a name with a .
0BE4:0120 43 4F 4D 20 65 78 74 65-6E 73 69 6F 6E 2C 20 77 COM extension, w
0BE4:0130 68 65 72 65 20 74 68 65-20 62 61 73 65 20 6E 61 here the base na
0BE4:0140 6D 65 20 69 73 20 6E 6F-20 6C 6F 6E 67 65 72 20 me is no longer
0BE4:0150 74 68 61 6E 20 65 69 67-68 74 20 63 68 61 72 61 than eight chara
0BE4:0160 63 74 65 72 73 2E 0D 0A-52 75 6E 20 44 45 42 55 cters...Run DEBU
0BE4:0170 47 20 2A 79 6F 75 72 5F-66 69 6C 65 6E 61 6D 65 G *your_filename
-d
0BE4:0180 2A 0D 0A 49 74 20 77 69-6C 6C 20 67 69 76 65 20 *..It will give
0BE4:0190 61 20 27 2D 27 20 70 72-6F 6D 70 74 2E 0D 0A 54 a '-' prompt...T
0BE4:01A0 79 70 65 20 44 20 45 6E-74 65 72 20 72 65 70 65 ype D Enter repe
0BE4:01B0 61 74 65 64 6C 79 20 74-6F 20 2A 2A 64 2A 2A 69 atedly to **d** i
0BE4:01C0 73 70 6C 61 79 20 74 68-65 20 66 69 6C 65 20 31 splay the file 1
0BE4:01D0 32 38 20 62 79 74 65 73-20 61 74 20 61 20 74 69 28 bytes at a ti
0BE4:01E0 6D 65 2E 0D 0A 54 79 70-65 20 44 20 5F 61 64 64 me...Type D _add
0BE4:01F0 72 65 73 73 5F 20 74 6F-20 64 69 73 70 6C 61 79 ress_ to display
-d 200 L16
0BE4:0200 20 31 32 38 20 62 79 74-65 73 20 73 74 61 72 74 128 bytes start
0BE4:0210 69 6E 67 20 61 74 ing at
-
```。
6
6
6
2014-02-12 22:39:12 +0000

HxD 是一个可移植的十六进制编辑器,这意味着无需安装,只是一个单一的 exe 文件。 http://mh-nexus.de/en/hxd/

另一个类似的可移植选项是 Frhed: http://frhed.sourceforge.net/en/screenshots/

5
Advertisement
5
5
2012-08-31 08:52:04 +0000
Advertisement

由于Windows 7内置了dotnet框架3.5,您将内置C#编译器,因此您可以从 http://illegalargumentexception.blogspot.co.uk/2008/04/c-file-hex-dump-application.html 中抓取列表,然后使用

\windows\Microsoft.NET\Framework\v3.5\csc printhex.cs

进行编译,您应该最终得到一个printhex.exe,它应该同时显示十六进制和ascii字符。

2
2
2
2012-08-30 23:04:31 +0000

这并不理想,但如果你真的不想下载任何东西,那么你可以尝试使用 fc /b (即二进制模式下的文件比较)来比较这个文件和另一个完全不同的文件,它将向你显示每个不同字节的十六进制值。你可能会得到一些恰好在两个文件中相同的值,因此可能会从输出中跳过,但你可以通过检查偏移列中的缺失值来判断是否发生这种情况。

2
Advertisement
2
2
2016-06-06 15:42:30 +0000
Advertisement

你可以使用下面的PowerShell函数和Get-Content查看文件内容的16进制转储,即Get-Content -Encoding Byte 'MyFile.bin' | Format-HexDump。转储一个 222 KB 的文件大约需要 23 秒,如果需要的话,输出可以重定向到一个文本文件,以便于检查转储。

$encodingAutoCompleter = {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
    $availableEncodings = ([System.Text.Encoding]::GetEncodings() | Select Name, CodePage, DisplayName) + @( [PSCustomObject] @{ CodePage = '20127'; Name = 'ascii'; DisplayName = 'US-ASCII' }, [PSCustomObject] @{ CodePage = '1200'; Name = 'unicode'; DisplayName = 'Unicode' } )
    $availableEncodings | ?{ $_.Name.StartsWith($wordToComplete) } | %{ New-Object System.Management.Automation.CompletionResult -ArgumentList $_.Name, $_.Name, 'ParameterValue', "$($_.DisplayName). Code Page $($_.CodePage)." }
}

function Format-BufferText([byte[]] $buffer, [System.Text.Encoding] $displayEncoding, [switch] $useControlPictures)
{
    $bufferChars = $displayEncoding.GetChars($buffer);
    $bufferText = (($bufferChars | %{ if ([char]::IsControl($_) -eq $true) { if ($useControlPictures -eq $false) { '.' } else { [char] ($_.ToInt16([cultureinfo]::InvariantCulture) + 0x2400) } } else { "$_" } }) -join "")

    $bufferText
}

<#
    .Synopsis
    Displays binary data as a hexadecimal dump.

    .Description
     Displays binary data as a hexadecimal dump. Options are available to suppress displaying text and to display control characters 
     as Unicode Control Pictures instead of dots.

    .Parameter Bytes
    The bytes to be displayed.

    .Parameter Encoding
    The name of the text encoding to use. The default is ascii.

    .Parameter NoTextDisplay
    If specified the text display sidebar will be suppressed; otherwise, the display text sidebar will be present.

    .Parameter UseControlPictures
    If specified control characters will be displayed as Unicode Control pictures; otherwise, dots are used to represent control 
    characters.

    .Example
    Format-HexDump -Encoding unicode $bytes

    .Example
    Get-Content -Encoding Byte 'MyFile.bin' | Format-HexDump -Encoding unicode

    .Example
    0..255 | Format-HexDump -NoTextDisplay
#>
function Format-HexDump
{
    [CmdletBinding()]
    param
    (
        [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [byte[]] $Bytes,
        [ValidateScript({ if (([System.Text.Encoding]::GetEncodings().Name + @('unicode', 'ascii')) -icontains $_) { return $true } else { Throw "Encoding must be one of the following: $([System.Text.Encoding]::GetEncodings().Name -join ', '), unicode, or ascii." } })]
        [Parameter(ValueFromPipeline = $false)]
        [string] $Encoding = "ASCII",
        [Parameter()]
        [switch] $NoTextDisplay,
        [Parameter()]
        [switch] $UseControlPictures
    )

    BEGIN
    {
        $displayEncoding = [System.Text.Encoding]::GetEncoding($Encoding)

        $counter = 0
        $hexRow = ""
        [byte[]] $buffer = @()
    }

    PROCESS
    {
        foreach ($byte in $Bytes)
        {
            $buffer += $byte
            $hexValue = $byte.ToString("X2")

            if ($counter % 16 -eq 0)
            {
                $buffer = @($byte)
                $hexRow = "$($counter.ToString("X8")): $($hexValue) "
            }
            elseif ($counter % 16 -eq 15)
            {
                if ($NoTextDisplay -eq $true)
                {
                    $hexRow += "$($hexValue)"
                    $hexRow
                }
                else
                {
                    $bufferText = Format-BufferText $buffer $displayEncoding $UseControlPictures
                    $hexRow += "$($hexValue) $($bufferText)"
                    $hexRow
                }
            }
            else
            {
                $hexRow += "$($hexValue) "
            }

            $counter++
        }
    }

    END
    {
        $counter--

        if ($counter % 16 -ne 15)
        {
            $hexRow += " " * (((16 - $counter % 16) * 3) - 1)

            if ($NoTextDisplay -eq $false)
            {
                $bufferText = Format-BufferText $buffer $displayEncoding $UseControlPictures
                $hexRow += "$($bufferText)"
            }

            $hexRow
        }
    }
}

Register-ArgumentCompleter -CommandName Format-HexDump -ParameterName Encoding -ScriptBlock $encodingAutoCompleter

输出看起来像这样。

00000000: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ................
00000010: 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F ................
00000020: 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F !"#$%&'()*+,-./
00000030: 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 0123456789:;<=>?
00000040: 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F @ABCDEFGHIJKLMNO
00000050: 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F PQRSTUVWXYZ[\]^_
00000060: 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F `abcdefghijklmno
00000070: 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F pqrstuvwxyz{|}~.
00000080: 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F ????????????????
00000090: 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F ????????????????
000000A0: A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF ????????????????
000000B0: B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF ????????????????
000000C0: C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF ????????????????
000000D0: D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF ????????????????
000000E0: E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF ????????????????
000000F0: F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF ????????????????
1
1
1
2017-05-04 12:26:00 +0000

由于Sublime text是我最喜欢的编辑器,我使用它的插件来查看十六进制文件。 http://facelessuser.github.io/HexViewer/

0
0
0
2017-08-25 01:07:56 +0000

我知道你用的是Emacs,但 Vim 用户可以使用xxd实用程序:

xxd -s <start_offset> -l <length_offest> <file>

Usage:
       xxd.exe [options] [infile [outfile]]
    or
       xxd.exe -r [-s [-]offset] [-c cols] [-ps] [infile [outfile]]
Options:
    -a toggle autoskip: A single '*' replaces nul-lines. Default off.
    -b binary digit dump (incompatible with -ps,-i,-r). Default hex.
    -c cols format <cols> octets per line. Default 16 (-i: 12, -ps: 30).
    -E show characters in EBCDIC. Default ASCII.
    -g number of octets per group in normal output. Default 2.
    -h print this summary.
    -i output in C include file style.
    -l len stop after <len> octets.
    -ps output in postscript plain hexdump style.
    -r reverse operation: convert (or patch) hexdump into binary.
    -r -s off revert with <off> added to file positions found in hexdump.
    -s [+][-]seek start at <seek> bytes abs. (or +: rel.) infile offset.
    -u use upper case hex letters.
    -v show version: "xxd V1.10 27oct98 by Juergen Weigert (Win32)".
```。
Advertisement

Questões relacionadas

3
28
13
7
8
Advertisement
Advertisement