Skip to content

Commit

Permalink
feat: Added bitwise shift left/right data processor nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Oct 19, 2023
1 parent 5d50a39 commit 79e25b0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plugins/builtin/romfs/lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
59 changes: 59 additions & 0 deletions plugins/builtin/source/content/data_processor_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") }) { }
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 79e25b0

Please sign in to comment.