def set(self, value): binary = Binary(value) upper, lower = binary.split(self.bits) if upper != 0: self.overflow = True self._value = Binary(lower)._value
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()
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
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
def test_binary_addition_int(): assert Binary(4) + 1 == Binary(5)
def test_binary_illegal_index(): with pytest.raises(IndexError): Binary('01101010')[7]
def test_binary_slice(): assert Binary('01101010')[0:3] == Binary('10') assert Binary('01101010')[1:4] == Binary('101') assert Binary('01101010')[4:] == Binary('110')
def test_binary_and(): assert Binary('1101') & Binary('1') == Binary('1')
def test_binary_init_bitstr(): binary = Binary('110') assert int(binary) == 6
def test_binary_division_int(): assert Binary(20) / 4 == Binary(5)
def test_binary_init_hex(): binary = Binary(0x6) assert int(binary) == 6
def test_binary_init_hexstr(): binary = Binary('0x6') assert int(binary) == 6
def test_binary_split_leading_zeros(): # assert Binary('100010110').split(8) == (1, Binary('10110')) assert Binary('100010110').split(8) == (1, 22)
def test_binary_split_exact(): assert Binary('100010110').split(9) == (0, Binary('100010110'))
def test_binary_split_remainder(): assert Binary('110').split(2) == (1, Binary('10'))
def test_binary_split_no_remainder(): assert Binary('110').split(4) == (0, Binary('110'))
def test_binary_addition_binary(): assert Binary(4) + Binary(5) == Binary(9)
def test_binary_division_rem_int(): assert Binary(21) / 4 == Binary(5)
def test_binary_init_inseq(): binary = Binary([1, 1, 0]) assert int(binary) == 6
def test_binary_get_bit(): binary = Binary('01011110001') assert binary[0] == '1' assert binary[5] == '1'
def test_binary_init_strseq(): binary = Binary(['1', '1', '0']) assert int(binary) == 6
def test_binary_not(): assert ~Binary('1101') == Binary('10')
def test_binary_init_negative(): with pytest.raises(ValueError): binary = Binary(-4)
def test_binary_shl_pos(): assert Binary('1101') << 5 == Binary('110100000')
def test_binary_int(): binary = Binary(6) assert int(binary) == 6
def test_size_binary_to_binary(): register8 = SizeBinary(8, 126) assert register8.to_binary() == Binary('1111110')
def to_binary(self): return Binary(self)
def test_binary_str(): binary = Binary(6) assert str(binary) == '110'
def test_binary_eq(): assert Binary(4) == Binary(4)