mirror of
https://github.com/aaru-dps/Aaru.Helpers.git
synced 2025-12-16 19:24:35 +00:00
[Aaru.Helpers] Reformat and cleanup.
This commit is contained in:
2480
.editorconfig
2480
.editorconfig
File diff suppressed because it is too large
Load Diff
@@ -1,2 +1,5 @@
|
|||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:s="clr-namespace:System;assembly=mscorlib"
|
||||||
|
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xml:space="preserve">
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=localization/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=localization/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||||
@@ -35,10 +35,7 @@ public static partial class ArrayHelpers
|
|||||||
/// <param name="destinationArray">Array</param>
|
/// <param name="destinationArray">Array</param>
|
||||||
/// <param name="value">Value</param>
|
/// <param name="value">Value</param>
|
||||||
/// <typeparam name="T">Array type</typeparam>
|
/// <typeparam name="T">Array type</typeparam>
|
||||||
public static void ArrayFill<T>(T[] destinationArray, T value) => ArrayFill(destinationArray, new[]
|
public static void ArrayFill<T>(T[] destinationArray, T value) => ArrayFill(destinationArray, new[] { value });
|
||||||
{
|
|
||||||
value
|
|
||||||
});
|
|
||||||
|
|
||||||
/// <summary>Fills an array with the contents of the specified array</summary>
|
/// <summary>Fills an array with the contents of the specified array</summary>
|
||||||
/// <param name="destinationArray">Array</param>
|
/// <param name="destinationArray">Array</param>
|
||||||
|
|||||||
5
CHS.cs
5
CHS.cs
@@ -43,6 +43,7 @@ public static class CHS
|
|||||||
/// <param name="maxSector">Number of sectors per track</param>
|
/// <param name="maxSector">Number of sectors per track</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector) =>
|
public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector) =>
|
||||||
maxHead == 0 || maxSector == 0 ? (((cyl * 16) + head) * 63) + sector - 1
|
maxHead == 0 || maxSector == 0
|
||||||
: (((cyl * maxHead) + head) * maxSector) + sector - 1;
|
? (cyl * 16 + head) * 63 + sector - 1
|
||||||
|
: (cyl * maxHead + head) * maxSector + sector - 1;
|
||||||
}
|
}
|
||||||
@@ -60,11 +60,13 @@ public static partial class ArrayHelpers
|
|||||||
leastBytes = compareArray1.LongLength;
|
leastBytes = compareArray1.LongLength;
|
||||||
|
|
||||||
for(long i = 0; i < leastBytes; i++)
|
for(long i = 0; i < leastBytes; i++)
|
||||||
|
{
|
||||||
if(compareArray1[i] != compareArray2[i])
|
if(compareArray1[i] != compareArray2[i])
|
||||||
{
|
{
|
||||||
different = true;
|
different = true;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,9 +40,9 @@ public static class CountBits
|
|||||||
/// <returns>Bits set to <c>true</c></returns>
|
/// <returns>Bits set to <c>true</c></returns>
|
||||||
public static int Count(uint number)
|
public static int Count(uint number)
|
||||||
{
|
{
|
||||||
number -= (number >> 1) & 0x55555555;
|
number -= number >> 1 & 0x55555555;
|
||||||
number = (number & 0x33333333) + ((number >> 2) & 0x33333333);
|
number = (number & 0x33333333) + (number >> 2 & 0x33333333);
|
||||||
|
|
||||||
return (int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
|
return (int)((number + (number >> 4) & 0x0F0F0F0F) * 0x01010101 >> 24);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ public static class DateHandlers
|
|||||||
/// <returns>.NET DateTime</returns>
|
/// <returns>.NET DateTime</returns>
|
||||||
public static DateTime HighSierraToDateTime(byte[] vdDateTime)
|
public static DateTime HighSierraToDateTime(byte[] vdDateTime)
|
||||||
{
|
{
|
||||||
byte[] isoTime = new byte[17];
|
var isoTime = new byte[17];
|
||||||
Array.Copy(vdDateTime, 0, isoTime, 0, 16);
|
Array.Copy(vdDateTime, 0, isoTime, 0, 16);
|
||||||
|
|
||||||
return Iso9660ToDateTime(isoTime);
|
return Iso9660ToDateTime(isoTime);
|
||||||
@@ -103,8 +103,8 @@ public static class DateHandlers
|
|||||||
/// <returns>.NET DateTime</returns>
|
/// <returns>.NET DateTime</returns>
|
||||||
public static DateTime Iso9660ToDateTime(byte[] vdDateTime)
|
public static DateTime Iso9660ToDateTime(byte[] vdDateTime)
|
||||||
{
|
{
|
||||||
byte[] twoCharValue = new byte[2];
|
var twoCharValue = new byte[2];
|
||||||
byte[] fourCharValue = new byte[4];
|
var fourCharValue = new byte[4];
|
||||||
|
|
||||||
fourCharValue[0] = vdDateTime[0];
|
fourCharValue[0] = vdDateTime[0];
|
||||||
fourCharValue[1] = vdDateTime[1];
|
fourCharValue[1] = vdDateTime[1];
|
||||||
@@ -175,7 +175,7 @@ public static class DateHandlers
|
|||||||
"decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);",
|
"decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);",
|
||||||
year, month, day, hour, minute, second, hundredths * 10);
|
year, month, day, hour, minute, second, hundredths * 10);
|
||||||
|
|
||||||
sbyte difference = (sbyte)vdDateTime[16];
|
var difference = (sbyte)vdDateTime[16];
|
||||||
|
|
||||||
var decodedDt = new DateTime(year, month, day, hour, minute, second, hundredths * 10, DateTimeKind.Utc);
|
var decodedDt = new DateTime(year, month, day, hour, minute, second, hundredths * 10, DateTimeKind.Utc);
|
||||||
|
|
||||||
@@ -260,9 +260,9 @@ public static class DateHandlers
|
|||||||
/// <returns>.NET DateTime</returns>
|
/// <returns>.NET DateTime</returns>
|
||||||
public static DateTime CpmToDateTime(byte[] timestamp)
|
public static DateTime CpmToDateTime(byte[] timestamp)
|
||||||
{
|
{
|
||||||
ushort days = BitConverter.ToUInt16(timestamp, 0);
|
var days = BitConverter.ToUInt16(timestamp, 0);
|
||||||
int hours = timestamp[2];
|
int hours = timestamp[2];
|
||||||
int minutes = timestamp[3];
|
int minutes = timestamp[3];
|
||||||
|
|
||||||
DateTime temp = _amigaEpoch.AddDays(days);
|
DateTime temp = _amigaEpoch.AddDays(days);
|
||||||
temp = temp.AddHours(hours);
|
temp = temp.AddHours(hours);
|
||||||
@@ -284,18 +284,18 @@ public static class DateHandlers
|
|||||||
/// <param name="microseconds">Microseconds</param>
|
/// <param name="microseconds">Microseconds</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte month, byte day, byte hour,
|
public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte month, byte day, byte hour,
|
||||||
byte minute, byte second, byte centiseconds, byte hundredsOfMicroseconds,
|
byte minute, byte second, byte centiseconds, byte hundredsOfMicroseconds,
|
||||||
byte microseconds)
|
byte microseconds)
|
||||||
{
|
{
|
||||||
byte specification = (byte)((typeAndTimeZone & 0xF000) >> 12);
|
var specification = (byte)((typeAndTimeZone & 0xF000) >> 12);
|
||||||
|
|
||||||
long ticks = ((long)centiseconds * 100000) + ((long)hundredsOfMicroseconds * 1000) + ((long)microseconds * 10);
|
long ticks = (long)centiseconds * 100000 + (long)hundredsOfMicroseconds * 1000 + (long)microseconds * 10;
|
||||||
|
|
||||||
if(specification == 0)
|
if(specification == 0)
|
||||||
return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc).AddTicks(ticks);
|
return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc).AddTicks(ticks);
|
||||||
|
|
||||||
ushort preOffset = (ushort)(typeAndTimeZone & 0xFFF);
|
var preOffset = (ushort)(typeAndTimeZone & 0xFFF);
|
||||||
short offset;
|
short offset;
|
||||||
|
|
||||||
if((preOffset & 0x800) == 0x800)
|
if((preOffset & 0x800) == 0x800)
|
||||||
offset = (short)(preOffset | 0xF000);
|
offset = (short)(preOffset | 0xF000);
|
||||||
@@ -327,15 +327,16 @@ public static class DateHandlers
|
|||||||
public static DateTime Os9ToDateTime(byte[] date)
|
public static DateTime Os9ToDateTime(byte[] date)
|
||||||
{
|
{
|
||||||
if(date == null ||
|
if(date == null ||
|
||||||
(date.Length != 3 && date.Length != 5))
|
date.Length != 3 && date.Length != 5)
|
||||||
return DateTime.MinValue;
|
return DateTime.MinValue;
|
||||||
|
|
||||||
DateTime os9Date;
|
DateTime os9Date;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
os9Date = date.Length == 5 ? new DateTime(1900 + date[0], date[1], date[2], date[3], date[4], 0)
|
os9Date = date.Length == 5
|
||||||
: new DateTime(1900 + date[0], date[1], date[2], 0, 0, 0);
|
? new DateTime(1900 + date[0], date[1], date[2], date[3], date[4], 0)
|
||||||
|
: new DateTime(1900 + date[0], date[1], date[2], 0, 0, 0);
|
||||||
}
|
}
|
||||||
catch(ArgumentOutOfRangeException)
|
catch(ArgumentOutOfRangeException)
|
||||||
{
|
{
|
||||||
@@ -348,7 +349,8 @@ public static class DateHandlers
|
|||||||
/// <summary>Converts a LIF timestamp to .NET DateTime</summary>
|
/// <summary>Converts a LIF timestamp to .NET DateTime</summary>
|
||||||
/// <param name="date">LIF timestamp</param>
|
/// <param name="date">LIF timestamp</param>
|
||||||
/// <returns>.NET DateTime</returns>
|
/// <returns>.NET DateTime</returns>
|
||||||
public static DateTime LifToDateTime(byte[] date) => date is not { Length: 6 } ? new DateTime(1970, 1, 1, 0, 0, 0)
|
public static DateTime LifToDateTime(byte[] date) => date is not { Length: 6 }
|
||||||
|
? new DateTime(1970, 1, 1, 0, 0, 0)
|
||||||
: LifToDateTime(date[0], date[1], date[2], date[3],
|
: LifToDateTime(date[0], date[1], date[2], date[3],
|
||||||
date[4], date[5]);
|
date[4], date[5]);
|
||||||
|
|
||||||
@@ -364,12 +366,12 @@ public static class DateHandlers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int iyear = ((year >> 4) * 10) + (year & 0xF);
|
int iyear = (year >> 4) * 10 + (year & 0xF);
|
||||||
int imonth = ((month >> 4) * 10) + (month & 0xF);
|
int imonth = (month >> 4) * 10 + (month & 0xF);
|
||||||
int iday = ((day >> 4) * 10) + (day & 0xF);
|
int iday = (day >> 4) * 10 + (day & 0xF);
|
||||||
int iminute = ((minute >> 4) * 10) + (minute & 0xF);
|
int iminute = (minute >> 4) * 10 + (minute & 0xF);
|
||||||
int ihour = ((hour >> 4) * 10) + (hour & 0xF);
|
int ihour = (hour >> 4) * 10 + (hour & 0xF);
|
||||||
int isecond = ((second >> 4) * 10) + (second & 0xF);
|
int isecond = (second >> 4) * 10 + (second & 0xF);
|
||||||
|
|
||||||
if(iyear >= 70)
|
if(iyear >= 70)
|
||||||
iyear += 1900;
|
iyear += 1900;
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public static class Extensions
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public static int EnsureRead(this Stream s, byte[] buffer, int offset, int count)
|
public static int EnsureRead(this Stream s, byte[] buffer, int offset, int count)
|
||||||
{
|
{
|
||||||
int pos = 0;
|
var pos = 0;
|
||||||
int read;
|
int read;
|
||||||
|
|
||||||
do
|
do
|
||||||
|
|||||||
44
Localization/Localization.Designer.cs
generated
44
Localization/Localization.Designer.cs
generated
@@ -11,32 +11,46 @@ namespace Aaru.Helpers {
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
|
||||||
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
/// <summary>
|
||||||
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||||
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
/// </summary>
|
||||||
|
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||||
|
// class via a tool like ResGen or Visual Studio.
|
||||||
|
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||||
|
// with the /str option, or rebuild your VS project.
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
internal class Localization {
|
internal class Localization {
|
||||||
|
|
||||||
private static System.Resources.ResourceManager resourceMan;
|
private static global::System.Resources.ResourceManager resourceMan;
|
||||||
|
|
||||||
private static System.Globalization.CultureInfo resourceCulture;
|
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||||
internal Localization() {
|
internal Localization() {
|
||||||
}
|
}
|
||||||
|
|
||||||
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
|
/// <summary>
|
||||||
internal static System.Resources.ResourceManager ResourceManager {
|
/// Returns the cached ResourceManager instance used by this class.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||||
get {
|
get {
|
||||||
if (object.Equals(null, resourceMan)) {
|
if (object.ReferenceEquals(resourceMan, null)) {
|
||||||
System.Resources.ResourceManager temp = new System.Resources.ResourceManager("Aaru.Helpers.Localization.Localization", typeof(Localization).Assembly);
|
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Aaru.Helpers.Localization.Localization", typeof(Localization).Assembly);
|
||||||
resourceMan = temp;
|
resourceMan = temp;
|
||||||
}
|
}
|
||||||
return resourceMan;
|
return resourceMan;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
|
/// <summary>
|
||||||
internal static System.Globalization.CultureInfo Culture {
|
/// Overrides the current thread's CurrentUICulture property for all
|
||||||
|
/// resource lookups using this strongly typed resource class.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Globalization.CultureInfo Culture {
|
||||||
get {
|
get {
|
||||||
return resourceCulture;
|
return resourceCulture;
|
||||||
}
|
}
|
||||||
@@ -45,12 +59,18 @@ namespace Aaru.Helpers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Length of value array must not be more than length of destination.
|
||||||
|
/// </summary>
|
||||||
internal static string Length_of_value_array_must_not_be_more_than_length_of_destination {
|
internal static string Length_of_value_array_must_not_be_more_than_length_of_destination {
|
||||||
get {
|
get {
|
||||||
return ResourceManager.GetString("Length_of_value_array_must_not_be_more_than_length_of_destination", resourceCulture);
|
return ResourceManager.GetString("Length_of_value_array_must_not_be_more_than_length_of_destination", resourceCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Offset.
|
||||||
|
/// </summary>
|
||||||
internal static string Offset {
|
internal static string Offset {
|
||||||
get {
|
get {
|
||||||
return ResourceManager.GetString("Offset", resourceCulture);
|
return ResourceManager.GetString("Offset", resourceCulture);
|
||||||
|
|||||||
@@ -1,21 +1,25 @@
|
|||||||
<root>
|
<root>
|
||||||
<!-- ReSharper disable MarkupTextTypo -->
|
<!-- ReSharper disable MarkupTextTypo -->
|
||||||
<resheader name="resmimetype">
|
<resheader name="resmimetype">
|
||||||
<value>text/microsoft-resx</value>
|
<value>text/microsoft-resx</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<resheader name="version">
|
<resheader name="version">
|
||||||
<value>1.3</value>
|
<value>1.3</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<resheader name="reader">
|
<resheader name="reader">
|
||||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
|
||||||
</resheader>
|
PublicKeyToken=b77a5c561934e089
|
||||||
<resheader name="writer">
|
</value>
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
</resheader>
|
||||||
</resheader>
|
<resheader name="writer">
|
||||||
<data name="Offset" xml:space="preserve">
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
|
||||||
|
PublicKeyToken=b77a5c561934e089
|
||||||
|
</value>
|
||||||
|
</resheader>
|
||||||
|
<data name="Offset" xml:space="preserve">
|
||||||
<value>Compensación</value>
|
<value>Compensación</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Length_of_value_array_must_not_be_more_than_length_of_destination" xml:space="preserve">
|
<data name="Length_of_value_array_must_not_be_more_than_length_of_destination" xml:space="preserve">
|
||||||
<value>La longitud de una colección no puede ser mayor que la longitud del destino</value>
|
<value>La longitud de una colección no puede ser mayor que la longitud del destino</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -1,30 +1,32 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
|
||||||
<root>
|
<root>
|
||||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root"
|
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||||
xmlns="">
|
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
|
||||||
<xsd:element name="root" msdata:IsDataSet="true"></xsd:element>
|
id="root"
|
||||||
</xsd:schema>
|
xmlns="">
|
||||||
<resheader name="resmimetype">
|
<xsd:element name="root" msdata:IsDataSet="true"></xsd:element>
|
||||||
<value>text/microsoft-resx</value>
|
</xsd:schema>
|
||||||
</resheader>
|
<resheader name="resmimetype">
|
||||||
<resheader name="version">
|
<value>text/microsoft-resx</value>
|
||||||
<value>1.3</value>
|
</resheader>
|
||||||
</resheader>
|
<resheader name="version">
|
||||||
<resheader name="reader">
|
<value>1.3</value>
|
||||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
|
</resheader>
|
||||||
PublicKeyToken=b77a5c561934e089
|
<resheader name="reader">
|
||||||
</value>
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
|
||||||
</resheader>
|
PublicKeyToken=b77a5c561934e089
|
||||||
<resheader name="writer">
|
</value>
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
|
</resheader>
|
||||||
PublicKeyToken=b77a5c561934e089
|
<resheader name="writer">
|
||||||
</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
|
||||||
</resheader>
|
PublicKeyToken=b77a5c561934e089
|
||||||
<data name="Length_of_value_array_must_not_be_more_than_length_of_destination" xml:space="preserve">
|
</value>
|
||||||
|
</resheader>
|
||||||
|
<data name="Length_of_value_array_must_not_be_more_than_length_of_destination" xml:space="preserve">
|
||||||
<value>Length of value array must not be more than length of destination</value>
|
<value>Length of value array must not be more than length of destination</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Offset" xml:space="preserve">
|
<data name="Offset" xml:space="preserve">
|
||||||
<value>Offset</value>
|
<value>Offset</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
</root>
|
||||||
133
Marshal.cs
133
Marshal.cs
@@ -250,91 +250,93 @@ public static class Marshal
|
|||||||
return ByteArrayToStructureLittleEndian<T>(bytes);
|
return ByteArrayToStructureLittleEndian<T>(bytes);
|
||||||
|
|
||||||
return properties.Endian switch
|
return properties.Endian switch
|
||||||
{
|
{
|
||||||
BitEndian.Little => properties.HasReferences ? ByteArrayToStructureLittleEndian<T>(bytes)
|
BitEndian.Little => properties.HasReferences
|
||||||
: SpanToStructureLittleEndian<T>(bytes),
|
? ByteArrayToStructureLittleEndian<T>(bytes)
|
||||||
BitEndian.Big => properties.HasReferences ? ByteArrayToStructureBigEndian<T>(bytes)
|
: SpanToStructureLittleEndian<T>(bytes),
|
||||||
: SpanToStructureBigEndian<T>(bytes),
|
BitEndian.Big => properties.HasReferences
|
||||||
BitEndian.Pdp => properties.HasReferences ? ByteArrayToStructurePdpEndian<T>(bytes)
|
? ByteArrayToStructureBigEndian<T>(bytes)
|
||||||
: SpanToStructurePdpEndian<T>(bytes),
|
: SpanToStructureBigEndian<T>(bytes),
|
||||||
_ => throw new ArgumentOutOfRangeException()
|
BitEndian.Pdp => properties.HasReferences
|
||||||
};
|
? ByteArrayToStructurePdpEndian<T>(bytes)
|
||||||
|
: SpanToStructurePdpEndian<T>(bytes),
|
||||||
|
_ => throw new ArgumentOutOfRangeException()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Swaps all members of a structure</summary>
|
/// <summary>Swaps all members of a structure</summary>
|
||||||
/// <param name="str"></param>
|
/// <param name="str"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining), SuppressMessage("ReSharper", "InconsistentNaming")]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||||
public static object SwapStructureMembersEndian(object str)
|
public static object SwapStructureMembersEndian(object str)
|
||||||
{
|
{
|
||||||
Type t = str.GetType();
|
Type t = str.GetType();
|
||||||
FieldInfo[] fieldInfo = t.GetFields();
|
FieldInfo[] fieldInfo = t.GetFields();
|
||||||
|
|
||||||
foreach(FieldInfo fi in fieldInfo)
|
foreach(FieldInfo fi in fieldInfo)
|
||||||
|
{
|
||||||
if(fi.FieldType == typeof(short) ||
|
if(fi.FieldType == typeof(short) ||
|
||||||
(fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(short)))
|
fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(short))
|
||||||
{
|
{
|
||||||
short x = (short)(fi.GetValue(str) ?? default(short));
|
var x = (short)(fi.GetValue(str) ?? default(short));
|
||||||
fi.SetValue(str, (short)((x << 8) | ((x >> 8) & 0xFF)));
|
fi.SetValue(str, (short)(x << 8 | x >> 8 & 0xFF));
|
||||||
}
|
}
|
||||||
else if(fi.FieldType == typeof(int) ||
|
else if(fi.FieldType == typeof(int) ||
|
||||||
(fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int)))
|
fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int))
|
||||||
{
|
{
|
||||||
int x = (int)(fi.GetValue(str) ?? default(int));
|
var x = (int)(fi.GetValue(str) ?? default(int));
|
||||||
x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF));
|
x = (int)(x << 8 & 0xFF00FF00 | (uint)x >> 8 & 0xFF00FF);
|
||||||
fi.SetValue(str, (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF)));
|
fi.SetValue(str, (int)((uint)x << 16 | (uint)x >> 16 & 0xFFFF));
|
||||||
}
|
}
|
||||||
else if(fi.FieldType == typeof(long) ||
|
else if(fi.FieldType == typeof(long) ||
|
||||||
(fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(long)))
|
fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(long))
|
||||||
{
|
{
|
||||||
long x = (long)(fi.GetValue(str) ?? default(long));
|
var x = (long)(fi.GetValue(str) ?? default(long));
|
||||||
x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32);
|
x = (x & 0x00000000FFFFFFFF) << 32 | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32);
|
||||||
x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16);
|
x = (x & 0x0000FFFF0000FFFF) << 16 | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16);
|
||||||
x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8);
|
x = (x & 0x00FF00FF00FF00FF) << 8 | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8);
|
||||||
|
|
||||||
fi.SetValue(str, x);
|
fi.SetValue(str, x);
|
||||||
}
|
}
|
||||||
else if(fi.FieldType == typeof(ushort) ||
|
else if(fi.FieldType == typeof(ushort) ||
|
||||||
(fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ushort)))
|
fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ushort))
|
||||||
{
|
{
|
||||||
ushort x = (ushort)(fi.GetValue(str) ?? default(ushort));
|
var x = (ushort)(fi.GetValue(str) ?? default(ushort));
|
||||||
fi.SetValue(str, (ushort)((x << 8) | (x >> 8)));
|
fi.SetValue(str, (ushort)(x << 8 | x >> 8));
|
||||||
}
|
}
|
||||||
else if(fi.FieldType == typeof(uint) ||
|
else if(fi.FieldType == typeof(uint) ||
|
||||||
(fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint)))
|
fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint))
|
||||||
{
|
{
|
||||||
uint x = (uint)(fi.GetValue(str) ?? default(uint));
|
var x = (uint)(fi.GetValue(str) ?? default(uint));
|
||||||
x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF);
|
x = x << 8 & 0xFF00FF00 | x >> 8 & 0xFF00FF;
|
||||||
fi.SetValue(str, (x << 16) | (x >> 16));
|
fi.SetValue(str, x << 16 | x >> 16);
|
||||||
}
|
}
|
||||||
else if(fi.FieldType == typeof(ulong) ||
|
else if(fi.FieldType == typeof(ulong) ||
|
||||||
(fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ulong)))
|
fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ulong))
|
||||||
{
|
{
|
||||||
ulong x = (ulong)(fi.GetValue(str) ?? default(ulong));
|
var x = (ulong)(fi.GetValue(str) ?? default(ulong));
|
||||||
x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32);
|
x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32;
|
||||||
x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16);
|
x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16;
|
||||||
x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8);
|
x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8;
|
||||||
fi.SetValue(str, x);
|
fi.SetValue(str, x);
|
||||||
}
|
}
|
||||||
else if(fi.FieldType == typeof(float))
|
else if(fi.FieldType == typeof(float))
|
||||||
{
|
{
|
||||||
float flt = (float)(fi.GetValue(str) ?? default(float));
|
var flt = (float)(fi.GetValue(str) ?? default(float));
|
||||||
byte[] flt_b = BitConverter.GetBytes(flt);
|
byte[] flt_b = BitConverter.GetBytes(flt);
|
||||||
|
|
||||||
fi.SetValue(str, BitConverter.ToSingle(new[]
|
fi.SetValue(str, BitConverter.ToSingle(new[] { flt_b[3], flt_b[2], flt_b[1], flt_b[0] }, 0));
|
||||||
{
|
|
||||||
flt_b[3], flt_b[2], flt_b[1], flt_b[0]
|
|
||||||
}, 0));
|
|
||||||
}
|
}
|
||||||
else if(fi.FieldType == typeof(double))
|
else if(fi.FieldType == typeof(double))
|
||||||
{
|
{
|
||||||
double dbl = (double)(fi.GetValue(str) ?? default(double));
|
var dbl = (double)(fi.GetValue(str) ?? default(double));
|
||||||
byte[] dbl_b = BitConverter.GetBytes(dbl);
|
byte[] dbl_b = BitConverter.GetBytes(dbl);
|
||||||
|
|
||||||
fi.SetValue(str, BitConverter.ToDouble(new[]
|
fi.SetValue(
|
||||||
{
|
str,
|
||||||
dbl_b[7], dbl_b[6], dbl_b[5], dbl_b[4], dbl_b[3], dbl_b[2], dbl_b[1], dbl_b[0]
|
BitConverter.ToDouble(
|
||||||
}, 0));
|
new[] { dbl_b[7], dbl_b[6], dbl_b[5], dbl_b[4], dbl_b[3], dbl_b[2], dbl_b[1], dbl_b[0] }, 0));
|
||||||
}
|
}
|
||||||
else if(fi.FieldType == typeof(byte) ||
|
else if(fi.FieldType == typeof(byte) ||
|
||||||
fi.FieldType == typeof(sbyte))
|
fi.FieldType == typeof(sbyte))
|
||||||
@@ -354,6 +356,7 @@ public static class Marshal
|
|||||||
object strc = SwapStructureMembersEndian(obj);
|
object strc = SwapStructureMembersEndian(obj);
|
||||||
fi.SetValue(str, strc);
|
fi.SetValue(str, strc);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@@ -368,6 +371,7 @@ public static class Marshal
|
|||||||
FieldInfo[] fieldInfo = t.GetFields();
|
FieldInfo[] fieldInfo = t.GetFields();
|
||||||
|
|
||||||
foreach(FieldInfo fi in fieldInfo)
|
foreach(FieldInfo fi in fieldInfo)
|
||||||
|
{
|
||||||
if(fi.FieldType == typeof(short) ||
|
if(fi.FieldType == typeof(short) ||
|
||||||
fi.FieldType == typeof(long) ||
|
fi.FieldType == typeof(long) ||
|
||||||
fi.FieldType == typeof(ushort) ||
|
fi.FieldType == typeof(ushort) ||
|
||||||
@@ -381,16 +385,16 @@ public static class Marshal
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
else if(fi.FieldType == typeof(int) ||
|
else if(fi.FieldType == typeof(int) ||
|
||||||
(fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int)))
|
fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int))
|
||||||
{
|
{
|
||||||
int x = (int)(fi.GetValue(str) ?? default(int));
|
var x = (int)(fi.GetValue(str) ?? default(int));
|
||||||
fi.SetValue(str, ((x & 0xffffu) << 16) | ((x & 0xffff0000u) >> 16));
|
fi.SetValue(str, (x & 0xffffu) << 16 | (x & 0xffff0000u) >> 16);
|
||||||
}
|
}
|
||||||
else if(fi.FieldType == typeof(uint) ||
|
else if(fi.FieldType == typeof(uint) ||
|
||||||
(fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint)))
|
fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint))
|
||||||
{
|
{
|
||||||
uint x = (uint)(fi.GetValue(str) ?? default(uint));
|
var x = (uint)(fi.GetValue(str) ?? default(uint));
|
||||||
fi.SetValue(str, ((x & 0xffffu) << 16) | ((x & 0xffff0000u) >> 16));
|
fi.SetValue(str, (x & 0xffffu) << 16 | (x & 0xffff0000u) >> 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Swap arrays
|
// TODO: Swap arrays
|
||||||
@@ -401,6 +405,7 @@ public static class Marshal
|
|||||||
object strc = SwapStructureMembersEndianPdp(obj);
|
object strc = SwapStructureMembersEndianPdp(obj);
|
||||||
fi.SetValue(str, strc);
|
fi.SetValue(str, strc);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@@ -412,8 +417,8 @@ public static class Marshal
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static byte[] StructureToByteArrayLittleEndian<T>(T str) where T : struct
|
public static byte[] StructureToByteArrayLittleEndian<T>(T str) where T : struct
|
||||||
{
|
{
|
||||||
byte[] buf = new byte[SizeOf<T>()];
|
var buf = new byte[SizeOf<T>()];
|
||||||
var ptr = GCHandle.Alloc(buf, GCHandleType.Pinned);
|
var ptr = GCHandle.Alloc(buf, GCHandleType.Pinned);
|
||||||
System.Runtime.InteropServices.Marshal.StructureToPtr(str, ptr.AddrOfPinnedObject(), false);
|
System.Runtime.InteropServices.Marshal.StructureToPtr(str, ptr.AddrOfPinnedObject(), false);
|
||||||
ptr.Free();
|
ptr.Free();
|
||||||
|
|
||||||
@@ -439,14 +444,14 @@ public static class Marshal
|
|||||||
if(hex is null or "")
|
if(hex is null or "")
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int off = 0;
|
var off = 0;
|
||||||
|
|
||||||
if(hex[0] == '0' &&
|
if(hex[0] == '0' &&
|
||||||
(hex[1] == 'x' || hex[1] == 'X'))
|
(hex[1] == 'x' || hex[1] == 'X'))
|
||||||
off = 2;
|
off = 2;
|
||||||
|
|
||||||
outBuf = new byte[(hex.Length - off) / 2];
|
outBuf = new byte[(hex.Length - off) / 2];
|
||||||
int count = 0;
|
var count = 0;
|
||||||
|
|
||||||
for(int i = off; i < hex.Length; i += 2)
|
for(int i = off; i < hex.Length; i += 2)
|
||||||
{
|
{
|
||||||
@@ -456,11 +461,11 @@ public static class Marshal
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
c -= c switch
|
c -= c switch
|
||||||
{
|
{
|
||||||
>= 'a' and <= 'f' => '\u0057',
|
>= 'a' and <= 'f' => '\u0057',
|
||||||
>= 'A' and <= 'F' => '\u0037',
|
>= 'A' and <= 'F' => '\u0037',
|
||||||
_ => '\u0030'
|
_ => '\u0030'
|
||||||
};
|
};
|
||||||
|
|
||||||
outBuf[(i - off) / 2] = (byte)(c << 4);
|
outBuf[(i - off) / 2] = (byte)(c << 4);
|
||||||
|
|
||||||
@@ -470,11 +475,11 @@ public static class Marshal
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
c -= c switch
|
c -= c switch
|
||||||
{
|
{
|
||||||
>= 'a' and <= 'f' => '\u0057',
|
>= 'a' and <= 'f' => '\u0057',
|
||||||
>= 'A' and <= 'F' => '\u0037',
|
>= 'A' and <= 'F' => '\u0037',
|
||||||
_ => '\u0030'
|
_ => '\u0030'
|
||||||
};
|
};
|
||||||
|
|
||||||
outBuf[(i - off) / 2] += (byte)c;
|
outBuf[(i - off) / 2] += (byte)c;
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ public sealed class MarshallingPropertiesAttribute : Attribute
|
|||||||
|
|
||||||
/// <summary>c</summary>
|
/// <summary>c</summary>
|
||||||
public BitEndian Endian { get; }
|
public BitEndian Endian { get; }
|
||||||
|
|
||||||
/// <summary>Tells if the structure, or any nested structure, has any non-value type (e.g. arrays, strings, etc).</summary>
|
/// <summary>Tells if the structure, or any nested structure, has any non-value type (e.g. arrays, strings, etc).</summary>
|
||||||
public bool HasReferences { get; set; }
|
public bool HasReferences { get; set; }
|
||||||
}
|
}
|
||||||
14
PrintHex.cs
14
PrintHex.cs
@@ -86,7 +86,7 @@ public static class PrintHex
|
|||||||
sb.Append(str);
|
sb.Append(str);
|
||||||
sb.Append(" ");
|
sb.Append(" ");
|
||||||
|
|
||||||
for(int i = 0; i < width; i++)
|
for(var i = 0; i < width; i++)
|
||||||
sb.AppendFormat(" {0:X2}", i);
|
sb.AppendFormat(" {0:X2}", i);
|
||||||
|
|
||||||
if(color)
|
if(color)
|
||||||
@@ -94,11 +94,11 @@ public static class PrintHex
|
|||||||
|
|
||||||
sb.AppendLine();
|
sb.AppendLine();
|
||||||
|
|
||||||
int b = 0;
|
var b = 0;
|
||||||
|
|
||||||
string format = $"{{0:X{offsetLength}}}";
|
var format = $"{{0:X{offsetLength}}}";
|
||||||
|
|
||||||
for(int i = 0; i < rows; i++)
|
for(var i = 0; i < rows; i++)
|
||||||
{
|
{
|
||||||
if(color)
|
if(color)
|
||||||
sb.Append("\u001b[36m");
|
sb.Append("\u001b[36m");
|
||||||
@@ -112,19 +112,19 @@ public static class PrintHex
|
|||||||
int lastBytes = i == rows - 1 ? last : width;
|
int lastBytes = i == rows - 1 ? last : width;
|
||||||
int lastSpaces = width - lastBytes;
|
int lastSpaces = width - lastBytes;
|
||||||
|
|
||||||
for(int j = 0; j < lastBytes; j++)
|
for(var j = 0; j < lastBytes; j++)
|
||||||
{
|
{
|
||||||
sb.AppendFormat(" {0:X2}", array[b]);
|
sb.AppendFormat(" {0:X2}", array[b]);
|
||||||
b++;
|
b++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int j = 0; j < lastSpaces; j++)
|
for(var j = 0; j < lastSpaces; j++)
|
||||||
sb.Append(" ");
|
sb.Append(" ");
|
||||||
|
|
||||||
b -= lastBytes;
|
b -= lastBytes;
|
||||||
sb.Append(" ");
|
sb.Append(" ");
|
||||||
|
|
||||||
for(int j = 0; j < lastBytes; j++)
|
for(var j = 0; j < lastBytes; j++)
|
||||||
{
|
{
|
||||||
int v = array[b];
|
int v = array[b];
|
||||||
sb.Append(v is > 31 and < 127 or > 159 ? (char)v : '.');
|
sb.Append(v is > 31 and < 127 or > 159 ? (char)v : '.');
|
||||||
|
|||||||
@@ -54,11 +54,12 @@ public static class StringHandlers
|
|||||||
if(cString == null)
|
if(cString == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
int len = 0;
|
var len = 0;
|
||||||
|
|
||||||
for(int i = start; i < cString.Length; i++)
|
for(int i = start; i < cString.Length; i++)
|
||||||
{
|
{
|
||||||
if(cString[i] == 0)
|
if(cString[i] == 0)
|
||||||
|
{
|
||||||
if(twoBytes)
|
if(twoBytes)
|
||||||
{
|
{
|
||||||
if(i + 1 < cString.Length &&
|
if(i + 1 < cString.Length &&
|
||||||
@@ -71,6 +72,7 @@ public static class StringHandlers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
@@ -78,7 +80,7 @@ public static class StringHandlers
|
|||||||
if(twoBytes && len % 2 > 0)
|
if(twoBytes && len % 2 > 0)
|
||||||
len--;
|
len--;
|
||||||
|
|
||||||
byte[] dest = new byte[len];
|
var dest = new byte[len];
|
||||||
Array.Copy(cString, start, dest, 0, len);
|
Array.Copy(cString, start, dest, 0, len);
|
||||||
|
|
||||||
return len == 0 ? "" : encoding.GetString(dest);
|
return len == 0 ? "" : encoding.GetString(dest);
|
||||||
@@ -100,7 +102,7 @@ public static class StringHandlers
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
byte length = pascalString[start];
|
byte length = pascalString[start];
|
||||||
int len = 0;
|
var len = 0;
|
||||||
|
|
||||||
for(int i = start + 1; i < length + 1 && i < pascalString.Length; i++)
|
for(int i = start + 1; i < length + 1 && i < pascalString.Length; i++)
|
||||||
{
|
{
|
||||||
@@ -110,7 +112,7 @@ public static class StringHandlers
|
|||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] dest = new byte[len];
|
var dest = new byte[len];
|
||||||
Array.Copy(pascalString, start + 1, dest, 0, len);
|
Array.Copy(pascalString, start + 1, dest, 0, len);
|
||||||
|
|
||||||
return len == 0 ? "" : encoding.GetString(dest);
|
return len == 0 ? "" : encoding.GetString(dest);
|
||||||
@@ -155,14 +157,14 @@ public static class StringHandlers
|
|||||||
/// <param name="dstring">OSTA compressed unicode byte array.</param>
|
/// <param name="dstring">OSTA compressed unicode byte array.</param>
|
||||||
public static string DecompressUnicode(byte[] dstring)
|
public static string DecompressUnicode(byte[] dstring)
|
||||||
{
|
{
|
||||||
byte compId = dstring[0];
|
byte compId = dstring[0];
|
||||||
string temp = "";
|
var temp = "";
|
||||||
|
|
||||||
if(compId != 8 &&
|
if(compId != 8 &&
|
||||||
compId != 16)
|
compId != 16)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
for(int byteIndex = 1; byteIndex < dstring.Length;)
|
for(var byteIndex = 1; byteIndex < dstring.Length;)
|
||||||
{
|
{
|
||||||
ushort unicode;
|
ushort unicode;
|
||||||
|
|
||||||
|
|||||||
28
Swapping.cs
28
Swapping.cs
@@ -41,25 +41,25 @@ public static class Swapping
|
|||||||
/// <param name="x">Little endian unsigned integer</param>
|
/// <param name="x">Little endian unsigned integer</param>
|
||||||
/// <returns>PDP unsigned integer</returns>
|
/// <returns>PDP unsigned integer</returns>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static uint PDPFromLittleEndian(uint x) => ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16);
|
public static uint PDPFromLittleEndian(uint x) => (x & 0xffff) << 16 | (x & 0xffff0000) >> 16;
|
||||||
|
|
||||||
/// <summary>Gets the PDP endian equivalent of the given big endian unsigned integer</summary>
|
/// <summary>Gets the PDP endian equivalent of the given big endian unsigned integer</summary>
|
||||||
/// <param name="x">Big endian unsigned integer</param>
|
/// <param name="x">Big endian unsigned integer</param>
|
||||||
/// <returns>PDP unsigned integer</returns>
|
/// <returns>PDP unsigned integer</returns>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static uint PDPFromBigEndian(uint x) => ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8);
|
public static uint PDPFromBigEndian(uint x) => (x & 0xff00ff) << 8 | (x & 0xff00ff00) >> 8;
|
||||||
|
|
||||||
/// <summary>Swaps the endian of the specified unsigned short integer</summary>
|
/// <summary>Swaps the endian of the specified unsigned short integer</summary>
|
||||||
/// <param name="x">Unsigned short integer</param>
|
/// <param name="x">Unsigned short integer</param>
|
||||||
/// <returns>Swapped unsigned short integer</returns>
|
/// <returns>Swapped unsigned short integer</returns>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static ushort Swap(ushort x) => (ushort)((x << 8) | (x >> 8));
|
public static ushort Swap(ushort x) => (ushort)(x << 8 | x >> 8);
|
||||||
|
|
||||||
/// <summary>Swaps the endian of the specified signed short integer</summary>
|
/// <summary>Swaps the endian of the specified signed short integer</summary>
|
||||||
/// <param name="x">Signed short integer</param>
|
/// <param name="x">Signed short integer</param>
|
||||||
/// <returns>Swapped signed short integer</returns>
|
/// <returns>Swapped signed short integer</returns>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static short Swap(short x) => (short)((x << 8) | ((x >> 8) & 0xFF));
|
public static short Swap(short x) => (short)(x << 8 | x >> 8 & 0xFF);
|
||||||
|
|
||||||
/// <summary>Swaps the endian of the specified unsigned integer</summary>
|
/// <summary>Swaps the endian of the specified unsigned integer</summary>
|
||||||
/// <param name="x">Unsigned integer</param>
|
/// <param name="x">Unsigned integer</param>
|
||||||
@@ -67,9 +67,9 @@ public static class Swapping
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static uint Swap(uint x)
|
public static uint Swap(uint x)
|
||||||
{
|
{
|
||||||
x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF);
|
x = x << 8 & 0xFF00FF00 | x >> 8 & 0xFF00FF;
|
||||||
|
|
||||||
return (x << 16) | (x >> 16);
|
return x << 16 | x >> 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Swaps the endian of the specified signed integer</summary>
|
/// <summary>Swaps the endian of the specified signed integer</summary>
|
||||||
@@ -78,9 +78,9 @@ public static class Swapping
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static int Swap(int x)
|
public static int Swap(int x)
|
||||||
{
|
{
|
||||||
x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF));
|
x = (int)(x << 8 & 0xFF00FF00 | (uint)x >> 8 & 0xFF00FF);
|
||||||
|
|
||||||
return (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF));
|
return (int)((uint)x << 16 | (uint)x >> 16 & 0xFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Swaps the endian of the specified unsigned long integer</summary>
|
/// <summary>Swaps the endian of the specified unsigned long integer</summary>
|
||||||
@@ -89,9 +89,9 @@ public static class Swapping
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static ulong Swap(ulong x)
|
public static ulong Swap(ulong x)
|
||||||
{
|
{
|
||||||
x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32);
|
x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32;
|
||||||
x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16);
|
x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16;
|
||||||
x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8);
|
x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
@@ -102,9 +102,9 @@ public static class Swapping
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static long Swap(long x)
|
public static long Swap(long x)
|
||||||
{
|
{
|
||||||
x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32);
|
x = (x & 0x00000000FFFFFFFF) << 32 | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32);
|
||||||
x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16);
|
x = (x & 0x0000FFFF0000FFFF) << 16 | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16);
|
||||||
x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8);
|
x = (x & 0x00FF00FF00FF00FF) << 8 | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8);
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user