MCPcopy Create free account
hub / github.com/TheAssassin/AppImageLauncher / copy_and_patch_runtime

Function copy_and_patch_runtime

src/binfmt-bypass/main.cpp:18–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16#define EXIT_CODE_FAILURE 0xff
17
18bool copy_and_patch_runtime(int fd, const char* const appimage_filename, const ssize_t elf_size) {
19 // copy runtime header into memfd "file"
20 {
21 const auto realfd = open(appimage_filename, O_RDONLY);
22 std::vector<char> buffer(elf_size);
23 // TODO: check for errors
24 read(realfd, buffer.data(), elf_size);
25 write(fd, buffer.data(), elf_size);
26 close(realfd);
27 }
28
29 // erase magic bytes
30 lseek(fd, 8, SEEK_SET);
31 char null_buf[]{0, 0, 0};
32 write(fd, null_buf, 3);
33
34 // TODO: handle errors properly
35 return true;
36}
37
38#ifdef HAVE_MEMFD_CREATE
39

Calls 1

openFunction · 0.85

Tested by

no test coverage detected