JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java ME、Google Android 平台與 JavaCard 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 目標要修改/system/etc/內的文件,跳出Permission denied的錯誤訊息
tamura425





發文: 2
積分: 0
於 2017-10-03 08:52 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我想要能夠可以修改到/system/etc裡面的一份文件,一開始跳出來的錯誤訊息是Read-only file system後來給了root權限之後錯誤訊息就變成Permission denied,查了其他的說法都只是說權限沒給足,但是該給的我應該都有給了,想詢問有沒有人做過類似的事情知道要如何解決或是有更好的方式可以提供。

PS.JAVA程式碼內有UpText和DownText兩個String,因為設定他們內容的副程式SetText太長了所以有精減掉。
JAVA程式碼
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.example.hjh.text3;
 
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
 
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
 
import static android.os.Environment.getExternalStorageDirectory;
import static android.os.Environment.getRootDirectory;
 
public class MainActivity extends AppCompatActivity {
    protected Process _process = null;
    protected DataOutputStream _outputStream = null;
    protected DataInputStream _inputStream = null;
    private EditText inputText;
    private Button Btn_new;
    private TextView TV;
    private String UpText,DownText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try
        {
            _process = Runtime.getRuntime().exec("su");
            _outputStream = new DataOutputStream(_process.getOutputStream());
            _inputStream = new DataInputStream(_process.getInputStream());
        }
        catch (IOException e)
        {
            setTitle("NOOP");
        }
        UnlockFile("/system/etc/","libnfc-nxp.conf");
        SetText();
        FindViewById();
        SetClick();
    }
    private void UnlockFile(String sFilePath, String sFileName)
    {
        if(!Write("su -c chmod 666 "+ sFilePath + sFileName +"\n"))
        {
            new AlertDialog.Builder(MainActivity.this)
                    .setTitle("無法讀取!")
                    .setMessage(sFilePath + sFileName + "\n無此檔案或異常終止")
                    .setPositiveButton("OK", new DialogInterface.OnClickListener()
                            {
                                public void onClick(DialogInterface d, int i )
                                {}
                            }
                    ).show();
 
            return;
        }
        else
        {
            new AlertDialog.Builder(MainActivity.this)
                    .setTitle("檔案授權成功!")
                    .setMessage("請按確認進行下一步!")
                    .setPositiveButton("OK", new DialogInterface.OnClickListener()
                            {
                                public void onClick( DialogInterface d, int i )
                                {}
                            }
                    ).show();
        }
    }
    public boolean Write(String sCommand)
    {
        boolean bResult = false;
        if(_outputStream == null)
        {
        }
        else
        {
            try
            {
                _outputStream.writeBytes(sCommand);
                _outputStream.flush();
                bResult = true;
            }
            catch (IOException e)
            {}
        }
        return bResult;
    }
    private void FindViewById(){
        inputText=(EditText)findViewById(R.id.inputText);
        Btn_new=(Button)findViewById(R.id.Btn_new);
        TV=(TextView)findViewById(R.id.TV);
    }
    private void SetClick(){
        Btn_new.setOnClickListener(Click);
    }
    private Button.OnClickListener Click=new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String Edit=inputText.getText().toString();
            String Edit2=getRootDirectory().toString()+"/etc/";
            try{
                File muFile=new File(Edit2+"libnfc-nxp.conf");
                FileOutputStream outStream=new FileOutputStream(muFile,true);
                outStream.write((UpText+Edit+DownText).getBytes());
                outStream.close();
                setTitle("Success");
            }catch(IOException e){
                setTitle("Error");
                TV.setText(e.toString()+"\n"+Edit2+"libnfc-nxp.conf");
            }
        }
    };
    private void SetText(){...}
}


Menifeast權限的部分
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.hjh.text3">
 
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.NFC"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
 
</manifest>


reply to postreply to post
作者 Re:目標要修改/system/etc/內的文件,跳出Permission denied的錯誤訊息 [Re:tamura425]
lnmlee





發文: 290
積分: 0
於 2017-10-04 16:36 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
apk 沒有權限

1
2
3
4
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     ... ... 
   android:sharedUserId="android.uid.system">
 


reply to postreply to post
我看你腦袋驚奇 充滿創意
是萬中無一的程式奇才 我看與你有緣
這本基礎Java程式語言 就送給你了
作者 Re:目標要修改/system/etc/內的文件,跳出Permission denied的錯誤訊息 [Re:lnmlee]
tamura425





發文: 2
積分: 0
於 2017-10-05 02:55 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我之前有加過這句,不過要燒進手機測試的時候會失敗

reply to postreply to post
» JWorld@TW »  Java ME、Google Android 平台與 JavaCard 討論區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8