如何使用.Net Reactor 批量加密 DLL

若在日常工作中加密操作的使用频率较高,每次启动程序并执行选择 DLL 文件等操作均会显得较为繁琐。在此,分享一种可提升操作效率的方法:通过命令行方式调用脚本,即可实现 DLL 或 Exe 文件的批量加密处理。具体操作如下:

下载NetReactor:下载链接(链接: https://pan.baidu.com/s/1B3oHvFZ83vzrYUmjne-foQ?pwd=1234)

复制下面脚本:

cpp 复制代码
# 设置 dotNET_Reactor 的路径
$dotnetReactorPath = "D:\Program Files (x86)\Eziriz\.NET Reactor\dotNET_Reactor.exe"

# 检查 dotNET_Reactor 是否存在
if (-Not (Test-Path -Path $dotnetReactorPath)) {
    Write-Error "dotNET_Reactor.exe not found at: $dotnetReactorPath"
    exit 1
}

# 定义需要处理的 DLL 文件所在目录
$inputDirectory = "D:\Protected\sourceDll" # 替换为你的 DLL 文件所在目录
$outputDirectory = "D:\Protected\ProtectedDLL" # 替换为目标输出目录

# 检查目标输出目录是否存在,如果不存在则创建
if (-Not (Test-Path -Path $outputDirectory)) {
    New-Item -ItemType Directory -Path $outputDirectory | Out-Null
}

# 定义加密函数
function Encrypt-Dll {
    param(
        [string]$dllPath,
        [string]$outputPath
    )
    & $dotnetReactorPath -file "$dllPath" -targetfile "$outputPath" -necrobit 1 -control_flow_obfuscation 1
    if ($?) {
        Write-Host "Encryption successful for $dllPath"
    } else {
        Write-Error "Encryption failed for $dllPath"
    }
}

# 递归获取输入目录及其子目录下的所有 DLL 文件
$dllFiles = Get-ChildItem -Path $inputDirectory -Filter "*.dll" -Recurse

# 对每个 DLL 文件进行加密处理
foreach ($file in $dllFiles) {
    $dllFullPath = $file.FullName
    # 获取文件在输入目录中的相对路径
    $relativePath = $dllFullPath.Substring($inputDirectory.Length + 1)
    # 构建目标路径
    $outputFilePath = Join-Path -Path $outputDirectory -ChildPath ("Protected_" + $relativePath)
    # 获取目标文件的目录路径
    $outputDir = Split-Path -Path $outputFilePath -Parent
    # 检查目标目录是否存在,如果不存在则创建
    if (-Not (Test-Path -Path $outputDir)) {
        New-Item -ItemType Directory -Path $outputDir | Out-Null
    }
    Encrypt-Dll -dllPath $dllFullPath -outputPath $outputFilePath
}

Write-Host "Batch encryption process completed."

使用步骤

修改脚本中的路径

$inputDirectory 替换为包含你的 .dll 文件的目录路径。

$outputDirectory 替换为你希望保存加密后的 .dll 文件的目录路径。

确保这两个路径在你的系统中是有效的。

保存脚本

将上述代码保存为一个 .ps1 文件,例如 EncryptDlls.ps1

运行脚本

打开 PowerShell。

切换到脚本所在的目录,例如:

复制代码
cd D:\Path\To\Your\Scripts

运行脚本:

复制代码
.\EncryptDlls.ps1

注意事项

确保你的 PowerShell 环境允许运行脚本。默认情况下,Windows 系统可能会限制脚本的运行,可以通过以下命令启用脚本执行:

cpp 复制代码
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

如果还不行,试试将 DOTNET_REACTOR 安装目录添加到系统环境变量,或者写全路径也可以。

相关推荐
张人玉2 小时前
c#中Random类、DateTime类、String类
开发语言·c#
future14123 小时前
游戏开发日记
数据结构·学习·c#
军训猫猫头5 小时前
3.检查函数 if (!CheckStart()) return 的妙用 C#例子
开发语言·c#
yngsqq8 小时前
netdxf—— CAD c#二次开发之(netDxf 处理 DXF 文件)
java·前端·c#
每日出拳老爷子8 小时前
[WinForms] 如何为 .NET Framework 4.8 窗体程序添加自定义图标
visualstudio·c#·.net
Yan90188 小时前
.net解析雷达拼图3.0组合反射率产品,并按经纬度裁剪绘制组合反射率图
.net
步、步、为营8 小时前
.net服务器Kestrel配置Nginx作为反向代理
服务器·nginx·.net
专注VB编程开发20年8 小时前
各版本操作系统对.NET支持情况(250707更新)
开发语言·前端·ide·vscode·.net
界面开发小八哥11 小时前
界面组件DevExpress WPF中文教程:Grid - 如何检查节点?
ui·.net·wpf·界面控件·devexpress·ui开发
钢铁男儿15 小时前
C#接口实现详解:从理论到实践,掌握面向对象编程的核心技巧
java·前端·c#