This commit is contained in:
MengYX 2020-05-14 23:46:21 +08:00
parent 7b9070f99d
commit bceabe4fcf
No known key found for this signature in database
GPG Key ID: E63F9C7303E8F604
2 changed files with 11 additions and 16 deletions

View File

@ -21,17 +21,6 @@ export async function Decrypt(file, raw_filename, raw_ext) {
let fileKey = oriData.slice(0x18, 0x20) let fileKey = oriData.slice(0x18, 0x20)
let mask = createMaskFromKey(fileKey) let mask = createMaskFromKey(fileKey)
function Uint8ArrayToString(fileData) {
var dataString = "";
for (var i = 0; i < fileData.length; i++) {
dataString += String.fromCharCode(fileData[i]);
}
return dataString
}
let audioData = oriData.slice(0x400); let audioData = oriData.slice(0x400);
let lenAudioData = audioData.length; let lenAudioData = audioData.length;
for (let cur = 0; cur < lenAudioData; ++cur) for (let cur = 0; cur < lenAudioData; ++cur)

View File

@ -1,14 +1,22 @@
const CryptoJS = require("crypto-js"); const CryptoJS = require("crypto-js");
const CORE_KEY = CryptoJS.enc.Hex.parse("687a4852416d736f356b496e62617857"); const CORE_KEY = CryptoJS.enc.Hex.parse("687a4852416d736f356b496e62617857");
const META_KEY = CryptoJS.enc.Hex.parse("2331346C6A6B5F215C5D2630553C2728"); const META_KEY = CryptoJS.enc.Hex.parse("2331346C6A6B5F215C5D2630553C2728");
import {AudioMimeType, DetectAudioExt, GetArrayBuffer, GetFileInfo, GetWebImage, WriteMp3Meta} from "./util" const MagicHeader = [0x43, 0x54, 0x45, 0x4E, 0x46, 0x44, 0x41, 0x4D];
import {
AudioMimeType,
DetectAudioExt,
GetArrayBuffer,
GetFileInfo,
GetWebImage,
IsBytesEqual,
WriteMp3Meta
} from "./util"
export async function Decrypt(file, raw_filename, raw_ext) { export async function Decrypt(file, raw_filename, raw_ext) {
const fileBuffer = await GetArrayBuffer(file); const fileBuffer = await GetArrayBuffer(file);
const dataView = new DataView(fileBuffer); const dataView = new DataView(fileBuffer);
if (dataView.getUint32(0, true) !== 0x4e455443 || if (!IsBytesEqual(MagicHeader, new Uint8Array(fileBuffer, 0, 8)))
dataView.getUint32(4, true) !== 0x4d414446)
return {status: false, message: "此ncm文件已损坏"}; return {status: false, message: "此ncm文件已损坏"};
const keyDataObj = getKeyData(dataView, fileBuffer, 10); const keyDataObj = getKeyData(dataView, fileBuffer, 10);
@ -22,7 +30,6 @@ export async function Decrypt(file, raw_filename, raw_ext) {
let lenAudioData = audioData.length; let lenAudioData = audioData.length;
for (let cur = 0; cur < lenAudioData; ++cur) audioData[cur] ^= keyBox[cur & 0xff]; for (let cur = 0; cur < lenAudioData; ++cur) audioData[cur] ^= keyBox[cur & 0xff];
if (musicMeta.album === undefined) musicMeta.album = ""; if (musicMeta.album === undefined) musicMeta.album = "";
const artists = []; const artists = [];
@ -132,7 +139,6 @@ function getMetaData(dataView, fileBuffer, offset) {
if (plainText.slice(0, labelIndex) === "dj") { if (plainText.slice(0, labelIndex) === "dj") {
result = result.mainMusic; result = result.mainMusic;
} }
console.log(result);
if (!!result.albumPic) result.albumPic = result.albumPic.replace("http://", "https://"); if (!!result.albumPic) result.albumPic = result.albumPic.replace("http://", "https://");
return {data: result, offset: offset}; return {data: result, offset: offset};
} }