GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — big change · ptr-ptr/linuxKernelRoot@122cef4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • PermissionManager/app/src/main
    • cpp
      • CMakeLists.txt
      • root.cpp
    • java/com/linux/permissionmanager
      • Adapter
        • SelectAppRecyclerAdapter.java
      • MainActivity.java
      • Model
        • PopupWindowOnTouchClose.java
        • SelectAppRecyclerItem.java
      • Utils
        • ScreenInfoUtils.java
        • UsbDebugSwitchHelper.java
    • res
      • drawable
        • line.xml
        • line_drawable.xml
        • ripple_grey.xml
        • shape_wnd_grey_corner.xml
        • thumb.xml
        • thumb_drawable.xml
      • layout
        • activity_main.xml
        • select_app_recycler_item.xml
        • select_app_wnd.xml
      • values
        • colors.xml
        • themes.xml
  • su
    • base64.cpp
    • base64.h
    • jni
      • Android.mk
    • pts.cpp
    • pts.hpp
    • root_key_helper.h
    • simple_su.cpp
    • socket.cpp
    • socket.hpp
    • su.cpp
    • su.h
    • su.vcxproj.filters
    • su.vcxproj
    • su_client.h
    • su_daemon.h
  • testRoot
    • README.md
    • adb64_helper.cpp
    • adb64_helper.h
    • adb64_inject.h
    • base64.cpp
    • base64.h
    • env64_inject.cpp
    • env64_inject.h
    • jni
      • Android.mk
    • maps_helper.cpp
    • maps_helper.h
    • process64_inject.h
    • ptrace_arm64_utils.cpp
    • ptrace_arm64_utils.h
    • su_install_helper.cpp
    • su_install_helper.h
    • testRoot.cpp
    • testRoot.h
    • testRoot.vcxproj.filters
    • testRoot.vcxproj

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎PermissionManager/app/src/main/cpp/CMakeLists.txt‎

Copy file name to clipboardExpand all lines: PermissionManager/app/src/main/cpp/CMakeLists.txt
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ add_library( # Sets the name of the library.
2121
SHARED
2222

2323
# Provides a relative path to your source file(s).
24-
../../../../../testRoot/adb_inject.cpp
24+
../../../../../testRoot/process64_inject.cpp
25+
../../../../../testRoot/adb64_helper.cpp
2526
../../../../../testRoot/ptrace_arm64_utils.cpp
27+
../../../../../testRoot/su_install_helper.cpp
28+
../../../../../testRoot/base64.cpp
2629
root.cpp)
2730

2831
# Searches for a specified prebuilt library and stores the path as a
Collapse file

‎PermissionManager/app/src/main/cpp/root.cpp‎

Copy file name to clipboardExpand all lines: PermissionManager/app/src/main/cpp/root.cpp
+162-15Lines changed: 162 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,32 @@
44
#include <string.h>
55
#include <unistd.h>
66
#include <sstream>
7+
#include <thread>
78
#include <sys/capability.h>
89

9-
#include "../../../../../testRoot/super_root.h"
10-
#include "../../../../../testRoot/adb_inject.h"
10+
#include "../../../../../testRoot/testRoot.h"
11+
#include "../../../../../testRoot/kernel_root_helper.h"
12+
#include "../../../../../testRoot/process64_inject.h"
13+
#include "../../../../../testRoot/adb64_helper.h"
14+
#include "../../../../../testRoot/su_install_helper.h"
1115

1216
using namespace std;
1317
string getCapabilityInfo()
1418
{
19+
__uid_t now_uid, now_euid, now_suid;
20+
if (getresuid(&now_uid, &now_euid, &now_suid)) {
21+
return "FAILED getresuid()";
22+
}
23+
24+
25+
__gid_t now_gid, now_egid, now_sgid;
26+
if (getresgid(&now_gid, &now_egid, &now_sgid)) {
27+
return "FAILED getresgid()";
28+
}
29+
30+
stringstream sstrCapInfo;
31+
sstrCapInfo<< "now_uid="<<now_uid <<", now_euid="<< now_euid <<", now_suid="<< now_suid <<", now_gid="<< now_gid <<", now_egid="<< now_egid << ", now_sgid="<< now_sgid <<"\n";
32+
1533
struct __user_cap_header_struct cap_header_data;
1634
cap_user_header_t cap_header = &cap_header_data;
1735

@@ -26,9 +44,7 @@ string getCapabilityInfo()
2644
// perror("FAILED capget()");
2745
//exit(1);
2846
}
29-
stringstream sstrCapInfo;
3047
sstrCapInfo << "Cap data effective:"<<(uint64_t *) cap_data->effective<<", permitted:"<<(uint64_t *) cap_data->permitted<<", inheritable:"<<(uint64_t *) cap_data->inheritable<<"\n";
31-
sstrCapInfo << "now getuid()="<< getuid() <<",geteuid()="<< geteuid() <<",getgid()="<< getgid() <<",getegid()="<< getegid() << "\n";
3248

3349
FILE * fp = popen("getenforce", "r");
3450
if (fp)
@@ -47,6 +63,7 @@ extern "C" JNIEXPORT jstring JNICALL
4763
Java_com_linux_permissionmanager_MainActivity_getCapabilityInfo(
4864
JNIEnv* env,
4965
jobject /* this */) {
66+
5067
return env->NewStringUTF(getCapabilityInfo().c_str());
5168
}
5269

@@ -74,7 +91,7 @@ Java_com_linux_permissionmanager_MainActivity_enableSElinux(
7491
}
7592

7693
extern "C" JNIEXPORT jstring JNICALL
77-
Java_com_linux_permissionmanager_MainActivity_runRootCmd(
94+
Java_com_linux_permissionmanager_MainActivity_runNormalCmd(
7895
JNIEnv* env,
7996
jobject /* this */,
8097
jlong rootKey,
@@ -85,28 +102,158 @@ Java_com_linux_permissionmanager_MainActivity_runRootCmd(
85102
env->ReleaseStringUTFChars(cmd, str1);
86103

87104
char szResult[0x1000] = {0};
88-
ssize_t ret = safe_run_root_cmd(rootKey, strCmd.c_str(), szResult, sizeof(szResult));
105+
ssize_t ret = safe_run_normal_cmd(rootKey, strCmd.c_str(), szResult, sizeof(szResult));
89106
stringstream sstr;
90107
sstr << "runRootCmd ret val:" << ret << ", result:" << szResult;
91108
return env->NewStringUTF(sstr.str().c_str());
92109
}
93110

94111
extern "C" JNIEXPORT jstring JNICALL
95-
Java_com_linux_permissionmanager_MainActivity_runAdbShell(
112+
Java_com_linux_permissionmanager_MainActivity_runRootCmd(
96113
JNIEnv* env,
97114
jobject /* this */,
98115
jlong rootKey,
99-
jstring shell,
100-
jboolean keepAdbRoot) {
116+
jstring cmd) {
101117

102-
const char *str1 = env->GetStringUTFChars(shell, 0);
103-
string strShell= str1;
104-
env->ReleaseStringUTFChars(shell, str1);
118+
const char *str1 = env->GetStringUTFChars(cmd, 0);
119+
string strCmd= str1;
120+
env->ReleaseStringUTFChars(cmd, str1);
105121

122+
stringstream sstr;
106123
char szResult[0x1000] = {0};
107-
ssize_t inject = safe_inject_adb_process_run_shell_wrapper(rootKey, strShell.c_str(), keepAdbRoot, szResult, sizeof(szResult));
108-
//ssize_t inject = safe_inject_adb_process_run_shell_wrapper(rootKey, strShell.c_str(), NULL, 0);
124+
ssize_t inject = safe_inject_adbd64_run_cmd_wrapper(rootKey, strCmd.c_str(), szResult, sizeof(szResult));
125+
//ssize_t inject = safe_inject_adbd64_run_cmd_wrapper(rootKey, strCmd.c_str(),NULL, 0);
126+
sstr << "runRootCmd ret val:" << inject << ", result:" << szResult;
127+
return env->NewStringUTF(sstr.str().c_str());
128+
}
129+
extern "C" JNIEXPORT jstring JNICALL
130+
Java_com_linux_permissionmanager_MainActivity_adbRoot(
131+
JNIEnv* env,
132+
jobject /* this */,
133+
jlong rootKey) {
134+
135+
stringstream sstr;
136+
char szResult[0x1000] = {0};
137+
ssize_t inject = safe_inject_adbd64_run_cmd_wrapper(rootKey, "id", NULL, 0, false ,true ,false, false);
138+
sstr << "adbRoot ret val:" << inject << ", result:" << szResult;
139+
return env->NewStringUTF(sstr.str().c_str());
140+
}
141+
extern "C" JNIEXPORT jstring JNICALL
142+
Java_com_linux_permissionmanager_MainActivity_installSuTools(
143+
JNIEnv* env,
144+
jobject /* this */,
145+
jlong rootKey,
146+
jstring basePath,
147+
jstring suToolsFilePath) {
148+
149+
const char *str1 = env->GetStringUTFChars(basePath, 0);
150+
string strBasePath= str1;
151+
env->ReleaseStringUTFChars(basePath, str1);
152+
153+
str1 = env->GetStringUTFChars(suToolsFilePath, 0);
154+
string strSuFilePath= str1;
155+
env->ReleaseStringUTFChars(suToolsFilePath, str1);
156+
157+
stringstream sstr;
158+
159+
//安装su工具套件
160+
std::string su_hidden_path;
161+
int install_su_tools_ret = safe_install_su_tools(rootKey, strBasePath.c_str(), su_hidden_path);
162+
sstr << "install_su_tools ret val:" << install_su_tools_ret<<", su_hidden_path:" << su_hidden_path << std::endl;
163+
164+
if (install_su_tools_ret == -504) {
165+
//需要补一下su文件的释放
166+
std::string tmpCmd = "cp "+strSuFilePath + " " + su_hidden_path+"/su";
167+
int cp_ret = safe_run_normal_cmd(rootKey, tmpCmd.c_str(), NULL, 0);
168+
if(cp_ret != 0) {
169+
sstr << "safe_run_normal_cmd cp_ret val:" <<cp_ret;
170+
return env->NewStringUTF(sstr.str().c_str());
171+
}
172+
install_su_tools_ret = safe_install_su_tools(rootKey, strBasePath.c_str(), su_hidden_path);
173+
sstr << "install_su_tools ret val:" << install_su_tools_ret<<", su_hidden_path:" << su_hidden_path << std::endl;
174+
}
175+
if (install_su_tools_ret != 0) {
176+
return env->NewStringUTF(sstr.str().c_str());
177+
}
178+
sstr << "installSuTools done.";
179+
return env->NewStringUTF(sstr.str().c_str());
180+
}
181+
extern "C" JNIEXPORT jstring JNICALL
182+
Java_com_linux_permissionmanager_MainActivity_uninstallSuTools(
183+
JNIEnv* env,
184+
jobject /* this */,
185+
jlong rootKey,
186+
jstring basePath) {
187+
188+
const char *str1 = env->GetStringUTFChars(basePath, 0);
189+
string strBasePath= str1;
190+
env->ReleaseStringUTFChars(basePath, str1);
191+
109192
stringstream sstr;
110-
sstr << "runAdbShell ret val:" << inject << ", result:" << szResult;
193+
194+
int uninstall_su_tools_ret = safe_uninstall_su_tools(rootKey, strBasePath.c_str());
195+
sstr << "uninstallSuTools ret val:" << uninstall_su_tools_ret << std::endl;
196+
197+
if (uninstall_su_tools_ret != 0) {
198+
return env->NewStringUTF(sstr.str().c_str());
199+
}
200+
sstr << "uninstallSuTools done.";
201+
return env->NewStringUTF(sstr.str().c_str());
202+
}
203+
extern "C" JNIEXPORT jstring JNICALL
204+
Java_com_linux_permissionmanager_MainActivity_autoSuEnvInject(
205+
JNIEnv* env,
206+
jobject /* this */,
207+
jlong rootKey,
208+
jstring targetProcessCmdline,
209+
jstring basePath) {
210+
211+
const char *str1 = env->GetStringUTFChars(targetProcessCmdline, 0);
212+
string strTargetProcessCmdline= str1;
213+
env->ReleaseStringUTFChars(targetProcessCmdline, str1);
214+
215+
str1 = env->GetStringUTFChars(basePath, 0);
216+
string strBasePath= str1;
217+
env->ReleaseStringUTFChars(basePath, str1);
218+
219+
stringstream sstr;
220+
221+
//杀光所有历史进程
222+
std::vector<pid_t> vOut;
223+
int find_all_cmdline_process_ret = safe_find_all_cmdline_process(rootKey, strTargetProcessCmdline.c_str(), vOut);
224+
sstr << "find_all_cmdline_process ret val:"<< find_all_cmdline_process_ret<<", cnt:"<<vOut.size() << std::endl;
225+
if (find_all_cmdline_process_ret != 0) {
226+
return env->NewStringUTF(sstr.str().c_str());
227+
}
228+
std::string kill_cmd;
229+
for (pid_t t : vOut) {
230+
kill_cmd += "kill -9 ";
231+
kill_cmd += std::to_string(t);
232+
kill_cmd += ";";
233+
}
234+
int kill_ret = run_normal_cmd(rootKey, kill_cmd.c_str());
235+
sstr << "kill_ret ret val:"<< kill_ret << std::endl;
236+
if (kill_ret != 0) {
237+
return env->NewStringUTF(sstr.str().c_str());
238+
}
239+
240+
//注入su环境变量到指定进程
241+
std::string su_hidden_path;
242+
int install_su_tools_ret = safe_install_su_tools(rootKey, strBasePath.c_str(), su_hidden_path);
243+
sstr << "install_su_tools ret val:" << install_su_tools_ret<<", su_hidden_path:" << su_hidden_path << std::endl;
244+
if (install_su_tools_ret != 0) {
245+
return env->NewStringUTF(sstr.str().c_str());
246+
}
247+
248+
int pid = safe_wait_and_find_cmdline_process(rootKey, strTargetProcessCmdline.c_str());
249+
250+
sstr << "autoSuEnvInject("<< pid<<", " << su_hidden_path<<")" << std::endl;
251+
ssize_t ret = safe_inject_process_env64_PATH_wrapper(rootKey, pid, su_hidden_path.c_str());
252+
sstr << "autoSuEnvInject ret val:" << ret << std::endl;
253+
254+
if (ret != 0) {
255+
return env->NewStringUTF(sstr.str().c_str());
256+
}
257+
sstr << "autoSuEnvInject done.";
111258
return env->NewStringUTF(sstr.str().c_str());
112259
}
Collapse file

‎PermissionManager/app/src/main/java/com/linux/permissionmanager/Adapter/SelectAppRecyclerAdapter.java‎

Copy file name to clipboard
+110Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package com.linux.permissionmanager.Adapter;
2+
3+
import android.content.Context;
4+
import android.os.Handler;
5+
import android.os.Message;
6+
import android.text.Html;
7+
import android.view.LayoutInflater;
8+
import android.view.View;
9+
import android.view.ViewGroup;
10+
import android.widget.ImageView;
11+
import android.widget.PopupWindow;
12+
import android.widget.TextView;
13+
14+
import androidx.annotation.NonNull;
15+
import androidx.recyclerview.widget.RecyclerView;
16+
17+
import com.linux.permissionmanager.Model.SelectAppRecyclerItem;
18+
import com.linux.permissionmanager.R;
19+
20+
import java.util.List;
21+
22+
public class SelectAppRecyclerAdapter extends RecyclerView.Adapter<SelectAppRecyclerAdapter.ViewHolder> {
23+
24+
25+
26+
public static class ViewHolder extends RecyclerView.ViewHolder {
27+
public View v;
28+
public ImageView select_app_icon;
29+
public TextView select_app_text;
30+
public TextView select_package_name;
31+
// TODO Auto-generated method stub
32+
public ViewHolder(View v) {
33+
super(v);
34+
this.v = v;
35+
}
36+
37+
}
38+
39+
private int resourceId;
40+
private List<SelectAppRecyclerItem> objects;
41+
private PopupWindow popupWindow;
42+
private Handler selectAppItemCallback;
43+
public SelectAppRecyclerAdapter(Context context, int textViewResourceId, List<SelectAppRecyclerItem> objects, PopupWindow popupWindow, Handler selectAppItemCallback) {
44+
this.resourceId = textViewResourceId;
45+
this.objects = objects;
46+
this. popupWindow = popupWindow;
47+
this. selectAppItemCallback = selectAppItemCallback;
48+
}
49+
50+
51+
52+
@NonNull
53+
@Override
54+
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
55+
View v =LayoutInflater.from(parent.getContext()).inflate(resourceId,parent,false);
56+
SelectAppRecyclerAdapter.ViewHolder holder = new SelectAppRecyclerAdapter.ViewHolder(v);
57+
58+
holder.select_app_icon = v.findViewById(R.id.select_app_icon);
59+
holder.select_app_text=v.findViewById(R.id.select_app_text) ;
60+
holder.select_package_name=v.findViewById(R.id.select_package_name) ;
61+
return holder;
62+
}
63+
64+
65+
@Override
66+
public void onBindViewHolder(@NonNull SelectAppRecyclerAdapter.ViewHolder holder, int position) {
67+
SelectAppRecyclerItem appItem=objects.get(position); //获取当前项的实例
68+
69+
//图标+进程PID+名字+内存
70+
holder.select_app_icon.setImageDrawable(appItem.getIcon());
71+
String showText="<font color = \"#88CC88\">"+appItem.getShowName() +"</font> "
72+
+" <font color = \"#88CCCC\">"+" ("+appItem.getPackageName()+")"+"</font>";
73+
74+
holder.select_app_text.setText(Html.fromHtml(showText));
75+
holder.select_package_name.setText(appItem.getPackageName());
76+
77+
//item被点击
78+
holder.v.setOnClickListener(new ClickRecyclerItemListener(appItem));
79+
}
80+
81+
82+
@Override
83+
public int getItemCount() {
84+
return objects.size();
85+
}
86+
87+
@Override
88+
public int getItemViewType(int position) {
89+
return position;
90+
}
91+
92+
93+
class ClickRecyclerItemListener implements View.OnClickListener {
94+
SelectAppRecyclerItem appItem;
95+
public ClickRecyclerItemListener( SelectAppRecyclerItem appItem){
96+
this.appItem =appItem;
97+
}
98+
@Override
99+
public void onClick(View v) {
100+
popupWindow.dismiss();
101+
Message msg = new Message();
102+
msg.obj = (SelectAppRecyclerItem)appItem;
103+
selectAppItemCallback.sendMessage(msg);
104+
}
105+
}
106+
107+
108+
109+
110+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.