Skip to content

Commit

Permalink
1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Majjcom committed Sep 2, 2023
1 parent c60bae2 commit 82b7fc1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 44 deletions.
8 changes: 4 additions & 4 deletions ncmppGui/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.aliyun.com/repository/jcenter' }
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:7.4.2'
}
}

repositories {
google()
jcenter()
maven { url 'https://maven.aliyun.com/repository/jcenter' }
}

apply plugin: 'com.android.application'
Expand All @@ -36,7 +36,7 @@ android {

compileSdkVersion androidCompileSdkVersion.toInteger()

buildToolsVersion '28.0.3'
buildToolsVersion '31.0.0'

sourceSets {
main {
Expand Down
2 changes: 1 addition & 1 deletion ncmppGui/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
8 changes: 7 additions & 1 deletion ncmppGui/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "ui_mainwindow.h"

#include <string>
#include "ncmdump.h"

#include "getpath.h"

Expand Down Expand Up @@ -39,7 +38,11 @@ void MainWindow::fileButtonClicked()
get_home_path(),
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks
#ifdef Q_OS_ANDROID
| QFileDialog::DontUseNativeDialog
#endif
);

if (get.length() != 0)
{
ui->outDir_lineEdit->setText(get);
Expand Down Expand Up @@ -100,6 +103,9 @@ void MainWindow::importButtonClicked()
this,
QStringLiteral("选择ncm文件所在的目录"),
get_home_path()
#ifdef Q_OS_ANDROID
,QFileDialog::ShowDirsOnly | QFileDialog::DontUseNativeDialog
#endif
);

QDir root_dir(path);
Expand Down
50 changes: 17 additions & 33 deletions ncmppGui/src/ncmdump.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@

#include <QFileInfo>
#include <QIODevice>
#include <QtCore>
#include <QDebug>
#include <QFile>
#include <QUrl>
#include <QDir>

#include "ncmdump.h"
#ifndef Q_OS_ANDROID
#include <filesystem>
#endif
#include <sstream>
#include <fstream>
#include <memory>
#include "openssl/aes.h"
#include "rapidjson/document.h"
#include "base64.h"
Expand All @@ -25,7 +23,7 @@ static char mata_hex[] = "2331346C6A6B5F215C5D2630553C2728";
void hex2str(const char* src_, unsigned char* tgt_);
unsigned int little_int(const unsigned char* src_);

void ncm::ncmDump(string path_, string out_path_)
void ncm::ncmDump(QString path_, QString out_path_)
{
unsigned char* core_key = new unsigned char[16];
unsigned char* mata_key = new unsigned char[16];
Expand All @@ -34,18 +32,9 @@ void ncm::ncmDump(string path_, string out_path_)
hex2str(core_hex, core_key);
hex2str(mata_hex, mata_key);

#ifdef Q_OS_ANDROID
ifstream fp;
fp.open(path_, ios::in | ios::binary);
fp.seekg(10, ios::cur); // 8 + 2
#else
using filesystem::path;

ifstream fp;
path raw_path = filesystem::u8path(path_);
fp.open(raw_path, ios::in | ios::binary);
fp.seekg(10, ios::cur); // 8 + 2
#endif
QFile fp(path_);
fp.open(QIODevice::ReadOnly);
fp.seek(fp.pos() + 10); // 8 + 2

unsigned char* key_len_bin = new unsigned char[4];
fp.read((char*)key_len_bin, 4);
Expand Down Expand Up @@ -145,32 +134,28 @@ void ncm::ncmDump(string path_, string out_path_)
rapidjson::Document& dom = *pdom;
dom.Parse(mata_str.c_str(), mata_str.length());

fp.seekg(9, ios::cur); // 4 + 5
fp.seek(fp.pos() + 9); // 4 + 5

mata_len_bin = new unsigned char[4];
fp.read((char*)mata_len_bin, 4);
mata_len = little_int(mata_len_bin);
delete[] mata_len_bin;

fp.seekg(mata_len, ios::cur);
fp.seek(fp.pos() + mata_len);

string extname = '.' + string(dom["format"].GetString());
#ifdef Q_OS_ANDROID
QFileInfo info(QString::fromUtf8(path_.c_str()));
QFileInfo info(path_);
QString out_name = info.baseName() + extname.c_str();
QDir out_p(out_path_.c_str());
string tgt = out_p.absoluteFilePath(out_name).toUtf8().toStdString();
#else
path tgt = filesystem::u8path(out_path_) / filesystem::u8path(raw_path.stem().u8string() + extname);
#endif
QDir out_p(out_path_);
QString tgt = out_p.absoluteFilePath(out_name);
delete pdom;

ofstream of;
of.open(tgt, ios::out | ios::binary);
QFile of(tgt);
of.open(QIODevice::WriteOnly);

unsigned char* buff = new unsigned char[0x8000];
fp.read((char*)buff, 0x8000);
unsigned int buff_len = (unsigned int)fp.gcount();

unsigned int buff_len = (unsigned int)fp.read((char*)buff, 0x8000);
while (buff_len)
{
for (unsigned int i = 1; i <= buff_len; i++)
Expand All @@ -179,8 +164,7 @@ void ncm::ncmDump(string path_, string out_path_)
buff[i - 1] ^= key_box[(key_box[j] + key_box[(key_box[j] + j) & 0xff]) & 0xff];
}
of.write((char*)buff, buff_len);
fp.read((char*)buff, 0x8000);
buff_len = (unsigned int)fp.gcount();
buff_len = (unsigned int)fp.read((char*)buff, 0x8000);
}
of.close();
fp.close();
Expand Down
4 changes: 2 additions & 2 deletions ncmppGui/src/ncmdump.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <string>
#include <QString>

namespace ncm
{
void ncmDump(std::string path, std::string outPath);
void ncmDump(QString path, QString outPath);
}
4 changes: 1 addition & 3 deletions ncmppGui/src/unlocker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ void Unlocker::run()
{
using std::string;
QString file = this->list_obj->getNextFile();
string src = file.toUtf8().toStdString();
string tgt = this->out_dir.toUtf8().toStdString();
ncm::ncmDump(src, tgt);
ncm::ncmDump(file, this->out_dir);
emit this->unlocked(i + 1, count);
}
this->exit();
Expand Down

0 comments on commit 82b7fc1

Please sign in to comment.