From 1dd5293f0c725c1d5f290bbed51b3bec59748d16 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Tue, 6 May 2014 22:43:00 +0200 Subject: Reorganized Windows specific files. Now installer can work directly from the repository --- install.bat | 25 +- src/luarocks/cfg.lua | 2 +- win32/LuaRocks.reg.lua | 51 ++++ win32/LuaRocks.reg.template | 59 +++++ win32/bin/LuaRocks.reg.lua | 51 ---- win32/bin/LuaRocks.reg.template | 59 ----- win32/bin/bin/7z.dll | Bin 858624 -> 0 bytes win32/bin/bin/7z.exe | Bin 161792 -> 0 bytes win32/bin/bin/cp.exe | Bin 130048 -> 0 bytes win32/bin/bin/find.exe | Bin 160256 -> 0 bytes win32/bin/bin/libeay32.dll | Bin 1177600 -> 0 bytes win32/bin/bin/libiconv2.dll | Bin 1008128 -> 0 bytes win32/bin/bin/libintl3.dll | Bin 103424 -> 0 bytes win32/bin/bin/libssl32.dll | Bin 232960 -> 0 bytes win32/bin/bin/ls.exe | Bin 180736 -> 0 bytes win32/bin/bin/md5sum.exe | Bin 41984 -> 0 bytes win32/bin/bin/mkdir.exe | Bin 32768 -> 0 bytes win32/bin/bin/mv.exe | Bin 138752 -> 0 bytes win32/bin/bin/pwd.exe | Bin 61440 -> 0 bytes win32/bin/bin/rmdir.exe | Bin 25088 -> 0 bytes win32/bin/bin/test.exe | Bin 62976 -> 0 bytes win32/bin/bin/uname.exe | Bin 33792 -> 0 bytes win32/bin/bin/wget.exe | Bin 449024 -> 0 bytes win32/bin/lua.ico | Bin 22486 -> 0 bytes win32/bin/luarocksw.bat | 49 ---- win32/bin/pe-parser.lua | 546 ---------------------------------------- win32/bin/rclauncher.c | 139 ---------- win32/lua.ico | Bin 0 -> 22486 bytes win32/luarocksw.bat | 49 ++++ win32/pe-parser.lua | 546 ++++++++++++++++++++++++++++++++++++++++ win32/rclauncher.c | 139 ++++++++++ win32/tools/7z.dll | Bin 0 -> 858624 bytes win32/tools/7z.exe | Bin 0 -> 161792 bytes win32/tools/cp.exe | Bin 0 -> 130048 bytes win32/tools/find.exe | Bin 0 -> 160256 bytes win32/tools/libeay32.dll | Bin 0 -> 1177600 bytes win32/tools/libiconv2.dll | Bin 0 -> 1008128 bytes win32/tools/libintl3.dll | Bin 0 -> 103424 bytes win32/tools/libssl32.dll | Bin 0 -> 232960 bytes win32/tools/ls.exe | Bin 0 -> 180736 bytes win32/tools/md5sum.exe | Bin 0 -> 41984 bytes win32/tools/mkdir.exe | Bin 0 -> 32768 bytes win32/tools/mv.exe | Bin 0 -> 138752 bytes win32/tools/pwd.exe | Bin 0 -> 61440 bytes win32/tools/rmdir.exe | Bin 0 -> 25088 bytes win32/tools/test.exe | Bin 0 -> 62976 bytes win32/tools/uname.exe | Bin 0 -> 33792 bytes win32/tools/wget.exe | Bin 0 -> 449024 bytes win32pack.bat | 33 --- 49 files changed, 862 insertions(+), 886 deletions(-) create mode 100644 win32/LuaRocks.reg.lua create mode 100644 win32/LuaRocks.reg.template delete mode 100644 win32/bin/LuaRocks.reg.lua delete mode 100644 win32/bin/LuaRocks.reg.template delete mode 100644 win32/bin/bin/7z.dll delete mode 100644 win32/bin/bin/7z.exe delete mode 100644 win32/bin/bin/cp.exe delete mode 100644 win32/bin/bin/find.exe delete mode 100644 win32/bin/bin/libeay32.dll delete mode 100644 win32/bin/bin/libiconv2.dll delete mode 100644 win32/bin/bin/libintl3.dll delete mode 100644 win32/bin/bin/libssl32.dll delete mode 100644 win32/bin/bin/ls.exe delete mode 100644 win32/bin/bin/md5sum.exe delete mode 100644 win32/bin/bin/mkdir.exe delete mode 100644 win32/bin/bin/mv.exe delete mode 100644 win32/bin/bin/pwd.exe delete mode 100644 win32/bin/bin/rmdir.exe delete mode 100644 win32/bin/bin/test.exe delete mode 100644 win32/bin/bin/uname.exe delete mode 100644 win32/bin/bin/wget.exe delete mode 100644 win32/bin/lua.ico delete mode 100644 win32/bin/luarocksw.bat delete mode 100644 win32/bin/pe-parser.lua delete mode 100644 win32/bin/rclauncher.c create mode 100644 win32/lua.ico create mode 100644 win32/luarocksw.bat create mode 100644 win32/pe-parser.lua create mode 100644 win32/rclauncher.c create mode 100644 win32/tools/7z.dll create mode 100644 win32/tools/7z.exe create mode 100644 win32/tools/cp.exe create mode 100644 win32/tools/find.exe create mode 100644 win32/tools/libeay32.dll create mode 100644 win32/tools/libiconv2.dll create mode 100644 win32/tools/libintl3.dll create mode 100644 win32/tools/libssl32.dll create mode 100644 win32/tools/ls.exe create mode 100644 win32/tools/md5sum.exe create mode 100644 win32/tools/mkdir.exe create mode 100644 win32/tools/mv.exe create mode 100644 win32/tools/pwd.exe create mode 100644 win32/tools/rmdir.exe create mode 100644 win32/tools/test.exe create mode 100644 win32/tools/uname.exe create mode 100644 win32/tools/wget.exe delete mode 100644 win32pack.bat diff --git a/install.bat b/install.bat index 6dc8cd02..85ef73f6 100644 --- a/install.bat +++ b/install.bat @@ -1,6 +1,6 @@ rem=rem --[[ @setlocal& set luafile="%~f0" & if exist "%~f0.bat" set luafile="%~f0.bat" -@lua5.1\bin\lua5.1.exe %luafile% %*& exit /b ]] +@win32\lua5.1\bin\lua5.1.exe %luafile% %*& exit /b ]] local vars = {} @@ -38,7 +38,7 @@ local SELFCONTAINED = false -- Some helpers -- -local pe = assert(loadfile(".\\bin\\pe-parser.lua"))() +local pe = assert(loadfile(".\\win32\\pe-parser.lua"))() local function die(message) if message then print(message) end @@ -80,12 +80,12 @@ local function exec(cmd) end local function exists(filename) - local cmd = [[.\bin\bin\test -e "]]..filename..[["]] + local cmd = [[.\win32\tools\test -e "]]..filename..[["]] return exec(cmd) end local function mkdir (dir) - return exec([[.\bin\bin\mkdir -p "]]..dir..[[" >NUL]]) + return exec([[.\win32\tools\mkdir -p "]]..dir..[[" >NUL]]) end -- does the current user have admin priviledges ( = elevated) @@ -666,13 +666,22 @@ if INSTALL_LUA then if not exists(vars.LUA_INCDIR) then mkdir(vars.LUA_INCDIR) end - exec(S[[COPY lua5.1\bin\*.* "$LUA_BINDIR" >NUL]]) - exec(S[[COPY lua5.1\include\*.* "$LUA_INCDIR" >NUL]]) + exec(S[[COPY win32\lua5.1\bin\*.* "$LUA_BINDIR" >NUL]]) + exec(S[[COPY win32\lua5.1\include\*.* "$LUA_INCDIR" >NUL]]) print(S"Installed the LuaRocks bundled Lua interpreter in $LUA_BINDIR") end -- Copy the LuaRocks binaries -if not exec(S[[XCOPY /S bin\*.* "$BINDIR" >NUL]]) then +if not exists(S[[$BINDIR\tools]]) then + if not mkdir(S[[$BINDIR\tools]]) then + die() + end +end +if not exec(S[[COPY win32\tools\*.* "$BINDIR\tools" >NUL]]) then + die() +end +-- Copy LR bin helper files +if not exec(S[[COPY win32\*.* "$BINDIR" >NUL]]) then die() end -- Copy the LuaRocks lua source files @@ -870,7 +879,7 @@ if REGISTRY then -- expand template with correct path information print() print([[Loading registry information for ".rockspec" files]]) - exec( S[[lua5.1\bin\lua5.1.exe "$FULL_PREFIX\LuaRocks.reg.lua" "$FULL_PREFIX\LuaRocks.reg.template"]] ) + exec( S[[win32\lua5.1\bin\lua5.1.exe "$FULL_PREFIX\LuaRocks.reg.lua" "$FULL_PREFIX\LuaRocks.reg.template"]] ) exec( S[[regedit /S "$FULL_PREFIX\\LuaRocks.reg"]] ) end diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 693cdbdb..59a17754 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -319,7 +319,7 @@ if detected.windows then "MKDIR", "MV", "PWD", "RMDIR", "TEST", "UNAME", "WGET" } for _, var in ipairs(bins) do if defaults.variables[var] then - defaults.variables[var] = full_prefix.."\\bin\\"..defaults.variables[var] + defaults.variables[var] = full_prefix.."\\tools\\"..defaults.variables[var] end end diff --git a/win32/LuaRocks.reg.lua b/win32/LuaRocks.reg.lua new file mode 100644 index 00000000..2eb7583a --- /dev/null +++ b/win32/LuaRocks.reg.lua @@ -0,0 +1,51 @@ +-- Call this file using its full path and the template file as a parameter; +-- +-- C:\> lua.exe "create_reg_file.lua" "c:\luarocks\2.0\LuaRocks.reg.template" +-- +-- it will strip the ".template" extension and write to that file the +-- template contents, where "" will be replaced by the path +-- to LuaRocks (including the trailing backslash) + + + +-- Check argument +local f = (arg or {})[1] +if not f then + print("must provide template file on command line") + os.exit(1) +end + +-- cleanup filepath, remove all double backslashes +while f:match("\\\\") do + f = f:gsub("\\\\", "\\") +end + +-- extract path and name from argument +local p = "" +local ni = f +for i = #f, 1, -1 do + if f:sub(i,i) == "\\" then + ni = f:sub(i+1) + p = f:sub(1, i) + break + end +end + +-- create output name +local no = ni:gsub("%.template","") + +-- create path substitute; escape backslash by doubles +local ps = p:gsub("\\", "\\\\") + +-- read template +local fh = io.open(f) +local content = fh:read("*a") +fh:close() + +-- fill template +content = content:gsub("%", ps) + +-- write destination file +fh = io.open(p..no, "w+") +fh:write(content) +fh:close() diff --git a/win32/LuaRocks.reg.template b/win32/LuaRocks.reg.template new file mode 100644 index 00000000..82cc180f --- /dev/null +++ b/win32/LuaRocks.reg.template @@ -0,0 +1,59 @@ +Windows Registry Editor Version 5.00 + +[HKEY_CLASSES_ROOT\.rockspec] +@="Lua.Rockspec" + +[HKEY_CLASSES_ROOT\.rockspec\Content Type] +@="text/plain" + +[HKEY_CLASSES_ROOT\.rockspec\PerceivedType] +@="text" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.rockspec] +@="Lua.Rockspec" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.rockspec\Content Type] +@="text/plain" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.rockspec\PerceivedType] +@="text" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec] +@="Lua Rockspec File" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\DefaultIcon] +@="lua.ico" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell] +@="Edit" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Fetch] +@="Fetch and install" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Fetch\Command] +@="\"luarocksw.bat\" install \"%1\"" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Install] +@="Install Lua module" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Install\Command] +@="\"luarocksw.bat\" make \"%1\"" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Uninstall] +@="Uninstall Lua module (this version)" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Uninstall\Command] +@="\"luarocksw.bat\" remove \"%1\"" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\UninstallAll] +@="Uninstall Lua module (all versions)" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\UninstallAll\Command] +@="\"luarocksw.bat\" removeall \"%1\"" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Edit] +@="Edit" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Edit\command] +@="notepad.exe \"%1\"" + 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 @@ --- Call this file using its full path and the template file as a parameter; --- --- C:\> lua.exe "create_reg_file.lua" "c:\luarocks\2.0\LuaRocks.reg.template" --- --- it will strip the ".template" extension and write to that file the --- template contents, where "" will be replaced by the path --- to LuaRocks (including the trailing backslash) - - - --- Check argument -local f = (arg or {})[1] -if not f then - print("must provide template file on command line") - os.exit(1) -end - --- cleanup filepath, remove all double backslashes -while f:match("\\\\") do - f = f:gsub("\\\\", "\\") -end - --- extract path and name from argument -local p = "" -local ni = f -for i = #f, 1, -1 do - if f:sub(i,i) == "\\" then - ni = f:sub(i+1) - p = f:sub(1, i) - break - end -end - --- create output name -local no = ni:gsub("%.template","") - --- create path substitute; escape backslash by doubles -local ps = p:gsub("\\", "\\\\") - --- read template -local fh = io.open(f) -local content = fh:read("*a") -fh:close() - --- fill template -content = content:gsub("%", ps) - --- write destination file -fh = io.open(p..no, "w+") -fh:write(content) -fh: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 @@ -Windows Registry Editor Version 5.00 - -[HKEY_CLASSES_ROOT\.rockspec] -@="Lua.Rockspec" - -[HKEY_CLASSES_ROOT\.rockspec\Content Type] -@="text/plain" - -[HKEY_CLASSES_ROOT\.rockspec\PerceivedType] -@="text" - -[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.rockspec] -@="Lua.Rockspec" - -[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.rockspec\Content Type] -@="text/plain" - -[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.rockspec\PerceivedType] -@="text" - -[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec] -@="Lua Rockspec File" - -[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\DefaultIcon] -@="lua.ico" - -[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell] -@="Edit" - -[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Fetch] -@="Fetch and install" - -[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Fetch\Command] -@="\"luarocksw.bat\" install \"%1\"" - -[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Install] -@="Install Lua module" - -[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Install\Command] -@="\"luarocksw.bat\" make \"%1\"" - -[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Uninstall] -@="Uninstall Lua module (this version)" - -[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Uninstall\Command] -@="\"luarocksw.bat\" remove \"%1\"" - -[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\UninstallAll] -@="Uninstall Lua module (all versions)" - -[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\UninstallAll\Command] -@="\"luarocksw.bat\" removeall \"%1\"" - -[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Edit] -@="Edit" - -[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Lua.Rockspec\Shell\Edit\command] -@="notepad.exe \"%1\"" - diff --git a/win32/bin/bin/7z.dll b/win32/bin/bin/7z.dll deleted file mode 100644 index c0ff7fbe..00000000 Binary files a/win32/bin/bin/7z.dll and /dev/null differ diff --git a/win32/bin/bin/7z.exe b/win32/bin/bin/7z.exe deleted file mode 100644 index 5e3d6f9c..00000000 Binary files a/win32/bin/bin/7z.exe and /dev/null differ diff --git a/win32/bin/bin/cp.exe b/win32/bin/bin/cp.exe deleted file mode 100644 index 0ef4fe85..00000000 Binary files a/win32/bin/bin/cp.exe and /dev/null differ diff --git a/win32/bin/bin/find.exe b/win32/bin/bin/find.exe deleted file mode 100644 index 85192fbf..00000000 Binary files a/win32/bin/bin/find.exe and /dev/null differ diff --git a/win32/bin/bin/libeay32.dll b/win32/bin/bin/libeay32.dll deleted file mode 100644 index 8d31f866..00000000 Binary files a/win32/bin/bin/libeay32.dll and /dev/null differ diff --git a/win32/bin/bin/libiconv2.dll b/win32/bin/bin/libiconv2.dll deleted file mode 100644 index 544dd92f..00000000 Binary files a/win32/bin/bin/libiconv2.dll and /dev/null differ diff --git a/win32/bin/bin/libintl3.dll b/win32/bin/bin/libintl3.dll deleted file mode 100644 index ec11e6b1..00000000 Binary files a/win32/bin/bin/libintl3.dll and /dev/null differ diff --git a/win32/bin/bin/libssl32.dll b/win32/bin/bin/libssl32.dll deleted file mode 100644 index a30ff0e9..00000000 Binary files a/win32/bin/bin/libssl32.dll and /dev/null differ diff --git a/win32/bin/bin/ls.exe b/win32/bin/bin/ls.exe deleted file mode 100644 index 96ff2e57..00000000 Binary files a/win32/bin/bin/ls.exe and /dev/null differ diff --git a/win32/bin/bin/md5sum.exe b/win32/bin/bin/md5sum.exe deleted file mode 100644 index 4ae9f74f..00000000 Binary files a/win32/bin/bin/md5sum.exe and /dev/null differ diff --git a/win32/bin/bin/mkdir.exe b/win32/bin/bin/mkdir.exe deleted file mode 100644 index 83e57d97..00000000 Binary files a/win32/bin/bin/mkdir.exe and /dev/null differ diff --git a/win32/bin/bin/mv.exe b/win32/bin/bin/mv.exe deleted file mode 100644 index 9fb65bb9..00000000 Binary files a/win32/bin/bin/mv.exe and /dev/null differ diff --git a/win32/bin/bin/pwd.exe b/win32/bin/bin/pwd.exe deleted file mode 100644 index 7dd114de..00000000 Binary files a/win32/bin/bin/pwd.exe and /dev/null differ diff --git a/win32/bin/bin/rmdir.exe b/win32/bin/bin/rmdir.exe deleted file mode 100644 index 6a85c3c4..00000000 Binary files a/win32/bin/bin/rmdir.exe and /dev/null differ diff --git a/win32/bin/bin/test.exe b/win32/bin/bin/test.exe deleted file mode 100644 index 94c95f9e..00000000 Binary files a/win32/bin/bin/test.exe and /dev/null differ diff --git a/win32/bin/bin/uname.exe b/win32/bin/bin/uname.exe deleted file mode 100644 index 3e2f4cf8..00000000 Binary files a/win32/bin/bin/uname.exe and /dev/null differ diff --git a/win32/bin/bin/wget.exe b/win32/bin/bin/wget.exe deleted file mode 100644 index 54b372e6..00000000 Binary files a/win32/bin/bin/wget.exe and /dev/null differ diff --git a/win32/bin/lua.ico b/win32/bin/lua.ico deleted file mode 100644 index 56dc4fe1..00000000 Binary files a/win32/bin/lua.ico and /dev/null 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 @@ -@echo off -setlocal -SET MYPATH=%~dp0 - -IF NOT [%1]==[] GOTO LETSGO -ECHO Same as 'luarocks' command, except this -ECHO command will pause after completion, allowing for -ECHO examination of output. -ECHO. -ECHO For LuaRocks help use: -ECHO LUAROCKS HELP -ECHO. -ECHO OPTIONS specific for LUAROCKSW: -ECHO REMOVEALL is a command specific to this batch file -ECHO the option takes a FULL ROCKSPEC filename and then -ECHO it will strip path, version and extension info from -ECHO it before executing the LUAROCKS REMOVE command -ECHO Example: -ECHO luarocksw remove "c:\somedir\modulename-1.0-1.rockspec" -ECHO will execute: -ECHO luarocks remove "c:\somedir\modulename-1.0-1.rockspec" -ECHO and will only remove the specific version 1.0 from the -ECHO system. -ECHO luarocksw removeall "c:\somedir\modulename-1.0-1.rockspec" -ECHO will execute: -ECHO luarocks remove modulename -ECHO and will remove all versions of this package -ECHO. -GOTO END - -:LETSGO -REM if REMOVEALL command then info must be stripped from the parameter -if [%1]==[removeall] goto REMOVEALL - -REM execute LuaRocks and wait for results -echo executing: luarocks %* -call "%MYPATH%luarocks" %* -pause -goto END - -:REMOVEALL -for /f "delims=-" %%a in ("%~n2") do ( - echo executing: luarocks remove %%a - "%MYPATH%luarocks" remove "%%a" - pause - goto END -) - -: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 @@ ---------------------------------------------------------------------------------------- --- Lua module to parse a Portable Executable (.exe , .dll, etc.) file and extract metadata. --- --- Version 0.1, [copyright (c) 2013 - Thijs Schreijer](http://www.thijsschreijer.nl) --- @name pe-parser --- @class module - -local M = {} - ---- Table with named constants/flag-constants. --- Named elements can be looked up by their name in the `const` table. The sub tables are index by value. --- For flag fields the name is extended with `_flags`. --- @usage -- lookup descriptive name for the myobj.Magic value --- local desc = pe.const.Magic(myobj.Magic) --- --- -- get list of flag names, indexed by flag values, for the Characteristics field --- local flag_list = pe.const.Characteristics_flags -M.const = { - Magic = { - ["10b"] = "PE32", - ["20b"] = "PE32+", - }, - Machine = { - ["0"] = "IMAGE_FILE_MACHINE_UNKNOWN", - ["1d3"] = "IMAGE_FILE_MACHINE_AM33", - ["8664"] = "IMAGE_FILE_MACHINE_AMD64", - ["1c0"] = "IMAGE_FILE_MACHINE_ARM", - ["1c4"] = "IMAGE_FILE_MACHINE_ARMNT", - ["aa64"] = "IMAGE_FILE_MACHINE_ARM64", - ["ebc"] = "IMAGE_FILE_MACHINE_EBC", - ["14c"] = "IMAGE_FILE_MACHINE_I386", - ["200"] = "IMAGE_FILE_MACHINE_IA64", - ["9041"] = "IMAGE_FILE_MACHINE_M32R", - ["266"] = "IMAGE_FILE_MACHINE_MIPS16", - ["366"] = "IMAGE_FILE_MACHINE_MIPSFPU", - ["466"] = "IMAGE_FILE_MACHINE_MIPSFPU16", - ["1f0"] = "IMAGE_FILE_MACHINE_POWERPC", - ["1f1"] = "IMAGE_FILE_MACHINE_POWERPCFP", - ["166"] = "IMAGE_FILE_MACHINE_R4000", - ["1a2"] = "IMAGE_FILE_MACHINE_SH3", - ["1a3"] = "IMAGE_FILE_MACHINE_SH3DSP", - ["1a6"] = "IMAGE_FILE_MACHINE_SH4", - ["1a8"] = "IMAGE_FILE_MACHINE_SH5", - ["1c2"] = "IMAGE_FILE_MACHINE_THUMB", - ["169"] = "IMAGE_FILE_MACHINE_WCEMIPSV2", - }, - Characteristics_flags = { - ["1"] = "IMAGE_FILE_RELOCS_STRIPPED", - ["2"] = "IMAGE_FILE_EXECUTABLE_IMAGE", - ["4"] = "IMAGE_FILE_LINE_NUMS_STRIPPED", - ["8"] = "IMAGE_FILE_LOCAL_SYMS_STRIPPED", - ["10"] = "IMAGE_FILE_AGGRESSIVE_WS_TRIM", - ["20"] = "IMAGE_FILE_LARGE_ADDRESS_AWARE", - ["40"] = "Reserved for future use", - ["80"] = "IMAGE_FILE_BYTES_REVERSED_LO", - ["100"] = "IMAGE_FILE_32BIT_MACHINE", - ["200"] = "IMAGE_FILE_DEBUG_STRIPPED", - ["400"] = "IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP", - ["800"] = "IMAGE_FILE_NET_RUN_FROM_SWAP", - ["1000"] = "IMAGE_FILE_SYSTEM", - ["2000"] = "IMAGE_FILE_DLL", - ["4000"] = "IMAGE_FILE_UP_SYSTEM_ONLY", - ["8000"] = "IMAGE_FILE_BYTES_REVERSED_HI", - }, - Subsystem = { - ["0"] = "IMAGE_SUBSYSTEM_UNKNOWN", - ["1"] = "IMAGE_SUBSYSTEM_NATIVE", - ["2"] = "IMAGE_SUBSYSTEM_WINDOWS_GUI", - ["3"] = "IMAGE_SUBSYSTEM_WINDOWS_CUI", - ["7"] = "IMAGE_SUBSYSTEM_POSIX_CUI", - ["9"] = "IMAGE_SUBSYSTEM_WINDOWS_CE_GUI", - ["a"] = "IMAGE_SUBSYSTEM_EFI_APPLICATION", - ["b"] = "IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER", - ["c"] = "IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER", - ["d"] = "IMAGE_SUBSYSTEM_EFI_ROM", - ["e"] = "IMAGE_SUBSYSTEM_XBOX", - }, - DllCharacteristics_flags = { - ["40"] = "IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE", - ["80"] = "IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY", - ["100"] = "IMAGE_DLL_CHARACTERISTICS_NX_COMPAT", - ["200"] = "IMAGE_DLLCHARACTERISTICS_NO_ISOLATION", - ["400"] = "IMAGE_DLLCHARACTERISTICS_NO_SEH", - ["800"] = "IMAGE_DLLCHARACTERISTICS_NO_BIND", - ["2000"] = "IMAGE_DLLCHARACTERISTICS_WDM_DRIVER", - ["8000"] = "IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE", - }, - Sections = { - Characteristics_flags = { - ["8"] = "IMAGE_SCN_TYPE_NO_PAD", - ["20"] = "IMAGE_SCN_CNT_CODE", - ["40"] = "IMAGE_SCN_CNT_INITIALIZED_DATA", - ["80"] = "IMAGE_SCN_CNT_UNINITIALIZED_ DATA", - ["100"] = "IMAGE_SCN_LNK_OTHER", - ["200"] = "IMAGE_SCN_LNK_INFO", - ["800"] = "IMAGE_SCN_LNK_REMOVE", - ["1000"] = "IMAGE_SCN_LNK_COMDAT", - ["8000"] = "IMAGE_SCN_GPREL", - ["20000"] = "IMAGE_SCN_MEM_PURGEABLE", - ["20000"] = "IMAGE_SCN_MEM_16BIT", - ["40000"] = "IMAGE_SCN_MEM_LOCKED", - ["80000"] = "IMAGE_SCN_MEM_PRELOAD", - ["100000"] = "IMAGE_SCN_ALIGN_1BYTES", - ["200000"] = "IMAGE_SCN_ALIGN_2BYTES", - ["300000"] = "IMAGE_SCN_ALIGN_4BYTES", - ["400000"] = "IMAGE_SCN_ALIGN_8BYTES", - ["500000"] = "IMAGE_SCN_ALIGN_16BYTES", - ["600000"] = "IMAGE_SCN_ALIGN_32BYTES", - ["700000"] = "IMAGE_SCN_ALIGN_64BYTES", - ["800000"] = "IMAGE_SCN_ALIGN_128BYTES", - ["900000"] = "IMAGE_SCN_ALIGN_256BYTES", - ["a00000"] = "IMAGE_SCN_ALIGN_512BYTES", - ["b00000"] = "IMAGE_SCN_ALIGN_1024BYTES", - ["c00000"] = "IMAGE_SCN_ALIGN_2048BYTES", - ["d00000"] = "IMAGE_SCN_ALIGN_4096BYTES", - ["e00000"] = "IMAGE_SCN_ALIGN_8192BYTES", - ["1000000"] = "IMAGE_SCN_LNK_NRELOC_OVFL", - ["2000000"] = "IMAGE_SCN_MEM_DISCARDABLE", - ["4000000"] = "IMAGE_SCN_MEM_NOT_CACHED", - ["8000000"] = "IMAGE_SCN_MEM_NOT_PAGED", - ["10000000"] = "IMAGE_SCN_MEM_SHARED", - ["20000000"] = "IMAGE_SCN_MEM_EXECUTE", - ["40000000"] = "IMAGE_SCN_MEM_READ", - ["80000000"] = "IMAGE_SCN_MEM_WRITE", - }, - }, - -} - - ---- convert integer to HEX representation --- @param IN the number to convert to hex --- @param len the size to return, any result smaller will be prefixed by "0"s --- @return string containing hex representation -function M.toHex(IN, len) - local B,K,OUT,I,D=16,"0123456789abcdef","",0 - while IN>0 do - I=I+1 - IN,D=math.floor(IN/B),math.fmod(IN,B)+1 - OUT=string.sub(K,D,D)..OUT - end - len = len or string.len(OUT) - if len<1 then len = 1 end - return (string.rep("0",len) .. OUT):sub(-len,-1) -end - ---- convert HEX to integer --- @param IN the string to convert to dec --- @return number in dec format -function M.toDec(IN) - assert(type(IN)=="string") - local OUT = 0 - IN = IN:lower() - while #IN > 0 do - local b = string.find("0123456789abcdef",IN:sub(1,1)) - OUT = OUT * 16 + (b-1) - IN = IN:sub(2,-1) - end - return OUT -end - -local function get_int(str) - -- convert a byte-sequence to an integer - assert(str) - local r = 0 - for i = #str, 1, -1 do - r = r*256 + string.byte(str,i,i) - end - return r -end - -local function get_hex(str) - -- convert a byte-sequence to a hex string - assert(str) - local r = "" - for i = #str, 1, -1 do - r = r .. M.toHex(string.byte(str,i,i),2) - end - while (#r > 1) and (r:sub(1,1) == "0") do - r = r:sub(2, -1) - end - return r -end - -local function get_list(list, f, add_to) - -- list: list of tables with 'size' and 'name' and is_str - -- f: file to read from - -- add_to: table to add results to (optional) - local r = add_to or {} - for i, t in ipairs(list) do - assert(r[t.name] == nil, "Value for '"..t.name.."' already set") - local val,err = f:read(t.size) -- read specified size in bytes - val = val or "\0" - if t.is_str then -- entry is marked as a string value, read as such - for i = 1, #val do - if val:sub(i,i) == "\0" then - r[t.name] = val:sub(1,i-1) - break - end - end - r[t.name] = r[t.name] or val - else -- entry not marked, so always read as hex value - r[t.name] = get_hex(val) - end - end - return r -end - ---- Calculates the fileoffset of a given RVA. --- This function is also available as a method on the parsed output table --- @param obj a parsed object (return value from `parse`) --- @param RVA an RVA value to convert to a fileoffset (either number or hex-string) --- @return fileoffset of the given RVA (number) -M.get_fileoffset = function(obj, RVA) - -- given an object with a section table, and an RVA, it returns - -- the fileoffset for the data - if type(RVA)=="string" then RVA = M.toDec(RVA) end - local section - for i, s in ipairs(obj.Sections) do - if M.toDec(s.VirtualAddress) <= RVA and M.toDec(s.VirtualAddress) + M.toDec(s.VirtualSize) >= RVA then - section = s - break - end - end - if not section then return nil, "No match RVA with Section list, RVA out of bounds" end - return RVA - M.toDec(section.VirtualAddress) + M.toDec(section.PointerToRawData) -end - -local function readstring(f) - -- reads a null-terminated string from the current file posistion - local name = "" - while true do - local c = f:read(1) - if c == "\0" then break end - name = name .. c - end - return name -end - ---- Parses a file and extracts the information. --- All numbers are delivered as "string" types containing hex values, see `toHex` and `toDec` conversion functions. --- @return table with data, or nil + error --- @usage local pe = require("pe-parser") --- local obj = pe.parse("c:\lua\lua.exe") --- obj:dump() -M.parse = function(target) - - local list = { -- list of known architectures - [332] = "x86", -- IMAGE_FILE_MACHINE_I386 - [512] = "x86_64", -- IMAGE_FILE_MACHINE_IA64 - [34404] = "x86_64", -- IMAGE_FILE_MACHINE_AMD64 - } - - local f, err = io.open(target, "rb") - if not f then return nil, err end - - local MZ = f:read(2) - if MZ ~= "MZ" then - f:close() - return nil, "Not a valid image" - end - - f:seek("set", 60) -- position of PE header position - local peoffset = get_int(f:read(4)) -- read position of PE header - - f:seek("set", peoffset) -- move to position of PE header - local out = get_list({ - { size = 4, - name = "PEheader", - is_str = true }, - { size = 2, - name = "Machine" }, - { size = 2, - name = "NumberOfSections"}, - { size = 4, - name = "TimeDateStamp" }, - { size = 4, - name = "PointerToSymbolTable"}, - { size = 4, - name = "NumberOfSymbols"}, - { size = 2, - name = "SizeOfOptionalHeader"}, - { size = 2, - name = "Characteristics"}, - }, f) - - if out.PEheader ~= "PE" then - f:close() - return nil, "Invalid PE header" - end - out.PEheader = nil -- remove it, has no value - out.dump = M.dump -- export dump function as a method - - if M.toDec(out.SizeOfOptionalHeader) > 0 then - -- parse optional header; standard - get_list({ - { size = 2, - name = "Magic" }, - { size = 1, - name = "MajorLinkerVersion"}, - { size = 1, - name = "MinorLinkerVersion"}, - { size = 4, - name = "SizeOfCode"}, - { size = 4, - name = "SizeOfInitializedData"}, - { size = 4, - name = "SizeOfUninitializedData"}, - { size = 4, - name = "AddressOfEntryPoint"}, - { size = 4, - name = "BaseOfCode"}, - }, f, out) - local plus = (out.Magic == "20b") - if not plus then -- plain PE32, not PE32+ - get_list({ - { size = 4, - name = "BaseOfData" }, - }, f, out) - end - -- parse optional header; windows-fields - local plussize = 4 - if plus then plussize = 8 end - get_list({ - { size = plussize, - name = "ImageBase"}, - { size = 4, - name = "SectionAlignment"}, - { size = 4, - name = "FileAlignment"}, - { size = 2, - name = "MajorOperatingSystemVersion"}, - { size = 2, - name = "MinorOperatingSystemVersion"}, - { size = 2, - name = "MajorImageVersion"}, - { size = 2, - name = "MinorImageVersion"}, - { size = 2, - name = "MajorSubsystemVersion"}, - { size = 2, - name = "MinorSubsystemVersion"}, - { size = 4, - name = "Win32VersionValue"}, - { size = 4, - name = "SizeOfImage"}, - { size = 4, - name = "SizeOfHeaders"}, - { size = 4, - name = "CheckSum"}, - { size = 2, - name = "Subsystem"}, - { size = 2, - name = "DllCharacteristics"}, - { size = plussize, - name = "SizeOfStackReserve"}, - { size = plussize, - name = "SizeOfStackCommit"}, - { size = plussize, - name = "SizeOfHeapReserve"}, - { size = plussize, - name = "SizeOfHeapCommit"}, - { size = 4, - name = "LoaderFlags"}, - { size = 4, - name = "NumberOfRvaAndSizes"}, - }, f, out) - -- Read data directory entries - for i = 1, M.toDec(out.NumberOfRvaAndSizes) do - out.DataDirectory = out.DataDirectory or {} - out.DataDirectory[i] = get_list({ - { size = 4, - name = "VirtualAddress"}, - { size = 4, - name = "Size"}, - }, f) - end - for i, name in ipairs{"ExportTable", "ImportTable", "ResourceTable", - "ExceptionTable", "CertificateTable", "BaseRelocationTable", - "Debug", "Architecture", "GlobalPtr", "TLSTable", - "LoadConfigTable", "BoundImport", "IAT", - "DelayImportDescriptor", "CLRRuntimeHeader", "Reserved"} do - out.DataDirectory[name] = out.DataDirectory[i] - if out.DataDirectory[name] then out.DataDirectory[name].name = name end - end - end - - -- parse section table - for i = 1, M.toDec(out.NumberOfSections) do - out.Sections = out.Sections or {} - out.Sections[i] = get_list({ - { size = 8, - name = "Name", - is_str = true}, - { size = 4, - name = "VirtualSize"}, - { size = 4, - name = "VirtualAddress"}, - { size = 4, - name = "SizeOfRawData"}, - { size = 4, - name = "PointerToRawData"}, - { size = 4, - name = "PointerToRelocations"}, - { size = 4, - name = "PointerToLinenumbers"}, - { size = 2, - name = "NumberOfRelocations"}, - { size = 2, - name = "NumberOfLinenumbers"}, - { size = 4, - name = "Characteristics"}, - }, f) - end - -- we now have section data, so add RVA convertion method - out.get_fileoffset = M.get_fileoffset - - -- get the import table - f:seek("set", out:get_fileoffset(out.DataDirectory.ImportTable.VirtualAddress)) - local done = false - local cnt = 1 - while not done do - local dll = get_list({ - { size = 4, - name = "ImportLookupTableRVA"}, - { size = 4, - name = "TimeDateStamp"}, - { size = 4, - name = "ForwarderChain"}, - { size = 4, - name = "NameRVA"}, - { size = 4, - name = "ImportAddressTableRVA"}, - }, f) - if M.toDec(dll.NameRVA) == 0 then - -- this is the final NULL entry, so we're done - done = true - else - -- store the import entry - out.DataDirectory.ImportTable[cnt] = dll - cnt = cnt + 1 - end - end - -- resolve imported DLL names - for i, dll in ipairs(out.DataDirectory.ImportTable) do - f:seek("set", out:get_fileoffset(dll.NameRVA)) - dll.Name = readstring(f) - end - - f:close() - return out -end - --- pad a string (prefix) to a specific length -local function pad(str, l, chr) - chr = chr or " " - l = l or 0 - return string.rep(chr,l-#str)..str -end - ---- Dumps the output parsed. --- This function is also available as a method on the parsed output table -M.dump = function(obj) - local l = 0 - for k,v in pairs(obj) do if #k > l then l = #k end end - - for k,v in pairs(obj) do - if (M.const[k] and type(v)=="string") then - -- look up named value - print(k..string.rep(" ", l - #k + 1)..": "..M.const[k][v]) - elseif M.const[k.."_flags"] then - -- flags should be listed - print(k..string.rep(" ", l - #k + 1)..": "..v.." (flag field)") - else - -- regular values - if type(v) == "number" then - print(k..string.rep(" ", l - #k + 1)..": "..v.." (dec)") - else - if (type(v)=="string") and (k ~= "DataDirectory") and (k ~= "Sections") then - print(k..string.rep(" ", l - #k + 1)..": "..v) - end - end - end - end - - if obj.DataDirectory then - print("DataDirectory (RVA, size):") - for i, v in ipairs(obj.DataDirectory) do - print(" Entry "..M.toHex(i-1).." "..pad(v.VirtualAddress,8,"0").." "..pad(v.Size,8,"0").." "..v.name) - end - end - - if obj.Sections then - print("Sections:") - print("idx name RVA VSize Offset RawSize") - for i, v in ipairs(obj.Sections) do - 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")) - end - end - - print("Imports:") - for i, dll in ipairs(obj.DataDirectory.ImportTable) do - print(" "..dll.Name) - end -end - ---- Checks the msvcrt dll the binary was linked against. --- Mixing and matching dlls only works when they all are using the same runtime, if --- not unexpected errors will probably occur. --- Checks the binary provided and then traverses all imported dlls to find the msvcrt --- used (it will only look for the dlls in the same directory). --- @param infile binary file to check --- @return msvcrt name (uppercase, without extension) + file where the reference was found, or nil + error -function M.msvcrt(infile) - local path, file = infile:match("(.+)\\(.+)$") - if not path then - path = "" - file = infile - else - path=path .. "\\" - end - local obj, err = M.parse(path..file) - if not obj then return obj, err end - - for i, dll in ipairs(obj.DataDirectory.ImportTable) do - dll = dll.Name:upper() - local result = dll:match('(MSVCR%d*)%.DLL') - if not result then - result = dll:match('(MSVCRT)%.DLL') - end - -- success, found it return name + binary where it was found - if result then return result, infile end - end - - -- not found, so traverse all imported dll's - for i, dll in ipairs(obj.DataDirectory.ImportTable) do - local rt, ref = M.msvcrt(path..dll.Name) - if rt then - return rt, ref -- found it - end - end - - return nil, "No msvcrt found" -end - -return 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 @@ - -/* -** Simple Lua interpreter. -** This program is used to run a Lua file embedded as a resource. -** It creates a Lua state, opens all its standard libraries, and run -** the Lua file in a protected environment just to redirect the error -** messages to stdout and stderr. -** -** $Id: rclauncher.c,v 1.1 2008/06/30 14:29:59 carregal Exp $ -*/ - -#include -#include - -#include "lua.h" -#include "lauxlib.h" -#include "lualib.h" -#include -#include -#include - -/* -** Report error message. -** Assumes that the error message is on top of the stack. -*/ -static int report (lua_State *L) { - fprintf (stderr, "lua: fatal error: `%s'\n", lua_tostring (L, -1)); - fflush (stderr); - printf ("Content-type: text/plain\n\nConfiguration fatal error: see error log!\n"); - printf ("%s", lua_tostring(L, -1)); - return 1; -} - -static int runlua (lua_State *L, const char *lua_string, int argc, char *argv[]) { - int err_func; - int err; - - lua_getglobal(L, "debug"); - lua_pushliteral(L, "traceback"); - lua_gettable(L, -2); - err_func = lua_gettop (L); - err = luaL_loadstring (L, lua_string); - if(!err) { - int i; - // fill global arg table - lua_getglobal(L, "arg"); - for(i = 1; i < argc; i++) - { - lua_pushstring(L, argv[i]); - lua_rawseti(L, -2, i); - } - lua_pop(L, 1); - // fill parameters (in vararg '...') - for(i = 1; i < argc; i++) - lua_pushstring(L, argv[i]); - return lua_pcall (L, argc - 1, LUA_MULTRET, err_func); - } else return err; -} - -static DWORD GetModulePath( HINSTANCE hInst, LPTSTR pszBuffer, DWORD dwSize ) -// -// Return the size of the path in bytes. -{ - DWORD dwLength = GetModuleFileName( hInst, pszBuffer, dwSize ); - if( dwLength ) - { - while( dwLength && pszBuffer[ dwLength ] != '.' ) - { - dwLength--; - } - - if( dwLength ) - pszBuffer[ dwLength ] = '\000'; - } - return dwLength; -} - - -/* -** MAIN -*/ -int main (int argc, char *argv[]) { - char name[ MAX_PATH ]; - DWORD dwLength; - int size; - luaL_Buffer b; - int i; -#ifdef UNICODE - TCHAR lua_wstring[4098]; -#endif - char lua_string[4098]; - lua_State *L = luaL_newstate(); - (void)argc; /* avoid "unused parameter" warning */ - luaL_openlibs(L); - lua_newtable(L); // create arg table - lua_pushstring(L, argv[0]); // add interpreter to arg table - lua_rawseti(L, -2, -1); - dwLength = GetModulePath( NULL, name, MAX_PATH ); - if(dwLength) { /* Optional bootstrap */ - strcat(name, ".lua"); - lua_pushstring(L, name); // add lua script to arg table - lua_rawseti(L, -2, 0); - lua_setglobal(L,"arg"); // set global arg table - if(!luaL_loadfile (L, name)) { - if(lua_pcall (L, 0, LUA_MULTRET, 0)) { - report (L); - lua_close (L); - return EXIT_FAILURE; - } - } - } - else - { - lua_pushstring(L, argv[0]); // no lua script, so add interpreter again, now as lua script - lua_rawseti(L, -2, 0); - lua_setglobal(L,"arg"); // set global arg table - } - - luaL_buffinit(L, &b); - for(i = 1; ; i++) { -#ifdef UNICODE - size = LoadString(GetModuleHandle(NULL), i, lua_wstring, - sizeof(lua_string)/sizeof(TCHAR)); - if(size > 0) wcstombs(lua_string, lua_wstring, size + 1); -#else - size = LoadString(GetModuleHandle(NULL), i, lua_string, - sizeof(lua_string)/sizeof(char)); -#endif - if(size) luaL_addlstring(&b, lua_string, size); else break; - } - luaL_pushresult(&b); - if (runlua (L, lua_tostring(L, -1), argc, argv)) { - report (L); - lua_close (L); - return EXIT_FAILURE; - } - lua_close (L); - return EXIT_SUCCESS; -} diff --git a/win32/lua.ico b/win32/lua.ico new file mode 100644 index 00000000..56dc4fe1 Binary files /dev/null and b/win32/lua.ico differ diff --git a/win32/luarocksw.bat b/win32/luarocksw.bat new file mode 100644 index 00000000..8ac02920 --- /dev/null +++ b/win32/luarocksw.bat @@ -0,0 +1,49 @@ +@echo off +setlocal +SET MYPATH=%~dp0 + +IF NOT [%1]==[] GOTO LETSGO +ECHO Same as 'luarocks' command, except this +ECHO command will pause after completion, allowing for +ECHO examination of output. +ECHO. +ECHO For LuaRocks help use: +ECHO LUAROCKS HELP +ECHO. +ECHO OPTIONS specific for LUAROCKSW: +ECHO REMOVEALL is a command specific to this batch file +ECHO the option takes a FULL ROCKSPEC filename and then +ECHO it will strip path, version and extension info from +ECHO it before executing the LUAROCKS REMOVE command +ECHO Example: +ECHO luarocksw remove "c:\somedir\modulename-1.0-1.rockspec" +ECHO will execute: +ECHO luarocks remove "c:\somedir\modulename-1.0-1.rockspec" +ECHO and will only remove the specific version 1.0 from the +ECHO system. +ECHO luarocksw removeall "c:\somedir\modulename-1.0-1.rockspec" +ECHO will execute: +ECHO luarocks remove modulename +ECHO and will remove all versions of this package +ECHO. +GOTO END + +:LETSGO +REM if REMOVEALL command then info must be stripped from the parameter +if [%1]==[removeall] goto REMOVEALL + +REM execute LuaRocks and wait for results +echo executing: luarocks %* +call "%MYPATH%luarocks" %* +pause +goto END + +:REMOVEALL +for /f "delims=-" %%a in ("%~n2") do ( + echo executing: luarocks remove %%a + "%MYPATH%luarocks" remove "%%a" + pause + goto END +) + +:END \ No newline at end of file diff --git a/win32/pe-parser.lua b/win32/pe-parser.lua new file mode 100644 index 00000000..30bb8390 --- /dev/null +++ b/win32/pe-parser.lua @@ -0,0 +1,546 @@ +--------------------------------------------------------------------------------------- +-- Lua module to parse a Portable Executable (.exe , .dll, etc.) file and extract metadata. +-- +-- Version 0.1, [copyright (c) 2013 - Thijs Schreijer](http://www.thijsschreijer.nl) +-- @name pe-parser +-- @class module + +local M = {} + +--- Table with named constants/flag-constants. +-- Named elements can be looked up by their name in the `const` table. The sub tables are index by value. +-- For flag fields the name is extended with `_flags`. +-- @usage -- lookup descriptive name for the myobj.Magic value +-- local desc = pe.const.Magic(myobj.Magic) +-- +-- -- get list of flag names, indexed by flag values, for the Characteristics field +-- local flag_list = pe.const.Characteristics_flags +M.const = { + Magic = { + ["10b"] = "PE32", + ["20b"] = "PE32+", + }, + Machine = { + ["0"] = "IMAGE_FILE_MACHINE_UNKNOWN", + ["1d3"] = "IMAGE_FILE_MACHINE_AM33", + ["8664"] = "IMAGE_FILE_MACHINE_AMD64", + ["1c0"] = "IMAGE_FILE_MACHINE_ARM", + ["1c4"] = "IMAGE_FILE_MACHINE_ARMNT", + ["aa64"] = "IMAGE_FILE_MACHINE_ARM64", + ["ebc"] = "IMAGE_FILE_MACHINE_EBC", + ["14c"] = "IMAGE_FILE_MACHINE_I386", + ["200"] = "IMAGE_FILE_MACHINE_IA64", + ["9041"] = "IMAGE_FILE_MACHINE_M32R", + ["266"] = "IMAGE_FILE_MACHINE_MIPS16", + ["366"] = "IMAGE_FILE_MACHINE_MIPSFPU", + ["466"] = "IMAGE_FILE_MACHINE_MIPSFPU16", + ["1f0"] = "IMAGE_FILE_MACHINE_POWERPC", + ["1f1"] = "IMAGE_FILE_MACHINE_POWERPCFP", + ["166"] = "IMAGE_FILE_MACHINE_R4000", + ["1a2"] = "IMAGE_FILE_MACHINE_SH3", + ["1a3"] = "IMAGE_FILE_MACHINE_SH3DSP", + ["1a6"] = "IMAGE_FILE_MACHINE_SH4", + ["1a8"] = "IMAGE_FILE_MACHINE_SH5", + ["1c2"] = "IMAGE_FILE_MACHINE_THUMB", + ["169"] = "IMAGE_FILE_MACHINE_WCEMIPSV2", + }, + Characteristics_flags = { + ["1"] = "IMAGE_FILE_RELOCS_STRIPPED", + ["2"] = "IMAGE_FILE_EXECUTABLE_IMAGE", + ["4"] = "IMAGE_FILE_LINE_NUMS_STRIPPED", + ["8"] = "IMAGE_FILE_LOCAL_SYMS_STRIPPED", + ["10"] = "IMAGE_FILE_AGGRESSIVE_WS_TRIM", + ["20"] = "IMAGE_FILE_LARGE_ADDRESS_AWARE", + ["40"] = "Reserved for future use", + ["80"] = "IMAGE_FILE_BYTES_REVERSED_LO", + ["100"] = "IMAGE_FILE_32BIT_MACHINE", + ["200"] = "IMAGE_FILE_DEBUG_STRIPPED", + ["400"] = "IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP", + ["800"] = "IMAGE_FILE_NET_RUN_FROM_SWAP", + ["1000"] = "IMAGE_FILE_SYSTEM", + ["2000"] = "IMAGE_FILE_DLL", + ["4000"] = "IMAGE_FILE_UP_SYSTEM_ONLY", + ["8000"] = "IMAGE_FILE_BYTES_REVERSED_HI", + }, + Subsystem = { + ["0"] = "IMAGE_SUBSYSTEM_UNKNOWN", + ["1"] = "IMAGE_SUBSYSTEM_NATIVE", + ["2"] = "IMAGE_SUBSYSTEM_WINDOWS_GUI", + ["3"] = "IMAGE_SUBSYSTEM_WINDOWS_CUI", + ["7"] = "IMAGE_SUBSYSTEM_POSIX_CUI", + ["9"] = "IMAGE_SUBSYSTEM_WINDOWS_CE_GUI", + ["a"] = "IMAGE_SUBSYSTEM_EFI_APPLICATION", + ["b"] = "IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER", + ["c"] = "IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER", + ["d"] = "IMAGE_SUBSYSTEM_EFI_ROM", + ["e"] = "IMAGE_SUBSYSTEM_XBOX", + }, + DllCharacteristics_flags = { + ["40"] = "IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE", + ["80"] = "IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY", + ["100"] = "IMAGE_DLL_CHARACTERISTICS_NX_COMPAT", + ["200"] = "IMAGE_DLLCHARACTERISTICS_NO_ISOLATION", + ["400"] = "IMAGE_DLLCHARACTERISTICS_NO_SEH", + ["800"] = "IMAGE_DLLCHARACTERISTICS_NO_BIND", + ["2000"] = "IMAGE_DLLCHARACTERISTICS_WDM_DRIVER", + ["8000"] = "IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE", + }, + Sections = { + Characteristics_flags = { + ["8"] = "IMAGE_SCN_TYPE_NO_PAD", + ["20"] = "IMAGE_SCN_CNT_CODE", + ["40"] = "IMAGE_SCN_CNT_INITIALIZED_DATA", + ["80"] = "IMAGE_SCN_CNT_UNINITIALIZED_ DATA", + ["100"] = "IMAGE_SCN_LNK_OTHER", + ["200"] = "IMAGE_SCN_LNK_INFO", + ["800"] = "IMAGE_SCN_LNK_REMOVE", + ["1000"] = "IMAGE_SCN_LNK_COMDAT", + ["8000"] = "IMAGE_SCN_GPREL", + ["20000"] = "IMAGE_SCN_MEM_PURGEABLE", + ["20000"] = "IMAGE_SCN_MEM_16BIT", + ["40000"] = "IMAGE_SCN_MEM_LOCKED", + ["80000"] = "IMAGE_SCN_MEM_PRELOAD", + ["100000"] = "IMAGE_SCN_ALIGN_1BYTES", + ["200000"] = "IMAGE_SCN_ALIGN_2BYTES", + ["300000"] = "IMAGE_SCN_ALIGN_4BYTES", + ["400000"] = "IMAGE_SCN_ALIGN_8BYTES", + ["500000"] = "IMAGE_SCN_ALIGN_16BYTES", + ["600000"] = "IMAGE_SCN_ALIGN_32BYTES", + ["700000"] = "IMAGE_SCN_ALIGN_64BYTES", + ["800000"] = "IMAGE_SCN_ALIGN_128BYTES", + ["900000"] = "IMAGE_SCN_ALIGN_256BYTES", + ["a00000"] = "IMAGE_SCN_ALIGN_512BYTES", + ["b00000"] = "IMAGE_SCN_ALIGN_1024BYTES", + ["c00000"] = "IMAGE_SCN_ALIGN_2048BYTES", + ["d00000"] = "IMAGE_SCN_ALIGN_4096BYTES", + ["e00000"] = "IMAGE_SCN_ALIGN_8192BYTES", + ["1000000"] = "IMAGE_SCN_LNK_NRELOC_OVFL", + ["2000000"] = "IMAGE_SCN_MEM_DISCARDABLE", + ["4000000"] = "IMAGE_SCN_MEM_NOT_CACHED", + ["8000000"] = "IMAGE_SCN_MEM_NOT_PAGED", + ["10000000"] = "IMAGE_SCN_MEM_SHARED", + ["20000000"] = "IMAGE_SCN_MEM_EXECUTE", + ["40000000"] = "IMAGE_SCN_MEM_READ", + ["80000000"] = "IMAGE_SCN_MEM_WRITE", + }, + }, + +} + + +--- convert integer to HEX representation +-- @param IN the number to convert to hex +-- @param len the size to return, any result smaller will be prefixed by "0"s +-- @return string containing hex representation +function M.toHex(IN, len) + local B,K,OUT,I,D=16,"0123456789abcdef","",0 + while IN>0 do + I=I+1 + IN,D=math.floor(IN/B),math.fmod(IN,B)+1 + OUT=string.sub(K,D,D)..OUT + end + len = len or string.len(OUT) + if len<1 then len = 1 end + return (string.rep("0",len) .. OUT):sub(-len,-1) +end + +--- convert HEX to integer +-- @param IN the string to convert to dec +-- @return number in dec format +function M.toDec(IN) + assert(type(IN)=="string") + local OUT = 0 + IN = IN:lower() + while #IN > 0 do + local b = string.find("0123456789abcdef",IN:sub(1,1)) + OUT = OUT * 16 + (b-1) + IN = IN:sub(2,-1) + end + return OUT +end + +local function get_int(str) + -- convert a byte-sequence to an integer + assert(str) + local r = 0 + for i = #str, 1, -1 do + r = r*256 + string.byte(str,i,i) + end + return r +end + +local function get_hex(str) + -- convert a byte-sequence to a hex string + assert(str) + local r = "" + for i = #str, 1, -1 do + r = r .. M.toHex(string.byte(str,i,i),2) + end + while (#r > 1) and (r:sub(1,1) == "0") do + r = r:sub(2, -1) + end + return r +end + +local function get_list(list, f, add_to) + -- list: list of tables with 'size' and 'name' and is_str + -- f: file to read from + -- add_to: table to add results to (optional) + local r = add_to or {} + for i, t in ipairs(list) do + assert(r[t.name] == nil, "Value for '"..t.name.."' already set") + local val,err = f:read(t.size) -- read specified size in bytes + val = val or "\0" + if t.is_str then -- entry is marked as a string value, read as such + for i = 1, #val do + if val:sub(i,i) == "\0" then + r[t.name] = val:sub(1,i-1) + break + end + end + r[t.name] = r[t.name] or val + else -- entry not marked, so always read as hex value + r[t.name] = get_hex(val) + end + end + return r +end + +--- Calculates the fileoffset of a given RVA. +-- This function is also available as a method on the parsed output table +-- @param obj a parsed object (return value from `parse`) +-- @param RVA an RVA value to convert to a fileoffset (either number or hex-string) +-- @return fileoffset of the given RVA (number) +M.get_fileoffset = function(obj, RVA) + -- given an object with a section table, and an RVA, it returns + -- the fileoffset for the data + if type(RVA)=="string" then RVA = M.toDec(RVA) end + local section + for i, s in ipairs(obj.Sections) do + if M.toDec(s.VirtualAddress) <= RVA and M.toDec(s.VirtualAddress) + M.toDec(s.VirtualSize) >= RVA then + section = s + break + end + end + if not section then return nil, "No match RVA with Section list, RVA out of bounds" end + return RVA - M.toDec(section.VirtualAddress) + M.toDec(section.PointerToRawData) +end + +local function readstring(f) + -- reads a null-terminated string from the current file posistion + local name = "" + while true do + local c = f:read(1) + if c == "\0" then break end + name = name .. c + end + return name +end + +--- Parses a file and extracts the information. +-- All numbers are delivered as "string" types containing hex values, see `toHex` and `toDec` conversion functions. +-- @return table with data, or nil + error +-- @usage local pe = require("pe-parser") +-- local obj = pe.parse("c:\lua\lua.exe") +-- obj:dump() +M.parse = function(target) + + local list = { -- list of known architectures + [332] = "x86", -- IMAGE_FILE_MACHINE_I386 + [512] = "x86_64", -- IMAGE_FILE_MACHINE_IA64 + [34404] = "x86_64", -- IMAGE_FILE_MACHINE_AMD64 + } + + local f, err = io.open(target, "rb") + if not f then return nil, err end + + local MZ = f:read(2) + if MZ ~= "MZ" then + f:close() + return nil, "Not a valid image" + end + + f:seek("set", 60) -- position of PE header position + local peoffset = get_int(f:read(4)) -- read position of PE header + + f:seek("set", peoffset) -- move to position of PE header + local out = get_list({ + { size = 4, + name = "PEheader", + is_str = true }, + { size = 2, + name = "Machine" }, + { size = 2, + name = "NumberOfSections"}, + { size = 4, + name = "TimeDateStamp" }, + { size = 4, + name = "PointerToSymbolTable"}, + { size = 4, + name = "NumberOfSymbols"}, + { size = 2, + name = "SizeOfOptionalHeader"}, + { size = 2, + name = "Characteristics"}, + }, f) + + if out.PEheader ~= "PE" then + f:close() + return nil, "Invalid PE header" + end + out.PEheader = nil -- remove it, has no value + out.dump = M.dump -- export dump function as a method + + if M.toDec(out.SizeOfOptionalHeader) > 0 then + -- parse optional header; standard + get_list({ + { size = 2, + name = "Magic" }, + { size = 1, + name = "MajorLinkerVersion"}, + { size = 1, + name = "MinorLinkerVersion"}, + { size = 4, + name = "SizeOfCode"}, + { size = 4, + name = "SizeOfInitializedData"}, + { size = 4, + name = "SizeOfUninitializedData"}, + { size = 4, + name = "AddressOfEntryPoint"}, + { size = 4, + name = "BaseOfCode"}, + }, f, out) + local plus = (out.Magic == "20b") + if not plus then -- plain PE32, not PE32+ + get_list({ + { size = 4, + name = "BaseOfData" }, + }, f, out) + end + -- parse optional header; windows-fields + local plussize = 4 + if plus then plussize = 8 end + get_list({ + { size = plussize, + name = "ImageBase"}, + { size = 4, + name = "SectionAlignment"}, + { size = 4, + name = "FileAlignment"}, + { size = 2, + name = "MajorOperatingSystemVersion"}, + { size = 2, + name = "MinorOperatingSystemVersion"}, + { size = 2, + name = "MajorImageVersion"}, + { size = 2, + name = "MinorImageVersion"}, + { size = 2, + name = "MajorSubsystemVersion"}, + { size = 2, + name = "MinorSubsystemVersion"}, + { size = 4, + name = "Win32VersionValue"}, + { size = 4, + name = "SizeOfImage"}, + { size = 4, + name = "SizeOfHeaders"}, + { size = 4, + name = "CheckSum"}, + { size = 2, + name = "Subsystem"}, + { size = 2, + name = "DllCharacteristics"}, + { size = plussize, + name = "SizeOfStackReserve"}, + { size = plussize, + name = "SizeOfStackCommit"}, + { size = plussize, + name = "SizeOfHeapReserve"}, + { size = plussize, + name = "SizeOfHeapCommit"}, + { size = 4, + name = "LoaderFlags"}, + { size = 4, + name = "NumberOfRvaAndSizes"}, + }, f, out) + -- Read data directory entries + for i = 1, M.toDec(out.NumberOfRvaAndSizes) do + out.DataDirectory = out.DataDirectory or {} + out.DataDirectory[i] = get_list({ + { size = 4, + name = "VirtualAddress"}, + { size = 4, + name = "Size"}, + }, f) + end + for i, name in ipairs{"ExportTable", "ImportTable", "ResourceTable", + "ExceptionTable", "CertificateTable", "BaseRelocationTable", + "Debug", "Architecture", "GlobalPtr", "TLSTable", + "LoadConfigTable", "BoundImport", "IAT", + "DelayImportDescriptor", "CLRRuntimeHeader", "Reserved"} do + out.DataDirectory[name] = out.DataDirectory[i] + if out.DataDirectory[name] then out.DataDirectory[name].name = name end + end + end + + -- parse section table + for i = 1, M.toDec(out.NumberOfSections) do + out.Sections = out.Sections or {} + out.Sections[i] = get_list({ + { size = 8, + name = "Name", + is_str = true}, + { size = 4, + name = "VirtualSize"}, + { size = 4, + name = "VirtualAddress"}, + { size = 4, + name = "SizeOfRawData"}, + { size = 4, + name = "PointerToRawData"}, + { size = 4, + name = "PointerToRelocations"}, + { size = 4, + name = "PointerToLinenumbers"}, + { size = 2, + name = "NumberOfRelocations"}, + { size = 2, + name = "NumberOfLinenumbers"}, + { size = 4, + name = "Characteristics"}, + }, f) + end + -- we now have section data, so add RVA convertion method + out.get_fileoffset = M.get_fileoffset + + -- get the import table + f:seek("set", out:get_fileoffset(out.DataDirectory.ImportTable.VirtualAddress)) + local done = false + local cnt = 1 + while not done do + local dll = get_list({ + { size = 4, + name = "ImportLookupTableRVA"}, + { size = 4, + name = "TimeDateStamp"}, + { size = 4, + name = "ForwarderChain"}, + { size = 4, + name = "NameRVA"}, + { size = 4, + name = "ImportAddressTableRVA"}, + }, f) + if M.toDec(dll.NameRVA) == 0 then + -- this is the final NULL entry, so we're done + done = true + else + -- store the import entry + out.DataDirectory.ImportTable[cnt] = dll + cnt = cnt + 1 + end + end + -- resolve imported DLL names + for i, dll in ipairs(out.DataDirectory.ImportTable) do + f:seek("set", out:get_fileoffset(dll.NameRVA)) + dll.Name = readstring(f) + end + + f:close() + return out +end + +-- pad a string (prefix) to a specific length +local function pad(str, l, chr) + chr = chr or " " + l = l or 0 + return string.rep(chr,l-#str)..str +end + +--- Dumps the output parsed. +-- This function is also available as a method on the parsed output table +M.dump = function(obj) + local l = 0 + for k,v in pairs(obj) do if #k > l then l = #k end end + + for k,v in pairs(obj) do + if (M.const[k] and type(v)=="string") then + -- look up named value + print(k..string.rep(" ", l - #k + 1)..": "..M.const[k][v]) + elseif M.const[k.."_flags"] then + -- flags should be listed + print(k..string.rep(" ", l - #k + 1)..": "..v.." (flag field)") + else + -- regular values + if type(v) == "number" then + print(k..string.rep(" ", l - #k + 1)..": "..v.." (dec)") + else + if (type(v)=="string") and (k ~= "DataDirectory") and (k ~= "Sections") then + print(k..string.rep(" ", l - #k + 1)..": "..v) + end + end + end + end + + if obj.DataDirectory then + print("DataDirectory (RVA, size):") + for i, v in ipairs(obj.DataDirectory) do + print(" Entry "..M.toHex(i-1).." "..pad(v.VirtualAddress,8,"0").." "..pad(v.Size,8,"0").." "..v.name) + end + end + + if obj.Sections then + print("Sections:") + print("idx name RVA VSize Offset RawSize") + for i, v in ipairs(obj.Sections) do + 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")) + end + end + + print("Imports:") + for i, dll in ipairs(obj.DataDirectory.ImportTable) do + print(" "..dll.Name) + end +end + +--- Checks the msvcrt dll the binary was linked against. +-- Mixing and matching dlls only works when they all are using the same runtime, if +-- not unexpected errors will probably occur. +-- Checks the binary provided and then traverses all imported dlls to find the msvcrt +-- used (it will only look for the dlls in the same directory). +-- @param infile binary file to check +-- @return msvcrt name (uppercase, without extension) + file where the reference was found, or nil + error +function M.msvcrt(infile) + local path, file = infile:match("(.+)\\(.+)$") + if not path then + path = "" + file = infile + else + path=path .. "\\" + end + local obj, err = M.parse(path..file) + if not obj then return obj, err end + + for i, dll in ipairs(obj.DataDirectory.ImportTable) do + dll = dll.Name:upper() + local result = dll:match('(MSVCR%d*)%.DLL') + if not result then + result = dll:match('(MSVCRT)%.DLL') + end + -- success, found it return name + binary where it was found + if result then return result, infile end + end + + -- not found, so traverse all imported dll's + for i, dll in ipairs(obj.DataDirectory.ImportTable) do + local rt, ref = M.msvcrt(path..dll.Name) + if rt then + return rt, ref -- found it + end + end + + return nil, "No msvcrt found" +end + +return M diff --git a/win32/rclauncher.c b/win32/rclauncher.c new file mode 100644 index 00000000..77459f46 --- /dev/null +++ b/win32/rclauncher.c @@ -0,0 +1,139 @@ + +/* +** Simple Lua interpreter. +** This program is used to run a Lua file embedded as a resource. +** It creates a Lua state, opens all its standard libraries, and run +** the Lua file in a protected environment just to redirect the error +** messages to stdout and stderr. +** +** $Id: rclauncher.c,v 1.1 2008/06/30 14:29:59 carregal Exp $ +*/ + +#include +#include + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include +#include +#include + +/* +** Report error message. +** Assumes that the error message is on top of the stack. +*/ +static int report (lua_State *L) { + fprintf (stderr, "lua: fatal error: `%s'\n", lua_tostring (L, -1)); + fflush (stderr); + printf ("Content-type: text/plain\n\nConfiguration fatal error: see error log!\n"); + printf ("%s", lua_tostring(L, -1)); + return 1; +} + +static int runlua (lua_State *L, const char *lua_string, int argc, char *argv[]) { + int err_func; + int err; + + lua_getglobal(L, "debug"); + lua_pushliteral(L, "traceback"); + lua_gettable(L, -2); + err_func = lua_gettop (L); + err = luaL_loadstring (L, lua_string); + if(!err) { + int i; + // fill global arg table + lua_getglobal(L, "arg"); + for(i = 1; i < argc; i++) + { + lua_pushstring(L, argv[i]); + lua_rawseti(L, -2, i); + } + lua_pop(L, 1); + // fill parameters (in vararg '...') + for(i = 1; i < argc; i++) + lua_pushstring(L, argv[i]); + return lua_pcall (L, argc - 1, LUA_MULTRET, err_func); + } else return err; +} + +static DWORD GetModulePath( HINSTANCE hInst, LPTSTR pszBuffer, DWORD dwSize ) +// +// Return the size of the path in bytes. +{ + DWORD dwLength = GetModuleFileName( hInst, pszBuffer, dwSize ); + if( dwLength ) + { + while( dwLength && pszBuffer[ dwLength ] != '.' ) + { + dwLength--; + } + + if( dwLength ) + pszBuffer[ dwLength ] = '\000'; + } + return dwLength; +} + + +/* +** MAIN +*/ +int main (int argc, char *argv[]) { + char name[ MAX_PATH ]; + DWORD dwLength; + int size; + luaL_Buffer b; + int i; +#ifdef UNICODE + TCHAR lua_wstring[4098]; +#endif + char lua_string[4098]; + lua_State *L = luaL_newstate(); + (void)argc; /* avoid "unused parameter" warning */ + luaL_openlibs(L); + lua_newtable(L); // create arg table + lua_pushstring(L, argv[0]); // add interpreter to arg table + lua_rawseti(L, -2, -1); + dwLength = GetModulePath( NULL, name, MAX_PATH ); + if(dwLength) { /* Optional bootstrap */ + strcat(name, ".lua"); + lua_pushstring(L, name); // add lua script to arg table + lua_rawseti(L, -2, 0); + lua_setglobal(L,"arg"); // set global arg table + if(!luaL_loadfile (L, name)) { + if(lua_pcall (L, 0, LUA_MULTRET, 0)) { + report (L); + lua_close (L); + return EXIT_FAILURE; + } + } + } + else + { + lua_pushstring(L, argv[0]); // no lua script, so add interpreter again, now as lua script + lua_rawseti(L, -2, 0); + lua_setglobal(L,"arg"); // set global arg table + } + + luaL_buffinit(L, &b); + for(i = 1; ; i++) { +#ifdef UNICODE + size = LoadString(GetModuleHandle(NULL), i, lua_wstring, + sizeof(lua_string)/sizeof(TCHAR)); + if(size > 0) wcstombs(lua_string, lua_wstring, size + 1); +#else + size = LoadString(GetModuleHandle(NULL), i, lua_string, + sizeof(lua_string)/sizeof(char)); +#endif + if(size) luaL_addlstring(&b, lua_string, size); else break; + } + luaL_pushresult(&b); + if (runlua (L, lua_tostring(L, -1), argc, argv)) { + report (L); + lua_close (L); + return EXIT_FAILURE; + } + lua_close (L); + return EXIT_SUCCESS; +} diff --git a/win32/tools/7z.dll b/win32/tools/7z.dll new file mode 100644 index 00000000..c0ff7fbe Binary files /dev/null and b/win32/tools/7z.dll differ diff --git a/win32/tools/7z.exe b/win32/tools/7z.exe new file mode 100644 index 00000000..5e3d6f9c Binary files /dev/null and b/win32/tools/7z.exe differ diff --git a/win32/tools/cp.exe b/win32/tools/cp.exe new file mode 100644 index 00000000..0ef4fe85 Binary files /dev/null and b/win32/tools/cp.exe differ diff --git a/win32/tools/find.exe b/win32/tools/find.exe new file mode 100644 index 00000000..85192fbf Binary files /dev/null and b/win32/tools/find.exe differ diff --git a/win32/tools/libeay32.dll b/win32/tools/libeay32.dll new file mode 100644 index 00000000..8d31f866 Binary files /dev/null and b/win32/tools/libeay32.dll differ diff --git a/win32/tools/libiconv2.dll b/win32/tools/libiconv2.dll new file mode 100644 index 00000000..544dd92f Binary files /dev/null and b/win32/tools/libiconv2.dll differ diff --git a/win32/tools/libintl3.dll b/win32/tools/libintl3.dll new file mode 100644 index 00000000..ec11e6b1 Binary files /dev/null and b/win32/tools/libintl3.dll differ diff --git a/win32/tools/libssl32.dll b/win32/tools/libssl32.dll new file mode 100644 index 00000000..a30ff0e9 Binary files /dev/null and b/win32/tools/libssl32.dll differ diff --git a/win32/tools/ls.exe b/win32/tools/ls.exe new file mode 100644 index 00000000..96ff2e57 Binary files /dev/null and b/win32/tools/ls.exe differ diff --git a/win32/tools/md5sum.exe b/win32/tools/md5sum.exe new file mode 100644 index 00000000..4ae9f74f Binary files /dev/null and b/win32/tools/md5sum.exe differ diff --git a/win32/tools/mkdir.exe b/win32/tools/mkdir.exe new file mode 100644 index 00000000..83e57d97 Binary files /dev/null and b/win32/tools/mkdir.exe differ diff --git a/win32/tools/mv.exe b/win32/tools/mv.exe new file mode 100644 index 00000000..9fb65bb9 Binary files /dev/null and b/win32/tools/mv.exe differ diff --git a/win32/tools/pwd.exe b/win32/tools/pwd.exe new file mode 100644 index 00000000..7dd114de Binary files /dev/null and b/win32/tools/pwd.exe differ diff --git a/win32/tools/rmdir.exe b/win32/tools/rmdir.exe new file mode 100644 index 00000000..6a85c3c4 Binary files /dev/null and b/win32/tools/rmdir.exe differ diff --git a/win32/tools/test.exe b/win32/tools/test.exe new file mode 100644 index 00000000..94c95f9e Binary files /dev/null and b/win32/tools/test.exe differ diff --git a/win32/tools/uname.exe b/win32/tools/uname.exe new file mode 100644 index 00000000..3e2f4cf8 Binary files /dev/null and b/win32/tools/uname.exe differ diff --git a/win32/tools/wget.exe b/win32/tools/wget.exe new file mode 100644 index 00000000..54b372e6 Binary files /dev/null and b/win32/tools/wget.exe differ diff --git a/win32pack.bat b/win32pack.bat deleted file mode 100644 index 022a44db..00000000 --- a/win32pack.bat +++ /dev/null @@ -1,33 +0,0 @@ -@ECHO OFF -ECHO. -IF "%1"=="" GOTO GOEXIT - -:PACKIT -mkdir %1 -mkdir %1\test -mkdir %1\src -xcopy /S/E .\test\*.* %1\test -xcopy /S/E .\src\*.* %1\src -xcopy /S/E .\win32\*.* %1 -copy *.* %1 -del %1\configure -del %1\makedist -del %1\Makefile -del %1\win32pack.bat -cd %1 - -GOTO:EOF - -:GOEXIT -ECHO. -ECHO This command creates a directory with an installable LuaRocks structure. This is -ECHO a workaround for the packaging script being a unix shell script. -ECHO. -ECHO To install LuaRocks on Windows from a Git repo use the following commands: -ECHO. -ECHO %0 ^ -ECHO install /? -ECHO. -ECHO Then follow instructions displayed to install LuaRocks -ECHO. - -- cgit v1.2.3-55-g6feb