Beispiel #1
0
def main(args):
    processes = []
    try:
        console_writer_q, log_file_q, metadata_file_q = set_up_writers(args)
        print("[!] Set up plugins. it may take a few seconds ..")
        sleep(2.5)
        acm = Acf(device_id=args.device_id, threads_num=args.threads)
        acm.setDaemon(True)
        acm.start()

        adb = AndroidDebuggingBridge(args.device_id)

        while True:
            running_processes = get_running_processes(adb, args.package_filter,
                                                      args.user_filter)
            for process in running_processes:
                if process not in processes:
                    p = Process(process, console_writer_q, log_file_q,
                                metadata_file_q)
                    processes.append(process)
                    acm.processes.append(p)
            sleep(1.2)

    except KeyboardInterrupt:
        print("Bye Bye")
        exit(0)
Beispiel #2
0
    def _init_process(self):
        """
        Initialize process class when it's needed by pymem.
        """

        self.process = Process()
Beispiel #3
0
class Pymem(object):
    """Provides class instance methods for general process and memory
manipulations.
    """
    def __init__(self):
        """
        Initialize pymem objects
        """

        self.process = None
        self.memory = None
        self.module = None
        self.pid = None  # refractor
        self.process32 = None  # refractor
        self.process_handle = None

    def _init_process(self):
        """
        Initialize process class when it's needed by pymem.
        """

        self.process = Process()

    def _init_memory(self):
        """
        Initialize memory class when it's needed by pymem.
        """

        self.memory = Memory()

    def _init_module(self):
        """
        Initialize module class when it's needed by pymem.
        """

        self.module = Module()

    @is_init('process')
    def open_process(self, process_id, debug=True):
        """
        Opens a process for interaction.
        """

        if debug:
            if self.process.open_debug(process_id):
                self.process_handle = self.process.h_process
                self.pid = process_id
                self.process32 = self.process.process32
                return True
            return False
        return self.process.open(process_id)

    @is_init('process')
    def open_process_from_name(self, process_name, debug=True, number=0):
        """
        Opens a process from its name for interaction.
        """

        processes = process_from_name(process_name)
        if processes is not None:
            if len(processes) - 1 == number:
                process = processes[len(processes) - 1]
                return self.open_process(process.th32ProcessID, debug)
        return False

    @is_init('memory')
    def read_offset(self, address, selected_type):
        """
        Read memory from a process.
        If the type <T> is supported, this method will provide the required
        call in order to read, from the process. If either the type <T> is not
        supported or process is not Open, the method will raise an Exception.

        Supported types : float, int, uint, long, ulong, int64, uint64, byte
        """

        if self.process.is_process_open:
            if self.memory.is_process_set == False:
                self.memory.set_process(self.process.h_process)
            return self.memory.read_offset(address, selected_type)
        return False

    @is_init('module')
    def list_module32(self):
        """
        Return module (MODULEENTRY32) loaded by current process.
        """

        if self.process32 is not None:
            if self.module.is_process_set == False:
                self.module.set_process32(self.process32)
            return self.module.list_module32()
        return []

    @is_init('module')
    def has_module32(self, module):
        """
        Return True if current process has loaded given module (dll)
        """

        if self.process32 is not None:
            if self.module.is_process_set == False:
                self.module.set_process32(self.process32)
            return self.module.has_module32(module)
        return False
Beispiel #4
0
    def _init_process(self):
        """
        Initialize process class when it's needed by pymem.
        """

        self.process = Process()
Beispiel #5
0
class Pymem(object):
    """Provides class instance methods for general process and memory
manipulations.
    """

    def __init__(self):
        """
        Initialize pymem objects
        """

        self.process = None
        self.memory = None
        self.module = None
        self.pid = None  # refractor
        self.process32 = None  # refractor
        self.process_handle = None

    def _init_process(self):
        """
        Initialize process class when it's needed by pymem.
        """

        self.process = Process()

    def _init_memory(self):
        """
        Initialize memory class when it's needed by pymem.
        """

        self.memory = Memory()

    def _init_module(self):
        """
        Initialize module class when it's needed by pymem.
        """

        self.module = Module()

    @is_init('process')
    def open_process(self, process_id, debug=True):
        """
        Opens a process for interaction.
        """

        if debug:
            if self.process.open_debug(process_id):
                self.process_handle = self.process.h_process
                self.pid = process_id
                self.process32 = self.process.process32
                return True
            return False
        return self.process.open(process_id)

    @is_init('process')
    def open_process_from_name(self, process_name, debug=True, number=0):
        """
        Opens a process from its name for interaction.
        """

        processes = process_from_name(process_name)
        if processes is not None:
            if len(processes) - 1 == number:
                process = processes[len(processes) - 1]
                return self.open_process(process.th32ProcessID, debug)
        return False

    @is_init('memory')
    def read_offset(self, address, selected_type):
        """
        Read memory from a process.
        If the type <T> is supported, this method will provide the required
        call in order to read, from the process. If either the type <T> is not
        supported or process is not Open, the method will raise an Exception.

        Supported types : float, int, uint, long, ulong, int64, uint64, byte
        """

        if self.process.is_process_open:
            if self.memory.is_process_set == False:
                self.memory.set_process(self.process.h_process)
            return self.memory.read_offset(address, selected_type)
        return False

    @is_init('module')
    def list_module32(self):
        """
        Return module (MODULEENTRY32) loaded by current process.
        """

        if self.process32 is not None:
            if self.module.is_process_set == False:
                self.module.set_process32(self.process32)
            return self.module.list_module32()
        return []

    @is_init('module')
    def has_module32(self, module):
        """
        Return True if current process has loaded given module (dll)
        """

        if self.process32 is not None:
            if self.module.is_process_set == False:
                self.module.set_process32(self.process32)
            return self.module.has_module32(module)
        return False
import sys

from modules.process import Event,Process

e1 = Event("e1",1,None)
e2 = Event("e2",2,None)
e3 = Event("e3",4,None)
e4 = Event("e4",3,e2)
e5 = Event("e5",5,None)
e6 = Event("e6",6,None)
e7 = Event("e7",7,e6)
e8 = Event("e8",8,None)
e9 = Event("e9",9,e3)


p1 = Process("P1",[e1,e2,e5],0)
p2 = Process("P2",[e4,e3,e6],0)
p3 = Process("P3",[e7,e8,e9],0)
# p2.display_events()
# if p1.search_event(e1):
#     print("Element found")


# sys.exit()
def lamport(all_processes):
    all_events = []
    for process in all_processes:
        for event in process.events:
            all_events.append(event)

Beispiel #7
0
        print("\nNew process input...")

        arrival_time = input("\tProcess arrival time: ")
        priority = input("\tProcess priority: ")
        burst_time = input("\tProcess burst time: ")

        try:
            arrival_time = int(arrival_time)
            priority = int(priority)
            burst_time = int(burst_time)
        except:
            print("Invalid input...\n")

            continue

        new_process = Process(burst_time, arrival_time, priority)

        processes.append(new_process)
        print(f"New process [id: {new_process.id}] added successfully.")

        user_input = input("Keep adding processes? [y/n] ") == "y"

    print("\n" + tabulate(
        [[
            process.id, process.arrival_time, process.priority,
            process.burst_time
        ] for process in processes],
        headers=["Process", "Arrival Time", "Priority", "Burst Time"]))

    print("\nRunning scheduling algorithms...\n")
Beispiel #8
0
# Processo com prioridade 0 (de tempo real) tentando utilizar impressora 1
procs_descr[0]['printer_cod'] = 1
print('\nVerificação de disponibilidade de recursos do processo 0, prioridade 0, printer 1...')
err_msgs = resmngr._resources_availability(procs_descr[0])
assert len(err_msgs) == 1
print(err_msgs)
procs_descr = original_procs()
err_msgs = []

# Ambos os processos de usuário, processo 1 com modem, impressora 1 e disco 2 alocados e o processo 0
# verificando se pode alocar o modem e o disco 2
err_msgs = []
procs_descr[0]['priority'] = 3
procs_descr[0]['modem'] = 1
procs_descr[0]['disk_cod'] = 2
process1 = Process(priority=1, printer_cod=1, scanner=0, modem=1, disk_cod=2, init_time=0, total_exec_time=0, blocks=0)
resmngr.allocate(process1)
print("\nVerificação de disponibilidade do modem e do disco para o processo 0...")
err_msgs = resmngr._resources_availability(procs_descr[0])
assert len(err_msgs) == 2
print(err_msgs)
err_msgs = []

# Teste do método free()
resmngr.free(process1)
print("\nVerificação de disponibilidade do modem e do disco para o processo 0 depois de chamar free()...")
err_msgs = resmngr._resources_availability(procs_descr[0])
assert len(err_msgs) == 0
print(err_msgs)