测试

package com.sunight.crackme;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.security.CodeSource;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
import rikka.shizuku.Shizuku;
import rikka.shizuku.ShizukuRemoteProcess;

public class MainActivity extends Activity {
    public static int KEY_O0Oo0O0Oo0O=58039;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try {
            if (!checkPermission(0)) {
                Toast.makeText(this, "请授予Shizuku权限后重新进入", Toast.LENGTH_SHORT).show();
                finish();
                return;
            }
        } catch (Exception e) {
            Toast.makeText(this, "请授予Shizuku权限后重新进入", Toast.LENGTH_SHORT).show();
            finish();
            return;
        }

        ShizukuRemoteProcess newProcess = Shizuku.newProcess(new String[]{"sh"}, (String[]) null, (String) null);
        try {
            OutputStream outputStream = newProcess.getOutputStream();
            // 在Activity或Context中
            String packageName = getPackageName();
            String apkPath = getPackageManager().getApplicationInfo(packageName, 0).sourceDir;
            String cmd="app_process64 -Djava.class.path=" + apkPath + " " + new File(apkPath).getParent() + " com.sunight.crackme.MainActivity " + apkPath ;
            
            outputStream.write((cmd + "\n").getBytes());
            outputStream.flush();
            outputStream.close();
            InputStream inputStream = newProcess.getInputStream();
            InputStream errorStream = newProcess.getErrorStream();
            // 读取输出
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            BufferedReader errorReader = new BufferedReader(new InputStreamReader(errorStream));

            StringBuilder output = new StringBuilder();
            StringBuilder errorOutput = new StringBuilder();

            String line;
            while ((line = reader.readLine()) != null) {
                output.append(line).append("\n");
            }
            while ((line = errorReader.readLine()) != null) {
                errorOutput.append(line).append("\n");
            }

            // 等待进程结束
            int exitCode = newProcess.waitFor();
            TextView textview=findViewById(R.id.activitymainTextView1);
            if (exitCode == 0)
                textview.setText(output.toString());
            else
                textview.setText("Bad!");
        } catch (PackageManager.NameNotFoundException e) {} catch (InterruptedException e) {} catch (IOException e) {}


    }


    public static String getFileMD5(File file) {
        try {
            FileInputStream fis = new FileInputStream(file);
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] buffer = new byte[8192];
            int length;

            while ((length = fis.read(buffer)) != -1) {
                md.update(buffer, 0, length);
            }

            byte[] digest = md.digest();
            return bytesToHex(digest);
        } catch (IOException e) {} catch (NoSuchAlgorithmException e) {}

        return null;
    }

    private static String bytesToHex(byte[] bytes) {
        StringBuilder hexString = new StringBuilder();
        for (byte b : bytes) {
            String hex = Integer.toHexString(0xff & b);
            if (hex.length() == 1) {
                hexString.append('0');
            }
            hexString.append(hex);
        }
        return hexString.toString();
    }
    public static void main(String[] args) {
        File file=new File(args[0]);
        if (file.length() == KEY_O0Oo0O0Oo0O)
            System.out.println("Normal");
        else
            System.out.println("Bad!");
    }




    private boolean checkPermission(int code) {
        if (Shizuku.isPreV11()) {
            // Pre-v11 is unsupported
            return false;
        }

        if (Shizuku.checkSelfPermission() == PackageManager.PERMISSION_GRANTED) {
            // Granted
            return true;
        } else if (Shizuku.shouldShowRequestPermissionRationale()) {
            // Users choose "Deny and don't ask again"
            return false;
        } else {
            // Request the permission
            Shizuku.requestPermission(code);
            return false;
        }
    }
}
#include <iostream>
#include <vector>
#include <string>
#include <dirent.h>
#include <fcntl.h>
#include <linux/input.h>
#include <sys/ioctl.h>
#include <unistd.h>

#define INPUT_DIR "/dev/input/"  // 设备目录

// 获取 /dev/input/ 目录下的所有设备文件
std::vector<std::string> getInputDevices() {
    std::vector<std::string> devices;
    DIR *dir = opendir(INPUT_DIR);
    if (!dir) {
        perror("无法打开 /dev/input/ 目录");
        return devices;
    }

    struct dirent *entry;
    while ((entry = readdir(dir)) != nullptr) {
        if (entry->d_name[0] != '.') {  // 忽略 . 和 ..
            devices.emplace_back(std::string(INPUT_DIR) + entry->d_name);
        }
    }
    closedir(dir);
    return devices;
}

// 进程独占设备
int grabDevice(const std::string &devicePath) {
    int fd = open(devicePath.c_str(), O_RDONLY);
    if (fd < 0) {
        perror(("无法打开设备: " + devicePath).c_str());
        return -1;
    }

    if (ioctl(fd, EVIOCGRAB, 1) < 0) {
        perror(("无法独占设备: " + devicePath).c_str());
        close(fd);
        return -1;
    }

    std::cout << "成功独占设备: " << devicePath << std::endl;
    return fd;
}

// 释放设备
void releaseDevices(const std::vector<int> &fds) {
    for (int fd : fds) {
        if (fd >= 0) {
            ioctl(fd, EVIOCGRAB, 0);
            close(fd);
        }
    }
    std::cout << "所有设备已恢复正常。" << std::endl;
}

int main() {
    std::vector<std::string> devices = getInputDevices();
    
    if (devices.empty()) {
        std::cerr << "未找到任何输入设备。" << std::endl;
        return 1;
    }

    std::vector<int> grabbed_fds;
    for (const auto &device : devices) {
        int fd = grabDevice(device);
        if (fd >= 0) {
            grabbed_fds.push_back(fd);
        }
    }

    if (grabbed_fds.empty()) {
        std::cerr << "未能独占任何设备。" << std::endl;
        return 1;
    }

    std::cout << "设备已独占 60 秒..." << std::endl;
    sleep(6);  // 保持独占 60 秒

    // 释放所有设备
    releaseDevices(grabbed_fds);

    return 0;
}


测试
https://sunight.cn/archives/lIA5ArDx
作者
Sunight
发布于
2025年04月10日
许可协议