LoginSignup
0
1

More than 1 year has passed since last update.

PowerShellにて16進数ダンプ。

Last updated at Posted at 2022-08-15

PowerShellにて16進数ダンプ。
Windows PowerShellについて触れる機会が増えたので、日記的な
16進数ダンプの必要があったので、最初面食らったのは「|」これ、パイプライン。変数は「$」。「-f」はフォーマット演算子【後述】。癖強いな・・・

Get-content.ps1
            $str=$InitialDirectory+'\log.csv'
            #ファイルから〇〇要素ずつ読み込み一連の文字をバイトのシーケンスにエンコードする、パイプの後は改行できる
            #この場合一度に-readcountバイト読み込みそれを-TotalCountバイトになるまで繰り返す指定なしは全て読み込む
            Get-content -path $File -encoding byte -readcount $readcount -TotalCount $totalCount|
            #2桁表示にする。空白なら無しにする。カンマ区切りにする
            foreach-object{
                ('{0:x2}'-f$_).replace(' ',",")
            }|
            #ファイルに追加する
            add-content $str

一般的なHEXダンプならこれで良い。

Format-Hex.ps1
    $hex= Format-Hex -Path $file
    out-file -filepath $hexout -inputobject $hex

PowerShellって独特な文法がネックだと思ったが、慣れると良いな!
後日ファイル指定が面倒になったので【ファイル選択ダイアログについて】 

【replaceについての参考文献】

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1