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