【Lua】xLua逻辑热更新

article/2025/9/28 0:54:21

1 前言

        Lua基础语法 中系统介绍了 Lua 的语法体系,ToLua逻辑热更新 中介绍了 ToLua 的应用,本文将进一步介绍 Unity3D 中基于 xLua 实现逻辑热更新。

        逻辑热更新是指:在保持程序正常运行的情况下,在后台修改代码逻辑,修改完成并推送到运行主机上,主机无缝接入更新后的代码逻辑。Unity3D 中,基于 Lua 的逻辑热更新方案主要有 ToLua、xLua、uLua、sLua,本文将介绍 xLua 逻辑热更新方案。

        1)热更新的好处

  • 不用浪费流量重新下载;
  • 不用通过商店审核,版本迭代更加快捷;
  • 不用重新安装,用户可以更快体验更新的内容

         2)xLua 插件下载

        xLua 是腾讯研发的 Unity3D 逻辑热更新方案,目前已开源,资源见:

  • github:https://github.com/Tencent/xLua
  • gitcode:https://gitcode.net/mirrors/Tencent/xlua

        3)xLua 插件导入

        将插件的 Assets 目录下的所有文件拷贝到项目的 Assets 目录下,如下:

        4)生成 Wrap 文件

        导入插件后,菜单栏会多一个 XLua 窗口,点击 Generate Code 会生成一些 Wrap 文件,生成路径见【Assets\XLua\Gen】,这些 Wrap 文件是 C# 与 Lua 沟通的桥梁。每次生成文件时,建议先点击下 Clear Generate Code,再点击 Generate Code。

        5)官方教程文档

        在【Assets\XLua\Doc\XLua教程.doc】中可以查阅官方教程文档,在线教程文档见:

  • github:https://github.com/Tencent/xLua/tree/master/Assets/XLua/Doc/XLua教程.md
  • gitcode:https://gitcode.net/mirrors/Tencent/xLua/tree/master/Assets/XLua/Doc/XLua教程.md

        6)官方Demo

2 xLua 应用

2.1 C# 中执行 Lua 代码串

        HelloWorld.cs

using UnityEngine;
using XLua;public class HelloWorld : MonoBehaviour {private void Start() {LuaEnv luaEnv = new LuaEnv();string luaStr = @"print('Hello World')CS.UnityEngine.Debug.Log('Hello World')";luaEnv.DoString(luaStr);luaEnv.Dispose();}
}

        运行如下:

        说明:第一个日志是 lua 打印的,所以有 "LUA: " 标识,第二个日志是 Lua 调用 C# 的 Debug 方法,所以没有 "LUA: " 标识。

2.2 C# 中调用 Lua 文件

        1)通过 Resources.Load 加载 lua 文件

         ScriptFromFile.cs

using UnityEngine;
using XLua;public class ScriptFromFile : MonoBehaviour {private void Start() {LuaEnv luaEnv = new LuaEnv();TextAsset textAsset = Resources.Load<TextAsset>("02/LuaScript.lua");luaEnv.DoString(textAsset.text);luaEnv.Dispose();}
}

        LuaScript.lua.txt

print("Load lua script")

        说明:LuaScript.lua.txt 文件放在 【Assets\Resources\02】目录下。因为 Resource 只支持有限的后缀,放 Resources 下的 lua 文件得加上 txt 后缀。

        2)通过内置 loader 加载 lua 文件

        ScriptFromFile.cs

using UnityEngine;
using XLua;public class ScriptFromFile : MonoBehaviour {private void Start() {LuaEnv luaEnv = new LuaEnv();luaEnv.DoString("require '02/LuaScript'");luaEnv.Dispose();}
}

        说明:require 实际上是调一个个的 loader 去加载,有一个成功就不再往下尝试,全失败则报文件找不到。 目前 xLua 除了原生的 loader 外,还添加了从 Resource 加载的 loader。因为 Resource 只支持有限的后缀,放 Resources 下的 lua 文件得加上 txt 后缀。 

        3)通过自定义 loader 加载 lua 文件

        ScriptFromFile.cs

using UnityEngine;
using XLua;
using System.IO;
using System.Text;public class ScriptFromFile : MonoBehaviour {private void Start() {LuaEnv luaEnv = new LuaEnv();luaEnv.AddLoader(MyLoader);luaEnv.DoString("require '02/LuaScript'");luaEnv.Dispose();}private byte[] MyLoader(ref string filePath) {string path = Application.dataPath + "/Resources/" + filePath + ".lua.txt";string txt = File.ReadAllText(path);return Encoding.UTF8.GetBytes(txt);}
}

2.3 C# 中调用 Lua 变量

        AccessVar.cs

using UnityEngine;
using XLua;public class AccessVar : MonoBehaviour {private LuaEnv luaEnv;private void Start() {luaEnv = new LuaEnv();luaEnv.DoString("require '03/LuaScript'");TestAccessVar();}private void TestAccessVar() {bool a = luaEnv.Global.Get<bool>("a");int b = luaEnv.Global.Get<int>("b");float c = luaEnv.Global.Get<float>("c");string d = luaEnv.Global.Get<string>("d");Debug.Log("a=" + a + ", b=" + b + ", c=" + c + ", d=" + d); // a=True, b=10, c=7.8, d=xxx}private void OnApplicationQuit() {luaEnv.Dispose();luaEnv = null;}
}

        LuaScript.lua.txt

a = true
b = 10
c = 7.8
d = "xxx"

2.4 C# 中调用 Lua table

        1)通过自定义类映射 table

        AccessTable.cs

using UnityEngine;
using XLua;public class AccessTable : MonoBehaviour {private LuaEnv luaEnv;private void Start() {luaEnv = new LuaEnv();luaEnv.DoString("require '04/LuaScript'");TestAccessTable();}private void TestAccessTable() {Student stu = luaEnv.Global.Get<Student>("stu");Debug.Log("name=" + stu.name + ", age=" + stu.age); // name=zhangsan, age=23stu.name = "lisi";luaEnv.DoString("print(stu.name)"); // LUA: zhangsan}private void OnApplicationQuit() {luaEnv.Dispose();luaEnv = null;}
}class Student {public string name;public int age;
}

        LuaScript.lua.txt

stu = {name = "zhangsan", age = 23, sex = 0, 1, 2, 3}

        说明:允许 table 中元素个数与自定义类中属性个数不一致,允许自定义类中属性顺序与 table 中元素顺序不一致;类中需要映射的属性名必须与 table 中相应元素名保持一致(大小写也必须一致);修改映射类的属性值,不影响 table 中相应元素的值

        2)通过自定义接口映射 table

        AccessTable.cs

using UnityEngine;
using XLua;public class AccessTable : MonoBehaviour {private LuaEnv luaEnv;private void Start() {luaEnv = new LuaEnv();luaEnv.DoString("require '04/LuaScript'");TestAccessTable();}private void TestAccessTable() {IStudent stu = luaEnv.Global.Get<IStudent>("stu");Debug.Log("name=" + stu.name + ", age=" + stu.age); // name=zhangsan, age=23stu.name = "lisi";luaEnv.DoString("print(stu.name)"); // LUA: lisistu.study("program"); // LUA: subject=programstu.raiseHand("right"); // LUA: hand=right}private void OnApplicationQuit() {luaEnv.Dispose();luaEnv = null;}
}[CSharpCallLua]
public interface IStudent {public string name {get; set;}public int age {get; set;}public void study(string subject);public void raiseHand(string hand);
}

        说明:在运行脚本之前,需要先点击下 Clear Generate Code,再点击 Generate Code;允许 table 中元素个数与自定义接口中属性个数不一致,允许自定义接口中属性顺序与 table 中元素顺序不一致;接口中需要映射的属性名和方法名必须与 table 中相应元素名和函数名保持一致(大小写也必须一致);修改映射接口的属性值,会影响 table 中相应元素的值

        LuaScript.lua.txt

stu = {name = "zhangsan",age = 23,study = function(self, subject)print("subject="..subject)end
}--function stu.raiseHand(self, hand)
function stu:raiseHand(hand)print("hand="..hand)
end

        3)通过 Dictionary 映射 table

         AccessTable.cs

using System.Collections.Generic;
using UnityEngine;
using XLua;public class AccessTable : MonoBehaviour {private LuaEnv luaEnv;private void Start() {luaEnv = new LuaEnv();luaEnv.DoString("require '04/LuaScript'");TestAccessTable();}private void TestAccessTable() {Dictionary<string, object> stu = luaEnv.Global.Get<Dictionary<string, object>>("stu");Debug.Log("name=" + stu["name"] + ", age=" + stu["age"]); // name=zhangsan, age=23stu["name"] = "lisi";luaEnv.DoString("print(stu.name)"); // LUA: zhangsan}private void OnApplicationQuit() {luaEnv.Dispose();luaEnv = null;}
}

        说明:修改映射 Dictionary 的元素值,不影响 table 中相应元素的值

        LuaScript.lua.txt

stu = {name = "zhangsan", age = 23, "math", 2, true}

       4)通过 List 映射 table

         AccessTable.cs

using System.Collections.Generic;
using UnityEngine;
using XLua;public class AccessTable : MonoBehaviour {private LuaEnv luaEnv;private void Start() {luaEnv = new LuaEnv();luaEnv.DoString("require '04/LuaScript'");TestAccessTable();}private void TestAccessTable() {List<object> list = luaEnv.Global.Get<List<object>>("stu");string str = "";foreach(var item in list) {str += item + ", ";}Debug.Log(str); // math, 2, True, }private void OnApplicationQuit() {luaEnv.Dispose();luaEnv = null;}
}

        LuaScript.lua.txt

stu = {name = "zhangsan", age = 23, "math", 2, true}

        5)通过 LuaTable 映射 table

        AccessTable.cs

using UnityEngine;
using XLua;public class AccessTable : MonoBehaviour {private LuaEnv luaEnv;private void Start() {luaEnv = new LuaEnv();luaEnv.DoString("require '04/LuaScript'");TestAccessTable();}private void TestAccessTable() {LuaTable table = luaEnv.Global.Get<LuaTable>("stu");Debug.Log("name=" + table.Get<string>("name") + ", age=" + table.Get<int>("age")); // name=zhangsan, age=23table.Set<string, string>("name", "lisi");luaEnv.DoString("print(stu.name)"); // LUA: lisitable.Dispose();}private void OnApplicationQuit() {luaEnv.Dispose();luaEnv = null;}
}

        说明:修改映射 LuaTable 的属性值,会影响 table 中相应元素的值 

        LuaScript.lua.txt

stu = {name = "zhangsan", age = 23, "math", 2, true}

2.5 C# 中调用 Lua 全局函数

        1)通过 delegate 映射 function

        AccessFunc.cs

using System;
using UnityEngine;
using XLua;public class AccessFunc : MonoBehaviour {private LuaEnv luaEnv;[CSharpCallLua] // 需要设置 public, 并且点击 Generate Codepublic delegate int MyFunc1(int arg1, int arg2);[CSharpCallLua] // 需要设置 public, 并且点击 Generate Codepublic delegate int MyFunc2(int arg1, int arg2, out int resOut);[CSharpCallLua] // 需要设置 public, 并且点击 Generate Codepublic delegate int MyFunc3(int arg1, int arg2, ref int resRef);private void Start() {luaEnv = new LuaEnv();luaEnv.DoString("require '05/LuaScript'");TestAccessFunc1();TestAccessFunc2();TestAccessFunc3();TestAccessFunc4();}private void TestAccessFunc1() { // 测试无参函数Action func1 = luaEnv.Global.Get<Action>("func1");func1(); // LUA: func1}private void TestAccessFunc2() { // 测试有参函数Action<string> func2 = luaEnv.Global.Get<Action<string>>("func2");func2("xxx"); // LUA: func2, arg=xxx}private void TestAccessFunc3() { // 测试有返回值函数MyFunc1 func3 = luaEnv.Global.Get<MyFunc1>("func3");Debug.Log(func3(2, 3)); // 6}private void TestAccessFunc4() { // 测试有多返回值函数MyFunc1 func41 = luaEnv.Global.Get<MyFunc1>("func4");Debug.Log(func41(2, 3)); // 5int res, resOut;MyFunc2 func42 = luaEnv.Global.Get<MyFunc2>("func4");res = func42(2, 3, out resOut);Debug.Log("res=" + res + ", resOut=" + resOut); // res=5, resOut=-1int ans, resRef = 0;MyFunc3 func43 = luaEnv.Global.Get<MyFunc3>("func4");ans = func43(2, 3, ref resRef);Debug.Log("ans=" + ans + ", resRef=" + resRef); // res=5, resRef=-1}private void OnApplicationQuit() {luaEnv.Dispose();luaEnv = null;}
}

        说明:Lua 函数支持多返回值,但 C# 函数不支持多返回值,要想让 C# 接收 Lua 函数的多个返回值,需要通过 out 或 ref 参数接收第 2 个及之后的返回值

        LuaScript.lua.txt

--无参函数
function func1()print("func1")
end--有参函数
function func2(arg)print("func2, arg="..arg)
end--有返回值函数
function func3(a, b)return a * b
end--有多返回值函数
function func4(a, b)return a + b, a - b
end

        2)通过 LuaFunction 映射 function

        AccessFunc.cs 

using UnityEngine;
using XLua;public class AccessFunc : MonoBehaviour {private LuaEnv luaEnv;private void Start() {luaEnv = new LuaEnv();luaEnv.DoString("require '05/LuaScript'");TestAccessFunc1();TestAccessFunc2();TestAccessFunc3();TestAccessFunc4();}private void TestAccessFunc1() { // 测试无参函数LuaFunction func1 = luaEnv.Global.Get<LuaFunction>("func1");func1.Call(); // LUA: func1}private void TestAccessFunc2() { // 测试有参函数LuaFunction func2 = luaEnv.Global.Get<LuaFunction>("func2");func2.Call("xxx"); // LUA: func2, arg=xxx}private void TestAccessFunc3() { // 测试有返回值函数LuaFunction func3 = luaEnv.Global.Get<LuaFunction>("func3");object[] res = func3.Call(2, 3);Debug.Log(res[0]); // 6}private void TestAccessFunc4() { // 测试有多返回值函数LuaFunction func4 = luaEnv.Global.Get<LuaFunction>("func4");object[] res = func4.Call(2, 3);Debug.Log("res1=" + res[0] + ", res2=" + res[1]); // res1=5, res2=-1}private void OnApplicationQuit() {luaEnv.Dispose();luaEnv = null;}
}

        说明:LuaScript.lua.txt 同第 1)节;LuaFunction 映射方式相较 delegate 方式,性能消耗较大

2.6 Lua 中创建 GameObject 并获取和添加组件

        TestGameObject.cs

using UnityEngine;
using XLua;public class TestGameObject : MonoBehaviour {private LuaEnv luaEnv;private void Start() {luaEnv = new LuaEnv();luaEnv.DoString("require '06/LuaScript'");}private void OnApplicationQuit() {luaEnv.Dispose();luaEnv = null;}
}

        LuaScript.lua.txt

local GameObject = CS.UnityEngine.GameObject
local PrimitiveType = CS.UnityEngine.PrimitiveType
local Color = CS.UnityEngine.Color
local Rigidbody = CS.UnityEngine.RigidbodyGameObject("xxx") --创建空对象
go = GameObject.CreatePrimitive(PrimitiveType.Cube)
go:GetComponent("MeshRenderer").sharedMaterial.color = Color.red
rigidbody = go:AddComponent(typeof(Rigidbody))
rigidbody.mass = 1000

2.7 Lua 中访问 C# 自定义类

        TestSelfClass.cs

using UnityEngine;
using XLua;public class TestSelfClass : MonoBehaviour {private LuaEnv luaEnv;private void Awake() {luaEnv = new LuaEnv();luaEnv.DoString("require '07/LuaScript'");}private void OnApplicationQuit() {luaEnv.Dispose();luaEnv = null;}
}[LuaCallCSharp] // 需要点击 Generate Code
class Person {public string name;public int age;public Person(string name, int age) {this.name = name;this.age = age;}public void Run() {Debug.Log("run");}public void Eat(string fruit) {Debug.Log("eat " + fruit);}public override string ToString() {return "name=" + name + ", age=" + age;}
}

        LuaScript.lua.txt

local Person = CS.Personperson = Person("zhangsan", 23)
print("name="..person.name..", age="..person.age) -- LUA: name=zhangsan, age=23
print(person:ToString()) -- LUA: name=zhangsan, age=23
person:Run() -- run
person:Eat("aple") -- eat aple

3 Lua Hook MonoBehaviour 生命周期方法

        MonoBehaviour 生命周期方法见→MonoBehaviour的生命周期。

        TestLife.cs

using System;
using System.Collections.Generic;
using UnityEngine;
using XLua;public class TestLife : MonoBehaviour {private LuaEnv luaEnv;private Dictionary<string, Action> func;private void Awake() {luaEnv = new LuaEnv();luaEnv.DoString("require '08/LuaScript'");GetFunc();CallFunc("awake");}private void OnEnable() {CallFunc("onEnable");}private void Start() {CallFunc("start");}private void Update() {CallFunc("update");}private void OnDisable() {CallFunc("onDisable");}private void OnDestroy() {CallFunc("onDestroy");}private void GetFunc() {func = new Dictionary<string, Action>();AddFunc("awake");AddFunc("onEnable");AddFunc("start");AddFunc("update");AddFunc("onDisable");AddFunc("onDestroy");}private void AddFunc(string funcName) {Action fun = luaEnv.Global.Get<Action>(funcName);if (fun != null) {func.Add(funcName, fun);}}private void CallFunc(string funcName) {if (func.ContainsKey(funcName)) {Action fun = func[funcName];fun();}}private void OnApplicationQuit() {func.Clear();func = null;luaEnv.Dispose();luaEnv = null;}
}

        LuaScript.lua.txt 

function awake()print("awake")
endfunction onEnable()print("onEnable")
endfunction start()print("start")
endfunction update()print("update")
endfunction onDisable()print("onDisable")
endfunction onDestroy()print("onDestroy")
end

http://chatgpt.dhexx.cn/article/fU5YAnaw.shtml

相关文章

[Unity实战]一个好用的lua/xlua/tolua/slua调试工具vscode-luaide-lite插件 好用到飞起..[Unity-Debug+Xlua-Debug][开箱可用]

[Unity实战]一个好用的lua调试工具vscode-luaide-lite插件 好用到飞起..[Debug][开箱可用][xlua] 简介官方例子:xlua/tolua/slua/lua5.1等1.安装2.配置3.使用3.1启动unity3.2vscode-debug:Unity Editor3.3vscode-debug:3.4运行unity进入断点... 4.核心代码:5.github地址 简介 l…

XLua——热更新

什么是热更新&#xff1f; 游戏上线后&#xff0c;出现游戏Bug或者需要更新小版本内容&#xff0c;游戏如果没有做热更新支持的话&#xff0c;就需要重重新打包游戏&#xff0c;然后上传平台进行审核&#xff0c;审核通过后玩家才可以下载新版本。审核期间需要时间&#xff0c;…

通过Xlua插件运行lua程序

using System.Collections; using System.Collections.Generic; using UnityEngine; using XLua; //引入xlua命名空间 public class Creat : MonoBehaviour {private LuaEnv luaenv;void Start(){luaenv new LuaEnv(); //LuaEnv可以理解为lua的运行环境luaenv.DoString("…

xlua基础知识

1.1 xLua简介 xLua是由腾讯维护的一个开源项目&#xff0c;xLua为Unity、 .Net、 Mono等C#环境增加Lua脚本编程的能力&#xff0c;借助xLua&#xff0c;这些Lua代码可以方便的和C#相互调用。自2016年初推广以来&#xff0c;已经应用于十多款腾讯自研游戏&#xff0c;因其良好性…

[Unity XLua]热更新XLua入门(一)-基础篇

无意中发现了一个巨牛巨牛的人工智能教程&#xff0c;忍不住分享一下给大家。教程不仅是零基础&#xff0c;通俗易懂&#xff0c;小白也能学&#xff0c;而且非常风趣幽默&#xff0c;还时不时有内涵段子&#xff0c;像看小说一样&#xff0c;哈哈&#xff5e;我正在学习中&…

Xlua

有一个项目做完快上线了,不是lua写的,能热更新的东西就特别少,如果遇到bug也很难在第一时间热修复,所以我就接入了Xlua这个插件点击打开链接 原本只是想热修复一下的,后来领导要求把逻辑系统的C#代码全部换成了Lua,至于为什么,因为他们习惯了每天都更新和修改的开发模式...所以…

xLua热更新(二)实现热更新

一、环境配置 要实现热更新功能&#xff0c;我们首先需要开启热更新的宏。操作方法是在「File->Build Settings->Player Settings->Player->Other Settings->Scripting Define Symbols」选项中添加HOTFIX_ENABLE 开启后&#xff0c;在xLua的菜单中就出现了「…

Unity 热更新技术 |(六)xLua框架学习最新系列完整教程

🎬 博客主页:https://xiaoy.blog.csdn.net 🎥 本文由 呆呆敲代码的小Y 原创,首发于 CSDN🙉 🎄 学习专栏推荐:Unity系统学习专栏 🌲 游戏制作专栏推荐:游戏制作 🌲Unity实战100例专栏推荐:Unity 实战100例 教程 🏅 欢迎点赞 👍 收藏 ⭐留言 📝 如有错误敬…

xLua(九)——实战

一&#xff1a;使用xLua的步骤 ——导入xLua插件 其实xLua本质就是一个Unity工程&#xff0c;把Asset中的文件导入到Unity工程中就搞定了&#xff08;导入之后编辑器菜单栏会扩展出一个XLua选项&#xff09; ——添加宏File——Build Settings——Player Settings——Other Se…

【XLua】简单使用

文章目录 前言1 配置1.1 配置宏1.2 XLua配置 2 lua和C#相互调用2.1 XLua.CSharpCallLua2.2 XLua.LuaCallCSharp 3 加载器 前言 XLua本质上是为Unity提供了使用lua的能力&#xff0c;实际多用于热更新。 热更新&#xff0c;因为要给代码打标签才能生效&#xff0c;所以需要预测…

xLua介绍

xLua地址&#xff1a;传送门 Xlua是啥&#xff1f; 2016年 腾讯推出的 一种 unity下 lua 编成的解决方案 基本概念介绍&#xff1a; 1.模块 模块就是一个 程序库&#xff0c;可以通过 require 加载&#xff0c;得到了一个表示 table的全局变量 这个table 就像一个命名空间&am…

Lua快速入门篇(XLua教程)(Yanlz+热更新+xLua+配置+热补丁+第三方库+API+二次开发+常见问题+示例参考)

《Lua热更新》 ##《Lua热更新》发布说明&#xff1a; “Lua热更新”开始了&#xff0c;立钻哥哥终于开始此部分的探索了。 作为游戏发布迭代的重要技术&#xff1a;Lua热更新在网络游戏迭代更新中非常重要&#xff0c;特别是对于AppStore这样的平台&#xff0c;我们只需要定…

XLua加载

XLua加载lua文件的方式 LuaEnv.DoString(print("hello world")); //直接执行lua的语句&#xff0c;在函数体内的语句格式要符合lua的语法 LuaEnv.DoString("require byfile")//使用require lua文件名也可在unity中加载lua 但是在unity中需要把文件放置在…

XLua系列讲解_Helloworld

一、XLua简介 XLua是Unity3D下Lua编程解决方案&#xff0c;自2016年初推广以来&#xff0c;已经应用于十多款腾讯自研游戏&#xff0c;因其良好性能、易用性、扩展性而广受好评。现在&#xff0c;腾讯已经将xLua开源到GitHub。 二、Xlua的优点 简洁易用&#xff0c;容易上手可…

Unity XLua Hotfix热更新配置笔记

Unity XLUA Hotfix热更新配置笔记 目录 Unity XLUA Hotfix热更新配置笔记 配置热更新步骤&#xff1a; 下载XLUA下载压缩包解压 复制xlua 和plugins到assets开启热补丁特性 先添加宏 HOTFIX_ENABLE;INJECT_WITHOUT_TOOL报“This delegate/interface must add to CSharpCallLu…

xLua热更新(一)xLua基本使用

一、什么是xLua xLua为Unity、 .Net、 Mono等C#环境增加Lua脚本编程的能力&#xff0c;借助xLua&#xff0c;这些Lua代码可以方便的和C#相互调用。 xLua是用来实现Lua代码与C#代码相互调用的插件。我们可以借助这个插件来实现热更新方案。 那么为什么要选择Lua实现热更新呢&am…

Bug-CTF-秋名山老司机(正则匹配)

题目: 没有啥思路&#xff0c;意外地刷新了一下页面&#xff0c;发现数值变化了 再刷新一次试试&#xff0c;出来一个提示&#xff0c;大概意思是需要提交结果&#xff0c;这里也不知道该怎么传参&#xff0c;也不晓得怎么写这个脚本&#xff0c;只能参考其他大佬的思路了 解题…

BUGKU------秋名山老司机

看到这个就直接上python吧&#xff0c;用eval计算子式 import requests from bs4 import BeautifulSoup r requests.session() s r.get(http://123.206.87.240:8002/qiumingshan/) soup BeautifulSoup(s.text, "html.parser") a soup.find(div) d {"valu…

bugku秋名山车神

不断的刷新&#xff0c;发现表达式一直在变换&#xff0c;这种必须写脚本&#xff0c;才能跟上速度。直接上代码 import re import requests srequests.session() rs.get("http://123.206.87.240:8002/qiumingshan/") searchObj re.search(r^<div>(.*)\?;<…

【BugkuCTF】Web--秋名山老司机

Description: http://123.206.87.240:8002/qiumingshan/ 是不是老司机试试就知道。 Solution: 打开网页 2秒解决问题真是稳稳的写脚本……但是不知道提交啥&#xff0c;刷新网页看看提示让用POST方式传递一个value变量&#xff0c;构造脚本 import requests import re url htt…