cscの作法 その245

# 概要
cscの作法、調べてみた。
ファイルをバイナリーダンプしてみた。

# サンプルコード

```
using System;
using System.IO;

namespace app
{
	public static class test0 {
		public static string Dump(ref byte[] binaryData, uint offset, int readLength) {
			System.Text.StringBuilder OutputBuffer = new System.Text.StringBuilder();
			uint dummyStart = offset - (offset % 0x10);
			OutputBuffer.Append("ADDRESS  : ");
			if (binaryData.Length > 0)
			{
				for (int i = 0; i <= 0x0f; i++)
				{
					OutputBuffer.Append(i.ToString("X2"));
					if (i == 0x0f)
					{
						OutputBuffer.Append(System.Environment.NewLine);
					}
					else
					{
						OutputBuffer.Append(" ");
					}
				}
				OutputBuffer.Append("---------:---------------" + "---------------------------------" + Environment.NewLine);
				for (uint k = dummyStart; k < binaryData.Length; k++)
				{
					if (k > readLength + offset)
					{
						OutputBuffer.Append(System.Environment.NewLine);
						break;
					}
					if (k % 0x10 == 0)
					{
						OutputBuffer.Append(k.ToString("X8") + " : ");
					}
					if (k < offset)
					{
						OutputBuffer.Append("  ");
					}
					else
					{
						OutputBuffer.Append(binaryData[k].ToString("X2"));
					}
					if ((k + 0x01) % 0x10 == 0)
					{
						OutputBuffer.Append(System.Environment.NewLine);
					}
					else
					{
						OutputBuffer.Append(" ");
					}
				}
				return OutputBuffer.ToString();
			}
			else
			{
				return "No Data.";
			}
		}
		[STAThread]
		static void Main(string[] args) {
			try
			{
				FileStream fs = new FileStream(args[0], FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
				BinaryReader binReader = new BinaryReader(fs);
				fs.Seek(0x00000000, SeekOrigin.Begin);
				byte[] binData = binReader.ReadBytes((int) fs.Length);
				int n = (int) fs.Length;
				Console.Write(Dump(ref binData, 0x0000000, n));
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
			}
		}
	}
}





```

#実行結果

```
>bd0 test.exe
ADDRESS  : 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
---------:------------------------------------------------
00000000 : 4D 5A 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000010 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000020 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000030 : 00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00
00000040 : 50 45 00 00 64 86 01 00 00 00 00 00 00 00 00 00
00000050 : 00 00 00 00 F0 00 27 00 0B 02 00 00 01 00 00 00
00000060 : 00 00 00 00 00 00 00 00 00 02 00 00 00 02 00 00
00000070 : 00 00 40 00 00 00 00 00 00 01 00 00 00 01 00 00
00000080 : 00 00 00 00 00 00 00 00 05 00 02 00 00 00 00 00
00000090 : 00 06 00 00 00 02 00 00 00 00 00 00 03 00 00 00
000000A0 : 00 00 20 00 00 00 00 00 00 10 00 00 00 00 00 00
000000B0 : 00 00 10 00 00 00 00 00 00 10 00 00 00 00 00 00
000000C0 : 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00
000000D0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000000E0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000000F0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000100 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000110 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000120 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000130 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000140 : 00 00 00 00 00 00 00 00 2E 74 65 78 74 00 00 00
00000150 : 00 01 00 00 00 02 00 00 00 01 00 00 00 02 00 00
00000160 : 00 00 00 00 00 00 00 00 00 00 00 00 20 00 00 60
00000170 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000180 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000190 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000001A0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000001B0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000001C0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000001D0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000001E0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000001F0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000200 : C3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000210 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000220 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000230 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000240 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000250 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000260 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000270 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000280 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000290 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000002A0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000002B0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000002C0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000002D0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000002E0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000002F0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

>





```


以上。