UnrestrainedGTA

2 Byte Big Endian

Oct 4th, 2022 (edited)
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. alloc(TypeName,256)
  2. alloc(ByteSize,4)
  3. alloc(ConvertRoutine,1024)
  4. alloc(ConvertBackRoutine,1024)
  5.  
  6. TypeName:
  7. db '2 Byte Big Endian',0
  8.  
  9. ByteSize:
  10. dd 2
  11.  
  12. //The convert routine should hold a routine that converts the data to an integer (in eax)
  13. //function declared as: stdcall int ConvertRoutine(unsigned char *input);
  14. //Note: Keep in mind that this routine can be called by multiple threads at the same time.
  15. ConvertRoutine:
  16. //jmp dllname.functionname
  17. [64-bit]
  18. //or manual:
  19. //parameters: (64-bit)
  20. //rcx=address of input
  21. xor eax,eax
  22. mov ax,[rcx] //eax now contains the bytes 'input' pointed to
  23. xchg ah,al //convert to big endian
  24.  
  25. ret
  26. [/64-bit]
  27.  
  28. [32-bit]
  29. //jmp dllname.functionname
  30. //or manual:
  31. //parameters: (32-bit)
  32. push ebp
  33. mov ebp,esp
  34. //[ebp+8]=input
  35. //example:
  36. mov eax,[ebp+8] //place the address that contains the bytes into eax
  37. mov ax,[eax] //place the bytes into eax so it's handled as a normal 4 byte value
  38. and eax,ffff //cleanup
  39. xchg ah,al //convert to big endian
  40.  
  41. pop ebp
  42. ret 4
  43. [/32-bit]
  44.  
  45. //The convert back routine should hold a routine that converts the given integer back to a row of bytes (e.g when the user wats to write a new value)
  46. //function declared as: stdcall void ConvertBackRoutine(int i, unsigned char *output);
  47. ConvertBackRoutine:
  48. //jmp dllname.functionname
  49. //or manual:
  50. [64-bit]
  51. //parameters: (64-bit)
  52. //ecx=input
  53. //rdx=address of output
  54. //example:
  55. xchg ch,cl //convert the little endian input into a big endian input
  56. mov [rdx],cx //place the integer the 4 bytes pointed to by rdx
  57.  
  58. ret
  59. [/64-bit]
  60.  
  61. [32-bit]
  62. //parameters: (32-bit)
  63. push ebp
  64. mov ebp,esp
  65. //[ebp+8]=input
  66. //[ebp+c]=address of output
  67. //example:
  68. push eax
  69. push ebx
  70. mov eax,[ebp+8] //load the value into eax
  71. mov ebx,[ebp+c] //load the address into ebx
  72.  
  73. //convert the value to big endian
  74. xchg ah,al
  75.  
  76. mov [ebx],ax //write the value into the address
  77. pop ebx
  78. pop eax
  79.  
  80. pop ebp
  81. ret 8
  82. [/32-bit]
Add Comment
Please, Sign In to add comment