2020-11-14 21:16:03 +01:00
|
|
|
#include "views/view_help.hpp"
|
|
|
|
|
2021-01-27 00:00:20 +01:00
|
|
|
#include <imgui_imhex_extensions.h>
|
|
|
|
|
2020-11-14 21:16:03 +01:00
|
|
|
namespace hex {
|
|
|
|
|
2020-11-23 23:57:19 +01:00
|
|
|
ViewHelp::ViewHelp() : View("Help") {
|
2020-11-14 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewHelp::~ViewHelp() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-30 21:44:40 +01:00
|
|
|
|
|
|
|
static void drawTitle(const std::string &title) {
|
|
|
|
ImGui::TextColored(ImVec4(0.6F, 0.6F, 1.0F, 1.0F), title.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void drawCodeSegment(const std::string &id, const std::string &code) {
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.2F, 0.2F, 0.2F, 0.3F));
|
|
|
|
ImGui::BeginChild(id.c_str(), ImVec2(-1, ImGui::CalcTextSize(code.c_str()).y));
|
|
|
|
|
|
|
|
ImGui::Text("%s", code.c_str());
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
};
|
|
|
|
|
2020-11-14 21:16:03 +01:00
|
|
|
|
2020-12-11 14:24:42 +01:00
|
|
|
void ViewHelp::drawAboutPopup() {
|
|
|
|
if (ImGui::BeginPopupModal("About", &this->m_aboutWindowOpen, ImGuiWindowFlags_AlwaysAutoResize)) {
|
2021-01-23 00:46:50 +01:00
|
|
|
ImGui::Text("ImHex Hex Editor v%s by WerWolv -", IMHEX_VERSION);
|
2021-01-10 22:57:57 +01:00
|
|
|
#if defined(GIT_BRANCH) && defined(GIT_COMMIT_HASH)
|
2021-01-27 00:00:20 +01:00
|
|
|
ImGui::SameLine();
|
|
|
|
if (ImGui::Hyperlink(hex::format("%s@%s", GIT_BRANCH, GIT_COMMIT_HASH).c_str()))
|
|
|
|
hex::openWebpage("https://github.com/WerWolv/ImHex/commit/" GIT_COMMIT_HASH);
|
2021-01-10 22:57:57 +01:00
|
|
|
#endif
|
2021-01-23 00:46:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
ImGui::TextUnformatted("Source code available on GitHub:"); ImGui::SameLine();
|
2021-01-27 00:00:20 +01:00
|
|
|
if (ImGui::Hyperlink("WerWolv/ImHex"))
|
|
|
|
hex::openWebpage("https://github.com/WerWolv/ImHex");
|
2020-11-14 21:16:03 +01:00
|
|
|
ImGui::NewLine();
|
|
|
|
|
2021-01-23 00:46:50 +01:00
|
|
|
ImGui::Text("Donations");
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
constexpr const char* Links[] = { "https://werwolv.net/donate", "https://www.patreon.com/werwolv", "https://github.com/sponsors/WerWolv" };
|
|
|
|
|
|
|
|
ImGui::TextWrapped("If you like my work, please consider donating to keep the project going. Thanks a lot <3");
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
for (auto &link : Links) {
|
2021-01-27 00:00:20 +01:00
|
|
|
if (ImGui::Hyperlink(link))
|
|
|
|
hex::openWebpage(link);
|
2021-01-23 00:46:50 +01:00
|
|
|
}
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
2020-11-14 21:16:03 +01:00
|
|
|
ImGui::Text("Libraries used");
|
2020-12-21 11:24:27 +01:00
|
|
|
ImGui::Separator();
|
2020-11-14 21:16:03 +01:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.2F, 0.2F, 0.2F, 0.3F));
|
|
|
|
ImGui::BulletText("ImGui by ocornut");
|
|
|
|
ImGui::BulletText("imgui_club by ocornut");
|
2020-11-17 15:38:42 +01:00
|
|
|
ImGui::BulletText("ImGui-Addons by gallickgunner");
|
2020-11-20 18:24:59 +01:00
|
|
|
ImGui::BulletText("ImGuiColorTextEdit by BalazsJako");
|
2020-11-22 23:07:50 +01:00
|
|
|
ImGui::BulletText("capstone by aquynh");
|
2020-11-30 21:44:40 +01:00
|
|
|
ImGui::BulletText("JSON for Modern C++ by nlohmann");
|
2020-11-14 21:16:03 +01:00
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::BulletText("GNU libmagic");
|
|
|
|
ImGui::BulletText("OpenSSL libcrypto");
|
|
|
|
ImGui::BulletText("GLFW3");
|
2020-11-30 21:44:40 +01:00
|
|
|
ImGui::BulletText("LLVM");
|
|
|
|
ImGui::BulletText("Python 3");
|
2020-12-21 11:24:27 +01:00
|
|
|
ImGui::BulletText("FreeType");
|
2020-11-14 21:16:03 +01:00
|
|
|
|
|
|
|
ImGui::PopStyleColor();
|
2021-01-14 17:01:44 +01:00
|
|
|
|
|
|
|
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
|
2020-11-14 21:16:03 +01:00
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewHelp::drawPatternHelpPopup() {
|
2020-12-05 11:34:49 +01:00
|
|
|
if (!this->m_patternHelpWindowOpen) return;
|
|
|
|
|
2020-11-14 21:16:03 +01:00
|
|
|
ImGui::SetNextWindowSizeConstraints(ImVec2(450, 300), ImVec2(2000, 1000));
|
2020-12-05 11:34:49 +01:00
|
|
|
if (ImGui::Begin("Pattern Language Cheat Sheet", &this->m_patternHelpWindowOpen)) {
|
2020-11-14 21:16:03 +01:00
|
|
|
ImGui::Text("ImHex Pattern Language Cheat Sheet");
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
2020-11-30 21:44:40 +01:00
|
|
|
drawTitle("Preprocessor directives");
|
2020-11-17 13:59:16 +01:00
|
|
|
ImGui::TextWrapped(
|
|
|
|
"Preprocessor directives can be used to alter the code before it's being parsed. Supported are "
|
|
|
|
"#define to replace one string with another and #include to include a separate file");
|
2020-11-30 21:44:40 +01:00
|
|
|
drawCodeSegment("preprocessor",
|
2020-11-17 13:59:16 +01:00
|
|
|
"#define HEADER_OFFSET 0x100\n"
|
|
|
|
"#include <cstdint.hexpat>\n"
|
|
|
|
"#include \"mypattern.hexpat\""
|
|
|
|
);
|
|
|
|
|
2020-11-30 21:44:40 +01:00
|
|
|
drawTitle("Pragma directives");
|
2020-11-22 11:20:01 +01:00
|
|
|
ImGui::TextWrapped(
|
|
|
|
"Pragma directives are used to give ImHex additional information about the code being read. Currently "
|
|
|
|
"the following directives are supported.");
|
2020-11-30 21:44:40 +01:00
|
|
|
drawCodeSegment("pragma",
|
|
|
|
"// Allow this file to be loaded as pattern when a file\n"
|
|
|
|
"// identified as application/x-executable gets loaded\n"
|
2020-11-22 11:20:01 +01:00
|
|
|
"#pragma MIME application/x-executable\n"
|
|
|
|
);
|
|
|
|
|
2020-11-30 21:44:40 +01:00
|
|
|
drawTitle("Built-in types");
|
2020-11-14 21:16:03 +01:00
|
|
|
ImGui::TextWrapped(
|
|
|
|
"The following built-in types are available for use");
|
2020-11-30 21:44:40 +01:00
|
|
|
drawCodeSegment("built-in",
|
2020-11-14 21:16:03 +01:00
|
|
|
"u8, s8\n"
|
|
|
|
"u16, s16\n"
|
|
|
|
"u32, s32\n"
|
|
|
|
"u64, s64\n"
|
|
|
|
"u128, s128\n"
|
|
|
|
"float, double"
|
|
|
|
);
|
|
|
|
|
2020-11-30 21:44:40 +01:00
|
|
|
drawTitle("Variables and Arrays");
|
2020-11-14 21:16:03 +01:00
|
|
|
ImGui::TextWrapped(
|
2020-11-22 11:20:01 +01:00
|
|
|
"Normal variables as well as arrays are used to highlight and display values. "
|
|
|
|
"It is possible to create arrays within structs and unions that use the value of a previously "
|
2020-12-06 21:40:57 +01:00
|
|
|
"declared variable as size. In order to override the native / globally set endianess setting, every "
|
|
|
|
"type in a variable declaration may be prefixed with be or le to turn only it into a big or little endian type.");
|
2020-11-30 21:44:40 +01:00
|
|
|
drawCodeSegment("vars arrays",
|
2020-11-14 21:16:03 +01:00
|
|
|
"u32 variable;\n"
|
2020-11-22 11:20:01 +01:00
|
|
|
"s8 string[16];\n"
|
2020-12-06 21:40:57 +01:00
|
|
|
"u8 customSizedArray[variable];\n"
|
|
|
|
"be u32 bigEndianVariable;"
|
2020-11-14 21:16:03 +01:00
|
|
|
);
|
|
|
|
|
2020-11-30 21:44:40 +01:00
|
|
|
drawTitle("Structs");
|
2020-11-14 21:16:03 +01:00
|
|
|
ImGui::TextWrapped(
|
2020-11-20 22:21:37 +01:00
|
|
|
"To bundle multiple variables together, a struct can be used. To insert padding bytes which won't show "
|
|
|
|
"up in the pattern data view or be highlighted, use the padding[size] syntax.");
|
2020-11-30 21:44:40 +01:00
|
|
|
drawCodeSegment("struct",
|
2020-11-14 21:16:03 +01:00
|
|
|
"struct Header {\n"
|
|
|
|
" u32 magic;\n"
|
|
|
|
" u8 version;\n"
|
2020-11-20 22:21:37 +01:00
|
|
|
" padding[4];\n"
|
2020-11-14 21:16:03 +01:00
|
|
|
" Flags flags;\n"
|
2020-11-22 11:20:01 +01:00
|
|
|
"};"
|
2020-11-14 21:16:03 +01:00
|
|
|
);
|
|
|
|
|
2020-11-30 21:44:40 +01:00
|
|
|
drawTitle("Unions");
|
2020-11-20 22:21:37 +01:00
|
|
|
ImGui::TextWrapped(
|
|
|
|
"A union is used to make two or more variables occupy the same region of memory. "
|
|
|
|
"The union will have the size of the biggest contained variable.");
|
2020-11-30 21:44:40 +01:00
|
|
|
drawCodeSegment("union",
|
2020-11-20 22:21:37 +01:00
|
|
|
"union Color {\n"
|
|
|
|
" u32 rgba;\n"
|
|
|
|
" Components components;\n"
|
2020-11-22 11:20:01 +01:00
|
|
|
"};"
|
|
|
|
);
|
|
|
|
|
2020-11-30 21:44:40 +01:00
|
|
|
drawTitle("Pointers");
|
2020-11-22 11:20:01 +01:00
|
|
|
ImGui::TextWrapped(
|
|
|
|
"\"Another possible type of member in structs and unions are pointers. They are variables"
|
|
|
|
"whose value is used as an offset from the start of the file to locate the actual offset. "
|
|
|
|
"The leading type is treated as the data being pointed to and the trailing type as the size of the pointer.");
|
2020-11-30 21:44:40 +01:00
|
|
|
drawCodeSegment("pointer",
|
2020-11-22 11:20:01 +01:00
|
|
|
"Data *data : u16;"
|
2020-11-20 22:21:37 +01:00
|
|
|
);
|
|
|
|
|
2020-11-30 21:44:40 +01:00
|
|
|
drawTitle("Bitfields");
|
2020-11-20 20:26:19 +01:00
|
|
|
ImGui::TextWrapped(
|
|
|
|
"To decode values that are stored in fields that don't follow the typical 8 bit alignment, bitfields can be used. "
|
|
|
|
"The size of these fields get specified in numbers of bits.");
|
2020-11-30 21:44:40 +01:00
|
|
|
drawCodeSegment("bitfield",
|
2020-11-20 20:26:19 +01:00
|
|
|
"bitfield Permission {\n"
|
|
|
|
" r : 1;\n"
|
|
|
|
" w : 1;\n"
|
|
|
|
" x : 1;\n"
|
2020-11-22 11:20:01 +01:00
|
|
|
"};"
|
2020-11-20 20:26:19 +01:00
|
|
|
);
|
|
|
|
|
2020-11-30 21:44:40 +01:00
|
|
|
drawTitle("Enum");
|
2020-11-14 21:16:03 +01:00
|
|
|
ImGui::TextWrapped(
|
|
|
|
"If a value can only be a few specific values with special meaning, an enum can be used. "
|
|
|
|
"The underlying type has to be specified using a unsigned, built-in type after the name. "
|
|
|
|
"Entries can be listed with or without a value. The values start counting at zero and increase by one "
|
|
|
|
"for every next entry");
|
2020-11-30 21:44:40 +01:00
|
|
|
drawCodeSegment("enum",
|
2020-11-14 21:16:03 +01:00
|
|
|
"enum OperatingSystem : u8 {\n"
|
|
|
|
" Windows = 0x10,\n"
|
|
|
|
" MacOSX,\n"
|
2020-11-30 21:44:40 +01:00
|
|
|
" Linux = 'L'\n"
|
2020-11-22 11:20:01 +01:00
|
|
|
"};"
|
2020-11-14 21:16:03 +01:00
|
|
|
);
|
|
|
|
|
2020-11-30 21:44:40 +01:00
|
|
|
drawTitle("Using declarations");
|
2020-11-14 21:16:03 +01:00
|
|
|
ImGui::TextWrapped(
|
|
|
|
"A using declaration can be used to create type aliases for already existing types. This can be "
|
|
|
|
"a built-in type, a struct, enum or another alias type.");
|
2020-11-30 21:44:40 +01:00
|
|
|
drawCodeSegment("using",
|
2020-11-14 21:16:03 +01:00
|
|
|
"using magic_t = u32;"
|
|
|
|
);
|
|
|
|
|
2020-11-30 21:44:40 +01:00
|
|
|
drawTitle("Comments");
|
2020-11-14 21:16:03 +01:00
|
|
|
ImGui::TextWrapped(
|
|
|
|
"To create a comment the C // or /* */ syntax can be used. //-style comments end at the next new line "
|
|
|
|
"and /*-style comments only end when at the next */.");
|
2020-11-30 21:44:40 +01:00
|
|
|
drawCodeSegment("comment",
|
2020-11-14 21:16:03 +01:00
|
|
|
"// This is a single line comment\n\n"
|
|
|
|
"/* This is a\n"
|
|
|
|
"multiline comment */"
|
|
|
|
);
|
|
|
|
|
2020-11-30 21:44:40 +01:00
|
|
|
drawTitle("Variable placement");
|
2020-11-14 21:16:03 +01:00
|
|
|
ImGui::TextWrapped(
|
|
|
|
"In order to highlight bytes and displaying their value in the pattern data window, "
|
|
|
|
"a variable needs to be created and placed in memory. The following line of code creates"
|
|
|
|
"a unsigned 32 bit variable named data and places it at offset 0x100."
|
|
|
|
);
|
2020-11-30 21:44:40 +01:00
|
|
|
drawCodeSegment("var placement", "u32 data @ 0x100;");
|
|
|
|
}
|
2020-12-05 11:34:49 +01:00
|
|
|
ImGui::End();
|
2020-11-30 21:44:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewHelp::drawMathEvaluatorHelp() {
|
2020-12-05 11:34:49 +01:00
|
|
|
if (!this->m_mathHelpWindowOpen) return;
|
2020-11-30 21:44:40 +01:00
|
|
|
|
|
|
|
ImGui::SetNextWindowSizeConstraints(ImVec2(450, 300), ImVec2(2000, 1000));
|
2020-12-05 11:34:49 +01:00
|
|
|
if (ImGui::Begin("Calculator Cheat Sheet", &this->m_mathHelpWindowOpen)) {
|
2020-11-30 21:44:40 +01:00
|
|
|
ImGui::Text("ImHex Math Evaluator Cheat Sheet");
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
ImGui::TextWrapped("ImGui has a simple math evaluator / calculator built-in. It works by parsing the "
|
|
|
|
"expressions passed to it and displaying the result in the History table.");
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
drawTitle("Basic Operators");
|
|
|
|
ImGui::TextWrapped(
|
|
|
|
"The following basic mathematical operators are supported");
|
|
|
|
drawCodeSegment("basicOperators",
|
|
|
|
"+ : Addition\n"
|
|
|
|
"- : Subtraction\n"
|
|
|
|
"* : Multiplication\n"
|
|
|
|
"/ : Division\n"
|
|
|
|
"% : Modulus\n"
|
|
|
|
"** : Exponentiation\n"
|
|
|
|
"() : Brackets\n"
|
|
|
|
"x = : Variable assignment");
|
|
|
|
|
|
|
|
drawTitle("Bitwise Operators");
|
|
|
|
ImGui::TextWrapped(
|
|
|
|
"The following bitwise operators are supported");
|
|
|
|
drawCodeSegment("bitwiseOperators",
|
|
|
|
"& : Bitwise AND\n"
|
|
|
|
"| : Bitwise OR\n"
|
|
|
|
"^ : Bitwise XOR\n"
|
|
|
|
"~ : Bitwise NOT\n"
|
|
|
|
"<< : Logical shift left\n"
|
|
|
|
">> : Logical shift right\n"
|
|
|
|
"## : Bitwise concatenation");
|
|
|
|
|
|
|
|
drawTitle("Boolean Operators");
|
|
|
|
ImGui::TextWrapped(
|
|
|
|
"The following bitwise operators are supported");
|
|
|
|
drawCodeSegment("booleanOperators",
|
|
|
|
"&& : Boolean AND\n"
|
|
|
|
"|| : Boolean OR\n"
|
|
|
|
"^^ : Boolean XOR\n"
|
|
|
|
"! : Boolean NOT\n"
|
|
|
|
"== : Equality comparison\n"
|
|
|
|
"!= : Inequality comparison\n"
|
|
|
|
"> : Greater than comparison\n"
|
|
|
|
"< : Less than comparison\n"
|
|
|
|
">= : Greater than or equals comparison\n"
|
|
|
|
"<= : Less than or equals comparison");
|
|
|
|
|
|
|
|
drawTitle("Built-in Functions");
|
|
|
|
ImGui::TextWrapped(
|
|
|
|
"The following functions are built into the evaluator");
|
|
|
|
drawCodeSegment("functions",
|
|
|
|
"sin(x) : Sine function\n"
|
|
|
|
"cos(x) : Cosine function\n"
|
|
|
|
"tan(x) : Tangent function\n"
|
|
|
|
"ceil(x) : Rounds value to next bigger integer\n"
|
|
|
|
"floor(x) : Rounds value to next smaller integer\n"
|
|
|
|
"sign(x) : Returns the value's sign\n"
|
|
|
|
"abs(x) : Absolute value\n"
|
|
|
|
"ln(x) : Natural Logarithm\n"
|
|
|
|
"lb(x) : Logarithm with base 2\n"
|
|
|
|
"log(x, b) : Logarithm with custom base. Defaults to base 10\n"
|
|
|
|
"clear() : Clear History and variables\n"
|
|
|
|
"read(a) : Read 1 byte from loaded data\n"
|
|
|
|
"write(a, x) : Write 1 byte to loaded data");
|
|
|
|
|
2020-11-14 21:16:03 +01:00
|
|
|
}
|
2020-12-05 11:34:49 +01:00
|
|
|
ImGui::End();
|
2020-11-14 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
void ViewHelp::drawContent() {
|
2021-01-27 14:26:24 +01:00
|
|
|
if (!this->m_aboutWindowOpen && !this->m_mathHelpWindowOpen && !this->m_patternHelpWindowOpen)
|
|
|
|
this->getWindowOpenState() = false;
|
|
|
|
|
2020-11-17 13:59:16 +01:00
|
|
|
this->drawAboutPopup();
|
|
|
|
this->drawPatternHelpPopup();
|
2020-11-30 21:44:40 +01:00
|
|
|
this->drawMathEvaluatorHelp();
|
2020-11-14 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
void ViewHelp::drawMenu() {
|
2020-11-14 21:16:03 +01:00
|
|
|
if (ImGui::BeginMenu("Help")) {
|
2020-11-30 21:44:40 +01:00
|
|
|
if (ImGui::MenuItem("About", "")) {
|
|
|
|
View::doLater([] { ImGui::OpenPopup("About"); });
|
|
|
|
this->m_aboutWindowOpen = true;
|
2021-01-27 14:26:24 +01:00
|
|
|
this->getWindowOpenState() = true;
|
2020-11-30 21:44:40 +01:00
|
|
|
}
|
2020-11-14 21:16:03 +01:00
|
|
|
ImGui::Separator();
|
2020-11-30 21:44:40 +01:00
|
|
|
if (ImGui::MenuItem("Pattern Language Cheat Sheet", "")) {
|
|
|
|
this->m_patternHelpWindowOpen = true;
|
2021-01-27 14:26:24 +01:00
|
|
|
this->getWindowOpenState() = true;
|
2020-11-30 21:44:40 +01:00
|
|
|
}
|
|
|
|
if (ImGui::MenuItem("Calculator Cheat Sheet", "")) {
|
|
|
|
this->m_mathHelpWindowOpen = true;
|
2021-01-27 14:26:24 +01:00
|
|
|
this->getWindowOpenState() = true;
|
2020-11-30 21:44:40 +01:00
|
|
|
}
|
2020-11-14 21:16:03 +01:00
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|