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

Windows7でファイルのバイナリ内容をネイティブで見るにはどうしたらいいですか?(可能なのでしょうか?)

Advertisement

500MBより少し大きいファイルを持っていますが、それがいくつかの問題を引き起こしています。

問題は使用されている行末(EOL)の規約にあると思います。ファイルのEOL規約を確認するために、解釈されていない生の状態(1)でファイルを見てみたいと思います。

Windows 7に内蔵されているものを使用して、ファイルの「バイナリ」を表示するにはどうすればいいですか?追加で何かをダウンロードしなくてもいいようにしたいのですが、どうすればいいですか?

(1) 同僚と私はテキストエディタでファイルを開きました。しかし、どちらのテキストエディタも異なる EOL 規約のファイルを開き、自動的に解釈します。(TextEdit と Emacs 24.2。Emacsでは、私はlinuxのボックスでhead -c4096を使って最初の4Kバイトだけの2つ目のファイルを作成し、それをwindowsのボックスから開いていました。

Emacsで16進数モードを使用しようとしましたが、16進数モードにしてからテキストモードに戻したところ、バッファの内容が変更され、各行の末尾に目に見える^Mが追加されていましたので、今のところ信用できません。

問題は、使用されている行末の文字にあるのではないかと思います。同僚と私が試したエディタでは (1) 行末の規則を自動的に認識して行を表示してくれました。そして、他の証拠に基づいて、私はEOLの規約はキャリッジリターンのみであると信じています。(2) return only.

ファイルの中に実際に何が入っているかを知るためには、ファイルのバイナリ内容、または少なくとも数千バイトのファイルを見たいと思います。1と0だけでは、見るにはかなり大雑把になってしまいます。

UPDATE

DEBUGを提案しているものを除いて、以下の回答はすべてある程度は動作します。私はこれらの回答を参考にして、それぞれの回答にアップ投票しました。私の質問は形式が間違っていました。それぞれの提案された解決策をテストする中で、私が本当に欲しいのは16進数とテキストの内容を横に並べて表示することで、カーソルをバイト値かテキスト文字のどちらかに置いたときに、反対側にあるマッチするものがハイライトされるようなものにしたいと思ったからです。

実際に問題が解決したのは、Emacs の hexl モードが「正しく」動作するようになってからでした。(本当にEmacsの奇妙な挙動を調査して、バグレポートを提出すべきです。)

Advertisement
Advertisement

回答 (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 はファイルから読みたいバイト数。

「powershell hexdump」でググれば、より洗練された、より実行可能なバージョンが手に入ります。

Windows Resource Kit Tools (正確には組み込まれていませんが、近いです) があれば、list.exe という cmd line ユーティリティを使うこともできます。これは16進数モードの小さなエディタです。特に大きなファイルを扱うために設計されています。

List Text File Tool (List) は、1 つ以上のテキストファイルを表示・検索するコマンドラインツールです。他のテキスト表示ツールとは異なり、List はファイルを開いたときにファイル全体をメモリに読み込んだりしません。16進数形式のテキストファイルを編集することができます。

Listは、リモートでテキストファイルやログファイルを表示したり、管理者がシステムパフォーマンスの低下を気にするサーバーでの使用に便利です。

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

六角エディタ」が必要です。私は「Hex Editor Neo」を何年も使っていますが、とても良いです。これは 無料版と有料版 で入手できます。(他にも似たようなツールがあると思いますが)

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

これはXP以降のすべてのものでも動作します。

certutil -encodehex MyProgram.exe MyProgram.txt

XP の場合は、ここから Windows Server 2003 Administration Tools Pack を入手する必要があります: 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 address と入力すると、address から始まる 128 バイトを表示するには

を入力します。   Type

- address Dnum addressから始まるnumバイト(長さ)を表示するには

を入力します。

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はポータブルな16進数エディタで、インストールの必要がなく、単一の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 framework 3.5 が組み込まれているので、C# コンパイラが組み込まれています。

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

理想的ではありませんが、もし本当に何もダウンロードしたくないのであれば、 fc /b (バイナリモードでのファイル比較)を使って、このファイルと別の全く別のファイルを比較してみると、異なる各バイトの 16 進数の値を表示してくれます。2つのファイルで同じ値がたまたま得られるかもしれないので、出力からスキップされるかもしれませんが、オフセット列で欠落している値をチェックすることで、それが起こるかどうかを知ることができます。

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

以下の PowerShell 関数を Get-Content と一緒に使用すると、ファイルの内容、つまり Get-Content -Encoding Byte 'MyFile.bin' | Format-HexDump の 16 進ダンプを見ることができます。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は私のお気に入りのエディタなので、16進数ファイルを見るためにそのプラグインを使っています。 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

関連する質問

3
16
28
13
7
Advertisement
Advertisement