Cast/convert 要寻址的字节数组
Cast/convert array of bytes to address
所以我有一个 vftable 偏移量所在的地址。它以字节形式存储在程序集中。例如:03 c3 bd 0c
我想获取字节,并将它们的小端格式转换为地址。
byte[0] = ((unsigned char *)addr)[3];
byte[1] = ((unsigned char *)addr)[2];
byte[2] = ((unsigned char *)addr)[1];
byte[3] = ((unsigned char *)addr)[0];
所以示例的输出将是 0x0cbdc303。
如何正确编码?
所以你有一个小端设备,想要将 4 个小端字节转换为一个 4 字节数字。这可以通过以下方式轻松完成:
uint32_t myNumber = *((uint32_t *)addr);
byte[0] = ((unsigned char *)addr)[3];
byte[1] = ((unsigned char *)addr)[2];
byte[2] = ((unsigned char *)addr)[1];
byte[3] = ((unsigned char *)addr)[0];
后面应该是
uint32_t address = (byte[0] << 24)|(byte[1] << 16)|(byte[2] << 8)|(byte[3]);
当然你可以去掉byte[]
,把原来的值代入这个
所以我有一个 vftable 偏移量所在的地址。它以字节形式存储在程序集中。例如:03 c3 bd 0c
我想获取字节,并将它们的小端格式转换为地址。
byte[0] = ((unsigned char *)addr)[3];
byte[1] = ((unsigned char *)addr)[2];
byte[2] = ((unsigned char *)addr)[1];
byte[3] = ((unsigned char *)addr)[0];
所以示例的输出将是 0x0cbdc303。
如何正确编码?
所以你有一个小端设备,想要将 4 个小端字节转换为一个 4 字节数字。这可以通过以下方式轻松完成:
uint32_t myNumber = *((uint32_t *)addr);
byte[0] = ((unsigned char *)addr)[3];
byte[1] = ((unsigned char *)addr)[2];
byte[2] = ((unsigned char *)addr)[1];
byte[3] = ((unsigned char *)addr)[0];
后面应该是
uint32_t address = (byte[0] << 24)|(byte[1] << 16)|(byte[2] << 8)|(byte[3]);
当然你可以去掉byte[]
,把原来的值代入这个