| 1 | #include "stdafx.h"
 | 
|---|
| 2 | 
 | 
|---|
| 3 | #include <Compiler.h>
 | 
|---|
| 4 | 
 | 
|---|
| 5 | #define BREAK_EIP(checkEip)  (obp+0x00401000>=checkEip)
 | 
|---|
| 6 | 
 | 
|---|
| 7 | void NativeCode::Put( const NativeCode &nativeCode )
 | 
|---|
| 8 | {
 | 
|---|
| 9 |     long baseOffset = size;
 | 
|---|
| 10 | 
 | 
|---|
| 11 |     // コードバッファを追加
 | 
|---|
| 12 |     Put( nativeCode.codeBuffer, nativeCode.size );
 | 
|---|
| 13 | 
 | 
|---|
| 14 |     // スケジュールを追加
 | 
|---|
| 15 |     BOOST_FOREACH( const Schedule &schedule, nativeCode.schedules )
 | 
|---|
| 16 |     {
 | 
|---|
| 17 |         this->schedules.push_back(
 | 
|---|
| 18 |             Schedule(
 | 
|---|
| 19 |                 schedule.GetType(),
 | 
|---|
| 20 |                 baseOffset + schedule.GetOffset(),
 | 
|---|
| 21 |                 schedule.GetLongPtrValue()
 | 
|---|
| 22 |             )
 | 
|---|
| 23 |         );
 | 
|---|
| 24 |     }
 | 
|---|
| 25 | 
 | 
|---|
| 26 |     // ソースコード行番号とネイティブコード位置の対応情報を追加
 | 
|---|
| 27 |     BOOST_FOREACH( const SourceLine &sourceLine, nativeCode.sourceLines )
 | 
|---|
| 28 |     {
 | 
|---|
| 29 |         this->sourceLines.push_back(
 | 
|---|
| 30 |             SourceLine(
 | 
|---|
| 31 |                 sourceLine.GetLineNum(),
 | 
|---|
| 32 |                 baseOffset + sourceLine.GetNativeCodePos(),
 | 
|---|
| 33 |                 sourceLine.GetSourceIndex(),
 | 
|---|
| 34 |                 sourceLine.GetSourceCodePos(),
 | 
|---|
| 35 |                 sourceLine.GetCodeType()
 | 
|---|
| 36 |             )
 | 
|---|
| 37 |         );
 | 
|---|
| 38 |     }
 | 
|---|
| 39 | }
 | 
|---|
| 40 | 
 | 
|---|
| 41 | void NativeCode::PutUserProcSchedule( const UserProc *pUserProc, bool isCall )
 | 
|---|
| 42 | {
 | 
|---|
| 43 |     pUserProc->Using();
 | 
|---|
| 44 | 
 | 
|---|
| 45 |     Schedule schedule( pUserProc, size );
 | 
|---|
| 46 |     if( isCall == false )
 | 
|---|
| 47 |     {
 | 
|---|
| 48 |         schedule.SpecifyAddressOf();
 | 
|---|
| 49 |     }
 | 
|---|
| 50 |     schedules.push_back( schedule );
 | 
|---|
| 51 | 
 | 
|---|
| 52 |     *((long *)(codeBuffer+size))=0;
 | 
|---|
| 53 |     size += sizeof(long);
 | 
|---|
| 54 | }
 | 
|---|
| 55 | 
 | 
|---|
| 56 | void NativeCode::PutDllProcSchedule( const DllProc *pDllProc )
 | 
|---|
| 57 | {
 | 
|---|
| 58 |     pDllProc->Using();
 | 
|---|
| 59 | 
 | 
|---|
| 60 |     schedules.push_back( Schedule( pDllProc, size ) );
 | 
|---|
| 61 | 
 | 
|---|
| 62 |     *((long *)(codeBuffer+size))=0;
 | 
|---|
| 63 |     size += sizeof(long);
 | 
|---|
| 64 | }
 | 
|---|
| 65 | 
 | 
|---|
| 66 | void NativeCode::NextSourceLine()
 | 
|---|
| 67 | {
 | 
|---|
| 68 |     if( sourceLines.size() )
 | 
|---|
| 69 |     {
 | 
|---|
| 70 |         if( sourceLines.back().GetNativeCodePos() == size )
 | 
|---|
| 71 |         {
 | 
|---|
| 72 |             sourceLines.back().SetSourceCodePos( cp );
 | 
|---|
| 73 |             return;
 | 
|---|
| 74 |         }
 | 
|---|
| 75 |     }
 | 
|---|
| 76 | 
 | 
|---|
| 77 |     extern BOOL bDebugSupportProc;
 | 
|---|
| 78 |     extern BOOL bSystemProc;
 | 
|---|
| 79 |     DWORD sourceLineType = 0;
 | 
|---|
| 80 |     if( bDebugSupportProc )
 | 
|---|
| 81 |     {
 | 
|---|
| 82 |         sourceLineType |= CODETYPE_DEBUGPROC;
 | 
|---|
| 83 |     }
 | 
|---|
| 84 |     if( bSystemProc )
 | 
|---|
| 85 |     {
 | 
|---|
| 86 |         sourceLineType |= CODETYPE_SYSTEMPROC;
 | 
|---|
| 87 |     }
 | 
|---|
| 88 |     sourceLines.push_back(
 | 
|---|
| 89 |         SourceLine(
 | 
|---|
| 90 |             (long)sourceLines.size(),
 | 
|---|
| 91 |             size,
 | 
|---|
| 92 |             compiler.GetObjectModule().GetCurrentSourceIndex(),
 | 
|---|
| 93 |             cp,
 | 
|---|
| 94 |             sourceLineType
 | 
|---|
| 95 |         )
 | 
|---|
| 96 |     );
 | 
|---|
| 97 | }
 | 
|---|
| 98 | 
 | 
|---|
| 99 | void NativeCode::ResetDataSectionBaseOffset( long dataSectionBaseOffset )
 | 
|---|
| 100 | {
 | 
|---|
| 101 |     BOOST_FOREACH( const Schedule &schedule, schedules )
 | 
|---|
| 102 |     {
 | 
|---|
| 103 |         if( schedule.GetType() == Schedule::DataTable )
 | 
|---|
| 104 |         {
 | 
|---|
| 105 |             Overwrite(
 | 
|---|
| 106 |                 schedule.GetOffset(),
 | 
|---|
| 107 |                 GetLong( schedule.GetOffset() ) + dataSectionBaseOffset
 | 
|---|
| 108 |             );
 | 
|---|
| 109 |         }
 | 
|---|
| 110 |     }
 | 
|---|
| 111 | }
 | 
|---|
| 112 | void NativeCode::ResetSourceIndexes( long sourceIndexBase )
 | 
|---|
| 113 | {
 | 
|---|
| 114 |     BOOST_FOREACH( SourceLine &sourceLine, sourceLines )
 | 
|---|
| 115 |     {
 | 
|---|
| 116 |         sourceLine.SetSourceIndex( sourceLine.GetSourceIndex() + sourceIndexBase );
 | 
|---|
| 117 |     }
 | 
|---|
| 118 | }
 | 
|---|