48 lines
1.4 KiB
C++
48 lines
1.4 KiB
C++
#include <libregexis024vm/vm_opcodes.h>
|
|
|
|
#ifndef __ORDER_LITTLE_ENDIAN__
|
|
#error "Big endian is currently unsupported"
|
|
#endif
|
|
|
|
bool vmprog_check_inboundness(regex_near_ptr_t prgSz, regex_near_ptr_t IP, regex_near_ptr_t region) {
|
|
return IP + region <= prgSz;
|
|
}
|
|
|
|
uint8_t vmprog_extract_b(regex_near_ptr_t *IPptr, const uint8_t *prg) {
|
|
return prg[(*IPptr)++];
|
|
}
|
|
|
|
uint16_t vmprog_extract_w(regex_near_ptr_t *IPptr, const uint8_t *prg) {
|
|
uint16_t answer = *(uint16_t*)(&prg[*IPptr]);
|
|
*IPptr += 2;
|
|
return answer;
|
|
}
|
|
|
|
uint32_t vmprog_extract_dw(regex_near_ptr_t *IPptr, const uint8_t *prg) {
|
|
uint32_t answer = *(uint32_t *)(&prg[*IPptr]);
|
|
*IPptr += 4;
|
|
return answer;
|
|
}
|
|
|
|
uint64_t vmprog_extract_qw(regex_near_ptr_t *IPptr, const uint8_t *prg) {
|
|
uint64_t answer = *(uint64_t *)(&prg[*IPptr]);
|
|
*IPptr += 8;
|
|
return answer;
|
|
}
|
|
|
|
uint8_t vmprog_extract_instruction(regex_near_ptr_t *IPptr, const uint8_t *prg) {
|
|
return vmprog_extract_b(IPptr, prg);
|
|
}
|
|
|
|
regex_sslot_id_t vmprog_extract_sslot_id(regex_near_ptr_t *IPptr, const uint8_t *prg) {
|
|
return vmprog_extract_dw(IPptr, prg);
|
|
}
|
|
|
|
regex_near_ptr_t vmprog_extract_near_pointer(regex_near_ptr_t *IPptr, const uint8_t *prg) {
|
|
return vmprog_extract_qw(IPptr, prg);
|
|
}
|
|
|
|
regex_tai_t vmprog_extrack_track_array_index(regex_near_ptr_t *IPptr, const uint8_t *prg) {
|
|
return vmprog_extract_w(IPptr, prg);
|
|
}
|