mirror of
https://github.com/KolibriOS/kolibrios.git
synced 2024-12-24 07:36:48 +03:00
146 lines
3.8 KiB
Plaintext
146 lines
3.8 KiB
Plaintext
|
// ---- <20><>ନ<E0ACA8><E0AEA2><EFBFBD><EFBFBD> IMPORT ᥪ樨
|
|||
|
void DoLink()
|
|||
|
dword i,j,DirTable,AddrTable,dllName,apiName,byName,hold;
|
|||
|
dword dll,api;
|
|||
|
{
|
|||
|
OptImportTableAdr=outptr-output;
|
|||
|
DirTable=outptr;
|
|||
|
if(APIcount==0){
|
|||
|
OUTDWORD(outptr -output + OptBaseOfCode + 4);
|
|||
|
OUTDWORD(0x80000001);
|
|||
|
OUTDWORD(0);
|
|||
|
OUTDWORD(DirTable-output+40+OptBaseOfCode);
|
|||
|
OUTDWORD(outptr-output + OptBaseOfCode - 12);
|
|||
|
DirTable=outptr;
|
|||
|
outptr = outptr + 20;
|
|||
|
OUTDWORD('resu');
|
|||
|
OUTDWORD('d.23');
|
|||
|
OUTDWORD('ll');
|
|||
|
// OUTDWORD(0x72657375); OUTDWORD(0x642E3233); OUTDWORD(0x6C6C);
|
|||
|
apiName=outptr;
|
|||
|
}
|
|||
|
else {
|
|||
|
EAX=DLLcount+1*20;
|
|||
|
outptr+=EAX; // <20><> <20><>砫<EFBFBD> LookupTables
|
|||
|
i=0;
|
|||
|
while(i<DLLcount){ // <20><><EFBFBD>ᬮ<EFBFBD><E1ACAE> ᯨ᪠ DLL
|
|||
|
EAX=i<<2;
|
|||
|
dll=DLLlist[EAX];
|
|||
|
EBX=dll; // <20><>뫪<EFBFBD> <20><> DLL <20> ᯨ᪥ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䨪<EFBFBD><E4A8AA><EFBFBD>
|
|||
|
byName = DSDWORD[EBX+rectype]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>?
|
|||
|
if(DSDWORD[EBX+recmodline]){ // <20>뫨 <20>맮<EFBFBD><EBA7AE> API <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> DLL?
|
|||
|
dllName=outptr;
|
|||
|
ESI=DSDWORD[EBX+recid]; // <20><><EFBFBD><EFBFBD><EFBFBD>⥫<EFBFBD> <20><> <20><><EFBFBD> DLL
|
|||
|
do{
|
|||
|
$LODSB;
|
|||
|
OP(byte AL);
|
|||
|
}while(AL!=0); // <20><><EFBFBD>࠭<EFBFBD><E0A0AD> <20><><EFBFBD> DLL
|
|||
|
AddrTable = outptr; //䨪<><E4A8AA><EFBFBD>㥬 <20><>砫<EFBFBD> AddrTable <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> DLL
|
|||
|
apiName=DSDWORD[EBX+recmodline]+1<<2+AddrTable;
|
|||
|
j=0;
|
|||
|
while(j<posts){ // <20>饬 <20> post
|
|||
|
EBX=j<<2+posttype;
|
|||
|
if(DSDWORD[EBX]==POST_API){
|
|||
|
EBX=j<<2+postnum;
|
|||
|
api=DSDWORD[EBX];
|
|||
|
ECX=api;
|
|||
|
if(DSDWORD[ECX+rectype]==dll){ // <20><> <20><>ࠡ<EFBFBD><E0A0A1>뢠<EFBFBD><EBA2A0><EFBFBD><EFBFBD><EFBFBD> DLL?
|
|||
|
if(DSDWORD[ECX+recmodline]==0){ // <20><><EFBFBD> <20><> <20><><EFBFBD>ᥭ <20> Lookup
|
|||
|
DSDWORD[ECX+recmodline]=outptr-output+OptBaseOfCode;
|
|||
|
IF(byName){
|
|||
|
OUTDWORD(apiName - output + OptBaseOfCode - 2);
|
|||
|
hold=outptr;
|
|||
|
outptr=apiName;
|
|||
|
EAX=DSDWORD[ECX+newid];
|
|||
|
IF(EAX!=0){ // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>?
|
|||
|
IF(lstrcmpA(DSDWORD[ECX+recid],EAX)!=0){
|
|||
|
ESI=api;
|
|||
|
ESI=DSDWORD[ESI+newid];
|
|||
|
GOTO L1;
|
|||
|
}
|
|||
|
}
|
|||
|
ESI=DSDWORD[ECX+recid];
|
|||
|
L1:
|
|||
|
do{
|
|||
|
$LODSB;
|
|||
|
OP(byte AL);
|
|||
|
}while(AL!=0); // <20><><EFBFBD>࠭<EFBFBD><E0A0AD> <20><><EFBFBD> API
|
|||
|
apiName=outptr;
|
|||
|
outptr=hold;
|
|||
|
}
|
|||
|
ELSE{
|
|||
|
EAX=DSDWORD[ECX+recnumber]|0x80000000; // ord number
|
|||
|
OUTDWORD(EAX);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
j++;
|
|||
|
} // end search in post
|
|||
|
OUTDWORD(0);
|
|||
|
outptr=hold;
|
|||
|
outptr=DirTable;
|
|||
|
OUTDWORD(AddrTable-output+OptBaseOfCode);
|
|||
|
OUTDWORD(0);
|
|||
|
OUTDWORD(0);
|
|||
|
OUTDWORD(dllName-output+OptBaseOfCode);
|
|||
|
OUTDWORD(AddrTable-output+OptBaseOfCode);
|
|||
|
DirTable=outptr;
|
|||
|
outptr=apiName;
|
|||
|
}
|
|||
|
i++;
|
|||
|
} // end search in DLLlist
|
|||
|
}
|
|||
|
outptr=DirTable;
|
|||
|
OUTDWORD(0);
|
|||
|
OUTDWORD(0);
|
|||
|
OUTDWORD(0);
|
|||
|
OUTDWORD(0);
|
|||
|
OUTDWORD(0);
|
|||
|
outptr=apiName;
|
|||
|
OptImportTableSize=outptr-output-OptImportTableAdr;
|
|||
|
OptImportTableAdr=OptImportTableAdr+OptBaseOfCode;
|
|||
|
}
|
|||
|
|
|||
|
// ---- <20><>ନ<E0ACA8><E0AEA2><EFBFBD><EFBFBD> EXE
|
|||
|
dword WriteEXE()
|
|||
|
dword diskout; // Handle <20><>室<EFBFBD><E5AEA4><EFBFBD><EFBFBD> 䠩<><E4A0A9>
|
|||
|
byte exefile[FILENAMESIZE];
|
|||
|
{
|
|||
|
wsprintfA(#exefile,"%s.EXE",#rawfilename);
|
|||
|
SHOW(#exefile);
|
|||
|
diskout=_lcreat(#exefile,0);
|
|||
|
IF(EAX==0){
|
|||
|
wsprintfA(#mapstr,"ERROR, unable to create output file %s.\n",#exefile);
|
|||
|
WRITESTR(#mapstr);
|
|||
|
return(-1);
|
|||
|
}
|
|||
|
OptCodeSize=outptr-startptr+1;
|
|||
|
OptImageSize=OptCodeSize/OptSectionAlignment;
|
|||
|
OptImageSize+=2;
|
|||
|
OptImageSize=OptImageSize*OptSectionAlignment;
|
|||
|
OptImageSize+=0x80000;
|
|||
|
TxtVirtualSize=OptCodeSize+0x80000;
|
|||
|
TxtSizeOfRawData=OptCodeSize/OptFileAlignment;
|
|||
|
TxtSizeOfRawData++;
|
|||
|
TxtSizeOfRawData=TxtSizeOfRawData*OptFileAlignment;
|
|||
|
_lwrite(diskout,#exeheader,0x160);
|
|||
|
WriteZero(diskout, 0xA0);
|
|||
|
IF(outptr-output)_lwrite(diskout,output,outptr-output);
|
|||
|
EAX=OptCodeSize%OptFileAlignment;
|
|||
|
EAX><EBX;
|
|||
|
EAX=OptFileAlignment-EBX;
|
|||
|
EAX++;
|
|||
|
WriteZero(diskout, EAX);
|
|||
|
_lclose(diskout);
|
|||
|
return(0);
|
|||
|
}
|
|||
|
|
|||
|
// ----
|
|||
|
WriteZero(dword handle,size)
|
|||
|
byte c;
|
|||
|
{
|
|||
|
c=0;
|
|||
|
loop(size)_lwrite(handle,#c,1);
|
|||
|
}
|