proc节点的应用

cat kmsg查看proc变化

 

写节点:

 File file = new File("/sys/bus/i2c/drivers/aw20108_led/1-003a/leds/aw20108_led/effect");
        if(!file.exists()) {
            print("color node  not exists");
            return;
        }

        try {
            RandomAccessFile rdf = new RandomAccessFile(file, "rw");
            rdf.writeBytes(effect);
            rdf.close();
            print("effect:"+effect+" 写成功");
        } catch (Exception e) {
            print("file 写失败 "+e.getMessage().toString());
            e.printStackTrace();
        }

读节点:

File file = new File("/proc/gate_code_config");
        if(!file.exists()) {
            print("/proc/gate_code_config not exists");
            return;
        }
        try {
            RandomAccessFile rdf = new RandomAccessFile(file, "rw");
            byte[] buf = new byte[8];
            int len = 0;
            while((len = rdf.read(buf)) != -1) {
                print("read:"+new String(buf));
            }
            print("read:data_all : "+buf[0]+"  "+buf[1]);
            print(byte2String(buf));
            rdf.close();
        } catch (Exception e) {
            print("/proc/gate_code_config "+e.getMessage());
            e.printStackTrace();
        }

节点提权:修改init.rc

init.rc 中启动的 Action 和 Service : 
on early-init:设置init进程以及它创建的子进程的优先级,设置init进程的安全环境 
on init:设置全局环境,为cpu accounting创建cgroup(资源控制)挂载点 
on fs:挂载mtd分区 
on post-fs:改变系统目录的访问权限 
on post-fs-data:改变/data目录以及它的子目录的访问权限 
on boot:基本网络的初始化,内存管理等等 
service servicemanager:启动系统管理器管理所有的本地服务,比如位置、音频、Shared preference等等… 
service zygote:启动zygote作为应用进程

on post-fs-data
    #chown system system /config
    #chmod 0771 /config
    chown system system /sys/bus/platform/drivers/usb20_host/host_cdp
    chmod 0777 /sys/bus/platform/drivers/usb20_host/host_cdp
    # We chown/chmod /data again so because mount is run as root + defaults
    chown system system /data
    chmod 0771 /data
    # We restorecon /data in case the userdata partition has been reset.
    restorecon /data

    # Emulated internal storage area
    mkdir /data/media 0770 media_rw media_rw

    # Make sure we have the device encryption key
    start logd
    start vold
    installkey /data

    # Start bootcharting as soon as possible after the data partition is
    # mounted to collect more data.
    mkdir /data/bootchart 0755 shell shell
    bootchart_init

    # Avoid predictable entropy pool. Carry over entropy from previous boot.
    copy /data/system/entropy.dat /dev/urandom

    # create basic filesystem structure
    mkdir /data/misc 01771 system misc
    mkdir /data/misc/adb 02750 system shell
    mkdir /data/misc/bluedroid 02770 bluetooth net_bt_stack
    # Fix the access permissions and group ownership for 'bt_config.conf'
    chmod 0660 /data/misc/bluedroid/bt_config.conf
    chown bluetooth net_bt_stack /data/misc/bluedroid/bt_config.conf
    mkdir /data/misc/bluetooth 0770 system system
    mkdir /data/misc/keystore 0700 keystore keystore
    mkdir /data/misc/gatekeeper 0700 system system
    mkdir /data/misc/keychain 0771 system system
    mkdir /data/misc/net 0750 root shell
    mkdir /data/misc/radio 0770 system radio
    mkdir /data/misc/sms 0770 system radio
    mkdir /data/misc/zoneinfo 0775 system system
    mkdir /data/misc/vpn 0770 system vpn
    mkdir /data/misc/shared_relro 0771 shared_relro shared_relro
    mkdir /data/misc/systemkeys 0700 system system
    mkdir /data/misc/wifi 0770 wifi wifi
    mkdir /data/misc/wifi/sockets 0770 wifi wifi
    mkdir /data/misc/wifi/wpa_supplicant 0770 wifi wifi
    mkdir /data/misc/ethernet 0770 system system
    mkdir /data/misc/dhcp 0770 dhcp dhcp
    mkdir /data/misc/user 0771 root root
    mkdir /data/misc/perfprofd 0775 root root
    # give system access to wpa_supplicant.conf for backup and restore
    chmod 0660 /data/misc/wifi/wpa_supplicant.conf
    mkdir /data/local 0751 root root
    mkdir /data/misc/media 0700 media media
    mkdir /data/misc/vold 0700 root root

    # For security reasons, /data/local/tmp should always be empty.
    # Do not place files or directories in /data/local/tmp
    mkdir /data/local/tmp 0771 shell shell
    mkdir /data/data 0771 system system
    mkdir /data/app-private 0771 system system
    mkdir /data/app-asec 0700 root root
    mkdir /data/app-lib 0771 system system
    mkdir /data/app 0771 system system
    mkdir /data/property 0700 root root
    mkdir /data/tombstones 0771 system system

    # create dalvik-cache, so as to enforce our permissions
    mkdir /data/dalvik-cache 0771 root root
    mkdir /data/dalvik-cache/profiles 0711 system system

    # create resource-cache and double-check the perms
    mkdir /data/resource-cache 0771 system system
    chown system system /data/resource-cache
    chmod 0771 /data/resource-cache

    # create the lost+found directories, so as to enforce our permissions
    mkdir /data/lost+found 0770 root root

    # create directory for DRM plug-ins - give drm the read/write access to
    # the following directory.
    mkdir /data/drm 0770 drm drm

    # create directory for MediaDrm plug-ins - give drm the read/write access to
    # the following directory.
    mkdir /data/mediadrm 0770 mediadrm mediadrm

    mkdir /data/adb 0700 root root

    # symlink to bugreport storage location
    symlink /data/data/com.android.shell/files/bugreports /data/bugreports

    # Separate location for storing security policy files on data
    mkdir /data/security 0711 system system

    # Create all remaining /data root dirs so that they are made through init
    # and get proper encryption policy installed
    mkdir /data/backup 0700 system system
    mkdir /data/media 0770 media_rw media_rw
    mkdir /data/ss 0700 system system
    mkdir /data/system 0775 system system
    mkdir /data/system/fingerprint 0777 root root
    mkdir /data/system/fingerprint/0 0777 root root
    mkdir /data/system/heapdump 0700 system system
    mkdir /data/user 0711 system system

    setusercryptopolicies /data/user

    # Reload policy from /data/security if present.
    setprop selinux.reload_policy 1

    # Set SELinux security contexts on upgrade or policy update.
    restorecon_recursive /data

    # Check any timezone data in /data is newer than the copy in /system, delete if not.
    exec - system system -- /system/bin/tzdatacheck /system/usr/share/zoneinfo /data/misc/zoneinfo

    # If there is no fs-post-data action in the init.<device>.rc file, you
    # must uncomment this line, otherwise encrypted filesystems
    # won't work.
    # Set indication (checked by vold) that we have finished this action
    #setprop vold.post_fs_data_done 1
package com.ifive.skq.utils;

import android.content.Context;
import com.ifive.skq.log.Plog;

import java.io.File;
import java.io.RandomAccessFile;

/**
 * -----------------------------------------------------------------
 * Copyright (C) 2014-2016, by your company, All rights reserved.
 * -----------------------------------------------------------------
 * File: NodeUtils.java
 * Author: win7
 * Version: V100R001C01
 * Create: 2019/3/27 11:15
 * Changes (from 2019/3/27)
 * -----------------------------------------------------------------
 * 2019/3/27 : Create NodeUtils.java (win7);
 * -----------------------------------------------------------------
 */
public class NodeUtils {
    private String TAG="NodeUtils";
    private Context context;

    public NodeUtils(Context context) {
        this.context = context;
    }

    public void write(String path, String value) {
        File file = new File(path);
        if(!file.exists()) {
            print(path+" not exists");
            return;
        }

        try {
            RandomAccessFile rdf = new RandomAccessFile(file, "rw");
            rdf.writeBytes(value);
            rdf.close();
            print("value:"+value+" 写成功");
        } catch (Exception e) {
            print("file 写失败 "+e.getMessage().toString());
            e.printStackTrace();
        }
    }

    private void print(String s) {
        Plog.getInstance(context).print(TAG,s);
    }

    public void read(String path) {
        File file = new File(path);
        if(!file.exists()) {
            print(path+" not exists");
            return;
        }
        try {
            RandomAccessFile rdf = new RandomAccessFile(file, "rw");
            byte[] buf = new byte[512];
            int len = 0;
            while((len = rdf.read(buf)) != -1) {
                print("while:"+new String(buf));
            }
            print("end:"+new String(buf));
            rdf.close();
        } catch (Exception e) {
            print(path+e.getMessage());
            e.printStackTrace();
        }
    }
}

修改parameter.txt 增加androidboot.selinux=permissive

转载于:https://my.oschina.net/wfy94/blog/2999635

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值