char* CBEEVBTextSection::GetWritableBuffer(wxUint32* size)
{
	if(!delegateSection){
		return NULL;
	}
	
	if(writableBuffer)
		return delegateSection->GetWritableBuffer(size);
	
	char* buffer=delegateSection->GetWritableBuffer(size);
	wxUint32* u32buffer=(wxUint32*)buffer;
	
	//absolutizing pointers
	for(size_t i=0;i<delegateSection->Size();i++){
		u32buffer[i]=wxINT32_SWAP_ON_LE(wxINT32_SWAP_ON_LE(u32buffer[i])+baseOffset);
	}
	
	char* textBuffer=&buffer[delegateSection->Size()*4];
	
	//crypting text data
	for(size_t i=0;i<*size-delegateSection->Size()*4;i++){
		textBuffer[i]^=EEVB_KEY[i%29];
	}
	
	writableBuffer=buffer;
	return writableBuffer;
}
CBEEVBTextSection::CBEEVBTextSection(wxByte* buffer,wxUint32 size,wxUint32 baseOffset)
{
	writableBuffer=NULL;
	lng=ALL_LANGUAGES;
	this->baseOffset=baseOffset;
	if(((wxUint32*)buffer)[0]==0){
		delegateSection=NULL;
		return;
	}
	
	wxByte* newBuffer=new wxByte[size];
	memcpy(newBuffer,buffer,size);
	
	wxUint32 totPointers=(wxINT32_SWAP_ON_LE(*((wxUint32*)&newBuffer[0]))-baseOffset)/4;
	wxUint32* u32buffer=(wxUint32*)newBuffer;
	
	//relativizing pointers
	for(size_t i=0;i<totPointers;i++){
		u32buffer[i]=wxINT32_SWAP_ON_LE(wxINT32_SWAP_ON_LE(u32buffer[i])-baseOffset);
	}
	
	char* textBuffer=(char*)&newBuffer[totPointers*4];
	
	//decrypting text data
	for(size_t i=0;i<size-totPointers*4;i++){
		textBuffer[i]^=EEVB_KEY[i%29];
	}
	
	//done, creating text section
	delegateSection=new CBTextArchiveSection(newBuffer,totPointers);
	
	delete[] newBuffer;
}
Exemple #3
0
void MyApp::DoByteOrderDemo(wxCommandEvent& WXUNUSED(event))
{
    wxTextCtrl& textCtrl = * GetTextCtrl();

    textCtrl.Clear();
    textCtrl << _T("\nTest byte order macros:\n\n");

    #if wxBYTE_ORDER == wxLITTLE_ENDIAN
        textCtrl << _T("This is a little endian system.\n\n");
    #else
        textCtrl << _T("This is a big endian system.\n\n");
    #endif

    wxString text;

    wxInt32 var = 0xF1F2F3F4;
    text = wxEmptyString;
    text.Printf( _T("Value of wxInt32 is now: %#x.\n\n"), var );
    textCtrl.WriteText( text );

    text = wxEmptyString;
    text.Printf( _T("Value of swapped wxInt32 is: %#x.\n\n"), wxINT32_SWAP_ALWAYS( var ) );
    textCtrl.WriteText( text );

    text = wxEmptyString;
    text.Printf( _T("Value of wxInt32 swapped on little endian is: %#x.\n\n"), wxINT32_SWAP_ON_LE( var ) );
    textCtrl.WriteText( text );

    text = wxEmptyString;
    text.Printf( _T("Value of wxInt32 swapped on big endian is: %#x.\n\n"), wxINT32_SWAP_ON_BE( var ) );
    textCtrl.WriteText( text );
}
Exemple #4
0
/// Read a 4-byte integer from file (big endian)
int
MakeFont::ReadInt(wxInputStream* stream)
{
  int i32;
  stream->Read(&i32, 4);
  return wxINT32_SWAP_ON_LE(i32);
}
Exemple #5
0
/* EntryOperations::setGfxOffsets
 * Changes the offsets of the given gfx entry. Returns false if the
 * entry is invalid or not an offset-supported format, true otherwise
 *******************************************************************/
bool EntryOperations::setGfxOffsets(ArchiveEntry* entry, int x, int y)
{
	if (entry == NULL || entry->getType() == NULL)
		return false;

	// Check entry type
	EntryType* type = entry->getType();
	string entryformat = type->getFormat();
	if (!(entryformat == "img_doom" || entryformat == "img_doom_arah" ||
		entryformat == "img_doom_alpha" || entryformat == "img_doom_beta" ||
		entryformat == "img_png"))
	{
		wxLogMessage("Entry \"%s\" is of type \"%s\" which does not support offsets", entry->getName(), entry->getType()->getName());
		return false;
	}

	// Doom gfx format, normal and beta version.
	// Also arah format from alpha 0.2 because it uses the same header format.
	if (entryformat == "img_doom" || entryformat == "img_doom_beta" || entryformat == "image_doom_arah")
	{
		// Get patch header
		patch_header_t header;
		entry->seek(0, SEEK_SET);
		entry->read(&header, 8);

		// Apply new offsets
		header.left = wxINT16_SWAP_ON_BE((int16_t)x);
		header.top = wxINT16_SWAP_ON_BE((int16_t)y);

		// Write new header to entry
		entry->seek(0, SEEK_SET);
		entry->write(&header, 8);
	}

	// Doom alpha gfx format
	else if (entryformat == "img_doom_alpha")
	{
		// Get patch header
		entry->seek(0, SEEK_SET);
		oldpatch_header_t header;
		entry->read(&header, 4);

		// Apply new offsets
		header.left = (int8_t)x;
		header.top = (int8_t)y;

		// Write new header to entry
		entry->seek(0, SEEK_SET);
		entry->write(&header, 4);
	}

	// PNG format
	else if (entryformat == "img_png")
	{
		// Find existing grAb chunk
		const uint8_t* data = entry->getData(true);
		uint32_t grab_start = 0;
		for (uint32_t a = 0; a < entry->getSize(); a++)
		{
			// Check for 'grAb' header
			if (data[a] == 'g' && data[a + 1] == 'r' &&
				data[a + 2] == 'A' && data[a + 3] == 'b')
			{
				grab_start = a - 4;
				break;
			}

			// Stop when we get to the 'IDAT' chunk
			if (data[a] == 'I' && data[a + 1] == 'D' &&
				data[a + 2] == 'A' && data[a + 3] == 'T')
				break;
		}

		// Create new grAb chunk
		uint32_t csize = wxUINT32_SWAP_ON_LE(8);
		grab_chunk_t gc ={ { 'g', 'r', 'A', 'b' }, wxINT32_SWAP_ON_LE(x), wxINT32_SWAP_ON_LE(y) };
		uint32_t dcrc = wxUINT32_SWAP_ON_LE(Misc::crc((uint8_t*)&gc, 12));

		// Build new PNG from the original w/ the new grAb chunk
		MemChunk npng;
		uint32_t rest_start = 33;

		// Init new png data size
		if (grab_start == 0)
			npng.reSize(entry->getSize() + 20);
		else
			npng.reSize(entry->getSize());

		// Write PNG header and IHDR chunk
		npng.write(data, 33);

		// If no existing grAb chunk was found, write new one here
		if (grab_start == 0)
		{
			npng.write(&csize, 4);
			npng.write(&gc, 12);
			npng.write(&dcrc, 4);
		}
		else
		{
			// Otherwise write any other data before the existing grAb chunk
			uint32_t to_write = grab_start - 33;
			npng.write(data + 33, to_write);
			rest_start = grab_start + 20;

			// And now write the new grAb chunk
			npng.write(&csize, 4);
			npng.write(&gc, 12);
			npng.write(&dcrc, 4);
		}

		// Write the rest of the PNG data
		uint32_t to_write = entry->getSize() - rest_start;
		npng.write(data + rest_start, to_write);

		// Load new png data to the entry
		entry->importMemChunk(npng);

		// Set its type back to png
		entry->setType(type);
	}
	else
		return false;

	return true;
}
Exemple #6
0
void *CudpdrvRxTread::Entry()
{
    pcap_t *fp;
	char errbuf[ PCAP_ERRBUF_SIZE ];
	uint8_t packet[ 512 ];

    // First log on to the host and get configuration 
    // variables
    
    if ( m_srv.doCmdOpen( m_pobj->m_host,
                                m_pobj->m_port,
                                m_pobj->m_username,
                                m_pobj->m_password ) <= 0 ) {
        return NULL;
    }

    // Find the channel id
    uint32_t ChannelID;
    m_srv.doCmdGetChannelID( &ChannelID );

    // We want to use our own Ethernet based  GUID for this interface
    wxString strGUID;
    m_pobj->m_localGUIDrx.toString( strGUID );
    m_srv.doCmdSetGUID( (char *)strGUID.ToAscii() );

    // Open the adapter 
    if ( (fp = pcap_open_live( m_pobj->m_interface.ToAscii(),  // name of the device
							    65536,			// portion of the packet to capture. It doesn't matter in this case 
							    1,				// promiscuous mode (nonzero means promiscuous)
							    1000,			// read timeout
							    errbuf			// error buffer
							 ) ) == NULL ) {
		//fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", argv[1]);
		return NULL;
	}


    // Enter receive loop to start to log events
	m_srv.doCmdEnterReceiveLoop();

    int rv;
    vscpEvent event;
	while ( !TestDestroy() && !m_pobj->m_bQuit ) {

        if ( CANAL_ERROR_SUCCESS == 
            ( rv = m_srv.doCmdBlockReceive( &event, 1000 ) ) ) {

            // As we are on a different VSCP interface we need to filter the events we sent out 
            // ourselves.
            if ( m_pobj->m_ChannelIDtx == event.obid ) {
                continue;
            }
          
            // Set mac destination to broadcast ff:ff:ff:ff:ff:ff 
	        packet[ 0 ] = 0xff;
	        packet[ 1 ] = 0xff;
	        packet[ 2 ] = 0xff;
	        packet[ 3 ] = 0xff;
	        packet[ 4 ] = 0xff;
	        packet[ 5 ] = 0xff;
	
	        // set mac source to configured value - 6..11
            memcpy( packet + 6, m_pobj->m_localMac, 6 );
	  
            // Set the type - always 0x2574 (9598)
            packet[ 12 ] = 0x25; 
            packet[ 13 ] = 0x7e;

            // rawEthernet frame version
            packet[ 14 ] = 0x00;

            // Head
            packet[ 15 ] = ( event.head & VSCP_HEADER_PRIORITY_MASK ); 
            packet[ 16 ] = 0x00;
            packet[ 17 ] = 0x00;
            packet[ 18 ] = 0x00;    // LSB

            // VSCP sub source address For this interface it's 0x0000
            packet[ 19 ] = 0x00;
            packet[ 20 ] = 0x00;

            // Timestamp
            uint32_t timestamp = wxINT32_SWAP_ON_LE( event.timestamp );
            packet[ 21 ] = ( timestamp & 0xff000000 ) >> 24;
            packet[ 22 ] = ( timestamp & 0x00ff0000 ) >> 16;
            packet[ 23 ] = ( timestamp & 0x0000ff00 ) >> 8;
            packet[ 24 ] = ( timestamp & 0x000000ff );

            // obid
            uint32_t obid = wxINT32_SWAP_ON_LE( event.obid );
            packet[ 25 ] = ( obid & 0xff000000 ) >> 24;
            packet[ 26 ] = ( obid & 0x00ff0000 ) >> 16;
            packet[ 27 ] = ( obid & 0x0000ff00 ) >> 8;
            packet[ 28 ] = ( obid & 0x000000ff );

            // VSCP Class
            uint16_t vscp_class = wxINT16_SWAP_ON_LE( event.vscp_class );
            packet[ 29 ] = ( vscp_class & 0xff00 ) >> 8;
            packet[ 30 ] = ( vscp_class & 0xff );

            // VSCP Type
            uint16_t vscp_type = wxINT16_SWAP_ON_LE( event.vscp_type );
            packet[ 31 ] = ( vscp_type & 0xff00 ) >> 8;
            packet[ 32 ] = ( vscp_class & 0xff );

            // Size
            packet[ 33 ] = event.sizeData >> 8;
            packet[ 34 ] = event.sizeData & 0xff; 

            // VSCP Data
            for ( int idx=0; idx < event.sizeData; idx++ ) {
                packet[ 35 + idx  ] = event.pdata[ idx ];
            }

            // Send the packet
	        if ( 0 != pcap_sendpacket( fp, packet, 32 + 1  + event.sizeData ) ) {
		        //fprintf(stderr,"\nError sending the packet: %s\n", pcap_geterr(fp));
		        // An error sending the frame - we do nothing
                // TODO: Send error frame back to daemon????
	        }

            // We are done with the event - remove data if any
            if ( NULL != event.pdata ) {
                delete [] event.pdata;
                event.pdata = NULL;
            }

        } // Event received

    } // work loop   
 
    // Close the ethernet interface
    pcap_close( fp );

    // Close the channel
    m_srv.doCmdClose();

    return NULL;  
}