• Use [hide] Content [/hide] to prevent leeching of your content.

Getting A Functions Length

(+)

Member
Get a functions length .

BY : (+) 8)

Normal use sample :

Except for __declspec(naked) Functions unless you added __asm ret; at the end .

---------------------------
Edit:
If in case you get wrong values or find
other C2|C3 in the func , just add more returns to adjust ...

C++:
/*
        UINT Length = 0;

        The_Func_Lenght( (DWORD) Your_Function, &Length, 1, TRUE );
        */
        //==============================//

        HRESULT __stdcall The_Func_Lenght( DWORD The_Function_Address, UINT * The_Lenght,
      int Number_Of_Returns_In_Func /* If added ret/retn in asm */, BOOL Has_Arguments )
   {
      BYTE * Return_Byte;
      int Returns_Counted = 0;
      for( UINT i = 0; ; i ++ )
      {
         Return_Byte = ( BYTE * )( The_Function_Address + i );

         if( *Return_Byte == 0xC3 || *Return_Byte == 0xC2 )
            Returns_Counted++;
        
         if( Returns_Counted >= Number_Of_Returns_In_Func )
         {
            if( Has_Arguments )
               *The_Lenght = ( i + 1 )  + 2;
            else
               *The_Lenght = ( i + 1 );
            return  S_OK;
         }
      }
      return E_FAIL;
   }
 
Last edited by a moderator:
Top Bottom