今天提取线刷包的system.img出来,使用Mount命令挂载

$ sudo mount -t ext4 -o loop system.img /mnt
mount: 文件系统类型错误、选项错误、/dev/loop0 上有坏超级块、
缺少代码页或助手程序,或其他错误 有些情况下在 syslog 中可以找到一些有用信息- 请尝试
dmesg | tail 这样的命令看看。

这坑爹死了。。于是想了个办法把ext4转为yaffs2格式,使用simg2img.py,脚本在博文最下面

$ ./simg2img.py system.img

等待转换完成,当前目录下就会出现一个tmp.img,然后我们就可以挂载了!

$ mkdir tmp
$ sudo mount tmp.img tmp

我需要提取system.img里面文件,所以复制一份出来,然后卸载tmp.img的挂载

$ sudo cp -r tmp system
$ sudo umount tmp

最后递归修改提取出来的文件用户就可以了!

$ sudo chown -R michellgaby system

这样就大功告成了!!下面是ext4转换为yaffs2的脚本

#!/usr/bin/env python
#encoding:utf8
#===============================================================================
#
# FILE: simg2img.py
#
# USAGE: ./simg2img.py system.img
#
# DESCRIPTION:
#
# AUTHOR: Karl Zheng
# COMPANY: Meizu
# CREATED: 2011年10月18日 15时25分15秒 CST
# REVISION: ---
#=============================================================================== import sys
import struct class ext4_file_header:
def __init__(self, buf):
self.magic, \
self.major, \
self.minor, \
self.file_header_size, \
self.chunk_header_size, \
self.block_size, \
self.total_blocks, \
self.total_chunks, \
self.crc32, \
= struct.unpack('<IHHHHIIII', buf) class ext4_chunk_header:
def __init__(self, buf):
self.type,\
self.reserved,\
self.chunk_size,\
self.total_size,\
= struct.unpack('<HHII', buf) if len(sys.argv) > 1:
filename = sys.argv[1]
else:
print "No file is designated!!"
sys.exit(1)
ifd = open(filename, "rb") buf="" # get filelen
ifd.seek(0, 2)
file_len = ifd.tell()
print file_len
ifd.seek(0, 0) buf = ifd.read(28)
#print repr(buf)
file_header = ext4_file_header(buf) EXT4_FILE_HEADER_MAGIC = 0xED26FF3A
EXT4_CHUNK_HEADER_SIZE = 12 if file_header.magic != EXT4_FILE_HEADER_MAGIC:
print "Not a compressed ext4 file!!"
sys.exit(1) print "file_header chunks:%X"%(file_header.total_chunks) total_chunks = file_header.total_chunks
print("total chunk = %d "%(total_chunks)) ofd = open("tmp.img", "wb") sector_base = 82528
output_len = 0 while total_chunks > 0:
buf = ifd.read(EXT4_CHUNK_HEADER_SIZE)
chunk_header = ext4_chunk_header(buf)
sector_size = (chunk_header.chunk_size * file_header.block_size) >> 9;
#print "ct:%X, cs:%X, ts:%X, ss:%X"%(chunk_header.type, chunk_header.chunk_size, chunk_header.total_size, sector_size) data = ""
if chunk_header.type == 0xCAC1: # raw type
data = ifd.read(chunk_header.total_size - EXT4_CHUNK_HEADER_SIZE)
if len(data) != (sector_size << 9):
print("len data:%d, sector_size:%d"%(len(data), (sector_size << 9)))
sys.exit(1)
else:
print ("len data:%d, sector_size:%d"%(len(data), sector_size << 9))
ofd.write(data)
output_len += len(data)
print("raw_chunk ")
print("write raw data in %d size %d \n"%(sector_base, sector_size))
print("output len:%x"%(output_len)) sector_base += sector_size
else:
if chunk_header.type == 0xCAC2: # TYPE_FILL
data = '\0' * (sector_size << 9);
ofd.write(data)
output_len += len(data)
print("fill_chunk \n")
print("chunk_size:%x"%(chunk_header.chunk_size))
print("output len:%x"%(output_len))
sector_base += sector_size
else:
if chunk_header.type == 0xCAC3: # TYPE_DONT_CARE
print "none chunk at chunk:%d"%(file_header.total_chunks - total_chunks)
print("data_size:0x%x, chunk_size:%d, block_size:%d"%(sector_size << 9, chunk_header.chunk_size, file_header.block_size))
data = '\0' * (sector_size << 9);
ofd.write(data)
output_len += len(data)
sector_base += sector_size
else:
data = '\0' * (sector_size << 9);
ofd.write(data)
print "unknown type!!"
output_len += len(data)
print("output len:%x"%(output_len))
sector_base += sector_size total_chunks -= 1
print("remain chunks = %d "%(total_chunks)); print "write done" ifd.close()
ofd.close()

挂载system.img并提取文件的更多相关文章

  1. 管理员技术(三): 配置静态网络地址、 使用yum软件源 、 升级Linux内核、查找并处理文件、查找并提取文件内容

    一. 配置静态网络地址 目标: 本例要求为虚拟机 server 配置以下静态地址参数: 1> 主机名:server0.example.com    2> IP地址:172.25.0.11  ...

  2. log4net 中错误 System.Web.HttpException (0x80004005): 文件不存在

    用日志组件,Global 中配置的输出最后一个错误信息,总是出现下面的错误信息: 2014-04-01 14:35:41,757 级别:ERROR 信息:[Exception]:System.Web. ...

  3. php读取zip文件(删除文件,提取文件,增加文件)实例

    <?php /* php 从zip压缩文件中提取文件 */ $zip = new ZipArchive; if ($zip->open('jQuery五屏上下滚动焦点图代码.zip') = ...

  4. python提取文件中的方法名称

    #提取文件中的方法名称 # -*- coding:utf-8 -*- def Query_Method(filepath): file = open(filepath,'r',encoding= 'U ...

  5. C# System.IO和对文件的读写操作

      System.IO命名空间中常用的非抽象类 BinaryReader 从二进制流中读取原始数据 BinaryWriter 从二进制格式中写入原始数据 BufferedStream 字节流的临时存储 ...

  6. shell提取文件后缀名,并判断其是否为特定字符串

    如果文件是 .css文件 或 .js文件,则进行处理. file=$1 if [ "${file##*.}"x = "css"x ]||[ "${fi ...

  7. [Oracle]System 表空间的文件丢失

    如果system 表空间的文件丢失,假设有备份的情况,可以恢复.数据库需要设置为mount 状态,然后restore/recover datafile 模拟实验: SQL> select nam ...

  8. shell 切分文件名提取文件扩展名或提取文件名

    有些脚本要根据文件名进行各种处理,有时候需要保留文件名抛弃文件后缀,也有时候需要文件后缀不要文件名,这类提取文件部分的操作使用shell的内建功能就能实现.需要用到的几个操作符有:%.%%.#.##. ...

  9. 三.Shell脚本提取文件名称和所在的目录

    一·简介 提取文件名称或者目录,一般都会使用到#,##,%和%%,但是他们的区别很容易记混淆了.在一下4种方式中,目标匹配字符是不在结果中. #:表示从左开始算起,并且截取第一个匹配的字符 ##:表示 ...

随机推荐

  1. 这些Android系统样式中的颜色属性你知道吗?

    Android 系统样式中的颜色属性 推荐阅读看完后彻底搞清楚Android中的 Attr . Style .Theme 几个常用的颜色属性 先放上一张经典的图片,图片来自网络. 这张图在网上很是流传 ...

  2. 使用VSCode创建一个Vue项目

    vue-cli 是vue.js的脚手架,用于自动生成vue.js模板工程的. 安装vue-cli之前,需要先安装了vue和webpack · node -v          //(版本低引起:bas ...

  3. SQL Server查询数据库近期执行的SQL语句

    SELECT TOP 1000        ST.text AS '执行的SQL语句',       QS.execution_count AS '执行次数',       QS.total_ela ...

  4. CSS .css边框属性(border)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. CodeForces 862B(思维+二分图染色)

    题意 https://vjudge.net/problem/CodeForces-862B 给出n个点,n-1条边,求再最多再添加多少边使得二分图的性质成立 思路 因为题目是求的最多添加多少边,所以可 ...

  6. Codeforces Round #594 (Div. 2)

    传送门 C. Ivan the Fool and the Probability Theory 题意: 给出一个\(n*m\)的方格,现在要给方格中的元素黑白染色,要求任一颜色最多有一个颜色相同的格子 ...

  7. Python学习一、一个小例子

    一.题目: 对于一串氨基酸序列(由字母表前二十个大写字母组成),需要得到每一个氨基酸数目,然后输出到文件夹D:\test\frq.txt,要求用循环和字典实现. 氨基酸序列如下: ABCDEFGHIJ ...

  8. Day5- Python基础5 模块导入、time、datetime、random、os、sys、hashlib、json&pickle

    本节目录: 1.模块的分类 2.模块的导入 3.time模块 4.datetime模块 5.random 6.os模块 7.sys模块 8.hashlib 9.json&pickle 一.模块 ...

  9. 剑指Offer-30.连续子数组的最大和(C++/Java)

    题目: HZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学.今天测试组开完会后,他又发话了:在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解决.但是,如果向量中 ...

  10. C语言中,字符型数字与常数型数字的加减实现

    char in-str[10],out-str[10]; for(int i=0;i<10;i++) { out-str[i]=9-(in-str[i]-'0')+'0'; }