ncmdump/ncmcrypt.h

71 lines
1.5 KiB
C
Raw Normal View History

2021-10-07 00:34:29 +08:00
#pragma once
#include "aes.h"
#include "cJSON.h"
#include <iostream>
#include <fstream>
#include <filesystem>
2021-10-07 00:34:29 +08:00
class NeteaseMusicMetadata {
private:
std::string mAlbum;
std::string mArtist;
std::string mFormat;
std::string mName;
int mDuration;
int mBitrate;
private:
cJSON* mRaw;
public:
NeteaseMusicMetadata(cJSON*);
~NeteaseMusicMetadata();
const std::string& name() const { return mName; }
const std::string& album() const { return mAlbum; }
const std::string& artist() const { return mArtist; }
const std::string& format() const { return mFormat; }
const int duration() const { return mDuration; }
const int bitrate() const { return mBitrate; }
};
class NeteaseCrypt {
private:
static const unsigned char sCoreKey[17];
static const unsigned char sModifyKey[17];
static const unsigned char mPng[8];
enum NcmFormat { MP3, FLAC };
private:
std::filesystem::path mFilepath;
std::filesystem::path mDumpFilepath;
2021-10-07 00:34:29 +08:00
NcmFormat mFormat;
std::string mImageData;
std::ifstream mFile;
unsigned char mKeyBox[256];
NeteaseMusicMetadata* mMetaData;
private:
bool isNcmFile();
bool openFile(std::filesystem::path const&);
2021-10-07 00:34:29 +08:00
int read(char *s, std::streamsize n);
void buildKeyBox(unsigned char *key, int keyLen);
std::string mimeType(std::string& data);
public:
const std::filesystem::path& filepath() const { return mFilepath; }
const std::filesystem::path& dumpFilepath() const { return mDumpFilepath; }
2021-10-07 00:34:29 +08:00
public:
NeteaseCrypt(std::filesystem::path const&);
2021-10-07 00:34:29 +08:00
~NeteaseCrypt();
public:
void Dump();
void FixMetadata();
};