/* Title: Tar Library License: v0.73 by Oberon under terms of GNU GPLv3 Function: tar_extract Get the content of a file from a tar archive. Function: tar_save Save a resource within a tar archive to a local file. Function: tar_delete Remove a file and its contents from a tar archive. Function: tar_add Create or update a file in a tar archive. Function: tar_list Get a list of files and their details from a tar archive. */ tar_extract(source, file, ByRef var) { Return, _tar(source, var, 1, file) } tar_save(source, file, saveas) { Return, _tar(null, source, 2, file, saveas) } tar_delete(source, file) { Return, _tar(source, void, 3, file) } tar_add(source, file, ByRef content) { Return, _tar(source, content, 4, file) } tar_list(source, ByRef var) { Return, _tar(source, var, 5) } _tar(t, ByRef d, m = 1, p1 = "", p2 = "") { ; enum m { extract = 1, save = 2, delete = 3, add = 4, list = 5 } If t is xdigit y := t & 0xffff, t >>= 16 Else { FileRead, t, *c %t% s := &t, y := VarSetCapacity(t), f := 1 } k = 1 c = 0 Loop, % y // 512 { If (--k > 0) Continue _tar_v(n, s, 100), _tar_v(xr1, s + 124, 12), _tar_v(xr2, s + 136, 12), _tar_v(e, s + 257, 5) Loop, 2 { i := A_Index, x%i% := 0 Loop, Parse, xr%A_Index% x%i% += A_LoopField * 8 ** (11 - A_Index) } If (m == 1 and n == p1) Return, _tar_v(d, s + 512, x1) . x1 Else If (m == 2 and n == p1) Return, _tar_v(x0, s + 512, x1) . _tar_f(x0, p2, x1) Else If (m == 3 and n == p1) Return, DllCall("RtlMoveMemory", "UInt", s, "UInt", s + x0 := 512 * (1 + Ceil(x1 / 512)), "UInt", y -= x0) . (f ? _tar_f(t, r, y) : VarSetCapacity(d, y) . _tar_v(t, &d, y) . d := "") Else If m = 5 { x0 = 19700101 x0 += x2, s d = %d%%n%,%x1%,%x0%`n c++ } k := 1 + Ceil(x1 / 512), s += k * 512 } Return, c } _tar_v(ByRef v, s, l) { VarSetCapacity(v, l), DllCall("RtlMoveMemory", "UInt", &v, "UInt", s, "UInt", l), VarSetCapacity(v, -1) } _tar_f(ByRef c, f, s) { h := DllCall("CreateFile", "Str", f, "UInt", 0x40000000, "UInt", 1, "UInt", 0, "UInt", 2, "UInt", 0, "UInt", 0) , DllCall("WriteFile", "UInt", h, "UInt", &c, "UInt", s, "UIntP", c, "UInt", 0) Return, DllCall("CloseHandle", "UInt", h) ? c : 0 }