Esempio n. 1
0
    def __getattribute__(self, name):
        if name == 'zones':
            self._zones_list = caching.GetDynamicCacheData(
                "kern._zones_list", [])
            if len(self._zones_list) > 0: return self._zones_list
            zone_array = self.GetGlobalVariable('zone_array')
            for i in range(0, self.GetGlobalVariable('num_zones')):
                self._zones_list.append(addressof(zone_array[i]))
            caching.SaveDynamicCacheData("kern._zones_list", self._zones_list)
            return self._zones_list

        if name == 'threads':
            self._threads_list = caching.GetDynamicCacheData(
                "kern._threads_list", [])
            if len(self._threads_list) > 0: return self._threads_list
            thread_queue_head = self.GetGlobalVariable('threads')
            thread_type = LazyTarget.GetTarget().FindFirstType('thread')
            thread_ptr_type = thread_type.GetPointerType()
            for th in IterateQueue(thread_queue_head, thread_ptr_type,
                                   'threads'):
                self._threads_list.append(th)
            caching.SaveDynamicCacheData("kern._threads_list",
                                         self._threads_list)
            return self._threads_list

        if name == 'tasks':
            self._tasks_list = caching.GetDynamicCacheData(
                "kern._tasks_list", [])
            if len(self._tasks_list) > 0: return self._tasks_list
            task_queue_head = self.GetGlobalVariable('tasks')
            task_type = LazyTarget.GetTarget().FindFirstType('task')
            task_ptr_type = task_type.GetPointerType()
            for tsk in IterateQueue(task_queue_head, task_ptr_type, 'tasks'):
                self._tasks_list.append(tsk)
            caching.SaveDynamicCacheData("kern._tasks_list", self._tasks_list)
            return self._tasks_list

        if name == 'coalitions':
            self._coalitions_list = caching.GetDynamicCacheData(
                "kern._coalitions_list", [])
            if len(self._coalitions_list) > 0: return self._coalitions_list
            coalition_queue_head = self.GetGlobalVariable('coalitions_q')
            coalition_type = LazyTarget.GetTarget().FindFirstType('coalition')
            coalition_ptr_type = coalition_type.GetPointerType()
            for coal in IterateLinkageChain(addressof(coalition_queue_head),
                                            coalition_ptr_type, 'coalitions'):
                self._coalitions_list.append(coal)
            caching.SaveDynamicCacheData("kern._coalitions_list",
                                         self._coalitions_list)
            return self._coalitions_list

        if name == 'thread_groups':
            self._thread_groups_list = caching.GetDynamicCacheData(
                "kern._thread_groups_list", [])
            if len(self._thread_groups_list) > 0:
                return self._thread_groups_list
            thread_groups_queue_head = self.GetGlobalVariable('tg_queue')
            thread_group_type = LazyTarget.GetTarget().FindFirstType(
                'thread_group')
            thread_groups_ptr_type = thread_group_type.GetPointerType()
            for coal in IterateLinkageChain(
                    addressof(thread_groups_queue_head),
                    thread_groups_ptr_type, 'tg_queue_chain'):
                self._thread_groups_list.append(coal)
            caching.SaveDynamicCacheData("kern._thread_groups_list",
                                         self._thread_groups_list)
            return self._thread_groups_list

        if name == 'terminated_tasks':
            self._terminated_tasks_list = caching.GetDynamicCacheData(
                "kern._terminated_tasks_list", [])
            if len(self._terminated_tasks_list) > 0:
                return self._terminated_tasks_list
            task_queue_head = self.GetGlobalVariable('terminated_tasks')
            task_type = LazyTarget.GetTarget().FindFirstType('task')
            task_ptr_type = task_type.GetPointerType()
            for tsk in IterateQueue(task_queue_head, task_ptr_type, 'tasks'):
                self._terminated_tasks_list.append(tsk)
            caching.SaveDynamicCacheData("kern._terminated_tasks_list",
                                         self._terminated_tasks_list)
            return self._terminated_tasks_list

        if name == 'procs':
            self._allproc = caching.GetDynamicCacheData("kern._allproc", [])
            if len(self._allproc) > 0: return self._allproc
            all_proc_head = self.GetGlobalVariable('allproc')
            proc_val = cast(all_proc_head.lh_first, 'proc *')
            while proc_val != 0:
                self._allproc.append(proc_val)
                proc_val = cast(proc_val.p_list.le_next, 'proc *')
            caching.SaveDynamicCacheData("kern._allproc", self._allproc)
            return self._allproc

        if name == 'interrupt_stats':
            self._interrupt_stats_list = caching.GetDynamicCacheData(
                "kern._interrupt_stats_list", [])
            if len(self._interrupt_stats_list) > 0:
                return self._interrupt_stats_list
            interrupt_stats_head = self.GetGlobalVariable(
                'gInterruptAccountingDataList')
            interrupt_stats_type = LazyTarget.GetTarget().FindFirstType(
                'IOInterruptAccountingData')
            interrupt_stats_ptr_type = interrupt_stats_type.GetPointerType()
            for interrupt_stats_obj in IterateQueue(interrupt_stats_head,
                                                    interrupt_stats_ptr_type,
                                                    'chain'):
                self._interrupt_stats_list.append(interrupt_stats_obj)
            caching.SaveDynamicCacheData("kern._interrupt_stats",
                                         self._interrupt_stats_list)
            return self._interrupt_stats_list

        if name == 'zombprocs':
            self._zombproc_list = caching.GetDynamicCacheData(
                "kern._zombproc_list", [])
            if len(self._zombproc_list) > 0: return self._zombproc_list
            zproc_head = self.GetGlobalVariable('zombproc')
            proc_val = cast(zproc_head.lh_first, 'proc *')
            while proc_val != 0:
                self._zombproc_list.append(proc_val)
                proc_val = cast(proc_val.p_list.le_next, 'proc *')
            caching.SaveDynamicCacheData("kern._zombproc_list",
                                         self._zombproc_list)
            return self._zombproc_list

        if name == 'version':
            self._version = caching.GetStaticCacheData("kern.version", None)
            if self._version != None: return self._version
            self._version = str(self.GetGlobalVariable('version'))
            caching.SaveStaticCacheData("kern.version", self._version)
            return self._version

        if name == 'arch':
            self._arch = caching.GetStaticCacheData("kern.arch", None)
            if self._arch != None: return self._arch
            arch = LazyTarget.GetTarget().triple.split('-')[0]
            if arch in ('armv7', 'armv7s', 'armv7k'):
                self._arch = 'arm'
            else:
                self._arch = arch
            caching.SaveStaticCacheData("kern.arch", self._arch)
            return self._arch

        if name == 'ptrsize':
            self._ptrsize = caching.GetStaticCacheData("kern.ptrsize", None)
            if self._ptrsize != None: return self._ptrsize
            arch = LazyTarget.GetTarget().triple.split('-')[0]
            if arch in ('x86_64', 'arm64'):
                self._ptrsize = 8
            else:
                self._ptrsize = 4
            caching.SaveStaticCacheData("kern.ptrsize", self._ptrsize)
            return self._ptrsize

        if name == 'VM_MIN_KERNEL_ADDRESS':
            if self.arch == 'x86_64':
                return unsigned(0xFFFFFF8000000000)
            elif self.arch == 'arm64':
                return unsigned(0xffffffe000000000)
            else:
                return unsigned(0x80000000)

        if name == 'VM_MIN_KERNEL_AND_KEXT_ADDRESS':
            if self.arch == 'x86_64':
                return self.VM_MIN_KERNEL_ADDRESS - 0x80000000
            else:
                return self.VM_MIN_KERNEL_ADDRESS

        return object.__getattribute__(self, name)
Esempio n. 2
0
    def __getattribute__(self, name):
        if name == 'zones':
            self._zones_list = caching.GetDynamicCacheData(
                "kern._zones_list", [])
            if len(self._zones_list) > 0: return self._zones_list
            first_zone = self.GetGlobalVariable('first_zone')
            for z in IterateLinkedList(first_zone, 'next_zone'):
                self._zones_list.append(z)
            caching.SaveDynamicCacheData("kern._zones_list", self._zones_list)
            return self._zones_list

        if name == 'threads':
            self._threads_list = caching.GetDynamicCacheData(
                "kern._threads_list", [])
            if len(self._threads_list) > 0: return self._threads_list
            thread_queue_head = self.GetGlobalVariable('threads')
            thread_type = LazyTarget.GetTarget().FindFirstType('thread')
            thread_ptr_type = thread_type.GetPointerType()
            for th in IterateQueue(thread_queue_head, thread_ptr_type,
                                   'threads'):
                self._threads_list.append(th)
            caching.SaveDynamicCacheData("kern._threads_list",
                                         self._threads_list)
            return self._threads_list

        if name == 'tasks':
            self._tasks_list = caching.GetDynamicCacheData(
                "kern._tasks_list", [])
            if len(self._tasks_list) > 0: return self._tasks_list
            task_queue_head = self.GetGlobalVariable('tasks')
            task_type = LazyTarget.GetTarget().FindFirstType('task')
            task_ptr_type = task_type.GetPointerType()
            for tsk in IterateQueue(task_queue_head, task_ptr_type, 'tasks'):
                self._tasks_list.append(tsk)
            caching.SaveDynamicCacheData("kern._tasks_list", self._tasks_list)
            return self._tasks_list

        if name == 'terminated_tasks':
            self._terminated_tasks_list = caching.GetDynamicCacheData(
                "kern._terminated_tasks_list", [])
            if len(self._terminated_tasks_list) > 0:
                return self._terminated_tasks_list
            task_queue_head = self.GetGlobalVariable('terminated_tasks')
            task_type = LazyTarget.GetTarget().FindFirstType('task')
            task_ptr_type = task_type.GetPointerType()
            for tsk in IterateQueue(task_queue_head, task_ptr_type, 'tasks'):
                self._terminated_tasks_list.append(tsk)
            caching.SaveDynamicCacheData("kern._terminated_tasks_list",
                                         self._terminated_tasks_list)
            return self._terminated_tasks_list

        if name == 'procs':
            self._allproc = caching.GetDynamicCacheData("kern._allproc", [])
            if len(self._allproc) > 0: return self._allproc
            all_proc_head = self.GetGlobalVariable('allproc')
            proc_val = cast(all_proc_head.lh_first, 'proc *')
            while proc_val != 0:
                self._allproc.append(proc_val)
                proc_val = cast(proc_val.p_list.le_next, 'proc *')
            caching.SaveDynamicCacheData("kern._allproc", self._allproc)
            return self._allproc

        if name == 'zombprocs':
            self._zombproc_list = caching.GetDynamicCacheData(
                "kern._zombproc_list", [])
            if len(self._zombproc_list) > 0: return self._zombproc_list
            zproc_head = self.GetGlobalVariable('zombproc')
            proc_val = cast(zproc_head.lh_first, 'proc *')
            while proc_val != 0:
                self._zombproc_list.append(proc_val)
                proc_val = cast(proc_val.p_list.le_next, 'proc *')
            caching.SaveDynamicCacheData("kern._zombproc_list",
                                         self._zombproc_list)
            return self._zombproc_list

        if name == 'version':
            self._version = caching.GetStaticCacheData("kern.version", None)
            if self._version != None: return self._version
            self._version = str(self.GetGlobalVariable('version'))
            caching.SaveStaticCacheData("kern.version", self._version)
            return self._version

        if name == 'arch':
            self._arch = caching.GetStaticCacheData("kern.arch", None)
            if self._arch != None: return self._arch
            arch = LazyTarget.GetTarget().triple.split('-')[0]
            if arch in ('armv7', 'armv7s'):
                self._arch = 'arm'
            else:
                self._arch = arch
            caching.SaveStaticCacheData("kern.arch", self._arch)
            return self._arch

        if name == 'ptrsize':
            self._ptrsize = caching.GetStaticCacheData("kern.ptrsize", None)
            if self._ptrsize != None: return self._ptrsize
            arch = LazyTarget.GetTarget().triple.split('-')[0]
            if arch in ('x86_64'):
                self._ptrsize = 8
            else:
                self._ptrsize = 4
            caching.SaveStaticCacheData("kern.ptrsize", self._ptrsize)
            return self._ptrsize

        return object.__getattribute__(self, name)