Ejemplo n.º 1
0
void
read_GF_index(struct font *fontp, wide_bool hushcs)
{
    int hppp, vppp;
    ubyte ch, cmnd;
    struct glyph *g;
    long checksum;

    fontp->read_char = read_GF_char;
    GF_file = fontp->file;
    if (globals.debug & DBG_PK)
	printf("Reading GF pixel file %s\n", fontp->filename);
    /*
     *	Find postamble.
     */
    fseek(GF_file, (long)-4, SEEK_END);
    while (get_bytes(GF_file, 4) != ((unsigned long)TRAILER << 24 | TRAILER << 16
				     | TRAILER << 8 | TRAILER))
	fseek(GF_file, (long)-5, SEEK_CUR);
    fseek(GF_file, (long)-5, SEEK_CUR);
    for (;;) {
	ch = get_byte(GF_file);
	if (ch != TRAILER)
	    break;
	fseek(GF_file, (long)-2, SEEK_CUR);
    }
    if (ch != GF_ID_BYTE)
	XDVI_FATAL((stderr, "Bad end of font file %s", fontp->fontname));
    fseek(GF_file, (long)-6, SEEK_CUR);
    expect(POST_POST);
    fseek(GF_file, get_lbytes(GF_file, 4), SEEK_SET);	/* move to postamble */
    /*
     *	Read postamble.
     */
    expect(POST);
    (void)get_bytes(GF_file, 4);	/* pointer to last eoc + 1 */
    (void)get_bytes(GF_file, 4);	/* skip design size */
    checksum = get_bytes(GF_file, 4);
    if (checksum != fontp->checksum && checksum != 0 && fontp->checksum != 0
	&& !hushcs)
	XDVI_WARNING((stderr, "Checksum mismatch (dvi = %lu, gf = %lu) in font file %s",
		      fontp->checksum, checksum, fontp->filename));
    hppp = get_lbytes(GF_file, 4);
    vppp = get_lbytes(GF_file, 4);
    if (hppp != vppp && (globals.debug & DBG_PK))
	printf("Font has non-square aspect ratio %d:%d\n", vppp, hppp);
    (void)get_bytes(GF_file, 4);	/* skip min_m */
    (void)get_bytes(GF_file, 4);	/* skip max_m */
    (void)get_bytes(GF_file, 4);	/* skip min_n */
    (void)get_bytes(GF_file, 4);	/* skip max_n */
    /*
     *	Prepare glyph array.
     */
    fontp->glyph = xmalloc(256 * sizeof(struct glyph));
    memset((char *)fontp->glyph, 0, 256 * sizeof(struct glyph));
    /*
     *	Read glyph directory.
     */
    while ((cmnd = get_byte(GF_file)) != POST_POST) {
	int addr;

	ch = get_byte(GF_file);	/* character code */
	g = &fontp->glyph[ch];
	switch (cmnd) {
	case CHAR_LOC:
	    /* g->pxl_adv = get_lbytes(GF_file, 4); */
	    (void)get_bytes(GF_file, 4);
	    (void)get_bytes(GF_file, 4);	/* skip dy */
	    break;
	case CHAR_LOC0:
	    /* g->pxl_adv = get_byte(GF_file) << 16; */
	    (void)get_byte(GF_file);
	    break;
	default:
	    XDVI_FATAL((stderr, "Non-char_loc command found in GF preamble:  %d", cmnd));
	}
	g->dvi_adv = fontp->dimconv * get_lbytes(GF_file, 4);
	addr = get_bytes(GF_file, 4);
	if (addr != -1)
	    g->addr = addr;
	if (globals.debug & DBG_PK)
	    printf("Read GF glyph for character %d; dy = %ld, addr = %x\n",
		   ch, g->dvi_adv, addr);
    }
}
Ejemplo n.º 2
0
static void skip_string(void)
{
    while (get_byte() != 0);
}
Ejemplo n.º 3
0
/* should be the first function */
void decompress_entry(unsigned long reg_a0, unsigned long reg_a1,
	unsigned long reg_a2, unsigned long reg_a3,
	unsigned long icache_size, unsigned long icache_lsize,
	unsigned long dcache_size, unsigned long dcache_lsize)
{
	unsigned char props[LZMA_PROPERTIES_SIZE];
	unsigned int i;  /* temp value */
	SizeT osize; /* uncompressed size */
	int res;

	board_init();

	printf("\n\nLZMA loader for " CONFIG_BOARD_NAME
			", Copyright (C) 2007-2008 OpenWrt.org\n\n");

	decompress_init();

	/* lzma args */
	for (i = 0; i < LZMA_PROPERTIES_SIZE; i++)
		props[i] = get_byte();

	/* skip rest of the LZMA coder property */
	/* read the lower half of uncompressed size in the header */
	osize = ((SizeT)get_byte()) +
		((SizeT)get_byte() << 8) +
		((SizeT)get_byte() << 16) +
		((SizeT)get_byte() << 24);

	/* skip rest of the header (upper half of uncompressed size) */
	for (i = 0; i < 4; i++)
		get_byte();

	res = LzmaDecodeProperties(&lzma_state.Properties, props,
					LZMA_PROPERTIES_SIZE);
	if (res != LZMA_RESULT_OK) {
		printf("Incorrect LZMA stream properties!\n");
		halt();
	}

	printf("decompressing kernel... ");

	lzma_state.Probs = (CProb *)workspace;
	res = decompress_data(&lzma_state, (unsigned char *)LOADADDR, osize);

	if (res != LZMA_RESULT_OK) {
		printf("failed, ");
		switch (res) {
		case LZMA_RESULT_DATA_ERROR:
			printf("data error!\n");
			break;
		default:
			printf("unknown error %d!\n", res);
		}
		halt();
	} else
		printf("done!\n");

	blast_dcache(dcache_size, dcache_lsize);
	blast_icache(icache_size, icache_lsize);

	printf("launching kernel...\n\n");

#ifdef CONFIG_PASS_KARGS
	reg_a0 = 0;
	reg_a1 = 0;
	reg_a2 = (unsigned long)env_vars;
	reg_a3 = 0;
#endif
	/* Jump to load address */
	((kernel_entry) LOADADDR)(reg_a0, reg_a1, reg_a2, reg_a3);
}
Ejemplo n.º 4
0
/*
* Copy out the digest
*/
void Tiger::copy_out(byte output[])
   {
   for(size_t i = 0; i != output_length(); ++i)
      output[i] = get_byte(7 - (i % 8), digest[i/8]);
   }
Ejemplo n.º 5
0
int
voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size)
{
    VocDecContext *voc = s->priv_data;
    AVCodecContext *dec = st->codec;
    ByteIOContext *pb = s->pb;
    VocType type;
    int size;
    int sample_rate = 0;
    int channels = 1;

    while (!voc->remaining_size) {
        type = get_byte(pb);
        if (type == VOC_TYPE_EOF)
            return AVERROR(EIO);
        voc->remaining_size = get_le24(pb);
        if (!voc->remaining_size) {
            if (url_is_streamed(s->pb))
                return AVERROR(EIO);
            voc->remaining_size = url_fsize(pb) - url_ftell(pb);
        }
        max_size -= 4;

        switch (type) {
        case VOC_TYPE_VOICE_DATA:
            dec->sample_rate = 1000000 / (256 - get_byte(pb));
            if (sample_rate)
                dec->sample_rate = sample_rate;
            dec->channels = channels;
            dec->codec_id = ff_codec_get_id(ff_voc_codec_tags, get_byte(pb));
            dec->bits_per_coded_sample = av_get_bits_per_sample(dec->codec_id);
            voc->remaining_size -= 2;
            max_size -= 2;
            channels = 1;
            break;

        case VOC_TYPE_VOICE_DATA_CONT:
            break;

        case VOC_TYPE_EXTENDED:
            sample_rate = get_le16(pb);
            get_byte(pb);
            channels = get_byte(pb) + 1;
            sample_rate = 256000000 / (channels * (65536 - sample_rate));
            voc->remaining_size = 0;
            max_size -= 4;
            break;

        case VOC_TYPE_NEW_VOICE_DATA:
            dec->sample_rate = get_le32(pb);
            dec->bits_per_coded_sample = get_byte(pb);
            dec->channels = get_byte(pb);
            dec->codec_id = ff_codec_get_id(ff_voc_codec_tags, get_le16(pb));
            url_fskip(pb, 4);
            voc->remaining_size -= 12;
            max_size -= 12;
            break;

        default:
            url_fskip(pb, voc->remaining_size);
            max_size -= voc->remaining_size;
            voc->remaining_size = 0;
            break;
        }
    }

    dec->bit_rate = dec->sample_rate * dec->bits_per_coded_sample;

    if (max_size <= 0)
        max_size = 2048;
    size = FFMIN(voc->remaining_size, max_size);
    voc->remaining_size -= size;
    return av_get_packet(pb, pkt, size);
}
static int avs_read_packet(AVFormatContext * s, AVPacket * pkt)
{
    AvsFormat *avs = s->priv_data;
    int sub_type = 0, size = 0;
    AvsBlockType type = AVS_NONE;
    int palette_size = 0;
    uint8_t palette[4 + 3 * 256];
    int ret;

    if (avs->remaining_audio_size > 0)
        if (avs_read_audio_packet(s, pkt) > 0)
            return 0;

    while (1) {
        if (avs->remaining_frame_size <= 0) {
            if (!get_le16(s->pb))    /* found EOF */
                return AVERROR(EIO);
            avs->remaining_frame_size = get_le16(s->pb) - 4;
        }

        while (avs->remaining_frame_size > 0) {
            sub_type = get_byte(s->pb);
            type = get_byte(s->pb);
            size = get_le16(s->pb);
            if (size < 4)
                return AVERROR_INVALIDDATA;
            avs->remaining_frame_size -= size;

            switch (type) {
            case AVS_PALETTE:
                if (size - 4 > sizeof(palette))
                    return AVERROR_INVALIDDATA;
                ret = get_buffer(s->pb, palette, size - 4);
                if (ret < size - 4)
                    return AVERROR(EIO);
                palette_size = size;
                break;

            case AVS_VIDEO:
                if (!avs->st_video) {
                    avs->st_video = av_new_stream(s, AVS_VIDEO);
                    if (avs->st_video == NULL)
                        return AVERROR(ENOMEM);
                    avs->st_video->codec->codec_type = CODEC_TYPE_VIDEO;
                    avs->st_video->codec->codec_id = CODEC_ID_AVS;
                    avs->st_video->codec->width = avs->width;
                    avs->st_video->codec->height = avs->height;
                    avs->st_video->codec->bits_per_coded_sample=avs->bits_per_sample;
                    avs->st_video->nb_frames = avs->nb_frames;
                    avs->st_video->codec->time_base = (AVRational) {
                    1, avs->fps};
                }
                return avs_read_video_packet(s, pkt, type, sub_type, size,
                                             palette, palette_size);

            case AVS_AUDIO:
                if (!avs->st_audio) {
                    avs->st_audio = av_new_stream(s, AVS_AUDIO);
                    if (avs->st_audio == NULL)
                        return AVERROR(ENOMEM);
                    avs->st_audio->codec->codec_type = CODEC_TYPE_AUDIO;
                }
                avs->remaining_audio_size = size - 4;
                size = avs_read_audio_packet(s, pkt);
                if (size != 0)
                    return size;
                break;

            default:
                url_fskip(s->pb, size - 4);
            }
        }
    }
}
Ejemplo n.º 7
0
/*
 * Process WVE file header
 * Returns 1 if the WVE file is valid and successfully opened, 0 otherwise
 */
static int process_ea_header(AVFormatContext *s) {
    int inHeader;
    uint32_t blockid, size;
    EaDemuxContext *ea = s->priv_data;
    ByteIOContext *pb = &s->pb;

    if (get_buffer(pb, (void*)&blockid, 4) != 4) {
        return 0;
    }
    if (le2me_32(blockid) != SCHl_TAG) {
        return 0;
    }

    if (get_buffer(pb, (void*)&size, 4) != 4) {
        return 0;
    }
    size = le2me_32(size);

    if (get_buffer(pb, (void*)&blockid, 4) != 4) {
        return 0;
    }
    if (le2me_32(blockid) != PT00_TAG) {
        av_log (s, AV_LOG_ERROR, "PT header missing\n");
        return 0;
    }

    inHeader = 1;
    while (inHeader) {
        int inSubheader;
        uint8_t byte;
        byte = get_byte(pb) & 0xFF;

        switch (byte) {
        case 0xFD:
            av_log (s, AV_LOG_INFO, "entered audio subheader\n");
            inSubheader = 1;
            while (inSubheader) {
                uint8_t subbyte;
                subbyte = get_byte(pb) & 0xFF;

                switch (subbyte) {
                case 0x82:
                    ea->num_channels = read_arbitary(pb);
                    av_log (s, AV_LOG_INFO, "num_channels (element 0x82) set to 0x%08x\n", ea->num_channels);
                    break;
                case 0x83:
                    ea->compression_type = read_arbitary(pb);
                    av_log (s, AV_LOG_INFO, "compression_type (element 0x83) set to 0x%08x\n", ea->compression_type);
                    break;
                case 0x85:
                    ea->num_samples = read_arbitary(pb);
                    av_log (s, AV_LOG_INFO, "num_samples (element 0x85) set to 0x%08x\n", ea->num_samples);
                    break;
                case 0x8A:
                    av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
                    av_log (s, AV_LOG_INFO, "exited audio subheader\n");
                    inSubheader = 0;
                    break;
                default:
                    av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
                    break;
                }
            }
            break;
        case 0xFF:
            av_log (s, AV_LOG_INFO, "end of header block reached\n");
            inHeader = 0;
            break;
        default:
            av_log (s, AV_LOG_INFO, "header element 0x%02x set to 0x%08x\n", byte, read_arbitary(pb));
            break;
        }
    }

    if ((ea->num_channels != 2) || (ea->compression_type != 7)) {
        av_log (s, AV_LOG_ERROR, "unsupported stream type\n");
        return 0;
    }

    /* skip to the start of the data */
    url_fseek(pb, size, SEEK_SET);

    return 1;
}
Ejemplo n.º 8
0
Archivo: wv.c Proyecto: DocOnDev/mythtv
static int wv_read_packet(AVFormatContext *s,
                          AVPacket *pkt)
{
    WVContext *wc = s->priv_data;
    int ret;
    int size, ver, off;

    if (url_feof(s->pb))
        return AVERROR(EIO);
    if(wc->block_parsed){
        if(wv_read_block_header(s, s->pb, 0) < 0)
            return -1;
    }

    off = wc->multichannel ? 4 : 0;
    if(av_new_packet(pkt, wc->blksize + WV_EXTRA_SIZE + off) < 0)
        return AVERROR(ENOMEM);
    if(wc->multichannel)
        AV_WL32(pkt->data, wc->blksize + WV_EXTRA_SIZE + 12);
    memcpy(pkt->data + off, wc->extra, WV_EXTRA_SIZE);
    ret = get_buffer(s->pb, pkt->data + WV_EXTRA_SIZE + off, wc->blksize);
    if(ret != wc->blksize){
        av_free_packet(pkt);
        return AVERROR(EIO);
    }
    while(!(wc->flags & WV_END_BLOCK)){
        if(get_le32(s->pb) != MKTAG('w', 'v', 'p', 'k')){
            av_free_packet(pkt);
            return -1;
        }
        if((ret = av_append_packet(s->pb, pkt, 4)) < 0){
            av_free_packet(pkt);
            return ret;
        }
        size = AV_RL32(pkt->data + pkt->size - 4);
        if(size < 24 || size > WV_BLOCK_LIMIT){
            av_free_packet(pkt);
            av_log(s, AV_LOG_ERROR, "Incorrect block size %d\n", size);
            return -1;
        }
        wc->blksize = size;
        ver = get_le16(s->pb);
        if(ver < 0x402 || ver > 0x410){
            av_free_packet(pkt);
            av_log(s, AV_LOG_ERROR, "Unsupported version %03X\n", ver);
            return -1;
        }
        get_byte(s->pb); // track no
        get_byte(s->pb); // track sub index
        wc->samples = get_le32(s->pb); // total samples in file
        wc->soff = get_le32(s->pb); // offset in samples of current block
        if((ret = av_append_packet(s->pb, pkt, WV_EXTRA_SIZE)) < 0){
            av_free_packet(pkt);
            return ret;
        }
        memcpy(wc->extra, pkt->data + pkt->size - WV_EXTRA_SIZE, WV_EXTRA_SIZE);

        if(wv_read_block_header(s, s->pb, 1) < 0){
            av_free_packet(pkt);
            return -1;
        }
        ret = av_append_packet(s->pb, pkt, wc->blksize);
        if(ret < 0){
            av_free_packet(pkt);
            return ret;
        }
    }
    pkt->stream_index = 0;
    wc->block_parsed = 1;
    pkt->pts = wc->soff;
    av_add_index_entry(s->streams[0], wc->pos, pkt->pts, 0, 0, AVINDEX_KEYFRAME);
    return 0;
}
Ejemplo n.º 9
0
Archivo: wv.c Proyecto: DocOnDev/mythtv
static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb, int append)
{
    WVContext *wc = ctx->priv_data;
    uint32_t tag, ver;
    int size;
    int rate, bpp, chan;
    uint32_t chmask;

    wc->pos = url_ftell(pb);
    if(!append){
        tag = get_le32(pb);
        if (tag != MKTAG('w', 'v', 'p', 'k'))
            return -1;
        size = get_le32(pb);
        if(size < 24 || size > WV_BLOCK_LIMIT){
            av_log(ctx, AV_LOG_ERROR, "Incorrect block size %i\n", size);
            return -1;
        }
        wc->blksize = size;
        ver = get_le16(pb);
        if(ver < 0x402 || ver > 0x410){
            av_log(ctx, AV_LOG_ERROR, "Unsupported version %03X\n", ver);
            return -1;
        }
        get_byte(pb); // track no
        get_byte(pb); // track sub index
        wc->samples = get_le32(pb); // total samples in file
        wc->soff = get_le32(pb); // offset in samples of current block
        get_buffer(pb, wc->extra, WV_EXTRA_SIZE);
    }else{
        size = wc->blksize;
    }
    wc->flags = AV_RL32(wc->extra + 4);
    //parse flags
    bpp = ((wc->flags & 3) + 1) << 3;
    chan = 1 + !(wc->flags & WV_MONO);
    chmask = wc->flags & WV_MONO ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
    rate = wv_rates[(wc->flags >> 23) & 0xF];
    wc->multichannel = !!((wc->flags & WV_SINGLE_BLOCK) != WV_SINGLE_BLOCK);
    if(wc->multichannel){
        chan = wc->chan;
        chmask = wc->chmask;
    }
    if((rate == -1 || !chan) && !wc->block_parsed){
        int64_t block_end = url_ftell(pb) + wc->blksize - 24;
        if(url_is_streamed(pb)){
            av_log(ctx, AV_LOG_ERROR, "Cannot determine additional parameters\n");
            return -1;
        }
        while(url_ftell(pb) < block_end){
            int id, size;
            id = get_byte(pb);
            size = (id & 0x80) ? get_le24(pb) : get_byte(pb);
            size <<= 1;
            if(id&0x40)
                size--;
            switch(id&0x3F){
            case 0xD:
                if(size <= 1){
                    av_log(ctx, AV_LOG_ERROR, "Insufficient channel information\n");
                    return -1;
                }
                chan = get_byte(pb);
                switch(size - 2){
                case 0:
                    chmask = get_byte(pb);
                    break;
                case 1:
                    chmask = get_le16(pb);
                    break;
                case 2:
                    chmask = get_le24(pb);
                    break;
                case 3:
                    chmask = get_le32(pb);
                    break;
                case 5:
                    url_fskip(pb, 1);
                    chan |= (get_byte(pb) & 0xF) << 8;
                    chmask = get_le24(pb);
                    break;
                default:
                    av_log(ctx, AV_LOG_ERROR, "Invalid channel info size %d\n", size);
                    return -1;
                }
                break;
            case 0x27:
                rate = get_le24(pb);
                break;
            default:
                url_fskip(pb, size);
            }
            if(id&0x40)
                url_fskip(pb, 1);
        }
        if(rate == -1){
            av_log(ctx, AV_LOG_ERROR, "Cannot determine custom sampling rate\n");
            return -1;
        }
        url_fseek(pb, block_end - wc->blksize + 24, SEEK_SET);
    }
    if(!wc->bpp) wc->bpp = bpp;
    if(!wc->chan) wc->chan = chan;
    if(!wc->chmask) wc->chmask = chmask;
    if(!wc->rate) wc->rate = rate;

    if(wc->flags && bpp != wc->bpp){
        av_log(ctx, AV_LOG_ERROR, "Bits per sample differ, this block: %i, header block: %i\n", bpp, wc->bpp);
        return -1;
    }
    if(wc->flags && !wc->multichannel && chan != wc->chan){
        av_log(ctx, AV_LOG_ERROR, "Channels differ, this block: %i, header block: %i\n", chan, wc->chan);
        return -1;
    }
    if(wc->flags && rate != -1 && rate != wc->rate){
        av_log(ctx, AV_LOG_ERROR, "Sampling rate differ, this block: %i, header block: %i\n", rate, wc->rate);
        return -1;
    }
    wc->blksize = size - 24;
    return 0;
}
Ejemplo n.º 10
0
/*
 * Process PT/GSTR sound header
 * return 1 if success, 0 if invalid format, otherwise AVERROR_xxx
 */
static int process_audio_header_elements(AVFormatContext *s)
{
    int inHeader = 1;
    EaDemuxContext *ea = s->priv_data;
    ByteIOContext *pb = s->pb;
    int compression_type = -1, revision = -1, revision2 = -1;

    ea->bytes = 2;
    ea->sample_rate = -1;
    ea->num_channels = 1;

    while (inHeader) {
        int inSubheader;
        uint8_t byte;
        byte = get_byte(pb);

        switch (byte) {
        case 0xFD:
            av_log (s, AV_LOG_INFO, "entered audio subheader\n");
            inSubheader = 1;
            while (inSubheader) {
                uint8_t subbyte;
                subbyte = get_byte(pb);

                switch (subbyte) {
                case 0x80:
                    revision = read_arbitary(pb);
                    av_log (s, AV_LOG_INFO, "revision (element 0x80) set to 0x%08x\n", revision);
                    break;
                case 0x82:
                    ea->num_channels = read_arbitary(pb);
                    av_log (s, AV_LOG_INFO, "num_channels (element 0x82) set to 0x%08x\n", ea->num_channels);
                    break;
                case 0x83:
                    compression_type = read_arbitary(pb);
                    av_log (s, AV_LOG_INFO, "compression_type (element 0x83) set to 0x%08x\n", compression_type);
                    break;
                case 0x84:
                    ea->sample_rate = read_arbitary(pb);
                    av_log (s, AV_LOG_INFO, "sample_rate (element 0x84) set to %i\n", ea->sample_rate);
                    break;
                case 0x85:
                    ea->num_samples = read_arbitary(pb);
                    av_log (s, AV_LOG_INFO, "num_samples (element 0x85) set to 0x%08x\n", ea->num_samples);
                    break;
                case 0x8A:
                    av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
                    av_log (s, AV_LOG_INFO, "exited audio subheader\n");
                    inSubheader = 0;
                    break;
                case 0xA0:
                    revision2 = read_arbitary(pb);
                    av_log (s, AV_LOG_INFO, "revision2 (element 0xA0) set to 0x%08x\n", revision2);
                    break;
                case 0xFF:
                    av_log (s, AV_LOG_INFO, "end of header block reached (within audio subheader)\n");
                    inSubheader = 0;
                    inHeader = 0;
                    break;
                default:
                    av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
                    break;
                }
            }
            break;
        case 0xFF:
            av_log (s, AV_LOG_INFO, "end of header block reached\n");
            inHeader = 0;
            break;
        default:
            av_log (s, AV_LOG_INFO, "header element 0x%02x set to 0x%08x\n", byte, read_arbitary(pb));
            break;
        }
    }

    switch (compression_type) {
    case  0: ea->audio_codec = CODEC_ID_PCM_S16LE; break;
    case  7: ea->audio_codec = CODEC_ID_ADPCM_EA; break;
    case -1:
        switch (revision) {
        case  1: ea->audio_codec = CODEC_ID_ADPCM_EA_R1; break;
        case  2: ea->audio_codec = CODEC_ID_ADPCM_EA_R2; break;
        case  3: ea->audio_codec = CODEC_ID_ADPCM_EA_R3; break;
        case -1: break;
        default:
            av_log(s, AV_LOG_ERROR, "unsupported stream type; revision=%i\n", revision);
            return 0;
        }
        switch (revision2) {
        case  8: ea->audio_codec = CODEC_ID_PCM_S16LE_PLANAR; break;
        case 10: ea->audio_codec = CODEC_ID_ADPCM_EA_R2; break;
        case 16: ea->audio_codec = CODEC_ID_MP3; break;
        case -1: break;
        default:
            av_log(s, AV_LOG_ERROR, "unsupported stream type; revision2=%i\n", revision2);
            return 0;
        }
        break;
    default:
        av_log(s, AV_LOG_ERROR, "unsupported stream type; compression_type=%i\n", compression_type);
        return 0;
    }

    if (ea->sample_rate == -1)
        ea->sample_rate = revision==3 ? 48000 : 22050;

    return 1;
}
Ejemplo n.º 11
0
uint8_t get_byte_seek(long offset, FILE *infile)
{
    CHECK_ERRNO(fseek(infile, offset, SEEK_SET) != 0, "fseek");

    return get_byte(infile);
}
Ejemplo n.º 12
0
int kexec (char *ufilename){

	int success, i;
	char kfilename[FILENAMELEN];
  	char *cp = kfilename;
  	int count = 0; 
  	u16 segment = running->uss;

  while (count < FILENAMELEN){
     *cp = get_byte(running->uss, ufilename);
     if (*cp == 0) break;
     cp++; ufilename++; count++;
  }

  kfilename[FILENAMELEN - 1] = 0;

	//printf("proc %d exec(%s) attempt ", running->pid, kfilename);

	//success = kkexec(file);
	//printf("load: %d\n", load(kfilename, segment));

	//gets(kfilename);

 //   for (i=1; i<= 32 * 1024; i++){
   //    put_word(0, segment, 2*i);
   //}

	if(!myload(kfilename, segment)){
		printf("failed at %x\n", segment);
		return -1;
	}

	//load(kfilename, segment);

    /**************************************************
    We know segment=0x2000 + index*0x1000 ====>
    ustack is at the high end of this segment, say TOP.
    We must make ustak contain:
          1   2   3  4  5  6  7  8  9 10 11 12
       flag uCS uPC ax bx cx dx bp si di es ds
     0x0200 seg  0  0  0  0  0  0  0  0 seg seg
  
    So, first a loop to set all to 0, then
    put_word(seg, segment, -2*i); i=2,11,12;*/

	for (i=1; i<=12; i++){
       put_word(0, segment, -2*i);
   }


   put_word(0x0200,  segment, -2*1);   /* flag */  
   put_word(segment, segment, -2*2);   /* uCS */
   put_word(segment, segment, -2*11);  /* uES */
   put_word(segment, segment, -2*12);  /* uDS */
   printf("success at %x\n", segment);
   /* initial USP relative to USS */
   running->usp = -2*12; 
   //running->uss = segment;

   return running->pid;

}
Ejemplo n.º 13
0
FX_WINOLEAPI_(int) FX_StringFromGUID2(FX_REFGUID rguid, wchar_t* lpsz, int cbMax)
{
    //The string that the lpsz parameter receives has a format
    // like that of the following sample:
    //{c200e360-38c5-11ce-ae62-08002b2b79ef}

    assert( lpsz );
    assert( sizeof(rguid) == 16 );
    // check that the string is long enough
    if ( cbMax < 39 ) return 0;
    // write out the output
    *lpsz++ = '{';
    *lpsz++ = upper_hex_char( get_byte( rguid, 0 ) );
    *lpsz++ = lower_hex_char( get_byte( rguid, 0 ) );
    *lpsz++ = upper_hex_char( get_byte( rguid, 1 ) );
    *lpsz++ = lower_hex_char( get_byte( rguid, 1 ) );
    *lpsz++ = upper_hex_char( get_byte( rguid, 2 ) );
    *lpsz++ = lower_hex_char( get_byte( rguid, 2 ) );
    *lpsz++ = upper_hex_char( get_byte( rguid, 3 ) );
    *lpsz++ = lower_hex_char( get_byte( rguid, 3 ) );
    *lpsz++ = '-';
    *lpsz++ = upper_hex_char( get_byte( rguid, 4 ) );
    *lpsz++ = lower_hex_char( get_byte( rguid, 4 ) );
    *lpsz++ = upper_hex_char( get_byte( rguid, 5 ) );
    *lpsz++ = lower_hex_char( get_byte( rguid, 5 ) );
    *lpsz++ = '-';
    *lpsz++ = upper_hex_char( get_byte( rguid, 6 ) );
    *lpsz++ = lower_hex_char( get_byte( rguid, 6 ) );
    *lpsz++ = upper_hex_char( get_byte( rguid, 7 ) );
    *lpsz++ = lower_hex_char( get_byte( rguid, 7 ) );
    *lpsz++ = '-';
    *lpsz++ = upper_hex_char( get_byte( rguid, 8 ) );
    *lpsz++ = lower_hex_char( get_byte( rguid, 8 ) );
    *lpsz++ = upper_hex_char( get_byte( rguid, 9 ) );
    *lpsz++ = lower_hex_char( get_byte( rguid, 9 ) );
    *lpsz++ = '-';
    *lpsz++ = upper_hex_char( get_byte( rguid, 10 ) );
    *lpsz++ = lower_hex_char( get_byte( rguid, 10 ) );
    *lpsz++ = upper_hex_char( get_byte( rguid, 11 ) );
    *lpsz++ = lower_hex_char( get_byte( rguid, 11 ) );
    *lpsz++ = upper_hex_char( get_byte( rguid, 12 ) );
    *lpsz++ = lower_hex_char( get_byte( rguid, 12 ) );
    *lpsz++ = upper_hex_char( get_byte( rguid, 13 ) );
    *lpsz++ = lower_hex_char( get_byte( rguid, 13 ) );
    *lpsz++ = upper_hex_char( get_byte( rguid, 14 ) );
    *lpsz++ = lower_hex_char( get_byte( rguid, 14 ) );
    *lpsz++ = upper_hex_char( get_byte( rguid, 15 ) );
    *lpsz++ = lower_hex_char( get_byte( rguid, 15 ) );
    *lpsz++ = '}';
    *lpsz++ = '\0';

    return 39;
}
Ejemplo n.º 14
0
static void
read_GF_char(struct font *fontp,
	     wide_ubyte ch)
{
    struct glyph *g;
    ubyte cmnd;
    int min_m, max_m, min_n, max_n;
    bmUnitT *cp, *basep, *maxp;
    int bytes_wide;
    Boolean paint_switch;
#define	White	False
#define	Black	True
    Boolean new_row;
    int count;
    int word_weight;

    g = &fontp->glyph[ch];
    GF_file = fontp->file;

    if (globals.debug & DBG_PK)
	printf("Loading gf char %d", ch);

    for (;;) {
	switch (cmnd = get_byte(GF_file)) {
	case XXX1:
	case XXX2:
	case XXX3:
	case XXX4:
	    fseek(GF_file, (long)get_bytes(GF_file, (int)(cmnd - XXX1 + 1)), SEEK_CUR);
	    continue;
	case YYY:
	    (void)get_bytes(GF_file, 4);
	    continue;
	case BOC:
	    (void)get_bytes(GF_file, 4);	/* skip character code */
	    (void)get_bytes(GF_file, 4);	/* skip pointer to prev char */
	    min_m = get_lbytes(GF_file, 4);
	    max_m = get_lbytes(GF_file, 4);
	    g->x = -min_m;
	    min_n = get_lbytes(GF_file, 4);
	    g->y = max_n = get_lbytes(GF_file, 4);
	    g->bitmap.w = max_m - min_m + 1;
	    g->bitmap.h = max_n - min_n + 1;
	    break;
	case BOC1:
	    (void)get_byte(GF_file);	/* skip character code */
	    g->bitmap.w = get_byte(GF_file);	/* max_m - min_m */
	    g->x = g->bitmap.w - get_byte(GF_file);	/* ditto - max_m */
	    ++g->bitmap.w;
	    g->bitmap.h = get_byte(GF_file) + 1;
	    g->y = get_byte(GF_file);
	    break;
	default:
	    XDVI_FATAL((stderr, "Bad BOC code:  %d", cmnd));
	}
	break;
    }
    paint_switch = White;

    if (globals.debug & DBG_PK)
	printf(", size=%dx%d, dvi_adv=%ld\n", g->bitmap.w, g->bitmap.h,
	       g->dvi_adv);

    alloc_bitmap(&g->bitmap);
    cp = basep = (bmUnitT *) g->bitmap.bits;
    /*
     *	Read character data into *basep
     */
    bytes_wide = ROUNDUP((int)g->bitmap.w, BMBITS) * BMBYTES;
    maxp = ADD(basep, g->bitmap.h * bytes_wide);
    memset(g->bitmap.bits, 0, g->bitmap.h * bytes_wide);
    new_row = False;
    word_weight = BMBITS;
    for (;;) {
	count = -1;
	cmnd = get_byte(GF_file);
	if (cmnd < 64)
	    count = cmnd;
	else if (cmnd >= NEW_ROW_0 && cmnd <= NEW_ROW_MAX) {
	    count = cmnd - NEW_ROW_0;
	    paint_switch = White;	/* it'll be complemented later */
	    new_row = True;
	}
	else
	    switch (cmnd) {
	    case PAINT1:
	    case PAINT2:
	    case PAINT3:
		count = get_bytes(GF_file, (int)(cmnd - PAINT1 + 1));
		break;
	    case EOC:
		if (cp >= ADD(basep, bytes_wide))
		    too_many_bits(ch);
		return;
	    case SKIP1:
	    case SKIP2:
	    case SKIP3:
		basep += get_bytes(GF_file, (int)(cmnd - SKIP0)) * bytes_wide / sizeof(bmUnitT);
		/* 		*((char **)&basep) += get_bytes(GF_file, WIDENINT cmnd - SKIP0) * bytes_wide; */
	    case SKIP0:
		new_row = True;
		paint_switch = White;
		break;
	    case XXX1:
	    case XXX2:
	    case XXX3:
	    case XXX4:
		fseek(GF_file, (long)get_bytes(GF_file, (int)(cmnd - XXX1 + 1)), SEEK_CUR);
		break;
	    case YYY:
		(void)get_bytes(GF_file, 4);
		break;
	    case NO_OP:
		break;
	    default:
		XDVI_FATAL((stderr, "Bad command in GF file:  %d", cmnd));
	    }	/* end switch */
	if (new_row) {
	    basep += bytes_wide / sizeof(bmUnitT);
	    /* 	    *((char **)&basep) += bytes_wide; */
	    if (basep >= maxp || cp >= basep)
		too_many_bits(ch);
	    cp = basep;
	    word_weight = BMBITS;
	    new_row = False;
	}
	if (count >= 0) {
	    while (count)
		if (count <= word_weight) {
#ifndef	WORDS_BIGENDIAN
		    if (paint_switch)
			*cp |= bit_masks[count] << (BMBITS - word_weight);
#endif
		    word_weight -= count;
#ifdef	WORDS_BIGENDIAN
		    if (paint_switch)
			*cp |= bit_masks[count] << word_weight;
#endif
		    break;
		}
		else {
		    if (paint_switch)
#ifndef	WORDS_BIGENDIAN
			*cp |= bit_masks[word_weight] << (BMBITS - word_weight);
#else
		    *cp |= bit_masks[word_weight];
#endif
		    cp++;
		    count -= word_weight;
		    word_weight = BMBITS;
		}
	    paint_switch = 1 - paint_switch;
	}
    }	/* end for */
}
Ejemplo n.º 15
0
/*
* AES Decryption
*/
void aes_decrypt_n(const byte in[], byte out[], size_t blocks,
                   const secure_vector<u32bit>& DK,
                   const secure_vector<byte>& MD)
   {
   BOTAN_ASSERT(DK.size() && MD.size() == 16, "Key was set");

   const size_t cache_line_size = CPUID::cache_line_size();
   const std::vector<u32bit>& TD = AES_TD();

   u32bit Z = 0;
   for(size_t i = 0; i < TD.size(); i += cache_line_size / sizeof(u32bit))
      {
      Z |= TD[i];
      }
   Z &= TD[99]; // this is zero, which hopefully the compiler cannot deduce

   for(size_t i = 0; i != blocks; ++i)
      {
      u32bit T0 = load_be<u32bit>(in, 0) ^ DK[0];
      u32bit T1 = load_be<u32bit>(in, 1) ^ DK[1];
      u32bit T2 = load_be<u32bit>(in, 2) ^ DK[2];
      u32bit T3 = load_be<u32bit>(in, 3) ^ DK[3];

      T0 ^= Z;

      u32bit B0 = TD[get_byte(0, T0)] ^
                  rotate_right(TD[get_byte(1, T3)],  8) ^
                  rotate_right(TD[get_byte(2, T2)], 16) ^
                  rotate_right(TD[get_byte(3, T1)], 24) ^ DK[4];

      u32bit B1 = TD[get_byte(0, T1)] ^
                  rotate_right(TD[get_byte(1, T0)],  8) ^
                  rotate_right(TD[get_byte(2, T3)], 16) ^
                  rotate_right(TD[get_byte(3, T2)], 24) ^ DK[5];

      u32bit B2 = TD[get_byte(0, T2)] ^
                  rotate_right(TD[get_byte(1, T1)],  8) ^
                  rotate_right(TD[get_byte(2, T0)], 16) ^
                  rotate_right(TD[get_byte(3, T3)], 24) ^ DK[6];

      u32bit B3 = TD[get_byte(0, T3)] ^
                  rotate_right(TD[get_byte(1, T2)],  8) ^
                  rotate_right(TD[get_byte(2, T1)], 16) ^
                  rotate_right(TD[get_byte(3, T0)], 24) ^ DK[7];

      for(size_t r = 2*4; r < DK.size(); r += 2*4)
         {
         T0 = DK[r  ] ^ TD[get_byte(0, B0)      ] ^ TD[get_byte(1, B3) + 256] ^
                        TD[get_byte(2, B2) + 512] ^ TD[get_byte(3, B1) + 768];
         T1 = DK[r+1] ^ TD[get_byte(0, B1)      ] ^ TD[get_byte(1, B0) + 256] ^
                        TD[get_byte(2, B3) + 512] ^ TD[get_byte(3, B2) + 768];
         T2 = DK[r+2] ^ TD[get_byte(0, B2)      ] ^ TD[get_byte(1, B1) + 256] ^
                        TD[get_byte(2, B0) + 512] ^ TD[get_byte(3, B3) + 768];
         T3 = DK[r+3] ^ TD[get_byte(0, B3)      ] ^ TD[get_byte(1, B2) + 256] ^
                        TD[get_byte(2, B1) + 512] ^ TD[get_byte(3, B0) + 768];

         B0 = DK[r+4] ^ TD[get_byte(0, T0)      ] ^ TD[get_byte(1, T3) + 256] ^
                        TD[get_byte(2, T2) + 512] ^ TD[get_byte(3, T1) + 768];
         B1 = DK[r+5] ^ TD[get_byte(0, T1)      ] ^ TD[get_byte(1, T0) + 256] ^
                        TD[get_byte(2, T3) + 512] ^ TD[get_byte(3, T2) + 768];
         B2 = DK[r+6] ^ TD[get_byte(0, T2)      ] ^ TD[get_byte(1, T1) + 256] ^
                        TD[get_byte(2, T0) + 512] ^ TD[get_byte(3, T3) + 768];
         B3 = DK[r+7] ^ TD[get_byte(0, T3)      ] ^ TD[get_byte(1, T2) + 256] ^
                        TD[get_byte(2, T1) + 512] ^ TD[get_byte(3, T0) + 768];
         }

      out[ 0] = SD[get_byte(0, B0)] ^ MD[0];
      out[ 1] = SD[get_byte(1, B3)] ^ MD[1];
      out[ 2] = SD[get_byte(2, B2)] ^ MD[2];
      out[ 3] = SD[get_byte(3, B1)] ^ MD[3];
      out[ 4] = SD[get_byte(0, B1)] ^ MD[4];
      out[ 5] = SD[get_byte(1, B0)] ^ MD[5];
      out[ 6] = SD[get_byte(2, B3)] ^ MD[6];
      out[ 7] = SD[get_byte(3, B2)] ^ MD[7];
      out[ 8] = SD[get_byte(0, B2)] ^ MD[8];
      out[ 9] = SD[get_byte(1, B1)] ^ MD[9];
      out[10] = SD[get_byte(2, B0)] ^ MD[10];
      out[11] = SD[get_byte(3, B3)] ^ MD[11];
      out[12] = SD[get_byte(0, B3)] ^ MD[12];
      out[13] = SD[get_byte(1, B2)] ^ MD[13];
      out[14] = SD[get_byte(2, B1)] ^ MD[14];
      out[15] = SD[get_byte(3, B0)] ^ MD[15];

      in += 16;
      out += 16;
      }
   }
Ejemplo n.º 16
0
void BytecodePrinter::print_attributes(Bytecodes::Code code, int bci, outputStream* st) {
  // Show attributes of pre-rewritten codes
  code = Bytecodes::java_code(code);
  // If the code doesn't have any fields there's nothing to print.
  // note this is ==1 because the tableswitch and lookupswitch are
  // zero size (for some reason) and we want to print stuff out for them.
  if (Bytecodes::length_for(code) == 1) {
    st->cr();
    return;
  }

  switch(code) {
    // Java specific bytecodes only matter.
    case Bytecodes::_bipush:
      st->print_cr(" " INT32_FORMAT, get_byte());
      break;
    case Bytecodes::_sipush:
      st->print_cr(" " INT32_FORMAT, get_short());
      break;
    case Bytecodes::_ldc:
      print_constant(get_index(), st);
      break;

    case Bytecodes::_ldc_w:
    case Bytecodes::_ldc2_w:
      print_constant(get_big_index(), st);
      break;

    case Bytecodes::_iload:
    case Bytecodes::_lload:
    case Bytecodes::_fload:
    case Bytecodes::_dload:
    case Bytecodes::_aload:
    case Bytecodes::_istore:
    case Bytecodes::_lstore:
    case Bytecodes::_fstore:
    case Bytecodes::_dstore:
    case Bytecodes::_astore:
      st->print_cr(" #%d", get_index_special());
      break;

    case Bytecodes::_iinc:
      { int index = get_index_special();
        jint offset = is_wide() ? get_short(): get_byte();
        st->print_cr(" #%d " INT32_FORMAT, index, offset);
      }
      break;

    case Bytecodes::_newarray: {
        BasicType atype = (BasicType)get_index();
        const char* str = type2name(atype);
        if (str == NULL || atype == T_OBJECT || atype == T_ARRAY) {
          assert(false, "Unidentified basic type");
        }
        st->print_cr(" %s", str);
      }
      break;
    case Bytecodes::_anewarray: {
        int klass_index = get_big_index();
        constantPoolOop constants = method()->constants();
        symbolOop name = constants->klass_name_at(klass_index);
        st->print_cr(" %s ", name->as_C_string());
      }
      break;
    case Bytecodes::_multianewarray: {
        int klass_index = get_big_index();
        int nof_dims = get_index();
        constantPoolOop constants = method()->constants();
        symbolOop name = constants->klass_name_at(klass_index);
        st->print_cr(" %s %d", name->as_C_string(), nof_dims);
      }
      break;

    case Bytecodes::_ifeq:
    case Bytecodes::_ifnull:
    case Bytecodes::_iflt:
    case Bytecodes::_ifle:
    case Bytecodes::_ifne:
    case Bytecodes::_ifnonnull:
    case Bytecodes::_ifgt:
    case Bytecodes::_ifge:
    case Bytecodes::_if_icmpeq:
    case Bytecodes::_if_icmpne:
    case Bytecodes::_if_icmplt:
    case Bytecodes::_if_icmpgt:
    case Bytecodes::_if_icmple:
    case Bytecodes::_if_icmpge:
    case Bytecodes::_if_acmpeq:
    case Bytecodes::_if_acmpne:
    case Bytecodes::_goto:
    case Bytecodes::_jsr:
      st->print_cr(" %d", bci + get_short());
      break;

    case Bytecodes::_goto_w:
    case Bytecodes::_jsr_w:
      st->print_cr(" %d", bci + get_int());
      break;

    case Bytecodes::_ret: st->print_cr(" %d", get_index_special()); break;

    case Bytecodes::_tableswitch:
      { align();
        int  default_dest = bci + get_int();
        int  lo           = get_int();
        int  hi           = get_int();
        int  len          = hi - lo + 1;
        jint* dest        = NEW_RESOURCE_ARRAY(jint, len);
        for (int i = 0; i < len; i++) {
          dest[i] = bci + get_int();
        }
        st->print(" %d " INT32_FORMAT " " INT32_FORMAT " ",
                      default_dest, lo, hi);
        int first = true;
        for (int ll = lo; ll <= hi; ll++, first = false)  {
          int idx = ll - lo;
          const char *format = first ? " %d:" INT32_FORMAT " (delta: %d)" :
                                       ", %d:" INT32_FORMAT " (delta: %d)";
          st->print(format, ll, dest[idx], dest[idx]-bci);
        }
        st->cr();
      }
      break;
    case Bytecodes::_lookupswitch:
      { align();
        int  default_dest = bci + get_int();
        int  len          = get_int();
        jint* key         = NEW_RESOURCE_ARRAY(jint, len);
        jint* dest        = NEW_RESOURCE_ARRAY(jint, len);
        for (int i = 0; i < len; i++) {
          key [i] = get_int();
          dest[i] = bci + get_int();
        };
        st->print(" %d %d ", default_dest, len);
        bool first = true;
        for (int ll = 0; ll < len; ll++, first = false)  {
          const char *format = first ? " " INT32_FORMAT ":" INT32_FORMAT :
                                       ", " INT32_FORMAT ":" INT32_FORMAT ;
          st->print(format, key[ll], dest[ll]);
        }
        st->cr();
      }
      break;

    case Bytecodes::_putstatic:
    case Bytecodes::_getstatic:
    case Bytecodes::_putfield:
    case Bytecodes::_getfield:
      print_field_or_method(get_big_index(), st);
      break;

    case Bytecodes::_invokevirtual:
    case Bytecodes::_invokespecial:
    case Bytecodes::_invokestatic:
      print_field_or_method(get_big_index(), st);
      break;

    case Bytecodes::_invokeinterface:
      { int i = get_big_index();
        int n = get_index();
        get_index();            // ignore zero byte
        print_field_or_method(i, st);
      }
      break;

    case Bytecodes::_invokedynamic:
      print_field_or_method(get_giant_index(), st);
      break;

    case Bytecodes::_new:
    case Bytecodes::_checkcast:
    case Bytecodes::_instanceof:
      { int i = get_big_index();
        constantPoolOop constants = method()->constants();
        symbolOop name = constants->klass_name_at(i);
        st->print_cr(" %d <%s>", i, name->as_C_string());
      }
      break;

    case Bytecodes::_wide:
      // length is zero not one, but printed with no more info.
      break;

    default:
      ShouldNotReachHere();
      break;
  }
}
Ejemplo n.º 17
0
void aes_key_schedule(const byte key[], size_t length,
                      secure_vector<u32bit>& EK,
                      secure_vector<u32bit>& DK,
                      secure_vector<byte>& ME,
                      secure_vector<byte>& MD)
   {
   static const u32bit RC[10] = {
      0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000,
      0x20000000, 0x40000000, 0x80000000, 0x1B000000, 0x36000000 };

   const size_t rounds = (length / 4) + 6;

   secure_vector<u32bit> XEK(length + 32), XDK(length + 32);

   const size_t X = length / 4;
   for(size_t i = 0; i != X; ++i)
      XEK[i] = load_be<u32bit>(key, i);

   for(size_t i = X; i < 4*(rounds+1); i += X)
      {
      XEK[i] = XEK[i-X] ^ RC[(i-X)/X] ^
               make_u32bit(SE[get_byte(1, XEK[i-1])],
                           SE[get_byte(2, XEK[i-1])],
                           SE[get_byte(3, XEK[i-1])],
                           SE[get_byte(0, XEK[i-1])]);

      for(size_t j = 1; j != X; ++j)
         {
         XEK[i+j] = XEK[i+j-X];

         if(X == 8 && j == 4)
            XEK[i+j] ^= make_u32bit(SE[get_byte(0, XEK[i+j-1])],
                                    SE[get_byte(1, XEK[i+j-1])],
                                    SE[get_byte(2, XEK[i+j-1])],
                                    SE[get_byte(3, XEK[i+j-1])]);
         else
            XEK[i+j] ^= XEK[i+j-1];
         }
      }

   const std::vector<u32bit>& TD = AES_TD();

   for(size_t i = 0; i != 4*(rounds+1); i += 4)
      {
      XDK[i  ] = XEK[4*rounds-i  ];
      XDK[i+1] = XEK[4*rounds-i+1];
      XDK[i+2] = XEK[4*rounds-i+2];
      XDK[i+3] = XEK[4*rounds-i+3];
      }

   for(size_t i = 4; i != length + 24; ++i)
      XDK[i] = TD[SE[get_byte(0, XDK[i])] +   0] ^
               TD[SE[get_byte(1, XDK[i])] + 256] ^
               TD[SE[get_byte(2, XDK[i])] + 512] ^
               TD[SE[get_byte(3, XDK[i])] + 768];

   ME.resize(16);
   MD.resize(16);

   for(size_t i = 0; i != 4; ++i)
      {
      store_be(XEK[i+4*rounds], &ME[4*i]);
      store_be(XEK[i], &MD[4*i]);
      }

   EK.resize(length + 24);
   DK.resize(length + 24);
   copy_mem(EK.data(), XEK.data(), EK.size());
   copy_mem(DK.data(), XDK.data(), DK.size());
   }
Ejemplo n.º 18
0
static int checkheader(z_stream *stream) {
    int flags, c;
    DWORD len;

    if (get_byte(stream) != 0x1f || get_byte(stream) != 0x8b)
        return Z_DATA_ERROR;
    if (get_byte(stream) != Z_DEFLATED || ((flags = get_byte(stream)) & 0xE0) != 0)
        return Z_DATA_ERROR;
    for (len = 0; len < 6; len++) (void)get_byte(stream);

    if ((flags & 0x04) != 0) { /* skip the extra field */
        len  =  (DWORD)get_byte(stream);
        len += ((DWORD)get_byte(stream)) << 8;
        /* len is garbage if EOF but the loop below will quit anyway */
        while (len-- != 0 && get_byte(stream) != EOF) ;
    }
    if ((flags & 0x08) != 0) { /* skip the original file name */
        while ((c = get_byte(stream)) != 0 && c != EOF) ;
    }
    if ((flags & 0x10) != 0) {   /* skip the .gz file comment */
        while ((c = get_byte(stream)) != 0 && c != EOF) ;
    }
    if ((flags & 0x02) != 0) {  /* skip the header crc */
        for (len = 0; len < 2; len++) (void)get_byte(stream);
    }
    return Z_OK;
}
Ejemplo n.º 19
0
static bool
transform_html_ucs2 (RECODE_SUBTASK subtask)
{
  RECODE_CONST_REQUEST request = subtask->task->request;
  int input_char;

  input_char = get_byte (subtask);
  if (input_char != EOF)
    put_ucs2 (BYTE_ORDER_MARK, subtask);	/* FIXME: experimental */

  while (input_char != EOF)

    if (input_char == '&')
      {
	char buffer[ENTITY_BUFFER_LENGTH];
	char *cursor = buffer;
	bool valid = true;
	bool echo = false;

	input_char = get_byte (subtask);
	if (input_char == '#')
	  {
	    input_char = get_byte (subtask);
	    if (input_char == 'x' || input_char == 'X')
	      {
		unsigned value = 0;

		/* Scan &#[xX][0-9a-fA-F]+; notation.  */

		*cursor++ = '#';
		*cursor++ = input_char;
		input_char = get_byte (subtask);

		while (valid)
		  {
		    if (input_char >= '0' && input_char <= '9')
		      value = 16 * value + input_char - '0';
		    else if (input_char >= 'A' && input_char <= 'F')
		      value = 16 * value + input_char - 'A' + 10;
		    else if (input_char >= 'a' && input_char <= 'f')
		      value = 16 * value + input_char - 'a' + 10;
		    else
		      break;

		    if (value >= 65535)
		      valid = false;
		    else if (cursor == buffer + ENTITY_BUFFER_LENGTH - 2)
		      valid = false;
		    else
		      {
			*cursor++ = input_char;
			input_char = get_byte (subtask);
		      }
		  }

		if (valid)
		  if (request->diacritics_only)
		    {
		      echo = true;
		      *cursor = '\0';
		    }
		  else
		    {
		      put_ucs2 (value, subtask);
		      if (input_char == ';')
			input_char = get_byte (subtask);
		    }
		else
		  *cursor = '\0';
	      }
	    else
	      {
		unsigned value = 0;

		/* Scan &#[0-9]+; notation.  */

		*cursor++ = '#';

		while (valid)
		  {
		    if (input_char >= '0' && input_char <= '9')
		      value = 10 * value + input_char - '0';
		    else
		      break;

		    if (value >= 65535)
		      valid = false;
		    else if (cursor == buffer + ENTITY_BUFFER_LENGTH - 2)
		      valid = false;
		    else
		      {
			*cursor++ = input_char;
			input_char = get_byte (subtask);
		      }
		  }

		if (valid)
		  if (request->diacritics_only)
		    {
		      echo = true;
		      *cursor = '\0';
		    }
		  else
		    {
		      put_ucs2 (value, subtask);
		      if (input_char == ';')
			input_char = get_byte (subtask);
		    }
		else
		  *cursor = '\0';
	      }
	  }
	else if ((input_char >= 'A' && input_char <= 'Z')
		 || (input_char >= 'a' && input_char <= 'z'))
	  {
	    /* Scan &[A-Za-z][A-Za-z0-9]*; notation.  */

	    *cursor++ = input_char;
	    input_char = get_byte (subtask);

	    while (valid
		   && input_char != EOF
		   && ((input_char >= 'A' && input_char <= 'Z')
		       || (input_char >= 'a' && input_char <= 'z')
		       || (input_char >= '0' && input_char <= '9')))
	      if (cursor == buffer + ENTITY_BUFFER_LENGTH - 2)
		valid = false;
	      else
		{
		  *cursor++ = input_char;
		  input_char = get_byte (subtask);
		}
	    *cursor = '\0';

	    if (valid)
	      {
		struct ucs2_to_string lookup;
		struct ucs2_to_string *entry;

		lookup.string = buffer;
		entry = hash_lookup (subtask->step->step_table, &lookup);
		if (entry)
		  {
		    put_ucs2 (entry->code, subtask);
		    if (input_char == ';')
		      input_char = get_byte (subtask);
		  }
		else
		  valid = false;
	      }
	  }

	if (echo || !valid)
	  {
	    put_ucs2 ('&', subtask);
	    for (cursor = buffer; *cursor; cursor++)
	      put_ucs2 (*cursor, subtask);
	  }
      }
    else
      {
	put_ucs2 (input_char, subtask);
	input_char = get_byte (subtask);
      }

  SUBTASK_RETURN (subtask);
}
Ejemplo n.º 20
0
static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb)
{
    WVContext *wc = ctx->priv_data;
    uint32_t tag, ver;
    int size;
    int rate, bpp, chan;

    wc->pos = url_ftell(pb);
    tag = get_le32(pb);
    if (tag != MKTAG('w', 'v', 'p', 'k'))
        return -1;
    size = get_le32(pb);
    if(size < 24 || size > WV_BLOCK_LIMIT){
        av_log(ctx, AV_LOG_ERROR, "Incorrect block size %i\n", size);
        return -1;
    }
    wc->blksize = size;
    ver = get_le16(pb);
    if(ver < 0x402 || ver > 0x40F){
        av_log(ctx, AV_LOG_ERROR, "Unsupported version %03X\n", ver);
        return -1;
    }
    get_byte(pb); // track no
    get_byte(pb); // track sub index
    wc->samples = get_le32(pb); // total samples in file
    wc->soff = get_le32(pb); // offset in samples of current block
    get_buffer(pb, wc->extra, WV_EXTRA_SIZE);
    wc->flags = AV_RL32(wc->extra + 4);
    //parse flags
    if(wc->flags & WV_FLOAT){
        av_log(ctx, AV_LOG_ERROR, "Floating point data is not supported\n");
        return -1;
    }
    if(wc->flags & WV_HYBRID){
        av_log(ctx, AV_LOG_ERROR, "Hybrid coding mode is not supported\n");
        return -1;
    }
    if(wc->flags & WV_INT32){
        av_log(ctx, AV_LOG_ERROR, "Integer point data is not supported\n");
        return -1;
    }

    bpp = ((wc->flags & 3) + 1) << 3;
    chan = 1 + !(wc->flags & WV_MONO);
    rate = wv_rates[(wc->flags >> 23) & 0xF];
    if(rate == -1){
        av_log(ctx, AV_LOG_ERROR, "Unknown sampling rate\n");
        return -1;
    }
    if(!wc->bpp) wc->bpp = bpp;
    if(!wc->chan) wc->chan = chan;
    if(!wc->rate) wc->rate = rate;

    if(wc->flags && bpp != wc->bpp){
        av_log(ctx, AV_LOG_ERROR, "Bits per sample differ, this block: %i, header block: %i\n", bpp, wc->bpp);
        return -1;
    }
    if(wc->flags && chan != wc->chan){
        av_log(ctx, AV_LOG_ERROR, "Channels differ, this block: %i, header block: %i\n", chan, wc->chan);
        return -1;
    }
    if(wc->flags && rate != wc->rate){
        av_log(ctx, AV_LOG_ERROR, "Sampling rate differ, this block: %i, header block: %i\n", rate, wc->rate);
        return -1;
    }
    wc->blksize = size - 24;
    return 0;
}
Ejemplo n.º 21
0
/*
 * Process the color table for the bmp input
 */
 bool SkBmpRLECodec::createColorTable(SkColorType dstColorType, int* numColors) {
    // Allocate memory for color table
    uint32_t colorBytes = 0;
    SkPMColor colorTable[256];
    if (this->bitsPerPixel() <= 8) {
        // Inform the caller of the number of colors
        uint32_t maxColors = 1 << this->bitsPerPixel();
        if (nullptr != numColors) {
            // We set the number of colors to maxColors in order to ensure
            // safe memory accesses.  Otherwise, an invalid pixel could
            // access memory outside of our color table array.
            *numColors = maxColors;
        }
        // Don't bother reading more than maxColors.
        const uint32_t numColorsToRead =
            fNumColors == 0 ? maxColors : SkTMin(fNumColors, maxColors);

        // Read the color table from the stream
        colorBytes = numColorsToRead * fBytesPerColor;
        SkAutoTDeleteArray<uint8_t> cBuffer(new uint8_t[colorBytes]);
        if (stream()->read(cBuffer.get(), colorBytes) != colorBytes) {
            SkCodecPrintf("Error: unable to read color table.\n");
            return false;
        }

        // Fill in the color table
        PackColorProc packARGB = choose_pack_color_proc(false, dstColorType);
        uint32_t i = 0;
        for (; i < numColorsToRead; i++) {
            uint8_t blue = get_byte(cBuffer.get(), i*fBytesPerColor);
            uint8_t green = get_byte(cBuffer.get(), i*fBytesPerColor + 1);
            uint8_t red = get_byte(cBuffer.get(), i*fBytesPerColor + 2);
            colorTable[i] = packARGB(0xFF, red, green, blue);
        }

        // To avoid segmentation faults on bad pixel data, fill the end of the
        // color table with black.  This is the same the behavior as the
        // chromium decoder.
        for (; i < maxColors; i++) {
            colorTable[i] = SkPackARGB32NoCheck(0xFF, 0, 0, 0);
        }

        // Set the color table
        fColorTable.reset(new SkColorTable(colorTable, maxColors));
    }

    // Check that we have not read past the pixel array offset
    if(fOffset < colorBytes) {
        // This may occur on OS 2.1 and other old versions where the color
        // table defaults to max size, and the bmp tries to use a smaller
        // color table.  This is invalid, and our decision is to indicate
        // an error, rather than try to guess the intended size of the
        // color table.
        SkCodecPrintf("Error: pixel data offset less than color table size.\n");
        return false;
    }

    // After reading the color table, skip to the start of the pixel array
    if (stream()->skip(fOffset - colorBytes) != fOffset - colorBytes) {
        SkCodecPrintf("Error: unable to skip to image data.\n");
        return false;
    }

    // Return true on success
    return true;
}
Ejemplo n.º 22
0
void InterpretCall(int object_id,local_var_type *local_vars,opcode_type opcode)
{
	parm_node normal_parm_array[MAX_C_PARMS],name_parm_array[MAX_NAME_PARMS]; 
	unsigned char info,num_normal_parms,num_name_parms,initial_type;
	int initial_value;
	val_type call_return;
	
	val_type name_val;
	int assign_index;
	int i;
	
	info = get_byte(); /* get function id */
	
	switch(opcode.source1)
	{
	case CALL_NO_ASSIGN :
		break;
	case CALL_ASSIGN_LOCAL_VAR :
	case CALL_ASSIGN_PROPERTY :
		assign_index = get_int();
		break;
	}
	
	num_normal_parms = get_byte();
	
	if (num_normal_parms > MAX_C_PARMS)
	{
		bprintf("InterpretCall found a call w/ more than %i parms, DEATH\n",
			MAX_C_PARMS);
		FlushDefaultChannels();
		num_normal_parms = MAX_C_PARMS;
	}
	
	for (i=0;i<num_normal_parms;i++)
	{
		normal_parm_array[i].type = get_byte();
		normal_parm_array[i].value = get_int();
	}
	
	num_name_parms = get_byte();
	
	if (num_name_parms > MAX_NAME_PARMS)
	{
		bprintf("InterpretCall found a call w/ more than %i name parms, DEATH\n",
			MAX_NAME_PARMS);
		FlushDefaultChannels();
		num_name_parms = MAX_NAME_PARMS;
	}
	
	for (i=0;i<num_name_parms;i++)
	{
		name_parm_array[i].name_id = get_int();
		
		initial_type = get_byte();
		initial_value = get_int();
		
		/* translate to literal now, because won't have local vars
		if nested call to sendmessage again */
		
		/* maybe only need to do this in call to sendmessage and postmessage? */
		
		name_val = RetrieveValue(object_id,local_vars,initial_type,initial_value);
		
		name_parm_array[i].value = name_val.int_val;
	}
	
	/* increment count of the c function, for profiling info */
	kod_stat.c_count[info]++;
	
	call_return.int_val = ccall_table[info](object_id,local_vars,num_normal_parms,
					   normal_parm_array,num_name_parms,
					   name_parm_array);
	
	switch(opcode.source1)
	{
		case CALL_NO_ASSIGN :
			break;
		case CALL_ASSIGN_LOCAL_VAR :
		case CALL_ASSIGN_PROPERTY :
			StoreValue(object_id,local_vars,opcode.source1,assign_index,call_return);      
			break;
	}
}
Ejemplo n.º 23
0
/*
* Tiger Pass
*/
void Tiger::pass(u64bit& A, u64bit& B, u64bit& C,
                 const MemoryRegion<u64bit>& X,
                 byte mul)
   {
   C ^= X[0];
   A -= SBOX1[get_byte(7, C)] ^ SBOX2[get_byte(5, C)] ^
        SBOX3[get_byte(3, C)] ^ SBOX4[get_byte(1, C)];
   B += SBOX1[get_byte(0, C)] ^ SBOX2[get_byte(2, C)] ^
        SBOX3[get_byte(4, C)] ^ SBOX4[get_byte(6, C)];
   B *= mul;

   A ^= X[1];
   B -= SBOX1[get_byte(7, A)] ^ SBOX2[get_byte(5, A)] ^
        SBOX3[get_byte(3, A)] ^ SBOX4[get_byte(1, A)];
   C += SBOX1[get_byte(0, A)] ^ SBOX2[get_byte(2, A)] ^
        SBOX3[get_byte(4, A)] ^ SBOX4[get_byte(6, A)];
   C *= mul;

   B ^= X[2];
   C -= SBOX1[get_byte(7, B)] ^ SBOX2[get_byte(5, B)] ^
        SBOX3[get_byte(3, B)] ^ SBOX4[get_byte(1, B)];
   A += SBOX1[get_byte(0, B)] ^ SBOX2[get_byte(2, B)] ^
        SBOX3[get_byte(4, B)] ^ SBOX4[get_byte(6, B)];
   A *= mul;

   C ^= X[3];
   A -= SBOX1[get_byte(7, C)] ^ SBOX2[get_byte(5, C)] ^
        SBOX3[get_byte(3, C)] ^ SBOX4[get_byte(1, C)];
   B += SBOX1[get_byte(0, C)] ^ SBOX2[get_byte(2, C)] ^
        SBOX3[get_byte(4, C)] ^ SBOX4[get_byte(6, C)];
   B *= mul;

   A ^= X[4];
   B -= SBOX1[get_byte(7, A)] ^ SBOX2[get_byte(5, A)] ^
        SBOX3[get_byte(3, A)] ^ SBOX4[get_byte(1, A)];
   C += SBOX1[get_byte(0, A)] ^ SBOX2[get_byte(2, A)] ^
        SBOX3[get_byte(4, A)] ^ SBOX4[get_byte(6, A)];
   C *= mul;

   B ^= X[5];
   C -= SBOX1[get_byte(7, B)] ^ SBOX2[get_byte(5, B)] ^
        SBOX3[get_byte(3, B)] ^ SBOX4[get_byte(1, B)];
   A += SBOX1[get_byte(0, B)] ^ SBOX2[get_byte(2, B)] ^
        SBOX3[get_byte(4, B)] ^ SBOX4[get_byte(6, B)];
   A *= mul;

   C ^= X[6];
   A -= SBOX1[get_byte(7, C)] ^ SBOX2[get_byte(5, C)] ^
        SBOX3[get_byte(3, C)] ^ SBOX4[get_byte(1, C)];
   B += SBOX1[get_byte(0, C)] ^ SBOX2[get_byte(2, C)] ^
        SBOX3[get_byte(4, C)] ^ SBOX4[get_byte(6, C)];
   B *= mul;

   A ^= X[7];
   B -= SBOX1[get_byte(7, A)] ^ SBOX2[get_byte(5, A)] ^
        SBOX3[get_byte(3, A)] ^ SBOX4[get_byte(1, A)];
   C += SBOX1[get_byte(0, A)] ^ SBOX2[get_byte(2, A)] ^
        SBOX3[get_byte(4, A)] ^ SBOX4[get_byte(6, A)];
   C *= mul;
   }
Ejemplo n.º 24
0
/* returns either RETURN_PROPAGATE or RETURN_NO_PROPAGATE.  If no propagate,
* then the return value in ret_val is good.
*/
int InterpretAtMessage(int object_id,class_node* c,message_node* m,
					   int num_sent_parms,
					   parm_node sent_parms[],val_type *ret_val)
{
	opcode_type opcode;
	char opcode_char;
	char num_locals,num_parms;
	local_var_type local_vars;
	int parm_id;
	val_type parm_init_value;
	
	int i,j;
	char *inst_start;
	Bool found_parm;
	
	num_locals = get_byte();
	num_parms = get_byte();
	
	local_vars.num_locals = num_locals+num_parms;
	if (local_vars.num_locals > MAX_LOCALS)
	{
		dprintf("InterpretAtMessage found too many locals and parms for OBJECT %i CLASS %s MESSAGE %s (%s) aborting and returning NIL\n",
			object_id,
			c? c->class_name : "(unknown)",
			m? GetNameByID(m->message_id) : "(unknown)",
			BlakodDebugInfo());
		(*ret_val).int_val = NIL;
		return RETURN_NO_PROPAGATE;
	}
	
	if (ConfigBool(DEBUG_INITLOCALS))
	{
		parm_init_value.v.tag = TAG_INVALID;
		parm_init_value.v.data = 1;
		
		for (i = 0; i < local_vars.num_locals; i++)
		{
			local_vars.locals[i] = parm_init_value;
		}
	}
	
	/* both table and call parms are sorted */
	
	j = 0;
	for (i=0;i<num_parms;i++)
	{
		parm_id = get_int(); /* match this with parameters */
		parm_init_value.int_val = get_int();
		
		/* look if we have a value for this parm */
		found_parm = False;
		j = 0;			/* don't assume sorted for now */
		while (j < num_sent_parms)
		{
			if (sent_parms[j].name_id == parm_id)
			{
			/* assuming no RetrieveValue needed here, since InterpretCall
				does that for us */
				local_vars.locals[i].int_val = sent_parms[j].value;
				found_parm = True;
				j++;
				break;
			}
			j++;
		}
		
		if (!found_parm)
			local_vars.locals[i].int_val = parm_init_value.int_val;
	}
	
	for(;;)			/* returns when gets a blakod return */
	{
		num_interpreted++;
		
		/* infinite loop check */
		if (num_interpreted > ConfigInt(BLAKOD_MAX_STATEMENTS))
		{
			bprintf("InterpretAtMessage interpreted too many instructions--infinite loop?\n");
			
			dprintf("Infinite loop at depth %i\n", message_depth);
			dprintf("  OBJECT %i CLASS %s MESSAGE %s (%s) aborting and returning NIL\n",
				object_id,
				c? c->class_name : "(unknown)",
				m? GetNameByID(m->message_id) : "(unknown)",
				BlakodDebugInfo());
			
			dprintf("  Local variables:\n");
			for (i=0;i<local_vars.num_locals;i++)
			{
				dprintf("  %3i : %s %5i\n",
					i,
					GetTagName(local_vars.locals[i]),
					local_vars.locals[i].v.data);
			}
			
			(*ret_val).int_val = NIL;
			return RETURN_NO_PROPAGATE;
		}
		
		opcode_char = get_byte();
		
		//memcpy(&opcode,&opcode_char,1);
		{
			char *ch=(char*)&opcode;
			*ch = opcode_char ;
		}
		
		/* use continues instead of breaks here since there is nothing
		after the switch, for efficiency */
		
		switch (opcode.command)
		{
			case UNARY_ASSIGN : 
				InterpretUnaryAssign(object_id,&local_vars,opcode);
				continue;
			case BINARY_ASSIGN : 
				InterpretBinaryAssign(object_id,&local_vars,opcode);
				continue;
			case GOTO : 
				inst_start = bkod - 1; /* we've read one byte of instruction so far */
				InterpretGoto(object_id,&local_vars,opcode,inst_start);
				continue;
			case CALL : 
				InterpretCall(object_id,&local_vars,opcode);
				continue;
			case RETURN : 
				if (opcode.dest == PROPAGATE)
					return RETURN_PROPAGATE;
				else
				{
					int data;
					data = get_int();	    
					*ret_val = RetrieveValue(object_id,&local_vars,opcode.source1,data);
					return RETURN_NO_PROPAGATE;
				}
				/* can't get here */
					continue;
			default : 
				bprintf("InterpretAtMessage found INVALID OPCODE command %i.  die.\n", opcode.command);
				FlushDefaultChannels();
				continue;
		}
	}
}
Ejemplo n.º 25
0
static void skip_bytes(int n)
{
    while (--n >= 0)
        get_byte();
}
Ejemplo n.º 26
0
void InterpretBinaryAssign(int object_id,local_var_type *local_vars,opcode_type opcode)
{
	char info;
	int dest,source1,source2;
	val_type source1_data,source2_data;
	
	info = get_byte();
	dest = get_int();
	source1 = get_int();
	source2 = get_int();
	
	source1_data = RetrieveValue(object_id,local_vars,opcode.source1,source1);
	source2_data = RetrieveValue(object_id,local_vars,opcode.source2,source2);
	
	/*
	if (source1_data.v.tag != source2_data.v.tag)
	bprintf("InterpretBinaryAssign is operating on 2 diff types!\n");
	*/
	switch (info)
	{
	case ADD : 
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't add 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data += source2_data.v.data;
		break;
	case SUBTRACT :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't sub 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data -= source2_data.v.data;
		break;
	case MULTIPLY :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't mult 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data *= source2_data.v.data;
		break;
	case DIV :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't div 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		if (source2_data.v.data == 0)
		{
			bprintf("InterpretBinaryAssign can't div by 0\n");
			break;
		}
		source1_data.v.data /= source2_data.v.data;
		break;
	case MOD :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't mod 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		if (source2_data.v.data == 0)
		{
			bprintf("InterpretBinaryAssign can't mod 0\n");
			break;
		}
		source1_data.v.data = abs(source1_data.v.data % source2_data.v.data);
		
		break;
	case AND :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't and 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data = source1_data.v.data && source2_data.v.data;
		break;
	case OR :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't or 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data = source1_data.v.data || source2_data.v.data;
		break;
		
	case EQUAL :
		
#if 0
		// disabled:  used to be only TAG_NIL vs TAG_X, or TAG_X vs TAG_X is legal
		// now:  TAG_X vs TAG_Y is legal, and returns FALSE for equal
		
		if (source1_data.v.tag != source2_data.v.tag &&
			source1_data.v.tag != TAG_NIL && source2_data.v.tag != TAG_NIL)
		{
			bprintf("InterpretBinaryAssign can't = 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
#endif
		
		if (source1_data.v.tag != source2_data.v.tag)
			source1_data.v.data = False;
		else
			source1_data.v.data = source1_data.v.data == source2_data.v.data;
		source1_data.v.tag = TAG_INT;
		break;
		
	case NOT_EQUAL :
		
#if 0
		// disabled:  used to be only TAG_NIL vs TAG_X, or TAG_X vs TAG_X is legal
		// now:  TAG_X vs TAG_Y is legal, and returns TRUE for not equal
		
		if (source1_data.v.tag != source2_data.v.tag &&
			source1_data.v.tag != TAG_NIL && source2_data.v.tag != TAG_NIL)
		{
			bprintf("InterpretBinaryAssign can't <> 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
#endif
		
		if (source1_data.v.tag != source2_data.v.tag)
			source1_data.v.data = True; 
		else
			source1_data.v.data = source1_data.v.data != source2_data.v.data;
		source1_data.v.tag = TAG_INT;
		break;
	case LESS_THAN :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't < 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data = source1_data.v.data < source2_data.v.data;
		break;
	case GREATER_THAN :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't > 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data = source1_data.v.data > source2_data.v.data;
		break;
	case LESS_EQUAL :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't <= 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data = source1_data.v.data <= source2_data.v.data;
		break;
	case GREATER_EQUAL :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't >= 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data = source1_data.v.data >= source2_data.v.data;
		break;
	case BITWISE_AND :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't and 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data = source1_data.v.data & source2_data.v.data;
		break;
	case BITWISE_OR :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't or 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data = source1_data.v.data | source2_data.v.data;
		break;
	default :
		bprintf("InterpretBinaryAssign can't perform binary op %i\n",info);
		break;
   }
   
   StoreValue(object_id,local_vars,opcode.dest,dest,source1_data);
}
Ejemplo n.º 27
0
void z_verify( void )
{
   unsigned long file_size;
   unsigned int pages, offset;
   unsigned int start, end, i, j;
   zword_t checksum = 0;
   zbyte_t buffer[PAGE_SIZE] = { 0 };
   char szBuffer[6] = { 0 };

   /* Print version banner */

   z_new_line(  );
   write_string( "Running on " );
   write_string( JZIPVER );
   write_string( " (" );
   switch ( JTERP )
   {
      case INTERP_GENERIC:
         write_string( "Generic" );
         break;
      case INTERP_AMIGA:
         write_string( "Amiga" );
         break;
      case INTERP_ATARI_ST:
         write_string( "Atari ST" );
         break;
      case INTERP_MSDOS:
         write_string( "DOS" );
         break;
      case INTERP_UNIX:
         write_string( "UNIX" );
         break;
      case INTERP_VMS:
         write_string( "VMS" );
         break;
   }
   write_string( "). Reporting Spec " );
   sprintf( szBuffer, "%d.%d", get_byte( H_STANDARD_HIGH ), get_byte( H_STANDARD_LOW ) );
   write_string( szBuffer );
   write_string( " Compliance." );
   z_new_line(  );

   write_string( "Compile options: " );
#ifdef USE_QUETZAL
   write_string( "USE_QUETZAL " );
#endif
#ifdef STRICTZ
   write_string( "STRICTZ " );
#endif
#ifdef USE_ZLIB
   write_string( "USE_ZLIB " );
#endif
#ifdef LOUSY_RANDOM
   write_string( "LOUSY_RANDOM " );
#endif
#ifdef HARD_COLORS
   write_string( "HARD_COLORS " );
#endif
   z_new_line(  );

   write_string( "Release " );
   write_string( JZIPRELDATE );
   write_string( "." );
   z_new_line(  );

   write_string( "Playing a Version " );
   z_print_num( (zword_t) GLOBALVER );
   write_string( " Story." );
   z_new_line(  );

   z_new_line(  );

   /* Calculate game file dimensions */

   file_size = ( unsigned long ) h_file_size *story_scaler;

   pages = ( unsigned int ) ( ( unsigned long ) file_size / PAGE_SIZE );
   offset = ( unsigned int ) file_size & PAGE_MASK;

   /* Sum all bytes in game file, except header bytes */

   for ( i = 0; i <= pages; i++ )
   {
      read_page( i, buffer );
      start = ( i == 0 ) ? 64 : 0;
      end = ( i == pages ) ? offset : PAGE_SIZE;
      for ( j = start; j < end; j++ )
      {
         checksum += buffer[j];
      }
   }

   /* Make a conditional jump based on whether the checksum is equal */

   conditional_jump( checksum == h_checksum );

}                               /* z_verify */
Ejemplo n.º 28
0
/*
* AES Encryption
*/
void aes_encrypt_n(const byte in[], byte out[],
                   size_t blocks,
                   const secure_vector<u32bit>& EK,
                   const secure_vector<byte>& ME)
   {
   BOTAN_ASSERT(EK.size() && ME.size() == 16, "Key was set");

   const size_t cache_line_size = CPUID::cache_line_size();

   const std::vector<u32bit>& TE = AES_TE();

   // Hit every cache line of TE
   u32bit Z = 0;
   for(size_t i = 0; i < TE.size(); i += cache_line_size / sizeof(u32bit))
      {
      Z |= TE[i];
      }
   Z &= TE[82]; // this is zero, which hopefully the compiler cannot deduce

   for(size_t i = 0; i != blocks; ++i)
      {
      u32bit T0 = load_be<u32bit>(in, 0) ^ EK[0];
      u32bit T1 = load_be<u32bit>(in, 1) ^ EK[1];
      u32bit T2 = load_be<u32bit>(in, 2) ^ EK[2];
      u32bit T3 = load_be<u32bit>(in, 3) ^ EK[3];

      T0 ^= Z;

      /* Use only the first 256 entries of the TE table and do the
      * rotations directly in the code. This reduces the number of
      * cache lines potentially used in the first round from 64 to 16
      * (assuming a typical 64 byte cache line), which makes timing
      * attacks a little harder; the first round is particularly
      * vulnerable.
      */

      u32bit B0 = TE[get_byte(0, T0)] ^
                  rotate_right(TE[get_byte(1, T1)],  8) ^
                  rotate_right(TE[get_byte(2, T2)], 16) ^
                  rotate_right(TE[get_byte(3, T3)], 24) ^ EK[4];

      u32bit B1 = TE[get_byte(0, T1)] ^
                  rotate_right(TE[get_byte(1, T2)],  8) ^
                  rotate_right(TE[get_byte(2, T3)], 16) ^
                  rotate_right(TE[get_byte(3, T0)], 24) ^ EK[5];

      u32bit B2 = TE[get_byte(0, T2)] ^
                  rotate_right(TE[get_byte(1, T3)],  8) ^
                  rotate_right(TE[get_byte(2, T0)], 16) ^
                  rotate_right(TE[get_byte(3, T1)], 24) ^ EK[6];

      u32bit B3 = TE[get_byte(0, T3)] ^
                  rotate_right(TE[get_byte(1, T0)],  8) ^
                  rotate_right(TE[get_byte(2, T1)], 16) ^
                  rotate_right(TE[get_byte(3, T2)], 24) ^ EK[7];

      for(size_t r = 2*4; r < EK.size(); r += 2*4)
         {
         T0 = EK[r  ] ^ TE[get_byte(0, B0)      ] ^ TE[get_byte(1, B1) + 256] ^
                        TE[get_byte(2, B2) + 512] ^ TE[get_byte(3, B3) + 768];
         T1 = EK[r+1] ^ TE[get_byte(0, B1)      ] ^ TE[get_byte(1, B2) + 256] ^
                        TE[get_byte(2, B3) + 512] ^ TE[get_byte(3, B0) + 768];
         T2 = EK[r+2] ^ TE[get_byte(0, B2)      ] ^ TE[get_byte(1, B3) + 256] ^
                        TE[get_byte(2, B0) + 512] ^ TE[get_byte(3, B1) + 768];
         T3 = EK[r+3] ^ TE[get_byte(0, B3)      ] ^ TE[get_byte(1, B0) + 256] ^
                        TE[get_byte(2, B1) + 512] ^ TE[get_byte(3, B2) + 768];

         B0 = EK[r+4] ^ TE[get_byte(0, T0)      ] ^ TE[get_byte(1, T1) + 256] ^
                        TE[get_byte(2, T2) + 512] ^ TE[get_byte(3, T3) + 768];
         B1 = EK[r+5] ^ TE[get_byte(0, T1)      ] ^ TE[get_byte(1, T2) + 256] ^
                        TE[get_byte(2, T3) + 512] ^ TE[get_byte(3, T0) + 768];
         B2 = EK[r+6] ^ TE[get_byte(0, T2)      ] ^ TE[get_byte(1, T3) + 256] ^
                        TE[get_byte(2, T0) + 512] ^ TE[get_byte(3, T1) + 768];
         B3 = EK[r+7] ^ TE[get_byte(0, T3)      ] ^ TE[get_byte(1, T0) + 256] ^
                        TE[get_byte(2, T1) + 512] ^ TE[get_byte(3, T2) + 768];
         }

      out[ 0] = SE[get_byte(0, B0)] ^ ME[0];
      out[ 1] = SE[get_byte(1, B1)] ^ ME[1];
      out[ 2] = SE[get_byte(2, B2)] ^ ME[2];
      out[ 3] = SE[get_byte(3, B3)] ^ ME[3];
      out[ 4] = SE[get_byte(0, B1)] ^ ME[4];
      out[ 5] = SE[get_byte(1, B2)] ^ ME[5];
      out[ 6] = SE[get_byte(2, B3)] ^ ME[6];
      out[ 7] = SE[get_byte(3, B0)] ^ ME[7];
      out[ 8] = SE[get_byte(0, B2)] ^ ME[8];
      out[ 9] = SE[get_byte(1, B3)] ^ ME[9];
      out[10] = SE[get_byte(2, B0)] ^ ME[10];
      out[11] = SE[get_byte(3, B1)] ^ ME[11];
      out[12] = SE[get_byte(0, B3)] ^ ME[12];
      out[13] = SE[get_byte(1, B0)] ^ ME[13];
      out[14] = SE[get_byte(2, B1)] ^ ME[14];
      out[15] = SE[get_byte(3, B2)] ^ ME[15];

      in += 16;
      out += 16;
      }
   }
Ejemplo n.º 29
0
static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    SmackerContext *smk = s->priv_data;
    int flags;
    int ret;
    int i;
    int frame_size = 0;
    int palchange = 0;
    int pos;

    if (url_feof(s->pb) || smk->cur_frame >= smk->frames)
        return AVERROR(EIO);

    /* if we demuxed all streams, pass another frame */
    if(smk->curstream < 0) {
        url_fseek(s->pb, smk->nextpos, 0);
        frame_size = smk->frm_size[smk->cur_frame] & (~3);
        flags = smk->frm_flags[smk->cur_frame];
        /* handle palette change event */
        pos = url_ftell(s->pb);
        if(flags & SMACKER_PAL){
            int size, sz, t, off, j, pos;
            uint8_t *pal = smk->pal;
            uint8_t oldpal[768];

            memcpy(oldpal, pal, 768);
            size = get_byte(s->pb);
            size = size * 4 - 1;
            frame_size -= size;
            frame_size--;
            sz = 0;
            pos = url_ftell(s->pb) + size;
            while(sz < 256){
                t = get_byte(s->pb);
                if(t & 0x80){ /* skip palette entries */
                    sz += (t & 0x7F) + 1;
                    pal += ((t & 0x7F) + 1) * 3;
                } else if(t & 0x40){ /* copy with offset */
                    off = get_byte(s->pb) * 3;
                    j = (t & 0x3F) + 1;
                    while(j-- && sz < 256) {
                        *pal++ = oldpal[off + 0];
                        *pal++ = oldpal[off + 1];
                        *pal++ = oldpal[off + 2];
                        sz++;
                        off += 3;
                    }
                } else { /* new entries */
                    *pal++ = smk_pal[t];
                    *pal++ = smk_pal[get_byte(s->pb) & 0x3F];
                    *pal++ = smk_pal[get_byte(s->pb) & 0x3F];
                    sz++;
                }
            }
            url_fseek(s->pb, pos, 0);
            palchange |= 1;
        }
        flags >>= 1;
        smk->curstream = -1;
        /* if audio chunks are present, put them to stack and retrieve later */
        for(i = 0; i < 7; i++) {
            if(flags & 1) {
                int size;
                size = get_le32(s->pb) - 4;
                frame_size -= size;
                frame_size -= 4;
                smk->curstream++;
                smk->bufs[smk->curstream] = av_realloc(smk->bufs[smk->curstream], size);
                smk->buf_sizes[smk->curstream] = size;
                ret = get_buffer(s->pb, smk->bufs[smk->curstream], size);
                if(ret != size)
                    return AVERROR(EIO);
                smk->stream_id[smk->curstream] = smk->indexes[i];
            }
            flags >>= 1;
        }
        if (av_new_packet(pkt, frame_size + 768))
            return AVERROR(ENOMEM);
        if(smk->frm_size[smk->cur_frame] & 1)
            palchange |= 2;
        pkt->data[0] = palchange;
        memcpy(pkt->data + 1, smk->pal, 768);
        ret = get_buffer(s->pb, pkt->data + 769, frame_size);
        if(ret != frame_size)
            return AVERROR(EIO);
        pkt->stream_index = smk->videoindex;
        pkt->size = ret + 769;
        smk->cur_frame++;
        smk->nextpos = url_ftell(s->pb);
    } else {
Ejemplo n.º 30
0
static int execscsicmd_direct (int unitnum, uaecptr acmd)
{
    int sactual = 0;
    struct scsidevdata *sdd = &drives[unitnum];
    SCSI *scgp              = sdd->scgp;
    struct scg_cmd *scmd    = scgp->scmd;

    uaecptr scsi_data      = get_long (acmd + 0);
    uae_u32 scsi_len       = get_long (acmd + 4);
    uaecptr scsi_cmd       = get_long (acmd + 12);
    int scsi_cmd_len       = get_word (acmd + 16);
    int scsi_cmd_len_orig  = scsi_cmd_len;
    uae_u8  scsi_flags     = get_byte (acmd + 20);
    uaecptr scsi_sense     = get_long (acmd + 22);
    uae_u16 scsi_sense_len = get_word (acmd + 26);
    int io_error           = 0;
    int parm;
    addrbank *bank_data    = &get_mem_bank (scsi_data);
    addrbank *bank_cmd	   = &get_mem_bank (scsi_cmd);
    uae_u8   *scsi_datap;
    uae_u8   *scsi_datap_org;

    DEBUG_LOG ("SCSIDEV: unit=%d: execscsicmd_direct\n", unitnum);

    /* do transfer directly to and from Amiga memory */
    if (!bank_data || !bank_data->check (scsi_data, scsi_len))
	return -5; /* IOERR_BADADDRESS */

    uae_sem_wait (&scgp_sem);

    memset (scmd, 0, sizeof (*scmd));
    /* the Amiga does not tell us how long the timeout shall be, so make it
     * _very_ long (specified in seconds) */
    scmd->timeout   = 80 * 60;
    scsi_datap      = scsi_datap_org = scsi_len
		      ? bank_data->xlateaddr (scsi_data) : 0;
    scmd->size      = scsi_len;
    scmd->flags     = (scsi_flags & 1) ? SCG_RECV_DATA : SCG_DISRE_ENA;
    memcpy (&scmd->cdb, bank_cmd->xlateaddr (scsi_cmd), scsi_cmd_len);
    scmd->target    = sdd->target;
    scmd->sense_len = (scsi_flags & 4) ? 4 : /* SCSIF_OLDAUTOSENSE */
		      (scsi_flags & 2) ? scsi_sense_len : /* SCSIF_AUTOSENSE */
		      -1;
    scmd->sense_count = 0;
    *(uae_u8 *)&scmd->scb = 0;
    if (sdd->isatapi)
	scsi_atapi_fixup_pre (scmd->cdb.cmd_cdb, &scsi_cmd_len, &scsi_datap,
			      &scsi_len, &parm);
    scmd->addr      = (caddr_t)scsi_datap;
    scmd->cdb_len   = scsi_cmd_len;

    scg_settarget (scgp, sdd->bus, sdd->target, sdd->lun);
    scgp->cmdname    = "???";
    scgp->curcmdname = "???";

    DEBUG_LOG ("SCSIDEV: sending command: 0x%2x\n", scmd->cdb.g0_cdb.cmd);

    scg_cmd (scgp);

    DEBUG_LOG ("SCSIDEV: result: %d %d %s\n", scmd->error, scmd->ux_errno,\
	       scgp->errstr);

	gui_flicker_led (LED_CD, 0, 1);

    put_word (acmd + 18, scmd->error == SCG_FATAL
					? 0 : scsi_cmd_len); /* fake scsi_CmdActual */
    put_byte (acmd + 21, *(uae_u8 *)&scmd->scb);	     /* scsi_Status */

    if (*(uae_u8 *)&scmd->scb) {
	io_error = 45; /* HFERR_BadStatus */
	/* copy sense? */
	for (sactual = 0;
	     scsi_sense && sactual < scsi_sense_len && sactual < scmd->sense_count;
	     sactual++) {
	     put_byte (scsi_sense + sactual, scmd->u_sense.cmd_sense[sactual]);
	}
	put_long (acmd + 8, 0); /* scsi_Actual */
    } else {
	int i;
	for (i = 0; i < scsi_sense_len; i++)
	    put_byte (scsi_sense + i, 0);
	sactual = 0;
	if (scmd->error != SCG_NO_ERROR || scmd->ux_errno != 0) {
	    /* We might have been limited by the hosts DMA limits,
	       which is usually indicated by ENOMEM */
	    if (scsi_len > (unsigned int)sdd->max_dma && scmd->ux_errno == ENOMEM)
		io_error = (uae_u8)-4; /* IOERR_BADLENGTH */
	    else {
		io_error = 20; /* io_Error, but not specified */
		put_long (acmd + 8, 0); /* scsi_Actual */
	    }
	} else {
	    scsi_len = scmd->size;
	    if (sdd->isatapi)
		scsi_atapi_fixup_post (scmd->cdb.cmd_cdb, scsi_cmd_len,
				       scsi_datap_org, scsi_datap,
				       &scsi_len, parm);
	    io_error = 0;
	    put_long (acmd + 8, scsi_len); /* scsi_Actual */
	}
    }
    put_word (acmd + 28, sactual);

    uae_sem_post (&scgp_sem);

    if (scsi_datap != scsi_datap_org)
	free (scsi_datap);

    return io_error;
}