gpt4 book ai didi

java - Delphi xe5 exec root命令转换

转载 作者:太空狗 更新时间:2023-10-29 16:04:30 25 4
gpt4 key购买 nike

我试图隐藏RuntimeProcess将 shell 命令发送到 root 手机我不明白为什么我有段错误。在互联网上我发现 Java 代码如下:

Runtime.getRuntime().exec(new String[]{"/system/bin/su","-c","reboot now"});` for reboot of the phone or `Runtime.getRuntime().exec("su");

用于 linux root 权限。

我试图在转换后只发送带有函数的“su”命令,但我想我错了......我认为一个可能的问题可能是从 java 类型转换的 Jstring 数组。

unit Androidapi.JNI.Root;

interface
procedure AskRoot;
implementation
uses System.SysUtils,
Androidapi.JNIBridge,
Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.JavaTypes,
FMX.Helpers.Android;

type
JProcess = interface;
JRuntime = interface;
//----------------------------------JProcess----------------------
JProcessClass = interface(JObjectClass)
['{7BFD2CCB-89B6-4382-A00B-A7B5BB0BC7C9}']

end;
[JavaSignature('java/lang/Process')]
JProcess = interface(JObject)
['{476414FD-570F-4EDF-B678-A2FE459EA6EB}']
{Methods}
procedure destroy; cdecl;
function exitValue:integer;cdecl;
function getErrorStream:JInputStream; cdecl;
function getInputStream:JOutputStream; cdecl;
function waitFor:integer;cdecl;
end;
TJProcess = class(TJavaGenericImport<JProcessClass, JProcess>) end;
//----------------------------------Jruntime----------------------
JRuntimeClass = interface(JObjectClass)
['{3F2E949D-E97C-4AD8-B5B9-19CB0A6A29F3}']
{costant}
end;
[JavaSignature('java/lang/Runtime')]
JRuntime = interface(JObject)
['{C097A7EC-677B-4BCB-A4BD-7227160750A5}']
{Methods}
procedure addShutdownHook(hook:JThread);cdecl;
function availableProcessors:integer; cdecl;
function exec(progArray,envp:array of JString):Jprocess; overload;
function exec(progArray:Jstring; envp:array of JString;directory:JFile):Jprocess; overload;
function exec(progArray,envp:array of JString;directory:JFile):Jprocess; overload;
function exec(prog:JString;envp:array of JString):Jprocess; cdecl; overload;
function exec(progArray:array of JString):Jprocess; overload;
function exec(prog:JString):Jprocess; cdecl; overload;
procedure Exit(code:Integer);cdecl;
function freeMemory:LongInt;cdecl;
procedure gc; cdecl;
function getLocalizedInputStream(stream:JInputStream):JInputStream; cdecl;
function getLocalizedOutputStream(stream:JOutputStream):JOutputStream; cdecl;
function getRuntime:JRuntime;cdecl;
procedure halt(code:Integer);cdecl;
procedure load(pathName:JString);cdecl;
procedure loadLibrary(libName:JString); cdecl;
function maxMemory:LongInt;cdecl;
function RemoveShutdownHook(hook:JThread):Boolean;cdecl;
procedure runFinalization;cdecl;
procedure runFinalizersOnExit(run:Boolean);cdecl;
function totalMemory:LongInt;cdecl;
procedure traceInstructions(enable:Boolean);cdecl;
procedure traceMethodCalls(enable:Boolean); cdecl;
end;
TJRuntime = class(TJavaGenericImport<JRuntimeClass, JRuntime>) end;

procedure AskRoot;
var root:JRuntime;
begin
root.getRuntime.exec(StringToJString('su'));
end;
end.

最佳答案

您的几个 exec 覆盖未标记为 cdecl

这无济于事 - 堆栈会变得困惑并可能导致段错误。

但是你调用的那个被标记为cdecl

另一方面,您正在调用尚未初始化的 root 对象/接口(interface)引用的方法。这种操作肯定会给您带来段错误。

getRuntime 看起来是 Runtime 类的类方法,因此您输入了错误的接口(interface)。当你把它移到正确的位置时,我想像这样的事情可能会做到:

TJRuntime.JavaClass.getRuntime.exec(StringToJString('su'));

关于java - Delphi xe5 exec root命令转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19857021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com