Example #1
0
class Darknet(Thread):
    def __init__(self, path, executable, args):
        Thread.__init__(self)
        self.path = path
        self.executable = executable
        self.args = args
        self.addresses = {}
        self.isDarknetRunning = False
        self.darknetProc = None
        self.mw = Pymem()
        self.objects = b'{}'

    def start_darknet(self):
        self.addresses = {}
        os.chdir(DARKNET_PATH)
        self.darknetProc = subprocess.Popen([self.executable] + self.args,
                                            stdout=subprocess.PIPE)
        while 1:
            try:
                self.mw.open_process_from_id(int(self.darknetProc.pid))
                break
            except (pymem.exception.CouldNotOpenProcess, TypeError):
                time.sleep(0.5)

        self.load_addresses()
        os.chdir(LOCAL_PATH)
        self.isDarknetRunning = True

    def stop_darknet(self):
        self.isDarknetRunning = False
        self.addresses = {}
        self.darknetProc.kill()

    def get_darknet_output(self):
        return darknetProc.communicate()[0]

    def run(self):
        try:
            while self.isDarknetRunning:
                length = self.mw.read_uint(
                    int(self.addresses['detectedObjectsLength'][0], 0))
                pointer = self.mw.read_bytes(
                    int(self.addresses['detectedObjects'][0], 0), 8)
                try:  #sometimes memory reads error here
                    self.objects = self.mw.read_bytes(
                        int.from_bytes(pointer, 'little'), length)
                except:
                    pass
                time.sleep(0.01)
        except:
            print("Darknet has stopped running!")
            self.isDarknetRunning = False
            self.addresses = {}

    def load_addresses(self):
        os.chdir(DARKNET_PATH)
        fName = self.executable + "-" + str(
            self.darknetProc.pid) + "-streamedFile.data"
        while not os.path.exists(fName):
            time.sleep(0.5)
        if os.path.isfile(fName):
            with open(fName, 'r') as f:
                self.addresses = json.load(f)
            os.remove(fName)

        os.chdir(LOCAL_PATH)

    def get_objects(self):
        #print(self.objects.decode())
        try:
            return json.loads(self.objects.decode())
        except:
            return None
Example #2
0
    log("Load config:" + key)
    return int(temp.lstrip('0x'), 16)


hs2int = lambda x: int(x.lstrip('0x'), 16)


def get_value(addr, length):
    return int.from_bytes(pm.read_bytes(addr, length), byteorder='little')


pid = config.try_get(config_section_name, 'application_pid')
if pid is not None:
    pm = Pymem()
    log("Load config:" + 'application_pid')
    pm.open_process_from_id(int(pid))
else:
    pm = Pymem(
        config.try_get(config_section_name, 'application_name')
        or 'ffxiv_dx11.exe')
'''
progress_offset = get_config_hex('current_progress') or 0x1D51C8C
cp_offset = get_config_hex('player_cp') or 0x1D307B4
actor_table_offset = get_config_hex('actor_table') or 0x1d2cf20
'''

progress_offset = hs2int(client_offset['CurrentProgress'])
cp_offset = hs2int(client_offset['MaxCp'])
actor_table_offset = hs2int(client_offset['ActorTable'])
cProgress_adr = pm.process_base.lpBaseOfDll + progress_offset
cQuality_adr = cProgress_adr + 0x8