1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _MSVBASIC_HXX 24 #define _MSVBASIC_HXX 25 26 #ifdef _SOLAR_H 27 #include <tools/solar.h> 28 #endif 29 #include <tools/debug.hxx> 30 #include <sot/storage.hxx> 31 32 33 /* class VBA: 34 * The VBA class provides a set of methods to handle Visual Basic For 35 * Applications streams, the constructor is given the root ole2 stream 36 * of the document, Open reads the VBA project file and figures out 37 * the number of VBA streams, and the offset of the data within them. 38 * Decompress decompresses a particular numbered stream, NoStreams returns 39 * this number, and StreamName can give you the streams name. Decompress 40 * will return a string with the decompressed data. The optional extra 41 * argument will be set if not NULL to 1 in the case of a string overflow, 42 * if I can figure out how to do that. 43 * 44 * Otherwise it is possible to inherit from VBA and implement a Output 45 * member which gets called with each 4096 output sized block. 46 * 47 * cmc 48 * */ 49 50 #define WINDOWLEN 4096 51 52 class VBA_Impl 53 { 54 public: VBA_Impl(SvStorage & rIn,sal_Bool bCmmntd=sal_True)55 VBA_Impl( SvStorage &rIn, sal_Bool bCmmntd = sal_True ) 56 : xStor(&rIn), pOffsets(0), nOffsets(0), bCommented(bCmmntd) 57 {} ~VBA_Impl()58 ~VBA_Impl() {if (nOffsets) delete [] pOffsets;} 59 //0 for failure, 1 for success 60 sal_Bool Open( const String &rToplevel, const String &rSublevel); 61 const String & Decompress( sal_uInt16 nIndex, int *pOverflow=0); GetNoStreams() const62 sal_uInt16 GetNoStreams() const { return nOffsets; } GetStreamName(sal_uInt16 nIndex) const63 const String &GetStreamName( sal_uInt16 nIndex ) const 64 { 65 DBG_ASSERT( nIndex < nOffsets, "Index out of range" ); 66 return pOffsets[ nIndex ].sName; 67 } 68 virtual void Output(int len,const sal_uInt8 *data); 69 private: 70 struct VBAOffset_Impl 71 { 72 String sName; 73 sal_uInt32 nOffset; 74 }; 75 76 SvStorageRef xVBA; 77 String sVBAString; 78 SvStorageRef xStor; 79 VBAOffset_Impl *pOffsets; 80 sal_uInt16 nOffsets; 81 sal_uInt8 aHistory[ WINDOWLEN ]; 82 sal_Bool bCommented; 83 84 //0 for failure, anything else for success 85 int ReadVBAProject(const SvStorageRef &rxVBAStorage); 86 int DecompressVBA(int index, SvStorageStreamRef &rxVBAStream); 87 void Confirm12Zeros(SvStorageStreamRef &xVBAProject); 88 void ConfirmHalfWayMarker(SvStorageStreamRef &xVBAProject); 89 void ConfirmFixedMiddle(SvStorageStreamRef &xVBAProject); 90 void ConfirmFixedMiddle2(SvStorageStreamRef &xVBAProject); 91 void ConfirmFixedOctect(SvStorageStreamRef &xVBAProject); 92 sal_uInt8 ReadPString(SvStorageStreamRef &xVBAProject); 93 }; 94 95 96 97 98 #endif 99