728x90
반응형
using System;
namespace HexaViewer
{
public class HexaView
{
static void PrintLine(char Char, ushort Count)
{
for(int Temp = 0; Temp < Count; ++Temp)
{
Console.Write(Char);
}
Console.WriteLine();
}
static void PrintHead(char Line1, char Line2, ushort Count)
{
PrintLine(Line1, Count);
PrintLine(Line2, Count);
Console.Write(" ADDRESS ");
for (int iCount = 0; iCount < 16; ++iCount)
{
Console.Write("{0:X02} ", iCount);
}
for (int iCount = 0; iCount < 16; ++iCount)
{
Console.Write("{0:X01}", iCount);
}
Console.WriteLine();
PrintLine(Line1, Count);
}
static void PrintHead()
{
PrintHead('=', '-',73);
}
static void PrintEnd()
{
PrintLine('=', 73);
}
public static void HexaViewText(byte[] Data)
{
ArraySegment<byte> TempDataPos;
int iLoopTotal = Data.Length / 16;
int iLoopRemain = Data.Length % 16;
PrintHead();
for (int iLoopCount = 0; iLoopCount < iLoopTotal; iLoopCount = iLoopCount + 1)
{
Console.Write("{0:X08} ", iLoopCount * 16);
TempDataPos = new ArraySegment<byte>(Data, iLoopCount * 16, 16);
foreach (var Temp in TempDataPos)
{
Console.Write("{0:X02} ", Temp);
}
foreach (char Temp in TempDataPos)
{
if (' ' > Temp)
{
Console.Write(".");
}
else if (127 < Temp)
{
Console.Write(".");
}
else
{
Console.Write("{0}", Temp);
}
}
Console.WriteLine();
}
if (0 != iLoopRemain)
{
iLoopTotal = iLoopTotal * 16;
Console.Write("{0:X08} ", iLoopTotal);
TempDataPos = new ArraySegment<byte>(Data, iLoopTotal, iLoopRemain);
foreach (var Temp in TempDataPos)
{
Console.Write("{0:X02} ", Temp);
}
for (int Temp = 0; Temp < 16 - iLoopRemain; ++Temp)
{
Console.Write(" ");
}
foreach (char Temp in TempDataPos)
{
if (' ' > Temp)
{
Console.Write(".");
}
else if (127 < Temp)
{
Console.Write(".");
}
else
{
Console.Write("{0}", Temp);
}
}
for (int Temp = 0; Temp < 16 - iLoopRemain; ++Temp)
{
Console.Write(" ");
}
}
Console.WriteLine();
PrintEnd();
}
}
}
728x90
'기술자료 > C#' 카테고리의 다른 글
C# 소켓 억셉트 Socket Asynchronous Accept 초간단 소스 (0) | 2021.09.15 |
---|---|
C# Console 비동기 입력 ReadLine ReadKey Asynchronous input 초간단 소스 (0) | 2021.09.15 |
C# Packet Capture Programming #4 - 패킷 출력 HexaView (0) | 2021.09.07 |
C# Packet Capture Programming #3 - 패킷 캡쳐 GetNextPacket (0) | 2021.09.07 |
C# Packet Capture Programming #2 - 캡쳐 장치 선정 ICaptureDevice (0) | 2021.09.01 |
C# Packet Capture Programming #1 (0) | 2021.09.01 |
예외처리 1 : try catch 문법 (0) | 2021.06.10 |
포인터 사용 C# Pointer unsafe (0) | 2021.04.29 |