qemu模拟armlinux执行目标文件系统的可执行文件

--------------------以下是2020年更新的内容

不需要自己编译qemu,直接apt安装一个静态编译版本的qemu
apt install qemu-user-static

进入解包的arm固件root,并复制一个qemu副本
cd ~/squashfs-root
cp /usr/bin/qemu-arm-static ./

chroot切换root模式运行qemu-arm-static,并模拟运行rootfs的/usr/bin/lua
chroot . ./qemu-arm-static /usr/bin/lua
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio (double int32) security
>

成功了

--------------------以下是第一次写的内容

squashfs
yum install -y xz-devel
wget https://jaist.dl.sourceforge.net/project/squashfs/squashfs/squashfs4.3/squashfs4.3.tar.gz
tar xzvf squashfs4.3.tar.gz
cd squashfs4.3/squashfs-tools
vi Makefile
有一些support是可以打开的例如 LZMA1 LZMA2之类的
make
make install


cd ~/
unsquash rootfs.bin
cd squash-root
cp /usr/local/bin/qemu-arm* ./


[root@centos squashfs-root]# ./bin/aescrypt2 
-bash: ./bin/aescrypt2: cannot execute binary file
[root@centos squashfs-root]# chroot . ./qemu-arm ./bin/aescrypt2 


  aescrypt2 <mode> <input filename> <output filename>


  <mode>: 0 = encrypt, 1 = decrypt


  example: aescrypt2 0 file file.aes

很屌。。qemu模拟了armlinux环境执行了这个嵌入式文件系统的elf可执行文件

 

 



下面是mount jffs2文件系统的脚本 mountjffs2.sh
#!/bin/bash


## Script to mount jffs2 filesystem using mtd kernel modules.
## EMAC, Inc. 2009


if [[ $# -lt 2 ]]
then
    echo "Usage: $0 FSNAME.JFFS2 MOUNTPOINT [ERASEBLOCK_SIZE]"
    exit 1
fi


if [ "$(whoami)" != "root" ]
then
    echo "$0 must be run as root!"
    exit 1
fi


if [[ ! -e $1 ]]
then
    echo "$1 does not exist"
    exit 1
fi


if [[ ! -d $2 ]]
then
    echo "$2 is not a valid mount point"
    exit 1
fi


if [[ "$3" == "" ]]
then
        esize="128"
else
        esize="$3"
fi


# cleanup if necessary
umount /dev/mtdblock0 &>/dev/null
modprobe -r mtdram &>/dev/null
modprobe -r mtdblock &>/dev/null


modprobe mtdram total_size=32768 erase_size=$esize || exit 1
modprobe mtdblock || exit 1
dd if="$1" of=/dev/mtdblock0 || exit 1
mount -t jffs2 /dev/mtdblock0 $2 || exit 1


echo "Successfully mounted $1 on $2"
exit 0




[root@centos ~]# ./mountjffs2.sh 
Usage: ./mountjffs2.sh FSNAME.JFFS2 MOUNTPOINT [ERASEBLOCK_SIZE]
[root@centos ~]# mkdir /mnt/jffs2
[root@centos ~]# ./mountjffs2.sh  file_system.img  /mnt/jffs2 128
3072+0 records in
3072+0 records out
1572864 bytes (1.6 MB) copied, 0.0215566 s, 73.0 MB/s
Successfully mounted file_system.img on /mnt/jffs2


[root@centos squashfs-root]# cp /mnt/jffs2/hw_ctree.xml ./hw_ctree.xml.gz
[root@centos squashfs-root]# chroot . ./qemu-arm ./bin/aescrypt2 1 ./hw_ctree.xml.gz ./tmpfile
[root@centos squashfs-root]# gunzip hw_ctree.xml.gz 
[root@centos squashfs-root]# cat hw_ctree.xml

QEMU 1.2.0 编译好的可执行程序,可以直接运行于windows平台,可以模拟各种硬件平台,例如ARM,X86,Sparc,PPC,MIPS等等。下面是文件列表 2012-09-20 00:18 3,211 bamboo.dtb 2012-09-20 00:18 131,072 bios.bin 2012-09-20 00:18 4,335 cpus-x86_64.conf 2012-09-20 00:18 keymaps 2012-09-20 00:18 9,216 kvmvapic.bin 2012-09-20 00:18 1,024 linuxboot.bin 2012-09-20 00:18 1,024 multiboot.bin 2012-09-20 00:18 729,908 openbios-ppc 2012-09-20 00:18 381,764 openbios-sparc32 2012-09-20 00:18 1,598,648 openbios-sparc64 2012-09-20 00:18 185,703 palcode-clipper 2012-09-20 00:18 9,982 petalogix-ml605.dtb 2012-09-20 00:18 8,259 petalogix-s3adsp1800.dtb 2012-09-20 00:18 524,288 ppc_rom.bin 2012-09-20 00:18 67,072 pxe-e1000.rom 2012-09-20 00:18 61,440 pxe-eepro100.rom 2012-09-20 00:18 61,440 pxe-ne2k_pci.rom 2012-09-20 00:18 61,440 pxe-pcnet.rom 2012-09-20 00:18 61,440 pxe-rtl8139.rom 2012-09-20 00:18 60,416 pxe-virtio.rom 2012-09-20 00:18 281,956 qemu-doc.html 2012-09-20 00:18 630 qemu-icon.bmp 2012-09-20 00:18 1,565,705 qemu-img.exe 2012-09-20 00:18 1,589,020 qemu-io.exe 2012-09-20 00:18 2,292,224 qemu-system-alpha.exe 2012-09-20 00:18 3,225,088 qemu-system-arm.exe 2012-09-20 00:18 1,677,312 qemu-system-cris.exe 2012-09-20 00:18 3,100,160 qemu-system-i386.exe 2012-09-20 00:19 1,628,160 qemu-system-lm32.exe 2012-09-20 00:19 2,105,344 qemu-system-m68k.exe 2012-09-20 00:19 1,631,744 qemu-system-microblaze.exe 2012-09-20 00:19 1,631,232 qemu-system-microblazeel.exe 2012-09-20 00:19 3,080,192 qemu-system-mips.exe 2012-09-20 00:19 3,257,344 qemu-system-mips64.exe 2012-09-20 00:19 3,269,120 qemu-system-mips64el.exe 2012-09-20 00:19 3,078,656 qemu-system-mipsel.exe 2012-09-20 00:19 1,601,536 qemu-system-or32.exe 2012-09-20 00:19 3,416,576 qemu-system-ppc.exe 2012-09-20 00:19 3,948,032 qemu-system-ppc64.exe 2012-09-20 00:19 3,411,456 qemu-system-ppcemb.exe 2012-09-20 00:19 1,839,104 qemu-system-s390x.exe 2012-09-20 00:19 2,116,608 qemu-system-sh4.exe 2012-09-20 00:19 2,118,144 qemu-system-sh4eb.exe 2012-09-20 00:19 1,843,712 qemu-system-sparc.exe 2012-09-20 00:19 2,611,200 qemu-system-sparc64.exe 2012-09-20 00:19 1,591,296 qemu-system-unicore32.exe 2012-09-20 00:18 3,273,728 qemu-system-x86_64.exe 2012-09-20 00:19 1,644,544 qemu-system-xtensa.exe 2012-09-20 00:19 1,637,376 qemu-system-xtensaeb.exe 2012-09-20 00:18 28,474 qemu-tech.html 2012-09-20 00:18 49,841 qmp-commands.txt 2012-09-20 00:18 3,304 s390-zipl.rom 2012-09-20 00:21 303,616 SDL.dll 2012-09-20 00:18 4,096 sgabios.bin 2012-09-20 00:18 878,640 slof.bin 2012-09-20 00:18 20 spapr-rtas.bin 2012-09-20 00:18 0 target-x86_64.conf 2012-09-20 00:18 35,840 vgabios-cirrus.bin 2012-09-20 00:18 40,448 vgabios-qxl.bin 2012-09-20 00:18 40,448 vgabios-stdvga.bin 2012-09-20 00:18 40,448 vgabios-vmware.bin 2012-09-20 00:18 40,448 vgabios.bin
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值