示例#1
0
// Candidate funciton for bs class
bool BitKey::isSubset(const BitKey & that) const
{
  bool result = true;
  const uint32_t * mydata = cDataPtr();
  const uint32_t * yodata = that.cDataPtr();
  uint32_t mysize = getWordSize(iv_Capacity);
  uint32_t yosize = getWordSize(that.iv_Capacity);
  uint32_t smsize = (yosize < mysize)? yosize : mysize;
  // size can be non-zero with no bits on - so if that has no bits than use
  // operator==
  BitKey zero;
  // only true if both are empty - eg not bits on"
  if(that == zero) result = operator==(that);
  // if yosize <= mysize than just match smallest amount of data
  // if yozize > mysize than extra yodata must be zero
  for(uint32_t i = 0; (i < smsize) && (result == true); ++i,++mydata,++yodata)
  {
    result = (*mydata & *yodata) == *yodata;
  }
  if(result &&  (yosize > mysize))
  {
    for(yosize -= mysize; yosize != 0 && result; --yosize, ++yodata)
    {
      result = *yodata == 0x00000000;
    }
  }

  return result;
}
示例#2
0
bool BitKey::operator==(const BitKey & that) const
{
  bool result = true;
  const uint32_t * mydata = cDataPtr();
  const uint32_t * yodata = that.cDataPtr();
  uint32_t mysize = getWordSize(iv_Capacity);
  uint32_t yosize = getWordSize(that.iv_Capacity);
  uint32_t smsize = (yosize < mysize)? yosize : mysize;

  // If size is different than the extra must be zero
  for(uint32_t i = 0; (i < smsize) && (result == true); ++i,++mydata,++yodata)
  {
    result = (*mydata == *yodata);
  }
  if(result &&  (yosize > mysize))
  {
    for(yosize -= mysize; yosize != 0 && result; --yosize, ++yodata)
    {
      result = *yodata == 0x00000000;
    }
  }
  else if (result && (mysize > yosize))
  {
    for(mysize -= yosize; mysize != 0 && result; --mysize, ++mydata)
    {
      result = *mydata == 0x00000000;
    }
  }

  return result;
}
示例#3
0
inline void setupECC()
{
#ifdef DEBUG
  print("Start ECC, Curve %d\n\r", uECC_curve());
  print("Start ECC, Wordsize %d\n\r", getWordSize());
  print("Start ECC, UECC Bytes %d\n\r", uECC_BYTES);
#endif
  uECC_set_rng(&fake_rng);
  int failed = uECC_make_key(public, private);
#ifdef INFO
  if (!failed){
    print("uECC_make_key() failed\n\r");
  }
#endif

#ifdef INFO
  int i;
  print("Public key:\n\r");
  for(i=0; i<uECC_BYTES * 2; i++){
    print("%x",public[i]);
  }
  print("\n\rPrivate key:\n\r");
  for(i=0; i<uECC_BYTES; i++){
    print("%x",private[i]);
  }
  print("\n\r");
#endif
  memcpy(hash, public, uECC_BYTES);
}
示例#4
0
文件: Task.c 项目: mountainstorm/Flow
/*
 * Exported function implementations
 */
kern_return_t Task_createWithTask(Task* self, task_t task) {
	kern_return_t retVal = KERN_INVALID_ARGUMENT;
	if (self == NULL || task == TASK_NULL) {
		Log_invalidArgument("self: %p, task: %p", self, (void*) task);
		
	} else {
		pid_t pid = -1;
		(void) pid_for_task(task, &pid);	

		cpu_type_t cpuType = getCPUTypeForTask(pid);
		if (cpuType == CPU_TYPE_ARM) {
			printf("ARM; NOT IMPLEMENTED\n");
			//self->arch = TaskArch_ARM_create();
			
		} else if (cpuType == CPU_TYPE_I386 || cpuType == CPU_TYPE_X86) {
			self->arch = TaskArch_x86_create();
			
		} else if (cpuType == CPU_TYPE_X86_64) {
			self->arch = TaskArch_x86_64_create();
			
		} else {
			Log_error("Unsupported process architecture, %d", cpuType);
			retVal = KERN_FAILURE;
		}
		
		if (self->arch) {
			self->task = task;
			self->pid = pid;
			self->cpuType = cpuType;
			self->wordSize = getWordSize(pid);
			retVal = KERN_SUCCESS;
		}
	}
	return retVal;
}
示例#5
0
void BitKey::ReAllocate(uint32_t i_len)
{
  if(i_len > iv_Capacity)  // never shrink
  {
    bool wasDirect = IsDirect();
    uint32_t oldSize = iv_Capacity;
    uint32_t * oldPtr = DataPtr();

    uint32_t wordsize = getWordSize(i_len);
    iv_Capacity = 32*wordsize;

    bool isDirect = IsDirect();

    if(!isDirect)  // to indirect
    {
      uint32_t * newBuffer = new uint32_t[wordsize];
      BitString dbs(iv_Capacity,newBuffer);
      dbs.Pattern(0x00000000);
      BitString sbs(oldSize,oldPtr);
      dbs.SetBits(sbs);
      iv_storage1 = 0;
      if(!wasDirect) // from indirect
      {
        delete [] iv_rep.buffer;
      }
      iv_rep.buffer = newBuffer;
    }
  }
}
示例#6
0
BitKey & BitKey::operator=(const BitKey & bit_list)
{
  if(iv_Capacity)
  {
    BitString bs(iv_Capacity,DataPtr());
    bs.Pattern(0x00000000);
  }
  ReAllocate(bit_list.iv_Capacity);
  if(IsDirect()) // implies bit_list is also direct
  {
    iv_storage1 = bit_list.iv_storage1;
    iv_rep.storage2 = bit_list.iv_rep.storage2;
  }
  else
  {
    const uint32_t * dataPtr = NULL;
    if(bit_list.IsDirect())
    {
      dataPtr = &bit_list.iv_storage1;
    } else
    {
      dataPtr = bit_list.iv_rep.buffer;
    }
    memcpy(iv_rep.buffer,dataPtr,4*getWordSize(bit_list.iv_Capacity));
  }
  return(*this);
}
NASubCollection<T> & NASubCollection<T>::complement()
   {
  // can only take the complement of a subset
  assert(superset_ != NULL);

  CollIndex maxWords;
  CollIndex superSetSize = superset_->getSize();

  resize(superSetSize);
  maxWords = getWordSize();

  // for each used entry in the superset, toggle the corresponding subset bit
  for (Int32 i = 0; i < (Int32) superSetSize; i++)
    {
      if (superset_->getUsage(i) == UNUSED_COLL_ENTRY)
	{
	  // a subset shouldn't have an element that's not part of
	  // the superset
	  assert(NOT testBit(i));
	}
      else
	{
	  // is the element in the subset
	  if (testBit(i))
	    // yes, then delete it
	    subtractElement(i);
	  else
	    // no, then add it
	    addElement(i);
	}
    }
  
  return *this;
  }
NABoolean NASubCollection<T>::lastUsed(CollIndex &lastBit) const
  {
  CollIndex lastNonZeroWord = getWordSize() - 1;

  // find last non-zero word -- the > 0 test is there to avoid wrapping
  // in case CollIndex is an unsigned integer
  while ((lastNonZeroWord > 0) && (word(lastNonZeroWord) == 0))
    {
      lastNonZeroWord--;
    }

  // at this point, we either found the last non-zero word or there
  // are none

  if (word(lastNonZeroWord) == 0)
    return FALSE;  // return; there are none

  // we know we have the last non-zero word; find last set bit

  lastBit = 
    (lastNonZeroWord << LogBitsPerWord) + BitsPerWord - 1;

  while (!testBit(lastBit))
    {
      lastBit--;
    }
  
  return TRUE;  // found the last set bit
  }
示例#9
0
BitKey::BitKey (const BitKey & bit_list)
: iv_Capacity(bit_list.iv_Capacity), iv_storage1(bit_list.iv_storage1)
{
  if(IsDirect())
  {
    iv_rep.storage2 = bit_list.iv_rep.storage2;
  }
  else
  {
    uint32_t size = getWordSize(iv_Capacity);
    iv_rep.buffer = new uint32_t[size];
    memcpy(iv_rep.buffer,bit_list.iv_rep.buffer,4*size);
  }
}
示例#10
0
const QString &map::getTableText(bool colour)
{
    QStringList tableTextList;
    double min = getZValues()->at(0);
    double max = getZValues()->at(getZValues()->length() - 1);
    double diff = max - min;

    int yAxisWidth = 0;
    if (axes[1]) {
        yAxisWidth = axes[1]->getWidth();
    }
    int xAxisWidth = axes[0]->getWidth();
    int valWidth = getWidth();
    if (xAxisWidth > valWidth) {
        valWidth = xAxisWidth;
    }
    if (isDTC()) {
        valWidth = 2 * getWordSize() + 2;
    }

    QString mapText = "<b>Map    " + formatHex(getAddress(), false, true) + ": " + label;
    if (units.length() != 0) {
        mapText += " (" + units + ")";
    }
    mapText += "</b>";
    tableTextList << mapText;

    if (!axes[0]->isFixed()) {
        QString axis1Text = "<b>X-Axis " + formatHex(axes[0]->getAddress(), false, true) + ": " + axes[0]->getLabel();
        if (axes[0]->getUnits().length() != 0) {
            axis1Text += " (" + axes[0]->getUnits() + ")";
        }
        axis1Text += "</b>";
        tableTextList << axis1Text;
    }
    if (axes[1]) {
        QString axis2Text = "<b>Y-Axis " + formatHex(axes[1]->getAddress(), false, true) + ": " + axes[1]->getLabel();
        if (axes[0]->getUnits().length() != 0) {
            axis2Text += " (" + axes[1]->getUnits() + ")";
        }
        axis2Text += "</b>";
        tableTextList << axis2Text;
    }
    tableTextList << "";

    QString xLabels;
    if (yAxisWidth > 0) {
        xLabels.fill(QChar(' '), yAxisWidth + 1);
    }
    for (int i = 0; i < getXDim(); i++) {
        xLabels += QString("%1 ").arg(axisValue(0, i), valWidth, 'f', axes[0]->getDecimalPoints(), QChar(' '));
    }
    xLabels = "<span style=\"text-decoration:underline; font-weight:bold;\">" + xLabels + "</span>";
    tableTextList << xLabels;

    for (int y = 0; y < getYDim(); y++) {
        QString row;
        if (axes[1]) {
            int dp = axes[1]->getDecimalPoints();
            row = QString("%1 ").arg(axisValue(1, y), yAxisWidth, 'f', dp, QChar(' '));
            row = "<span style=\"font-weight:bold\">" + row + "</span>";
        }

        for (int x = 0; x < getXDim(); x++) {
            int dp = getDecimalPoints();
            if (isDTC()) {
                int val = getValue(x,y);
                row += "0x" + QString("%1 ").arg(val, valWidth-2, 16, QChar('0')).toUpper();
            }
            else {
                double val = getValue(x, y);
                if (colour) {
                    double temp = val - min;
                    if (diff == 0) {
                        temp = 1.0;
                    }
                    else {
                        temp /= diff;
                    }
                    int red = 255*temp;
                    int green = 255-255*temp;
                    row += "<span style=\"background-color: rgb(" + QString::number(red) + "," + QString::number(green) + ",0);\">";
                }
                else {
                    row += "<span>";
                }

                row += QString("%1 </span>").arg(val, valWidth, 'f', dp, QChar(' '));
            }
        }
        tableTextList << row;
    }

    tableText = "<pre style=\"font-size:16px; color:black\">" + tableTextList.join("\n") + "</pre>";
    return tableText;
}