static void MichaelAppend( struct michel_mic_t *Mic, uint8_t *src, int nBytes ) { int addlen ; if (Mic->nBytesInM) { addlen = 4 - Mic->nBytesInM; if (addlen > nBytes) addlen = nBytes; memcpy(&Mic->M[Mic->nBytesInM], src, addlen); Mic->nBytesInM += addlen; src += addlen; nBytes -= addlen; if (Mic->nBytesInM < 4) return; Mic->L ^= getUInt32(Mic->M,0); MichaelBlockFunction(Mic->L, Mic->R); Mic->nBytesInM = 0; } while(nBytes >= 4){ Mic->L ^= getUInt32(src,0); MichaelBlockFunction(Mic->L, Mic->R); src += 4; nBytes -= 4; } if (nBytes > 0) { Mic->nBytesInM = nBytes; memcpy(Mic->M, src, nBytes); } }
UInt32List* MtpDataPacket::getAUInt32() { UInt32List* result = new UInt32List; int count = getUInt32(); for (int i = 0; i < count; i++) result->push_back(getUInt32()); return result; }
static void MichaelInitializeFunction( struct michel_mic_t *Mic, uint8_t *key ) { // Set the key Mic->K0 = getUInt32( key , 0 ); Mic->K1 = getUInt32( key , 4 ); //clear(); MichaelClear(Mic); }
UInt32List* MtpDataPacket::getAUInt32() { uint32_t count; if (!getUInt32(count)) return NULL; UInt32List* result = new UInt32List; for (uint32_t i = 0; i < count; i++) { uint32_t value; if (!getUInt32(value)) { delete result; return NULL; } result->push(value); } return result; }
uint32_t MtpPacket::getParameter(int index) const { if (index < 1 || index > 5) { ALOGE("index %d out of range in MtpPacket::getParameter", index); return 0; } return getUInt32(MTP_CONTAINER_PARAMETER_OFFSET + (index - 1) * sizeof(uint32_t)); }
document_attachment_ptr Document::getAttachment(const char* name, bool includeBody) { document_attachment_ptr attachment; auto attachmentsObj = obj_->getObject("_attachments", false); if (!!attachmentsObj) { auto attachmentObj = attachmentsObj->getObject(name, false); if (!!attachmentObj) { auto contentType = attachmentObj->getString("content_type"); auto digest = attachmentObj->getString("digest"); if (includeBody) { auto encodedData = attachmentObj->getString("data"); auto encodedDataSize = attachmentObj->getStringLength("data"); auto data = Base64Helper::Decode(encodedData, encodedDataSize); attachment = DocumentAttachment::Create(name, contentType, digest, std::move(data)); } else { int lengthIndex = -1; auto size = attachmentObj->getType("length", lengthIndex) == rs::scriptobject::ScriptObjectType::UInt32 ? attachmentObj->getUInt32(lengthIndex) : attachmentObj->getUInt64(lengthIndex); attachment = DocumentAttachment::Create(name, contentType, digest, Base64Helper::buffer_type{}, size); } } } return attachment; }
Int8List* MtpDataPacket::getAInt8() { Int8List* result = new Int8List; int count = getUInt32(); for (int i = 0; i < count; i++) result->push(getInt8()); return result; }
uint16_t JSValue::toUInt16(ExecState *exec) const { uint32_t i; if (getUInt32(i)) return static_cast<uint16_t>(i); return KJS::toUInt16(const_cast<JSValue*>(this)->toNumber(exec)); }
/** Return value as unsigned integer, depending on length. */ unsigned getUInt() { switch(mLength) { case sizeof(uint8_t): return getUInt8(); break; case sizeof(uint16_t): return getUInt16(); break; case sizeof(uint32_t): default: return getUInt32(); break; } return 0; }
/*------------------------------------------------------*/ int getAndMoveToFrontDecode(unsigned limit) { char yy[256]; int32_t i, tmpOrigPtr; tmpOrigPtr = getUInt32(); origPtr = (tmpOrigPtr < 0 ? -tmpOrigPtr : tmpOrigPtr) - 1; initModels(); for (i = 0; i < 256; i++) yy[i] = i; for (block_end = 0; ; block_end++) { unsigned nextSym; nextSym = getSymbol(&models[MODEL_BASIS]); if (nextSym == VAL_RUNA || nextSym == VAL_RUNB) { /* Acquire run-length bits, most significant first */ unsigned n; n = 0; do { n <<= 1; n++; if (nextSym == VAL_RUNA) n++; nextSym = getSymbol(&models[MODEL_BASIS]); } while (nextSym == VAL_RUNA || nextSym == VAL_RUNB); if (block_end + n > limit) invalid_input("file corrupt"); memset(&ll[block_end], yy[0], n); block_end += n; } /* if */ if (nextSym == VAL_EOB) break; nextSym = getMTFVal(nextSym); assert(INRANGE(nextSym, 1, 255)); if (block_end >= limit) invalid_input("file corrupt"); ll[block_end] = yy[nextSym]; memmove(&yy[1], &yy[0], nextSym); yy[0] = ll[block_end]; } /* for */ return tmpOrigPtr < 0; } /* getAndMoveToFrontDecode */
void shuffle(RandomAccessIterator first, RandomAccessIterator last) { UInt n = last - first; while (first != last) { // Pick a random position between the current and the end to swap the // current element with. UInt i = getUInt32(n); std::swap(*first, *(first + i)); // Move to the next element and decrement the number of possible // positions remaining. first++; n--; } }
void sample(T population[], UInt32 nPopulation, T choices[], UInt32 nChoices) { if (nChoices == 0) { return; } if (nChoices > nPopulation) { NTA_THROW << "population size must be greater than number of choices"; } UInt32 nextChoice = 0; for (UInt32 i = 0; i < nPopulation; ++i) { if (getUInt32(nPopulation - i) < (nChoices - nextChoice)) { choices[nextChoice] = population[i]; ++nextChoice; if (nextChoice == nChoices) { break; } } } }
MtpTransactionID MtpPacket::getTransactionID() const { return getUInt32(MTP_CONTAINER_TRANSACTION_ID_OFFSET); }
void MtpDataPacket::getUInt128(uint128_t& value) { value[0] = getUInt32(); value[1] = getUInt32(); value[2] = getUInt32(); value[3] = getUInt32(); }
// for STL compatibility UInt32 operator()(UInt32 n = MAX32) { return getUInt32(n); }
int Hdf::compare(uint32_t v2) const { uint32_t v1 = getUInt32(); if (v1 == v2) return 0; return v1 > v2 ? 1 : -1; }
void qipinfium::loadMessages(const QString &path) { QDir dir = path; if(!dir.cd("History")) return; QHash<QString,QString> protocols; protocols[QLatin1String("icq")] = QLatin1String("ICQ"); protocols[QLatin1String("jabber")] = QLatin1String("Jabber"); protocols[QLatin1String("mra")] = QLatin1String("MRIM"); QStringList filters; foreach(QString format,protocols.keys()) filters << (format + QLatin1String("*.qhf")) << (format + QLatin1String("*.ahf")); QFileInfoList files = dir.entryInfoList(filters, QDir::Files); setMaxValue(files.size()); for(int i = 0; i < files.size(); i++) { setValue(i + 1); QString protocol = files[i].fileName().section("_",0,0); while(!protocol.isEmpty() && protocol.at(protocol.length() - 1).isDigit()) protocol.chop(1); protocol = protocols[protocol.toLower()]; if(protocol.isEmpty()) { warning() << "Unknown protocol: " << files[i].fileName(); continue; } setProtocol(protocol); setAccount(m_accounts.value(protocol)); QFile file(files[i].absoluteFilePath()); if(file.open(QFile::ReadOnly)) { QByteArray bytearray = file.readAll(); const uchar *data = (const uchar *)bytearray.constData(); const uchar *end = data + bytearray.size(); if(memcmp(data, "QHF", 3)) continue; uchar version = data[3]; data += 44; QString uin = getString(data, getUInt16(data)); QString name = getString(data, getUInt16(data)); Q_UNUSED(name); QDateTime time; setContact(uin); while(data < end) { quint16 type = getUInt16(data); quint32 index = getUInt32(data); data += 2; if(type == 1) { Message message; data += 10; time = QDateTime::fromTime_t(getUInt32(data)); time.setTimeSpec(Qt::LocalTime); if(version == 1) time = time.toUTC().addDays(2); else time = time.toUTC(); message.setTime(time); data += 4; message.setIncoming(getUInt8(data) == 0); data += 4; int mes_len = version == 3 ? getUInt32(data) : getUInt16(data); message.setText(getString(data, mes_len, version > 1)); appendMessage(message); } else data += index; } } } }
bool MtpDataPacket::getUInt128(uint128_t& value) { return getUInt32(value[0]) && getUInt32(value[1]) && getUInt32(value[2]) && getUInt32(value[3]); }