diff options
Diffstat (limited to 'utils/hwpatcher/view.lua')
-rw-r--r-- | utils/hwpatcher/view.lua | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/utils/hwpatcher/view.lua b/utils/hwpatcher/view.lua new file mode 100644 index 0000000000..35c383800f --- /dev/null +++ b/utils/hwpatcher/view.lua | |||
@@ -0,0 +1,38 @@ | |||
1 | --[[ | ||
2 | Sansa View bootloader hacking | ||
3 | required argument (in order): | ||
4 | - path to bootloader | ||
5 | - path to output bootloader | ||
6 | - path to stub | ||
7 | ]]-- | ||
8 | require("lib") | ||
9 | require("arm") | ||
10 | |||
11 | if #arg < 3 then | ||
12 | error("not enough argument to fuzep patcher") | ||
13 | end | ||
14 | |||
15 | local md5 = hwp.md5sum(arg[1]) | ||
16 | if hwp.md5str(md5) ~= "4bc1760327c37b9ffd00315c8aa7f376" then | ||
17 | error("MD5 sum of the file doesn't match") | ||
18 | end | ||
19 | |||
20 | local fw = hwp.load_file(arg[1]) | ||
21 | local jump_instr_addr = arm.to_thumb(hwp.make_addr(0x753C)) | ||
22 | local stub_addr = hwp.make_addr(0x137B0) | ||
23 | -- read old jump address | ||
24 | --local old_jump = arm.parse_branch(fw, jump_instr_addr) | ||
25 | --print(string.format("Old jump address: %s", old_jump)) | ||
26 | -- put stub at the right place | ||
27 | local stub = hwp.load_bin_file(arg[3]) | ||
28 | local stub_info = hwp.section_info(stub, "") | ||
29 | local stub_data = hwp.read(stub, hwp.make_addr(stub_info.addr, ""), stub_info.size) | ||
30 | hwp.write(fw, stub_addr, stub_data) | ||
31 | -- patch jump | ||
32 | local branch_to_stub = arm.make_branch(arm.to_arm(stub_addr), true) | ||
33 | arm.write_branch(fw, jump_instr_addr, branch_to_stub, hwp.inc_addr(stub_addr, stub_info.size)) | ||
34 | -- read jump address | ||
35 | local new_jump = arm.parse_branch(fw, jump_instr_addr) | ||
36 | print(string.format("New jump address: %s", new_jump)) | ||
37 | -- save | ||
38 | hwp.save_file(fw, arg[2]) | ||