Exemplo n.º 1
0
    def set(self, value):
        binary = Binary(value)
        upper, lower = binary.split(self.bits)

        if upper != 0:
            self.overflow = True

        self._value = Binary(lower)._value
Exemplo n.º 2
0
    def entitlements(self) -> dict:
        from binary.binary import Binary

        try:
            exe_path = self.executable_path()
            return Binary.get_entitlements(exe_path)
        except NotImplementedError:
            return dict()
Exemplo n.º 3
0
    def executable(self):
        from binary.binary import Binary

        if hasattr(self, 'binary'):
            return self.binary

        linker_paths = self.linker_paths()
        try:
            self.binary = Binary(self.executable_path(),
                                 executable_path=linker_paths[0],
                                 loader_path=linker_paths[1])
        except ValueError:
            # The Binary() constructor throws an error when the supplied
            # binary is not a Mach-O file (for example, if it is a shell script)
            self.binary = None

        return self.binary
Exemplo n.º 4
0
def _entitlements_can_be_parsed(app_bundle: Bundle) -> bool:
    """
    Check whether an application's entitlements can be parsed by libsecinit.
    We only check part of the process, namely the parsing of entitlements via xpc_create_from_plist.

    :param app_bundle: Bundle for which to check whether the entitlements can be parsed
    :type app_bundle: Bundle

    :return: True, iff the entitlements of the main executable can be parsed, else false.
    """
    # No entitlements, no problem
    # If the app contains no entitlements, entitlement validation cannot fail.
    if not app_bundle.has_entitlements():
        return True

    exe_path = app_bundle.executable_path()
    raw_entitlements = Binary.get_entitlements(exe_path, raw=True)

    # Call the local xpc_vuln_checker program that does the actual checking.
    exit_code, _ = tool_named("xpc_vuln_checker")(input=raw_entitlements)

    return exit_code != 1
Exemplo n.º 5
0
def test_binary_addition_int():
    assert Binary(4) + 1 == Binary(5)
Exemplo n.º 6
0
def test_binary_illegal_index():
    with pytest.raises(IndexError):
        Binary('01101010')[7]
Exemplo n.º 7
0
def test_binary_slice():
    assert Binary('01101010')[0:3] == Binary('10')
    assert Binary('01101010')[1:4] == Binary('101')
    assert Binary('01101010')[4:] == Binary('110')
Exemplo n.º 8
0
def test_binary_and():
    assert Binary('1101') & Binary('1') == Binary('1')
Exemplo n.º 9
0
def test_binary_init_bitstr():
    binary = Binary('110')
    assert int(binary) == 6
Exemplo n.º 10
0
def test_binary_division_int():
    assert Binary(20) / 4 == Binary(5)
Exemplo n.º 11
0
def test_binary_init_hex():
    binary = Binary(0x6)
    assert int(binary) == 6
Exemplo n.º 12
0
def test_binary_init_hexstr():
    binary = Binary('0x6')
    assert int(binary) == 6
Exemplo n.º 13
0
def test_binary_split_leading_zeros():
    #    assert Binary('100010110').split(8) == (1, Binary('10110'))

    assert Binary('100010110').split(8) == (1, 22)
Exemplo n.º 14
0
def test_binary_split_exact():
    assert Binary('100010110').split(9) == (0, Binary('100010110'))
Exemplo n.º 15
0
def test_binary_split_remainder():
    assert Binary('110').split(2) == (1, Binary('10'))
Exemplo n.º 16
0
def test_binary_split_no_remainder():
    assert Binary('110').split(4) == (0, Binary('110'))
Exemplo n.º 17
0
def test_binary_addition_binary():
    assert Binary(4) + Binary(5) == Binary(9)
Exemplo n.º 18
0
def test_binary_division_rem_int():
    assert Binary(21) / 4 == Binary(5)
Exemplo n.º 19
0
def test_binary_init_inseq():
    binary = Binary([1, 1, 0])
    assert int(binary) == 6
Exemplo n.º 20
0
def test_binary_get_bit():
    binary = Binary('01011110001')
    assert binary[0] == '1'
    assert binary[5] == '1'
Exemplo n.º 21
0
def test_binary_init_strseq():
    binary = Binary(['1', '1', '0'])
    assert int(binary) == 6
Exemplo n.º 22
0
def test_binary_not():
    assert ~Binary('1101') == Binary('10')
Exemplo n.º 23
0
def test_binary_init_negative():
    with pytest.raises(ValueError):
        binary = Binary(-4)
Exemplo n.º 24
0
def test_binary_shl_pos():
    assert Binary('1101') << 5 == Binary('110100000')
Exemplo n.º 25
0
def test_binary_int():
    binary = Binary(6)
    assert int(binary) == 6
Exemplo n.º 26
0
def test_size_binary_to_binary():
    register8 = SizeBinary(8, 126)
    assert register8.to_binary() == Binary('1111110')
Exemplo n.º 27
0
 def to_binary(self):
     return Binary(self)
Exemplo n.º 28
0
def test_binary_str():
    binary = Binary(6)
    assert str(binary) == '110'
Exemplo n.º 29
0
def test_binary_eq():
    assert Binary(4) == Binary(4)