Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

What does this code do?

Name: Anonymous 2011-10-04 11:23

What does this code do?

      v8 = v46;
      v45 = &(*Tree)->Root;
      v44 = &(*Tree)->Left;
      v43 = &(*Tree)->Right;
      if ( v46->Left )
      {
        v9 = v46->Right;
        if ( !v9 )
        {
          v10 = v46->Left;
          goto LABEL_20;
        }
        v8 = v46->Right;
        if ( v9->Left )
        {
          do
            v8 = v8->Left;
          while ( v8->Left );
        }
      }
      v10 = v8->Right;
LABEL_20:
      if ( v8 == v46 )
      {
        v11 = v8->Root;
        if ( v10 )
          v10->Root = v11;
        if ( *v45 == v8 )
        {
          *v45 = v10;
        }
        else
        {
          v14 = v8->Root;
          if ( v14->Left == v8 )
            v14->Left = v10;
          else
            v14->Right = v10;
        }
        if ( *v44 == v46 )
        {
          if ( v46->Right )
          {
            for ( i = v10; i->Left; i = i->Left )
              ;
          }
          else
          {
            i = v46->Root;
          }
          *v44 = i;
        }
        if ( *v43 == v46 )
        {
          if ( v46->Left )
          {
            for ( j = v10; j->Right; j = j->Right )
              ;
            *v43 = j;
          }
          else
          {
            *v43 = v46->Root;
          }
        }
      }
      else
      {
        v46->Left->Root = v8;
        v8->Left = v46->Left;
        if ( v8 == v46->Right )
        {
          v11 = v8;
        }
        else
        {
          v11 = v8->Root;
          if ( v10 )
            v10->Root = v11;
          v8->Root->Left = v10;
          v8->Right = v46->Right;
          v46->Right->Root = v8;
        }
        if ( *v45 == v46 )
        {
          *v45 = v8;
        }
        else
        {
          v12 = v46->Root;
          if ( v12->Left == v46 )
            v12->Left = v8;
          else
            v12->Right = v8;
        }
        v8->Root = v46->Root;
        v13 = LOBYTE(v8->field_0);
        LOBYTE(v8->field_0) = LOBYTE(v46->field_0);
        LOBYTE(v46->field_0) = v13;
        v8 = v46;
      }
      if ( LOBYTE(v8->field_0) )
      {
        if ( v10 != *v45 )
        {
          while ( !v10 || LOBYTE(v10->field_0) == 1 )
          {
            v17 = v11->Left;
            if ( v10 == v17 )
            {
              v18 = v11->Right;
              if ( !LOBYTE(v18->field_0) )
              {
                LOBYTE(v18->field_0) = 1;
                v19 = v11->Right;
                LOBYTE(v11->field_0) = 0;
                v11->Right = v19->Left;
                v20 = v19->Left;
                if ( v20 )
                  v20->Root = v11;
                v19->Root = v11->Root;
                if ( v11 == *v45 )
                {
                  *v45 = v19;
                }
                else
                {
                  v21 = v11->Root;
                  if ( v11 == v21->Left )
                    v21->Left = v19;
                  else
                    v21->Right = v19;
                }
                v19->Left = v11;
                v11->Root = v19;
                v18 = v11->Right;
              }

Name: Anonymous 2011-10-04 11:28

It does thimblerig.

Name: Anonymous 2011-10-04 11:34

it looks like a self balancing tree that supports multiple rotations, so should be used to balance after many actions and not on a one-action-one-balance methodology... anyways it's shitty code though

Name: Anonymous 2011-10-04 11:35

Some sort of binary tree sorting routine unrolled.

Name: Anonymous 2011-10-04 11:38

>>4
Does GCC unroll recursive code? Where is the rest of recursion, then?

Name: Anonymous 2011-10-04 11:41

Wand what is field_0 flag in LOBYTE(v10->field_0) == 1 used for? When I myself impelemented tree, every node kept the length of subtree, this way I also used tree as an array.

Name: Anonymous 2011-10-04 11:43

Basically it looks like folloing

struct node {
  int SomeFlag; // balance-related flag
  node *Root; // maybe not tree's root, but points to some node
  node *Left;
  node *Right;
  /* user data */
}

Dunno how one balances that.

Name: Anonymous 2011-10-04 13:46

Are you the same guy who asked about some other tree-ish code a while back?

Name: Anonymous 2011-10-04 15:57

>>8
That was List code. This time it's tree code.

Name: Anonymous 2011-10-04 17:07

I'm not going to analyze some random code you decompiled using Hex-Rays. Do it yourself, and if you have trouble, read the assembly and use a debugger!

Name: Anonymous 2011-10-04 17:23

>>10
How reading assembly would tell me how and why algorithm works?

Name: Anonymous 2011-10-04 17:40

>>11
I tend to find that decompiler output can sometimes contain duplicated code and may even be harder to understand than the optimized assembly. You can also debug the assembly thus see exactly what it does - no guessing and it's the most accurate answer you'll be getting.

Name: Anonymous 2011-10-04 18:17

I just learned how to use the spoiler tag, and now I'm shitposting on pork!

Name: Anonymous 2011-10-04 18:28

>>12
Decompiler is supposed to reduce duplication and roll back unrolled loops. It can use some compression algorithm to find repeated patterns.

Name: Anonymous 2011-10-04 18:30

>>12
You can also debug the assembly thus see exactly what it does - no guessing and it's the most accurate answer you'll be getting.
CPU can "see" exactly what it does, but I doubt stock Intel CPU undestands what it sees.

Name: Anonymous 2011-10-04 20:37

>>14
It does to some extent, but I've found that in many cases the assembly is more compact and sometimes clearer. It depends on the piece of code that is being decompiler.
>>15
I meant that the person doing the reverse engineering would see exactly what is going on by stepping through the assembly code in a debugger. I meant it in a rather literal sense.

Name: Anonymous 2011-10-05 1:05

>>16
I meant that the person doing the reverse engineering would see exactly what is going on by stepping through the assembly code in a debugger. I meant it in a rather literal sense.
Only if person already knows the algorithm. Tree balancing algorithms are notoriously difficult to get without some kind of formal theory.

Name: Cudder !MhMRSATORI!FBeUS42x4uM+kgp 2011-10-05 5:05

Name: Anonymous 2011-10-05 5:12

>>18
Yep! They use flag and look exactly that confusing.

Name: Anonymous 2011-10-05 5:18

>>19
Anyway, it's a badly done agorithm, because it requires storing useless red-black-flag and wastes memory for root and leaf links.

Name: Anonymous 2011-10-05 10:29

>>20
90% of the time it's going to be code from some standard tree library.

Name: Anonymous 2011-10-05 10:34

>>21
Majesty uses RogueWave. But C++ template code is even harder than decompiler output.

Name: Anonymous 2011-10-06 9:27


while you == lol:
    nope = 1

Don't change these.
Name: Email:
Entire Thread Thread List