Gnash
0.8.10
|
00001 // 00002 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 00003 // Free Software Foundation, Inc 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 00019 #ifndef GNASH_ACTION_BUFFER_H 00020 #define GNASH_ACTION_BUFFER_H 00021 00022 #include <string> 00023 #include <vector> 00024 #include <map> 00025 #include <boost/noncopyable.hpp> 00026 #include <boost/cstdint.hpp> 00027 00028 #include "GnashException.h" 00029 #include "ConstantPool.h" 00030 #include "log.h" 00031 00032 // Forward declarations 00033 namespace gnash { 00034 class as_value; 00035 class movie_definition; 00036 class SWFStream; // for read signature 00037 } 00038 00039 namespace gnash { 00040 00042 // 00047 // 00049 class action_buffer : boost::noncopyable 00050 { 00051 public: 00052 00053 action_buffer(const movie_definition& md); 00054 00056 // 00063 void read(SWFStream& in, unsigned long endPos); 00064 00065 size_t size() const { return m_buffer.size(); } 00066 00067 boost::uint8_t operator[] (size_t off) const 00068 { 00069 if (off >= m_buffer.size()) { 00070 throw ActionParserException (_("Attempt to read outside " 00071 "action buffer")); 00072 } 00073 return m_buffer[off]; 00074 } 00075 00077 std::string disasm(size_t pc) const; 00078 00080 // 00083 const char* read_string(size_t pc) const 00084 { 00085 assert(pc <= m_buffer.size() ); 00086 if (pc == m_buffer.size()) 00087 { 00088 throw ActionParserException(_("Asked to read string when only " 00089 "1 byte remains in the buffer")); 00090 } 00091 return reinterpret_cast<const char*>(&m_buffer[pc]); 00092 } 00093 00095 const unsigned char* getFramePointer(size_t pc) const 00096 { 00097 assert (pc < m_buffer.size()); 00098 return reinterpret_cast<const unsigned char*>(&m_buffer.at(pc)); 00099 } 00100 00102 // 00105 boost::int16_t read_int16(size_t pc) const 00106 { 00107 if (pc + 1 >= m_buffer.size()) { 00108 throw ActionParserException(_("Attempt to read outside action buffer limits")); 00109 } 00110 boost::int16_t ret = (m_buffer[pc] | (m_buffer[pc + 1] << 8)); 00111 return ret; 00112 } 00113 00116 boost::uint16_t read_uint16(size_t pc) const 00117 { 00118 return static_cast<boost::uint16_t>(read_int16(pc)); 00119 } 00120 00122 // 00125 boost::int32_t read_int32(size_t pc) const 00126 { 00127 if (pc + 3 >= m_buffer.size()) { 00128 throw ActionParserException(_("Attempt to read outside action buffer limits")); 00129 } 00130 00131 boost::int32_t val = m_buffer[pc] 00132 | (m_buffer[pc + 1] << 8) 00133 | (m_buffer[pc + 2] << 16) 00134 | (m_buffer[pc + 3] << 24); 00135 return val; 00136 } 00137 00139 // 00142 float read_float_little(size_t pc) const; 00143 00145 // 00149 double read_double_wacky(size_t pc) const; 00150 00152 const char* dictionary_get(size_t n) const 00153 { 00154 if ( _pools.empty() ) return 0; 00155 00156 // We'll query the last inserted one for now (highest PC) 00157 const ConstantPool& pool = _pools.rbegin()->second; 00158 00159 if ( n < pool.size() ) return pool[n]; 00160 00161 else return 0; 00162 } 00163 00165 // 00177 const ConstantPool& readConstantPool(size_t start_pc, size_t stop_pc) const; 00178 00180 const std::string& getDefinitionURL() const; 00181 00183 int getDefinitionVersion() const; 00184 00185 const movie_definition& getMovieDefinition() const { 00186 return _src; 00187 } 00188 00189 private: 00190 00192 std::vector<boost::uint8_t> m_buffer; 00193 00195 typedef std::map<size_t, ConstantPool> PoolsMap; 00196 mutable PoolsMap _pools; 00197 00199 // 00203 const movie_definition& _src; 00204 }; 00205 00206 00207 } // end namespace gnash 00208 00209 00210 #endif // GNASH_ACTION_BUFFER_H 00211 00212 00213 // Local Variables: 00214 // mode: C++ 00215 // indent-tabs-mode: t 00216 // End: