Skip to content

Instantly share code, notes, and snippets.

View CaptainPRICE's full-sized avatar
💭
🥚

CaptainPRICE

💭
🥚
View GitHub Profile
@CaptainPRICE
CaptainPRICE / m_fFlags.lua
Created July 26, 2019 09:10
Reconstruction of AddFlags/RemoveFlags/IsFlagSet on Garry's Mod Lua...
local ENTITY = FindMetaTable("Entity")
local Entity_GetInternalVariable = ENTITY.GetInternalVariable
local Entity_AddFlags, Entity_RemoveFlags = ENTITY.AddFlags, ENTITY.RemoveFlags
local bit_bor, bit_bnot, bit_band = bit.bor, bit.bnot, bit.band
function ENTITY.AddFlags(this, flagMask)
assert(IsValid(this), "attempt to AddFlags on NULL entity")
local m_fFlags = Entity_GetInternalVariable(this, "m_fFlags")
Entity_AddFlags(this, bit_bor(m_fFlags, flagMask))
end
function ENTITY.RemoveFlags(this, flagMask)

API draft (rev. 2)

See proposal here.
tldr: This document is unofficial until finally revised by Garry's Mod development team!

Status: See response from @robotboy655.

This is a preview API draft of new functionality for HTTP requests in Garry's Mod Lua.
Everything presented in this document is a subject to change without any notice.
There is a possibility of being unaccepted and/or altered by devs. For example:

  • Only partial functions may be implemented.
@CaptainPRICE
CaptainPRICE / cry_more
Last active May 17, 2019 17:40
A test source code to be converted from GLua into Lua syntax. Regex users tryhard. If you ever come up with the Regex solution that would convert such code from GLua into Lua syntax (without breaking any of the code including comments), please do let me know.
// Convert me into Lua syntax
// using Regex./*
if (!false != !!!(!false)
||not !'\"\\'
)/*&&"!||false!=true\
*/then
local _=MsgN(
"!*/es\"cap[==[!i[[ng!=]'!=\'*/"&&"/*!es\"cap[==[!i[[ng!=]'!=\'\
'\34Regex fails hard\34\\/*\
!nope"||!(
@CaptainPRICE
CaptainPRICE / e2-keyboard-linker.txt
Last active April 28, 2019 10:26
A full E2, used as an example usecase for https://github.com/wiremod/wire/issues/1900
@inputs User:entity
@outputs Kick
@persist Keyboard:entity Seat:entity
if (first()) {
Keyboard = entity():isWeldedTo()
if (Keyboard:type() != "gmod_wire_keyboard") { error("Not spawned on Wire Keyboard") }
propSpawnEffect(1)
propSpawnUndo(0)
Seat = seatSpawn("models/nova/airboat_seat.mdl", 1)
@CaptainPRICE
CaptainPRICE / spectre.c
Created January 6, 2018 20:30
CPU flaw: Spectre attack. Proof-of-Concept exploit code implementation in C. https://spectreattack.com/spectre.pdf
/*
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
@CaptainPRICE
CaptainPRICE / sandbox.lua
Last active October 9, 2017 05:34
A small and simple, yet safe Lua Sandbox program. (It is nowhere near "done", it does work tho!)
-- Lua Sandbox by CaptainPRICE
-- Last tested: 9 October 2017. [Compiled with LuaJIT 2.0.5, and it works as expected - so far]
-- Please try to BREAK it, NOT CRASH it (using infinite loop or such).
-- Only THE FIRST ONE WILL BE REWARDED, once You send me the Lua Sandbox breaking code!
-- Feel free to report bugs as well.
-- Source: https://gist.github.com/CaptainPRICE/bd19a8b92d9cb8a74329ba8b26d2e2c9
--
-- *great* feature in Lua Sandbox: isolated environment is immutable (so, you can't replace the standard Lua functions/constants/etc).
-- *hidden* feature in Lua Sandbox: calling a `tostring` on a global function will result in the "path" being revealed (works only for global functions).
-- ...more coming soon (find more features by yourself, hehe)...

Exploiting Lua 5.1 on 32-bit Windows

The following Lua program generates a Lua bytecode program called ignore-unsigned-sga.fnt, which in turn loads a DLL from within an extremely locked down Lua 5.1 sandbox in a program called RelicCOH2.exe. The remainder of this document attempts to explain how this program works by a whirlwind tour of relevent bits of the Lua 5.1 virtual machine.

if string.dump(function()end):sub(1, 12) ~= "\27Lua\81\0\1\4\4\4\8\0" then
  error("This generator requires a 32-bit version of Lua 5.1")
end

local function outer()
  local magic -- In bytecode, the stack slot corresponding to this local is changed
@CaptainPRICE
CaptainPRICE / function-detour.txt
Last active June 23, 2017 19:07
An example of how you can detour a user-defined function (UDF) in Expression 2.
@persist Function:table
if (first())
{
Function = table()
function call(ID)
{
timer("function_" + ID, first() ? 0 : 1000)
}
call(1)
}
@CaptainPRICE
CaptainPRICE / angle-snapto.txt
Last active June 23, 2017 14:27
GLua "Angle.SnapTo" function for Expression 2.
#ifndef normalizeAngle(number)
### <summary>Normalizes angle (-180 <= A <= 180).</summary>
### <param name="A">The angle to normalize, in degrees.</param>
### <returns>Returns the normalized angle, in the range of -180 to 180 degrees.</returns>
function number normalizeAngle(A)
{
return (A + 180) % 360 - 180
} # End of function number=normalizeAngle(number)
#endif
@CaptainPRICE
CaptainPRICE / e2-highlight-test.txt
Last active June 18, 2017 15:35
Expression 2 highlighting tests.
@inputs A
local N = 1
local R = array((N) = _PI)
local N = R[N*1-1+1/1,number],##include #[#include #[@name #[\n#[]#]#]#]#"\@name Uh oh!
#if\"\]#
N++,N--
print(N==_PI, !N == !_PI, !0, !0x1, !-0b0)
N = -N - 0xFF+(0b1101 && N /2) *N
N = N * -1 * ( N < -0 ? -1 : 1 )
N += curtime() % N ? 1 : _PHI