Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
113 views
in Technique[技术] by (71.8m points)

c - Pointers outside of () statement

I can't understand whats going on inside of the loop

char var_64;
char var_24;
int32_t r0_6 = 0;

do
{
   *(&var_24 + r0_6) = *(&var_64 + r0_6);
   r0_6 = r0_6 + 1;
}
while (r0_6 != 8);

I cant get this part:

*(&var_24 + r0_6) = *(&var_64 + r0_6);

does it take the address of var_24 increment it by 1 and assigned to it the address of var_64 incremented by 1? and what does the pointer * do here?

EDIT:

Here is the same decompiled code from another decompiler:

 char v29[16];
 unsigned __int8 v39;
 memset(&v39, 0, 8u);
 memset(v29, 0, 0x10u);
 do
  {
    *(&v39 + v10) = v29[v10];
    ++v10;
  }
  while ( v10 != 8 );

Here I think it the same, but it shows the v29 as an array

question from:https://stackoverflow.com/questions/65921333/pointers-outside-of-statement

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
char v29[16];
unsigned __int8 v39;
memset(&v39, 0, 8u);
memset(v29, 0, 0x10u);
do
{
    *(&v39 + v10) = v29[v10];
    ++v10;
}
while ( v10 != 8 );

Since this is decompiled code, I assume that the original code might looke like this:

{
    char v29[16];
    int8_t v39[8];

    memset(&v39, 0, sizeof (v39));
    memset(v29, 0, sizeof(v29));

    for(int i = 0; i < sizeof(v39); i++)
    {
        ((char *)(&v39))[i] = v29[i];
    }
}

Which would mean that you have an array of binary bytes, converted to a binary value, ignoring machine byte order, so it might be that this is only part of the code, or the array already is in the correct byte order.

The reason why v10 is not declared or initialized MIGHT be, that the compiler optimized code by reusing a register knowing that it has to be zero from the previous call to memset. But this is only an assumption.

The code is still pretty useless IMO, because the result will always be zero as the array is initialized with 0.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...