local invoker = require 'invoker' local MMC_HOST_PATH = "/sys/class/mmc_host" local VERI_FILE_PATH = "/boot/verificationfile" local function read_veri() local veri_file = io.open(VERI_FILE_PATH, "r") if not veri_file then print("Error opening verification file:", VERI_FILE_PATH) return nil end local veri_sha256 = veri_file:read("*l") veri_file:close() return veri_sha256 end local function calculate_cid_sha256(cid_data) local cmd = string.format("echo -n '%s' | sha256sum | awk '{print $1}'", cid_data) local pipe = io.popen(cmd, "r") if not pipe then print("Error executing command:", cmd) return nil end local cid_sha256 = pipe:read("*l") pipe:close() return cid_sha256 end local function find_cid_files(directory) local cid_files = {} if directory then local file = io.popen ("find " .. directory .. " -name 'cid' -type f 2>/dev/null") if file then for entry in file:lines() do cid_files[#cid_files + 1] = entry end end file:close () end return cid_files end local function get_absolute_path(root_path, path) if string.sub(path, 1, 1) == "/" then return path else return root_path .. "/" .. path end end local function check_mmc_devices() if not io.open(MMC_HOST_PATH) then print("MMC host path not found:", MMC_HOST_PATH) return end local f_result = io.popen("find " .. MMC_HOST_PATH .. " -name 'mmc*' -type l") if f_result then for entry in f_result:lines() do local path_result = io.popen("realpath " .. entry) if path_result then local actual_dev_path = path_result:read("*l") local cid_files = find_cid_files(actual_dev_path) if #cid_files then for _, cid_file_path in ipairs(cid_files) do local cid_file = io.open(cid_file_path, "r") if cid_file then local cid_data = cid_file:read("*l") cid_file:close() local cid_sha256 = calculate_cid_sha256(cid_data) if cid_sha256 then local veri_sha256 = read_veri() if not cid_sha256 or not veri_sha256 then return end if cid_sha256 ~= veri_sha256 then local t = io.popen("systemctl stop emsd") t:close() print("SHA-256 mismatch! Stop lnxall application") return else print("SHA-256 matched! continue.....") end end end end end path_result:close() end end f_result:close() end end while true do local is_exists = io.open("/boot/.need_verify") if is_exists then check_mmc_devices() end invoker.msleep (1000000) is_exists:close() end