ElfOpenFromMemoryCopy
Description
Parse an ELF object from an in-memory byte range – R-value / copy form (mirrors VecInsertR).
Parser allocates its own buffer through alloc and MemCopys the caller’s bytes in. The caller’s pointer is never retained: after this call returns, the caller’s buffer is theirs to do anything with (including free, mutate, or hand to another parser).
Parameters
| Name | Direction | Description |
|---|---|---|
out |
out | Populated on success. |
data |
in | Raw ELF bytes. Read-only here; caller keeps them. |
data_size |
in | Length of data in bytes. |
alloc |
in | Allocator for the internal copy and the section / symbol vectors. Must outlive the Elf. |
Success
Returns true; out owns an independent copy of data.
Failure
Returns false; logs the failing step. out is left zeroed and the caller’s data is untouched.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Elf.c:511:
bool elf_open_from_memory_copy(Elf *out, const u8 *data, size data_size, Allocator *alloc) {
if (!out || !data || !alloc) {
LOG_FATAL("ElfOpenFromMemoryCopy: NULL argument (contract violation)");
}
Buf copy = BufInit(alloc);- In
Elf.c:515:
Buf copy = BufInit(alloc);
if (!VecReserve(©, (u64)data_size)) {
LOG_ERROR("ElfOpenFromMemoryCopy: allocation failed ({} bytes)", (u64)data_size);
return false;
}- In
Elf.c:350:
Elf elf;
bool ok = ElfOpenFromMemoryCopy(&elf, elf_blob, sizeof(elf_blob), ALLOCATOR_OF(&alloc));
if (!ok) {
DefaultAllocatorDeinit(&alloc);- In
Elf.c:394:
Elf elf;
bool ok = ElfOpenFromMemoryCopy(&elf, elf_blob, sizeof(elf_blob), ALLOCATOR_OF(&alloc));
if (ok) {
ok = VecLen(&elf.segments) == 2;- In
Elf.c:420:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elf_blob, sizeof(elf_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:456:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elf_blob, sizeof(elf_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:472:
DefaultAllocator alloc = DefaultAllocatorInit();
Elf elf;
bool opened = ElfOpenFromMemoryCopy(&elf, bytes, len, ALLOCATOR_OF(&alloc));
if (opened)
ElfDeinit(&elf);- In
Elf.c:711:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, dbg_blob, sizeof(dbg_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:747:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elf_blob, sizeof(elf_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:773:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elf_blob, sizeof(elf_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:795:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elf_blob, sizeof(elf_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:861:
Elf elf;
bool ok = ElfOpenFromMemoryCopy(&elf, elf_blob, sizeof(elf_blob), ALLOCATOR_OF(&alloc));
if (ok) {
// Names resolved through the in-range shstrtab.
- In
Elf.c:885:
Elf elf;
bool ok = ElfOpenFromMemoryCopy(&elf, bad, sizeof(bad), ALLOCATOR_OF(&alloc));
if (ok) {
// Empty shstrtab => every section name decodes to "".
- In
Elf.c:909:
Elf elf;
bool ok = ElfOpenFromMemoryCopy(&elf, bad, sizeof(bad), ALLOCATOR_OF(&alloc));
if (ok) {
ok = VecLen(&elf.sections) == N_SECTIONS;- In
Elf.c:988:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elf_blob, sizeof(elf_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:1048:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elf_blob, sizeof(elf_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:1107:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elf_blob, sizeof(elf_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:1127:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elf_blob, sizeof(elf_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:1155:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elf_blob, sizeof(elf_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:1209:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elf_blob, sizeof(elf_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:1267:
DefaultAllocator alloc = DefaultAllocatorInit();
Elf elf;
bool opened = ElfOpenFromMemoryCopy(&elf, b, sizeof(b), ALLOCATOR_OF(&alloc));
bool ok = opened && elf.header.shnum == 1 && VecLen(&elf.sections) == 1;
if (opened)- In
Elf.c:1287:
DefaultAllocator alloc = DefaultAllocatorInit();
Elf elf;
bool opened = ElfOpenFromMemoryCopy(&elf, elf_blob, sizeof(elf_blob), ALLOCATOR_OF(&alloc));
if (opened)
ElfDeinit(&elf);- In
Elf.c:1416:
DefaultAllocator alloc = DefaultAllocatorInit();
Elf elf;
bool opened = ElfOpenFromMemoryCopy(&elf, bad, sizeof(bad), ALLOCATOR_OF(&alloc));
if (opened) {
// Should not happen on real code; clean up and fail the test.
- In
Elf.c:1676:
static bool open_sym(Elf *elf, DefaultAllocator *alloc) {
build_sym_blob();
return ElfOpenFromMemoryCopy(elf, sym_blob, sizeof(sym_blob), ALLOCATOR_OF(alloc));
}- In
Elf.c:1762:
Elf elf;
bool opened = ElfOpenFromMemoryCopy(&elf, sym_blob, sizeof(sym_blob), ALLOCATOR_OF(&alloc));
if (opened)
ElfDeinit(&elf);- In
Elf.c:1920:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, bid_blob, sizeof(bid_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:1941:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, bid_blob, sizeof(bid_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:1963:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, bid_blob, sizeof(bid_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:1984:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, bid_blob, sizeof(bid_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:2006:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, bid_blob, sizeof(bid_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:2072:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, dl_blob, sizeof(dl_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:2100:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, dl_blob, sizeof(dl_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:2120:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, dl_blob, sizeof(dl_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:2143:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, dl_blob, sizeof(dl_blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:2213:
Elf elf;
bool opened = ElfOpenFromMemoryCopy(&elf, blob, sizeof(blob), ALLOCATOR_OF(&alloc));
if (opened)
ElfDeinit(&elf);- In
Elf.c:2281:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, blob, sizeof(blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:2315:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, blob, sizeof(blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:2344:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, blob, sizeof(blob), ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:2470:
Elf elf;
bool opened = ElfOpenFromMemoryCopy(&elf, buf, sizeof(buf), ALLOCATOR_OF(&alloc));
if (opened)
ElfDeinit(&elf);
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DefaultAllocatorDeinit(&alloc);
return false;
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DefaultAllocatorDeinit(&alloc);
return false;
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DefaultAllocatorDeinit(&alloc);
return false;
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DefaultAllocatorDeinit(&alloc);
return false; bool ok = false;
Elf elf;
if (ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DwarfCfi cfi;
if (DwarfCfiBuildFromElf(&cfi, &elf, base)) { bool ok = false;
Elf elf;
if (ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DwarfCfi cfi;
if (DwarfCfiBuildFromElf(&cfi, &elf, base)) { bool ok = false;
Elf elf;
if (ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DwarfCfi cfi;
if (DwarfCfiBuildFromElf(&cfi, &elf, base)) { bool ok = false;
Elf elf;
if (ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DwarfCfi cfi;
if (DwarfCfiBuildFromElf(&cfi, &elf, base)) { bool ok = false;
Elf elf;
if (ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DwarfCfi cfi;
if (DwarfCfiBuildFromElf(&cfi, &elf, base)) {- In
Dwarf.c:577:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Dwarf.c:632:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Dwarf.c:752:
build_elf_with_debug_line_8192(elfbuf, &elf_len, dl, dl_len);
if (!ElfOpenFromMemoryCopy(&fx->elf, elfbuf, (size)elf_len, base)) {
DefaultAllocatorDeinit(&fx->alloc);
return false;- In
Dwarf.c:881:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base))
return false;- In
Dwarf.c:1012:
u64 elf_len = 0;
build_elf_with_debug_line_8192(elfbuf, &elf_len, dl, dl_len);
if (!ElfOpenFromMemoryCopy(elf, elfbuf, (size)elf_len, base))
return false;
return DwarfLinesBuildFromElf(out, elf, base);- In
Dwarf.c:1518:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Dwarf.c:1914:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base))
return false;- In
Dwarf.c:2468:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Dwarf.c:2512:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Dwarf.c:2548:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Dwarf.c:2583:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Dwarf.c:2637:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DebugAllocatorDeinit(&dbg);
return false;- In
Dwarf.c:2683:
Elf elf;
if (!ElfOpenFromMemoryCopy(&elf, elfbuf, (size)elf_len, base)) {
DebugAllocatorDeinit(&dbg);
return false;- In
Dwarf.c:3082:
u64 elf_len = 0;
build_elf_with_debug_line_8192(elfbuf, &elf_len, dl, dl_len);
if (!ElfOpenFromMemoryCopy(elf, elfbuf, (size)elf_len, base))
return false;
bool built = DwarfLinesBuildFromElf(lines, elf, base);
Last updated on