00001
00002
00003
00004
00005
00006 #ifndef __PATCH_C
00007 #define __PATCH_C
00008
00009 #include <rwKernel.hpp>
00010 #include <SymbolTable.hpp>
00011 #include <SystemMap.hpp>
00012 #include <stoi16.hpp>
00013 #include <itos16.hpp>
00014 #include <utility>
00015 #include <functional>
00016 #include <algorithm>
00017 #include <list>
00018 #include <fstream>
00019 #include <string>
00020 #include <name2add.h>
00021
00022
00023 typedef pair<unsigned int, unsigned int> Addr2Addr;
00024 typedef list<Addr2Addr *> Addr2AddrList;
00025
00026 Addr2AddrList *genReplaceValMap (SymbolTable *st);
00027 void genDummyValMap ();
00028 extern SystemMap DummyValMap;
00029
00030
00031 #define CLEAN 1
00032 #define LINKED 2
00033 #define APPLIED 4
00034 #define LFAILED 8
00035 #define AFAILED 16
00036
00037
00050 class Patch
00051 {
00052 private:
00053 int state;
00054 unsigned short len;
00055 unsigned char *back_data, *data, *overwr;
00056 unsigned int address;
00057 rwKernel *local_rw;
00058
00059 bool initObjects (unsigned char *, unsigned short, unsigned int, rwKernel *);
00060 string state2string ();
00061 void string2state (string);
00062 string data2string (unsigned char *);
00063 void string2data (string, unsigned char *);
00064 void parse (string);
00065
00066 public:
00070 Patch ();
00071
00078 Patch (unsigned char *data, unsigned short len, unsigned int addr);
00079
00085 Patch (unsigned char *data, unsigned short len, unsigned int addr, rwKernel *x);
00086
00091 Patch (string);
00092
00097 Patch (string, rwKernel *);
00098
00102 ~Patch ();
00103
00104
00108 void initFromString (string);
00109
00113 string getPatchAsString ();
00114
00119 bool wasChanged ();
00120
00124 bool isLinked ();
00125
00129 bool isApplied ();
00130
00134 bool isFailed ();
00135
00139 bool isClean ();
00140
00144 int getState ();
00145
00149 void restore ();
00150
00154 bool remove ();
00155
00159 bool remove (rwKernel *);
00160
00164 unsigned char *getData ();
00165
00171 void apply (rwKernel *);
00172
00177 void apply ();
00178
00182 void link (Addr2AddrList *);
00183
00192 void dump (string file);
00193
00197 friend istream& operator>> (istream&, Patch&);
00198
00202 friend ostream& operator<< (ostream&, Patch&);
00203 };
00204 #endif