├── .gitignore ├── .gitmodules ├── src ├── func.h ├── main.cpp ├── fills.hpp └── func.cpp ├── LICENSE ├── makefile ├── README.md └── config_template.json /.gitignore: -------------------------------------------------------------------------------- 1 | /**/*.out 2 | /.vscode/ 3 | /out 4 | /src/include/myBase64/* 5 | /src/lib/ 6 | /test.cpp 7 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "3rdparty/myBase64"] 2 | path = 3rdparty/myBase64 3 | url = https://github.com/leafee98/myBase64.git 4 | branch = stable 5 | -------------------------------------------------------------------------------- /src/func.h: -------------------------------------------------------------------------------- 1 | # pragma once 2 | 3 | #include 4 | #include 5 | 6 | struct run_param { 7 | std::string template_file; 8 | std::string output_file; 9 | std::string vmess_link; 10 | bool display_help; 11 | bool display_ps; 12 | bool display_link; 13 | 14 | run_param(); 15 | }; 16 | 17 | extern const std::string VMESS_SCHEMA; 18 | 19 | void print_usage(); 20 | void display_ps(const run_param & runp); 21 | void display_link(const run_param & runp); 22 | 23 | bool parse_parameters(int argc, char * argv[], run_param & runp); 24 | std::string check_files(const run_param & runp); 25 | 26 | Json::Value decode_vmess(const std::string & vmess_link); 27 | Json::Value read_template(const std::string & template_file); 28 | 29 | std::string unicode_to_utf8(const std::string & str); 30 | void write_output(const run_param & runp, const Json::Value & output_json, 31 | const Json::Value vmess_json); 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Leafee 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "fills.hpp" 2 | #include "func.h" 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char * argv[]) { 8 | run_param runp; 9 | 10 | if (! parse_parameters(argc, argv, runp)) 11 | return EXIT_FAILURE; 12 | 13 | if (runp.display_help) { 14 | print_usage(); 15 | return EXIT_SUCCESS; 16 | } 17 | 18 | if (runp.display_link) { 19 | display_link(runp); 20 | return EXIT_SUCCESS; 21 | } 22 | 23 | if (runp.display_ps) { 24 | display_ps(runp); 25 | return EXIT_SUCCESS; 26 | } 27 | 28 | std::string check_result = check_files(runp); 29 | if (check_result.size() > 0) { 30 | std::cerr << check_result; 31 | return EXIT_FAILURE; 32 | } 33 | 34 | Json::Value vmess_json = decode_vmess(runp.vmess_link); 35 | if (vmess_json == Json::Value::nullSingleton) { 36 | std::cerr << "unsupported schema or not the vmess 2rd version\n"; 37 | return EXIT_FAILURE; 38 | } 39 | 40 | Json::Value template_json = read_template(runp.template_file); 41 | Json::Value output_json = fill_config(template_json, vmess_json); 42 | write_output(runp, output_json, vmess_json); 43 | 44 | return EXIT_SUCCESS; 45 | } 46 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | .PHONY : help 2 | help : 3 | @echo " gitSubModule update submodule of git" 4 | @echo " dependency copy dependency from submodule" 5 | @echo " build build the project" 6 | @echo " install install the binary file and template file" 7 | @echo " all build and install the project" 8 | @echo " clean clean files created by build" 9 | 10 | .PHONY : gitSubModule 11 | gitSubModule : 12 | git submodule init 13 | git submodule update 14 | 15 | .PHONY : dependency 16 | dependency : gitSubModule 17 | make --directory=./3rdparty/myBase64/ all 18 | [ -d ./src/lib/ ] || mkdir -p ./src/lib 19 | cp ./3rdparty/myBase64/out/libmyBase64.a ./src/lib/libmyBase64.a 20 | [ -d ./src/include/myBase64 ] || mkdir -p ./src/include/myBase64 21 | cp ./3rdparty/myBase64/src/myBase64.h ./src/include/myBase64/myBase64.h 22 | 23 | .PHONY : clean 24 | clean : 25 | make --directory=./3rdparty/myBase64/ clean 26 | rm -rf ./out/ 27 | 28 | .PHONY : build 29 | build : dependency 30 | [ -d ./out/ ] || mkdir ./out/ 31 | g++ --std=c++17 ./src/main.cpp ./src/func.cpp -o ./out/parsevmess -L./src/lib -lmyBase64 -ljsoncpp 32 | 33 | .PHONY : install 34 | install : build 35 | install ./out/parsevmess /usr/bin/ 36 | [ -f /etc/v2ray/config_template.json ] || install ./config_template.json /etc/v2ray/ 37 | 38 | .PHONY : all 39 | all : build install 40 | 41 | .PHONY : uninstall 42 | uninstall : 43 | rm /usr/bin/parsevmess 44 | rm /etc/v2ray/config_template.json 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ParseVmess 2 | 3 | 把Vmess链接导入到配置模板生成可用的配置 4 | 5 | ⚠⚠ This is a practice project when I'm learning cpp, and shouldn't be used 6 | for purpose other than practice, not to mention in product environment. ⚠⚠ 7 | 8 | ⚠⚠ 这只是一个学习 cpp 时的练习项目,不应该以练习以外为目的来使用,更不应该用于生产环境。 ⚠⚠ 9 | 10 | ## 编译 11 | 12 | 请**预先安装jsoncpp的依赖项**, 13 | 如arch Linux的发行版可以使用`pacman -S jsoncpp`进行安装. 14 | 15 | 在依赖项安装正确的前提下, 16 | 可以在克隆整个项目以后使用`make all`进行编译, 17 | `makefile`中会递归克隆子模块. 18 | 19 | ## 使用 20 | 21 | 几乎完全重写了整个代码, 22 | 重写后的项目在以命令行参数的形式接收vmess链接和制定输入输出位置. 23 | 24 | 使用时需要有配置模板文件, 25 | 配置模板与普通的v2ray配置文件类似, 26 | 可以根据自己需要进行修改, 27 | 但是outbound的第一个对象会被vmess分享链接的内容覆盖, 28 | 其他项的内容则会保留. 29 | 30 | 程序帮助如下: 31 | 32 | ``` 33 | usage: 34 | parsevmess [-t