1
0
mirror of synced 2024-11-13 18:50:53 +01:00

feat: Added various new Copy as... options

This commit is contained in:
WerWolv 2022-09-13 23:48:47 +02:00
parent 9fa6d82775
commit 75047e26e2
9 changed files with 89 additions and 10 deletions

View File

@ -3,6 +3,7 @@
#include <hex/providers/provider.hpp>
#include <hex/providers/buffered_reader.hpp>
#include <hex/helpers/fmt.hpp>
#include <hex/helpers/crypto.hpp>
namespace hex::plugin::builtin {
@ -19,13 +20,14 @@ namespace hex::plugin::builtin {
reader.seek(offset);
reader.setEndAddress(offset + size);
u64 index = 0x00;
for (u8 byte : reader) {
if ((offset % LineLength) == 0x00)
if ((index % LineLength) == 0x00)
result += NewLineIndent;
result += hex::format(byteFormat, byte);
offset++;
index++;
}
// Remove trailing comma
@ -69,6 +71,35 @@ namespace hex::plugin::builtin {
return formatLanguageArray(provider, offset, size, "const data = new Uint8Array([", "0x{0:02X}, ", "]);");
});
ContentRegistry::DataFormatter::add("hex.builtin.view.hex_editor.copy.lua", [](prv::Provider *provider, u64 offset, size_t size) {
return formatLanguageArray(provider, offset, size, "data = {", "0x{0:02X}, ", "}");
});
ContentRegistry::DataFormatter::add("hex.builtin.view.hex_editor.copy.go", [](prv::Provider *provider, u64 offset, size_t size) {
return formatLanguageArray(provider, offset, size, "data := [...]byte {", "0x{0:02X}, ", "}");
});
ContentRegistry::DataFormatter::add("hex.builtin.view.hex_editor.copy.crystal", [](prv::Provider *provider, u64 offset, size_t size) {
return formatLanguageArray(provider, offset, size, "data = [", "0x{0:02X}, ", "] of UInt8");
});
ContentRegistry::DataFormatter::add("hex.builtin.view.hex_editor.copy.swift", [](prv::Provider *provider, u64 offset, size_t size) {
return formatLanguageArray(provider, offset, size, "let data: [Uint8] = [", "0x{0:02X}, ", "]");
});
ContentRegistry::DataFormatter::add("hex.builtin.view.hex_editor.copy.pascal", [](prv::Provider *provider, u64 offset, size_t size) {
return formatLanguageArray(provider, offset, size, hex::format("data: array[0..{0}] of Byte = (", size - 1), "${0:02X}, ", ")");
});
ContentRegistry::DataFormatter::add("hex.builtin.view.hex_editor.copy.base64", [](prv::Provider *provider, u64 offset, size_t size) {
std::vector<u8> data(size, 0x00);
provider->read(offset, data.data(), size);
auto result = crypt::encode64(data);
return std::string(result.begin(), result.end());
});
ContentRegistry::DataFormatter::add("hex.builtin.view.hex_editor.copy.ascii", [](prv::Provider *provider, u64 offset, size_t size) {
constexpr static auto HeaderLine = "Hex View 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n";
std::string result;

View File

@ -293,7 +293,13 @@ namespace hex::plugin::builtin {
{ "hex.builtin.view.hex_editor.copy.python", "Python Array" },
{ "hex.builtin.view.hex_editor.copy.java", "Java Array" },
{ "hex.builtin.view.hex_editor.copy.js", "JavaScript Array" },
{ "hex.builtin.view.hex_editor.copy.ascii", "ASCII Art" },
{ "hex.builtin.view.hex_editor.copy.lua", "Lua Array" },
{ "hex.builtin.view.hex_editor.copy.go", "Go Array" },
{ "hex.builtin.view.hex_editor.copy.crystal", "Crystal Array" },
{ "hex.builtin.view.hex_editor.copy.swift", "Swift Array" },
{ "hex.builtin.view.hex_editor.copy.pascal", "Pascal Array" },
{ "hex.builtin.view.hex_editor.copy.base64", "Base64" },
{ "hex.builtin.view.hex_editor.copy.ascii", "Text Area" },
{ "hex.builtin.view.hex_editor.copy.html", "HTML" },
{ "hex.builtin.view.hex_editor.menu.edit.paste", "Einfügen" },
{ "hex.builtin.view.hex_editor.menu.edit.select_all", "Alles auswählen" },

View File

@ -297,7 +297,13 @@ namespace hex::plugin::builtin {
{ "hex.builtin.view.hex_editor.copy.python", "Python Array" },
{ "hex.builtin.view.hex_editor.copy.java", "Java Array" },
{ "hex.builtin.view.hex_editor.copy.js", "JavaScript Array" },
{ "hex.builtin.view.hex_editor.copy.ascii", "ASCII Art" },
{ "hex.builtin.view.hex_editor.copy.lua", "Lua Array" },
{ "hex.builtin.view.hex_editor.copy.go", "Go Array" },
{ "hex.builtin.view.hex_editor.copy.crystal", "Crystal Array" },
{ "hex.builtin.view.hex_editor.copy.swift", "Swift Array" },
{ "hex.builtin.view.hex_editor.copy.pascal", "Pascal Array" },
{ "hex.builtin.view.hex_editor.copy.base64", "Base64" },
{ "hex.builtin.view.hex_editor.copy.ascii", "Text Area" },
{ "hex.builtin.view.hex_editor.copy.html", "HTML" },
{ "hex.builtin.view.hex_editor.menu.edit.paste", "Paste" },
{ "hex.builtin.view.hex_editor.menu.edit.select_all", "Select all" },

View File

@ -298,7 +298,13 @@ namespace hex::plugin::builtin {
{ "hex.builtin.view.hex_editor.copy.python", "Python Array" },
{ "hex.builtin.view.hex_editor.copy.java", "Java Array" },
{ "hex.builtin.view.hex_editor.copy.js", "JavaScript Array" },
{ "hex.builtin.view.hex_editor.copy.ascii", "ASCII Art" },
{ "hex.builtin.view.hex_editor.copy.lua", "Lua Array" },
{ "hex.builtin.view.hex_editor.copy.go", "Go Array" },
{ "hex.builtin.view.hex_editor.copy.crystal", "Crystal Array" },
{ "hex.builtin.view.hex_editor.copy.swift", "Swift Array" },
{ "hex.builtin.view.hex_editor.copy.pascal", "Pascal Array" },
{ "hex.builtin.view.hex_editor.copy.base64", "Base64" },
//{ "hex.builtin.view.hex_editor.copy.ascii", "Text Area" },
{ "hex.builtin.view.hex_editor.copy.html", "HTML" },
{ "hex.builtin.view.hex_editor.menu.edit.paste", "Incolla" },
{ "hex.builtin.view.hex_editor.menu.edit.select_all", "Seleziona tutti" },

View File

@ -297,7 +297,13 @@ namespace hex::plugin::builtin {
{ "hex.builtin.view.hex_editor.copy.python", "Python 配列" },
{ "hex.builtin.view.hex_editor.copy.java", "Java 配列" },
{ "hex.builtin.view.hex_editor.copy.js", "JavaScript 配列" },
{ "hex.builtin.view.hex_editor.copy.ascii", "アスキーアート" },
{ "hex.builtin.view.hex_editor.copy.lua", "Lua 配列" },
{ "hex.builtin.view.hex_editor.copy.go", "Go 配列" },
{ "hex.builtin.view.hex_editor.copy.crystal", "Crystal 配列" },
{ "hex.builtin.view.hex_editor.copy.swift", "Swift 配列" },
{ "hex.builtin.view.hex_editor.copy.pascal", "Pascal 配列" },
{ "hex.builtin.view.hex_editor.copy.base64", "Base64" },
//{ "hex.builtin.view.hex_editor.copy.ascii", "Text Area" },
{ "hex.builtin.view.hex_editor.copy.html", "HTML" },
{ "hex.builtin.view.hex_editor.menu.edit.paste", "貼り付け" },
{ "hex.builtin.view.hex_editor.menu.edit.select_all", "すべて選択" },

View File

@ -296,7 +296,13 @@ namespace hex::plugin::builtin {
{ "hex.builtin.view.hex_editor.copy.python", "Python 배열" },
{ "hex.builtin.view.hex_editor.copy.java", "Java 배열" },
{ "hex.builtin.view.hex_editor.copy.js", "JavaScript 배열" },
{ "hex.builtin.view.hex_editor.copy.ascii", "ASCII 아트" },
{ "hex.builtin.view.hex_editor.copy.lua", "Lua 배열" },
{ "hex.builtin.view.hex_editor.copy.go", "Go 배열" },
{ "hex.builtin.view.hex_editor.copy.crystal", "Crystal 배열" },
{ "hex.builtin.view.hex_editor.copy.swift", "Swift 배열" },
{ "hex.builtin.view.hex_editor.copy.pascal", "Pascal 배열" },
{ "hex.builtin.view.hex_editor.copy.base64", "Base64" },
//{ "hex.builtin.view.hex_editor.copy.ascii", "Text Area" },
{ "hex.builtin.view.hex_editor.copy.html", "HTML" },
{ "hex.builtin.view.hex_editor.menu.edit.paste", "붙여넣기" },
{ "hex.builtin.view.hex_editor.menu.edit.select_all", "모두 선택하기" },

View File

@ -295,7 +295,13 @@ namespace hex::plugin::builtin {
{ "hex.builtin.view.hex_editor.copy.python", "Python Array" },
{ "hex.builtin.view.hex_editor.copy.java", "Java Array" },
{ "hex.builtin.view.hex_editor.copy.js", "JavaScript Array" },
{ "hex.builtin.view.hex_editor.copy.ascii", "ASCII Art" },
{ "hex.builtin.view.hex_editor.copy.lua", "Lua Array" },
{ "hex.builtin.view.hex_editor.copy.go", "Go Array" },
{ "hex.builtin.view.hex_editor.copy.crystal", "Crystal Array" },
{ "hex.builtin.view.hex_editor.copy.swift", "Swift Array" },
{ "hex.builtin.view.hex_editor.copy.pascal", "Pascal Array" },
{ "hex.builtin.view.hex_editor.copy.base64", "Base64" },
//{ "hex.builtin.view.hex_editor.copy.ascii", "Text Area" },
{ "hex.builtin.view.hex_editor.copy.html", "HTML" },
{ "hex.builtin.view.hex_editor.menu.edit.paste", "Colar" },
{ "hex.builtin.view.hex_editor.menu.edit.select_all", "Selecionar tudo" },

View File

@ -298,7 +298,13 @@ namespace hex::plugin::builtin {
{ "hex.builtin.view.hex_editor.copy.python", "Python 数组" },
{ "hex.builtin.view.hex_editor.copy.java", "Java 数组" },
{ "hex.builtin.view.hex_editor.copy.js", "JavaScript 数组" },
{ "hex.builtin.view.hex_editor.copy.ascii", "Hex DumpASCII 艺术)" },
{ "hex.builtin.view.hex_editor.copy.lua", "Lua 数组" },
{ "hex.builtin.view.hex_editor.copy.go", "Go 数组" },
{ "hex.builtin.view.hex_editor.copy.crystal", "Crystal 数组" },
{ "hex.builtin.view.hex_editor.copy.swift", "Swift 数组" },
{ "hex.builtin.view.hex_editor.copy.pascal", "Pascal 数组" },
{ "hex.builtin.view.hex_editor.copy.base64", "Base64" },
//{ "hex.builtin.view.hex_editor.copy.ascii", "Text Area" },
{ "hex.builtin.view.hex_editor.copy.html", "HTML" },
{ "hex.builtin.view.hex_editor.menu.edit.paste", "粘贴" },
{ "hex.builtin.view.hex_editor.menu.edit.select_all", "全选" },

View File

@ -295,7 +295,13 @@ namespace hex::plugin::builtin {
{ "hex.builtin.view.hex_editor.copy.python", "Python 陣列" },
{ "hex.builtin.view.hex_editor.copy.java", "Java 陣列" },
{ "hex.builtin.view.hex_editor.copy.js", "JavaScript 陣列" },
{ "hex.builtin.view.hex_editor.copy.ascii", "ASCII 畫" },
{ "hex.builtin.view.hex_editor.copy.lua", "Lua 陣列" },
{ "hex.builtin.view.hex_editor.copy.go", "Go 陣列" },
{ "hex.builtin.view.hex_editor.copy.crystal", "Crystal 陣列" },
{ "hex.builtin.view.hex_editor.copy.swift", "Swift 陣列" },
{ "hex.builtin.view.hex_editor.copy.pascal", "Pascal 陣列" },
{ "hex.builtin.view.hex_editor.copy.base64", "Base64" },
// { "hex.builtin.view.hex_editor.copy.ascii", "Text Area" },
{ "hex.builtin.view.hex_editor.copy.html", "HTML" },
{ "hex.builtin.view.hex_editor.menu.edit.paste", "貼上" },
{ "hex.builtin.view.hex_editor.menu.edit.select_all", "全選" },