为了在端口<1025上打开套接字,我需要root访问权限.究竟如何给我的应用程序这个特权?我知道我可以在shell中运行su命令以获得root访问权限,但是我需要做什么才能在端口<1025上打开套接字?或者我是否需要像su open socket 0.0.0.0:80那样运行某种命令?我很困惑,因为那里有这么少的资源.谷歌没有预先植根所有设备的目的是什么?
以下是我知道我可以做的root访问权限.http://www.youtube.com/watch?v=jmfvX8zvsS0&list=UUk1SpWNzOs4MYmr0uICEntg&index=4&feature=plcp
编辑:我刚写了这个:
public class RootTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String cmds[] = {"su", "-c", "ls /system/app"};
Shell shell = new Shell();
String text = shell.sendShellCommand(cmds);
TextView textView = (TextView)findViewById(R.id.textView);
textView.setText(text);
try {
ServerSocket socket = new ServerSocket(80);
Log.d("Root", "Opened socket on port 80!!!");
}catch(Exception e) {
Log.d("Root", "Failed to open socket on port 80!!!");
e.printStackTrace();
}
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
这样做是在单击按钮时运行命令su,-c,然后运行ls/system/app.然后它获取输出并在textview上显示它(实际上是有效的.我得到了su提示并选择了accept并且它列出了/ system/apps /中的所有内容).但之后我尝试在端口80上打开一个套接字,它仍然说Permission Denied.该应用程序具有root访问权限,但仍无法打开套接字!在logcat中打印出"无法在端口80上打开套接字!!!" 正如我告诉它要抓住异常一样.如果未经许可拒绝,我该如何在端口80上打开套接字?
根据https://serverfault.com/questions/112795/how-can-i-run-a-server-on-linux-on-port-80-as-a-normal-user
我以root身份运行此命令:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
Run Code Online (Sandbox Code Playgroud)
它奏效了!我在端口8080上打开了一个套接字,当在端口80上连接到我的手机时,所有流量都被重定向到8080!哇!
| 归档时间: |
|
| 查看次数: |
3470 次 |
| 最近记录: |