301 lines
9.4 KiB
C#
301 lines
9.4 KiB
C#
#if USE_UNI_LUA
|
|
using LuaAPI = UniLua.Lua;
|
|
using RealStatePtr = UniLua.ILuaState;
|
|
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
|
#else
|
|
using LuaAPI = XLua.LuaDLL.Lua;
|
|
using RealStatePtr = System.IntPtr;
|
|
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
|
#endif
|
|
|
|
using XLua;
|
|
using System.Collections.Generic;
|
|
|
|
|
|
namespace XLua.CSObjectWrap
|
|
{
|
|
using Utils = XLua.Utils;
|
|
public class BFNetAesEncryptWrap
|
|
{
|
|
public static void __Register(RealStatePtr L)
|
|
{
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
System.Type type = typeof(BF.NetAesEncrypt);
|
|
Utils.BeginObjectRegister(type, L, translator, 0, 6, 1, 1);
|
|
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "CreateEncryptor", _m_CreateEncryptor);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "CreateDecryptor", _m_CreateDecryptor);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "GenerateKey", _m_GenerateKey);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "GenerateIV", _m_GenerateIV);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "Encrypt", _m_Encrypt);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "Decrypt", _m_Decrypt);
|
|
|
|
|
|
Utils.RegisterFunc(L, Utils.GETTER_IDX, "aesKey", _g_get_aesKey);
|
|
|
|
Utils.RegisterFunc(L, Utils.SETTER_IDX, "aesKey", _s_set_aesKey);
|
|
|
|
|
|
Utils.EndObjectRegister(type, L, translator, null, null,
|
|
null, null, null);
|
|
|
|
Utils.BeginClassRegister(type, L, __CreateInstance, 1, 0, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Utils.EndClassRegister(type, L, translator);
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int __CreateInstance(RealStatePtr L)
|
|
{
|
|
|
|
try {
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
if(LuaAPI.lua_gettop(L) == 2 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING))
|
|
{
|
|
byte[] _counter = LuaAPI.lua_tobytes(L, 2);
|
|
|
|
var gen_ret = new BF.NetAesEncrypt(_counter);
|
|
translator.Push(L, gen_ret);
|
|
|
|
return 1;
|
|
}
|
|
|
|
}
|
|
catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
return LuaAPI.luaL_error(L, "invalid arguments to BF.NetAesEncrypt constructor!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_CreateEncryptor(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetAesEncrypt gen_to_be_invoked = (BF.NetAesEncrypt)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
byte[] _rgbKey = LuaAPI.lua_tobytes(L, 2);
|
|
byte[] _ignoredParameter = LuaAPI.lua_tobytes(L, 3);
|
|
|
|
var gen_ret = gen_to_be_invoked.CreateEncryptor( _rgbKey, _ignoredParameter );
|
|
translator.PushAny(L, gen_ret);
|
|
|
|
|
|
|
|
return 1;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_CreateDecryptor(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetAesEncrypt gen_to_be_invoked = (BF.NetAesEncrypt)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
byte[] _rgbKey = LuaAPI.lua_tobytes(L, 2);
|
|
byte[] _ignoredParameter = LuaAPI.lua_tobytes(L, 3);
|
|
|
|
var gen_ret = gen_to_be_invoked.CreateDecryptor( _rgbKey, _ignoredParameter );
|
|
translator.PushAny(L, gen_ret);
|
|
|
|
|
|
|
|
return 1;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_GenerateKey(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetAesEncrypt gen_to_be_invoked = (BF.NetAesEncrypt)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
|
|
gen_to_be_invoked.GenerateKey( );
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_GenerateIV(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetAesEncrypt gen_to_be_invoked = (BF.NetAesEncrypt)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
|
|
gen_to_be_invoked.GenerateIV( );
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_Encrypt(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetAesEncrypt gen_to_be_invoked = (BF.NetAesEncrypt)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
byte[] _inputBuffer = LuaAPI.lua_tobytes(L, 2);
|
|
int _inputOffset = LuaAPI.xlua_tointeger(L, 3);
|
|
int _inputCount = LuaAPI.xlua_tointeger(L, 4);
|
|
byte[] _outputBuffer = LuaAPI.lua_tobytes(L, 5);
|
|
int _outputOffset = LuaAPI.xlua_tointeger(L, 6);
|
|
|
|
gen_to_be_invoked.Encrypt( _inputBuffer, _inputOffset, _inputCount, _outputBuffer, _outputOffset );
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_Decrypt(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetAesEncrypt gen_to_be_invoked = (BF.NetAesEncrypt)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
byte[] _inputBuffer = LuaAPI.lua_tobytes(L, 2);
|
|
int _inputOffset = LuaAPI.xlua_tointeger(L, 3);
|
|
int _inputCount = LuaAPI.xlua_tointeger(L, 4);
|
|
byte[] _outputBuffer = LuaAPI.lua_tobytes(L, 5);
|
|
int _outputOffset = LuaAPI.xlua_tointeger(L, 6);
|
|
|
|
gen_to_be_invoked.Decrypt( _inputBuffer, _inputOffset, _inputCount, _outputBuffer, _outputOffset );
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _g_get_aesKey(RealStatePtr L)
|
|
{
|
|
try {
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
BF.NetAesEncrypt gen_to_be_invoked = (BF.NetAesEncrypt)translator.FastGetCSObj(L, 1);
|
|
LuaAPI.lua_pushstring(L, gen_to_be_invoked.aesKey);
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _s_set_aesKey(RealStatePtr L)
|
|
{
|
|
try {
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
BF.NetAesEncrypt gen_to_be_invoked = (BF.NetAesEncrypt)translator.FastGetCSObj(L, 1);
|
|
gen_to_be_invoked.aesKey = LuaAPI.lua_tobytes(L, 2);
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|