예제 #1
0
def dex2jar(f):
    # 如果操作的是apk,则将apk中全部的dex转换为jar文件输出到在apk同级目录下
    if f.endswith('.apk'):
        output_jar_prefix = os.path.splitext(f)[0] + '_'
        temp_dex_dir = PathManager.get_temp_dir_path()
        ZipManager.unzip_dexFile_to_dest(f, temp_dex_dir)
        filenames = os.listdir(temp_dex_dir)
        for dex_name in filenames:
            if dex_name.endswith('.dex'):
                dex_file_path = os.path.join(temp_dex_dir, dex_name)
                jar_file = output_jar_prefix + os.path.splitext(
                    dex_name)[0] + '.jar'
                retcode, msg = star.runcmd2([
                    PathManager.get_dex2jar_path(), dex_file_path, '-f', '-o',
                    jar_file
                ])
                if retcode == 0:
                    star.run_cmd_asyn([PathManager.get_jdgui_path(), jar_file])
                    print('dex2jar ok')
        shutil.rmtree(temp_dex_dir)
        return retcode, msg
    elif f.endswith('.dex'):
        jarFile = os.path.splitext(f)[0] + '.jar'
        retcode, msg = star.runcmd2(
            [PathManager.get_dex2jar_path(), f, '-f', '-o', jarFile])
        if retcode == 0:
            star.run_cmd_asyn([PathManager.get_jdgui_path(), jarFile])
            print('dex2jar ok')
        return retcode, msg
    else:
        print(u'选择文件不合法,文件格式需要是apk或者dex格式')
        os.system("pause")
        return 0, None
def importMetaData(moduleName, site=None):
    locPath = 'HazardServices/hazardMetaData/'
    # Use the base class to get the BASE file path
    scriptName = 'CommonMetaData.py'
    fileName = locPath + scriptName

    pathMgr = PathManager()
    filePath = pathMgr.getLocalizationFile(fileName,
                                           loctype='COMMON_STATIC',
                                           loclevel='BASE').getFile().name
    basePath = filePath.replace(scriptName, '')

    # Import all the modules in the formats BASE directory using PythonOverrider.
    for s in basePath.split(os.path.pathsep):
        if os.path.exists(s):
            scriptfiles = os.listdir(s)
            for filename in scriptfiles:
                split = string.split(filename, ".")
                if len(split) == 2 and len(split[0]) > 0 and split[1] == "py":
                    if sys.modules.has_key(split[0]):
                        clearModuleAttributes(split[0])
                    tmpModule = importModule(locPath + filename,
                                             localizedSite=site)

    # Reload the desired metadata module again since above import order
    # is random which may cause subclasses to have old references to superclasses.
    return importModule(locPath + moduleName + '.py', localizedSite=site)
예제 #3
0
def axml2txt(f):
    ret = 0
    msg = None
    ext = os.path.splitext(f)[1].lower()
    txtFile = None
    if ext == '.apk':
        print('axml2txt .apk')
        zfile = zipfile.ZipFile(f, 'r', compression=zipfile.ZIP_DEFLATED)
        for p in zfile.namelist():
            if p == "AndroidManifest.xml":
                axmlFile = os.path.join(Utils.getparent(f),
                                        'AndroidManifest.xml')
                file(axmlFile, 'wb').write(zfile.read(p))
                txtFile = axmlFile + '.txt'
                star.runcmd2([
                    PathManager.get_axmlprinter_path(), axmlFile, '>', txtFile
                ])
                break
        os.remove(axmlFile)
    else:
        txtFile = f + '.txt'
        ret, msg = star.runcmd2(
            [PathManager.get_axmlprinter_path(), f, '>', txtFile])
        print('axml2txt .xml')
    if os.path.exists(txtFile):
        star.run_cmd_asyn(['notepad', txtFile])

    print('axml2txt ok')
    return ret, msg
예제 #4
0
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(745, 683)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout_3.setObjectName("verticalLayout_3")
        self.pathWidget = PathManager(self.centralwidget)
        self.pathWidget.setMinimumSize(QtCore.QSize(0, 256))
        self.pathWidget.setObjectName("pathWidget")
        self.verticalLayout_3.addWidget(self.pathWidget)
        self.frame = QtWidgets.QFrame(self.centralwidget)
        self.frame.setMaximumSize(QtCore.QSize(16777215, 25))
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.frame)
        self.verticalLayout.setContentsMargins(-1, 0, 0, 0)
        self.verticalLayout.setSpacing(0)
        self.verticalLayout.setObjectName("verticalLayout")
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.label = QtWidgets.QLabel(self.frame)
        self.label.setObjectName("label")
        self.horizontalLayout_2.addWidget(self.label)
        self.root = QtWidgets.QLineEdit(self.frame)
        self.root.setObjectName("root")
        self.horizontalLayout_2.addWidget(self.root)
        self.browse = QtWidgets.QPushButton(self.frame)
        self.browse.setObjectName("browse")
        self.horizontalLayout_2.addWidget(self.browse)
        self.verticalLayout.addLayout(self.horizontalLayout_2)
        self.verticalLayout_3.addWidget(self.frame)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 745, 21))
        self.menubar.setObjectName("menubar")
        self.menuFile = QtWidgets.QMenu(self.menubar)
        self.menuFile.setObjectName("menuFile")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionOpen = QtWidgets.QAction(MainWindow)
        self.actionOpen.setObjectName("actionOpen")
        self.actionSave = QtWidgets.QAction(MainWindow)
        self.actionSave.setObjectName("actionSave")
        self.actionSave_As = QtWidgets.QAction(MainWindow)
        self.actionSave_As.setObjectName("actionSave_As")
        self.actionNew = QtWidgets.QAction(MainWindow)
        self.actionNew.setObjectName("actionNew")
        self.menuFile.addAction(self.actionNew)
        self.menuFile.addAction(self.actionOpen)
        self.menuFile.addAction(self.actionSave)
        self.menuFile.addAction(self.actionSave_As)
        self.menubar.addAction(self.menuFile.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
예제 #5
0
    def writeJsonFile(self, filename, id, dataDicts, replaceFile=False):
        if replaceFile:
            mode = "w"
        else:
            mode = "w+"

        pathMgr = PathManager()
        vtecFile = pathMgr.getLocalizationFile(str(filename + ".json"),
                                               'CAVE_STATIC', 'USER')
        fd = vtecFile.getFile(mode)
        fd.write(json.dumps(dataDicts, sort_keys=True, indent=4))
        fd.close()
        vtecFile.save()
예제 #6
0
def viewapk(apk_path):
    infoFile = os.path.splitext(apk_path)[0] + '_apkinfo.txt'
    retcode, msg = star.runcmd2(
        [PathManager.get_aapt_path(), 'dump', 'badging', apk_path])
    if retcode == 0:
        package = star.find("package: name='(.*?)'", msg)
        versionCode = star.find("versionCode='(.*?)'", msg)
        versionName = star.find("versionName='(.*?)'", msg)
        appName = star.find("application-label:'(.*?)'", msg)
        activity = star.find("launchable-activity: name='(.*?)'", msg)
        print(package)
        print(versionCode)
        print(versionName)
        print(appName)
        print(activity)
        # APK类型探测
        app_type, is_game_app = detectApk(apk_path)
        if is_game_app:
            info = '软件名称: {0}\n软件包名: {1}\n软件版本: {2} ( {3} )\n启动Activity: {4}\n该apk为游戏类型app,使用的游戏引擎为: {5}\n'.format(
                appName, package, versionName, versionCode, activity,
                ''.join(app_type))
        else:
            info = '软件名称: {0}\n软件包名: {1}\n软件版本: {2} ( {3} )\n启动Activity: {4}\n'.format(
                appName, package, versionName, versionCode, activity)
        star.log(info, infoFile)

        # 打开日志文件
        if os.path.exists(infoFile):
            star.run_cmd_asyn(['notepad', infoFile])
    return retcode, msg
예제 #7
0
def extracticon(apk_path):
    apk_dir = os.path.splitext(apk_path)[0]
    retcode, msg = star.runcmd2(
        [PathManager.get_aapt_path(), 'dump', 'badging', apk_path])
    if retcode == 0:
        icons = star.findall("icon.*?'(.+?)'", msg)
        icons = list(set(icons))
        # icons匹配出来的字符串可能不是图片格式,这里过滤删除下
        for i in range(len(icons) - 1, -1, -1):
            if not (icons[i].endswith('.png') or icons[i].endswith('.jpg') or
                    icons[i].endswith('.jpeg') or icons[i].endswith('.bmp')):
                icons.remove(icons[i])

        zfile = zipfile.ZipFile(apk_path,
                                'r',
                                compression=zipfile.ZIP_DEFLATED)

        for icon in icons:
            icon_name = '_' + os.path.splitext(os.path.basename(icon))[0]
            icon_file = apk_dir + '_temp.png'
            file(icon_file, 'wb').write(zfile.read(icon))
            image = Image.open(icon_file)
            image_size = '_' + str(image.size[0])
            image.close()  # 一定要调用close否则下面的rename会出现异常
            new_icon_file = apk_dir + icon_name + image_size + '.png'
            if not os.path.exists(new_icon_file):
                os.rename(icon_file, new_icon_file)
            else:  # 如果当前目录下已存在提取后重新命名的文件,则删除临时文件而不是重命名
                os.remove(icon_file)
        print(u'不同分辨率的图标已经提取完成,路径位于和apk同级目录下')
    return retcode, msg
예제 #8
0
파일: Vamos.py 프로젝트: rmtew/amitools
  def __init__(self, raw_mem, cpu, cfg):
    self.raw_mem = raw_mem
    self.ram_size = raw_mem.ram_size
    self.cpu = cpu
    self.cpu_type = cfg.cpu
    self.path_mgr = PathManager( cfg )

    # create a label manager and error tracker
    self.label_mgr = LabelManager()
    self.error_tracker = ErrorTracker(cpu, self.label_mgr)
    self.label_mgr.error_tracker = self.error_tracker

    # set a label for first two dwords
    label = LabelRange("zero_page",0,8)
    self.label_mgr.add_label(label)
    
    # create memory access
    self.mem = MainMemory(self.raw_mem, self.error_tracker)
    self.mem.ctx = self

    # create memory allocator
    self.mem_begin = 0x1000
    self.alloc = MemoryAlloc(self.mem, 0, self.ram_size, self.mem_begin, self.label_mgr)
    
    # create segment loader
    self.seg_loader = SegmentLoader( self.mem, self.alloc, self.label_mgr, self.path_mgr )

    # lib manager
    self.lib_mgr = LibManager( self.label_mgr, cfg)
    
    # no current process right now
    self.process = None
    self.proc_list = []
예제 #9
0
def importModule(name,
                 loctype='COMMON_STATIC',
                 level=None,
                 localizedSite=None,
                 localizationUser=None):
    """
    Takes a name (filename and localization path) and the localization type and finds the 
    file and overrides it, and returns the module
    
    Args:
            name : the name and path of the file in localization
            loctype : a string representation of the localization type
            level : a string representation of the localization level (BASE, SITE, etc.)
            localizedSite: the site that localization information should be
                retrieved for (if applicable)
            localizationUser: the user that localization information should
                be retrieved for (if applicable)
    
    Returns:
            a module that has all the correct methods after being overridden
    """
    if not JEP_AVAILABLE:
        if localizationHost is None:
            localizationHost = THRIFT_HOST

        if localizationPort is None:
            localizationPort = THRIFT_PORT

        return PythonOverriderPure.importModule(name, localizationHost,
                                                localizationPort,
                                                localizedSite,
                                                localizationUser, loctype,
                                                level)

    pathManager = PathManager()
    tieredFiles = pathManager.getTieredLocalizationFile(loctype, name)
    availableLevels = pathManager.getAvailableLevels()
    levels = PythonOverriderCore._buildLocalizationLevelsList(
        availableLevels, level)

    lfiles = []
    for _level in levels:
        if _level in tieredFiles:
            lfiles.append(tieredFiles[_level].getPath())
    themodule = PythonOverriderCore._internalOverride(lfiles)
    return themodule
예제 #10
0
def zipalign(apk_path):
    output_apk_name = os.path.splitext(
        os.path.basename(apk_path))[0] + '_aligned.apk'
    retcode, msg = star.runcmd2([
        PathManager.get_zipaligin_tool_path(), '-f', '4', apk_path,
        os.path.join(Utils.getparent(apk_path), output_apk_name)
    ])
    if retcode == 0:
        print('zipalign successed')
    return retcode, msg
예제 #11
0
def viewwrapper(file_path):
    dict = {'apkPath': file_path, 'aaptPath': PathManager.get_aapt_path()}
    apk_detect = ApkDetect(dict)
    apk_detect.getXmlInfo()
    apk_detect.getWrapperSdk()
    if apk_detect.is_netease_protect:  # 如果是网易加固,提示使用插件获取
        print(apk_detect.wrapperSdk)
        print(u'要查看网易加固版本号,您可使用插件“网易加固版本号”获取')
    else:
        print(apk_detect.wrapperSdk)
    return apk_detect.wrapperSdk, None
예제 #12
0
    def __init__(self, scriptPath, localizationPath, site):
        super(ProductInterface, self).__init__(scriptPath, localizationPath,
                                               site)
        self.pathMgr = PathManager()
        # TODO - every file that exists in localization and is class based needs
        # to be imported via PythonOverrider. Not just the 2 below directories.

        # Import the textUtilities dir using PythonOverrider
        self.importTextUtility(reloadModules=False)
        # Import the eventUtilities dir using PythonOverrider
        self.importEventUtility(reloadModules=False)
        # Import all the generator modules using PythonOverrider.
        self.importModules()
        # Import all the formatter modules using PythonOverrider.
        self.importFormatters()
        self.logger = logging.getLogger("ProductInterface")
        self.logger.addHandler(
            UFStatusHandler.UFStatusHandler(
                "com.raytheon.uf.common.hazards.productgen",
                "ProductInterface",
                level=logging.INFO))
        self.logger.setLevel(logging.INFO)
예제 #13
0
    def __init__(self, markers, occupancy_map, pos_init, pos_goal, max_speed,
                 min_speed, max_omega, x_spacing, y_spacing, t_cam_to_body,
                 mode):
        """
        Initialize the class
        """
        # plan a path around obstacles using dijkstra's algorithm
        print('Planning path...')
        path = findShortestPath(occupancy_map,
                                x_spacing,
                                y_spacing,
                                pos_init[0:2],
                                pos_goal[0:2],
                                dilate=2)
        print('Done!')
        self.path_manager = PathManager(path)
        self.kalman_filter = KalmanFilter(markers, pos_init)
        self.diff_drive_controller = DiffDriveController(
            max_speed, min_speed, max_omega)

        if 'HARDWARE' in mode:
            # Handles all the ROS related items
            self.ros_interface = ROSInterface(t_cam_to_body)

        elif 'SIMULATE' in mode:
            self.robot_sim = RobotSim(markers, occupancy_map, pos_init,
                                      pos_goal, max_speed, max_omega,
                                      x_spacing, y_spacing,
                                      self.path_manager.path, mode)

        self.user_control = UserControl()
        self.vel = 0  # save velocity to use for kalman filter
        self.goal = self.path_manager.getNextWaypoint()  # get first waypoint

        # for logging postion data to csv file
        self.stateSaved = []
        self.tagsSaved = []
        self.waypoints = []
예제 #14
0
def plug_get_neprotect_ver(apk_path):
    version = None
    try:
        import NEProtectVerManager
        version = NEProtectVerManager.get_version(apk_path,
                                                  PathManager.get_aapt_path())
    except Exception as e:
        print(traceback.format_exc())
        os.system('pause')
        return None, None
    if version:
        print(u'当前apk使用的网易易盾加密的版本号为: ' + version)
        return version, None
    else:
        return None, None
예제 #15
0
def viewsign(f):
    infoFile = os.path.splitext(f)[0] + '_signinfo.txt'
    check_v2sign_tool_path = PathManager.get_checkV2_sign_tool_path()
    code, info = star.runcmd2(['java', '-jar', check_v2sign_tool_path, f])
    if code == 0:
        msg_dic = json.loads(info)
        if msg_dic['isV1OK']:  # 如果使用了v1签名,不管是否使用了v2签名检测v1签名
            code, info = star.runcmd2(
                [Constant.KEYTOOL_FILENAME, '-printcert', '-jarfile', f])
            if msg_dic['isV2']:
                info += u"该apk使用了V1+V2签名,其中V1签名信息如上所示"
            else:
                info += u"该apk仅仅用了V1签名,其签名信息如上所示"
        if msg_dic['isV2'] and not msg_dic['isV1OK']:  # 未使用v1签名,仅仅使用了v2签名
            info += u"该apk仅仅使用了v2签名,未使用v1签名,具体信息如上所示"
    if code == 0:
        star.log(info, infoFile)
        if os.path.exists(infoFile):
            star.run_cmd_asyn(['notepad', infoFile])

    return code, info
예제 #16
0
    def __init__(self, scriptPath, localizationPath, site):
        super(RecommenderInterface, self).__init__(scriptPath,
                                                   localizationPath, site)
        self.pathMgr = PathManager()
        # Import the textUtilities dir using PythonOverrider
        self.importTextUtility(reloadModules=False)
        # Import the eventUtilities dir using PythonOverrider
        self.importEventUtility(reloadModules=False)
        # Import all the generator modules using PythonOverrider.
        self.importModules()

        # This variable will be used to cache the Pythonic version of the
        # event set supplied by the last call to getDialogInfo(), or the
        # last call to getSpatialInfo() that included a non-None event set.
        # It is then used as the event set between then and the next
        # invocation of execute() for calls to the methods getSpatialInfo(),
        # handleDialogParameterChange(), and isSpatialInfoComplete().
        #
        # This is done because event sets can have complex attributes that
        # take a while to convert to Python values from the original Java
        # objects (e.g. the geometry associated with CWAs if the scope is
        # national), and since the event set should not change during
        # parameter gathering, reusing it is OK.
        self.parameterGatheringEventSet = None
예제 #17
0
def smali(f):
    return star.runcmd2([PathManager.get_apktool_path(), 'b', f])
예제 #18
0
def on_command(params):
    ret = 0  # 默认返回成功
    msg = None

    paramCount = len(params)
    isMultiFiles = False
    if params is None or paramCount < 3:
        print(params[0])
        print(params[1])
        return -1, u'参数不对,需要传至少 3 个参数'
    CMD_STR = params[1]
    filesSelected = params[2]
    if paramCount > 3:
        isMultiFiles = True
    if sys.platform == 'win32':
        pass
        # win下命令行参数为gbk编码,转换为UNICODE
        # filesSelected = filesSelected.decode('gbk', 'ignore')
    print(str(paramCount) + ' ' + CMD_STR + ' ' + filesSelected)

    if CMD_STR == 'dex2jar':
        ret, msg = dex2jar(filesSelected)
    elif CMD_STR == 'axml2txt':
        ret, msg = axml2txt(filesSelected)
    elif CMD_STR == 'viewapk':
        ret, msg = viewapk(filesSelected)
    elif CMD_STR == 'viewsign':
        ret, msg = viewsign(filesSelected)
    elif CMD_STR == 'sign':
        ret, msg = sign(filesSelected)
    elif CMD_STR == 'sign_v1_v2':
        ret, msg = sign_v1_v2(filesSelected)
    elif CMD_STR == 'installd':
        ret, msg = installd(filesSelected)
    elif CMD_STR == 'installr':
        ret, msg = installr(filesSelected)
    elif CMD_STR == 'uninstall':
        ret, msg = uninstall(filesSelected)
    elif CMD_STR == 'viewwrapper':
        ret, msg = viewwrapper(filesSelected)
    elif CMD_STR == 'phone':
        ret, msg = viewphone(filesSelected)
        if ret == 0:
            os.system('pause')
    elif CMD_STR == 'photo':
        ret, msg = photo(filesSelected)
    elif CMD_STR == 'icon':
        ret, msg = extracticon(filesSelected)
        os.system('pause')
    elif CMD_STR == 'zipalign':
        ret, msg = zipalign(filesSelected)
        os.system('pause')
    elif CMD_STR == 'baksmali':
        ret, msg = baksmali(filesSelected)
    elif CMD_STR == 'smali':
        ret, msg = smali(filesSelected)
    elif CMD_STR == 'plug_get_neprotect_ver':
        ret, msg = plug_get_neprotect_ver(filesSelected)
        os.system('pause')
    elif CMD_STR == 'md2html':
        ret, msg = md2html(filesSelected)
    elif CMD_STR == 'md2pdf':
        ret, msg = md2pdf(filesSelected)
    elif CMD_STR == 'plug3':
        ret, msg = plug(filesSelected)
    elif CMD_STR == 'about':
        print(u'\n\n右键工具v3.0 by bising(https://github.com/bigsinger)\n\n')
        os.system('pause')
        # star.runcmd2([PathManager.get_about_path()])
    elif CMD_STR == 'notepad':
        ret, msg = star.run_cmd_asyn(['notepad', filesSelected])
    elif CMD_STR == 'hex':
        print('open with hex tool')
        tool = PathManager.get_hextool_path()
        ret, msg = star.run_cmd_asyn([tool, filesSelected])
    elif CMD_STR == 'lua':
        print('open with Lua Editor')
        tool = PathManager.get_luaeditor_path()
        ret, msg = star.run_cmd_asyn([tool, filesSelected])
    elif CMD_STR == 'luyten':
        print('open with luyten')
        tool = PathManager.get_luyten_path()
        ret, msg = star.run_cmd_asyn([tool, filesSelected])
        if ret != 0:  # 说明此时执行命令出错,暂停下让用户能够看到cmd窗口的出错信息
            os.system('pause')
    elif CMD_STR == 'jdgui':
        print('open with jdgui')
        tool = PathManager.get_jdgui_path()
        ret, msg = star.run_cmd_asyn([tool, filesSelected])
    elif CMD_STR == 'md5':
        ret, msg = md5(filesSelected)
        os.system('pause')
    else:
        return -1, u'\n\n未实现命令:' + CMD_STR + u'请检查您输入的命令是否正确\n\n'
    return ret, msg
예제 #19
0
def baksmali(f):
    print(u'反编译完成')
    return star.runcmd2([PathManager.get_apktool_path(), 'd', '-f', f])
예제 #20
0
def get_package(f):
    retcode, msg = star.runcmd2(
        [PathManager.get_aapt_path(), 'dump', 'badging', f])
    if retcode == 0:
        package = star.find("package: name='(.*?)'", msg)
    return package
예제 #21
0
def sign_v1_v2(f):
    print(u"使用v1+v2签名")
    return star.runcmd2([PathManager.get_v2_sign_tool_path(), f])
예제 #22
0
def get_value_from_confing(node_name, item_name):
    config = ConfigParser.ConfigParser()
    with open(PathManager.get_config_file_path(), 'r') as config_file:
        config.readfp(config_file)
        return config.get(node_name, item_name)
예제 #23
0
# ========== My class inport ==========
# from EncodeManager import NetManager  # 呼び出すネットによって変える
NetManager = import_module(IMPORT_NET_CLS).NetManager
from DataManager import DataManager
from PathManager import PathManager
from ImageGenerator import ImageGenerator
from FitManager import FitManager
import ShareNetFunc as nfunc
import PlotFunc

# ========== NetManager呼び出し ==========
net_cls = NetManager()

# ========== PathManager呼び出し ==========
path_cls = PathManager(tfrecord_folder=TFRECORD_FOLDER,
                       output_rootfolder=OUT_ROOT_FOLDER,
                       epoch_output_rootfolder=EPOCH_OUT_ROOT_FOLDER)
path_cls.all_makedirs()  # 結果保存フォルダ生成

# ========== DataSet呼び出し ==========
# プロパティデータ読み込み
df = pd.read_csv(path_cls.get_property_path())
shuf_train_ds_cls = DataManager(
    tfrecord_path=path_cls.get_train_ds_path(),
    img_root=IMAGE_ROOT_PATH,
    batch_size=SHUF_LEARN_BATCH_SIZE,
    net_cls=net_cls,
    data_n=df.at[0, 'total_learn_data'],
    suffle_buffer=SUFFLE_BUFFER_SIZE,
)
train_ds_cls = DataManager(
예제 #24
0
class RobotControl(object):
    """Class used to interface with the rover. Gets sensor measurements
    through ROS subscribers, and transforms them into the 2D plane,
    and publishes velocity commands.

    """
    def __init__(self, markers, occupancy_map, pos_init, pos_goal, max_speed,
                 min_speed, max_omega, x_spacing, y_spacing, t_cam_to_body,
                 mode):
        """
        Initialize the class
        """
        # plan a path around obstacles using dijkstra's algorithm
        print('Planning path...')
        path = findShortestPath(occupancy_map,
                                x_spacing,
                                y_spacing,
                                pos_init[0:2],
                                pos_goal[0:2],
                                dilate=2)
        print('Done!')
        self.path_manager = PathManager(path)
        self.kalman_filter = KalmanFilter(markers, pos_init)
        self.diff_drive_controller = DiffDriveController(
            max_speed, min_speed, max_omega)

        if 'HARDWARE' in mode:
            # Handles all the ROS related items
            self.ros_interface = ROSInterface(t_cam_to_body)

        elif 'SIMULATE' in mode:
            self.robot_sim = RobotSim(markers, occupancy_map, pos_init,
                                      pos_goal, max_speed, max_omega,
                                      x_spacing, y_spacing,
                                      self.path_manager.path, mode)

        self.user_control = UserControl()
        self.vel = 0  # save velocity to use for kalman filter
        self.goal = self.path_manager.getNextWaypoint()  # get first waypoint

        # for logging postion data to csv file
        self.stateSaved = []
        self.tagsSaved = []
        self.waypoints = []

    def process_measurements(self):
        """Main loop of the robot - where all measurements, control, and
        estimation are done.

        """
        v, omega, wayptReached = self.user_control.compute_vel()
        self.robot_sim.command_velocity(v, omega)
        return

        #meas = None # for testing purposes
        #imu_meas = None # for testing purpose
        #pdb.set_trace()
        if (imu_meas is None) and (meas is None):
            pass
        else:
            state = self.kalman_filter.step_filter(self.vel, imu_meas, meas)
            if 'SIMULATE' in mode:
                self.robot_sim.set_est_state(state)

            #print("X = {} cm, Y = {} cm, Theta = {} deg".format(100*state[0],100*state[1],state[2]*180/np.pi))

            # save the estimated state and tag statuses for offline animation
            self.stateSaved.append(state)
            self.waypoints.append(self.path_manager.getActiveWaypointsPos())
            if meas is None:
                self.tagsSaved.append(None)
            else:
                meas = np.array(meas)
                tagIDs = [int(i) for i in meas[:, 3]]
                self.tagsSaved.append(tagIDs)

            v, omega, wayptReached = self.diff_drive_controller.compute_vel(
                state, self.goal.pos)
            self.vel = v

            if wayptReached:
                self.goal = self.path_manager.getNextWaypoint()
                self.diff_drive_controller.done = False  # reset diff controller status

            if self.goal is None:
                print('Goal has been reached!')
                np.savez('savedState.npz',
                         stateSaved=self.stateSaved,
                         tagsSaved=self.tagsSaved,
                         waypoints=self.waypoints)
                print('Position data saved!')
                if 'HARDWARE' in mode:
                    self.ros_interface.command_velocity(0, 0)
                elif 'SIMULATE' in mode:

                    self.robot_sim.command_velocity(0, 0)
                    self.robot_sim.done = True
                return
            else:
                if 'HARDWARE' in mode:
                    self.ros_interface.command_velocity(self.vel, omega)
                elif 'SIMULATE' in mode:
                    self.robot_sim.command_velocity(self.vel, omega)
        return

    def myhook():
        print "shutdown time!"
예제 #25
0
파일: Builder.py 프로젝트: whenisee/wotmods
 def run(cls):
     super(Builder, Builder).run()
     saveOldFuncs()
     injectNewFuncs()
     Builder.pm = PathManager()
예제 #26
0
def main():
    mIns = MissionManager()
    PathManagerIns = PathManager()
    targetPos = [7, 5]  # set target position
    startPos = [0, 0]  # set start position
    PathManagerIns.pathGenerator(0, mIns, startPos, targetPos, PathManagerIns)
예제 #27
0
class ProductInterface(HazardServicesPythonOverriderInterface.
                       HazardServicesPythonOverriderInterface):
    def __init__(self, scriptPath, localizationPath, site):
        super(ProductInterface, self).__init__(scriptPath, localizationPath,
                                               site)
        self.pathMgr = PathManager()
        # TODO - every file that exists in localization and is class based needs
        # to be imported via PythonOverrider. Not just the 2 below directories.

        # Import the textUtilities dir using PythonOverrider
        self.importTextUtility(reloadModules=False)
        # Import the eventUtilities dir using PythonOverrider
        self.importEventUtility(reloadModules=False)
        # Import all the generator modules using PythonOverrider.
        self.importModules()
        # Import all the formatter modules using PythonOverrider.
        self.importFormatters()
        self.logger = logging.getLogger("ProductInterface")
        self.logger.addHandler(
            UFStatusHandler.UFStatusHandler(
                "com.raytheon.uf.common.hazards.productgen",
                "ProductInterface",
                level=logging.INFO))
        self.logger.setLevel(logging.INFO)

    def executeGenerator(self, moduleName, className, **kwargs):
        javaDialogInput = kwargs['dialogInputMap']
        if javaDialogInput is not None:
            kwargs['dialogInputMap'] = JUtil.javaObjToPyVal(javaDialogInput)
        formats = kwargs.pop('formats')
        javaEventSet = kwargs['eventSet']
        # execute method in generators is expecting a python eventSet
        kwargs['eventSet'] = PythonEventSet(kwargs['eventSet'])
        dataList, events = self.runMethod(moduleName, className, 'execute',
                                          **kwargs)
        if not isinstance(dataList, list):
            raise Exception('Expecting a list from ' + moduleName +
                            '.execute()')

        kwargs['dataList'] = dataList
        # executeGeneratorFrom method is expecting a javaEventSet
        kwargs['eventSet'] = javaEventSet
        # dialogInputMap no longer needed for executeFrom method
        kwargs.pop('dialogInputMap')

        genProdList = self.executeGeneratorFrom(moduleName, className,
                                                **kwargs)

        javaEventSet = EventSet()
        javaEventSet.addAll(JUtil.pyValToJavaObj(events))
        genProdList.setEventSet(javaEventSet)
        return genProdList

    def executeGeneratorFrom(self, moduleName, className, **kwargs):
        eventSet = []
        if 'generatedProductList' in kwargs:
            updateList = True
            genProdList = kwargs.pop('generatedProductList')
            eventSet = PythonEventSet(genProdList.getEventSet())
            dataList = []
            for i in range(genProdList.size()):
                # make sure dataList is a python object
                dataList.append(
                    JUtil.javaObjToPyVal(genProdList.get(i).getData()))
            kwargs['dataList'] = dataList
            kwargs['eventSet'] = eventSet
        else:
            updateList = False
            genProdList = GeneratedProductList()
            eventSet = PythonEventSet(kwargs.get('eventSet'))

        productParts = kwargs.get('productParts', None)
        # make sure keyInfoList is a python object
        if hasattr(productParts, 'java_name'):
            productParts = JUtil.javaObjToPyVal(productParts)
            kwargs['productParts'] = productParts

        # call executeFrom from product generator
        dataList = self.runMethod(moduleName, className, 'executeFrom',
                                  **kwargs)

        genProdList.setProductInfo(moduleName)
        self.createProductsFromDictionary(dataList, eventSet, genProdList,
                                          updateList)
        return genProdList

    def executeGeneratorUpdate(self, moduleName, className, **kwargs):
        dataList = kwargs['dataList']
        # make sure dataList is a python object
        if hasattr(dataList, 'java_name'):
            dataList = JUtil.javaObjToPyVal(dataList)
            kwargs['dataList'] = dataList

        formats = kwargs.pop('formats')
        javaEventSet = kwargs['eventSet']
        kwargs['eventSet'] = PythonEventSet(javaEventSet)

        # call updateDataList from product generator
        dataList, events = self.runMethod(moduleName, className,
                                          'updateDataList', **kwargs)

        if not isinstance(dataList, list):
            raise Exception('Expecting a list from ' + moduleName +
                            '.execute()')

        kwargs['dataList'] = dataList
        # executeGeneratorFrom method is expected a javaEventSet
        kwargs['eventSet'] = javaEventSet
        genProdList = self.executeGeneratorFrom(moduleName, className,
                                                **kwargs)

        javaEventSet = EventSet()
        javaEventSet.addAll(JUtil.pyValToJavaObj(events))
        genProdList.setEventSet(javaEventSet)
        return genProdList

    def executeFormatter(self, moduleName, className, **kwargs):
        generatedProductList = kwargs['generatedProductList']
        formats = JUtil.javaObjToPyVal(kwargs['formats'])

        # Loop over each product that has been generated and format them
        for i in range(generatedProductList.size()):
            generatedProduct = generatedProductList.get(i)
            self.formatProduct(generatedProduct, formats)

        return generatedProductList

    def formatProduct(self, generatedProduct, formats):
        # Retrieve the product's data to pass to the formatter
        productData = JUtil.javaObjToPyVal(generatedProduct.getData())
        # Retrieve the product's editableEntries if available
        editableEntries = JUtil.javaObjToPyVal(
            generatedProduct.getEditableEntries())

        if isinstance(productData, dict):
            errors = []
            # Dictionary containing the formatted products
            productDict = OrderedDict()
            for format in formats:
                try:
                    locPath = 'HazardServices/python/events/productgen/formats/'
                    scriptName = locPath + format + '.py'
                    if sys.modules.has_key(format):
                        self.clearModuleAttributes(format)
                    formatModule = HazardServicesPythonOverrider.importModule(
                        scriptName, localizedSite=self.site)
                    instance = formatModule.Format()
                    product, editableEntries = instance.execute(
                        productData, editableEntries)
                    productDict[format] = product
                    generatedProduct.setEditableEntries(
                        JUtil.pyValToJavaObj(editableEntries))

                except Exception as err:
                    errMsg = 'ERROR:  Failed to execute ' + format + '. ' + str(
                        err)
                    productDict[format] = [errMsg]
                    errors.append(errMsg)
                    exc_type, exc_value, exc_traceback = sys.exc_info()
                    print traceback.format_exc(limit=20)
                    os.sys.__stdout__.flush()

            # TODO Use JUtil.pyValToJavaObj() when JUtil.pyDictToJavaMap() is fully resolved
            generatedProduct.setEntries(JUtil.pyDictToJavaMap(productDict))
            if errors:
                generatedProduct.setErrors('\n'.join(errors))

    def createProductsFromDictionary(self, dataList, eventSet, genProdList,
                                     updateList):
        if dataList is not None:
            if updateList:
                for i in range(len(dataList)):
                    data = dataList[i]
                    if isinstance(data, dict):
                        generatedProduct = genProdList.get(i)
                        generatedProduct.setData(JUtil.pyValToJavaObj(data))
            else:
                for data in dataList:
                    if isinstance(data, dict):
                        productID = data.get('productID')
                        generatedProduct = GeneratedProduct(productID)
                        generatedProduct.setData(JUtil.pyValToJavaObj(data))
                        javaEventSet = self.getEventSetForProduct(
                            data, eventSet)
                        generatedProduct.setEventSet(javaEventSet)
                        genProdList.add(generatedProduct)

    def getEventSetForProduct(self, data, eventSet):
        """
        @return: Returns a sub set of the eventSet passed to the generator that pertains
        to this one product. This sub set will be used as a PK to save the product to the 
        productData table during  dissemination.
        """
        # Get all the eventIDs from the product
        eventIDs = set()
        for segment in data.get('segments', []):
            for vtecRecord in segment.get('vtecRecords', []):
                for eventID in vtecRecord.get('eventID', []):
                    eventIDs.add(eventID)

        # Create a sub set of the eventSet based on the product eventIDs
        productEventSet = set()
        for eventID in eventIDs:
            for event in eventSet:
                if event.getEventID() == eventID:
                    productEventSet.add(event)
                    break
        javaEventSet = EventSet()
        javaEventSet.addAll(JUtil.pyValToJavaObj(productEventSet))
        javaEventSet.addAttribute('runMode', eventSet.getAttribute('runMode'))

        return javaEventSet

    def getDialogInfo(self, moduleName, className, **kwargs):
        """
        @return: Returns a map of string to string of the dialog info.
        """
        kwargs['eventSet'] = PythonEventSet(kwargs['eventSet'])
        val = self.runMethod(moduleName, className, 'defineDialog', **kwargs)
        if val is not None:
            val = JUtil.pyValToJavaObj(val)
        return val

    def getScriptMetadata(self, moduleName, className, **kwargs):
        """
        @return: Returns a map of string to string of the metadata.
        """
        val = self.runMethod(moduleName, className, 'defineScriptMetadata',
                             **kwargs)
        return JUtil.pyValToJavaObj(val)

    def importFormatters(self):
        locPath = 'HazardServices/python/events/productgen/formats/'
        lf = self.pathMgr.getLocalizationFile(locPath,
                                              loctype='COMMON_STATIC',
                                              loclevel='BASE')
        basePath = lf.getPath()
        # Import all the files in this directory
        self.importFilesFromDir(basePath, locPath)

    def importTextUtility(self, reloadModules=True):
        locPath = 'HazardServices/python/textUtilities/'
        self.importDirectory(locPath, reloadModules)
        if reloadModules:
            self.importFormatters()

    def importEventUtility(self, reloadModules=True):
        locPath = 'HazardServices/python/events/utilities/'
        self.importDirectory(locPath, reloadModules)
        if reloadModules:
            self.importFormatters()
예제 #28
0
파일: Vamos.py 프로젝트: ilibz2012/amitools
class Vamos:
  
  def __init__(self, raw_mem, cpu, cfg):
    self.raw_mem = raw_mem
    self.ram_size = raw_mem.ram_size
    self.cpu = cpu
    self.path_mgr = PathManager( cfg )

    # create a label manager and error tracker
    self.label_mgr = LabelManager()
    self.error_tracker = ErrorTracker(cpu, self.label_mgr)
    self.label_mgr.error_tracker = self.error_tracker

    # set a label for first two dwords
    label = LabelRange("zero_page",0,8)
    self.label_mgr.add_label(label)
    
    # create memory access
    self.mem = MainMemory(self.raw_mem, self.error_tracker)
    self.mem.ctx = self

    # create memory allocator
    self.mem_begin = 0x1000
    self.alloc = MemoryAlloc(self.mem, 0, self.ram_size, self.mem_begin, self.label_mgr)
    
    # create segment loader
    self.seg_loader = SegmentLoader( self.mem, self.alloc, self.label_mgr, self.path_mgr )

    # lib manager
    self.lib_mgr = LibManager( self.label_mgr, cfg.data_dir )
    
    # no current process right now
    self.process = None
    self.proc_list = []
    self.tr_list = []

  def init(self, cfg):
    self.init_managers()
    self.register_base_libs(cfg)
    self.init_trampoline()  
    self.create_old_dos_guard()
    self.open_exec_lib()
    return True

  def cleanup(self):
    self.close_exec_lib()
    self.free_trampoline()
    self.alloc.dump_orphans()
  
  # ----- process handling -----
  
  def _set_this_task(self, proc):
    """tell exec about this process and all others referencing process from here"""
    self.process = proc
    self.exec_lib.lib_class.set_this_task(self.exec_lib, proc)
  
  def set_main_process(self, proc):
    log_proc.info("set main process: %s", proc)
    self.proc_list.append(proc)
    self._set_this_task(proc)
  
  def start_sub_process(self, proc):
    log_proc.info("start sub process: %s", proc)
    self.proc_list.append(proc)
    self._set_this_task(proc)
    
    # setup trampoline to enter sub process
    tr_mem_size = 128
    tr_mem = self.alloc.alloc_memory("SubProcJump", tr_mem_size)
    tr = Trampoline(self, tr_mem)
    tr.init()
    tr.save_all_but_d0()
    # new proc registers: d0=arg_len a0=arg_cptr
    tr.set_dx_l(0, proc.arg_len)
    tr.set_ax_l(0, proc.arg_base)
    # to track old dos values
    tr.set_ax_l(2, self.dos_guard_base)
    tr.set_ax_l(5, self.dos_guard_base)
    tr.set_ax_l(6, self.dos_guard_base)
    # setup new stack
    stack_save_addr = tr_mem.addr + tr_mem_size - 4
    tr.write_ax_l(7, stack_save_addr)
    new_stack = proc.stack_initial
    tr.set_ax_l(7, new_stack)
    # call code! (jmp - return value is on stack)
    tr.jmp(proc.prog_start)
    # restore stack (set a label to return from new stack - see below)
    lab = tr.set_label()
    tr.read_ax_l(7, stack_save_addr)
    # restore regs
    tr.restore_all_but_d0()
    # trap to clean up sub process resources
    tr.trap(lambda x : self.stop_sub_process())
    tr.rts()
    tr.done()
    # get label addr -> set as return value of new stack
    lab_addr = tr.get_label(lab)
    log_proc.debug("new_stack=%06x trampoline_return=%06x", new_stack, lab_addr)
    self.mem.access.w32(new_stack, lab_addr)
    
    # push trampoline
    self.tr_list.append(tr)
  
  def stop_sub_process(self):
    # get return value
    ret_code = self.cpu.r_reg(REG_D0)
    # pop process
    proc = self.proc_list.pop()
    log_proc.info("stop sub process: %s ret_code=%d", proc, ret_code)
    proc.free()
    # pop trampoline
    tr = self.tr_list.pop()
    self.alloc.free_memory(tr.mem)
    
  # ----- init environment -----
  
  def init_managers(self):
    self.doslist_base = self.mem.reserve_special_range()
    self.doslist_size = 0x010000
    self.doslist_mgr = DosListManager(self.path_mgr, self.doslist_base, self.doslist_size)
    self.label_mgr.add_label(self.doslist_mgr)
    self.mem.set_special_range_read_funcs(self.doslist_base, r32=self.doslist_mgr.r32_doslist)
    log_mem_init.info(self.doslist_mgr)

    # fill dos list
    volumes = self.path_mgr.get_all_volume_names()
    for vol in volumes:
      self.doslist_mgr.add_volume(vol)
    
    self.lock_base = self.mem.reserve_special_range()
    self.lock_size = 0x010000
    self.lock_mgr = LockManager(self.path_mgr, self.doslist_mgr, self.lock_base, self.lock_size)
    self.label_mgr.add_label(self.lock_mgr)
    self.mem.set_special_range_read_funcs(self.lock_base, r32=self.lock_mgr.r32_lock)
    log_mem_init.info(self.lock_mgr)
    
    self.file_base = self.mem.reserve_special_range()
    self.file_size = 0x010000
    self.file_mgr = FileManager(self.path_mgr, self.file_base, self.file_size)
    self.label_mgr.add_label(self.file_mgr)
    self.mem.set_special_range_read_funcs(self.file_base, r32=self.file_mgr.r32_fh)
    log_mem_init.info(self.file_mgr)

    self.port_base = self.mem.reserve_special_range()
    self.port_size = 0x010000
    self.port_mgr  = PortManager(self.port_base, self.port_size)
    self.label_mgr.add_label(self.port_mgr)
    log_mem_init.info(self.port_mgr)

  def register_base_libs(self, cfg):
    libs_cfg = cfg.libs
    # register libraries
    # exec
    self.exec_lib_def = ExecLibrary(self.lib_mgr, self.alloc, version=libs_cfg['exec']['version'], profile=libs_cfg['exec']['profile'])
    self.lib_mgr.register_int_lib(self.exec_lib_def)
    # dos
    self.dos_lib_def = DosLibrary(self.mem, self.alloc, version=libs_cfg['dos']['version'], profile=libs_cfg['dos']['profile'])
    self.dos_lib_def.set_managers(self.path_mgr, self.lock_mgr, self.file_mgr, self.port_mgr, self.seg_loader)
    self.lib_mgr.register_int_lib(self.dos_lib_def)
    # icon
    self.icon_lib_def = IconLibrary()
    self.lib_mgr.register_int_lib(self.icon_lib_def)
    # iffparse
    self.iffparse_lib_def = IFFParseLibrary()
    self.lib_mgr.register_int_lib(self.iffparse_lib_def)

  def init_trampoline(self):
    self.tr_mem_size = 256
    self.tr_mem = self.alloc.alloc_memory("Trampoline", self.tr_mem_size)
    self.tr = Trampoline(self, self.tr_mem)

  def free_trampoline(self):
    self.alloc.free_memory(self.tr_mem)

  def open_exec_lib(self):
    # open exec lib
    self.exec_lib = self.lib_mgr.open_lib(ExecLibrary.name, 0, self)
    log_mem_init.info(self.exec_lib)

  def close_exec_lib(self):
    self.lib_mgr.close_lib(self.exec_lib.lib_base, self)

  def create_old_dos_guard(self):
    # create a guard memory for tracking invalid old dos access
    self.dos_guard_base = self.mem.reserve_special_range()
    self.dos_guard_size = 0x010000
    label = LabelRange("old_dos",self.dos_guard_base, self.dos_guard_size)
    self.label_mgr.add_label(label)
    log_mem_init.info(label)
예제 #29
0
def md2html(f):
    return star.runcmd2([PathManager.get_mdconverter_path(), f])
예제 #30
0
def sign(f):
    return star.runcmd2([PathManager.get_signtool_path(), f])
예제 #31
0
def md2pdf(f):
    return star.runcmd2([PathManager.get_mdconverter_path(), f, 'pdf'])
예제 #32
0
파일: Vamos.py 프로젝트: rmtew/amitools
class Vamos:
  
  def __init__(self, raw_mem, cpu, cfg):
    self.raw_mem = raw_mem
    self.ram_size = raw_mem.ram_size
    self.cpu = cpu
    self.cpu_type = cfg.cpu
    self.path_mgr = PathManager( cfg )

    # create a label manager and error tracker
    self.label_mgr = LabelManager()
    self.error_tracker = ErrorTracker(cpu, self.label_mgr)
    self.label_mgr.error_tracker = self.error_tracker

    # set a label for first two dwords
    label = LabelRange("zero_page",0,8)
    self.label_mgr.add_label(label)
    
    # create memory access
    self.mem = MainMemory(self.raw_mem, self.error_tracker)
    self.mem.ctx = self

    # create memory allocator
    self.mem_begin = 0x1000
    self.alloc = MemoryAlloc(self.mem, 0, self.ram_size, self.mem_begin, self.label_mgr)
    
    # create segment loader
    self.seg_loader = SegmentLoader( self.mem, self.alloc, self.label_mgr, self.path_mgr )

    # lib manager
    self.lib_mgr = LibManager( self.label_mgr, cfg)
    
    # no current process right now
    self.process = None
    self.proc_list = []

  def init(self, cfg):
    self.init_managers()
    self.register_base_libs(cfg)
    self.create_old_dos_guard()
    self.open_exec_lib()
    return True

  def cleanup(self):
    self.close_exec_lib()
    self.alloc.dump_orphans()
  
  # ----- process handling -----
  
  def _set_this_task(self, proc):
    """tell exec about this process and all others referencing process from here"""
    self.process = proc
    self.exec_lib.set_this_task(proc)
  
  def set_main_process(self, proc):
    log_proc.info("set main process: %s", proc)
    self.proc_list.append(proc)
    self._set_this_task(proc)
  
  def start_sub_process(self, proc):
    log_proc.info("start sub process: %s", proc)
    self.proc_list.append(proc)
    self._set_this_task(proc)
    
    # setup trampoline to enter sub process
    tr = Trampoline(self, "SubProcJump")

    # reserve a long for old stack
    old_stack_off = tr.dc_l(0)

    # code starts
    tr.save_all_but_d0()
    # new proc registers: d0=arg_len a0=arg_cptr
    tr.set_dx_l(0, proc.arg_len)
    tr.set_ax_l(0, proc.arg_base)
    # d2=stack_size.  this value is also in 4(sp) (see Process.init_stack), but
    # various C programs rely on it being present (1.3-3.1 at least have it).
    tr.set_dx_l(2, proc.stack_size)
    # to track old dos values
    tr.set_ax_l(2, self.dos_guard_base)
    tr.set_ax_l(5, self.dos_guard_base)
    tr.set_ax_l(6, self.dos_guard_base)
    # save old stack and set new stack
    tr.write_ax_l(7, old_stack_off, True) # write to data offset (dc.l above)
    new_stack = proc.stack_initial
    tr.set_ax_l(7, new_stack)
    # call code! (jmp - return value is on stack)
    tr.jmp(proc.prog_start)
    # restore stack (set a label to return from new stack - see below)
    return_off = tr.get_code_offset()
    tr.read_ax_l(7, old_stack_off, True) # read from data offset (dc.l above)
    # restore regs
    tr.restore_all_but_d0()
    # trap to clean up sub process resources
    def trap_stop_sub_process():
      self.stop_sub_process()
    tr.final_rts(trap_stop_sub_process)
    # realize trampoline in memory (data+code)
    tr.done()
    # get label addr -> set as return value of new stack
    return_addr = tr.get_code_addr(return_off)
    log_proc.debug("new_stack=%06x return_addr=%06x", new_stack, return_addr)
    # place return address for new process
    self.mem.access.w32(new_stack, return_addr)

  def stop_sub_process(self):
    # get return value
    ret_code = self.cpu.r_reg(REG_D0)
    # pop process
    proc = self.proc_list.pop()
    log_proc.info("stop sub process: %s ret_code=%d", proc, ret_code)
    proc.free()
    
  # ----- init environment -----
  
  def init_managers(self):
    self.doslist_base = self.mem.reserve_special_range()
    self.doslist_size = 0x010000
    self.doslist_mgr = DosListManager(self.path_mgr, self.doslist_base, self.doslist_size)
    self.label_mgr.add_label(self.doslist_mgr)
    self.mem.set_special_range_read_funcs(self.doslist_base, r32=self.doslist_mgr.r32_doslist)
    log_mem_init.info(self.doslist_mgr)

    # fill dos list
    volumes = self.path_mgr.get_all_volume_names()
    for vol in volumes:
      self.doslist_mgr.add_volume(vol)
    
    self.lock_base = self.mem.reserve_special_range()
    self.lock_size = 0x010000
    self.lock_mgr = LockManager(self.path_mgr, self.doslist_mgr, self.lock_base, self.lock_size)
    self.label_mgr.add_label(self.lock_mgr)
    self.mem.set_special_range_read_funcs(self.lock_base, r32=self.lock_mgr.r32_lock)
    log_mem_init.info(self.lock_mgr)
    
    self.file_base = self.mem.reserve_special_range()
    self.file_size = 0x010000
    self.file_mgr = FileManager(self.path_mgr, self.file_base, self.file_size)
    self.label_mgr.add_label(self.file_mgr)
    self.mem.set_special_range_read_funcs(self.file_base, r32=self.file_mgr.r32_fh)
    log_mem_init.info(self.file_mgr)

    self.port_base = self.mem.reserve_special_range()
    self.port_size = 0x010000
    self.port_mgr  = PortManager(self.port_base, self.port_size)
    self.label_mgr.add_label(self.port_mgr)
    log_mem_init.info(self.port_mgr)

  def register_base_libs(self, cfg):
    # register libraries
    # exec
    exec_cfg = cfg.get_lib_config('exec.library')
    self.exec_lib_def = ExecLibrary(self.lib_mgr, self.alloc, exec_cfg)
    self.lib_mgr.register_vamos_lib(self.exec_lib_def)
    # dos
    dos_cfg = cfg.get_lib_config('dos.library')
    self.dos_lib_def = DosLibrary(self.mem, self.alloc, dos_cfg)
    self.dos_lib_def.set_managers(self.path_mgr, self.lock_mgr, self.file_mgr, self.port_mgr, self.seg_loader)
    self.lib_mgr.register_vamos_lib(self.dos_lib_def)

  def open_exec_lib(self):
    # open exec lib
    self.exec_lib = self.lib_mgr.open_lib(ExecLibrary.name, 0, self)
    self.exec_lib_def.set_cpu(self.cpu_type)
    log_mem_init.info(self.exec_lib)

  def close_exec_lib(self):
    self.lib_mgr.close_lib(self.exec_lib.addr_base, self)

  def create_old_dos_guard(self):
    # create a guard memory for tracking invalid old dos access
    self.dos_guard_base = self.mem.reserve_special_range()
    self.dos_guard_size = 0x010000
    label = LabelRange("old_dos",self.dos_guard_base, self.dos_guard_size)
    self.label_mgr.add_label(label)
    log_mem_init.info(label)
예제 #33
0
 def getUserPath(self, category):
     pathMgr = PathManager()
     lf = pathMgr.getLocalizationFile(str(self._localizationPath),
                                      'CAVE_STATIC', 'USER')
     fullpath = lf.getPath()
     return fullpath + "/"
예제 #34
0
def main():
    mIns = MissionManager()
    PathManagerIns = PathManager()
    targetPos = [7, 5] # set target position
    startPos = [0, 0] # set start position
    PathManagerIns.pathGenerator(0, mIns, startPos, targetPos, PathManagerIns)