Changeset 75 in dev for BasicCompiler32/MakePeHdr.cpp
- Timestamp:
- Mar 20, 2007, 4:36:16 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler32/MakePeHdr.cpp
r73 r75 8 8 // 特殊関数の構造体ポインタ 9 9 //////////////////////////// 10 SubInfo 10 UserProc 11 11 *pSub_System_StartupProgram, 12 12 *pSub_DebugSys_StartProc, … … 150 150 151 151 //関数ポインタ情報を初期化 152 extern P ROCPTRINFO *pProcPtrInfo;152 extern ProcPointer **ppProcPtrInfo; 153 153 extern int ProcPtrInfoNum; 154 p ProcPtrInfo=(PROCPTRINFO*)HeapAlloc(hHeap,0,1);154 ppProcPtrInfo=(ProcPointer **)HeapAlloc(hHeap,0,1); 155 155 ProcPtrInfoNum=0; 156 156 … … 184 184 185 185 if(pSub_System_StartupProgram=GetSubHash("_System_StartupProgram",1)) 186 pSub_System_StartupProgram-> bUse=1;186 pSub_System_StartupProgram->Using(); 187 187 188 188 if(pSub_DebugSys_StartProc=GetSubHash("_DebugSys_StartProc",1)) 189 pSub_DebugSys_StartProc-> bUse=1;189 pSub_DebugSys_StartProc->Using(); 190 190 191 191 if(pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc",1)) 192 pSub_DebugSys_EndProc-> bUse=1;192 pSub_DebugSys_EndProc->Using(); 193 193 194 194 if(pSub_DebugSys_SaveContext=GetSubHash("_DebugSys_SaveContext",1)) 195 pSub_DebugSys_SaveContext-> bUse=1;195 pSub_DebugSys_SaveContext->Using(); 196 196 197 197 if(pSub_System_GetEip=GetSubHash("_System_GetEip",1)){ 198 pSub_System_GetEip-> bUse=1;199 pSub_System_GetEip-> bSystem=1;198 pSub_System_GetEip->Using(); 199 pSub_System_GetEip->ThisIsSystemProc(); 200 200 } 201 201 202 202 if(pSub_System_InitDllGlobalVariables=GetSubHash("_System_InitDllGlobalVariables",1)){ 203 pSub_System_InitDllGlobalVariables-> bUse=1;204 pSub_System_InitDllGlobalVariables-> bSystem=1;203 pSub_System_InitDllGlobalVariables->Using(); 204 pSub_System_InitDllGlobalVariables->ThisIsSystemProc(); 205 205 } 206 206 207 207 if(pSub_System_InitStaticLocalVariables=GetSubHash("_System_InitStaticLocalVariables",1)){ 208 pSub_System_InitStaticLocalVariables-> bUse=1;209 pSub_System_InitStaticLocalVariables-> bSystem=1;208 pSub_System_InitStaticLocalVariables->Using(); 209 pSub_System_InitStaticLocalVariables->ThisIsSystemProc(); 210 210 } 211 211 212 212 if(pSub_System_Call_Destructor_of_GlobalObject=GetSubHash("_System_Call_Destructor_of_GlobalObject",1)){ 213 pSub_System_Call_Destructor_of_GlobalObject-> bUse=1;214 pSub_System_Call_Destructor_of_GlobalObject-> bSystem=1;213 pSub_System_Call_Destructor_of_GlobalObject->Using(); 214 pSub_System_Call_Destructor_of_GlobalObject->ThisIsSystemProc(); 215 215 } 216 216 217 217 if(pSub_System_GetSp=GetSubHash("_System_GetSp",1)){ 218 pSub_System_GetSp-> bUse=1;219 pSub_System_GetSp-> bSystem=1;218 pSub_System_GetSp->Using(); 219 pSub_System_GetSp->ThisIsSystemProc(); 220 220 } 221 221 222 222 if(pSub_pow=GetSubHash("pow",1)) 223 pSub_pow-> bUse=1;223 pSub_pow->Using(); 224 224 225 225 if(pSub_calloc=GetSubHash("calloc",1)) 226 pSub_calloc-> bUse=1;226 pSub_calloc->Using(); 227 227 228 228 if(pSub_realloc=GetSubHash("realloc",1)) 229 pSub_realloc-> bUse=1;229 pSub_realloc->Using(); 230 230 231 231 if(pSub_free=GetSubHash("free",1)) 232 pSub_free-> bUse=1;232 pSub_free->Using(); 233 233 234 234 if( pSub_System_GC_malloc_ForObject = GetSubHash( "_System_GC_malloc_ForObject",1 ) ) 235 pSub_System_GC_malloc_ForObject-> bUse = 1;235 pSub_System_GC_malloc_ForObject->Using(); 236 236 237 237 if( pSub_System_GC_malloc_ForObjectPtr = GetSubHash( "_System_GC_malloc_ForObjectPtr",1 ) ) 238 pSub_System_GC_malloc_ForObjectPtr-> bUse = 1;238 pSub_System_GC_malloc_ForObjectPtr->Using(); 239 239 240 240 if( pSub_System_GC_free_for_SweepingDelete = GetSubHash( "_System_GC_free_for_SweepingDelete",1 ) ) 241 pSub_System_GC_free_for_SweepingDelete-> bUse = 1;241 pSub_System_GC_free_for_SweepingDelete->Using(); 242 242 243 243 pSub_allrem=GetSubHash("_allrem"); 244 pSub_allrem-> bUse=1;245 pSub_allrem-> bSystem=1;244 pSub_allrem->Using(); 245 pSub_allrem->ThisIsSystemProc(); 246 246 247 247 pSub_aullrem=GetSubHash("_aullrem"); 248 pSub_aullrem-> bUse=1;249 pSub_aullrem-> bSystem=1;248 pSub_aullrem->Using(); 249 pSub_aullrem->ThisIsSystemProc(); 250 250 251 251 pSub_allmul=GetSubHash("_allmul"); 252 pSub_allmul-> bUse=1;253 pSub_allmul-> bSystem=1;252 pSub_allmul->Using(); 253 pSub_allmul->ThisIsSystemProc(); 254 254 255 255 pSub_alldiv=GetSubHash("_alldiv"); 256 pSub_alldiv-> bUse=1;257 pSub_alldiv-> bSystem=1;256 pSub_alldiv->Using(); 257 pSub_alldiv->ThisIsSystemProc(); 258 258 259 259 pSub_aulldiv=GetSubHash("_aulldiv"); 260 pSub_aulldiv-> bUse=1;261 pSub_aulldiv-> bSystem=1;260 pSub_aulldiv->Using(); 261 pSub_aulldiv->ThisIsSystemProc(); 262 262 263 263 pSub_allshl=GetSubHash("_allshl"); 264 pSub_allshl-> bUse=1;265 pSub_allshl-> bSystem=1;264 pSub_allshl->Using(); 265 pSub_allshl->ThisIsSystemProc(); 266 266 267 267 pSub_allshr=GetSubHash("_allshr"); 268 pSub_allshr-> bUse=1;269 pSub_allshr-> bSystem=1;268 pSub_allshr->Using(); 269 pSub_allshr->ThisIsSystemProc(); 270 270 271 271 pSub_aullshr=GetSubHash("_aullshr"); 272 pSub_aullshr-> bUse=1;273 pSub_aullshr-> bSystem=1;272 pSub_aullshr->Using(); 273 pSub_aullshr->ThisIsSystemProc(); 274 274 275 275 pSub_esp_error=GetSubHash("_esp_error"); 276 pSub_esp_error-> bUse=1;276 pSub_esp_error->Using(); 277 277 278 278 … … 391 391 392 392 //call _System_Call_Destructor_of_GlobalObject 393 extern SubInfo*pSub_System_Call_Destructor_of_GlobalObject;393 extern UserProc *pSub_System_Call_Destructor_of_GlobalObject; 394 394 op_call(pSub_System_Call_Destructor_of_GlobalObject); 395 395 … … 425 425 for(i=0;i<SynonymErrorNum;i++) HeapDefaultFree(SynonymErrorWords[i]); 426 426 HeapDefaultFree(SynonymErrorWords); 427 SynonymErrorWords=0; 427 428 428 429 … … 451 452 //////////////////////////////// 452 453 for(i=0;i<MAX_HASH;i++){ 453 extern DECLAREINFO **ppDeclareHash; 454 DECLAREINFO *pdi; 455 pdi=ppDeclareHash[i]; 456 while(pdi){ 457 if(pdi->bUse==0){ 458 pdi=pdi->pNextData; 454 extern DllProc **ppDeclareHash; 455 const DllProc *pDllProc = ppDeclareHash[i]; 456 while(pDllProc){ 457 if( !pDllProc->IsUsing() ){ 458 pDllProc=pDllProc->pNextData; 459 459 continue; 460 460 } … … 462 462 //エラーチェック 463 463 HINSTANCE hLib; 464 hLib=LoadLibrary( pdi->file);464 hLib=LoadLibrary( pDllProc->GetDllFileName().c_str() ); 465 465 if(!hLib){ 466 466 extern char OutputFileName[MAX_PATH]; … … 468 468 _splitpath(OutputFileName,temp2,temp3,NULL,NULL); 469 469 lstrcat(temp2,temp3); 470 lstrcpy(temp3,p di->file);470 lstrcpy(temp3,pDllProc->GetDllFileName().c_str()); 471 471 GetFullPath(temp3,temp2); 472 472 hLib=LoadLibrary(temp3); 473 473 474 474 if(!hLib){ 475 SetError(-106,p di->file,pdi->pos);475 SetError(-106,pDllProc->GetDllFileName().c_str(),pDllProc->GetCodePos()); 476 476 } 477 477 } 478 478 479 479 if(hLib){ 480 if(!GetProcAddress(hLib,p di->alias)){480 if(!GetProcAddress(hLib,pDllProc->GetAlias().c_str())){ 481 481 FreeLibrary(hLib); 482 SetError(-107,p di->alias,pdi->pos);482 SetError(-107,pDllProc->GetAlias(),pDllProc->GetCodePos()); 483 483 } 484 484 FreeLibrary(hLib); 485 485 } 486 486 487 p di=pdi->pNextData;487 pDllProc=pDllProc->pNextData; 488 488 } 489 489 } … … 522 522 ExportNamesLength=lstrlen(lpExportNames)+1; 523 523 524 extern SubInfo**ppSubHash;525 SubInfo *psi,*psi2;524 extern UserProc **ppSubHash; 525 UserProc *pUserProc,*psi2; 526 526 while(1){ 527 527 //辞書順にサーチ 528 528 temporary[0]=0; 529 529 for(i=0,psi2=0;i<MAX_HASH;i++){ 530 p si=ppSubHash[i];531 while(p si){532 if(p si->bExport){530 pUserProc=ppSubHash[i]; 531 while(pUserProc){ 532 if(pUserProc->IsExport()){ 533 533 if(temporary[0]=='\0'){ 534 lstrcpy(temporary,p si->name);535 psi2=p si;534 lstrcpy(temporary,pUserProc->GetName().c_str()); 535 psi2=pUserProc; 536 536 } 537 537 else{ 538 538 i3=lstrlen(temporary); 539 i4= lstrlen(psi->name);539 i4=(int)pUserProc->GetName().size(); 540 540 if(i3<i4) i3=i4; 541 if(memcmp(temporary,p si->name,i3)>0){542 lstrcpy(temporary,p si->name);543 psi2=p si;541 if(memcmp(temporary,pUserProc->GetName().c_str(),i3)>0){ 542 lstrcpy(temporary,pUserProc->GetName().c_str()); 543 psi2=pUserProc; 544 544 } 545 545 } 546 546 } 547 p si=psi->pNextData;547 pUserProc=pUserProc->pNextData; 548 548 } 549 549 } 550 550 if(psi2==0) break; 551 psi=psi2; 552 553 psi->bExport=0; 554 555 if(lstrcmpi(psi->name,"DllMain")==0) 556 DllMain_EntryPoint=psi->CompileAddress; 551 pUserProc=psi2; 552 553 pUserProc->ExportOff(); 554 555 if( pUserProc->GetName() == "DllMain" ){ 556 DllMain_EntryPoint=pUserProc->beginOpAddress; 557 } 557 558 558 559 lpdwExportAddressTable=(DWORD *)HeapReAlloc(hHeap,0,lpdwExportAddressTable,(ExportNum+1)*sizeof(DWORD)); 559 lpdwExportAddressTable[ExportNum]=p si->CompileAddress;560 lpdwExportAddressTable[ExportNum]=pUserProc->beginOpAddress; 560 561 561 562 lpdwExportNamePointerTable=(DWORD *)HeapReAlloc(hHeap,0,lpdwExportNamePointerTable,(ExportNum+1)*sizeof(DWORD)); … … 565 566 lpwExportOrdinalTable[ExportNum]=ExportNum; 566 567 567 lstrcpy(lpExportNames+ExportNamesLength,p si->name);568 lstrcpy(lpExportNames+ExportNamesLength,pUserProc->GetName().c_str()); 568 569 ExportNamesLength+=lstrlen(lpExportNames+ExportNamesLength)+1; 569 570 … … 598 599 //インポートDLL情報 599 600 ///////////////////// 600 extern DECLAREINFO **ppDeclareHash; 601 DECLAREINFO *pdi; 601 extern DllProc **ppDeclareHash; 602 602 char **ppDllNames; 603 603 int ImportDllNum; … … 621 621 ImportDllNum=0; 622 622 for(i=0;i<MAX_HASH;i++){ 623 pdi=ppDeclareHash[i]; 624 while(pdi){ 625 if(pdi->dwType==DECLARE_STATIC|| 626 pdi->bUse==0){ 627 pdi=pdi->pNextData; 623 const DllProc *pDllProc=ppDeclareHash[i]; 624 while(pDllProc){ 625 if( !pDllProc->IsUsing() ){ 626 pDllProc=pDllProc->pNextData; 628 627 continue; 629 628 } 630 629 631 if( lstrlen(pdi->file)>16){630 if( pDllProc->GetDllFileName().size() > 16 ){ 632 631 SetError(7,NULL,cp); 633 632 break; 634 633 } 635 634 for(i2=0;i2<ImportDllNum;i2++){ 636 if(lstrcmp(ppDllNames[i2],pdi->file)==0) break; 635 if( pDllProc->GetDllFileName() == ppDllNames[i2] ){ 636 break; 637 } 637 638 } 638 639 if(i2==ImportDllNum){ 639 640 ppDllNames=(char **)HeapReAlloc(hHeap,0,ppDllNames,(ImportDllNum+1)*sizeof(char **)); 640 641 ppDllNames[ImportDllNum]=(char *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,16); 641 lstrcpy(ppDllNames[ImportDllNum],p di->file);642 lstrcpy(ppDllNames[ImportDllNum],pDllProc->GetDllFileName().c_str()); 642 643 ImportDllNum++; 643 644 } 644 645 645 p di=pdi->pNextData;646 pDllProc=pDllProc->pNextData; 646 647 } 647 648 } … … 660 661 pImportTable[i].Name=i3+i*0x10; 661 662 for(i2=0;i2<MAX_HASH;i2++){ 662 pdi=ppDeclareHash[i2]; 663 while(pdi){ 664 if(pdi->dwType==DECLARE_STATIC|| 665 pdi->bUse==0){ 666 pdi=pdi->pNextData; 663 const DllProc *pDllProc=ppDeclareHash[i2]; 664 while(pDllProc){ 665 if( !pDllProc->IsUsing() ){ 666 pDllProc=pDllProc->pNextData; 667 667 continue; 668 668 } 669 669 670 if( lstrcmp(ppDllNames[i],pdi->file)==0){670 if( pDllProc->GetDllFileName() == ppDllNames[i] ){ 671 671 //ルックアップデータのサイズを追加 672 672 LookupSize+=sizeof(DWORD); 673 673 } 674 674 675 p di=pdi->pNextData;675 pDllProc=pDllProc->pNextData; 676 676 } 677 677 } … … 691 691 for(i=0,i5=0;i<ImportDllNum;i++){ 692 692 for(i2=0;i2<MAX_HASH;i2++){ 693 pdi=ppDeclareHash[i2]; 694 while(pdi){ 695 if(pdi->dwType==DECLARE_STATIC|| 696 pdi->bUse==0){ 697 pdi=pdi->pNextData; 693 DllProc *pDllProc=ppDeclareHash[i2]; 694 while(pDllProc){ 695 if( !pDllProc->IsUsing() ){ 696 pDllProc=pDllProc->pNextData; 698 697 continue; 699 698 } 700 699 701 if( lstrcmp(ppDllNames[i],pdi->file)==0){700 if( pDllProc->GetDllFileName() == ppDllNames[i] ){ 702 701 //ルックアップの位置をセット(後にインポート アドレス テーブルにセットしなおされる) 703 p di->LookupAddress=i3+(i5*sizeof(DWORD));702 pDllProc->SetLookupAddress( i3+(i5*sizeof(DWORD)) ); 704 703 705 704 //ルックアップ テーブル … … 709 708 pHintTable[HintSize++]=0; 710 709 pHintTable[HintSize++]=0; 711 lstrcpy(pHintTable+HintSize,p di->alias);712 i4= lstrlen(pdi->alias);710 lstrcpy(pHintTable+HintSize,pDllProc->GetAlias().c_str()); 711 i4=(int)pDllProc->GetAlias().size(); 713 712 HintSize+=i4+1; 714 713 if(i4%2==0) pHintTable[HintSize++]=0; … … 720 719 } 721 720 722 p di=pdi->pNextData;721 pDllProc=pDllProc->pNextData; 723 722 } 724 723 } … … 993 992 994 993 for(i2=0;i2<MAX_HASH;i2++){ 995 pdi=ppDeclareHash[i2];996 while(p di){997 if( pdi->bUse==0){998 p di=pdi->pNextData;994 const DllProc *pDllProc=ppDeclareHash[i2]; 995 while(pDllProc){ 996 if( !pDllProc->IsUsing() ){ 997 pDllProc=pDllProc->pNextData; 999 998 continue; 1000 999 } 1001 1000 1002 if( lstrcmp(ppDllNames[i],pdi->file)==0){1001 if( pDllProc->GetDllFileName() == ppDllNames[i] ){ 1003 1002 //ルックアップ テーブル 1004 1003 pLookupTable[i5++]+=MemPos_ImportSection; 1005 1004 } 1006 1005 1007 p di=pdi->pNextData;1006 pDllProc=pDllProc->pNextData; 1008 1007 } 1009 1008 } … … 1028 1027 // インポートテーブルスケジュール(インポート アドレス テーブルを指し示させる) 1029 1028 for(i=0;i<pobj_ImportAddrSchedule->num;i++){ 1030 DECLAREINFO *pdi; 1031 pdi=pobj_ImportAddrSchedule->ppdi[i]; 1029 const DllProc *pDllProc=pobj_ImportAddrSchedule->ppdi[i]; 1032 1030 *((long *)(OpBuffer+pobj_ImportAddrSchedule->pObpValues[i]))= 1033 1031 ImageBase+ … … 1035 1033 LookupSize+ //ルックアップテーブル 1036 1034 HintSize+ //ヒント名(関数名)テーブル 1037 p di->LookupAddress;1035 pDllProc->GetLookupAddress(); 1038 1036 } 1039 1037 delete pobj_ImportAddrSchedule; … … 1043 1041 // プロシージャポインタスケジュール 1044 1042 for(i=0;i<pobj_SubAddrSchedule->num;i++){ 1045 if(pobj_SubAddrSchedule->ppsi[i]-> CompileAddress==01046 &&pobj_SubAddrSchedule->ppsi[i]-> EndOpAddr==0){1043 if(pobj_SubAddrSchedule->ppsi[i]->beginOpAddress==0 1044 &&pobj_SubAddrSchedule->ppsi[i]->endOpAddress==0){ 1047 1045 SetError(300,NULL,-1); 1048 1046 } … … 1050 1048 if(pobj_SubAddrSchedule->pbCall[i]){ 1051 1049 *((long *)(OpBuffer+pobj_SubAddrSchedule->pObpValues[i]))= 1052 pobj_SubAddrSchedule->ppsi[i]-> CompileAddress-(pobj_SubAddrSchedule->pObpValues[i]+sizeof(long));1050 pobj_SubAddrSchedule->ppsi[i]->beginOpAddress-(pobj_SubAddrSchedule->pObpValues[i]+sizeof(long)); 1053 1051 } 1054 1052 else{ 1055 1053 *((long *)(OpBuffer+pobj_SubAddrSchedule->pObpValues[i]))= 1056 pobj_SubAddrSchedule->ppsi[i]-> CompileAddress+ImageBase+MemPos_CodeSection;1054 pobj_SubAddrSchedule->ppsi[i]->beginOpAddress+ImageBase+MemPos_CodeSection; 1057 1055 } 1058 1056 }
Note:
See TracChangeset
for help on using the changeset viewer.