コード例 #1
0
ファイル: bytecode.py プロジェクト: HuSunMyan/CodeForAndroid
def method2format( output, _format="png", mx = None, raw = False ) :
    """
        Export method to a specific file format

        @param output : output filename
        @param _format : format type (png, jpg ...) (default : png)
        @param mx : specify the MethodAnalysis object
        @param raw : use directly a dot raw buffer
    """
    try :
        import pydot
    except ImportError :
        error("module pydot not found")

    buff = "digraph code {\n"
    buff += "graph [bgcolor=white];\n"
    buff += "node [color=lightgray, style=filled shape=box fontname=\"Courier\" fontsize=\"8\"];\n"

    if raw == False :
        buff += method2dot( mx )
    else :
        buff += raw

    buff += "}"

    d = pydot.graph_from_dot_data( buff )
    if d :
        getattr(d, "write_" + _format)( output )
コード例 #2
0
ファイル: bytecode.py プロジェクト: daz0/apkinspector
def method2format(output, _format="png", mx=None, raw=None):
    """
        Export method to a specific file format

        @param output : output filename
        @param _format : format type (png, jpg ...) (default : png)
        @param mx : specify the MethodAnalysis object
        @param raw : use directly a dot raw buffer if None
    """
    try:
        import pydot
    except ImportError:
        error("module pydot not found")

    buff = "digraph {\n"
    buff += "graph [rankdir=TB]\n"
    buff += "node [shape=plaintext]\n"

    if raw:
        data = raw
    else:
        data = method2dot(mx)

    # subgraphs cluster
    buff += "subgraph cluster_" + hashlib.md5(output).hexdigest() + " {\nlabel=\"%s\"\n" % data['name']
    buff += data['nodes']
    buff += "}\n"

    # subgraphs edges
    buff += data['edges']
    buff += "}\n"

    d = pydot.graph_from_dot_data(buff)
    if d:
        getattr(d, "write_" + _format.lower())(output)
コード例 #3
0
ファイル: bytecode.py プロジェクト: wjk20120522/SADroid
def method2format(
    output,
    _format='png',
    mx=None,
    raw=None,
    ):
    """
        Export method to a specific file format

        @param output : output filename
        @param _format : format type (png, jpg ...) (default : png)
        @param mx : specify the MethodAnalysis object
        @param raw : use directly a dot raw buffer if None
    """

    try:
        import pydot
    except ImportError:
        error('module pydot not found')

    buff = 'digraph {\n'
    buff += 'graph [rankdir=TB]\n'
    buff += 'node [shape=plaintext]\n'

    if raw:
        data = raw
    else:
        data = method2dot(mx)

    # subgraphs cluster

    buff += 'subgraph cluster_' + hashlib.md5(output).hexdigest() \
        + ''' {
label="%s"
''' % data['name']
    buff += data['nodes']
    buff += '}\n'

    # subgraphs edges

    buff += data['edges']
    buff += '}\n'

    d = pydot.graph_from_dot_data(buff)
    if d:
        getattr(d, 'write_' + _format.lower())(output)
コード例 #4
0
ファイル: jvm_generate.py プロジェクト: Bludge0n/AREsoft
    def __init__(self, _analysis) :
        self.__analysis = _analysis

        try :
            from networkx import DiGraph
            from networkx import draw_graphviz, write_dot
        except ImportError :
            error("module networkx not found")

        self.__G = DiGraph()

        for m in self.__analysis.get_methods() :
            for bb in m.basic_blocks.get() :
                for trace in bb.stack_traces.get() :
                    for mre in jvm.MATH_JVM_RE :
                        if mre[0].match( trace[2].get_name() ) :
                            for i in trace[3].gets() :
                                self._add( str(i) )
コード例 #5
0
    def __init__(self, _analysis):
        self.__analysis = _analysis

        try:
            from networkx import DiGraph
            from networkx import draw_graphviz, write_dot
        except ImportError:
            error("module networkx not found")

        self.__G = DiGraph()

        for m in self.__analysis.get_methods():
            for bb in m.basic_blocks.get():
                for trace in bb.stack_traces.get():
                    for mre in jvm.MATH_JVM_RE:
                        if mre[0].match(trace[2].get_name()):
                            for i in trace[3].gets():
                                self._add(str(i))
コード例 #6
0
def method2format(output, _format="png", mx=None, raw=None):
    """
        Export method to a specific file format

        @param output : output filename
        @param _format : format type (png, jpg ...) (default : png)
        @param mx : specify the MethodAnalysis object
        @param raw : use directly a dot raw buffer if None
    """
    try:
        import pydot
    except ImportError:
        error("module pydot not found")

    buff = "digraph {\n"
    buff += "graph [rankdir=TB]\n"
    buff += "node [shape=plaintext]\n"

    if raw:
        data = raw
    else:
        data = method2dot(mx)

    # subgraphs cluster
    buff += "subgraph cluster_" + hashlib.md5(
        output).hexdigest() + " {\nlabel=\"%s\"\n" % data['name']
    buff += data['nodes']
    buff += "}\n"

    # subgraphs edges
    buff += data['edges']
    buff += "}\n"

    #print buff
    d = pydot.graph_from_dot_data(buff)
    if d:
        getattr(d, "write_" + _format.lower())(output)
コード例 #7
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Androguard.  If not, see <http://www.gnu.org/licenses/>.

import hashlib, string, random

from androconf import error

try :
    from networkx import DiGraph, all_pairs_dijkstra_path_length, simple_cycles
    from networkx import draw_graphviz, write_dot
except ImportError :
    error("module networkx not found")

def INIT() :
    return WM_L2

# name, access_flags, descriptor
# initial value
# all access (write)
# all dependencies actions (read / write )
class Field :
    def __init__(self, _vm, _analysis, _vm_generate, field, offsets, real=False) :
        self.__vm = _vm
        self.__analysis = _analysis
        self.__vm_generate = _vm_generate

        self.__field = field
コード例 #8
0
ファイル: risk.py プロジェクト: pombredanne/AREsoft
def create_system_method_one_score():
    try:
        import fuzzy
    except ImportError:
        error("please install pyfuzzy to use this module !")

    import fuzzy.System
    import fuzzy.InputVariable
    import fuzzy.fuzzify.Plain
    import fuzzy.OutputVariable
    import fuzzy.defuzzify.COGS
    import fuzzy.set.Polygon
    import fuzzy.set.Singleton
    import fuzzy.set.Triangle
    import fuzzy.Adjective
    import fuzzy.operator.Input
    import fuzzy.operator.Compound
    import fuzzy.norm.Min
    import fuzzy.norm.Max
    import fuzzy.Rule

    system = fuzzy.System.System()

    input_Length_MS = fuzzy.InputVariable.InputVariable(fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_AndroidEntropy_MS = fuzzy.InputVariable.InputVariable(fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_JavaEntropy_MS = fuzzy.InputVariable.InputVariable(fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_Permissions_MS = fuzzy.InputVariable.InputVariable(fuzzify=fuzzy.fuzzify.Plain.Plain())

    # Input variables

    # Length
    system.variables["input_Length_MS"] = input_Length_MS
    input_Length_MS.adjectives[LOW_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (50.0, 1.0), (100.0, 0.0)])
    )
    input_Length_MS.adjectives[AVERAGE_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(50.0, 0.0), (100.0, 1.0), (150.0, 1.0), (300.0, 0.0)])
    )
    input_Length_MS.adjectives[HIGH_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(150.0, 0.0), (200.0, 1.0), (300.0, 1.0), (400.0, 0.0)])
    )
    input_Length_MS.adjectives[PERFECT_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(350.0, 0.0), (400.0, 1.0), (500.0, 1.0)])
    )

    # Android Entropy
    system.variables["input_AndroidEntropy_MS"] = input_AndroidEntropy_MS
    input_AndroidEntropy_MS.adjectives[LOW_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (2.0, 1.0), (4.0, 0.0)])
    )
    input_AndroidEntropy_MS.adjectives[HIGH_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(3.0, 0.0), (4.0, 1.0), (30.0, 1.0)])
    )

    # Java Entropy
    system.variables["input_JavaEntropy_MS"] = input_JavaEntropy_MS
    input_JavaEntropy_MS.adjectives[LOW_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (2.0, 1.0), (4.0, 0.0)])
    )
    input_JavaEntropy_MS.adjectives[HIGH_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(3.0, 0.0), (4.0, 1.0), (30.0, 1.0)])
    )

    # Permissions
    system.variables["input_Permissions_MS"] = input_Permissions_MS
    input_Permissions_MS.adjectives[LOW_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (3.0, 1.0), (4.0, 0.0)])
    )
    input_Permissions_MS.adjectives[AVERAGE_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(3.0, 0.0), (4.0, 1.0), (8.0, 1.0), (9.0, 0.0)])
    )
    input_Permissions_MS.adjectives[HIGH_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(8.0, 0.0), (10.0, 1.0), (12.0, 1.0), (13.0, 0.0)])
    )
    input_Permissions_MS.adjectives[PERFECT_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(12.0, 0.0), (13.0, 1.0), (20.0, 1.0)])
    )

    # Output variables
    output_method_score = fuzzy.OutputVariable.OutputVariable(
        defuzzify=fuzzy.defuzzify.COGS.COGS(), description="method one score", min=0.0, max=100.0
    )
    output_method_score.adjectives[NULL_METHOD_SCORE] = fuzzy.Adjective.Adjective(fuzzy.set.Singleton.Singleton(0.0))
    output_method_score.adjectives[AVERAGE_METHOD_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Singleton.Singleton(50.0)
    )
    output_method_score.adjectives[HIGH_METHOD_SCORE] = fuzzy.Adjective.Adjective(fuzzy.set.Singleton.Singleton(80.0))
    output_method_score.adjectives[PERFECT_METHOD_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Singleton.Singleton(100.0)
    )

    system.variables["output_method_one_score"] = output_method_score

    add_system_rule(
        system,
        "android entropy null",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_method_one_score"].adjectives[NULL_METHOD_SCORE]],
            operator=fuzzy.operator.Input.Input(system.variables["input_AndroidEntropy_MS"].adjectives[LOW_SCORE]),
        ),
    )

    add_system_rule(
        system,
        "java entropy null",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_method_one_score"].adjectives[NULL_METHOD_SCORE]],
            operator=fuzzy.operator.Input.Input(system.variables["input_JavaEntropy_MS"].adjectives[LOW_SCORE]),
        ),
    )

    add_system_rule(
        system,
        "permissions null",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_method_one_score"].adjectives[NULL_METHOD_SCORE]],
            operator=fuzzy.operator.Input.Input(system.variables["input_Permissions_MS"].adjectives[LOW_SCORE]),
        ),
    )

    add_system_rule(
        system,
        "permissions average",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_method_one_score"].adjectives[AVERAGE_METHOD_SCORE]],
            operator=fuzzy.operator.Input.Input(system.variables["input_Permissions_MS"].adjectives[AVERAGE_SCORE]),
        ),
    )

    add_system_rule(
        system,
        "permissions high",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_method_one_score"].adjectives[HIGH_METHOD_SCORE]],
            operator=fuzzy.operator.Input.Input(system.variables["input_Permissions_MS"].adjectives[HIGH_SCORE]),
        ),
    )

    add_system_rule(
        system,
        "permissions perfect",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_method_one_score"].adjectives[PERFECT_METHOD_SCORE]],
            operator=fuzzy.operator.Input.Input(system.variables["input_Permissions_MS"].adjectives[PERFECT_SCORE]),
        ),
    )

    add_system_rule(
        system,
        "length permissions perfect",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_method_one_score"].adjectives[PERFECT_METHOD_SCORE]],
            operator=fuzzy.operator.Compound.Compound(
                fuzzy.norm.Min.Min(),
                fuzzy.operator.Input.Input(system.variables["input_Length_MS"].adjectives[PERFECT_SCORE]),
                fuzzy.operator.Input.Input(system.variables["input_Permissions_MS"].adjectives[PERFECT_SCORE]),
            ),
        ),
    )

    add_system_rule(
        system,
        "length AndroidEntropy perfect",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_method_one_score"].adjectives[HIGH_METHOD_SCORE]],
            operator=fuzzy.operator.Compound.Compound(
                fuzzy.norm.Min.Min(),
                fuzzy.operator.Input.Input(system.variables["input_Length_MS"].adjectives[PERFECT_SCORE]),
                fuzzy.operator.Input.Input(system.variables["input_AndroidEntropy_MS"].adjectives[HIGH_SCORE]),
            ),
        ),
    )

    add_system_rule(
        system,
        "length JavaEntropy perfect",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_method_one_score"].adjectives[HIGH_METHOD_SCORE]],
            operator=fuzzy.operator.Compound.Compound(
                fuzzy.norm.Min.Min(),
                fuzzy.operator.Input.Input(system.variables["input_Length_MS"].adjectives[PERFECT_SCORE]),
                fuzzy.operator.Input.Input(system.variables["input_JavaEntropy_MS"].adjectives[HIGH_SCORE]),
            ),
        ),
    )

    return system
コード例 #9
0
ファイル: risk.py プロジェクト: pombredanne/AREsoft
def create_system_risk():
    try:
        import fuzzy
    except ImportError:
        error("please install pyfuzzy to use this module !")

    import fuzzy.System
    import fuzzy.InputVariable
    import fuzzy.fuzzify.Plain
    import fuzzy.OutputVariable
    import fuzzy.defuzzify.COGS
    import fuzzy.set.Polygon
    import fuzzy.set.Singleton
    import fuzzy.set.Triangle
    import fuzzy.Adjective
    import fuzzy.operator.Input
    import fuzzy.operator.Compound
    import fuzzy.norm.Min
    import fuzzy.norm.Max
    import fuzzy.Rule

    system = fuzzy.System.System()

    input_Dangerous_Risk = fuzzy.InputVariable.InputVariable(fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_Money_Risk = fuzzy.InputVariable.InputVariable(fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_Privacy_Risk = fuzzy.InputVariable.InputVariable(fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_Binary_Risk = fuzzy.InputVariable.InputVariable(fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_Internet_Risk = fuzzy.InputVariable.InputVariable(fuzzify=fuzzy.fuzzify.Plain.Plain())

    # Input variables

    # Dangerous Risk
    system.variables["input_Dangerous_Risk"] = input_Dangerous_Risk
    input_Dangerous_Risk.adjectives[LOW_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (8.0, 1.0), (12.0, 0.0)])
    )
    input_Dangerous_Risk.adjectives[AVERAGE_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(8.0, 0.0), (16.0, 1.0), (20.0, 0.0)])
    )
    input_Dangerous_Risk.adjectives[HIGH_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(16.0, 0.0), (24.0, 1.0)])
    )

    # Money Risk
    system.variables["input_Money_Risk"] = input_Money_Risk
    input_Money_Risk.adjectives[LOW_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (5.0, 0.0)])
    )
    input_Money_Risk.adjectives[HIGH_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(4.0, 0.0), (6.0, 1.0), (30.0, 1.0)])
    )

    # Privacy Risk
    system.variables["input_Privacy_Risk"] = input_Privacy_Risk
    input_Privacy_Risk.adjectives[LOW_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (6.0, 0.0)])
    )
    input_Privacy_Risk.adjectives[HIGH_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(4.0, 0.0), (30.0, 1.0)])
    )

    # Binary Risk
    system.variables["input_Binary_Risk"] = input_Binary_Risk
    input_Binary_Risk.adjectives[LOW_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (20.0, 0.0)])
    )
    input_Binary_Risk.adjectives[HIGH_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(10.0, 0.0), (30.0, 1.0)])
    )

    # Internet Risk
    system.variables["input_Internet_Risk"] = input_Internet_Risk
    input_Internet_Risk.adjectives[LOW_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (4.0, 0.0)])
    )
    input_Internet_Risk.adjectives[HIGH_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(2.0, 0.0), (27.0, 1.0)])
    )

    # Output variables
    output_malware_risk = fuzzy.OutputVariable.OutputVariable(
        defuzzify=fuzzy.defuzzify.COGS.COGS(), description="malware risk", min=0.0, max=100.0
    )
    output_malware_risk.adjectives[NULL_MALWARE_RISK] = fuzzy.Adjective.Adjective(fuzzy.set.Singleton.Singleton(0.0))
    output_malware_risk.adjectives[AVERAGE_MALWARE_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Singleton.Singleton(20.0)
    )
    output_malware_risk.adjectives[HIGH_MALWARE_RISK] = fuzzy.Adjective.Adjective(fuzzy.set.Singleton.Singleton(80.0))
    output_malware_risk.adjectives[UNACCEPTABLE_MALWARE_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Singleton.Singleton(100.0)
    )

    system.variables["output_malware_risk"] = output_malware_risk

    # Rules
    # RULE 1 : IF input_Dangerous_Risk IS Low THEN output_risk_malware IS Null;

    add_system_rule(
        system,
        "r1",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_malware_risk"].adjectives[NULL_MALWARE_RISK]],
            operator=fuzzy.operator.Input.Input(system.variables["input_Dangerous_Risk"].adjectives[LOW_RISK]),
        ),
    )

    # RULE 2 : IF input_Dangerous_Risk IS Average THEN output_risk_malware IS Average;
    add_system_rule(
        system,
        "r2",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_malware_risk"].adjectives[AVERAGE_MALWARE_RISK]],
            operator=fuzzy.operator.Input.Input(system.variables["input_Dangerous_Risk"].adjectives[AVERAGE_RISK]),
        ),
    )

    # RULE 3 : IF input_Dangerous_Risk IS High THEN output_risk_malware IS High;
    add_system_rule(
        system,
        "r3",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_malware_risk"].adjectives[HIGH_MALWARE_RISK]],
            operator=fuzzy.operator.Input.Input(system.variables["input_Dangerous_Risk"].adjectives[HIGH_RISK]),
        ),
    )

    # RULE 4 : IF input_Dangerous_Risk IS Low AND input_Binary_Risk IS High THEN output_risk_malware IS High;
    add_system_rule(
        system,
        "r4",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_malware_risk"].adjectives[HIGH_MALWARE_RISK]],
            operator=fuzzy.operator.Input.Input(system.variables["input_Binary_Risk"].adjectives[HIGH_RISK]),
        ),
    )

    # RULE 5 : IF input_Money_Risk IS High THEN output_risk_malware IS Unacceptable;
    add_system_rule(
        system,
        "r5",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_malware_risk"].adjectives[UNACCEPTABLE_MALWARE_RISK]],
            operator=fuzzy.operator.Input.Input(system.variables["input_Money_Risk"].adjectives[HIGH_RISK]),
        ),
    )

    # RULE 6 : IF input_Dangerous_Risk IS High AND input_Binary_Risk IS High THEN output_risk_malware IS Unacceptable;
    add_system_rule(
        system,
        "r6",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_malware_risk"].adjectives[UNACCEPTABLE_MALWARE_RISK]],
            operator=fuzzy.operator.Compound.Compound(
                fuzzy.norm.Min.Min(),
                fuzzy.operator.Input.Input(system.variables["input_Dangerous_Risk"].adjectives[HIGH_RISK]),
                fuzzy.operator.Input.Input(system.variables["input_Binary_Risk"].adjectives[HIGH_RISK]),
            ),
        ),
    )

    # RULE 7 : IF input_Internet_Risk IS Low AND input_Privacy_Risk IS High THEN output_risk_malware IS High;
    add_system_rule(
        system,
        "r7",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_malware_risk"].adjectives[HIGH_MALWARE_RISK]],
            operator=fuzzy.operator.Compound.Compound(
                fuzzy.norm.Min.Min(),
                fuzzy.operator.Input.Input(system.variables["input_Internet_Risk"].adjectives[LOW_RISK]),
                fuzzy.operator.Input.Input(system.variables["input_Privacy_Risk"].adjectives[HIGH_RISK]),
            ),
        ),
    )

    # RULE 8 : IF input_Internet_Risk IS High AND input_Privacy_Risk IS High THEN output_risk_malware IS Unacceptable;
    add_system_rule(
        system,
        "r8",
        fuzzy.Rule.Rule(
            adjective=[system.variables["output_malware_risk"].adjectives[UNACCEPTABLE_MALWARE_RISK]],
            operator=fuzzy.operator.Compound.Compound(
                fuzzy.norm.Min.Min(),
                fuzzy.operator.Input.Input(system.variables["input_Internet_Risk"].adjectives[HIGH_RISK]),
                fuzzy.operator.Input.Input(system.variables["input_Privacy_Risk"].adjectives[HIGH_RISK]),
            ),
        ),
    )

    return system
コード例 #10
0
ファイル: risk.py プロジェクト: capoitaly/Kali
def create_system() :
    try :
        import fuzzy
    except ImportError :
        error("please install pyfuzzy to use this module !")

    import fuzzy.System
    import fuzzy.InputVariable
    import fuzzy.fuzzify.Plain
    import fuzzy.OutputVariable
    import fuzzy.defuzzify.COGS
    import fuzzy.set.Polygon
    import fuzzy.set.Singleton
    import fuzzy.set.Triangle
    import fuzzy.Adjective
    import fuzzy.operator.Input
    import fuzzy.operator.Compound
    import fuzzy.norm.Min
    import fuzzy.norm.Max
    import fuzzy.Rule
    
    system = fuzzy.System.System()

    input_Dangerous_Risk = fuzzy.InputVariable.InputVariable(fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_Money_Risk = fuzzy.InputVariable.InputVariable(fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_Privacy_Risk = fuzzy.InputVariable.InputVariable(fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_Binary_Risk = fuzzy.InputVariable.InputVariable(fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_Internet_Risk = fuzzy.InputVariable.InputVariable(fuzzify=fuzzy.fuzzify.Plain.Plain())
    
    # Input variables

        # Dangerous Risk
    system.variables["input_Dangerous_Risk"] = input_Dangerous_Risk
    in1_set = fuzzy.set.Polygon.Polygon([(0.0, 1.0), (8.0, 1.0), (12.0, 0.0)])
    in1 = fuzzy.Adjective.Adjective(in1_set)
    input_Dangerous_Risk.adjectives[LOW_RISK] = in1

    in2_set = fuzzy.set.Polygon.Polygon([(8.0, 0.0), (16.0, 1.0), (20.0, 0.0)])
    in2 = fuzzy.Adjective.Adjective(in2_set)
    input_Dangerous_Risk.adjectives[AVERAGE_RISK] = in2

    in3_set = fuzzy.set.Polygon.Polygon([(16.0, 0.0), (24.0, 1.0)])
    in3 = fuzzy.Adjective.Adjective(in3_set)
    input_Dangerous_Risk.adjectives[HIGH_RISK] = in3
    
        # Money Risk
    system.variables["input_Money_Risk"] = input_Money_Risk
    in4_set = fuzzy.set.Polygon.Polygon([(0.0, 1.0), (5.0, 0.0)])
    in4 = fuzzy.Adjective.Adjective(in4_set)
    input_Money_Risk.adjectives[LOW_RISK] = in4

    in5_set = fuzzy.set.Polygon.Polygon([(4.0, 0.0), (6.0, 1.0), (30.0, 1.0)])
    in5 = fuzzy.Adjective.Adjective(in5_set)
    input_Money_Risk.adjectives[HIGH_RISK] = in5

        # Privacy Risk
    system.variables["input_Privacy_Risk"] = input_Privacy_Risk
    in6_set = fuzzy.set.Polygon.Polygon([(0.0, 1.0), (6.0, 0.0)])
    in6 = fuzzy.Adjective.Adjective(in6_set)
    input_Privacy_Risk.adjectives[LOW_RISK] = in6

    in7_set = fuzzy.set.Polygon.Polygon([(4.0, 0.0), (30.0, 1.0)])
    in7 = fuzzy.Adjective.Adjective(in7_set)
    input_Privacy_Risk.adjectives[HIGH_RISK] = in7

        # Binary Risk
    system.variables["input_Binary_Risk"] = input_Binary_Risk
    in8_set = fuzzy.set.Polygon.Polygon([(0.0, 1.0), (20.0, 0.0)])
    in8 = fuzzy.Adjective.Adjective(in8_set)
    input_Binary_Risk.adjectives[LOW_RISK] = in8

    in9_set = fuzzy.set.Polygon.Polygon([(10.0, 0.0), (30.0, 1.0)]) 
    in9 = fuzzy.Adjective.Adjective(in9_set)
    input_Binary_Risk.adjectives[HIGH_RISK] = in9

        # Internet Risk
    system.variables["input_Internet_Risk"] = input_Internet_Risk
    in10_set = fuzzy.set.Polygon.Polygon([(0.0, 1.0), (4.0, 0.0)])
    in10 = fuzzy.Adjective.Adjective(in10_set)
    input_Internet_Risk.adjectives[LOW_RISK] = in10

    in11_set = fuzzy.set.Polygon.Polygon([(2.0, 0.0), (27.0, 1.0)]) 
    in11 = fuzzy.Adjective.Adjective(in11_set)
    input_Internet_Risk.adjectives[HIGH_RISK] = in11


    # Output variables
    output_malware_risk = fuzzy.OutputVariable.OutputVariable(
                            defuzzify=fuzzy.defuzzify.COGS.COGS(),
                            description="malware risk",
                            min=0.0,max=100.0,
                        )
    output_malware_risk.adjectives[NULL_MALWARE_RISK] = fuzzy.Adjective.Adjective(fuzzy.set.Singleton.Singleton(0.0))
    output_malware_risk.adjectives[AVERAGE_MALWARE_RISK] = fuzzy.Adjective.Adjective(fuzzy.set.Singleton.Singleton(20.0))
    output_malware_risk.adjectives[HIGH_MALWARE_RISK] = fuzzy.Adjective.Adjective(fuzzy.set.Singleton.Singleton(80.0))
    output_malware_risk.adjectives[UNACCEPTABLE_MALWARE_RISK] = fuzzy.Adjective.Adjective(fuzzy.set.Singleton.Singleton(100.0))

    system.variables["output_malware_risk"] = output_malware_risk

    # Rules
    #RULE 1 : IF input_Dangerous_Risk IS Faible THEN output_risk_malware IS Nul;
    rule1 = fuzzy.Rule.Rule(
                adjective=[system.variables["output_malware_risk"].adjectives[NULL_MALWARE_RISK]],
                operator=fuzzy.operator.Input.Input( system.variables["input_Dangerous_Risk"].adjectives[LOW_RISK] )
    )
     
    #RULE 2 : IF input_Dangerous_Risk IS Moyen THEN output_risk_malware IS Moyen;
    rule2 = fuzzy.Rule.Rule(
                adjective=[system.variables["output_malware_risk"].adjectives[AVERAGE_MALWARE_RISK]],
                operator=fuzzy.operator.Input.Input( system.variables["input_Dangerous_Risk"].adjectives[AVERAGE_RISK] )
    )
     
     
    #RULE 3 : IF input_Dangerous_Risk IS Eleve THEN output_risk_malware IS Eleve;
    rule3 = fuzzy.Rule.Rule(
                adjective=[system.variables["output_malware_risk"].adjectives[HIGH_MALWARE_RISK]],
                operator=fuzzy.operator.Input.Input( system.variables["input_Dangerous_Risk"].adjectives[HIGH_RISK] )
    )
      
     
    #RULE 4 : IF input_Dangerous_Risk IS Faible AND input_Binary_Risk IS Eleve THEN output_risk_malware IS Eleve;
    rule4 = fuzzy.Rule.Rule(
                adjective=[system.variables["output_malware_risk"].adjectives[HIGH_MALWARE_RISK]],
                operator = fuzzy.operator.Input.Input( system.variables["input_Binary_Risk"].adjectives[HIGH_RISK] )
    )
    
    #RULE 5 : IF input_Money_Risk IS Eleve THEN output_risk_malware IS Inacceptable;
    rule5 = fuzzy.Rule.Rule(
                adjective=[system.variables["output_malware_risk"].adjectives[UNACCEPTABLE_MALWARE_RISK]],
                operator=fuzzy.operator.Input.Input( system.variables["input_Money_Risk"].adjectives[HIGH_RISK] )
    )
    
    #RULE 6 : IF input_Dangerous_Risk IS Eleve AND input_Binary_Risk IS Eleve THEN output_risk_malware IS Inacceptable;
    rule6 = fuzzy.Rule.Rule(
                adjective=[system.variables["output_malware_risk"].adjectives[UNACCEPTABLE_MALWARE_RISK]],
                operator=fuzzy.operator.Compound.Compound(
                    fuzzy.norm.Min.Min(),
                    fuzzy.operator.Input.Input( system.variables["input_Dangerous_Risk"].adjectives[HIGH_RISK] ),
                    fuzzy.operator.Input.Input( system.variables["input_Binary_Risk"].adjectives[HIGH_RISK] ) )
    )


    #RULE 7 : IF input_Internet_Risk IS Faible AND input_Privacy_Risk IS Eleve THEN output_risk_malware IS Eleve;
    rule7 = fuzzy.Rule.Rule(
                adjective=[system.variables["output_malware_risk"].adjectives[HIGH_MALWARE_RISK]],
                operator=fuzzy.operator.Compound.Compound(
                    fuzzy.norm.Min.Min(),
                    fuzzy.operator.Input.Input( system.variables["input_Internet_Risk"].adjectives[LOW_RISK] ),
                    fuzzy.operator.Input.Input( system.variables["input_Privacy_Risk"].adjectives[HIGH_RISK] ) )
    )
    
    #RULE 8 : IF input_Internet_Risk IS Eleve AND input_Privacy_Risk IS Eleve THEN output_risk_malware IS Inacceptable;
    rule8 = fuzzy.Rule.Rule(
                adjective=[system.variables["output_malware_risk"].adjectives[UNACCEPTABLE_MALWARE_RISK]],
                operator=fuzzy.operator.Compound.Compound(
                    fuzzy.norm.Min.Min(),
                    fuzzy.operator.Input.Input( system.variables["input_Internet_Risk"].adjectives[HIGH_RISK] ),
                    fuzzy.operator.Input.Input( system.variables["input_Privacy_Risk"].adjectives[HIGH_RISK] ) )
    )
        
    system.rules["r1"] = rule1
    system.rules["r2"] = rule2
    system.rules["r3"] = rule3
    system.rules["r4"] = rule4
    system.rules["r5"] = rule5
    system.rules["r6"] = rule6
    system.rules["r7"] = rule7
    system.rules["r8"] = rule8

    return system
コード例 #11
0
+        r['subgraphs'].append({ 'name': method.m.class_name+"."+method.m.name+"->"+method.m.get_descriptor(), 'nodes' : blocks_html, 'edges' : edges_html })        
+
+    return r      
+
+def diff2format( output, _format="png", data = False ) :
+    """
+        Export method to a specific file format
+
+        @param output : output filename
+        @param _format : format type (png, jpg ...) (default : png)
+        @param raw : subgraphs dicts list
+    """
+    try :
+        import pydot
+    except ImportError :
+        error("module pydot not found")
+
+    buff = "digraph {\n"
+    buff += "graph [ rankdir=TB]\n"
+    buff += "node [shape=plaintext]\n"
+
+    i=0
+    # subgraphs cluster
+    for subgraph in data['subgraphs']:
+        buff += "subgraph cluster_" + hashlib.md5(output).hexdigest() + str(i) + " {\nlabel=\"%s\"\n" % subgraph['name']
+        buff +=  subgraph['nodes']
+        buff += "}\n"
+        i+=1
+        
+    # subgraphs edges
+    buff += subgraph['edges']
コード例 #12
0
def create_system_method_one_score():
    try:
        import fuzzy
    except ImportError:
        error("please install pyfuzzy to use this module !")

    import fuzzy.System
    import fuzzy.InputVariable
    import fuzzy.fuzzify.Plain
    import fuzzy.OutputVariable
    import fuzzy.defuzzify.COGS
    import fuzzy.set.Polygon
    import fuzzy.set.Singleton
    import fuzzy.set.Triangle
    import fuzzy.Adjective
    import fuzzy.operator.Input
    import fuzzy.operator.Compound
    import fuzzy.norm.Min
    import fuzzy.norm.Max
    import fuzzy.Rule

    system = fuzzy.System.System()

    input_Length_MS = fuzzy.InputVariable.InputVariable(
        fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_AndroidEntropy_MS = fuzzy.InputVariable.InputVariable(
        fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_JavaEntropy_MS = fuzzy.InputVariable.InputVariable(
        fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_Permissions_MS = fuzzy.InputVariable.InputVariable(
        fuzzify=fuzzy.fuzzify.Plain.Plain())

    # Input variables

    # Length
    system.variables["input_Length_MS"] = input_Length_MS
    input_Length_MS.adjectives[LOW_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (50.0, 1.0), (100.0, 0.0)]))
    input_Length_MS.adjectives[AVERAGE_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(50.0, 0.0), (100.0, 1.0), (150.0, 1.0),
                                   (300.0, 0.0)]))
    input_Length_MS.adjectives[HIGH_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(150.0, 0.0), (200.0, 1.0), (300.0, 1.0),
                                   (400.0, 0.0)]))
    input_Length_MS.adjectives[PERFECT_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(350.0, 0.0), (400.0, 1.0), (500.0, 1.0)]))

    # Android Entropy
    system.variables["input_AndroidEntropy_MS"] = input_AndroidEntropy_MS
    input_AndroidEntropy_MS.adjectives[LOW_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (2.0, 1.0), (4.0, 0.0)]))
    input_AndroidEntropy_MS.adjectives[HIGH_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(3.0, 0.0), (4.0, 1.0), (30.0, 1.0)]))

    # Java Entropy
    system.variables["input_JavaEntropy_MS"] = input_JavaEntropy_MS
    input_JavaEntropy_MS.adjectives[LOW_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (2.0, 1.0), (4.0, 0.0)]))
    input_JavaEntropy_MS.adjectives[HIGH_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(3.0, 0.0), (4.0, 1.0), (30.0, 1.0)]))

    # Permissions
    system.variables["input_Permissions_MS"] = input_Permissions_MS
    input_Permissions_MS.adjectives[LOW_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (3.0, 1.0), (4.0, 0.0)]))
    input_Permissions_MS.adjectives[AVERAGE_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(3.0, 0.0), (4.0, 1.0), (8.0, 1.0),
                                   (9.0, 0.0)]))
    input_Permissions_MS.adjectives[HIGH_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(8.0, 0.0), (10.0, 1.0), (12.0, 1.0),
                                   (13.0, 0.0)]))
    input_Permissions_MS.adjectives[PERFECT_SCORE] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(12.0, 0.0), (13.0, 1.0), (20.0, 1.0)]))

    # Output variables
    output_method_score = fuzzy.OutputVariable.OutputVariable(
        defuzzify=fuzzy.defuzzify.COGS.COGS(),
        description="method one score",
        min=0.0,
        max=100.0,
    )
    output_method_score.adjectives[
        NULL_METHOD_SCORE] = fuzzy.Adjective.Adjective(
            fuzzy.set.Singleton.Singleton(0.0))
    output_method_score.adjectives[
        AVERAGE_METHOD_SCORE] = fuzzy.Adjective.Adjective(
            fuzzy.set.Singleton.Singleton(50.0))
    output_method_score.adjectives[
        HIGH_METHOD_SCORE] = fuzzy.Adjective.Adjective(
            fuzzy.set.Singleton.Singleton(80.0))
    output_method_score.adjectives[
        PERFECT_METHOD_SCORE] = fuzzy.Adjective.Adjective(
            fuzzy.set.Singleton.Singleton(100.0))

    system.variables["output_method_one_score"] = output_method_score

    add_system_rule(
        system, "android entropy null",
        fuzzy.Rule.Rule(adjective=[
            system.variables["output_method_one_score"].
            adjectives[NULL_METHOD_SCORE]
        ],
                        operator=fuzzy.operator.Input.Input(
                            system.variables["input_AndroidEntropy_MS"].
                            adjectives[LOW_SCORE])))

    add_system_rule(
        system, "java entropy null",
        fuzzy.Rule.Rule(adjective=[
            system.variables["output_method_one_score"].
            adjectives[NULL_METHOD_SCORE]
        ],
                        operator=fuzzy.operator.Input.Input(
                            system.variables["input_JavaEntropy_MS"].
                            adjectives[LOW_SCORE])))

    add_system_rule(
        system, "permissions null",
        fuzzy.Rule.Rule(adjective=[
            system.variables["output_method_one_score"].
            adjectives[NULL_METHOD_SCORE]
        ],
                        operator=fuzzy.operator.Input.Input(
                            system.variables["input_Permissions_MS"].
                            adjectives[LOW_SCORE])))

    add_system_rule(
        system, "permissions average",
        fuzzy.Rule.Rule(adjective=[
            system.variables["output_method_one_score"].
            adjectives[AVERAGE_METHOD_SCORE]
        ],
                        operator=fuzzy.operator.Input.Input(
                            system.variables["input_Permissions_MS"].
                            adjectives[AVERAGE_SCORE])))

    add_system_rule(
        system, "permissions high",
        fuzzy.Rule.Rule(adjective=[
            system.variables["output_method_one_score"].
            adjectives[HIGH_METHOD_SCORE]
        ],
                        operator=fuzzy.operator.Input.Input(
                            system.variables["input_Permissions_MS"].
                            adjectives[HIGH_SCORE])))

    add_system_rule(
        system, "permissions perfect",
        fuzzy.Rule.Rule(adjective=[
            system.variables["output_method_one_score"].
            adjectives[PERFECT_METHOD_SCORE]
        ],
                        operator=fuzzy.operator.Input.Input(
                            system.variables["input_Permissions_MS"].
                            adjectives[PERFECT_SCORE])))

    add_system_rule(
        system, "length permissions perfect",
        fuzzy.Rule.Rule(
            adjective=[
                system.variables["output_method_one_score"].
                adjectives[PERFECT_METHOD_SCORE]
            ],
            operator=fuzzy.operator.Compound.Compound(
                fuzzy.norm.Min.Min(),
                fuzzy.operator.Input.Input(system.variables["input_Length_MS"].
                                           adjectives[PERFECT_SCORE]),
                fuzzy.operator.Input.Input(
                    system.variables["input_Permissions_MS"].
                    adjectives[PERFECT_SCORE]))))

    add_system_rule(
        system, "length AndroidEntropy perfect",
        fuzzy.Rule.Rule(
            adjective=[
                system.variables["output_method_one_score"].
                adjectives[HIGH_METHOD_SCORE]
            ],
            operator=fuzzy.operator.Compound.Compound(
                fuzzy.norm.Min.Min(),
                fuzzy.operator.Input.Input(system.variables["input_Length_MS"].
                                           adjectives[PERFECT_SCORE]),
                fuzzy.operator.Input.Input(
                    system.variables["input_AndroidEntropy_MS"].
                    adjectives[HIGH_SCORE]))))

    add_system_rule(
        system, "length JavaEntropy perfect",
        fuzzy.Rule.Rule(
            adjective=[
                system.variables["output_method_one_score"].
                adjectives[HIGH_METHOD_SCORE]
            ],
            operator=fuzzy.operator.Compound.Compound(
                fuzzy.norm.Min.Min(),
                fuzzy.operator.Input.Input(system.variables["input_Length_MS"].
                                           adjectives[PERFECT_SCORE]),
                fuzzy.operator.Input.Input(
                    system.variables["input_JavaEntropy_MS"].
                    adjectives[HIGH_SCORE]))))

    return system
コード例 #13
0
def create_system_risk():
    try:
        import fuzzy
    except ImportError:
        error("please install pyfuzzy to use this module !")

    import fuzzy.System
    import fuzzy.InputVariable
    import fuzzy.fuzzify.Plain
    import fuzzy.OutputVariable
    import fuzzy.defuzzify.COGS
    import fuzzy.set.Polygon
    import fuzzy.set.Singleton
    import fuzzy.set.Triangle
    import fuzzy.Adjective
    import fuzzy.operator.Input
    import fuzzy.operator.Compound
    import fuzzy.norm.Min
    import fuzzy.norm.Max
    import fuzzy.Rule

    system = fuzzy.System.System()

    input_Dangerous_Risk = fuzzy.InputVariable.InputVariable(
        fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_Money_Risk = fuzzy.InputVariable.InputVariable(
        fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_Privacy_Risk = fuzzy.InputVariable.InputVariable(
        fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_Binary_Risk = fuzzy.InputVariable.InputVariable(
        fuzzify=fuzzy.fuzzify.Plain.Plain())
    input_Internet_Risk = fuzzy.InputVariable.InputVariable(
        fuzzify=fuzzy.fuzzify.Plain.Plain())

    # Input variables

    # Dangerous Risk
    system.variables["input_Dangerous_Risk"] = input_Dangerous_Risk
    input_Dangerous_Risk.adjectives[LOW_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (8.0, 1.0), (12.0, 0.0)]))
    input_Dangerous_Risk.adjectives[AVERAGE_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(8.0, 0.0), (16.0, 1.0), (20.0, 0.0)]))
    input_Dangerous_Risk.adjectives[HIGH_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(16.0, 0.0), (24.0, 1.0)]))

    # Money Risk
    system.variables["input_Money_Risk"] = input_Money_Risk
    input_Money_Risk.adjectives[LOW_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (5.0, 0.0)]))
    input_Money_Risk.adjectives[HIGH_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(4.0, 0.0), (6.0, 1.0), (30.0, 1.0)]))

    # Privacy Risk
    system.variables["input_Privacy_Risk"] = input_Privacy_Risk
    input_Privacy_Risk.adjectives[LOW_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (6.0, 0.0)]))
    input_Privacy_Risk.adjectives[HIGH_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(4.0, 0.0), (30.0, 1.0)]))

    # Binary Risk
    system.variables["input_Binary_Risk"] = input_Binary_Risk
    input_Binary_Risk.adjectives[LOW_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (20.0, 0.0)]))
    input_Binary_Risk.adjectives[HIGH_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(10.0, 0.0), (30.0, 1.0)]))

    # Internet Risk
    system.variables["input_Internet_Risk"] = input_Internet_Risk
    input_Internet_Risk.adjectives[LOW_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(0.0, 1.0), (4.0, 0.0)]))
    input_Internet_Risk.adjectives[HIGH_RISK] = fuzzy.Adjective.Adjective(
        fuzzy.set.Polygon.Polygon([(2.0, 0.0), (27.0, 1.0)]))

    # Output variables
    output_malware_risk = fuzzy.OutputVariable.OutputVariable(
        defuzzify=fuzzy.defuzzify.COGS.COGS(),
        description="malware risk",
        min=0.0,
        max=100.0,
    )
    output_malware_risk.adjectives[
        NULL_MALWARE_RISK] = fuzzy.Adjective.Adjective(
            fuzzy.set.Singleton.Singleton(0.0))
    output_malware_risk.adjectives[
        AVERAGE_MALWARE_RISK] = fuzzy.Adjective.Adjective(
            fuzzy.set.Singleton.Singleton(20.0))
    output_malware_risk.adjectives[
        HIGH_MALWARE_RISK] = fuzzy.Adjective.Adjective(
            fuzzy.set.Singleton.Singleton(80.0))
    output_malware_risk.adjectives[
        UNACCEPTABLE_MALWARE_RISK] = fuzzy.Adjective.Adjective(
            fuzzy.set.Singleton.Singleton(100.0))

    system.variables["output_malware_risk"] = output_malware_risk

    # Rules
    #RULE 1 : IF input_Dangerous_Risk IS Low THEN output_risk_malware IS Null;

    add_system_rule(
        system, "r1",
        fuzzy.Rule.Rule(adjective=[
            system.variables["output_malware_risk"].
            adjectives[NULL_MALWARE_RISK]
        ],
                        operator=fuzzy.operator.Input.Input(
                            system.variables["input_Dangerous_Risk"].
                            adjectives[LOW_RISK])))

    #RULE 2 : IF input_Dangerous_Risk IS Average THEN output_risk_malware IS Average;
    add_system_rule(
        system, "r2",
        fuzzy.Rule.Rule(adjective=[
            system.variables["output_malware_risk"].
            adjectives[AVERAGE_MALWARE_RISK]
        ],
                        operator=fuzzy.operator.Input.Input(
                            system.variables["input_Dangerous_Risk"].
                            adjectives[AVERAGE_RISK])))

    #RULE 3 : IF input_Dangerous_Risk IS High THEN output_risk_malware IS High;
    add_system_rule(
        system, "r3",
        fuzzy.Rule.Rule(adjective=[
            system.variables["output_malware_risk"].
            adjectives[HIGH_MALWARE_RISK]
        ],
                        operator=fuzzy.operator.Input.Input(
                            system.variables["input_Dangerous_Risk"].
                            adjectives[HIGH_RISK])))

    #RULE 4 : IF input_Dangerous_Risk IS Low AND input_Binary_Risk IS High THEN output_risk_malware IS High;
    add_system_rule(
        system, "r4",
        fuzzy.Rule.Rule(
            adjective=[
                system.variables["output_malware_risk"].
                adjectives[HIGH_MALWARE_RISK]
            ],
            operator=fuzzy.operator.Input.Input(
                system.variables["input_Binary_Risk"].adjectives[HIGH_RISK])))

    #RULE 5 : IF input_Money_Risk IS High THEN output_risk_malware IS Unacceptable;
    add_system_rule(
        system, "r5",
        fuzzy.Rule.Rule(
            adjective=[
                system.variables["output_malware_risk"].
                adjectives[UNACCEPTABLE_MALWARE_RISK]
            ],
            operator=fuzzy.operator.Input.Input(
                system.variables["input_Money_Risk"].adjectives[HIGH_RISK])))

    #RULE 6 : IF input_Dangerous_Risk IS High AND input_Binary_Risk IS High THEN output_risk_malware IS Unacceptable;
    add_system_rule(
        system, "r6",
        fuzzy.Rule.Rule(adjective=[
            system.variables["output_malware_risk"].
            adjectives[UNACCEPTABLE_MALWARE_RISK]
        ],
                        operator=fuzzy.operator.Compound.Compound(
                            fuzzy.norm.Min.Min(),
                            fuzzy.operator.Input.Input(
                                system.variables["input_Dangerous_Risk"].
                                adjectives[HIGH_RISK]),
                            fuzzy.operator.Input.Input(
                                system.variables["input_Binary_Risk"].
                                adjectives[HIGH_RISK]))))

    #RULE 7 : IF input_Internet_Risk IS Low AND input_Privacy_Risk IS High THEN output_risk_malware IS High;
    add_system_rule(
        system, "r7",
        fuzzy.Rule.Rule(adjective=[
            system.variables["output_malware_risk"].
            adjectives[HIGH_MALWARE_RISK]
        ],
                        operator=fuzzy.operator.Compound.Compound(
                            fuzzy.norm.Min.Min(),
                            fuzzy.operator.Input.Input(
                                system.variables["input_Internet_Risk"].
                                adjectives[LOW_RISK]),
                            fuzzy.operator.Input.Input(
                                system.variables["input_Privacy_Risk"].
                                adjectives[HIGH_RISK]))))

    #RULE 8 : IF input_Internet_Risk IS High AND input_Privacy_Risk IS High THEN output_risk_malware IS Unacceptable;
    add_system_rule(
        system, "r8",
        fuzzy.Rule.Rule(adjective=[
            system.variables["output_malware_risk"].
            adjectives[UNACCEPTABLE_MALWARE_RISK]
        ],
                        operator=fuzzy.operator.Compound.Compound(
                            fuzzy.norm.Min.Min(),
                            fuzzy.operator.Input.Input(
                                system.variables["input_Internet_Risk"].
                                adjectives[HIGH_RISK]),
                            fuzzy.operator.Input.Input(
                                system.variables["input_Privacy_Risk"].
                                adjectives[HIGH_RISK]))))

    return system