mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-12-26 22:31:22 -08:00
9ac5583513
* Better support for user accounts * Nits * Check for invalid ids
52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace Ryujinx.HLE.OsHle.Utilities
|
|
{
|
|
static class StringUtils
|
|
{
|
|
public static byte[] GetFixedLengthBytes(string InputString, int Size, Encoding Encoding)
|
|
{
|
|
InputString = InputString + "\0";
|
|
|
|
int BytesCount = Encoding.GetByteCount(InputString);
|
|
|
|
byte[] Output = new byte[Size];
|
|
|
|
if (BytesCount < Size)
|
|
{
|
|
Encoding.GetBytes(InputString, 0, InputString.Length, Output, 0);
|
|
}
|
|
else
|
|
{
|
|
int NullSize = Encoding.GetByteCount("\0");
|
|
|
|
Output = Encoding.GetBytes(InputString);
|
|
|
|
Array.Resize(ref Output, Size - NullSize);
|
|
|
|
Output = Output.Concat(Encoding.GetBytes("\0")).ToArray();
|
|
}
|
|
|
|
return Output;
|
|
}
|
|
|
|
public static byte[] HexToBytes(string HexString)
|
|
{
|
|
//Ignore last charactor if HexLength % 2 != 0.
|
|
int BytesInHex = HexString.Length / 2;
|
|
|
|
byte[] Output = new byte[BytesInHex];
|
|
|
|
for (int Index = 0; Index < BytesInHex; Index++)
|
|
{
|
|
Output[Index] = byte.Parse(HexString.Substring(Index * 2, 2), NumberStyles.HexNumber);
|
|
}
|
|
|
|
return Output;
|
|
}
|
|
}
|
|
}
|