Skip to content

Commit

Permalink
update adb
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-black-tea committed Jul 8, 2024
1 parent b2a2c2a commit 24f997a
Show file tree
Hide file tree
Showing 22 changed files with 774 additions and 417 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,13 @@ AndroidHelper.javaUse("p.r.o.x.y.PrivacyApi", function(clazz) {
# 调用android-tools.apk中的方法
$ at-agent common --set-clipboard "剪切板内容"

# 添加插件并调用android-tools.apk中的方法
# 获取剪切板内容
$ at-agent common --get-clipboard

# 以root权限dump系统服务信息,包括服务所在进程信息,需要root设备并且挂载DebugFS:https://source.android.com/docs/core/architecture/kernel/using-debugfs-12?hl=zh-cn
$ at-agent -u root --debug service --detail

# 添加插件并调用插件方法
$ at-agent --plugin app-release.apk
```

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.ironman.framework.bean.os;

public class File {
public String name;
public String path;
public boolean isDirectory;
public boolean readable;
public boolean writable;
public boolean executable;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.ironman.framework.bean.process;
package org.ironman.framework.bean.os;

public class Process {
public long pid;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.ironman.framework.bean.os;

import android.os.IBinder;

import java.util.List;

public class Service {
public String name;
public String desc;
public IBinder binder;
public Process owner;
public List<Process> users;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.ironman.framework.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class CommandUtil {

public static String execCommand(String... commands) throws IOException {
Process proccess = null;
BufferedReader stdout = null;
BufferedReader stderr = null;

try {
proccess = Runtime.getRuntime().exec(commands);

stdout = new BufferedReader(new InputStreamReader(proccess.getInputStream()));
stderr = new BufferedReader(new InputStreamReader(proccess.getErrorStream()));

String line;
StringBuilder sb = new StringBuilder();
while ((line = stdout.readLine()) != null) {
sb.append(line).append('\n');
}

return sb.toString();
} finally {
if (stdout != null) {
try {
stdout.close();
} catch (Exception e) {
// ignore
}
}
if (stderr != null) {
try {
stderr.close();
} catch (Exception e) {
// ignore
}
}
if (proccess != null) {
try {
proccess.destroy();
} catch (Exception e) {
// ignore
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,71 @@

public class FileUtil {

public static File[] listFiles(File file) {
try {
return file.listFiles();
} catch (SecurityException e) {
return null;
}
}

public static boolean canWrite(String fileName) {
return new File(fileName).canWrite();
return canWrite(new File(fileName));
}

public static boolean canWrite(File file) {
try {
return file.canWrite();
} catch (SecurityException e) {
return false;
}
}

public static boolean canRead(String fileName) {
return new File(fileName).canRead();
return canRead(new File(fileName));
}

public static boolean canRead(File file) {
try {
return file.canRead();
} catch (SecurityException e) {
return false;
}
}

public static boolean canExecute(String fileName) {
return new File(fileName).canExecute();
return canExecute(new File(fileName));
}

public static boolean canExecute(File file) {
try {
return file.canExecute();
} catch (SecurityException e) {
return false;
}
}

public static boolean isDirectory(String fileName) {
return isDirectory(new File(fileName));
}

public static boolean isDirectory(File file) {
try {
return file.isDirectory();
} catch (SecurityException e) {
return false;
}
}

public static String readString(String fileName) throws IOException {
return readString(new File(fileName));
}

public static String readString(File file) throws IOException {
StringBuilder result = new StringBuilder();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(fileName));
reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
result.append(line);
Expand All @@ -46,9 +94,13 @@ public static String readString(String fileName) throws IOException {
}

public static void writeString(String fileName, String buffer) throws IOException {
writeString(new File(fileName), buffer);
}

public static void writeString(File file, String buffer) throws IOException {
FileWriter writer = null;
try {
writer = new FileWriter(fileName);
writer = new FileWriter(file);
writer.write(buffer);
} finally {
CommonUtil.closeQuietly(writer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package org.ironman.framework.util;

import android.os.IBinder;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import java.lang.reflect.Type;

public class GsonUtil {

private final static Gson gson = new Gson();
private final static Gson gson = new GsonBuilder()
.registerTypeAdapter(IBinder.class, new BinderSerializer())
.create();

public static String toJson(Object src) {
return gson.toJson(src);
Expand All @@ -15,4 +24,14 @@ public static String toJson(Object src) {
public String toJson(Object src, Type typeOfSrc) {
return gson.toJson(src, typeOfSrc);
}

private static class BinderSerializer implements JsonSerializer<IBinder> {

public JsonElement serialize(
IBinder binder,
Type type,
JsonSerializationContext jsonSerializationContext) {
return new JsonPrimitive(binder.toString());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.ironman.framework.util;

import org.ironman.framework.bean.process.Process;
import org.ironman.framework.bean.os.Process;

import java.io.BufferedReader;
import java.io.File;
Expand Down
Loading

0 comments on commit 24f997a

Please sign in to comment.