#ifdef _WIN32
#define __USE_MINGW_ANSI_STDIO 1
#endif #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#ifdef HAS_STDINT_H
#include <stdint.h>
#endif
#ifdef unix
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#else
#include <direct.h>
#include <io.h>
#endif #define MAGIC 0xF97CFF8A #define S_IFMT 00170000
#define S_IFSOCK 0140000
#define S_IFLNK 0120000
#define S_IFREG 0100000
#define S_IFBLK 0060000
#define S_IFDIR 0040000
#define S_IFCHR 0020000
#define S_IFIFO 0010000
#define S_ISUID 0004000
#define S_ISGID 0002000
#define S_ISVTX 0001000 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) char *mode_to_string(unsigned int mode)
{
if (S_ISBLK(mode))
return "-b";
else if (S_ISCHR(mode))
return "-c";
else if (S_ISDIR(mode))
return "-d";
else if (S_ISFIFO(mode))
return "-p";
else if (S_ISLNK(mode))
return "-l";
else if (S_ISSOCK(mode))
return "-s";
else if (S_ISREG(mode))
return "--";
else
return "";
} int main(int argc, char *argv[])
{
unsigned int selinux_vers;
unsigned int nothing;
unsigned int i;
unsigned int steams;
unsigned int num_of_regex; char steam[];
char src[];
char context[]; FILE *fp = NULL;
FILE *fpout = NULL; if (argc != ) {
printf("usage: %s BINARY_FILE OUTPUT_TEXT_FILE\n", argv[]);
printf("e.g: %s file_contexts.bin file_contexts\n", argv[]);
return ;
} if ((fp = fopen(argv[], "rb")) == NULL) {
printf("Unable to open %s : ", argv[]);
perror("");
return ;
}
fread(&nothing, , , fp);
if (nothing != MAGIC) {
printf("%s is not a binary!\n", argv[]);
if (fp) fclose(fp);
return ;
} fread(&nothing, , , fp);
selinux_vers = nothing;
fread(&nothing, , , fp);
fseek(fp, (unsigned int)ftell(fp) + nothing, SEEK_SET); fread(&nothing, , , fp);
//printf("num of steams: 0x%x\n", nothing); for (i=; i<nothing; ++i) {
fread(&steams, , , fp);
fread(steam, , steams+, fp);
//printf("%s\n", steam);
} fread(&num_of_regex, , , fp);
//printf("num of regex: 0x%x\n", num_of_regex); if ((fpout = fopen(argv[], "wb")) == NULL) {
printf("unable to open %s for write!\n", argv[]);
if (fp) fclose(fp);
return ;
} //printf("selinux version: %d\n", selinux_vers);
fprintf(fpout, "#context version %d\n", selinux_vers); for (i=; i<num_of_regex; ++i) {
fread(&nothing, , , fp);
fread(context, , nothing, fp);
fread(&nothing, , , fp);
fread(src, , nothing, fp);
//printf("%s %s\n", src, context);
fread(&nothing, , , fp);
fprintf(fpout, "%s\t%s\t%s\n", src, mode_to_string(nothing), context);
fseek(fp, (unsigned int)ftell(fp) + , SEEK_SET);
fread(&nothing, , , fp);
fseek(fp, (unsigned int)ftell(fp) + nothing, SEEK_SET);
fread(&nothing, , , fp);
fread(&nothing, , , fp);
fseek(fp, (unsigned int)ftell(fp) + nothing - , SEEK_SET);
} if (fp) fclose(fp);
if (fpout) fclose(fpout); return ;
}

Android系统file_contexts二进制与文本转换工具的更多相关文章

  1. 我的Android进阶之旅------>Java文件大小转换工具类 (B,KB,MB,GB,TB,PB之间的大小转换)

    Java文件大小转换工具类 (B,KB,MB,GB,TB,PB之间的大小转换) 有时候要做出如下所示的展示文件大小的效果时候,需要对文件大小进行转换,然后再进行相关的代码逻辑编写. 下面是一个Java ...

  2. Json:Java对象和Json文本转换工具类

    Json 是一个用于 Java 对象 和 Json 文本 相互转换的工具类. 安装 下载源码 git clone https://github.com/njdi/durian.git 编译源码 cd ...

  3. android px,dp,sp大小转换工具

    package com.voole.playerlib.util; import android.content.Context; /** * Android大小单位转换工具类<br/> ...

  4. Android 系统API实现数据库的增删改查和SQLite3工具的使用

    在<Android SQL语句实现数据库的增删改查>中介绍了使用sql语句来实现数据库的增删改查操作,本文介绍Android 系统API实现数据库的增删改查和SQLite3工具的使用. 系 ...

  5. android的二进制和十六进制的相互转换工具类(一):

    二进制和十六进制的相互转换工具类: package com.gzcivil.utils; public class BinStr { /** * 将二进制转换成16进制 * @param buf * ...

  6. Android Bitmap与DrawAble与byte[]与InputStream之间的转换工具类【转】

    package com.soai.imdemo; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; ...

  7. 【安卓本卓】Android系统源码篇之(一)源码获取、源码目录结构及源码阅读工具简介

    前言        古人常说,“熟读唐诗三百首,不会作诗也会吟”,说明了大量阅读诗歌名篇对学习作诗有非常大的帮助.做开发也一样,Android源码是全世界最优秀的Android工程师编写的代码,也是A ...

  8. Android 系统工具类

    系统工具类 public class systemUtil { //隐藏ipad底部虚拟按键栏 @RequiresApi(api = Build.VERSION_CODES.KITKAT) publi ...

  9. Android系统源代码——所需工具

    一.概述 众所周知,Android移动操作系统是Google花费了很大的财力.物力及人力的前提下,推广到世界各个角落,以开放源代码的方式(当然也不是完全开放所有),使其在世界范围内迅速漫延开来,到目前 ...

随机推荐

  1. rabbit:Mnesia could not connect to any nodes

    环境: rabbitmq集群   2台机器,挂了一台后重启服务,发现在服务启动不了错误如下: 这里rabbit连接不商rabbit02这里这个服务也无法启动 解决办法: rabbitmq默认的数据库位 ...

  2. 关于PyCharm database查看db.sqlites文件无内容的一种可能解决方法

    初学python,学到了scrapy爬虫数据入库,在网上跟着一个视频课进行学习,但是碰到了如下问题: 这里新建了数据库文件之后,将这个.sqlite文件拖动到Database里面,然后出现了上图描述问 ...

  3. vijos p1768 数学

    链接:点我 预处理:b[i][j]表示a[1] ... a[j]中比a[i]小的数的数量. 设 int get_lower_count(int b[], int l, int r) { return ...

  4. the elements of computing systems 的读书笔记1

    想转职程序猿,还真不是说懂一门语言就够的了,想要继续进步,必须懂其相关实现原理,比如这些底层的构造.最近看的就是这一本计算机入门级的书,但是对我这个纯自学的人来说真是能学到很多. 这本书从最基本的Na ...

  5. NSAttributedString描述

    字符属性 字符属性可以应用于 attributed string 的文本中. NSString *const NSFontAttributeName;(字体) NSString *const NSPa ...

  6. SQLite3知识(1)--教程

    1.SQLite3教程 [1].SQLite 教程 2.选择数据库: [2]. SQLite Select 语句 3.更新数据库: [3]. SQLite Update 语句 4.插入数据库: [4] ...

  7. Git_删除文件

    在Git中,删除也是一个修改操作,我们实战一下,先添加一个新文件test.txt到Git并且提交: $ git add test.txt $ git commit -m "add test. ...

  8. Centos安装Perforce

    Author: JinDate: 20140827System: CentOS release 6.5 (Final) 参考:http://www.cnblogs.com/itech/archive/ ...

  9. 忘记Oracle系统管理员sys的密码

    sqlplus / as sysdba; alter user sys identified by newpwd***;

  10. 【scrapy】使用方法概要(一)(转)

    [请初学者作为参考,不建议高手看这个浪费时间] 工作中经常会有这种需求,需要抓取互联网上的数据.笔者就经常遇到这种需求,一般情况下会临时写个抓取程序,但是每次遇到这种需求的时候,都几乎要重头写,特别是 ...