2021-01-30 22:39:06 +01:00
|
|
|
#include <hex/plugin.hpp>
|
|
|
|
|
2021-02-03 11:54:41 +01:00
|
|
|
#include <hex/helpers/crypto.hpp>
|
|
|
|
|
2021-02-04 00:21:53 +01:00
|
|
|
#include <cctype>
|
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
2021-02-04 00:21:53 +01:00
|
|
|
class NodeNullptr : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeNullptr() : Node("hex.builtin.nodes.constants.nullptr.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.constants.nullptr.output"_lang)
|
|
|
|
}) {}
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
void process() override {
|
|
|
|
this->setBufferOnOutput(0, { });
|
|
|
|
}
|
2021-02-08 23:17:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class NodeBuffer : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeBuffer() : Node("hex.builtin.nodes.constants.buffer.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.constants.buffer.output"_lang)
|
|
|
|
}) {}
|
2021-02-08 23:17:30 +01:00
|
|
|
|
|
|
|
void drawNode() override {
|
|
|
|
constexpr int StepSize = 1, FastStepSize = 10;
|
|
|
|
|
|
|
|
ImGui::PushItemWidth(100);
|
2021-02-11 23:09:45 +01:00
|
|
|
ImGui::InputScalar("hex.builtin.nodes.constants.buffer.size"_lang, ImGuiDataType_U32, &this->m_size, &StepSize, &FastStepSize);
|
2021-02-08 23:17:30 +01:00
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
if (this->m_buffer.size() != this->m_size)
|
|
|
|
this->m_buffer.resize(this->m_size, 0x00);
|
|
|
|
|
|
|
|
this->setBufferOnOutput(0, this->m_buffer);
|
|
|
|
}
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
private:
|
2021-02-08 23:17:30 +01:00
|
|
|
u32 m_size = 1;
|
|
|
|
std::vector<u8> m_buffer;
|
2021-02-04 00:21:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class NodeString : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeString() : Node("hex.builtin.nodes.constants.string.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.constants.string.output"_lang)
|
|
|
|
}) {
|
2021-02-04 00:21:53 +01:00
|
|
|
this->m_value.resize(0xFFF, 0x00);
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawNode() override {
|
|
|
|
ImGui::PushItemWidth(100);
|
|
|
|
ImGui::InputText("##string", reinterpret_cast<char*>(this->m_value.data()), this->m_value.size() - 1);
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
std::vector<u8> output(std::strlen(this->m_value.c_str()) + 1, 0x00);
|
|
|
|
std::strcpy(reinterpret_cast<char*>(output.data()), this->m_value.c_str());
|
|
|
|
|
|
|
|
output.pop_back();
|
|
|
|
|
|
|
|
this->setBufferOnOutput(0, output);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_value;
|
|
|
|
};
|
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
class NodeInteger : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeInteger() : Node("hex.builtin.nodes.constants.int.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.constants.int.output"_lang)
|
|
|
|
}) {}
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
void drawNode() override {
|
|
|
|
ImGui::TextUnformatted("0x"); ImGui::SameLine(0, 0);
|
|
|
|
ImGui::PushItemWidth(100);
|
|
|
|
ImGui::InputScalar("##integerValue", ImGuiDataType_U64, &this->m_value, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
2021-01-31 01:42:29 +01:00
|
|
|
std::vector<u8> data(sizeof(this->m_value), 0);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 01:42:29 +01:00
|
|
|
std::memcpy(data.data(), &this->m_value, sizeof(u64));
|
2021-01-31 16:11:25 +01:00
|
|
|
this->setBufferOnOutput(0, data);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
u64 m_value = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeFloat : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeFloat() : Node("hex.builtin.nodes.constants.float.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Float, "hex.builtin.nodes.constants.float.output"_lang)
|
|
|
|
}) {}
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
void drawNode() override {
|
|
|
|
ImGui::PushItemWidth(100);
|
|
|
|
ImGui::InputScalar("##floatValue", ImGuiDataType_Float, &this->m_value, nullptr, nullptr, "%f", ImGuiInputTextFlags_CharsDecimal);
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
2021-01-30 22:39:06 +01:00
|
|
|
std::vector<u8> data;
|
|
|
|
data.resize(sizeof(this->m_value));
|
|
|
|
|
|
|
|
std::copy(&this->m_value, &this->m_value + 1, data.data());
|
2021-01-31 16:11:25 +01:00
|
|
|
this->setBufferOnOutput(0, data);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
float m_value = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeRGBA8 : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeRGBA8() : Node("hex.builtin.nodes.constants.rgba8.header"_lang,
|
|
|
|
{ dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.constants.rgba8.output.r"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.constants.rgba8.output.g"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.constants.rgba8.output.b"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.constants.rgba8.output.a"_lang)}) {}
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
void drawNode() override {
|
|
|
|
ImGui::PushItemWidth(200);
|
|
|
|
ImGui::ColorPicker4("##colorPicker", &this->m_color.Value.x, ImGuiColorEditFlags_AlphaBar);
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
this->setBufferOnOutput(0, hex::toBytes<u64>(this->m_color.Value.x * 0xFF));
|
|
|
|
this->setBufferOnOutput(1, hex::toBytes<u64>(this->m_color.Value.y * 0xFF));
|
|
|
|
this->setBufferOnOutput(2, hex::toBytes<u64>(this->m_color.Value.z * 0xFF));
|
|
|
|
this->setBufferOnOutput(3, hex::toBytes<u64>(this->m_color.Value.w * 0xFF));
|
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ImColor m_color;
|
|
|
|
};
|
|
|
|
|
2021-02-04 12:46:38 +01:00
|
|
|
class NodeComment : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeComment() : Node("hex.builtin.nodes.constants.comment.header"_lang, { }) {
|
2021-02-04 12:46:38 +01:00
|
|
|
this->m_comment.resize(0xFFF, 0x00);
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawNode() override {
|
|
|
|
ImGui::InputTextMultiline("##string", reinterpret_cast<char*>(this->m_comment.data()), this->m_comment.size() - 1, ImVec2(150, 100));
|
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_comment;
|
|
|
|
};
|
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
class NodeDisplayInteger : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeDisplayInteger() : Node("hex.builtin.nodes.display.int.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.display.int.input"_lang)
|
|
|
|
}) {}
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
void drawNode() override {
|
|
|
|
ImGui::PushItemWidth(150);
|
|
|
|
if (this->m_value.has_value())
|
|
|
|
ImGui::Text("0x%llx", this->m_value.value());
|
|
|
|
else
|
|
|
|
ImGui::TextUnformatted("???");
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
2021-02-04 01:14:05 +01:00
|
|
|
this->m_value.reset();
|
2021-01-31 16:11:25 +01:00
|
|
|
auto input = this->getIntegerOnInput(0);
|
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->m_value = input;
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-02-04 01:14:05 +01:00
|
|
|
std::optional<u64> m_value;
|
2021-01-30 22:39:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class NodeDisplayFloat : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeDisplayFloat() : Node("hex.builtin.nodes.display.float.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Float, "hex.builtin.nodes.display.float.input"_lang)
|
|
|
|
}) {}
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
void drawNode() override {
|
|
|
|
ImGui::PushItemWidth(150);
|
|
|
|
if (this->m_value.has_value())
|
|
|
|
ImGui::Text("%f", this->m_value.value());
|
|
|
|
else
|
|
|
|
ImGui::TextUnformatted("???");
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
2021-02-04 01:14:05 +01:00
|
|
|
this->m_value.reset();
|
2021-01-31 16:11:25 +01:00
|
|
|
auto input = this->getFloatOnInput(0);
|
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->m_value = input;
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-02-04 01:14:05 +01:00
|
|
|
std::optional<float> m_value;
|
2021-01-30 22:39:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class NodeBitwiseNOT : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeBitwiseNOT() : Node("hex.builtin.nodes.bitwise.not.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.bitwise.not.input"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.bitwise.not.output"_lang) }) {}
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto input = this->getBufferOnInput(0);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
std::vector<u8> output = input;
|
2021-01-30 22:39:06 +01:00
|
|
|
for (auto &byte : output)
|
|
|
|
byte = ~byte;
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
this->setBufferOnOutput(1, output);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeBitwiseAND : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeBitwiseAND() : Node("hex.builtin.nodes.bitwise.and.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.bitwise.and.input.a"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.bitwise.and.input.b"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.bitwise.and.output"_lang) }) {}
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getBufferOnInput(0);
|
|
|
|
auto inputB = this->getBufferOnInput(1);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
std::vector<u8> output(std::min(inputA.size(), inputB.size()), 0x00);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
for (u32 i = 0; i < output.size(); i++)
|
2021-02-04 01:14:05 +01:00
|
|
|
output[i] = inputA[i] & inputB[i];
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
this->setBufferOnOutput(2, output);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeBitwiseOR : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeBitwiseOR() : Node("hex.builtin.nodes.bitwise.or.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.bitwise.or.input.a"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.bitwise.or.input.b"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.bitwise.or.output"_lang) }) {}
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getBufferOnInput(0);
|
|
|
|
auto inputB = this->getBufferOnInput(1);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
std::vector<u8> output(std::min(inputA.size(), inputB.size()), 0x00);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
for (u32 i = 0; i < output.size(); i++)
|
2021-02-04 01:14:05 +01:00
|
|
|
output[i] = inputA[i] | inputB[i];
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
this->setBufferOnOutput(2, output);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeBitwiseXOR : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeBitwiseXOR() : Node("hex.builtin.nodes.bitwise.xor.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.bitwise.xor.input.a"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.bitwise.xor.input.b"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.bitwise.xor.output"_lang) }) {}
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getBufferOnInput(0);
|
|
|
|
auto inputB = this->getBufferOnInput(1);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
std::vector<u8> output(std::min(inputA.size(), inputB.size()), 0x00);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
for (u32 i = 0; i < output.size(); i++)
|
2021-02-04 01:14:05 +01:00
|
|
|
output[i] = inputA[i] ^ inputB[i];
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
this->setBufferOnOutput(2, output);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeReadData : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeReadData() : Node("hex.builtin.nodes.data_access.read.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.data_access.read.address"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.data_access.read.size"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.data_access.read.data"_lang)
|
2021-01-30 22:39:06 +01:00
|
|
|
}) { }
|
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto address = this->getIntegerOnInput(0);
|
|
|
|
auto size = this->getIntegerOnInput(1);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
std::vector<u8> data;
|
2021-02-04 01:14:05 +01:00
|
|
|
data.resize(size);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
SharedData::currentProvider->readRaw(address, data.data(), size);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
this->setBufferOnOutput(2, data);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeWriteData : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeWriteData() : Node("hex.builtin.nodes.data_access.write.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.data_access.write.address"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.data_access.write.data"_lang) }) {}
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto address = this->getIntegerOnInput(0);
|
|
|
|
auto data = this->getBufferOnInput(1);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->setOverlayData(address, data);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-31 01:42:29 +01:00
|
|
|
class NodeCastIntegerToBuffer : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeCastIntegerToBuffer() : Node("hex.builtin.nodes.casting.int_to_buffer.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.casting.int_to_buffer.input"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.casting.int_to_buffer.output"_lang) }) {}
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto input = this->getIntegerOnInput(0);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
std::vector<u8> output(sizeof(u64), 0x00);
|
2021-02-04 01:14:05 +01:00
|
|
|
std::memcpy(output.data(), &input, sizeof(u64));
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
this->setBufferOnOutput(1, output);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeCastBufferToInteger : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeCastBufferToInteger() : Node("hex.builtin.nodes.casting.buffer_to_int.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.casting.buffer_to_int.input"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.casting.buffer_to_int.output"_lang) }) {}
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto input = this->getBufferOnInput(0);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
u64 output;
|
2021-02-04 01:14:05 +01:00
|
|
|
std::memcpy(&output, input.data(), sizeof(u64));
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
this->setIntegerOnOutput(1, output);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeIf : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeIf() : Node("ex.builtin.nodes.control_flow.if.header"_lang,
|
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.if.condition"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.control_flow.if.true"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.control_flow.if.false"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.control_flow.if.output"_lang) }) {}
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto cond = this->getIntegerOnInput(0);
|
|
|
|
auto trueData = this->getBufferOnInput(1);
|
|
|
|
auto falseData = this->getBufferOnInput(2);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
if (cond != 0)
|
|
|
|
this->setBufferOnOutput(3, trueData);
|
2021-01-31 01:42:29 +01:00
|
|
|
else
|
2021-02-04 01:14:05 +01:00
|
|
|
this->setBufferOnOutput(3, falseData);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeEquals : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeEquals() : Node("hex.builtin.nodes.control_flow.equals.header"_lang,
|
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.equals.input.a"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.equals.input.b"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.equals.output"_lang) }) {}
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getIntegerOnInput(0);
|
|
|
|
auto inputB = this->getIntegerOnInput(1);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->setIntegerOnOutput(2, inputA == inputB);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeNot : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeNot() : Node("hex.builtin.nodes.control_flow.not.header"_lang,
|
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.not.input"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.not.output"_lang) }) {}
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto input = this->getIntegerOnInput(0);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->setIntegerOnOutput(1, !input);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeGreaterThan : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeGreaterThan() : Node("hex.builtin.nodes.control_flow.gt.header"_lang,
|
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.gt.input.a"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.gt.input.b"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.gt.output"_lang) }) {}
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getIntegerOnInput(0);
|
|
|
|
auto inputB = this->getIntegerOnInput(1);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->setIntegerOnOutput(2, inputA > inputB);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeLessThan : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeLessThan() : Node("hex.builtin.nodes.control_flow.lt.header"_lang,
|
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.lt.input.a"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.lt.input.b"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.lt.output"_lang) }) {}
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getIntegerOnInput(0);
|
|
|
|
auto inputB = this->getIntegerOnInput(1);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->setIntegerOnOutput(2, inputA < inputB);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeBoolAND : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeBoolAND() : Node("hex.builtin.nodes.control_flow.and.header"_lang,
|
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.and.input.a"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.and.input.b"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.and.output"_lang) }) {}
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getIntegerOnInput(0);
|
|
|
|
auto inputB = this->getIntegerOnInput(1);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->setIntegerOnOutput(2, inputA && inputB);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeBoolOR : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeBoolOR() : Node("hex.builtin.nodes.control_flow.or.header"_lang,
|
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.or.input.a"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.or.input.b"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.or.output"_lang) }) {}
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getIntegerOnInput(0);
|
|
|
|
auto inputB = this->getIntegerOnInput(1);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->setIntegerOnOutput(2, inputA || inputB);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-04 00:21:53 +01:00
|
|
|
class NodeCryptoAESDecrypt : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeCryptoAESDecrypt() : Node("hex.builtin.nodes.crypto.aes.header"_lang,
|
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.crypto.aes.key"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.crypto.aes.iv"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.crypto.aes.nonce"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.crypto.aes.input"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.crypto.aes.output"_lang) }) {}
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
void drawNode() override {
|
|
|
|
ImGui::PushItemWidth(100);
|
2021-02-11 23:09:45 +01:00
|
|
|
ImGui::Combo("hex.builtin.nodes.crypto.aes.mode"_lang, &this->m_mode, "ECB\0CBC\0CFB128\0CTR\0GCM\0CCM\0OFB\0");
|
|
|
|
ImGui::Combo("hex.builtin.nodes.crypto.aes.key_length"_lang, &this->m_keyLength, "128 Bits\000192 Bits\000256 Bits\000");
|
2021-02-04 00:21:53 +01:00
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto key = this->getBufferOnInput(0);
|
|
|
|
auto iv = this->getBufferOnInput(1);
|
|
|
|
auto nonce = this->getBufferOnInput(2);
|
|
|
|
auto input = this->getBufferOnInput(3);
|
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
if (key.empty())
|
|
|
|
throwNodeError("Key cannot be empty");
|
2021-02-04 00:21:53 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
if (input.empty())
|
|
|
|
throwNodeError("Input cannot be empty");
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
std::array<u8, 8> ivData = { 0 }, nonceData = { 0 };
|
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
std::copy(iv.begin(), iv.end(), ivData.begin());
|
|
|
|
std::copy(nonce.begin(), nonce.end(), nonceData.begin());
|
2021-02-04 00:21:53 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
auto output = crypt::aesDecrypt(static_cast<crypt::AESMode>(this->m_mode), static_cast<crypt::KeyLength>(this->m_keyLength), key, nonceData, ivData, input);
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
this->setBufferOnOutput(4, output);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_mode = 0;
|
|
|
|
int m_keyLength = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeDecodingBase64 : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeDecodingBase64() : Node("hex.builtin.nodes.decoding.base64.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.decoding.base64.input"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.decoding.base64.output"_lang) }) {}
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto input = this->getBufferOnInput(0);
|
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
auto output = crypt::decode64(input);
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
this->setBufferOnOutput(1, output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeDecodingHex : public dp::Node {
|
|
|
|
public:
|
2021-02-11 23:09:45 +01:00
|
|
|
NodeDecodingHex() : Node("hex.builtin.nodes.decoding.hex.header"_lang, {
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.decoding.hex.input"_lang),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.decoding.hex.output"_lang) }) {}
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto input = this->getBufferOnInput(0);
|
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
if (input.size() % 2 != 0)
|
|
|
|
throwNodeError("Can't decode odd number of hex characters");
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
std::vector<u8> output;
|
2021-02-04 01:14:05 +01:00
|
|
|
for (u32 i = 0; i < input.size(); i += 2) {
|
2021-02-04 12:46:38 +01:00
|
|
|
char c1 = static_cast<char>(std::tolower(input[i]));
|
|
|
|
char c2 = static_cast<char>(std::tolower(input[i + 1]));
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
if (!std::isxdigit(c1) || !isxdigit(c2))
|
2021-02-04 01:14:05 +01:00
|
|
|
throwNodeError("Can't decode non-hexadecimal character");
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
u8 value;
|
|
|
|
if (std::isdigit(c1))
|
|
|
|
value = (c1 - '0') << 4;
|
|
|
|
else
|
|
|
|
value = ((c1 - 'a') + 0x0A) << 4;
|
|
|
|
|
|
|
|
if (std::isdigit(c2))
|
|
|
|
value |= c2 - '0';
|
|
|
|
else
|
|
|
|
value |= (c2 - 'a') + 0x0A;
|
|
|
|
|
|
|
|
output.push_back(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->setBufferOnOutput(1, output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
void registerDataProcessorNodes() {
|
2021-02-11 23:09:45 +01:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeInteger>("hex.builtin.nodes.constants"_lang, "hex.builtin.nodes.constants.int"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeFloat>("hex.builtin.nodes.constants"_lang, "hex.builtin.nodes.constants.float"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeNullptr>("hex.builtin.nodes.constants"_lang, "hex.builtin.nodes.constants.nullptr"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBuffer>("hex.builtin.nodes.constants"_lang, "hex.builtin.nodes.constants.buffer"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeString>("hex.builtin.nodes.constants"_lang, "hex.builtin.nodes.constants.string"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeRGBA8>("hex.builtin.nodes.constants"_lang, "hex.builtin.nodes.constants.rgba8"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeComment>("hex.builtin.nodes.constants"_lang, "hex.builtin.nodes.constants.comment"_lang);
|
|
|
|
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeDisplayInteger>("hex.builtin.nodes.display"_lang, "hex.builtin.nodes.display.int"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeDisplayFloat>("hex.builtin.nodes.display"_lang, "hex.builtin.nodes.display.float"_lang);
|
|
|
|
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeReadData>("hex.builtin.nodes.data_access"_lang, "hex.builtin.nodes.data_access.read"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeWriteData>("hex.builtin.nodes.data_access"_lang, "hex.builtin.nodes.data_access.write"_lang);
|
|
|
|
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeCastIntegerToBuffer>("hex.builtin.nodes.casting"_lang, "hex.builtin.nodes.casting.int_to_buffer"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeCastBufferToInteger>("hex.builtin.nodes.casting"_lang, "hex.builtin.nodes.casting.buffer_to_int"_lang);
|
|
|
|
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeIf>("hex.builtin.nodes.control_flow"_lang, "hex.builtin.nodes.control_flow.if"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeEquals>("hex.builtin.nodes.control_flow"_lang, "hex.builtin.nodes.control_flow.equals"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeNot>("hex.builtin.nodes.control_flow"_lang, "hex.builtin.nodes.control_flow.not"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeGreaterThan>("hex.builtin.nodes.control_flow"_lang, "hex.builtin.nodes.control_flow.gt"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeLessThan>("hex.builtin.nodes.control_flow"_lang, "hex.builtin.nodes.control_flow.lt"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBoolAND>("hex.builtin.nodes.control_flow"_lang, "hex.builtin.nodes.control_flow.and"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBoolOR>("hex.builtin.nodes.control_flow"_lang, "hex.builtin.nodes.control_flow.or"_lang);
|
|
|
|
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBitwiseAND>("hex.builtin.nodes.bitwise"_lang, "hex.builtin.nodes.bitwise.and"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBitwiseOR>("hex.builtin.nodes.bitwise"_lang, "hex.builtin.nodes.bitwise.or"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBitwiseXOR>("hex.builtin.nodes.bitwise"_lang, "hex.builtin.nodes.bitwise.xor"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBitwiseNOT>("hex.builtin.nodes.bitwise"_lang, "hex.builtin.nodes.bitwise.not"_lang);
|
|
|
|
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeDecodingBase64>("hex.builtin.nodes.decoding"_lang, "hex.builtin.nodes.decoding.base64"_lang);
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeDecodingHex>("hex.builtin.nodes.decoding"_lang, "hex.builtin.nodes.decoding.hex"_lang);
|
|
|
|
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeCryptoAESDecrypt>("hex.builtin.nodes.crypto"_lang, "hex.builtin.nodes.crypto.aes"_lang);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|