1+ // Decompiled with JetBrains decompiler
2+ // Type: HwidGetCurrentEx.BitUtil
3+ // Assembly: HwidGetCurrentEx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
4+ // MVID: 200C1AD7-2186-49E5-9EB2-5AB7013ECA80 Assembly location: D:\downloads\Programs\HwidGetCurrentEx.dll
5+
6+ using System ;
7+ using System . Collections . Generic ;
8+ using System . Linq ;
9+ using System . Runtime . CompilerServices ;
10+ using System . Text ;
11+
12+ namespace HWIDEx
13+ {
14+ internal static class BitUtil
15+ {
16+ public static string ReadNullTerminatedAnsiString ( byte [ ] buffer , int offset )
17+ {
18+ StringBuilder stringBuilder = new StringBuilder ( ) ;
19+ for ( char ch = ( char ) buffer [ offset ] ; ch > char . MinValue ; ch = ( char ) buffer [ offset ] )
20+ {
21+ stringBuilder . Append ( ch ) ;
22+ ++ offset ;
23+ }
24+ return stringBuilder . ToString ( ) ;
25+ }
26+
27+ public static byte [ ] StrToByteArray ( string str )
28+ {
29+ Dictionary < string , byte > dictionary = new Dictionary < string , byte > ( ) ;
30+ for ( int index = 0 ; index <= ( int ) byte . MaxValue ; ++ index )
31+ dictionary . Add ( index . ToString ( "X2" ) , ( byte ) index ) ;
32+ List < byte > byteList = new List < byte > ( ) ;
33+ for ( int startIndex = 0 ; startIndex < str . Length ; startIndex += 2 )
34+ byteList . Add ( dictionary [ str . Substring ( startIndex , 2 ) ] ) ;
35+ return byteList . ToArray ( ) ;
36+ }
37+
38+ public static ulong array2ulong ( byte [ ] bytes , int start , int length )
39+ {
40+ bytes = ( ( IEnumerable < byte > ) bytes ) . Skip < byte > ( start ) . Take < byte > ( length ) . ToArray < byte > ( ) ;
41+ ulong num1 = 0 ;
42+ foreach ( byte num2 in bytes )
43+ num1 = num1 * 256UL + ( ulong ) num2 ;
44+ return num1 ;
45+ }
46+
47+ public static T [ ] Concats < T > ( this T [ ] array1 , params T [ ] array2 ) => BitUtil . ConcatArray < T > ( array1 , array2 ) ;
48+
49+ public static T [ ] ConcatArray < T > ( params T [ ] [ ] arrays )
50+ {
51+ int index1 ;
52+ int length ;
53+ for ( length = index1 = 0 ; index1 < arrays . Length ; ++ index1 )
54+ length += arrays [ index1 ] . Length ;
55+ T [ ] objArray = new T [ length ] ;
56+ int index2 ;
57+ for ( int index3 = index2 = 0 ; index2 < arrays . Length ; ++ index2 )
58+ {
59+ arrays [ index2 ] . CopyTo ( ( Array ) objArray , index3 ) ;
60+ index3 += arrays [ index2 ] . Length ;
61+ }
62+ return objArray ;
63+ }
64+
65+ public static byte LOBYTE ( int a ) => ( byte ) ( ( uint ) ( short ) a & ( uint ) byte . MaxValue ) ;
66+
67+ public static short MAKEWORD ( byte a , byte b ) => ( short ) ( ( int ) ( byte ) ( ( uint ) a & ( uint ) byte . MaxValue ) | ( int ) ( byte ) ( ( uint ) b & ( uint ) byte . MaxValue ) << 8 ) ;
68+
69+ public static byte LOBYTE ( short a ) => ( byte ) ( ( uint ) a & ( uint ) byte . MaxValue ) ;
70+
71+ public static byte HIBYTE ( short a ) => ( byte ) ( ( uint ) a >> 8 ) ;
72+
73+ public static int MAKELONG ( short a , short b ) => ( int ) a & ( int ) ushort . MaxValue | ( ( int ) b & ( int ) ushort . MaxValue ) << 16 ;
74+
75+ public static short HIWORD ( int a ) => ( short ) ( a >> 16 ) ;
76+
77+ public static short LOWORD ( int a ) => ( short ) ( a & ( int ) ushort . MaxValue ) ;
78+
79+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
80+ public static uint RotateLeft ( uint value , int offset ) => value << offset | value >> 32 - offset ;
81+
82+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
83+ public static ulong RotateLeft64 ( ulong value , int offset ) => value << offset | value >> 64 - offset ;
84+
85+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
86+ public static uint RotateRight ( uint value , int offset ) => value >> offset | value << 32 - offset ;
87+
88+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
89+ public static ulong RotateRight64 ( ulong value , int offset ) => value >> offset | value << 64 - offset ;
90+
91+ public static int HIDWORD ( long intValue ) => Convert . ToInt32 ( intValue >> 32 ) ;
92+
93+ public static int LODWORD ( long intValue ) => Convert . ToInt32 ( intValue << 32 >> 32 ) ;
94+
95+ public static short PAIR ( sbyte high , sbyte low ) => ( short ) ( ( int ) high << 8 | ( int ) ( byte ) low ) ;
96+
97+ public static int PAIR ( short high , int low ) => ( int ) high << 16 | ( int ) ( ushort ) low ;
98+
99+ public static long PAIR ( int high , long low ) => ( long ) high << 32 | ( long ) ( uint ) low ;
100+
101+ public static ushort PAIR ( byte high , ushort low ) => ( ushort ) ( ( uint ) high << 8 | ( uint ) ( byte ) low ) ;
102+
103+ public static uint PAIR ( ushort high , uint low ) => ( uint ) high << 16 | ( uint ) ( ushort ) low ;
104+
105+ public static ulong PAIR ( uint high , ulong low ) => ( ulong ) high << 32 | ( ulong ) ( uint ) low ;
106+
107+ public static int adc ( uint first , uint second , ref uint carry )
108+ {
109+ uint carry1 = 0 ;
110+ if ( carry == 0U )
111+ {
112+ uint num = first + second ;
113+ carry = num >= first || num >= second ? 0U : 1U ;
114+ return ( int ) num ;
115+ }
116+ uint num1 = ( uint ) BitUtil . adc ( first , second , ref carry1 ) ;
117+ if ( carry > 0U )
118+ {
119+ ++ num1 ;
120+ carry1 |= num1 == 0U ? 1U : 0U ;
121+ }
122+ carry = carry1 ;
123+ return ( int ) num1 ;
124+ }
125+ }
126+ }
0 commit comments