Symbian platform (C++)
SDK native APIs, runtime and tooling
Loading...
Searching...
No Matches
bytes.h
Go to the documentation of this file.
1#ifndef SYMBIAN_ANALYSIS_BYTES_H_
2#define SYMBIAN_ANALYSIS_BYTES_H_
3
4#include <cstddef>
5#include <cstdint>
6#include <string>
7#include <string_view>
8
10
11// Callers must bound the range before reading or writing.
12inline uint16_t Read16(std::string_view bytes, size_t offset) {
13 return static_cast<uint16_t>(static_cast<uint8_t>(bytes[offset])) |
14 static_cast<uint16_t>(static_cast<uint8_t>(bytes[offset + 1]) << 8);
15}
16
17inline uint32_t Read32(std::string_view bytes, size_t offset) {
18 uint32_t value = 0;
19 for (size_t i = 0; i < 4; ++i) {
20 value |= static_cast<uint32_t>(static_cast<uint8_t>(bytes[offset + i]))
21 << (i * 8);
22 }
23 return value;
24}
25
26inline void Put16(std::string& bytes, size_t offset, uint16_t value) {
27 bytes[offset] = static_cast<char>(value & 0xff);
28 bytes[offset + 1] = static_cast<char>(value >> 8);
29}
30
31inline void Put32(std::string& bytes, size_t offset, uint32_t value) {
32 for (size_t i = 0; i < 4; ++i) {
33 bytes[offset + i] = static_cast<char>((value >> (i * 8)) & 0xff);
34 }
35}
36
37inline bool Within(uint64_t size, uint64_t offset, uint64_t length) {
38 return offset <= size && length <= size - offset;
39}
40
41} // namespace symbian::analysis::internal
42
43#endif // SYMBIAN_ANALYSIS_BYTES_H_
Definition bytes.h:9
void Put16(std::string &bytes, size_t offset, uint16_t value)
Definition bytes.h:26
bool Within(uint64_t size, uint64_t offset, uint64_t length)
Definition bytes.h:37
void Put32(std::string &bytes, size_t offset, uint32_t value)
Definition bytes.h:31
uint16_t Read16(std::string_view bytes, size_t offset)
Definition bytes.h:12
uint32_t Read32(std::string_view bytes, size_t offset)
Definition bytes.h:17
uint32_t offset
Definition exports.cc:70
uint32_t size
Definition exports.cc:71
std::string_view bytes
Definition exports.cc:74
libusb_context * value
Definition usb.cc:35