This repository has been archived by the owner on Dec 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes, added unit tests, all working well now
Minor API change, but we're keeping our version in sync with the target native version so #yolo. Fixes #1 Fixes #2 Converted all WinDivert tests to individual unit tests, all passing now. Added additional tests to make sure checksum calculation matched the calculation of an external library (not ideal not coding it ourselves, but if two libs can agree then that's OK for me).
- Loading branch information
1 parent
290ea07
commit 846a09a
Showing
19 changed files
with
2,298 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,19 @@ | ||
/* | ||
* Copyright © 2018-Present Jesse Nicholson | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
using System.Runtime.CompilerServices; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace WinDivertSharp.Extensions | ||
{ | ||
/// <summary> | ||
/// Some handy-dandy extensions for integral types. | ||
/// </summary> | ||
public static class IntegralTypeExtensions | ||
internal static class IntegralTypeExtensions | ||
{ | ||
/// <summary> | ||
/// Swaps the endianness of the short. | ||
/// </summary> | ||
/// <param name="val"> | ||
/// The current value. | ||
/// </param> | ||
/// <returns> | ||
/// The short value in reverse-order from its current state. | ||
/// </returns> | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static short SwapByteOrder(this short val) | ||
{ | ||
return (short)(((ushort)val).SwapByteOrder()); | ||
} | ||
|
||
/// <summary> | ||
/// Swaps the endianness of the ushort. | ||
/// </summary> | ||
/// <param name="val"> | ||
/// The current value. | ||
/// </param> | ||
/// <returns> | ||
/// The ushort value in reverse-order from its current state. | ||
/// </returns> | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static ushort SwapByteOrder(this ushort val) | ||
{ | ||
return (ushort)(((val & 0xFF00) >> 8) | ((val & 0x00FF) << 8)); | ||
} | ||
|
||
/// <summary> | ||
/// Swaps the endianness of the integer. | ||
/// </summary> | ||
/// <param name="val"> | ||
/// The current value. | ||
/// </param> | ||
/// <returns> | ||
/// The integer value in reverse-order from its current state. | ||
/// </returns> | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static int SwapByteOrder(this int val) | ||
{ | ||
return (int)(((uint)val).SwapByteOrder()); | ||
} | ||
|
||
/// <summary> | ||
/// Swaps the endianness of the unsigned integer. | ||
/// </summary> | ||
/// <param name="val"> | ||
/// The current value. | ||
/// </param> | ||
/// <returns> | ||
/// The unsigned integer value in reverse-order from its current state. | ||
/// </returns> | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static uint SwapByteOrder(this uint val) | ||
{ | ||
val = (val >> 16) | (val << 16); | ||
return ((val & 0xFF00) >> 8) | ((val & 0x00FF) << 8); | ||
} | ||
|
||
/// <summary> | ||
/// Swaps the endianness of the long integer. | ||
/// </summary> | ||
/// <param name="val"> | ||
/// The current value. | ||
/// </param> | ||
/// <returns> | ||
/// The long integer value in reverse-order from its current state. | ||
/// </returns> | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static long SwapByteOrder(this long val) | ||
public static byte GetBit(this byte @byte, int index) | ||
{ | ||
return (long)(((ulong)val).SwapByteOrder()); | ||
return (byte)(@byte & (1 << index - 1)); | ||
} | ||
|
||
/// <summary> | ||
/// Swaps the endianness of the unsigned long integer. | ||
/// </summary> | ||
/// <param name="val"> | ||
/// The current value. | ||
/// </param> | ||
/// <returns> | ||
/// The unsigned long integer value in reverse-order from its current state. | ||
/// </returns> | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static ulong SwapByteOrder(this ulong val) | ||
public static byte SetBit(this byte @byte, int index) | ||
{ | ||
val = (val >> 32) | (val << 32); | ||
val = ((val & 0xFFFF0000FFFF0000) >> 16) | ((val & 0x0000FFFF0000FFFF) << 16); | ||
return ((val & 0xFF00FF00FF00FF00) >> 8) | ((val & 0x00FF00FF00FF00FF) << 8); | ||
return (byte)(@byte & (1 << index - 1)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.