summaryrefslogtreecommitdiff
path: root/utils/hwpatcher/view.lua
diff options
context:
space:
mode:
Diffstat (limited to 'utils/hwpatcher/view.lua')
-rw-r--r--utils/hwpatcher/view.lua38
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--[[
2Sansa View bootloader hacking
3required argument (in order):
4- path to bootloader
5- path to output bootloader
6- path to stub
7]]--
8require("lib")
9require("arm")
10
11if #arg < 3 then
12 error("not enough argument to fuzep patcher")
13end
14
15local md5 = hwp.md5sum(arg[1])
16if hwp.md5str(md5) ~= "4bc1760327c37b9ffd00315c8aa7f376" then
17 error("MD5 sum of the file doesn't match")
18end
19
20local fw = hwp.load_file(arg[1])
21local jump_instr_addr = arm.to_thumb(hwp.make_addr(0x753C))
22local 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
27local stub = hwp.load_bin_file(arg[3])
28local stub_info = hwp.section_info(stub, "")
29local stub_data = hwp.read(stub, hwp.make_addr(stub_info.addr, ""), stub_info.size)
30hwp.write(fw, stub_addr, stub_data)
31-- patch jump
32local branch_to_stub = arm.make_branch(arm.to_arm(stub_addr), true)
33arm.write_branch(fw, jump_instr_addr, branch_to_stub, hwp.inc_addr(stub_addr, stub_info.size))
34-- read jump address
35local new_jump = arm.parse_branch(fw, jump_instr_addr)
36print(string.format("New jump address: %s", new_jump))
37-- save
38hwp.save_file(fw, arg[2])