m_javaloader.h

Go to the documentation of this file.
00001 ///
00002 /// \file       m_javaloader.h
00003 ///             Mode class for the JavaLoader mode
00004 ///
00005 
00006 /*
00007     Copyright (C) 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)
00008     Copyright (C) 2008-2009, Nicolas VIVIEN
00009 
00010         Some parts are inspired from m_desktop.h
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00020 
00021     See the GNU General Public License in the COPYING file at the
00022     root directory of this project for more details.
00023 */
00024 
00025 #ifndef __BARRY_M_JAVALOADER_H__
00026 #define __BARRY_M_JAVALOADER_H__
00027 
00028 #include "dll.h"
00029 #include "m_mode_base.h"
00030 #include "data.h"
00031 #include "pin.h"
00032 
00033 namespace Barry {
00034 
00035 // forward declarations
00036 class Parser;
00037 class Builder;
00038 class Controller;
00039 class CodFileBuilder;
00040 
00041 class JLDirectoryEntry;
00042 
00043 class JLEventlogEntry;
00044 
00045 class BXEXPORT JLDirectory : public std::vector<JLDirectoryEntry>
00046 {
00047 public:
00048         typedef std::vector<JLDirectoryEntry>   BaseType;
00049         typedef BaseType::iterator              BaseIterator;
00050         typedef std::vector<uint16_t>           TableType;
00051         typedef TableType::iterator             TableIterator;
00052 
00053 private:
00054         TableType m_idTable;
00055 
00056         int m_level;
00057 
00058 public:
00059         JLDirectory(int level = 0);
00060         ~JLDirectory();
00061 
00062         int Level() const { return m_level; }
00063         TableIterator TableBegin() { return m_idTable.begin(); }
00064         TableIterator TableEnd()   { return m_idTable.end(); }
00065 
00066         void ParseTable(const Data &table_packet);
00067 
00068         void Dump(std::ostream &os) const;
00069 };
00070 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDirectory &d) {
00071         d.Dump(os);
00072         return os;
00073 }
00074 
00075 class BXEXPORT JLDirectoryEntry
00076 {
00077 private:
00078         int m_level;
00079 
00080 public:
00081         uint16_t Id;
00082         std::string Name;
00083         std::string Version;
00084         uint32_t CodSize;
00085         time_t Timestamp;
00086 
00087         JLDirectory SubDir;
00088 
00089 public:
00090         explicit JLDirectoryEntry(int level);
00091 
00092         void Parse(uint16_t id, const Data &entry_packet);
00093 
00094         void Dump(std::ostream &os) const;
00095 };
00096 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDirectoryEntry &e) {
00097         e.Dump(os);
00098         return os;
00099 }
00100 
00101 
00102 class BXEXPORT JLScreenInfo {
00103 public:
00104         uint16_t width;
00105         uint16_t height;
00106 
00107 public:
00108         JLScreenInfo();
00109         ~JLScreenInfo();
00110 };
00111 
00112 
00113 class BXEXPORT JLEventlog : public std::vector<JLEventlogEntry>
00114 {
00115 public:
00116         void Dump(std::ostream &os) const;
00117 };
00118 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLEventlog &log) {
00119         log.Dump(os);
00120         return os;
00121 }
00122 
00123 
00124 class BXEXPORT JLEventlogEntry
00125 {
00126 public:
00127         typedef enum {
00128                 JES_ALWAYS_LOG,
00129                 JES_SEVERE_ERROR,
00130                 JES_ERROR,
00131                 JES_WARNING,
00132                 JES_INFORMATION,
00133                 JES_DEBUG_INFO
00134         } Severity_t;
00135 
00136         typedef enum {
00137                 JEVT_NUMBER = 1,
00138                 JEVT_STRING,
00139                 JEVT_EXCEPTION
00140         } ViewerType_t;
00141 
00142         std::string     Guid;
00143         uint64_t        MSTimestamp;    // time_t in milliseconds
00144         Severity_t      Severity;
00145         ViewerType_t    Type;
00146         std::string     App;
00147         std::string     Data;
00148 
00149 protected:
00150         static Severity_t SeverityProto2Rec(unsigned int s);
00151         static unsigned int SeverityRec2Proto(Severity_t s);
00152 
00153         static ViewerType_t ViewerTypeProto2Rec(unsigned int v);
00154         static unsigned int ViewerTypeRec2Proto(ViewerType_t v);
00155 
00156 public:
00157         void Parse(uint16_t size, const char* str);
00158 
00159         std::string GetFormattedTimestamp() const;
00160 
00161         void Dump(std::ostream &os) const;
00162 };
00163 
00164 
00165 class BXEXPORT JLDeviceInfo
00166 {
00167 public:
00168         struct VersionQuad {
00169                 VersionQuad() { }
00170                 VersionQuad(uint32_t v) {
00171                         Major = (v & 0xff000000) >> 24;
00172                         Minor = (v & 0xff0000) >> 16;
00173                         SubMinor = (v & 0xff00) >> 8;
00174                         Build = (v & 0xff);
00175                 }
00176 
00177                 unsigned int Major;
00178                 unsigned int Minor;
00179                 unsigned int SubMinor;
00180                 unsigned int Build;
00181         };
00182 
00183 public:
00184         uint32_t        HardwareId;
00185         struct Pin      Pin;
00186         VersionQuad     OsVersion;
00187         VersionQuad     VmVersion;
00188         uint32_t        RadioId;
00189         uint32_t        VendorId;
00190         uint32_t        ActiveWafs;
00191         Data            OsMetrics;
00192         Data            BootromMetrics;
00193 
00194 public:
00195         void Dump(std::ostream &os) const;
00196 };
00197 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDeviceInfo &info) {
00198         info.Dump(os);
00199         return os;
00200 }
00201 
00202 
00203 namespace Mode {
00204 
00205 //
00206 // JavaLoader class
00207 //
00208 /// The main interface class to the java program loader protocol
00209 ///
00210 /// To use this class, use the following steps:
00211 ///
00212 ///     - Create a Controller object (see Controller class for more details)
00213 ///     - Create this Mode::JavaLoader object, passing in the Controller
00214 ///             object during construction
00215 ///     - Call Open() to open database socket and finish constructing.
00216 ///     - Call LoadDatabase() to retrieve and store a database
00217 ///
00218 class BXEXPORT JavaLoader : public Mode
00219 {
00220 private:
00221         bool m_StreamStarted;
00222 
00223 protected:
00224         void GetDirectoryEntries(JLPacket &packet, uint8_t entry_cmd,
00225                 JLDirectory &dir, bool include_subdirs);
00226         void GetDir(JLPacket &packet, uint8_t entry_cmd, JLDirectory &dir,
00227                 bool include_subdirs);
00228         void ThrowJLError(const std::string &msg, uint8_t cmd);
00229         void DoErase(uint8_t cmd, const std::string &cod_name);
00230         void SaveData(JLPacket &packet, uint16_t, CodFileBuilder &builder,
00231                 std::ostream &output);
00232 
00233         //////////////////////////////////
00234         // overrides
00235 
00236         virtual void OnOpen();
00237 
00238 public:
00239         JavaLoader(Controller &con);
00240         ~JavaLoader();
00241 
00242         //////////////////////////////////
00243         // API
00244         void StartStream();
00245         bool StopStream();
00246 
00247         // mid-stream operations
00248         void SendStream(std::istream &input, size_t module_size);
00249         void LoadApp(std::istream &input);
00250         void SetTime(time_t when);
00251         void GetDirectory(JLDirectory &dir, bool include_subdirs);
00252         void GetScreenshot(JLScreenInfo &info, Data &image);
00253         void Erase(const std::string &cod_name);
00254         void ForceErase(const std::string &cod_name);
00255         void GetEventlog(JLEventlog &log);
00256         void ClearEventlog();
00257         void Save(const std::string &cod_name, std::ostream &output);
00258         void DeviceInfo(JLDeviceInfo &info);
00259         void Wipe(bool apps = true, bool fs = true);
00260         void LogStackTraces();
00261         void ResetToFactory();
00262 };
00263 
00264 }} // namespace Barry::Mode
00265 
00266 #endif
00267