// hacky but faster version of "QString::sprintf("%d-%d", i, enabled)"
static QString qPixmapSerial(quint64 i, bool enabled)
{
    ushort arr[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', ushort('0' + enabled) };
    ushort *ptr = &arr[16];

    while (i > 0) {
        // hey - it's our internal representation, so use the ascii character after '9'
        // instead of 'a' for hex
        *(--ptr) = '0' + i % 16;
        i >>= 4;
    }

    return QString((const QChar *)ptr, int(&arr[sizeof(arr) / sizeof(ushort)] - ptr));
}
示例#2
0
// делит a на b, при учёте, что b*MAX_ELEM >=a
ushort DivideTwo( TrueLong& a, TrueLong& b )
{
   if( a.IsZero() )   return 0;
   if( b.IsZero() )   return 0;
   ushort min = 0, cur = ushort(LIMIT >> 1);
   ulong max = LIMIT;
   TrueLong c;
   for( ; (max-min) > 1; cur = ushort((max+min)/2) )
   {
      c = b; c *= cur;
      if( c <= a )   min = cur;
      else           max = cur;
   }
   return min;
}
示例#3
0
文件: ETBrush.cpp 项目: oksangman/Ant
  void saveBrushToImage(const Brush& brush, Image& image)
  {
    // save brush as a 16bit grayscale image
#if OGRE_VERSION_MINOR > 4
    ushort* data = (ushort*)OGRE_ALLOC_T(uchar, brush.getWidth()*brush.getHeight()*sizeof(ushort), MEMCATEGORY_GENERAL);
#else
    ushort* data = (ushort*)new uchar[brush.getWidth()*brush.getHeight()*sizeof(ushort)];
#endif
    for (size_t x = 0; x < brush.getWidth(); ++x)
      for (size_t y = 0; y < brush.getHeight(); ++y)
        data[y*brush.getWidth() + x] = ushort(brush.at(x, y) * 0xffff);

    // pass the data to the image, image takes over ownership
    image.loadDynamicImage((uchar*)data, brush.getWidth(), brush.getHeight(), 1, PF_L16, true);
  }
示例#4
0
static void OutVarNameVal(op_t &x)
{
ushort addr = ushort(x.value);
ea_t toea = toEA(codeSeg(addr,x.n), addr);
#if IDP_INTERFACE_VERSION > 37
        if ( out_name_expr(x,toea,addr) )return;
#else
        const char *ptr;
        if ( (ptr=get_name_expr(cmd.ea+x.offb, toea, addr)) != NULL ){
                //вывод имен переменных и меток перехода
            OutLine(ptr);
        }
#endif
else OutValue(x, OOFW_16);
}
示例#5
0
//���������������������������������������������������������������������������
// SimOffield - insert
//���������������������������������������������������������������������������
BOOL SimOffield::insert(ushort t)
{
    assertMyth("SimOffield::insert needs parent",
               parent != 0 && parent->teams[t].offields != 0);

    if (index != ushort(-1))
        remove();

    team = t;

//��� Find empty slot
    SimulatorState::sim_team_t *st = &parent->teams[t];

    for (int i=0; i < st->ofld_max; i++)
    {
        if (!st->offields[i])
            break;
    }
    //��� Expand array
    if (i >= st->ofld_max)
    {
        ushort nsize = st->ofld_max + SIM_INIT_OBJECTS;

        SimOffield **tmp = new SimOffield *[nsize];
        if (!tmp)
            return FALSE;

        memset(tmp, 0, sizeof(SimOffield*) * nsize);

        memcpy(tmp, st->offields, sizeof(SimOffield*) * st->ofld_max);

        delete [] st->offields;

        st->offields = tmp;
        st->ofld_max = nsize;
    }

//��� Insert into slot
    st->offields[i] = this;
    index = i;

    if (i >= st->ofld_hi)
        st->ofld_hi = i + 1;

    return TRUE;
}
    void LodOutputProviderBuffer::bakeLodLevel(LodData* data, int lodIndex)
    {
        unsigned short submeshCount = ushort(mBuffer.submesh.size());

        // Create buffers.
        for (unsigned short i = 0; i < submeshCount; i++) {
            vector<LodIndexBuffer>::type& lods = mBuffer.submesh[i].genIndexBuffers;
            size_t indexCount = data->mIndexBufferInfoList[i].indexCount;
            lods.reserve(lods.size() + 1);
            LodIndexBuffer& curLod = *lods.insert(lods.begin() + lodIndex, LodIndexBuffer());
            if (indexCount == 0) {
                curLod.indexCount = 3;
            } else {
                curLod.indexCount = indexCount;
            }
            curLod.indexStart = 0;
            curLod.indexSize = data->mIndexBufferInfoList[i].indexSize;
            curLod.indexBufferSize = 0; // It means same as index count
            curLod.indexBuffer = Ogre::SharedPtr<unsigned char>(new unsigned char[curLod.indexCount * curLod.indexSize]);
            // buf is an union, so pint=pshort
            data->mIndexBufferInfoList[i].buf.pshort = (unsigned short*) curLod.indexBuffer.get();

            if (indexCount == 0) {
                memset(data->mIndexBufferInfoList[i].buf.pshort, 0, 3 * data->mIndexBufferInfoList[i].indexSize);
            }
        }

        // Fill buffers.
        size_t triangleCount = data->mTriangleList.size();
        for (size_t i = 0; i < triangleCount; i++) {
            if (!data->mTriangleList[i].isRemoved) {
                if (data->mIndexBufferInfoList[data->mTriangleList[i].submeshID].indexSize == 2) {
                    for (int m = 0; m < 3; m++) {
                        *(data->mIndexBufferInfoList[data->mTriangleList[i].submeshID].buf.pshort++) =
                            static_cast<unsigned short>(data->mTriangleList[i].vertexID[m]);
                    }
                } else {
                    for (int m = 0; m < 3; m++) {
                        *(data->mIndexBufferInfoList[data->mTriangleList[i].submeshID].buf.pint++) =
                            static_cast<unsigned int>(data->mTriangleList[i].vertexID[m]);
                    }
                }
            }
        }
    }
示例#7
0
void tst_QTextScriptEngine::thaiLineSplitting()
{
    //Test that a word with full stops is treated as a single item
    QString s(QString::fromUtf8("ม.ค."));
    QTextLayout layout(s);
    layout.beginLayout();
    layout.createLine();
    layout.endLayout();

    QTextEngine *e = layout.engine();
    e->width(0, s.length()); //force itemize and shape

    // A thai implementation could either remove the ZWJ and ZWNJ characters, or hide them.
    // The current implementation hides them, so we test for that.
    // But make sure that we don't hide anything else
    QCOMPARE(e->layoutData->items.size(), 1);
    QCOMPARE(e->layoutData->items[0].num_glyphs, ushort(4));  // Thai: It's important that the whole string is counted as one string
}
示例#8
0
void QGLIndexBufferPrivate::append
    (const QGLIndexBufferPrivate *other, uint offset, int start)
{
    if (elementType == GL_UNSIGNED_SHORT &&
            other->elementType == GL_UNSIGNED_SHORT) {
        // Both buffers are ushort.
        const ushort *data = other->indexesShort.constData() + start;
        int count = other->indexesShort.count() - start;
        indexesShort.reserve(indexesShort.count() + count);
        indexCount += count;
        while (count-- > 0)
            indexesShort.append(ushort(*data++ + offset));
    } else if (elementType == GL_UNSIGNED_SHORT) {
        // Only first buffer is ushort: convert it to int first.
        const ushort *indexes = indexesShort.constData();
        int count = indexesShort.count();
        indexesInt.reserve(count + other->indexesInt.count());
        while (count-- > 0)
            indexesInt.append(*indexes++);
        indexesShort = QArray<ushort>();
        elementType = GL_UNSIGNED_INT;
        const uint *data = other->indexesInt.constData() + start;
        count = other->indexesInt.count() - start;
        indexCount += count;
        while (count-- > 0)
            indexesInt.append(*data++ + offset);
    } else if (other->elementType == GL_UNSIGNED_SHORT) {
        // Only second buffer is ushort.
        const ushort *data = other->indexesShort.constData() + start;
        int count = other->indexesShort.count() - start;
        indexesInt.reserve(indexesInt.count() + count);
        indexCount += count;
        while (count-- > 0)
            indexesInt.append(*data++ + offset);
    } else {
        // Neither buffer is ushort.
        const uint *data = other->indexesInt.constData() + start;
        int count = other->indexesInt.count() - start;
        indexesInt.reserve(indexesInt.count() + count);
        indexCount += count;
        while (count-- > 0)
            indexesInt.append(*data++ + offset);
    }
}
示例#9
0
//���������������������������������������������������������������������������
// SimObject - insert
//���������������������������������������������������������������������������
BOOL SimObject::insert(ushort t)
{
    assertMyth("SimObject::insert needs parent",
               parent != 0 && parent->objects != 0);

    if (index != ushort(-1))
        remove();

    team = t;

//��� Find empty slot
    for (int i=0; i < parent->obj_max; i++)
    {
        if (!parent->objects[i])
            break;
    }
    //��� Expand array
    if (i >= parent->obj_max)
    {
        ushort nsize = parent->obj_max + SIM_INIT_OBJECTS;

        SimObject **tmp = new SimObject *[nsize];
        if (!tmp)
            return FALSE;

        memset(tmp, 0, sizeof(SimObject*) * nsize);

        memcpy(tmp, parent->objects, sizeof(SimObject*) * parent->obj_max);

        delete [] parent->objects;

        parent->objects = tmp;
        parent->obj_max = nsize;
    }

//��� Insert into slot
    parent->objects[i] = this;
    index = i;

    if (i >= parent->obj_hi)
        parent->obj_hi = i + 1;

    return TRUE;
}
示例#10
0
 QVariant parseString()
 {
     QVarLengthArray<QChar, 1024> result;
     QChar c = next();
     DENG2_ASSERT(c == '\"');
     forever
     {
         c = nextNoSkip();
         if(c == '\\')
         {
             // Escape.
             c = nextNoSkip();
             if(c == '\"' || c == '\\' || c == '/')
                 result.append(c);
             else if(c == 'b')
                 result.append('\b');
             else if(c == 'f')
                 result.append('\f');
             else if(c == 'n')
                 result.append('\n');
             else if(c == 'r')
                 result.append('\r');
             else if(c == 't')
                 result.append('\t');
             else if(c == 'u')
             {
                 QString code = source.mid(pos, 4);
                 pos += 4;
                 result.append(QChar(ushort(code.toLong(0, 16))));
             }
             else error("unknown escape sequence in string");
         }
         else if(c == '\"')
         {
             // End of string.
             break;
         }
         else
         {
             result.append(c);
         }
     }
     return QString(result.constData(), result.size());
 }
 void LodOutputProviderBuffer::bakeManualLodLevel( LodData* data, String& manualMeshName, int lodIndex )
 {
     // placeholder dummy
     unsigned short submeshCount = ushort(mBuffer.submesh.size());
     LodIndexBuffer buffer;
     buffer.indexSize = 2;
     buffer.indexCount = 0;
     buffer.indexStart = 0;
     buffer.indexBufferSize = 0;
     if(lodIndex < 0) {
         for (unsigned short i = 0; i < submeshCount; i++) {
             mBuffer.submesh[i].genIndexBuffers.push_back(buffer);
         }
     } else {
         for (unsigned short i = 0; i < submeshCount; i++) {
             mBuffer.submesh[i].genIndexBuffers.insert(mBuffer.submesh[i].genIndexBuffers.begin() + lodIndex, buffer);
         }
     }
 }
示例#12
0
void GameState::sendLoginHandshake()
{
    if(getServerState() != nc::ServerState::Login)
    {
        qWarning() << "GameState: called sendLoginHandshake() in state" << static_cast<int>(getServerState());
        return;
    }

    nc::MessageBuffer buffer;
    buffer
        << nc::VarInt(0x00) // packet id
        << nc::VarInt(47)   // protocol version (1.8.8)
        << QString(m_host)  // server address
        << ushort(m_port)   // server port
        << nc::VarInt(2);   // next state: login

    QByteArray bufferBytes = buffer.getAllBytes();
    emit outboundMessage(bufferBytes);
}
void AlsaMidiOutputDevice::writeChannel(ushort channel, uchar value)
{
    // m_universe contains scaled values (0-127), so we have to compare scaled value as well
    // however, since writeUniverse scales the value again, we have to store unscaled value.
    char scaled = DMX2MIDI(value);
    if (channel < ushort(m_universe.size()) && m_universe[channel] != scaled)
    {
        QByteArray tmp(m_universe);

        for (uchar ch = 0; ch < MAX_MIDI_DMX_CHANNELS && ch < tmp.size(); ++ch)
        {
           char midi = tmp[ch];
           tmp[ch] = (char)MIDI2DMX(midi);
        }

        tmp[channel] = value;
        writeUniverse(tmp);
    }
}
    void LodInputProviderBuffer::initialize( LodData* data )
    {
#if OGRE_DEBUG_MODE
        data->mMeshName = mBuffer.meshName;
#endif
        data->mMeshBoundingSphereRadius = mBuffer.boundingSphereRadius;
        unsigned short submeshCount = ushort(mBuffer.submesh.size());
        for (unsigned short i = 0; i < submeshCount; ++i) {
            LodInputBuffer::Submesh& submesh = mBuffer.submesh[i];
            LodVertexBuffer& vertexBuffer =
                (submesh.useSharedVertexBuffer ? mBuffer.sharedVertexBuffer : submesh.vertexBuffer);
            addVertexData(data, vertexBuffer, submesh.useSharedVertexBuffer);
            addIndexData(data, submesh.indexBuffer, submesh.useSharedVertexBuffer, i);
        }

        // These were only needed for addIndexData() and addVertexData().
        mSharedVertexLookup.clear();
        mVertexLookup.clear();
    }
示例#15
0
inline void drawPixel(QCosmeticStroker *stroker, int x, int y, int coverage)
{
    const QRect &cl = stroker->clip;
    if (x < cl.x() || x > cl.right() || y < cl.y() || y > cl.bottom())
        return;

    int lastx = stroker->spans[stroker->current_span-1].x + stroker->spans[stroker->current_span-1].len ;
    int lasty = stroker->spans[stroker->current_span-1].y;

    if (stroker->current_span == QCosmeticStroker::NSPANS || y < lasty || (y == lasty && x < lastx)) {
        stroker->blend(stroker->current_span, stroker->spans, &stroker->state->penData);
        stroker->current_span = 0;
    }

    stroker->spans[stroker->current_span].x = ushort(x);
    stroker->spans[stroker->current_span].len = 1;
    stroker->spans[stroker->current_span].y = y;
    stroker->spans[stroker->current_span].coverage = coverage*stroker->opacity >> 8;
    ++stroker->current_span;
}
示例#16
0
//--------------------------------------------------------------------------
static bool load_name2(ushort index, ulong offset)
{
  uint64 off, size;
  if ( index == ushort(-1) )
  {
    off = dynstr_off;
    size = dynstr_size;
  }
  else
  {
    off  = elf64 ? shdr64[index].sh_offset : shdr32[index].sh_offset;
    size = elf64 ? shdr64[index].sh_size   : shdr32[index].sh_size;
  }
  if ( offset >= size )
  {
    qsnprintf(name, sizeof(name), "bad offset %08lx", low(offset+off));
    return false;
  }
  ulong pos = qltell(li);
  offset = low(offset + off);
  qlseek(li, offset);

  register char *p;
  register int  i, j;
  bool ok = true;
  for(i = 0, p = name; i < sizeof(name)-1; i++, p++)
    if((j = qlgetc(li)) == EOF)
    {
      qstrncpy(p, "{truncated name}", sizeof(name)-(p-name));
      ok = false;
      break;
    }
    else if((*p = (char)j) == '\0') break;
  if(i == sizeof(name)-1)
  {
    qstrncpy(p-5, "...", 5);
    ok = false;
  }
  qlseek(li, pos);
  return ok;
}
示例#17
0
Boolean TFileEditor::loadFile()
{
    ifstream f( fileName, ios::in | ios::binary );
    if( !f )
        {
        setBufLen( 0 );
        return True;
        }
    else
        {
        long fSize = filelength( f.rdbuf()->fd() );
        if( fSize > (UINT_MAX-0x1F) || setBufSize(ushort(fSize)) == False )
            {
            editorDialog( edOutOfMemory );
            return False;
            }
        else
            {
            if ( fSize > INT_MAX )
            {
               f.read( &buffer[bufSize - size_t(fSize)], INT_MAX );
               f.read( &buffer[bufSize - size_t(fSize) + INT_MAX],
                                size_t(fSize - INT_MAX) );

            }
            else
               f.read( &buffer[bufSize - size_t(fSize)], size_t(fSize) );
            if( !f )
                {
                editorDialog( edReadError, fileName );
                return False;
                }
            else
                {
                setBufLen(size_t(fSize));
                return True;
                }
            }
        }
}
示例#18
0
文件: pilot.cpp 项目: nealey/vera
static uchar* apply_relocs(uchar *packed, ea_t relocbase, ea_t targetbase, bool code=false)
{
  uint32 nrelocs = swap32(*(uint32*)packed);
  packed+=4;
  ea_t offset = relocbase;
  fixup_data_t reloc;
  if ( code )
  {
    segment_t* seg = getseg(targetbase);
    reloc.sel = ushort(seg != NULL ? seg->sel : BADSEL);
    reloc.type = FIXUP_OFF32;
  }
  else
  {
    reloc.type = FIXUP_OFF32|FIXUP_REL;
    reloc.sel = (ushort)BADSEL;
  }
  reloc.displacement = 0;
  //msg("%d relocations\n", nrelocs);
  for ( uint i=0; i<nrelocs; i++ )
  {
    uchar c = *packed;
    if ( c&0x80 )
    {
      //signed 8-bit delta
      offset+=(char)(c<<1);
      packed++;
    }
    else if ( c&0x40 )
    {
      //15-bit unsigned(?) delta
      //comment in PalmOS_Startup.cpp says "unsigned" but they cast it to a signed short...
      uint32 o1 = swap16(*(ushort*)packed);
      packed+=2;
      offset+=(short)(o1<<2)>>1;
    }
    else
    {
Boolean graphAppLoadDriver( int driverNum )
{
    char fileName[MAXSIZE];
    int handle, ccode;
    ostrstream ss(fileName, MAXSIZE);

    if (driverNum <= lastDriver)
        {
        if (bgiPath[strlen(bgiPath)-1] != '\\')
            strcat(bgiPath,"\\");
        ss << bgiPath << driverName[driver-1] << ".BGI" << ends;

        ifstream f(ss.str(), ios::in|ios::binary);
        if (f)
            {
            handle = f.rdbuf()->fd();
            driverSize = (unsigned int)filelength(handle);
            f.seekg( 0L, ios::beg);
	    if (driverSize < (64 * 1024L - 0xF))
                {
                driverPtr = NULL;
                driverPtr = (DriverPtrFunction) new char[driverSize];
                f.read((char *)driverPtr, ushort(driverSize));
                if (f)
                    {
                    ccode = registerfarbgidriver(driverPtr);
                    if (ccode >= 0)
                        return True;
                    else
                        freeDriverMem();
                    }
                    f.close();
                }
            }
        }
    return False;
}
//--------------------------------------------------------------------------
// Get PE header
// In: ea=DLL imagebase, nh=buffer to keep the answer
//     child==true:ea is an address in the child process
//     child==false:ea is an address in the the debugger itself
// Returns: offset to the headers, BADADDR means failure
ea_t win32_debmod_t::get_pe_header(ea_t ea, peheader_t *nh)
{
  uint32 offset = 0;
  uint32 magic;
  if ( _read_memory(ea, &magic, sizeof(magic)) != sizeof(magic) )
    return BADADDR;
  if ( ushort(magic) == MC2('M','Z') )
  {
    if ( _read_memory(ea+PE_PTROFF, &offset, sizeof(offset)) != sizeof(offset) )
      return BADADDR;
  }
  peheader64_t pe64;
  if ( _read_memory(ea+offset, &pe64, sizeof(pe64)) != sizeof(pe64) )
    return BADADDR;
  if ( !pe64_to_pe(*nh, pe64, true, true) )
    return BADADDR;
  if ( nh->signature != PEEXE_ID )
    return BADADDR;
#ifdef __X64__
  if ( debapp_attrs.addrsize == 8 && !pe64.is_pe_plus() )
    debapp_attrs.addrsize = 4;
#endif
  return offset;
}
示例#21
0
TrueLong& TrueLong::operator *= ( long val )
{  
   if( !val )   return *this = 0;
   if( val < 0 )
      val = -val;
   if( IsZero() || val==1 )   return *this;

   if( val >= LIMIT )
      return *this *= TrueLong( val );

   ulong tmp, add = 0;
   ushort* end = value + meenl;
   for( ushort* cur = value; cur<end; cur++ )
   {
      tmp = *cur;
      tmp *= val;
      tmp += add;
      *cur = ushort(tmp % LIMIT);
      add = tmp / LIMIT;
   }
   AddHighElem( (ushort)add );
   Optimize();
   return *this;
}
示例#22
0
void tst_QTextScriptEngine::thaiSaraAM()
{
    //U+0E33 (SARA AM, ำ) gets counted as two characters, so make sure it does not throw off the word boundaries by throwing off the logClusters
    QString s(QString::fromUtf8("มาฟังคำตัดสินคดีฆ่ากำนันยูร"));
    unsigned short clusterNumber[] = {0,1,2,2,3,4,6,7,7,9,10,10,12,13,14,14,16,16,18,19,21,22,22,24,25,25,27};
    QTextLayout layout(s);
    layout.beginLayout();
    layout.createLine();
    layout.endLayout();

    QTextEngine *e = layout.engine();
    e->width(0, s.length()); //force itemize and shape

    QCOMPARE(e->layoutData->items.size(), 1);
    QEXPECT_FAIL("", "QTBUG-26495", Abort);
    QCOMPARE(e->layoutData->items[0].num_glyphs, ushort(28));
    QCOMPARE(sizeof(clusterNumber) / sizeof(unsigned short), (size_t)s.size());

    for (int i = 0 ; i < e->layoutData->items[0].num_glyphs; i++)
        QCOMPARE((bool)e->layoutData->glyphLayout.attributes[i].dontPrint, 0);

    for (int i = 0; i < s.length(); i++)
        QCOMPARE(e->layoutData->logClustersPtr[i], clusterNumber[i]);
}
示例#23
0
/*
 * Elf32 binaries.
 */
static int
elfdotout(int fd, Fhdr *fp, ExecHdr *hp)
{

	ulong (*swal)(ulong);
	ushort (*swab)(ushort);
	Ehdr *ep;
	Phdr *ph;
	int i, it, id, is, phsz;

	/* bitswap the header according to the DATA format */
	ep = &hp->e;
	if(ep->ident[CLASS] != ELFCLASS32) {
		werrstr("bad ELF class - not 32 bit");
		return 0;
	}
	if(ep->ident[DATA] == ELFDATA2LSB) {
		swab = leswab;
		swal = leswal;
	} else if(ep->ident[DATA] == ELFDATA2MSB) {
		swab = beswab;
		swal = beswal;
	} else {
		werrstr("bad ELF encoding - not big or little endian");
		return 0;
	}

	ep->type = swab(ep->type);
	ep->machine = swab(ep->machine);
	ep->version = swal(ep->version);
	ep->elfentry = swal(ep->elfentry);
	ep->phoff = swal(ep->phoff);
	ep->shoff = swal(ep->shoff);
	ep->flags = swal(ep->flags);
	ep->ehsize = swab(ep->ehsize);
	ep->phentsize = swab(ep->phentsize);
	ep->phnum = swab(ep->phnum);
	ep->shentsize = swab(ep->shentsize);
	ep->shnum = swab(ep->shnum);
	ep->shstrndx = swab(ep->shstrndx);
	if(ep->type != EXEC || ep->version != CURRENT)
		return 0;

	/* we could definitely support a lot more machines here */
	fp->magic = ELF_MAG;
	fp->hdrsz = (ep->ehsize+ep->phnum*ep->phentsize+16)&~15;
	switch(ep->machine) {
	case I386:
		mach = &mi386;
		fp->type = FI386;
		break;
	case MIPS:
		mach = &mmips;
		fp->type = FMIPS;
		break;
	case SPARC64:
		mach = &msparc64;
		fp->type = FSPARC64;
		break;
	case POWER:
		mach = &mpower;
		fp->type = FPOWER;
		break;
	case AMD64:
		mach = &mamd64;
		fp->type = FAMD64;
		break;
	case ARM:
		mach = &marm;
		fp->type = FARM;
		break;
	default:
		return 0;
	}

	if(ep->phentsize != sizeof(Phdr)) {
		werrstr("bad ELF header size");
		return 0;
	}
	phsz = sizeof(Phdr)*ep->phnum;
	ph = malloc(phsz);
	if(!ph)
		return 0;
	seek(fd, ep->phoff, 0);
	if(read(fd, ph, phsz) < 0) {
		free(ph);
		return 0;
	}
	hswal(ph, phsz/sizeof(ulong), swal);

	/* find text, data and symbols and install them */
	it = id = is = -1;
	for(i = 0; i < ep->phnum; i++) {
		if(ph[i].type == LOAD
		&& (ph[i].flags & (R|X)) == (R|X) && it == -1)
			it = i;
		else if(ph[i].type == LOAD
		&& (ph[i].flags & (R|W)) == (R|W) && id == -1)
			id = i;
		else if(ph[i].type == NOPTYPE && is == -1)
			is = i;
	}
	if(it == -1 || id == -1) {
		/*
		 * The SPARC64 boot image is something of an ELF hack.
		 * Text+Data+BSS are represented by ph[0].  Symbols
		 * are represented by ph[1]:
		 *
		 *		filesz, memsz, vaddr, paddr, off
		 * ph[0] : txtsz+datsz, txtsz+datsz+bsssz, txtaddr-KZERO, datasize, txtoff
		 * ph[1] : symsz, lcsz, 0, 0, symoff
		 */
		if(ep->machine == SPARC64 && ep->phnum == 2) {
			ulong txtaddr, txtsz, dataddr, bsssz;

			txtaddr = ph[0].vaddr | 0x80000000;
			txtsz = ph[0].filesz - ph[0].paddr;
			dataddr = txtaddr + txtsz;
			bsssz = ph[0].memsz - ph[0].filesz;
			settext(fp, ep->elfentry | 0x80000000, txtaddr, txtsz, ph[0].offset);
			setdata(fp, dataddr, ph[0].paddr, ph[0].offset + txtsz, bsssz);
			setsym(fp, ph[1].filesz, 0, ph[1].memsz, ph[1].offset);
			free(ph);
			return 1;
		}

		werrstr("No TEXT or DATA sections");
		free(ph);
		return 0;
	}

	settext(fp, ep->elfentry, ph[it].vaddr, ph[it].memsz, ph[it].offset);
	setdata(fp, ph[id].vaddr, ph[id].filesz, ph[id].offset, ph[id].memsz - ph[id].filesz);
	if(is != -1)
		setsym(fp, ph[is].filesz, 0, ph[is].memsz, ph[is].offset);
	free(ph);
	return 1;
}
示例#24
0
文件: emu.cpp 项目: nealey/vera
//----------------------------------------------------------------------
int i5_emu(void) {

  uint32 Feature = cmd.get_canon_feature();
  flow = ((Feature & CF_STOP) == 0);

  if ( (Feature & CF_USE1) ) LoadArg(cmd.Op1);
  if ( (Feature & CF_USE2) ) LoadArg(cmd.Op2);

  if ( Feature & CF_JUMP ) QueueMark(Q_jumps,cmd.ea);


  switch ( cmd.itype )
  {
    case I5_mov:
    case I5_mvi:
    case Z80_ld:
//        if ( ! fail ) R1.doInt( R2.value() );
//        else R1.undef();
        break;
    case Z80_jp:
    case Z80_jr:                // Z80
    case Z80_ret:               // Z80
        if ( cmd.Op1.Cond != oc_not ) break;
    case I5_jmp:
        if ( cmd.Op2.type == o_phrase ) QueueMark(Q_jumps,cmd.ea);
    case I5_ret:
        flow = 0;
        break;
    case I5_rstv:
        ua_add_cref(0,toEA(codeSeg(0x40,0),0x40),fl_CN);
        break;
    case I5_rst:
        {
          int mul = (isZ80() ? 1 : 8);
          ushort offset = ushort(cmd.Op1.value * mul);
          ua_add_cref(0,toEA(codeSeg(offset,0),offset),fl_CN);
        }
    case I5_call:
    case I5_cc:
    case I5_cnc:
    case I5_cz:
    case I5_cnz:
    case I5_cpe:
    case I5_cpo:
    case I5_cp:
    case I5_cm:
    case Z80_exx:               // Z80
//        i5_CPUregs.bc.undef();
//        i5_CPUregs.de.undef();
//        i5_CPUregs.hl.undef();
//        i5_CPUregs.af.undef();
//        i5_CPUregs.ix.undef();
//        i5_CPUregs.iy.undef();
        break;
    default:
//        R1.undef();
//        R2.undef();
        break;
  }

  if ( Feature & CF_CHG1 ) SaveArg(cmd.Op1);
  if ( Feature & CF_CHG2 ) SaveArg(cmd.Op2);

  if ( flow ) ua_add_cref(0,cmd.ea+cmd.size,fl_F);

  return 1;
}
示例#25
0
static POINTS2IMAGEPtr points_to_image(sensor_msgs::PointCloud2ConstPtr velodyneData,
				       cv::Mat cameraExtrinsicMat,
				       cv::Mat cameraMat, cv::Mat distCoeff,
				       cv::Size imageSize)
{
    POINTS2IMAGEPtr result(new POINTS2IMAGE);
    result->header=velodyneData->header;
    result->height=imageSize.height;
    result->width=imageSize.width;
    POINT2IMAGE tmpdata;
    tmpdata.intensity=0;
    tmpdata.distance=0;
    result->points.resize(result->height*result->width,tmpdata);

    cv::Mat invR=cameraExtrinsicMat(cv::Rect(0,0,3,3)).t();
    cv::Mat invT=-invR*(cameraExtrinsicMat(cv::Rect(3,0,1,3)));

    int n=velodyneData->height;
    int m=velodyneData->width;
    char * data=(char *)(velodyneData->data.data());
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            int id=i*m+j;
            float * dataptr=(float *)(data+id*velodyneData->point_step);

            cv::Mat point(1,3,CV_64F);
            point.at<double>(0)=double(dataptr[0]);
            point.at<double>(1)=double(dataptr[1]);
            point.at<double>(2)=double(dataptr[2]);
            point=point*invR.t()+invT.t();

            if(point.at<double>(2)<=0)
            {
                continue;
            }

            double tmpx=point.at<double>(0)/point.at<double>(2);
            double tmpy=point.at<double>(1)/point.at<double>(2);
            double r2=tmpx*tmpx+tmpy*tmpy;
            double tmpdist=1+distCoeff.at<double>(0)*r2+distCoeff.at<double>(1)*r2*r2+distCoeff.at<double>(4)*r2*r2*r2;

            cv::Point2d imagepoint;
            imagepoint.x=tmpx*tmpdist+2*distCoeff.at<double>(2)*tmpx*tmpy+distCoeff.at<double>(3)*(r2+2*tmpx*tmpx);
            imagepoint.y=tmpy*tmpdist+distCoeff.at<double>(2)*(r2+2*tmpy*tmpy)+2*distCoeff.at<double>(3)*tmpx*tmpy;
            imagepoint.x=cameraMat.at<double>(0,0)*imagepoint.x+cameraMat.at<double>(0,2);
            imagepoint.y=cameraMat.at<double>(1,1)*imagepoint.y+cameraMat.at<double>(1,2);
            if(imagepoint.x>=0&&imagepoint.x<result->width&&imagepoint.y>=0&&imagepoint.y<result->height)
            {
                int px=int(imagepoint.x+0.5);
                int py=int(imagepoint.y+0.5);
                int pid=py*result->width+px;
                if(result->points[pid].distance==0||(result->points[pid].distance/100.0)>point.at<double>(2))
                {
                    result->points[pid].distance=ushort(point.at<double>(2)*100+0.5);
                    result->points[pid].intensity=uchar(dataptr[4]);
                }
            }
        }
    }
    return result;
}
示例#26
0
bool Foam::ping
(
    const word& destName,
    const label destPort,
    const label timeOut
)
{
    char *serverAddress;
    struct in_addr *ptr;
    struct hostent *hostPtr;
    volatile int sockfd;
    struct sockaddr_in destAddr;      // will hold the destination addr
    u_int addr;

    if ((hostPtr = gethostbyname(destName.c_str())) == NULL)
    {
        FatalErrorIn
        (
            "Foam::ping(const word&, const label)"
        )   << "gethostbyname error " << h_errno << " for host " << destName
            << abort(FatalError);
    }

    // Get first of the SLL of addresses
    serverAddress = *(hostPtr->h_addr_list);
    ptr = reinterpret_cast<struct in_addr*>(serverAddress);
    addr = ptr->s_addr;

    // Allocate socket
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0)
    {
        FatalErrorIn
        (
            "Foam::ping(const word&, const label)"
        )   << "socket error"
            << abort(FatalError);
    }

    // Fill sockaddr_in structure with dest address and port
    memset (reinterpret_cast<char *>(&destAddr), '\0', sizeof(destAddr));
    destAddr.sin_family = AF_INET;
    destAddr.sin_port = htons(ushort(destPort));
    destAddr.sin_addr.s_addr = addr;


    timer myTimer(timeOut);

    if (timedOut(myTimer))
    {
        // Setjmp from timer jumps back to here
        fdClose(sockfd);
        return false;
    }

    if
    (
        connect
        (
            sockfd,
            reinterpret_cast<struct sockaddr*>(&destAddr),
            sizeof(struct sockaddr)
        ) != 0
    )
    {
        // Connection refused. Check if network was actually used or not.

        int connectErr = errno;

        fdClose(sockfd);

        if (connectErr == ECONNREFUSED)
        {
            return true;
        }
        //perror("connect");

        return false;
    }

    fdClose(sockfd);

    return true;
}
示例#27
0
文件: uiswitch.cpp 项目: nealey/vera
//---------------------------------------------------------------------------
// The main function - called when the user selects the menu item
static bool idaapi callback(void *)
{
  // Calculate the default values to display in the form
  ea_t screen_ea = get_screen_ea();
  segment_t *s = getseg(screen_ea);
  if ( s == NULL || !isCode(get_flags_novalue(screen_ea)) )
  {
    warning("AUTOHIDE NONE\nThe cursor must be on the table jump instruction");
    return false;
  }
  ea_t startea = screen_ea;
  while ( true )
  {
    ea_t prev = prev_not_tail(startea);
    if ( !is_switch_insn(prev) )
      break;
    startea = prev;
  }
  ea_t jumps = get_first_dref_from(screen_ea);
  uval_t jelsize = s->abytes();
  uval_t jtsize = 0;
  if ( jumps != BADADDR )
  {
    decode_insn(screen_ea);
    jtsize = guess_table_size(jumps);
  }
  uval_t shift = 0;
  uval_t elbase = 0;
  char input[MAXSTR];
  input[0] = '\0';
  ea_t defea = BADADDR;
  uval_t lowcase = 0;
  ushort jflags = 0;
  ushort vflags = 0;
  ea_t vtable = BADADDR;
  ea_t vtsize = 0;
  ea_t velsize = s->abytes();
  reg_info_t ri;
  ri.size = 0;
  // If switch information is present in the database, use it for defaults
  switch_info_ex_t si;
  if ( get_switch_info_ex(screen_ea, &si, sizeof(si)) > 0 )
  {
    jumps = si.jumps;
    jtsize = si.ncases;
    startea = si.startea;
    elbase = si.elbase;
    jelsize = si.get_jtable_element_size();
    shift = si.get_shift();
    defea = (si.flags & SWI_DEFAULT) ? si.defjump : BADADDR;
    if ( si.regnum != -1 )
      get_reg_name(si.regnum, get_dtyp_size(si.regdtyp), input, sizeof(input));
    if ( si.flags & SWI_SIGNED )
      jflags |= 2;
    if ( si.flags2 & SWI2_SUBTRACT )
      jflags |= 4;
    if ( si.flags & SWI_SPARSE )
    {
      jflags |= 1;
      vtable = si.values;
      vtsize = jtsize;
      velsize = si.get_vtable_element_size();
      if ( si.flags2 & SWI2_INDIRECT )
      {
        vflags |= 1;
        jtsize = si.jcases;
      }
      if ( si.flags & SWI_JMP_INV )
        vflags |= 2;
    }
    else
    {
      lowcase = si.lowcase;
    }
  }
  // Now display the form and let the user edit the attributes
  while ( AskUsingForm_c(main_form, &jumps, &jtsize, &jelsize, &shift, &elbase,
                         &startea, input, &lowcase, &defea, &jflags) )
  {
    if ( !check_table(jumps, jelsize, jtsize) )
      continue;
    if ( shift > 3 )
    {
      warning("AUTOHIDE NONE\nInvalid shift value (allowed values are 0..3)");
      continue;
    }
    if ( !isCode(get_flags_novalue(startea)) )
    {
      warning("AUTOHIDE NONE\nInvalid switch idiom start %a (must be an instruction", startea);
      continue;
    }
    ri.reg = -1;
    if ( input[0] != '\0' && !parse_reg_name(input, &ri) )
    {
      warning("AUTOHIDE NONE\nUnknown input register: %s", input);
      continue;
    }
    if ( defea != BADADDR && !isCode(get_flags_novalue(defea)) )
    {
      warning("AUTOHIDE NONE\nInvalid default jump %a (must be an instruction", defea);
      continue;
    }
    if ( jflags & 1 ) // value table is present
    {
      bool vok = false;
      while ( AskUsingForm_c(value_form, &vflags, &vtable, &vtsize, &velsize) )
      {
        if ( (vflags & 1) == 0 )
          vtsize = jtsize;
        if ( check_table(vtable, velsize, vtsize) )
        {
          vok = true;
          break;
        }
      }
      if ( !vok )
        break;
    }
    // ok, got and validated all params -- fill the structure
    si.flags = SWI_EXTENDED;
    si.flags2 = 0;
    if ( jflags & 2 )
      si.flags |= SWI_SIGNED;
    if ( jflags & 4 )
      si.flags2 |= SWI2_SUBTRACT;
    si.jumps = jumps;
    si.ncases = ushort(jtsize);
    si.startea = startea;
    si.elbase = elbase;
    if ( elbase != 0 )
      si.flags |= SWI_ELBASE;
    si.set_jtable_element_size((int)jelsize);
    si.set_shift((int)shift);
    if ( defea != BADADDR )
    {
      si.flags |= SWI_DEFAULT;
      si.defjump = defea;
    }
    if ( ri.reg != -1 )
      si.set_expr(ri.reg, get_dtyp_by_size(ri.size));
    if ( jflags & 1 ) // value table is present
    {
      si.flags |= SWI_SPARSE;
      si.values = vtable;
      si.set_vtable_element_size((int)velsize);
      if ( (vflags & 1) != 0 )
      {
        si.flags2 |= SWI2_INDIRECT;
        si.jcases = (int)jtsize;
        si.ncases = (ushort)vtsize;
      }
      if ( (vflags & 2) != 0 )
        si.flags |= SWI_JMP_INV;
    }
    else
    {
      si.lowcase = lowcase;
    }
    // ready, store it
    set_switch_info_ex(screen_ea, &si);
    create_switch_table(screen_ea, &si);
    setFlbits(screen_ea, FF_JUMP);
    create_insn(screen_ea);
    info("AUTOHIDE REGISTRY\nSwitch information has been stored");
    break;
  }
  return true;
}
示例#28
0
static inline Char Latin1Char(char ch)
{
    return ushort(uchar(ch));
}
示例#29
0
文件: qchar.cpp 项目: phen89/rtqt
    out << quint16(chr.unicode());
    return out;
}

/*!
    \relates QChar

    Reads a char from the stream \a in into char \a chr.

    \sa {Serializing Qt Data Types}
*/
QDataStream &operator>>(QDataStream &in, QChar &chr)
{
    quint16 u;
    in >> u;
    chr.unicode() = ushort(u);
    return in;
}
#endif // QT_NO_DATASTREAM

/*!
    \fn ushort & QChar::unicode()

    Returns a reference to the numeric Unicode value of the QChar.
*/

/*!
    \fn ushort QChar::unicode() const

    \overload
*/
示例#30
0
/*
 * ELF64 binaries.
 */
static int
elf64dotout(int fd, Fhdr *fp, ExecHdr *hp)
{
	E64hdr *ep;
	P64hdr *ph;
	ushort (*swab)(ushort);
	ulong (*swal)(ulong);
	uvlong (*swav)(uvlong);
	int i, it, id, is, phsz;
	uvlong uvl;

	ep = &hp->e;
	if(ep->ident[DATA] == ELFDATA2LSB) {
		swab = leswab;
		swal = leswal;
		swav = leswav;
	} else if(ep->ident[DATA] == ELFDATA2MSB) {
		swab = beswab;
		swal = beswal;
		swav = beswav;
	} else {
		werrstr("bad ELF64 encoding - not big or little endian");
		return 0;
	}

	ep->type = swab(ep->type);
	ep->machine = swab(ep->machine);
	ep->version = swal(ep->version);
	if(ep->type != EXEC || ep->version != CURRENT)
		return 0;
	ep->elfentry = swav(ep->elfentry);
	ep->phoff = swav(ep->phoff);
	ep->shoff = swav(ep->shoff);
	ep->flags = swal(ep->flags);
	ep->ehsize = swab(ep->ehsize);
	ep->phentsize = swab(ep->phentsize);
	ep->phnum = swab(ep->phnum);
	ep->shentsize = swab(ep->shentsize);
	ep->shnum = swab(ep->shnum);
	ep->shstrndx = swab(ep->shstrndx);

	fp->magic = ELF_MAG;
	fp->hdrsz = (ep->ehsize+ep->phnum*ep->phentsize+16)&~15;
	switch(ep->machine) {
	default:
		return 0;
	case AMD64:
		mach = &mamd64;
		fp->type = FAMD64;
		fp->name = "amd64 ELF64 executable";
		break;
	case POWER64:
		mach = &mpower64;
		fp->type = FPOWER64;
		fp->name = "power64 ELF64 executable";
		break;
	}

	if(ep->phentsize != sizeof(P64hdr)) {
		werrstr("bad ELF64 header size");
		return 0;
	}
	phsz = sizeof(P64hdr)*ep->phnum;
	ph = malloc(phsz);
	if(!ph)
		return 0;
	seek(fd, ep->phoff, 0);
	if(read(fd, ph, phsz) < 0) {
		free(ph);
		return 0;
	}
	for(i = 0; i < ep->phnum; i++) {
		ph[i].type = swal(ph[i].type);
		ph[i].flags = swal(ph[i].flags);
		ph[i].offset = swav(ph[i].offset);
		ph[i].vaddr = swav(ph[i].vaddr);
		ph[i].paddr = swav(ph[i].paddr);
		ph[i].filesz = swav(ph[i].filesz);
		ph[i].memsz = swav(ph[i].memsz);
		ph[i].align = swav(ph[i].align);
	}

	/* find text, data and symbols and install them */
	it = id = is = -1;
	for(i = 0; i < ep->phnum; i++) {
		if(ph[i].type == LOAD
		&& (ph[i].flags & (R|X)) == (R|X) && it == -1)
			it = i;
		else if(ph[i].type == LOAD
		&& (ph[i].flags & (R|W)) == (R|W) && id == -1)
			id = i;
		else if(ph[i].type == NOPTYPE && is == -1)
			is = i;
	}
	if(it == -1 || id == -1) {
		werrstr("No ELF64 TEXT or DATA sections");
		free(ph);
		return 0;
	}

	settext(fp, ep->elfentry, ph[it].vaddr, ph[it].memsz, ph[it].offset);
	/* 8c: out of fixed registers */
	uvl = ph[id].memsz - ph[id].filesz;
	setdata(fp, ph[id].vaddr, ph[id].filesz, ph[id].offset, uvl);
	if(is != -1)
		setsym(fp, ph[is].filesz, 0, ph[is].memsz, ph[is].offset);
	free(ph);
	return 1;
}