mirror of
https://github.com/xoureldeen/Vectras-VM-Android.git
synced 2026-04-29 14:59:50 +00:00
Quince Jelly
This commit is contained in:
parent
f497260dee
commit
c04715e03f
5 changed files with 63 additions and 27 deletions
|
|
@ -990,8 +990,8 @@ public class MainActivity extends AppCompatActivity {
|
|||
File romDir = new File(Config.getCacheDir()+ "/" + Config.vmID);
|
||||
romDir.mkdirs();
|
||||
|
||||
if (!VMManager.isthiscommandsafe(env)) {
|
||||
VectrasApp.oneDialog(activity.getResources().getString(R.string.problem_has_been_detected), activity.getResources().getString(R.string.harmful_command_was_detected), true, false, activity);
|
||||
if (!VMManager.isthiscommandsafe(env, activity.getApplicationContext())) {
|
||||
VectrasApp.oneDialog(activity.getResources().getString(R.string.problem_has_been_detected), activity.getResources().getString(R.string.harmful_command_was_detected) + " " + activity.getResources().getString(R.string.reason) + ": " + VMManager.latestUnsafeCommandReason, true, false, activity);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1197,22 +1197,23 @@ public class MainActivity extends AppCompatActivity {
|
|||
doneonstart = true;
|
||||
|
||||
if (!AppConfig.pendingCommand.isEmpty()) {
|
||||
if (!VMManager.isthiscommandsafe(AppConfig.pendingCommand)) {
|
||||
if (!VMManager.isthiscommandsafe(AppConfig.pendingCommand, getApplicationContext())) {
|
||||
AppConfig.pendingCommand = "";
|
||||
VectrasApp.oneDialog(activity.getResources().getString(R.string.problem_has_been_detected), activity.getResources().getString(R.string.harmful_command_was_detected), true, false, activity);
|
||||
return;
|
||||
}
|
||||
if (AppConfig.pendingCommand.startsWith("qemu-img")) {
|
||||
if (!VMManager.isthiscommandsafeimg(AppConfig.pendingCommand)) {
|
||||
return;
|
||||
}
|
||||
Terminal _vterm = new Terminal(MainActivity.this);
|
||||
_vterm.executeShellCommand2(AppConfig.pendingCommand, false, MainActivity.activity);
|
||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.done), Toast.LENGTH_LONG).show();
|
||||
VectrasApp.oneDialog(activity.getResources().getString(R.string.problem_has_been_detected), activity.getResources().getString(R.string.harmful_command_was_detected) + " " + activity.getResources().getString(R.string.reason) + ": " + VMManager.latestUnsafeCommandReason, true, false, activity);
|
||||
} else {
|
||||
StartVM.cdrompath = "";
|
||||
String env = StartVM.env(MainActivity.activity, AppConfig.pendingCommand, "", "1");
|
||||
MainActivity.startVM("Quick run", env, AppConfig.pendingCommand, "");
|
||||
if (AppConfig.pendingCommand.startsWith("qemu-img")) {
|
||||
if (!VMManager.isthiscommandsafeimg(AppConfig.pendingCommand, getApplicationContext())) {
|
||||
VectrasApp.oneDialog(activity.getResources().getString(R.string.problem_has_been_detected), activity.getResources().getString(R.string.size_too_large_try_qcow2_format), true, false, activity);
|
||||
} else {
|
||||
Terminal _vterm = new Terminal(MainActivity.this);
|
||||
_vterm.executeShellCommand2(AppConfig.pendingCommand, false, MainActivity.activity);
|
||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.done), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else {
|
||||
StartVM.cdrompath = "";
|
||||
String env = StartVM.env(MainActivity.activity, AppConfig.pendingCommand, "", "1");
|
||||
MainActivity.startVM("Quick run", env, AppConfig.pendingCommand, "");
|
||||
}
|
||||
}
|
||||
AppConfig.pendingCommand = "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ public class VMManager {
|
|||
public static int restoredVMs = 0;
|
||||
public static boolean isKeptSomeFiles = false;
|
||||
|
||||
public static String latestUnsafeCommandReason = "";
|
||||
|
||||
public static void createNewVM(String name, String thumbnail, String drive, String arch, String cdrom, String params, String vmID, int port) {
|
||||
mapForCreateNewVM.clear();
|
||||
mapForCreateNewVM.put("imgName", name);
|
||||
|
|
@ -717,35 +719,61 @@ public class VMManager {
|
|||
movetoRecycleBin();
|
||||
}
|
||||
|
||||
public static boolean isthiscommandsafe(String _command) {
|
||||
public static boolean isthiscommandsafe(String _command, Context _context) {
|
||||
if (_command.startsWith("qemu")) {
|
||||
if (!_command.contains("&")) {
|
||||
if (!_command.contains("\n")) {
|
||||
if (!_command.contains(";")) {
|
||||
if (!_command.contains("|")) {
|
||||
return true;
|
||||
} else {
|
||||
latestUnsafeCommandReason = _context.getString(R.string.command_are_not_allowed_to_contain_vertical_bars);
|
||||
}
|
||||
} else {
|
||||
latestUnsafeCommandReason = _context.getString(R.string.command_are_not_allowed_to_contain_semicolons);
|
||||
}
|
||||
} else {
|
||||
latestUnsafeCommandReason = _context.getString(R.string.command_are_not_allowed_to_contain_multiple_lines);
|
||||
}
|
||||
} else {
|
||||
latestUnsafeCommandReason = _context.getString(R.string.command_are_not_allowed_to_contain_amp);
|
||||
}
|
||||
} else {
|
||||
latestUnsafeCommandReason = _context.getString(R.string.not_the_command_to_run_qemu);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isthiscommandsafeimg(String _command) {
|
||||
public static boolean isthiscommandsafeimg(String _command, Context _context) {
|
||||
if (!_command.contains("qcow2")) {
|
||||
String _getsize = _command.substring(_command.lastIndexOf(" ") + 1);
|
||||
if (_getsize.toLowerCase().endsWith("t") || _getsize.toLowerCase().endsWith("p") || _getsize.toLowerCase().endsWith("e")) {
|
||||
latestUnsafeCommandReason = _context.getString(R.string.size_too_large_try_qcow2_format);
|
||||
return false;
|
||||
}
|
||||
if (_getsize.toLowerCase().endsWith("g")) {
|
||||
return _getsize.length() <= 2;
|
||||
if (_getsize.length() <= 2) {
|
||||
return true;
|
||||
} else {
|
||||
latestUnsafeCommandReason = _context.getString(R.string.size_too_large_try_qcow2_format);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (_getsize.toLowerCase().endsWith("m")) {
|
||||
return _getsize.length() <= 4;
|
||||
if (_getsize.length() <= 4) {
|
||||
return true;
|
||||
} else {
|
||||
latestUnsafeCommandReason = _context.getString(R.string.size_too_large_try_qcow2_format);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (_getsize.toLowerCase().endsWith("k")) {
|
||||
return _getsize.length() <= 8;
|
||||
if (_getsize.length() <= 8) {
|
||||
return true;
|
||||
} else {
|
||||
latestUnsafeCommandReason = _context.getString(R.string.size_too_large_try_qcow2_format);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue