MCPcopy Create free account
hub / github.com/D7EAD/mkPIVM / encode_bytecode

Function encode_bytecode

src/packager.cpp:217–234  ·  view source on GitHub ↗

runs the IR through the codecs and hands back raw plaintext bytecode.

Source from the content-addressed store, hash-verified

215
216 // runs the IR through the codecs and hands back raw plaintext bytecode.
217 static std::vector<std::uint8_t> encode_bytecode(const IRProgram& prog, const VMConfig& vm, const CodecRegistry& codecs) {
218 BytecodeBuilder bb;
219
220 // data refs get resolved later once the data island layout is known
221 for (const auto& blk : prog.blocks) {
222 bb.mark_block(blk.id);
223
224 for (const auto& insn : blk.insns) {
225 const std::string fam = codec_family_for(insn.op);
226 const Codec* c = codecs.by_family(fam);
227 if (!c) throw Error("no codec for family " + fam);
228 c->encode(bb, insn, vm);
229 }
230 }
231
232 bb.resolve_branches();
233 return std::move(bb).take();
234 }
235
236 PackageResult package_shellcode(Span<std::uint8_t> shellcode, const PackageOptions& opt) {
237 SeedRng rng{opt.seed};

Callers

nothing calls this directly

Calls 7

codec_family_forFunction · 0.85
ErrorClass · 0.85
mark_blockMethod · 0.80
by_familyMethod · 0.80
encodeMethod · 0.80
resolve_branchesMethod · 0.80
takeMethod · 0.45

Tested by

no test coverage detected