Book a Demo

Author Topic: Reverse engineering of C++ source with macros  (Read 4686 times)

Andreas Börzel

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Reverse engineering of C++ source with macros
« on: August 14, 2008, 05:42:14 pm »
Hello,
I want to reverse engineere an existing C++ project.
This project makes intensive use of preprocessor macros, to keep the source code platform independent.

Sample:

class DCFRAMEWORK_API MyClass
{
   public:
   …

  virtual bool onInit (STD_STL(string) & strText);

  …
 
  private:

   STD_STL(string)   m_strStaticUuid;
   STD_STL(string)   m_strDynamicUuid;
   STD_STL(string)   m_strName;

   typedef STD_STL(map)<STD_STL(string),  DCParamPtr>  DCParamMap;
   typedef DCParamMap::iterator                                                  DCParamMapIter;
   typedef DCParamMap::value_type                                          DCParamMapEntry;
  
   DCParamMap   m_DCGlobalParameters;
}

Defines:

#ifdef WIN32
#ifdef DCFRAMEWORKDLL_EXPORTS
#define DCFRAMEWORK_API __declspec(dllexport)
#elif DCFRAMEWORKDLL_IMPORTS
#define DCFRAMEWORK_API __declspec(dllimport)
#else
#define DCFRAMEWORK_API
#endif
#else  // WIN32
#define DCFRAMEWORK_API
#endif  // WIN32

Macros:

#define USING_NAMESPACE_STD = using namespace std;
#define BEGIN_NAMESPACE(x) = namespace x;
#define END_NAMESPACE(x) = };
#define USING_NAMESPACE(x) = using namespace x;
#define NAMESPACE(ns,class) = ns::class
#define STD_STL(x) = std::x
#define STD_IO(x) = std::x
#define STD_IOMANIP(x) = std::x


When I try to import the source code into the EA, I get many error messages of this type:

There was an error parsing D:\Projects\AM\DCFramework\dev\Exported\impl\CounterBase_impl.h on line 67.  Unexpected symbol: &      
You may need to define a language macro.      
There was an error parsing D:\Projects\AM\DCFramework\dev\Exported\impl\DCApp_impl.h on line 121.  Unexpected symbol: &      
You may need to define a language macro.      
There was an error parsing D:\Projects\AM\DCFramework\dev\Exported\impl\DCBase_impl.h on line 64.  Unexpected symbol: ;      
You may need to define a language macro.      
There was an error parsing D:\Projects\AM\DCFramework\dev\Exported\impl\GenericDCElement_impl.h on line 70.  Unexpected symbol: ;      
You may need to define a language macro.      
There was an error parsing D:\Projects\AM\DCFramework\dev\Exported\impl\MOBase_impl.h on line 73.  Unexpected symbol: ;      


I have already read the help under http://www.sparxsystems.com.au/EAUserGuide/index.html?languagemacros.htm, but there is not sufficiently explained how I can define preprocessor macros.

Can anyone help?
Thanks!

Lars H

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Reverse engineering of C++ source with macros
« Reply #1 on: September 04, 2008, 06:36:48 pm »
Hi Andreas,

We have the same problem. EA doesn't have a C/C++ preprocessor. You can define macros that will be ignored during reverse engineering, but they will not be expanded. And #ifdef's are not handled either.

I ended up writing my own script that preprocesses the code before reverse engineering it. This is far from ideal, but at least I can get the code in.

Andreas Börzel

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Reverse engineering of C++ source with macros
« Reply #2 on: September 05, 2008, 07:00:51 pm »
Hi Lars,

thank you for your answer. I thought almost that the EA does not support preprocesor macros, but I hoped that it is maybe possible. I am going to make a feature request therefore.

Thanks

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Reverse engineering of C++ source with macros
« Reply #3 on: September 05, 2008, 09:46:06 pm »
It seems - I have not tried this - that you can define tagged values to capture macro bodies. I do not know if EA will capture these for you automatically, but I believe it will not.

Look up Language | Macros in the EA help index and you'll see something (all I could find) on this.

HTH, David
No, you can't have it!