0

How do you copy a value or string in lua? I’ve only found alternatives for the regular microsoft os api. For my use I do not have access to the os api and instead have access to ffi and steam panorama.

If possible I would also know how to get a string from the current clipboard.

I have access to,

  1. LuaJIT 2.0.5 (https://github.com/LuaJIT/LuaJIT)

  2. FFI (https://luajit.org/ext_ffi.html)

  3. bit (https://bitop.luajit.org/api.html)

    via neverlose (https://docs.neverlose.cc)

Nepo
  • 1
  • 2
  • I don't see how you would get to the system clipboard without interfacing the system. ffi allows you to call C code, but even in C you would need some API. you can probably run some external program or shell commands though – Piglet Jan 31 '22 at 15:09
  • What is the "steam panorama"? What set of API functions do you have access to? Is it true that you can not invoke WinAPI function from user32.dll/kernel32.dll? – Egor Skriptunoff Jan 31 '22 at 15:17
  • There is a function `CopyTextToClipboard` at the panorama docs page you linked to in the comment below. – Egor Skriptunoff Feb 12 '22 at 11:57

2 Answers2

1

Probably not the most beautiful solution, but assuming you can run the powershell:

local pipe = io.popen("powershell get-clipboard", "r")
local clipboard = pipe:read("*a")
print("Clipboard: " .. clipboard)
pipe:close()
Piglet
  • 27,501
  • 3
  • 20
  • 43
  • 1
    In macOS, use `pbpaste`. – lhf Jan 31 '22 at 16:47
  • [string "local pipe = io.popen("power..."]:1: attempt to index global 'io' (a nil value) stack traceback: [string "local pipe = io.popen("power..."]:1: in main chunk-- – Nepo Feb 01 '22 at 15:11
  • your running Lua in some sandbox without Lua's standard io library. without further information on your environment we can't help you but I guess chances that you can do this at all are close to zero. – Piglet Feb 01 '22 at 15:17
  • ive seen it done with getting a string from the clipboard. – Nepo Feb 01 '22 at 15:18
  • I have access to, 1. LuaJIT 2.0.5 (https://github.com/LuaJIT/LuaJIT) 2. FFI (https://luajit.org/ext_ffi.html) 3. bit (https://bitop.luajit.org/api.html) 4. Steam Panorama API (https://developer.valvesoftware.com/wiki/CSGO_Panorama_API) via neverlose (https://docs.neverlose.cc) – Nepo Feb 01 '22 at 15:21
-1

In conditions of Source Engine (in this case - csgo) hacks Lua api, you can create interface to vgui2.dll and ffi.cast to it's functions. Here is three snippets of code for neverlose - initialisation, getting and setting clipboard.

If you want - you can still port this code to other csgo cheats by replacing Utils.CreateInterface with the same function what is in your cheat's api documentation. For example, in gamesense it will be client.create_interface

-- initialisation (ffi, creating functions and interface)
local ffi = require("ffi")
ffi.cdef[[
  typedef int(__thiscall* get_clipboard_text_count)(void*);
  typedef void(__thiscall* get_clipboard_text)(void*, int, const char*, int);
  typedef void(__thiscall* set_clipboard_text)(void*, const char*, int);
]]

local VGUI_Systemdll =  Utils.CreateInterface("vgui2.dll", "VGUI_System010")
local VGUI_System = ffi.cast(ffi.typeof('void***'), VGUI_Systemdll)
local get_clipboard_text_count = ffi.cast( "get_clipboard_text_count", VGUI_System[ 0 ][ 7 ] )
local get_clipboard_text = ffi.cast( "get_clipboard_text", VGUI_System[ 0 ][ 11 ] )
local set_clipboard_text = ffi.cast( "set_clipboard_text", VGUI_System[ 0 ][ 9 ] )
-- getting clipboard content
local clipboard_text_length = get_clipboard_text_count( VGUI_System )
local clipboardstring = ""
if clipboard_text_length > 0 then -- game will probably crash without that check
  local buffer = ffi.new("char[?]", clipboard_text_length)
  local size = clipboard_text_length * ffi.sizeof("char[?]", clipboard_text_length)
  get_clipboard_text( VGUI_System, 0, buffer, size )
  clipboardstring = ffi.string( buffer, clipboard_text_length-1 )
end
-- clipboardstring variable is what's in the clipboard
-- writing to clipboard
local some_cool_string = "i love ryuko very much"
set_clipboard_text(VGUI_System, some_cool_string, some_cool_string:len())
zeron1x
  • 1
  • 1