Пример #1
0
RcStatus SemCopyDataUntilEOF( WResFileOffset offset, WResFileID handle,
                         void *buff, int buffsize, int *err_code )
/****************************************************************/
{
    bool            error;
    WResFileSSize   numread;

    if( RCSEEK( handle, offset, SEEK_SET ) == -1 ) {
        *err_code = errno;
        return( RS_READ_ERROR );
    }

    numread = RCREAD( handle, buff, buffsize );
    while( numread != 0 ) {
        if( RCIOERR( handle, numread ) ) {
            *err_code = errno;
            return( RS_READ_ERROR );
        }
        error = ResWrite( buff, numread, CurrResFile.handle );
        if( error ) {
            *err_code = LastWresErr();
            return( RS_WRITE_ERROR );
        }
        numread = RCREAD( handle, buff, buffsize );
    }

    return( RS_OK );
}
Пример #2
0
extern uint_32 ComputeSegmentSize( WResFileID handle, SegTable * segs, int shift_count )
{
    segment_record *    currseg;
    segment_record *    afterlast;
    uint_32             length;
    WResFileSSize       numread;
    uint_16             num_relocs;

    length = 0;
    for( currseg = segs->Segments, afterlast = segs->Segments + segs->NumSegs;
            currseg < afterlast; currseg++ ) {
        length += currseg->size;
        if( currseg->info & SEG_RELOC ) {
            if( RCSEEK( handle, (((long)currseg->address) << (long)shift_count) + currseg->size, SEEK_SET ) == -1 )
                return( 0 );
            numread = RCREAD( handle, &num_relocs, sizeof(uint_16) );
            if( numread != sizeof(uint_16) )
                return( 0 );
            length += (unsigned_32)num_relocs * (unsigned_32)OS_RELOC_ITEM_SIZE;
        }
    }

    return( length );

} /* ComputeSegmentSize */
Пример #3
0
static RcStatus readDBRanges( WResFileID handle )
{
    WResFileSSize       numread;

    numread = RCREAD( handle, &charInfo.begchars, 256 );
    if( numread != 256 ) {
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    return( RS_OK );
}
Пример #4
0
/*
 * ReadBitmapInfoHeader-
 * NB when an error occurs this func must return without altering errno
 */
static RcStatus ReadBitmapInfoHeader( BitmapInfoHeader * head, WResFileID handle )
/********************************************************************************/
{
    WResFileSSize   numread;

    numread = RCREAD( handle, head, sizeof(BitmapInfoHeader) );
    if( numread == sizeof( BitmapInfoHeader ) )
        return( RS_OK );
    return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
}
Пример #5
0
static RcStatus readFontInfo( WResFileID handle, FontInfo *info, int *err_code )
/******************************************************************************/
{
    WResFileSSize   numread;

    numread = RCREAD( handle, info, sizeof( FontInfo ) );
    if( numread != sizeof( FontInfo ) ) {
        *err_code = errno;
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    return( RS_OK );
}
Пример #6
0
/*
 * CopyData -
 */
RcStatus CopyData( uint_32 offset, uint_32 length, WResFileID handle,
                void *buff, int buffsize, int *err_code )
/***************************************************************************/
{
    bool            error;
    WResFileSSize   numread;

    if( RCSEEK( handle, offset, SEEK_SET ) == -1 ) {
        *err_code = errno;
        return( RS_READ_ERROR );
    }

    while( length > buffsize ) {
        numread = RCREAD( handle, buff, buffsize );
        if( numread != buffsize ) {
            *err_code = errno;
            return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
        }
        length -= buffsize;
        error = ResWrite( buff, buffsize, CurrResFile.handle );
        if( error ) {
            *err_code = LastWresErr();
            return( RS_WRITE_ERROR );
        }
    }

    numread = RCREAD( handle, buff, length );
    if( numread != length ) {
        *err_code = errno;
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    error = ResWrite( buff, length, CurrResFile.handle );
    if( error ) {
        *err_code = errno;
        return( RS_WRITE_ERROR );
    }

    return( RS_OK );
} /* CopyData */
Пример #7
0
static RcStatus readDBTable( WResFileID handle )
{
    WResFileSSize       numread;
    int                 size;

    size = charInfo.header.num_entries * sizeof( uint_16 );
    charInfo.entries = RCALLOC( size );
    numread = RCREAD( handle, charInfo.entries, size );
    if( numread != size ) {
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    return( RS_OK );
}
Пример #8
0
static RcStatus readDBIndex( WResFileID handle )
{
    WResFileSSize       numread;
    int                 size;

    size = charInfo.header.num_indices * sizeof( DBIndexEntry );
    charInfo.index = RCALLOC( size );
    numread = RCREAD( handle, charInfo.index, size );
    if( numread != size ) {
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    return( RS_OK );
}
Пример #9
0
static RcStatus readBitmapFileHeader( WResFileID handle, BitmapFileHeader *head,
                                        int *err_code )
/******************************************************************************/
{
    WResFileSSize   numread;

    numread = RCREAD( handle, head, sizeof(BitmapFileHeader) );
    if( numread != sizeof( BitmapFileHeader ) ) {
        *err_code = errno;
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    return( RS_OK );
}
Пример #10
0
static RcStatus readCurFileDirEntry( CurFileDirEntry * entry, WResFileID handle,
                                        int *err_code )
/******************************************************************************/
{
    WResFileSSize   numread;

    numread = RCREAD( handle, entry, sizeof(CurFileDirEntry) );
    if( numread != sizeof(CurFileDirEntry ) ) {
        *err_code = errno;
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    return( RS_OK );
} /* readCurFileDirEntry */
Пример #11
0
static RcStatus readIcoCurFileDirHeader( IconCurDirHeader * head,
                                    WResFileID handle, int *err_code )
/********************************************************************/
{
    WResFileSSize   numread;

    numread = RCREAD( handle, head, sizeof(IconCurDirHeader) );
    if( numread != sizeof( IconCurDirHeader ) ) {
        *err_code = errno;
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    return( RS_OK );
} /* readIcoCurFileDirHeader */
Пример #12
0
/*
 * readSegTable
 * NB when an error occurs this function must return without altering errno
 */
static RcStatus readSegTable( WResFileID handle, uint_32 offset, SegTable * seg )
{
    int             tablesize;
    WResFileSSize   numread;

    tablesize = seg->NumSegs * sizeof(segment_record);

    if( RCSEEK( handle, offset, SEEK_SET ) == -1 )
        return( RS_READ_ERROR );
    numread = RCREAD( handle, seg->Segments, tablesize );
    if( numread != tablesize ) {
        return( RCIOERR( handle, numread ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    return( RS_OK );

} /* readSegTable */
Пример #13
0
static RcStatus readDBHeader( WResFileID handle )
{
    WResFileSSize       numread;

    numread = RCREAD( handle, &charInfo.header, sizeof( DBTableHeader ) );
    if( numread != sizeof( DBTableHeader ) ) {
        return( RCIOERR( handle, numread  ) ? RS_READ_ERROR : RS_READ_INCMPLT );
    }
    if( charInfo.header.sig[0] != DB_TABLE_SIG_1 ||
        charInfo.header.sig[1] != DB_TABLE_SIG_2 ) {
        return( RS_BAD_FILE_FMT );
    }
    if( charInfo.header.ver != DB_TABLE_VER ) {
        return( RS_WRONG_VER );
    }
    return( RS_OK );
}
Пример #14
0
bool DumpString( uint_32 offset, uint_32 length, WResFileID handle )
/******************************************************************/
{
    WResFileOffset      prevpos;
    unsigned            len;
    unsigned            numread;
    unsigned            cursor;
    unsigned            stringlen;
    char                *stringbuff;

    prevpos = RCSEEK( handle, offset, SEEK_SET );
    if( prevpos == -1 )
        return( true );
    len = DMP_STR_BUF_LEN;
    stringbuff = (char *)RCALLOC( len );
    if( stringbuff == NULL )
        return( true );

    printf( "\t\t   Strings:\n" );
    printf( "\t\t   --------" );

    numread = 0;
    stringlen = 0;
    cursor = 0;
    do {
        if( numread == 0 ) {
            if( length > len ) {
                length -= len;
            } else {
                len = length;
                length = 0;
            }
            numread = RCREAD( handle, stringbuff, len );
            cursor = 0;
        }
        if( stringlen == 0 ) {
            stringlen = (unsigned char)stringbuff[cursor++];
            if( stringlen != 0 ) {
                printf( "\n\t\t   " );
            }
            ++stringlen;    // trailing '\0'
        }
        if( cursor < numread ) {
            for( ; stringlen > 0; --stringlen ) {
                if( cursor >= numread )
                    break;
                if( stringbuff[cursor] != '\0' && stringbuff[cursor] != '\n' ) {
                    putchar( stringbuff[cursor] );
                }
                cursor++;
            }
        } else {
            numread = 0;
        }
    } while( length != 0 || numread > 0 );
    putchar( '\n' );

    RCFREE( stringbuff );

    RCSEEK( handle, prevpos, SEEK_SET );

    return( false );
}
Пример #15
0
static CpSegRc copyOneSegment( const segment_record * inseg,
            segment_record * outseg, ExeFileInfo *inexe, ExeFileInfo *outexe,
            int old_shift_count, int new_shift_count, bool pad_end )
{
    CpSegRc         ret;
    bool            error;
    WResFileSSize   numread;
    uint_16         numrelocs;
    long            out_offset;
    long            align_amount;
    uint_32         seg_len = 0L;
    char            zero;

    zero = 0;
    error = false;
    ret = CPSEG_OK;

    /* check if this is a segment that has no image in the exe file */
    if( inseg->address != 0 ) {
        /* align in the out file so that shift_count will be valid */
        out_offset = RCTELL( outexe->Handle );
        if( out_offset == -1 ) {
            error = true;
            RcError( ERR_WRITTING_FILE, outexe->name, strerror( errno ) );
        }
        if( !error ) {
            align_amount = AlignAmount( out_offset, new_shift_count );
            if( RCSEEK( outexe->Handle, align_amount, SEEK_CUR ) == -1 ) {
                error = true;
                RcError( ERR_WRITTING_FILE, outexe->name, strerror( errno ) );
            }
            out_offset += align_amount;
        }

        /* move in the in file to the start of the segment */
        if( !error ) {
            /* convert the address to a long before shifting it */
            if( RCSEEK( inexe->Handle, (long)inseg->address << old_shift_count, SEEK_SET ) == -1 ) {
                error = true;
                RcError( ERR_READING_EXE, inexe->name, strerror( errno ) );
            }
        }

        if( !error ) {
            if( inseg->size == 0 ) {
                seg_len = 0x10000L;
            } else {
                seg_len = inseg->size;
            }
            error = myCopyExeData( inexe, outexe, seg_len );
        }

        if( (inseg->info & SEG_RELOC) && !error ) {
            /* read the number of relocation items */
            numread = RCREAD( inexe->Handle, &numrelocs, sizeof(uint_16) );
            if( numread != sizeof( uint_16 ) ) {
                error = true;
                if( RCIOERR( inexe->Handle, numread ) ) {
                    RcError( ERR_READING_EXE, inexe->name, strerror( errno ) );
                } else {
                    RcError( ERR_UNEXPECTED_EOF, inexe->name );
                }
            } else {
                if( RCWRITE( outexe->Handle, &numrelocs, sizeof(uint_16) ) != sizeof( uint_16 ) ) {
                    error = true;
                    RcError( ERR_WRITTING_FILE, outexe->name, strerror( errno ) );
                }
            }
            /* copy the relocation information */
            if( !error ) {
                error = myCopyExeData( inexe, outexe, numrelocs * OS_RELOC_ITEM_SIZE );
            }
            if( numrelocs * OS_RELOC_ITEM_SIZE + seg_len > 0x10000L ) {
                ret = CPSEG_SEG_TOO_BIG;
            }
        }

        if( pad_end && ret != CPSEG_SEG_TOO_BIG && !error ) {
            align_amount = AlignAmount( RCTELL( outexe->Handle ), new_shift_count );
            /* make sure there is room for the memory arena header */
            if( align_amount < 16 ) {
                align_amount += 16;
            }
            if( RCSEEK( outexe->Handle, align_amount - 1, SEEK_CUR ) == -1 ) {
                error = true;
                RcError( ERR_WRITTING_FILE, outexe->name );
            } else {
                /* write something out so if we have just seeked past the
                 * end of the file the file's size will be adjusted
                 * appropriately */
                if( RCWRITE( outexe->Handle, &zero, 1 ) != 1 ) {
                    error = true;
                    RcError( ERR_WRITTING_FILE, outexe->name );
                }
            }
        }
    } else {
        out_offset = 0;
    }

    /* copy the segment record to outseg */
    if( !error ) {
        outseg->size = inseg->size;
        outseg->info = inseg->info;
        outseg->min = inseg->min;
        outseg->address = out_offset >> new_shift_count;
    }