Exemplo n.º 1
0
ElfFile::ElfFile(ElfContent& data) 
     : 
       offsets(data),
       header(data.progHeaders.size() > 0 ? 
                 ElfHeaderX86_64::NewExecutable() :
                 ElfHeaderX86_64::NewObjectFile()),
       file(1024) , 
       dataSectionStart(file),
       sectionHeadersStart(file)
{
    InitialiseHeader(data);
    InitialiseFile(data);
      
    // Process the program headers
    ProcessProgHeaders( data);

    
    sectionHeadersStart.Offset() = WriteDataSections(data);

    Bootstrap(data);

    header.SectionTableStart() = sectionHeadersStart.Offset();


    WriteSectionHeaders(data);

    // Finally write the header
    file.Writer().Write(&header,header.Size());

    // clean up any extra data
    file.Resize( (long)sectionHeadersStart + 
                 header.Sections() * header.SectionHeaderSize() );
}
Exemplo n.º 2
0
int CreateHelpFile(char* listfile, char* helpfile)
{
     FILE *ifptr, *ofptr;
     int filecount, i;
     unsigned csum;

     ifptr = fopen(listfile, "rb");
     if (!ifptr)
     {
        printf("Listfile cannot be opened.");
        return 1;
     }

     ofptr = fopen(helpfile, "wb");
     if (!ofptr)
     {
   fclose(ifptr);
        printf("Unable to open destination help file.");
        return 1;
     }

     filecount = CountFiles(ifptr);
     if (filecount == 0) return 0;

     if ((filecount < 0)                      ||
    (InitialiseHeader(ofptr, filecount)) ||
         (MoveTextFiles(ifptr, ofptr)))
     {
   printf("Error processing listfile.\n");

   fclose(ifptr);
   fclose(ofptr);

        return 1;
     }

     fclose(ifptr);
     fclose(ofptr);

     csum = CalculateCheckSum(helpfile);

#ifdef VERBOSE
     printf("Checksum = %X\n", csum);
#endif

     ofptr = fopen(helpfile, "ab");
     if (!ofptr)
     {
   fclose(ifptr);
        printf("Unable to open destination help file.");
        return 1;
     }

     fseek(ofptr, 0, SEEK_END);

     for (i = 0; i < sizeof(unsigned); i++)
    fputc(*(((char*)(&csum))+i), ofptr);

     fclose(ofptr);

     return 0;
}