-- Définitions pour l'extracteur/inséreur -- little_endian = true big_endian = false -- Définitions de fonctions diverses -- function insert(f_in, debut, data) if (io.type(f_in) ~= "file") then print("insert : le premier argument est incorrect") return end if (type(debut) ~= "number") then print("insert : le second argument est incorrect") return end if (type(data) ~= "string") then print("insert : le troisième argument est incorrect") return end if (debut > f_in:seek("end")) then print("insert : la zone à dumper se situe en dehors du fichier") f_in:seek("set", pos_in) return end f_in:seek("set", debut) f_in:write(data) end function hexdump(f_in, debut, taille) local pos_in = f_in:seek() local data if (io.type(f_in) ~= "file") then print("hexdump : le premier argument est incorrect") return end if (type(debut) ~= "number") then print("hexdump : le second argument est incorrect") return end if (type(taille) ~= "number") then print("hexdump : le troisième argument est incorrect") return end if (f_in:seek("end") < debut + taille) then print("hexdump : la zone à dumper se situe en dehors du fichier") f_in:seek("set", pos_in) return end f_in:seek("set", debut) data = f_in:read(taille) f_in:seek("set", pos_in) return data end function concatener(nom_out, table_noms) local i, data_temp, taille_table local f_in, out local erreur taille_table = table.getn(table_noms) if (type(nom_out) ~= "string") then print("concatener : Le premier argument doit être une chaine") return end out, erreur = io.open(nom_out, "wb") if (out == nil) then print("concatener : Erreur lors de l'ouverture du fichier sortie :") print(erreur) return end if (type(table_noms) ~= "table") then print("concatener : Le second argument doit être une table") return end for i = 1, taille_table do if (type(table_noms[i]) ~= "string") then print("concatener : Le " .. i .. "ème élément de la table n'est pas une chaine") else f_in , erreur = io.open(table_noms[i], "rb") if (f_in == nil) then print("concatener : Erreur lors de l'ouverture d'un fichier d'entrée :") print(erreur) else data_temp = f_in:read("*a") out:write(data_temp) f_in:close() end end end out:close() end function creer_table(nom_in, nom_out, debut) local f_in, f_out local temp local n_courant = debut if (type(nom_in) ~= "string") then print("creer_table : le premier argument doit être une chaine") return end if (type(nom_out) ~= "string") then print("creer_table : le deuxième argument doit être une chaine") return end if (type(debut) ~= "number") then print("creer_table : le troisième argument doit être un nombre") return end f_in = io.open(nom_in, "r") f_out = io.open(nom_out, "w") temp = 0 while (temp ~= nil) do temp = f_in:read("*l") if (temp ~= nil and string.len(temp) ~= 0) then f_out:write(string.format("%X=%s\n", n_courant, temp)) n_courant = n_courant + 1 end end f_in:close() f_out:close() end