This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Turtlemoviesco's profile picture

[Question]Virus

Started by Turtlemoviesco, 30 March 2012 - 03:08 PM
Turtlemoviesco #1
Posted 30 March 2012 - 05:08 PM
I want to make a virus on a floppy that puts a copy of its self on the computer. Now I want the virus to make a copy of all of the computers user created programs and put them in a new folder on the disk. Then I want the virus to edit the code of every program on the computer so if the person runs any of them it changes the computers startup to run the virus program. Fianlly the virus will change the computers current startup to run the virus file.

The reason for virus putting startup code in everyfile is beacuse the person will probbly just put a new boot floppy in and repace it.

Does anyone know how to do this? I can do the last step :o/>/>

Also if you know any other cool virus programs, feel free to share them.
Turtlemoviesco #2
Posted 30 March 2012 - 09:42 PM
Could someone also tell me how to make this code work?
when it runs, it edits the computers clear program so if a person uses it then there startup file will be messed up


h = fs.open("clear","w")
h.write("h = fs.open("startup","w")")
h.write("h.write("shell.run("virus")")")
h.write("h.close()")
h.close()
Espen #3
Posted 30 March 2012 - 11:57 PM
Could someone also tell me how to make this code work? when it runs, it edits the computers clear program so if a person uses it then there startup file will be messed up h = fs.open("clear","w") h.write("h = fs.open("startup","w")") h.write("h.write("shell.run("virus")")") h.write("h.close()") h.close()
You need to escape the double-quotes in strings with the back-slash character, like so:
h.write("h = fs.open("startup","w")")

EDIT: But keep in mind that you're not overwriting the 'clear' program, as that one is in the rom folder and thus can't be overwritten. What you're really doing is creating a new program in the root folder.
Turtlemoviesco #4
Posted 31 March 2012 - 03:00 AM
Could someone also tell me how to make this code work? when it runs, it edits the computers clear program so if a person uses it then there startup file will be messed up h = fs.open("clear","w") h.write("h = fs.open("startup","w")") h.write("h.write("shell.run("virus")")") h.write("h.close()") h.close()
You need to escape the double-quotes in strings with the back-slash character, like so:
h.write("h = fs.open("startup","w")")

EDIT: But keep in mind that you're mot overwriting the 'clear' program, as that one is in the rom folder and thus can't be overwritten. What you're really doing is creating a new program in the root folder.

ok thankyou, but if the person does shell.run("clear") will he be using my clear or the rom?
ComputerCraftFan11 #5
Posted 31 March 2012 - 07:26 AM
Could someone also tell me how to make this code work? when it runs, it edits the computers clear program so if a person uses it then there startup file will be messed up h = fs.open("clear","w") h.write("h = fs.open("startup","w")") h.write("h.write("shell.run("virus")")") h.write("h.close()") h.close()
You need to escape the double-quotes in strings with the back-slash character, like so:
h.write("h = fs.open("startup","w")")

EDIT: But keep in mind that you're mot overwriting the 'clear' program, as that one is in the rom folder and thus can't be overwritten. What you're really doing is creating a new program in the root folder.

ok thankyou, but if the person does shell.run("clear") will he be using my clear or the rom?

Your clear, also puting a . Before a name will make it invisible to programs like dir (but to run it you need to write shell.run(".whatever"))
Turtlemoviesco #6
Posted 01 April 2012 - 01:48 AM
Could someone also tell me how to make this code work? when it runs, it edits the computers clear program so if a person uses it then there startup file will be messed up h = fs.open("clear","w") h.write("h = fs.open("startup","w")") h.write("h.write("shell.run("virus")")") h.write("h.close()") h.close()
You need to escape the double-quotes in strings with the back-slash character, like so:
h.write("h = fs.open("startup","w")")

EDIT: But keep in mind that you're mot overwriting the 'clear' program, as that one is in the rom folder and thus can't be overwritten. What you're really doing is creating a new program in the root folder.

ok thankyou, but if the person does shell.run("clear") will he be using my clear or the rom?

Your clear, also puting a . Before a name will make it invisible to programs like dir (but to run it you need to write shell.run(".whatever"))
Wow thats good to know thanks
you seem to know alot, do you know how to make font and backdrop colorful in a program?
ComputerCraftFan11 #7
Posted 01 April 2012 - 02:12 AM
Could someone also tell me how to make this code work? when it runs, it edits the computers clear program so if a person uses it then there startup file will be messed up h = fs.open("clear","w") h.write("h = fs.open("startup","w")") h.write("h.write("shell.run("virus")")") h.write("h.close()") h.close()
You need to escape the double-quotes in strings with the back-slash character, like so:
h.write("h = fs.open("startup","w")")

EDIT: But keep in mind that you're mot overwriting the 'clear' program, as that one is in the rom folder and thus can't be overwritten. What you're really doing is creating a new program in the root folder.

ok thankyou, but if the person does shell.run("clear") will he be using my clear or the rom?

Your clear, also puting a . Before a name will make it invisible to programs like dir (but to run it you need to write shell.run(".whatever"))
Wow thats good to know thanks
you seem to know alot, do you know how to make font and backdrop colorful in a program?

You can't do font colors yet
Turtlemoviesco #8
Posted 01 April 2012 - 02:27 AM
Could someone also tell me how to make this code work? when it runs, it edits the computers clear program so if a person uses it then there startup file will be messed up h = fs.open("clear","w") h.write("h = fs.open("startup","w")") h.write("h.write("shell.run("virus")")") h.write("h.close()") h.close()
You need to escape the double-quotes in strings with the back-slash character, like so:
h.write("h = fs.open("startup","w")")

EDIT: But keep in mind that you're mot overwriting the 'clear' program, as that one is in the rom folder and thus can't be overwritten. What you're really doing is creating a new program in the root folder.

ok thankyou, but if the person does shell.run("clear") will he be using my clear or the rom?

Your clear, also puting a . Before a name will make it invisible to programs like dir (but to run it you need to write shell.run(".whatever"))
Wow thats good to know thanks
you seem to know alot, do you know how to make font and backdrop colorful in a program?

You can't do font colors yet
oh ok so what are the color things for in the API?
Turtlemoviesco #9
Posted 01 April 2012 - 02:54 AM
Could someone also tell me how to make this code work? when it runs, it edits the computers clear program so if a person uses it then there startup file will be messed up h = fs.open("clear","w") h.write("h = fs.open("startup","w")") h.write("h.write("shell.run("virus")")") h.write("h.close()") h.close()
You need to escape the double-quotes in strings with the back-slash character, like so:
h.write("h = fs.open(\"startup\",\"w\")")

EDIT: But keep in mind that you're mot overwriting the 'clear' program, as that one is in the rom folder and thus can't be overwritten. What you're really doing is creating a new program in the root folder.

ok thankyou, but if the person does shell.run("clear") will he be using my clear or the rom?

Your clear, also puting a . Before a name will make it invisible to programs like dir (but to run it you need to write shell.run(".whatever"))
Wow thats good to know thanks
you seem to know alot, do you know how to make font and backdrop colorful in a program?

You can't do font colors yet
oh ok so what are the color things for in the API?

I made a turtle program that is suppose to dig out a room but it wont work right, can you take a look at it?
[attachment=137:Rooms.txt]
Luanub #10
Posted 01 April 2012 - 04:40 AM
you have used else if multiple times in your code, it should be elseif 1 word.

and a few to many ends. you only need 1 end per if statement..


if
code
elseif
code
elseif
code
elseif
code
else
code
end

Edited on 01 April 2012 - 02:45 AM
Turtlemoviesco #11
Posted 01 April 2012 - 12:11 PM
you have used else if multiple times in your code, it should be elseif 1 word.

and a few to many ends. you only need 1 end per if statement..


if
code
elseif
code
elseif
code
elseif
code
else
code
end

Thank you, I thought it was weird that it wanted that many ends but it complained and said it wanted ends.
I am used to C++ and C# and they use if else with a space.
Does != work Lua? if so how would I use? in C++ it would be while X != 10 etc
that didn't seem to work in Lua
but thanks again
Turtlemoviesco #12
Posted 01 April 2012 - 12:38 PM
you have used else if multiple times in your code, it should be elseif 1 word.

and a few to many ends. you only need 1 end per if statement..


if
code
elseif
code
elseif
code
elseif
code
else
code
end


Ok well even though it was doing
if
else
if
else
etc
the way I have the code that did not change anything, the turtle still makes a bigger frst floor then asked and it only does 1 floor so if you want a 5x5x3 room it does 7x7x1. That is what I wanted to know how to fix
Luanub #13
Posted 01 April 2012 - 11:06 PM
!= in lua is ~= and yes you can do something like

while length ~= x do
stuff
end.

If I tell it to build a 5x5x2 room I get a 6x6x1. I notice that you have:

Y = Y + 1
X = X + 1

This is adding to this size. If I remove it I get 5x5x1. There is some logic issues in the code, need to better position him after the first layer so he can start on the second properly. As well as the logic to digUp doesn't seem to work. I'm going to play with it some more.

Okay I've got it so that it will do multiple layers. Part of your problem you were never resetting the checkLength and checkWidth vars after doing the first floor. As you will see there is some logical issues as to the turtle placement after the last row is dug. Probably needs to add in some extra intelligence to the turtle so it knows it is at the last row and position itself towhere it can cleanly start the next layer.

See comments in code for what was done:
Spoiler

checkLength = 1 -- changed to 1 to accommodate for turtle being in position 1, otherwise room would be selected length + 1.
checkWidth = 0
checkHeight = 0
down = Y
local rownum = X - 1 -- added so turtle will know to position itself for the next layer
--Y = Y + 1 -- removed adding extra layers
--X = X + 1 -- removed adding extra rows/columns
switch = false
while checkHeight < Y do
	checkHeight = checkHeight + 1
	while checkWidth < X do
		while checkLength < X do
			turtle.dig()
			turtle.forward()
			checkLength = checkLength + 1
		end
		checkLength = 1 -- updated so that you only get selected room size instead of +1
		-- print ("Room Status HxWxL: ")..checkHeight..("x")..checkWidth..("x")..checkLength..(" ")--
		if checkWidth == rownum then -- added for end of layer intel
			for x=1, 2 do
				turtle.turnLeft()
				checkWidth = checkWidth + 1
			end
		elseif switch == false then
			turtle.turnRight()
			turtle.dig()
			turtle.forward()
			checkWidth = checkWidth + 1
			turtle.turnRight()
			turtle.dig()
			switch = true
		else
			turtle.turnLeft()
			turtle.dig()
			turtle.forward()
			checkWidth = checkWidth + 1
			turtle.turnLeft()
			turtle.dig()
			switch = false			
		end
	end
	turtle.digUp() -- added so turtle would remove obstructions above prior to trying to move up
	turtle.up()
	checkLength = 0 -- reset for new layer
	checkWidth = 0 -- reset for new layer
	switch = false -- reset for new layer
end
while down > 0 do
	turtle.down()
	down = down - 1
end

Let me know if you run into anymore issues or need help with making the needed updates.

Okay I was bored so I just fixed it all the way… The code should work as you intended now..

You will have issues if you run into sand or gravel. I would update your forward movements to be something like what I have in my Turtle Tree Farmer API. Take a look at the forward() function.
Edited on 01 April 2012 - 11:39 PM
Turtlemoviesco #14
Posted 02 April 2012 - 02:50 PM
!= in lua is ~= and yes you can do something like

while length ~= x do
stuff
end.

If I tell it to build a 5x5x2 room I get a 6x6x1. I notice that you have:

Y = Y + 1
X = X + 1

This is adding to this size. If I remove it I get 5x5x1. There is some logic issues in the code, need to better position him after the first layer so he can start on the second properly. As well as the logic to digUp doesn't seem to work. I'm going to play with it some more.

Okay I've got it so that it will do multiple layers. Part of your problem you were never resetting the checkLength and checkWidth vars after doing the first floor. As you will see there is some logical issues as to the turtle placement after the last row is dug. Probably needs to add in some extra intelligence to the turtle so it knows it is at the last row and position itself towhere it can cleanly start the next layer.

See comments in code for what was done:
Spoiler

checkLength = 1 -- changed to 1 to accommodate for turtle being in position 1, otherwise room would be selected length + 1.
checkWidth = 0
checkHeight = 0
down = Y
local rownum = X - 1 -- added so turtle will know to position itself for the next layer
--Y = Y + 1 -- removed adding extra layers
--X = X + 1 -- removed adding extra rows/columns
switch = false
while checkHeight < Y do
	checkHeight = checkHeight + 1
	while checkWidth < X do
		while checkLength < X do
			turtle.dig()
			turtle.forward()
			checkLength = checkLength + 1
		end
		checkLength = 1 -- updated so that you only get selected room size instead of +1
		-- print ("Room Status HxWxL: ")..checkHeight..("x")..checkWidth..("x")..checkLength..(" ")--
		if checkWidth == rownum then -- added for end of layer intel
			for x=1, 2 do
				turtle.turnLeft()
				checkWidth = checkWidth + 1
			end
		elseif switch == false then
			turtle.turnRight()
			turtle.dig()
			turtle.forward()
			checkWidth = checkWidth + 1
			turtle.turnRight()
			turtle.dig()
			switch = true
		else
			turtle.turnLeft()
			turtle.dig()
			turtle.forward()
			checkWidth = checkWidth + 1
			turtle.turnLeft()
			turtle.dig()
			switch = false			
		end
	end
	turtle.digUp() -- added so turtle would remove obstructions above prior to trying to move up
	turtle.up()
	checkLength = 0 -- reset for new layer
	checkWidth = 0 -- reset for new layer
	switch = false -- reset for new layer
end
while down > 0 do
	turtle.down()
	down = down - 1
end

Let me know if you run into anymore issues or need help with making the needed updates.

Okay I was bored so I just fixed it all the way… The code should work as you intended now..

You will have issues if you run into sand or gravel. I would update your forward movements to be something like what I have in my Turtle Tree Farmer API. Take a look at the forward() function.
That makes alot of thanks, I will learn from what you corrected and all future will be alot better thanks alot.
Now back to the virus question lol still want to know about this :)/>/>
Is there a way I can add you so if I have any future questions I can ask you?
Luanub #15
Posted 02 April 2012 - 10:01 PM
Indeed hit me up anytime you need help. Just shoot me a PM on here and it will email me letting me know you have messaged me.