这里发生了什么:v5 = *(_Byte *)(this + 4)?
我正在查看 IDA pro 的代码转储。有一个函数如下布局:
garbled_name(int this...
unsigned int v5 ;
v5 = *(_Byte *)(this + 4);
...
我真正好奇的是“+ 4”到底在做什么?这是补充还是其他什么?
谢谢
I am looking at a code dump from IDA pro. There is a function which as this layout:
garbled_name(int this...
unsigned int v5 ;
v5 = *(_Byte *)(this + 4);
...
What I am really curious about is what exactly the '+ 4' is doing? Is this an addition or something else?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
该代码采用整数“this”,加 4,将其转换为指向字节的指针,然后将“v5”设置为该地址处的字节值。
The code takes the integer 'this', adds 4 to it, casts it to a pointer to a byte, and then sets 'v5' to the value of the byte at that address.
它只是 C++ 类的成员函数,
this
是指向对象的指针。该对象的签名可能是:有问题的代码是:
It's just a member function of a C++ class,
this
being pointer to the object. This signature of the object is probably:The code in question is:
它是对对象开头的第五个字节的引用。根据生成该代码的编译器,它很可能是类顺序中位于对象实例中第五个字节的项。
It is a reference to the fifth byte from the beginning of the object. Depending on what compiler generated that code, it is most likely the item in class order which is at the fifth byte in the object instance.
编辑:叹息,我错过了“IDA Pro”部分。我将其留在这里只是为了娱乐价值,以防有人想知道“this+4”在普通 C++ 代码中的作用。
<罢工>
“this+4”将当前的 this 指针向前移动四倍。然后它将其转换为字节指针并读取它。
考虑一下:
在 32 位系统上,sizeof(A) 最有可能是 8 个字节。
现在 pA 指向 &myArray[0]。
现在 pA 指向 &myArray[1],即它向前移动了 8 个字节。
如果您在 &myArray[0] 上调用此函数,它将指向 &myArray[4],即接下来的 32 个字节。
EDIT: Sigh, I missed the "IDA Pro" part. I'll just leave this here for entertainment value, in case someone is wondering what "this+4" does in normal C++ code.
"this+4" takes your current this pointer, moves forward four times its size. Then it casts that to a byte pointer and reads it.
Consider this:
sizeof(A), on a 32-bit system, is most likely 8 bytes.
Now pA points to &myArray[0].
Now pA points to &myArray[1], i.e. it moved 8 bytes forward.
If you call this on &myArray[0], it will point to &myArray[4], i.e. 32 bytes further down the road.