以root权限运行的服务或具有根权限添加 [英] Run a service with Root privileges or adding permissions with root

查看:411
本文介绍了以root权限运行的服务或具有根权限添加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个应用程序,读取短信/电子邮件,而驾驶。许多用户希望支持的WhatsApp / KakaoTalk。

I am currently developing an app that reads out SMS/Emails while driving. Many users wished support for WhatsApp / KakaoTalk.

然而,因为没有正式的方式来接收他们的邮件,将只有三种选择,都需要根:

However, as there is no "official" way to receive their messages, there would be only three options, all requiring root:

扫描他们的数据库在给定INTERVALL的更简单的方法。

The easier way of scanning their database in a given intervall.

  • 易于实施。
  • 然而,并非电池效率
  • 同样的消息没有立即读出。

这是另一种方式是将运行具有root权限的服务并注册一个接收器,监听他们的推送通知。这必须以root做,因为这两个包需要接受他的推送通知的基于签名的权限。

An other way would be to run a service with root rights and register a receiver that listens for their push notifications. This has to be done with root, as both packages require a signature based permission for receiving their push notifications.

  • 很难实现
  • 在更好的用户体验

还有另一件事情来到我的脑海:有没有可能在安装后手动添加权限到APK?在这种情况下,我可以添加C2DM权限,以我的包。

Also another thing came to my mind: Would it be possible to manually add permissions to an APK after installing? In that case I could add the c2dm permissions to my package.

  • 这将会使事情变得非常容易
  • 不过,我有点害怕改变我的应用程序的权限,因为这完全是针对Android的沙箱原则。
  • 不过,如果有可能,让我知道!

现在的问题是,怎样的完全的做我执行root权限(它实际上是可能)服务? 我知道如何运行shell命令或二进制文件的根的,但我不知道如何开始APK为根的一部分。

The problem is, how exactly do I run a service with root rights (is it actually possible)? I know how to run shell commands or binaries with root, but I have no idea how to start a part of an APK as root.

另外,它有可能以一个BroadcastReceiver整合成二进制?其实我也用C / C ++的经验,尤其是在Android环境中。

Also, would it be possible to integrate a BroadcastReceiver into a binary? I have actually no experience with C/C++, especially in an android environment.

你能帮我吗? 谢谢。

Can you help me with that? Thanks.

编辑:就像我在注释中说,我不想使用AccesibilityService ,因为它不适合我的需要(例如,它会给我2封未读邮件,如果有一个以上未读,也不会包括全身)。

edit: Like I said in the comment, I do not want to use an AccesibilityService, as it does not fit my needs (eg it will give me "2 unread messages" if more then one is unread, also it does not include the full body).

EDIT2:只是为了澄清事情:我知道如何使用root身份运行命令。我需要知道的是如何注册一个BroadcastReceiver,它接收特定广播正常的接收器没有得到,因为广播本身需要一个基于签名同意,我没有。

edit2: Just to clarify things: I know how to run commands with root. What I need to know is how to register a Broadcastreceiver, that receives a specific broadcast "normal" receivers don't get, as the Broadcast itself requires a signature based permission I don't have.

推荐答案

这是远离微不足道,但应该工作的时候,你要监视使用SQLite数据库,或者更一般的,消息写入文件,当他们到达的应用程序。

This is far away from trivial but should work when the apps you want to monitor use sqlite databases or, more generic, write messages to a file when they arrive.

您确实需要有root访问设备,因为这违反了Android安全系统:

You will indeed need to have root access to the device as this violates the android security system:

写它与NDK的一个守护进程运行本机进程,并启动以root身份后一次产卵了。您现在已经3个主要的问题需要解决:

Write a native process which runs as a daemon with the NDK and spawn it once after boot as root. You have now 3 major problems to solve:

如何查出是否有变化?

这是比较容易的部分。您需要使用Linux的inotify的接口,它应该是accessable每一个Android手机上的SDK具有的 FileObserver 因为API 1,让您在保存在这里边。

This is the easy part. You would need to utilize the linux inotify interface which should be accessable on every android phone as the SDK has a FileObserver since API 1, so you are on the save side here.

另一个有趣的事情可能是赶上C2DM消息。我已经发现这被称为类NDK <一href="http://$c$c.google.com/p/android-cpp-sdk/source/browse/trunk/android-cpp-sdk/platforms/android-4/android/content/BroadcastReceiver.hpp?spec=svn52&r=52"相对=nofollow> BroadcastReceiver的,所以NDK可能能够赶上他们。但我个人不会做,感到不对劲偷意图。你也将不得不重新分配它们,或让他们前往真正的收件人,所以我不会详细描述这个在这里。它可以工作,但它可能是更难,应该只是一个备用的。

Another interesting thing may be to catch the C2DM messages. I have found a NDK class which is called BroadcastReceiver, so the NDK may be able to catch them. But I personally wouldn't do that, it feels wrong to steal intents. Also you would have to redistribute them or let them travel to real recipient, so I will not describe this in detail here. It may work, but it may be harder and should only be a fallback.

所以,当你已经解决了这个,接下来的问题就出现了:

So, when you have solved this, the next problem arises:

如何阅读改变保存方式?

您有一个问题,一个大的,在这里。该文件不属于你,你甚至不知道它在哪里(正常)的权利。所以被监控应用程序是不知道您和会像的文件是由它独有。如果他们使用一些普通的旧文本文件写邮件,你必须找到一种方式,从它读取安全,因为它可能会被覆盖或扩展在任何时间。但是,当他们使用SQLite,你是幸运的,根据此内容这是完全合法拥有更多不止一个读者的同时,仅仅只有一位作家。我们在规范,一切都很好了。如果你现在已经读出新的数据,更多的问题需要解决:

You have a problem, a big one, here. The file doesn't belong to you, you doesn't even have the right to know where it is (normally). So the monitored app is not aware of you and will act like the file is exclusively owned by it. If they use some plain old textfile to write messages to you have to find out a way to read from it safely as it may be overwritten or extended at any time. But you may be lucky when they use sqlite, according to this it's totally valid to have more than one simultaneous reader, just only one writer. We are in the specs, everything fine again. When you have now read out the new data, more problems to solve:

如何获得新的数据备份到主应用程序?

,因为它作为系统管理员身份运行,您应该做的只是最低限度在这个C / C ++程序。你也应该保护你的应用程序的用户的安全漏洞,所以请编写考虑到这一点的守护进程。我对这个没有真正的想法可以工作真的很好,但下面是其中一些:

You should do only the bare minimum in this c/c++ program because it runs as root. You should also protect your app users from security breaches, so please program the daemon with this in mind. I have no real idea for this could work really good, but here are some them:

  • 写收集的数据到您自己的SQLite数据库(容易在C / C ++和Java)
  • 写采集数据到一个纯文本文件(不推荐可言,痛在后)
  • 发送有意向其中包括新的数据(也许不是在C / C ++容易,但容易在Java)
  • 插座/管材/ ...,只要它是由Linux的赞助商每一个RPC机制,你能想象(相同的文件,不这样做)

如上文所述,请当你写这个后台程序,因为它是一个潜在的安全隐患要小心。此外,它可能很难,当你有没有关于C知识,要做到这一点/ C ++的一切,即使你已经写简单的程序,这应该是一个不平凡的任务。

As stated in the text above, please be careful when you write this daemon as it is a potential security hazard. Also it may be hard to do this when you have no knowledge about c/c++ at all, and even when you have written simple programs this should be a non trivial task.

在通过网络我的搜索,我发现这个NDK的C ++类我上面提到的。它可以在谷歌code 被发现。我与NDK,也没有与C ++包装没有任何经验,但是当你打算写这可能是值得一试。

On my search through the web I have found this NDK c++ classes I mentioned above. It can be found at google code. I have no experience with the NDK nor with the c++ wrapper but it may be worth a look when you plan to write this.

这篇关于以root权限运行的服务或具有根权限添加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆