[232] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[237] | 3 | #define BREAK_EIP(checkEip) (obp+0x00401000>=checkEip)
|
---|
[232] | 4 |
|
---|
[465] | 5 | const ::DllProc &Schedule::GetDllProc() const
|
---|
| 6 | {
|
---|
[549] | 7 | _ASSERT( type == Schedule::DllProc );
|
---|
[465] | 8 | return *pDllProc;
|
---|
| 9 | }
|
---|
| 10 | const ::UserProc &Schedule::GetUserProc() const
|
---|
| 11 | {
|
---|
[549] | 12 | _ASSERT( type == Schedule::UserProc || type == Schedule::AddressOf || type == Schedule::CatchAddress );
|
---|
[465] | 13 | return *pUserProc;
|
---|
| 14 | }
|
---|
| 15 | const ::CClass &Schedule::GetClass() const
|
---|
| 16 | {
|
---|
[549] | 17 | _ASSERT( type == Schedule::ComVtbl || type == Schedule::Vtbl || type == Schedule::TypeInfo );
|
---|
[465] | 18 | return *pClass;
|
---|
| 19 | }
|
---|
| 20 |
|
---|
[639] | 21 | bool Schedule::Resolve( const ObjectModule &resolver )
|
---|
| 22 | {
|
---|
| 23 | switch( type )
|
---|
| 24 | {
|
---|
| 25 | case UserProc:
|
---|
| 26 | case AddressOf:
|
---|
| 27 | case CatchAddress:
|
---|
| 28 | if( pUserProc->IsNeedResolve() )
|
---|
| 29 | {
|
---|
| 30 | pUserProc = resolver.meta.GetUserProcs().FindLike( pUserProc );
|
---|
| 31 | }
|
---|
| 32 | break;
|
---|
| 33 | case DllProc:
|
---|
| 34 | if( pDllProc->IsNeedResolve() )
|
---|
| 35 | {
|
---|
| 36 | pDllProc = resolver.meta.GetDllProcs().FindLike( pDllProc );
|
---|
| 37 | }
|
---|
| 38 | break;
|
---|
| 39 | case ComVtbl:
|
---|
| 40 | case Vtbl:
|
---|
| 41 | case TypeInfo:
|
---|
| 42 | if( pClass->IsNeedResolve() )
|
---|
| 43 | {
|
---|
| 44 | pClass = resolver.meta.GetClasses().FindLike( pClass );
|
---|
| 45 | }
|
---|
| 46 | break;
|
---|
| 47 | default:
|
---|
| 48 | break;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | return true;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[287] | 54 | void NativeCode::PutEx( const NativeCode &nativeCode )
|
---|
[232] | 55 | {
|
---|
[287] | 56 | long baseOffset = GetSize();
|
---|
[257] | 57 |
|
---|
[263] | 58 | // コードバッファを追加
|
---|
[287] | 59 | Put( nativeCode.GetBuffer(), nativeCode.GetSize() );
|
---|
[257] | 60 |
|
---|
[263] | 61 | // スケジュールを追加
|
---|
[257] | 62 | BOOST_FOREACH( const Schedule &schedule, nativeCode.schedules )
|
---|
| 63 | {
|
---|
| 64 | this->schedules.push_back(
|
---|
| 65 | Schedule(
|
---|
| 66 | schedule.GetType(),
|
---|
[258] | 67 | baseOffset + schedule.GetOffset(),
|
---|
| 68 | schedule.GetLongPtrValue()
|
---|
[257] | 69 | )
|
---|
| 70 | );
|
---|
| 71 | }
|
---|
[263] | 72 |
|
---|
| 73 | // ソースコード行番号とネイティブコード位置の対応情報を追加
|
---|
| 74 | BOOST_FOREACH( const SourceLine &sourceLine, nativeCode.sourceLines )
|
---|
| 75 | {
|
---|
| 76 | this->sourceLines.push_back(
|
---|
| 77 | SourceLine(
|
---|
| 78 | baseOffset + sourceLine.GetNativeCodePos(),
|
---|
[637] | 79 | sourceLine.GetCodeType(),
|
---|
| 80 | sourceLine.GetSourceCodePosition()
|
---|
[263] | 81 | )
|
---|
| 82 | );
|
---|
| 83 | }
|
---|
[257] | 84 | }
|
---|
| 85 |
|
---|
[357] | 86 | void NativeCode::PutEx( long l, Schedule::Type scheduleType )
|
---|
| 87 | {
|
---|
[551] | 88 | if( scheduleType != Schedule::None )
|
---|
[357] | 89 | {
|
---|
[551] | 90 | schedules.push_back( Schedule( scheduleType, GetSize() ) );
|
---|
[357] | 91 | }
|
---|
| 92 |
|
---|
[551] | 93 | Put( l );
|
---|
[357] | 94 | }
|
---|
| 95 |
|
---|
[245] | 96 | void NativeCode::PutUserProcSchedule( const UserProc *pUserProc, bool isCall )
|
---|
| 97 | {
|
---|
| 98 | pUserProc->Using();
|
---|
| 99 |
|
---|
[550] | 100 | Schedule::Type type = isCall ? Schedule::UserProc : Schedule::AddressOf;
|
---|
[245] | 101 |
|
---|
[550] | 102 | schedules.push_back( Schedule( type, pUserProc, GetSize() ) );
|
---|
| 103 |
|
---|
[287] | 104 | Put( (long)0 );
|
---|
[245] | 105 | }
|
---|
[250] | 106 |
|
---|
[357] | 107 | void NativeCode::PutCatchAddressSchedule( const UserProc *pUserProc, long codePos )
|
---|
| 108 | {
|
---|
| 109 | pUserProc->Using();
|
---|
| 110 |
|
---|
[550] | 111 | schedules.push_back( Schedule( Schedule::CatchAddress, pUserProc, GetSize() ) );
|
---|
[357] | 112 |
|
---|
| 113 | Put( codePos );
|
---|
| 114 | }
|
---|
| 115 |
|
---|
[250] | 116 | void NativeCode::PutDllProcSchedule( const DllProc *pDllProc )
|
---|
| 117 | {
|
---|
| 118 | pDllProc->Using();
|
---|
| 119 |
|
---|
[287] | 120 | schedules.push_back( Schedule( pDllProc, GetSize() ) );
|
---|
[250] | 121 |
|
---|
[287] | 122 | Put( (long)0 );
|
---|
[250] | 123 | }
|
---|
[263] | 124 |
|
---|
[370] | 125 | void NativeCode::PutComVtblSchedule( const CClass *pClass )
|
---|
| 126 | {
|
---|
| 127 | schedules.push_back( Schedule( Schedule::ComVtbl, pClass, GetSize() ) );
|
---|
| 128 |
|
---|
| 129 | Put( (long)0 );
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[282] | 132 | void NativeCode::PutVtblSchedule( const CClass *pClass )
|
---|
| 133 | {
|
---|
[370] | 134 | schedules.push_back( Schedule( Schedule::Vtbl, pClass, GetSize() ) );
|
---|
[282] | 135 |
|
---|
[287] | 136 | Put( (long)0 );
|
---|
[282] | 137 | }
|
---|
| 138 |
|
---|
[637] | 139 | void NativeCode::NextSourceLine( const SourceCodePosition &sourceCodePosition )
|
---|
[263] | 140 | {
|
---|
| 141 | if( sourceLines.size() )
|
---|
| 142 | {
|
---|
[287] | 143 | if( sourceLines.back().GetNativeCodePos() == GetSize() )
|
---|
[263] | 144 | {
|
---|
[637] | 145 | sourceLines.back().SetSourceCodePosition( sourceCodePosition );
|
---|
[263] | 146 | return;
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | extern BOOL bDebugSupportProc;
|
---|
| 151 | extern BOOL bSystemProc;
|
---|
| 152 | DWORD sourceLineType = 0;
|
---|
| 153 | if( bDebugSupportProc )
|
---|
| 154 | {
|
---|
| 155 | sourceLineType |= CODETYPE_DEBUGPROC;
|
---|
| 156 | }
|
---|
| 157 | if( bSystemProc )
|
---|
| 158 | {
|
---|
| 159 | sourceLineType |= CODETYPE_SYSTEMPROC;
|
---|
| 160 | }
|
---|
[280] | 161 | sourceLines.push_back(
|
---|
| 162 | SourceLine(
|
---|
[287] | 163 | GetSize(),
|
---|
[637] | 164 | sourceLineType,
|
---|
| 165 | sourceCodePosition
|
---|
[280] | 166 | )
|
---|
| 167 | );
|
---|
[263] | 168 | }
|
---|
[273] | 169 |
|
---|
| 170 | void NativeCode::ResetDataSectionBaseOffset( long dataSectionBaseOffset )
|
---|
| 171 | {
|
---|
| 172 | BOOST_FOREACH( const Schedule &schedule, schedules )
|
---|
| 173 | {
|
---|
| 174 | if( schedule.GetType() == Schedule::DataTable )
|
---|
| 175 | {
|
---|
| 176 | Overwrite(
|
---|
| 177 | schedule.GetOffset(),
|
---|
| 178 | GetLong( schedule.GetOffset() ) + dataSectionBaseOffset
|
---|
| 179 | );
|
---|
| 180 | }
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
[637] | 183 | void NativeCode::ResetRelationalObjectModuleIndex( const std::vector<int> &relationTable )
|
---|
[280] | 184 | {
|
---|
| 185 | BOOST_FOREACH( SourceLine &sourceLine, sourceLines )
|
---|
| 186 | {
|
---|
[637] | 187 | sourceLine.GetSourceCodePosition().SetRelationalObjectModuleIndex(
|
---|
| 188 | relationTable[sourceLine.GetSourceCodePosition().GetRelationalObjectModuleIndex()]
|
---|
| 189 | );
|
---|
[280] | 190 | }
|
---|
| 191 | }
|
---|
[637] | 192 |
|
---|
[639] | 193 | void NativeCode::Resolve( const ObjectModule &resolver )
|
---|
[637] | 194 | {
|
---|
[639] | 195 | BOOST_FOREACH( Schedule &schedule, schedules )
|
---|
| 196 | {
|
---|
| 197 | schedule.Resolve( resolver );
|
---|
| 198 | }
|
---|
[637] | 199 | }
|
---|