Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/lua-winreg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lua_int64.h10
-rw-r--r--src/lua_mtutil.h2
-rw-r--r--src/luareg.h12
-rw-r--r--src/win_trace.h8
-rw-r--r--src/winreg.c30
5 files changed, 56 insertions, 6 deletions
diff --git a/src/lua_int64.h b/src/lua_int64.h
index 6bed1dd..d6f84dd 100644
--- a/src/lua_int64.h
+++ b/src/lua_int64.h
@@ -15,6 +15,10 @@ INT64 lua_checkINT64(lua_State *L, int i);
int atoUINT64(const char* s, UINT64 * pv);
int atoINT64(const char* s, INT64 *pv);
+#ifndef MINGW_HAS_SECURE_API
+#define _ui64toa_s(val, buf, sz, radix) !_ui64toa(val, buf, radix)
+#endif
+
#ifdef __GNUC__
#define CONST_9007199254740992 0x20000000000000LL
#else
@@ -24,7 +28,11 @@ int atoINT64(const char* s, INT64 *pv);
#define lua_pushUINT64(L,n) \
if( n > CONST_9007199254740992 ){ \
char buf[24]; \
- lua_pushstring(L, _ui64toa(n, buf, 10)); \
+ if(_ui64toa_s(n, buf, _countof(buf), 10)){ \
+ lua_pushnil(L);return; \
+ }else{ \
+ lua_pushstring(L, buf); \
+ } \
}else{ \
lua_pushnumber(L, (lua_Number)(__int64)n); \
}
diff --git a/src/lua_mtutil.h b/src/lua_mtutil.h
index 01f56e9..746552f 100644
--- a/src/lua_mtutil.h
+++ b/src/lua_mtutil.h
@@ -7,7 +7,7 @@ extern "C" {
#include <lualib.h>
#include <lauxlib.h>
-int lua_opentablemt(lua_State *L, const char * libname, const luaL_Reg * reg);
+int lua_opentablemt(lua_State *L, const char * libname, const luaL_Reg * reg, int upval);
void * lua_newuserdatamt(lua_State *L, size_t cdata, const char * mtname, const luaL_Reg * mtreg);
void * lua_newuserdatamtuv(lua_State *L, size_t cdata, const char * mtname, const luaL_Reg * mtreg, int upval);
#ifdef __cplusplus
diff --git a/src/luareg.h b/src/luareg.h
index 26c5f05..0a46aa5 100644
--- a/src/luareg.h
+++ b/src/luareg.h
@@ -15,13 +15,19 @@ int reg_enumvalue(lua_State *L);
int reg_flushkey(lua_State *L);
int reg_getinfo(lua_State *L);
int reg_getvalue(lua_State *L);
+#ifndef LUA_REG_NO_HIVEOPS
int reg_loadkey(lua_State *L);
+#endif // LUA_REG_NO_HIVEOPS
int reg_openkey(lua_State *L);
+#ifndef LUA_REG_NO_HIVEOPS
int reg_replacekey(lua_State *L);
int reg_restorekey(lua_State *L);
int reg_savekey(lua_State *L);
+#endif // LUA_REG_NO_HIVEOPS
int reg_setvalue(lua_State *L);
+#ifndef LUA_REG_NO_HIVEOPS
int reg_unloadkey(lua_State *L);
+#endif // LUA_REG_NO_HIVEOPS
int reg_handle(lua_State *L);
int reg_detach(lua_State *L);
int reg_getstrval(lua_State *L);
@@ -41,13 +47,19 @@ luaL_Reg lreg_regobj[] = {
{"flushkey",reg_flushkey},
{"getinfo",reg_getinfo},
{"getvalue",reg_getvalue},
+#ifndef LUA_REG_NO_HIVEOPS
{"load",reg_loadkey},
+#endif // LUA_REG_NO_HIVEOPS
{"openkey",reg_openkey},
+#ifndef LUA_REG_NO_HIVEOPS
{"replace",reg_replacekey},
{"restore",reg_restorekey},
{"save",reg_savekey},
+#endif // LUA_REG_NO_HIVEOPS
{"setvalue",reg_setvalue},
+#ifndef LUA_REG_NO_HIVEOPS
{"unload",reg_unloadkey},
+#endif // LUA_REG_NO_HIVEOPS
{"handle",reg_handle},
{"detach",reg_detach},
{"getstrval",reg_getstrval},
diff --git a/src/win_trace.h b/src/win_trace.h
index d2e2114..d5e1e5c 100644
--- a/src/win_trace.h
+++ b/src/win_trace.h
@@ -17,7 +17,13 @@ extern "C" {
#endif
#include <windows.h>
-#ifdef NDEBUG
+#if defined(NDEBUG) && (defined(__MINGW32__) || (defined(_MSC_VER) && (_MSC_VER >= 1400)))
+ #define WIN_TRACET(...) do {} while(0)
+ #define WIN_TRACEA(...) do {} while(0)
+ #define WIN_TRACEW(...) do {} while(0)
+ #define WIN_TRACEA_FT(...) do {} while(0)
+ #define WIN_TRACEA_ST(...) do {} while(0)
+#elif defined(NDEBUG) && defined(_MSC_VER) && (_MSC_VER < 1400)
#define WIN_TRACET NOP_FUNCTION
#define WIN_TRACEA NOP_FUNCTION
#define WIN_TRACEW NOP_FUNCTION
diff --git a/src/winreg.c b/src/winreg.c
index 1952a46..b8c8f48 100644
--- a/src/winreg.c
+++ b/src/winreg.c
@@ -2,8 +2,11 @@
# include <luamsvc.h>
#endif
+#include <stdlib.h> /* _ui64toa/_ui64toa_s */
#include <assert.h>
+#ifndef lua_assert
#define lua_assert assert
+#endif
#include <lua.h>
#include <lualib.h>
@@ -37,7 +40,14 @@
#define REG_QWORD ( 11 ) // 64-bit number
#endif
+#if !defined(KEY_WOW64_32KEY) && defined(__MINGW32__)
+#define KEY_WOW64_32KEY (0x0200)
+#endif
+#if !defined(KEY_WOW64_64KEY) && defined(__MINGW32__)
+#define KEY_WOW64_64KEY (0x0100)
+#endif
+#ifndef LUA_REG_NO_DLL
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved){
UNUSED(hModule);
UNUSED(lpReserved);
@@ -45,7 +55,9 @@ BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReser
return TRUE;
}
-__declspec(dllexport) int luaopen_winreg(lua_State *L){
+__declspec(dllexport)
+#endif
+int luaopen_winreg(lua_State *L){
luaL_register(L, "winreg", lreg_reglib);
return 1;
}
@@ -151,7 +163,7 @@ HKEY reg_aux_strtohkey(lua_State *L, const char * psz){
WIN_TRACEA("DIGIT ROOTKEY %s", psz);
return (HKEY)(size_t)x;
}else{
- for(pph = ph; pph->name && stricmp(psz, pph->name); pph++);
+ for(pph = ph; pph->name && _stricmp(psz, pph->name); pph++);
if(!pph->data)luaL_error(L, "invalid prefix key '%s'", psz);
return (HKEY)pph->data;
}
@@ -342,7 +354,13 @@ void reg_aux_pusheregstrdata(lua_State *L, PVOID pdata, size_t cdata, DWORD dwTy
}else{
n = (DWORD64)(*((PDWORD32)pdata));
}
- lua_pushstring(L, _ui64toa(n, buf, 10));
+ if(_ui64toa_s(n, buf, _countof(buf), 10)){
+ lua_pushnil(L);
+ return;
+ }else{
+ lua_pushstring(L, buf);
+ }
+
}
break; case REG_MULTI_SZ:
{
@@ -572,6 +590,7 @@ int reg_getvalue(lua_State *L){//regobj.getvalue
}
return 2;
}
+#ifndef LUA_REG_NO_HIVEOPS
//docok
int reg_loadkey(lua_State *L){//regobj.load
LONG ret;
@@ -580,12 +599,14 @@ int reg_loadkey(lua_State *L){//regobj.load
LUA_CHECK_DLL_ERROR(L, ret);
LUA_CHECK_RETURN_OBJECT(L, ret == ERROR_SUCCESS);
}
+#endif // LUA_REG_NO_HIVEOPS
//docok
int reg_openkey(lua_State *L){//regobj.openkey
reg_aux_newkey(L, reg_aux_gethkey(L, 1),
lua_checktstring(L, 2), NULL, reg_aux_getaccess(L, 3), FALSE);
return 1;
}
+#ifndef LUA_REG_NO_HIVEOPS
//docok
int reg_replacekey(lua_State *L){//regobj.replace
LONG ret;
@@ -616,12 +637,14 @@ int reg_savekey(lua_State *L){//regobj.save
LUA_CHECK_DLL_ERROR(L, ret);
LUA_CHECK_RETURN_OBJECT(L, ret == ERROR_SUCCESS);
}
+#endif // LUA_REG_NO_HIVEOPS
//docok
int reg_setvalue(lua_State *L){//regobj.setvalue
LUA_CHECK_RETURN_OBJECT(L,
reg_aux_setvalue(L, reg_aux_gethkey(L, 1), lua_opttstring(L, 2, NULL), reg_aux_getdatatype(L, 4), 3)
);
}
+#ifndef LUA_REG_NO_HIVEOPS
//docok
int reg_unloadkey(lua_State *L){//regobj.unload
LONG ret;
@@ -630,6 +653,7 @@ int reg_unloadkey(lua_State *L){//regobj.unload
LUA_CHECK_DLL_ERROR(L, ret);
LUA_CHECK_RETURN_OBJECT(L, ret == ERROR_SUCCESS);
}
+#endif // LUA_REG_NO_HIVEOPS
int reg_handle(lua_State *L){//regobj.handle
HKEY hKey = reg_aux_gethkey(L, 1);