1
0
mirror of synced 2025-01-29 19:17:28 +01:00

feat: Added bitwise shift left/right data processor nodes

This commit is contained in:
WerWolv 2023-10-19 22:08:39 +02:00
parent 5d50a3927e
commit 79e25b0889
2 changed files with 64 additions and 0 deletions

View File

@ -282,6 +282,10 @@
"hex.builtin.nodes.bitwise.not.header": "Bitwise NOT",
"hex.builtin.nodes.bitwise.or": "OR",
"hex.builtin.nodes.bitwise.or.header": "Bitwise OR",
"hex.builtin.nodes.bitwise.shift_left": "Shift Left",
"hex.builtin.nodes.bitwise.shift_left.header": "Bitwise Shift Left",
"hex.builtin.nodes.bitwise.shift_right": "Shift Right",
"hex.builtin.nodes.bitwise.shift_right.header": "Bitwise Shift Right",
"hex.builtin.nodes.bitwise.swap": "Reverse",
"hex.builtin.nodes.bitwise.swap.header": "Reverse bits",
"hex.builtin.nodes.bitwise.xor": "XOR",
@ -321,6 +325,7 @@
"hex.builtin.nodes.common.input.b": "Input B",
"hex.builtin.nodes.common.output": "Output",
"hex.builtin.nodes.common.width": "Width",
"hex.builtin.nodes.common.amount": "Amount",
"hex.builtin.nodes.constants": "Constants",
"hex.builtin.nodes.constants.buffer": "Buffer",
"hex.builtin.nodes.constants.buffer.header": "Buffer",

View File

@ -376,6 +376,63 @@ namespace hex::plugin::builtin {
}
};
class NodeBitwiseShiftLeft : public dp::Node {
public:
NodeBitwiseShiftLeft() : Node("hex.builtin.nodes.bitwise.shift_left.header", {
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"),
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.amount"),
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output")
}) { }
void process() override {
const auto &input = this->getBufferOnInput(0);
const auto &amount = this->getIntegerOnInput(1);
std::vector<u8> output = input;
for (u32 i = 0; i < amount; i += 1) {
u8 prevByte = 0x00;
for (auto &byte : output) {
auto startValue = byte;
byte <<= 1;
byte |= (prevByte & 0x80) >> 7;
prevByte = startValue;
}
}
this->setBufferOnOutput(2, output);
}
};
class NodeBitwiseShiftRight : public dp::Node {
public:
NodeBitwiseShiftRight() : Node("hex.builtin.nodes.bitwise.shift_left.header", {
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"),
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.amount"),
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output")
}) { }
void process() override {
const auto &input = this->getBufferOnInput(0);
const auto &amount = this->getIntegerOnInput(1);
std::vector<u8> output = input;
for (u32 i = 0; i < amount; i += 1) {
u8 prevByte = 0x00;
for (auto &byte : output | std::views::reverse) {
auto startValue = byte;
byte >>= 1;
byte |= (prevByte & 0x01) << 7;
prevByte = startValue;
}
}
this->setBufferOnOutput(2, output);
}
};
class NodeBitwiseADD : public dp::Node {
public:
NodeBitwiseADD() : Node("hex.builtin.nodes.bitwise.add.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input.a"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input.b"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
@ -1325,6 +1382,8 @@ namespace hex::plugin::builtin {
ContentRegistry::DataProcessorNode::add<NodeBitwiseOR>("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.or");
ContentRegistry::DataProcessorNode::add<NodeBitwiseXOR>("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.xor");
ContentRegistry::DataProcessorNode::add<NodeBitwiseNOT>("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.not");
ContentRegistry::DataProcessorNode::add<NodeBitwiseShiftLeft>("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.shift_left");
ContentRegistry::DataProcessorNode::add<NodeBitwiseShiftRight>("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.shift_right");
ContentRegistry::DataProcessorNode::add<NodeBitwiseSwap>("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.swap");
ContentRegistry::DataProcessorNode::add<NodeDecodingBase64>("hex.builtin.nodes.decoding", "hex.builtin.nodes.decoding.base64");