`
quanminchaoren
  • 浏览: 911250 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Android安全和权限①----ShareUserId和文件访问(File Access)--Security and Permission

阅读更多

关于SharedUserId的总结:

 我们知道一般每个app都有一个唯一的linux user ID,则这样权限就被设置成该应用程序的文件只对该用户可见,只对该应用程序自身可见,而我们可以使他们对其他的应用程序可见,这会使我们用到 SharedUserId,也就是让两个apk使用相同的userID,这样它们就可以看到对方的文件。为了节省资源,具有相同ID的apk也可以在相同 的linux进程中进行(这儿需要注意,并不是一定要在一个进程里面运行),共享一个虚拟机。

我们可以建立两个application,分别为test_a和test_b,我们的目的就是让test_b访问test_a里面的文件或者是数据:具体做法如下

在test_a应用程序的包com.test1的manifest里面添加anroid:shareuserid=“com.test2”(注:这 儿test_a是被访的apk,so 加上这句  android:exported="false"说明它是私有的,然后会让shareuserid应用更有力)

具体内容如下:

  1. <? xml   version = "1.0"   encoding = "utf-8" ?>   
  2. < manifest   xmlns:android = "http://schemas.android.com/apk/res/android"   
  3.       package = "com.test1"   
  4.       android:sharedUserId = "com.test2"   
  5.       android:exported = "false"   
  6.       android:versionCode = "1"   
  7.       android:versionName = "1.0" >   
  8.     < application   android:icon = "@drawable/icon"   android:label = "@string/app_name" >   
  9.         < activity   android:name = ".TestAcitvity1"   
  10.                   android:label = "@string/app_name" >   
  11.             < intent-filter >   
  12.                 < action   android:name = "android.intent.action.MAIN"   />   
  13.                 < category   android:name = "android.intent.category.LAUNCHER"   />   
  14.             </ intent-filter >   
  15.         </ activity >   
  16.     </ application >   
  17.   
  18.   
  19. </ manifest >    

然后再应用程序test_b的包com.test2下的manifest.xml中添加anroid:shareuserid=“com.test2”

然后在test_b的TestActivity2中添加如下代码:

  1. private  Button.OnClickListener button_listener =  new  Button.OnClickListener() {  
  2.         public   void  onClick(View v) {  
  3.             Intent intent = new  Intent();  
  4.               
  5.             intent.setClassName("us.imnet.iceskysl.db" , "us.imnet.iceskysl.db.DBSharedPreferences" );  
  6.             //intent.setClassName("com.test1","com.test1.TestActivity1");   
  7.   
  8.               
  9.             startActivity(intent);  
  10.         }  
  11.     };  

这样就可以调整跳转,然后就可以运行。完整代码是:

  1. package  com.test2;  
  2.   
  3. import  android.app.Activity;  
  4. import  android.content.Intent;  
  5. import  android.os.Bundle;  
  6. import  android.view.View;  
  7. import  android.widget.Button;  
  8.   
  9. public   class  TestActivity2  extends  Activity {  
  10.     /** Called when the activity is first created. */   
  11.     @Override   
  12.     public   void  onCreate(Bundle savedInstanceState) {  
  13.         super .onCreate(savedInstanceState);  
  14.         setContentView(R.layout.main);  
  15.         find_and_modify_button();  
  16.     }  
  17.     private   void  find_and_modify_button(){  
  18.         Button change_test1 = (Button) findViewById(R.id.change_test1);  
  19.         change_test1.setOnClickListener(button_listener);  
  20. }  
  21.     private  Button.OnClickListener button_listener =  new  Button.OnClickListener() {  
  22.         public   void  onClick(View v) {  
  23.             Intent intent = new  Intent();  
  24.               
  25.             intent.setClassName("us.imnet.iceskysl.db" , "us.imnet.iceskysl.db.DBSharedPreferences" );  
  26.             //intent.setClassName("com.test1","com.test1.TestActivity1");   
  27.   
  28.               
  29.             startActivity(intent);  
  30.         }  
  31.     };  
  32. }  

运行结果是:从test_b的TestActivity1中进去,然后跳到TestActivity2中,这样可以读取到它里面的数据出来

文件访问:

可以通过getSharedPreferences(String, int) , openFileOutput(String, int) 或者 openOrCreateDatabase(String, int, SQLiteDatabase.CursorFactory) 创建一个新文件时, 你可以同时或分别使用 MODE_WORLD_READABLE MODE_WORLD_WRITEABLE 标志允许其它包读 / 写此文件。

下面是用getSharedPreferences(String, int) ,创建到文件,修改它的属性为MODE_WORLD_WRITEABLE 则看到它的文件权限的变化:

(补充):关于linux下面文件权限

第2~10个字符当中的每3个为一组,左边三个字符表示所有者权限,中间3个字符表示与所有者同一组的用户的权限,右边3个字符是其他用户的权限。这三个一组共9个字符,代表的意义如下:   
r(Read,读取):对文件而言,具有读取文件内容的权限;对目录来说,具有浏览目 录的权限。   
w(Write,写入):对文件而言,具有新增、修改文件内容的权限;对目录来说,具有删除、移动目录内文件的权限。   
x(eXecute,执行):对文件而言,具有执行文件的权限;对目录了来说该用户具有进入目录的权限。   
-:表示不具有该项权限

0
0
分享到:
评论

相关推荐

    Android Security- Attacks and Defenses

    Explaining the Android security model and architecture, the book describes Android permissions, including Manifest permissions, to help readers analyze applications and understand permission ...

    JAVA 2平台安全技术-结构,API设计和实现

    本书首先概述了计算机和网络安全概念并解释了Java安全模型,并在此基础上,详细描述了Java 2平台中新增加的许多安全结构方面的措施,同时对Java安全性的实施提出了使用指导,描绘了如何定制、扩展和精化安全结构以及...

    Java 2平台安全技术-结构,API设计和实现

    3.6.4 java.io.FilePermission 31 3.6.5 java.net.SocketPermission 33 3.6.6 java.security.BasicPermission 35 3.6.7 java.util.PropertyPermission 36 3.6.8 java.lang.RuntimePermission 37 3.6.9 java.awt....

    CommonsWare.The.Busy.Coders.Guide.to.Android.Development.Version.8.2.2017

    It will help you more quickly climb the Android learning curve, so you can create the “killer app” you’ve dreamed of…or perhaps just a quick-and-dirty application for you and your friends. ...

    Web Security.pdf

    Web attack techniques can be ...The popularity of dynamic scripting languages and insufficient cognition of web technologies on security issues in the early stages caused a lot of issues, such as the ...

    ICS delphixe10源码版

    ICS V9 is in early development and is planned to support Android. There are no current plans for ICS for iOS. Version Control repository: --------------------------- svn://svn.overbyte.be/ics or ...

    Beginning T-SQL with Microsoft SQL Server 2005 and 2008

    The SQL Server client tools must be installed on your desktop computer and the SQL Server relational database server must be installed on ...remote server with network connectivity and permission to access....

    Programming Excel With Vba And .net.chm

    Macros and Security Section 1.9. Write Bug-Free Code Section 1.10. Navigate Samples and Help Section 1.11. What You've Learned Chapter 2. Knowing the Basics Section 2.1. Parts of a Program ...

    Linux FTP服务配置

    最终权限等于配置文件中的权限和linux文件系统权限相或的结果。比如vsftp配置文件中允许匿名用户下载,但光这样是不够的,还需要被下载的文件或文件夹的能够被其他用户读取。 尝试上传文件失败,符合匿名用户只允许...

    (重要)AIX command 使用总结.txt

    #如何取定文件与文件集的对应关系,有时想使用某个安装文件, 但没有安装包含该文件的文件集,找到文件集来安装所需文件 首先确认系统中已经安装了“bos.content_list”文件集(fileset), 如果没有安装, 请使用smitty ...

    NewSID(光学习一下代码就可以了,没看清楚介绍别运行)

    It also has been updated to change SIDs associated with the permission settings of file and printer shares. Cloning and Alternate Rollout Methods One of the most popular ways of performing mass ...

    windowsnt 技术内幕

    Windows NT组简介 理解用户权限和组的访问权限 理解用户和组的权利 分清权限(permission)和权利(right) 设置组成成员关系 理解全局帐号 理解本地帐号 定义Everyone组 Network组的详细说明 Inteactive组的详细说明 ...

    a project model for the FreeBSD Project.7z

    Committers fall into three groups: committers who are only concerned with one area of the project (for instance file systems), committers who are involved only with one sub-project and committers who ...

    Professional C# 3rd Edition

    The Security Configuration File 419 Managing Code Groups and Permissions 423 Turning Security On and Off 423 Resetting Security Policy 423 Creating a Code Group 423 Deleting a Code Group 424 Changing ...

    PROGRAMMING ACTIONSCRIPT 3.0

    About this manual 13 Using this manual..14 Accessing ActionScript documentation15 ActionScript learning resources.. 17 ...Camera, microphone, clipboard, mouse, and keyboard access.794

    cuteEditor6.0

    You can also create your own policy files that define arbitrary permission sets. &lt;br/&gt;Comparison of the sample security policy file &lt;br/&gt; Permissions/Resource Setting Admin Default ...

    VB.NET Developer's Guide(4574).pdf

    Declarative and Imperative Security 564 Requesting Permissions 565 Demanding Permissions 570 Overriding Security Checks 572 Custom Permissions 576 Role-Based Security 578 Principals 578 ...

    windows上传文件到虚拟机的hdfs上

    org.apache.hadoop.security.AccessControlException: Permission denied: user=ASUS, access=WRITE, inode 今天在windows连接虚拟机的hdfs,通过IDEA上传文件到虚拟机的hdfs上,出现了权限不足问题,原因是以...

    Wi-Fi_Simple_Configuration_Technical_Specification_v2-0

    4.3 Security Overview ................................................................................................ 22 4.3.1 In-band Configuration .....................................................

    pro_apache_third_edition..pdf

    About the Technical Reviewer and Contributing Author.................xxi Chapter1 Apache and the Internet..............................................1 Apache: The Anatomy of a Web Server...............

Global site tag (gtag.js) - Google Analytics