コード例 #1
0
ファイル: write.c プロジェクト: AlexSteel/wine
static void output_bin_data( lan_blk_t *lbp )
{
    unsigned int offs = 4 * (lbp->nblk * 3 + 1);
    int i, j, k;

    put_dword( lbp->nblk );  /* NBlocks */
    for (i = 0; i < lbp->nblk; i++)
    {
        put_dword( lbp->blks[i].idlo );  /* Lo */
        put_dword( lbp->blks[i].idhi );  /* Hi */
        put_dword( offs );               /* Offs */
        offs += lbp->blks[i].size;
    }
    for (i = 0; i < lbp->nblk; i++)
    {
        block_t *blk = &lbp->blks[i];
        for (j = 0; j < blk->nmsg; j++)
        {
            int len = (2 * blk->msgs[j]->len + 3) & ~3;
            put_word( len + 4 );
            put_word( 1 );
            for (k = 0; k < blk->msgs[j]->len; k++) put_word( blk->msgs[j]->msg[k] );
            align_output( 4 );
        }
    }
}
コード例 #2
0
ファイル: outppc.c プロジェクト: brandw/8086-toolchain
PRIVATE void put_double P1 (const RVAL *, vp)
{
    unsigned long ul[2];

    ieee_double (vp, ul, TRUE);
    put_dword (ul[0]);
    put_dword (ul[1]);
}
コード例 #3
0
ファイル: resource16.c プロジェクト: howard5888/wineT
/**********************************************************************
 *	    ConvertMenu32To16   (KERNEL.616)
 */
VOID WINAPI ConvertMenu32To16( LPVOID menu32, DWORD size, LPVOID menu16 )
{
    WORD version, headersize, flags, level = 1;

    version = get_word( &menu32 );
    headersize = get_word( &menu32 );
    put_word( &menu16, version );
    put_word( &menu16, headersize );
    if ( headersize )
    {
        memcpy( menu16, menu32, headersize );
        menu16 = (BYTE *)menu16 + headersize;
        menu32 = (BYTE *)menu32 + headersize;
    }

    while ( level )
        if ( version == 0 )  /* standard */
        {
            flags = get_word( &menu32 );
            put_word( &menu16, flags );
            if ( !(flags & MF_POPUP) )
                put_word( &menu16, get_word( &menu32 ) );  /* ID */
            else
                level++;

            WideCharToMultiByte( CP_ACP, 0, (LPWSTR)menu32, -1, (LPSTR)menu16, 0x7fffffff, NULL, NULL );
            menu16 = (LPSTR)menu16 + strlen( (LPSTR)menu16 ) + 1;
            menu32 = (LPWSTR)menu32 + strlenW( (LPWSTR)menu32 ) + 1;

            if ( flags & MF_END )
                level--;
        }
        else  /* extended */
        {
            put_dword( &menu16, get_dword( &menu32 ) );  /* fType */
            put_dword( &menu16, get_dword( &menu32 ) );  /* fState */
            put_word( &menu16, get_dword( &menu32 ) );   /* ID */
            flags = get_word( &menu32 );
            put_byte(&menu16,flags);

            WideCharToMultiByte( CP_ACP, 0, (LPWSTR)menu32, -1, (LPSTR)menu16, 0x7fffffff, NULL, NULL );
            menu16 = (LPSTR)menu16 + strlen( (LPSTR)menu16 ) + 1;
            menu32 = (LPWSTR)menu32 + strlenW( (LPWSTR)menu32 ) + 1;

            /* align on DWORD boundary (32-bit only) */
            menu32 = (LPVOID)(((UINT_PTR)menu32 + 3) & ~3);

            /* If popup, transfer helpid */
            if ( flags & 1)
            {
                put_dword( &menu16, get_dword( &menu32 ) );
                level++;
            }

            if ( flags & MF_END )
                level--;
        }
}
コード例 #4
0
ファイル: res32.c プロジェクト: bilboed/wine
/* output a resource directory in binary format */
static inline void output_bin_res_dir( unsigned int nb_names, unsigned int nb_ids )
{
    put_dword( 0 );        /* Characteristics */
    put_dword( 0 );        /* TimeDateStamp */
    put_word( 0 );         /* MajorVersion */
    put_word( 0 );         /* MinorVersion */
    put_word( nb_names );  /* NumberOfNamedEntries */
    put_word( nb_ids );    /* NumberOfIdEntries */
}
コード例 #5
0
ファイル: outppc.c プロジェクト: brandw/8086-toolchain
PRIVATE void put_float P1 (const RVAL *, vp)
{
    unsigned long ul;

    ieee_single (vp, &ul);
    put_dword (ul);
}
コード例 #6
0
ファイル: write.c プロジェクト: AlexSteel/wine
void write_res_file( const char *name )
{
    lan_blk_t *lbp;
    int i, j;

    init_output_buffer();

    put_dword( 0 );      /* ResSize */
    put_dword( 32 );     /* HeaderSize */
    put_word( 0xffff );  /* ResType */
    put_word( 0x0000 );
    put_word( 0xffff );  /* ResName */
    put_word( 0x0000 );
    put_dword( 0 );      /* DataVersion */
    put_word( 0 );       /* Memory options */
    put_word( 0 );       /* Language */
    put_dword( 0 );      /* Version */
    put_dword( 0 );      /* Characteristics */

    for (lbp = lanblockhead; lbp; lbp = lbp->next)
    {
        unsigned int data_size = 4 * (lbp->nblk * 3 + 1);
        unsigned int header_size = 5 * sizeof(unsigned int) + 6 * sizeof(unsigned short);

        for (i = 0; i < lbp->nblk; i++)
        {
            block_t *blk = &lbp->blks[i];
            for (j = 0; j < blk->nmsg; j++) data_size += 4 + ((blk->msgs[j]->len * 2 + 3) & ~3);
        }

        put_dword( data_size );     /* ResSize */
        put_dword( header_size );   /* HeaderSize */
        put_word( 0xffff );         /* ResType */
        put_word( 0x000b /*RT_MESSAGETABLE*/ );
        put_word( 0xffff );         /* ResName */
        put_word( 0x0001 );
        align_output( 4 );
        put_dword( 0 );             /* DataVersion */
        put_word( 0x30 );           /* Memory options */
        put_word( lbp->lan );       /* Language */
        put_dword( lbp->version );  /* Version */
        put_dword( 0 );             /* Characteristics */

        output_bin_data( lbp );
    }
    flush_output_buffer( name );
}
コード例 #7
0
ファイル: acmtool.c プロジェクト: BackupTheBerlios/libacm
static int write_wav_header(FILE *f, ACMStream *acm)
{
	unsigned char hdr[50], *p = hdr;
	int res;
	unsigned datalen = acm_pcm_total(acm) * ACM_WORD * acm_channels(acm);
	
	int code = 1;
	unsigned n_channels = acm_channels(acm);
	unsigned srate = acm_rate(acm);
	unsigned avg_bps = srate * n_channels * ACM_WORD;
	unsigned significant_bits = ACM_WORD * 8;
	unsigned block_align = significant_bits * n_channels / 8;
	unsigned hdrlen = 16;
	unsigned wavlen = 4 + 8 + hdrlen + 8 + datalen;
	
	memset(hdr, 0, sizeof(hdr));
	
	put_data(p, "RIFF", 4);
	put_dword(p, wavlen);
	put_data(p, "WAVEfmt ", 8);
	put_dword(p, hdrlen);
	put_word(p, code);
	put_word(p, n_channels);
	put_dword(p, srate);
	put_dword(p, avg_bps);
	put_word(p, block_align);
	put_word(p, significant_bits);
	
	put_data(p, "data", 4);
	put_dword(p, datalen);

	res = fwrite(hdr, 1, p - hdr, f);
	if (res != p - hdr)
		return -1;
	else
		return 0;
}
コード例 #8
0
ファイル: d_ser.c プロジェクト: hackshields/antivirus
// ---
static AVP_dword DATA_PARAM flush_put_bytes( Serialize* sz ) {
  AVP_dword crc = sz->crc;

  if ( !sz->crc_cluster || put_dword (sz, &crc) == sizeof(sz->crc) ) {
    if ( sz->proc ) {
      AVP_dword out_size = 0;
      if ( sz->proc(sz->buffer,sz->csize,&out_size,sz->data) && sz->csize == out_size )
        return sz->tsize;
      else
        return 0;
    }
    else
      return  sz->tsize;
  }
  else
    return 0;
}                 
コード例 #9
0
ファイル: resource16.c プロジェクト: howard5888/wineT
/**********************************************************************
 *	    ConvertDialog32To16   (KERNEL.615)
 */
VOID WINAPI ConvertDialog32To16( LPVOID dialog32, DWORD size, LPVOID dialog16 )
{
    WORD nbItems, data, dialogEx;
    DWORD style;

    style = get_dword( &dialog32 );
    put_dword( &dialog16, style );
    dialogEx = (style == 0xffff0001);  /* DIALOGEX resource */
    if (dialogEx)
    {
        put_dword( &dialog16, get_dword( &dialog32 ) );  /* helpID */
        put_dword( &dialog16, get_dword( &dialog32 ) );  /* exStyle */
        style = get_dword( &dialog32 );
        put_dword( &dialog16, style );                   /* style */
    }
    else
        dialog32 = (DWORD *)dialog32 + 1; /* exStyle ignored in 16-bit standard dialog */

    nbItems = get_word( &dialog32 );
    put_byte( &dialog16, nbItems );
    put_word( &dialog16, get_word( &dialog32 ) ); /* x */
    put_word( &dialog16, get_word( &dialog32 ) ); /* y */
    put_word( &dialog16, get_word( &dialog32 ) ); /* cx */
    put_word( &dialog16, get_word( &dialog32 ) ); /* cy */

    /* Transfer menu name */
    convert_name( &dialog16, &dialog32 );

    /* Transfer class name */
    convert_name( &dialog16, &dialog32 );

    /* Transfer window caption */
    WideCharToMultiByte( CP_ACP, 0, dialog32, -1, dialog16, 0x7fffffff, NULL, NULL );
    dialog16 = (LPSTR)dialog16 + strlen( (LPSTR)dialog16 ) + 1;
    dialog32 = (LPWSTR)dialog32 + strlenW( (LPWSTR)dialog32 ) + 1;

    /* Transfer font info */
    if (style & DS_SETFONT)
    {
        put_word( &dialog16, get_word( &dialog32 ) );  /* pointSize */
        if (dialogEx)
        {
            put_word( &dialog16, get_word( &dialog32 ) ); /* weight */
            put_word( &dialog16, get_word( &dialog32 ) ); /* italic */
        }
        WideCharToMultiByte( CP_ACP, 0, (LPWSTR)dialog32, -1, (LPSTR)dialog16, 0x7fffffff, NULL, NULL );  /* faceName */
        dialog16 = (LPSTR)dialog16 + strlen( (LPSTR)dialog16 ) + 1;
        dialog32 = (LPWSTR)dialog32 + strlenW( (LPWSTR)dialog32 ) + 1;
    }

    /* Transfer dialog items */
    while (nbItems)
    {
        /* align on DWORD boundary (32-bit only) */
        dialog32 = (LPVOID)(((UINT_PTR)dialog32 + 3) & ~3);

        if (dialogEx)
        {
            put_dword( &dialog16, get_dword( &dialog32 ) ); /* helpID */
            put_dword( &dialog16, get_dword( &dialog32 ) ); /* exStyle */
            put_dword( &dialog16, get_dword( &dialog32 ) ); /* style */
        }
        else
        {
            style = get_dword( &dialog32 );    /* save style */
            dialog32 = (DWORD *)dialog32 + 1;  /* ignore exStyle */
        }

        put_word( &dialog16, get_word( &dialog32 ) ); /* x */
        put_word( &dialog16, get_word( &dialog32 ) ); /* y */
        put_word( &dialog16, get_word( &dialog32 ) ); /* cx */
        put_word( &dialog16, get_word( &dialog32 ) ); /* cy */

        if (dialogEx)
            put_dword( &dialog16, get_dword( &dialog32 ) ); /* ID */
        else
        {
            put_word( &dialog16, get_word( &dialog32 ) ); /* ID */
            put_dword( &dialog16, style );  /* style from above */
        }

        /* Transfer class name */
        switch (*(WORD *)dialog32)
        {
        case 0x0000:
            get_word( &dialog32 );
            put_byte( &dialog16, 0 );
            break;
        case 0xffff:
            get_word( &dialog32 );
            put_byte( &dialog16, get_word( &dialog32 ) );
            break;
        default:
            WideCharToMultiByte( CP_ACP, 0, (LPWSTR)dialog32, -1, (LPSTR)dialog16, 0x7fffffff, NULL, NULL );
            dialog16 = (LPSTR)dialog16 + strlen( (LPSTR)dialog16 ) + 1;
            dialog32 = (LPWSTR)dialog32 + strlenW( (LPWSTR)dialog32 ) + 1;
            break;
        }

        /* Transfer window name */
        convert_name( &dialog16, &dialog32 );

        /* Transfer data */
        data = get_word( &dialog32 );
        if (dialogEx)
            put_word(&dialog16, data);
        else
            put_byte(&dialog16,(BYTE)data);

        if (data)
        {
            memcpy( dialog16, dialog32, data );
            dialog16 = (BYTE *)dialog16 + data;
            dialog32 = (BYTE *)dialog32 + data;
        }

        /* Next item */
        nbItems--;
    }
}
コード例 #10
0
ファイル: spec32.c プロジェクト: Sunmonds/wine
/*******************************************************************
 *         output_fake_module
 *
 * Build a fake binary module from a spec file.
 */
void output_fake_module( DLLSPEC *spec )
{
    static const unsigned char dll_code_section[] = { 0x31, 0xc0,          /* xor %eax,%eax */
                                                      0xc2, 0x0c, 0x00 };  /* ret $12 */

    static const unsigned char exe_code_section[] = { 0xb8, 0x01, 0x00, 0x00, 0x00,  /* movl $1,%eax */
                                                      0xc2, 0x04, 0x00 };            /* ret $4 */

    static const char fakedll_signature[] = "Wine placeholder DLL";
    const unsigned int page_size = get_page_size();
    const unsigned int section_align = page_size;
    const unsigned int file_align = 0x200;
    const unsigned int reloc_size = 8;
    const unsigned int lfanew = (0x40 + sizeof(fakedll_signature) + 15) & ~15;
    const unsigned int nb_sections = 2 + (spec->nb_resources != 0);
    const unsigned int text_size = (spec->characteristics & IMAGE_FILE_DLL) ?
                                    sizeof(dll_code_section) : sizeof(exe_code_section);
    unsigned char *resources;
    unsigned int resources_size;
    unsigned int image_size = 3 * section_align;

    resolve_imports( spec );
    output_bin_resources( spec, 3 * section_align );
    resources = output_buffer;
    resources_size = output_buffer_pos;
    if (resources_size) image_size += (resources_size + section_align - 1) & ~(section_align - 1);

    init_output_buffer();

    put_word( 0x5a4d );       /* e_magic */
    put_word( 0x40 );         /* e_cblp */
    put_word( 0x01 );         /* e_cp */
    put_word( 0 );            /* e_crlc */
    put_word( lfanew / 16 );  /* e_cparhdr */
    put_word( 0x0000 );       /* e_minalloc */
    put_word( 0xffff );       /* e_maxalloc */
    put_word( 0x0000 );       /* e_ss */
    put_word( 0x00b8 );       /* e_sp */
    put_word( 0 );            /* e_csum */
    put_word( 0 );            /* e_ip */
    put_word( 0 );            /* e_cs */
    put_word( lfanew );       /* e_lfarlc */
    put_word( 0 );            /* e_ovno */
    put_dword( 0 );           /* e_res */
    put_dword( 0 );
    put_word( 0 );            /* e_oemid */
    put_word( 0 );            /* e_oeminfo */
    put_dword( 0 );           /* e_res2 */
    put_dword( 0 );
    put_dword( 0 );
    put_dword( 0 );
    put_dword( 0 );
    put_dword( lfanew );

    put_data( fakedll_signature, sizeof(fakedll_signature) );
    align_output( 16 );

    put_dword( 0x4550 );                             /* Signature */
    switch(target_cpu)
    {
    case CPU_x86:     put_word( IMAGE_FILE_MACHINE_I386 ); break;
    case CPU_x86_64:  put_word( IMAGE_FILE_MACHINE_AMD64 ); break;
    case CPU_POWERPC: put_word( IMAGE_FILE_MACHINE_POWERPC ); break;
    case CPU_SPARC:   put_word( IMAGE_FILE_MACHINE_SPARC ); break;
    case CPU_ARM:     put_word( IMAGE_FILE_MACHINE_ARMV7 ); break;
    }
    put_word( nb_sections );                         /* NumberOfSections */
    put_dword( 0 );                                  /* TimeDateStamp */
    put_dword( 0 );                                  /* PointerToSymbolTable */
    put_dword( 0 );                                  /* NumberOfSymbols */
    put_word( get_ptr_size() == 8 ?
              IMAGE_SIZEOF_NT_OPTIONAL64_HEADER :
              IMAGE_SIZEOF_NT_OPTIONAL32_HEADER );   /* SizeOfOptionalHeader */
    put_word( spec->characteristics );               /* Characteristics */
    put_word( get_ptr_size() == 8 ?
              IMAGE_NT_OPTIONAL_HDR64_MAGIC :
              IMAGE_NT_OPTIONAL_HDR32_MAGIC );       /* Magic */
    put_byte(  0 );                                  /* MajorLinkerVersion */
    put_byte(  0 );                                  /* MinorLinkerVersion */
    put_dword( text_size );                          /* SizeOfCode */
    put_dword( 0 );                                  /* SizeOfInitializedData */
    put_dword( 0 );                                  /* SizeOfUninitializedData */
    put_dword( section_align );                      /* AddressOfEntryPoint */
    put_dword( section_align );                      /* BaseOfCode */
    if (get_ptr_size() == 4) put_dword( 0 );         /* BaseOfData */
    put_pword( 0x10000000 );                         /* ImageBase */
    put_dword( section_align );                      /* SectionAlignment */
    put_dword( file_align );                         /* FileAlignment */
    put_word( 1 );                                   /* MajorOperatingSystemVersion */
    put_word( 0 );                                   /* MinorOperatingSystemVersion */
    put_word( 0 );                                   /* MajorImageVersion */
    put_word( 0 );                                   /* MinorImageVersion */
    put_word( spec->subsystem_major );               /* MajorSubsystemVersion */
    put_word( spec->subsystem_minor );               /* MinorSubsystemVersion */
    put_dword( 0 );                                  /* Win32VersionValue */
    put_dword( image_size );                         /* SizeOfImage */
    put_dword( file_align );                         /* SizeOfHeaders */
    put_dword( 0 );                                  /* CheckSum */
    put_word( spec->subsystem );                     /* Subsystem */
    put_word( spec->dll_characteristics );           /* DllCharacteristics */
    put_pword( (spec->stack_size ? spec->stack_size : 1024) * 1024 ); /* SizeOfStackReserve */
    put_pword( page_size );                          /* SizeOfStackCommit */
    put_pword( (spec->heap_size ? spec->heap_size : 1024) * 1024 );   /* SizeOfHeapReserve */
    put_pword( page_size );                          /* SizeOfHeapCommit */
    put_dword( 0 );                                  /* LoaderFlags */
    put_dword( 16 );                                 /* NumberOfRvaAndSizes */

    put_dword( 0 ); put_dword( 0 );   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT] */
    put_dword( 0 ); put_dword( 0 );   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] */
    if (resources_size)   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE] */
    {
        put_dword( 3 * section_align );
        put_dword( resources_size );
    }
    else
    {
        put_dword( 0 );
        put_dword( 0 );
    }

    put_dword( 0 ); put_dword( 0 );   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXCEPTION] */
    put_dword( 0 ); put_dword( 0 );   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY] */
    put_dword( 2 * section_align );   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC] */
    put_dword( reloc_size );
    put_dword( 0 ); put_dword( 0 );   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG] */
    put_dword( 0 ); put_dword( 0 );   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_COPYRIGHT] */
    put_dword( 0 ); put_dword( 0 );   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_GLOBALPTR] */
    put_dword( 0 ); put_dword( 0 );   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS] */
    put_dword( 0 ); put_dword( 0 );   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG] */
    put_dword( 0 ); put_dword( 0 );   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT] */
    put_dword( 0 ); put_dword( 0 );   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT] */
    put_dword( 0 ); put_dword( 0 );   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT] */
    put_dword( 0 ); put_dword( 0 );   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR] */
    put_dword( 0 ); put_dword( 0 );   /* DataDirectory[15] */

    /* .text section */
    put_data( ".text\0\0", 8 );    /* Name */
    put_dword( section_align );    /* VirtualSize */
    put_dword( section_align );    /* VirtualAddress */
    put_dword( text_size );        /* SizeOfRawData */
    put_dword( file_align );       /* PointerToRawData */
    put_dword( 0 );                /* PointerToRelocations */
    put_dword( 0 );                /* PointerToLinenumbers */
    put_word( 0 );                 /* NumberOfRelocations */
    put_word( 0 );                 /* NumberOfLinenumbers */
    put_dword( 0x60000020 /* CNT_CODE|MEM_EXECUTE|MEM_READ */ ); /* Characteristics  */

    /* .reloc section */
    put_data( ".reloc\0", 8 );     /* Name */
    put_dword( section_align );    /* VirtualSize */
    put_dword( 2 * section_align );/* VirtualAddress */
    put_dword( reloc_size );       /* SizeOfRawData */
    put_dword( 2 * file_align );   /* PointerToRawData */
    put_dword( 0 );                /* PointerToRelocations */
    put_dword( 0 );                /* PointerToLinenumbers */
    put_word( 0 );                 /* NumberOfRelocations */
    put_word( 0 );                 /* NumberOfLinenumbers */
    put_dword( 0x42000040 /* CNT_INITIALIZED_DATA|MEM_DISCARDABLE|MEM_READ */ ); /* Characteristics */

    /* .rsrc section */
    if (resources_size)
    {
        put_data( ".rsrc\0\0", 8 );    /* Name */
        put_dword( (resources_size + section_align - 1) & ~(section_align - 1) ); /* VirtualSize */
        put_dword( 3 * section_align );/* VirtualAddress */
        put_dword( resources_size );   /* SizeOfRawData */
        put_dword( 3 * file_align );   /* PointerToRawData */
        put_dword( 0 );                /* PointerToRelocations */
        put_dword( 0 );                /* PointerToLinenumbers */
        put_word( 0 );                 /* NumberOfRelocations */
        put_word( 0 );                 /* NumberOfLinenumbers */
        put_dword( 0x40000040 /* CNT_INITIALIZED_DATA|MEM_READ */ ); /* Characteristics */
    }

    /* .text contents */
    align_output( file_align );
    if (spec->characteristics & IMAGE_FILE_DLL)
        put_data( dll_code_section, sizeof(dll_code_section) );
    else
        put_data( exe_code_section, sizeof(exe_code_section) );

    /* .reloc contents */
    align_output( file_align );
    put_dword( 0 );   /* VirtualAddress */
    put_dword( 0 );   /* SizeOfBlock */

    /* .rsrc contents */
    if (resources_size)
    {
        align_output( file_align );
        put_data( resources, resources_size );
    }
    flush_output_buffer();
}
コード例 #11
0
ファイル: glprgr.c プロジェクト: emersonxsu/glpk
int rgr_write_bmp16(const char *fname, int m, int n, const char map[])
{     FILE *fp;
      int offset, bmsize, i, j, b, ret = 0;
      if (!(1 <= m && m <= 32767))
         xfault("rgr_write_bmp16: m = %d; invalid height\n", m);
      if (!(1 <= n && n <= 32767))
         xfault("rgr_write_bmp16: n = %d; invalid width\n", n);
      fp = fopen(fname, "wb");
      if (fp == NULL)
      {  xprintf("rgr_write_bmp16: unable to create '%s' - %s\n",
            fname, strerror(errno));
         ret = 1;
         goto fini;
      }
      offset = 14 + 40 + 16 * 4;
      bmsize = (4 * n + 31) / 32;
      /* struct BMPFILEHEADER (14 bytes) */
      /* UINT bfType */          put_byte(fp, 'B'), put_byte(fp, 'M');
      /* DWORD bfSize */         put_dword(fp, offset + bmsize * 4);
      /* UINT bfReserved1 */     put_word(fp, 0);
      /* UNIT bfReserved2 */     put_word(fp, 0);
      /* DWORD bfOffBits */      put_dword(fp, offset);
      /* struct BMPINFOHEADER (40 bytes) */
      /* DWORD biSize */         put_dword(fp, 40);
      /* LONG biWidth */         put_dword(fp, n);
      /* LONG biHeight */        put_dword(fp, m);
      /* WORD biPlanes */        put_word(fp, 1);
      /* WORD biBitCount */      put_word(fp, 4);
      /* DWORD biCompression */  put_dword(fp, 0 /* BI_RGB */);
      /* DWORD biSizeImage */    put_dword(fp, 0);
      /* LONG biXPelsPerMeter */ put_dword(fp, 2953 /* 75 dpi */);
      /* LONG biYPelsPerMeter */ put_dword(fp, 2953 /* 75 dpi */);
      /* DWORD biClrUsed */      put_dword(fp, 0);
      /* DWORD biClrImportant */ put_dword(fp, 0);
      /* struct RGBQUAD (16 * 4 = 64 bytes) */
      /* CGA-compatible colors: */
      /* 0x00 = black */         put_dword(fp, 0x000000);
      /* 0x01 = blue */          put_dword(fp, 0x000080);
      /* 0x02 = green */         put_dword(fp, 0x008000);
      /* 0x03 = cyan */          put_dword(fp, 0x008080);
      /* 0x04 = red */           put_dword(fp, 0x800000);
      /* 0x05 = magenta */       put_dword(fp, 0x800080);
      /* 0x06 = brown */         put_dword(fp, 0x808000);
      /* 0x07 = light gray */    put_dword(fp, 0xC0C0C0);
      /* 0x08 = dark gray */     put_dword(fp, 0x808080);
      /* 0x09 = bright blue */   put_dword(fp, 0x0000FF);
      /* 0x0A = bright green */  put_dword(fp, 0x00FF00);
      /* 0x0B = bright cyan */   put_dword(fp, 0x00FFFF);
      /* 0x0C = bright red */    put_dword(fp, 0xFF0000);
      /* 0x0D = bright magenta */ put_dword(fp, 0xFF00FF);
      /* 0x0E = yellow */        put_dword(fp, 0xFFFF00);
      /* 0x0F = white */         put_dword(fp, 0xFFFFFF);
      /* pixel data bits */
      b = 0;
      for (i = m - 1; i >= 0; i--)
      {  for (j = 0; j < ((n + 7) / 8) * 8; j++)
         {  b <<= 4;
            b |= (j < n ? map[i * n + j] & 15 : 0);
            if (j & 1) put_byte(fp, b);
         }
      }
      fflush(fp);
      if (ferror(fp))
      {  xprintf("rgr_write_bmp16: write error on '%s' - %s\n",
            fname, strerror(errno));
         ret = 1;
      }
fini: if (fp != NULL) fclose(fp);
      return ret;
}
コード例 #12
0
ファイル: d_ser.c プロジェクト: hackshields/antivirus
static AVP_dword DATA_PARAM WritePropertyItem( Serialize* sz, AVP_byte type, void* val ) {
	AVP_dword size = 0;
	AVP_dword psize;
	AVP_word wsize;    
	AVP_byte tmpbyte;

	switch( type ) {
		case avpt_nothing : return sizeof(AVP_Property);

		// Byte-sized types
		case avpt_char    : 
		case avpt_byte    : 
		case avpt_group   : size = put_byte( sz, (AVP_byte*)val ); break;
		case avpt_bool    : 
			tmpbyte = *((AVP_bool*)val) ? 1 : 0;
			size = put_byte(sz, &tmpbyte);
			break;

		// Word-sized types            
		case avpt_wchar   :
		case avpt_short   :
		case avpt_word    : size = put_word( sz, (AVP_word *)val ); break;

		// Dword-sized types      
		case avpt_long    : 
		case avpt_dword   : 
		case avpt_int     : 
		case avpt_uint    : size = put_dword( sz, (AVP_dword *)val ); break;

		// QWord-sized types
		case avpt_qword   : 
		case avpt_longlong: size = put_qword( sz, (AVP_qword*)val ); break;

		// size_t-sized types
		case avpt_size_t  : size = put_size_t( sz, (AVP_size_t*)val ); break;

		// Custom structures
		case avpt_date    : size = put_date(sz, (AVP_date *)val); break;
		case avpt_time    : size = put_time(sz, (AVP_time *)val); break;
		case avpt_datetime: size = put_datetime(sz, (AVP_datetime *)val); break;

		// String
		case avpt_str     :
			if ( *((AVP_char**)val) ) {
				psize = (AVP_dword)strlen( *((AVP_char**)val) );
				wsize = (AVP_word)psize;
				if ( psize >= USHRT_MAX ) {
					_RPT0( _CRT_ASSERT, "String is too long" );
					return 0;
				}
				if ( sizeof(AVP_word) == put_word (sz, &wsize) && psize == put_bytes(sz,*((AVP_char**)val),psize) )
					size += sizeof(AVP_word) + psize;
				else
					size = 0;
			}
			else {
				AVP_word dummy = USHRT_MAX;
				if ( sizeof(AVP_word) == put_word (sz, &dummy) )
					size += sizeof(AVP_word);
				else
					size = 0;
			}
			break;

			// Windows unicode string
		case avpt_wstr :
			size = put_wchar_string(sz,*((wchar_t**) val));
			break;

		case avpt_bin :
			if ( ((AVP_Bin_Item *)val)->size > USHRT_MAX ) {
				_RPT0( _CRT_ASSERT, "Binary property is too large" );
				return 0;
			}
			wsize = (AVP_word)((AVP_Bin_Item *)val)->size;
			if ( sizeof(AVP_word) == put_word (sz, &wsize ) &&
				((AVP_Bin_Item *)val)->size == put_bytes( sz, ((AVP_Bin_Item *)val)->data, ((AVP_Bin_Item *)val)->size ) 
				) 
				size = sizeof(AVP_word) + ((AVP_Bin_Item *)val)->size;
			else
				size = 0;
			break;

		default :
			_RPT0( _CRT_ASSERT, "Bad property type" );
			return 0;
	}

	return size ? size + sizeof(AVP_Property) : 0;
}
コード例 #13
0
ファイル: d_ser.c プロジェクト: hackshields/antivirus
// ---
DATA_PROC AVP_bool DATA_PARAM DATA_Serialize( HDATA data, AVP_dword* addr, AVP_Serialize_Data* opt, void* buffer, AVP_dword buffer_size, AVP_dword* size_out ) {

  AVP_word    magic;
  AVP_dword   version;
  AVP_dword   max_size;
  AVP_dword*  include;
  AVP_dword*  exclude;
  AVP_bool    root_siblings;
  Serialize   sz;
  Buffer_Proc flush;

  FIND_DATA( data, addr );

  /*
  size_to_save = 
    sizeof( ((AVP_Serialize_Data*)0)->magic )           + // magic number
    sizeof( ((AVP_Serialize_Data*)0)->version )         + // version
    sizeof( ((AVP_Serialize_Data*)0)->translate_method ) + // translate_method
    sizeof( ((AVP_Serialize_Data*)0)->header_size );      // header size
  */

  if ( opt ) {
    include = opt->props_include;
    exclude = opt->props_exclude;
    opt->version = 1;
  }
  else {
    include = 0;
    exclude = 0;
  }

  if ( buffer ) {
    if ( buffer_size ) {
      max_size = buffer_size;
      flush = opt ? opt->proc : 0; 
    }
    else {
      _RPT0( _CRT_ASSERT, "Bad parameters" );
      if ( size_out )
        *size_out = 0;
      return 0;
    }
  }
  else {
    flush = 0; 
    max_size = (AVP_dword)-1;
  }

  init_put_bytes( &sz, buffer, max_size, flush, opt ? opt->user_data : 0 );

  magic = 0xadad;
  if ( put_word(&sz, &magic) != sizeof(magic) ) {
    if ( size_out )
      *size_out = sz.tsize;
    return 0;
  }

  version = 1;
  if ( opt ) {
    root_siblings = opt->root_siblings;
    opt->version = 1;
  }
  else
    root_siblings = 1;


  if ( put_dword (&sz, &version) != sizeof(version) ) {
    if ( size_out )
      *size_out = sz.tsize;
    return 0;
  }

  if ( put_dword (&sz, &sz.crc_cluster) != sizeof(sz.crc_cluster) ) {
    if ( size_out )
      *size_out = sz.tsize;
    return 0;
  }

  sz.crc = -1;

  if ( 0 == DATA_Put(&sz,(AVP_Data*)data,root_siblings,include,exclude) ) {
    if ( size_out )
      *size_out = sz.tsize;
    return 0;
  }
  else {
    AVP_dword res = flush_put_bytes( &sz );
    if ( size_out )
      *size_out = sz.tsize;
    return res != 0;
  }
}
コード例 #14
0
ファイル: spec16.c プロジェクト: otya128/winevdm
/*******************************************************************
 *         output_fake_module16
 *
 * Create a fake 16-bit binary module.
 */
void output_fake_module16( DLLSPEC *spec )
{
    static const unsigned char code_segment[] = { 0x90, 0xc3 };
    static const unsigned char data_segment[16] = { 0 };
    static const char fakedll_signature[] = "Wine placeholder DLL";
    const unsigned int cseg = 2;
    const unsigned int lfanew = (0x40 + sizeof(fakedll_signature) + 15) & ~15;
    const unsigned int segtab = lfanew + 0x40;

    unsigned int i, rsrctab, restab, namelen, modtab, imptab, enttab, cbenttab, codeseg, dataseg, rsrcdata;

    init_output_buffer();

    rsrctab = lfanew;
    restab = segtab + 8 * cseg;
    if (spec->nb_resources)
    {
        output_bin_res16_directory( spec, 0 );
        align_output( 2 );
        rsrctab = restab;
        restab += output_buffer_pos;
        free( output_buffer );
        init_output_buffer();
    }

    namelen  = strlen( spec->dll_name );
    modtab   = restab + ((namelen + 3) & ~1);
    imptab   = modtab;
    enttab   = modtab + 2;
    cbenttab = 1;
    codeseg  = (enttab + cbenttab + 1) & ~1;
    dataseg  = codeseg + sizeof(code_segment);
    rsrcdata = dataseg + sizeof(data_segment);

    init_output_buffer();

    put_word( 0x5a4d );       /* e_magic */
    put_word( 0x40 );         /* e_cblp */
    put_word( 0x01 );         /* e_cp */
    put_word( 0 );            /* e_crlc */
    put_word( lfanew / 16 );  /* e_cparhdr */
    put_word( 0x0000 );       /* e_minalloc */
    put_word( 0xffff );       /* e_maxalloc */
    put_word( 0x0000 );       /* e_ss */
    put_word( 0x00b8 );       /* e_sp */
    put_word( 0 );            /* e_csum */
    put_word( 0 );            /* e_ip */
    put_word( 0 );            /* e_cs */
    put_word( lfanew );       /* e_lfarlc */
    put_word( 0 );            /* e_ovno */
    put_dword( 0 );           /* e_res */
    put_dword( 0 );
    put_word( 0 );            /* e_oemid */
    put_word( 0 );            /* e_oeminfo */
    put_dword( 0 );           /* e_res2 */
    put_dword( 0 );
    put_dword( 0 );
    put_dword( 0 );
    put_dword( 0 );
    put_dword( lfanew );

    put_data( fakedll_signature, sizeof(fakedll_signature) );
    align_output( 16 );

    put_word( 0x454e );                    /* ne_magic */
    put_byte( 0 );                         /* ne_ver */
    put_byte( 0 );                         /* ne_rev */
    put_word( enttab - lfanew );           /* ne_enttab */
    put_word( cbenttab );                  /* ne_cbenttab */
    put_dword( 0 );                        /* ne_crc */
    put_word( NE_FFLAGS_SINGLEDATA |       /* ne_flags */
              ((spec->characteristics & IMAGE_FILE_DLL) ? NE_FFLAGS_LIBMODULE : 0) );
    put_word( 2 );                         /* ne_autodata */
    put_word( spec->heap_size );           /* ne_heap */
    put_word( 0 );                         /* ne_stack */
    put_word( 0 ); put_word( 0 );          /* ne_csip */
    put_word( 0 ); put_word( 2 );          /* ne_sssp */
    put_word( cseg );                      /* ne_cseg */
    put_word( 0 );                         /* ne_cmod */
    put_word( 0 );                         /* ne_cbnrestab */
    put_word( segtab - lfanew );           /* ne_segtab */
    put_word( rsrctab - lfanew );          /* ne_rsrctab */
    put_word( restab - lfanew );           /* ne_restab */
    put_word( modtab - lfanew );           /* ne_modtab */
    put_word( imptab - lfanew );           /* ne_imptab */
    put_dword( 0 );                        /* ne_nrestab */
    put_word( 0 );                         /* ne_cmovent */
    put_word( 0 );                         /* ne_align */
    put_word( 0 );                         /* ne_cres */
    put_byte( 2 /*NE_OSFLAGS_WINDOWS*/ );  /* ne_exetyp */
    put_byte( 8 /*NE_AFLAGS_FASTLOAD*/ );  /* ne_flagsothers */
    put_word( 0 );                         /* ne_pretthunks */
    put_word( 0 );                         /* ne_psegrefbytes */
    put_word( 0 );                         /* ne_swaparea */
    put_word( 0 );                         /* ne_expver */

    /* segment table */
    put_word( codeseg );
    put_word( sizeof(code_segment) );
    put_word( 0x2000 /* NE_SEGFLAGS_32BIT */ );
    put_word( sizeof(code_segment) );
    put_word( dataseg );
    put_word( sizeof(data_segment) );
    put_word( 0x0001 /* NE_SEGFLAGS_DATA */ );
    put_word( sizeof(data_segment) );

    /* resource directory */
    if (spec->nb_resources)
    {
        output_bin_res16_directory( spec, rsrcdata );
        align_output( 2 );
    }

    /* resident names table */
    put_byte( namelen );
    for (i = 0; i < namelen; i++) put_byte( toupper(spec->dll_name[i]) );
    put_byte( 0 );
    align_output( 2 );

    /* imported names table */
    put_word( 0 );

    /* entry table */
    put_byte( 0 );
    align_output( 2 );

    /* code segment */
    put_data( code_segment, sizeof(code_segment) );

    /* data segment */
    put_data( data_segment, sizeof(data_segment) );

    /* resource data */
    output_bin_res16_data( spec );

    flush_output_buffer();
}
コード例 #15
0
ファイル: res32.c プロジェクト: bilboed/wine
/* output the resource definitions in binary format */
void output_bin_resources( DLLSPEC *spec, unsigned int start_rva )
{
    int k, nb_id_types;
    unsigned int i, n, data_offset;
    struct res_tree *tree;
    struct res_type *type;
    struct res_name *name;
    const struct resource *res;

    if (!spec->nb_resources) return;

    tree = build_resource_tree( spec, &data_offset );
    init_output_buffer();

    /* output the resource directories */

    for (i = nb_id_types = 0, type = tree->types; i < tree->nb_types; i++, type++)
        if (!type->type->str) nb_id_types++;

    output_bin_res_dir( tree->nb_types - nb_id_types, nb_id_types );

    /* dump the type directory */

    for (i = 0, type = tree->types; i < tree->nb_types; i++, type++)
    {
        put_dword( type->name_offset );
        put_dword( type->dir_offset | 0x80000000 );
    }

    /* dump the names and languages directories */

    for (i = 0, type = tree->types; i < tree->nb_types; i++, type++)
    {
        output_bin_res_dir( type->nb_names - type->nb_id_names, type->nb_id_names );
        for (n = 0, name = type->names; n < type->nb_names; n++, name++)
        {
            put_dword( name->name_offset );
            put_dword( name->dir_offset | 0x80000000 );
        }

        for (n = 0, name = type->names; n < type->nb_names; n++, name++)
        {
            output_bin_res_dir( 0, name->nb_languages );
            for (k = 0, res = name->res; k < name->nb_languages; k++, res++)
            {
                put_dword( res->lang );
                put_dword( res->data_offset );
            }
        }
    }

    /* dump the resource data entries */

    for (i = 0, res = spec->resources; i < spec->nb_resources; i++, res++)
    {
        put_dword( data_offset + start_rva );
        put_dword( (res->data_size + 3) & ~3 );
        put_dword( 0 );
        put_dword( 0 );
        data_offset += (res->data_size + 3) & ~3;
    }

    /* dump the name strings */

    for (i = 0, type = tree->types; i < tree->nb_types; i++, type++)
    {
        if (type->type->str) output_bin_string( type->type->str );
        for (n = 0, name = type->names; n < type->nb_names; n++, name++)
            if (name->name->str) output_bin_string( name->name->str );
    }

    /* resource data */

    align_output( 4 );
    for (i = 0, res = spec->resources; i < spec->nb_resources; i++, res++)
    {
        put_data( res->data, res->data_size );
        align_output( 4 );
    }

    free_resource_tree( tree );
}
コード例 #16
0
ファイル: d_ser.c プロジェクト: hackshields/antivirus
// ---
static AVP_dword DATA_PARAM put_bytes( Serialize* sz, void* val, AVP_dword size ) {

  AVP_dword saved = 0;

  if ( !size )
    return 0;

  if ( sz->crc_cluster && sz->crc_len + size > sz->crc_cluster ) {
    AVP_dword crc;
    AVP_dword r_size = sz->crc_cluster - sz->crc_len;
    AVP_dword s_size = r_size ? put_bytes( sz, val, r_size ) : 0;
    if ( s_size == r_size ) {
      crc = sz->crc;
      sz->crc_len = 0;
      if ( put_dword (sz, &crc) == sizeof(sz->crc) ) {
        sz->crc = -1;
        sz->crc_len = 0;
        r_size = size - r_size;
        saved = s_size + ( r_size ? put_bytes(sz,((AVP_byte*)val)+s_size,r_size) : 0 );
      }
    }
  }
  else {
    if ( sz->crc_cluster ) {
      if ( sz->buffer )
        sz->crc = CountCRC32WithCRC( size, (AVP_byte*)val, sz->crc );
      sz->crc_len += size;
    }

    while( sz->bsize < sz->csize + size ) {
      AVP_dword out_size = 0;
      AVP_dword psize = sz->bsize - sz->csize;
      if ( psize && sz->buffer ) 
        memcpy( sz->buffer+sz->csize, val, psize );

      if ( sz->proc && sz->proc(sz->buffer,sz->bsize,&out_size,sz->data) ) {
        if ( sz->bsize > out_size )
          return 0;
        if ( psize ) {
          *((AVP_byte**)&val) += psize;
          size -= psize;
          saved += psize;
          sz->tsize += psize;
        }
      }
      else 
        return 0;

      sz->csize = 0;
    }

    if ( size ) {
      if ( sz->buffer )
        memcpy( sz->buffer+sz->csize, val, size );
      sz->csize += size;
      sz->tsize += size;
      saved += size;
    }

  }
  return saved;
}
コード例 #17
0
ファイル: res32.c プロジェクト: bilboed/wine
/* output the resources into a .o file */
void output_res_o_file( DLLSPEC *spec )
{
    unsigned int i;
    char *res_file = NULL;
    int fd, err;

    if (!spec->nb_resources) fatal_error( "--resources mode needs at least one resource file as input\n" );
    if (!output_file_name) fatal_error( "No output file name specified\n" );

    byte_swapped = 0;
    init_output_buffer();

    put_dword( 0 );      /* ResSize */
    put_dword( 32 );     /* HeaderSize */
    put_word( 0xffff );  /* ResType */
    put_word( 0x0000 );
    put_word( 0xffff );  /* ResName */
    put_word( 0x0000 );
    put_dword( 0 );      /* DataVersion */
    put_word( 0 );       /* Memory options */
    put_word( 0 );       /* Language */
    put_dword( 0 );      /* Version */
    put_dword( 0 );      /* Characteristics */

    for (i = 0; i < spec->nb_resources; i++)
    {
        unsigned int header_size = get_resource_header_size( &spec->resources[i] );

        put_dword( spec->resources[i].data_size );
        put_dword( (header_size + 3) & ~3 );
        put_string( &spec->resources[i].type );
        put_string( &spec->resources[i].name );
        align_output( 4 );
        put_dword( 0 );
        put_word( spec->resources[i].mem_options );
        put_word( spec->resources[i].lang );
        put_dword( 0 );
        put_dword( 0 );
        put_data( spec->resources[i].data, spec->resources[i].data_size );
        align_output( 4 );
    }

    /* if the output file name is a .res too, don't run the results through windres */
    if (strendswith( output_file_name, ".res"))
    {
        flush_output_buffer();
        return;
    }

    res_file = get_temp_file_name( output_file_name, ".res" );
    if ((fd = open( res_file, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600 )) == -1)
        fatal_error( "Cannot create %s\n", res_file );
    if (write( fd, output_buffer, output_buffer_pos ) != output_buffer_pos)
        fatal_error( "Error writing to %s\n", res_file );
    close( fd );
    free( output_buffer );

    if (res_file)
    {
        char *prog = find_tool( "windres", NULL );
        char *cmd = xmalloc( strlen(prog) + strlen(res_file) + strlen(output_file_name) + 9 );
        sprintf( cmd, "%s -i %s -o %s", prog, res_file, output_file_name );
        if (verbose) fprintf( stderr, "%s\n", cmd );
        err = system( cmd );
        if (err) fatal_error( "%s failed with status %d\n", prog, err );
        free( cmd );
        free( prog );
    }
    output_file_name = NULL;  /* so we don't try to assemble it */
}
コード例 #18
0
ファイル: res32.c プロジェクト: AlexSteel/wine
/* output the resources into a .o file */
void output_res_o_file( DLLSPEC *spec )
{
    unsigned int i;
    char *res_file = NULL;
    int fd;
    struct strarray *args;

    if (!spec->nb_resources) fatal_error( "--resources mode needs at least one resource file as input\n" );
    if (!output_file_name) fatal_error( "No output file name specified\n" );

    qsort( spec->resources, spec->nb_resources, sizeof(*spec->resources), cmp_res );
    remove_duplicate_resources( spec );

    byte_swapped = 0;
    init_output_buffer();

    put_dword( 0 );      /* ResSize */
    put_dword( 32 );     /* HeaderSize */
    put_word( 0xffff );  /* ResType */
    put_word( 0x0000 );
    put_word( 0xffff );  /* ResName */
    put_word( 0x0000 );
    put_dword( 0 );      /* DataVersion */
    put_word( 0 );       /* Memory options */
    put_word( 0 );       /* Language */
    put_dword( 0 );      /* Version */
    put_dword( 0 );      /* Characteristics */

    for (i = 0; i < spec->nb_resources; i++)
    {
        unsigned int header_size = get_resource_header_size( &spec->resources[i] );

        put_dword( spec->resources[i].data_size );
        put_dword( (header_size + 3) & ~3 );
        put_string( &spec->resources[i].type );
        put_string( &spec->resources[i].name );
        align_output( 4 );
        put_dword( 0 );
        put_word( spec->resources[i].mem_options );
        put_word( spec->resources[i].lang );
        put_dword( spec->resources[i].version );
        put_dword( 0 );
        put_data( spec->resources[i].data, spec->resources[i].data_size );
        align_output( 4 );
    }

    /* if the output file name is a .res too, don't run the results through windres */
    if (strendswith( output_file_name, ".res"))
    {
        flush_output_buffer();
        return;
    }

    res_file = get_temp_file_name( output_file_name, ".res" );
    if ((fd = open( res_file, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600 )) == -1)
        fatal_error( "Cannot create %s\n", res_file );
    if (write( fd, output_buffer, output_buffer_pos ) != output_buffer_pos)
        fatal_error( "Error writing to %s\n", res_file );
    close( fd );
    free( output_buffer );

    args = find_tool( "windres", NULL );
    strarray_add( args, "-i", res_file, "-o", output_file_name, NULL );
    spawn( args );
    strarray_free( args );

    output_file_name = NULL;  /* so we don't try to assemble it */
}