You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Vladimir <pb...@panban.co.yu> on 2007/08/02 11:47:46 UTC

detecting password protected macros

Hi,

I have a few Excel documents with macros. Some of those documents have password
protected access to macro, and others do not have (I am not writting about
password protected Excel files). Is there any way to detect which documents
contain password protected macros, and which contain macros that are not
password protected, by using POI?

I found the way to determine if an Excel document contains macro, but I can't
distinguish if that macro is password protected or visible to everyone.

Any suggestions? 

Vladimir



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: detecting password protected macros

Posted by Nick Burch <ni...@torchbox.com>.
On Thu, 2 Aug 2007, Vladimir wrote:
> but document with macro and its copy with password protected macro, 
> produced no difference.
>
> Simplification of code which I use to detect macro:

Ahh, looks like the macro is stored in a different poifs stream (not in 
the excel stream, which is what biffviewer checks)

Since the macros are in their own poifs stream, you'll need the 
org.apache.poi.poifs.dev tools instead (POIFSViewer). That'll print out 
each block in turn, and you should find that the Macro or VBA stream holds 
your differences

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: detecting password protected macros

Posted by Vladimir <pb...@panban.co.yu>.
Nick Burch <nick <at> torchbox.com> writes:

> 
> On Thu, 2 Aug 2007, Vladimir wrote:
> > I found the way to determine if an Excel document contains macro, but I 
> > can't distinguish if that macro is password protected or visible to 
> > everyone.
> 
> Your best bet is to create a simple excel file, containing a few cells, 
> and your macro (un-protected). Save a copy of that.
> 
> Now, open up the copy, and password protect the macro. Save
> 
> Finally, make use of the classes under org.apache.poi.hssf.dev (especially 
> BiffViewer) to spot what's different. Once you know that, it ought to be 
> fairly easy to spot the bit of POI that'll know, or at least the bit of 
> POI that could know with a tiny patch :)
> 
> Nick
> 

Thank you for quick response.

I tried your idea:

BiffViewer.main(new String[]{
      "C:\\Radni\\historianTest\\tmp\\in\\test03_with_macro_protected.xls"});

but document with macro and its copy with password protected macro, produced no
difference.

Any other idea?

Simplification of code which I use to detect macro:

 ...

POIFSReader r = new POIFSReader();
MacroListener macroL = new MacroListener();
r.registerListener(macroL);
FileInputStream fis = new FileInputStream(file);
r.read(fis);

 ...


private class MacroListener implements POIFSReaderListener {
   boolean macroDetected = false;
   	
   public boolean isMacroDetected() {
      return macroDetected;
   }
   	  
   public void processPOIFSReaderEvent(POIFSReaderEvent event) {
       
      if(event.getPath().toString().startsWith("\\Macros") ||
         event.getPath().toString().startsWith("\\_VBA")) {
            macroDetected = true;
      }

   }

...

Beside Excel this code can be used to detect macros in other Office documents.
Is it possible to do some extension or variation of this code to detect
differences between macros without password protection and password protected
macros?


Any idea is welcome.

Vladimir



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: detecting password protected macros

Posted by Nick Burch <ni...@torchbox.com>.
On Thu, 2 Aug 2007, Vladimir wrote:
> I found the way to determine if an Excel document contains macro, but I 
> can't distinguish if that macro is password protected or visible to 
> everyone.

Your best bet is to create a simple excel file, containing a few cells, 
and your macro (un-protected). Save a copy of that.

Now, open up the copy, and password protect the macro. Save

Finally, make use of the classes under org.apache.poi.hssf.dev (especially 
BiffViewer) to spot what's different. Once you know that, it ought to be 
fairly easy to spot the bit of POI that'll know, or at least the bit of 
POI that could know with a tiny patch :)

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org