├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ └── Project.xml
├── gradle.xml
├── misc.xml
├── runConfigurations.xml
└── vcs.xml
├── app
├── .gitignore
├── build.gradle
├── libs
│ ├── json-20190722.jar
│ └── rhino-1.7.12.jar
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── mjtg
│ │ └── neutron
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ ├── classes.dex
│ │ └── pre.js
│ ├── java
│ │ └── com
│ │ │ └── mjtg
│ │ │ └── neutron
│ │ │ ├── AboutActivity.java
│ │ │ ├── FileActivity.java
│ │ │ ├── FileUntil.java
│ │ │ ├── FileViewAdapter.java
│ │ │ ├── GData.java
│ │ │ ├── JSEngine.java
│ │ │ ├── MainActivity.java
│ │ │ ├── ModDemo.java
│ │ │ ├── ModViewAdapter.java
│ │ │ ├── SelectActivity.java
│ │ │ ├── SettingActivity.java
│ │ │ ├── TransService.java
│ │ │ └── loader
│ │ │ ├── ModLoadingProtocolServer.java
│ │ │ └── protocol
│ │ │ ├── ProtocolException.java
│ │ │ ├── format
│ │ │ ├── FetchModsPacket.java
│ │ │ ├── FetchModsResponsePacket.java
│ │ │ ├── FetchRuntimePacket.java
│ │ │ ├── FetchRuntimeResponsePacket.java
│ │ │ ├── JSONUtils.java
│ │ │ └── Packet.java
│ │ │ ├── package-info.java
│ │ │ └── server
│ │ │ ├── LoadingWebsocketProtocolServer.java
│ │ │ ├── NeutronProtocolServer.java
│ │ │ └── ProtocolRequestHandler.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── file.png
│ │ ├── folder.png
│ │ ├── ic_launcher_background.xml
│ │ └── pack.png
│ │ ├── layout
│ │ ├── activity_about.xml
│ │ ├── activity_file.xml
│ │ ├── activity_main.xml
│ │ ├── activity_select.xml
│ │ ├── activity_setting.xml
│ │ ├── alert.xml
│ │ ├── file_row.xml
│ │ └── mod_row.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ │ └── xml
│ │ └── filepaths.xml
│ └── test
│ └── java
│ └── com
│ └── mjtg
│ └── neutron
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── readme.md
├── runtime
├── .gitignore
├── api
│ ├── .gitignore
│ ├── build.gradle
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── mjtg
│ │ └── neutron
│ │ └── api
│ │ ├── NeutronMod.java
│ │ └── hooks
│ │ ├── ItemStack.java
│ │ └── NeutronHooks.java
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── local.properties
├── preloading
│ ├── .gitignore
│ ├── build.gradle
│ ├── consumer-rules.pro
│ ├── proguard-rules.pro
│ └── src
│ │ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── cpp
│ │ ├── CMakeLists.txt
│ │ └── stub.cpp
│ │ └── java
│ │ └── com
│ │ └── mjtg
│ │ └── neutron
│ │ └── runtime
│ │ ├── hook
│ │ └── PESORegistry.java
│ │ ├── loader
│ │ └── protocol
│ │ │ ├── ProtocolException.java
│ │ │ ├── client
│ │ │ ├── NeutronProtocolClient.java
│ │ │ └── NeutronWebSocketClient.java
│ │ │ ├── format
│ │ │ ├── FetchModsPacket.java
│ │ │ ├── FetchModsResponsePacket.java
│ │ │ ├── FetchRuntimePacket.java
│ │ │ ├── FetchRuntimeResponsePacket.java
│ │ │ ├── JSONUtils.java
│ │ │ └── Packet.java
│ │ │ └── package-info.java
│ │ └── mixin
│ │ └── MCMainActivityMixin.java
├── running
│ ├── .gitignore
│ ├── build.gradle
│ ├── consumer-rules.pro
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── mjtg
│ │ │ └── neutron
│ │ │ └── patcher
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── cpp
│ │ │ ├── CMakeLists.txt
│ │ │ ├── dummy.cpp
│ │ │ ├── libs
│ │ │ │ ├── libsubstrate-dvm.so
│ │ │ │ └── libsubstrate.so
│ │ │ ├── neutron.cy.cpp
│ │ │ └── substrate.h
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── mjtg
│ │ │ │ └── neutron
│ │ │ │ ├── hook
│ │ │ │ └── NeutronHooking.java
│ │ │ │ └── runtime
│ │ │ │ └── NeutronRuntime.java
│ │ └── res
│ │ │ ├── values
│ │ │ └── strings.xml
│ │ │ └── xml
│ │ │ └── filepaths.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── mjtg
│ │ └── neutron
│ │ └── patcher
│ │ └── ExampleUnitTest.java
└── settings.gradle
├── settings.gradle
└── tools
├── .gitignore
├── README.md
├── build.gradle
├── libs
├── dex2jar
│ ├── antlr-runtime-3.5.jar
│ ├── asm-debug-all-4.1.jar
│ ├── d2j-base-cmd-2.0.jar
│ ├── d2j-jasmin-2.0.jar
│ ├── d2j-smali-2.0.jar
│ ├── dex-ir-2.0.jar
│ ├── dex-reader-2.0.jar
│ ├── dex-reader-api-2.0.jar
│ ├── dex-tools-2.0.jar
│ ├── dex-translator-2.0.jar
│ ├── dex-writer-2.0.jar
│ └── dx-1.7.jar
└── javaassist
│ └── javassist-3.26.0.jar
└── src
└── main
└── java
├── android
└── os
│ └── Bundle.java
└── com
└── mjtg
└── neutron
├── cli
└── Main.java
├── converter
└── DexJarConverter.java
├── packer
└── JarPacker.java
├── patcher
├── ApkPatcher.java
├── DexPatcher.java
├── PatchApkFromRuntimeAARCommand.java
└── PrepareRuntimeDirFromAAR.java
└── util
├── PathUtil.java
└── ZipUtil.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | .cxx
4 | /local.properties
5 | /.idea/libraries
6 | /.idea/caches
7 | /.idea/modules.xml
8 | /.idea/workspace.xml
9 | .DS_Store
10 | /build
11 | /captures
12 | .externalNativeBuild
13 | .idea
14 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | xmlns:android
11 |
12 | ^$
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | xmlns:.*
22 |
23 | ^$
24 |
25 |
26 | BY_NAME
27 |
28 |
29 |
30 |
31 |
32 |
33 | .*:id
34 |
35 | http://schemas.android.com/apk/res/android
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | .*:name
45 |
46 | http://schemas.android.com/apk/res/android
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | name
56 |
57 | ^$
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | style
67 |
68 | ^$
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | .*
78 |
79 | ^$
80 |
81 |
82 | BY_NAME
83 |
84 |
85 |
86 |
87 |
88 |
89 | .*
90 |
91 | http://schemas.android.com/apk/res/android
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 | .*
101 |
102 | .*
103 |
104 |
105 | BY_NAME
106 |
107 |
108 |
109 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.mjtg.neutron"
7 | minSdkVersion 24
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | compileOptions {
20 | sourceCompatibility = 1.8
21 | targetCompatibility = 1.8
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(include: ['*.jar'], dir: 'libs')
27 | implementation 'org.java-websocket:Java-WebSocket:1.4.0'
28 | implementation 'com.google.guava:guava:28.2-jre'
29 | implementation 'com.android.support:appcompat-v7:28.0.0'
30 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
31 | implementation 'com.android.support:design:28.0.0'
32 | testImplementation 'junit:junit:4.12'
33 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
34 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
35 | implementation 'com.android.support:gridlayout-v7:28.0.0'
36 | implementation 'com.github.tbruyelle:rxpermissions:0.10.2'
37 | implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
38 | implementation 'io.reactivex.rxjava2:rxjava:2.2.4'
39 | implementation files('libs/json-20190722.jar')
40 | implementation files('libs/rhino-1.7.12.jar')
41 | }
42 |
--------------------------------------------------------------------------------
/app/libs/json-20190722.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/app/libs/json-20190722.jar
--------------------------------------------------------------------------------
/app/libs/rhino-1.7.12.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/app/libs/rhino-1.7.12.jar
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/mjtg/neutron/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.mjtg.neutron", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
17 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/assets/classes.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/app/src/main/assets/classes.dex
--------------------------------------------------------------------------------
/app/src/main/assets/pre.js:
--------------------------------------------------------------------------------
1 | function EXPORT(func){
2 |
3 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/AboutActivity.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.webkit.WebView;
7 |
8 | public class AboutActivity extends AppCompatActivity {
9 | @Override
10 | protected void onCreate(@Nullable Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.activity_about);
13 |
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/FileActivity.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron;
2 |
3 | import android.os.Bundle;
4 | import android.os.Environment;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.widget.ListView;
8 | import android.widget.TextView;
9 |
10 | import java.io.File;
11 | import java.lang.ref.WeakReference;
12 |
13 | public class FileActivity extends AppCompatActivity {
14 | public File dir;
15 | ListView list;
16 | TextView pathView;
17 | @Override
18 | protected void onCreate(@Nullable Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_file);
21 |
22 | GData.fileActivity=new WeakReference<>(this);
23 |
24 | dir= Environment.getExternalStorageDirectory();
25 | list=findViewById(R.id.file_list);
26 | pathView=findViewById(R.id.path);
27 |
28 | toPath();
29 | }
30 | public void toPath(){
31 | FileViewAdapter fva=new FileViewAdapter(this,dir.getPath());
32 | list.setAdapter(fva);
33 | pathView.setText(dir.getPath());
34 | }
35 | public void upPath(){
36 | dir=dir.getParentFile();
37 | toPath();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/FileUntil.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron;
2 |
3 | import android.content.Context;
4 | import android.os.Build;
5 | import android.support.annotation.RequiresApi;
6 |
7 | import java.io.BufferedOutputStream;
8 | import java.io.BufferedReader;
9 | import java.io.File;
10 | import java.io.FileInputStream;
11 | import java.io.FileNotFoundException;
12 | import java.io.FileOutputStream;
13 | import java.io.FileReader;
14 | import java.io.IOException;
15 | import java.io.InputStream;
16 | import java.io.OutputStream;
17 | import java.nio.file.Path;
18 | import java.util.Enumeration;
19 | import java.util.zip.ZipEntry;
20 | import java.util.zip.ZipException;
21 | import java.util.zip.ZipFile;
22 | import java.util.zip.ZipInputStream;
23 | import java.util.zip.ZipOutputStream;
24 |
25 |
26 | /**
27 | *
28 | * @version 1.0
29 | * @since 2015-9-11
30 | * @category com.feng.util
31 | *
32 | */
33 | public final class FileUntil
34 | {
35 | public static void zipUncompress(String inputFile, String destDirPath) throws IOException {
36 | File srcFile = new File(inputFile);//获取当前压缩文件
37 | // 判断源文件是否存在
38 | if (!srcFile.exists()) {
39 | throw new IOException(srcFile.getPath() + "所指文件不存在");
40 | }
41 | //开始解压
42 | //构建解压输入流
43 | ZipInputStream zIn = new ZipInputStream(new FileInputStream(srcFile));
44 | ZipEntry entry = null;
45 | File file = null;
46 | while ((entry = zIn.getNextEntry()) != null) {
47 | if (!entry.isDirectory()) {
48 | file = new File(destDirPath, entry.getName());
49 | if (!file.exists()) {
50 | new File(file.getParent()).mkdirs();//创建此文件的上级目录
51 | }
52 | OutputStream out = new FileOutputStream(file);
53 | BufferedOutputStream bos = new BufferedOutputStream(out);
54 | int len = -1;
55 | byte[] buf = new byte[1024];
56 | while ((len = zIn.read(buf)) != -1) {
57 | bos.write(buf, 0, len);
58 | }
59 | // 关流顺序,先打开的后关闭
60 | bos.close();
61 | out.close();
62 | }
63 | }
64 | }
65 | public static String readAssets(Context context, String fileName){
66 | try {
67 | InputStream is = context.getAssets().open(fileName);
68 | int size = is.available();
69 | byte[] buffer = new byte[size];
70 | is.read(buffer);
71 | is.close();
72 | return new String(buffer, "utf-8");
73 | } catch (IOException e) {
74 | e.printStackTrace();
75 | }
76 | return null;
77 | }
78 | public static String readFile(String path){
79 | StringBuilder res=new StringBuilder();
80 | try {
81 | FileReader reader = new FileReader(new File(path));
82 | BufferedReader bufferedReader=new BufferedReader(reader);
83 | String line;
84 | while((line=bufferedReader.readLine())!=null){
85 | res.append(line);
86 | }
87 | bufferedReader.close();
88 | reader.close();
89 | }catch (IOException e){
90 | e.printStackTrace();
91 | }
92 | return res.toString();
93 | }
94 | public static boolean deletefile(String path){
95 | boolean flag = false;
96 | File file = new File(path);
97 | if (!file.exists()) {
98 | return false;
99 | }
100 | if (!file.isDirectory()) {
101 | return false;
102 | }
103 | String[] str = file.list();
104 | for (int i = 0; i < str.length; i++) {
105 | System.out.println("333:"+str[i]);
106 | File fi = new File(path + "/" + str[i]);
107 | if (path.endsWith(File.separator)) {
108 | fi = new File(path + str[i]);
109 | } else {
110 | fi = new File(path + File.separator + str[i]);
111 | }
112 |
113 | if(fi.exists()||fi.list().length==0){
114 | File myFilePath = new File(path+"/"+str[i]);
115 | myFilePath.delete();
116 | }
117 | if(fi.isDirectory())//如果文件假内还有 就继续调用本方法
118 | {
119 | deletefile(path+"/"+str[i]);
120 | }else{
121 | fi.delete();
122 | }
123 |
124 | }
125 | return true;
126 | }
127 |
128 |
129 | }
130 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/FileViewAdapter.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.BaseAdapter;
9 | import android.widget.ImageView;
10 | import android.widget.TextView;
11 |
12 | import java.io.File;
13 |
14 | public class FileViewAdapter extends BaseAdapter {
15 | File dir;
16 | Context ctx;
17 | public FileViewAdapter(Context ctx,String path){
18 | this.ctx=ctx;
19 | dir=new File(path);
20 | }
21 | @Override
22 | public int getCount() {
23 | return dir.list().length;
24 | }
25 |
26 | @Override
27 | public Object getItem(int i) {
28 | return null;
29 | }
30 |
31 | @Override
32 | public long getItemId(int i) {
33 | return 0;
34 | }
35 |
36 | @Override
37 | @SuppressLint("ViewHolder")
38 | public View getView(final int i, View view, ViewGroup viewGroup) {
39 | final File[] files=dir.listFiles();
40 |
41 | final FileActivity fa= GData.fileActivity.get();
42 | final SelectActivity sa=GData.selectActivity.get();
43 | View v= LayoutInflater.from(ctx).inflate(R.layout.file_row,null);
44 | final TextView tv=v.findViewById(R.id.name);
45 | ImageView icon=v.findViewById(R.id.icon);
46 | tv.setText(files[i].getName());
47 |
48 | if(files[i].isDirectory()) {
49 | icon.setImageResource(R.drawable.folder);
50 | v.setOnClickListener(new View.OnClickListener() {
51 | @Override
52 | public void onClick(View view) {
53 | fa.dir=files[i];
54 | fa.toPath();
55 | }
56 | });
57 | }
58 | else{
59 | String[] ss=files[i].getName().split("\\.");
60 | String s=ss[ss.length-1];
61 | if(s.equals("neu")) {
62 | icon.setImageResource(R.drawable.pack);
63 | GData.showAlert(ctx, fa.getWindow().getDecorView(), "你确定添加此模组吗", new View.OnClickListener() {
64 | @Override
65 | public void onClick(View view) {
66 | sa.addMod(GData.decodeModFromPath(files[i].getPath()));
67 | }
68 | });
69 | }
70 | else
71 | icon.setImageResource(R.drawable.file);
72 | }
73 | return v;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/GData.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Color;
7 | import android.graphics.drawable.ColorDrawable;
8 | import android.view.Display;
9 | import android.view.Gravity;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.widget.PopupWindow;
13 | import android.widget.TextView;
14 |
15 | import org.json.JSONException;
16 | import org.json.JSONObject;
17 |
18 | import java.io.File;
19 | import java.io.IOException;
20 | import java.lang.ref.WeakReference;
21 | import java.util.ArrayList;
22 |
23 | public class GData {
24 | public static ArrayList modDemoList=new ArrayList<>();
25 | public static WeakReference selectActivity;
26 | public static WeakReference fileActivity;
27 |
28 | public static void showAlert(Context ctx,View parent,String content, View.OnClickListener ifyes){
29 | PopupWindow pw=new PopupWindow(ctx);
30 | View v= LayoutInflater.from(ctx).inflate(R.layout.alert,null);
31 | TextView contentText=v.findViewById(R.id.content),
32 | yesText=v.findViewById(R.id.yes);
33 | contentText.setText(content);
34 | yesText.setOnClickListener(ifyes);
35 |
36 | pw.setWidth(-2);
37 | pw.setHeight(-2);
38 | pw.setFocusable(false);
39 | pw.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
40 | pw.showAtLocation(parent, Gravity.CENTER,0,0);
41 | pw.setContentView(v);
42 | }
43 | public static ModDemo decodeModFromPath(String path) {
44 | ModDemo md=new ModDemo();
45 | String introduction="F2L";
46 | String name="F2L";
47 | String s=File.separator;
48 | File file=new File(path);
49 | md.path=path;
50 | try {
51 | FileUntil.zipUncompress(path,file.getParent()+s+"temp"+s);
52 | } catch (IOException e) {
53 | e.printStackTrace();
54 | }
55 | md.icon= BitmapFactory.decodeFile(file.getParent()+s+"temp"+s+"icon.png");
56 | try {
57 | JSONObject json=new JSONObject(FileUntil.readFile(file.getParent()+s+"temp"+s+"info.json"));
58 | introduction=json.getString("introduction");
59 | name=json.getString("name");
60 | } catch (JSONException e) {
61 | e.printStackTrace();
62 | }
63 | md.introduction=introduction;
64 | md.name=name;
65 | FileUntil.deletefile(file.getParent()+s+"temp");
66 | return md;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/JSEngine.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron;
2 |
3 |
4 | import android.content.Context;
5 |
6 | import org.mozilla.javascript.Scriptable;
7 | import org.mozilla.javascript.ScriptableObject;
8 |
9 | import java.io.File;
10 |
11 | public class JSEngine {
12 | private Class clazz;
13 | private String allFunctions = "";//js方法语句
14 | private Context ctx;
15 | public JSEngine(Context ctx) {
16 | this.clazz = JSEngine.class;
17 | initJSStr("pre.js");//初始化js语句
18 | }
19 |
20 | private void initJSStr(String filename) {
21 | this.ctx=ctx;
22 | allFunctions = " var ScriptAPI = java.lang.Class.forName(\"" + JSEngine.class.getName() + "\", true, javaLoader);\n"+FileUntil.readAssets(ctx,filename);
23 | }
24 |
25 | //本地java方法
26 | public void setValue(Object keyStr, Object o) {
27 | System.out.println("JSEngine output - setValue : " + keyStr.toString() + " ------> " + o.toString());
28 | }
29 |
30 | //本地java方法
31 | public String getValue(String keyStr) {
32 | System.out.println("JSEngine output - getValue : " + keyStr.toString());
33 | return "获取到值了";
34 | }
35 |
36 | public void runScript(String js) {
37 | String runJSStr = allFunctions + "\n" + js;//运行js = allFunctions + js
38 | org.mozilla.javascript.Context rhino = org.mozilla.javascript.Context.enter();
39 | rhino.setOptimizationLevel(-1) ;
40 | try {
41 | Scriptable scope = rhino.initStandardObjects();
42 |
43 | ScriptableObject.putProperty(scope, "javaContext", org.mozilla.javascript.Context.javaToJS(this, scope));//配置属性 javaContext:当前类JSEngine的上下文
44 | ScriptableObject.putProperty(scope, "javaLoader", org.mozilla.javascript.Context.javaToJS(clazz.getClassLoader(), scope));//配置属性 javaLoader:当前类的JSEngine的类加载器
45 |
46 | rhino.evaluateString(scope, runJSStr, clazz.getSimpleName(), 1, null);
47 | } finally {
48 | org.mozilla.javascript.Context.exit();
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron;
2 |
3 | import android.Manifest;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.design.widget.FloatingActionButton;
7 | import android.support.design.widget.Snackbar;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.support.v7.widget.CardView;
10 | import android.support.v7.widget.Toolbar;
11 | import android.view.View;
12 | import android.widget.Button;
13 |
14 | import com.tbruyelle.rxpermissions2.RxPermissions;
15 |
16 | import java.util.function.Consumer;
17 |
18 | public class MainActivity extends AppCompatActivity {
19 | Button card_manage,card_launch,card_settings,card_shop;
20 | private String[] permissionsGroup = new String[]{
21 | Manifest.permission.READ_EXTERNAL_STORAGE,
22 | Manifest.permission.WRITE_EXTERNAL_STORAGE};
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 |
28 | startService(new Intent(this,TransService.class));
29 |
30 | card_manage=findViewById(R.id.button_manage);
31 | card_launch=findViewById(R.id.button_init);
32 | card_settings=findViewById(R.id.button_set);
33 | card_shop=findViewById(R.id.button_shop);
34 |
35 | card_manage.setOnClickListener(new View.OnClickListener() {
36 | @Override
37 | public void onClick(View view) {
38 | Intent intent=new Intent(MainActivity.this,SelectActivity.class);
39 | startActivity(intent);
40 | }
41 | });
42 | RxPermissions permissions=new RxPermissions(this);
43 | permissions.request(permissionsGroup);
44 |
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/ModDemo.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | public class ModDemo {
6 | public String path;
7 | public String name;
8 | public String introduction;
9 | public Bitmap icon;
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/ModViewAdapter.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.BaseAdapter;
9 | import android.widget.ImageView;
10 | import android.widget.TextView;
11 |
12 | import org.w3c.dom.Text;
13 |
14 | import java.util.ArrayList;
15 |
16 | public class ModViewAdapter extends BaseAdapter {
17 | Context ctx;
18 | ArrayList list;
19 | public ModViewAdapter(Context ctx,ArrayList list){
20 | this.ctx=ctx;
21 |
22 | }
23 | @Override
24 | public int getCount() {
25 | return list.size();
26 | }
27 |
28 | @Override
29 | public Object getItem(int i) {
30 | return null;
31 | }
32 |
33 | @Override
34 | public long getItemId(int i) {
35 | return 0;
36 | }
37 |
38 | @Override
39 | @SuppressLint("ViewHolder")
40 | public View getView(int i, View view, ViewGroup viewGroup) {
41 | View v= LayoutInflater.from(ctx).inflate(R.layout.mod_row,null);
42 | ImageView icon=v.findViewById(R.id.icon);
43 | TextView name=v.findViewById(R.id.name);
44 | TextView introduction=v.findViewById(R.id.introduction);
45 | icon.setImageBitmap(list.get(i).icon);
46 | name.setText(list.get(i).name);
47 | introduction.setText(list.get(i).introduction);
48 | return v;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/SelectActivity.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.widget.ListView;
9 | import android.widget.TextView;
10 |
11 | import java.lang.ref.WeakReference;
12 |
13 | public class SelectActivity extends AppCompatActivity {
14 |
15 | ListView list;
16 | TextView addModText;
17 | @Override
18 | protected void onCreate(@Nullable Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_select);
21 |
22 | GData.selectActivity=new WeakReference<>(this);
23 |
24 | list=findViewById(R.id.mod_list);
25 | addModText=findViewById(R.id.add_mod);
26 |
27 | addModText.setOnClickListener(new View.OnClickListener() {
28 | @Override
29 | public void onClick(View view) {
30 | Intent intent=new Intent(SelectActivity.this,FileActivity.class);
31 | startActivity(intent);
32 | }
33 | });
34 |
35 | updateList();
36 |
37 | }
38 | public void addMod(ModDemo md){
39 | GData.modDemoList.add(0,md);
40 | updateList();
41 | }
42 | public void removeMod(int index){
43 | GData.modDemoList.remove(index);
44 | updateList();
45 |
46 | }
47 | public void updateList(){
48 | list.setAdapter(new ModViewAdapter(this,GData.modDemoList));
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/SettingActivity.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.support.v7.widget.CardView;
8 | import android.view.View;
9 |
10 | public class SettingActivity extends AppCompatActivity {
11 | @Override
12 | protected void onCreate(@Nullable Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_setting);
15 |
16 | CardView cv_about=findViewById(R.id.button_about);
17 |
18 | cv_about.setOnClickListener(new View.OnClickListener() {
19 | @Override
20 | public void onClick(View view) {
21 | startActivity(new Intent(SettingActivity.this,AboutActivity.class));
22 | }
23 | });
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/TransService.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.Handler;
6 | import android.os.IBinder;
7 | import android.support.annotation.Nullable;
8 | import android.util.Log;
9 |
10 | import com.google.common.collect.Lists;
11 | import com.mjtg.neutron.loader.ModLoadingProtocolServer;
12 | import com.mjtg.neutron.loader.protocol.server.NeutronProtocolServer;
13 |
14 | import java.io.File;
15 | import java.io.FileInputStream;
16 | import java.io.FileNotFoundException;
17 | import java.io.IOException;
18 | import java.io.InputStream;
19 | import java.nio.ByteBuffer;
20 | import java.nio.file.Paths;
21 |
22 | public class TransService extends Service {
23 |
24 | private NeutronProtocolServer server;
25 |
26 | @Nullable
27 | @Override
28 | public IBinder onBind(Intent intent) {
29 | return null;
30 | }
31 |
32 |
33 | @Override
34 | public void onCreate() {
35 | super.onCreate();
36 | }
37 |
38 | @Override
39 | public int onStartCommand(Intent intent, int flags, int startId) {
40 | Log.d("Neutron-ModServer", "starting protocol server");
41 | server = new NeutronProtocolServer(this);
42 | server.start();
43 | return super.onStartCommand(intent, flags, startId);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/loader/ModLoadingProtocolServer.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.loader;
2 |
3 | import android.util.Log;
4 |
5 | import com.google.common.io.ByteStreams;
6 |
7 | import org.java_websocket.WebSocket;
8 | import org.java_websocket.handshake.ClientHandshake;
9 | import org.java_websocket.server.WebSocketServer;
10 | import org.json.JSONArray;
11 | import org.json.JSONException;
12 | import org.json.JSONObject;
13 |
14 | import java.io.BufferedInputStream;
15 | import java.io.FileInputStream;
16 | import java.io.IOException;
17 | import java.io.InputStream;
18 | import java.net.InetSocketAddress;
19 | import java.nio.ByteBuffer;
20 | import java.nio.file.Path;
21 | import java.util.List;
22 | import java.util.function.Function;
23 | import java.util.function.Supplier;
24 |
25 | public class ModLoadingProtocolServer extends WebSocketServer {
26 |
27 | //a function that returns a list of mods to load
28 | private Supplier> fetchModList;
29 | //a function that turns a mod name into a path to it's jar, return null if the mod not exists
30 | private Function fetchMod;
31 |
32 | public ModLoadingProtocolServer(Supplier> fetchModList, Function fetchMod) {
33 | super( new InetSocketAddress( 32770 ) );
34 | this.fetchModList = fetchModList;
35 | this.fetchMod = fetchMod;
36 | }
37 |
38 | @Override
39 | public void onOpen(WebSocket conn, ClientHandshake handshake) {}
40 |
41 | @Override
42 | public void onClose(WebSocket conn, int code, String reason, boolean remote) {}
43 |
44 | @Override
45 | public void onMessage( WebSocket conn, String message ) {
46 | Log.d("Neutron-ModServer", "onMessage: received message from client: "+message);
47 | try {
48 | final JSONObject json = new JSONObject(message);
49 | switch(json.getString("type")) {
50 | case "listMods":
51 | handleListMods(conn, json);
52 | break;
53 | case "fetchMod":
54 | handleFetchMod(conn, json);
55 | break;
56 | }
57 | } catch (JSONException e) {
58 | Log.w("Neutron-ModServer", "onMessage: received invalid message from client: "+message, e);
59 | conn.close();
60 | }
61 | }
62 |
63 | private void handleFetchMod(WebSocket conn, JSONObject json) throws JSONException {
64 | final String name = json.getString("modName");
65 | try(InputStream path = fetchMod.apply(name)) {
66 | final byte[] read = ByteStreams.toByteArray(path);
67 | conn.send(read);
68 | } catch (IOException e) {
69 | Log.w("Neutron-ModServer", "onMessage: unable to read name: "+name, e);
70 | conn.close();
71 | }
72 | }
73 |
74 | @Override
75 | public void onMessage( WebSocket conn, ByteBuffer message ) {
76 | Log.w("Neutron-ModServer", "onMessage: received invalid message from client: "+message);
77 | conn.close();
78 | }
79 |
80 | @Override
81 | public void onError( WebSocket conn, Exception ex ) {
82 | Log.w("Neutron-ModServer", "onError: error trying to start Mod Server!", ex);
83 | if( conn != null ) {
84 | // some errors like port binding failed may not be assignable to a specific websocket
85 | }
86 | }
87 |
88 | @Override
89 | public void onStart() {
90 | Log.d("Neutron-ModServer", "server is now up and running!");
91 | setConnectionLostTimeout(0);
92 | setConnectionLostTimeout(100);
93 | }
94 |
95 | private void handleListMods(WebSocket conn, JSONObject json) {
96 | conn.send(new JSONArray(fetchModList.get()).toString());
97 | }
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/loader/protocol/ProtocolException.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.loader.protocol;
2 |
3 | public class ProtocolException extends RuntimeException {
4 |
5 | public ProtocolException() {
6 | super();
7 | }
8 |
9 | public ProtocolException(String message) {
10 | super(message);
11 | }
12 |
13 |
14 | public ProtocolException(String message, Throwable cause) {
15 | super(message, cause);
16 | }
17 |
18 |
19 | public ProtocolException(Throwable cause) {
20 | super(cause);
21 | }
22 |
23 |
24 | protected ProtocolException(String message, Throwable cause,
25 | boolean enableSuppression,
26 | boolean writableStackTrace) {
27 | super(message, cause, enableSuppression, writableStackTrace);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/loader/protocol/format/FetchModsPacket.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.loader.protocol.format;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | public class FetchModsPacket extends Packet {
7 |
8 | public static final String TYPE = "fetchMods";
9 |
10 |
11 | @Override
12 | public String getType() {
13 | return TYPE;
14 | }
15 |
16 | public JSONObject toJson() {
17 | try {
18 | return new JSONObject()
19 | .put("type", TYPE)
20 | ;
21 | } catch (JSONException e) {
22 | throw new RuntimeException(e);
23 | }
24 | }
25 |
26 | public static FetchModsPacket fromJson(JSONObject obj) {
27 | try {
28 | if(obj.getString("type").equals(TYPE)) {
29 | return new FetchModsPacket();
30 | } else {
31 | throw new IllegalArgumentException("incorrect type");
32 | }
33 | } catch (JSONException e) {
34 | throw new RuntimeException(e);
35 | }
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/loader/protocol/format/FetchModsResponsePacket.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.loader.protocol.format;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | public class FetchModsResponsePacket extends Packet {
10 |
11 | public static final String TYPE = "fetchModsResponsePacket";
12 |
13 | public Map mods = new HashMap<>();
14 |
15 |
16 | @Override
17 | public String getType() {
18 | return TYPE;
19 | }
20 |
21 | public JSONObject toJson() {
22 | try {
23 | return new JSONObject()
24 | .put("type", TYPE)
25 | .put("mods", JSONUtils.encodeAsBase64Object(mods))
26 | ;
27 | } catch (JSONException e) {
28 | throw new RuntimeException(e);
29 | }
30 | }
31 |
32 | public static FetchModsResponsePacket fromJson(JSONObject obj) {
33 | try {
34 | if(obj.getString("type").equals(TYPE)) {
35 | final FetchModsResponsePacket result = new FetchModsResponsePacket();
36 | result.mods = JSONUtils.decodeAsBase64Object(obj.getJSONObject("mods"));
37 | return result;
38 | } else {
39 | throw new IllegalArgumentException("incorrect type");
40 | }
41 | } catch (JSONException e) {
42 | throw new RuntimeException(e);
43 | }
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/loader/protocol/format/FetchRuntimePacket.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.loader.protocol.format;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | public class FetchRuntimePacket extends Packet {
7 |
8 | public static final String TYPE = "fetchRuntime";
9 |
10 |
11 | @Override
12 | public String getType() {
13 | return TYPE;
14 | }
15 |
16 | public JSONObject toJson() {
17 | try {
18 | return new JSONObject()
19 | .put("type", TYPE)
20 | ;
21 | } catch (JSONException e) {
22 | throw new RuntimeException(e);
23 | }
24 | }
25 |
26 | public static FetchRuntimePacket fromJson(JSONObject obj) {
27 | try {
28 | if(obj.getString("type").equals(TYPE)) {
29 | return new FetchRuntimePacket();
30 | } else {
31 | throw new IllegalArgumentException("incorrect type");
32 | }
33 | } catch (JSONException e) {
34 | throw new RuntimeException(e);
35 | }
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/loader/protocol/format/FetchRuntimeResponsePacket.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.loader.protocol.format;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | public class FetchRuntimeResponsePacket extends Packet {
10 |
11 | public static final String TYPE = "fetchRuntimeResponse";
12 |
13 | //map of libname-binary value
14 | public Map nativeLibraries = new HashMap<>();
15 |
16 | //map of dexname-binary value
17 | public Map runtimeJars = new HashMap<>();
18 |
19 |
20 | @Override
21 | public String getType() {
22 | return TYPE;
23 | }
24 |
25 | public JSONObject toJson() {
26 | try {
27 | return new JSONObject()
28 | .put("type", TYPE)
29 | .put("nativeLibs", JSONUtils.encodeAsBase64Object(nativeLibraries))
30 | .put("jars", JSONUtils.encodeAsBase64Object(runtimeJars))
31 | ;
32 | } catch (JSONException e) {
33 | throw new RuntimeException(e);
34 | }
35 | }
36 |
37 | public static FetchRuntimeResponsePacket fromJson(JSONObject obj) {
38 | try {
39 | if(obj.getString("type").equals(TYPE)) {
40 | final FetchRuntimeResponsePacket result = new FetchRuntimeResponsePacket();
41 | result.nativeLibraries = JSONUtils.decodeAsBase64Object(obj.getJSONObject("nativeLibs"));
42 | result.runtimeJars = JSONUtils.decodeAsBase64Object(obj.getJSONObject("jars"));
43 | return result;
44 | } else {
45 | throw new IllegalArgumentException("incorrect type");
46 | }
47 | } catch (JSONException e) {
48 | throw new RuntimeException(e);
49 | }
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/loader/protocol/format/JSONUtils.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.loader.protocol.format;
2 |
3 | import android.util.Base64;
4 |
5 | import org.json.JSONException;
6 | import org.json.JSONObject;
7 |
8 | import java.util.HashMap;
9 | import java.util.Iterator;
10 | import java.util.Map;
11 |
12 | public class JSONUtils {
13 |
14 | public static JSONObject encodeAsBase64Object(Map map) throws JSONException {
15 | JSONObject object = new JSONObject();
16 | for (Map.Entry entry : map.entrySet()) {
17 | object.put(
18 | entry.getKey(),
19 | Base64.encodeToString(entry.getValue(), Base64.DEFAULT)
20 | );
21 | }
22 | return object;
23 | }
24 |
25 | public static Map decodeAsBase64Object(JSONObject obj) throws JSONException {
26 | Map map = new HashMap<>();
27 | final Iterator iter = obj.keys();
28 | while (iter.hasNext()) {
29 | final String key = iter.next();
30 | map.put(
31 | key,
32 | Base64.decode(obj.getString(key), Base64.DEFAULT)
33 | );
34 | }
35 | return map;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/loader/protocol/format/Packet.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.loader.protocol.format;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | public abstract class Packet {
7 |
8 | public abstract String getType();
9 |
10 | public abstract JSONObject toJson();
11 |
12 | public static Packet fromJson(JSONObject obj) {
13 | try {
14 | switch(obj.getString("type")) {
15 | case FetchModsPacket.TYPE:
16 | return FetchModsPacket.fromJson(obj);
17 | case FetchModsResponsePacket.TYPE:
18 | return FetchModsResponsePacket.fromJson(obj);
19 | case FetchRuntimePacket.TYPE:
20 | return FetchRuntimePacket.fromJson(obj);
21 | case FetchRuntimeResponsePacket.TYPE:
22 | return FetchRuntimeResponsePacket.fromJson(obj);
23 | default:
24 | throw new IllegalArgumentException("invalid type!");
25 | }
26 | } catch (JSONException e) {
27 | throw new RuntimeException(e);
28 | }
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/loader/protocol/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * the package that contains all the protocols needed to communicate with launcher
3 | * to download runtime and mods
4 | *
5 | * use client.NeutronProtocolClient to communicate!
6 | **/
7 | package com.mjtg.neutron.loader.protocol;
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/loader/protocol/server/LoadingWebsocketProtocolServer.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.loader.protocol.server;
2 |
3 | import android.util.Log;
4 |
5 | import com.google.common.io.Files;
6 | import com.mjtg.neutron.loader.protocol.format.FetchModsPacket;
7 | import com.mjtg.neutron.loader.protocol.format.FetchModsResponsePacket;
8 | import com.mjtg.neutron.loader.protocol.format.FetchRuntimePacket;
9 | import com.mjtg.neutron.loader.protocol.format.FetchRuntimeResponsePacket;
10 | import com.mjtg.neutron.loader.protocol.format.Packet;
11 |
12 | import org.java_websocket.WebSocket;
13 | import org.java_websocket.handshake.ClientHandshake;
14 | import org.java_websocket.server.WebSocketServer;
15 | import org.json.JSONException;
16 | import org.json.JSONObject;
17 |
18 | import java.io.File;
19 | import java.io.IOException;
20 | import java.net.InetSocketAddress;
21 | import java.nio.ByteBuffer;
22 | import java.util.Map;
23 |
24 | public class LoadingWebsocketProtocolServer extends WebSocketServer {
25 |
26 | private static final String TAG = "Neutron-ModServer";
27 |
28 | private ProtocolRequestHandler handler;
29 |
30 |
31 | public LoadingWebsocketProtocolServer(int port, ProtocolRequestHandler handler) {
32 | super( new InetSocketAddress( port ) );
33 | this.handler = handler;
34 | }
35 |
36 | @Override
37 | public void onOpen(WebSocket conn, ClientHandshake handshake) {
38 | Log.d(TAG, "onOpen: received connection from client!");
39 | }
40 |
41 | @Override
42 | public void onClose(WebSocket conn, int code, String reason, boolean remote) {
43 | Log.d(TAG, "onClose: client disconnected!");
44 | }
45 |
46 | @Override
47 | public void onMessage( WebSocket conn, String message ) {
48 | Log.d(TAG, "onMessage: received message from client: "+message);
49 | try {
50 | final Packet packet = Packet.fromJson(new JSONObject(message));
51 | switch (packet.getType()) {
52 | case FetchModsPacket.TYPE:
53 | handleFetchMod(conn, (FetchModsPacket) packet);
54 | break;
55 | case FetchRuntimePacket.TYPE:
56 | handleFetchRuntime(conn, (FetchRuntimePacket) packet);
57 | break;
58 | default:
59 | throw new IllegalArgumentException("invalid type:"+ packet.getType());
60 | }
61 | } catch (IllegalArgumentException | JSONException e) {
62 | Log.w(TAG, "onMessage: received invalid message from client: "+message, e);
63 | conn.close();
64 | }
65 | }
66 |
67 | private void handleFetchRuntime(WebSocket conn, FetchRuntimePacket packet) {
68 | final ProtocolRequestHandler.Runtime rt = handler.getRuntime();
69 | final FetchRuntimeResponsePacket response = new FetchRuntimeResponsePacket();
70 |
71 | try {
72 | for (Map.Entry entry : rt.nativeLibs.entrySet()) {
73 | response.nativeLibraries.put(entry.getKey(), Files.toByteArray(entry.getValue()));
74 | }
75 | for (Map.Entry entry : rt.jars.entrySet()) {
76 | response.runtimeJars.put(entry.getKey(), Files.toByteArray(entry.getValue()));
77 | }
78 | } catch (IOException e) {
79 | e.printStackTrace();
80 | }
81 |
82 | conn.send(response.toJson().toString());
83 | }
84 |
85 | private void handleFetchMod(WebSocket conn, FetchModsPacket packet) {
86 | final Map mods = handler.getMods();
87 | final FetchModsResponsePacket response = new FetchModsResponsePacket();
88 |
89 | try {
90 | for (Map.Entry entry : mods.entrySet()) {
91 | response.mods.put(entry.getKey(), Files.toByteArray(entry.getValue()));
92 | }
93 | } catch (IOException e) {
94 | throw new RuntimeException(e);
95 | }
96 |
97 | conn.send(response.toJson().toString());
98 | }
99 |
100 | @Override
101 | public void onMessage( WebSocket conn, ByteBuffer message ) {
102 | Log.w(TAG, "onMessage: received invalid message from client: "+message);
103 | conn.close();
104 | }
105 |
106 | @Override
107 | public void onError( WebSocket conn, Exception ex ) {
108 | Log.w(TAG, "onError: error with connection!", ex);
109 | if( conn != null ) {
110 | // some errors like port binding failed may not be assignable to a specific websocket
111 | }
112 | }
113 |
114 | @Override
115 | public void onStart() {
116 | Log.d(TAG, "server is now up and running!");
117 | setConnectionLostTimeout(0);
118 | setConnectionLostTimeout(100);
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/loader/protocol/server/NeutronProtocolServer.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.loader.protocol.server;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 | import java.util.HashMap;
9 | import java.util.Map;
10 |
11 | public class NeutronProtocolServer {
12 |
13 | private static final int PORT = 32770;
14 |
15 | private LoadingWebsocketProtocolServer server;
16 |
17 | public NeutronProtocolServer(Context context) {
18 | String modsDirPath = context.getExternalFilesDir(null).toString()+File.separator+"mods";
19 |
20 | String runtimeDirPath = context.getExternalFilesDir(null).toString()+File.separator+"runtime";
21 | String nativeLibPath = runtimeDirPath + File.separator + "libs";
22 | String jarsPath = runtimeDirPath + File.separator + "jars";
23 |
24 | server = new LoadingWebsocketProtocolServer(PORT, new ProtocolRequestHandler() {
25 | @Override
26 | public Runtime getRuntime() {
27 | Runtime rt = new Runtime();
28 | Log.d("Neutron-ModServer", "reading runtime jar files from "+jarsPath);
29 | Log.d("Neutron-ModServer", "reading runtime native libraries from "+nativeLibPath);
30 | rt.nativeLibs = readAllFilesInDirectory(new File(nativeLibPath));
31 | rt.jars = readAllFilesInDirectory(new File(jarsPath));
32 | Log.d("Neutron-ModServer", "read "+ rt.nativeLibs.size()+" native libraries, "+ rt.jars.size()+" jars");
33 | return rt;
34 | }
35 |
36 | @Override
37 | public Map getMods() {
38 | Log.d("Neutron-ModServer", "fetching mods from "+ modsDirPath);
39 | Map mods = readAllFilesInDirectory(new File(modsDirPath));
40 | Log.d("Neutron-ModServer", "read "+ mods.size()+" mods");
41 | return mods;
42 | }
43 | });
44 | }
45 |
46 | public void start() {
47 | Log.d("Neutron-ModServer", "starting server");
48 | server.start();
49 | }
50 |
51 | public void stop() {
52 | try {
53 | server.stop();
54 | } catch (IOException | InterruptedException e) {
55 | throw new RuntimeException(e);
56 | }
57 | }
58 |
59 | private static Map readAllFilesInDirectory(File dir) {
60 | Map files = new HashMap<>();
61 | final File[] listFiles = dir.listFiles();
62 | if(listFiles == null) {
63 | return files;
64 | }
65 | for (File file : listFiles) {
66 | if(!file.isDirectory()) {
67 | files.put(file.getName(), file);
68 | }
69 | }
70 | return files;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mjtg/neutron/loader/protocol/server/ProtocolRequestHandler.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.loader.protocol.server;
2 |
3 | import java.io.File;
4 | import java.util.HashMap;
5 | import java.util.Map;
6 |
7 | public interface ProtocolRequestHandler {
8 |
9 | public static class Runtime {
10 |
11 | public Map jars = new HashMap<>();
12 |
13 | public Map nativeLibs = new HashMap<>();
14 |
15 | }
16 |
17 | Runtime getRuntime();
18 |
19 | Map getMods();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/app/src/main/res/drawable/file.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/app/src/main/res/drawable/folder.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/pack.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/app/src/main/res/drawable/pack.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_about.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
22 |
23 |
32 |
33 |
34 |
35 |
46 |
47 |
53 |
54 |
55 |
66 |
67 |
77 |
78 |
79 |
90 |
91 |
101 |
102 |
103 |
114 |
115 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_file.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
22 |
23 |
27 |
28 |
33 |
34 |
44 |
45 |
46 |
47 |
55 |
56 |
57 |
58 |
59 |
60 |
70 |
71 |
79 |
80 |
81 |
89 |
90 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
20 |
21 |
28 |
29 |
36 |
37 |
38 |
45 |
46 |
53 |
54 |
55 |
56 |
57 |
60 |
61 |
68 |
69 |
76 |
77 |
78 |
85 |
86 |
93 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_select.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
22 |
23 |
32 |
33 |
34 |
35 |
44 |
45 |
54 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_setting.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
22 |
23 |
32 |
33 |
34 |
40 |
41 |
50 |
51 |
59 |
60 |
61 |
69 |
70 |
78 |
79 |
80 |
88 |
89 |
97 |
98 |
99 |
100 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/alert.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
19 |
20 |
29 |
30 |
41 |
42 |
53 |
54 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/file_row.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
24 |
25 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/mod_row.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
23 |
24 |
29 |
30 |
38 |
39 |
45 |
46 |
47 |
48 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #ffffff
7 | #ffffff
8 | #000000
9 | #b0b0b0
10 | #595959
11 | #ffffff
12 | #b9b9b9
13 | #909090
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Neutron
3 | MainActivity
4 | 选择文件
5 | 管理插件
6 | 提示
7 | 设置
8 | 版本
9 | 开发人员
10 | 关于
11 | 反馈
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
25 |
26 |
31 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/filepaths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/test/java/com/mjtg/neutron/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.2'
11 | classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.0'
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
20 | maven { url 'https://jitpack.io' }
21 | google()
22 | jcenter()
23 | }
24 | }
25 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | android.useDeprecatedNdk = true
15 | android.useAndroidX=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Feb 08 13:49:01 CST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Neutron ModPE
2 | ## Contributors
3 | We have a strong team.
4 | | Name | Image |
5 | | -------- | ------------------------------------------------------------ |
6 | | CAIMEO | [](https://imgchr.com/i/31iYMn) |
7 | | Dexer | [](https://imgchr.com/i/31iYMn) |
8 | | Johnbanq | [](https://imgchr.com/i/31iYMn) |
9 | | Lampese | [](https://imgchr.com/i/31iYMn) |
10 | | Torrekie | [](https://imgchr.com/i/31AeM9) |
11 | | is you? | [](https://imgchr.com/i/31iYMn) |
12 |
13 | 我们承接渔业项目、传信工作,工资面议。水利工程同时考虑。
14 |
15 | 价格免费,真心服务
16 |
--------------------------------------------------------------------------------
/runtime/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | .idea
--------------------------------------------------------------------------------
/runtime/api/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/runtime/api/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 |
3 | repositories {
4 | maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
5 | google()
6 | jcenter()
7 | }
8 |
9 | sourceCompatibility = "8"
10 | targetCompatibility = "8"
11 |
12 | dependencies {
13 | implementation 'org.slf4j:slf4j-api:1.7.30'
14 | }
15 |
--------------------------------------------------------------------------------
/runtime/api/src/main/java/com/mjtg/neutron/api/NeutronMod.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.api;
2 |
3 | public interface NeutronMod {
4 |
5 | public void onLoad();
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/runtime/api/src/main/java/com/mjtg/neutron/api/hooks/ItemStack.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.api.hooks;
2 |
3 | public class ItemStack {
4 | }
5 |
--------------------------------------------------------------------------------
/runtime/api/src/main/java/com/mjtg/neutron/api/hooks/NeutronHooks.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.api.hooks;
2 |
3 |
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 |
7 | public class NeutronHooks {
8 |
9 | private static Logger logger = LoggerFactory.getLogger(NeutronHooks.class);
10 |
11 | public static final NeutronHooks INSTANCE = new NeutronHooks();
12 |
13 | public static native void displayClientMessage(String str);
14 |
15 | public void onUseItem(long itemStackPtr, long itemUseMethodPtr, boolean bool) {
16 | logger.info("An item has been used!");
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/runtime/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 |
3 | repositories {
4 | maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
5 | google()
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.5.3'
10 | classpath 'com.kezong:fat-aar:1.2.8'
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
--------------------------------------------------------------------------------
/runtime/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 | android.useAndroidX=true
--------------------------------------------------------------------------------
/runtime/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/runtime/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/runtime/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Feb 11 10:33:33 CST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/runtime/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/runtime/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/runtime/local.properties:
--------------------------------------------------------------------------------
1 | ## This file must *NOT* be checked into Version Control Systems,
2 | # as it contains information specific to your local configuration.
3 | #
4 | # Location of the SDK. This is only used by Gradle.
5 | # For customization when using a Version Control System, please read the
6 | # header note.
7 | #Sat Feb 08 17:58:14 CST 2020
8 | ndk.dir=F\:\\Android\\Sdk\\ndk\\21.0.6113669
9 | sdk.dir=F\:\\Android\\Sdk
10 |
--------------------------------------------------------------------------------
/runtime/preloading/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/runtime/preloading/build.gradle:
--------------------------------------------------------------------------------
1 | repositories {
2 | maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
3 | google()
4 | jcenter()
5 | }
6 |
7 | apply plugin: 'com.android.library'
8 | apply plugin: 'com.kezong.fat-aar'
9 |
10 | android {
11 | compileSdkVersion 28
12 | buildToolsVersion "28.0.3"
13 |
14 | defaultConfig {
15 | minSdkVersion 24
16 | targetSdkVersion 28
17 | versionCode 1
18 | versionName "1.0"
19 |
20 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
21 | consumerProguardFiles 'consumer-rules.pro'
22 |
23 | ndk {
24 | abiFilter 'armeabi-v7a'
25 | }
26 | externalNativeBuild {
27 | cmake {
28 | cppFlags "-std=c++14"
29 | }
30 | }
31 | }
32 |
33 | buildTypes {
34 | release {
35 | minifyEnabled false
36 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
37 | }
38 | }
39 |
40 | compileOptions {
41 | sourceCompatibility = 1.7
42 | targetCompatibility = 1.7
43 | }
44 |
45 | externalNativeBuild {
46 | cmake {
47 | path "src/main/cpp/CMakeLists.txt"
48 | }
49 | }
50 |
51 | }
52 |
53 | dependencies {
54 | embed 'org.slf4j:slf4j-api:1.7.30'
55 | embed 'commons-io:commons-io:2.6'
56 | embed 'org.java-websocket:Java-WebSocket:1.4.0'
57 | embed group: 'org.slf4j', name: 'slf4j-android', version: '1.7.30'
58 | testImplementation 'junit:junit:4.12'
59 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
60 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
61 | }
62 |
--------------------------------------------------------------------------------
/runtime/preloading/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/runtime/preloading/consumer-rules.pro
--------------------------------------------------------------------------------
/runtime/preloading/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/runtime/preloading/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/runtime/preloading/src/main/cpp/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.6)
2 |
3 | find_library( log-lib log )
4 |
5 |
6 | add_library(
7 | stub
8 | SHARED
9 | stub.cpp
10 | )
11 |
12 | target_link_libraries(
13 | stub
14 | PRIVATE
15 | ${log-lib}
16 | )
--------------------------------------------------------------------------------
/runtime/preloading/src/main/cpp/stub.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "dlfcn.h"
3 |
4 | extern "C" JNIEXPORT jlong JNICALL Java_com_mjtg_neutron_runtime_hook_PESORegistry_getPEAddress(JNIEnv* env, jclass clazz) {
5 | return (jlong)dlopen("libminecraftpe.so",RTLD_LAZY);
6 | }
--------------------------------------------------------------------------------
/runtime/preloading/src/main/java/com/mjtg/neutron/runtime/hook/PESORegistry.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.runtime.hook;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 |
6 | public class PESORegistry {
7 |
8 | private static final Logger logger = LoggerFactory.getLogger(PESORegistry.class);
9 |
10 | //the libminecraftpe.so
11 | public static long PE_ADDRESS = 0;
12 |
13 | private static native long getPEAddress();
14 |
15 | public static void setupPEAddress() {
16 | logger.debug("getting libminecraftpe.so address");
17 | System.loadLibrary("stub");
18 | PE_ADDRESS = getPEAddress();
19 | logger.info("got libminecraftpe.so address: {}", PE_ADDRESS);
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/runtime/preloading/src/main/java/com/mjtg/neutron/runtime/loader/protocol/ProtocolException.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.runtime.loader.protocol;
2 |
3 | public class ProtocolException extends RuntimeException {
4 |
5 | public ProtocolException() {
6 | super();
7 | }
8 |
9 | public ProtocolException(String message) {
10 | super(message);
11 | }
12 |
13 |
14 | public ProtocolException(String message, Throwable cause) {
15 | super(message, cause);
16 | }
17 |
18 |
19 | public ProtocolException(Throwable cause) {
20 | super(cause);
21 | }
22 |
23 |
24 | protected ProtocolException(String message, Throwable cause,
25 | boolean enableSuppression,
26 | boolean writableStackTrace) {
27 | super(message, cause, enableSuppression, writableStackTrace);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/runtime/preloading/src/main/java/com/mjtg/neutron/runtime/loader/protocol/client/NeutronProtocolClient.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.runtime.loader.protocol.client;
2 |
3 | import com.mjtg.neutron.runtime.loader.protocol.format.Packet;
4 | import com.mjtg.neutron.runtime.loader.protocol.ProtocolException;
5 | import com.mjtg.neutron.runtime.loader.protocol.format.FetchModsPacket;
6 | import com.mjtg.neutron.runtime.loader.protocol.format.FetchModsResponsePacket;
7 | import com.mjtg.neutron.runtime.loader.protocol.format.FetchRuntimePacket;
8 | import com.mjtg.neutron.runtime.loader.protocol.format.FetchRuntimeResponsePacket;
9 |
10 | import org.apache.commons.io.FileUtils;
11 | import org.java_websocket.exceptions.WebsocketNotConnectedException;
12 |
13 | import java.io.File;
14 | import java.io.IOException;
15 | import java.net.URI;
16 | import java.net.URISyntaxException;
17 | import java.util.Map;
18 | import java.util.concurrent.ExecutionException;
19 | import java.util.concurrent.Future;
20 | import java.util.concurrent.TimeUnit;
21 | import java.util.concurrent.TimeoutException;
22 |
23 | public class NeutronProtocolClient implements AutoCloseable {
24 |
25 | private static final String SERVER_URL = "ws://localhost:32770";
26 |
27 | private NeutronWebSocketClient protocolClient;
28 |
29 | public void downloadRuntime(File runtimeJarDir, File runtimeNativeLibDir) {
30 | try {
31 | createConnectClientIfNone();
32 |
33 | //fetch response
34 | final Future respFut = protocolClient.sendMessage(new FetchRuntimePacket());
35 | FetchRuntimeResponsePacket resp;
36 | try {
37 | resp = (FetchRuntimeResponsePacket) respFut.get(10, TimeUnit.SECONDS);
38 | } catch (ClassCastException e) {
39 | throw new ProtocolException("invalid response type in fetchRuntime: "+respFut.get().getType());
40 | }
41 |
42 | //prepare directories
43 | mkdirsIfNotExists(runtimeJarDir);
44 | mkdirsIfNotExists(runtimeNativeLibDir);
45 |
46 | //extract response
47 | try {
48 | for (Map.Entry entry : resp.runtimeJars.entrySet()) {
49 | File f = new File(runtimeJarDir.toString()+File.separator+entry.getKey());
50 | FileUtils.writeByteArrayToFile(f, entry.getValue());
51 | }
52 | } catch (IOException e) {
53 | throw new RuntimeException("error writing jars", e);
54 | }
55 |
56 | try {
57 | for (Map.Entry entry : resp.nativeLibraries.entrySet()) {
58 | File f = new File(runtimeNativeLibDir.toString()+File.separator+entry.getKey());
59 | FileUtils.writeByteArrayToFile(f, entry.getValue());
60 | }
61 | } catch (IOException e) {
62 | throw new RuntimeException("error writing native libraries", e);
63 | }
64 |
65 | } catch (InterruptedException | ExecutionException | TimeoutException e) {
66 | throw new ProtocolException("error in waiting response", e);
67 | }
68 | }
69 |
70 | public void downloadMods(File modsDir) {
71 | try {
72 | createConnectClientIfNone();
73 |
74 | //fetch response
75 | final Future respFut = protocolClient.sendMessage(new FetchModsPacket());
76 | FetchModsResponsePacket resp;
77 | try {
78 | resp = (FetchModsResponsePacket) respFut.get(10, TimeUnit.SECONDS);
79 | } catch (ClassCastException e) {
80 | throw new ProtocolException("invalid response type in fetch mods: "+respFut.get().getType());
81 | }
82 |
83 | //prepare directories
84 | mkdirsIfNotExists(modsDir);
85 |
86 | //extract response
87 | try {
88 | for (Map.Entry entry : resp.mods.entrySet()) {
89 | File f = new File(modsDir.toString()+File.separator+entry.getKey());
90 | FileUtils.writeByteArrayToFile(f, entry.getValue());
91 | }
92 | } catch (IOException e) {
93 | throw new RuntimeException("error writing mods", e);
94 | }
95 |
96 | } catch (InterruptedException | ExecutionException | TimeoutException e) {
97 | throw new ProtocolException("error in waiting response", e);
98 | }
99 | }
100 |
101 | private void mkdirsIfNotExists(File dir) {
102 | if(!dir.exists()) {
103 | if(!dir.mkdirs()) {
104 | throw new RuntimeException("unable to mkdir for runtimeDexDir: "+dir.toString());
105 | }
106 | }
107 | }
108 |
109 | @Override
110 | public void close() {
111 | if (protocolClient!=null) {
112 | protocolClient.close();
113 | protocolClient = null;
114 | }
115 | }
116 |
117 | private void createConnectClientIfNone() {
118 | if(protocolClient == null) {
119 | try {
120 | protocolClient = new NeutronWebSocketClient(new URI(SERVER_URL));
121 | if (!protocolClient.connectBlocking()) {
122 | throw new WebsocketNotConnectedException();
123 | }
124 | } catch (URISyntaxException | InterruptedException e) {
125 | protocolClient = null;
126 | throw new RuntimeException(e);
127 | }
128 | }
129 | }
130 |
131 | }
132 |
--------------------------------------------------------------------------------
/runtime/preloading/src/main/java/com/mjtg/neutron/runtime/loader/protocol/client/NeutronWebSocketClient.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.runtime.loader.protocol.client;
2 |
3 |
4 | import android.util.Base64;
5 | import android.util.Log;
6 |
7 | import com.mjtg.neutron.runtime.loader.protocol.format.Packet;
8 |
9 | import org.java_websocket.client.WebSocketClient;
10 | import org.java_websocket.handshake.ServerHandshake;
11 | import org.json.JSONObject;
12 |
13 | import java.net.URI;
14 | import java.nio.ByteBuffer;
15 | import java.util.concurrent.CompletableFuture;
16 | import java.util.concurrent.Future;
17 | import java.util.function.Consumer;
18 |
19 | public class NeutronWebSocketClient extends WebSocketClient {
20 |
21 | private static final String TAG = "Neutron-Client";
22 |
23 | private boolean inProgress;
24 |
25 | private Consumer stringMessageConsumer;
26 |
27 |
28 | public NeutronWebSocketClient(URI serverUri) {
29 | super(serverUri);
30 | }
31 |
32 | @Override
33 | public void onOpen(ServerHandshake handshakedata) {
34 | Log.d(TAG, "connected to server: "+ getRemoteSocketAddress().toString());
35 | }
36 |
37 | @Override
38 | public void onMessage(String message) {
39 | Log.d(TAG, "onMessage: received text message from server: "+message);
40 | if(stringMessageConsumer!=null) {
41 | stringMessageConsumer.accept(message);
42 | }
43 | }
44 |
45 | @Override
46 | public void onMessage(ByteBuffer bytes) {
47 | Log.d(TAG, "onMessage: received byte message from server: "+ Base64.encodeToString(bytes.array(), Base64.DEFAULT));
48 | }
49 |
50 | @Override
51 | public void onClose(int code, String reason, boolean remote) {
52 | Log.d(TAG, "connection closed");
53 | }
54 |
55 | @Override
56 | public void onError(Exception ex) {
57 | Log.e(TAG, "error while communicating with server", ex);
58 | }
59 |
60 | public Future sendMessage(Packet request) {
61 | if(inProgress) {
62 | throw new IllegalStateException("the client does not support concurrent usage!");
63 | }
64 |
65 | final CompletableFuture fut = new CompletableFuture<>();
66 |
67 | //handle response
68 | inProgress = true;
69 | stringMessageConsumer = new Consumer() {
70 | @Override
71 | public void accept(String str) {
72 | inProgress = false;
73 | stringMessageConsumer = null;
74 | try {
75 | final Packet packet = Packet.fromJson(new JSONObject(str));
76 | fut.complete(packet);
77 | } catch (Exception e) {
78 | fut.completeExceptionally(e);
79 | NeutronWebSocketClient.this.close();
80 | }
81 | }
82 | };
83 |
84 | //send request
85 | send(request.toJson().toString());
86 |
87 | return fut;
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/runtime/preloading/src/main/java/com/mjtg/neutron/runtime/loader/protocol/format/FetchModsPacket.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.runtime.loader.protocol.format;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | public class FetchModsPacket extends Packet {
7 |
8 | public static final String TYPE = "fetchMods";
9 |
10 |
11 | @Override
12 | public String getType() {
13 | return TYPE;
14 | }
15 |
16 | public JSONObject toJson() {
17 | try {
18 | return new JSONObject()
19 | .put("type", TYPE)
20 | ;
21 | } catch (JSONException e) {
22 | throw new RuntimeException(e);
23 | }
24 | }
25 |
26 | public static FetchModsPacket fromJson(JSONObject obj) {
27 | try {
28 | if(obj.getString("type").equals(TYPE)) {
29 | return new FetchModsPacket();
30 | } else {
31 | throw new IllegalArgumentException("incorrect type");
32 | }
33 | } catch (JSONException e) {
34 | throw new RuntimeException(e);
35 | }
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/runtime/preloading/src/main/java/com/mjtg/neutron/runtime/loader/protocol/format/FetchModsResponsePacket.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.runtime.loader.protocol.format;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | public class FetchModsResponsePacket extends Packet {
10 |
11 | public static final String TYPE = "fetchModsResponsePacket";
12 |
13 | public Map mods = new HashMap<>();
14 |
15 |
16 | @Override
17 | public String getType() {
18 | return TYPE;
19 | }
20 |
21 | public JSONObject toJson() {
22 | try {
23 | return new JSONObject()
24 | .put("type", TYPE)
25 | .put("mods", JSONUtils.encodeAsBase64Object(mods))
26 | ;
27 | } catch (JSONException e) {
28 | throw new RuntimeException(e);
29 | }
30 | }
31 |
32 | public static FetchModsResponsePacket fromJson(JSONObject obj) {
33 | try {
34 | if(obj.getString("type").equals(TYPE)) {
35 | final FetchModsResponsePacket result = new FetchModsResponsePacket();
36 | result.mods = JSONUtils.decodeAsBase64Object(obj.getJSONObject("mods"));
37 | return result;
38 | } else {
39 | throw new IllegalArgumentException("incorrect type");
40 | }
41 | } catch (JSONException e) {
42 | throw new RuntimeException(e);
43 | }
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/runtime/preloading/src/main/java/com/mjtg/neutron/runtime/loader/protocol/format/FetchRuntimePacket.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.runtime.loader.protocol.format;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | public class FetchRuntimePacket extends Packet {
7 |
8 | public static final String TYPE = "fetchRuntime";
9 |
10 |
11 | @Override
12 | public String getType() {
13 | return TYPE;
14 | }
15 |
16 | public JSONObject toJson() {
17 | try {
18 | return new JSONObject()
19 | .put("type", TYPE)
20 | ;
21 | } catch (JSONException e) {
22 | throw new RuntimeException(e);
23 | }
24 | }
25 |
26 | public static FetchRuntimePacket fromJson(JSONObject obj) {
27 | try {
28 | if(obj.getString("type").equals(TYPE)) {
29 | return new FetchRuntimePacket();
30 | } else {
31 | throw new IllegalArgumentException("incorrect type");
32 | }
33 | } catch (JSONException e) {
34 | throw new RuntimeException(e);
35 | }
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/runtime/preloading/src/main/java/com/mjtg/neutron/runtime/loader/protocol/format/FetchRuntimeResponsePacket.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.runtime.loader.protocol.format;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | public class FetchRuntimeResponsePacket extends Packet {
10 |
11 | public static final String TYPE = "fetchRuntimeResponse";
12 |
13 | //map of libname-binary value
14 | public Map nativeLibraries = new HashMap<>();
15 |
16 | //map of dexname-binary value
17 | public Map runtimeJars = new HashMap<>();
18 |
19 |
20 | @Override
21 | public String getType() {
22 | return TYPE;
23 | }
24 |
25 | public JSONObject toJson() {
26 | try {
27 | return new JSONObject()
28 | .put("type", TYPE)
29 | .put("nativeLibs", JSONUtils.encodeAsBase64Object(nativeLibraries))
30 | .put("jars", JSONUtils.encodeAsBase64Object(runtimeJars))
31 | ;
32 | } catch (JSONException e) {
33 | throw new RuntimeException(e);
34 | }
35 | }
36 |
37 | public static FetchRuntimeResponsePacket fromJson(JSONObject obj) {
38 | try {
39 | if(obj.getString("type").equals(TYPE)) {
40 | final FetchRuntimeResponsePacket result = new FetchRuntimeResponsePacket();
41 | result.nativeLibraries = JSONUtils.decodeAsBase64Object(obj.getJSONObject("nativeLibs"));
42 | result.runtimeJars = JSONUtils.decodeAsBase64Object(obj.getJSONObject("jars"));
43 | return result;
44 | } else {
45 | throw new IllegalArgumentException("incorrect type");
46 | }
47 | } catch (JSONException e) {
48 | throw new RuntimeException(e);
49 | }
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/runtime/preloading/src/main/java/com/mjtg/neutron/runtime/loader/protocol/format/JSONUtils.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.runtime.loader.protocol.format;
2 |
3 | import android.util.Base64;
4 |
5 | import org.json.JSONException;
6 | import org.json.JSONObject;
7 |
8 | import java.util.HashMap;
9 | import java.util.Iterator;
10 | import java.util.Map;
11 |
12 | public class JSONUtils {
13 |
14 | public static JSONObject encodeAsBase64Object(Map map) throws JSONException {
15 | JSONObject object = new JSONObject();
16 | for (Map.Entry entry : map.entrySet()) {
17 | object.put(
18 | entry.getKey(),
19 | Base64.encodeToString(entry.getValue(), Base64.DEFAULT)
20 | );
21 | }
22 | return object;
23 | }
24 |
25 | public static Map decodeAsBase64Object(JSONObject obj) throws JSONException {
26 | Map map = new HashMap<>();
27 | final Iterator iter = obj.keys();
28 | while (iter.hasNext()) {
29 | final String key = iter.next();
30 | map.put(
31 | key,
32 | Base64.decode(obj.getString(key), Base64.DEFAULT)
33 | );
34 | }
35 | return map;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/runtime/preloading/src/main/java/com/mjtg/neutron/runtime/loader/protocol/format/Packet.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.runtime.loader.protocol.format;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | public abstract class Packet {
7 |
8 | public abstract String getType();
9 |
10 | public abstract JSONObject toJson();
11 |
12 | public static Packet fromJson(JSONObject obj) {
13 | try {
14 | switch(obj.getString("type")) {
15 | case FetchModsPacket.TYPE:
16 | return FetchModsPacket.fromJson(obj);
17 | case FetchModsResponsePacket.TYPE:
18 | return FetchModsResponsePacket.fromJson(obj);
19 | case FetchRuntimePacket.TYPE:
20 | return FetchRuntimePacket.fromJson(obj);
21 | case FetchRuntimeResponsePacket.TYPE:
22 | return FetchRuntimeResponsePacket.fromJson(obj);
23 | default:
24 | throw new IllegalArgumentException("invalid type!");
25 | }
26 | } catch (JSONException e) {
27 | throw new RuntimeException(e);
28 | }
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/runtime/preloading/src/main/java/com/mjtg/neutron/runtime/loader/protocol/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * the package that contains all the protocols needed to communicate with launcher
3 | * to download runtime and mods
4 | *
5 | * use client.NeutronProtocolClient to communicate!
6 | **/
7 | package com.mjtg.neutron.runtime.loader.protocol;
--------------------------------------------------------------------------------
/runtime/preloading/src/main/java/com/mjtg/neutron/runtime/mixin/MCMainActivityMixin.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.runtime.mixin;
2 |
3 | import android.app.Activity;
4 | import android.util.Log;
5 |
6 | import com.mjtg.neutron.runtime.hook.PESORegistry;
7 | import com.mjtg.neutron.runtime.loader.protocol.client.NeutronProtocolClient;
8 | import com.mjtg.neutron.runtime.loader.protocol.client.NeutronWebSocketClient;
9 |
10 | import java.io.File;
11 | import java.lang.reflect.Method;
12 | import java.util.StringJoiner;
13 |
14 | import dalvik.system.DexClassLoader;
15 |
16 |
17 | public class MCMainActivityMixin {
18 |
19 | private Object mcActivity;
20 |
21 | private Object neutronRuntime;
22 |
23 | public MCMainActivityMixin() {}
24 |
25 | public void onCreate(Object mcActivity) {
26 | Log.i("Neutron-Mixin", "intercepted MinecraftActivity::onCreate!");
27 | this.mcActivity = mcActivity;
28 |
29 | //prepare the hooking address
30 | PESORegistry.setupPEAddress();
31 |
32 | //start runtime
33 | startRuntime();
34 |
35 | }
36 |
37 | private void startRuntime() {
38 | Log.i("Neutron-Mixin", "loading runtime from launcher");
39 | final File cacheDir = ((Activity) mcActivity).getCacheDir();
40 | final File runtimeDir = new File(cacheDir.toString()+File.separator+"runtime");
41 | final File nativeLibDir = new File(runtimeDir.toString()+File.separator+"libs");
42 | final File jarsDir = new File(runtimeDir.toString()+File.separator+"jars");
43 |
44 | NeutronProtocolClient client = new NeutronProtocolClient();
45 | try {
46 | client.downloadRuntime(jarsDir, nativeLibDir);
47 |
48 | //the jars path
49 | final StringBuilder dexes = new StringBuilder();
50 | for (File jar : jarsDir.listFiles()) {
51 | if(dexes.length()!=0) {
52 | dexes.append(File.pathSeparator);
53 | }
54 | dexes.append(jar.getAbsolutePath());
55 | }
56 |
57 | //setup the class loader
58 | final DexClassLoader cl = new DexClassLoader(
59 | dexes.toString(),
60 | ((Activity) mcActivity).getCodeCacheDir().toString(),
61 | nativeLibDir.getAbsolutePath(),
62 | getClass().getClassLoader()
63 | );
64 |
65 | //load the class and reflectively start it
66 | Log.i("Neutron-Mixin", "reflectively starting the runtime");
67 | final Class> clazz = cl.loadClass("com.mjtg.neutron.runtime.NeutronRuntime");
68 | neutronRuntime = clazz.newInstance();
69 | final Method start = clazz.getMethod("start", Activity.class, NeutronProtocolClient.class);
70 | start.invoke(neutronRuntime, (Activity)mcActivity, client);
71 | client = null;
72 |
73 | } catch (Exception e) {
74 | throw new RuntimeException(e);
75 | } finally {
76 | if( client != null ) {
77 | client.close();
78 | }
79 | if(runtimeDir.exists()) {
80 | if(!runtimeDir.delete()) {
81 | Log.w("Neutron-Mixin", "unable to erase runtime tmp directory, this might become a source of issue!");
82 | }
83 | }
84 | }
85 | }
86 |
87 | }
--------------------------------------------------------------------------------
/runtime/running/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/runtime/running/build.gradle:
--------------------------------------------------------------------------------
1 |
2 | repositories {
3 | maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
4 | google()
5 | jcenter()
6 | }
7 |
8 | apply plugin: 'com.android.library'
9 | apply plugin: 'com.kezong.fat-aar'
10 |
11 | android {
12 | compileSdkVersion 28
13 | buildToolsVersion "28.0.3"
14 |
15 |
16 | defaultConfig {
17 | minSdkVersion 24
18 | targetSdkVersion 28
19 | versionCode 1
20 | versionName "1.0"
21 |
22 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
23 | consumerProguardFiles 'consumer-rules.pro'
24 |
25 | ndk {
26 | abiFilter 'armeabi-v7a'
27 | }
28 | externalNativeBuild {
29 | cmake {
30 | cppFlags "-std=c++14"
31 | }
32 | }
33 | }
34 |
35 | buildTypes {
36 |
37 | release {
38 | minifyEnabled false
39 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
40 | }
41 | }
42 |
43 | externalNativeBuild {
44 | cmake {
45 | path "src/main/cpp/CMakeLists.txt"
46 | }
47 | }
48 | compileOptions {
49 | sourceCompatibility = 1.7
50 | targetCompatibility = 1.7
51 | }
52 |
53 | }
54 |
55 | dependencies {
56 | //these 3 jars are already provided in preload-runtime, so we dont need them here
57 | implementation 'org.slf4j:slf4j-api:1.7.30'
58 | implementation 'commons-io:commons-io:2.6'
59 | implementation 'org.java-websocket:Java-WebSocket:1.4.0'
60 |
61 | testImplementation 'junit:junit:4.12'
62 | implementation project(":preloading")
63 | embed project(":api")
64 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
65 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
66 | }
67 |
68 | task copyJniLibs(type: Copy) {
69 | from 'src/main/cpp/libs'
70 | into 'src/main/jniLibs/armeabi-v7a'
71 | }
72 | tasks.withType(JavaCompile) {
73 | compileTask -> compileTask.dependsOn(copyJniLibs)
74 | }
75 | clean.dependsOn 'cleanCopyJniLibs'
--------------------------------------------------------------------------------
/runtime/running/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/runtime/running/consumer-rules.pro
--------------------------------------------------------------------------------
/runtime/running/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/runtime/running/src/androidTest/java/com/mjtg/neutron/patcher/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.patcher;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 |
25 | assertEquals("com.mjtg.neutron.patcher.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/runtime/running/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/runtime/running/src/main/cpp/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.6)
2 |
3 | find_library( log-lib log )
4 |
5 |
6 | add_library(
7 | neutron
8 | SHARED
9 | dummy.cpp
10 | neutron.cy.cpp
11 | )
12 |
13 | target_link_libraries(
14 | neutron
15 | PRIVATE
16 | ${log-lib}
17 | ${CMAKE_SOURCE_DIR}/libs/libsubstrate.so
18 | )
--------------------------------------------------------------------------------
/runtime/running/src/main/cpp/dummy.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/runtime/running/src/main/cpp/dummy.cpp
--------------------------------------------------------------------------------
/runtime/running/src/main/cpp/libs/libsubstrate-dvm.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/runtime/running/src/main/cpp/libs/libsubstrate-dvm.so
--------------------------------------------------------------------------------
/runtime/running/src/main/cpp/libs/libsubstrate.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/runtime/running/src/main/cpp/libs/libsubstrate.so
--------------------------------------------------------------------------------
/runtime/running/src/main/cpp/neutron.cy.cpp:
--------------------------------------------------------------------------------
1 | #include "substrate.h"
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #define LOG_TAG "native-dev"
11 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
12 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
13 |
14 | //正在施工
15 |
16 | //algorithm
17 |
18 |
19 |
20 | char* JstringToChar(JNIEnv* env, jstring jstr) {
21 | if(jstr == NULL) {
22 | return NULL;
23 | }
24 | char* rtn = NULL;
25 | jclass clsstring = env->FindClass("java/lang/String");
26 | jstring strencode = env->NewStringUTF("utf-8");
27 | jmethodID mid = env->GetMethodID(clsstring, "getBytes",
28 | "(Ljava/lang/String;)[B");
29 | jbyteArray barr = (jbyteArray) env->CallObjectMethod(jstr, mid, strencode);
30 | jsize alen = env->GetArrayLength(barr);
31 | jbyte* ba = env->GetByteArrayElements(barr, JNI_FALSE);
32 | if (alen > 0) {
33 | rtn = (char*) malloc(alen + 1);
34 | memcpy(rtn, ba, alen);
35 | rtn[alen] = 0;
36 | }
37 | env->ReleaseByteArrayElements(barr, ba, 0);
38 | return rtn;
39 | }
40 |
41 |
42 | //METHODS INSTANCE
43 |
44 | void* mcClient;
45 | JNIEnv* env = NULL;
46 | jmethodID cid;
47 | jclass cls;
48 | jobject instance;
49 | void (*displayClientMessage)(void*,std::string const&);
50 |
51 | void* (*getGuiData)(void*);
52 |
53 | void (*minecraftClientInit)(void*);
54 | void onMinecraftClientInit(void*thiz){
55 | //todo
56 | minecraftClientInit(mcClient=thiz);
57 | }
58 | void (*useItem)(int32_t thisPtr, int32_t itemStackPtr, int32_t itemUseMethod, int8_t boo);
59 | void onUseItem(int32_t thisPtr, int32_t itemStackPtr, int32_t itemUseMethod, int8_t boo){
60 | LOGI("intercepted onUseItem!");
61 | (env)->CallVoidMethod(instance,cid,itemStackPtr, itemUseMethod,boo);
62 | useItem(thisPtr, itemStackPtr, itemUseMethod, boo);
63 | }
64 |
65 |
66 | void displayClientMessage_(JNIEnv *env, jclass clazz, jstring str){
67 | jboolean isCopy = false;
68 | const jchar* ch = env->GetStringChars(str, &isCopy);
69 | std::string str2((const char*)ch);
70 | displayClientMessage(getGuiData(mcClient), str2);
71 | env->ReleaseStringChars(str, ch);
72 | }
73 | /*
74 | void (*tick)(void*);
75 | void onTick(void*thiz){
76 | //todo
77 | tick(thiz);
78 | }
79 | void (*explode)(void*thiz);
80 | void onExplode(void*thiz){
81 | //todo
82 | }
83 | void (*blockModified)(void const& block1, void const& block2, void const& block3);
84 | void onBlockModified(void const&, void const&, void const&){
85 | //todo
86 | }
87 | void (*blockDestroyedByPlayer)(void & , std::string, void const&);
88 | void onBlockDestroyedByPlayer(void*){
89 | //todo
90 | }
91 | */
92 |
93 | //MS HOOK & D
94 |
95 | static JNINativeMethod getMethods[] = {
96 | {"displayClientMessage","(Ljava/lang/String;)V",(void*)displayClientMessage_}
97 | };
98 |
99 |
100 | static int registerNativeMethods(JNIEnv* env, const char* className, JNINativeMethod* getMethods, int methodsNum){
101 | jclass clazz;
102 | clazz = env->FindClass(className);
103 | if(clazz == NULL){
104 | return JNI_FALSE;
105 | }
106 | if(env->RegisterNatives(clazz,getMethods,methodsNum) < 0){
107 | return JNI_FALSE;
108 | }
109 | return JNI_TRUE;
110 | }
111 |
112 | static int registerNatives(JNIEnv* env){
113 | const char* className = "com/mjtg/neutron/api/hooks/NeutronHooks";
114 | return registerNativeMethods(env,className,getMethods, sizeof(getMethods)/ sizeof(getMethods[0]));
115 | }
116 |
117 | extern "C" JNIEXPORT jint JNICALL Java_com_mjtg_neutron_hook_NeutronHooking_performHooking(JNIEnv* env, jclass clazz, jlong addr) {
118 |
119 | __android_log_print(ANDROID_LOG_WARN, "neutron-test", "loading neutron .so!\n");
120 | assert(env != NULL);
121 | LOGI("registering natives...");
122 | if(!registerNatives(env)){
123 | return -1;
124 | }
125 |
126 | LOGI("registered!");
127 | LOGI("registering hook JNI!");
128 | cls = env->FindClass("com/mjtg/neutron/api/hooks/NeutronHooks");
129 | jfieldID id = env->GetStaticFieldID(cls, "INSTANCE", "Lcom/mjtg/neutron/api/hooks/NeutronHooks;");
130 | instance = env->GetStaticObjectField(cls, id);
131 | cid = env->GetMethodID(cls,"onUseItem", "(JJZ)V");
132 |
133 | LOGI("hooking!");
134 | void * image = (void*)addr;
135 | LOGI("minecraft image: %ld", (long)image);
136 | LOGI("onUseItemHook: %ld", (long)dlsym(image,"_ZN6Player7useItemER9ItemStack13ItemUseMethodb"));
137 | MSHookFunction(dlsym(image,"_ZN15MinecraftClient4initEv"),(void*)&onMinecraftClientInit,(void**)&minecraftClientInit);
138 | MSHookFunction(dlsym(image,"_ZN6Player7useItemER9ItemStack13ItemUseMethodb"),(void*)onUseItem,(void**)&useItem);
139 | LOGI("old use item: %ld", (long)useItem);
140 |
141 | /*
142 | MSHookFunction(dlsym(image,"_ZN13MinecraftGame6onTickEv"),(void*)&onTick,(void**)&tick);
143 | MSHookFunction(dlsym(image,"_ZN18BlockEventListener15onBlockModifiedERK8BlockPosRK5BlockS5_"),(void*)&onBlockModified,(void**)&blockModified);
144 | MSHookFunction(dlsym(image,"_ZN18BlockEventListener24onBlockDestroyedByPlayerER6PlayerSsRK8BlockPos"),(void*)&onBlockDestroyedByPlayer,(void**)&blockDestroyedByPlayer);
145 | MSHookFunction(dlsym(image,"_ZN9Explosion7explodeEv"),(void*)&onExplode,(void*)&explode);
146 | */
147 | getGuiData=(void*(*)(void*)) dlsym(image,"_ZN15MinecraftClient10getGuiDataEv");
148 | displayClientMessage= (void(*)(void*,std::string const&)) dlsym(image,"_ZN7GuiData20displayClientMessageERKSs");
149 |
150 | return 0;
151 | }
--------------------------------------------------------------------------------
/runtime/running/src/main/java/com/mjtg/neutron/hook/NeutronHooking.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.hook;
2 |
3 | import com.mjtg.neutron.runtime.hook.PESORegistry;
4 |
5 | import static java.lang.System.loadLibrary;
6 |
7 | public class NeutronHooking {
8 |
9 | private static native int performHooking(long PESOAddress);
10 |
11 | public static void performHooking() {
12 | loadLibrary("substrate");
13 | loadLibrary("neutron");
14 | performHooking(PESORegistry.PE_ADDRESS);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/runtime/running/src/main/java/com/mjtg/neutron/runtime/NeutronRuntime.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.runtime;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.util.Log;
6 |
7 | import com.mjtg.neutron.hook.NeutronHooking;
8 | import com.mjtg.neutron.runtime.loader.protocol.client.NeutronProtocolClient;
9 |
10 | import java.io.File;
11 |
12 | import static java.lang.System.loadLibrary;
13 |
14 | public class NeutronRuntime {
15 |
16 | private Context context;
17 |
18 | public void start(Activity activity, NeutronProtocolClient client) {
19 | context = activity;
20 | Log.i("Neutron", "starting neutron runtime...");
21 |
22 | Log.i("Neutron", "performing hooking...");
23 | NeutronHooking.performHooking();
24 |
25 | final File modDir = new File(activity.getCacheDir().toString() + File.separator + "mods");
26 | modDir.mkdir();
27 | Log.i("Neutron", "fetching mods...");
28 | client.downloadMods(modDir);
29 | Log.i("Neutron", "fetched " + modDir.list().length + " mods...");
30 | client.close();
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/runtime/running/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | patcher
3 |
4 |
--------------------------------------------------------------------------------
/runtime/running/src/main/res/xml/filepaths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/runtime/running/src/test/java/com/mjtg/neutron/patcher/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.patcher;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/runtime/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':preloading', ':running', ':api'
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':tools'
2 |
--------------------------------------------------------------------------------
/tools/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/tools/README.md:
--------------------------------------------------------------------------------
1 | # Tools for Neutron Modding
2 |
3 | ## Functionality
4 |
5 | the packer takes a minecraft APK,
6 | unpack it,
7 | put native libraries into libs/eabiarm-v7
8 | put classes files in jar into classes.dex
9 | and instrument MainActivity of Minecraft for Neutron Runtime startup
10 | then put it back.
11 |
12 | ## Usage
13 | java -jar packer-all.jar
14 | -rtjar %PATH TO JAR% (such as ./neutron_runtime.jar, NOTE: it must be a path! ./ part is needed!)
15 | -lib %PATH TO NATIVE LIBRARY% (such as ./libneutron.so)
16 | -apk %PATH TO MINECRAFT APK% (such as ./mc.apk)
17 |
18 | the result will be put in to mc-patched.apk in the current working directory
19 |
20 | Note: THIS IS USED TO INSTALL NEUTRON RUNTIME, so a runtime jar is always needed!
21 |
22 | Note: the outcome is a unsigned apk, you need to sign it to use it!
23 |
24 | # Packer for mincraft mod
--------------------------------------------------------------------------------
/tools/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'application'
2 | apply plugin: "com.github.johnrengelman.shadow"
3 |
4 | dependencies {
5 | implementation fileTree(dir: 'libs/dex2jar', include: ['*.jar'])
6 | implementation fileTree(dir: 'libs/javaassist', include: ['*.jar'])
7 | implementation("com.google.guava:guava:28.2-jre")
8 | implementation 'net.lingala.zip4j:zip4j:2.3.1'
9 | implementation 'commons-io:commons-io:2.6'
10 | implementation 'org.slf4j:slf4j-api:1.7.30'
11 | implementation "com.beust:jcommander:1.71"
12 | }
13 |
14 | mainClassName = 'com.mjtg.neutron.cli.Main'
15 |
16 | sourceCompatibility = "1.8"
17 | targetCompatibility = "1.8"
18 |
19 |
--------------------------------------------------------------------------------
/tools/libs/dex2jar/antlr-runtime-3.5.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/tools/libs/dex2jar/antlr-runtime-3.5.jar
--------------------------------------------------------------------------------
/tools/libs/dex2jar/asm-debug-all-4.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/tools/libs/dex2jar/asm-debug-all-4.1.jar
--------------------------------------------------------------------------------
/tools/libs/dex2jar/d2j-base-cmd-2.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/tools/libs/dex2jar/d2j-base-cmd-2.0.jar
--------------------------------------------------------------------------------
/tools/libs/dex2jar/d2j-jasmin-2.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/tools/libs/dex2jar/d2j-jasmin-2.0.jar
--------------------------------------------------------------------------------
/tools/libs/dex2jar/d2j-smali-2.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/tools/libs/dex2jar/d2j-smali-2.0.jar
--------------------------------------------------------------------------------
/tools/libs/dex2jar/dex-ir-2.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/tools/libs/dex2jar/dex-ir-2.0.jar
--------------------------------------------------------------------------------
/tools/libs/dex2jar/dex-reader-2.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/tools/libs/dex2jar/dex-reader-2.0.jar
--------------------------------------------------------------------------------
/tools/libs/dex2jar/dex-reader-api-2.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/tools/libs/dex2jar/dex-reader-api-2.0.jar
--------------------------------------------------------------------------------
/tools/libs/dex2jar/dex-tools-2.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/tools/libs/dex2jar/dex-tools-2.0.jar
--------------------------------------------------------------------------------
/tools/libs/dex2jar/dex-translator-2.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/tools/libs/dex2jar/dex-translator-2.0.jar
--------------------------------------------------------------------------------
/tools/libs/dex2jar/dex-writer-2.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/tools/libs/dex2jar/dex-writer-2.0.jar
--------------------------------------------------------------------------------
/tools/libs/dex2jar/dx-1.7.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/tools/libs/dex2jar/dx-1.7.jar
--------------------------------------------------------------------------------
/tools/libs/javaassist/javassist-3.26.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeutronLauncher-Dev/Neutron/49b205768f370de26a113cc430f5e5cc8c643e0a/tools/libs/javaassist/javassist-3.26.0.jar
--------------------------------------------------------------------------------
/tools/src/main/java/android/os/Bundle.java:
--------------------------------------------------------------------------------
1 | package android.os;
2 |
3 | /**
4 | * stub to cheat the javaassist
5 | */
6 | public class Bundle {
7 | }
8 |
--------------------------------------------------------------------------------
/tools/src/main/java/com/mjtg/neutron/cli/Main.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.cli;
2 |
3 | import com.beust.jcommander.JCommander;
4 | import com.beust.jcommander.Parameter;
5 | import com.mjtg.neutron.packer.JarPacker;
6 | import com.mjtg.neutron.patcher.ApkPatcher;
7 | import com.mjtg.neutron.patcher.PatchApkFromRuntimeAARCommand;
8 | import com.mjtg.neutron.patcher.PrepareRuntimeDirFromAAR;
9 | import com.mjtg.neutron.util.PathUtil;
10 |
11 | import java.io.File;
12 | import java.nio.file.Path;
13 | import java.nio.file.Paths;
14 | import java.util.ArrayList;
15 | import java.util.List;
16 | import java.util.stream.Collectors;
17 |
18 | public class Main {
19 |
20 | public static class PackRuntimeFromAARCommandArgs {
21 |
22 | @Parameter(names = "-aar", description = "path to the aar that is built by runtime/running")
23 | public String aarFile;
24 |
25 | }
26 |
27 | public static class PatchFromAARCommandArgs {
28 |
29 | @Parameter(names = "-aar", description = "path to the aar that is built by runtime/preloading")
30 | public String aarFile;
31 |
32 | @Parameter(names = "-apk", description = "path to the apk to patch")
33 | public String apkFile;
34 |
35 | }
36 |
37 | public static class PatcherCommandArgs {
38 |
39 | @Parameter(names = "-rtjar", description = "path to the jars that contains the java classes to put in")
40 | public List rtJars = new ArrayList<>();
41 |
42 | @Parameter(names = "-lib", description = "path to native library to put in")
43 | public List libraries = new ArrayList<>();
44 |
45 | @Parameter(names = "-apk", description = "path to the apk to patch")
46 | public String apkFile;
47 |
48 | }
49 |
50 | public static class PackerCommandArgs {
51 |
52 | @Parameter(names = "-jar", description = "path to the jars that needs to be packed into one jar with all java classes put into classes.dex")
53 | public List jars = new ArrayList<>();
54 |
55 | }
56 |
57 | public static void main(String[] args) {
58 | final PackRuntimeFromAARCommandArgs packRTArgs = new PackRuntimeFromAARCommandArgs();
59 | final PatchFromAARCommandArgs aarCommandArgs = new PatchFromAARCommandArgs();
60 | PatcherCommandArgs patchArgs = new PatcherCommandArgs();
61 | PackerCommandArgs packArgs = new PackerCommandArgs();
62 | JCommander cmder = JCommander.newBuilder()
63 | .addCommand("patch", patchArgs)
64 | .addCommand("pack", packArgs)
65 | .addCommand("patch-aar", aarCommandArgs)
66 | .addCommand("pack-runtime", packRTArgs)
67 | .build()
68 | ;
69 |
70 | cmder.parse(args);
71 |
72 | if(cmder.getParsedCommand().equals("patch")) {
73 | Path apkPath = Paths.get(new File(patchArgs.apkFile).getAbsolutePath());
74 | List rtJars = patchArgs.rtJars.stream().map(i -> Paths.get(new File(i).getAbsolutePath())).collect(Collectors.toList());
75 | List libs = patchArgs.libraries.stream().map(i -> Paths.get(new File(i).getAbsolutePath())).collect(Collectors.toList());
76 | ApkPatcher.start(apkPath, rtJars, libs);
77 | } else if(cmder.getParsedCommand().equals("pack")) {
78 | final Path tmpPath = Paths.get("./packerTemp");
79 | PathUtil.ensureDirExists(tmpPath);
80 | List libs = packArgs.jars.stream().map(i -> Paths.get(new File(i).getAbsolutePath())).collect(Collectors.toList());
81 | JarPacker.packJar(tmpPath, libs, Paths.get("./packed.jar"));
82 | System.out.println("packed to packed.jar");
83 | } else if(cmder.getParsedCommand().equals("patch-aar")) {
84 | final Path tmpPath = Paths.get("./aarTemp");
85 | PathUtil.ensureDirExists(tmpPath);
86 | PatchApkFromRuntimeAARCommand.run(
87 | Paths.get(new File(aarCommandArgs.apkFile).getAbsolutePath()),
88 | Paths.get(new File(aarCommandArgs.aarFile).getAbsolutePath()),
89 | tmpPath
90 | );
91 | } else if(cmder.getParsedCommand().equals("pack-runtime")) {
92 | final Path aarTmpPath = Paths.get("./aarTemp2");
93 | PathUtil.ensureDirExists(aarTmpPath);
94 | final Path runtimePath = Paths.get("./runtime");
95 | runtimePath.toFile().mkdir();
96 | PrepareRuntimeDirFromAAR.run(
97 | runtimePath,
98 | Paths.get(new File(packRTArgs.aarFile).getAbsolutePath()),
99 | aarTmpPath
100 | );
101 | }
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/tools/src/main/java/com/mjtg/neutron/converter/DexJarConverter.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.converter;
2 |
3 | import com.googlecode.d2j.dex.Dex2jar;
4 | import com.googlecode.dex2jar.tools.BaksmaliBaseDexExceptionHandler;
5 |
6 | import java.io.IOException;
7 | import java.lang.reflect.Method;
8 | import java.nio.file.Path;
9 | import java.util.ArrayList;
10 | import java.util.Arrays;
11 | import java.util.List;
12 |
13 | public class DexJarConverter {
14 |
15 | public static void dex2jar(Path dexFile, Path jarFilePath) {
16 | try {
17 | Dex2jar.from(dexFile.toFile())
18 | .withExceptionHandler(new BaksmaliBaseDexExceptionHandler())
19 | .reUseReg(false)
20 | .topoLogicalSort()
21 | .skipDebug(true)
22 | .optimizeSynchronized(false)
23 | .printIR(false)
24 | .noCode(false)
25 | .to(jarFilePath)
26 | ;
27 | } catch (IOException e) {
28 | throw new RuntimeException(e);
29 | }
30 | }
31 |
32 | public static void jar2dex(Path jarFile, Path dexFilePath) {
33 | try {
34 | Class> c = Class.forName("com.android.dx.command.Main");
35 | Method m = c.getMethod("main", String[].class);
36 |
37 | List ps = new ArrayList<>(Arrays.asList(
38 | "--dex", "--no-strict",
39 | "--output=" + dexFilePath.toAbsolutePath().toString(),
40 | jarFile.toAbsolutePath().toString()
41 | ));
42 | m.invoke(null, new Object[] { ps.toArray(new String[0]) });
43 | } catch (Exception e) {
44 | throw new RuntimeException(e);
45 | }
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/tools/src/main/java/com/mjtg/neutron/packer/JarPacker.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.packer;
2 |
3 | import com.mjtg.neutron.converter.DexJarConverter;
4 | import com.mjtg.neutron.util.PathUtil;
5 | import com.mjtg.neutron.util.ZipUtil;
6 |
7 | import net.lingala.zip4j.ZipFile;
8 |
9 | import org.apache.commons.io.FileUtils;
10 |
11 | import java.io.IOException;
12 | import java.nio.file.Files;
13 | import java.nio.file.Path;
14 | import java.time.Instant;
15 | import java.util.List;
16 |
17 |
18 | public class JarPacker {
19 |
20 | public static void packJar(Path tmpDir, List jarsToPack, Path resultJar) {
21 | Path unpackDir = tmpDir.resolve("unpacked");
22 | final Path dexPath = tmpDir.resolve("classes.dex");
23 |
24 | PathUtil.ensureDirExists(tmpDir);
25 | PathUtil.ensureDirExists(unpackDir);
26 |
27 | unpackJars(jarsToPack, unpackDir);
28 |
29 | packClassesToDex(tmpDir, dexPath);
30 |
31 | repackJarWithDexInstead(unpackDir, dexPath, resultJar);
32 | }
33 |
34 | private static void repackJarWithDexInstead(Path unpackDir, Path dexPath, Path resultJar) {
35 | System.out.println("repacking .dex and other than .class into .jar");
36 | try {
37 | FileUtils.copyFile(dexPath.toFile(), unpackDir.resolve(dexPath.getFileName()).toFile());
38 | ZipUtil.zipDirectory(
39 | unpackDir, resultJar.toAbsolutePath(),
40 | file->!file.getFileName().toString().endsWith(".class")
41 | );
42 | } catch (IOException e) {
43 | throw new RuntimeException(e);
44 | }
45 | }
46 |
47 | private static void packClassesToDex(Path tmpDir, Path dexPath) {
48 | System.out.println("packing classes into dex");
49 | Path tmpJar = null;
50 | try {
51 | try {
52 | final Path d2jDir = Files.createTempDirectory("d2j");
53 | tmpJar = d2jDir.resolve("d2j-"+ Instant.now().getEpochSecond()+".jar");
54 | ZipUtil.zipDirectory(
55 | tmpDir, tmpJar.toAbsolutePath(),
56 | file-> file.getFileName().toString().endsWith(".class")
57 | );
58 |
59 | DexJarConverter.jar2dex(tmpJar, dexPath);
60 |
61 | } finally {
62 | if (tmpJar != null) {
63 | Files.deleteIfExists(tmpJar);
64 | }
65 | }
66 | } catch (Exception e) {
67 | throw new RuntimeException(e);
68 | }
69 | }
70 |
71 | private static void unpackJars(List jarsToPack, Path unpackDir) {
72 | System.out.println("unpacking jars");
73 | for (Path jar : jarsToPack) {
74 | try {
75 | new ZipFile(jar.toFile()).extractAll(unpackDir.toAbsolutePath().toString());
76 | } catch (IOException e) {
77 | throw new RuntimeException(e);
78 | }
79 | }
80 | }
81 |
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/tools/src/main/java/com/mjtg/neutron/patcher/ApkPatcher.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.patcher;
2 |
3 |
4 | import com.google.common.io.Files;
5 | import com.mjtg.neutron.util.ZipUtil;
6 |
7 | import java.io.IOException;
8 | import java.nio.file.Path;
9 | import java.util.List;
10 | import java.util.Locale;
11 |
12 | public class ApkPatcher {
13 |
14 | public static void start(Path apkPath, List runtimeJarsPath, List librariesToPatch) {
15 | System.out.println("Performing Minecraft APK Injection");
16 | System.out.println(String.format(Locale.US, "have %d native libraries to inject, %d jars to inject", librariesToPatch.size(), runtimeJarsPath.size()));
17 |
18 | //准备临时dex临时文件
19 | Path dexTmpPath = apkPath.getParent().resolve("dexTemp");
20 | dexTmpPath.toFile().mkdir();
21 |
22 | Path unpackedDir = unpackApk(apkPath);
23 |
24 | DexPatcher.transformDex(unpackedDir, dexTmpPath, runtimeJarsPath);
25 |
26 | injectLibraries(
27 | unpackedDir.resolve("lib").resolve("armeabi-v7a"),
28 | librariesToPatch
29 | );
30 |
31 | repackApk(
32 | unpackedDir,
33 | apkPath.getParent().resolve("mc-patched.apk")
34 | );
35 |
36 | System.out.println("Patched successfully, result saved to mc-patched.apk");
37 | }
38 |
39 | private static Path unpackApk(Path apk) {
40 | System.out.println("Unpacking Apk...");
41 | Path unpackedDir = apk.getParent().resolve("temp");
42 | com.mjtg.neutron.util.ZipUtil.unzipDirectory(apk, unpackedDir);
43 | return unpackedDir;
44 | }
45 |
46 | private static void injectLibraries(Path libDir, List toInjectLibs) {
47 | System.out.println("Injecting libs...");
48 | for (Path p : toInjectLibs) {
49 | System.out.println("injecting "+p.getFileName());
50 | copy(p, libDir.resolve(p.getFileName()));
51 | }
52 | }
53 |
54 | private static void repackApk(Path unpackedDir, Path newApk) {
55 | System.out.println("Repacking Apk...");
56 | ZipUtil.zipDirectory(unpackedDir, newApk);
57 | }
58 |
59 | private static void copy(Path from,Path to) {
60 | try {
61 | Files.copy(from.toFile(), to.toFile());
62 | } catch (IOException e) {
63 | throw new RuntimeException(e);
64 | }
65 | }
66 |
67 | }
--------------------------------------------------------------------------------
/tools/src/main/java/com/mjtg/neutron/patcher/DexPatcher.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.patcher;
2 |
3 | import com.googlecode.d2j.dex.Dex2jar;
4 | import com.googlecode.dex2jar.tools.BaksmaliBaseDexExceptionHandler;
5 | import com.mjtg.neutron.converter.DexJarConverter;
6 | import com.mjtg.neutron.util.ZipUtil;
7 |
8 | import java.io.DataOutputStream;
9 | import java.io.FileOutputStream;
10 | import java.io.IOException;
11 | import java.nio.file.Files;
12 | import java.nio.file.Path;
13 | import java.nio.file.Paths;
14 | import java.time.Instant;
15 | import java.util.List;
16 |
17 |
18 | import javassist.ClassPool;
19 | import javassist.CtClass;
20 | import javassist.CtConstructor;
21 | import javassist.CtField;
22 | import javassist.CtMethod;
23 |
24 |
25 | public class DexPatcher {
26 |
27 | /**
28 | * perform transformation on dex, inject the neutron runtime
29 | * @param unpackedDir the directory containing the unpacked apk
30 | * @param dexTmpDir the directory for temp use by dex transformer, must exist before calling
31 | * @param runtimeJar the path to the jar that contains the neutron runtime
32 | */
33 | public static void transformDex(Path unpackedDir, Path dexTmpDir, List runtimeJar) {
34 | System.out.println("Injecting dex...");
35 |
36 | Path dexPath = unpackedDir.resolve("classes.dex");
37 |
38 | //build the tmp directory for exploded values
39 | Path unpackedDexDir = dexTmpDir.resolve("unpacked");
40 | unpackedDexDir.toFile().mkdir();
41 |
42 | performDex2Jar(unpackedDexDir, dexPath);
43 |
44 | insertJarClasses(unpackedDexDir, runtimeJar);
45 |
46 | instrumentMainActivity(unpackedDexDir);
47 |
48 | dexPath.toFile().delete();
49 | performJar2Dex(unpackedDexDir, dexPath);
50 | }
51 |
52 | private static void instrumentMainActivity(Path unpackedDexDir) {
53 | System.out.println("Instrumenting MainActivity...");
54 | try {
55 | ClassPool pool = ClassPool.getDefault();
56 | pool.insertClassPath(unpackedDexDir.toString());
57 |
58 | CtClass clazz = pool.get("com.mojang.minecraftpe.MainActivity");
59 |
60 | clazz.addField(CtField.make( "public com.mjtg.neutron.runtime.mixin.MCMainActivityMixin $neutron_mixin;", clazz));
61 |
62 | CtConstructor ctor = clazz.getConstructor("()V");
63 | ctor.insertBefore("$0.$neutron_mixin = new com.mjtg.neutron.runtime.mixin.MCMainActivityMixin();");
64 |
65 | CtMethod onCreate = clazz.getMethod("onCreate", "(Landroid/os/Bundle;)V");
66 | onCreate.insertBefore("$0.$neutron_mixin.onCreate((Object)$0);");
67 |
68 | Path clazzFile = unpackedDexDir.resolve(Paths.get("com", "mojang", "minecraftpe").resolve("MainActivity.class"));
69 | try(DataOutputStream fos = new DataOutputStream(new FileOutputStream(clazzFile.toAbsolutePath().toString()))) {
70 | clazz.toBytecode(fos);
71 | }
72 | } catch(Exception e){
73 | throw new RuntimeException(e);
74 | }
75 | }
76 |
77 | private static void insertJarClasses(Path unpackedDexDir, List jars) {
78 | System.out.println("Inserting java classes in jar");
79 | for (Path jar : jars) {
80 | System.out.println("inserting "+jar.getFileName());
81 | ZipUtil.unzipDirectory(jar, unpackedDexDir);
82 | }
83 | }
84 |
85 | private static void performDex2Jar(Path resultDir, Path dexPath) {
86 | System.out.println("Performing Dex2Jar...");
87 | try {
88 | Dex2jar.from(dexPath.toFile())
89 | .withExceptionHandler(new BaksmaliBaseDexExceptionHandler())
90 | .reUseReg(false)
91 | .topoLogicalSort()
92 | .skipDebug(true)
93 | .optimizeSynchronized(false)
94 | .printIR(false)
95 | .noCode(false)
96 | .to(resultDir)
97 | ;
98 | } catch (IOException e) {
99 | throw new RuntimeException(e);
100 | }
101 | }
102 |
103 | private static void performJar2Dex(Path sourceDir, Path dexPath) {
104 | System.out.println("Performing Jar2Dex...");
105 | Path tmp = null;
106 | try {
107 | try {
108 | final Path d2jDir = Files.createTempDirectory("d2j");
109 | Path realJar = d2jDir.resolve("d2j-"+ Instant.now().getEpochSecond()+".jar");
110 | tmp = realJar;
111 | ZipUtil.zipDirectory(sourceDir, realJar.toAbsolutePath());
112 |
113 | DexJarConverter.jar2dex(realJar, dexPath);
114 | } finally {
115 | if (tmp != null) {
116 | Files.deleteIfExists(tmp);
117 | }
118 | }
119 | } catch (Exception e) {
120 | throw new RuntimeException(e);
121 | }
122 | }
123 |
124 | }
125 |
--------------------------------------------------------------------------------
/tools/src/main/java/com/mjtg/neutron/patcher/PatchApkFromRuntimeAARCommand.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.patcher;
2 |
3 | import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
4 |
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 |
8 | import static com.mjtg.neutron.util.ZipUtil.unzipFiles;
9 | import java.nio.file.Path;
10 | import java.util.List;
11 | import java.util.Map;
12 | import java.util.stream.Collectors;
13 |
14 | public class PatchApkFromRuntimeAARCommand {
15 |
16 | public static void run(Path apkPath, Path aarPath, Path aarTemp) {
17 | List paths = unzipFiles(aarPath, aarTemp, p->{
18 | return p.startsWith("/libs")
19 | || p.getFileName().toString().endsWith(".so")
20 | || p.getFileName().toString().equals("classes.jar")
21 | ;
22 | });
23 |
24 | final Map> suffixes = paths.stream()
25 | .collect(Collectors.groupingBy(k -> {
26 | final String filename = k.getFileName().toString();
27 | return filename.substring(filename.lastIndexOf('.')+1);
28 | }));
29 |
30 | System.out.println("scanned aar file:"+aarPath.toString());
31 | System.out.println("got "+suffixes.get("so").size()+" .so");
32 | suffixes.get("so").forEach(System.out::println);
33 | System.out.println("got "+suffixes.get("jar").size()+" .jar");
34 | suffixes.get("jar").forEach(System.out::println);
35 | System.out.println("patching...");
36 | ApkPatcher.start(apkPath, suffixes.get("jar"), suffixes.get("so"));
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/tools/src/main/java/com/mjtg/neutron/patcher/PrepareRuntimeDirFromAAR.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.patcher;
2 |
3 | import com.mjtg.neutron.packer.JarPacker;
4 |
5 | import java.io.IOException;
6 | import java.nio.file.Files;
7 | import java.nio.file.Path;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.stream.Collectors;
11 |
12 | import static com.mjtg.neutron.util.ZipUtil.unzipFiles;
13 |
14 | public class PrepareRuntimeDirFromAAR {
15 |
16 | public static void run(Path destDirPath, Path aarPath, Path aarTemp) {
17 | List paths = unzipFiles(aarPath, aarTemp, p->{
18 | return p.startsWith("/libs")
19 | || p.getFileName().toString().endsWith(".so")
20 | || p.getFileName().toString().equals("classes.jar")
21 | ;
22 | });
23 |
24 | final Map> suffixes = paths.stream()
25 | .collect(Collectors.groupingBy(k -> {
26 | final String filename = k.getFileName().toString();
27 | return filename.substring(filename.lastIndexOf('.')+1);
28 | }));
29 |
30 | System.out.println("scanned aar file:"+aarPath.toString());
31 | System.out.println("got "+suffixes.get("so").size()+" .so");
32 | suffixes.get("so").forEach(System.out::println);
33 | System.out.println("got "+suffixes.get("jar").size()+" .jar");
34 | suffixes.get("jar").forEach(System.out::println);
35 |
36 | System.out.println("packing jars");
37 | final Path packerTmp = aarTemp.resolve("packTmp");
38 | packerTmp.toFile().mkdir();
39 | final Path jarsPath = destDirPath.resolve("jars");
40 | jarsPath.toFile().mkdir();
41 | JarPacker.packJar(packerTmp, suffixes.get("jar"), jarsPath.resolve("packed.jar"));
42 |
43 | System.out.println("copying so");
44 | final Path libsPath = destDirPath.resolve("libs");
45 | libsPath.toFile().mkdir();
46 | for (Path path : suffixes.get("so")) {
47 | try {
48 | Files.copy(path, libsPath.resolve(path.getFileName()));
49 | } catch (IOException e) {
50 | throw new RuntimeException(e);
51 | }
52 | }
53 | }
54 |
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/tools/src/main/java/com/mjtg/neutron/util/PathUtil.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.util;
2 |
3 | import java.nio.file.Path;
4 |
5 | public class PathUtil {
6 |
7 | public static void ensureDirExists(Path path) {
8 | path = path.toAbsolutePath();
9 | if(!path.toFile().exists()) {
10 | if (!path.toFile().mkdirs()) {
11 | throw new RuntimeException("unable to make directory for :" + path.toString());
12 | }
13 | }
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/tools/src/main/java/com/mjtg/neutron/util/ZipUtil.java:
--------------------------------------------------------------------------------
1 | package com.mjtg.neutron.util;
2 |
3 | import net.lingala.zip4j.ZipFile;
4 | import net.lingala.zip4j.exception.ZipException;
5 | import net.lingala.zip4j.io.outputstream.ZipOutputStream;
6 | import net.lingala.zip4j.model.ZipParameters;
7 |
8 | import java.io.File;
9 | import java.nio.file.CopyOption;
10 | import java.nio.file.Paths;
11 | import java.nio.file.StandardCopyOption;
12 | import java.util.List;
13 | import java.io.FileOutputStream;
14 | import java.io.IOException;
15 | import java.nio.file.FileSystem;
16 | import java.nio.file.FileSystems;
17 | import java.nio.file.FileVisitResult;
18 | import java.nio.file.Files;
19 | import java.nio.file.Path;
20 | import java.nio.file.SimpleFileVisitor;
21 | import java.nio.file.attribute.BasicFileAttributes;
22 | import java.util.ArrayList;
23 | import java.util.function.Predicate;
24 |
25 | public class ZipUtil {
26 |
27 | public static List unzipFiles(Path zipPath, Path intoDirectoryPath, Predicate toUnzip) {
28 | ArrayList paths = new ArrayList<>();
29 | try (FileSystem zipFileSystem = FileSystems.newFileSystem(zipPath, null)) {
30 | final Path root = zipFileSystem.getPath("/");
31 | //walk the zip file tree and copy files to the destination
32 | Files.walkFileTree(root, new SimpleFileVisitor(){
33 | @Override
34 | public FileVisitResult visitFile(Path o, BasicFileAttributes basicFileAttributes) throws IOException {
35 | if(!toUnzip.test(o)) {
36 | //if reject, ignore
37 | return FileVisitResult.CONTINUE;
38 | } else {
39 | String cleanedPath = o.toString().substring(1).replace('\\', File.pathSeparatorChar);
40 | Path path = intoDirectoryPath.resolve(cleanedPath).normalize().toAbsolutePath();
41 | paths.add(path);
42 | System.out.println(path);
43 | final File file = path.toFile();
44 | file.getParentFile().mkdirs();
45 | Files.copy(o, path, StandardCopyOption.REPLACE_EXISTING);
46 | return FileVisitResult.CONTINUE;
47 | }
48 | }
49 | });
50 | } catch (IOException e) {
51 | throw new RuntimeException(e);
52 | }
53 | return paths;
54 | }
55 |
56 | public static void unzipDirectory(Path zipPath, Path intoDirectoryPath) {
57 | try {
58 | new ZipFile(zipPath.toAbsolutePath().toString()).extractAll(intoDirectoryPath.toAbsolutePath().toString());
59 | } catch (ZipException e) {
60 | throw new RuntimeException(e);
61 | }
62 | }
63 |
64 | public static void zipDirectory(Path directoryPath, Path zipPath) {
65 | zipDirectory(directoryPath, zipPath, p->true);
66 | }
67 |
68 | public static void zipDirectory(Path directoryPath, Path zipPath, Predicate toZipInto) {
69 | try (FileOutputStream fis = new FileOutputStream(zipPath.toAbsolutePath().toString())){
70 | try(ZipOutputStream zos = new ZipOutputStream(fis)) {
71 | Files.walkFileTree(directoryPath, new SimpleFileVisitor() {
72 | public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
73 | if(!toZipInto.test(file)) {
74 | //if reject, ignore
75 | return FileVisitResult.CONTINUE;
76 | }
77 |
78 | ZipParameters zipParameters = new ZipParameters();
79 | String fileNameWithPath = directoryPath.relativize(file).toString();
80 | //bug: you need to have \ as pathSeparator to please android!
81 | if(File.separatorChar != '/') {
82 | if(File.separatorChar == '\\') {
83 | fileNameWithPath = fileNameWithPath.replace('\\','/');
84 | } else {
85 | //we dont know how to fix it for you, so we fail to tell you about it
86 | throw new AssertionError("error in translating path separator, please add it here!");
87 | }
88 | }
89 | zipParameters.setFileNameInZip(fileNameWithPath);
90 | zos.putNextEntry(zipParameters);
91 | Files.copy(file, zos);
92 | zos.closeEntry();
93 | return FileVisitResult.CONTINUE;
94 | }
95 | });
96 | }
97 | } catch (IOException e) {
98 | throw new RuntimeException(e);
99 | }
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------