diff --git a/.gitmodules b/.gitmodules index 9566564..220621f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "src\\ddcon"] - path = src\\ddcon +[submodule "src/ddcon"] + path = src/ddcon url = https://github.com/dd86k/ddcon.git diff --git a/dscanner.ini b/dscanner.ini new file mode 100644 index 0000000..7004ee1 --- /dev/null +++ b/dscanner.ini @@ -0,0 +1,85 @@ +; Configure which static analysis checks are enabled +[analysis.config.StaticAnalysisConfig] +; Check variable, class, struct, interface, union, and function names against t +; he Phobos style guide +style_check="disabled" +; Check for array literals that cause unnecessary allocation +enum_array_literal_check="enabled" +; Check for poor exception handling practices +exception_check="enabled" +; Check for use of the deprecated 'delete' keyword +delete_check="enabled" +; Check for use of the deprecated floating point operators +float_operator_check="enabled" +; Check number literals for readability +number_style_check="enabled" +; Checks that opEquals, opCmp, toHash, and toString are either const, immutable +; , or inout. +object_const_check="enabled" +; Checks for .. expressions where the left side is larger than the right. +backwards_range_check="enabled" +; Checks for if statements whose 'then' block is the same as the 'else' block +if_else_same_check="enabled" +; Checks for some problems with constructors +constructor_check="enabled" +; Checks for unused variables and function parameters +unused_variable_check="enabled" +; Checks for unused labels +unused_label_check="enabled" +; Checks for duplicate attributes +duplicate_attribute="enabled" +; Checks that opEquals and toHash are both defined or neither are defined +opequals_tohash_check="enabled" +; Checks for subtraction from .length properties +length_subtraction_check="enabled" +; Checks for methods or properties whose names conflict with built-in propertie +; s +builtin_property_names_check="enabled" +; Checks for confusing code in inline asm statements +asm_style_check="enabled" +; Checks for confusing logical operator precedence +logical_precedence_check="enabled" +; Checks for undocumented public declarations +undocumented_declaration_check="enabled" +; Checks for poor placement of function attributes +function_attribute_check="enabled" +; Checks for use of the comma operator +comma_expression_check="enabled" +; Checks for local imports that are too broad +local_import_check="enabled" +; Checks for variables that could be declared immutable +could_be_immutable_check="enabled" +; Checks for redundant expressions in if statements +redundant_if_check="enabled" +; Checks for redundant parenthesis +redundant_parens_check="enabled" +; Checks for mismatched argument and parameter names +mismatched_args_check="enabled" +; Checks for labels with the same name as variables +label_var_same_name_check="enabled" +; Checks for lines longer than 120 characters +long_line_check="enabled" +; Checks for assignment to auto-ref function parameters +auto_ref_assignment_check="enabled" +; Checks for incorrect infinite range definitions +incorrect_infinite_range_check="enabled" +; Checks for asserts that are always true +useless_assert_check="enabled" +; Check for uses of the old-style alias syntax +alias_syntax_check="enabled" +; Checks for else if that should be else static if +static_if_else_check="enabled" +; Check for unclear lambda syntax +lambda_return_check="enabled" +; Check for auto function without return statement +auto_function_check="enabled" +; Check for sortedness of imports +imports_sortedness="disabled" +; Check for explicitly annotated unittests +explicitly_annotated_unittests="enabled" +; Check for properly documented public functions (Returns, Params) +properly_documented_public_functions="enabled" +; Check for useless usage of the final attribute +final_attribute_check="enabled" +; Check for virtual calls in the class constructors +vcall_in_ctor="enabled" diff --git a/src/Menu.d b/src/Menu.d index 99a503f..ab5bd59 100644 --- a/src/Menu.d +++ b/src/Menu.d @@ -68,12 +68,12 @@ else MessageAlt("Missing argument. (String)"); break; - /*case "ss16": // Search UTF-16 string + case "ss16": // Search UTF-16 string if (e.length > 1) SearchUTF16String(e[1]); else MessageAlt("Missing argument. (String)"); - break;*/ + break; case "sb": // Search byte SEARCH_BYTE: if (e.length > 1) { diff --git a/src/Searcher.d b/src/Searcher.d index 15dce3a..ba3cd1c 100644 --- a/src/Searcher.d +++ b/src/Searcher.d @@ -7,7 +7,21 @@ private enum CHUNK_SIZE = MB / 2; //TODO: Progress bar -//TODO: One main function with an ubyte[] parameter +//TODO: String REGEX + +void SearchUTF8String(const char[] s) +{ + SearchArray(cast(ubyte[])s, "string"); +} + +void SearchUTF16String(const char[] s) +{ + const size_t l = s.length; + ubyte[] buf = new ubyte[l * 2]; + for (int i = 1, e = 0; e < l; i += 2, ++e) + buf[i] = s[e]; + SearchArray(buf, "wstring"); +} void SearchByte(const ubyte b) { @@ -27,46 +41,21 @@ MessageAlt("Not found"); } -//TODO: ONE function that translate any strings to a byte array - -void SearchUTF8String(const char[] s) +private void SearchArray(const ubyte[] a, string type) { - const char b = s[0]; - const size_t len = s.length; - MessageAlt("Searching string..."); + MessageAlt(format("Searching %s...", type)); + const char b = a[0]; + const size_t len = a.length; long pos = CurrentPosition + 1; CurrentFile.seek(pos); - //TODO: String compare between chunks + //TODO: array compare between chunks foreach (const ubyte[] buf; CurrentFile.byChunk(CHUNK_SIZE)) { for (int i; i < buf.length; ++i) { if (b == buf[i]) { - if (buf[i..i+len] == s) { + if (buf[i..i+len] == a) { GotoC(pos); - MessageAlt(format(` Found string "%s" at %XH`, s, pos)); - return; - } - } - ++pos; - } - } - MessageAlt("Not found"); -} - -void SearchUTF16String(const char[] s) -{ - //TODO: UTF-16 string searching - const char b = s[0]; - const size_t len = s.length; - MessageAlt("Searching string..."); - long pos = CurrentPosition + 1; - CurrentFile.seek(pos); - //TODO: String compare between chunks - foreach (const ubyte[] buf; CurrentFile.byChunk(CHUNK_SIZE)) { - for (int i; i < buf.length; ++i) { - if (b == buf[i]) { - if (buf[i..i+len] == s) { - GotoC(pos); - MessageAlt(format(` Found wstring "%s" at %XH`, s, pos)); + MessageAlt(format( + ` Found %s value at %XH`, type, pos)); return; } } diff --git a/src/ddcon b/src/ddcon index 4a4939c..baa932c 160000 --- a/src/ddcon +++ b/src/ddcon @@ -1 +1 @@ -Subproject commit 4a4939c4f70f3987b11520f9f8e6ecab56da9050 +Subproject commit baa932c376a0ee45a923bb820e6dd60192982cf7