DWORD COMPSTREXTRA::Store(const LogCompStrExtra *log) { FOOTMARK(); assert(this); assert(log); BYTE *pb = GetBytes(); dwSignature = 0xDEADFACE; iClause = log->iClause; pb += sizeof(COMPSTREXTRA); DWORD size; dwHiraganaClauseOffset = (DWORD)(pb - GetBytes()); dwHiraganaClauseCount = 0; for (size_t i = 0; i < log->hiragana_clauses.size(); ++i) { size = (log->hiragana_clauses[i].size() + 1) * sizeof(WCHAR); memcpy(pb, &log->hiragana_clauses[i][0], size); ++dwHiraganaClauseCount; pb += size; } dwTypingClauseOffset = (DWORD)(pb - GetBytes()); dwTypingClauseCount = 0; for (size_t i = 0; i < log->typing_clauses.size(); ++i) { size = (log->typing_clauses[i].size() + 1) * sizeof(WCHAR); memcpy(pb, &log->typing_clauses[i][0], size); ++dwTypingClauseCount; pb += size; } assert(log->GetTotalSize() == (DWORD)(pb - GetBytes())); return (DWORD)(pb - GetBytes()); } // COMPSTREXTRA::Store
/// start : 0 ~ GetBytes()-1 std::string AsString(size_t start, size_t length)const { BOOST_ASSERT(start < GetBytes()); BOOST_ASSERT(start + length <= GetBytes()); return std::string(ptr_ + start, length); }
/** * Fetch (and sign extend, if necessary) a 8/16/32 bit value from the code * stream and advance the instruction pointer accordingly. */ static int32 Fetch(byte opcode, const byte *code, const WorkaroundEntry* &wkEntry, int &ip) { if (TinselV0) // Fetch a 32 bit value. return GetBytes(code, wkEntry, ip, 4); else if (opcode & OPSIZE8) // Fetch and sign extend a 8 bit value to 32 bits. return GetBytes(code, wkEntry, ip, 1); else if (opcode & OPSIZE16) return GetBytes(code, wkEntry, ip, 2); return GetBytes(code, wkEntry, ip, 4); }
Message *GetMdsMsg(int id, int *status) { MsgHdr header; Message *msg = 0; int msglen = 0; //MdsSetClientAddr(0); *status = 0; *status = GetBytes(id, (void *)&header, sizeof(MsgHdr)); if (*status &1){ if ( Endian(header.client_type) != Endian(ClientType()) ) FlipHeader(&header); #ifdef DEBUG printf("msglen = %d\nstatus = %d\nlength = %d\nnargs = %d\ndescriptor_idx = %d\nmessage_id = %d\ndtype = %d\n", header.msglen,header.status,header.length,header.nargs,header.descriptor_idx,header.message_id,header.dtype); printf("client_type = %d\nndims = %d\n",header.client_type,header.ndims); #endif if (CType(header.client_type) > CRAY_CLIENT || header.ndims > MAX_DIMS) { DisconnectConnection(id); fprintf(stderr,"\rGetMdsMsg shutdown connection %d: bad msg header, header.ndims=%d, client_type=%d\n",id,header.ndims,CType(header.client_type)); *status = 0; return 0; } msglen = header.msglen; msg = malloc(header.msglen); msg->h = header; *status = GetBytes(id, msg->bytes, msglen - sizeof(MsgHdr)); if (*status & 1 && IsCompressed(header.client_type)) { Message *m; unsigned long dlen; memcpy(&msglen, msg->bytes, 4); if (Endian(header.client_type) != Endian(ClientType())) FlipBytes(4,(char *)&msglen); m = malloc(msglen); m->h = header; dlen = msglen - sizeof(MsgHdr); *status = uncompress(m->bytes, &dlen, msg->bytes + 4, header.msglen - sizeof(MsgHdr) - 4) == 0; if (*status & 1) { m->h.msglen = msglen; free(msg); msg = m; } else free(m); } if (*status & 1 && (Endian(header.client_type) != Endian(ClientType()))) FlipData(msg); } return msg; }
void UUID::Dump (Stream *s) const { const uint8_t *u = (const uint8_t *)GetBytes(); s->Printf ("%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7],u[8],u[9],u[10],u[11],u[12],u[13],u[14],u[15]); }
std::string UUID::GetAsString (const char *separator) const { std::string result; char buf[256]; if (!separator) separator = "-"; const uint8_t *u = (const uint8_t *)GetBytes(); if (sizeof (buf) > (size_t)snprintf (buf, sizeof (buf), "%2.2X%2.2X%2.2X%2.2X%s%2.2X%2.2X%s%2.2X%2.2X%s%2.2X%2.2X%s%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", u[0],u[1],u[2],u[3],separator, u[4],u[5],separator, u[6],u[7],separator, u[8],u[9],separator, u[10],u[11],u[12],u[13],u[14],u[15])) { result.append (buf); if (m_num_uuid_bytes == 20) { if (sizeof (buf) > (size_t)snprintf (buf, sizeof (buf), "%s%2.2X%2.2X%2.2X%2.2X", separator,u[16],u[17],u[18],u[19])) result.append (buf); } } return result; }
std::vector<byte> CSP::GetBytes(size_t Length) { std::vector<byte> data(Length); GetBytes(data); return data; }
HRESULT CBPersistMgr::Transfer(const char* Name, AnsiStringArray& Val) { size_t size; if (m_Saving) { size = Val.size(); PutBytes((BYTE*)&size, sizeof(size_t)); for (AnsiStringArray::iterator it = Val.begin(); it != Val.end(); ++it) { PutString((*it).c_str()); } } else { Val.clear(); GetBytes((BYTE*)&size, sizeof(size_t)); for (size_t i = 0; i < size; i++) { char* str = GetString(); if (str) Val.push_back(str); } } return S_OK; }
WCHAR *COMPSTREXTRA::GetTypingClauses(DWORD& dwCount) { FOOTMARK(); dwCount = dwTypingClauseCount; if (dwCount) { return (WCHAR *)(GetBytes() + dwTypingClauseOffset); } return NULL; }
char * UUID::GetAsCString (char *dst, size_t dst_len) const { const uint8_t *u = (const uint8_t *)GetBytes(); snprintf(dst, dst_len, "%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7],u[8],u[9],u[10],u[11],u[12],u[13],u[14],u[15]); return dst; }
// Settings for this kernel (general) static TunerSettings GetTunerSettings(const Arguments<T> &args) { auto settings = TunerSettings(); // Identification of the kernel settings.kernel_family = (V==1) ? "xgemv" : ((V==2) ? "xgemv_fast" : "xgemv_fast_rot"); settings.kernel_name = (V==1) ? "Xgemv" : ((V==2) ? "XgemvFast" : "XgemvFastRot"); settings.sources = #include "../src/kernels/common.opencl" #include "../src/kernels/level2/xgemv.opencl" #include "../src/kernels/level2/xgemv_fast.opencl" ; // Buffer sizes settings.size_x = args.n; settings.size_y = args.m; settings.size_a = args.m * args.n; // Sets the base thread configuration settings.global_size = {args.m}; settings.global_size_ref = settings.global_size; settings.local_size = {1}; settings.local_size_ref = {64}; // Transforms the thread configuration based on the parameters settings.mul_local = {{"WGS"+std::to_string(V)}}; settings.div_global = (V==1 || V==2) ? TunerSettings::TransformVector{{"WPT"+std::to_string(V)}} : TunerSettings::TransformVector{}; // Sets the tuning parameters and their possible values if (V==1) { settings.parameters = { {"WGS"+std::to_string(V), {32, 64, 128, 256}}, {"WPT"+std::to_string(V), {1, 2, 4}}, }; } if (V==2) { settings.parameters = { {"WGS"+std::to_string(V), {16, 32, 64, 128, 256}}, {"WPT"+std::to_string(V), {1, 2, 4}}, {"VW"+std::to_string(V), {1, 2, 4, 8}}, }; } if (V==3) { settings.parameters = { {"WGS"+std::to_string(V), {16, 32, 64, 128}}, {"WPT"+std::to_string(V), {1, 2, 4, 8, 16, 32}}, {"VW"+std::to_string(V), {1, 2, 4, 8}}, }; } // Describes how to compute the performance metrics settings.metric_amount = (args.m*args.n + 2*args.m + args.n) * GetBytes(args.precision); settings.performance_unit = "GB/s"; return settings; }
ECode UriCodec::Decode( /* [in] */ const String& s, /* [in] */ Boolean convertPlus, /* [in] */ ICharset* charset, /* [in] */ Boolean throwOnFailure, /* [out] */ String* decodedString) { VALIDATE_NOT_NULL(decodedString); if (s.IndexOf('%') == -1 && (!convertPlus || s.IndexOf('+') == -1)) { *decodedString = s; return NOERROR; } StringBuilder result(s.GetByteLength()); AutoPtr<IByteArrayOutputStream> out; CByteArrayOutputStream::New((IByteArrayOutputStream**)&out); IOutputStream* os = IOutputStream::Probe(out); AutoPtr<ArrayOf<Char32> > char32Array = s.GetChars(); for (Int32 i = 0; i < s.GetLength();) { Char32 c = (*char32Array)[i]; if (c == '%') { do { Int32 d1, d2; if (i + 2 < s.GetLength() && (d1 = HexToInt((*char32Array)[i + 1])) != -1 && (d2 = HexToInt((*char32Array)[i + 2])) != -1) { os->Write((Byte) ((d1 << 4) + d2)); } else if (throwOnFailure) { return E_ILLEGAL_ARGUMENT_EXCEPTION; } else { // TODO: unicode escape const char* chars = "\ufffd"; AutoPtr<ArrayOf<Byte> > replacement = GetBytes(chars, charset); os->Write(replacement, 0, replacement->GetLength()); } i += 3; } while (i < s.GetLength() && (*char32Array)[i] == '%'); AutoPtr<ArrayOf<Byte> > bytes; out->ToByteArray((ArrayOf<Byte>**)&bytes); //result.append(new String(out.toByteArray(), charset); result.Append(String((char*)bytes->GetPayload())); out->Reset(); } else { if (convertPlus && c == '+') { c = ' '; } result.AppendChar(c); i++; } } *decodedString = result.ToString(); return NOERROR; }
void CSP::GetBytes(std::vector<byte> &Output, size_t Offset, size_t Length) { if (Offset + Length > Output.size()) throw CryptoRandomException("CSP:GetBytes", "The array is too small to fulfill this request!"); std::vector<byte> rnd(Length); GetBytes(rnd); memcpy(&Output[Offset], &rnd[0], rnd.size()); }
bool CGXStandardObisCodeCollection::Find(basic_string<char> ln, OBJECT_TYPE objectType, CGXStandardObisCode& item) { unsigned char bytes[6]; if (GetBytes(ln, bytes) != ERROR_CODES_OK) { return NULL; } return Find(bytes, objectType, item); }
int c4_Handler::Compare(int index_, const c4_Bytes &buf_) { // create a copy for small data, since ints use a common _item buffer c4_Bytes copy(buf_.Contents(), buf_.Size(), buf_.Size() <= 8); c4_Bytes data; GetBytes(index_, data); return f4_CompareFormat(Property().Type(), data, copy); }
bool CGXStandardObisCodeCollection::EqualsMask(basic_string<char> obisMask, basic_string<char> ln) { unsigned char bytes[6]; if (GetBytes(ln, bytes) != ERROR_CODES_OK) { return NULL; } vector< basic_string<char> > tmp = GXHelpers::Split(obisMask, '.'); return EqualsObisCode(tmp, bytes); }
static void SetLocalMemorySize(cltune::Tuner &tuner, const size_t id, const Arguments<T> &args) { if (V==1 || V==2) { auto LocalMemorySize = [args] (std::vector<size_t> v) { return v[0]*GetBytes(args.precision); }; tuner.SetLocalMemoryUsage(id, LocalMemorySize, {"WGS"+std::to_string(V)}); } else { auto LocalMemorySize = [args] (std::vector<size_t> v) { return (v[0]*v[1] + v[1])*GetBytes(args.precision); }; tuner.SetLocalMemoryUsage(id, LocalMemorySize, {"WGS"+std::to_string(V), "WPT"+std::to_string(V)}); } }
uint CSP::Next() { uint rndNum = 0; size_t len = sizeof(rndNum); std::vector<byte> rnd(len); GetBytes(rnd); memcpy(&rndNum, &rnd[0], len); return rndNum; }
// extension COMPSTREXTRA *CompStr::GetExtra() { if (dwPrivateSize > sizeof(COMPSTREXTRA)) { BYTE *pb = GetBytes(); pb += dwPrivateOffset; COMPSTREXTRA *pExtra = (COMPSTREXTRA *)pb; if (pExtra->dwSignature == 0xDEADFACE) { return pExtra; } } return NULL; }
void UUID::Dump (Stream *s) const { const uint8_t *u = (const uint8_t *)GetBytes(); s->Printf ("%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7],u[8],u[9],u[10],u[11],u[12],u[13],u[14],u[15]); if (m_num_uuid_bytes == 20) { s->Printf ("-%2.2X%2.2X%2.2X%2.2X", u[16],u[17],u[18],u[19]); } }
bool TriAcePS1Seq::GetTrackPointers(void) { VGMHeader *TrkInfoHeader = header->AddHeader(dwOffset + 0x16, 6 * 32, L"Track Info Blocks"); GetBytes(dwOffset + 0x16, 6 * 32, &TrkInfos); for (int i = 0; i < 32; i++) if (TrkInfos[i].trkOffset != 0) { aTracks.push_back(new TriAcePS1Track(this, TrkInfos[i].trkOffset, 0)); VGMHeader *TrkInfoBlock = TrkInfoHeader->AddHeader(dwOffset + 0x16 + 6 * i, 6, L"Track Info"); } return true; }
ECode UriCodec::AppendHex( /* [in] */ IStringBuilder * builder, /* [in] */ const String& s, /* [in] */ ICharset* charset) { AutoPtr<ArrayOf<Byte> > bytes; bytes = GetBytes(s.string(), charset); assert(bytes != NULL); for (Int32 i = 0; i < bytes->GetLength(); ++i) { AppendHex(builder, (*bytes)[i]); } return NOERROR; }
void c4_Handler::Move(int from_, int to_) { if (from_ != to_) { c4_Bytes data; GetBytes(from_, data); Remove(from_, 1); if (to_ > from_) { --to_; } Insert(to_, data, 1); } }
UUID UUID::RandomUUID() { auto secureRandom = Crypto::CreateSecureRandomBytesImplementation(); assert(secureRandom); unsigned char randomBytes[UUID_BINARY_SIZE]; memset(randomBytes, 0, UUID_BINARY_SIZE); secureRandom->GetBytes(randomBytes, UUID_BINARY_SIZE); //Set version bits to 0100 //https://tools.ietf.org/html/rfc4122#section-4.1.3 randomBytes[VERSION_LOCATION] = (randomBytes[VERSION_LOCATION] & VERSION_MASK) | VERSION; //set variant bits to 10 //https://tools.ietf.org/html/rfc4122#section-4.1.1 randomBytes[VARIANT_LOCATION] = (randomBytes[VARIANT_LOCATION] & VARIANT_MASK) | VARIANT; return UUID(randomBytes); }
ReturnCode ES::ImportTitleInit(Context& context, const std::vector<u8>& tmd_bytes, const std::vector<u8>& cert_chain) { INFO_LOG(IOS_ES, "ImportTitleInit"); ResetTitleImportContext(&context, m_ios.GetIOSC()); context.title_import_export.tmd.SetBytes(tmd_bytes); if (!context.title_import_export.tmd.IsValid()) { ERROR_LOG(IOS_ES, "Invalid TMD while adding title (size = %zd)", tmd_bytes.size()); return ES_EINVAL; } // Finish a previous import (if it exists). FinishStaleImport(context.title_import_export.tmd.GetTitleId()); ReturnCode ret = VerifyContainer(VerifyContainerType::TMD, VerifyMode::UpdateCertStore, context.title_import_export.tmd, cert_chain); if (ret != IPC_SUCCESS) return ret; const auto ticket = FindSignedTicket(context.title_import_export.tmd.GetTitleId()); if (!ticket.IsValid()) return ES_NO_TICKET; std::vector<u8> cert_store; ret = ReadCertStore(&cert_store); if (ret != IPC_SUCCESS) return ret; ret = VerifyContainer(VerifyContainerType::Ticket, VerifyMode::DoNotUpdateCertStore, ticket, cert_store); if (ret != IPC_SUCCESS) return ret; ret = InitTitleImportKey(ticket.GetBytes(), m_ios.GetIOSC(), &context.title_import_export.key_handle); if (ret != IPC_SUCCESS) return ret; if (!InitImport(context.title_import_export.tmd)) return ES_EIO; context.title_import_export.valid = true; return IPC_SUCCESS; }
bool Buffer::ReadTo(Buffer& other, size_t length) { other.EnsureWritableSize(length); if ((m_curOff + length) > m_bytes->size()) { return false; } auto bytes = GetBytes(); auto otherBytes = other.GetBytes(); memcpy(&(*otherBytes)[other.GetCurOffset()], &(*bytes)[GetCurOffset()], length); m_curOff += length; other.m_curOff += length; // ugly :( return true; }
vector<achar> Generator::GetCharactors(astring textPath) { std::vector<achar> charactors; auto bytes = GetBytes(textPath); auto chars = ToUtf16(bytes.data(), bytes.size()); std::set<achar> charactorSet; for (auto& c : chars) { charactorSet.insert(c); } std::vector<achar> charactorVector; for (auto& c : charactorSet) { charactorVector.push_back(c); } return charactorVector; }
byte *BitConverter::GetBytes(double value) { if (SwappedWordsInDouble()) { byte *data = new byte[8]; byte *p = (byte*)&value; data[0] = p[4]; data[1] = p[5]; data[2] = p[6]; data[3] = p[7]; data[4] = p[0]; data[5] = p[1]; data[6] = p[2]; data[7] = p[3]; return data; } else { return GetBytes((byte *) &value, 8); } }
/* Shoutouts * To * Marc3842h * for * the * way * better * sigscan */ uintptr_t CSignature::dwFindPattern(uintptr_t dwAddress, uintptr_t dwLength, const char *szPattern) { const char *pattern = szPattern; uintptr_t firstMatch = 0; uintptr_t start = dwAddress; uintptr_t end = dwLength; for (uintptr_t pos = start; pos < end; pos++) { if (*pattern == 0) return firstMatch; const uint8_t currentPattern = *reinterpret_cast<const uint8_t *>(pattern); const uint8_t currentMemory = *reinterpret_cast<const uint8_t *>(pos); if (currentPattern == '\?' || currentMemory == GetBytes(pattern)) { if (firstMatch == 0) firstMatch = pos; if (pattern[2] == 0) { logging::Info("Found pattern \"%s\" at 0x%08X.", szPattern, firstMatch); return firstMatch; } pattern += currentPattern != '\?' ? 3 : 2; } else { pattern = szPattern; firstMatch = 0; } } logging::Info("THIS IS SERIOUS: Could not locate signature: " "\n============\n\"%s\"\n============", szPattern); return 0; }
ReturnCode ES::DeleteTicket(const u8* ticket_view) { const auto fs = m_ios.GetFS(); const u64 title_id = Common::swap64(ticket_view + offsetof(IOS::ES::TicketView, title_id)); if (!CanDeleteTitle(title_id)) return ES_EINVAL; auto ticket = FindSignedTicket(title_id); if (!ticket.IsValid()) return FS_ENOENT; const u64 ticket_id = Common::swap64(ticket_view + offsetof(IOS::ES::TicketView, ticket_id)); ticket.DeleteTicket(ticket_id); const std::vector<u8>& new_ticket = ticket.GetBytes(); const std::string ticket_path = Common::GetTicketFileName(title_id); if (!new_ticket.empty()) { const auto file = fs->OpenFile(PID_KERNEL, PID_KERNEL, ticket_path, FS::Mode::ReadWrite); if (!file || !file->Write(new_ticket.data(), new_ticket.size())) return ES_EIO; } else { // Delete the ticket file if it is now empty. fs->Delete(PID_KERNEL, PID_KERNEL, ticket_path); } // Delete the ticket directory if it is now empty. const std::string ticket_parent_dir = StringFromFormat("/ticket/%08x", static_cast<u32>(title_id >> 32)); const auto ticket_parent_dir_entries = fs->ReadDirectory(PID_KERNEL, PID_KERNEL, ticket_parent_dir); if (ticket_parent_dir_entries && ticket_parent_dir_entries->empty()) fs->Delete(PID_KERNEL, PID_KERNEL, ticket_parent_dir); return IPC_SUCCESS; }