Search code examples
c++decompiling

some disassemble c++ code I am puzzled


I use the IDA pro,hex-rays to decompile some code of a dll.

get some code like below:

void __stdcall IsDotInLine(double a1, double a2, double a3, double a4, double a5, double a6, double a7)
{
  int v7; // edx@1
  int v8; // ecx@1
  double v9; // st7@10
  char v10; // [sp+14h] [bp-88h]@1
  double v11; // [sp+54h] [bp-48h]@10
  double v12; // [sp+5Ch] [bp-40h]@10
  double v13; // [sp+64h] [bp-38h]@10
  double v14; // [sp+6Ch] [bp-30h]@6
  double v15; // [sp+74h] [bp-28h]@6
  double v16; // [sp+7Ch] [bp-20h]@1
  double v17; // [sp+84h] [bp-18h]@1
  double v18; // [sp+8Ch] [bp-10h]@1
  double v19; // [sp+94h] [bp-8h]@1

  memset(&v10, -858993460, 0x88u);
  sub_100014D3((int)&v15);
  v16 = a3;
  v18 = a5;
  v19 = a4;
  v17 = a6;
  sub_10001550(&v16);
  v16 = v16 - a7;
  v18 = v18 + a7;
  v17 = v17 - a7;
  v19 = v19 + a7;
  if ( a1 >= v16 )
  {
    if ( a1 <= v18 )
    {
      if ( a2 >= v17 )
      {
        if ( a2 <= v19 )
        {
          v15 = a6 - a4;
          v14 = a3 - a5;
          if ( v15 > 0.000000001 || v15 < -0.000000001 || v14 > 0.000000001 || v14 < -0.000000001 )
          {
            v13 = -v15 * a3 - v14 * a4;
            v11 = fabs(v15 * a1 + v14 * a2 + v13);
            v9 = sqrt(v15 * v15 + v14 * v14);
            v12 = v11 / v9;
          }
        }
      }
    }
  }
  chkesp(v8, v7);
}

After my ananlysis, besides some functional code.

I think the code like this type is no use, at least in this function , I can not figure out the use of the "sub_100021C0" function.

Can anyone got some idea about this code, what effect of the "sub_100021C0"?

thanks, attached is the code

int __thiscall sub_100014D3(int this)
{
  return sub_100021C0(this);
}
int __thiscall sub_100021C0(int this)
{
  int v1; // ecx@1
  int v2; // edx@1
  int v3; // eax@1
  int v5; // [sp+4Ch] [bp-4h]@1

  v5 = this;
  *(_DWORD *)this = 0;
  *(_DWORD *)(this + 4) = 0;
  v1 = v5;
  *(_DWORD *)(v5 + 8) = 0;
  *(_DWORD *)(v1 + 12) = 0;
  v2 = v5;
  *(_DWORD *)(v5 + 16) = 0;
  *(_DWORD *)(v2 + 20) = 0;
  v3 = v5;
  *(_DWORD *)(v5 + 24) = 0;
  *(_DWORD *)(v3 + 28) = 0;
  return v5;
}

Solution

  • That's probably the constructor/initializer of whatever class that is. Notice the this pointer being passed as the first argument, and v1 through v5 are just aliases for that. So it is setting (presumably) every member of the structure or class at the address this to 0.

    The memset line above the call to that function is setting all the local variables (including the members of the class) to 0xcccccccc, which is a sentinel value used by some compilers to mean "uninitialized" if you compile in debug mode. Thus, the called function is necessary to initialize the values.

    My guess is that there's a struct that looks something like struct Line { double x1, y1, x2, y2; }; with a constructor that initializes them to 0.