Package: demal
demalMAL (Meta Attack Language) to JSON encoding/decoding library and command-line tool.Convert from MAL to JSON and, as of version 2, from JSON to MAL. Incompatible with theofficial tool.InfoAuthor:Victor AzzamLicense:MITLatest version:2.1.0Requires:Python 3.8 or laterBatteries included:Tests and examples are provided in this repository.UsageInstall~pipinstalldemalOr install from source~gitclonehttps://github.com/victorazzam/demal
~cddemal&&pipinstall.Uninstall~pipuninstalldemalGeneral usageConvertfile.maltofile.mal.json~demalfile.malConvertfile.maltofile.json~demalfile.malfile.jsonConvertfile.jsontofile.mal(if JSON abides bydemal's output)~demalfile.jsonfile.mal-rConvertfile.maland print it out~demalfile.mal-Read from standard input, convert, and print it out~catfile.mal|demal--Read from standard input, convert, and write toout.json~catfile.mal|demal-out.jsonConvert several files and view them interactively~catfile1.malfile2.mal|demal--|lessDisplay debugging information while converting~demaltest2.maldebug
parsegot:'#id: "tmp"'parsegot:'#version: "0.0.0"'parsegot:'category C1 {'parse_categorygot:'}'parsegot:'category C2'parse_headergot:'user info: "info"'parse_headergot:'{'parse_categorygot:'asset A1 {'parse_assetgot:'& At1'parse_assetgot:'| At2'# output truncatedUse it as a Python modulefromdemalimportMalParsermal=MalParser('threat-model.mal')mal.debug=Truemal.parse()# displays debugging messages due to the previous line# output suppressedmal.dump(out='parsed.json',pretty=True)# beautify and save to parsed.jsonprint(mal)# pretty-prints the json object{"associations":[{"asset_l":"Server","asset_l":"Client",# output truncatedMerge multiple instances by addition (or multiplication or bitwise-or) akin to usingincludeChecktests/test-lib.py:fromdemalimportMalParserprint('Parse and combine two test files.')m1,m2=MalParser('test1.mal'),MalParser('test2.mal')m1.parse()m2.parse()print('First:',m1['version'])# First: 1.0.0print('Second:',m2['version'])# Second: 0.0.0m=m1+m2# combine category/association items, same as "include"print('Combined:',m['version'])# Combined: 0.0.0print('\nModify variable.')v={'version':'1.3.3.7'}m+=vprint('New version:',m['version'])# New version: 1.3.3.7print('\nChange inner dictionary data.')print('Before:',m['categories']['System']['assets']['Host']['attributes']['guessedPassword']['probability'])# Before: Exponential(0.02)m['categories']['System']['assets']['Host']['attributes']['guessedPassword']['probability']='abc'print('After:',m['categories']['System']['assets']['Host']['attributes']['guessedPassword']['probability'])# After: abcprint('\nList assets with dot notation: category.asset')print('m1:',list(m1))print('m2:',list(m2))print('m (m1+m2):',list(m))# m1: ['System.Host', 'System.Network', 'System.Password', 'System.User']# m2: ['C2.A1', 'C2.A2', 'C2.A3', 'C2.A4', 'C2.A5', 'C2.A6', 'C3.A1', 'C4.A1', 'C5.distribution']# m (m1+m2): ['System.Host', 'System.Network', 'System.Password', 'System.User', 'C2.A1', 'C2.A2', 'C2.A3', 'C2.A4', 'C2.A5', 'C2.A6', 'C3.A1', 'C4.A1', 'C5.distribution']print('\nConvert JSON back to MAL syntax.')m.dump_mal(out=sys.stdout)# Output redactedOutputExpect the following approximate output structure when converting to JSON:{"associations":[{"asset_l":"left_asset","asset_r":"right_asset","field_l":"left_field","field_r":"right_field","meta":{"key":"value"# ...},"mult_l":"left_multiplier","mult_r":"right_multiplier","name":"Association"}# ...],"categories":{"Category1":{"assets":{"Asset1":{"abstract":false,"attributes":{"access":{"cia":["C","A"],"meta":{},"probability":"Exponential(0.02)",# etc, or simply null"tags":[],"type":"and"},"authenticate":{"cia":null,"leads_to":{"0":"access","a":"b\\/ c "# result of: let a = ...},"meta":{},"probability":null,"tags":["hidden","debug","trace"],"type":"or"}# ...},"extends":null,"meta":{}}# ...},"meta":{}}},"id":"org.name.project","version":"1.0.0"}When converting to MAL the output should closely resemble the original, albeit more concise.LimitationsMulti-line comments should be avoided.Quotation marks must not be escaped.Expects clean spec-compliant code.ResourcesExample:exampleLang/src/main/mal/exampleLang.malSpec:malcompiler/wiki/MAL-language-specificationSyntax:mal-documentation/wiki/MAL-SyntaxReference:malcompiler-lib/src/main/java/org/mal_lang/compiler/lib/Lexer.javaGuide:https://nse.digital/...MAL author video:https://play.kth.se/...Project page:https://www.kth.se/...Research paper:https://dl.acm.org/doi/10.1145/3230833.3232799Official MAL to JSON converter:mal2json