diff --git a/apkstudio.pro b/apkstudio.pro index b518061..d0c807a 100644 --- a/apkstudio.pro +++ b/apkstudio.pro @@ -22,7 +22,6 @@ HEADERS += \ include/flickcharm.h \ include/ide.h \ include/installrunnable.h \ - include/jarsigner.h \ include/java.h \ include/macros.h \ include/menubar.h \ @@ -43,7 +42,7 @@ HEADERS += \ include/toolbar.h \ include/viewer.h \ include/widgetbar.h \ - include/zipalign.h + include/uberapksigner.h OTHER_FILES += \ .gitignore \ @@ -88,7 +87,6 @@ SOURCES += \ src/flickcharm.cpp \ src/ide.cpp \ src/installrunnable.cpp \ - src/jarsigner.cpp \ src/java.cpp \ src/main.cpp \ src/menubar.cpp \ @@ -109,7 +107,7 @@ SOURCES += \ src/toolbar.cpp \ src/viewer.cpp \ src/widgetbar.cpp \ - src/zipalign.cpp + src/uberapksigner.cpp TARGET = apkstudio diff --git a/include/constants.h b/include/constants.h index 534b53e..dfc88e5 100644 --- a/include/constants.h +++ b/include/constants.h @@ -54,6 +54,7 @@ #define REGEX_LF "[\\r\\n]" #define REGEX_ADB_VERSION "^.*(\\d+)\\.(\\d+)\\.(\\d+)$" #define REGEX_APKTOOL_VERSION "^(\\d+)\\.(\\d+)\\.(\\d+)$" +#define REGEX_UBERAPKTOOL_VERSION "^.*(\\d+)\\.(\\d+)\\.(\\d+)$" #define REGEX_JAVA_VERSION "^.*\"(\\d+)\\.(\\d+)\\.(\\d+)_(\\d+)\"$" #define REGEX_THEME_STYLE "\\b([a-z]+)\\:\\s*([0-9a-z#]+)\\b" #define REGEX_WHITESPACE "\\s+" diff --git a/include/jarsigner.h b/include/jarsigner.h deleted file mode 100644 index 5eb0b09..0000000 --- a/include/jarsigner.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef JARSIGNER_H -#define JARSIGNER_H - -#include "macros.h" -#include "process.h" - -APP_NAMESPACE_START - -class JarSigner : public Process -{ -private: - static JarSigner *_self; -private: - explicit JarSigner(QObject *parent = 0); -public: - static JarSigner *get(); - Result sign(const QString &src, const QString &dest, const QString &keystore, const QString &keystorePass, const QString &key, const QString &keyPass = QString()); -}; - -APP_NAMESPACE_END - -#endif // JARSIGNER_H diff --git a/include/uberapksigner.h b/include/uberapksigner.h new file mode 100644 index 0000000..529b58f --- /dev/null +++ b/include/uberapksigner.h @@ -0,0 +1,31 @@ +#ifndef UBERAPKSIGNER_H +#define UBERAPKSIGNER_H + +#include +#include "macros.h" +#include "java.h" + +APP_NAMESPACE_START + +class UberApkSigner : public Java +{ +private: + QString _jar; + static UberApkSigner *_self; +private: + explicit UberApkSigner(QObject *parent = 0); +public: + // Result build(const QString &project, const QString &apk); + // Result decode(const QString &apk, const QString &project, const QString &framework, const bool sources, const bool resources); + Result sign(const QString &src, const QString &keystore, const QString &keystorePass, const QString &key, const QString &keyPass = QString()); + Result signDebug(const QString &src); + inline Result exec(const QString &arg) { return exec(QStringList(arg)); } + Result exec(const QStringList &args = QStringList()); + static UberApkSigner *get(); + QString getVersion(); +}; + +APP_NAMESPACE_END + +#endif // UBERAPKSIGNER_H + diff --git a/include/zipalign.h b/include/zipalign.h deleted file mode 100644 index b107c19..0000000 --- a/include/zipalign.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef ZIPALIGN_H -#define ZIPALIGN_H - -#include "macros.h" -#include "process.h" - -APP_NAMESPACE_START - -class ZipAlign : public Process -{ -private: - static ZipAlign *_self; -private: - explicit ZipAlign(QObject *parent = 0); -public: - Result align(const QString &src, const QString &dest); - static ZipAlign *get(); -}; - -APP_NAMESPACE_END - -#endif // ZIPALIGN_H diff --git a/res/lang/en.ts b/res/lang/en.ts index 5088827..09387f7 100644 --- a/res/lang/en.ts +++ b/res/lang/en.ts @@ -380,6 +380,10 @@ version_apktool APK Tool: %1 + + version_uberapksigner + APK Signer: %1 + version_java Java: %1 diff --git a/src/consoledock.cpp b/src/consoledock.cpp index 9f93959..8435947 100644 --- a/src/consoledock.cpp +++ b/src/consoledock.cpp @@ -3,9 +3,8 @@ #include "include/apktool.h" #include "include/consoledock.h" #include "include/constants.h" -#include "include/jarsigner.h" +#include "include/uberapksigner.h" #include "include/qrc.h" -#include "include/zipalign.h" APP_NAMESPACE_START @@ -35,12 +34,11 @@ ConsoleDock::ConsoleDock(QWidget *parent) _connections << connect(Adb::get(), &Process::executing, this, &ConsoleDock::onExecuting); _connections << connect(ApkTool::get(), &Process::executed, this, &ConsoleDock::onExecuted); _connections << connect(ApkTool::get(), &Process::executing, this, &ConsoleDock::onExecuting); - _connections << connect(JarSigner::get(), &Process::executed, this, &ConsoleDock::onExecuted); - _connections << connect(JarSigner::get(), &Process::executing, this, &ConsoleDock::onExecuting); + _connections << connect(UberApkSigner::get(), &Process::executed, this, &ConsoleDock::onExecuted); + _connections << connect(UberApkSigner::get(), &Process::executing, this, &ConsoleDock::onExecuting); _connections << connect(Java::get(), &Process::executed, this, &ConsoleDock::onExecuted); _connections << connect(Java::get(), &Process::executing, this, &ConsoleDock::onExecuting); - _connections << connect(ZipAlign::get(), &Process::executed, this, &ConsoleDock::onExecuted); - _connections << connect(ZipAlign::get(), &Process::executing, this, &ConsoleDock::onExecuting); + } void ConsoleDock::onExecuted(const Process::Result &r) diff --git a/src/jarsigner.cpp b/src/jarsigner.cpp deleted file mode 100644 index d636101..0000000 --- a/src/jarsigner.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "include/constants.h" -#include "include/jarsigner.h" - -APP_NAMESPACE_START - -JarSigner* JarSigner::_self = NULL; - -JarSigner::JarSigner(QObject *parent) -#ifdef Q_OS_WIN - : Process("jarsigner.exe", parent) -#else - : Process("jarsigner", parent) -#endif -{ -} - -Process::Result JarSigner::sign(const QString &s, const QString &d, const QString &ks, const QString &ksp, const QString &k, const QString &kp) -{ - QStringList args("-verbose"); - args << "-sigalg" << "SHA1withRSA" << "-digestalg" << "SHA1"; - args << "-keystore" << ks << "-storepass" << ksp; - if (!kp.isEmpty()) - { - args << "-keypass" << kp; - } - return exec(args << "-signedjar" << d << s << k); -} - -JarSigner *JarSigner::get() -{ - if (!_self) - { - _self = new JarSigner(); - } - return _self; -} - -APP_NAMESPACE_END diff --git a/src/signrunnable.cpp b/src/signrunnable.cpp index f055e76..80b6b02 100644 --- a/src/signrunnable.cpp +++ b/src/signrunnable.cpp @@ -1,8 +1,7 @@ #include -#include "include/jarsigner.h" +#include "include/uberapksigner.h" #include "include/pathutils.h" #include "include/signrunnable.h" -#include "include/zipalign.h" APP_NAMESPACE_START @@ -17,18 +16,14 @@ void SignRunnable::run() { emit runnableStarted(); QString tmp = PathUtils::temp("signed.apk"); - Process::Result r = JarSigner::get()->sign(_src, tmp, _keystore, _keystorePass, _key, _keyPass); + Process::Result r; + if(_keystore.isEmpty()) + r = UberApkSigner::get()->signDebug(_src); + else + r = UberApkSigner::get()->sign(_src, _keystore, _keystorePass, _key, _keyPass); if (r.code == 0) { - r = ZipAlign::get()->align(tmp, _src); - if (r.code == 0) - { - emit signSuccess(_src); - } - else - { - emit signFailure(_src); - } + emit signSuccess(_src); QFile::remove(tmp); } else diff --git a/src/statusbar.cpp b/src/statusbar.cpp index 57a6d53..86913d2 100644 --- a/src/statusbar.cpp +++ b/src/statusbar.cpp @@ -1,5 +1,6 @@ #include "include/adb.h" #include "include/apktool.h" +#include "include/uberapksigner.h" #include "include/java.h" #include "include/statusbar.h" #include "include/qrc.h" @@ -11,12 +12,15 @@ StatusBar::StatusBar(QWidget *parent) { QLabel *adb; QLabel *apkTool; + QLabel *uberApkSigner; QLabel *java; addPermanentWidget(java = new QLabel(this)); addPermanentWidget(new StatusBarSeparator(this)); addPermanentWidget(adb = new QLabel(this)); addPermanentWidget(new StatusBarSeparator(this)); addPermanentWidget(apkTool = new QLabel(this)); + addPermanentWidget(new StatusBarSeparator(this)); + addPermanentWidget(uberApkSigner = new QLabel(this)); addPermanentWidget(new QWidget(this), 1); addPermanentWidget(_message = new QLabel(this)); setContentsMargins(4, 0, 4, 0); @@ -38,6 +42,14 @@ StatusBar::StatusBar(QWidget *parent) { apkTool->setText(__("version_apktool", "statusbar", "n/a")); } + if ((v = UberApkSigner::get()->getVersion()).isEmpty() == false) + { + uberApkSigner->setText(__("version_uberapksigner", "statusbar", v)); + } + else + { + uberApkSigner->setText(__("version_uberapksigner", "statusbar", "n/a")); + } if ((v = Java::get()->getVersion()).isEmpty() == false) { java->setText(__("version_java", "statusbar", v)); diff --git a/src/uberapksigner.cpp b/src/uberapksigner.cpp new file mode 100644 index 0000000..9971a47 --- /dev/null +++ b/src/uberapksigner.cpp @@ -0,0 +1,67 @@ +#include "include/uberapksigner.h" +#include "include/constants.h" +#include "include/pathutils.h" +#include "include/textutils.h" + +APP_NAMESPACE_START + +UberApkSigner* UberApkSigner::_self = NULL; + +UberApkSigner::UberApkSigner(QObject *parent) + : Java(parent) +{ + _jar = PathUtils::find("uber-apk-signer.jar"); +} + +Process::Result UberApkSigner::sign(const QString &s, const QString &ks, const QString &ksp, const QString &k, const QString &kp) +{ + QStringList args("--debug"); + args << "-ks" << ks << "--ksPass" << ksp; + if (!kp.isEmpty()) + { + args << "--ksKeyPass" << kp; + } + return exec(args << "-a" << s << "--ksAlias" << k << "--overwrite" << "--allowResign"); +} + +Process::Result UberApkSigner::signDebug(const QString &s) +{ + QStringList args("--debug"); + return exec(args << "-a" << s << "--overwrite" << "--allowResign"); +} + +UberApkSigner *UberApkSigner::get() +{ + if (!_self) + { + _self = new UberApkSigner(); + } + return _self; +} + +Process::Result UberApkSigner::exec(const QStringList &a) +{ + return Java::exec(QStringList("-jar") << _jar << a); +} + + +QString UberApkSigner::getVersion() +{ + Process::Result r = exec("-version"); + QRegularExpression rgx(REGEX_UBERAPKTOOL_VERSION); + foreach (const QString &l, r.output) + { + QRegularExpressionMatch m = rgx.match(l); + if (m.hasMatch()) + { + QString v("%1.%2.%3"); + for (int i = 1; i <= 3; i++) + { v = v.arg(m.captured(i)); } + return v; + } + } + return QString(); +} + +APP_NAMESPACE_END + diff --git a/src/zipalign.cpp b/src/zipalign.cpp deleted file mode 100644 index b7e08eb..0000000 --- a/src/zipalign.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "include/zipalign.h" -#include "include/constants.h" - -APP_NAMESPACE_START - -ZipAlign* ZipAlign::_self = NULL; - -ZipAlign::ZipAlign(QObject *parent) -#ifdef Q_OS_WIN - : Process("zipalign.exe", parent) -#else - : Process("zipalign", parent) -#endif -{ -} - -Process::Result ZipAlign::align(const QString &src, const QString &dest) -{ - return exec(QStringList("-f") << "-v" << "4" << src << dest); -} - -ZipAlign *ZipAlign::get() -{ - if (!_self) - { - _self = new ZipAlign(); - } - return _self; -} - -APP_NAMESPACE_END