为什么在C ++中将字节数组中的字节反转 [英] why are the bytes in byte array reversed in C++

查看:112
本文介绍了为什么在C ++中将字节数组中的字节反转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解的代码会覆盖游戏进程内存的一部分(window.h,WriteProcessMemory),以便修改游戏中的参数(例如,强度).该值很可能是整数

代码尝试使用此功能替换

  WriteProcessMemory(GameHandle,(BYTE *)StrengthMemoryAddress,& StrengthValue,sizeof(StrengthValue),NULL); 

其中,StrengthMemoryAddress是预先计算的动态地址,StrengthValue是以下内容:

  byte StrengthValue [] = {0x39,0x5,0x0,0x0}; 

用1337代替强度

我的问题基本上是字节数组在此函数中的工作方式.从谷歌我知道1337的十六进制值为0x539.

为什么要在字节数组中将其反转?我看到他先放0x39,然后放0x5,我得出的结论可能是以相反的顺序组合到0x539.另外,为什么最后需要额外的0x0-难道不能就把它留在外面吗?

谢谢

解决方案

从Google我知道1337的十六进制值为0x539.

或者它是0x00000539,它是相同的,但写为4字节整数.现在,如果您以小尾数法将此整数写入内存,则必须按以下顺序存储它(最低有效字节-0x39-首先):

 内存地址值1000 0x391001 0x051002 0x001003 0x00 

所以这与字节序有关.您可能需要阅读更多有关该主题的信息.

the code i am trying to understand overwrites a section of a game process memory (window.h, WriteProcessMemory) in order to modify a parameter in the game (for example, strength). the values would most likely be integers

the code attempts replacement with this function

WriteProcessMemory( GameHandle, (BYTE*)StrengthMemoryAddress, &StrengthValue, sizeof(StrengthValue), NULL);

where StrengthMemoryAddress is a pre-calculated dynamic address and StrengthValue is the following:

byte StrengthValue[] = { 0x39, 0x5, 0x0, 0x0 };

it replaces strength with 1337

my question is basically how the byte array works in this function. from google i know that the hex value of 1337 is 0x539.

how come you have to reverse it in the byte array? i see that he first puts 0x39 then 0x5, which i concluded probably combines to 0x539 in some reverse order. also, why do you need the extra 0x0 at the end - can't you just leave it out?

thanks

解决方案

from google i know that the hex value of 1337 is 0x539.

Or it is 0x00000539 which is same but written as a 4 byte integer. Now if you write this integer in little endian way in memory you would have to store it in following order (Least significant byte - 0x39 - goes first):

Memory Address   Values
1000             0x39  
1001             0x05
1002             0x00
1003             0x00

So that has to do with endianness. You may want to read more on that topic.

这篇关于为什么在C ++中将字节数组中的字节反转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆