|
![]() |
|
Thread Tools | Search this Thread |
![]() |
#1 |
Connoisseur
![]() ![]() ![]() Posts: 52
Karma: 216
Join Date: Apr 2010
Device: PRS-T1
|
![]()
I really should get a blog or something so I can put these things up in more detail. As I don't, I'll just post here.
Short version: This tool (requires ARM toolchain, get it from embedded Debian) goes through an ELF executable's .text section and via simplistic symbolic execution detects when a register obtains a value that is a reference to a string in the constant data section (.rodata) Run python arm-disasm.py the_executable It'll print some tracing data, and among it where you see STRING, you get the location of the instruction that put a string's address into a register, as well as the string. Caveats: assumes the executable is compiled by something gcc-like, only deals with simple cases and absolutely no obfuscation. Hence might miss strings. Now the long version: Basically, the problem is this. Say I write hello world in C: Code:
#include <stdio.h> int main(int argc, char* argv[]) { printf("Hello from C!\n"); return 0; } Code:
arm-linux-gnueabi-gcc -Wall -o hello hello.c Code:
arm-linux-gnueabi-objdump -EL -j .text -d hello Code:
0000845c <main>: ... (preamble) 8474: e59f0014 ldr r0, [pc, #20] ; 8490 <main+0x34> 8478: ebffffaf bl 833c <_init+0x5c> ... (more unimportant stuff) 8490: 0000852c .word 0x0000852c Code:
arm-linux-gnueabi-objdump -EL -j .rodata -s hello hello: file format elf32-littlearm Contents of section .rodata: 8528 01000200 48656c6c 6f206672 6f6d2043 ....Hello from C 8538 21000000 !... Ok, so what's the problem then? Well, if we're dealing with a .so file (shared library), it can be placed anywhere in memory, so the code must be entirely independent of its position in memory. To simulate this, we need to recompile hello.c with position-independent-code: Code:
arm-linux-gnueabi-gcc -fPIC -Wall -o hello hello.c Code:
arm-linux-gnueabi-objdump -EL -j .rodata -s hello hello: file format elf32-littlearm Contents of section .rodata: 853c 01000200 48656c6c 6f206672 6f6d2043 ....Hello from C 854c 21000000 !... Let's take a look at what happened to the main function: Code:
0000845c <main>: ... (preamble) 846c: e59f202c ldr r2, [pc, #44] ; 84a0 <main+0x44> 8470: e08f2002 add r2, pc, r2 8474: e50b0010 str r0, [fp, #-16] 8478: e50b1014 str r1, [fp, #-20] 847c: e59f3020 ldr r3, [pc, #32] ; 84a4 <main+0x48> 8480: e0823003 add r3, r2, r3 8484: e1a00003 mov r0, r3 8488: ebffffab bl 833c <_init+0x5c> ... (not relevant) 849c: e12fff1e bx lr 84a0: 000081d8 .word 0x000081d8 84a4: ffff7ef0 .word 0xffff7ef0 So how does it get the address of the string? Well, let's look at what exactly contributes to generating the r0 value: Code:
846c: e59f202c ldr r2, [pc, #44] ; 84a0 <main+0x44> 8470: e08f2002 add r2, pc, r2 847c: e59f3020 ldr r3, [pc, #32] ; 84a4 <main+0x48> 8480: e0823003 add r3, r2, r3 8484: e1a00003 mov r0, r3 8488: ebffffab bl 833c <_init+0x5c> ... 84a0: 000081d8 .word 0x000081d8 84a4: ffff7ef0 .word 0xffff7ef0
Now, this is already ridiculous for hello.c, and I was trying to look through ebookConfig.so searching for references to /dev/fb0. I'd have to be stupid to try do it by hand. So let's try running my tool on hello: Code:
python arm-disasm.py hello Code:
846c: ldr r2, [pc, #44] r2 <- [84a0] (000081d8) 8470: add r2, pc, r2 r2 <- pc (8478) + r2 (81d8) = 10650 8474: str r0, [fp, #-16] 8478: str r1, [fp, #-20] 847c: ldr r3, [pc, #32] r3 <- [84a4] (ffff7ef0) 8480: add r3, r2, r3 r3 <- r2 (10650) + r3 (ffff7ef0) = 8540 8480: STRING "Hello from C!" 8484: mov r0, r3 r0 <- r3 (8540) 8484: STRING "Hello from C!" 8488: bl 833c <_init+0x5c> Awesome, in two seconds we see that first r3 gets the address of our string, then it gets moved to r0. The tool may not be great, but it beats the manual process! Finally, let's try it on what I originally wanted to do: Code:
python arm-disasm.py ebookConfig.so|grep STRING Code:
fc4: STRING "@" 11c8: STRING "/usr/local/sony/bin/nblconfig -bootdone" 12b0: STRING "/sbin/shutdown -h now" 149c: STRING "/" 15b0: STRING "/Data/screenLock" 15bc: STRING "[PreferencesDir]" 15f4: STRING "/Data/tmp/preload.lst" 15f8: STRING "/Data/tmp/preload.lst" 1614: STRING "/Data/tmp/preload.lst" 1650: STRING "/Data/tmp/preload.lst" 1748: STRING "[mediaPath]" 177c: STRING "[keyPath]" 178c: STRING "/Data/tmp/checked" 1798: STRING "[adeptKeyPath]" 17a8: STRING "cp -Rp /Data/tmp/database/cache /Data/database/" 17b4: STRING "/dev/fb0" 17c0: STRING "/dev/fb0" 17f4: STRING "/dev/fb0" 1804: STRING "/dev/fb0" 1818: STRING "/dev/fb0" 183c: STRING "/dev/fb0" 184c: STRING "/dev/fb0" 185c: STRING "/dev/fb0" 186c: STRING "/dev/fb0" |
![]() |
![]() |
![]() |
#2 |
PRS+ author
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,637
Karma: 2446233
Join Date: Dec 2007
Device: Sony PRS-300, 505, 600, 650, 950
|
Xaphiosis
I can give you access to PRS+ project's wiki (and there is wiki.mobileread.com) By the way, check the attached file out (slightly modified fsk decompiler by igorsk). Some so files and all xsb files contain compiled javascript (ecmascript). Igorsk has managed to write a decompiler for it. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Connoisseur
![]() ![]() ![]() Posts: 52
Karma: 216
Join Date: Apr 2010
Device: PRS-T1
|
kartu: thanks again, porkupan told me about DeFsk but I didn't manage to find it, and I bothered him with so many questions already. Glad to see igorsk is also a python hacker.
As for the wiki, thank you for the offer, but I don't think I'm doing anything PRS+ would find useful. If you do need something compiled at the C level but don't want to mess around with linux and cross-compilation, drop me a line. Speaking of PRS+, I looked at the sources. I have to say that the parts that are in the repository are truly much nicer than what I've seen from sony. Nice work! |
![]() |
![]() |
![]() |
#4 | ||
PRS+ author
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,637
Karma: 2446233
Join Date: Dec 2007
Device: Sony PRS-300, 505, 600, 650, 950
|
Xaphiosis
Quote:
https://www.mobileread.com/forums/sho...29&postcount=9 would be a breakthrough. Quote:
![]() |
||
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Firmware-update switch tool (batch files) | T_Frain_K | Bookeen | 3 | 01-19-2010 06:21 AM |
6.17 installer not executable?? | petercreasey | Calibre | 3 | 10-13-2009 05:28 PM |
Is there a dictionary tool for pdf files? | booklover | iRex | 2 | 07-12-2008 12:15 AM |
Is there a tool to combine LRF files? | Lime2K | Sony Reader | 1 | 03-03-2008 02:09 AM |
New PDF to LRF Tool (for DJVU and CBZ files too) | RWood | Sony Reader | 0 | 08-29-2007 02:13 PM |