Debugging EP_ProtectedStringBy*

Post here any topics that related to Enigma Protector, its functionality, your misunderstanding, offers to improvements etc etc etc
Post Reply
iaanus
Posts: 24
Joined: Tue Feb 03, 2009 12:08 pm

Debugging EP_ProtectedStringBy*

Post by iaanus »

Hi,

I have a program using EP_ProtectedStringBy* functions in a few critical places and I would like to debug them. The problem is that if I protect the code with Enigma I can't run it in the debugger, but if I don't protect it I don't get the strings... Any advice?

Thanks in advance,
Enigma
Site Admin
Posts: 2945
Joined: Wed Aug 20, 2008 2:24 pm

Re: Debugging EP_ProtectedStringBy*

Post by Enigma »

Hi iaanus, frustrating, but debugging is not possible using Enigma Protector.

But, why you can't run your program under debugger? If you are using Enigma API, then compiled application will require enigma_ide.dll. To run compiled application without protection simply take enigma_ide.dll from the installation folder of Enigma Protector and place it to the same folder with your compiled program. After that you will be able to run your program in debugger, just EP_ProtectedStringBy* will fail (until file is protected)
iaanus
Posts: 24
Joined: Tue Feb 03, 2009 12:08 pm

Re: Debugging EP_ProtectedStringBy*

Post by iaanus »

Yes, yes, I can run the program in the debugger using enigma_ide.dll, I just don't get the protected strings because EP_ProtectedStringBy* fails. The problem is that I can't debug the code that depends on those strings to be present :( I think I'll resort to macros that expand to string literals in debug mode and to EP_ProtectedStringBy* calls in release mode.
Enigma
Site Admin
Posts: 2945
Joined: Wed Aug 20, 2008 2:24 pm

Re: Debugging EP_ProtectedStringBy*

Post by Enigma »

yes, just simply use macros or IFDEF for Delphi.

For example, something like this may be used (Delphi):

Code: Select all

var
  str : string;
  cnt : integer;
begin
  ...
  {$IFDEF DEBUG}
  str := 'my hidden string';
  {$ELSE}
  cnt := EP_ProtectedStringById(12345, nil, 0);
  SetLength(str, cnt);
  EP_ProtectedStringById(12345, pointer(str), cnt);
  {$ENDIF}
  ...
end;
iaanus
Posts: 24
Joined: Tue Feb 03, 2009 12:08 pm

Re: Debugging EP_ProtectedStringBy*

Post by iaanus »

In case anyone is interested, I am using this in C++:

Code: Select all

#ifdef _DEBUG

#define EP_PROTECTED_STRING(id, str) std::string(str)

#else

#define EP_PROTECTED_STRING(id, str) getEPProtectedString(id)

static std::string getEPProtectedString(int id)
{
	int size = EP_ProtectedStringByID(id, 0, 0);
	std::string result(size, '\0');
	EP_ProtectedStringByID(id, &result[0], size);
	return result;
}

#endif
Enigma
Site Admin
Posts: 2945
Joined: Wed Aug 20, 2008 2:24 pm

Re: Debugging EP_ProtectedStringBy*

Post by Enigma »

thanks iaanus for the useful code!
mtx-electronics
Posts: 17
Joined: Wed Oct 10, 2012 8:09 am

Re: Debugging EP_ProtectedStringBy*

Post by mtx-electronics »

In BCB I'm using this macro

Code: Select all

#ifdef DEBUG
  #define PROTECTED_STRING_BY_ID(id, str) str
#else
  #define PROTECTED_STRING_BY_ID(id, str) GetProtectedStringByID(id)
#endif

String __fastcall TfrmMain::GetProtectedStringByID(int id)
{
  #include "Enigma\vm_begin.inc"

  int len = EP_ProtectedStringByID( id, NULL, 0 );
  char* str = new char[len + 1];
  memset(str , 0, len + 1);
  EP_ProtectedStringByID( id, str, len );

  #include "Enigma\vm_end.inc"

  return ((String)str);
}
Enigma
Site Admin
Posts: 2945
Joined: Wed Aug 20, 2008 2:24 pm

Re: Debugging EP_ProtectedStringBy*

Post by Enigma »

Thanks mtx-electronics, I will test it out and add this function to the enigma_ide.h!
Post Reply