mirror of https://github.com/WerWolv/ImHex.git
tools: Added UNIX permissions calculator
This commit is contained in:
parent
fcb00292a5
commit
07ad9ed772
|
@ -340,6 +340,65 @@ namespace hex::plugin::builtin {
|
|||
|
||||
}
|
||||
|
||||
void drawPermissionsCalculator() {
|
||||
static bool setuid, setgid, sticky;
|
||||
static bool r[3], w[3], x[3];
|
||||
|
||||
ImGui::TextUnformatted("hex.builtin.tools.permissions.perm_bits"_lang);
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::BeginTable("Permissions", 4, ImGuiTableFlags_Borders)) {
|
||||
ImGui::TableSetupScrollFreeze(0, 1);
|
||||
ImGui::TableSetupColumn("Special", ImGuiTableColumnFlags_NoSort);
|
||||
ImGui::TableSetupColumn("User", ImGuiTableColumnFlags_NoSort);
|
||||
ImGui::TableSetupColumn("Group", ImGuiTableColumnFlags_NoSort);
|
||||
ImGui::TableSetupColumn("Other", ImGuiTableColumnFlags_NoSort);
|
||||
|
||||
ImGui::TableHeadersRow();
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::Checkbox("setuid", &setuid);
|
||||
ImGui::Checkbox("setgid", &setgid);
|
||||
ImGui::Checkbox("Sticky bit", &sticky);
|
||||
|
||||
for (u8 i = 0; i < 3; i++) {
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::PushID(i);
|
||||
ImGui::Checkbox("Read", &r[i]);
|
||||
ImGui::Checkbox("Write", &w[i]);
|
||||
ImGui::Checkbox("Execute", &x[i]);
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::NewLine();
|
||||
ImGui::TextUnformatted("hex.builtin.tools.permissions.absolute"_lang);
|
||||
ImGui::Separator();
|
||||
|
||||
auto result = hex::format("{}{}{}{}",
|
||||
(setuid << 2) | (setgid << 1) | (sticky << 0),
|
||||
(r[0] << 2) | (w[0] << 1) | (x[0] << 0),
|
||||
(r[1] << 2) | (w[1] << 1) | (x[1] << 0),
|
||||
(r[2] << 2) | (w[2] << 1) | (x[2] << 0));
|
||||
ImGui::InputText("##permissions_absolute", result.data(), result.size(), ImGuiInputTextFlags_ReadOnly);
|
||||
|
||||
ImGui::NewLine();
|
||||
|
||||
static const auto WarningColor = ImColor(0.92F, 0.25F, 0.2F, 1.0F);
|
||||
if (setuid && !x[0])
|
||||
ImGui::TextColored(WarningColor, "hex.builtin.tools.permissions.setuid_error"_lang);
|
||||
if (setgid && !x[1])
|
||||
ImGui::TextColored(WarningColor, "hex.builtin.tools.permissions.setgid_error"_lang);
|
||||
if (sticky && !x[2])
|
||||
ImGui::TextColored(WarningColor, "hex.builtin.tools.permissions.sticky_error"_lang);
|
||||
|
||||
}
|
||||
|
||||
void registerToolEntries() {
|
||||
ContentRegistry::Tools::add("hex.builtin.tools.demangler", drawDemangler);
|
||||
ContentRegistry::Tools::add("hex.builtin.tools.ascii_table", drawASCIITable);
|
||||
|
@ -347,6 +406,7 @@ namespace hex::plugin::builtin {
|
|||
ContentRegistry::Tools::add("hex.builtin.tools.color", drawColorPicker);
|
||||
ContentRegistry::Tools::add("hex.builtin.tools.calc", drawMathEvaluator);
|
||||
ContentRegistry::Tools::add("hex.builtin.tools.base_converter", drawBaseConverter);
|
||||
ContentRegistry::Tools::add("hex.builtin.tools.permissions", drawPermissionsCalculator);
|
||||
}
|
||||
|
||||
}
|
|
@ -518,6 +518,12 @@ namespace hex::plugin::builtin {
|
|||
{ "hex.builtin.tools.base_converter.hex", "HEX" },
|
||||
{ "hex.builtin.tools.base_converter.oct", "OCT" },
|
||||
{ "hex.builtin.tools.base_converter.bin", "BIN" },
|
||||
{ "hex.builtin.tools.permissions", "UNIX Berechtigungsrechner" },
|
||||
{ "hex.builtin.tools.permissions.perm_bits", "Berechtigungs bits" },
|
||||
{ "hex.builtin.tools.permissions.absolute", "Absolute Notation" },
|
||||
{ "hex.builtin.tools.permissions.setuid_error", "User benötigt execute Rechte, damit setuid bit gilt!" },
|
||||
{ "hex.builtin.tools.permissions.setgid_error", "Group benötigt execute Rechte, damit setgid bit gilt!" },
|
||||
{ "hex.builtin.tools.permissions.sticky_error", "Other benötigt execute Rechte, damit sticky bit gilt!" },
|
||||
|
||||
{ "hex.builtin.setting.imhex", "ImHex" },
|
||||
{ "hex.builtin.setting.imhex.recent_files", "Kürzlich geöffnete Dateien" },
|
||||
|
|
|
@ -518,6 +518,12 @@ namespace hex::plugin::builtin {
|
|||
{ "hex.builtin.tools.base_converter.hex", "HEX" },
|
||||
{ "hex.builtin.tools.base_converter.oct", "OCT" },
|
||||
{ "hex.builtin.tools.base_converter.bin", "BIN" },
|
||||
{ "hex.builtin.tools.permissions", "UNIX Permissions Calculator" },
|
||||
{ "hex.builtin.tools.permissions.perm_bits", "Permission bits" },
|
||||
{ "hex.builtin.tools.permissions.absolute", "Absolute Notation" },
|
||||
{ "hex.builtin.tools.permissions.setuid_error", "User must have execute rights for setuid bit to apply!" },
|
||||
{ "hex.builtin.tools.permissions.setgid_error", "Group must have execute rights for setgid bit to apply!" },
|
||||
{ "hex.builtin.tools.permissions.sticky_error", "Other must have execute rights for sticky bit to apply!" },
|
||||
|
||||
{ "hex.builtin.setting.imhex", "ImHex" },
|
||||
{ "hex.builtin.setting.imhex.recent_files", "Recent Files" },
|
||||
|
|
|
@ -518,6 +518,12 @@ namespace hex::plugin::builtin {
|
|||
{ "hex.builtin.tools.base_converter.hex", "HEX" },
|
||||
{ "hex.builtin.tools.base_converter.oct", "OCT" },
|
||||
{ "hex.builtin.tools.base_converter.bin", "BIN" },
|
||||
//{ "hex.builtin.tools.permissions", "UNIX Permissions Calculator" },
|
||||
//{ "hex.builtin.tools.permissions.perm_bits", "Permission bits" },
|
||||
//{ "hex.builtin.tools.permissions.absolute", "Absolute Notation" },
|
||||
//{ "hex.builtin.tools.permissions.setuid_error", "User must have execute rights for setuid bit to apply!" },
|
||||
//{ "hex.builtin.tools.permissions.setgid_error", "Group must have execute rights for setgid bit to apply!" },
|
||||
//{ "hex.builtin.tools.permissions.sticky_error", "Other must have execute rights for sticky bit to apply!" },
|
||||
|
||||
{ "hex.builtin.setting.imhex", "ImHex" },
|
||||
{ "hex.builtin.setting.imhex.recent_files", "File recenti" },
|
||||
|
|
|
@ -83,7 +83,7 @@ namespace hex::prv {
|
|||
}
|
||||
|
||||
void FileProvider::resize(ssize_t newSize) {
|
||||
close();
|
||||
this->close();
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
std::wstring widePath;
|
||||
|
@ -106,12 +106,12 @@ namespace hex::prv {
|
|||
#else
|
||||
auto handle = ::open(this->m_path.data(), 0644);
|
||||
|
||||
ftruncate(handle, newSize - 1);
|
||||
::ftruncate(handle, newSize - 1);
|
||||
|
||||
close(handle);
|
||||
::close(handle);
|
||||
#endif
|
||||
|
||||
open();
|
||||
this->open();
|
||||
}
|
||||
|
||||
size_t FileProvider::getActualSize() {
|
||||
|
@ -198,7 +198,7 @@ namespace hex::prv {
|
|||
#else
|
||||
this->m_file = ::open(this->m_path.data(), O_RDWR);
|
||||
if (this->m_file == -1) {
|
||||
this->m_file = ::open(path.data(), O_RDONLY);
|
||||
this->m_file = ::open(this->m_path.data(), O_RDONLY);
|
||||
this->m_writable = false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue