diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..d30c5da2 --- /dev/null +++ b/.clang-format @@ -0,0 +1,121 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 2 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseTab: Never +... + diff --git a/.gitignore b/.gitignore index ba3071c0..87ea0c20 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,28 @@ doc/api/ pubspec.lock log.txt -.dart_tool \ No newline at end of file +.dart_tool + +# Created by https://www.gitignore.io/api/cmake +# Edit at https://www.gitignore.io/?templates=cmake + +### CMake ### +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +### CMake Patch ### +# External projects +*-prefix/ + +# End of https://www.gitignore.io/api/cmake +build/ +cmake-build-* \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..9e894bd7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "cmake_dart_utils"] + path = cmake_dart_utils + url = https://github.com/thosakwe/cmake_dart_utils.git diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 00000000..c9a8b53a --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +angel_security \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..8822db8f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..20d6502b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/security.iml b/.idea/security.iml new file mode 100644 index 00000000..f08604bb --- /dev/null +++ b/.idea/security.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..fcb4eac7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..1d389a26 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..8bdf07a7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.0) +project(angel_security) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_dart_utils/cmake") +find_package(Dart REQUIRED) +add_dart_native_extension(angel_security_native lib/src/native/angel_security.cc) \ No newline at end of file diff --git a/cmake_dart_utils b/cmake_dart_utils new file mode 160000 index 00000000..7f0bbac1 --- /dev/null +++ b/cmake_dart_utils @@ -0,0 +1 @@ +Subproject commit 7f0bbac1dfbb4aa7ce9b8f178505d24974adf85a diff --git a/lib/native.dart b/lib/native.dart new file mode 100644 index 00000000..3dffded9 --- /dev/null +++ b/lib/native.dart @@ -0,0 +1 @@ +export 'src/native/native.dart'; diff --git a/lib/src/native/angel_security.cc b/lib/src/native/angel_security.cc new file mode 100644 index 00000000..78a35d59 --- /dev/null +++ b/lib/src/native/angel_security.cc @@ -0,0 +1,43 @@ +#include +#include + +Dart_NativeFunction ResolveName(Dart_Handle name, int argc, + bool *auto_setup_scope); + +DART_EXPORT Dart_Handle angel_security_native_Init(Dart_Handle parent_library) { + if (Dart_IsError(parent_library)) + return parent_library; + + Dart_Handle result_code = + Dart_SetNativeResolver(parent_library, ResolveName, NULL); + if (Dart_IsError(result_code)) + return result_code; + + return Dart_Null(); +} + +Dart_Handle HandleError(Dart_Handle handle) { + if (Dart_IsError(handle)) + Dart_PropagateError(handle); + return handle; +} + +void Angel_Security_IsSqli(Dart_NativeArguments arguments) { + char* text; + HandleError(); + Dart_Handle result = HandleError(Dart_NewInteger(rand())); + Dart_SetReturnValue(arguments, result); +} + +Dart_NativeFunction ResolveName(Dart_Handle name, int argc, + bool *auto_setup_scope) { + if (!Dart_IsString(name)) + return NULL; + Dart_NativeFunction result = NULL; + const char *cname; + HandleError(Dart_StringToCString(name, &cname)); + + if (strcmp("Angel_Security_IsSqli", cname) == 0) + result = Angel_Security_IsSqli; + return result; +} diff --git a/lib/src/native/native.dart b/lib/src/native/native.dart new file mode 100644 index 00000000..ea0199c8 --- /dev/null +++ b/lib/src/native/native.dart @@ -0,0 +1,5 @@ +import 'dart-ext:angel_security_native'; + +/// Using `libinjection`, determines whether a string contains +/// a SQL injection. +bool isSqli(String text) native "Angel_Security_IsSqli";