-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_inspect.lua
More file actions
72 lines (62 loc) · 2.5 KB
/
debug_inspect.lua
File metadata and controls
72 lines (62 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-- debug_inspect.lua
-- Create a small dbg.zip in the repo and inspect its central directory
local sep = package.config:sub(1,1)
local src = debug.getinfo(1, 'S').source or ''
local dir = src:match('@?(.*[\\/])') or './'
dir = dir:gsub('[\\/]+$', '')
local base = dir
-- If a project test harness exists, run it (non-fatal)
pcall(function() dofile(base .. sep .. 'test.lua') end)
local outzip = base .. sep .. 'dbg.zip'
pcall(function() os.remove(outzip) end)
local zw, err = ZipWriter.new(outzip, {compress = false})
if not zw then print('create failed', err); os.exit(1) end
zw:add_data('hello.txt','Hello World')
zw:close()
local f = io.open(outzip,'rb')
local data = f:read('*a')
f:close()
local pos = data:find('\x50\x4b\x01\x02')
if not pos then print('central not found') os.exit(1) end
print('central at', pos)
local name_len = (data:byte(pos+28) or 0) + ((data:byte(pos+29) or 0)*256)
print('name_len', name_len)
local name = data:sub(pos+46, pos+45+name_len)
print('name bytes:', #name, name)
print('hexdump of central start:', (data:sub(pos, pos+100)))
-- debug_inspect.lua
-- Create a small dbg.zip in the repo and inspect its central directory
local sep = package.config:sub(1,1)
local src = debug.getinfo(1, 'S').source or ''
local dir = src:match('@?(.*[\\/])') or './'
dir = dir:gsub('[\\/]+$', '')
local base = dir
-- If a project test harness exists, run it (non-fatal)
pcall(function() dofile(base .. sep .. 'test.lua') end)
-- debug_inspect.lua
-- Create a small dbg.zip in the repo and inspect its central directory
local sep = package.config:sub(1,1)
local src = debug.getinfo(1, 'S').source or ''
local dir = src:match('@?(.*[\\/])') or './'
dir = dir:gsub('[\\/]+$', '')
local base = dir
-- If a project test harness exists, run it (non-fatal)
pcall(function() dofile(base .. sep .. 'test.lua') end)
local outzip = base .. sep .. 'dbg.zip'
pcall(function() os.remove(outzip) end)
local zw, err = ZipWriter.new(outzip, {compress = false})
if not zw then print('create failed', err); os.exit(1) end
zw:add_data('hello.txt','Hello World')
zw:close()
local f = io.open(outzip,'rb')
local data = f:read('*a')
f:close()
local pos = data:find('\x50\x4b\x01\x02')
if not pos then print('central not found') os.exit(1) end
print('central at', pos)
local name_len = (data:byte(pos+28) or 0) + ((data:byte(pos+29) or 0)*256)
print('name_len', name_len)
local name = data:sub(pos+46, pos+45+name_len)
print('name bytes:', #name, name)
print('hexdump of central start:', (data:sub(pos, pos+100)))
local outzip = base .. sep .. 'dbg.zip'