Skip to content

Instantly share code, notes, and snippets.

@fnuecke
Created December 24, 2014 00:35
Show Gist options
  • Save fnuecke/6bcbd66910b946b54ec7 to your computer and use it in GitHub Desktop.
Save fnuecke/6bcbd66910b946b54ec7 to your computer and use it in GitHub Desktop.
Primitive remote code execution via OC network
local m=component.proxy(component.list("modem")())
m.open(2412)
local function respond(...)
local args=table.pack(...)
pcall(function() m.broadcast(2412, table.unpack(args)) end)
end
local function receive()
while true do
local evt,_,_,_,_,cmd=computer.pullSignal()
if evt=="modem_message" then return load(cmd) end
end
end
while true do
local result,reason=pcall(function()
local result,reason=receive()
if not result then return respond(reason) end
respond(result())
end)
if not result then respond(reason) end
end
local component = require("component")
local event = require("event")
local modem = component.modem
modem.open(2412)
modem.broadcast(2412, "drone=component.proxy(component.list('drone')())")
while true do
local cmd=io.read()
if not cmd then return end
modem.broadcast(2412, cmd)
print(select(6, event.pull(5, "modem_message")))
end
@JCBurnside
Copy link

Do you have a wireless modem installed on your computer?

@Notawallplan
Copy link

Can you create a primitive analog to digital and a digital to analog lua script for a microcontroller?

@joserobjr
Copy link

local function proxyComp(name) return component.proxy(component.list(name)()) end

Can be useful to reduce the code size and complexity when we need many components, for example:

local drive = proxyComp("drive")
local filesystem = proxyComp("filesystem")
local geolyzer = proxyComp("geolyzer")
local modem = proxyComp("modem")

is much easier to write and much smaller then:

local drive = component.proxy(component.list("drive")())
local filesystem = component.proxy(component.list("filesystem")())
local geolyzer = component.proxy(component.list("geolyzer")())
local modem = component.proxy(component.list("modem")())

@BJoeBR
Copy link

BJoeBR commented Apr 19, 2020

ok for some reason if I flash this to an eeprom and try to boot the robot he tells me that there is a missing ")" on line 15 to close the "(" on line 14 any suggestion why? Seems he doesn´t like the pcall one going over multiple lines

edit this was in Minecraft 1.12 with Open Computers 1.7.5

@isaaachipkiss
Copy link

Tried this and nothing happens when I parse commands.

@Bioscreeper
Copy link

You need a wireless modem/network card, not a wired one (called "Network Card")

@Bioscreeper
Copy link

Also, edit the first line from "local m=component.proxy(component.list("modem")())" to "local m=component.proxy(component.list("modem"))())"
, because print(returnsfoo() will print returnsfoo(, which is an invalid lua command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment