├── .clang-format ├── .clang-format-ignore ├── .editorconfig ├── .gitattributes ├── .github └── workflows │ ├── build.yml │ └── clang-format.yml ├── .gitignore ├── .gitmodules ├── .luarc.json ├── .vscode ├── extensions.json ├── launch.json ├── settings.json └── tasks.json ├── 3rd ├── frida_gum │ └── .gitignore ├── lua │ ├── lua-latest │ │ ├── Makefile │ │ ├── lapi.c │ │ ├── lapi.h │ │ ├── lauxlib.c │ │ ├── lauxlib.h │ │ ├── lbaselib.c │ │ ├── lcode.c │ │ ├── lcode.h │ │ ├── lcorolib.c │ │ ├── lctype.c │ │ ├── lctype.h │ │ ├── ldblib.c │ │ ├── ldebug.c │ │ ├── ldebug.h │ │ ├── ldo.c │ │ ├── ldo.h │ │ ├── ldump.c │ │ ├── lfunc.c │ │ ├── lfunc.h │ │ ├── lgc.c │ │ ├── lgc.h │ │ ├── linit.c │ │ ├── liolib.c │ │ ├── ljumptab.h │ │ ├── llex.c │ │ ├── llex.h │ │ ├── llimits.h │ │ ├── lmathlib.c │ │ ├── lmem.c │ │ ├── lmem.h │ │ ├── loadlib.c │ │ ├── lobject.c │ │ ├── lobject.h │ │ ├── lopcodes.c │ │ ├── lopcodes.h │ │ ├── lopnames.h │ │ ├── loslib.c │ │ ├── lparser.c │ │ ├── lparser.h │ │ ├── lprefix.h │ │ ├── lstate.c │ │ ├── lstate.h │ │ ├── lstring.c │ │ ├── lstring.h │ │ ├── lstrlib.c │ │ ├── ltable.c │ │ ├── ltable.h │ │ ├── ltablib.c │ │ ├── ltm.c │ │ ├── ltm.h │ │ ├── lua.c │ │ ├── lua.h │ │ ├── lua.hpp │ │ ├── luac.c │ │ ├── luaconf.h │ │ ├── lualib.h │ │ ├── lundump.c │ │ ├── lundump.h │ │ ├── lutf8lib.c │ │ ├── lvm.c │ │ ├── lvm.h │ │ ├── lzio.c │ │ └── lzio.h │ ├── lua51 │ │ ├── lapi.c │ │ ├── lapi.h │ │ ├── lauxlib.c │ │ ├── lauxlib.h │ │ ├── lbaselib.c │ │ ├── lcode.c │ │ ├── lcode.h │ │ ├── ldblib.c │ │ ├── ldebug.c │ │ ├── ldebug.h │ │ ├── ldo.c │ │ ├── ldo.h │ │ ├── ldump.c │ │ ├── lfunc.c │ │ ├── lfunc.h │ │ ├── lgc.c │ │ ├── lgc.h │ │ ├── linit.c │ │ ├── liolib.c │ │ ├── llex.c │ │ ├── llex.h │ │ ├── llimits.h │ │ ├── lmathlib.c │ │ ├── lmem.c │ │ ├── lmem.h │ │ ├── loadlib.c │ │ ├── lobject.c │ │ ├── lobject.h │ │ ├── lopcodes.c │ │ ├── lopcodes.h │ │ ├── loslib.c │ │ ├── lparser.c │ │ ├── lparser.h │ │ ├── lstate.c │ │ ├── lstate.h │ │ ├── lstring.c │ │ ├── lstring.h │ │ ├── lstrlib.c │ │ ├── ltable.c │ │ ├── ltable.h │ │ ├── ltablib.c │ │ ├── ltm.c │ │ ├── ltm.h │ │ ├── lua.c │ │ ├── lua.h │ │ ├── lua.hpp │ │ ├── luac.c │ │ ├── luaconf.h │ │ ├── lualib.h │ │ ├── lundump.c │ │ ├── lundump.h │ │ ├── lvm.c │ │ ├── lvm.h │ │ ├── lzio.c │ │ └── lzio.h │ ├── lua52 │ │ ├── lapi.c │ │ ├── lapi.h │ │ ├── lauxlib.c │ │ ├── lauxlib.h │ │ ├── lbaselib.c │ │ ├── lbitlib.c │ │ ├── lcode.c │ │ ├── lcode.h │ │ ├── lcorolib.c │ │ ├── lctype.c │ │ ├── lctype.h │ │ ├── ldblib.c │ │ ├── ldebug.c │ │ ├── ldebug.h │ │ ├── ldo.c │ │ ├── ldo.h │ │ ├── ldump.c │ │ ├── lfunc.c │ │ ├── lfunc.h │ │ ├── lgc.c │ │ ├── lgc.h │ │ ├── linit.c │ │ ├── liolib.c │ │ ├── llex.c │ │ ├── llex.h │ │ ├── llimits.h │ │ ├── lmathlib.c │ │ ├── lmem.c │ │ ├── lmem.h │ │ ├── loadlib.c │ │ ├── lobject.c │ │ ├── lobject.h │ │ ├── lopcodes.c │ │ ├── lopcodes.h │ │ ├── loslib.c │ │ ├── lparser.c │ │ ├── lparser.h │ │ ├── lstate.c │ │ ├── lstate.h │ │ ├── lstring.c │ │ ├── lstring.h │ │ ├── lstrlib.c │ │ ├── ltable.c │ │ ├── ltable.h │ │ ├── ltablib.c │ │ ├── ltm.c │ │ ├── ltm.h │ │ ├── lua.c │ │ ├── lua.h │ │ ├── lua.hpp │ │ ├── luac.c │ │ ├── luaconf.h │ │ ├── lualib.h │ │ ├── lundump.c │ │ ├── lundump.h │ │ ├── lvm.c │ │ ├── lvm.h │ │ ├── lzio.c │ │ └── lzio.h │ ├── lua53 │ │ ├── Makefile │ │ ├── lapi.c │ │ ├── lapi.h │ │ ├── lauxlib.c │ │ ├── lauxlib.h │ │ ├── lbaselib.c │ │ ├── lbitlib.c │ │ ├── lcode.c │ │ ├── lcode.h │ │ ├── lcorolib.c │ │ ├── lctype.c │ │ ├── lctype.h │ │ ├── ldblib.c │ │ ├── ldebug.c │ │ ├── ldebug.h │ │ ├── ldo.c │ │ ├── ldo.h │ │ ├── ldump.c │ │ ├── lfunc.c │ │ ├── lfunc.h │ │ ├── lgc.c │ │ ├── lgc.h │ │ ├── linit.c │ │ ├── liolib.c │ │ ├── llex.c │ │ ├── llex.h │ │ ├── llimits.h │ │ ├── lmathlib.c │ │ ├── lmem.c │ │ ├── lmem.h │ │ ├── loadlib.c │ │ ├── lobject.c │ │ ├── lobject.h │ │ ├── lopcodes.c │ │ ├── lopcodes.h │ │ ├── loslib.c │ │ ├── lparser.c │ │ ├── lparser.h │ │ ├── lprefix.h │ │ ├── lstate.c │ │ ├── lstate.h │ │ ├── lstring.c │ │ ├── lstring.h │ │ ├── lstrlib.c │ │ ├── ltable.c │ │ ├── ltable.h │ │ ├── ltablib.c │ │ ├── ltm.c │ │ ├── ltm.h │ │ ├── lua.c │ │ ├── lua.h │ │ ├── lua.hpp │ │ ├── luac.c │ │ ├── luaconf.h │ │ ├── lualib.h │ │ ├── lundump.c │ │ ├── lundump.h │ │ ├── lutf8lib.c │ │ ├── lvm.c │ │ ├── lvm.h │ │ ├── lzio.c │ │ └── lzio.h │ ├── lua54 │ │ ├── Makefile │ │ ├── lapi.c │ │ ├── lapi.h │ │ ├── lauxlib.c │ │ ├── lauxlib.h │ │ ├── lbaselib.c │ │ ├── lcode.c │ │ ├── lcode.h │ │ ├── lcorolib.c │ │ ├── lctype.c │ │ ├── lctype.h │ │ ├── ldblib.c │ │ ├── ldebug.c │ │ ├── ldebug.h │ │ ├── ldo.c │ │ ├── ldo.h │ │ ├── ldump.c │ │ ├── lfunc.c │ │ ├── lfunc.h │ │ ├── lgc.c │ │ ├── lgc.h │ │ ├── linit.c │ │ ├── liolib.c │ │ ├── ljumptab.h │ │ ├── llex.c │ │ ├── llex.h │ │ ├── llimits.h │ │ ├── lmathlib.c │ │ ├── lmem.c │ │ ├── lmem.h │ │ ├── loadlib.c │ │ ├── lobject.c │ │ ├── lobject.h │ │ ├── lopcodes.c │ │ ├── lopcodes.h │ │ ├── lopnames.h │ │ ├── loslib.c │ │ ├── lparser.c │ │ ├── lparser.h │ │ ├── lprefix.h │ │ ├── lstate.c │ │ ├── lstate.h │ │ ├── lstring.c │ │ ├── lstring.h │ │ ├── lstrlib.c │ │ ├── ltable.c │ │ ├── ltable.h │ │ ├── ltablib.c │ │ ├── ltm.c │ │ ├── ltm.h │ │ ├── lua.c │ │ ├── lua.h │ │ ├── lua.hpp │ │ ├── luac.c │ │ ├── luaconf.h │ │ ├── lualib.h │ │ ├── lundump.c │ │ ├── lundump.h │ │ ├── lutf8lib.c │ │ ├── lvm.c │ │ ├── lvm.h │ │ ├── lzio.c │ │ └── lzio.h │ └── luai_devent.h └── wow64ext │ ├── .gitignore │ ├── .hgignore │ ├── README.md │ ├── doc │ └── wow64ext.txt │ ├── lgpl-3.0.txt │ ├── sample │ ├── build.bat │ └── main.cpp │ └── src │ ├── CMemPtr.h │ ├── internal.h │ ├── resource.h │ ├── wow64ext.cpp │ ├── wow64ext.h │ ├── wow64ext.rc │ ├── wow64ext.sln │ └── wow64ext.vcxproj ├── LICENSE ├── README.md ├── compile ├── clang-format.lua ├── common │ ├── bee.lua │ ├── config.lua │ ├── detect_platform.lua │ ├── frida.lua │ ├── launcher.lua │ ├── lua-debug.lua │ ├── make.lua │ ├── package_json.lua │ ├── run_luamake.lua │ ├── runtime.lua │ └── write_json.lua ├── copy.lua ├── copy_extension.lua ├── download_deps.lua ├── linux │ ├── make.lua │ └── runtime.lua ├── luadbg │ ├── build.lua │ └── compile.lua ├── luajit │ ├── defined.lua │ ├── make.lua │ ├── make_buildtools.lua │ └── make_windows.lua ├── macos │ ├── export_shellcode.lua │ ├── make.lua │ ├── runtime.lua │ └── shellcode.lua ├── test │ └── make.lua └── windows │ ├── lua-debug.ico │ ├── lua-debug.rc │ ├── make.lua │ └── runtime.lua ├── docs ├── capabilities.md ├── debugProtocol.json ├── luadebug │ ├── README.md │ ├── hookmgr.lua │ ├── init.lua │ ├── stdio.lua │ ├── utility.lua │ └── visitor.lua └── ported.md ├── examples ├── attach │ ├── .vscode │ │ └── launch.json │ ├── README.md │ ├── debugger.lua │ └── test.lua ├── attach_thread │ ├── .vscode │ │ └── launch.json │ ├── README.md │ ├── debugger.lua │ ├── test.lua │ └── thread.lua └── standalone │ ├── .vscode │ └── launch.json │ ├── README.md │ ├── debugger.lua │ └── test.lua ├── extension ├── images │ └── logo.png ├── js │ ├── configurationProvider.js │ ├── descriptorFactory.js │ ├── extension.js │ ├── pickProcess.js │ └── trackerFactory.js ├── package.nls.json └── script │ ├── attach.lua │ ├── backend │ ├── bootstrap.lua │ ├── event.lua │ ├── master │ │ ├── event.lua │ │ ├── mgr.lua │ │ ├── request.lua │ │ ├── response.lua │ │ └── threads.lua │ ├── worker.lua │ └── worker │ │ ├── breakpoint.lua │ │ ├── crc32.lua │ │ ├── eval.lua │ │ ├── eval │ │ ├── ffi_reflect.lua │ │ ├── readonly.lua │ │ ├── readwrite.lua │ │ └── verify.lua │ │ ├── evaluate.lua │ │ ├── filesystem.lua │ │ ├── luaver.lua │ │ ├── parser.lua │ │ ├── serialize.lua │ │ ├── source.lua │ │ ├── stdout.lua │ │ ├── traceback.lua │ │ ├── undump.lua │ │ └── variables.lua │ ├── bootstrap.lua │ ├── common │ ├── base64.lua │ ├── capabilities.lua │ ├── ipc.lua │ ├── log.lua │ ├── net.lua │ ├── protocol.lua │ └── socket.lua │ ├── debugger.lua │ ├── frontend │ ├── debuger_factory.lua │ ├── main.lua │ ├── platform_os.lua │ ├── powershell.lua │ ├── process_inject.lua │ ├── proxy.lua │ ├── query_process.lua │ └── stdio.lua │ └── launch.lua ├── make.lua ├── src ├── launcher │ ├── autoattach │ │ ├── autoattach.cpp │ │ ├── autoattach.h │ │ ├── ctx.h │ │ ├── lua_module.cpp │ │ ├── lua_module.h │ │ ├── wait_dll.cpp │ │ └── wait_dll.h │ ├── hook │ │ ├── create_watchdog.cpp │ │ ├── create_watchdog.h │ │ ├── listener.cpp │ │ ├── listener.h │ │ ├── luajit_listener.cpp │ │ ├── luajit_listener.h │ │ ├── watch_point.cpp │ │ ├── watch_point.h │ │ ├── watchdog.cpp │ │ └── watchdog.h │ ├── main.cpp │ ├── resolver │ │ ├── lua_delayload.h │ │ ├── lua_funcname.h │ │ ├── lua_resolver.cpp │ │ └── lua_resolver.h │ └── util │ │ ├── bee_inline.cpp │ │ ├── log.cpp │ │ └── log.h ├── luadebug │ ├── compat │ │ ├── 5x │ │ │ ├── callinfo.cpp │ │ │ ├── common.cpp │ │ │ ├── mainthread.cpp │ │ │ ├── stacklevel.cpp │ │ │ └── table.cpp │ │ ├── internal.h │ │ ├── jit │ │ │ ├── callinfo.cpp │ │ │ ├── common.cpp │ │ │ ├── mainthread.cpp │ │ │ ├── stacklevel.cpp │ │ │ └── table.cpp │ │ ├── lua.h │ │ └── table.h │ ├── luadbg │ │ ├── bee_inline.cpp │ │ ├── bee_module.cpp │ │ ├── bee_module.h │ │ ├── inc │ │ │ └── .gitignore │ │ ├── lua.hpp │ │ └── onelua.c │ ├── rdebug_debughost.cpp │ ├── rdebug_debughost.h │ ├── rdebug_eventfree.cpp │ ├── rdebug_eventfree.h │ ├── rdebug_hookmgr.cpp │ ├── rdebug_init.cpp │ ├── rdebug_lua.h │ ├── rdebug_redirect.cpp │ ├── rdebug_redirect.h │ ├── rdebug_stdio.cpp │ ├── rdebug_utility.cpp │ ├── rdebug_visitor.cpp │ ├── rdebug_win32.cpp │ ├── rdebug_win32.h │ ├── symbolize │ │ ├── symbolize.cpp │ │ ├── symbolize.h │ │ ├── symbolize_linux.inl │ │ ├── symbolize_macos.inl │ │ └── symbolize_win32.inl │ ├── thunk │ │ ├── thunk.cpp │ │ ├── thunk.h │ │ ├── thunk_arm64.inl │ │ ├── thunk_jit.h │ │ ├── thunk_jit.inl │ │ ├── thunk_nojit.h │ │ ├── thunk_nojit.inl │ │ ├── thunk_posix.inl │ │ ├── thunk_posix_amd64.inl │ │ ├── thunk_windows.inl │ │ ├── thunk_windows_amd64.inl │ │ └── thunk_windows_i386.inl │ └── util │ │ ├── protected_area.h │ │ ├── refvalue.cpp │ │ ├── refvalue.h │ │ └── variant.h └── process_inject │ ├── .gitignore │ ├── macos │ ├── injectdll.cpp │ ├── injectdll.h │ ├── main.cpp │ ├── process_helper.mm │ └── shellcode.cpp │ └── windows │ ├── inject.cpp │ ├── injectdll.cpp │ └── injectdll.h ├── test.lua └── test ├── delayload.cpp ├── inject ├── inject_macos.lua └── launcher.cpp ├── interceptor.cpp ├── interceptor.lua ├── launcher.lua ├── load ├── test.cpp └── test_macos.lua ├── symbol ├── gum_symbol.c └── symbols.c ├── thunk.cpp ├── undump.lua ├── waitdll.cpp └── waitdll.lua /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | AccessModifierOffset: -4 3 | AlignAfterOpenBracket: BlockIndent 4 | AlignConsecutiveAssignments: 5 | Enabled: true 6 | BreakConstructorInitializers: BeforeComma 7 | BreakInheritanceList: BeforeComma 8 | ColumnLimit: 0 9 | Cpp11BracedListStyle: false 10 | FixNamespaceComments: false 11 | IndentCaseLabels: false 12 | IndentPPDirectives: AfterHash 13 | IndentWidth: 4 14 | NamespaceIndentation: All 15 | PackConstructorInitializers: Never 16 | QualifierAlignment: Left 17 | SpaceBeforeCpp11BracedList: true 18 | -------------------------------------------------------------------------------- /.clang-format-ignore: -------------------------------------------------------------------------------- 1 | 3rd/.* 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | 3rd/** linguist-vendored=true 2 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | branches: 8 | - master 9 | jobs: 10 | compile: 11 | runs-on: ${{ matrix.os }} 12 | strategy: 13 | fail-fast: false 14 | matrix: 15 | include: 16 | - os: windows-latest 17 | platform: win32-x64 18 | - os: ubuntu-22.04 19 | platform: linux-x64 20 | - os: ubuntu-22.04-arm 21 | platform: linux-arm64 22 | - os: macos-latest 23 | platform: darwin-x64 24 | - os: macos-latest 25 | platform: darwin-arm64 26 | steps: 27 | - uses: actions/checkout@v4 28 | with: 29 | submodules : recursive 30 | - uses: actboy168/setup-luamake@master 31 | - run: luamake lua compile/download_deps.lua 32 | - run: luamake -mode release -platform ${{ matrix.platform }} 33 | - run: npm install -g @vscode/vsce ovsx 34 | - run: npx vsce publish --target ${{ matrix.platform }} -p ${{ secrets.VSCE_KEY }} 35 | working-directory: publish 36 | continue-on-error: true 37 | - run: npx ovsx publish --target ${{ matrix.platform }} -p ${{ secrets.OVSX_KEY }} 38 | working-directory: publish 39 | continue-on-error: true 40 | -------------------------------------------------------------------------------- /.github/workflows/clang-format.yml: -------------------------------------------------------------------------------- 1 | name: clang-format 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | branches: 8 | - master 9 | jobs: 10 | clang-format: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - run: sudo apt-get install -y clang-format-15 15 | - run: find src -iname *.cpp -o -iname *.c -o -iname *.h -o -iname *.inl | xargs clang-format-15 --dry-run --Werror 16 | 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.vscode/ipch/ 2 | /.vscode/c_cpp_properties.json 3 | /.vs/ 4 | /publish/ 5 | /build/ 6 | /extension/package.json 7 | .DS_Store 8 | .idea/ -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "3rd/bee.lua"] 2 | path = 3rd/bee.lua 3 | url = https://github.com/actboy168/bee.lua.git 4 | [submodule "3rd/lua/luajit"] 5 | path = 3rd/lua/luajit 6 | url = https://github.com/fesily/luajit2 7 | [submodule "3rd/json.lua"] 8 | path = 3rd/json.lua 9 | url = https://github.com/actboy168/json.lua 10 | [submodule "3rd/frida_gum/gumpp"] 11 | path = 3rd/frida_gum/gumpp 12 | url = https://github.com/fesily/gumpp 13 | 14 | -------------------------------------------------------------------------------- /.luarc.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtime.version": "Lua 5.4", 3 | "workspace": { 4 | "ignoreDir": [ 5 | "extension/script/backend/worker/eval/ffi_reflect.lua" 6 | ] 7 | }, 8 | "diagnostics": { 9 | "globals": [ 10 | "loadstring", 11 | "unpack", 12 | "jit" 13 | ], 14 | "disable": [ 15 | "discard-returns", 16 | "undefined-field", 17 | "need-check-nil" 18 | ], 19 | "neededFileStatus": { 20 | "redefined-local": "Any", 21 | "unused-vararg": "Any", 22 | "unused-function": "Any", 23 | "unused-local": "Any", 24 | "unused-label": "Any", 25 | "code-after-break": "Any", 26 | "empty-block": "Any", 27 | "trailing-space": "Any" 28 | }, 29 | "severity": { 30 | "redefined-local": "Hint", 31 | "unused-vararg": "Warning", 32 | "unused-function": "Warning", 33 | "unused-local": "Warning", 34 | "unused-label": "Warning", 35 | "code-after-break": "Warning", 36 | "empty-block": "Warning", 37 | "trailing-space": "Warning" 38 | } 39 | }, 40 | "workspace.checkThirdParty": false 41 | } -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "actboy168.tasks", 4 | "actboy168.lua-debug" 5 | ] 6 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "lua", 6 | "request": "launch", 7 | "name": "Test Client", 8 | "console": "integratedTerminal", 9 | "luaVersion": "lua-latest", 10 | "windows": { 11 | "luaexe": "${extensionInstallFolder:actboy168.lua-debug}/bin/lua-debug.exe" 12 | }, 13 | "linux": { 14 | "luaexe": "${extensionInstallFolder:actboy168.lua-debug}/bin/lua-debug", 15 | }, 16 | "osx": { 17 | "luaexe": "${extensionInstallFolder:actboy168.lua-debug}/bin/lua-debug", 18 | }, 19 | "outputCapture": [ 20 | ], 21 | "program": "", 22 | "path": null, 23 | "cpath": null, 24 | "arg": [ 25 | "4711" 26 | ] 27 | }, 28 | { 29 | "type": "extensionHost", 30 | "request": "launch", 31 | "name": "Test Extension", 32 | "runtimeExecutable": "${execPath}", 33 | "args": [ 34 | "--extensionDevelopmentPath=${workspaceFolder}/extension/" 35 | ], 36 | "env": { 37 | "VSCODE_EXTENSION_PATH" : "${extensionInstallFolder:actboy168.lua-debug}" 38 | } 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp.autoAddFileAssociations": false, 3 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "type": "shell", 6 | "windows": { 7 | "options": { 8 | "shell": { 9 | "executable": "C:\\Windows\\System32\\cmd.exe", 10 | "args": [ 11 | "/c" 12 | ] 13 | } 14 | } 15 | }, 16 | "options": { 17 | "cwd": "${workspaceFolder}" 18 | }, 19 | "tasks": [ 20 | { 21 | "label": "Clang Format", 22 | "command": "luamake", 23 | "args": [ 24 | "lua", 25 | "compile/clang-format.lua", 26 | ] 27 | }, 28 | { 29 | "label": "Copy Extension", 30 | "command": "luamake", 31 | "args": [ 32 | "lua", 33 | "compile/copy.lua", 34 | "extension", 35 | "${extensionInstallFolder:actboy168.lua-debug}" 36 | ] 37 | }, 38 | { 39 | "label": "Copy Publish", 40 | "command": "luamake", 41 | "args": [ 42 | "lua", 43 | "compile/copy.lua", 44 | "publish", 45 | "${extensionInstallFolder:actboy168.lua-debug}" 46 | ] 47 | } 48 | ] 49 | } -------------------------------------------------------------------------------- /3rd/frida_gum/.gitignore: -------------------------------------------------------------------------------- 1 | *.c 2 | !gumpp/internal/*.c 3 | *.sln 4 | *.vcxproj 5 | *.vcxproj.filters 6 | *.user 7 | *.tar.xz 8 | *.exe 9 | *.a 10 | *.h 11 | *.lib -------------------------------------------------------------------------------- /3rd/lua/lua-latest/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | 15 | /* Increments 'L->top.p', checking for stack overflows */ 16 | #define api_incr_top(L) {L->top.p++; \ 17 | api_check(L, L->top.p <= L->ci->top.p, \ 18 | "stack overflow");} 19 | 20 | 21 | /* 22 | ** If a call returns too many multiple returns, the callee may not have 23 | ** stack space to accommodate all results. In this case, this macro 24 | ** increases its stack space ('L->ci->top.p'). 25 | */ 26 | #define adjustresults(L,nres) \ 27 | { if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \ 28 | L->ci->top.p = L->top.p; } 29 | 30 | 31 | /* Ensure the stack has at least 'n' elements */ 32 | #define api_checknelems(L,n) \ 33 | api_check(L, (n) < (L->top.p - L->ci->func.p), \ 34 | "not enough elements in the stack") 35 | 36 | 37 | /* 38 | ** To reduce the overhead of returning from C functions, the presence of 39 | ** to-be-closed variables in these functions is coded in the CallInfo's 40 | ** field 'nresults', in a way that functions with no to-be-closed variables 41 | ** with zero, one, or "all" wanted results have no overhead. Functions 42 | ** with other number of wanted results, as well as functions with 43 | ** variables to be closed, have an extra check. 44 | */ 45 | 46 | #define hastocloseCfunc(n) ((n) < LUA_MULTRET) 47 | 48 | /* Map [-1, inf) (range of 'nresults') into (-inf, -2] */ 49 | #define codeNresults(n) (-(n) - 3) 50 | #define decodeNresults(n) (-(n) - 3) 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /3rd/lua/lua-latest/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast_int(offsetof(CClosure, upvalue)) + \ 15 | cast_int(sizeof(TValue)) * (n)) 16 | 17 | #define sizeLclosure(n) (cast_int(offsetof(LClosure, upvals)) + \ 18 | cast_int(sizeof(TValue *)) * (n)) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | #define upisopen(up) ((up)->v.p != &(up)->u.value) 33 | 34 | 35 | #define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v.p)) 36 | 37 | 38 | /* 39 | ** maximum number of misses before giving up the cache of closures 40 | ** in prototypes 41 | */ 42 | #define MAXMISS 10 43 | 44 | 45 | 46 | /* special status to close upvalues preserving the top of the stack */ 47 | #define CLOSEKTOP (-1) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nupvals); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nupvals); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level); 57 | LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy); 58 | LUAI_FUNC void luaF_unlinkupval (UpVal *uv); 59 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 60 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 61 | int pc); 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /3rd/lua/lua-latest/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {LUA_GNAME, luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | {NULL, NULL} 54 | }; 55 | 56 | 57 | LUALIB_API void luaL_openlibs (lua_State *L) { 58 | const luaL_Reg *lib; 59 | /* "require" functions from 'loadedlibs' and set results to global table */ 60 | for (lib = loadedlibs; lib->func; lib++) { 61 | luaL_requiref(L, lib->name, lib->func, 1); 62 | lua_pop(L, 1); /* remove lib */ 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /3rd/lua/lua-latest/lopnames.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopnames.h $ 3 | ** Opcode names 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #if !defined(lopnames_h) 8 | #define lopnames_h 9 | 10 | #include 11 | 12 | 13 | /* ORDER OP */ 14 | 15 | static const char *const opnames[] = { 16 | "MOVE", 17 | "LOADI", 18 | "LOADF", 19 | "LOADK", 20 | "LOADKX", 21 | "LOADFALSE", 22 | "LFALSESKIP", 23 | "LOADTRUE", 24 | "LOADNIL", 25 | "GETUPVAL", 26 | "SETUPVAL", 27 | "GETTABUP", 28 | "GETTABLE", 29 | "GETI", 30 | "GETFIELD", 31 | "SETTABUP", 32 | "SETTABLE", 33 | "SETI", 34 | "SETFIELD", 35 | "NEWTABLE", 36 | "SELF", 37 | "ADDI", 38 | "ADDK", 39 | "SUBK", 40 | "MULK", 41 | "MODK", 42 | "POWK", 43 | "DIVK", 44 | "IDIVK", 45 | "BANDK", 46 | "BORK", 47 | "BXORK", 48 | "SHRI", 49 | "SHLI", 50 | "ADD", 51 | "SUB", 52 | "MUL", 53 | "MOD", 54 | "POW", 55 | "DIV", 56 | "IDIV", 57 | "BAND", 58 | "BOR", 59 | "BXOR", 60 | "SHL", 61 | "SHR", 62 | "MMBIN", 63 | "MMBINI", 64 | "MMBINK", 65 | "UNM", 66 | "BNOT", 67 | "NOT", 68 | "LEN", 69 | "CONCAT", 70 | "CLOSE", 71 | "TBC", 72 | "JMP", 73 | "EQ", 74 | "LT", 75 | "LE", 76 | "EQK", 77 | "EQI", 78 | "LTI", 79 | "LEI", 80 | "GTI", 81 | "GEI", 82 | "TEST", 83 | "TESTSET", 84 | "CALL", 85 | "TAILCALL", 86 | "RETURN", 87 | "RETURN0", 88 | "RETURN1", 89 | "FORLOOP", 90 | "FORPREP", 91 | "TFORPREP", 92 | "TFORCALL", 93 | "TFORLOOP", 94 | "SETLIST", 95 | "CLOSURE", 96 | "VARARG", 97 | "VARARGPREP", 98 | "EXTRAARG", 99 | NULL 100 | }; 101 | 102 | #endif 103 | 104 | -------------------------------------------------------------------------------- /3rd/lua/lua-latest/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #include "luai_devent.h" 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /3rd/lua/lua-latest/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | /* 16 | ** Memory-allocation error message must be preallocated (it cannot 17 | ** be created after memory is exhausted) 18 | */ 19 | #define MEMERRMSG "not enough memory" 20 | 21 | 22 | /* 23 | ** Size of a TString: Size of the header plus space for the string 24 | ** itself (including final '\0'). 25 | */ 26 | #define sizelstring(l) (offsetof(TString, contents) + ((l) + 1) * sizeof(char)) 27 | 28 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 29 | (sizeof(s)/sizeof(char))-1)) 30 | 31 | 32 | /* 33 | ** test whether a string is a reserved word 34 | */ 35 | #define isreserved(s) ((s)->tt == LUA_VSHRSTR && (s)->extra > 0) 36 | 37 | 38 | /* 39 | ** equality for short strings, which are always internalized 40 | */ 41 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_VSHRSTR, (a) == (b)) 42 | 43 | 44 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 45 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 46 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 47 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 48 | LUAI_FUNC void luaS_clearcache (global_State *g); 49 | LUAI_FUNC void luaS_init (lua_State *L); 50 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 51 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue); 52 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 53 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 54 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /3rd/lua/lua-latest/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /3rd/lua/lua-latest/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* version suffix for environment variable names */ 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR 16 | 17 | 18 | LUAMOD_API int (luaopen_base) (lua_State *L); 19 | 20 | #define LUA_COLIBNAME "coroutine" 21 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 22 | 23 | #define LUA_TABLIBNAME "table" 24 | LUAMOD_API int (luaopen_table) (lua_State *L); 25 | 26 | #define LUA_IOLIBNAME "io" 27 | LUAMOD_API int (luaopen_io) (lua_State *L); 28 | 29 | #define LUA_OSLIBNAME "os" 30 | LUAMOD_API int (luaopen_os) (lua_State *L); 31 | 32 | #define LUA_STRLIBNAME "string" 33 | LUAMOD_API int (luaopen_string) (lua_State *L); 34 | 35 | #define LUA_UTF8LIBNAME "utf8" 36 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 37 | 38 | #define LUA_MATHLIBNAME "math" 39 | LUAMOD_API int (luaopen_math) (lua_State *L); 40 | 41 | #define LUA_DBLIBNAME "debug" 42 | LUAMOD_API int (luaopen_debug) (lua_State *L); 43 | 44 | #define LUA_LOADLIBNAME "package" 45 | LUAMOD_API int (luaopen_package) (lua_State *L); 46 | 47 | 48 | /* open all previous libraries */ 49 | LUALIB_API void (luaL_openlibs) (lua_State *L); 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /3rd/lua/lua-latest/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | /* 22 | ** Encode major-minor version in one byte, one nibble for each 23 | */ 24 | #define LUAC_VERSION (((LUA_VERSION_NUM / 100) * 16) + LUA_VERSION_NUM % 100) 25 | 26 | #define LUAC_FORMAT 0 /* this is the official format */ 27 | 28 | /* load one chunk; from lundump.c */ 29 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 30 | 31 | /* dump one chunk; from ldump.c */ 32 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 33 | void* data, int strip); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /3rd/lua/lua-latest/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /3rd/lua/lua-latest/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /3rd/lua/lua51/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /3rd/lua/lua51/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, 22 | const char *opname); 23 | LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); 24 | LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, 25 | const TValue *p2); 26 | LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, 27 | const TValue *p2); 28 | LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); 29 | LUAI_FUNC void luaG_errormsg (lua_State *L); 30 | LUAI_FUNC int luaG_checkcode (const Proto *pt); 31 | LUAI_FUNC int luaG_checkopenop (Instruction i); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /3rd/lua/lua51/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | #define luaD_checkstack(L,n) \ 17 | if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ 18 | luaD_growstack(L, n); \ 19 | else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); 20 | 21 | 22 | #define incr_top(L) {luaD_checkstack(L,1); L->top++;} 23 | 24 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 25 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 26 | 27 | #define saveci(L,p) ((char *)(p) - (char *)L->base_ci) 28 | #define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) 29 | 30 | 31 | /* results from luaD_precall */ 32 | #define PCRLUA 0 /* initiated a call to a Lua function */ 33 | #define PCRC 1 /* did a call to a C function */ 34 | #define PCRYIELD 2 /* C funtion yielded */ 35 | 36 | 37 | /* type of protected functions, to be ran by `runprotected' */ 38 | typedef void (*Pfunc) (lua_State *L, void *ud); 39 | 40 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); 41 | LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); 42 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 43 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 44 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 45 | ptrdiff_t oldtop, ptrdiff_t ef); 46 | LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); 47 | LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); 48 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 49 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 50 | 51 | LUAI_FUNC void luaD_throw (lua_State *L, int errcode); 52 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 53 | 54 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /3rd/lua/lua51/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 22 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); 23 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); 24 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L); 25 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 26 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 27 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 28 | LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); 29 | LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); 30 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 31 | int pc); 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /3rd/lua/lua51/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Initialization of libraries for lua.c 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | #include "lua.h" 12 | 13 | #include "lualib.h" 14 | #include "lauxlib.h" 15 | 16 | 17 | static const luaL_Reg lualibs[] = { 18 | {"", luaopen_base}, 19 | {LUA_LOADLIBNAME, luaopen_package}, 20 | {LUA_TABLIBNAME, luaopen_table}, 21 | {LUA_IOLIBNAME, luaopen_io}, 22 | {LUA_OSLIBNAME, luaopen_os}, 23 | {LUA_STRLIBNAME, luaopen_string}, 24 | {LUA_MATHLIBNAME, luaopen_math}, 25 | {LUA_DBLIBNAME, luaopen_debug}, 26 | {NULL, NULL} 27 | }; 28 | 29 | 30 | LUALIB_API void luaL_openlibs (lua_State *L) { 31 | const luaL_Reg *lib = lualibs; 32 | for (; lib->func; lib++) { 33 | lua_pushcfunction(L, lib->func); 34 | lua_pushstring(L, lib->name); 35 | lua_call(L, 1, 0); 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /3rd/lua/lua51/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | #define MEMERRMSG "not enough memory" 17 | 18 | 19 | #define luaM_reallocv(L,b,on,n,e) \ 20 | ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ 21 | luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ 22 | luaM_toobig(L)) 23 | 24 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 25 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 26 | #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) 27 | 28 | #define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) 29 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 30 | #define luaM_newvector(L,n,t) \ 31 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 32 | 33 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 34 | if ((nelems)+1 > (size)) \ 35 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 36 | 37 | #define luaM_reallocvector(L, v,oldn,n,t) \ 38 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 39 | 40 | 41 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 42 | size_t size); 43 | LUAI_FUNC void *luaM_toobig (lua_State *L); 44 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 45 | size_t size_elem, int limit, 46 | const char *errormsg); 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /3rd/lua/lua51/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | 11 | #include "lgc.h" 12 | #include "lobject.h" 13 | #include "lstate.h" 14 | 15 | 16 | #define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) 17 | 18 | #define sizeudata(u) (sizeof(union Udata)+(u)->len) 19 | 20 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) 21 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 22 | (sizeof(s)/sizeof(char))-1)) 23 | 24 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) 25 | 26 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 27 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); 28 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /3rd/lua/lua51/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gkey(n) (&(n)->i_key.nk) 15 | #define gval(n) (&(n)->i_val) 16 | #define gnext(n) ((n)->i_key.nk.next) 17 | 18 | #define key2tval(n) (&(n)->i_key.tvk) 19 | 20 | 21 | LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); 22 | LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); 23 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 24 | LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); 25 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 26 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 27 | LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); 28 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); 29 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 30 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 31 | LUAI_FUNC int luaH_getn (Table *t); 32 | 33 | 34 | #if defined(LUA_DEBUG) 35 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 36 | LUAI_FUNC int luaH_isdummy (Node *n); 37 | #endif 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /3rd/lua/lua51/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define ltm_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "lobject.h" 16 | #include "lstate.h" 17 | #include "lstring.h" 18 | #include "ltable.h" 19 | #include "ltm.h" 20 | 21 | 22 | 23 | const char *const luaT_typenames[] = { 24 | "nil", "boolean", "userdata", "number", 25 | "string", "table", "function", "userdata", "thread", 26 | "proto", "upval" 27 | }; 28 | 29 | 30 | void luaT_init (lua_State *L) { 31 | static const char *const luaT_eventname[] = { /* ORDER TM */ 32 | "__index", "__newindex", 33 | "__gc", "__mode", "__eq", 34 | "__add", "__sub", "__mul", "__div", "__mod", 35 | "__pow", "__unm", "__len", "__lt", "__le", 36 | "__concat", "__call" 37 | }; 38 | int i; 39 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); 41 | luaS_fix(G(L)->tmname[i]); /* never collect these names */ 42 | } 43 | } 44 | 45 | 46 | /* 47 | ** function to be used with macro "fasttm": optimized for absence of 48 | ** tag methods 49 | */ 50 | const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { 51 | const TValue *tm = luaH_getstr(events, ename); 52 | lua_assert(event <= TM_EQ); 53 | if (ttisnil(tm)) { /* no tag method? */ 54 | events->flags |= cast_byte(1u<metatable; 66 | break; 67 | case LUA_TUSERDATA: 68 | mt = uvalue(o)->metatable; 69 | break; 70 | default: 71 | mt = G(L)->mt[ttype(o)]; 72 | } 73 | return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); 74 | } 75 | 76 | -------------------------------------------------------------------------------- /3rd/lua/lua51/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_EQ, /* last tag method with `fast' access */ 24 | TM_ADD, 25 | TM_SUB, 26 | TM_MUL, 27 | TM_DIV, 28 | TM_MOD, 29 | TM_POW, 30 | TM_UNM, 31 | TM_LEN, 32 | TM_LT, 33 | TM_LE, 34 | TM_CONCAT, 35 | TM_CALL, 36 | TM_N /* number of elements in the enum */ 37 | } TMS; 38 | 39 | 40 | 41 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 42 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 43 | 44 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 45 | 46 | LUAI_DATA const char *const luaT_typenames[]; 47 | 48 | 49 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 50 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 51 | TMS event); 52 | LUAI_FUNC void luaT_init (lua_State *L); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /3rd/lua/lua51/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /3rd/lua/lua51/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* Key to file-handle type */ 15 | #define LUA_FILEHANDLE "FILE*" 16 | 17 | 18 | #define LUA_COLIBNAME "coroutine" 19 | LUALIB_API int (luaopen_base) (lua_State *L); 20 | 21 | #define LUA_TABLIBNAME "table" 22 | LUALIB_API int (luaopen_table) (lua_State *L); 23 | 24 | #define LUA_IOLIBNAME "io" 25 | LUALIB_API int (luaopen_io) (lua_State *L); 26 | 27 | #define LUA_OSLIBNAME "os" 28 | LUALIB_API int (luaopen_os) (lua_State *L); 29 | 30 | #define LUA_STRLIBNAME "string" 31 | LUALIB_API int (luaopen_string) (lua_State *L); 32 | 33 | #define LUA_MATHLIBNAME "math" 34 | LUALIB_API int (luaopen_math) (lua_State *L); 35 | 36 | #define LUA_DBLIBNAME "debug" 37 | LUALIB_API int (luaopen_debug) (lua_State *L); 38 | 39 | #define LUA_LOADLIBNAME "package" 40 | LUALIB_API int (luaopen_package) (lua_State *L); 41 | 42 | 43 | /* open all previous libraries */ 44 | LUALIB_API void (luaL_openlibs) (lua_State *L); 45 | 46 | 47 | 48 | #ifndef lua_assert 49 | #define lua_assert(x) ((void)0) 50 | #endif 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /3rd/lua/lua51/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | /* load one chunk; from lundump.c */ 14 | LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); 15 | 16 | /* make header; from lundump.c */ 17 | LUAI_FUNC void luaU_header (char* h); 18 | 19 | /* dump one chunk; from ldump.c */ 20 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); 21 | 22 | #ifdef luac_c 23 | /* print one chunk; from print.c */ 24 | LUAI_FUNC void luaU_print (const Proto* f, int full); 25 | #endif 26 | 27 | /* for header of binary files -- this is Lua 5.1 */ 28 | #define LUAC_VERSION 0x51 29 | 30 | /* for header of binary files -- this is the official format */ 31 | #define LUAC_FORMAT 0 32 | 33 | /* size of header of binary files */ 34 | #define LUAC_HEADERSIZE 12 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /3rd/lua/lua51/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) 17 | 18 | #define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ 19 | (((o) = luaV_tonumber(o,n)) != NULL)) 20 | 21 | #define equalobj(L,o1,o2) \ 22 | (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) 23 | 24 | 25 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 26 | LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); 27 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); 28 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); 29 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 30 | StkId val); 31 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 32 | StkId val); 33 | LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); 34 | LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /3rd/lua/lua51/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** a generic input stream interface 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lzio_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "llimits.h" 16 | #include "lmem.h" 17 | #include "lstate.h" 18 | #include "lzio.h" 19 | 20 | 21 | int luaZ_fill (ZIO *z) { 22 | size_t size; 23 | lua_State *L = z->L; 24 | const char *buff; 25 | lua_unlock(L); 26 | buff = z->reader(L, z->data, &size); 27 | lua_lock(L); 28 | if (buff == NULL || size == 0) return EOZ; 29 | z->n = size - 1; 30 | z->p = buff; 31 | return char2int(*(z->p++)); 32 | } 33 | 34 | 35 | int luaZ_lookahead (ZIO *z) { 36 | if (z->n == 0) { 37 | if (luaZ_fill(z) == EOZ) 38 | return EOZ; 39 | else { 40 | z->n++; /* luaZ_fill removed first byte; put back it */ 41 | z->p--; 42 | } 43 | } 44 | return char2int(*z->p); 45 | } 46 | 47 | 48 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 49 | z->L = L; 50 | z->reader = reader; 51 | z->data = data; 52 | z->n = 0; 53 | z->p = NULL; 54 | } 55 | 56 | 57 | /* --------------------------------------------------------------- read --- */ 58 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 59 | while (n) { 60 | size_t m; 61 | if (luaZ_lookahead(z) == EOZ) 62 | return n; /* return number of missing bytes */ 63 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 64 | memcpy(b, z->p, m); 65 | z->n -= m; 66 | z->p += m; 67 | b = (char *)b + m; 68 | n -= m; 69 | } 70 | return 0; 71 | } 72 | 73 | /* ------------------------------------------------------------------------ */ 74 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { 75 | if (n > buff->buffsize) { 76 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; 77 | luaZ_resizebuffer(L, buff, n); 78 | } 79 | return buff->buffer; 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /3rd/lua/lua51/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define char2int(c) cast(int, cast(unsigned char, (c))) 21 | 22 | #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) 23 | 24 | typedef struct Mbuffer { 25 | char *buffer; 26 | size_t n; 27 | size_t buffsize; 28 | } Mbuffer; 29 | 30 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 31 | 32 | #define luaZ_buffer(buff) ((buff)->buffer) 33 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 34 | #define luaZ_bufflen(buff) ((buff)->n) 35 | 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ 41 | (buff)->buffsize = size) 42 | 43 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 44 | 45 | 46 | LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ 50 | LUAI_FUNC int luaZ_lookahead (ZIO *z); 51 | 52 | 53 | 54 | /* --------- Private Part ------------------ */ 55 | 56 | struct Zio { 57 | size_t n; /* bytes still unread */ 58 | const char *p; /* current position in buffer */ 59 | lua_Reader reader; 60 | void* data; /* additional data */ 61 | lua_State *L; /* Lua state (for reader) */ 62 | }; 63 | 64 | 65 | LUAI_FUNC int luaZ_fill (ZIO *z); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /3rd/lua/lua52/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.7.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /3rd/lua/lua52/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.7.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | /* Active Lua function (given call info) */ 21 | #define ci_func(ci) (clLvalue((ci)->func)) 22 | 23 | 24 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 25 | const char *opname); 26 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, StkId p1, StkId p2); 27 | LUAI_FUNC l_noret luaG_aritherror (lua_State *L, const TValue *p1, 28 | const TValue *p2); 29 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 30 | const TValue *p2); 31 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 32 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /3rd/lua/lua52/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.20.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | #define luaD_checkstack(L,n) if (L->stack_last - L->top <= (n)) \ 17 | luaD_growstack(L, n); else condmovestack(L); 18 | 19 | 20 | #define incr_top(L) {L->top++; luaD_checkstack(L,0);} 21 | 22 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 23 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 24 | 25 | 26 | /* type of protected functions, to be ran by `runprotected' */ 27 | typedef void (*Pfunc) (lua_State *L, void *ud); 28 | 29 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 30 | const char *mode); 31 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); 32 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 33 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults, 34 | int allowyield); 35 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 36 | ptrdiff_t oldtop, ptrdiff_t ef); 37 | LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); 38 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 39 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 40 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 41 | 42 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 43 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /3rd/lua/lua52/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.8.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 22 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems); 23 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems); 24 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L); 25 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 26 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 27 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 28 | LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); 29 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 30 | int pc); 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /3rd/lua/lua52/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.32.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | /* 9 | ** If you embed Lua in your program and need to open the standard 10 | ** libraries, call luaL_openlibs in your program. If you need a 11 | ** different set of libraries, copy this file to your project and edit 12 | ** it to suit your needs. 13 | */ 14 | 15 | 16 | #define linit_c 17 | #define LUA_LIB 18 | 19 | #include "lua.h" 20 | 21 | #include "lualib.h" 22 | #include "lauxlib.h" 23 | 24 | 25 | /* 26 | ** these libs are loaded by lua.c and are readily available to any Lua 27 | ** program 28 | */ 29 | static const luaL_Reg loadedlibs[] = { 30 | {"_G", luaopen_base}, 31 | {LUA_LOADLIBNAME, luaopen_package}, 32 | {LUA_COLIBNAME, luaopen_coroutine}, 33 | {LUA_TABLIBNAME, luaopen_table}, 34 | {LUA_IOLIBNAME, luaopen_io}, 35 | {LUA_OSLIBNAME, luaopen_os}, 36 | {LUA_STRLIBNAME, luaopen_string}, 37 | {LUA_BITLIBNAME, luaopen_bit32}, 38 | {LUA_MATHLIBNAME, luaopen_math}, 39 | {LUA_DBLIBNAME, luaopen_debug}, 40 | {NULL, NULL} 41 | }; 42 | 43 | 44 | /* 45 | ** these libs are preloaded and must be required before used 46 | */ 47 | static const luaL_Reg preloadedlibs[] = { 48 | {NULL, NULL} 49 | }; 50 | 51 | 52 | LUALIB_API void luaL_openlibs (lua_State *L) { 53 | const luaL_Reg *lib; 54 | /* call open functions from 'loadedlibs' and set results to global table */ 55 | for (lib = loadedlibs; lib->func; lib++) { 56 | luaL_requiref(L, lib->name, lib->func, 1); 57 | lua_pop(L, 1); /* remove lib */ 58 | } 59 | /* add open functions from 'preloadedlibs' into 'package.preload' table */ 60 | luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); 61 | for (lib = preloadedlibs; lib->func; lib++) { 62 | lua_pushcfunction(L, lib->func); 63 | lua_setfield(L, -2, lib->name); 64 | } 65 | lua_pop(L, 1); /* remove _PRELOAD table */ 66 | } 67 | 68 | -------------------------------------------------------------------------------- /3rd/lua/lua52/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.40.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | 17 | /* 18 | ** This macro avoids the runtime division MAX_SIZET/(e), as 'e' is 19 | ** always constant. 20 | ** The macro is somewhat complex to avoid warnings: 21 | ** +1 avoids warnings of "comparison has constant result"; 22 | ** cast to 'void' avoids warnings of "value unused". 23 | */ 24 | #define luaM_reallocv(L,b,on,n,e) \ 25 | (cast(void, \ 26 | (cast(size_t, (n)+1) > MAX_SIZET/(e)) ? (luaM_toobig(L), 0) : 0), \ 27 | luaM_realloc_(L, (b), (on)*(e), (n)*(e))) 28 | 29 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 30 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 31 | #define luaM_freearray(L, b, n) luaM_reallocv(L, (b), n, 0, sizeof((b)[0])) 32 | 33 | #define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s)) 34 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 35 | #define luaM_newvector(L,n,t) \ 36 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 37 | 38 | #define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s)) 39 | 40 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 41 | if ((nelems)+1 > (size)) \ 42 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 43 | 44 | #define luaM_reallocvector(L, v,oldn,n,t) \ 45 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 46 | 47 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 48 | 49 | /* not to be called directly */ 50 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 51 | size_t size); 52 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 53 | size_t size_elem, int limit, 54 | const char *what); 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /3rd/lua/lua52/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.49.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | #define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) 16 | 17 | #define sizeudata(u) (sizeof(union Udata)+(u)->len) 18 | 19 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 20 | (sizeof(s)/sizeof(char))-1)) 21 | 22 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) 23 | 24 | 25 | /* 26 | ** test whether a string is a reserved word 27 | */ 28 | #define isreserved(s) ((s)->tsv.tt == LUA_TSHRSTR && (s)->tsv.extra > 0) 29 | 30 | 31 | /* 32 | ** equality for short strings, which are always internalized 33 | */ 34 | #define eqshrstr(a,b) check_exp((a)->tsv.tt == LUA_TSHRSTR, (a) == (b)) 35 | 36 | 37 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 38 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 39 | LUAI_FUNC int luaS_eqstr (TString *a, TString *b); 40 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 41 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); 42 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 43 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /3rd/lua/lua52/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.16.1.2 2013/08/30 15:49:41 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gkey(n) (&(n)->i_key.tvk) 15 | #define gval(n) (&(n)->i_val) 16 | #define gnext(n) ((n)->i_key.nk.next) 17 | 18 | #define invalidateTMcache(t) ((t)->flags = 0) 19 | 20 | /* returns the key, given the value of a table entry */ 21 | #define keyfromval(v) \ 22 | (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val)))) 23 | 24 | 25 | LUAI_FUNC const TValue *luaH_getint (Table *t, int key); 26 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, int key, TValue *value); 27 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 28 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 29 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 30 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 31 | LUAI_FUNC Table *luaH_new (lua_State *L); 32 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize); 33 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); 34 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 35 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 36 | LUAI_FUNC int luaH_getn (Table *t); 37 | 38 | 39 | #if defined(LUA_DEBUG) 40 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 41 | LUAI_FUNC int luaH_isdummy (Node *n); 42 | #endif 43 | 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /3rd/lua/lua52/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.11.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with `fast' access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_DIV, 29 | TM_MOD, 30 | TM_POW, 31 | TM_UNM, 32 | TM_LT, 33 | TM_LE, 34 | TM_CONCAT, 35 | TM_CALL, 36 | TM_N /* number of elements in the enum */ 37 | } TMS; 38 | 39 | 40 | 41 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 42 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 43 | 44 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 45 | 46 | #define ttypename(x) luaT_typenames_[(x) + 1] 47 | #define objtypename(x) ttypename(ttypenv(x)) 48 | 49 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; 50 | 51 | 52 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 53 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 54 | TMS event); 55 | LUAI_FUNC void luaT_init (lua_State *L); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /3rd/lua/lua52/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /3rd/lua/lua52/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.43.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | 15 | LUAMOD_API int (luaopen_base) (lua_State *L); 16 | 17 | #define LUA_COLIBNAME "coroutine" 18 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 19 | 20 | #define LUA_TABLIBNAME "table" 21 | LUAMOD_API int (luaopen_table) (lua_State *L); 22 | 23 | #define LUA_IOLIBNAME "io" 24 | LUAMOD_API int (luaopen_io) (lua_State *L); 25 | 26 | #define LUA_OSLIBNAME "os" 27 | LUAMOD_API int (luaopen_os) (lua_State *L); 28 | 29 | #define LUA_STRLIBNAME "string" 30 | LUAMOD_API int (luaopen_string) (lua_State *L); 31 | 32 | #define LUA_BITLIBNAME "bit32" 33 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 34 | 35 | #define LUA_MATHLIBNAME "math" 36 | LUAMOD_API int (luaopen_math) (lua_State *L); 37 | 38 | #define LUA_DBLIBNAME "debug" 39 | LUAMOD_API int (luaopen_debug) (lua_State *L); 40 | 41 | #define LUA_LOADLIBNAME "package" 42 | LUAMOD_API int (luaopen_package) (lua_State *L); 43 | 44 | 45 | /* open all previous libraries */ 46 | LUALIB_API void (luaL_openlibs) (lua_State *L); 47 | 48 | 49 | 50 | #if !defined(lua_assert) 51 | #define lua_assert(x) ((void)0) 52 | #endif 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /3rd/lua/lua52/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.39.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | /* load one chunk; from lundump.c */ 14 | LUAI_FUNC Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); 15 | 16 | /* make header; from lundump.c */ 17 | LUAI_FUNC void luaU_header (lu_byte* h); 18 | 19 | /* dump one chunk; from ldump.c */ 20 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); 21 | 22 | /* data to catch conversion errors */ 23 | #define LUAC_TAIL "\x19\x93\r\n\x1a\n" 24 | 25 | /* size in bytes of header of binary files */ 26 | #define LUAC_HEADERSIZE (sizeof(LUA_SIGNATURE)-sizeof(char)+2+6+sizeof(LUAC_TAIL)-sizeof(char)) 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /3rd/lua/lua52/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.18.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #define tostring(L,o) (ttisstring(o) || (luaV_tostring(L, o))) 17 | 18 | #define tonumber(o,n) (ttisnumber(o) || (((o) = luaV_tonumber(o,n)) != NULL)) 19 | 20 | #define equalobj(L,o1,o2) (ttisequal(o1, o2) && luaV_equalobj_(L, o1, o2)) 21 | 22 | #define luaV_rawequalobj(o1,o2) equalobj(NULL,o1,o2) 23 | 24 | 25 | /* not to called directly */ 26 | LUAI_FUNC int luaV_equalobj_ (lua_State *L, const TValue *t1, const TValue *t2); 27 | 28 | 29 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 30 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 31 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); 32 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); 33 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 34 | StkId val); 35 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 36 | StkId val); 37 | LUAI_FUNC void luaV_finishOp (lua_State *L); 38 | LUAI_FUNC void luaV_execute (lua_State *L); 39 | LUAI_FUNC void luaV_concat (lua_State *L, int total); 40 | LUAI_FUNC void luaV_arith (lua_State *L, StkId ra, const TValue *rb, 41 | const TValue *rc, TMS op); 42 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /3rd/lua/lua52/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.35.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lzio_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "llimits.h" 16 | #include "lmem.h" 17 | #include "lstate.h" 18 | #include "lzio.h" 19 | 20 | 21 | int luaZ_fill (ZIO *z) { 22 | size_t size; 23 | lua_State *L = z->L; 24 | const char *buff; 25 | lua_unlock(L); 26 | buff = z->reader(L, z->data, &size); 27 | lua_lock(L); 28 | if (buff == NULL || size == 0) 29 | return EOZ; 30 | z->n = size - 1; /* discount char being returned */ 31 | z->p = buff; 32 | return cast_uchar(*(z->p++)); 33 | } 34 | 35 | 36 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 37 | z->L = L; 38 | z->reader = reader; 39 | z->data = data; 40 | z->n = 0; 41 | z->p = NULL; 42 | } 43 | 44 | 45 | /* --------------------------------------------------------------- read --- */ 46 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 47 | while (n) { 48 | size_t m; 49 | if (z->n == 0) { /* no bytes in buffer? */ 50 | if (luaZ_fill(z) == EOZ) /* try to read more */ 51 | return n; /* no more input; return number of missing bytes */ 52 | else { 53 | z->n++; /* luaZ_fill consumed first byte; put it back */ 54 | z->p--; 55 | } 56 | } 57 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 58 | memcpy(b, z->p, m); 59 | z->n -= m; 60 | z->p += m; 61 | b = (char *)b + m; 62 | n -= m; 63 | } 64 | return 0; 65 | } 66 | 67 | /* ------------------------------------------------------------------------ */ 68 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { 69 | if (n > buff->buffsize) { 70 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; 71 | luaZ_resizebuffer(L, buff, n); 72 | } 73 | return buff->buffer; 74 | } 75 | 76 | 77 | -------------------------------------------------------------------------------- /3rd/lua/lua52/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.26.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 36 | 37 | 38 | #define luaZ_resizebuffer(L, buff, size) \ 39 | (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ 40 | (buff)->buffsize = size) 41 | 42 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 43 | 44 | 45 | LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 46 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 47 | void *data); 48 | LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ 49 | 50 | 51 | 52 | /* --------- Private Part ------------------ */ 53 | 54 | struct Zio { 55 | size_t n; /* bytes still unread */ 56 | const char *p; /* current position in buffer */ 57 | lua_Reader reader; /* reader function */ 58 | void* data; /* additional data */ 59 | lua_State *L; /* Lua state (for reader) */ 60 | }; 61 | 62 | 63 | LUAI_FUNC int luaZ_fill (ZIO *z); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /3rd/lua/lua53/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.9.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /3rd/lua/lua53/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.14.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : -1) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 22 | const char *opname); 23 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 24 | const TValue *p2); 25 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 26 | const TValue *p2, 27 | const char *msg); 28 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 29 | const TValue *p2); 30 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 31 | const TValue *p2); 32 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 33 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, 34 | TString *src, int line); 35 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 36 | LUAI_FUNC void luaG_traceexec (lua_State *L); 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /3rd/lua/lua53/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.15.1.1 2017/04/19 17:39:34 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | /* 33 | ** Upvalues for Lua closures 34 | */ 35 | struct UpVal { 36 | TValue *v; /* points to stack or to its own value */ 37 | lu_mem refcount; /* reference counter */ 38 | union { 39 | struct { /* (when open) */ 40 | UpVal *next; /* linked list */ 41 | int touched; /* mark to avoid cycles with dead threads */ 42 | } open; 43 | TValue value; /* the value (when closed) */ 44 | } u; 45 | }; 46 | 47 | #define upisopen(up) ((up)->v != &(up)->u.value) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 57 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 58 | int pc); 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /3rd/lua/lua53/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.39.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {"_G", luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | #if defined(LUA_COMPAT_BITLIB) 54 | {LUA_BITLIBNAME, luaopen_bit32}, 55 | #endif 56 | {NULL, NULL} 57 | }; 58 | 59 | 60 | LUALIB_API void luaL_openlibs (lua_State *L) { 61 | const luaL_Reg *lib; 62 | /* "require" functions from 'loadedlibs' and set results to global table */ 63 | for (lib = loadedlibs; lib->func; lib++) { 64 | luaL_requiref(L, lib->name, lib->func, 1); 65 | lua_pop(L, 1); /* remove lib */ 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /3rd/lua/lua53/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h,v 1.2.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #include "luai_devent.h" 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /3rd/lua/lua53/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.61.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | #define sizelstring(l) (sizeof(union UTString) + ((l) + 1) * sizeof(char)) 16 | 17 | #define sizeludata(l) (sizeof(union UUdata) + (l)) 18 | #define sizeudata(u) sizeludata((u)->len) 19 | 20 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 21 | (sizeof(s)/sizeof(char))-1)) 22 | 23 | 24 | /* 25 | ** test whether a string is a reserved word 26 | */ 27 | #define isreserved(s) ((s)->tt == LUA_TSHRSTR && (s)->extra > 0) 28 | 29 | 30 | /* 31 | ** equality for short strings, which are always internalized 32 | */ 33 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_TSHRSTR, (a) == (b)) 34 | 35 | 36 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 37 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 38 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 39 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 40 | LUAI_FUNC void luaS_clearcache (global_State *g); 41 | LUAI_FUNC void luaS_init (lua_State *L); 42 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 43 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s); 44 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 45 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 46 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /3rd/lua/lua53/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /3rd/lua/lua53/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* version suffix for environment variable names */ 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR 16 | 17 | 18 | LUAMOD_API int (luaopen_base) (lua_State *L); 19 | 20 | #define LUA_COLIBNAME "coroutine" 21 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 22 | 23 | #define LUA_TABLIBNAME "table" 24 | LUAMOD_API int (luaopen_table) (lua_State *L); 25 | 26 | #define LUA_IOLIBNAME "io" 27 | LUAMOD_API int (luaopen_io) (lua_State *L); 28 | 29 | #define LUA_OSLIBNAME "os" 30 | LUAMOD_API int (luaopen_os) (lua_State *L); 31 | 32 | #define LUA_STRLIBNAME "string" 33 | LUAMOD_API int (luaopen_string) (lua_State *L); 34 | 35 | #define LUA_UTF8LIBNAME "utf8" 36 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 37 | 38 | #define LUA_BITLIBNAME "bit32" 39 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 40 | 41 | #define LUA_MATHLIBNAME "math" 42 | LUAMOD_API int (luaopen_math) (lua_State *L); 43 | 44 | #define LUA_DBLIBNAME "debug" 45 | LUAMOD_API int (luaopen_debug) (lua_State *L); 46 | 47 | #define LUA_LOADLIBNAME "package" 48 | LUAMOD_API int (luaopen_package) (lua_State *L); 49 | 50 | 51 | /* open all previous libraries */ 52 | LUALIB_API void (luaL_openlibs) (lua_State *L); 53 | 54 | 55 | 56 | #if !defined(lua_assert) 57 | #define lua_assert(x) ((void)0) 58 | #endif 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /3rd/lua/lua53/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | #define MYINT(s) (s[0]-'0') 22 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 23 | #define LUAC_FORMAT 0 /* this is the official format */ 24 | 25 | /* load one chunk; from lundump.c */ 26 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 27 | 28 | /* dump one chunk; from ldump.c */ 29 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 30 | void* data, int strip); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /3rd/lua/lua53/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.37.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /3rd/lua/lua53/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.31.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /3rd/lua/lua54/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | 15 | /* Increments 'L->top.p', checking for stack overflows */ 16 | #define api_incr_top(L) {L->top.p++; \ 17 | api_check(L, L->top.p <= L->ci->top.p, \ 18 | "stack overflow");} 19 | 20 | 21 | /* 22 | ** If a call returns too many multiple returns, the callee may not have 23 | ** stack space to accommodate all results. In this case, this macro 24 | ** increases its stack space ('L->ci->top.p'). 25 | */ 26 | #define adjustresults(L,nres) \ 27 | { if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \ 28 | L->ci->top.p = L->top.p; } 29 | 30 | 31 | /* Ensure the stack has at least 'n' elements */ 32 | #define api_checknelems(L,n) \ 33 | api_check(L, (n) < (L->top.p - L->ci->func.p), \ 34 | "not enough elements in the stack") 35 | 36 | 37 | /* 38 | ** To reduce the overhead of returning from C functions, the presence of 39 | ** to-be-closed variables in these functions is coded in the CallInfo's 40 | ** field 'nresults', in a way that functions with no to-be-closed variables 41 | ** with zero, one, or "all" wanted results have no overhead. Functions 42 | ** with other number of wanted results, as well as functions with 43 | ** variables to be closed, have an extra check. 44 | */ 45 | 46 | #define hastocloseCfunc(n) ((n) < LUA_MULTRET) 47 | 48 | /* Map [-1, inf) (range of 'nresults') into (-inf, -2] */ 49 | #define codeNresults(n) (-(n) - 3) 50 | #define decodeNresults(n) (-(n) - 3) 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /3rd/lua/lua54/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast_int(offsetof(CClosure, upvalue)) + \ 15 | cast_int(sizeof(TValue)) * (n)) 16 | 17 | #define sizeLclosure(n) (cast_int(offsetof(LClosure, upvals)) + \ 18 | cast_int(sizeof(TValue *)) * (n)) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | #define upisopen(up) ((up)->v.p != &(up)->u.value) 33 | 34 | 35 | #define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v.p)) 36 | 37 | 38 | /* 39 | ** maximum number of misses before giving up the cache of closures 40 | ** in prototypes 41 | */ 42 | #define MAXMISS 10 43 | 44 | 45 | 46 | /* special status to close upvalues preserving the top of the stack */ 47 | #define CLOSEKTOP (-1) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nupvals); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nupvals); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level); 57 | LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy); 58 | LUAI_FUNC void luaF_unlinkupval (UpVal *uv); 59 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 60 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 61 | int pc); 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /3rd/lua/lua54/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {LUA_GNAME, luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | {NULL, NULL} 54 | }; 55 | 56 | 57 | LUALIB_API void luaL_openlibs (lua_State *L) { 58 | const luaL_Reg *lib; 59 | /* "require" functions from 'loadedlibs' and set results to global table */ 60 | for (lib = loadedlibs; lib->func; lib++) { 61 | luaL_requiref(L, lib->name, lib->func, 1); 62 | lua_pop(L, 1); /* remove lib */ 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /3rd/lua/lua54/lopnames.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopnames.h $ 3 | ** Opcode names 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #if !defined(lopnames_h) 8 | #define lopnames_h 9 | 10 | #include 11 | 12 | 13 | /* ORDER OP */ 14 | 15 | static const char *const opnames[] = { 16 | "MOVE", 17 | "LOADI", 18 | "LOADF", 19 | "LOADK", 20 | "LOADKX", 21 | "LOADFALSE", 22 | "LFALSESKIP", 23 | "LOADTRUE", 24 | "LOADNIL", 25 | "GETUPVAL", 26 | "SETUPVAL", 27 | "GETTABUP", 28 | "GETTABLE", 29 | "GETI", 30 | "GETFIELD", 31 | "SETTABUP", 32 | "SETTABLE", 33 | "SETI", 34 | "SETFIELD", 35 | "NEWTABLE", 36 | "SELF", 37 | "ADDI", 38 | "ADDK", 39 | "SUBK", 40 | "MULK", 41 | "MODK", 42 | "POWK", 43 | "DIVK", 44 | "IDIVK", 45 | "BANDK", 46 | "BORK", 47 | "BXORK", 48 | "SHRI", 49 | "SHLI", 50 | "ADD", 51 | "SUB", 52 | "MUL", 53 | "MOD", 54 | "POW", 55 | "DIV", 56 | "IDIV", 57 | "BAND", 58 | "BOR", 59 | "BXOR", 60 | "SHL", 61 | "SHR", 62 | "MMBIN", 63 | "MMBINI", 64 | "MMBINK", 65 | "UNM", 66 | "BNOT", 67 | "NOT", 68 | "LEN", 69 | "CONCAT", 70 | "CLOSE", 71 | "TBC", 72 | "JMP", 73 | "EQ", 74 | "LT", 75 | "LE", 76 | "EQK", 77 | "EQI", 78 | "LTI", 79 | "LEI", 80 | "GTI", 81 | "GEI", 82 | "TEST", 83 | "TESTSET", 84 | "CALL", 85 | "TAILCALL", 86 | "RETURN", 87 | "RETURN0", 88 | "RETURN1", 89 | "FORLOOP", 90 | "FORPREP", 91 | "TFORPREP", 92 | "TFORCALL", 93 | "TFORLOOP", 94 | "SETLIST", 95 | "CLOSURE", 96 | "VARARG", 97 | "VARARGPREP", 98 | "EXTRAARG", 99 | NULL 100 | }; 101 | 102 | #endif 103 | 104 | -------------------------------------------------------------------------------- /3rd/lua/lua54/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #include "luai_devent.h" 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /3rd/lua/lua54/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | /* 16 | ** Memory-allocation error message must be preallocated (it cannot 17 | ** be created after memory is exhausted) 18 | */ 19 | #define MEMERRMSG "not enough memory" 20 | 21 | 22 | /* 23 | ** Size of a TString: Size of the header plus space for the string 24 | ** itself (including final '\0'). 25 | */ 26 | #define sizelstring(l) (offsetof(TString, contents) + ((l) + 1) * sizeof(char)) 27 | 28 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 29 | (sizeof(s)/sizeof(char))-1)) 30 | 31 | 32 | /* 33 | ** test whether a string is a reserved word 34 | */ 35 | #define isreserved(s) ((s)->tt == LUA_VSHRSTR && (s)->extra > 0) 36 | 37 | 38 | /* 39 | ** equality for short strings, which are always internalized 40 | */ 41 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_VSHRSTR, (a) == (b)) 42 | 43 | 44 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 45 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 46 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 47 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 48 | LUAI_FUNC void luaS_clearcache (global_State *g); 49 | LUAI_FUNC void luaS_init (lua_State *L); 50 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 51 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue); 52 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 53 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 54 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /3rd/lua/lua54/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /3rd/lua/lua54/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* version suffix for environment variable names */ 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR 16 | 17 | 18 | LUAMOD_API int (luaopen_base) (lua_State *L); 19 | 20 | #define LUA_COLIBNAME "coroutine" 21 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 22 | 23 | #define LUA_TABLIBNAME "table" 24 | LUAMOD_API int (luaopen_table) (lua_State *L); 25 | 26 | #define LUA_IOLIBNAME "io" 27 | LUAMOD_API int (luaopen_io) (lua_State *L); 28 | 29 | #define LUA_OSLIBNAME "os" 30 | LUAMOD_API int (luaopen_os) (lua_State *L); 31 | 32 | #define LUA_STRLIBNAME "string" 33 | LUAMOD_API int (luaopen_string) (lua_State *L); 34 | 35 | #define LUA_UTF8LIBNAME "utf8" 36 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 37 | 38 | #define LUA_MATHLIBNAME "math" 39 | LUAMOD_API int (luaopen_math) (lua_State *L); 40 | 41 | #define LUA_DBLIBNAME "debug" 42 | LUAMOD_API int (luaopen_debug) (lua_State *L); 43 | 44 | #define LUA_LOADLIBNAME "package" 45 | LUAMOD_API int (luaopen_package) (lua_State *L); 46 | 47 | 48 | /* open all previous libraries */ 49 | LUALIB_API void (luaL_openlibs) (lua_State *L); 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /3rd/lua/lua54/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | /* 22 | ** Encode major-minor version in one byte, one nibble for each 23 | */ 24 | #define LUAC_VERSION (((LUA_VERSION_NUM / 100) * 16) + LUA_VERSION_NUM % 100) 25 | 26 | #define LUAC_FORMAT 0 /* this is the official format */ 27 | 28 | /* load one chunk; from lundump.c */ 29 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 30 | 31 | /* dump one chunk; from ldump.c */ 32 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 33 | void* data, int strip); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /3rd/lua/lua54/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /3rd/lua/lua54/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /3rd/lua/luai_devent.h: -------------------------------------------------------------------------------- 1 | #include "lua.h" 2 | 3 | #if LUA_VERSION_NUM >= 504 4 | #define LUA_CALLHOOK(L,event, type) luaD_hook(L, event, type, 0, 0) 5 | #elif LUA_VERSION_NUM >= 502 6 | #define LUA_CALLHOOK(L,event, type) luaD_hook(L, event, type) 7 | #elif LUA_VERSION_NUM >= 501 8 | #define LUA_CALLHOOK(L,event, type) luaD_callhook(L, event, type) 9 | #else 10 | #error unknown lua version 11 | #endif 12 | 13 | #if LUA_VERSION_NUM >= 504 14 | #define LUA_STKID(s) s.p 15 | #define LUA_S2V(s) s2v(s) 16 | #else 17 | #define LUA_S2V(s) (s) 18 | #define LUA_STKID(s) s 19 | #endif 20 | 21 | #define luai_threadevent(L, from, type) \ 22 | if (L && (L->l_G->mainthread->hookmask & LUA_MASKTHREAD)) { \ 23 | setpvalue(LUA_S2V(LUA_STKID(L->top)), from); \ 24 | LUA_STKID(L->top)++; \ 25 | LUA_CALLHOOK(L, LUA_HOOKTHREAD, type); \ 26 | LUA_STKID(L->top)--; \ 27 | } 28 | 29 | #define luai_threadcall(L, from) luai_threadevent(L, from, 0) 30 | #define luai_threadret(L, to) luai_threadevent(L, to, 1) 31 | 32 | #define LUA_ERREVENT_PANIC 0x10 33 | 34 | #if LUA_VERSION_NUM >= 504 35 | #define luai_errevent_(L, errcode) luaD_hook(L, LUA_HOOKEXCEPTION, cast_int(LUA_STKID(L->top) - LUA_STKID(L->stack)), 0, errcode) 36 | #else 37 | #define luai_errevent_(L, errcode) LUA_CALLHOOK(L, LUA_HOOKEXCEPTION, errcode) 38 | #endif 39 | 40 | #define luai_errevent(L, errcode) \ 41 | if (L->hookmask & LUA_MASKEXCEPTION) { \ 42 | switch (errcode) { \ 43 | case LUA_ERRRUN: \ 44 | case LUA_ERRSYNTAX: \ 45 | case LUA_ERRMEM: \ 46 | case LUA_ERRERR: { \ 47 | int code = errcode; \ 48 | if (!L->errorJmp) { \ 49 | code |= LUA_ERREVENT_PANIC; \ 50 | } \ 51 | luai_errevent_(L, code); \ 52 | break; \ 53 | }} \ 54 | } 55 | -------------------------------------------------------------------------------- /3rd/wow64ext/.gitignore: -------------------------------------------------------------------------------- 1 | *.opensdf 2 | *.sdf 3 | *.suo 4 | *.obj 5 | *.ilk 6 | *.db 7 | *.user 8 | *.opendb 9 | *.pdb 10 | src/Release/* 11 | src/Debug/* 12 | sample/*.exe 13 | sample/*.dll 14 | sample/*.lib -------------------------------------------------------------------------------- /3rd/wow64ext/.hgignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/actboy168/lua-debug/0bd08237866d3dc5d3654d99fa6849b11e45bef1/3rd/wow64ext/.hgignore -------------------------------------------------------------------------------- /3rd/wow64ext/README.md: -------------------------------------------------------------------------------- 1 | # rewolf-wow64ext 2 | WOW64Ext is a helper library for x86 programs that runs under WOW64 layer on x64 versions of Microsoft Windows operating systems. It enables x86 applications to read, write and enumerate memory of a native x64 applications. There is also possibility to call any x64 function from 64-bits version of NTDLL through a special function called X64Call(). As a bonus, wow64ext.h contains definitions of some structures that might be useful for programs that want to access PEB, TEB, TIB etc. 3 | -------------------------------------------------------------------------------- /3rd/wow64ext/sample/build.bat: -------------------------------------------------------------------------------- 1 | cl /Zi /D "UNICODE" ../bin/wow64ext.lib main.cpp 2 | -------------------------------------------------------------------------------- /3rd/wow64ext/src/CMemPtr.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * WOW64Ext Library 4 | * 5 | * Copyright (c) 2014 ReWolf 6 | * http://blog.rewolf.pl/ 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published 10 | * by the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program. If not, see . 20 | * 21 | */ 22 | #pragma once 23 | 24 | class CMemPtr 25 | { 26 | private: 27 | void** m_ptr; 28 | bool watchActive; 29 | 30 | public: 31 | CMemPtr(void** ptr) : m_ptr(ptr), watchActive(true) {} 32 | 33 | ~CMemPtr() 34 | { 35 | if (*m_ptr && watchActive) 36 | { 37 | free(*m_ptr); 38 | *m_ptr = 0; 39 | } 40 | } 41 | 42 | void disableWatch() { watchActive = false; } 43 | }; 44 | 45 | #define WATCH(ptr) \ 46 | CMemPtr watch_##ptr((void**)&ptr) 47 | 48 | #define DISABLE_WATCH(ptr) \ 49 | watch_##ptr.disableWatch() 50 | -------------------------------------------------------------------------------- /3rd/wow64ext/src/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by wow64ext.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /3rd/wow64ext/src/wow64ext.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/actboy168/lua-debug/0bd08237866d3dc5d3654d99fa6849b11e45bef1/3rd/wow64ext/src/wow64ext.rc -------------------------------------------------------------------------------- /3rd/wow64ext/src/wow64ext.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wow64ext", "wow64ext.vcxproj", "{9DA7F232-0096-45BC-A452-24C7F3AFA0F8}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {9DA7F232-0096-45BC-A452-24C7F3AFA0F8}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {9DA7F232-0096-45BC-A452-24C7F3AFA0F8}.Debug|Win32.Build.0 = Debug|Win32 16 | {9DA7F232-0096-45BC-A452-24C7F3AFA0F8}.Release|Win32.ActiveCfg = Release|Win32 17 | {9DA7F232-0096-45BC-A452-24C7F3AFA0F8}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 - present actboy168 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lua-debug 2 | 3 | [![Build Status](https://github.com/actboy168/lua-debug/workflows/build/badge.svg)](https://github.com/actboy168/lua-debug/actions?workflow=build) 4 | 5 | ## Requirements 6 | 7 | * Lua 5.1 - 5.4 or luajit (thanks [@fesily](https://github.com/fesily)) 8 | * Platform: Windows, macOS, Linux, Android, NetBSD, FreeBSD 9 | 10 | ## Feature 11 | 12 | * Breakpoints 13 | * Function breakpoints 14 | * Conditional breakpoints 15 | * Hit Conditional breakpoints 16 | * Step over, step in, step out 17 | * Watches 18 | * Evaluate expressions 19 | * Exception 20 | * Remote debugging 21 | * Support WSL 22 | 23 | ## Build 24 | 25 | 1. Install [luamake](https://github.com/actboy168/luamake) 26 | ``` bash 27 | git clone https://github.com/actboy168/luamake 28 | pushd luamake 29 | git submodule init 30 | git submodule update 31 | .\compile\install.bat(msvc) 32 | ./compile/install.sh (other) 33 | popd 34 | ``` 35 | 36 | 2. Clone repo. 37 | ``` bash 38 | git clone https://github.com/actboy168/lua-debug 39 | cd lua-debug 40 | git submodule init 41 | git submodule update 42 | ``` 43 | 44 | 3. Download deps. 45 | ``` bash 46 | luamake lua compile/download_deps.lua 47 | ``` 48 | 49 | 4. Build 50 | ``` 51 | luamake -mode release 52 | ``` 53 | 54 | ## Install to VSCode 55 | 56 | 1. Install extension `actboy168.lua-debug` and `actboy168.extension-path` 57 | 2. Open [repo](https://github.com/actboy168/lua-debug) in VSCode 58 | 3. Run task:Copy Publish 59 | 60 | ## Todo 61 | 62 | * iOS example. 63 | -------------------------------------------------------------------------------- /compile/clang-format.lua: -------------------------------------------------------------------------------- 1 | local fs = require "bee.filesystem" 2 | local sp = require "bee.subprocess" 3 | 4 | local sourcefile = {} 5 | 6 | local EXTENSION = { 7 | [".h"] = true, 8 | [".inl"] = true, 9 | [".c"] = true, 10 | [".cpp"] = true, 11 | } 12 | 13 | local function scan(dir) 14 | for path in fs.pairs(dir) do 15 | if fs.is_directory(path) then 16 | scan(path) 17 | else 18 | local ext = path:extension() 19 | if EXTENSION[ext] then 20 | sourcefile[#sourcefile + 1] = path:string() 21 | end 22 | end 23 | end 24 | end 25 | 26 | scan "src" 27 | 28 | if #sourcefile > 0 then 29 | local process = assert(sp.spawn { 30 | "luamake", "shell", "clang-format", 31 | "-i", sourcefile, 32 | stdout = true, 33 | stderr = "stdout", 34 | searchPath = true, 35 | }) 36 | for line in process.stdout:lines() do 37 | io.write(line, "\n") 38 | io.flush() 39 | end 40 | process.stdout:close() 41 | local code = process:wait() 42 | if code ~= 0 then 43 | os.exit(code, true) 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /compile/common/config.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | lm.compile_commands = "build" 4 | lm.c = "c11" 5 | lm.cxx = "c++17" 6 | 7 | lm.mode = "debug" 8 | 9 | lm.msvc = { 10 | flags = "/wd5105" 11 | } 12 | -------------------------------------------------------------------------------- /compile/common/frida.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | require 'compile.common.detect_platform' 4 | 5 | local arch = lm.arch 6 | if not arch then 7 | arch = lm.runtime_platform:match "[%w]+-([%w]+)" 8 | end 9 | 10 | if arch == "x64" then 11 | arch = "x86_64" 12 | end 13 | 14 | local dir = "3rd/frida_gum/"..lm.os.."-"..arch 15 | lm:source_set "frida" { 16 | includes = {dir, "3rd/frida_gum/gumpp"}, 17 | defines = {"GUMPP_STATIC"}, 18 | windows = { 19 | defines = {"HAVE_WINDOWS", "_CRT_SECURE_NO_WARNINGS"}, 20 | links = {"kernel32","user32","gdi32","winspool","comdlg32","advapi32","shell32","ole32","oleaut32","uuid","odbc32","odbccp32"}, 21 | sources = "3rd/frida_gum/gumpp/src/internal/*.c", 22 | flags = { 23 | '/wd4819', 24 | '/wd5051', 25 | } 26 | }, 27 | linux = { 28 | flags = "-fPIC", 29 | }, 30 | sources = { 31 | "3rd/frida_gum/gumpp/src/*.cpp", 32 | }, 33 | linkdirs = dir, 34 | links = "frida-gum", 35 | } 36 | -------------------------------------------------------------------------------- /compile/common/launcher.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | require "compile.common.frida" 4 | 5 | lm:source_set "launcher_hook_luajit" { 6 | includes = { 7 | "3rd/lua/luajit/src", 8 | "3rd/frida_gum/gumpp", 9 | "src/launcher" 10 | }, 11 | sources = "src/launcher/hook/luajit_listener.cpp", 12 | } 13 | 14 | lm:lua_src 'launcher_source' { 15 | deps = { 16 | "frida", 17 | "launcher_hook_luajit", 18 | }, 19 | includes = { 20 | "3rd/bee.lua", 21 | "3rd/frida_gum/gumpp", 22 | "3rd/lua/lua54", 23 | "src/launcher", 24 | }, 25 | sources = { 26 | "src/launcher/**/*.cpp", 27 | "!src/launcher/hook/luajit_listener.cpp", 28 | }, 29 | defines = { 30 | "BEE_INLINE", 31 | }, 32 | windows = { 33 | defines = "_CRT_SECURE_NO_WARNINGS", 34 | links = { 35 | "ws2_32", 36 | "user32", 37 | "shell32", 38 | "ole32", 39 | "delayimp", 40 | "ntdll", 41 | "Version" 42 | }, 43 | ldflags = { 44 | "/NODEFAULTLIB:LIBCMT" 45 | } 46 | }, 47 | linux = { 48 | flags = "-fPIC", 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /compile/common/lua-debug.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | if lm.os == "windows" then 4 | lm:source_set "source_inject" { 5 | bindir = "publish/bin", 6 | includes = { 7 | "3rd/bee.lua", 8 | "3rd/bee.lua/3rd/lua", 9 | "3rd/wow64ext/src", 10 | }, 11 | sources = { 12 | "src/process_inject/windows/*.cpp", 13 | "3rd/wow64ext/src/wow64ext.cpp", 14 | }, 15 | links = "advapi32", 16 | } 17 | end 18 | 19 | lm:executable "lua-debug" { 20 | bindir = "publish/bin/", 21 | deps = "source_bootstrap", 22 | windows = { 23 | deps = "source_inject", 24 | sources = { 25 | "compile/windows/lua-debug.rc" 26 | } 27 | }, 28 | msvc = { 29 | ldflags = "/IMPLIB:$obj/lua-debug.lib" 30 | }, 31 | mingw = { 32 | ldflags = "-Wl,--out-implib,$obj/lua-debug.lib" 33 | }, 34 | linux = { 35 | crt = "static", 36 | ldflags = "-rdynamic" 37 | }, 38 | netbsd = { 39 | crt = "static", 40 | }, 41 | freebsd = { 42 | crt = "static", 43 | }, 44 | openbsd = { 45 | crt = "static", 46 | }, 47 | } 48 | -------------------------------------------------------------------------------- /compile/common/make.lua: -------------------------------------------------------------------------------- 1 | local lm = require 'luamake' 2 | 3 | lm:copy 'copy_json' { 4 | inputs = '3rd/json.lua/json.lua', 5 | outputs = 'publish/script/common/json.lua' 6 | } 7 | 8 | lm:copy 'copy_bootstrap' { 9 | inputs = 'extension/script/bootstrap.lua', 10 | outputs = 'publish/bin/main.lua', 11 | } 12 | 13 | lm:runlua 'package_json' { 14 | script = 'compile/common/write_json.lua', 15 | args = {'$in', '$out', lm.platform}, 16 | inputs = "compile/common/package_json.lua", 17 | outputs = "extension/package.json", 18 | } 19 | 20 | lm:runlua 'copy_extension' { 21 | deps = 'package_json', 22 | script = 'compile/copy_extension.lua', 23 | } 24 | 25 | lm:phony 'common' { 26 | deps = { 27 | 'copy_json', 28 | 'copy_bootstrap', 29 | 'copy_extension', 30 | 'package_json', 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /compile/common/run_luamake.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | lm:rule "run_luamake" { 4 | args = { 5 | "$luamake", 6 | "-mode", lm.mode, 7 | "-C", lm.workdir, 8 | "-f", "$in", 9 | "$args", 10 | }, 11 | pool = "console", 12 | } 13 | -------------------------------------------------------------------------------- /compile/common/write_json.lua: -------------------------------------------------------------------------------- 1 | local input, output, platform = ... 2 | 3 | package.path = package.path ..";3rd/json.lua/?.lua" 4 | local json = require "json-beautify" 5 | 6 | local jsondata = assert(loadfile(input))(platform) 7 | local f = assert(io.open(output, "wb")) 8 | f:write(json.beautify(jsondata)) 9 | -------------------------------------------------------------------------------- /compile/copy.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path..";3rd/json.lua/?.lua" 2 | 3 | local fs = require 'bee.filesystem' 4 | local OS = require 'bee.platform'.os 5 | 6 | local function crtdll(path) 7 | if path:find("api-ms-win-", 1, true) then 8 | return true 9 | end 10 | if path:sub(1, 5) == "msvcp" then 11 | return true 12 | end 13 | if path:sub(1, 9) == "vcruntime" then 14 | return true 15 | end 16 | if path == "concrt140.dll" then 17 | return true 18 | end 19 | if path == "ucrtbase.dll" then 20 | return true 21 | end 22 | return false 23 | end 24 | 25 | local function copy_directory(from, to, filter) 26 | fs.create_directories(to) 27 | for fromfile in fs.pairs(from) do 28 | if (not filter) or filter(fromfile) then 29 | if fs.is_directory(fromfile) then 30 | copy_directory(fromfile, to / fromfile:filename(), filter) 31 | else 32 | local filename = fromfile:filename() 33 | if not crtdll(filename:string():lower()) then 34 | print('copy', fromfile, to / filename) 35 | end 36 | if OS == "macos" then 37 | -- must remove first, it will cause a code signature error 38 | fs.remove(to / filename) 39 | end 40 | fs.copy_file(fromfile, to / filename, fs.copy_options.overwrite_existing) 41 | end 42 | end 43 | end 44 | end 45 | 46 | local sourceDir, extensionDir = ... 47 | local sourceDir = fs.path(sourceDir) 48 | copy_directory(sourceDir, extensionDir, function (path) 49 | local ext = path:extension() 50 | return ext ~= '.log' and path ~= sourceDir / "tmp" 51 | end) 52 | 53 | print 'ok' 54 | -------------------------------------------------------------------------------- /compile/copy_extension.lua: -------------------------------------------------------------------------------- 1 | local fs = require 'bee.filesystem' 2 | local root = fs.absolute(fs.path '.') 3 | local outputDir = root / 'publish' 4 | local OVERWRITE = fs.copy_options.overwrite_existing 5 | 6 | local function copy_directory(from, to) 7 | fs.create_directories(to) 8 | for fromfile in fs.pairs(from) do 9 | if fs.is_directory(fromfile) then 10 | copy_directory(fromfile, to / fromfile:filename()) 11 | else 12 | fs.copy_file(fromfile, to / fromfile:filename(), OVERWRITE) 13 | end 14 | end 15 | end 16 | 17 | copy_directory(root / 'extension', outputDir) 18 | 19 | fs.copy_file(root / "LICENSE", outputDir / "LICENSE", OVERWRITE) 20 | fs.copy_file(root / "README.md", outputDir / "README.md", OVERWRITE) 21 | -------------------------------------------------------------------------------- /compile/linux/make.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | lm.builddir = ("build/%s/%s"):format(lm.platform, lm.mode) 4 | lm:import "compile/common/bee.lua" 5 | require "compile.common.lua-debug" 6 | 7 | lm.runtime_platform = lm.platform 8 | require "compile.linux.runtime" 9 | 10 | lm:default { 11 | "common", 12 | "lua-debug", 13 | "runtime", 14 | "launcher", 15 | } 16 | -------------------------------------------------------------------------------- /compile/linux/runtime.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | require "compile.common.runtime" 4 | require "compile.common.launcher" 5 | 6 | lm:lua_dll 'launcher' { 7 | bindir = "publish/bin/", 8 | export_luaopen = "off", 9 | deps = { 10 | "launcher_source", 11 | }, 12 | } 13 | -------------------------------------------------------------------------------- /compile/luadbg/build.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | local newname = "luadbg" 4 | local luapath = [[3rd/bee.lua/3rd/lua/]] 5 | local outpath = [[src/luadebug/luadbg/inc/]] 6 | local filelist = { 7 | "lua.h", 8 | "luaconf.h", 9 | "lualib.h", 10 | "lauxlib.h", 11 | "lua.hpp", 12 | } 13 | 14 | local function compile(v) 15 | return v 16 | :gsub("lua", newname) 17 | :gsub("lauxlib", newname.."auxlib") 18 | end 19 | 20 | local input = {} 21 | local output = {} 22 | for i, file in ipairs(filelist) do 23 | input[i] = luapath..file 24 | output[i] = outpath..compile(file) 25 | end 26 | 27 | output[#output + 1] = outpath..compile("luaexports.h") 28 | output[#output + 1] = outpath..compile("luarename.h") 29 | 30 | lm:runlua "compile_to_luadbg" { 31 | script = "compile/luadbg/compile.lua", 32 | args = { 33 | newname, 34 | luapath, 35 | outpath, 36 | }, 37 | inputs = input, 38 | outputs = output, 39 | } 40 | 41 | lm:phony { 42 | inputs = outpath..compile("lua.hpp"), 43 | outputs = { 44 | "src/luadebug/rdebug_hookmgr.cpp", 45 | "src/luadebug/rdebug_debughost.cpp", 46 | "src/luadebug/rdebug_stdio.cpp", 47 | "src/luadebug/rdebug_utility.cpp", 48 | "src/luadebug/rdebug_visitor.cpp", 49 | "src/luadebug/util/refvalue.cpp", 50 | }, 51 | } 52 | 53 | lm:phony { 54 | inputs = { 55 | outpath..compile("lua.hpp"), 56 | outpath..compile("luaexports.h"), 57 | outpath..compile("luarename.h"), 58 | }, 59 | outputs = { 60 | "src/luadebug/luadbg/bee_module.cpp", 61 | }, 62 | } 63 | 64 | lm:phony { 65 | inputs = { 66 | outpath..compile("luaexports.h"), 67 | }, 68 | outputs = { 69 | "src/luadebug/luadbg/onelua.c", 70 | }, 71 | } 72 | -------------------------------------------------------------------------------- /compile/luajit/defined.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | local arch = lm.runtime_platform:sub(lm.runtime_platform:find("-") + 1) 4 | if arch == "ia32" then 5 | arch = "x86" 6 | end 7 | 8 | local luaver = "luajit" 9 | local LUAJIT_ENABLE_LUA52COMPAT = "LUAJIT_ENABLE_LUA52COMPAT" 10 | local LUAJIT_NUMMODE = "LUAJIT_NUMMODE=2" 11 | local luajitDir = '3rd/lua/' .. luaver .. "/src" 12 | 13 | local _M = { 14 | arch = arch, 15 | LUAJIT_ENABLE_LUA52COMPAT = LUAJIT_ENABLE_LUA52COMPAT, 16 | LUAJIT_NUMMODE = LUAJIT_NUMMODE, 17 | luajitDir = luajitDir 18 | } 19 | 20 | return _M 21 | -------------------------------------------------------------------------------- /compile/luajit/make_buildtools.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | --the generated file must store into different directory 4 | local defined = require "compile.luajit.defined" 5 | 6 | local arch = defined.arch 7 | local LUAJIT_ENABLE_LUA52COMPAT = defined.LUAJIT_ENABLE_LUA52COMPAT 8 | local LUAJIT_NUMMODE = defined.LUAJIT_NUMMODE 9 | local luajitDir = defined.luajitDir 10 | 11 | local LUAJIT_TARGET = string.format("LUAJIT_TARGET=LUAJIT_ARCH_%s", string.upper(arch)) 12 | local LJ_ARCH_HASFPU = "LJ_ARCH_HASFPU=1" 13 | local LJ_ABI_SOFTFP = "LJ_ABI_SOFTFP=0" 14 | 15 | lm:executable("minilua") { 16 | rootdir = luajitDir, 17 | defines = { 18 | LUAJIT_TARGET, 19 | LJ_ARCH_HASFPU, 20 | LJ_ABI_SOFTFP, 21 | LUAJIT_ENABLE_LUA52COMPAT, 22 | LUAJIT_NUMMODE 23 | }, 24 | sources = { "host/minilua.c" }, 25 | links = { "m" } 26 | } 27 | 28 | local arch_flags = { 29 | "-D", "ENDIAN_LE", 30 | "-D", "P64", 31 | "-D", "JIT", 32 | "-D", "FFI", 33 | "-D", "FPU", 34 | "-D", "HFABI", 35 | "-D", "VER=80", 36 | "-D", "DUALNUM" 37 | } 38 | 39 | lm:build("builvm_arch.h") { 40 | deps = "minilua", 41 | args = { 42 | lm.bindir .. "/minilua", 43 | luajitDir .. "/../dynasm/dynasm.lua", 44 | arch_flags, 45 | "-o", "$out", "$in", 46 | }, 47 | inputs = luajitDir .. string.format("/vm_%s.dasc", arch), 48 | outputs = lm.bindir .. "/buildvm_arch.h" 49 | } 50 | 51 | lm:executable("buildvm") { 52 | rootdir = luajitDir, 53 | deps = "builvm_arch.h", 54 | objdeps = { lm.bindir .. "/buildvm_arch.h" }, 55 | defines = { 56 | LUAJIT_TARGET, 57 | LJ_ARCH_HASFPU, 58 | LJ_ABI_SOFTFP, 59 | LUAJIT_ENABLE_LUA52COMPAT, 60 | LUAJIT_NUMMODE 61 | }, 62 | sources = { 63 | "host/*.c", 64 | "!host/minilua.c" 65 | }, 66 | includes = { 67 | ".", 68 | "../../../../" .. lm.bindir 69 | } 70 | } -------------------------------------------------------------------------------- /compile/macos/export_shellcode.lua: -------------------------------------------------------------------------------- 1 | local input, output = ... 2 | 3 | local stats = 0 4 | local result = {} 5 | for line in io.lines(input) do 6 | if stats == 0 then 7 | if line == 'Contents of section __TEXT,__text:' then 8 | stats = 1 9 | end 10 | else 11 | if line:sub(1, 6):match "^ [0-9a-f][0-9a-f][0-9a-f][0-9a-f] $" then 12 | local hexstring = line:sub(7, 7 + 9 * 4) 13 | for hex in hexstring:gmatch "[0-9a-f][0-9a-f]" do 14 | result[#result + 1] = "\\x" .. hex 15 | end 16 | else 17 | if line ~= 'Contents of section __TEXT,__cstring:' then 18 | stats = 0 19 | end 20 | end 21 | end 22 | if line == 'Contents of section __TEXT,__stubs:' then 23 | io.stderr:write("please chek shellcode find the dependency on external functions\n") 24 | os.exit(1) 25 | end 26 | end 27 | 28 | local f = assert(output and io.open(output, "w") or io.stdout) 29 | f:write("const char inject_code[] = {\n") 30 | f:write('"') 31 | f:write(table.concat(result)) 32 | f:write('"\n') 33 | f:write("};\n") 34 | -------------------------------------------------------------------------------- /compile/macos/make.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | if lm.platform == "darwin-arm64" then 4 | lm.target = "arm64-apple-macos11" 5 | else 6 | lm.target = "x86_64-apple-macos10.12" 7 | end 8 | 9 | lm.builddir = ("build/%s/%s"):format(lm.platform, lm.mode) 10 | lm:import "compile/common/bee.lua" 11 | require "compile.common.lua-debug" 12 | 13 | lm.runtime_platform = lm.platform 14 | require "compile.macos.runtime" 15 | require "compile.macos.shellcode" 16 | 17 | if lm.platform == "darwin-arm64" then 18 | require "compile.common.run_luamake" 19 | lm:build "x86_64" { 20 | rule = "run_luamake", 21 | inputs = "compile/macos/runtime.lua", 22 | args = { 23 | "-builddir", "build/darwin-x64/"..lm.mode, 24 | "-runtime_platform", "darwin-x64", 25 | "-target", "x86_64-apple-macos10.12", 26 | }, 27 | } 28 | end 29 | 30 | 31 | lm:executable 'process_inject_helper' { 32 | bindir = "publish/bin/", 33 | deps = { "shellcode" }, 34 | includes = { 35 | "3rd/bee.lua", 36 | }, 37 | sources = { 38 | "src/process_inject/macos/*.cpp", 39 | "src/process_inject/macos/process_helper.mm", 40 | }, 41 | } 42 | 43 | if lm.platform == "darwin-arm64" then 44 | lm:build "merge_launcher" { 45 | deps = { "x86_64", "launcher" }, 46 | args = { 47 | "lipo", "-create", "-output", "$out", "$in", 48 | "build/darwin-x64/"..lm.mode.."/bin/launcher.so", --TODO 49 | }, 50 | inputs = "$bin/launcher.so", 51 | outputs = "publish/bin/launcher.so", 52 | } 53 | else 54 | lm:copy "merge_launcher" { 55 | deps = "launcher", 56 | inputs = "$bin/launcher.so", 57 | outputs = "publish/bin/launcher.so" 58 | } 59 | end 60 | 61 | lm:default { 62 | "common", 63 | "lua-debug", 64 | "runtime", 65 | "process_inject_helper", 66 | "merge_launcher", 67 | lm.platform == "darwin-arm64" and "x86_64", 68 | } 69 | -------------------------------------------------------------------------------- /compile/macos/runtime.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | require "compile.common.config" 4 | require "compile.common.runtime" 5 | require "compile.common.launcher" 6 | 7 | lm:lua_dll 'launcher' { 8 | export_luaopen = "off", 9 | deps = { 10 | "launcher_source", 11 | }, 12 | } 13 | -------------------------------------------------------------------------------- /compile/macos/shellcode.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | lm:build "shellcode_compile" { 4 | args = { "clang", "$in", "-shared", "-fpic", "-o", "$out", "-std=c++17", "-O3", lm.target and "--target="..lm.target }, 5 | inputs = "src/process_inject/macos/shellcode.cpp", 6 | outputs = "$builddir/shellcode/shellcode.so", 7 | } 8 | 9 | lm:build "shellcode_dump" { 10 | args = { "objdump", "-s", "$in", ">", "$out" }, 11 | inputs = "$builddir/shellcode/shellcode.so", 12 | outputs = "$builddir/shellcode/shellcode.txt", 13 | } 14 | 15 | lm:runlua "shellcode_export" { 16 | script = "compile/macos/export_shellcode.lua", 17 | args = { "$in", "$out" }, 18 | inputs = "$builddir/shellcode/shellcode.txt", 19 | outputs = "src/process_inject/macos/shellcode.inl", 20 | } 21 | 22 | lm:phony "shellcode" { 23 | inputs = "src/process_inject/macos/shellcode.inl", 24 | outputs = "src/process_inject/macos/injectdll.cpp", 25 | } -------------------------------------------------------------------------------- /compile/test/make.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | local platform = require 'bee.platform' 3 | 4 | lm.builddir = ("build/test/%s"):format(lm.mode) 5 | 6 | if not lm.runtime_platform then 7 | lm.runtime_platform = lm.os..'-'..platform.Arch 8 | end 9 | 10 | local arch = lm.arch 11 | if not arch then 12 | arch = lm.runtime_platform:match "[%w]+-([%w]+)" 13 | end 14 | 15 | if arch == "x64" then 16 | arch = "x86_64" 17 | end 18 | 19 | require 'compile.common.frida' 20 | 21 | lm:executable "test_frida" { 22 | bindir = lm.builddir.."/tests", 23 | deps = "frida", 24 | includes = "3rd/frida_gum/gumpp", 25 | sources = "test/interceptor.cpp", 26 | } 27 | 28 | lm:executable "test_symbol" { 29 | bindir = lm.builddir.."/tests", 30 | deps = "frida", 31 | sources = "test/symbol/*.c", 32 | includes = { 33 | "3rd/frida_gum/"..lm.os.."-"..arch, 34 | "3rd/frida_gum/gumpp" 35 | }, 36 | } 37 | 38 | lm:executable "test_delayload" { 39 | sources = "test/delayload.cpp", 40 | includes = { 41 | "src/launcher", 42 | "3rd/lua/lua54" 43 | }, 44 | } 45 | 46 | lm:executable "testwaitdll" { 47 | sources = "test/waitdll.cpp", 48 | includes = { "3rd/lua/lua51" }, 49 | } 50 | 51 | lm:executable "test_thunk" { 52 | sources = "test/thunk.cpp", 53 | includes = { "src/luadebug" }, 54 | } 55 | 56 | lm:default { 57 | "test_frida", 58 | "test_delayload", 59 | "test_symbol", 60 | "testwaitdll", 61 | "test_thunk" 62 | } 63 | -------------------------------------------------------------------------------- /compile/windows/lua-debug.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/actboy168/lua-debug/0bd08237866d3dc5d3654d99fa6849b11e45bef1/compile/windows/lua-debug.ico -------------------------------------------------------------------------------- /compile/windows/lua-debug.rc: -------------------------------------------------------------------------------- 1 | #include "Windows.h" 2 | 10086 ICON "compile/windows/lua-debug.ico" 3 | -------------------------------------------------------------------------------- /compile/windows/make.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | lm.arch = "x86" 4 | lm.runtime_platform = "win32-ia32" 5 | 6 | require "compile.windows.runtime" 7 | require "compile.common.run_luamake" 8 | 9 | lm:build "x86_64" { 10 | rule = "run_luamake", 11 | inputs = "compile/windows/runtime.lua", 12 | args = { 13 | "-builddir", "build/win32-x64/"..lm.mode, 14 | "-runtime_platform", "win32-x64", 15 | "-arch", "x86_64" 16 | }, 17 | } 18 | 19 | lm:import "compile/common/bee.lua" 20 | require "compile.common.lua-debug" 21 | 22 | lm:default { 23 | "common", 24 | lm.mode ~= "debug" and "copy_vcredist", 25 | "lua-debug", 26 | "launcher", 27 | "runtime", 28 | "x86_64", 29 | } 30 | -------------------------------------------------------------------------------- /compile/windows/runtime.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | lm:conf { 4 | flags = "/utf-8", 5 | } 6 | 7 | require "compile.common.config" 8 | 9 | local platform = lm.runtime_platform 10 | 11 | lm.defines = "_WIN32_WINNT=0x0602" 12 | lm.builddir = ("build/%s/%s"):format(platform, lm.mode) 13 | 14 | require "compile.common.runtime" 15 | require "compile.common.launcher" 16 | 17 | if lm.mode ~= "debug" then 18 | lm:msvc_copydll "copy_vcredist" { 19 | type = "vcrt", 20 | outputs = 'publish/vcredist/'..platform 21 | } 22 | end 23 | 24 | local ArchAlias = { 25 | ["win32-x64"] = "x64", 26 | ["win32-ia32"] = "x86", 27 | } 28 | 29 | lm:lua_dll ('launcher.'..ArchAlias[platform]) { 30 | bindir = "publish/bin", 31 | export_luaopen = "off", 32 | deps = { 33 | "launcher_source", 34 | } 35 | } 36 | 37 | lm:phony "launcher" { 38 | deps = 'launcher.'..ArchAlias[platform] 39 | } 40 | -------------------------------------------------------------------------------- /docs/luadebug/README.md: -------------------------------------------------------------------------------- 1 | > 为什么需要luadebug? 2 | 3 | luadebug设计的首要目标是尽可能减少调试器对调试目标的影响。虽然lua-debug看起来和其它Lua调试器一样大部分的代码是用Lua编写,但这些Lua没有在调试目标的VM上执行。luadebug内嵌了一个Lua 5.4的VM,无论调试目标是Lua5.1或者Lua5.4,调试器的代码始终是跑在luadebug内嵌的Lua 5.4上。调试器只能通过luadebug提供的API读取和修改调试目标的数据。这样可以最大限度地降低调试器对调试目标的影响。 4 | 5 | 因此luadebug可以被调试目标和调试器的代码分别加载,但对它们提供的API并不相同。 6 | -------------------------------------------------------------------------------- /docs/luadebug/init.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | --- 4 | ---@class LuaDebug 5 | ---在调试目标中管理调试器VM。 6 | --- 7 | local rdebug = {} 8 | 9 | ---@param script string 10 | ---@param init function | nil 11 | ---启动调试器VM,执行script的代码。init是可选参数,可以传入一个不带upvalue的c function。它将会作为执行script时的第一个参数传入。 12 | --- 13 | function rdebug.start(script, init) 14 | end 15 | 16 | --- 17 | ---关闭调试器VM。 18 | --- 19 | function rdebug.clear() 20 | end 21 | 22 | --- 23 | ---@param name string 24 | ---@vararg any 25 | ---@return boolean | nil 26 | ---触发一个事件给调试器VM。它会等调试器VM处理完毕才会返回。如果失败或者返回值不是boolean,则返回nil,否则返回事件的返回值。 27 | --- 28 | function rdebug.event(name, ...) 29 | end 30 | 31 | --- 32 | ---@param str string 33 | ---@return string 34 | ---字符串编码转换,从ansi到utf8。 35 | --- 36 | function rdebug.a2u(str) 37 | end 38 | 39 | --- 40 | ---@param name string 41 | ---@param value string 42 | ---设置环境变量,可以被os.getenv获取。(如果set和get为同一个CRT) 43 | --- 44 | function rdebug.setenv(name, value) 45 | end 46 | 47 | return rdebug 48 | -------------------------------------------------------------------------------- /docs/luadebug/stdio.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | --- 4 | ---@class LuaDebugStdio 5 | ---用于截获调试目标中的输出。 6 | --- 7 | local stdio = {} 8 | 9 | --- 10 | ---@class LuaDebugRedirect 11 | --- 12 | local redirect = {} 13 | 14 | --- 15 | ---@param n integer | nil 16 | ---@return string 17 | ---读取n个字节的数据。如果没有n,则读到文件结束为止。 18 | --- 19 | function redirect:read(n) 20 | end 21 | 22 | --- 23 | ---@return integer 24 | ---获取当前有多少数据可读。 25 | --- 26 | function redirect:peek() 27 | end 28 | 29 | --- 30 | ---关闭重定向。 31 | --- 32 | function redirect:close() 33 | end 34 | 35 | --- 36 | ---@param iotype string 37 | ---@return LuaDebugRedirect 38 | ---重定向调试目标的stdout/stderr。 39 | --- 40 | function stdio.redirect(iotype) 41 | end 42 | 43 | --- 44 | ---@param enable boolean 45 | ---启用`print`事件。 46 | ---调试目标每次调用print,都会触发print事件,事件返回值可以决定是否忽略本次的print。 47 | --- 48 | function stdio.open_print(enable) 49 | end 50 | 51 | --- 52 | ---@param enable boolean 53 | ---启用`iowrite`事件。 54 | ---调试目标每次调用io.write/io.stdout:write,都会触发iowrite事件,事件返回值可以决定是否忽略本次的write。 55 | --- 56 | function stdio.open_iowrite(enable) 57 | end 58 | 59 | return stdio 60 | -------------------------------------------------------------------------------- /docs/luadebug/utility.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | --- 4 | ---@class LuaDebugUtility 5 | --- 6 | local utility = {} 7 | 8 | --- 9 | --- * Windows下的行为 10 | --- 1. 向主线程发送WM_QUIT消息。 11 | --- * 非Windows下的行为 12 | --- 1. 什么都不做 13 | --- 14 | function utility.closewindow() 15 | end 16 | 17 | --- 18 | --- 发送SIGINT信号。 19 | --- 20 | function utility.closeprocess() 21 | end 22 | 23 | return utility 24 | -------------------------------------------------------------------------------- /examples/attach/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "attach", 6 | "type": "lua", 7 | "request": "attach", 8 | "stopOnEntry": true, 9 | "address": "127.0.0.1:12306" 10 | }, 11 | { 12 | "name": "launch", 13 | "type": "lua", 14 | "request": "launch", 15 | "stopOnEntry": true, 16 | "runtimeExecutable": "${workspaceFolder}/../../publish/runtime/win32-x64/lua-latest/lua.exe", 17 | "runtimeArgs": "${workspaceFolder}/test.lua", 18 | "inject": "none", 19 | "address": "127.0.0.1:12306" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /examples/attach/README.md: -------------------------------------------------------------------------------- 1 | * Run `lua test.lua`. 2 | * Open VSCode, and press `F5`. 3 | -------------------------------------------------------------------------------- /examples/attach/debugger.lua: -------------------------------------------------------------------------------- 1 | local INSIDERS = false 2 | 3 | local function searchDebugger(luaDebugs, tag) 4 | if INSIDERS then 5 | tag = tag .. "-insiders" 6 | end 7 | local isWindows = package.config:sub(1,1) == "\\" 8 | local extensionPath = (isWindows and os.getenv "USERPROFILE" or os.getenv "HOME") .. "/.vscode"..tag.."/extensions" 9 | local command = isWindows and ("dir /B " .. extensionPath:gsub("/", "\\") .. " 2>nul") or ("ls -1 " .. extensionPath .. " 2>/dev/null") 10 | for name in io.popen(command):lines() do 11 | local a, b, c = name:match "^actboy168%.lua%-debug%-(%d+)%.(%d+)%.(%d+)" 12 | if a then 13 | luaDebugs[#luaDebugs+1] = { a * 10000 + b * 100 + c, extensionPath .. "/" .. name } 14 | end 15 | end 16 | end 17 | 18 | local function getLatestDebugger() 19 | local luaDebugs = {} 20 | searchDebugger(luaDebugs, "") 21 | searchDebugger(luaDebugs, "-server") 22 | if #luaDebugs == 0 then 23 | error "Cant find `actboy168.lua-debug`" 24 | end 25 | table.sort(luaDebugs, function (a, b) return a[1] == b[1] and a[2] > b[2] or a[1] > b[1] end) 26 | return luaDebugs[1][2] 27 | end 28 | 29 | local function dofile(filename) 30 | local load = _VERSION == "Lua 5.1" and loadstring or load 31 | local f = assert(io.open(filename)) 32 | local str = f:read "*a" 33 | f:close() 34 | return assert(load(str, "=(debugger.lua)"))(filename) 35 | end 36 | 37 | local path = getLatestDebugger() 38 | return dofile(path .. "/script/debugger.lua") 39 | -------------------------------------------------------------------------------- /examples/attach/test.lua: -------------------------------------------------------------------------------- 1 | require "debugger":start "127.0.0.1:12306":event "wait" 2 | print "ok" 3 | -------------------------------------------------------------------------------- /examples/attach_thread/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "test", 6 | "type": "lua", 7 | "request": "launch", 8 | "stopOnEntry": true, 9 | "stopOnThreadEntry": true, 10 | "luaexe": "luamake", 11 | "path": null, 12 | "cpath": null, 13 | "arg0": ["lua"], 14 | "program": "${workspaceFolder}/test.lua", 15 | "skipFiles": [ 16 | "${exe}/*" 17 | ] 18 | } 19 | ] 20 | } -------------------------------------------------------------------------------- /examples/attach_thread/README.md: -------------------------------------------------------------------------------- 1 | * Open VSCode, and press `F5`. 2 | -------------------------------------------------------------------------------- /examples/attach_thread/debugger.lua: -------------------------------------------------------------------------------- 1 | local function dofile(filename) 2 | local f = assert(io.open(filename)) 3 | local str = f:read "a" 4 | f:close() 5 | return assert(load(str, "=(debugger.lua)"))(filename) 6 | end 7 | 8 | local path = os.getenv "LUA_DEBUG_PATH" 9 | if path then 10 | return dofile(path .. "/script/debugger.lua") 11 | : attach {} 12 | end 13 | -------------------------------------------------------------------------------- /examples/attach_thread/test.lua: -------------------------------------------------------------------------------- 1 | local thread = require "bee.thread" 2 | local thd = thread.thread [[dofile "thread.lua"]] 3 | thread.wait(thd) 4 | -------------------------------------------------------------------------------- /examples/attach_thread/thread.lua: -------------------------------------------------------------------------------- 1 | require "debugger" : event "wait" 2 | print "hello thread" 3 | -------------------------------------------------------------------------------- /examples/standalone/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "test", 6 | "type": "lua", 7 | "request": "attach", 8 | "stopOnEntry": true, 9 | "address": "127.0.0.1:12306", 10 | "sourceMaps": [ 11 | [ 12 | "./*", 13 | "${workspaceFolder}/*" 14 | ] 15 | ] 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /examples/standalone/README.md: -------------------------------------------------------------------------------- 1 | * Run `lua test.lua`. 2 | * Open VSCode, and press `F5`. 3 | -------------------------------------------------------------------------------- /examples/standalone/debugger.lua: -------------------------------------------------------------------------------- 1 | local function dofile(filename) 2 | local load = _VERSION == "Lua 5.1" and loadstring or load 3 | local f = assert(io.open(filename)) 4 | local str = f:read "*a" 5 | f:close() 6 | return assert(load(str, "=(debugger.lua)"))(filename) 7 | end 8 | 9 | local path = "../../publish" 10 | return dofile(path .. "/script/debugger.lua") 11 | -------------------------------------------------------------------------------- /examples/standalone/test.lua: -------------------------------------------------------------------------------- 1 | require "debugger":start "0.0.0.0:12306":event "wait" 2 | print "ok" -------------------------------------------------------------------------------- /extension/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/actboy168/lua-debug/0bd08237866d3dc5d3654d99fa6849b11e45bef1/extension/images/logo.png -------------------------------------------------------------------------------- /extension/js/descriptorFactory.js: -------------------------------------------------------------------------------- 1 | const vscode = require("vscode"); 2 | const path = require("path"); 3 | const os = require('os'); 4 | const extension = require("./extension"); 5 | 6 | function createDebugAdapterDescriptor(session, executable) { 7 | if (typeof session.configuration.debugServer === 'number') { 8 | return new vscode.DebugAdapterServer(session.configuration.debugServer); 9 | } 10 | let ROOT = extension.extensionDirectory 11 | let EXE = os.platform() == "win32" ? ".exe" : "" 12 | let runtime = path.join(ROOT, 'bin', 'lua-debug' + EXE) 13 | return new vscode.DebugAdapterExecutable(runtime); 14 | } 15 | 16 | exports.createDebugAdapterDescriptor = createDebugAdapterDescriptor; 17 | -------------------------------------------------------------------------------- /extension/js/trackerFactory.js: -------------------------------------------------------------------------------- 1 | const vscode = require("vscode"); 2 | const fs = require('fs'); 3 | 4 | async function onWillReceiveMessage(m) { 5 | if (m.type == "request" 6 | && m.command == "setBreakpoints" 7 | && typeof m.arguments.source == 'object' 8 | && typeof m.arguments.source.path == 'string' 9 | ) { 10 | for (const doc of vscode.workspace.textDocuments) { 11 | if (doc.fileName == m.arguments.source.path) { 12 | m.arguments.sourceContent = doc.getText(); 13 | return; 14 | } 15 | } 16 | try { 17 | //let uri = vscode.Uri.file(m.arguments.source.path); 18 | //m.arguments.sourceContent = await vscode.workspace.fs.readFile(uri).then((bytes) => { 19 | // return new TextDecoder("utf-8").decode(bytes); 20 | //}); 21 | m.arguments.sourceContent = fs.readFileSync(m.arguments.source.path, 'utf8'); 22 | } catch (error) { 23 | } 24 | } 25 | } 26 | 27 | function createDebugAdapterTracker(session) { 28 | return { 29 | onWillReceiveMessage: onWillReceiveMessage, 30 | }; 31 | } 32 | 33 | exports.createDebugAdapterTracker = createDebugAdapterTracker; 34 | -------------------------------------------------------------------------------- /extension/package.nls.json: -------------------------------------------------------------------------------- 1 | { 2 | "lua.debug.launch.console.description": "The specified console to launch the program.", 3 | "lua.debug.launch.console.internalConsole.description": "VS Code debug console (input stream not supported).", 4 | "lua.debug.launch.console.integratedTerminal.description": "VS Code integrated terminal.", 5 | "lua.debug.launch.console.externalTerminal.description": "External terminal that can be configured in user settings.", 6 | "lua.debug.launch.luaVersion.description": "Default lua version.", 7 | "lua.debug.launch.luaArch.description": "Default lua arch.", 8 | "lua.debug.launch.sourceCoding.description": "Source encoding.", 9 | "lua.debug.launch.path.description": "Search path for Lua programs", 10 | "lua.debug.launch.cpath.description": "Search path for native libraries" 11 | } 12 | -------------------------------------------------------------------------------- /extension/script/attach.lua: -------------------------------------------------------------------------------- 1 | local path, pid = ... 2 | if _VERSION == nil 3 | or type == nil 4 | or assert == nil 5 | or tostring == nil 6 | or error == nil 7 | or dofile == nil 8 | or io == nil 9 | or os == nil 10 | or debug == nil 11 | or package == nil 12 | or string == nil 13 | then 14 | return "wait initialized" 15 | end 16 | 17 | local is_luajit = tostring(assert):match('builtin') ~= nil 18 | if is_luajit and jit == nil then 19 | return "wait initialized" 20 | end 21 | 22 | local function dofile(filename) 23 | local load = _VERSION == "Lua 5.1" and loadstring or load 24 | local f = assert(io.open(filename)) 25 | local str = f:read "*a" 26 | f:close() 27 | return assert(load(str, "=(debugger.lua)"))(filename) 28 | end 29 | local function getLuaVersion() 30 | local ipc = dofile(path.."/script/common/ipc.lua") 31 | local fd = ipc(path, pid, "luaVersion") 32 | if not fd then 33 | return 34 | end 35 | local result = fd:read "a" 36 | fd:close() 37 | return result 38 | end 39 | local dbg = dofile(path.."/script/debugger.lua") 40 | dbg:start { 41 | address = ("@%s/tmp/pid_%s"):format(path, pid), 42 | luaVersion = getLuaVersion(), 43 | } 44 | dbg:event "wait" 45 | return "ok" -------------------------------------------------------------------------------- /extension/script/backend/bootstrap.lua: -------------------------------------------------------------------------------- 1 | local thread = require "bee.thread" 2 | local channel = require "bee.channel" 3 | 4 | local m = {} 5 | 6 | local function hasMaster() 7 | return channel.query "DbgMaster" ~= nil 8 | end 9 | 10 | local function initMaster(rootpath, address) 11 | if hasMaster() then 12 | return 13 | end 14 | local chan = channel.create "DbgMaster" 15 | local mt = thread.create(([[ 16 | local rootpath = %q 17 | package.path = rootpath.."/script/?.lua" 18 | local log = require "common.log" 19 | log.file = rootpath.."/master.log" 20 | local ok, err = xpcall(function() 21 | local socket = require "common.socket"(%q) 22 | local master = require "backend.master.mgr" 23 | master.init(socket) 24 | master.update() 25 | end, debug.traceback) 26 | if not ok then 27 | log.error("ERROR:" .. err) 28 | end 29 | ]]):format( 30 | rootpath, 31 | address 32 | )) 33 | ExitGuard = setmetatable({}, {__gc=function() 34 | chan:push(nil, "EXIT") 35 | thread.wait(mt) 36 | channel.destroy("DbgMaster") 37 | end}) 38 | end 39 | 40 | local function startWorker(rootpath) 41 | local log = require 'common.log' 42 | log.file = rootpath..'/worker.log' 43 | require 'backend.worker' 44 | end 45 | 46 | function m.start(rootpath, address) 47 | initMaster(rootpath, address) 48 | startWorker(rootpath) 49 | end 50 | 51 | function m.attach(rootpath) 52 | if hasMaster() then 53 | startWorker(rootpath) 54 | end 55 | end 56 | 57 | return m 58 | -------------------------------------------------------------------------------- /extension/script/backend/event.lua: -------------------------------------------------------------------------------- 1 | local _events = {} 2 | local ev = {} 3 | 4 | function ev.emit(name, ...) 5 | local event = _events[name] 6 | if event then 7 | for i = 1, #event do 8 | event[i](...) 9 | end 10 | end 11 | end 12 | 13 | function ev.on(name, f) 14 | local event = _events[name] 15 | if event then 16 | event[#event+1] = f 17 | else 18 | _events[name] = {f} 19 | end 20 | end 21 | 22 | return ev 23 | -------------------------------------------------------------------------------- /extension/script/backend/master/response.lua: -------------------------------------------------------------------------------- 1 | local mgr = require 'backend.master.mgr' 2 | 3 | local response = {} 4 | 5 | function response.error(req, msg) 6 | mgr.clientSend { 7 | type = 'response', 8 | seq = mgr.newSeq(), 9 | command = req.command, 10 | request_seq = req.seq, 11 | success = false, 12 | message = msg, 13 | } 14 | end 15 | 16 | function response.success(req, body) 17 | mgr.clientSend { 18 | type = 'response', 19 | seq = mgr.newSeq(), 20 | command = req.command, 21 | request_seq = req.seq, 22 | success = true, 23 | body = body, 24 | } 25 | end 26 | 27 | function response.initialize(req) 28 | if req.__norepl then 29 | mgr.newSeq() 30 | return 31 | end 32 | mgr.clientSend { 33 | type = 'response', 34 | seq = mgr.newSeq(), 35 | command = req.command, 36 | request_seq = req.seq, 37 | success = true, 38 | body = require 'common.capabilities', 39 | } 40 | end 41 | 42 | function response.threads(req, threads) 43 | mgr.clientSend { 44 | type = 'response', 45 | seq = mgr.newSeq(), 46 | command = req.command, 47 | request_seq = req.seq, 48 | success = true, 49 | body = { 50 | threads = threads 51 | }, 52 | } 53 | end 54 | 55 | return response 56 | -------------------------------------------------------------------------------- /extension/script/backend/worker/crc32.lua: -------------------------------------------------------------------------------- 1 | local string_byte = string.byte 2 | local crc_table = {} 3 | local POLY = 0xEDB88320 4 | 5 | for i = 0, 255 do 6 | local crc = i 7 | for _ = 1, 8 do 8 | local b = crc & 1 9 | crc = crc >> 1 10 | if b == 1 then crc = crc ~ POLY end 11 | end 12 | crc_table[i] = crc 13 | end 14 | 15 | return function (s, crc) 16 | crc = ~(crc or 0) & 0xffffffff 17 | local sz = #s 18 | for i = 1, sz - 15, 16 do 19 | local s0, s1, s2, s3, s4, s5, s6, s7 20 | , s8, s9, sa, sb, sc, sd, se, sf = string_byte(s, i, i + 15) 21 | crc = crc_table[(crc & 0xFF) ~ s0] ~ (crc >> 8) 22 | crc = crc_table[(crc & 0xFF) ~ s1] ~ (crc >> 8) 23 | crc = crc_table[(crc & 0xFF) ~ s2] ~ (crc >> 8) 24 | crc = crc_table[(crc & 0xFF) ~ s3] ~ (crc >> 8) 25 | crc = crc_table[(crc & 0xFF) ~ s4] ~ (crc >> 8) 26 | crc = crc_table[(crc & 0xFF) ~ s5] ~ (crc >> 8) 27 | crc = crc_table[(crc & 0xFF) ~ s6] ~ (crc >> 8) 28 | crc = crc_table[(crc & 0xFF) ~ s7] ~ (crc >> 8) 29 | crc = crc_table[(crc & 0xFF) ~ s8] ~ (crc >> 8) 30 | crc = crc_table[(crc & 0xFF) ~ s9] ~ (crc >> 8) 31 | crc = crc_table[(crc & 0xFF) ~ sa] ~ (crc >> 8) 32 | crc = crc_table[(crc & 0xFF) ~ sb] ~ (crc >> 8) 33 | crc = crc_table[(crc & 0xFF) ~ sc] ~ (crc >> 8) 34 | crc = crc_table[(crc & 0xFF) ~ sd] ~ (crc >> 8) 35 | crc = crc_table[(crc & 0xFF) ~ se] ~ (crc >> 8) 36 | crc = crc_table[(crc & 0xFF) ~ sf] ~ (crc >> 8) 37 | end 38 | for i = sz - (sz % 16) + 1, sz do 39 | crc = crc_table[(crc & 0xFF) ~ string_byte(s, i)] ~ (crc >> 8) 40 | end 41 | return ~crc & 0xffffffff 42 | end 43 | -------------------------------------------------------------------------------- /extension/script/backend/worker/eval/verify.lua: -------------------------------------------------------------------------------- 1 | local source = ... 2 | if _VERSION == "Lua 5.1" then 3 | load = loadstring 4 | end 5 | assert(load("return " .. source, '=(EVAL)')) 6 | -------------------------------------------------------------------------------- /extension/script/backend/worker/luaver.lua: -------------------------------------------------------------------------------- 1 | local rdebug = require 'luadebug.visitor' 2 | 3 | local m = {} 4 | 5 | function m.init() 6 | local version = rdebug.fieldv(rdebug._G, "_VERSION") 7 | local ver = 0 8 | if type(version) ~= "string" then 9 | m.LUAVERSION = 54 10 | return 11 | end 12 | for n in version:gmatch "%d" do 13 | ver = ver * 10 + (math.tointeger(n) or 0) 14 | end 15 | m.LUAVERSION = ver 16 | if ver == 51 then 17 | m.isjit = rdebug.fieldv(rdebug._G, "jit") ~= nil 18 | end 19 | end 20 | 21 | return m 22 | -------------------------------------------------------------------------------- /extension/script/bootstrap.lua: -------------------------------------------------------------------------------- 1 | local root; do 2 | local pattern = "[/][^/]+" 3 | root = package.cpath:match("(.+)"..pattern..pattern.."$") 4 | end 5 | package.path = root .. "/script/?.lua" 6 | 7 | for i = 1, #arg do 8 | if arg[i] == '-e' then 9 | i = i + 1 10 | local expr = assert(arg[i], "'-e' needs argument") 11 | assert(load(expr, "=(command line)"))() 12 | table.remove(arg, i) 13 | table.remove(arg, i - 1) 14 | break 15 | end 16 | end 17 | 18 | for i = #arg, 1, -1 do 19 | if arg[i] == '' then 20 | table.remove(arg, i) 21 | end 22 | end 23 | 24 | local func = assert(loadfile(root .. "/script/frontend/main.lua")) 25 | func(arg[1]) -------------------------------------------------------------------------------- /extension/script/common/ipc.lua: -------------------------------------------------------------------------------- 1 | return function(root, pid, name, mode) 2 | return io.open(tostring(root).."/tmp/ipc_"..pid.."_"..name, mode) 3 | end 4 | -------------------------------------------------------------------------------- /extension/script/common/protocol.lua: -------------------------------------------------------------------------------- 1 | local json = require 'common.json' 2 | 3 | local m = {} 4 | 5 | local function recv(s, bytes) 6 | bytes = bytes or '' 7 | s.bytes = s.bytes and (s.bytes .. bytes) or bytes 8 | while true do 9 | if s.length then 10 | if s.length <= #s.bytes then 11 | local res = s.bytes:sub(1, s.length) 12 | s.bytes = s.bytes:sub(s.length + 1) 13 | s.length = nil 14 | return res 15 | end 16 | return 17 | end 18 | local pos = s.bytes:find('\r\n\r\n', 1, true) 19 | if not pos then 20 | return 21 | end 22 | if pos <= 15 or s.bytes:sub(1, 16) ~= 'Content-Length: ' then 23 | return error('Invalid protocol.') 24 | end 25 | local length = tonumber(s.bytes:sub(17, pos-1)) 26 | if not length then 27 | return error('Invalid protocol.') 28 | end 29 | s.bytes = s.bytes:sub(pos + 4) 30 | s.length = length 31 | end 32 | end 33 | 34 | function m.recv(bytes, stat) 35 | local pkg = recv(stat, bytes) 36 | if pkg then 37 | if stat.debug then print('[recv]', pkg) end 38 | return json.decode(pkg) 39 | end 40 | end 41 | 42 | function m.send(cmd, stat) 43 | --if cmd.type == 'response' and cmd.success == false then 44 | -- error(debug.traceback(cmd.message)) 45 | --end 46 | local pkg = json.encode(cmd) 47 | if stat.debug then print('[send]', pkg) end 48 | return ('Content-Length: %d\r\n\r\n%s'):format(#pkg, pkg) 49 | end 50 | 51 | return m 52 | -------------------------------------------------------------------------------- /extension/script/frontend/main.lua: -------------------------------------------------------------------------------- 1 | local port = ... 2 | local sys = require 'bee.sys' 3 | local socket = require 'common.socket' 4 | local proxy = require 'frontend.proxy' 5 | local vscode 6 | WORKDIR = sys.exe_path():parent_path():parent_path() 7 | 8 | local function run() 9 | if port then 10 | vscode = socket('listen:127.0.0.1:'..port) 11 | else 12 | vscode = require 'frontend.stdio' 13 | --vscode.debug(true) 14 | end 15 | proxy.init(vscode) 16 | 17 | while true do 18 | proxy.update() 19 | end 20 | end 21 | 22 | local log = require 'common.log' 23 | log.root = (WORKDIR / "script"):string() 24 | log.file = (WORKDIR / "client.log"):string() 25 | 26 | local ok, errmsg = xpcall(run, debug.traceback) 27 | if not ok then 28 | log.error(errmsg) 29 | end 30 | -------------------------------------------------------------------------------- /extension/script/frontend/platform_os.lua: -------------------------------------------------------------------------------- 1 | local platform = require 'bee.platform' 2 | 3 | local m = { 4 | os = platform.os, 5 | } 6 | 7 | function m.init(args) 8 | if platform.os == "windows" and args.useWSL then 9 | m.os = "linux" 10 | args.useWSL = true 11 | return 12 | end 13 | m.os = platform.os 14 | args.useWSL = nil 15 | end 16 | 17 | return setmetatable(m, {__call = function() return m.os end}) 18 | -------------------------------------------------------------------------------- /extension/script/frontend/powershell.lua: -------------------------------------------------------------------------------- 1 | local fs = require "bee.filesystem" 2 | 3 | local function split(s) 4 | local r = {} 5 | s:gsub('[^;]*', function (w) r[#r+1] = w end) 6 | return r 7 | end 8 | 9 | local dirs = split(os.getenv "PATH" or "") 10 | local exts = split(os.getenv "PATHEXT" or "") 11 | 12 | local function where(name) 13 | for _, dir in ipairs(dirs) do 14 | for _, ext in ipairs(exts) do 15 | if fs.exists(fs.path(dir) / (name..ext)) then 16 | return true 17 | end 18 | end 19 | end 20 | end 21 | 22 | return function () 23 | for _, name in ipairs {"pwsh", "powershell"} do 24 | if where(name) then 25 | return name 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /extension/script/frontend/query_process.lua: -------------------------------------------------------------------------------- 1 | local platform = require "bee.platform" 2 | local COMMAND 3 | local SKIP = 0 4 | if platform.os == "windows" then 5 | local pwsh = require "frontend.powershell"() 6 | if pwsh then 7 | COMMAND = pwsh .. " -NoProfile -Command \"Get-CimInstance Win32_Process | Select-Object Name,ProcessId\"" 8 | SKIP = 3 9 | else 10 | COMMAND = "wmic process get name,processid" 11 | SKIP = 1 12 | end 13 | elseif platform.os == "linux" then 14 | COMMAND = "ps axww -o comm=,pid=" 15 | elseif platform.os == "macos" then 16 | COMMAND = "ps axww -o comm=,pid= -c" 17 | else 18 | error("Unsupported OS:"..platform.os) 19 | end 20 | return function (n) 21 | local res = {} 22 | local f = assert(io.popen(COMMAND)) 23 | for _ = 1, SKIP do 24 | f:read "l" 25 | end 26 | for line in f:lines() do 27 | local name, processid = line:match "^([^%s].*[^%s])%s+(%d+)%s*$" 28 | if n == name then 29 | res[#res+1] = tonumber(processid) 30 | end 31 | end 32 | return res 33 | end 34 | -------------------------------------------------------------------------------- /extension/script/frontend/stdio.lua: -------------------------------------------------------------------------------- 1 | local subprocess = require 'bee.subprocess' 2 | local platform = require 'bee.platform' 3 | local proto = require 'common.protocol' 4 | local STDIN = io.stdin 5 | local STDOUT = io.stdout 6 | local peek = subprocess.peek 7 | if platform.os == "windows" then 8 | local windows = require 'bee.windows' 9 | windows.filemode(STDIN, 'b') 10 | windows.filemode(STDOUT, 'b') 11 | end 12 | STDIN:setvbuf 'no' 13 | STDOUT:setvbuf 'no' 14 | 15 | local function send(v) 16 | STDOUT:write(v) 17 | end 18 | local function recv() 19 | local n = peek(STDIN) 20 | if n == nil or n == 0 then 21 | return "" 22 | end 23 | return STDIN:read(n) 24 | end 25 | 26 | local m = {} 27 | local stat = {} 28 | function m.debug(v) 29 | stat.debug = v 30 | end 31 | function m.sendmsg(pkg) 32 | send(proto.send(pkg, stat)) 33 | end 34 | function m.recvmsg() 35 | return proto.recv(recv(), stat) 36 | end 37 | 38 | return m 39 | -------------------------------------------------------------------------------- /extension/script/launch.lua: -------------------------------------------------------------------------------- 1 | local path = debug.getinfo(1,"S").source:sub(2) 2 | :match("(.+)[/\\][%w_.-]+$") 3 | :match("(.+)[/\\][%w_.-]+$") 4 | 5 | local function dofile(filename) 6 | local load = _VERSION == "Lua 5.1" and loadstring or load 7 | local f = assert(io.open(filename)) 8 | local str = f:read "*a" 9 | f:close() 10 | return assert(load(str, "=(debugger.lua)"))(filename) 11 | end 12 | local dbg = dofile(path.."/script/debugger.lua") 13 | dbg:set_wait("DBG", function(str) 14 | local params = {} 15 | str:gsub('[^/]+', function (w) params[#params+1] = w end) 16 | 17 | local cfg 18 | if not params[1]:match "^%d+$" then 19 | local client, address = params[1]:match "^([sc]):(.*)$" 20 | cfg = { address = address, client = (client == "c") } 21 | else 22 | local pid = params[1] 23 | cfg = { address = ("@%s/tmp/pid_%s"):format(path, pid) } 24 | end 25 | if params[2] == "ansi" then 26 | cfg.ansi = true 27 | if params[3] then 28 | cfg.luaVersion = params[3] 29 | end 30 | else 31 | if params[2] then 32 | cfg.luaVersion = params[2] 33 | end 34 | end 35 | dbg:start(cfg) 36 | end) 37 | -------------------------------------------------------------------------------- /make.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | require "compile.common.detect_platform" 4 | require "compile.common.config" 5 | 6 | if lm.test then 7 | require "compile.test.make" 8 | return 9 | end 10 | 11 | require "compile.common.make" 12 | 13 | if lm.os == "windows" then 14 | require "compile.windows.make" 15 | elseif lm.os == "macos" then 16 | require "compile.macos.make" 17 | else 18 | require "compile.linux.make" 19 | end 20 | -------------------------------------------------------------------------------- /src/launcher/autoattach/autoattach.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace luadebug::autoattach { 6 | enum class attach_status { 7 | success, 8 | fatal, 9 | wait, 10 | }; 11 | enum class work_mode { 12 | launch, 13 | attach, 14 | }; 15 | attach_status attach_lua(lua::state L); 16 | void initialize(work_mode mode); 17 | } 18 | -------------------------------------------------------------------------------- /src/launcher/autoattach/ctx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace luadebug::autoattach { 13 | struct ctx { 14 | std::mutex mtx; 15 | work_mode mode; 16 | std::optional lua_module; 17 | bool wait_dll = false; 18 | 19 | static ctx* get() { 20 | static ctx obj; 21 | return &obj; 22 | } 23 | }; 24 | } -------------------------------------------------------------------------------- /src/launcher/autoattach/lua_module.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace luadebug::autoattach { 9 | struct watchdog; 10 | enum class lua_version { 11 | unknown, 12 | luajit, 13 | lua51, 14 | lua52, 15 | lua53, 16 | lua54, 17 | }; 18 | struct lua_module { 19 | std::string path; 20 | std::string name; 21 | void* memory_address = 0; 22 | size_t memory_size = 0; 23 | lua_version version = lua_version::unknown; 24 | lua_resolver resolver; 25 | work_mode mode; 26 | struct watchdog* watchdog = nullptr; 27 | 28 | lua_module(work_mode mode) 29 | : mode(mode) {} 30 | lua_module(const lua_module&) = delete; 31 | lua_module& operator=(const lua_module&) = delete; 32 | 33 | lua_module(lua_module&& rhs) { 34 | swap(std::forward(rhs)); 35 | }; 36 | lua_module& operator=(lua_module&& rhs) { 37 | swap(std::forward(rhs)); 38 | return *this; 39 | }; 40 | 41 | void swap(lua_module&& rhs) { 42 | std::swap(path, rhs.path); 43 | std::swap(name, rhs.name); 44 | std::swap(memory_address, rhs.memory_address); 45 | std::swap(memory_size, rhs.memory_size); 46 | std::swap(version, rhs.version); 47 | std::swap(resolver, rhs.resolver); 48 | std::swap(mode, rhs.mode); 49 | std::swap(watchdog, rhs.watchdog); 50 | } 51 | 52 | bool initialize(); 53 | ~lua_module(); 54 | }; 55 | } 56 | -------------------------------------------------------------------------------- /src/launcher/autoattach/wait_dll.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace luadebug::autoattach { 6 | bool wait_dll(bool (*loaded)(const std::string &)); 7 | } 8 | -------------------------------------------------------------------------------- /src/launcher/hook/create_watchdog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace luadebug::lua { 9 | struct resolver; 10 | } 11 | 12 | namespace luadebug::autoattach { 13 | struct watchdog; 14 | watchdog* create_watchdog(work_mode mode, lua_version v, const lua::resolver& resolver); 15 | } 16 | -------------------------------------------------------------------------------- /src/launcher/hook/listener.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | namespace luadebug::autoattach { 6 | 7 | void common_listener::on_enter(Gum::InvocationContext* context) { 8 | watchdog* w = (watchdog*)context->get_listener_function_data_ptr(); 9 | w->watch_entry((uintptr_t)context->get_nth_argument_ptr(0)); 10 | } 11 | 12 | void luajit_global_listener::on_enter(Gum::InvocationContext* context) { 13 | watchdog* w = (watchdog*)context->get_listener_function_data_ptr(); 14 | w->watch_entry(global2state(context->get_nth_argument_ptr(0))); 15 | } 16 | 17 | void luajit_jit_listener::on_enter(Gum::InvocationContext* context) { 18 | watchdog* w = (watchdog*)context->get_listener_function_data_ptr(); 19 | w->watch_entry(jit2state(context->get_nth_argument_ptr(0))); 20 | } 21 | 22 | void ret_listener::on_leave(Gum::InvocationContext* context) { 23 | watchdog* w = (watchdog*)context->get_listener_function_data_ptr(); 24 | w->watch_entry((uintptr_t)context->get_return_value_ptr()); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/launcher/hook/listener.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace luadebug::autoattach { 6 | 7 | struct common_listener : Gum::NoLeaveInvocationListener { 8 | virtual ~common_listener() = default; 9 | virtual void on_enter(Gum::InvocationContext* context) override; 10 | }; 11 | 12 | struct luajit_global_listener : Gum::NoLeaveInvocationListener { 13 | virtual ~luajit_global_listener() = default; 14 | virtual void on_enter(Gum::InvocationContext* context) override; 15 | }; 16 | 17 | struct luajit_jit_listener : Gum::NoLeaveInvocationListener { 18 | virtual ~luajit_jit_listener() = default; 19 | virtual void on_enter(Gum::InvocationContext* context) override; 20 | }; 21 | 22 | struct ret_listener : Gum::NoEnterInvocationListener { 23 | virtual ~ret_listener() = default; 24 | virtual void on_leave(Gum::InvocationContext* context) override; 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /src/launcher/hook/luajit_listener.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | namespace luadebug::autoattach { 6 | uintptr_t jit2state(void* ctx) { 7 | auto j = (jit_State*)ctx; 8 | return (uintptr_t)j->L; 9 | } 10 | uintptr_t global2state(void* ctx) { 11 | auto g = (global_State*)ctx; 12 | return (uintptr_t)gco2th(gcref(g->cur_L)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/launcher/hook/luajit_listener.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace luadebug::autoattach { 6 | 7 | uintptr_t jit2state(void* ctx); 8 | uintptr_t global2state(void* ctx); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/launcher/hook/watch_point.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace luadebug::autoattach { 4 | watch_point::operator bool() const { 5 | return !!address; 6 | } 7 | bool watch_point::find_symbol(const lua::resolver& resolver) { 8 | address = (void*)resolver.find(funcname); 9 | return !!address; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/launcher/hook/watch_point.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace luadebug::autoattach { 8 | struct watch_point { 9 | enum class type { 10 | common, 11 | luajit_global, 12 | luajit_jit, 13 | ret, 14 | }; 15 | type listener; 16 | std::string_view funcname; 17 | void* address = nullptr; 18 | explicit operator bool() const; 19 | bool find_symbol(const lua::resolver& resolver); 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /src/launcher/hook/watchdog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace luadebug::autoattach { 15 | struct watchdog { 16 | static_assert(std::is_same_v); 17 | 18 | public: 19 | watchdog(); 20 | ~watchdog(); 21 | watchdog(const watchdog&) = delete; 22 | bool init(); 23 | bool init_watch(const lua::resolver& resolver, std::vector&& points); 24 | bool hook(); 25 | void unhook(); 26 | void watch_entry(lua::state L); 27 | void attach_lua(lua::state L, lua::debug ar); 28 | 29 | private: 30 | std::mutex mtx; 31 | std::vector watch_points; 32 | Gum::RefPtr interceptor; 33 | common_listener listener_common; 34 | luajit_global_listener listener_luajit_global; 35 | luajit_jit_listener listener_luajit_jit; 36 | ret_listener listener_ret; 37 | std::set lua_state_hooked; 38 | uint8_t luahook_index; 39 | lua::cfunction luahook_set = nullptr; 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /src/launcher/resolver/lua_resolver.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | namespace luadebug { 7 | static int (*_lua_pcall)(intptr_t L, int nargs, int nresults, int errfunc); 8 | static int _lua_pcallk(intptr_t L, int nargs, int nresults, int errfunc, intptr_t ctx, intptr_t k) { 9 | return _lua_pcall(L, nargs, nresults, errfunc); 10 | } 11 | static int (*_luaL_loadbuffer)(intptr_t L, const char* buff, size_t size, const char* name); 12 | static int _luaL_loadbufferx(intptr_t L, const char* buff, size_t size, const char* name, const char* mode) { 13 | return _luaL_loadbuffer(L, buff, size, name); 14 | } 15 | 16 | intptr_t lua_resolver::find_export(std::string_view name) const { 17 | return (intptr_t)Gum::Process::module_find_export_by_name(module_name.data(), name.data()); 18 | } 19 | 20 | intptr_t lua_resolver::find_symbol(std::string_view name) const { 21 | return (intptr_t)Gum::Process::module_find_symbol_by_name(module_name.data(), name.data()); 22 | } 23 | 24 | intptr_t lua_resolver::find(std::string_view name) const { 25 | using namespace std::string_view_literals; 26 | for (auto& finder : { &lua_resolver::find_export, &lua_resolver::find_symbol }) { 27 | if (auto result = (this->*finder)(name)) { 28 | return result; 29 | } 30 | if (name == "lua_pcallk"sv) { 31 | _lua_pcall = (decltype(_lua_pcall))(this->*finder)("lua_pcall"sv); 32 | if (_lua_pcall) { 33 | return (intptr_t)_lua_pcallk; 34 | } 35 | } else if (name == "luaL_loadbufferx"sv) { 36 | _luaL_loadbuffer = (decltype(_luaL_loadbuffer))(this->*finder)("luaL_loadbuffer"sv); 37 | if (_luaL_loadbuffer) { 38 | return (intptr_t)_luaL_loadbufferx; 39 | } 40 | } 41 | } 42 | return 0; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/launcher/resolver/lua_resolver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace luadebug { 8 | struct lua_resolver : lua::resolver { 9 | intptr_t find(std::string_view name) const override; 10 | intptr_t find_export(std::string_view name) const; 11 | intptr_t find_symbol(std::string_view name) const; 12 | std::string_view module_name; 13 | }; 14 | } -------------------------------------------------------------------------------- /src/launcher/util/bee_inline.cpp: -------------------------------------------------------------------------------- 1 | #if defined _WIN32 2 | # include 3 | #endif 4 | 5 | #include <3rd/fmt/format.cc> 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #if defined(_WIN32) 12 | # include 13 | # include 14 | # include 15 | # include 16 | #else 17 | # include 18 | # include 19 | # if defined(__APPLE__) 20 | # include 21 | # include 22 | # elif defined(__linux__) 23 | # include 24 | # include 25 | # elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) 26 | # include 27 | # include 28 | # endif 29 | #endif 30 | -------------------------------------------------------------------------------- /src/launcher/util/log.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #if !defined(__cpp_lib_format) 7 | namespace std { 8 | using ::fmt::format_string; 9 | } 10 | #endif 11 | 12 | #if !defined(NDEBUG) 13 | # define LUADEBUG_ENABLE_LOG 1 14 | #endif 15 | 16 | namespace luadebug::log { 17 | void init(bool attach); 18 | void notify_frontend(const std::string& msg); 19 | 20 | template 21 | inline void error(std::format_string fmt, T&&... args) { 22 | std::print(stderr, "[lua-debug][launcher]{}\n", std::format(fmt, std::forward(args)...)); 23 | } 24 | 25 | #if defined(LUADEBUG_ENABLE_LOG) 26 | template 27 | inline void info(std::format_string fmt, T&&... args) { 28 | error(fmt, std::forward(args)...); 29 | } 30 | #else 31 | template 32 | inline void info(std::format_string fmt, T&&... args) {} 33 | #endif 34 | 35 | template 36 | inline void fatal(std::format_string fmt, T&&... args) { 37 | auto msg = std::format(fmt, std::forward(args)...); 38 | #if defined(LUADEBUG_ENABLE_LOG) 39 | error("{}", msg); 40 | #endif 41 | notify_frontend(msg); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/luadebug/compat/5x/callinfo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "compat/internal.h" 4 | 5 | #if LUA_VERSION_NUM >= 504 6 | # define LUA_STKID(s) s.p 7 | #else 8 | # define LUA_STKID(s) s 9 | # define s2v(o) (o) 10 | #endif 11 | 12 | CallInfo* lua_getcallinfo(lua_State* L) { 13 | return L->ci; 14 | } 15 | 16 | inline Proto* func2proto(StkId func) { 17 | #if LUA_VERSION_NUM >= 502 18 | if (!ttisLclosure(s2v(func))) { 19 | return 0; 20 | } 21 | return clLvalue(s2v(func))->p; 22 | #else 23 | if (clvalue(func)->c.isC) { 24 | return 0; 25 | } 26 | return clvalue(func)->l.p; 27 | #endif 28 | } 29 | 30 | Proto* lua_ci2proto(CallInfo* ci) { 31 | StkId func = LUA_STKID(ci->func); 32 | return func2proto(func); 33 | } 34 | 35 | CallInfo* lua_debug2ci(lua_State* L, const lua_Debug* ar) { 36 | #if LUA_VERSION_NUM >= 502 37 | return ar->i_ci; 38 | #else 39 | return L->base_ci + ar->i_ci; 40 | #endif 41 | } 42 | 43 | Proto* lua_getproto(lua_State* L, int idx) { 44 | auto func = LUA_STKID(L->top) + idx; 45 | return func2proto(func); 46 | } 47 | -------------------------------------------------------------------------------- /src/luadebug/compat/5x/common.cpp: -------------------------------------------------------------------------------- 1 | #include "compat/internal.h" 2 | #include "compat/lua.h" 3 | 4 | const void* lua_tocfunction_pointer(lua_State* L, int idx) { 5 | return (const void*)lua_tocfunction(L, idx); 6 | } 7 | #if LUA_VERSION_NUM == 501 8 | # include 9 | # include 10 | namespace lua { 11 | # define api_incr_top(L) \ 12 | { \ 13 | api_check(L, L->top < L->ci->top); \ 14 | L->top++; \ 15 | } 16 | 17 | const char* lua_getlocal(lua_State* L, const lua_Debug* ar, int n) { 18 | if (n < 0) { 19 | auto ci = lua_debug2ci(L, ar); 20 | auto proto = lua_ci2proto(ci); 21 | if (!proto) { 22 | return nullptr; 23 | } 24 | 25 | n = -n; 26 | auto nparams = proto->numparams; 27 | if (n >= ci->base - ci->func - nparams) { 28 | return nullptr; // no such vararg 29 | } else { 30 | auto o = ci->func + nparams + n; 31 | setobj2s(L, L->top, o); 32 | api_incr_top(L); 33 | return "(*vararg)"; 34 | } 35 | return nullptr; 36 | } 37 | return ::lua_getlocal(L, ar, n); 38 | } 39 | } 40 | #endif 41 | -------------------------------------------------------------------------------- /src/luadebug/compat/5x/mainthread.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "compat/internal.h" 4 | 5 | lua_State* lua_getmainthread(lua_State* L) { 6 | return L->l_G->mainthread; 7 | } 8 | -------------------------------------------------------------------------------- /src/luadebug/compat/5x/stacklevel.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "compat/internal.h" 5 | 6 | int lua_stacklevel(lua_State* L) { 7 | int level = 0; 8 | #if LUA_VERSION_NUM >= 502 9 | for (CallInfo* ci = L->ci; ci != &L->base_ci; ci = ci->previous) { 10 | level++; 11 | } 12 | #else 13 | for (CallInfo* ci = L->ci; ci > L->base_ci; ci--) { 14 | level++; 15 | if (f_isLua(ci)) level += ci->tailcalls; 16 | } 17 | #endif 18 | return level; 19 | } 20 | -------------------------------------------------------------------------------- /src/luadebug/compat/internal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "compat/lua.h" 4 | 5 | #ifdef LUAJIT_VERSION 6 | const char* lua_cdatatype(lua_State* L, int idx); 7 | int lua_isinteger(lua_State* L, int idx); 8 | #endif 9 | 10 | const void* lua_tocfunction_pointer(lua_State* L, int idx); 11 | 12 | #ifdef LUAJIT_VERSION 13 | union TValue; 14 | struct GCproto; 15 | using CallInfo = TValue; 16 | using Proto = GCproto; 17 | #else 18 | struct CallInfo; 19 | struct Proto; 20 | #endif 21 | 22 | Proto* lua_getproto(lua_State* L, int idx); 23 | CallInfo* lua_getcallinfo(lua_State* L); 24 | Proto* lua_ci2proto(CallInfo* ci); 25 | CallInfo* lua_debug2ci(lua_State* L, const lua_Debug* ar); 26 | 27 | #ifdef LUAJIT_VERSION 28 | int lua_isluafunc(lua_State* L, lua_Debug* ar); 29 | #endif 30 | 31 | int lua_stacklevel(lua_State* L); 32 | lua_State* lua_getmainthread(lua_State* L); 33 | -------------------------------------------------------------------------------- /src/luadebug/compat/jit/callinfo.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "compat/internal.h" 8 | 9 | extern TValue* index2adr(lua_State* L, int idx); 10 | 11 | static cTValue* debug_frame(lua_State* L, int level, int* size) { 12 | cTValue *frame, *nextframe, *bot = tvref(L->stack) + LJ_FR2; 13 | /* Traverse frames backwards. */ 14 | for (nextframe = frame = L->base - 1; frame > bot;) { 15 | if (frame_gc(frame) == obj2gco(L)) 16 | level++; /* Skip dummy frames. See lj_err_optype_call(). */ 17 | if (level-- == 0) { 18 | *size = (int)(nextframe - frame); 19 | return frame; /* Level found. */ 20 | } 21 | nextframe = frame; 22 | if (frame_islua(frame)) { 23 | frame = frame_prevl(frame); 24 | } else { 25 | if (frame_isvarg(frame)) 26 | level++; /* Skip vararg pseudo-frame. */ 27 | frame = frame_prevd(frame); 28 | } 29 | } 30 | *size = level; 31 | return NULL; /* Level not found. */ 32 | } 33 | 34 | CallInfo* lua_getcallinfo(lua_State* L) { 35 | int size; 36 | return const_cast(debug_frame(L, 0, &size)); 37 | } 38 | 39 | inline Proto* func2proto(GCfunc* func) { 40 | if (!isluafunc(func)) 41 | return 0; 42 | return funcproto(func); 43 | } 44 | 45 | Proto* lua_getproto(lua_State* L, int idx) { 46 | GCfunc* func = funcV(index2adr(L, idx)); 47 | return func2proto(func); 48 | } 49 | 50 | Proto* lua_ci2proto(CallInfo* ci) { 51 | GCfunc* func = frame_func(ci); 52 | return func2proto(func); 53 | } 54 | 55 | CallInfo* lua_debug2ci(lua_State* L, const lua_Debug* ar) { 56 | uint32_t offset = (uint32_t)ar->i_ci & 0xffff; 57 | return tvref(L->stack) + offset; 58 | } 59 | 60 | int lua_isluafunc(lua_State* L, lua_Debug* ar) { 61 | return isluafunc(frame_func(lua_debug2ci(L, ar))); 62 | } 63 | -------------------------------------------------------------------------------- /src/luadebug/compat/jit/mainthread.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "compat/internal.h" 4 | 5 | lua_State* lua_getmainthread(lua_State* L) { 6 | return mainthread(G(L)); 7 | } 8 | -------------------------------------------------------------------------------- /src/luadebug/compat/jit/stacklevel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "compat/internal.h" 4 | 5 | int lua_stacklevel(lua_State* L) { 6 | int level = 0; 7 | cTValue *frame, *nextframe, *bot = tvref(L->stack) + LJ_FR2; 8 | /* Traverse frames backwards. */ 9 | for (nextframe = frame = L->base - 1; frame > bot;) { 10 | if (frame_gc(frame) == obj2gco(L)) { 11 | level--; 12 | } 13 | level++; 14 | nextframe = frame; 15 | if (frame_islua(frame)) { 16 | frame = frame_prevl(frame); 17 | } else { 18 | if (frame_isvarg(frame)) 19 | level--; /* Skip vararg pseudo-frame. */ 20 | frame = frame_prevd(frame); 21 | } 22 | } 23 | return level; 24 | } 25 | -------------------------------------------------------------------------------- /src/luadebug/compat/table.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct lua_State; 4 | 5 | namespace luadebug::table { 6 | unsigned int array_size(const void* t); 7 | unsigned int hash_size(const void* t); 8 | bool array_base_zero(); 9 | bool get_hash_kv(lua_State* L, const void* tv, unsigned int i); 10 | bool get_hash_k(lua_State* L, const void* tv, unsigned int i); 11 | bool get_hash_v(lua_State* L, const void* tv, unsigned int i); 12 | bool set_hash_v(lua_State* L, const void* tv, unsigned int i); 13 | bool get_array(lua_State* L, const void* tv, unsigned int i); 14 | bool set_array(lua_State* L, const void* tv, unsigned int i); 15 | } 16 | -------------------------------------------------------------------------------- /src/luadebug/luadbg/bee_inline.cpp: -------------------------------------------------------------------------------- 1 | #if defined _WIN32 2 | # include 3 | #endif 4 | 5 | #include <3rd/fmt/format.cc> 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #if defined(_WIN32) 16 | # include 17 | # include 18 | # include 19 | # include 20 | # include 21 | # include 22 | # include 23 | # include 24 | # include 25 | # include 26 | #else 27 | # include 28 | # include 29 | # include 30 | # include 31 | #endif 32 | 33 | #if defined(__APPLE__) 34 | # include 35 | # include 36 | # include 37 | #elif defined(__linux__) 38 | # include 39 | # include 40 | # include 41 | #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) 42 | # include 43 | # include 44 | # include 45 | #endif 46 | -------------------------------------------------------------------------------- /src/luadebug/luadbg/bee_module.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct luadbg_State; 4 | 5 | namespace luadebug { 6 | int require_all(luadbg_State* L); 7 | } 8 | -------------------------------------------------------------------------------- /src/luadebug/luadbg/inc/.gitignore: -------------------------------------------------------------------------------- 1 | *.h 2 | *.hpp 3 | -------------------------------------------------------------------------------- /src/luadebug/luadbg/lua.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if !defined(LUADBG_DISABLE) 4 | #include "luadbg/inc/luadbg.hpp" 5 | #else 6 | #include 7 | #include "luadbg/inc/luadbgimports.h" 8 | #endif 9 | -------------------------------------------------------------------------------- /src/luadebug/rdebug_debughost.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rdebug_lua.h" 4 | 5 | struct lua_State; 6 | struct luadbg_State; 7 | 8 | namespace luadebug::debughost { 9 | luadbg_State* get_client(lua_State* hL); 10 | lua_State* get(luadbg_State* L); 11 | void set(luadbg_State* L, lua_State* hL); 12 | } 13 | -------------------------------------------------------------------------------- /src/luadebug/rdebug_eventfree.cpp: -------------------------------------------------------------------------------- 1 | #include "rdebug_eventfree.h" 2 | 3 | #include 4 | 5 | #include "compat/lua.h" 6 | #include "thunk/thunk.h" 7 | 8 | namespace luadebug::eventfree { 9 | struct userdata { 10 | lua_Alloc l_allocf; 11 | void* l_ud; 12 | notify cb; 13 | void* ud; 14 | #if !defined(LUADEBUG_DISABLE_THUNK) 15 | std::unique_ptr f; 16 | #endif 17 | }; 18 | static void* fake_allocf(void* ud, void* ptr, size_t osize, size_t nsize) { 19 | userdata* self = (userdata*)ud; 20 | if (ptr != NULL && nsize == 0 && self->cb) { 21 | self->cb(self->ud, ptr); 22 | } 23 | return self->l_allocf(self->l_ud, ptr, osize, nsize); 24 | } 25 | void* create(lua_State* L, notify cb, void* ud) { 26 | userdata* self = new userdata; 27 | self->cb = cb; 28 | self->ud = ud; 29 | self->l_allocf = lua_getallocf(L, &self->l_ud); 30 | #if defined(LUADEBUG_DISABLE_THUNK) 31 | lua_setallocf(L, fake_allocf, self); 32 | #else 33 | self->f.reset(thunk_create_allocf((intptr_t)self, (intptr_t)fake_allocf)); 34 | lua_setallocf(L, (lua_Alloc)self->f->data, self->l_ud); 35 | #endif 36 | return self; 37 | } 38 | void destroy(lua_State* L, void* handle) { 39 | userdata* self = (userdata*)handle; 40 | lua_setallocf(L, self->l_allocf, self->l_ud); 41 | delete self; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/luadebug/rdebug_eventfree.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct lua_State; 4 | 5 | namespace luadebug::eventfree { 6 | typedef void (*notify)(void* ud, void* ptr); 7 | void* create(lua_State* L, notify cb, void* ud); 8 | void destroy(lua_State* L, void* handle); 9 | } 10 | -------------------------------------------------------------------------------- /src/luadebug/rdebug_init.cpp: -------------------------------------------------------------------------------- 1 | #if defined(_MSC_VER) 2 | 3 | # include 4 | 5 | # include "rdebug_win32.h" 6 | 7 | extern "C" __declspec(dllexport) int init(lua_State* hL) { 8 | if (!luadebug::win32::caller_is_luadll(_ReturnAddress())) { 9 | luadebug::win32::find_luadll(); 10 | } 11 | if (lua_type(hL, 1) == LUA_TSTRING) { 12 | luadebug::win32::set_luaapi(*(void**)lua_tostring(hL, -1)); 13 | } else { 14 | luadebug::win32::set_luaapi(nullptr); 15 | } 16 | return 0; 17 | } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/luadebug/rdebug_lua.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(_WIN32) 4 | # define LUADEBUG_FUNC extern "C" __declspec(dllexport) 5 | #else 6 | # define LUADEBUG_FUNC extern "C" __attribute__((visibility("default"))) 7 | #endif 8 | 9 | #include "compat/lua.h" 10 | #include "luadbg/lua.hpp" 11 | -------------------------------------------------------------------------------- /src/luadebug/rdebug_redirect.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace luadebug::stdio { 6 | enum class std_fd { 7 | STDIN = 0, 8 | STDOUT, 9 | STDERR, 10 | }; 11 | 12 | class std_redirect { 13 | public: 14 | #if defined(_WIN32) 15 | typedef void* handle_t; 16 | #else 17 | typedef int handle_t; 18 | #endif 19 | public: 20 | std_redirect(); 21 | ~std_redirect(); 22 | bool open(std_fd type); 23 | void close(); 24 | size_t read(char* buf, size_t len); 25 | #if defined(_WIN32) 26 | size_t peek(); 27 | #endif 28 | private: 29 | handle_t m_pipe[2]; 30 | handle_t m_old; 31 | std_fd m_type; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /src/luadebug/rdebug_utility.cpp: -------------------------------------------------------------------------------- 1 | #include "rdebug_lua.h" 2 | #if defined(_WIN32) 3 | # include 4 | # include 5 | #endif 6 | #include 7 | 8 | namespace luadebug::utility { 9 | #if defined(_WIN32) 10 | static bool closeWindow() { 11 | bool ok = false; 12 | HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); 13 | if (h != INVALID_HANDLE_VALUE) { 14 | THREADENTRY32 te; 15 | te.dwSize = sizeof(te); 16 | for (BOOL ok = Thread32First(h, &te); ok; ok = Thread32Next(h, &te)) { 17 | if (te.th32OwnerProcessID == GetCurrentProcessId()) { 18 | BOOL suc = PostThreadMessageW(te.th32ThreadID, WM_QUIT, 0, 0); 19 | ok = ok || suc; 20 | } 21 | } 22 | CloseHandle(h); 23 | } 24 | return ok; 25 | } 26 | #endif 27 | 28 | static int closewindow(luadbg_State* L) { 29 | bool ok = false; 30 | #if defined(_WIN32) 31 | ok = closeWindow(); 32 | #endif 33 | luadbg_pushboolean(L, ok); 34 | return 1; 35 | } 36 | 37 | static int closeprocess(luadbg_State* L) { 38 | raise(SIGINT); 39 | return 0; 40 | } 41 | static int luaopen(luadbg_State* L) { 42 | luadbg_newtable(L); 43 | luadbgL_Reg lib[] = { 44 | { "closewindow", closewindow }, 45 | { "closeprocess", closeprocess }, 46 | { NULL, NULL } 47 | }; 48 | luadbgL_setfuncs(L, lib, 0); 49 | return 1; 50 | } 51 | } 52 | 53 | LUADEBUG_FUNC 54 | int luaopen_luadebug_utility(luadbg_State* L) { 55 | return luadebug::utility::luaopen(L); 56 | } 57 | -------------------------------------------------------------------------------- /src/luadebug/rdebug_win32.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(_WIN32) 4 | 5 | # include 6 | # include 7 | 8 | namespace luadebug::win32 { 9 | HMODULE get_luadll(); 10 | void set_luadll(HMODULE handle); 11 | void set_luaapi(void* fn); 12 | bool caller_is_luadll(void* callerAddress); 13 | bool find_luadll(); 14 | void putenv(const char* envstr); 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/luadebug/symbolize/symbolize.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined(_WIN32) 4 | # include 5 | #elif defined(__APPLE__) 6 | # include 7 | #elif defined(__linux__) 8 | # include 9 | #else 10 | 11 | namespace luadebug { 12 | symbol_info symbolize(const void* ptr) { 13 | return {}; 14 | } 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/luadebug/symbolize/symbolize.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace luadebug { 7 | struct symbol_info { 8 | std::optional module_name; 9 | std::optional function_name; 10 | std::optional file_name; 11 | std::optional line_number; 12 | }; 13 | symbol_info symbolize(const void* ptr); 14 | } 15 | -------------------------------------------------------------------------------- /src/luadebug/thunk/thunk.cpp: -------------------------------------------------------------------------------- 1 | #include "thunk.h" 2 | 3 | #if defined(THUNK_JIT) 4 | # include "thunk_jit.inl" 5 | #else 6 | # include "thunk_nojit.inl" 7 | #endif 8 | -------------------------------------------------------------------------------- /src/luadebug/thunk/thunk.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | struct thunk; 7 | thunk* thunk_create_hook(intptr_t dbg, intptr_t hook); 8 | thunk* thunk_create_allocf(intptr_t dbg, intptr_t allocf); 9 | 10 | #if defined(_WIN32) 11 | # define THUNK_JIT 1 12 | #else 13 | # if defined(__ia64__) 14 | # define THUNK_JIT 1 15 | # elif defined(__aarch64__) 16 | # if defined(__APPLE__) 17 | # include 18 | # if !TARGET_OS_IPHONE 19 | # define THUNK_JIT 1 20 | # endif 21 | # else 22 | # define THUNK_JIT 1 23 | # endif 24 | # endif 25 | #endif 26 | 27 | #if defined(THUNK_JIT) 28 | # include "thunk_jit.h" 29 | #else 30 | # include "thunk_nojit.h" 31 | #endif 32 | -------------------------------------------------------------------------------- /src/luadebug/thunk/thunk_jit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | struct thunk { 6 | void* data = 0; 7 | size_t size = 0; 8 | bool create(size_t s); 9 | bool write(void* buf); 10 | ~thunk(); 11 | }; 12 | -------------------------------------------------------------------------------- /src/luadebug/thunk/thunk_jit.inl: -------------------------------------------------------------------------------- 1 | #include "thunk_jit.h" 2 | 3 | #if defined(_WIN32) 4 | # include "thunk_windows.inl" 5 | # if defined(_M_X64) 6 | # include "thunk_windows_amd64.inl" 7 | # elif defined(_M_ARM64) || defined(_M_ARM64EC) 8 | # include "thunk_arm64.inl" 9 | # else 10 | # include "thunk_windows_i386.inl" 11 | # endif 12 | #else 13 | # include "thunk_posix.inl" 14 | # if defined(__ia64__) 15 | # include "thunk_posix_amd64.inl" 16 | # elif defined(__aarch64__) 17 | # include "thunk_arm64.inl" 18 | # endif 19 | #endif 20 | -------------------------------------------------------------------------------- /src/luadebug/thunk/thunk_nojit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | struct thunk { 6 | void* data = 0; 7 | }; 8 | struct lua_State; 9 | intptr_t thunk_get(lua_State* L, void* key); 10 | void thunk_set(lua_State* L, void* key, intptr_t v); 11 | #define LUADEBUG_DISABLE_THUNK 1 12 | -------------------------------------------------------------------------------- /src/luadebug/thunk/thunk_nojit.inl: -------------------------------------------------------------------------------- 1 | #include "compat/lua.h" 2 | #include "thunk_nojit.h" 3 | 4 | intptr_t thunk_get(lua_State* L, void* key) { 5 | if (LUA_TLIGHTUSERDATA != lua::rawgetp(L, LUA_REGISTRYINDEX, key)) { 6 | lua_pop(L, 1); 7 | return 0; 8 | } 9 | intptr_t v = (intptr_t)lua_touserdata(L, -1); 10 | lua_pop(L, 1); 11 | return v; 12 | } 13 | 14 | void thunk_set(lua_State* L, void* key, intptr_t v) { 15 | lua_pushlightuserdata(L, (void*)v); 16 | lua_rawsetp(L, LUA_REGISTRYINDEX, key); 17 | } 18 | 19 | thunk* thunk_create_hook(intptr_t dbg, intptr_t hook) { 20 | thunk* t = new thunk; 21 | t->data = (void*)hook; 22 | return t; 23 | } 24 | -------------------------------------------------------------------------------- /src/luadebug/thunk/thunk_posix.inl: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include "thunk_jit.h" 6 | 7 | bool thunk::create(size_t s) { 8 | data = mmap(NULL, s, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 9 | if (!data) { 10 | size = 0; 11 | return false; 12 | } 13 | size = s; 14 | return true; 15 | } 16 | 17 | bool thunk::write(void* buf) { 18 | memcpy(data, buf, size); 19 | mprotect(data, size, PROT_READ | PROT_EXEC); 20 | return true; 21 | } 22 | 23 | thunk::~thunk() { 24 | if (!data) return; 25 | munmap(data, size); 26 | } 27 | -------------------------------------------------------------------------------- /src/luadebug/thunk/thunk_windows.inl: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "thunk_jit.h" 4 | 5 | bool thunk::create(size_t s) { 6 | data = VirtualAllocEx(GetCurrentProcess(), NULL, s, MEM_COMMIT, PAGE_EXECUTE_READWRITE); 7 | if (!data) { 8 | size = 0; 9 | return false; 10 | } 11 | size = s; 12 | return true; 13 | } 14 | 15 | bool thunk::write(void* buf) { 16 | SIZE_T written = 0; 17 | BOOL ok = WriteProcessMemory(GetCurrentProcess(), data, buf, size, &written); 18 | if (!ok || written != size) { 19 | return false; 20 | } 21 | return true; 22 | } 23 | 24 | thunk::~thunk() { 25 | if (!data) return; 26 | VirtualFreeEx(GetCurrentProcess(), data, 0, MEM_RELEASE); 27 | } 28 | -------------------------------------------------------------------------------- /src/luadebug/thunk/thunk_windows_i386.inl: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "thunk_jit.h" 4 | 5 | thunk* thunk_create_hook(intptr_t dbg, intptr_t hook) { 6 | // int __cedel thunk_hook(lua_State* L, lua_Debug* ar) 7 | // { 8 | // `hook`(`dbg`, L, ar); 9 | // return `undefinition`; 10 | // } 11 | static unsigned char sc[] = { 12 | 0xff, 0x74, 0x24, 0x08, // push [esp+8] 13 | 0xff, 0x74, 0x24, 0x08, // push [esp+8] 14 | 0x68, 0x00, 0x00, 0x00, 0x00, // push dbg 15 | 0xe8, 0x00, 0x00, 0x00, 0x00, // call hook 16 | 0x83, 0xc4, 0x0c, // add esp, 12 17 | 0xc3, // ret 18 | }; 19 | std::unique_ptr t(new thunk); 20 | if (!t->create(sizeof(sc))) { 21 | return 0; 22 | } 23 | memcpy(sc + 9, &dbg, sizeof(dbg)); 24 | hook = hook - ((intptr_t)t->data + 18); 25 | memcpy(sc + 14, &hook, sizeof(hook)); 26 | if (!t->write(&sc)) { 27 | return 0; 28 | } 29 | return t.release(); 30 | } 31 | 32 | thunk* thunk_create_allocf(intptr_t dbg, intptr_t allocf) { 33 | // void* __cedel thunk_allocf(void *ud, void *ptr, size_t osize, size_t nsize) 34 | // { 35 | // return `allocf`(`dbg`, ptr, osize, nsize); 36 | // } 37 | static unsigned char sc[] = { 38 | 0xff, 0x74, 0x24, 0x10, // push [esp+0x10] 39 | 0xff, 0x74, 0x24, 0x10, // push [esp+0x10] 40 | 0xff, 0x74, 0x24, 0x10, // push [esp+0x10] 41 | 0x68, 0x00, 0x00, 0x00, 0x00, // push dbg 42 | 0xe8, 0x00, 0x00, 0x00, 0x00, // call allocf 43 | 0x83, 0xc4, 0x10, // add esp, 0x10 44 | 0xc3, // ret 45 | }; 46 | std::unique_ptr t(new thunk); 47 | if (!t->create(sizeof(sc))) { 48 | return 0; 49 | } 50 | memcpy(sc + 13, &dbg, sizeof(dbg)); 51 | allocf = allocf - ((intptr_t)t->data + 22); 52 | memcpy(sc + 18, &allocf, sizeof(allocf)); 53 | if (!t->write(&sc)) { 54 | return 0; 55 | } 56 | return t.release(); 57 | } 58 | -------------------------------------------------------------------------------- /src/process_inject/.gitignore: -------------------------------------------------------------------------------- 1 | /macos/shellcode.inl 2 | -------------------------------------------------------------------------------- /src/process_inject/macos/injectdll.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | bool injectdll(pid_t pid, const std::string& dll, const char* entry = 0); 8 | -------------------------------------------------------------------------------- /src/process_inject/macos/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "injectdll.h" 4 | 5 | int main(const int argc, const char* argv[]) { 6 | if (argc < 4) { 7 | return -1; 8 | } 9 | if (!argv[1]) return 1; 10 | if (!argv[2]) return 2; 11 | if (!argv[3]) return 3; 12 | int base = 10; 13 | if (argv[1][0] == '0' && argv[1][1] == 'x') { 14 | base = 16; 15 | } 16 | pid_t pid = (pid_t)strtoull(argv[1], nullptr, base); 17 | return injectdll(pid, argv[2], argv[3]) ? 0 : 4; 18 | } -------------------------------------------------------------------------------- /src/process_inject/windows/inject.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "injectdll.h" 12 | 13 | static std::string_view checkstrview(lua_State* L, int idx) { 14 | size_t len = 0; 15 | const char* buf = luaL_checklstring(L, idx, &len); 16 | return { buf, len }; 17 | } 18 | 19 | static std::wstring checkstring(lua_State* L, int idx) { 20 | auto str = checkstrview(L, idx); 21 | return bee::wtf8::u2w(str); 22 | } 23 | 24 | static int injectdll(lua_State* L) { 25 | if (lua_type(L, 1) == LUA_TNUMBER) { 26 | DWORD pid = (DWORD)luaL_checkinteger(L, 1); 27 | bool ok = injectdll(pid, checkstring(L, 2), checkstring(L, 3), checkstrview(L, 4)); 28 | lua_pushboolean(L, ok); 29 | return 1; 30 | } else { 31 | auto& self = bee::lua::checkudata(L, 1); 32 | bool ok = injectdll(self.native_handle(), self.thread_handle(), checkstring(L, 2), checkstring(L, 3), checkstrview(L, 4)); 33 | lua_pushboolean(L, ok); 34 | return 1; 35 | } 36 | } 37 | 38 | extern "C" int luaopen_inject(lua_State* L) { 39 | luaL_Reg lib[] = { 40 | { "injectdll", injectdll }, 41 | { NULL, NULL }, 42 | }; 43 | luaL_newlibtable(L, lib); 44 | luaL_setfuncs(L, lib, 0); 45 | return 1; 46 | } 47 | 48 | static ::bee::lua::callfunc _init(::bee::lua::register_module, "inject", luaopen_inject); 49 | -------------------------------------------------------------------------------- /src/process_inject/windows/injectdll.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(_M_X64) 4 | # error unsupport x86_64 5 | #endif 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | bool injectdll(HANDLE process_handle, HANDLE thread_handle, const std::wstring& x86dll, const std::wstring& x64dll, const std::string_view& entry = 0); 13 | bool injectdll(DWORD pid, const std::wstring& x86dll, const std::wstring& x64dll, const std::string_view& entry = 0); 14 | -------------------------------------------------------------------------------- /test.lua: -------------------------------------------------------------------------------- 1 | local os = require "bee.platform".os 2 | if os == "macos" then 3 | require "test.load.test_macos" 4 | require "test.inject.inject_macos" 5 | require "test.waitdll" 6 | end 7 | 8 | require "test.interceptor" 9 | -------------------------------------------------------------------------------- /test/delayload.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | int main(){ 6 | using namespace std::string_view_literals; 7 | using namespace luadebug::lua; 8 | #define check_symbol_name(name) \ 9 | constexpr auto name##_s = function_name_v;\ 10 | static_assert((std::string_view{name##_s.data(), name##_s.size()} == #name##sv)); 11 | 12 | check_symbol_name(lua_gethook); 13 | check_symbol_name(lua_sethook); 14 | 15 | assert(impl::initfunc::v.size() == 4); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/inject/launcher.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | extern "C" { 7 | void attach() { 8 | std::thread([](){ 9 | using namespace std::chrono_literals; 10 | std::this_thread::sleep_for(1s); 11 | std::filesystem::remove(std::filesystem::current_path() / "test/inject/launcher.so"); 12 | exit(0); 13 | }).detach(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/interceptor.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #define LOG(fmt, ...) printf("[test_native] " fmt "\n", ##__VA_ARGS__) 8 | 9 | extern "C" { 10 | void test_add(int a, int b) { 11 | printf("%d,%d,%d", a, b, a + b); 12 | a = a + 1; 13 | b = b + 1; 14 | printf("%d,%d,%d", a,b,a+b); 15 | } 16 | } 17 | static int on_enter = 1; 18 | static int on_leave = 2; 19 | struct MyInvocationListener : Gum::InvocationListener{ 20 | virtual ~MyInvocationListener () {} 21 | 22 | virtual void on_enter (Gum::InvocationContext * context){ 23 | LOG("on_enter"); 24 | ::on_enter = 0; 25 | }; 26 | virtual void on_leave (Gum::InvocationContext * context){ 27 | LOG("on_leave"); 28 | ::on_leave = 0; 29 | }; 30 | }; 31 | 32 | int main(int argc, char *argv[]) { 33 | LOG("test execve"); 34 | Gum::RefPtr interceptor (Gum::Interceptor_obtain ()); 35 | MyInvocationListener listener; 36 | interceptor->attach((void*)&test_add, &listener, 0); 37 | 38 | test_add(1, 2); 39 | 40 | return on_enter + on_leave; 41 | } 42 | -------------------------------------------------------------------------------- /test/interceptor.lua: -------------------------------------------------------------------------------- 1 | local fs = require "bee.filesystem" 2 | local sp = require "bee.subprocess" 3 | 4 | local all_tests = {} 5 | local function find_directory_test(dir) 6 | for file in fs.pairs(dir) do 7 | if fs.is_directory(file) then 8 | find_directory_test(file) 9 | else 10 | local filename = file:filename() 11 | local ext = file:extension() 12 | if tostring(filename):find("test_") and (ext:find(".exe") or ext == "" or ext == nil )then 13 | table.insert(all_tests, tostring(file)) 14 | end 15 | end 16 | end 17 | end 18 | 19 | find_directory_test("build") 20 | 21 | local function run_tests() 22 | local res = true 23 | for i, test in ipairs(all_tests) do 24 | print(("%d/%d : %s"):format(i, #all_tests, test)) 25 | local p, err = sp.spawn({ 26 | test, 27 | }) 28 | if not p then 29 | res = false 30 | print("can't run:", test, "err:", err) 31 | else 32 | local ec = p:wait() 33 | if ec ~= 0 then 34 | print("test return not 0") 35 | res = false 36 | end 37 | end 38 | end 39 | return res 40 | end 41 | 42 | if not run_tests() then 43 | os.exit(1) 44 | end 45 | -------------------------------------------------------------------------------- /test/launcher.lua: -------------------------------------------------------------------------------- 1 | loadfile "publish/script/debugger.lua" "publish" 2 | :start "127.0.0.1:4278" 3 | :event "wait" 4 | 5 | print "ok" 6 | -------------------------------------------------------------------------------- /test/load/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) { 5 | for (size_t i = 1; i < argc; i++) 6 | { 7 | const char* path = argv[i]; 8 | if(!dlopen(path, RTLD_NOW|RTLD_GLOBAL)) { 9 | fprintf(stderr,"load %s failed: %s\n", path, dlerror()); 10 | return 1; 11 | } 12 | } 13 | return 0; 14 | } -------------------------------------------------------------------------------- /test/load/test_macos.lua: -------------------------------------------------------------------------------- 1 | local fs = require "bee.filesystem" 2 | local arch = require "bee.platform".Arch 3 | local path = 'test/load/test' 4 | 5 | 6 | local x86_64 = {} 7 | local arm64 = {} 8 | local function find_directory_so(dir) 9 | for file in fs.pairs(dir) do 10 | if fs.is_directory(file) then 11 | find_directory_so(file) 12 | else 13 | local extension = file:extension() 14 | if extension == ".so" then 15 | local filepath = tostring(file) 16 | local t = filepath:find("x64") and x86_64 or arm64 17 | if filepath:find("remote") then 18 | table.insert(t, { tostring(file:replace_filename("lua")), filepath }) 19 | else 20 | table.insert(t, filepath) 21 | end 22 | end 23 | end 24 | end 25 | end 26 | 27 | find_directory_so("publish") 28 | local count = #x86_64 + #arm64 29 | local index = 1; 30 | local function load_test(paths, arch) 31 | local target = ("%s_%s"):format(path, arch) 32 | assert(os.execute(("clang %s.cpp -o %s -arch %s"):format(path, target, arch))) 33 | for _, file in ipairs(paths) do 34 | if type(file) == "table" then 35 | file = table.concat(file, " ") 36 | end 37 | local shell = ("%s %s"):format(target, file) 38 | print(index .. "/" .. count .. " " .. shell) 39 | assert(os.execute(shell)) 40 | index = index + 1 41 | end 42 | os.execute(("rm -rf %s"):format(target)) 43 | end 44 | 45 | 46 | load_test(x86_64, "x86_64") 47 | if arch == "arm64" then 48 | load_test(arm64, "arm64") 49 | end 50 | -------------------------------------------------------------------------------- /test/symbol/symbols.c: -------------------------------------------------------------------------------- 1 | #ifdef _WIN32 2 | #define EXPORT_HIDDEN 3 | #define EXPORT __declspec( dllexport ) 4 | #else 5 | #define EXPORT_HIDDEN __attribute__((visibility("hidden"))) 6 | #define EXPORT __attribute__((visibility("default"))) 7 | #endif 8 | static const char* static_data= "static_data"; 9 | const char* extern_data = "data2"; 10 | 11 | 12 | static void static_function(const char* fmt,...) {} 13 | EXPORT_HIDDEN extern void hidden_extern_function(const char* fmt,...) {static_function(static_data);} 14 | EXPORT extern void extern_function(const char* fmt,...) {static_function(static_data);} -------------------------------------------------------------------------------- /test/thunk.cpp: -------------------------------------------------------------------------------- 1 | #include "thunk/thunk.cpp" 2 | 3 | #include 4 | struct HHI { 5 | int a = 0x1; 6 | }; 7 | 8 | int add(HHI* h, void* a, void* b) { 9 | h->a = 2; 10 | assert(a == (void*)0x1); 11 | assert(b == (void*)0x2); 12 | return 1; 13 | } 14 | 15 | void* add1(HHI* h, void* a, size_t b, size_t c) { 16 | h->a = 3; 17 | assert(a == (void*)0x1); 18 | assert(b == 2); 19 | assert(c == 3); 20 | return (void*)4; 21 | } 22 | 23 | int main() { 24 | HHI hhi; 25 | auto* thunk = thunk_create_hook((intptr_t)&hhi, (intptr_t)&add); 26 | int ret = ((int (*)(void* a, void* b))thunk->data)((void*)0x1, (void*)0x2); 27 | assert(hhi.a == 2); 28 | assert(ret == 1); 29 | 30 | auto* thunk1 = thunk_create_allocf((intptr_t)&hhi, (intptr_t)&add1); 31 | auto ret1 = ((void* (*)(void* a, size_t b, size_t c))thunk1->data)((void*)0x1, 2, 3); 32 | assert(hhi.a == 3); 33 | assert(ret1 == (void*)4); 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /test/undump.lua: -------------------------------------------------------------------------------- 1 | -- publish\runtime\win32\lua53\lua.exe test\undump.lua 2 | -- publish\runtime\win64\lua54\lua.exe test\undump.lua 3 | -- publish\runtime\win32\lua53\lua.exe test\undump.lua 4 | -- publish\runtime\win64\lua54\lua.exe test\undump.lua 5 | 6 | package.path = "extension/script/?.lua" 7 | local undump = require "backend.worker.undump" 8 | local parser = require "backend.worker.parser" 9 | 10 | package.loaded["backend.worker.evaluate"] = { 11 | dump = function(content) 12 | return true, string.dump(content) 13 | end, 14 | } 15 | 16 | local function getproto(f) 17 | local cl = undump(string.dump(f)) 18 | return cl.f 19 | end 20 | 21 | getproto(function()end) 22 | getproto(assert(loadfile "extension/script/backend/worker/undump.lua")) 23 | 24 | local si = parser(assert(loadfile "extension/script/frontend/main.lua")) 25 | assert(si["20-34"]) 26 | assert(si["20-34"][25] == nil) 27 | assert(si["20-34"][27] == true) 28 | 29 | print "ok" 30 | -------------------------------------------------------------------------------- /test/waitdll.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | using namespace std::literals; 7 | 8 | int main(int argc, char** argv) { 9 | if (argc != 3) { 10 | return -1; 11 | } 12 | std::string error; 13 | auto launcher = dlopen(argv[1], RTLD_NOW | RTLD_GLOBAL); 14 | if (!launcher) { 15 | printf("Error: %s", dlerror()); 16 | return 1; 17 | } 18 | auto attach = (void (*)())dlsym(launcher, "attach"); 19 | attach(); 20 | auto hmod = dlopen(argv[2], RTLD_NOW | RTLD_GLOBAL); 21 | if (!hmod) { 22 | printf("Error: %s", dlerror()); 23 | return 1; 24 | } 25 | std::this_thread::sleep_for(1s); 26 | auto _luaL_newstate = (decltype(&luaL_newstate))dlsym(hmod, "luaL_newstate"); 27 | auto L = _luaL_newstate(); 28 | auto _lua_createtable = (decltype(&lua_createtable))dlsym(hmod, "lua_createtable"); 29 | _lua_createtable(L, 0, 0); 30 | auto _lua_getfield = (decltype(&lua_getfield))dlsym(hmod, "lua_getfield"); 31 | _lua_getfield(L, -1, "1"); 32 | auto _lua_gethook = (decltype(&lua_gethook))dlsym(hmod, "lua_gethook"); 33 | return _lua_gethook(L) != nullptr ? 0 : 3; 34 | } -------------------------------------------------------------------------------- /test/waitdll.lua: -------------------------------------------------------------------------------- 1 | local platform = require "bee.platform" 2 | local fs = require "bee.filesystem" 3 | local sp = require "bee.subprocess" 4 | 5 | assert(platform.os == "macos") 6 | local runtime_platform = "darwin-"..(platform.Arch == "x86_64" and "x64" or platform.Arch) 7 | local lua_path = (fs.path("publish/runtime/") / runtime_platform / "lua51" / "lua"):string() 8 | local launcher_path = "publish/bin/launcher.so" 9 | 10 | local executable = fs.path("build") / runtime_platform / "debug" / "bin" / "testwaitdll" 11 | 12 | print("testwaitdll:", executable, launcher_path, lua_path) 13 | local proc, err = sp.spawn({ 14 | executable, 15 | launcher_path, 16 | lua_path, 17 | }) 18 | assert(proc, err) 19 | 20 | assert(proc:wait() == 0) 21 | --------------------------------------------------------------------------------