Unpack.rawint_hpp.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #if !Rar2017_64bit
  2. using nint = System.Int32;
  3. using nuint = System.UInt32;
  4. using size_t = System.UInt32;
  5. #else
  6. using nint = System.Int64;
  7. using nuint = System.UInt64;
  8. using size_t = System.UInt64;
  9. #endif
  10. using int64 = System.Int64;
  11. using uint32 = System.UInt32;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Text;
  15. namespace SharpCompress.Compressors.Rar.UnpackV2017
  16. {
  17. internal partial class Unpack
  18. {
  19. //#define rotls(x,n,xsize) (((x)<<(n)) | ((x)>>(xsize-(n))))
  20. //#define rotrs(x,n,xsize) (((x)>>(n)) | ((x)<<(xsize-(n))))
  21. //#define rotl32(x,n) rotls(x,n,32)
  22. //#define rotr32(x,n) rotrs(x,n,32)
  23. //
  24. //inline uint RawGet2(const void *Data)
  25. //{
  26. // byte *D=(byte *)Data;
  27. // return D[0]+(D[1]<<8);
  28. //}
  29. private uint32 RawGet4(byte[] D, int offset)
  30. {
  31. return (uint)(D[offset]+(D[offset+1]<<8)+(D[offset+2]<<16)+(D[offset+3]<<24));
  32. }
  33. //inline uint64 RawGet8(const void *Data)
  34. //{
  35. //#if defined(BIG_ENDIAN) || !defined(ALLOW_MISALIGNED)
  36. // byte *D=(byte *)Data;
  37. // return INT32TO64(RawGet4(D+4),RawGet4(D));
  38. //#else
  39. // return *(uint64 *)Data;
  40. //#endif
  41. //}
  42. //
  43. //
  44. //inline void RawPut2(uint Field,void *Data)
  45. //{
  46. // byte *D=(byte *)Data;
  47. // D[0]=(byte)(Field);
  48. // D[1]=(byte)(Field>>8);
  49. //}
  50. private void RawPut4(uint32 Field,byte[] D, int offset)
  51. {
  52. D[offset]=(byte)(Field);
  53. D[offset+1]=(byte)(Field>>8);
  54. D[offset+2]=(byte)(Field>>16);
  55. D[offset+3]=(byte)(Field>>24);
  56. }
  57. //inline void RawPut8(uint64 Field,void *Data)
  58. //{
  59. //#if defined(BIG_ENDIAN) || !defined(ALLOW_MISALIGNED)
  60. // byte *D=(byte *)Data;
  61. // D[0]=(byte)(Field);
  62. // D[1]=(byte)(Field>>8);
  63. // D[2]=(byte)(Field>>16);
  64. // D[3]=(byte)(Field>>24);
  65. // D[4]=(byte)(Field>>32);
  66. // D[5]=(byte)(Field>>40);
  67. // D[6]=(byte)(Field>>48);
  68. // D[7]=(byte)(Field>>56);
  69. //#else
  70. // *(uint64 *)Data=Field;
  71. //#endif
  72. //}
  73. //#if defined(LITTLE_ENDIAN) && defined(ALLOW_MISALIGNED)
  74. //#define USE_MEM_BYTESWAP
  75. //#endif
  76. // Load 4 big endian bytes from memory and return uint32.
  77. //inline uint32 RawGetBE4(const byte *m)
  78. //{
  79. //#if defined(USE_MEM_BYTESWAP) && defined(_MSC_VER)
  80. // return _byteswap_ulong(*(uint32 *)m);
  81. //#elif defined(USE_MEM_BYTESWAP) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 2)
  82. // return __builtin_bswap32(*(uint32 *)m);
  83. //#else
  84. // return uint32(m[0]<<24) | uint32(m[1]<<16) | uint32(m[2]<<8) | m[3];
  85. //#endif
  86. //}
  87. // Save integer to memory as big endian.
  88. //inline void RawPutBE4(uint32 i,byte *mem)
  89. //{
  90. //#if defined(USE_MEM_BYTESWAP) && defined(_MSC_VER)
  91. // *(uint32*)mem = _byteswap_ulong(i);
  92. //#elif defined(USE_MEM_BYTESWAP) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 2)
  93. // *(uint32*)mem = __builtin_bswap32(i);
  94. //#else
  95. // mem[0]=byte(i>>24);
  96. // mem[1]=byte(i>>16);
  97. // mem[2]=byte(i>>8);
  98. // mem[3]=byte(i);
  99. //#endif
  100. //}
  101. //inline uint32 ByteSwap32(uint32 i)
  102. //{
  103. //#ifdef _MSC_VER
  104. // return _byteswap_ulong(i);
  105. //#elif (__GNUC__ > 3) && (__GNUC_MINOR__ > 2)
  106. // return __builtin_bswap32(i);
  107. //#else
  108. // return (rotl32(i,24)&0xFF00FF00)|(rotl32(i,8)&0x00FF00FF);
  109. //#endif
  110. //}
  111. }
  112. }