2

can I detect wheather madexcept is used inside an delphi application by analyzing the exe file only ?

Is there a simple way by adding a few lines of code to my application and inform the final exe file user if madshi madexcept has been used or not

Franz
  • 1,883
  • 26
  • 47
  • Are you compiling the executable? If so surely you know whether or not madExcept is in there. – David Heffernan Jan 20 '13 at 15:05
  • @DavidHeffernan conceivable situation could be distribution of components which "need" to know ... – bummi Jan 20 '13 at 15:54
  • the executable is at the customer, we compiled with madshi but madshi does not pop up at acess violation or frozen thread at customers PC's. Without exchanging executables once more we would like to confirm that our code is according to our specification including madshi debugg tools. – Franz Jan 20 '13 at 16:27
  • 1
    If you have a repeatable build process you can regenerate the executable yourself and work with that. – David Heffernan Jan 20 '13 at 16:47

3 Answers3

12

If you use madexcept with a Delphi application, there should be a resource entry: MAD->EXCEPT in that executable.

To test an external application:

var
  h: HMODULE;

  h := LoadLibraryEx('c:\foo\bar.exe', 0, LOAD_LIBRARY_AS_DATAFILE);
  if h <> 0 then
  begin
    if FindResource(h, 'EXCEPT', 'MAD') <> 0 then 
      ShowMessage('madexcept Found!');
    FreeLibrary(h);
  end;

To test inside your own application:

if FindResource(HInstance, 'EXCEPT', 'MAD') <> 0 then 
  ShowMessage('madexcept Found!');

Note that whis however will NOT tell you what options madexcept uses. for example there could be an exception filter set to filter access violation exceptions, or a setting that will NOT check frozen threads etc...

kobik
  • 21,001
  • 4
  • 61
  • 121
5

You can do a plain text search for the text "madexcept". The easiest way to do that that I know of is with command line utilities. I would combine the strings and grep utilities like this:

C:\mydir>strings MyApp.exe | grep -i madexcept
MadException
MadExceptionT
madExcept
        madExcept
U9v;1   madExcept5
A       madExcept
        madExcept
        madExcept1
c       madExceptL
c       madExcept
c       madExcept
c       madExceptL
c       madExcept
c       madExcept
        madExcept
c       madExceptH
This way madExcept can't install the thread hooks.
.........

I personally use GnuWin32 as my source for these indispensable utilities.

If you are not a command line sort of a person, use Process Explorer. Run the executable and then run Process Explorer. Find the process and double click it. The brings up the Process Explorer properties dialog which contains a page named Strings. Select that page and click on the save button. Now you have a text file with all the strings in the executable in which you can search.

All this will tell you is that you compiled the madExcept code into your program. You won't know whether or not it is actually active.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
4

If you look into a project options with madExcept enabled I believe that you will see the define madExcept used, eg in your program anywhere you can do:

{$IFDEF madExcept}
  ....
{$ENDIF}
kobik
  • 21,001
  • 4
  • 61
  • 121
Brian Frost
  • 13,334
  • 11
  • 80
  • 154
  • You can then assign a value to a variable such as `IsMadExcept` inside of this conditional. [+1] – TLama Jan 21 '13 at 14:05
  • +1 from me as well. if you want to test for madExcept in your own application, this is better than `FindResource` as I suggested. – kobik Jan 21 '13 at 20:55