Exemplo n.º 1
0
    def test_detect(self):
        """Test detect() function."""
        positive = lambda source: self.assertTrue(detect(source))
        negative = lambda source: self.assertFalse(detect(source))

        negative('')
        negative('var a = b')
        positive('eval(function(p,a,c,k,e,r')
        positive('eval ( function(p, a, c, k, e, r')
Exemplo n.º 2
0
    def test_detect(self):
        """Test detect() function."""
        positive = lambda source: self.assertTrue(detect(source))
        negative = lambda source: self.assertFalse(detect(source))

        negative('')
        negative('var a = b')
        positive('eval(function(p,a,c,k,e,r')
        positive('eval ( function(p, a, c, k, e, r')
Exemplo n.º 3
0
def is_artefact_packed(filename, byte_content):
    """
   Returns a tuple (is_packed, unpacked_byte_content) if the artefact is packed using an algorithm
   similar to Dave Edward's p.a.c.k.e.r algorithm. This appears to generate syntax errors compounding feature analysis,
   but we try anyway...
   """
    # dont load the file again if we already have the byte-content...
    if byte_content is None:
        with open(filename, 'rb') as fp:
            byte_content = fp.read()

    try:
        source = fast_decode(byte_content)
        is_packed = packer.detect(source)
        if is_packed:
            ret = packer.unpack(source)
            # TODO FIXME... yuk this is so silly! But we have to return bytes since extract-features.jar program expects that...
            # fortunately most artefacts arent packed so this is not as expensive as it could be...
            result = decode(encode(ret, 'utf-8', 'backslashreplace'),
                            'unicode-escape').encode()
            assert isinstance(result, bytes)
            assert len(result) > 0
            return (True, result)
        # else
        return (False, byte_content)
    except Exception as e:
        # we fail an artefact that is purportedly packed, but which cannot be unpacked...
        raise e
Exemplo n.º 4
0
 def negative(source):
     return self.assertFalse(detect(source))
Exemplo n.º 5
0
 def positive(source):
     return self.assertTrue(detect(source))
Exemplo n.º 6
0
 def check(inp, out):
     return detect(inp) and self.assertEqual(unpack(inp), out)
Exemplo n.º 7
0
        def negative(source): return self.assertFalse(detect(source))

        negative('')
Exemplo n.º 8
0
        def positive(source): return self.assertTrue(detect(source))

        def negative(source): return self.assertFalse(detect(source))
Exemplo n.º 9
0
 def check(inp, out):
     return detect(inp) and self.assertEqual(unpack(inp), out)
Exemplo n.º 10
0
        def positive(source): return self.assertTrue(detect(source))

        def negative(source): return self.assertFalse(detect(source))