├── .github └── workflows │ ├── build-and-deploy-artifacts.yml │ └── maven-build.yml ├── .gitignore ├── LICENSE ├── NOTICE ├── README.md ├── grammar ├── mal-maven-plugin ├── pom.xml └── src │ └── main │ └── java │ ├── module-info.java │ └── org │ └── mal_lang │ └── compiler │ └── mojo │ ├── MalMojo.java │ ├── ReferenceMojo.java │ └── SecuriCADMojo.java ├── malcompiler-cli ├── pom.xml └── src │ └── main │ ├── java │ ├── module-info.java │ └── org │ │ └── mal_lang │ │ └── compiler │ │ └── cli │ │ ├── CLIArguments.java │ │ ├── CLIParser.java │ │ ├── Main.java │ │ └── SGR.java │ └── resources-filtered │ └── META-INF │ └── MANIFEST.MF ├── malcompiler-jlink ├── pom.xml └── src │ ├── assembly │ ├── unix.xml │ └── windows.xml │ └── main │ └── resources │ ├── malc │ └── malc.bat ├── malcompiler-lib ├── pom.xml └── src │ └── main │ ├── java │ ├── module-info.java │ └── org │ │ └── mal_lang │ │ ├── compiler │ │ └── lib │ │ │ ├── AST.java │ │ │ ├── Analyzer.java │ │ │ ├── CompilerException.java │ │ │ ├── Distributions.java │ │ │ ├── Generator.java │ │ │ ├── JavaGenerator.java │ │ │ ├── Lang.java │ │ │ ├── LangConverter.java │ │ │ ├── Lexer.java │ │ │ ├── MalInfo.java │ │ │ ├── MalLogger.java │ │ │ ├── Parser.java │ │ │ ├── Position.java │ │ │ ├── Scope.java │ │ │ ├── Token.java │ │ │ ├── TokenType.java │ │ │ ├── d3 │ │ │ └── Generator.java │ │ │ ├── reference │ │ │ └── Generator.java │ │ │ └── securicad │ │ │ ├── AssetGenerator.java │ │ │ ├── AttackStepGenerator.java │ │ │ ├── DefenseGenerator.java │ │ │ ├── ExpressionGenerator.java │ │ │ ├── Generator.java │ │ │ └── VariableGenerator.java │ │ └── formatter │ │ ├── Formatter.java │ │ ├── Parser.java │ │ └── blocks │ │ ├── AbstractBlock.java │ │ ├── Block.java │ │ ├── ChoiceBlock.java │ │ ├── IndentBlock.java │ │ ├── LineBlock.java │ │ ├── MultiBlock.java │ │ ├── StackBlock.java │ │ ├── TextBlock.java │ │ └── WrapBlock.java │ ├── resources-filtered │ └── META-INF │ │ └── MANIFEST.MF │ └── resources │ ├── d3 │ └── visualization.html │ ├── reference │ ├── Asset.java │ ├── AttackStep.java │ ├── AttackStepMax.java │ ├── AttackStepMin.java │ ├── Attacker.java │ └── Defense.java │ └── securicad │ ├── Attacker.java │ └── mock │ ├── corelib │ ├── AbstractSample.java │ ├── AssociationManager.java │ ├── BaseSample.java │ ├── DefaultValue.java │ ├── FAnnotations.java │ ├── FClass.java │ ├── Link.java │ ├── ModelElement.java │ ├── math │ │ ├── FBernoulliDistribution.java │ │ ├── FBinomialDistribution.java │ │ ├── FDistribution.java │ │ ├── FExponentialDistribution.java │ │ ├── FGammaDistribution.java │ │ ├── FLogNormalDistribution.java │ │ ├── FMath.java │ │ ├── FParetoDistribution.java │ │ ├── FTruncatedNormalDistribution.java │ │ └── FUniformDistribution.java │ └── util │ │ ├── FProb.java │ │ └── FProbSet.java │ └── simulator │ ├── AbstractAttacker.java │ ├── Asset.java │ ├── AttackStep.java │ ├── AttackStepMax.java │ ├── AttackStepMin.java │ ├── BaseLangLink.java │ ├── ConcreteSample.java │ ├── Defense.java │ ├── MultiParentAsset.java │ └── SingleParentAsset.java ├── malcompiler-test ├── pom.xml └── src │ └── test │ ├── java │ └── org │ │ └── mal_lang │ │ └── compiler │ │ └── test │ │ ├── MalTest.java │ │ ├── allfeatures │ │ └── TestAllFeatures.java │ │ ├── bled │ │ └── TestFirewall.java │ │ ├── cli │ │ ├── TestCLIParser.java │ │ ├── TestMain.java │ │ └── TestSGR.java │ │ ├── formatter │ │ └── TestFormatter.java │ │ ├── lib │ │ ├── AssertAST.java │ │ ├── AssertLang.java │ │ ├── AssertToken.java │ │ ├── JavaGeneratorTest.java │ │ ├── TestAnalyzer.java │ │ ├── TestLangConverter.java │ │ ├── TestLexer.java │ │ ├── TestParser.java │ │ ├── TestParserFail.java │ │ ├── d3 │ │ │ └── TestD3Generator.java │ │ ├── reference │ │ │ └── TestReferenceGenerator.java │ │ └── securicad │ │ │ └── TestSecuricadGenerator.java │ │ └── vehiclelang │ │ ├── AdvancedNetworkTest.java │ │ ├── AdvancedVulnerabilityTest.java │ │ ├── CoreDataTest.java │ │ ├── CoreEcuTest.java │ │ ├── CoreEthernetNetworkTest.java │ │ ├── CoreFirmwareTest.java │ │ ├── CoreMachineTest.java │ │ ├── CoreVehicleNetworkTest.java │ │ ├── CoreVulnerabilityTest.java │ │ ├── InfotainmentTest.java │ │ ├── MessageInjectionTest.java │ │ ├── PublicInterfacesTest.java │ │ ├── expertSessionTest.java │ │ └── newTest.java │ └── resources │ ├── all-features │ ├── all-features.mal │ ├── core.mal │ ├── included.mal │ └── subdir │ │ └── subincluded.mal │ ├── analyzer │ ├── bad1.mal │ ├── bad2.mal │ ├── bad3.mal │ ├── complex-analyzer-debug.txt │ ├── complex-analyzer-verbose.txt │ ├── complex-analyzer-warnings.txt │ ├── complex-lexer-debug.txt │ ├── complex-lexer-verbose.txt │ ├── complex-lexer.txt │ ├── complex-parser-debug.txt │ ├── complex-parser-verbose.txt │ ├── complex-parser.txt │ ├── complex.mal │ ├── dist-fail.mal │ ├── distributions.mal │ └── invalid-assoc.mal │ ├── bled │ └── bled.mal │ ├── formatter │ ├── comments.ans │ ├── comments.mal │ ├── escape.ans │ ├── escape.mal │ ├── margin.mal │ ├── margin30.ans │ ├── margin50.ans │ ├── oneline.ans │ ├── oneline.mal │ ├── readable.ans │ └── readable.mal │ ├── generator │ ├── attack-step-set.mal │ ├── bad-lang.mal │ ├── debug-step.mal │ ├── dist.mal │ ├── naming.mal │ ├── nested.mal │ ├── steps.mal │ ├── subtype.mal │ └── variable.mal │ ├── lang-converter │ └── reverse.mal │ ├── lexer │ ├── bad-unicode-1.txt │ ├── bad-unicode-2.txt │ ├── invalid.txt │ ├── invalid_escape_sequence.txt │ ├── keywords.txt │ ├── lexemes.txt │ ├── tokens.txt │ ├── unicode.txt │ ├── unterminated_comment.txt │ └── unterminated_string.txt │ ├── parser │ ├── assets.mal │ ├── associations.mal │ ├── attacksteps.mal │ ├── bad-asset1.mal │ ├── bad-asset2.mal │ ├── bad-asset3.mal │ ├── bad-asset4.mal │ ├── bad-association1.mal │ ├── bad-association2.mal │ ├── bad-association3.mal │ ├── bad-association4.mal │ ├── bad-association5.mal │ ├── bad-attackstep1.mal │ ├── bad-attackstep2.mal │ ├── bad-attackstep3.mal │ ├── bad-attackstep4.mal │ ├── bad-attackstep5.mal │ ├── bad-attackstep6.mal │ ├── bad-attackstep7.mal │ ├── bad-attackstep8.mal │ ├── bad-category1.mal │ ├── bad-define1.mal │ ├── bad-define2.mal │ ├── bad-include1.mal │ ├── bad-include2.mal │ ├── bad-include3.mal │ ├── bad-meta1.mal │ ├── bad-meta2.mal │ ├── bad-meta3.mal │ ├── categories.mal │ ├── defines.mal │ ├── empty.mal │ ├── include.mal │ ├── included1.mal │ ├── included2.mal │ ├── subDir │ │ ├── bad-included1.mal │ │ └── subIncluded1.mal │ ├── to-string.ans │ ├── to-string.mal │ └── whitespace.mal │ └── vehiclelang │ ├── vehicleLang.mal │ ├── vehicleLangEncryption.mal │ ├── vehicleLangEthernet.mal │ └── vehicleLangPublicInterfaces.mal ├── pom.xml ├── tools ├── git-hooks │ ├── install.sh │ └── pre-commit.d │ │ ├── format-java.sh │ │ ├── format-pom.sh │ │ └── format-xml.sh └── scripts │ ├── google-java-format.sh │ └── utils.sh └── update_mal ├── new-spec.mal ├── old-spec.mal ├── run-tests.sh └── update_mal.py /.github/workflows/build-and-deploy-artifacts.yml: -------------------------------------------------------------------------------- 1 | name: Build and Deploy Artifacts 2 | on: 3 | push: 4 | branches: 5 | - master 6 | jobs: 7 | build-and-deploy-artifacts: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout 11 | uses: actions/checkout@v2 12 | with: 13 | persist-credentials: false 14 | 15 | - name: Set up JDK 16 | uses: actions/setup-java@v2 17 | with: 18 | distribution: temurin 19 | java-version: 11 20 | check-latest: true 21 | server-id: ossrh 22 | server-username: MAVEN_USERNAME 23 | server-password: MAVEN_PASSWORD 24 | gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} 25 | gpg-passphrase: MAVEN_GPG_PASSPHRASE 26 | 27 | - name: Build and Deploy Artifacts 28 | run: mvn -B deploy -Prelease 29 | env: 30 | MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} 31 | MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} 32 | MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} 33 | -------------------------------------------------------------------------------- /.github/workflows/maven-build.yml: -------------------------------------------------------------------------------- 1 | name: Maven Build 2 | on: 3 | pull_request: 4 | branches: 5 | - master 6 | jobs: 7 | maven-build: 8 | runs-on: ${{ matrix.os }} 9 | strategy: 10 | matrix: 11 | os: [ubuntu-latest, macos-latest] 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v2 15 | with: 16 | persist-credentials: false 17 | 18 | - name: Set up cache for ~/.m2/repository 19 | uses: actions/cache@v2 20 | with: 21 | path: ~/.m2/repository 22 | key: maven-${{ matrix.os }}-java11-${{ hashFiles('**/pom.xml') }} 23 | restore-keys: | 24 | maven-${{ matrix.os }}-java11- 25 | maven-${{ matrix.os }}- 26 | 27 | - name: Set up JDK 28 | uses: actions/setup-java@v2 29 | with: 30 | distribution: temurin 31 | java-version: 11 32 | check-latest: true 33 | 34 | - name: Maven Build 35 | run: mvn -B install 36 | 37 | - name: update_mal 38 | run: cd update_mal && ./run-tests.sh 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | replay_pid* 25 | 26 | # Maven 27 | target/ 28 | pom.xml.tag 29 | pom.xml.releaseBackup 30 | pom.xml.versionsBackup 31 | pom.xml.next 32 | release.properties 33 | dependency-reduced-pom.xml 34 | buildNumber.properties 35 | .mvn/timing.properties 36 | # https://github.com/takari/maven-wrapper#usage-without-binary-jar 37 | .mvn/wrapper/maven-wrapper.jar 38 | 39 | # Eclipse m2e generated files 40 | # Eclipse Core 41 | .project 42 | # JDT-specific (Eclipse Java Development Tools) 43 | .classpath 44 | 45 | # Eclipse 46 | .settings/ 47 | 48 | # Java annotation processor (APT) 49 | .factorypath 50 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Meta Attack Language - MAL 2 | 3 | Copyright 2017-2022 The MAL founders and contributors 4 | 5 | MAL founders: Pontus Johnson, Mathias Ekstedt, Robert Lagerström 6 | 7 | MAL contributors: Foreseeti AB, Sotirios Katsikeas 8 | 9 | This product includes/uses software, javapoet 1.12.0-SNAPSHOT (https://github.com/square/javapoet), 10 | developed by Square (https://square.github.io/) 11 | License: The Apache Software License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.txt) 12 | 13 | This product includes/uses software, svgSalamander 1.1.2 (https://github.com/blackears/svgSalamander) 14 | developed by Mark McKay (http://www.kitfox.com/) 15 | License: The 3-Clause BSD License (https://opensource.org/licenses/BSD-3-Clause) 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MAL (the Meta Attack Language) 2 | 3 | MAL is a language for designing cyber threat modeling languages for 4 | specific domains. For more information, see . 5 | 6 | Some examples of MAL languages are: 7 | * [exampleLang](https://github.com/mal-lang/exampleLang) 8 | * [vehicleLang](https://github.com/mal-lang/vehicleLang) 9 | 10 | ## Creating a MAL language: 11 | 12 | For information on how to set up your development environment for 13 | creating MAL languages, please refer to the `README.md` file in 14 | exampleLang: 15 | 16 | 17 | For MAL language development, you don't need to compile the 18 | MAL compiler yourself. It will be downloaded by maven automatically. 19 | 20 | ## Developing the MAL compiler 21 | 22 | To develop the MAL compiler, you need to have Apache Maven and a Java 23 | JDK installed. You also need to enable the OSSRH snapshot repository. 24 | You can do that by creating a file `~/.m2/settings.xml` with the 25 | following content: 26 | 27 | ``` 28 | 29 | 30 | 31 | 32 | ossrh-snapshots 33 | 34 | 35 | ossrh 36 | https://oss.sonatype.org/content/repositories/snapshots 37 | 38 | false 39 | 40 | 41 | true 42 | 43 | 44 | 45 | 46 | 47 | 48 | ossrh-snapshots 49 | 50 | 51 | ``` 52 | 53 | Execute the following steps to download and compile the MAL complier: 54 | 55 | ``` 56 | git clone git://github.com/mal-lang/malcompiler.git 57 | cd malcomplier 58 | mvn install 59 | ``` 60 | -------------------------------------------------------------------------------- /grammar: -------------------------------------------------------------------------------- 1 | ; rules 2 | ::= ( | | | )* EOF 3 | ::= HASH ID COLON STRING 4 | ::= ID 5 | ::= INFO COLON STRING 6 | ::= INCLUDE STRING 7 | ::= INT | FLOAT 8 | 9 | ::= CATEGORY ID * LCURLY * RCURLY 10 | ::= ABSTRACT? ASSET ID (EXTENDS ID)? * LCURLY ( | )* RCURLY 11 | ::= ID * ? ? * ? ? 12 | ::= ALL | ANY | HASH | EXIST | NOTEXIST 13 | ::= AT ID 14 | ::= LCURLY ? RCURLY 15 | ::= (COMMA )* 16 | ::= C | I | A 17 | ::= LBRACKET ? RBRACKET 18 | ::= ((PLUS | MINUS) )* 19 | ::= ((STAR | DIVIDE) )* 20 | ::= (POWER )? 21 | ::= ID (LPAREN ( (COMMA )*)? RPAREN)? | LPAREN RPAREN | 22 | ::= REQUIRE (COMMA )* 23 | ::= (INHERIT | OVERRIDE) (COMMA )* 24 | 25 | ::= LET ID ASSIGN 26 | ::= ((UNION | INTERSECT | MINUS) )* 27 | ::= (DOT )* 28 | ::= (LPAREN RPAREN | ID (LPAREN RPAREN)?) (STAR | )* 29 | 30 | ::= ASSOCIATIONS LCURLY ? RCURLY 31 | ::= ID (ID ( | ))* 32 | ::= LARROW ID RARROW ID 33 | ::= (RANGE )? 34 | ::= INT | STAR 35 | ::= LBRACKET ID LBRACKET 36 | 37 | 38 | ; keywords 39 | INCLUDE ::= "include" 40 | INFO ::= "info" 41 | CATEGORY ::= "category" 42 | ABSTRACT ::= "abstract" 43 | ASSET ::= "asset" 44 | EXTENDS ::= "extends" 45 | ASSOCIATIONS ::= "associations" 46 | LET ::= "let" 47 | EXIST ::= "E" 48 | C ::= "C" 49 | I ::= "I" 50 | A ::= "A" 51 | 52 | 53 | ; tokens 54 | EOF ; end of file 55 | STRING ; java string literal 56 | ID ; java identifier 57 | INT ::= [0-9]+ 58 | FLOAT ::= [0-9]+ (DOT [0-9]+)? 59 | HASH ::= "#" 60 | COLON ::= ":" 61 | LCURLY ::= "{" 62 | RCURLY ::= "}" 63 | INHERIT ::= "+>" 64 | OVERRIDE ::= "->" 65 | ALL ::= "&" 66 | ANY ::= "|" 67 | NOTEXIST ::= "!E" 68 | AT ::= "@" 69 | LBRACKET ::= "[" 70 | RBRACKET ::= "]" 71 | LPAREN ::= "(" 72 | RPAREN ::= ")" 73 | COMMA ::= "," 74 | REQUIRE ::= "<-" 75 | ASSIGN ::= "=" 76 | UNION ::= "\/" 77 | INTERSECT ::= "/\" 78 | DOT ::= "." 79 | RANGE ::= ".." 80 | STAR ::= "*" 81 | PLUS ::= "+" 82 | MINUS ::= "-" 83 | DIVIDE ::= "/" 84 | POWER ::= "^" 85 | LARROW ::= "<--" 86 | RARROW ::= "-->" 87 | -------------------------------------------------------------------------------- /mal-maven-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | 21 | org.mal-lang 22 | malcompiler 23 | 0.1.0-SNAPSHOT 24 | 25 | 26 | mal-maven-plugin 27 | maven-plugin 28 | 29 | ${project.groupId}:${project.artifactId} 30 | Maven plugin of the compiler for the Meta Attack Language 31 | https://mal-lang.org/ 32 | 33 | 34 | Apache License, Version 2.0 35 | https://www.apache.org/licenses/LICENSE-2.0.txt 36 | 37 | 38 | 39 | 40 | 41 | Mikael Modin 42 | mikael.modin@foreseeti.com 43 | foreseeti 44 | https://www.foreseeti.com/ 45 | 46 | 47 | Simon Wrede 48 | simon.wrede@foreseeti.com 49 | foreseeti 50 | https://www.foreseeti.com/ 51 | 52 | 53 | Max Wällstedt 54 | max.wallstedt@foreseeti.com 55 | foreseeti 56 | https://www.foreseeti.com/ 57 | 58 | 59 | 60 | 61 | scm:git:git://github.com/mal-lang/malcompiler.git 62 | scm:git:ssh://github.com:mal-lang/malcompiler.git 63 | https://github.com/mal-lang/malcompiler/tree/master/mal-maven-plugin 64 | 65 | 66 | 67 | 68 | org.apache.maven 69 | maven-model 70 | 3.8.5 71 | 72 | 73 | org.apache.maven 74 | maven-project 75 | 2.2.1 76 | 77 | 78 | org.apache.maven 79 | maven-plugin-api 80 | 3.8.5 81 | 82 | 83 | org.apache.maven.plugin-tools 84 | maven-plugin-annotations 85 | 3.6.4 86 | 87 | 88 | org.mal-lang 89 | malcompiler-lib 90 | ${project.version} 91 | 92 | 93 | 94 | 95 | 96 | 97 | org.apache.maven.plugins 98 | maven-plugin-plugin 99 | 3.6.4 100 | 101 | 102 | org.apache.maven.plugins 103 | maven-source-plugin 104 | 105 | 106 | attach-sources 107 | 108 | jar 109 | 110 | 111 | 112 | 113 | 114 | org.apache.maven.plugins 115 | maven-javadoc-plugin 116 | 117 | 118 | attach-javadocs 119 | 120 | jar 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /mal-maven-plugin/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Foreseeti AB 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | module org.mal_lang.compiler.mojo { 17 | requires org.mal_lang.compiler.lib; 18 | requires maven.model; 19 | requires maven.project; 20 | requires maven.plugin.api; 21 | requires maven.plugin.annotations; 22 | } 23 | -------------------------------------------------------------------------------- /mal-maven-plugin/src/main/java/org/mal_lang/compiler/mojo/ReferenceMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Foreseeti AB 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mal_lang.compiler.mojo; 17 | 18 | import java.io.File; 19 | import java.io.IOException; 20 | import java.util.HashMap; 21 | import org.apache.maven.model.Resource; 22 | import org.apache.maven.plugin.MojoExecutionException; 23 | import org.apache.maven.plugin.MojoFailureException; 24 | import org.apache.maven.plugins.annotations.LifecyclePhase; 25 | import org.apache.maven.plugins.annotations.Mojo; 26 | import org.apache.maven.plugins.annotations.Parameter; 27 | import org.mal_lang.compiler.lib.Analyzer; 28 | import org.mal_lang.compiler.lib.CompilerException; 29 | import org.mal_lang.compiler.lib.LangConverter; 30 | import org.mal_lang.compiler.lib.Parser; 31 | import org.mal_lang.compiler.lib.reference.Generator; 32 | 33 | @Mojo(name = "reference", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES) 34 | public class ReferenceMojo extends MalMojo { 35 | /** The output directory to store the generated java files in. */ 36 | @Parameter(property = "mal.reference.path") 37 | private File path; 38 | 39 | /** The package name to use for the generated java files. */ 40 | @Parameter(property = "mal.reference.package") 41 | private String packageName; 42 | 43 | /** Specifies whether the {@code core} classes should be generated. */ 44 | @Parameter(property = "mal.reference.core", defaultValue = "true") 45 | private boolean core; 46 | 47 | @Override 48 | public void execute() throws MojoExecutionException, MojoFailureException { 49 | init(); 50 | var log = getLog(); 51 | var input = validateAndGetInputFile(); 52 | 53 | // Initialize output directory 54 | if (path == null) { 55 | path = new File(getBuildDirectory(), "generated-test-sources"); 56 | } 57 | createOrClearDirectory(path); 58 | 59 | // Create argument map for code generator 60 | var args = new HashMap(); 61 | args.put("path", path.getPath()); 62 | 63 | if (packageName != null && !packageName.isBlank()) { 64 | args.put("package", packageName); 65 | } 66 | 67 | args.put("core", String.valueOf(core)); 68 | 69 | // Generate code 70 | log.info(String.format("Compiling MAL specification %s", input.getPath())); 71 | try { 72 | var ast = Parser.parse(input); 73 | Analyzer.analyze(ast); 74 | var lang = LangConverter.convert(ast); 75 | Generator.generate(lang, args, verbose, debug); 76 | } catch (IOException | CompilerException e) { 77 | throw new MojoFailureException(e.getMessage()); 78 | } 79 | 80 | // Add generated code to project's test source root 81 | log.info(String.format("Adding test compile source root %s", path.getPath())); 82 | project.addTestCompileSourceRoot(path.getPath()); 83 | 84 | // Add attackerProfile.ttc as a resource 85 | var attackerProfile = "attackerProfile.ttc"; 86 | log.info(String.format("Adding test resource %s/%s", path.getPath(), attackerProfile)); 87 | var resource = new Resource(); 88 | resource.setDirectory(path.getPath()); 89 | resource.addInclude(attackerProfile); 90 | project.addTestResource(resource); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /mal-maven-plugin/src/main/java/org/mal_lang/compiler/mojo/SecuriCADMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Foreseeti AB 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mal_lang.compiler.mojo; 17 | 18 | import java.io.File; 19 | import java.io.IOException; 20 | import java.util.HashMap; 21 | import org.apache.maven.plugin.MojoExecutionException; 22 | import org.apache.maven.plugin.MojoFailureException; 23 | import org.apache.maven.plugins.annotations.LifecyclePhase; 24 | import org.apache.maven.plugins.annotations.Mojo; 25 | import org.apache.maven.plugins.annotations.Parameter; 26 | import org.mal_lang.compiler.lib.Analyzer; 27 | import org.mal_lang.compiler.lib.CompilerException; 28 | import org.mal_lang.compiler.lib.LangConverter; 29 | import org.mal_lang.compiler.lib.Parser; 30 | import org.mal_lang.compiler.lib.securicad.Generator; 31 | 32 | @Mojo(name = "securicad", defaultPhase = LifecyclePhase.GENERATE_SOURCES) 33 | public class SecuriCADMojo extends MalMojo { 34 | /** The output directory to store the generated java files in. */ 35 | @Parameter(property = "mal.securicad.path") 36 | private File path; 37 | 38 | /** The package name to use for the generated java files. */ 39 | @Parameter(property = "mal.securicad.package") 40 | private String packageName; 41 | 42 | /** The directory where asset icons are located. */ 43 | @Parameter(property = "mal.securicad.icons") 44 | private File icons; 45 | 46 | /** Specifies if debug steps should be kept. */ 47 | @Parameter(property = "mal.securicad.debug") 48 | private boolean keepDebugSteps; 49 | 50 | @Override 51 | public void execute() throws MojoExecutionException, MojoFailureException { 52 | init(); 53 | var log = getLog(); 54 | var input = validateAndGetInputFile(); 55 | 56 | // Initialize output directory 57 | if (path == null) { 58 | path = new File(getBuildDirectory(), "generated-sources"); 59 | } 60 | createOrClearDirectory(path); 61 | 62 | // Create argument map for code generator 63 | var args = new HashMap(); 64 | args.put("path", path.getPath()); 65 | 66 | if (packageName != null && !packageName.isBlank()) { 67 | args.put("package", packageName); 68 | } 69 | 70 | if (icons == null) { 71 | icons = new File(getResourceDirectory(), "icons"); 72 | if (icons.exists() && icons.isDirectory()) { 73 | args.put("icons", icons.getPath()); 74 | } 75 | } else { 76 | validateFileExists(icons); 77 | validateFileIsDirectory(icons); 78 | args.put("icons", icons.getPath()); 79 | } 80 | 81 | args.put("debug", Boolean.toString(keepDebugSteps)); 82 | 83 | // Generate code 84 | log.info(String.format("Compiling MAL specification %s", input.getPath())); 85 | try { 86 | var ast = Parser.parse(input); 87 | Analyzer.analyze(ast); 88 | var lang = LangConverter.convert(ast); 89 | Generator.generate(lang, args, verbose, debug); 90 | } catch (IOException | CompilerException e) { 91 | throw new MojoFailureException(e.getMessage()); 92 | } 93 | 94 | // Add generated code to project's source root 95 | log.info(String.format("Adding compile source root %s", path.getPath())); 96 | project.addCompileSourceRoot(path.getPath()); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /malcompiler-cli/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | 21 | org.mal-lang 22 | malcompiler 23 | 0.1.0-SNAPSHOT 24 | 25 | 26 | malcompiler-cli 27 | jar 28 | 29 | ${project.groupId}:${project.artifactId} 30 | Command-line interface of the compiler for the Meta Attack Language 31 | https://mal-lang.org/ 32 | 33 | 34 | Apache License, Version 2.0 35 | https://www.apache.org/licenses/LICENSE-2.0.txt 36 | 37 | 38 | 39 | 40 | 41 | Mikael Modin 42 | mikael.modin@foreseeti.com 43 | foreseeti 44 | https://www.foreseeti.com/ 45 | 46 | 47 | Simon Wrede 48 | simon.wrede@foreseeti.com 49 | foreseeti 50 | https://www.foreseeti.com/ 51 | 52 | 53 | Max Wällstedt 54 | max.wallstedt@foreseeti.com 55 | foreseeti 56 | https://www.foreseeti.com/ 57 | 58 | 59 | 60 | 61 | scm:git:git://github.com/mal-lang/malcompiler.git 62 | scm:git:ssh://github.com:mal-lang/malcompiler.git 63 | https://github.com/mal-lang/malcompiler/tree/master/malcompiler-cli 64 | 65 | 66 | 67 | org.mal_lang.compiler.cli.Main 68 | 69 | 70 | 71 | 72 | org.mal-lang 73 | malcompiler-lib 74 | ${project.version} 75 | 76 | 77 | 78 | 79 | 80 | 81 | false 82 | ${project.basedir}/src/main/resources 83 | 84 | 85 | true 86 | ${project.basedir}/src/main/resources-filtered 87 | 88 | 89 | 90 | 91 | false 92 | ${project.basedir}/src/test/resources 93 | 94 | 95 | true 96 | ${project.basedir}/src/test/resources-filtered 97 | 98 | 99 | 100 | 101 | org.apache.maven.plugins 102 | maven-jar-plugin 103 | 104 | 105 | ${project.build.outputDirectory}/META-INF/MANIFEST.MF 106 | 107 | 108 | 109 | 110 | org.apache.maven.plugins 111 | maven-source-plugin 112 | 113 | 114 | attach-sources 115 | 116 | jar 117 | 118 | 119 | 120 | 121 | 122 | org.apache.maven.plugins 123 | maven-javadoc-plugin 124 | 125 | 126 | attach-javadocs 127 | 128 | jar 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /malcompiler-cli/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Foreseeti AB 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | module org.mal_lang.compiler.cli { 17 | exports org.mal_lang.compiler.cli; 18 | 19 | requires java.logging; 20 | requires org.mal_lang.compiler.lib; 21 | } 22 | -------------------------------------------------------------------------------- /malcompiler-cli/src/main/java/org/mal_lang/compiler/cli/CLIArguments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Foreseeti AB 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mal_lang.compiler.cli; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | public class CLIArguments { 22 | private List