cmder lib_path.bat分析学习

0x00 前言

lib_path.bat分析学习是在init.bat的基础上进行调用的。
其他相关分析文章
cmder Cmder.bat分析学习
DIY自己的cmder.exe
cmder init.bat分析学习

0x01 正文

1. 1~10行

@echo off


call "%~dp0lib_base.cmd"
call "%%~dp0lib_console"
set lib_path=call "%~dp0lib_path.cmd"

if "%~1" == "/h" (
    %lib_base% help "%~0"
) else if "%1" neq "" (
    call :%*
)

exit /b

在这里插入图片描述

2.enhance_path

2.1 第一部分

 if "%~1" neq "" (
        set "add_path=%~1"
    ) else (
        %lib_console% show_error "You must specify a directory to add to the path!"
        exit 1
    )

    if "%~2" neq "" if /i "%~2" == "append" (
        set "position=%~2"
    ) else (
        set "position="
    )

    if "%fast_init%" == "1" (
      if "%position%" == "append" (
        set "PATH=%PATH%;%add_path%"
      ) else (
        set "PATH=%add_path%;%PATH%"
      )
    )

    set "PATH=%PATH:;;=;%"
    if "%fast_init%" == "1" (
      exit /b
    )

在这里插入图片描述

2.2 第二部分

    set found=0
    set "find_query=%add_path%"
    set "find_query=%find_query:\=\\%"
    set "find_query=%find_query: =\ %"

    if "%CMDER_CONFIGURED%" == "1" (
      %lib_console% debug_output  :enhance_path "Env Var - find_query=%find_query%"
      echo "%path%"|%WINDIR%\System32\findstr >nul /I /R ";%find_query%\"$"
      REM if "!ERRORLEVEL!" == "0" set found=1
      call :set_found
    )
    %lib_console% debug_output  :enhance_path "Env Var 1 - found=%found%"

2.3 第三部分

if "%found%" == "0" (
        if "%CMDER_CONFIGURED%" == "1" (
            echo "%path%"|%WINDIR%\System32\findstr >nul /i /r ";%find_query%;"
            REM if "!ERRORLEVEL!" == "0" set found=1
            call :set_found
        )
        %lib_console% debug_output  :enhance_path "Env Var 2 - found=%found%"
    )

    if "%found%" == "0" (
        %lib_console% debug_output :enhance_path "BEFORE Env Var - PATH=%path%"
        if /i "%position%" == "append" (
            %lib_console% debug_output :enhance_path "Appending '%add_path%'"
            set "PATH=%PATH%;%add_path%"
        ) else (
            %lib_console% debug_output :enhance_path "Prepending '%add_path%'"
            set "PATH=%add_path%;%PATH%"
        )

        %lib_console% debug_output  :enhance_path "AFTER Env Var - PATH=%path%"
    )

    rem :end_enhance_path
    rem endlocal & set "PATH=%PATH:;;=;%"
    set "PATH=%PATH:;;=;%"
    exit /b

在这里插入图片描述
这里的部分其实感觉有一点重复了。

3.enhance_path_recursive

3.1 第一部分

if "%~1" neq "" (
        set "add_path=%~1"
    ) else (
        %lib_console% show_error "You must specify a directory to add to the path!"
        exit 1
    )

    if "%~2" gtr "1" (
        set "max_depth=%~2"
    ) else (
        set "max_depth=1"
    )

    if "%~3" neq "" if /i "%~3" == "append" (
        set "position=%~3"
    ) else (
        set "position="
    )

    if "%fast_init%" == "1" (
      call :enhance_path "%add_path%" %position%
    )

    set "PATH=%PATH:;;=;%"
    if "%fast_init%" == "1" (
      exit /b
    )

在这里插入图片描述

3.2 第二部分

    if "%depth%" == "" set depth=0

    %lib_console% debug_output  :enhance_path_recursive "Env Var - add_path=%add_path%"
    %lib_console% debug_output  :enhance_path_recursive "Env Var - position=%position%"
    %lib_console% debug_output  :enhance_path_recursive "Env Var - max_depth=%max_depth%"

    if %max_depth% gtr %depth% (
        %lib_console% debug_output :enhance_path_recursive "Adding parent directory - '%add_path%'"
        call :enhance_path "%add_path%" %position%
        REM set /a "depth=!depth!+1"
        call :set_depth
        call :loop_depth
    )

    rem :end_enhance_path_recursive
    rem endlocal & set "PATH=%PATH%"
    set "PATH=%PATH%"
    exit /b

在这里插入图片描述

4.loop_depth

:loop_depth
    for /d %%i in ("%add_path%\*") do (
        %lib_console% debug_output  :enhance_path_recursive "Env Var BEFORE - depth=%depth%"
        %lib_console% debug_output :enhance_path_recursive "Found Subdirectory - '%%~fi'"
        call :enhance_path_recursive "%%~fi" %max_depth% %position%
        %lib_console% debug_output  :enhance_path_recursive "Env Var AFTER- depth=%depth%"
    )
    exit /b

在这里插入图片描述

0x02 总结

这里的感觉是获取到了PATH,并且可以对整个文件夹进行PATH的获取。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王嘟嘟_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值