Compare commits

...

25 Commits
1.4.0 ... main

Author SHA1 Message Date
TaurusXin
a2d65257da
Add DartNode branding image to README for enhanced visibility and support recognition.
Some checks failed
CI / build_on_windows_msys2 (push) Has been cancelled
CI / build_on_windows_msvc (push) Has been cancelled
CI / build_on_linux_amd64 (push) Has been cancelled
CI / build_on_macos_amd64 (push) Has been cancelled
CI / build_on_macos_arm64 (push) Has been cancelled
2025-06-08 10:19:48 +08:00
TaurusXin
80a607a8fb
Merge pull request #52 from npt-1707/fix_CVE-2023-50471
Some checks failed
CI / build_on_windows_msys2 (push) Has been cancelled
CI / build_on_windows_msvc (push) Has been cancelled
CI / build_on_linux_amd64 (push) Has been cancelled
CI / build_on_macos_amd64 (push) Has been cancelled
CI / build_on_macos_arm64 (push) Has been cancelled
Fix potential vulnerable cloned function
2025-06-04 10:01:34 +08:00
npt-1707
6c125d6152 src/utils/cJSON.cpp: add NULL check in cJSON_InsertItemInArray 2025-05-23 03:24:55 +08:00
taurusxin
3fe1518325
removed: text 2024-12-09 11:58:14 +08:00
TaurusXin
ae45748724
Update README.md 2024-11-27 19:25:41 +08:00
TaurusXin
a23503c3cc
Update README.md 2024-11-27 19:25:03 +08:00
TaurusXin
95bcc209f3
Update README.md 2024-11-27 16:18:41 +08:00
TaurusXin
245e46a2a0
Merge pull request #44 from WhatDamon/main
feat: update issue templates to YAML form
2024-11-17 08:59:31 +08:00
Damon Lu
13ca3e81d1 feat: update issue templates to YAML form 2024-11-16 18:05:38 +08:00
TaurusXin
e29fdaf850
update: Action build type to MinSizeRel 2024-11-02 21:37:22 +08:00
TaurusXin
b812fe4e30
ignore: build dirs 2024-11-02 21:12:21 +08:00
TaurusXin
8c4ec2ab0a
Update bug_report.md 2024-10-29 13:50:02 +08:00
TaurusXin
22768594ba
chore: typo 2024-10-21 16:15:12 +08:00
TaurusXin
6af854b376
removed: copyright comment 2024-10-21 15:21:05 +08:00
TaurusXin
ed6c05b4bf
taglib: bump version to 2.0.2 2024-09-27 20:57:41 +08:00
TaurusXin
dc2830d5c3
update: README.md 2024-09-25 23:21:43 +08:00
TaurusXin
cb7a84662f
update: README.md; bump version to 1.5.0; 2024-09-25 23:18:18 +08:00
TaurusXin
39adf93e46
feat: handle exception 2024-09-25 23:08:14 +08:00
TaurusXin
0befc5bc93
feat: allow sepecify output dir; process dir recursively
use cxxopts library to parse command line options
2024-09-25 22:41:33 +08:00
TaurusXin
b9299d8988 feat: comment for ncm 3.0 2024-09-23 20:10:20 +08:00
TaurusXin
84b5c0044d
chore: typo 2024-09-21 00:10:26 +08:00
TaurusXin
f060bee5ad
feat: autobuild for macOS arm64 2024-09-21 00:08:51 +08:00
TaurusXin
bc5719ac11
feat: docs for cross build on macOS 2024-09-20 23:55:46 +08:00
TaurusXin
5e41d41874
update: README.md 2024-09-13 11:46:44 +08:00
TaurusXin
3906a49f7a
update: README.md 2024-09-13 11:39:00 +08:00
17 changed files with 3290 additions and 141 deletions

View File

@ -1,35 +0,0 @@
---
name: "[请按照此模板填写] 报告 Bug"
about: "创建一个 Bug 报告,不按照模板的 Issue 会被关闭。"
title: "[Bug] 总结你的 Bug 报告"
labels: bug
assignees: taurusxin
---
**Bug 描述**
清晰地描述一下 Bug 的大致问题。
**复现方法**
复现此 Bug 的方法
1. 打开 '...'
2. 点击 '....'
3. 发生报错
**预期行为**
解释一下原本应该出现的结果。
**屏幕截图**
如果可以,屏幕截图可以更好地阐述你的问题。
**环境**
- OS: [e.g. Windows 11]
- 软件版本: [e.g. 1.3.2]
**附加内容**
添加更多其他内容以帮助开发者更好地了解这个 Bug。

101
.github/ISSUE_TEMPLATE/bug_report.yml vendored Normal file
View File

@ -0,0 +1,101 @@
name: 报告 Bug
description: 创建一个 Bug 报告。
title: "[Bug]: "
labels: "bug"
assignees:
- taurusxin
body:
- type: markdown
attributes:
value: |
# taurusxin/ncmdump Bug 反馈须知
请__严格遵守该模板进行 Bug 反馈__否则维护者有权直接关闭本 Issue 不予回复!
为了保证 Bug 追踪的顺利请__务必提供详细信息并接受来自维护者的提问__
- type: checkboxes
attributes:
label: 该 Bug 是否针对 `libncmdump`
description: 如果是命令行工具 `ncmdump` 请不要勾选。
options:
- label: 是的,此 Bug 是针对动态库 `libncmdump` 而不是命令行工具 `ncmdump`!
- type: dropdown
attributes:
label: 类型
options:
- 无法转换文件
- 转换成功但音频文件无法播放
- 功能失效
- 程序崩溃
- 其他
validations:
required: true
- type: textarea
attributes:
label: Bug 描述
description: 清晰地描述一下 Bug 的大致问题及表现,对上面的类型进行补充说明。
validations:
required: true
- type: textarea
attributes:
label: 复现方法
description: 复现此 Bug 的方法。
placeholder: |
1. 使用本项目处理文件 '...'
2. 发生报错
validations:
required: true
- type: textarea
attributes:
label: 屏幕截图或视频
description: 如果可以,屏幕截图可以更好地阐述你的问题。
placeholder: 将截图或视频文件拖入此处
validations:
required: false
- type: input
attributes:
label: 操作系统
description: 请提供您当前正在使用的操作系统如果可以请提供更多关于操作系统的版本信息Linux 请提供发行版名称。
placeholder: Windows / macOS / Debian
validations:
required: true
- type: input
attributes:
label: ncmdump 版本
description: 请提供您正在使用的 ncmdump 版本,如果是来自 Github Actions 的构建,请提供 commit 信息。
placeholder: 1.5.0
validations:
required: true
- type: input
attributes:
label: 网易云版本(重要)
description: 请提供您下载 ncm 文件的网易云客户端及版本,请写明客户端平台与版本号。
placeholder: Windows 版 3.0.1
validations:
required: true
- type: dropdown
attributes:
label: 所下载的音质
options:
- 标准
- 极高
- 无损
- 高清臻音
- 超清母带
- 沉浸环绕声
validations:
required: true
- type: textarea
attributes:
label: 附加内容
placeholder: 如果遇到无法转换的问题,请将样本附加到这里,便于分析。
validations:
required: false

8
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@ -0,0 +1,8 @@
blank_issues_enabled: false
contact_links:
- name: 寻求帮助
url: https://github.com/taurusxin/ncmdump/discussions/categories/q-a
about: 有疑问?请转移到讨论的 Q&A 分区!
- name: 意见与新功能请求
url: https://github.com/taurusxin/ncmdump/discussions/categories/ideas
about: 需要什么新功能?请到讨论的 Ideas 分区!

View File

@ -1,6 +1,6 @@
name: CI
env:
BUILD_TYPE: Release
BUILD_TYPE: MinSizeRel
BUILD_PATH: build
on:
push:
@ -35,7 +35,7 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: Windows amd64 Build - MinGW
name: windows_amd64_build_msys2_exe
path: ${{ env.BUILD_PATH }}/ncmdump.exe
build_on_windows_msvc:
@ -56,16 +56,16 @@ jobs:
- name: Upload artifact executable
uses: actions/upload-artifact@v4
with:
name: Windows amd64 Build - MSVC
name: windows_amd64_build_msvc_exe
path: ${{ env.BUILD_PATH }}/${{ env.BUILD_TYPE }}/ncmdump.exe
- name: Upload artifact DLL
uses: actions/upload-artifact@v4
with:
name: Windows amd64 Build - MSVC DLL
name: windows_amd64_build_msvc_dll
path: ${{ env.BUILD_PATH }}/${{ env.BUILD_TYPE }}/libncmdump.dll
build_on_linux:
build_on_linux_amd64:
runs-on: ubuntu-latest
steps:
@ -88,10 +88,10 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: Linux amd64 Build
name: linux_build_amd64
path: ${{ env.BUILD_PATH }}/ncmdump
build_on_macos:
build_on_macos_amd64:
runs-on: macos-latest
steps:
@ -105,7 +105,7 @@ jobs:
brew install git cmake
- name: Configure build
run: cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -B ${{ env.BUILD_PATH }}
run: cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -B ${{ env.BUILD_PATH }} -DCMAKE_OSX_ARCHITECTURES=x86_64
- name: Build
run: cmake --build ${{ env.BUILD_PATH }} -j 4
@ -113,5 +113,30 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: macOS amd64 Build
name: macOS_build_amd64
path: ${{ env.BUILD_PATH }}/ncmdump
build_on_macos_arm64:
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install dependencies
run: |
brew install git cmake
- name: Configure build
run: cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -B ${{ env.BUILD_PATH }} -DCMAKE_OSX_ARCHITECTURES=arm64
- name: Build
run: cmake --build ${{ env.BUILD_PATH }} -j 4
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: macOS_build_arm64
path: ${{ env.BUILD_PATH }}/ncmdump

2
.gitignore vendored
View File

@ -5,3 +5,5 @@ ncmdump
.idea
build
cmake-build-*

View File

@ -6,25 +6,19 @@
该版本为最早的 C++ 版本,也是作者开发的市面上第一个支持 ncm 转换的程序
源码复刻自 anonymous5l/ncmdump,感谢前辈的付出!做了 Windows 下的移植,修复了一些编译问题
源码复刻自 anonymous5l/ncmdump (2021年10月6日原作者已经删库)
1.3.0 版本更新说明因为之前有小伙伴反馈无法解密带有特殊字符的文件名例如中文、日文、韩文或者是表情符号等在1.3.0以及之后的版本彻底修复了这个问题,所有的 UTF-8 字符都可以正常解密。并且还自带了 dll 的构建可以供其他应用程序C#、Python、Java等调用
感谢前辈的付出!此版本做了全操作系统下的的跨平台编译移植,修复了一些内存溢出的问题
## 传送门
2021年10月6日原作者已经删库
1.3.0 版本更新说明:因为之前有较多 Issue 反馈无法解密带有特殊字符的文件名例如中文、日文、韩文或者是表情符号等在1.3.0以及之后的版本彻底修复了这个问题,所有的 UTF-8 字符都可以正常解密。并且还自带了 dll 的构建可以供其他应用程序C#、Python、Java等调用。
## 使用
注意:网易云音乐 3.0 之后的某些版本,下载的 ncm 文件会出现不内置歌曲专辑的封面图片的情况,所需的封面图数据需要从网络获取,介于在一个小工具中嵌入庞大网络库的非必要性,可以移步我的另一个仓库 [ncmdump-go](https://git.taurusxin.com/taurusxin/ncmdump-go) 或者使用基于此项目开发的可视化 GUI 程序 [ncmdump-gui](https://git.taurusxin.com/taurusxin/ncmdump-gui),其中后者基于前者,均完全使用 Golang 重写,并支持自动从元数据读取封面信息后从网络获取封面图并嵌入到目标音乐文件。
### 命令行工具
你可以使用 Homebrew 来安装 ncmdump 的 cli 版本
```shell
brew install ncmdump
```
或者从 [Release](https://github.com/taurusxin/ncmdump/releases) 下载最新版本的对应系统的已编译好的二进制文件
从 [Release](https://github.com/taurusxin/ncmdump/releases) 下载最新版本的对应系统的已编译好的二进制文件
使用 `-h``--help` 参数来打印帮助
@ -32,16 +26,41 @@ brew install ncmdump
ncmdump -h
```
命令行下输入一个或多个文件
使用 `-v``--version` 参数来打印版本信息
```shell
ncmdump file1 file2...
ncmdump -v
```
你可以使用 `-d` 参数来指定一个文件夹,对文件夹下的所有文件批量处理
处理单个或多个文件
```shell
ncmdump -d folder
ncmdump 1.ncm 2.ncm...
```
使用 `-d` 参数来指定一个文件夹,对文件夹下的所有以 ncm 为扩展名的文件进行批量处理
```shell
ncmdump -d source_dir
```
使用 `-r` 配合 `-d` 参数来递归处理文件夹下的所有以 ncm 为扩展名的文件
```shell
ncmdump -d source_dir -r
```
使用 `-o` 参数来指定输出目录,将转换后的文件输出到指定目录,该参数支持与 `-r` 参数一起使用
```shell
# 处理单个或多个文件并输出到指定目录
ncmdump 1.ncm 2.ncm -o output_dir
# 处理文件夹下的所有以 ncm 为扩展名并输出到指定目录,不包含子文件夹
ncmdump -d source_dir -o output_dir
# 递归处理文件夹并输出到指定目录,并保留目录结构
ncmdump -d source_dir -o output_dir -r
```
### 动态库
@ -76,6 +95,10 @@ cmake -G "Visual Studio 17 2022" -A x64 -B build
# Linux / macOS
cmake -DCMAKE_BUILD_TYPE=Release -B build
# 如果需要在 macOS 下交叉编译,可以指定 `CMAKE_OSX_ARCHITECTURES` 变量来指明目标系统架构
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=arm64 -B build # arm64
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=x86_64 -B build # Intel-based
```
编译项目
@ -90,6 +113,8 @@ cmake --build build -j 8
你可以在 `build` 文件夹下找到编译好的二进制文件,以及一个可供其它项目使用的动态库(Windows Only),使用方法见仓库的 `example` 文件夹
[![Powered by DartNode]( https://dartnode.com/branding/DN-Open-Source-sm.png)]( https://dartnode.com "Powered by DartNode - Free VPS for Open Source")
## Star History
[![Star History Chart](https://api.star-history.com/svg?repos=taurusxin/ncmdump&type=Date)](https://star-history.com/#taurusxin/ncmdump&Date)

View File

@ -14,7 +14,7 @@ namespace libncmdump_demo_cli
private static extern IntPtr CreateNeteaseCrypt(IntPtr path);
[DllImport(DLL_PATH, CallingConvention = CallingConvention.Cdecl)]
private static extern int Dump(IntPtr NeteaseCrypt);
private static extern int Dump(IntPtr NeteaseCrypt, IntPtr outputPath);
[DllImport(DLL_PATH, CallingConvention = CallingConvention.Cdecl)]
private static extern void FixMetadata(IntPtr NeteaseCrypt);
@ -42,10 +42,17 @@ namespace libncmdump_demo_cli
/// <summary>
/// 启动转换过程。
/// </summary>
/// <param name="OutputPath">指定一个路径输出,如果为空,则输出到原路径</param>
/// <returns>返回一个整数指示转储过程的结果。如果成功返回0如果失败返回1。</returns>
public int Dump()
public int Dump(string OutputPath)
{
return Dump(NeteaseCryptClass);
byte[] bytes = Encoding.UTF8.GetBytes(OutputPath);
IntPtr outputPtr = Marshal.AllocHGlobal(bytes.Length + 1);
Marshal.Copy(bytes, 0, outputPtr, bytes.Length);
Marshal.WriteByte(outputPtr, bytes.Length, 0);
return Dump(NeteaseCryptClass, outputPtr);
}
/// <summary>

View File

@ -14,7 +14,7 @@ namespace libncmdump_demo_cli
NeteaseCrypt neteaseCrypt = new NeteaseCrypt(filePath);
// 启动转换过程
int result = neteaseCrypt.Dump();
int result = neteaseCrypt.Dump(""); // 为空则输出到源
// 修复元数据
neteaseCrypt.FixMetadata();

2909
src/include/cxxopts.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -47,7 +47,7 @@ private:
NcmFormat mFormat;
std::string mImageData;
std::ifstream mFile;
unsigned char mKeyBox[256];
unsigned char mKeyBox[256]{};
NeteaseMusicMetadata* mMetaData;
private:
@ -66,6 +66,6 @@ public:
~NeteaseCrypt();
public:
void Dump();
void Dump(std::string const&);
void FixMetadata();
};

3
src/include/version.h Normal file
View File

@ -0,0 +1,3 @@
#define VERSION_MAJOR 1
#define VERSION_MINOR 5
#define VERSION_PATCH 0

View File

@ -9,10 +9,10 @@ extern "C" {
return new NeteaseCrypt(fPath.u8string());
}
API int Dump(NeteaseCrypt* neteaseCrypt) {
API int Dump(NeteaseCrypt* neteaseCrypt, const char* outputPath) {
try
{
neteaseCrypt->Dump();
neteaseCrypt->Dump(outputPath);
}
catch (const std::invalid_argument& e)
{

View File

@ -8,7 +8,7 @@
extern "C" {
API NeteaseCrypt* CreateNeteaseCrypt(const char* path);
API int Dump(NeteaseCrypt* neteaseCrypt);
API int Dump(NeteaseCrypt* neteaseCrypt, const char* outputPath);
API void FixMetadata(NeteaseCrypt* neteaseCrypt);
API void DestroyNeteaseCrypt(NeteaseCrypt* neteaseCrypt);
}

View File

@ -10,115 +10,207 @@
#endif
#include "color.h"
#include "version.h"
#include "cxxopts.hpp"
namespace fs = std::filesystem;
void displayHelp()
{
std::cout << "Usage: ncmdump [-d] [-h] file1 file2 ..." << std::endl;
std::cout << "Options:" << std::endl;
std::cout << " -d Process files in a folder (requires folder path)" << std::endl;
std::cout << " -h, --help Display this help message" << std::endl;
}
void processFile(const fs::path &filePath)
void processFile(const fs::path &filePath, const fs::path &outputFolder)
{
if (fs::exists(filePath) == false)
{
std::cerr << BOLDRED << "Error: " << RESET << "file '" << filePath.u8string() << "' does not exist." << std::endl;
std::cerr << BOLDRED << "[Error] " << RESET << "file '" << filePath.u8string() << "' does not exist." << std::endl;
return;
}
// skip if not ending with ".ncm"
if (!filePath.has_extension() || filePath.extension().u8string() != ".ncm")
{
return;
}
try
{
NeteaseCrypt crypt(filePath.u8string());
crypt.Dump();
crypt.Dump(outputFolder.u8string());
crypt.FixMetadata();
std::cout << BOLDGREEN << "[Done] " << RESET << "'" << filePath.u8string() << "' -> '" << crypt.dumpFilepath().u8string() << "'" << std::endl;
}
catch (const std::invalid_argument &e)
{
std::cerr << BOLDRED << "Exception: " << RESET << RED << e.what() << RESET << " '" << filePath.u8string() << "'" << std::endl;
std::cerr << BOLDRED << "[Exception] " << RESET << RED << e.what() << RESET << " '" << filePath.u8string() << "'" << std::endl;
}
catch (...)
{
std::cerr << BOLDRED << "Unexpected exception while processing file: " << RESET << filePath.u8string() << std::endl;
}
}
void processFilesInFolder(const fs::path &folderPath)
{
for (const auto &entry : fs::directory_iterator(folderPath))
{
if (fs::is_regular_file(entry.status()))
{
processFile(entry.path());
}
std::cerr << BOLDRED << "[Error] Unexpected exception while processing file: " << RESET << filePath.u8string() << std::endl;
}
}
int main(int argc, char **argv)
{
#if defined(_WIN32)
win32_utf8argv(&argc, &argv);
win32_utf8argv(&argc, &argv); // Convert command line arguments to UTF-8 under Windows
#endif
if (argc <= 1)
{
displayHelp();
cxxopts::Options options("ncmdump");
options.add_options()
("h,help", "Print usage")
("d,directory", "Process files in a folder (requires folder path)", cxxopts::value<std::string>())
("r,recursive", "Process files recursively (requires -d option)", cxxopts::value<bool>()->default_value("false"))
("o,output", "Output folder (default: original file folder)", cxxopts::value<std::string>())
("v,version", "Print version information", cxxopts::value<bool>()->default_value("false"))
("filenames", "Input files", cxxopts::value<std::vector<std::string>>());
options.positional_help("<files>");
options.parse_positional({"filenames"});
options.allow_unrecognised_options();
// Parse options the usual way
cxxopts::ParseResult result;
try {
result = options.parse(argc, argv);
} catch(cxxopts::exceptions::parsing const& e) {
std::cout << options.help() << std::endl;
return 1;
}
std::vector<fs::path> files;
bool processFolders = false;
bool folderProvided = false;
#define COMPARE_STR(s1, s2) (strcmp(s1, s2) == 0)
#define HELP_SHORT "-h"
#define HELP_LONG "--help"
#define PROCESS_FOLDER "-d"
for (int i = 1; i < argc; ++i)
// print usage message if unrecognised options are present
if (result.unmatched().size() > 0)
{
if (COMPARE_STR(argv[i], HELP_SHORT) || COMPARE_STR(argv[i], HELP_LONG))
std::cout << options.help() << std::endl;
return 1;
}
// display help message
if (result.count("help"))
{
displayHelp();
std::cout << options.help() << std::endl;
return 0;
}
else if (COMPARE_STR(argv[i], PROCESS_FOLDER))
// display version information
if (result.count("version"))
{
processFolders = true;
if (i + 1 < argc && argv[i + 1][0] != '-')
{
folderProvided = true;
processFilesInFolder(fs::u8path(argv[i + 1]));
// Skip the folder name
++i;
std::cout << "ncmdump version " << VERSION_MAJOR << "." << VERSION_MINOR << "." << VERSION_PATCH << std::endl;
return 0;
}
else
// no input files or folder provided
if (result.count("directory") == 0 && result.count("filenames") == 0)
{
std::cerr << "Error: -d option requires a folder path." << std::endl;
std::cout << options.help() << std::endl;
return 1;
}
// only -r option without -d option
if (result.count("recursive") && result.count("directory") == 0)
{
std::cerr << BOLDRED << "[Error] " << RESET << "-r option requires -d option." << std::endl;
return 1;
}
// check output folder
fs::path outputDir = fs::u8path("");
bool outputDirSpecified = result.count("output") > 0;
if (outputDirSpecified)
{
outputDir = fs::u8path(result["output"].as<std::string>());
if (fs::exists(outputDir))
{
if (!fs::is_directory(outputDir))
{
std::cerr << BOLDRED << "[Error] " << RESET << "'" << outputDir.u8string() << "' is not a valid directory." << std::endl;
return 1;
}
}
else
{
fs::path path = fs::u8path(argv[i]);
files.push_back(path);
}
fs::create_directories(outputDir);
}
for (const auto &file : files)
// process files in a folder
if (result.count("directory"))
{
if (processFolders && fs::is_directory(file))
fs::path sourceDir = fs::u8path(result["directory"].as<std::string>());
if (!fs::is_directory(sourceDir))
{
processFilesInFolder(file);
std::cerr << BOLDRED << "[Error] " << RESET << "'" << sourceDir.u8string() << "' is not a valid directory." << std::endl;
return 1;
}
bool recursive = result["recursive"].as<bool>();
if (recursive)
{
// 递归遍历源目录
for (const auto &entry : fs::recursive_directory_iterator(sourceDir))
{
// 没有指定输出目录,则使用源目录作为输出目录
if (!outputDirSpecified)
{
outputDir = sourceDir;
}
// 获得递归遍历的相对路径
const auto &path = fs::u8path(entry.path().u8string());
auto relativePath = fs::relative(path, sourceDir);
fs::path destinationPath = outputDir / relativePath;
if (fs::is_regular_file(path))
{
// 确保输出文件的目录存在
fs::create_directories(destinationPath.parent_path());
// 处理文件
processFile(path, destinationPath.parent_path());
}
}
}
else
{
processFile(file);
for (const auto &entry : fs::directory_iterator(sourceDir))
{
const auto &path = fs::u8path(entry.path().u8string());
if (entry.is_regular_file())
{
if (outputDirSpecified)
{
processFile(path, outputDir);
}
else
{
processFile(path, "");
}
}
}
}
return 0;
}
// process individual files
if (result.count("filenames"))
{
for (const auto &filePath : result["filenames"].as<std::vector<std::string>>())
{
fs::path filePathU8 = fs::u8path(filePath);
if (!fs::is_regular_file(filePathU8))
{
std::cerr << BOLDRED << "[Error] " << RESET << "'" << filePathU8.u8string() << "' is not a valid file." << std::endl;
continue;
}
if (outputDirSpecified)
{
processFile(filePathU8, outputDir);
}
else
{
processFile(filePathU8, "");
}
}
}
return 0;
}

View File

@ -16,6 +16,9 @@
#include <string>
#include <filesystem>
#pragma warning(disable:4267)
#pragma warning(disable:4244)
const unsigned char NeteaseCrypt::sCoreKey[17] = {0x68, 0x7A, 0x48, 0x52, 0x41, 0x6D, 0x73, 0x6F, 0x35, 0x6B, 0x49, 0x6E, 0x62, 0x61, 0x78, 0x57, 0};
const unsigned char NeteaseCrypt::sModifyKey[17] = {0x23, 0x31, 0x34, 0x6C, 0x6A, 0x6B, 0x5F, 0x21, 0x5C, 0x5D, 0x26, 0x30, 0x55, 0x3C, 0x27, 0x28, 0};
@ -221,7 +224,7 @@ void NeteaseCrypt::FixMetadata()
audioFile = new TagLib::MPEG::File(mDumpFilepath.c_str());
tag = dynamic_cast<TagLib::MPEG::File *>(audioFile)->ID3v2Tag(true);
if (mImageData.length() > 0)
if (!mImageData.empty())
{
TagLib::ID3v2::AttachedPictureFrame *frame = new TagLib::ID3v2::AttachedPictureFrame;
@ -236,7 +239,7 @@ void NeteaseCrypt::FixMetadata()
audioFile = new TagLib::FLAC::File(mDumpFilepath.c_str());
tag = audioFile->tag();
if (mImageData.length() > 0)
if (!mImageData.empty())
{
TagLib::FLAC::Picture *cover = new TagLib::FLAC::Picture;
cover->setMimeType(mimeType(mImageData));
@ -254,15 +257,20 @@ void NeteaseCrypt::FixMetadata()
tag->setAlbum(TagLib::String(mMetaData->album(), TagLib::String::UTF8));
}
tag->setComment(TagLib::String("Create by taurusxin/ncmdump.", TagLib::String::UTF8));
// tag->setComment(TagLib::String("Create by taurusxin/ncmdump.", TagLib::String::UTF8));
audioFile->save();
audioFile->~File();
}
void NeteaseCrypt::Dump()
void NeteaseCrypt::Dump(std::string const &outputDir = "")
{
if (outputDir.empty())
{
mDumpFilepath = std::filesystem::u8path(mFilepath);
} else {
mDumpFilepath = std::filesystem::u8path(outputDir) / std::filesystem::u8path(mFilepath).filename();
}
std::vector<unsigned char> buffer(0x8000);
@ -293,7 +301,7 @@ void NeteaseCrypt::Dump()
mFormat = NeteaseCrypt::FLAC;
}
output.open(mDumpFilepath, output.out | output.binary);
output.open(mDumpFilepath, std::ofstream::out | std::ofstream::binary);
}
output.write((char *)buffer.data(), n);

View File

@ -2142,7 +2142,7 @@ CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newit
{
cJSON *after_inserted = NULL;
if (which < 0)
if (which < 0 || newitem == NULL)
{
return;
}
@ -2154,6 +2154,10 @@ CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newit
return;
}
if (after_inserted != array->child && newitem->prev == NULL) {
return;
}
newitem->next = after_inserted;
newitem->prev = after_inserted->prev;
after_inserted->prev = newitem;

2
taglib

@ -1 +1 @@
Subproject commit 0896fb90920c125e55248360d271d1a1674e2a4d
Subproject commit e3de03501ff66221d1f1f971022b248d5b38ba06