more or less almost done with the instr reels.
This commit is contained in:
@@ -8,22 +8,16 @@ namespace spider {
|
||||
|
||||
// Constructors & Destructors //
|
||||
|
||||
InstrReelFixed::InstrReelFixed(u64 length) {
|
||||
this->_offset = 0;
|
||||
this->_size = length;
|
||||
this->_total_size = length;
|
||||
|
||||
InstrReelFixed::InstrReelFixed(u64 length)
|
||||
: _mem(nullptr), _size(length) {
|
||||
if (_size > 0) {
|
||||
_mem = new u8[_size];
|
||||
std::memset(_mem, 0, _size);
|
||||
}
|
||||
}
|
||||
|
||||
InstrReelFixed::InstrReelFixed(const u8* data, u64 length) {
|
||||
this->_offset = 0;
|
||||
this->_size = length;
|
||||
this->_total_size = length;
|
||||
|
||||
InstrReelFixed::InstrReelFixed(const u8* data, u64 length)
|
||||
: _mem(nullptr), _size(length) {
|
||||
if (_size > 0) {
|
||||
_mem = new u8[_size];
|
||||
std::copy(data, data + _size, _mem);
|
||||
@@ -31,29 +25,77 @@ namespace spider {
|
||||
}
|
||||
|
||||
InstrReelFixed::InstrReelFixed(const InstrReelFixed& other) {
|
||||
_offset = other._offset;
|
||||
_size = other._size;
|
||||
_total_size = other._total_size;
|
||||
_mem = new u8[_size];
|
||||
std::copy(other._mem, other._mem + _size, _mem);
|
||||
}
|
||||
|
||||
InstrReelFixed::InstrReelFixed(InstrReelFixed&& other) noexcept {
|
||||
_mem = other._mem;
|
||||
_offset = other._offset;
|
||||
_size = other._size;
|
||||
_total_size = other._total_size;
|
||||
|
||||
other._mem = nullptr;
|
||||
other._offset = 0;
|
||||
other._size = 0;
|
||||
other._total_size = 0;
|
||||
}
|
||||
|
||||
InstrReelFixed::~InstrReelFixed() {
|
||||
delete[] _mem;
|
||||
}
|
||||
|
||||
// General Case(s) //
|
||||
|
||||
// Instruction abstraction //
|
||||
|
||||
u8 InstrReelFixed::readU8(u64 ip) {
|
||||
// guard against access
|
||||
if(ip + 1 > _size) return 0;
|
||||
|
||||
// send byte
|
||||
return _mem[ip];
|
||||
}
|
||||
|
||||
u16 InstrReelFixed::readU16(u64 ip) {
|
||||
// guard against access
|
||||
if(ip + 2 > _size) return 0;
|
||||
|
||||
// build a 16-bit big endian number
|
||||
u16 dat;
|
||||
spider::loadLE(&dat, _mem + ip);
|
||||
return dat;
|
||||
}
|
||||
|
||||
u32 InstrReelFixed::readU32(u64 ip) {
|
||||
// guard against access
|
||||
if(ip + 4 > _size) return 0;
|
||||
|
||||
// build a 32-bit big endian number
|
||||
u32 dat;
|
||||
spider::loadLE(&dat, _mem + ip);
|
||||
return dat;
|
||||
}
|
||||
|
||||
u64 InstrReelFixed::readU64(u64 ip) {
|
||||
// guard against access
|
||||
if(ip + 8 > _size) return 0;
|
||||
|
||||
// build a 64-bit big endian number
|
||||
u64 dat;
|
||||
spider::loadLE(&dat, _mem + ip);
|
||||
return dat;
|
||||
}
|
||||
|
||||
void InstrReelFixed::readRange(u64 ip, u8* out, u64 length) {
|
||||
if(ip + length > _size) {
|
||||
std::memset(out, 0, length);
|
||||
return;
|
||||
}
|
||||
std::memcpy(out, _mem + ip, length);
|
||||
}
|
||||
|
||||
u64 InstrReelFixed::size() {
|
||||
return _size;
|
||||
}
|
||||
|
||||
// Assign Operators //
|
||||
|
||||
InstrReelFixed& InstrReelFixed::operator=(const InstrReelFixed& other) {
|
||||
@@ -64,9 +106,7 @@ namespace spider {
|
||||
|
||||
delete[] _mem;
|
||||
_mem = new_mem;
|
||||
_offset = other._offset;
|
||||
_size = other._size;
|
||||
_total_size = other._total_size;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -77,36 +117,32 @@ namespace spider {
|
||||
delete[] _mem;
|
||||
|
||||
_mem = other._mem; // steal
|
||||
_offset = other._offset;
|
||||
_size = other._size;
|
||||
_total_size = other._total_size;
|
||||
|
||||
other._mem = nullptr; // leave as husk
|
||||
other._offset = 0;
|
||||
other._size = 0;
|
||||
other._total_size = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Misc //
|
||||
|
||||
void InstrReelFixed::at(u64 ip, u8 dat) {
|
||||
void InstrReelFixed::writeU8(u64 ip, u8 dat) {
|
||||
if(ip + 1 > _size) return;
|
||||
_mem[ip] = dat;
|
||||
}
|
||||
|
||||
void InstrReelFixed::at(u64 ip, u16 dat) {
|
||||
void InstrReelFixed::writeU16(u64 ip, u16 dat) {
|
||||
if(ip + 2 > _size) return;
|
||||
spider::storeLE(dat, _mem + ip);
|
||||
}
|
||||
|
||||
void InstrReelFixed::at(u64 ip, u32 dat) {
|
||||
void InstrReelFixed::writeU32(u64 ip, u32 dat) {
|
||||
if(ip + 4 > _size) return;
|
||||
spider::storeLE(dat, _mem + ip);
|
||||
}
|
||||
|
||||
void InstrReelFixed::at(u64 ip, u64 dat) {
|
||||
void InstrReelFixed::writeU64(u64 ip, u64 dat) {
|
||||
if(ip + 8 > _size) return;
|
||||
spider::storeLE(dat, _mem + ip);
|
||||
}
|
||||
@@ -120,7 +156,6 @@ namespace spider {
|
||||
delete[] _mem;
|
||||
_mem = nullptr;
|
||||
_size = 0;
|
||||
_total_size = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -143,7 +178,6 @@ namespace spider {
|
||||
delete[] _mem;
|
||||
_mem = new_mem;
|
||||
_size = new_size;
|
||||
_total_size = new_size;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user