编程技术分享平台

网站首页 > 技术教程 正文

flash_image刷机及(PIE) are supported问题解决(IDA反汇编)

xnh888 2024-10-22 18:08:48 技术教程 33 ℃ 0 评论

前 提

有root权限

打开手机的USB调式模式

bootloader模式下用fastboot刷机经常不成功

C:\tmp\fastboot>adb reboot bootloader

C:\tmp\fastboot>fastboot flash boot C:\tmp\gionee-f103_SV16\boot.img
Sending 'boot' (7004 KB)                           OKAY [  0.689s]
Writing 'boot'                                     FAILED (remote: 'download for partition 'boot' is not allowed
')
fastboot: error: Command failed

此时可用flash_image命令刷入试试(成功率低)。

将flash_image和将要刷入的boot.img传到手机sdcard目录下:

c:\tmp\fastboot>adb push c:/tmp/fastboot/flash_image11 /sdcard/flash_image
c:/tmp/fastboot/flash_image11: 1 file pushed. 0.2 MB/s (26172 bytes in 0.133s)

C:\tmp\fastboot>adb push C:\tmp\gionee-f103_SV16\boot.img /sdcard
C:\tmp\gionee-f103_SV16\boot.img: 1 fil...hed. 5.6 MB/s (7172096 bytes in 1.220s)

移动flash_image到/system/bin,改变属性和用户组:

1|root@GiONEE_GBL7319:/ # mount -rw -o remount /system
root@GiONEE_GBL7319:/sdcard # mv flash_image /system/bin/
root@GiONEE_GBL7319:/sdcard # chmod 755 /system/bin/flash_image
root@GiONEE_GBL7319:/sdcard # chown root.shell /system/bin/flash_image
root@GiONEE_GBL7319:/sdcard # ls -l /system/bin/fla*
-rwxr-xr-x root     shell       26172 2022-02-23 15:00 flash_image
-rwxr-xr-x root     shell       13968 2022-02-22 22:43 flash_image22

手机正常开机状态下刷机:

255|root@GiONEE_GBL7319:/sdcard # flash_image boot boot.img
刷recovery用:
255|root@GiONEE_GBL7319:/sdcard # flash_image recovery recovery.img

flash_image刷机时会遇到问题

only position independent executables (PIE) are supported

root@GiONEE_GBL7319:/sdcard # flash_image boot boot.img
error: only position independent executables (PIE) are supported.

解决方法

将/system/bin/linker从手机里下载到电脑:

C:\tmp\fastboot>adb pull /system/bin/linker c:/tmp/
/system/bin/linker: 1 file pulled. 5.2 MB/s (86664 bytes in 0.016s)

下载、安装、打开IDA反汇编软件,打开linker - 右键 - 选择“Text View” :

点击 “Text search” - 输入问题描述:

鼠标放在方框位置时会提示调用处的相关汇编命令:

相关内容上双击或右键 - 选择“Jump to Operand” 会跳到调用处:

触发错误信息的相关命令:

先了解几个汇编命令

  • CMP: 比较是否相等,相等时置Z标志为0
  • B: 无条件跳转到它后面的标签
  • BL: 无条件跳转到它后面的标签,跳转前将PC存入R14
  • BNE: Z标志位不等于0时,跳转到它后面的标签处
  • BEQ: Z标志位等于0时,跳转到它后面的标签处
  • BNE.W: W:word,指操作数大小2个字节,B:byte,一个字节,L:long,4个字节
  • NOP: 空指令(机器码0X00BF)
  • CBNZ Rn, label : Rn非零时跳转
  • CBZ Rn, label : Rn为零时跳转
.text:00002F4C                 CMP             R2, #3
.text:00002F4E                 BEQ             loc_2F60
.text:00002F50                 LDR             R1, =(aErrorOnlyPosit - 0x2F58) ; "error: only position independent execut"...
.text:00002F52                 MOVS            R0, #2
.text:00002F54                 ADD             R1, PC  ; "error: only position independent execut"...
.text:00002F56                 BL              __dl___libc_format_fd
.text:00002F5A                 MOV             R0, R5
.text:00002F5C
.text:00002F5C loc_2F5C                                ; CODE XREF: __dl___linker_init+230↑j
.text:00002F5C                 BL              __dl_exit
.text:00002F60
.text:00002F60 loc_2F60                                ; CODE XREF: __dl___linker_init+38E↑j
.text:00002F60                 LDR             R1, =(asc_96C7 - 0x2F6C) ; ":"
.text:00002F62                 MOV             R0, R10
.text:00002F64                 LDR             R2, =(__dl__ZL18g_ld_library_paths - 0x2F6E)

上面第1行:命令 CMP R2, #3

  • 地址是:0X00002F4C
  • 意思:比较寄存器R2与数字3的大小

上面第2行:命令 BEQ loc_2F60

  • 地址:00002F4E
  • loc_2F60是下面第12行的标签,地址为0X00002F60
  • 意思:第1行比较结果相等则跳转到标签loc_2F60处继续执行。否则显示错误并中断程序。

我们的目的是无条件跳转到loc_2F60处继续执行,用“B”汇编指令替换“BEQ”。

鼠标点到BEQ上,然后切换到“Hex View - 1" :

将07D0修改为07E0: “E”是跳转指令“B”的机器码编码格式的第28-31位

右击 - 选择“Edit...”:

右击 - 选择“Apply chages”:

Edit - Patch program - Apply Patches to input file... :

修改保存后再上传linker到手机的/system/bin/目录下,修改一下属性.

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表