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
227 views
in Technique[技术] by (71.8m points)

c - Understanding the increment in the array (v6++)[4] = v9;

I have decompiled some .elf file with IDA's hex rays, what it gave me:

signed int __fastcall SEC_calc_(unsigned int a1, unsigned int a2, _DWORD *a3)
{
  char v30;    
  v3 = a1;
  v4 = a2;
  v6 = &v30;
  int v7;
  unsigned int v9;
  unsigned int v8; 
  v7 = 0;
  do
  {
    v8 = v4 >> v7;
    v9 = v3 >> v7;
    v7 += 8;
    *v6 = v8;
    (v6++)[4] = v9;
  }
  while ( v7 != 32 );

Assume that

 a1 = 0xC9A6010C
 a2 = 0xF1FFDFEF

I can understand that it's shifting the bits to the right and increasing the shifting value by 8 every loop until v7=32 (means only 4 loops). But what is

*v6 = v8;
(v6++)[4] = v9;

*v6 = v8 is pointer right? so t means v30 will equal v8 value as well? and I completely don't understand

 (v6++)[4] = v9;

why its an increment in the [4] array? And why it is signed with v9?

question from:https://stackoverflow.com/questions/65617707/understanding-the-increment-in-the-array-v64-v9

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

1 Reply

0 votes
by (71.8m points)
*v6 = v8;
(v6++)[4] = v9;

*v6 = v8 is pointer right? so t means v30 will equal v8 value as well?

v6 is the pointer, so *v6 designates the object it points to (v30 in this case). Thus, yes, *v6 = v8 copies the current value of variable v8 to variable v30.

I completely don't understand

 (v6++)[4] = v9;

why its an increment in the [4] array?

v6++ evaluates to the current value of v6, with a side effect of afterward incrementing v6 by one. The overall statement is approximately equivalent to these two separate statements:

 v6[4] = v9;
 v6 = v6 + 1;

For its part, v6[4] designates the object of the same type as *v6 that appears four positions after *v6, just as if v6 itself designated an array having at least five elements.

And why it is signed with v9?

The = v9 part is a straightforward assignment. It assigns the current value of variable v9 to the object designated by (v6++)[4]. I would have to study the code a lot more deeply to hypothesize about why the function performs that assignment.


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

...