剖析andriod联系人(SQLITE3)应用

在android里面大量用到了sqlite3数据库存储数据,我们的联系人,通话记录,分类,缩略图像都是存放在

/data/data/com.android.providers.contacts/databases/contacts.db

这个文件里面

我现在带大家仔细研究下这个文件。问了防止误操作,我们把这个文件单独拷出来。
adb shell //进入到手机shell里面
cp /data/data/com.android.providers.contacts/databases/contacts.db / //把contacts.db拷贝到根目录
sqlite3 contacts.db // 加载数据库

sqlite> .help
.help
.bail ON|OFF Stop after hitting an error. Default OFF
.databases List names and files of attached databases
.dump ?TABLE? ... Dump the database in an SQL text format
.echo ON|OFF Turn command echo on or off
.exit Exit this program
.explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
.header(s) ON|OFF Turn display of headers on or off
.help Show this message
.import FILE TABLE Import data from FILE into TABLE
.indices TABLE Show names of all indices on TABLE
.load FILE ?ENTRY? Load an extension library
.mode MODE ?TABLE? Set output mode where MODE is one of:
csv Comma-separated values
column Left-aligned columns. (See .width)
html HTML <table> code
insert SQL insert statements for TABLE
line One value per line
list Values delimited by .separator string
tabs Tab-separated values
tcl TCL list elements
.nullvalue STRING Print STRING in place of NULL values
.output FILENAME Send output to FILENAME
.output stdout Send output to the screen
.prompt MAIN CONTINUE Replace the standard prompts
.quit Exit this program
.read FILENAME Execute SQL in FILENAME
.schema ?TABLE? Show the CREATE statements
.separator STRING Change separator used by output mode and .import
.show Show the current values for various settings
.tables ?PATTERN? List names of tables matching a LIKE pattern
.timeout MS Try opening locked tables for MS milliseconds
.timer ON|OFF Turn the CPU timer measurement on or off
.width NUM NUM ... Set column widths for "column" mode


.help可以获取详细的帮助信息,这里列出了很多常用的命令,包括数据库的加载,导入导出,设置输出宽度,格里夫,查看表和备份数据等命令

sqlite> .table
.table
_deleted_groups contact_methods peopleLookup
_deleted_people extensions phones
_sync_state groupmembership photos
_sync_state_metadata groups settings
android_metadata organizations voice_dialer_timestamp
calls people


这里我们能得到很多有用的信息,首先我们知道这个数据库里面有一系列的表,包括通话记录,联系人,缩略图像(以base64编码的),联系人组,铃声设置,语音拨号,同步状态,删除组和删除联系人等等。大学学过数据库的同学应该都熟悉基本的sql语句吧,这里我们可以通过DML来管理数据,select查询update更新delete删除

sqlite> select * from phones;
select * from phones;
1045|1032|2|15916266xxx|87066261951||1
1046|1033|2|02366525xxx|31352566320||1
1047|1034|2|10607138926xxx|68462983170601||1
1048|1035|2|13002329xxx|86892320031||1
1049|1036|2|13476483xxx|82938467431||1
1050|1037|2|02366685xxx|95158666320||1
1051|1038|2|07132694xxx|70649623170||1
1052|1039|2|15971371xxx|75117317951||1
1053|1040|2|13117151xxx|03215171131||1


这里查询到了所有联系人电话信息,熟悉数据库的朋友肯定知道,这里还关联了其他的表

sqlite> select * from calls;
select * from calls;
1|15823506xxx|1251703788223|33|1|1|鑼?鐜瞸2|
2|13167870xxx|1251713299121|0|2|1||0|
3|13167870xxx|1251713377134|0|2|1||0|
4|13167870xxx|1251713713422|0|2|1||0|
5|13167870xxx|1251713771272|0|2|1||0|
6|13167870xxx|1251713865558|0|2|1||0|
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值