Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Jul 21, 2023
1 parent e98cd52 commit b9c1d53
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 41 deletions.
94 changes: 94 additions & 0 deletions Android/app/src/main/java/com/dergoogler/core/NativeSuFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@
import com.dergoogler.mmrl.MainActivity;
import com.topjohnwu.superuser.io.SuFile;
import com.topjohnwu.superuser.io.SuFileInputStream;
import com.topjohnwu.superuser.io.SuFileOutputStream;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class NativeSuFile {
private final MainActivity ctx;
Expand Down Expand Up @@ -63,4 +77,84 @@ public boolean existFile(String path) {
return new SuFile(path).exists();
}


@JavascriptInterface
public static boolean downloadFile(final String url, final String savePath, final String saveName) {
try {
File savefilepath = new SuFile(savePath);
if (!savefilepath.exists()) {
savefilepath.mkdirs();
}
File savefile = new SuFile(savePath + saveName);
if (savefile.exists()) {
savefile.delete();
}
savefile.createNewFile();

URL u = new URL(url);
URLConnection conn = u.openConnection();
int contentLength = conn.getContentLength();

DataInputStream stream = new DataInputStream(u.openStream());

byte[] buffer = new byte[contentLength];
stream.readFully(buffer);
stream.close();

DataOutputStream fos = new DataOutputStream(SuFileOutputStream.open(
savePath + saveName, true));
fos.write(buffer);
fos.flush();
fos.close();
return true;
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}

private void dirChecker(String filePath) {
File file = new File(filePath);
if (!file.exists()) {
file.mkdirs();
} else {

}
}

@JavascriptInterface
public boolean unzip(String _zipFile, String _targetLocation) {
//create target location folder if not exist
dirChecker(_targetLocation);

try {
FileInputStream fin = new FileInputStream(_zipFile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {

//create dir if required while unzipping
if (ze.isDirectory()) {
dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(_targetLocation + ze.getName());

Check failure

Code scanning / CodeQL

Arbitrary file access during archive extraction ("Zip Slip") High

Unsanitized archive entry, which may contain '..', is used in a
file system operation
.
for (int c = zin.read(); c != -1; c = zin.read()) {
fout.write(c);
}

zin.closeEntry();
fout.close();
}

}
zin.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
27 changes: 23 additions & 4 deletions Website/src/activitys/DescriptonActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useTheme } from "@Hooks/useTheme";
import { StyledIconButtonWithText } from "@Components/StyledIconButton";
import { useModuleOptions } from "@Hooks/useModuleOptions";
import { useSupportIconForUrl } from "@Hooks/useSupportIconForUrl";
import TerminalActivity from "./TerminalActivity";

type Extra = {
title: string;
Expand Down Expand Up @@ -257,13 +258,31 @@ function DescriptonActivity() {
onClick={() => {
os.open(zip_url);
}}
endIcon={<FileDownloadIcon />}
startIcon={<FileDownloadIcon />}
>
{strings.download}
</Button>
{/* <Button fullWidth variant="contained" disableElevation onClick={() => {}}>
{strings.install}
</Button> */}
{/* {os.isAndroid && (
<Button
fullWidth
variant="contained"
disableElevation
onClick={() => {
context.pushPage({
component: TerminalActivity,
props: {
key: "explore_install",
extra: {
exploreInstall: true,
path: zip_url,
},
},
});
}}
>
{strings.install}
</Button>
)} */}
</Stack>
)}
</div>
Expand Down
73 changes: 63 additions & 10 deletions Website/src/activitys/TerminalActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,65 @@ const TerminalActivity = () => {

const ref = React.useRef<HTMLDivElement>(null);

const addLine = (line: string) => {
setLines((lines) => [...lines, line]);
};

const dl = (url: string, savePath: string, saveName: string) => {
try {
return window.__sufile__.downloadFile(url, savePath, saveName);
} catch {
return false;
}
};

const unzip = (file: string, target: string) => {
try {
return window.__sufile__.unzip(file, target);
} catch {
return false;
}
};

const install = () => {
// @ts-ignore
Terminal.exec(
`magisk --install-module "${extra.path}"`,
(r) => {
setLines((prev) => [...prev, r]);
},
(code) => {
if (code) {
const { exploreInstall, path } = extra;

const url = new URL(path).pathname.split("/");
const getFileName = url[2] + "-" + url[4];

if (exploreInstall) {
addLine("- Download module");
const success = dl(path, "/sdcard/MMRL/", getFileName);

if (success) {
addLine("- Unzipping file");
const unzippSuccess = unzip(`/sdcard/MMRL/${getFileName}`, "/sdcard/MMRL/unzipped/");

if (unzippSuccess) {
addLine("\x1B[32m- Success\x1b[0m");
setActive(false);
} else {
setActive(false);
addLine("\x1B[31m! Unzipping failed\x1b[0m");
}
} else {
setActive(false);
addLine("\x1B[31m! Download failed\x1b[0m");
}
);
} else {
// @ts-ignore
Terminal.exec(
`magisk --install-module "${path}"`,
(r) => {
addLine(r);
},
(code) => {
if (code) {
setActive(false);
}
}
);
}
};

const renderToolbar = () => {
Expand All @@ -51,7 +97,14 @@ const TerminalActivity = () => {
};

return (
<Page onShow={install} modifier="noshadow" renderToolbar={renderToolbar}>
<Page
onShow={install}
modifier="noshadow"
renderToolbar={renderToolbar}
backgroundStyle={{
backgroundColor: "black",
}}
>
<div
ref={ref}
style={{
Expand Down
32 changes: 14 additions & 18 deletions Website/src/components/dapi/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,24 @@ const Video = (props: VideoProps) => {
switch (type) {
case "video/youtube":
return (
<>
<iframe
className="Video--Custom card"
style={util.typeCheck(style, Style)}
src={`https://www.youtube.com/embed/${src.replace("https://www.youtube.com/watch?v=", "")}`}
></iframe>
</>
<iframe
className="Video--Custom card"
style={util.typeCheck(style, Style)}
src={`https://www.youtube.com/embed/${src.replace("https://www.youtube.com/watch?v=", "")}`}
></iframe>
);

default:
return (
<>
<video
className="Video--Custom card"
style={util.typeCheck(style, Style)}
controls={util.typeCheck(controls, true)}
poster={poster}
>
<source src={src} type={util.typeCheck(type, "video/mp4")} />
{util.typeCheck(noSupportText, "Your browser does not support HTML video.")}
</video>
</>
<video
className="Video--Custom card"
style={util.typeCheck(style, Style)}
controls={util.typeCheck(controls, true)}
poster={poster}
>
<source src={src} type={util.typeCheck(type, "video/mp4")} />
{util.typeCheck(noSupportText, "Your browser does not support HTML video.")}
</video>
);
}
};
Expand Down
3 changes: 2 additions & 1 deletion Website/src/components/onsenui/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface NativeUIColors {

interface HTMLPage {
contentStyle?: React.CSSProperties;
backgroundStyle?: React.CSSProperties;
modifier?: string;
renderModal?: RenderFunction;
renderToolbar?: RenderFunction;
Expand Down Expand Up @@ -52,7 +53,7 @@ const _Page = React.forwardRef<HTMLElement, HTMLPage>((props, ref) => {
return (
<HTMLPage {...rest} ref={ref}>
{renderToolbar && renderToolbar(ref)}
<div className="page__background"> </div>
<div className="page__background" style={props.backgroundStyle}></div>
<div className="page__content" style={contentStyle}>
{children}
</div>
Expand Down
39 changes: 39 additions & 0 deletions Website/src/custom-elements/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { BuildConfig } from "@Native/BuildConfig";

export class MMRLApp extends HTMLElement {
public constructor() {
super();
this.initConfigStats([
{
key: "package",
value: BuildConfig.APPLICATION_ID,
},
{
key: "version-name",
value: BuildConfig.VERSION_NAME,
},
{
key: "version-code",
value: BuildConfig.VERSION_CODE,
},
{
key: "debug",
value: BuildConfig.DEBUG,
},
{
key: "build-type",
value: BuildConfig.BUILD_TYPE,
},
]);
}

private initConfigStats(data: any) {
return data.map((element: { key: string; value: any }) => {
return this.set(element.key, element.value);
});
}

private set(qualifiedName: string, value: string) {
this.setAttribute(qualifiedName, value);
}
}
11 changes: 8 additions & 3 deletions Website/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from "react";
import ons from "onsenui";
import "onsenui/css/onsenui.css";
import "@Styles/default.scss";
import { CssBaseline } from "@mui/material";
import { LightTheme } from "@Styles/light_theme";
import { ConfirmProvider } from "material-ui-confirm";
Expand All @@ -12,13 +10,20 @@ import { MainActivity } from "@Activitys/MainActivity";
import { RepoProvider } from "@Hooks/useRepos";
import { SettingsProvider } from "@Hooks/useSettings";

import { MMRLApp } from "./custom-elements/app";

import "onsenui/css/onsenui.css";
import "@Styles/default.scss";

ons.platform.select("android");

ons.ready(() => {
if (window.__nativeStorage__) {
window.__nativeStorage__.defineName("localstorage");
}

customElements.define("mmrl-app", MMRLApp);

render(
<React.StrictMode>
<SettingsProvider>
Expand All @@ -37,6 +42,6 @@ ons.ready(() => {
</StringProvider>
</SettingsProvider>
</React.StrictMode>,
"app"
"mmrl-app"
);
});
2 changes: 1 addition & 1 deletion Website/src/native/BuildConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class BuildConfigClass extends Native {
if (this.isAndroid) {
return this.getInterface.DEBUG;
} else {
return NODE_ENV === "development";
return __webpack__mode__ === "development";
}
}

Expand Down
2 changes: 1 addition & 1 deletion Website/src/typings/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ declare global {
LENGTH_SHORT: "short";
};

const NODE_ENV: string | undefined;
const __webpack__mode__: "production" | "development";

type PushPropsExtra<E = {}> = E & {
param?: {
Expand Down
Loading

0 comments on commit b9c1d53

Please sign in to comment.