【声明:本文仅为代码研究使用,严禁用于侵权等非法行为】
效果:
解密前 --解密后
源码转自 https://github.com/MegrezZhu/qmcdump
并不一定要unity来做,编译源码就行。
使用Visual studio2019 创建c++ 控制台应用
main.cpp脚本如下
#include <iostream>
#include <string>
#include "crypt.h"
using namespace std;
string convertName(const string& filename);
int main(int argc, char** argv) {
if (argc != 2 && argc != 3) {
cerr << "Usage: qmcdump <input_path> [output_path]" << endl;
return 1;
}
string in = argv[1];
string out = argc == 3 ? argv[2] : convertName(in);
bool result = convert(in, out);
if (!result) {
return 1;
}
else {
cout << "dumped to " << out << endl;
}
}
string convertName(const string& filename) {
auto pos = filename.rfind('.');
if (pos == string::npos) {
cerr << "Warning: no extname." << endl;
return filename + "_CONVERTED";
}
else {
auto base = filename.substr(0, pos);
auto ext = filename.substr(pos + 1);
if (ext == "qmcflac")
ext = "flac";
else if (ext == "qmc0" || ext == "qmc3")
ext = "mp3";
else {
cerr << "Warning: unknown extname (support: qmcflac, qmc0, qmc3)."
<< endl;
ext = "mp3";
}
return base + '.' + ext;
}
}
创建crypt.h头文件
#include <cstdint>
#include <string>
const int BUFFER_SIZE = 8192;
int encrypt(int offset, char* buf, int len);
char mapL(int v);
bool convert(const std::string& in, const std::string& out);
创建crypt.cpp源文件
#include "crypt.h"
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
int encrypt(int offset, char* buf, int len) {
if (offset < 0) {
return -1;
}
for (int i = 0; i < len; ++i) {
buf[i] ^= mapL(offset + i);
}
return 0;
}
char mapL(int v) {
static const int key[] = {
0x77, 0x48, 0x32, 0x73, 0xDE, 0xF2, 0xC0, 0xC8, 0x95, 0xEC, 0x30, 0xB2,
0x51, 0xC3, 0xE1, 0xA0, 0x9E, 0xE6, 0x9D, 0xCF, 0xFA, 0x7F, 0x14, 0xD1,
0xCE, 0xB8, 0xDC, 0xC3, 0x4A, 0x67, 0x93, 0xD6, 0x28, 0xC2, 0x91, 0x70,
0xCA, 0x8D, 0xA2, 0xA4, 0xF0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0x06, 0x5F, 0x4D, 0xCF,
0x3D, 0x1A, 0xFE, 0x20, 0x77, 0xE4, 0xD9, 0xDA, 0xF9, 0xA4, 0x2B, 0x76,
0x1C, 0x71, 0xDB, 0x00, 0xBC, 0xFD, 0xC, 0x6C, 0xA5, 0x47, 0xF7, 0xF6,
0x00, 0x79, 0x4A, 0x11 };
if (v >= 0) {
if (v > 0x7FFF) v %= 0x7FFF;
}
else {
v = 0;
}
return char(key[(v * v + 80923) % 256]);
}
bool convert(const std::string& in, const std::string& out) {
static char buf[BUFFER_SIZE];
ifstream fin(in, ios::binary);
if (!fin.is_open()) {
cerr << "opening file " << in << " failed.";
return false;
}
ofstream fout(out, ios::binary);
if (!fout.is_open()) {
cerr << "opening file " << out << " failed.";
return false;
}
int offset = 0;
while (true) {
fin.read(buf, BUFFER_SIZE);
int length = fin.gcount();
encrypt(offset, buf, length);
fout.write(buf, length);
offset += length;
if (!fin) break;
}
return true;
}
此时生成的exe文件 即可使用控制台命令解密了,使用方法如下
怎么看有没有效果呢,qmcflac的文件如果是vip播放的,只能播放1分钟
output.flac即使显示是vip的也能播放。(腾讯爸爸放过我)
以下是使用unity批量转换的操作,目的是学习unity调用动态库dll。
VS依旧创建使用控制台应用
不过属性这里需要修改为x64的
修改配置类型为动态库dll
代码照搬上面的,只不过要修改main函数,源码提供了convertName方法,可以不提供导出的位置,程序自动判断输出位置及格式。
完整main.cpp如下
// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <string>
#include <iostream>
#include "crypt.h"
#define _DllExport extern "C" __declspec(dllexport)
using namespace std;
string convertName(const string& filename);
_DllExport int DecryptQm(char** str_ptr)
{
string in = str_ptr[0];
string out = convertName(in);
const char* p = out.data();
bool result = convert(in, out);
if (!result)
return -1;
else
return 1;
}
string convertName(const string& filename) {
auto pos = filename.rfind('.');
if (pos == string::npos) {
cerr << "Warning: no extname." << endl;
return filename + "_CONVERTED";
}
else {
auto base = filename.substr(0, pos);
auto ext = filename.substr(pos + 1);
if (ext == "qmcflac")
ext = "flac";
else if (ext == "qmc0" || ext == "qmc3")
ext = "mp3";
else {
cerr << "Warning: unknown extname (support: qmcflac, qmc0, qmc3)."
<< endl;
ext = "mp3";
}
return base + '.' + ext;
}
}
生成dll文件放到unity的Plugins目录下。
unity下创建OpenDialogFile.cs脚本,用来选择需要处理的目录
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class OpenDialogFile
{
public int structSize = 0;
public IntPtr dlgOwner = IntPtr.Zero;
public IntPtr instance = IntPtr.Zero;
public String filter = null;
public String customFilter = null;
public int maxCustFilter = 0;
public int filterIndex = 0;
public String file = null;
public int maxFile = 0;
public String fileTitle = null;
public int maxFileTitle = 0;
public String initialDir = null;
public String title = null;
public int flags = 0;
public short fileOffset = 0;
public short fileExtension = 0;
public String defExt = null;
public IntPtr custData = IntPtr.Zero;
public IntPtr hook = IntPtr.Zero;
public String templateName = null;
public IntPtr reservedPtr = IntPtr.Zero;
public int reservedInt = 0;
public int flagsEx = 0;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class OpenDialogDir
{
public IntPtr hwndOwner = IntPtr.Zero;
public IntPtr pidlRoot = IntPtr.Zero;
public String pszDisplayName = null;
public String lpszTitle = null;
public UInt32 ulFlags = 0;
public IntPtr lpfn = IntPtr.Zero;
public IntPtr lParam = IntPtr.Zero;
public int iImage = 0;
}
public class DllOpenFileDialog
{
[DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern bool GetOpenFileName([In, Out] OpenDialogFile ofn);
[DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern bool GetSaveFileName([In, Out] OpenDialogFile ofn);
[DllImport("shell32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern IntPtr SHBrowseForFolder([In, Out] OpenDialogDir ofn);
[DllImport("shell32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern bool SHGetPathFromIDList([In] IntPtr pidl, [In, Out] char[] fileName);
}
创建控制脚本TestManager.cs,挂载任意物体
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using UnityEngine;
public class TestManager : MonoBehaviour
{
[DllImport("Project1")]
private static extern int DecryptQm(ref StringBuilder ptrStr);
void Start()
{
string folder=OpenWindowsDialog();
DirectoryInfo directoryInfo = new DirectoryInfo(folder);
FileInfo[] fileInfos = directoryInfo.GetFiles("*", SearchOption.AllDirectories);
foreach (FileInfo item in fileInfos)
{
if (item.Name.EndsWith("qmcflac")|| item.Name.EndsWith("qmc0") || item.Name.EndsWith("qmc3"))
{
StringBuilder str = new StringBuilder(item.FullName);
DecryptQm(ref str);
}
}
}
public string OpenWindowsDialog()
{
OpenDialogDir ofn2 = new OpenDialogDir();
ofn2.pszDisplayName = new string(new char[2000]); ; // 存放目录路径缓冲区
ofn2.lpszTitle = "Open Music Folder";// 标题
IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(ofn2);
char[] charArray = new char[2000];
for (int i = 0; i < 2000; i++)
charArray[i] = '\0';
DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray);
string fullDirPath = new String(charArray);
fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0'));
return fullDirPath;//这个就是选择的目录路径。
}
}
运行一下,会自动把这个目录下所有符合解密条件的文件解密
已知问题:暂时不支持有中文文件名的歌曲
施工完毕!
网友评论