blob: 9cfcbf941613977f0bfd0e388cf40652c2e33b05 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/**
* @file elfload.hpp
* @brief Loads ELF binary data into memory for execution.
*
* Copyright (C) 2023 Clyne Sullivan
*
* Distributed under the GNU GPL v3 or later. You should have received a copy of
* the GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef ELF_LOAD_HPP_
#define ELF_LOAD_HPP_
#include "samplebuffer.hpp"
#include <array>
#include <cstddef>
constexpr unsigned int MAX_ELF_FILE_SIZE = 16 * 1024;
class ELFManager
{
public:
using EntryFunc = Sample *(*)(Sample *, size_t);
/**
* Attempts to parse the ELF binary loaded in the file buffer.
* Returns true if successful.
*/
static bool loadFromInternalBuffer();
/**
* Returns a function pointer to the loaded ELF's entry point.
* Returns nullptr if a valid ELF is not loaded.
*/
static EntryFunc loadedElf();
/**
* Returns the address of the ELF file buffer (copy ELF binary to here).
*/
static unsigned char *fileBuffer();
/**
* "Unloads" the loaded binary by invalidating the entry pointer.
*/
static void unload();
private:
static EntryFunc m_entry;
static std::array<unsigned char, MAX_ELF_FILE_SIZE> m_file_buffer;
};
#endif // ELF_LOAD_HPP_
|