Skip to content

Commit

Permalink
调整部分代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Vera-Firefly committed Nov 7, 2024
1 parent a3cfe02 commit 6caa88c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 40 deletions.
18 changes: 1 addition & 17 deletions app_pojavlauncher/src/main/java/com/firefly/utils/MesaUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Set<String> getMesaList() {

public boolean saveMesaVersion(Context context, Uri fileUri, String folderName) {
try (InputStream inputStream = context.getContentResolver().openInputStream(fileUri)) {
if (inputStream == null || !isELFFile(inputStream)) {
if (inputStream == null || !PGWTools.isELFFile(inputStream)) {
return false;
}

Expand Down Expand Up @@ -156,22 +156,6 @@ public static class MesaObj {
public String x86_64;
}

private boolean isELFFile(InputStream inputStream) {
try {
byte[] elfMagic = new byte[4];
int bytesRead = inputStream.read(elfMagic);

return bytesRead == 4 &&
elfMagic[0] == 0x7F &&
elfMagic[1] == 'E' &&
elfMagic[2] == 'L' &&
elfMagic[3] == 'F';
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

public boolean deleteMesaLib(String version) {
File libDir = new File(mesaDir, version);
if (libDir.exists()) {
Expand Down
19 changes: 19 additions & 0 deletions app_pojavlauncher/src/main/java/com/firefly/utils/PGWTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import android.opengl.GLES20;
import android.util.Log;

import java.io.InputStream;
import java.io.IOException;

public class PGWTools {

public static boolean isAdrenoGPU() {
Expand Down Expand Up @@ -68,4 +71,20 @@ public static boolean isAdrenoGPU() {
return isAdreno;
}

public static boolean isELFFile(InputStream inputStream) {
try {
byte[] elfMagic = new byte[4];
int bytesRead = inputStream.read(elfMagic);

return bytesRead == 4 &&
elfMagic[0] == 0x7F &&
elfMagic[1] == 'E' &&
elfMagic[2] == 'L' &&
elfMagic[3] == 'F';
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

}
25 changes: 2 additions & 23 deletions app_pojavlauncher/src/main/java/com/firefly/utils/TurnipUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public String getTurnipDriver(String version) {
*/
public boolean saveTurnipDriver(Context context, Uri fileUri, String folderName) {
try (InputStream inputStream = context.getContentResolver().openInputStream(fileUri)) {
if (inputStream == null || !isELFFile(inputStream)) {
if (inputStream == null || !PGWTools.isELFFile(inputStream)) {
return false;
}

inputStream.close(); // Close an open validation file stream
InputStream newInputStream = context.getContentResolver().openInputStream(fileUri);

Expand All @@ -79,27 +79,6 @@ public boolean saveTurnipDriver(Context context, Uri fileUri, String folderName)
}
}

/** Why is there a verification here?
* MovTery: 没有,哪怕是不是被小白用的,你都得检查用户导入了什么东西,检查它能不能用才是关键
* Vera-Firefly: 总不能真有唐完的人不会用硬用它吧?
* 最终我检查了一下代码…所以…这个是遗漏的验证…
*/
private boolean isELFFile(InputStream inputStream) {
try {
byte[] elfMagic = new byte[4];
int bytesRead = inputStream.read(elfMagic);

return bytesRead == 4 &&
elfMagic[0] == 0x7F &&
elfMagic[1] == 'E' &&
elfMagic[2] == 'L' &&
elfMagic[3] == 'F';
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

public boolean deleteTurnipDriver(String version) {
File libDir = new File(turnipDir, version);
if (libDir.exists()) {
Expand Down

0 comments on commit 6caa88c

Please sign in to comment.