BufData
Description
Pointer to the contiguous byte storage backing b. Read-only at the macro level; the bytes themselves are mutable through this pointer. Invalidated by any growth (BufReserve, BufResize, BufPushByte, BufPushBytes).
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Io.c:1129:
ok = false;
} else if (StrLen(&tmp)) {
MemCopy(BufData(out) + offset, StrBegin(&tmp), StrLen(&tmp));
}
}- In
MachoCache.c:137:
const MachoSection *str_sec = MachoFindSection(&e->dsym, "__DWARF", "__debug_str");
const u8 *info_b = info_sec ? BufData(&e->dsym.data) + info_sec->offset : NULL;
u64 info_n = info_sec ? info_sec->size : 0;
const u8 *abbrev_b = abbrev_sec ? BufData(&e->dsym.data) + abbrev_sec->offset : NULL;- In
MachoCache.c:139:
const u8 *info_b = info_sec ? BufData(&e->dsym.data) + info_sec->offset : NULL;
u64 info_n = info_sec ? info_sec->size : 0;
const u8 *abbrev_b = abbrev_sec ? BufData(&e->dsym.data) + abbrev_sec->offset : NULL;
u64 abbrev_n = abbrev_sec ? abbrev_sec->size : 0;
const u8 *str_b = str_sec ? BufData(&e->dsym.data) + str_sec->offset : NULL;- In
MachoCache.c:141:
const u8 *abbrev_b = abbrev_sec ? BufData(&e->dsym.data) + abbrev_sec->offset : NULL;
u64 abbrev_n = abbrev_sec ? abbrev_sec->size : 0;
const u8 *str_b = str_sec ? BufData(&e->dsym.data) + str_sec->offset : NULL;
u64 str_n = str_sec ? str_sec->size : 0;- In
MachO.c:354:
return false;
}
const u8 *str_base = BufData(&ctx->out->data) + ctx->stroff;
BufIter tab = BufIterFromBuf(&ctx->out->data);
IterMustMove(&tab, ctx->symoff);- In
Elf.c:100:
// read past the strtab. Scan forward; if no NUL is found inside
// [idx, strtab_size), return an empty string.
Zstr base = (Zstr)(BufData(&self->data) + strtab_offset);
for (u64 p = idx; p < strtab_size; ++p) {
if (base[p] == '\0') {- In
Elf.c:131:
}
const u8 *id = BufData(&self->data);
if (id[EI_MAG0] != ELF_MAG0 || id[EI_MAG1] != ELF_MAG1 || id[EI_MAG2] != ELF_MAG2 || id[EI_MAG3] != ELF_MAG3) {
LOG_ERROR("Elf: bad magic");- In
Elf.c:359:
return;
}
const u8 *p = BufData(&self->data) + note->offset;
const u8 *end = p + note->size;
if ((u64)(end - p) < 12)- In
Elf.c:390:
return;
}
Zstr base = (Zstr)(BufData(&self->data) + dl->offset);
// filename runs up to (and including) the NUL; CRC follows in the
// last 4 bytes of the section, after alignment padding.
- In
Elf.c:402:
}
// CRC is in the last 4 bytes.
const u8 *crc_bytes = BufData(&self->data) + dl->offset + dl->size - 4;
BufIter crc_iter = BufIterFromMemory(crc_bytes, 4);
u32 crc;- In
Dwarf.c:549:
U64Vec pending_dir_offsets = VecInitT(pending_dir_offsets, alloc);
BufIter section_cur = BufIterFromMemory(BufData(&elf->data) + line_section->offset, line_section->size);
bool ok = true;- In
DwarfInfo.c:646:
const ElfSection *str_sec = ElfFindSection(elf, ".debug_str");
const u8 *info_b = info_sec ? BufData(&elf->data) + info_sec->offset : NULL;
u64 info_n = info_sec ? info_sec->size : 0;
const u8 *abbrev_b = abbrev_sec ? BufData(&elf->data) + abbrev_sec->offset : NULL;- In
DwarfInfo.c:648:
const u8 *info_b = info_sec ? BufData(&elf->data) + info_sec->offset : NULL;
u64 info_n = info_sec ? info_sec->size : 0;
const u8 *abbrev_b = abbrev_sec ? BufData(&elf->data) + abbrev_sec->offset : NULL;
u64 abbrev_n = abbrev_sec ? abbrev_sec->size : 0;
const u8 *str_b = str_sec ? BufData(&elf->data) + str_sec->offset : NULL;- In
DwarfInfo.c:650:
const u8 *abbrev_b = abbrev_sec ? BufData(&elf->data) + abbrev_sec->offset : NULL;
u64 abbrev_n = abbrev_sec ? abbrev_sec->size : 0;
const u8 *str_b = str_sec ? BufData(&elf->data) + str_sec->offset : NULL;
u64 str_n = str_sec ? str_sec->size : 0;
return DwarfFunctionsBuildFromSlices(out, info_b, info_n, abbrev_b, abbrev_n, str_b, str_n, alloc);- In
Pdb.c:91:
if (off + self->block_size > BufLength(&self->data))
return NULL;
return BufData(&self->data) + off;
}- In
Pdb.c:141:
return false;
}
if (MemCompare(BufData(&self->data), kMsfMagic7, sizeof(kMsfMagic7)) != 0) {
LOG_ERROR("PDB: bad MSF magic (not 7.00)");
return false;- In
Pdb.c:145:
return false;
}
BufIter sb = BufIterFromMemory(BufData(&self->data) + 32, BufLength(&self->data) - 32);
u32 free_blk, num_blocks, unknown;
if (!BufReadFmt(- In
Pdb.c:743:
return false;
}
MemCopy(BufData(©), data, data_size);
BufResize(©, (size)data_size);
return PdbOpenFromMemory(out, ©); out->eh_frame_addr = eh->addr;
const u8 *section_data = BufData(&elf->data) + eh->offset;
BufIter section_cur = BufIterFromMemory(section_data, eh->size);- In
Pe.c:163:
return false;
}
BufIter mz_iter = BufIterFromMemory(BufData(&ctx->out->data), 2);
u16 mz;
if (!BufReadU16LE(&mz_iter, &mz)) {- In
Pe.c:174:
u32 e_lfanew;
BufIter c = BufIterFromMemory(
BufData(&ctx->out->data) + DOS_E_LFANEW_OFFSET,
BufLength(&ctx->out->data) - DOS_E_LFANEW_OFFSET
);- In
Pe.c:190:
static bool pe_decode_nt(PeContext *ctx, u64 *out_opt_offset) {
BufIter c =
BufIterFromMemory(BufData(&ctx->out->data) + ctx->nt_offset, BufLength(&ctx->out->data) - ctx->nt_offset);
u32 sig;
if (!BufReadU32LE(&c, &sig) || sig != NT_SIGNATURE) {- In
Pe.c:209:
ctx->num_sections = num_sec;
ctx->opt_hdr_size = size_opt;
*out_opt_offset = (u64)(c.data + c.pos - BufData(&ctx->out->data));
return true;
}- In
Pe.c:220:
return false;
}
BufIter c = BufIterFromMemory(BufData(&ctx->out->data) + opt_offset, ctx->opt_hdr_size);
u16 magic;- In
Pe.c:370:
static bool pe_decode_sections(PeContext *ctx, u64 opt_offset) {
u64 sec_offset = opt_offset + ctx->opt_hdr_size;
BufIter c = BufIterFromMemory(BufData(&ctx->out->data) + sec_offset, BufLength(&ctx->out->data) - sec_offset);
for (u32 i = 0; i < ctx->num_sections; ++i) {- In
Pe.c:439:
for (u32 i = 0; i < num_entries; ++i) {
u64 entry_off = dir_offset + (u64)i * DEBUG_ENTRY_SIZE;
BufIter c = BufIterFromMemory(BufData(&ctx->out->data) + entry_off, BufLength(&ctx->out->data) - entry_off);
u32 charac, ts, type, sz, raddr, rptr;
u16 ver_maj, ver_min;- In
Pe.c:458:
if (sz < 4 + 16 + 4 + 1)
continue;
BufIter cv_cur = BufIterFromMemory(BufData(&ctx->out->data) + rptr, sz);
u32 cv_sig;
if (!BufReadU32LE(&cv_cur, &cv_sig))- In
Pe.c:543:
return false;
}
MemCopy(BufData(©), data, data_size);
BufResize(©, (size)data_size);
return PeOpenFromMemory(out, ©);- In
Buf.c:19:
BufWriteU8(&b, 0x42);
BufWriteU8(&b, 0x43);
ok = ok && BufLength(&b) == 2 && BufData(&b)[0] == 0x42 && BufData(&b)[1] == 0x43;
BufClear(&b);
ok = ok && BufLength(&b) == 0;- In
Buf.c:44:
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // u64 BE
};
bool ok = BufLength(&b) == sizeof(expect) && MemCompare(BufData(&b), expect, sizeof(expect)) == 0;
BufDeinit(&b);
DefaultAllocatorDeinit(&alloc);- In
Buf.c:58:
BufWriteULeb128(&b, 16384);
const u8 expect_uleb[] = {0x00, 0x7F, 0x80, 0x01, 0x80, 0x80, 0x01};
if (BufLength(&b) != sizeof(expect_uleb) || MemCompare(BufData(&b), expect_uleb, sizeof(expect_uleb)) != 0) {
BufDeinit(&b);
DefaultAllocatorDeinit(&alloc);- In
Buf.c:70:
BufWriteSLeb128(&b, -64);
const u8 expect_sleb[] = {0x00, 0x7F, 0xC0, 0x00, 0x40};
bool ok = BufLength(&b) == sizeof(expect_sleb) && MemCompare(BufData(&b), expect_sleb, sizeof(expect_sleb)) == 0;
BufDeinit(&b);- In
Buf.c:82:
BufWriteZstr(&b, "hi");
const u8 expect[] = {'h', 'i', 0};
bool ok = BufLength(&b) == sizeof(expect) && MemCompare(BufData(&b), expect, sizeof(expect)) == 0;
BufDeinit(&b);
DefaultAllocatorDeinit(&alloc);- In
Buf.c:158:
bool ok = BufAppendFmt(&b, "{<2r}{>4r}", (u16)0xCAFE, (u32)0xDEADBEEF);
const u8 expect[] = {0x99, 0xFE, 0xCA, 0xDE, 0xAD, 0xBE, 0xEF};
ok = ok && BufLength(&b) == sizeof(expect) && MemCompare(BufData(&b), expect, sizeof(expect)) == 0;
BufDeinit(&b);
DefaultAllocatorDeinit(&alloc);- In
Buf.c:172:
bool ok = BufWriteFmt(&b, "{<2r}", (u16)0x1234);
const u8 expect[] = {0x34, 0x12};
ok = ok && BufLength(&b) == sizeof(expect) && MemCompare(BufData(&b), expect, sizeof(expect)) == 0;
BufDeinit(&b);
DefaultAllocatorDeinit(&alloc);- In
Buf.c:200:
0x11
};
ok = ok && BufLength(&b) == sizeof(expect) && MemCompare(BufData(&b), expect, sizeof(expect)) == 0;
// Out-of-range patch must fail and leave the buf unchanged.
- In
Buf.c:204:
// Out-of-range patch must fail and leave the buf unchanged.
Buf snapshot = BufInit(&alloc);
BufPushBytes(&snapshot, BufData(&b), BufLength(&b));
ok = ok && !BufPatchFmt(&b, BufLength(&b), "{<2r}", (u16)0);
ok = ok && BufLength(&b) == BufLength(&snapshot);- In
Buf.c:207:
ok = ok && !BufPatchFmt(&b, BufLength(&b), "{<2r}", (u16)0);
ok = ok && BufLength(&b) == BufLength(&snapshot);
ok = ok && MemCompare(BufData(&b), BufData(&snapshot), BufLength(&b)) == 0;
BufDeinit(&snapshot);- In
Dns.c:27:
bool match = ok && BufLength(&buf) == sizeof(expected);
for (u64 i = 0; match && i < sizeof(expected); ++i) {
if (BufData(&buf)[i] != expected[i]) {
match = false;
}- In
Dns.c:48:
bool match = ok && BufLength(&no_dot) == BufLength(&w_dot);
for (u64 i = 0; match && i < BufLength(&no_dot); ++i) {
if (BufData(&no_dot)[i] != BufData(&w_dot)[i]) {
match = false;
}
Last updated on