如何向 ARM 固件添加新语言

逆向工程 二元分析 固件
2021-07-05 00:09:02

我有一个固件(从这里下载),我需要访问它的文件系统。

这是binwalk扫描的输出

root@kali:~/Desktop/E1200YDXNB1_OLAANB1# binwalk --dd=".*" ps.bin
DECIMAL       HEXADECIMAL     DESCRIPTION
108542        0x1A7FE         Unix path: /source/base/src/doidleonpage.c
172162        0x2A082         Unix path: /source/efs/src/efs_item.c
215976        0x34BA8         Unix path: /Layer1/source/c/datacnfproc.c
309012        0x4B714         Unix path: /Layer1/source/c/systeminfo.c
747043        0xB6623         MySQL ISAM index file Version 4
763097        0xBA4D9         Minix filesystem, V1, little endian, 4 zones
763641        0xBA6F9         Minix filesystem, V1, little endian, 8192 zones
796248        0xC2658         MySQL ISAM compressed data file Version 2
801115        0xC395B         MySQL MISAM index file Version 3
819081        0xC7F89         MySQL MISAM compressed data file Version 9
821756        0xC89FC         MySQL MISAM index file Version 7
825421        0xC984D         MySQL MISAM index file Version 5
842282        0xCDA2A         MySQL ISAM index file Version 10
864884        0xD3274         Unix path: /source/src/c/sci_mem.c
870088        0xD46C8         Unix path: /source/src/c/threadx_os.c
882552        0xD7778         Unix path: /source/src/c/sci_log.c
887232        0xD89C0         Unix path: /source/src/c/threadx_appmem.c
1350524       0x149B7C        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
2244000       0x223DA0        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
2246600       0x2247C8        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
2251808       0x225C20        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
2254368       0x226620        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
2256964       0x227044        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
2259516       0x227A3C        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
2262096       0x228450        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
2266940       0x22973C        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
2269388       0x22A0CC        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
2271928       0x22AAB8        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
2274460       0x22B49C        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
3425084       0x34433C        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
3535408       0x35F230        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
3535448       0x35F258        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
3535488       0x35F280        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
3536360       0x35F5E8        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
3555612       0x36411C        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
3814428       0x3A341C        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes
3818348       0x3A436C        LZMA compressed data, properties: 0x5A, dictionary size: 16777216 bytes, uncompressed size: 4096 bytes

如您所见,有两个文件被binwalk检测为 Minix 文件系统。

但是,当我尝试像这样挂载这些文件时mount -t minix BA6F9 test/,会导致错误:

wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error

我的问题是如何挂载或提取此文件系统?

我编辑了有关我的项目的更多详细信息的问题:

我的目标是在这个固件中添加希伯来语。

所以,我找到了一个可以将字符串编辑为希伯来语的工具,但我仍然有两个问题。

首先,这个固件的字体不支持希伯来字母。

其次,希伯来语是RTL语言,所以我需要将这种语言的设置编辑为RTL。

关于字体,我在固件中找到了一个路径,其中提到了名为 font 的目录中的字体文件,并且这些文件的扩展名为 .lib(例如 english_font.lib)。我有另一个固件,非常相似的手机,三星 b110e(相同的 CPU)包含希伯来语。

我的问题是是否可以选择将字体从该固件复制到我的固件。

关于 RTL,我不知道我需要编辑什么,但我想,那是在一个 xml 文件中。

谢谢你的帮助。

1个回答

第一个被识别为Minix fs的区域只有几百字节长,第二个不到3kB(如果我们假设后续的数据识别为MySQL数据是正确的),第二个位置的内容看起来并不真实对我来说就像一个 fs 图像。所以我认为可以安全地假设 binwalk 错误地识别了这些。

查看固件映像中包含的一些字符串,似乎这是在 ARM 上使用 ThreadX RTOS(几个文件名提到了这一点)(有字符串表示 SVC 和 FIQ,它们是 ARM 异常/中断方法)。AFAIK,ThreadX 仅支持某种开箱即用的 FAT 文件系统。

所以,不要盲目相信binwalk等工具。大多数工具仅依赖于识别“幻数”,即也可以随机出现的字节序列,因此可以预料到一些误报。

(感谢您更新有关硬件的信息)

在像这样的功能手机上,固件通常只是一个链接在一起的大二进制博客,所以可能没有文件系统可以更容易地修改内容。

E1200Y使用展讯 SC6500 SoC根据芯片制造商的说法,它是 ARM9EJ-S 内核(以 208 MHz 运行)——字符串“SC6500”也在固件映像中多次出现。与此类 IC 一样,文档不可用。

如果您想开始对代码进行逆向工程,这里有一些提示可以帮助您入门。

仔细查看固件映像,前 32 个字节看起来像是有效的复位和异常向量。在“常规”(即非 Cortex-M)ARM 处理器上,这些不包含向量,但包含将 PC 更新为新值的指令——本质上是某种跳转指令。

00000000  18 f0 9f e5 18 f0 9f e5  18 f0 9f e5 18 f0 9f e5
00000010  18 f0 9f e5 18 f0 9f e5  18 f0 9f e5 18 f0 9f e5

这是小端字节序,每组四字节“18 f0 9f e5”是 LDR 指令的操作码(用在线反汇编器反汇编):

00000000  18 f0 9f e5  ldr pc, [pc, #24]

ARM 上的 PC 始终指向当前指令 +8,因此 PC+24 = 0(复位时的当前 PC)+ 8 + 24(指令中的偏移量)= 32 = 0x20。在偏移为0x20,你可以找到复位程序的(载体中描述的地址,这个帖子):

00000020  30 6c 0a 00

因此,在复位时 CPU 将执行地址 0x000a6c30 处的代码。但是,在您上传的固件转储中的此偏移处反汇编代码不会产生看起来非常合理的代码。

常规 32 位 ARM 代码可通过查看每个 32 位操作码的最高 4 位来识别。对于大多数指令,它们应该包含 0xe,因为 4 个 MSB 用于谓词执行(即,根据 CPU 标志的当前值执行指令)。0xe 是“always”的谓词,大多数指令都应该是这种情况。

所以你必须在这里深入挖掘。似乎一些看起来合理的启动代码位于文件中的偏移量 0x00096c30 - 复位向量地址下方的 0x10000 字节(64 kB)(此处显示的代码地址将被 CPU 看到,减去 0x10000 以查找固件映像中的字节):

000a6c30  60 c1 1f e5  ldr ip, [pc, #-352]   ; 0x000a6ad8
000a6c34  00 c0 9c e5  ldr ip, [ip]
000a6c38  ff a0 a0 e3  mov sl, #255          ; 0xff
000a6c3c  0a c0 0c e0  and ip, ip, sl
000a6c40  6c b1 1f e5  ldr fp, [pc, #-364]   ; 0x000a6adc
000a6c44  00 b0 9b e5  ldr fp, [fp]
000a6c48  dc a0 9f e5  ldr sl, [pc, #220]       ;0x000a6d2c
000a6c4c  0a b0 0b e0  and fp, fp, sl
000a6c50  78 a1 1f e5  ldr sl, [pc, #-376]   ; 0x000a6ae0
000a6c54  00 a0 9a e5  ldr sl, [sl]
000a6c58  00 b0 8a e5  str fp, [sl]
000a6c5c  80 b1 1f e5  ldr fp, [pc, #-384]   ; 0x000a6ae4
000a6c60  00 a0 9b e5  ldr sl, [fp]
000a6c64  00 b0 9a e5  ldr fp, [sl]
000a6c68  02 01 1b e3  tst fp, #-2147483648  ; 0x80000000
000a6c6c  fc ff ff 1a  bne 0x000a6c64
...

从这里开始,您显然需要对 ARM 汇编程序和 SC6500 中使用的特定硬件有很好的了解(上面最后三个反汇编指令看起来像一个轮询循环,等待某些 I/O 条件发生)。所以看起来你在这里做了很大的努力......