aboutsummaryrefslogtreecommitdiff
path: root/win32/bin
diff options
context:
space:
mode:
Diffstat (limited to 'win32/bin')
-rw-r--r--win32/bin/LuaRocks.reg.lua51
-rw-r--r--win32/bin/LuaRocks.reg.template59
-rw-r--r--win32/bin/bin/7z.dllbin858624 -> 0 bytes
-rw-r--r--win32/bin/bin/7z.exebin161792 -> 0 bytes
-rw-r--r--win32/bin/bin/cp.exebin130048 -> 0 bytes
-rw-r--r--win32/bin/bin/find.exebin160256 -> 0 bytes
-rw-r--r--win32/bin/bin/libeay32.dllbin1177600 -> 0 bytes
-rw-r--r--win32/bin/bin/libiconv2.dllbin1008128 -> 0 bytes
-rw-r--r--win32/bin/bin/libintl3.dllbin103424 -> 0 bytes
-rw-r--r--win32/bin/bin/libssl32.dllbin232960 -> 0 bytes
-rw-r--r--win32/bin/bin/ls.exebin180736 -> 0 bytes
-rw-r--r--win32/bin/bin/md5sum.exebin41984 -> 0 bytes
-rw-r--r--win32/bin/bin/mkdir.exebin32768 -> 0 bytes
-rw-r--r--win32/bin/bin/mv.exebin138752 -> 0 bytes
-rw-r--r--win32/bin/bin/pwd.exebin61440 -> 0 bytes
-rw-r--r--win32/bin/bin/rmdir.exebin25088 -> 0 bytes
-rw-r--r--win32/bin/bin/test.exebin62976 -> 0 bytes
-rw-r--r--win32/bin/bin/uname.exebin33792 -> 0 bytes
-rw-r--r--win32/bin/bin/wget.exebin449024 -> 0 bytes
-rw-r--r--win32/bin/lua.icobin22486 -> 0 bytes
-rw-r--r--win32/bin/luarocksw.bat49
-rw-r--r--win32/bin/pe-parser.lua546
-rw-r--r--win32/bin/rclauncher.c139
23 files changed, 0 insertions, 844 deletions
diff --git a/win32/bin/LuaRocks.reg.lua b/win32/bin/LuaRocks.reg.lua
deleted file mode 100644
index 2eb7583a..00000000
--- a/win32/bin/LuaRocks.reg.lua
+++ /dev/null
@@ -1,51 +0,0 @@
1-- Call this file using its full path and the template file as a parameter;
2--
3-- C:\> lua.exe "create_reg_file.lua" "c:\luarocks\2.0\LuaRocks.reg.template"
4--
5-- it will strip the ".template" extension and write to that file the
6-- template contents, where "<LUAROCKSPATH>" will be replaced by the path
7-- to LuaRocks (including the trailing backslash)
8
9
10
11-- Check argument
12local f = (arg or {})[1]
13if not f then
14 print("must provide template file on command line")
15 os.exit(1)
16end
17
18-- cleanup filepath, remove all double backslashes
19while f:match("\\\\") do
20 f = f:gsub("\\\\", "\\")
21end
22
23-- extract path and name from argument
24local p = ""
25local ni = f
26for i = #f, 1, -1 do
27 if f:sub(i,i) == "\\" then
28 ni = f:sub(i+1)
29 p = f:sub(1, i)
30 break
31 end
32end
33
34-- create output name
35local no = ni:gsub("%.template","")
36
37-- create path substitute; escape backslash by doubles
38local ps = p:gsub("\\", "\\\\")
39
40-- read template
41local fh = io.open(f)
42local content = fh:read("*a")
43fh:close()
44
45-- fill template
46content = content:gsub("%<LUAROCKSPATH%>", ps)
47
48-- write destination file
49fh = io.open(p..no, "w+")
50fh:write(content)
51fh:close()
diff --git a/win32/bin/LuaRocks.reg.template b/win32/bin/LuaRocks.reg.template
deleted file mode 100644
index 82cc180f..00000000
--- a/win32/bin/LuaRocks.reg.template
+++ /dev/null
@@ -1,59 +0,0 @@
1Windows Registry Editor Version 5.00
2
3[HKEY_CLASSES_ROOT\.rockspec]
4@="Lua.Rockspec"
5
6[HKEY_CLASSES_ROOT\.rockspec\Content Type]
7@="text/plain"
8
9[HKEY_CLASSES_ROOT\.rockspec\PerceivedType]
10@="text"
11
12[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.rockspec]
13@="Lua.Rockspec"
14
15[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.rockspec\Content Type]
16@="text/plain"
17
18[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.rockspec\PerceivedType]
19@="text"
20
21[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec]
22@="Lua Rockspec File"
23
24[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\DefaultIcon]
25@="<LUAROCKSPATH>lua.ico"
26
27[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell]
28@="Edit"
29
30[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Fetch]
31@="Fetch and install"
32
33[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Fetch\Command]
34@="\"<LUAROCKSPATH>luarocksw.bat\" install \"%1\""
35
36[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Install]
37@="Install Lua module"
38
39[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Install\Command]
40@="\"<LUAROCKSPATH>luarocksw.bat\" make \"%1\""
41
42[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Uninstall]
43@="Uninstall Lua module (this version)"
44
45[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Uninstall\Command]
46@="\"<LUAROCKSPATH>luarocksw.bat\" remove \"%1\""
47
48[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\UninstallAll]
49@="Uninstall Lua module (all versions)"
50
51[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\UninstallAll\Command]
52@="\"<LUAROCKSPATH>luarocksw.bat\" removeall \"%1\""
53
54[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Edit]
55@="Edit"
56
57[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Edit\command]
58@="notepad.exe \"%1\""
59
diff --git a/win32/bin/bin/7z.dll b/win32/bin/bin/7z.dll
deleted file mode 100644
index c0ff7fbe..00000000
--- a/win32/bin/bin/7z.dll
+++ /dev/null
Binary files differ
diff --git a/win32/bin/bin/7z.exe b/win32/bin/bin/7z.exe
deleted file mode 100644
index 5e3d6f9c..00000000
--- a/win32/bin/bin/7z.exe
+++ /dev/null
Binary files differ
diff --git a/win32/bin/bin/cp.exe b/win32/bin/bin/cp.exe
deleted file mode 100644
index 0ef4fe85..00000000
--- a/win32/bin/bin/cp.exe
+++ /dev/null
Binary files differ
diff --git a/win32/bin/bin/find.exe b/win32/bin/bin/find.exe
deleted file mode 100644
index 85192fbf..00000000
--- a/win32/bin/bin/find.exe
+++ /dev/null
Binary files differ
diff --git a/win32/bin/bin/libeay32.dll b/win32/bin/bin/libeay32.dll
deleted file mode 100644
index 8d31f866..00000000
--- a/win32/bin/bin/libeay32.dll
+++ /dev/null
Binary files differ
diff --git a/win32/bin/bin/libiconv2.dll b/win32/bin/bin/libiconv2.dll
deleted file mode 100644
index 544dd92f..00000000
--- a/win32/bin/bin/libiconv2.dll
+++ /dev/null
Binary files differ
diff --git a/win32/bin/bin/libintl3.dll b/win32/bin/bin/libintl3.dll
deleted file mode 100644
index ec11e6b1..00000000
--- a/win32/bin/bin/libintl3.dll
+++ /dev/null
Binary files differ
diff --git a/win32/bin/bin/libssl32.dll b/win32/bin/bin/libssl32.dll
deleted file mode 100644
index a30ff0e9..00000000
--- a/win32/bin/bin/libssl32.dll
+++ /dev/null
Binary files differ
diff --git a/win32/bin/bin/ls.exe b/win32/bin/bin/ls.exe
deleted file mode 100644
index 96ff2e57..00000000
--- a/win32/bin/bin/ls.exe
+++ /dev/null
Binary files differ
diff --git a/win32/bin/bin/md5sum.exe b/win32/bin/bin/md5sum.exe
deleted file mode 100644
index 4ae9f74f..00000000
--- a/win32/bin/bin/md5sum.exe
+++ /dev/null
Binary files differ
diff --git a/win32/bin/bin/mkdir.exe b/win32/bin/bin/mkdir.exe
deleted file mode 100644
index 83e57d97..00000000
--- a/win32/bin/bin/mkdir.exe
+++ /dev/null
Binary files differ
diff --git a/win32/bin/bin/mv.exe b/win32/bin/bin/mv.exe
deleted file mode 100644
index 9fb65bb9..00000000
--- a/win32/bin/bin/mv.exe
+++ /dev/null
Binary files differ
diff --git a/win32/bin/bin/pwd.exe b/win32/bin/bin/pwd.exe
deleted file mode 100644
index 7dd114de..00000000
--- a/win32/bin/bin/pwd.exe
+++ /dev/null
Binary files differ
diff --git a/win32/bin/bin/rmdir.exe b/win32/bin/bin/rmdir.exe
deleted file mode 100644
index 6a85c3c4..00000000
--- a/win32/bin/bin/rmdir.exe
+++ /dev/null
Binary files differ
diff --git a/win32/bin/bin/test.exe b/win32/bin/bin/test.exe
deleted file mode 100644
index 94c95f9e..00000000
--- a/win32/bin/bin/test.exe
+++ /dev/null
Binary files differ
diff --git a/win32/bin/bin/uname.exe b/win32/bin/bin/uname.exe
deleted file mode 100644
index 3e2f4cf8..00000000
--- a/win32/bin/bin/uname.exe
+++ /dev/null
Binary files differ
diff --git a/win32/bin/bin/wget.exe b/win32/bin/bin/wget.exe
deleted file mode 100644
index 54b372e6..00000000
--- a/win32/bin/bin/wget.exe
+++ /dev/null
Binary files differ
diff --git a/win32/bin/lua.ico b/win32/bin/lua.ico
deleted file mode 100644
index 56dc4fe1..00000000
--- a/win32/bin/lua.ico
+++ /dev/null
Binary files differ
diff --git a/win32/bin/luarocksw.bat b/win32/bin/luarocksw.bat
deleted file mode 100644
index 8ac02920..00000000
--- a/win32/bin/luarocksw.bat
+++ /dev/null
@@ -1,49 +0,0 @@
1@echo off
2setlocal
3SET MYPATH=%~dp0
4
5IF NOT [%1]==[] GOTO LETSGO
6ECHO Same as 'luarocks' command, except this
7ECHO command will pause after completion, allowing for
8ECHO examination of output.
9ECHO.
10ECHO For LuaRocks help use:
11ECHO LUAROCKS HELP
12ECHO.
13ECHO OPTIONS specific for LUAROCKSW:
14ECHO REMOVEALL is a command specific to this batch file
15ECHO the option takes a FULL ROCKSPEC filename and then
16ECHO it will strip path, version and extension info from
17ECHO it before executing the LUAROCKS REMOVE command
18ECHO Example:
19ECHO luarocksw remove "c:\somedir\modulename-1.0-1.rockspec"
20ECHO will execute:
21ECHO luarocks remove "c:\somedir\modulename-1.0-1.rockspec"
22ECHO and will only remove the specific version 1.0 from the
23ECHO system.
24ECHO luarocksw removeall "c:\somedir\modulename-1.0-1.rockspec"
25ECHO will execute:
26ECHO luarocks remove modulename
27ECHO and will remove all versions of this package
28ECHO.
29GOTO END
30
31:LETSGO
32REM if REMOVEALL command then info must be stripped from the parameter
33if [%1]==[removeall] goto REMOVEALL
34
35REM execute LuaRocks and wait for results
36echo executing: luarocks %*
37call "%MYPATH%luarocks" %*
38pause
39goto END
40
41:REMOVEALL
42for /f "delims=-" %%a in ("%~n2") do (
43 echo executing: luarocks remove %%a
44 "%MYPATH%luarocks" remove "%%a"
45 pause
46 goto END
47)
48
49:END \ No newline at end of file
diff --git a/win32/bin/pe-parser.lua b/win32/bin/pe-parser.lua
deleted file mode 100644
index 30bb8390..00000000
--- a/win32/bin/pe-parser.lua
+++ /dev/null
@@ -1,546 +0,0 @@
1---------------------------------------------------------------------------------------
2-- Lua module to parse a Portable Executable (.exe , .dll, etc.) file and extract metadata.
3--
4-- Version 0.1, [copyright (c) 2013 - Thijs Schreijer](http://www.thijsschreijer.nl)
5-- @name pe-parser
6-- @class module
7
8local M = {}
9
10--- Table with named constants/flag-constants.
11-- Named elements can be looked up by their name in the `const` table. The sub tables are index by value.
12-- For flag fields the name is extended with `_flags`.
13-- @usage -- lookup descriptive name for the myobj.Magic value
14-- local desc = pe.const.Magic(myobj.Magic)
15--
16-- -- get list of flag names, indexed by flag values, for the Characteristics field
17-- local flag_list = pe.const.Characteristics_flags
18M.const = {
19 Magic = {
20 ["10b"] = "PE32",
21 ["20b"] = "PE32+",
22 },
23 Machine = {
24 ["0"] = "IMAGE_FILE_MACHINE_UNKNOWN",
25 ["1d3"] = "IMAGE_FILE_MACHINE_AM33",
26 ["8664"] = "IMAGE_FILE_MACHINE_AMD64",
27 ["1c0"] = "IMAGE_FILE_MACHINE_ARM",
28 ["1c4"] = "IMAGE_FILE_MACHINE_ARMNT",
29 ["aa64"] = "IMAGE_FILE_MACHINE_ARM64",
30 ["ebc"] = "IMAGE_FILE_MACHINE_EBC",
31 ["14c"] = "IMAGE_FILE_MACHINE_I386",
32 ["200"] = "IMAGE_FILE_MACHINE_IA64",
33 ["9041"] = "IMAGE_FILE_MACHINE_M32R",
34 ["266"] = "IMAGE_FILE_MACHINE_MIPS16",
35 ["366"] = "IMAGE_FILE_MACHINE_MIPSFPU",
36 ["466"] = "IMAGE_FILE_MACHINE_MIPSFPU16",
37 ["1f0"] = "IMAGE_FILE_MACHINE_POWERPC",
38 ["1f1"] = "IMAGE_FILE_MACHINE_POWERPCFP",
39 ["166"] = "IMAGE_FILE_MACHINE_R4000",
40 ["1a2"] = "IMAGE_FILE_MACHINE_SH3",
41 ["1a3"] = "IMAGE_FILE_MACHINE_SH3DSP",
42 ["1a6"] = "IMAGE_FILE_MACHINE_SH4",
43 ["1a8"] = "IMAGE_FILE_MACHINE_SH5",
44 ["1c2"] = "IMAGE_FILE_MACHINE_THUMB",
45 ["169"] = "IMAGE_FILE_MACHINE_WCEMIPSV2",
46 },
47 Characteristics_flags = {
48 ["1"] = "IMAGE_FILE_RELOCS_STRIPPED",
49 ["2"] = "IMAGE_FILE_EXECUTABLE_IMAGE",
50 ["4"] = "IMAGE_FILE_LINE_NUMS_STRIPPED",
51 ["8"] = "IMAGE_FILE_LOCAL_SYMS_STRIPPED",
52 ["10"] = "IMAGE_FILE_AGGRESSIVE_WS_TRIM",
53 ["20"] = "IMAGE_FILE_LARGE_ADDRESS_AWARE",
54 ["40"] = "Reserved for future use",
55 ["80"] = "IMAGE_FILE_BYTES_REVERSED_LO",
56 ["100"] = "IMAGE_FILE_32BIT_MACHINE",
57 ["200"] = "IMAGE_FILE_DEBUG_STRIPPED",
58 ["400"] = "IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP",
59 ["800"] = "IMAGE_FILE_NET_RUN_FROM_SWAP",
60 ["1000"] = "IMAGE_FILE_SYSTEM",
61 ["2000"] = "IMAGE_FILE_DLL",
62 ["4000"] = "IMAGE_FILE_UP_SYSTEM_ONLY",
63 ["8000"] = "IMAGE_FILE_BYTES_REVERSED_HI",
64 },
65 Subsystem = {
66 ["0"] = "IMAGE_SUBSYSTEM_UNKNOWN",
67 ["1"] = "IMAGE_SUBSYSTEM_NATIVE",
68 ["2"] = "IMAGE_SUBSYSTEM_WINDOWS_GUI",
69 ["3"] = "IMAGE_SUBSYSTEM_WINDOWS_CUI",
70 ["7"] = "IMAGE_SUBSYSTEM_POSIX_CUI",
71 ["9"] = "IMAGE_SUBSYSTEM_WINDOWS_CE_GUI",
72 ["a"] = "IMAGE_SUBSYSTEM_EFI_APPLICATION",
73 ["b"] = "IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER",
74 ["c"] = "IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER",
75 ["d"] = "IMAGE_SUBSYSTEM_EFI_ROM",
76 ["e"] = "IMAGE_SUBSYSTEM_XBOX",
77 },
78 DllCharacteristics_flags = {
79 ["40"] = "IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE",
80 ["80"] = "IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY",
81 ["100"] = "IMAGE_DLL_CHARACTERISTICS_NX_COMPAT",
82 ["200"] = "IMAGE_DLLCHARACTERISTICS_NO_ISOLATION",
83 ["400"] = "IMAGE_DLLCHARACTERISTICS_NO_SEH",
84 ["800"] = "IMAGE_DLLCHARACTERISTICS_NO_BIND",
85 ["2000"] = "IMAGE_DLLCHARACTERISTICS_WDM_DRIVER",
86 ["8000"] = "IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE",
87 },
88 Sections = {
89 Characteristics_flags = {
90 ["8"] = "IMAGE_SCN_TYPE_NO_PAD",
91 ["20"] = "IMAGE_SCN_CNT_CODE",
92 ["40"] = "IMAGE_SCN_CNT_INITIALIZED_DATA",
93 ["80"] = "IMAGE_SCN_CNT_UNINITIALIZED_ DATA",
94 ["100"] = "IMAGE_SCN_LNK_OTHER",
95 ["200"] = "IMAGE_SCN_LNK_INFO",
96 ["800"] = "IMAGE_SCN_LNK_REMOVE",
97 ["1000"] = "IMAGE_SCN_LNK_COMDAT",
98 ["8000"] = "IMAGE_SCN_GPREL",
99 ["20000"] = "IMAGE_SCN_MEM_PURGEABLE",
100 ["20000"] = "IMAGE_SCN_MEM_16BIT",
101 ["40000"] = "IMAGE_SCN_MEM_LOCKED",
102 ["80000"] = "IMAGE_SCN_MEM_PRELOAD",
103 ["100000"] = "IMAGE_SCN_ALIGN_1BYTES",
104 ["200000"] = "IMAGE_SCN_ALIGN_2BYTES",
105 ["300000"] = "IMAGE_SCN_ALIGN_4BYTES",
106 ["400000"] = "IMAGE_SCN_ALIGN_8BYTES",
107 ["500000"] = "IMAGE_SCN_ALIGN_16BYTES",
108 ["600000"] = "IMAGE_SCN_ALIGN_32BYTES",
109 ["700000"] = "IMAGE_SCN_ALIGN_64BYTES",
110 ["800000"] = "IMAGE_SCN_ALIGN_128BYTES",
111 ["900000"] = "IMAGE_SCN_ALIGN_256BYTES",
112 ["a00000"] = "IMAGE_SCN_ALIGN_512BYTES",
113 ["b00000"] = "IMAGE_SCN_ALIGN_1024BYTES",
114 ["c00000"] = "IMAGE_SCN_ALIGN_2048BYTES",
115 ["d00000"] = "IMAGE_SCN_ALIGN_4096BYTES",
116 ["e00000"] = "IMAGE_SCN_ALIGN_8192BYTES",
117 ["1000000"] = "IMAGE_SCN_LNK_NRELOC_OVFL",
118 ["2000000"] = "IMAGE_SCN_MEM_DISCARDABLE",
119 ["4000000"] = "IMAGE_SCN_MEM_NOT_CACHED",
120 ["8000000"] = "IMAGE_SCN_MEM_NOT_PAGED",
121 ["10000000"] = "IMAGE_SCN_MEM_SHARED",
122 ["20000000"] = "IMAGE_SCN_MEM_EXECUTE",
123 ["40000000"] = "IMAGE_SCN_MEM_READ",
124 ["80000000"] = "IMAGE_SCN_MEM_WRITE",
125 },
126 },
127
128}
129
130
131--- convert integer to HEX representation
132-- @param IN the number to convert to hex
133-- @param len the size to return, any result smaller will be prefixed by "0"s
134-- @return string containing hex representation
135function M.toHex(IN, len)
136 local B,K,OUT,I,D=16,"0123456789abcdef","",0
137 while IN>0 do
138 I=I+1
139 IN,D=math.floor(IN/B),math.fmod(IN,B)+1
140 OUT=string.sub(K,D,D)..OUT
141 end
142 len = len or string.len(OUT)
143 if len<1 then len = 1 end
144 return (string.rep("0",len) .. OUT):sub(-len,-1)
145end
146
147--- convert HEX to integer
148-- @param IN the string to convert to dec
149-- @return number in dec format
150function M.toDec(IN)
151 assert(type(IN)=="string")
152 local OUT = 0
153 IN = IN:lower()
154 while #IN > 0 do
155 local b = string.find("0123456789abcdef",IN:sub(1,1))
156 OUT = OUT * 16 + (b-1)
157 IN = IN:sub(2,-1)
158 end
159 return OUT
160end
161
162local function get_int(str)
163 -- convert a byte-sequence to an integer
164 assert(str)
165 local r = 0
166 for i = #str, 1, -1 do
167 r = r*256 + string.byte(str,i,i)
168 end
169 return r
170end
171
172local function get_hex(str)
173 -- convert a byte-sequence to a hex string
174 assert(str)
175 local r = ""
176 for i = #str, 1, -1 do
177 r = r .. M.toHex(string.byte(str,i,i),2)
178 end
179 while (#r > 1) and (r:sub(1,1) == "0") do
180 r = r:sub(2, -1)
181 end
182 return r
183end
184
185local function get_list(list, f, add_to)
186 -- list: list of tables with 'size' and 'name' and is_str
187 -- f: file to read from
188 -- add_to: table to add results to (optional)
189 local r = add_to or {}
190 for i, t in ipairs(list) do
191 assert(r[t.name] == nil, "Value for '"..t.name.."' already set")
192 local val,err = f:read(t.size) -- read specified size in bytes
193 val = val or "\0"
194 if t.is_str then -- entry is marked as a string value, read as such
195 for i = 1, #val do
196 if val:sub(i,i) == "\0" then
197 r[t.name] = val:sub(1,i-1)
198 break
199 end
200 end
201 r[t.name] = r[t.name] or val
202 else -- entry not marked, so always read as hex value
203 r[t.name] = get_hex(val)
204 end
205 end
206 return r
207end
208
209--- Calculates the fileoffset of a given RVA.
210-- This function is also available as a method on the parsed output table
211-- @param obj a parsed object (return value from `parse`)
212-- @param RVA an RVA value to convert to a fileoffset (either number or hex-string)
213-- @return fileoffset of the given RVA (number)
214M.get_fileoffset = function(obj, RVA)
215 -- given an object with a section table, and an RVA, it returns
216 -- the fileoffset for the data
217 if type(RVA)=="string" then RVA = M.toDec(RVA) end
218 local section
219 for i, s in ipairs(obj.Sections) do
220 if M.toDec(s.VirtualAddress) <= RVA and M.toDec(s.VirtualAddress) + M.toDec(s.VirtualSize) >= RVA then
221 section = s
222 break
223 end
224 end
225 if not section then return nil, "No match RVA with Section list, RVA out of bounds" end
226 return RVA - M.toDec(section.VirtualAddress) + M.toDec(section.PointerToRawData)
227end
228
229local function readstring(f)
230 -- reads a null-terminated string from the current file posistion
231 local name = ""
232 while true do
233 local c = f:read(1)
234 if c == "\0" then break end
235 name = name .. c
236 end
237 return name
238end
239
240--- Parses a file and extracts the information.
241-- All numbers are delivered as "string" types containing hex values, see `toHex` and `toDec` conversion functions.
242-- @return table with data, or nil + error
243-- @usage local pe = require("pe-parser")
244-- local obj = pe.parse("c:\lua\lua.exe")
245-- obj:dump()
246M.parse = function(target)
247
248 local list = { -- list of known architectures
249 [332] = "x86", -- IMAGE_FILE_MACHINE_I386
250 [512] = "x86_64", -- IMAGE_FILE_MACHINE_IA64
251 [34404] = "x86_64", -- IMAGE_FILE_MACHINE_AMD64
252 }
253
254 local f, err = io.open(target, "rb")
255 if not f then return nil, err end
256
257 local MZ = f:read(2)
258 if MZ ~= "MZ" then
259 f:close()
260 return nil, "Not a valid image"
261 end
262
263 f:seek("set", 60) -- position of PE header position
264 local peoffset = get_int(f:read(4)) -- read position of PE header
265
266 f:seek("set", peoffset) -- move to position of PE header
267 local out = get_list({
268 { size = 4,
269 name = "PEheader",
270 is_str = true },
271 { size = 2,
272 name = "Machine" },
273 { size = 2,
274 name = "NumberOfSections"},
275 { size = 4,
276 name = "TimeDateStamp" },
277 { size = 4,
278 name = "PointerToSymbolTable"},
279 { size = 4,
280 name = "NumberOfSymbols"},
281 { size = 2,
282 name = "SizeOfOptionalHeader"},
283 { size = 2,
284 name = "Characteristics"},
285 }, f)
286
287 if out.PEheader ~= "PE" then
288 f:close()
289 return nil, "Invalid PE header"
290 end
291 out.PEheader = nil -- remove it, has no value
292 out.dump = M.dump -- export dump function as a method
293
294 if M.toDec(out.SizeOfOptionalHeader) > 0 then
295 -- parse optional header; standard
296 get_list({
297 { size = 2,
298 name = "Magic" },
299 { size = 1,
300 name = "MajorLinkerVersion"},
301 { size = 1,
302 name = "MinorLinkerVersion"},
303 { size = 4,
304 name = "SizeOfCode"},
305 { size = 4,
306 name = "SizeOfInitializedData"},
307 { size = 4,
308 name = "SizeOfUninitializedData"},
309 { size = 4,
310 name = "AddressOfEntryPoint"},
311 { size = 4,
312 name = "BaseOfCode"},
313 }, f, out)
314 local plus = (out.Magic == "20b")
315 if not plus then -- plain PE32, not PE32+
316 get_list({
317 { size = 4,
318 name = "BaseOfData" },
319 }, f, out)
320 end
321 -- parse optional header; windows-fields
322 local plussize = 4
323 if plus then plussize = 8 end
324 get_list({
325 { size = plussize,
326 name = "ImageBase"},
327 { size = 4,
328 name = "SectionAlignment"},
329 { size = 4,
330 name = "FileAlignment"},
331 { size = 2,
332 name = "MajorOperatingSystemVersion"},
333 { size = 2,
334 name = "MinorOperatingSystemVersion"},
335 { size = 2,
336 name = "MajorImageVersion"},
337 { size = 2,
338 name = "MinorImageVersion"},
339 { size = 2,
340 name = "MajorSubsystemVersion"},
341 { size = 2,
342 name = "MinorSubsystemVersion"},
343 { size = 4,
344 name = "Win32VersionValue"},
345 { size = 4,
346 name = "SizeOfImage"},
347 { size = 4,
348 name = "SizeOfHeaders"},
349 { size = 4,
350 name = "CheckSum"},
351 { size = 2,
352 name = "Subsystem"},
353 { size = 2,
354 name = "DllCharacteristics"},
355 { size = plussize,
356 name = "SizeOfStackReserve"},
357 { size = plussize,
358 name = "SizeOfStackCommit"},
359 { size = plussize,
360 name = "SizeOfHeapReserve"},
361 { size = plussize,
362 name = "SizeOfHeapCommit"},
363 { size = 4,
364 name = "LoaderFlags"},
365 { size = 4,
366 name = "NumberOfRvaAndSizes"},
367 }, f, out)
368 -- Read data directory entries
369 for i = 1, M.toDec(out.NumberOfRvaAndSizes) do
370 out.DataDirectory = out.DataDirectory or {}
371 out.DataDirectory[i] = get_list({
372 { size = 4,
373 name = "VirtualAddress"},
374 { size = 4,
375 name = "Size"},
376 }, f)
377 end
378 for i, name in ipairs{"ExportTable", "ImportTable", "ResourceTable",
379 "ExceptionTable", "CertificateTable", "BaseRelocationTable",
380 "Debug", "Architecture", "GlobalPtr", "TLSTable",
381 "LoadConfigTable", "BoundImport", "IAT",
382 "DelayImportDescriptor", "CLRRuntimeHeader", "Reserved"} do
383 out.DataDirectory[name] = out.DataDirectory[i]
384 if out.DataDirectory[name] then out.DataDirectory[name].name = name end
385 end
386 end
387
388 -- parse section table
389 for i = 1, M.toDec(out.NumberOfSections) do
390 out.Sections = out.Sections or {}
391 out.Sections[i] = get_list({
392 { size = 8,
393 name = "Name",
394 is_str = true},
395 { size = 4,
396 name = "VirtualSize"},
397 { size = 4,
398 name = "VirtualAddress"},
399 { size = 4,
400 name = "SizeOfRawData"},
401 { size = 4,
402 name = "PointerToRawData"},
403 { size = 4,
404 name = "PointerToRelocations"},
405 { size = 4,
406 name = "PointerToLinenumbers"},
407 { size = 2,
408 name = "NumberOfRelocations"},
409 { size = 2,
410 name = "NumberOfLinenumbers"},
411 { size = 4,
412 name = "Characteristics"},
413 }, f)
414 end
415 -- we now have section data, so add RVA convertion method
416 out.get_fileoffset = M.get_fileoffset
417
418 -- get the import table
419 f:seek("set", out:get_fileoffset(out.DataDirectory.ImportTable.VirtualAddress))
420 local done = false
421 local cnt = 1
422 while not done do
423 local dll = get_list({
424 { size = 4,
425 name = "ImportLookupTableRVA"},
426 { size = 4,
427 name = "TimeDateStamp"},
428 { size = 4,
429 name = "ForwarderChain"},
430 { size = 4,
431 name = "NameRVA"},
432 { size = 4,
433 name = "ImportAddressTableRVA"},
434 }, f)
435 if M.toDec(dll.NameRVA) == 0 then
436 -- this is the final NULL entry, so we're done
437 done = true
438 else
439 -- store the import entry
440 out.DataDirectory.ImportTable[cnt] = dll
441 cnt = cnt + 1
442 end
443 end
444 -- resolve imported DLL names
445 for i, dll in ipairs(out.DataDirectory.ImportTable) do
446 f:seek("set", out:get_fileoffset(dll.NameRVA))
447 dll.Name = readstring(f)
448 end
449
450 f:close()
451 return out
452end
453
454-- pad a string (prefix) to a specific length
455local function pad(str, l, chr)
456 chr = chr or " "
457 l = l or 0
458 return string.rep(chr,l-#str)..str
459end
460
461--- Dumps the output parsed.
462-- This function is also available as a method on the parsed output table
463M.dump = function(obj)
464 local l = 0
465 for k,v in pairs(obj) do if #k > l then l = #k end end
466
467 for k,v in pairs(obj) do
468 if (M.const[k] and type(v)=="string") then
469 -- look up named value
470 print(k..string.rep(" ", l - #k + 1)..": "..M.const[k][v])
471 elseif M.const[k.."_flags"] then
472 -- flags should be listed
473 print(k..string.rep(" ", l - #k + 1)..": "..v.." (flag field)")
474 else
475 -- regular values
476 if type(v) == "number" then
477 print(k..string.rep(" ", l - #k + 1)..": "..v.." (dec)")
478 else
479 if (type(v)=="string") and (k ~= "DataDirectory") and (k ~= "Sections") then
480 print(k..string.rep(" ", l - #k + 1)..": "..v)
481 end
482 end
483 end
484 end
485
486 if obj.DataDirectory then
487 print("DataDirectory (RVA, size):")
488 for i, v in ipairs(obj.DataDirectory) do
489 print(" Entry "..M.toHex(i-1).." "..pad(v.VirtualAddress,8,"0").." "..pad(v.Size,8,"0").." "..v.name)
490 end
491 end
492
493 if obj.Sections then
494 print("Sections:")
495 print("idx name RVA VSize Offset RawSize")
496 for i, v in ipairs(obj.Sections) do
497 print(" "..i.." "..v.Name.. string.rep(" ",9-#v.Name)..pad(v.VirtualAddress,8,"0").." "..pad(v.VirtualSize,8,"0").." "..pad(v.PointerToRawData,8,"0").." "..pad(v.SizeOfRawData,8,"0"))
498 end
499 end
500
501 print("Imports:")
502 for i, dll in ipairs(obj.DataDirectory.ImportTable) do
503 print(" "..dll.Name)
504 end
505end
506
507--- Checks the msvcrt dll the binary was linked against.
508-- Mixing and matching dlls only works when they all are using the same runtime, if
509-- not unexpected errors will probably occur.
510-- Checks the binary provided and then traverses all imported dlls to find the msvcrt
511-- used (it will only look for the dlls in the same directory).
512-- @param infile binary file to check
513-- @return msvcrt name (uppercase, without extension) + file where the reference was found, or nil + error
514function M.msvcrt(infile)
515 local path, file = infile:match("(.+)\\(.+)$")
516 if not path then
517 path = ""
518 file = infile
519 else
520 path=path .. "\\"
521 end
522 local obj, err = M.parse(path..file)
523 if not obj then return obj, err end
524
525 for i, dll in ipairs(obj.DataDirectory.ImportTable) do
526 dll = dll.Name:upper()
527 local result = dll:match('(MSVCR%d*)%.DLL')
528 if not result then
529 result = dll:match('(MSVCRT)%.DLL')
530 end
531 -- success, found it return name + binary where it was found
532 if result then return result, infile end
533 end
534
535 -- not found, so traverse all imported dll's
536 for i, dll in ipairs(obj.DataDirectory.ImportTable) do
537 local rt, ref = M.msvcrt(path..dll.Name)
538 if rt then
539 return rt, ref -- found it
540 end
541 end
542
543 return nil, "No msvcrt found"
544end
545
546return M
diff --git a/win32/bin/rclauncher.c b/win32/bin/rclauncher.c
deleted file mode 100644
index 77459f46..00000000
--- a/win32/bin/rclauncher.c
+++ /dev/null
@@ -1,139 +0,0 @@
1
2/*
3** Simple Lua interpreter.
4** This program is used to run a Lua file embedded as a resource.
5** It creates a Lua state, opens all its standard libraries, and run
6** the Lua file in a protected environment just to redirect the error
7** messages to stdout and stderr.
8**
9** $Id: rclauncher.c,v 1.1 2008/06/30 14:29:59 carregal Exp $
10*/
11
12#include <string.h>
13#include <stdlib.h>
14
15#include "lua.h"
16#include "lauxlib.h"
17#include "lualib.h"
18#include <windows.h>
19#include <io.h>
20#include <fcntl.h>
21
22/*
23** Report error message.
24** Assumes that the error message is on top of the stack.
25*/
26static int report (lua_State *L) {
27 fprintf (stderr, "lua: fatal error: `%s'\n", lua_tostring (L, -1));
28 fflush (stderr);
29 printf ("Content-type: text/plain\n\nConfiguration fatal error: see error log!\n");
30 printf ("%s", lua_tostring(L, -1));
31 return 1;
32}
33
34static int runlua (lua_State *L, const char *lua_string, int argc, char *argv[]) {
35 int err_func;
36 int err;
37
38 lua_getglobal(L, "debug");
39 lua_pushliteral(L, "traceback");
40 lua_gettable(L, -2);
41 err_func = lua_gettop (L);
42 err = luaL_loadstring (L, lua_string);
43 if(!err) {
44 int i;
45 // fill global arg table
46 lua_getglobal(L, "arg");
47 for(i = 1; i < argc; i++)
48 {
49 lua_pushstring(L, argv[i]);
50 lua_rawseti(L, -2, i);
51 }
52 lua_pop(L, 1);
53 // fill parameters (in vararg '...')
54 for(i = 1; i < argc; i++)
55 lua_pushstring(L, argv[i]);
56 return lua_pcall (L, argc - 1, LUA_MULTRET, err_func);
57 } else return err;
58}
59
60static DWORD GetModulePath( HINSTANCE hInst, LPTSTR pszBuffer, DWORD dwSize )
61//
62// Return the size of the path in bytes.
63{
64 DWORD dwLength = GetModuleFileName( hInst, pszBuffer, dwSize );
65 if( dwLength )
66 {
67 while( dwLength && pszBuffer[ dwLength ] != '.' )
68 {
69 dwLength--;
70 }
71
72 if( dwLength )
73 pszBuffer[ dwLength ] = '\000';
74 }
75 return dwLength;
76}
77
78
79/*
80** MAIN
81*/
82int main (int argc, char *argv[]) {
83 char name[ MAX_PATH ];
84 DWORD dwLength;
85 int size;
86 luaL_Buffer b;
87 int i;
88#ifdef UNICODE
89 TCHAR lua_wstring[4098];
90#endif
91 char lua_string[4098];
92 lua_State *L = luaL_newstate();
93 (void)argc; /* avoid "unused parameter" warning */
94 luaL_openlibs(L);
95 lua_newtable(L); // create arg table
96 lua_pushstring(L, argv[0]); // add interpreter to arg table
97 lua_rawseti(L, -2, -1);
98 dwLength = GetModulePath( NULL, name, MAX_PATH );
99 if(dwLength) { /* Optional bootstrap */
100 strcat(name, ".lua");
101 lua_pushstring(L, name); // add lua script to arg table
102 lua_rawseti(L, -2, 0);
103 lua_setglobal(L,"arg"); // set global arg table
104 if(!luaL_loadfile (L, name)) {
105 if(lua_pcall (L, 0, LUA_MULTRET, 0)) {
106 report (L);
107 lua_close (L);
108 return EXIT_FAILURE;
109 }
110 }
111 }
112 else
113 {
114 lua_pushstring(L, argv[0]); // no lua script, so add interpreter again, now as lua script
115 lua_rawseti(L, -2, 0);
116 lua_setglobal(L,"arg"); // set global arg table
117 }
118
119 luaL_buffinit(L, &b);
120 for(i = 1; ; i++) {
121#ifdef UNICODE
122 size = LoadString(GetModuleHandle(NULL), i, lua_wstring,
123 sizeof(lua_string)/sizeof(TCHAR));
124 if(size > 0) wcstombs(lua_string, lua_wstring, size + 1);
125#else
126 size = LoadString(GetModuleHandle(NULL), i, lua_string,
127 sizeof(lua_string)/sizeof(char));
128#endif
129 if(size) luaL_addlstring(&b, lua_string, size); else break;
130 }
131 luaL_pushresult(&b);
132 if (runlua (L, lua_tostring(L, -1), argc, argv)) {
133 report (L);
134 lua_close (L);
135 return EXIT_FAILURE;
136 }
137 lua_close (L);
138 return EXIT_SUCCESS;
139}