Subversion Repositories Kolibri OS

Rev

Rev 1846 | Blame | Last modification | View Log | Download | RSS feed

  1. // ---- ”®à¬¨à®¢ ­¨¥ IMPORT ᥪ樨
  2. void DoLink()
  3. dword i,j,DirTable,AddrTable,dllName,apiName,byName,hold;
  4. dword dll,api;
  5. {
  6.         OptImportTableAdr=outptr-output;
  7.         DirTable=outptr;
  8.         if(APIcount==0){
  9.                 OUTDWORD(outptr -output + OptBaseOfCode + 4);
  10.                 OUTDWORD(0x80000001);
  11.                 OUTDWORD(0);
  12.                 OUTDWORD(DirTable-output+40+OptBaseOfCode);
  13.                 OUTDWORD(outptr-output + OptBaseOfCode - 12);
  14.                 DirTable=outptr;
  15.                 outptr = outptr + 20;
  16.                 OUTDWORD('resu');
  17.                 OUTDWORD('d.23');
  18.                 OUTDWORD('ll');
  19. //      OUTDWORD(0x72657375); OUTDWORD(0x642E3233); OUTDWORD(0x6C6C);
  20.                 apiName=outptr;
  21.         }
  22.         else {
  23.                 EAX=DLLcount+1*20;
  24.                 outptr+=EAX;    // ­  ­ ç «® LookupTables
  25.                 i=0;
  26.                 while(i<DLLcount){              // à®á¬®âà ᯨ᪠ DLL
  27.                         EAX=i<<2;
  28.                         dll=DLLlist[EAX];
  29.                         EBX=dll;                // ‘á뫪  ­  DLL ¢ ᯨ᪥ ¨¤¥­â¨ä¨ª â®à®¢
  30.                         byName = DSDWORD[EBX+rectype];  // ˆ¬¯®àâ ¯® ¨¬¥­¨?
  31.                         if(DSDWORD[EBX+recmodline]){    // ë«¨ ¢ë§®¢ë API ¨§ ¤ ­­®© DLL?
  32.                                 dllName=outptr;
  33.                                 ESI=DSDWORD[EBX+recid]; // “ª § â¥«ì ­  ¨¬ï DLL
  34.                                 do{
  35.                                         $LODSB;
  36.                                         OP(byte AL);
  37.                                 }while(AL!=0);  // ‘®åà ­¨¬ ¨¬ï DLL
  38.                                 AddrTable = outptr; //䨪á¨à㥬 ­ ç «® AddrTable ¤«ï ¤ ­­®£® DLL
  39.                                 apiName=DSDWORD[EBX+recmodline]+1<<2+AddrTable;
  40.                                 j=0;
  41.                                 while(j<posts){         // ˆé¥¬ ¢ post
  42.                                         EBX=j<<2+posttype;
  43.                                         if(DSDWORD[EBX]==POST_API){
  44.                                                 EBX=j<<2+postnum;
  45.                                                 api=DSDWORD[EBX];
  46.                                                 ECX=api;
  47.                                                 if(DSDWORD[ECX+rectype]==dll){          // ˆ§ ®¡à ¡ â뢠¥¬®£® DLL?
  48.                                                         if(DSDWORD[ECX+recmodline]==0){ // …é¥ ­¥ ¢­¥á¥­ ¢ Lookup
  49.                                                                 DSDWORD[ECX+recmodline]=outptr-output+OptBaseOfCode;
  50.                                                                 IF(byName){
  51.                                                                         OUTDWORD(apiName - output + OptBaseOfCode - 2);
  52.                                                                         hold=outptr;
  53.                                                                         outptr=apiName;
  54.                                                                         EAX=DSDWORD[ECX+newid];
  55.                                                                         IF(EAX!=0){ // …áâì  «¨ á?
  56.                                                                                 IF(lstrcmpA(DSDWORD[ECX+recid],EAX)!=0){
  57.                                                                                         ESI=api;
  58.                                                                                         ESI=DSDWORD[ESI+newid];
  59.                                                                                         GOTO L1;
  60.                                                                                 }
  61.                                                                         }
  62.                                                                         ESI=DSDWORD[ECX+recid];
  63. L1:
  64.                                                                         do{
  65.                                                                                 $LODSB;
  66.                                                                                 OP(byte AL);
  67.                                                                         }while(AL!=0);  // ‘®åà ­¨¬ ¨¬ï API
  68.                                                                         apiName=outptr;
  69.                                                                         outptr=hold;
  70.                                                                 }
  71.                                                                 ELSE{
  72.                                                                         EAX=DSDWORD[ECX+recnumber]|0x80000000;  // ord number
  73.                                                                         OUTDWORD(EAX);
  74.                                                                 }
  75.                                                         }
  76.                                                 }
  77.                                         }
  78.                                         j++;
  79.                                 } // end search in post
  80.                                 OUTDWORD(0);
  81.                                 outptr=hold;
  82.                                 outptr=DirTable;
  83.                                 OUTDWORD(AddrTable-output+OptBaseOfCode);
  84.                                 OUTDWORD(0);
  85.                                 OUTDWORD(0);
  86.                                 OUTDWORD(dllName-output+OptBaseOfCode);
  87.                                 OUTDWORD(AddrTable-output+OptBaseOfCode);
  88.                                 DirTable=outptr;
  89.                                 outptr=apiName;
  90.                         }
  91.                         i++;
  92.                 } // end search in DLLlist
  93.         }
  94.         outptr=DirTable;
  95.         OUTDWORD(0);
  96.         OUTDWORD(0);
  97.         OUTDWORD(0);
  98.         OUTDWORD(0);
  99.         OUTDWORD(0);
  100.         outptr=apiName;
  101.         OptImportTableSize=outptr-output-OptImportTableAdr;
  102.         OptImportTableAdr=OptImportTableAdr+OptBaseOfCode;
  103. }
  104.  
  105. // ---- ”®à¬¨à®¢ ­¨¥ EXE
  106. dword WriteEXE()
  107. dword diskout;  // Handle ¢ë室­®£® ä ©« 
  108. byte exefile[FILENAMESIZE];
  109. {
  110.         wsprintfA(#exefile,"%s.EXE",#rawfilename);
  111.         WRITESTR(#exefile);
  112.         diskout=_lcreat(#exefile,0);
  113.         IF(EAX==0){
  114.                 wsprintfA(#mapstr,"ERROR, unable to create output file %s.\n",#exefile);
  115.                 WRITESTR(#mapstr);
  116.                 return(-1);
  117.         }
  118.         OptCodeSize=outptr-startptr+1;
  119.         OptImageSize=OptCodeSize/OptSectionAlignment;
  120.         OptImageSize+=2;
  121.         OptImageSize=OptImageSize*OptSectionAlignment;
  122.         OptImageSize+=0x80000;
  123.         TxtVirtualSize=OptCodeSize+0x80000;
  124.         TxtSizeOfRawData=OptCodeSize/OptFileAlignment;
  125.         TxtSizeOfRawData++;
  126.         TxtSizeOfRawData=TxtSizeOfRawData*OptFileAlignment;
  127.         _lwrite(diskout,#exeheader,0x160);
  128.         WriteZero(diskout, 0xA0);
  129.         IF(outptr-output)_lwrite(diskout,output,outptr-output);
  130.         EAX=OptCodeSize%OptFileAlignment;
  131.         EAX><EBX;
  132.         EAX=OptFileAlignment-EBX;
  133.         EAX++;
  134.         WriteZero(diskout, EAX);
  135.         _lclose(diskout);
  136.         return(0);
  137. }
  138.  
  139. // ----
  140. WriteZero(dword handle,size)
  141. byte c;
  142. {
  143.         c=0;
  144.         loop(size)_lwrite(handle,#c,1);
  145. }
  146.