#pragma once #include #include #include void ObpPlus( int step = 1 ); class UserProc; class Schedule { public: enum Type { None = 10000, GlobalVar, // グローバル変数スケジュール DataTable, // データテーブル スケジュール Relocation, // リロケーション情報スケジュール UserProc, // ユーザ定義関数呼び出し側スケジュール AddressOf, // ユーザ定義関数位置スケジュール DllProc, // DLL関数位置スケジュール }; private: Type type; long offset; union{ LONG_PTR lpValue; const ::UserProc *pUserProc; const ::DllProc *pDllProc; }; // XMLシリアライズ用 private: friend class boost::serialization::access; template void serialize(Archive& ar, const unsigned int version) { trace_for_serialize( "serializing - Schedule" ); ar & BOOST_SERIALIZATION_NVP( type ); ar & BOOST_SERIALIZATION_NVP( offset ); } public: Schedule() { } Schedule( Type type, long offset ) : type( type ) , offset( offset ) , lpValue( 0 ) { } Schedule( const ::UserProc *pUserProc, long offest ) : type( Schedule::UserProc ) , offset( offset ) , pUserProc( pUserProc ) { } Schedule( const ::DllProc *pDllProc, long offest ) : type( Schedule::DllProc ) , offset( offset ) , pDllProc( pDllProc ) { } ~Schedule() { } Type GetType() const { return type; } long GetOffset() const { return offset; } const ::DllProc &GetDllProc() const { if( type != Schedule::DllProc ) { SetError(); } return *pDllProc; } const ::UserProc &GetUserProc() const { if( type != Schedule::UserProc ) { SetError(); } return *pUserProc; } void SpecifyAddressOf() { if( type != Schedule::UserProc ) { SetError(); } type = Schedule::AddressOf; } }; typedef std::vector Schedules; class NativeCode { int allocateSize; char *codeBuffer; int size; Schedules schedules; // XMLシリアライズ用 private: friend class boost::serialization::access; BOOST_SERIALIZATION_SPLIT_MEMBER(); template void load(Archive& ar, const unsigned int version) { trace_for_serialize( "serializing(load) - NativeCode" ); std::string code; ar & BOOST_SERIALIZATION_NVP( code ); ar & BOOST_SERIALIZATION_NVP( size ); ar & BOOST_SERIALIZATION_NVP( schedules ); // 読み込み後の処理 Realloc( size ); for( int i=0; i void save(Archive& ar, const unsigned int version) const { trace_for_serialize( "serializing(save) - NativeCode" ); // 保存準備 char *tempCode = (char *)calloc( (size+1) * 3, 1 ); for( int i=0; icodeBuffer+codePos); } long _GetLong_ObpOld( int _obpOld ) const { extern char *OpBuffer; return *(long *)(OpBuffer+_obpOld); } void Overwrite( int codePos, char c ) { codeBuffer[codePos] = c; } void OverwriteOld( int _obpOld, char c ) { // 未完成 extern char *OpBuffer; OpBuffer[_obpOld] = c; } void Overwrite( int codePos, long newLongValue ) { *(long *)(this->codeBuffer+codePos) = newLongValue; } void OverwriteOld( int _obpOld, long newLongValue ) { // 未完成 extern char *OpBuffer; *(long *)(OpBuffer+_obpOld) = newLongValue; } void Put( const char *codeBuffer, int size ) { Realloc( this->size + size ); memcpy( this->codeBuffer + this->size, codeBuffer, size ); this->size += size; // 未完成 extern char *OpBuffer; extern int obp; memcpy( OpBuffer + obp, codeBuffer, size ); ObpPlus( size ); } void Put( const NativeCode &nativeCode ); void Put( _int64 i64data ) { Put( (const char *)(&i64data), sizeof(_int64) ); } void Put( long l, Schedule::Type scheduleType = Schedule::None ) { if( scheduleType != Schedule::None ) { schedules.push_back( Schedule( scheduleType, size ) ); } *((long *)(codeBuffer+size))=l; size += sizeof(long); // 未完成 switch( scheduleType ) { case Schedule::None: // 何もしない break; case Schedule::GlobalVar: extern CSchedule *pobj_GlobalVarSchedule; pobj_GlobalVarSchedule->add(); break; case Schedule::DataTable: extern CSchedule *pobj_DataTableSchedule; pobj_DataTableSchedule->add(); break; case Schedule::Relocation: // 未完成 break; default: Jenga::Throw( "scheduleTypeが無効な値を保持している" ); break; } extern char *OpBuffer; extern int obp; *((long *)(OpBuffer+obp))=l; ObpPlus( sizeof(long) ); } void PutUserProcSchedule( const UserProc *pUserProc, bool isCall ); void PutDllProcSchedule( const DllProc *pDllProc ); void Put( short s ) { Put( (const char *)(&s), sizeof(short) ); } void Put( char c ) { Realloc( size + 1 ); codeBuffer[size++] = c; // 未完成 extern char *OpBuffer; extern int obp; OpBuffer[obp]=c; ObpPlus(); } };