2011-06-22 5 views
3

/dev/localという名前のnative(私はadbを通してプッシュしました)というバイナリをルート権限で実行したいとします。私はBrokenPipeエラーを取得これによりバイナリをrootのAndroidアプリケーションから実行する

try{ 
     root=Runtime.getRuntime().exec("su"); 
     root.waitFor(); 
     DataOutputStream os = new DataOutputStream(root.getOutputStream()); 
     DataInputStream osRes = new DataInputStream(root.getInputStream()); 
     os.writeBytes("/data/local/native\n"); 
     os.flush(); 
     TextView output=(TextView)findViewById(R.id.textview); 
     output.append(osRes.readLine()); 
     root.waitFor(); 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     Toast.makeText(this, e.toString() , Toast.LENGTH_SHORT).show(); 
    } 

:私はそれを変更してみました、これは私にNullPointerException。だからを与えた

try { 
     root=Runtime.getRuntime().exec("su"); 
     DataOutputStream os = new DataOutputStream(root.getOutputStream()); 
     DataInputStream osRes = new DataInputStream(root.getInputStream()); 
     os.writeBytes("/data/local/native\n"); 
     os.flush(); 
     TextView output=(TextView)findViewById(R.id.textview); 
     output.append(osRes.readLine()); 
     root.waitFor(); 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     Toast.makeText(this, e.toString() , Toast.LENGTH_SHORT).show(); 
    } 

: はそれを達成するために、私は次のコードを書きました。

私はroot特権でバイナリを実行したいのですが、別の方法があるのでしょうか、それとも間違っているのですか?

答えて

1

su -c /path/to/executableを試してみてください。

+0

私はこれを試しましたが、このように実行可能ファイルは実行されません! :( – d34th4ck3r

0

私はこれまで何度も答えてくれました。これを試してください:

Usage: Run(new String[]{"/system/bin/sh", "-c", "su"}); 

public String Run(String[] cmd) { 
    StringBuffer theRun = null; 
    try { 
     Process process = Runtime.getRuntime().exec(cmd); 

     BufferedReader reader = new BufferedReader(
       new InputStreamReader(process.getInputStream())); 
     int read; 
     char[] buffer = new char[4096]; 
     StringBuffer output = new StringBuffer(); 
     while ((read = reader.read(buffer)) > 0) { 
      theRun = output.append(buffer, 0, read);//output 
     } 
     reader.close(); 
     process.waitFor(); 

    } catch (IOException e) { 
     throw new RuntimeException(e); 
    } catch (InterruptedException e) { 
     throw new RuntimeException(e); 
    } 
     return theRun.toString();//return output 
} 

また、このリンクは便利です:http://www.stealthcopter.com/blog/2010/01/android-requesting-root-access-in-your-app/

-1

私は私の答えは遅れている知っているが、あなたはまだこの問題に直面している場合は、ここで私がやったことです。私はroot権限を持ってバイナリを実行しなければなりませんでした。私は/ system/appフォルダにバイナリを置くようないくつかのことを試しました。そこでは、システムアプリケーションは実行され、root権限を持っています。しかし、それは動作しませんでした。そこで、THISサイトで述べたように、su.cファイルを修正してカーネルを再コンパイルする必要がありました。カーネルを再コンパイルすることができない場合は、ルーティン(busyboxなど)で同じ変更を行い、再コンパイルすることができます。 "su -c"の代わりに "busybox su -c"を使用できるようになりました。

+1

株式Androidの「su」が目的のために使用できないという事実を根本的に引き上げる以外に、これは削除すべき誤った投機の束です。 –

関連する問題