kolibrios-fun/programs/develop/c--/trunk/exe.h--
Yogev Ezra 0c96c62ef9 Test C--
git-svn-id: svn://kolibrios.org@1848 a494cfbc-eb01-0410-851d-a64ba20cac60
2011-02-05 17:41:24 +00:00

146 lines
3.8 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ---- ”®à¬¨à®¢ ­¨¥ 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; // ­  ­ ç «® LookupTables
i=0;
while(i<DLLcount){ // <20>à®á¬®âà ᯨ᪠ DLL
EAX=i<<2;
dll=DLLlist[EAX];
EBX=dll; // ‘á뫪  ­  DLL ¢ ᯨ᪥ ¨¤¥­â¨ä¨ª â®à®¢
byName = DSDWORD[EBX+rectype]; // ˆ¬¯®àâ ¯® ¨¬¥­¨?
if(DSDWORD[EBX+recmodline]){ // <20>뫨 ¢ë§®¢ë API ¨§ ¤ ­­®© DLL?
dllName=outptr;
ESI=DSDWORD[EBX+recid]; // “ª § â¥«ì ­  ¨¬ï DLL
do{
$LODSB;
OP(byte AL);
}while(AL!=0); // ‘®åà ­¨¬ ¨¬ï DLL
AddrTable = outptr; //䨪á¨à㥬 ­ ç «® AddrTable ¤«ï ¤ ­­®£® DLL
apiName=DSDWORD[EBX+recmodline]+1<<2+AddrTable;
j=0;
while(j<posts){ // ˆé¥¬ ¢ post
EBX=j<<2+posttype;
if(DSDWORD[EBX]==POST_API){
EBX=j<<2+postnum;
api=DSDWORD[EBX];
ECX=api;
if(DSDWORD[ECX+rectype]==dll){ // ˆ§ ®¡à ¡ â뢠¥¬®£® DLL?
if(DSDWORD[ECX+recmodline]==0){ // …é¥ ­¥ ¢­¥á¥­ ¢ 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){ // …áâì  «¨ á?
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); // ‘®åà ­¨¬ ¨¬ï 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;
}
// ---- ”®à¬¨à®¢ ­¨¥ EXE
dword WriteEXE()
dword diskout; // Handle ¢ë室­®£® ä ©« 
byte exefile[FILENAMESIZE];
{
wsprintfA(#exefile,"%s.EXE",#rawfilename);
WRITESTR(#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);
}