Jump to content


ViperLordX's Content

There have been 43 items by ViperLordX (Search limited from 10-February 22)


By content type

See this member's


Sort by                Order  

#245455 Virus Remover (Disk)

Posted by ViperLordX on 12 February 2016 - 10:00 PM in APIs and Utilities

I haven't used ComputerCraft for almost 6 months now, so I probably missed it.



#245407 Virus Remover (Disk)

Posted by ViperLordX on 11 February 2016 - 09:50 PM in APIs and Utilities

Really? How do you prevent startup disk drives from working? I've heard nothing of it.



#245373 Virus Remover (Disk)

Posted by ViperLordX on 11 February 2016 - 01:08 PM in APIs and Utilities

The whole point of this program is that it deletes the startup. If there's nothing in your startup, a virus can't do anything to your computer on startup. Startup disk cannot be disabled by any program, all you need to do is shutdown the computer, put in a disk with a startup, and reboot.



#245339 Local variables by default

Posted by ViperLordX on 11 February 2016 - 01:11 AM in APIs and Utilities

Ok, I updated my code again so that shell will appear in the environments.

local oldload = load
function _G.load(str, arg1, arg2, arg3)
  local func,err = oldload(str, arg1, arg2, arg3)
  if not (func) then
    return func, err
  end
  local env = getfenv(func)
  for k, v in pairs(env) do
    _G[k] = v
  end
  if (env == _G) then
    env = {}
  end
  setmetatable(env, {__index = _G})
  setfenv(func, env)
  return func,err
end
loadstring = load




#245313 Local variables by default

Posted by ViperLordX on 10 February 2016 - 09:40 PM in APIs and Utilities

Yes, I am.



#245307 Local variables by default

Posted by ViperLordX on 10 February 2016 - 09:06 PM in APIs and Utilities

Well, I need to override both load and loadstring, right? I'll need to mix 5.1 and 5.2 either way.



#245305 Local variables by default

Posted by ViperLordX on 10 February 2016 - 08:47 PM in APIs and Utilities

Thank you all for your help! CometWolf, I tried your code and it doesn't seem to work, but I did update mine.

local oldload = load
function _G.load(str, arg1, arg2, arg3)
  local func,err = oldload(str, arg1, arg2, arg3)
  if not (func) then
    return func, err
  end
  local env = getfenv(func)
  if (env == _G) then
    env = {}
  end
  setmetatable(env, {__index = _G})
  setfenv(func, env)
  return func,err
end
loadstring = load



#245243 Local variables by default

Posted by ViperLordX on 10 February 2016 - 04:44 AM in APIs and Utilities

Hello, fellow programmers! Have you become tired of the Lua variables being global by default? Well, I present unto you thirteen glorious lines of code which should be run upon the startup of a computer. They will not completely disable global variables, but make all variables local by default in any program run after it. If you must, you can still set global variables by doing _G.varname = "value," but doing varname = "value" will define a local variable as opposed to a global one. I've tested this with multiple complex programs, and it has caused no issues thus far and will hopefully solve quite a few problems with colliding variables. So here are my thirteen lines of code which will save you plenty of time and trouble. Simply run it on startup and it'll work its magic.

local oldload = load
function _G.load(str, arg1, arg2, arg3)
  local func = oldload(str, arg1, arg2, arg3)
  local env = getfenv(func)
  if (env == _G) then
	env = {}
  end
  setmetatable(env, {__index = _G, __newindex =
  function(table, var, val)
	rawset(env, var, val)
  end})
  return func
end



#245226 java.lang.ArrayIndexOutOfBoundsException at line 5?

Posted by ViperLordX on 09 February 2016 - 10:39 PM in Ask a Pro

Yes, thanks, but I already got it ;)



#245223 java.lang.ArrayIndexOutOfBoundsException at line 5?

Posted by ViperLordX on 09 February 2016 - 10:36 PM in Ask a Pro

So I've been trying to make a simple system to prevent people from defining global variables, and I did it like this:

args = {...}
if (#args == 1) then
  func = loadfile(args[1])
  env = {}
  setmetatable(env, {__index = _G, __newindex = function(table, val, var) env[var] = val end})
  setfenv(func, env)
  func()
end

However, when I run it on a simple program,

a = 1 print(a)

It tells me there's an ArrayIndexOutOfBoundsException at line 5 in gman, which is the one setting the metatable on env. Does anyone know why this is happening and how to fix it?

Ah, I found two problems after looking at my code for a while. I got two variables backwards, and I got a stack overflow by doing env[var] = val in the __newindex metamethod.



#237600 Quarantine program not functioning

Posted by ViperLordX on 10 November 2015 - 12:00 AM in Ask a Pro

Sorry about not trying your code, I didn't try it because I thought it was the same as mine... If you look at the cover() function, it's doing pretty much the same thing. Your way works now, but why? What's the difference?



#237598 Quarantine program not functioning

Posted by ViperLordX on 09 November 2015 - 11:53 PM in Ask a Pro

I did change it to _G.fs = vfs, and got the same error. I'll try your fix now, I thought I had done shell.resolve instead of hell.resolve.



#237475 Quarantine program not functioning

Posted by ViperLordX on 08 November 2015 - 07:36 PM in Ask a Pro

Could you explain how it causes the too long without yielding error to me and tell me how to fix it?

Oh, does fs.combine() use shell.resolve() so when I do cover() in shell.resolve(), it calls itself recursively?



#237461 Quarantine program not functioning

Posted by ViperLordX on 08 November 2015 - 06:50 PM in Ask a Pro

Didn't you admit that I shouldn't overwrite io.open?



#237371 Quarantine program not functioning

Posted by ViperLordX on 07 November 2015 - 10:35 PM in Ask a Pro

Ah, that makes sense. I'll try it.

Still not working, getting the same exact error at line 16.



#237336 Quarantine program not functioning

Posted by ViperLordX on 07 November 2015 - 06:22 PM in Ask a Pro

So what is the issue with the code? Why is it saying that it's too long without yielding when it's not even in a loop, and it's the first line in the function?



#237284 Quarantine program not functioning

Posted by ViperLordX on 07 November 2015 - 06:18 AM in Ask a Pro

My new code is below, and it's still not working. Now it thinks that anything within q does not exist, and it also errors if I do "edit ___" where ___ is anything, saying that it's too long without yielding on line 16 of all things: file = es.combine(file, ""). It's not even in a loop!
local function contains(table, value)
  for k, v in pairs(table) do
    if (v == value) then
	  return true;
    end
  end
  return false;
end
function main()
  local es = {}
  for k, v in pairs(fs) do
    es[k] = v
  end
  allowed = {"rom", "disk[1-6]"}
  function cover(file)
    file = es.combine(file, "")
    file = string.gsub(file, "%.%.", "")
    permitted = false
    for _, v in pairs(allowed) do
	  if (string.find(file, v)) then
	    permitted = true
	  end
    end
    if (not (permitted)) then
	  file = "q/"..file
    end
    return file
  end
  function uncover(file)
    file = es.combine(file, "")
    file = string.gsub(file, "^q/", "")
    return file
  end
  if (not es.exists("q")) then
    es.makeDir("q")
  end
  files = es.list("/")
  for k, v in pairs(files) do
    if (not (v == "start") and not (v == "q")) then
	  if (not (es.exists(cover(v)))) then
	    es.copy(v, cover(v))
	  end
	  if (not (es.isReadOnly(v)) and not (v == "q")) then
	    es.delete(v)
	  end
    end
  end
  local vfs = {}
  function vfs.list(path)
    r = es.list(cover(path))
    if (path == "") then
	  r[#r + 1] = "rom"
    end
    for k, v in pairs(r) do
	  r[k] = uncover(v)
    end
    return r
  end
  function vfs.exists(path)
    return es.exists(cover(path))
  end
  function vfs.isDir(path)
    return es.isDir(cover(path))
  end
  function vfs.isReadOnly(path)
    return es.isReadOnly(cover(path))
  end
  function vfs.getDrive(path)
    return es.getDrive(cover(path))
  end
  function vfs.getSize(path)
    return es.getSize(cover(path))
  end
  function vfs.getFreeSpace(path)
    return es.getFreeSpace(cover(path))
  end
  function vfs.makeDir(path)
    es.makeDir(cover(path))
  end
  function vfs.move(fromPath, toPath)
    es.move(cover(fromPath), cover(toPath))
  end
  function vfs.copy(fromPath, toPath)
    es.copy(cover(fromPath), cover(toPath))
  end
  function vfs.delete(path)
    es.delete(cover(path))
  end
  function vfs.open(path, mode)
    return es.open(cover(path), mode)
  end
  function vfs.find(wildcard)
    value = es.find(cover(wildcard))
    for k, v in pairs(value) do
	  value[k] = uncover(v)
    end
    return value
  end
  vfs.complete = es.complete
  vfs.combine = es.combine
  vfs.getName = es.getName
  fs = vfs
  local hell = {}
  function hell.resolve(name)
    return hell.resolve(cover(name))
  end
    function hell.resolveProgram(name)
    return hell.resolveProgram(cover(name))
  end
  setmetatable(hell, {__index = shell})
  shell = hell
end
main()



#237283 Quarantine program not functioning

Posted by ViperLordX on 07 November 2015 - 05:01 AM in Ask a Pro

Come to think of it, I could just do blah = {} then set blah.resolve(), then setmetatable(blah, {__index = shell}) shell = blah



#237275 Quarantine program not functioning

Posted by ViperLordX on 07 November 2015 - 02:55 AM in Ask a Pro

So how do I avoid this?



#237273 Quarantine program not functioning

Posted by ViperLordX on 07 November 2015 - 02:52 AM in Ask a Pro

Yes, I am



#237271 Quarantine program not functioning

Posted by ViperLordX on 07 November 2015 - 02:47 AM in Ask a Pro

No, I did this:
function shell.resolve(name)
  return blah.resolve(name)
end



#237249 Quarantine program not functioning

Posted by ViperLordX on 06 November 2015 - 09:38 PM in Ask a Pro

When I overwrite shell.resolve() or shell.resolveProgram(), the entire computer freezes, including the event queue but not the cursor, and then shuts down after a while.

Ok, I tested it, and it only seems to freeze shell, and nothing else. If I use lua to manually overwrite it, then exit lua, the shell freezes. It also happens if I make shell.resolve() return the value of blah.resolve() where blah = shell.



#237248 Quarantine program not functioning

Posted by ViperLordX on 06 November 2015 - 09:18 PM in Ask a Pro

Ok, I'll try it. Thanks!



#237197 Quarantine program not functioning

Posted by ViperLordX on 06 November 2015 - 01:03 AM in Ask a Pro

I've been writing a program designed to move everything to a folder, q, and make it virtually undetectable. When it runs, it will move all files other than itself and q to q, and it modifies the fs api so that everything appears normal. The problem is that if you try to run a program in the q folder while quarantined, it won't run. However, if you try running q/[program], it will. Can anyone explain this? fs.exists, fs.open, and everything else still work like I made them work. I don't know what shell is doing to break out.
function main()
  local es = fs
  allowed = {"rom", "disk[1-6]"}
  function cover(file)
    file = es.combine(file, "")
    file = file:gsub("%.%.", "")
    permitted = false
    for _, v in pairs(allowed) do
	  if (string.find(file, v)) then
	    permitted = true
	  end
    end
    if (not (permitted)) then
	  file = "q/"..file
    end
    return file
  end
  function uncover(file)
    file = es.combine(file, "")
    file = string.gsub(file, "^q/", "")
    return file
  end
  if (not es.exists("q")) then
    es.makeDir("q")
  end
  files = es.list("/")
  for k, v in pairs(files) do
    if (not (v == "start") and not (v == "q")) then
	  if (not (es.exists(cover(v)))) then
	    es.copy(v, cover(v))
	  end
	  if (not (es.isReadOnly(v)) and not (v == "q")) then
	    es.delete(v)
	  end
    end
  end
  local vfs = {}
  function vfs.list(path)
    r = es.list(cover(path))
    if (path == "") then
	  r[#r + 1] = "rom"
    end
    for k, v in pairs(r) do
	  r[k] = uncover(v)
    end
    return r
  end
  function vfs.exists(path)
    return es.exists(cover(path))
  end
  function vfs.isDir(path)
    return es.isDir(cover(path))
  end
  function vfs.isReadOnly(path)
    return es.isReadOnly(cover(path))
  end
  function vfs.getDrive(path)
    return es.getDrive(cover(path))
  end
  function vfs.getSize(path)
    return es.getSize(cover(path))
  end
  function vfs.getFreeSpace(path)
    return es.getFreeSpace(cover(path))
  end
  function vfs.makeDir(path)
    es.makeDir(cover(path))
  end
  function vfs.move(fromPath, toPath)
    es.move(cover(fromPath), cover(toPath))
  end
  function vfs.copy(fromPath, toPath)
    es.copy(cover(fromPath), cover(toPath))
  end
  function vfs.delete(path)
    es.delete(cover(path))
  end
  function vfs.open(path, mode)
    return es.open(cover(path), mode)
  end
  function vfs.find(wildcard)
    value = es.find(cover(wildcard))
    for k, v in pairs(value) do
	  value[k] = uncover(v)
    end
    return value
  end
  vfs.complete = es.complete
  vfs.combine = es.combine
  vfs.getName = es.getName
  fs = vfs
end
main()



#221405 Wanted: The Best Community Made Programs To Include In Computercraft. Seeking...

Posted by ViperLordX on 14 June 2015 - 09:22 PM in Programs

Ok, thanks.