Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1.  
  2. Function baRBytes([Byte[]]$ba, [Int]$pos, [Int]$length)
  3. {
  4. $newbytes = [System.Byte[]]::CreateInstance([System.Byte],$length)
  5. [System.Buffer]::BlockCopy($bytes, $pos, $newbytes, 0, $length)
  6. return $newbytes
  7. }
  8. Function baRInt16([Byte[]]$ba, [Int]$pos)
  9. {
  10. return [System.BitConverter]::ToInt16($ba, $pos)
  11. }
  12. Function baRInt32([Byte[]]$ba, [Int]$pos)
  13. {
  14. return [System.BitConverter]::ToInt32($ba, $pos)
  15. }
  16. Function baRInt64([Byte[]]$ba, [Int]$pos)
  17. {
  18. return [System.BitConverter]::ToInt64($ba, $pos)
  19. }
  20. Function baRUInt16([Byte[]]$ba, [Int]$pos)
  21. {
  22. return [System.BitConverter]::ToUInt16($ba, $pos)
  23. }
  24. Function baRUInt32([Byte[]]$ba, [Int]$pos)
  25. {
  26. return [System.BitConverter]::ToUInt32($ba, $pos)
  27. }
  28. Function baRUInt64([Byte[]]$ba, [Int]$pos)
  29. {
  30. return [System.BitConverter]::ToUInt64($ba, $pos)
  31. }
  32. Function baRAString([Byte[]]$ba, [Int]$pos)
  33. {
  34. $length = 0x200
  35. if (($pos + $length) -gt $ba.length)
  36. {
  37. $length = $ba.length - $pos
  38. }
  39. $ascii = [System.Text.ASCIIEncoding]::new()
  40. return ($ascii.GetString($ba, $pos, $length)).Split(0)[0]
  41. }
  42. Function baRUString([Byte[]]$ba, [Int]$pos)
  43. {
  44. $length = 0x200
  45. if (($pos + $length) -gt $ba.length)
  46. {
  47. $length = $ba.length - $pos
  48. }
  49. $unicode = [System.Text.UnicodeEncoding]::new()
  50. return ($unicode.GetString($ba, $pos, $length)).Split(0)[0]
  51. }
  52.  
  53. Function baWBytes([Byte[]]$ba, [Int]$pos, [Byte[]]$bins)
  54. {
  55. [System.Buffer]::BlockCopy($bins, 0, $ba, $pos, $bins.length)
  56. }
  57. Function baWInt16([Byte[]]$ba, [Int]$pos, [Int16]$val)
  58. {
  59. baWBytes $ba $pos ([System.BitConverter]::GetBytes($val))
  60. }
  61. Function baWInt32([Byte[]]$ba, [Int]$pos, [Int32]$val)
  62. {
  63. baWBytes $ba $pos ([System.BitConverter]::GetBytes($val))
  64. }
  65. Function baWInt64([Byte[]]$ba, [Int]$pos, [Int64]$val)
  66. {
  67. baWBytes $ba $pos ([System.BitConverter]::GetBytes($val))
  68. }
  69. Function baWUInt16([Byte[]]$ba, [Int]$pos, [UInt16]$val)
  70. {
  71. baWBytes $ba $pos ([System.BitConverter]::GetBytes($val))
  72. }
  73. Function baWUInt32([Byte[]]$ba, [Int]$pos, [UInt32]$val)
  74. {
  75. baWBytes $ba $pos ([System.BitConverter]::GetBytes($val))
  76. }
  77. Function baWUInt64([Byte[]]$ba, [Int]$pos, [UInt64]$val)
  78. {
  79. baWBytes $ba $pos ([System.BitConverter]::GetBytes($val))
  80. }
  81. Function baWAString([Byte[]]$ba, [Int]$pos, [string]$str)
  82. {
  83. $ascii = [System.Text.ASCIIEncoding]::new()
  84. baWBytes $ba $pos ($ascii.GetBytes($str))
  85. }
  86. Function baWUString([Byte[]]$ba, [Int]$pos, [string]$str)
  87. {
  88. $unicode = [System.Text.UnicodeEncoding]::new()
  89. baWBytes $ba $pos ($unicode.GetBytes($str))
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement