local L1_1, L2_2, L3_3, L4_4, L5_5, L6_6, L7_7, L8_8, L9_9, L10_10, L11_11, L12_12, L13_13, L14_14, L15_15, L16_16, L17_17, L18_18, L19_19, L20_20, L21_21 L0_0 = require L1_1 = "luaext.sys" L0_0 = L0_0(L1_1) L1_1 = require L2_2 = "luaext.aes" L1_1 = L1_1(L2_2) L2_2 = arg L3_3 = string L3_3 = L3_3.format L4_4 = io L5_5 = ipairs L6_6 = os L7_7 = print L8_8 = string L9_9 = table L10_10 = tonumber L11_11 = {} _ENV = L11_11 L11_11, L12_12 = nil, nil function L13_13(A0_22, ...) A0_22 = "update_sd: " .. A0_22 L4_4.stderr:write(A0_22:format(...)) end function L14_14(A0_23, A1_24) local L2_25, L3_26, L4_27, L5_28 L2_25 = "/tmp/update_sd-getsum.tmp" L3_26 = L4_4.popen L4_27 = "sha256sum >" L5_28 = L2_25 L4_27 = L4_27 .. L5_28 L5_28 = "w" L3_26 = L3_26(L4_27, L5_28) repeat if A1_24 > 4096 then L4_27 = 4096 else L4_27 = L4_27 or A1_24 end L5_28 = A0_23.read L5_28 = L5_28(A0_23, L4_27) L3_26:write(L5_28) A1_24 = A1_24 - L4_27 until A1_24 == 0 L5_28 = L3_26 L4_27 = L3_26.close L4_27(L5_28) L4_27 = nil L5_28 = L4_4.open L5_28 = L5_28(L2_25) if L5_28 then if L5_28:read() then L4_27 = L5_28:read():match("%x+") end L5_28:close() L6_6.remove(L2_25) end return L4_27 end function L15_15(A0_29) local L1_30, L2_31, L3_32, L4_33, L5_34 L1_30 = {} for L5_34 = 1, #A0_29, 2 do L1_30[#L1_30 + 1] = L10_10(A0_29:sub(L5_34, L5_34 + 1), 16) end L5_34 = L3_32(L4_33) return L2_31(L3_32, L4_33, L5_34, L3_32(L4_33)) end function L16_16() local L0_35, L1_36, L2_37, L3_38, L4_39, L5_40 L0_35 = { L1_36, L2_37, L3_38, L4_39, L5_40, 2197438769, 632650056, 2567168270 } L4_39 = 4287771157 L5_40 = 4188798088 for L4_39, L5_40 in L1_36(L2_37) do L0_35[L4_39] = L3_3("%08x", L5_40) end L5_40 = L2_37(L3_38) L0_35 = L1_36 return L1_36(L2_37) end function L17_17(A0_41, A1_42) local L2_43, L3_44, L4_45, L5_46, L6_47 L2_43 = {} for L6_47 = 1, 16 do L2_43[L6_47] = A0_41:byte(L6_47) ~ A1_42:byte(L6_47) end L6_47 = L4_45(L5_46) return L3_44(L4_45, L5_46, L6_47, L4_45(L5_46)) end function L18_18(A0_48) local L1_49, L2_50, L3_51, L4_52, L5_53, L6_54, L7_55, L8_56 L1_49 = L8_8.rep L2_50 = "\000" L3_51 = 16 L1_49 = L1_49(L2_50, L3_51) L2_50 = L16_16 L2_50 = L2_50() L3_51 = {} for L7_55 = 1, #A0_48, 16 do L8_56 = A0_48.sub L8_56 = L8_56(A0_48, L7_55, L7_55 + 15) L8_56 = L17_17(L1_49, L8_56) L1_49 = L2_50:enc(L8_56) L3_51[#L3_51 + 1] = L1_49 end L4_52(L5_53) return L4_52(L5_53) end function L19_19(A0_57, A1_58, A2_59) local L3_60, L4_61, L5_62 L3_60 = L4_4.open L4_61 = A1_58 L5_62 = "wb" L3_60 = L3_60(L4_61, L5_62) if not L3_60 then L4_61 = L13_13 L5_62 = "Can't create file: %s\n" L4_61(L5_62, A1_58) L4_61 = false return L4_61 end repeat if A2_59 > 1024 then L4_61 = 1024 else L4_61 = L4_61 or A2_59 end L5_62 = A0_57.read L5_62 = L5_62(A0_57, L4_61) L3_60:write(L5_62) A2_59 = A2_59 - L4_61 until A2_59 == 0 L5_62 = L3_60 L4_61 = L3_60.close L4_61(L5_62) L4_61 = true return L4_61 end function L20_20(A0_63) local L1_64 L1_64 = A0_63.seek L1_64(A0_63, "end", -100) L1_64 = A0_63.read L1_64 = L1_64(A0_63, 4) L13_13("cam_hw_ver(%s), file_hw_ver(%s)\n", L12_12, L1_64) if L12_12 ~= L1_64 then L13_13("Skip update\n") return false end return true end function L21_21() local L0_65, L1_66, L2_67, L3_68, L4_69, L5_70, L6_71, L7_72 L0_65 = L2_2 L0_65 = #L0_65 if L0_65 ~= 2 then L0_65 = L13_13 L1_66 = "need arg: fw_name hw_ver\n" L0_65(L1_66) return end L0_65 = L2_2[1] L1_66 = L2_2[2] L12_12 = L1_66 L11_11 = L0_65 L0_65 = "/home/app/sd/" L1_66 = L11_11 L0_65 = L0_65 .. L1_66 L1_66 = L4_4.open L2_67 = L0_65 L3_68 = "rb" L1_66 = L1_66(L2_67, L3_68) if not L1_66 then L2_67 = L13_13 L3_68 = "Can't open file: %s\n" L4_69 = L0_65 L2_67(L3_68, L4_69) return end L3_68 = L1_66 L2_67 = L1_66.seek L4_69 = "end" L2_67 = L2_67(L3_68, L4_69) if L2_67 < 164 then L4_69 = L1_66 L3_68 = L1_66.close L3_68(L4_69) L3_68 = L13_13 L4_69 = "File(%s) size(%d) too small\n" L5_70 = L0_65 L6_71 = L2_67 L3_68(L4_69, L5_70, L6_71) return end L3_68 = L20_20 L4_69 = L1_66 L3_68 = L3_68(L4_69) if not L3_68 then L4_69 = L1_66 L3_68 = L1_66.close L3_68(L4_69) return end L4_69 = L1_66 L3_68 = L1_66.seek L5_70 = "set" L3_68(L4_69, L5_70) L3_68 = L14_14 L4_69 = L1_66 L5_70 = L2_67 - 32 L3_68 = L3_68(L4_69, L5_70) if not L3_68 then L5_70 = L1_66 L4_69 = L1_66.close L4_69(L5_70) L4_69 = L13_13 L5_70 = "Can't get sum for file: %s\n" L6_71 = L0_65 L4_69(L5_70, L6_71) return end L4_69 = L15_15 L5_70 = L3_68 L4_69 = L4_69(L5_70) L3_68 = L4_69 L4_69 = L18_18 L5_70 = L3_68 L4_69 = L4_69(L5_70) L3_68 = L4_69 L5_70 = L1_66 L4_69 = L1_66.read L6_71 = 32 L4_69 = L4_69(L5_70, L6_71) if L3_68 ~= L4_69 then L6_71 = L1_66 L5_70 = L1_66.close L5_70(L6_71) L5_70 = L13_13 L6_71 = "Invalid update file\n" L5_70(L6_71) return end L6_71 = L1_66 L5_70 = L1_66.seek L7_72 = "set" L5_70(L6_71, L7_72) L5_70 = "/tmp/update_sd-fwhead.tmp" L6_71 = L19_19 L7_72 = L1_66 L6_71 = L6_71(L7_72, L5_70, 64) L7_72 = L1_66.close L7_72(L1_66) if not L6_71 then return end L7_72 = " >/dev/null 2>&1" L6_6.execute("/home/bin/flash_eraseall /dev/mtd10" .. L7_72) L6_6.execute("nandwrite -p -s 0 /dev/mtd10 " .. L0_65 .. L7_72) L6_6.execute("nandwrite -p -s 0x3100000 /dev/mtd10 " .. L5_70 .. L7_72) L7_7("1") end L21_21()