Skip to content

Commit

Permalink
security
Browse files Browse the repository at this point in the history
  • Loading branch information
arpruss committed Oct 5, 2015
1 parent f266116 commit 047c774
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 51 deletions.
Binary file modified python2-scripts.zip
Binary file not shown.
13 changes: 9 additions & 4 deletions python2-scripts/mcpipy/digitalclock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@
import time
import sys
import fonts
import ast

foreground = SEA_LANTERN # this needs Minecraft 1.8
background = AIR

def parseBlock(s):
try:
return ast.literal_eval(s)
except:
return globals()[s.upper()]

try:
if len(sys.argv) > 1 and not "__" in sys.argv[1]:
foreground = eval(sys.argv[1])
foreground = parseBlock(sys.argv[1])
except:
pass

try:
if len(sys.argv) > 2 and not "__" in sys.argv[2]:
background = eval(sys.argv[2])
background = parseBlock(sys.argv[2])
except:
pass

Expand Down
27 changes: 15 additions & 12 deletions python2-scripts/mcpipy/explosify.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,35 @@
# Code under the MIT license by Alexander Pruss
#

import mcpi.minecraft as minecraft
import mcpi.block as block
from mc import *
import math
import sys
from ast import literal_eval

def replace(mcx,mcy,mcz,R,mcblock,mcmeta):
def parseBlock(s):
try:
return literal_eval(s)
except:
return globals()[s.upper()]

def replace(mcx,mcy,mcz,R,mcblock):
for x in range(-R,R):
for y in range(-R,R):
for z in range(-R,R):
if (x**2 + y**2 + z**2 <= R**2 and mc.getBlock(mcx+x,mcy+y,mcz+z) != block.AIR.id):
mc.setBlock(mcx+x,mcy+y,mcz+z,mcblock,mcmeta)
if (x**2 + y**2 + z**2 <= R**2 and mc.getBlock(mcx+x,mcy+y,mcz+z) != AIR.id):
mc.setBlock(mcx+x,mcy+y,mcz+z,mcblock)

mc = minecraft.Minecraft()
mc = Minecraft()

playerPos = mc.player.getPos()
R = 20
b = block.TNT.id
m = 0
b = TNT

if len(sys.argv) >= 2:
R = int(sys.argv[1])
if len(sys.argv) >= 3:
b = int(sys.argv[2])
if len(sys.argv) >= 4:
m = int(sys.argv[3])
b = parseBlock(sys.argv[2])

replace(playerPos.x, playerPos.y, playerPos.z, R, b, m)
replace(playerPos.x, playerPos.y, playerPos.z, R, b)

mc.postToChat("Explosify done")
10 changes: 9 additions & 1 deletion python2-scripts/mcpipy/sphere.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
from mcturtle import *
import sys
from ast import literal_eval

def parseBlock(s):
try:
return literal_eval(s)
except:
return globals()[s.upper()]

t = Turtle()
t.pendelay(0)
if len(sys.argv) >= 2:
radius = int(sys.argv[1])
else:
radius = 10
if len(sys.argv) >= 3:
material = eval(sys.argv[2].replace("__","(undefined)"))
material = parseBlock(sys.argv[2])
else:
material = GOLD_BLOCK
t.penwidth(2*radius)
Expand Down
19 changes: 12 additions & 7 deletions python2-scripts/mcpipy/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from math import *
from sys import maxsize
from copy import copy
from ast import literal_eval
import re

def getSavePath(directory, extension):
Expand Down Expand Up @@ -122,19 +123,23 @@ def save(self,filename):
f.write("baseAngle,highWater,baseVehicle="+repr((self.baseAngle,self.highWater,self.baseVehicle))+"\n")
f.close()

@staticmethod
def safeEval(string):
if "__" in string:
raise ValueError
return eval(string)

def load(self,filename):
with open(filename) as f:
data = ''.join(f.readlines())
result = re.search("=\\s*(.*)",data)
if result is None:
raise ValueError
self.baseAngle,self.highWater,self.baseVehicle = Vehicle.safeEval(result.group(1))
self.baseAngle,self.highWater,v = literal_eval(result.group(1).replace("Block",""))
self.baseVehicle = {}
for key,value in v.items():
if isinstance(value,tuple):
if len(value) > 1:
self.baseVehicle[key] = Block(value[0], value[1])
else:
self.baseVehicle[key] = Block(value[0])
else:
self.baseVehicle[key] = Block(value)

self.curLocation = None

def safeSetBlockWithData(self,pos,block):
Expand Down
Binary file modified python3-scripts.zip
Binary file not shown.
13 changes: 9 additions & 4 deletions python3-scripts/mcpipy/digitalclock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@
import time
import sys
import fonts
import ast

foreground = SEA_LANTERN # this needs Minecraft 1.8
background = AIR

def parseBlock(s):
try:
return ast.literal_eval(s)
except:
return globals()[s.upper()]

try:
if len(sys.argv) > 1 and not "__" in sys.argv[1]:
foreground = eval(sys.argv[1])
foreground = parseBlock(sys.argv[1])
except:
pass

try:
if len(sys.argv) > 2 and not "__" in sys.argv[2]:
background = eval(sys.argv[2])
background = parseBlock(sys.argv[2])
except:
pass

Expand Down
2 changes: 1 addition & 1 deletion python3-scripts/mcpipy/donut.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ def draw_donut(mcx,mcy,mcz,R,r,mcblock):

draw_donut(playerPos.x, playerPos.y + 9, playerPos.z, 18, 9, GLASS)
mc.postToChat("Glass donut done")
draw_donut(playerPos.x, playerPos.y + 9, playerPos.z, 18, 6, WATER)
draw_donut(playerPos.x, playerPos.y + 9, playerPos.z, 18, 6, WATER_STATIONARY)
mc.postToChat("Water donut done")
27 changes: 15 additions & 12 deletions python3-scripts/mcpipy/explosify.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,35 @@
# Code under the MIT license by Alexander Pruss
#

import mcpi.minecraft as minecraft
import mcpi.block as block
from mc import *
import math
import sys
from ast import literal_eval

def replace(mcx,mcy,mcz,R,mcblock,mcmeta):
def parseBlock(s):
try:
return literal_eval(s)
except:
return globals()[s.upper()]

def replace(mcx,mcy,mcz,R,mcblock):
for x in range(-R,R):
for y in range(-R,R):
for z in range(-R,R):
if (x**2 + y**2 + z**2 <= R**2 and mc.getBlock(mcx+x,mcy+y,mcz+z) != block.AIR.id):
mc.setBlock(mcx+x,mcy+y,mcz+z,mcblock,mcmeta)
if (x**2 + y**2 + z**2 <= R**2 and mc.getBlock(mcx+x,mcy+y,mcz+z) != AIR.id):
mc.setBlock(mcx+x,mcy+y,mcz+z,mcblock)

mc = minecraft.Minecraft()
mc = Minecraft()

playerPos = mc.player.getPos()
R = 20
b = block.TNT.id
m = 0
b = TNT

if len(sys.argv) >= 2:
R = int(sys.argv[1])
if len(sys.argv) >= 3:
b = int(sys.argv[2])
if len(sys.argv) >= 4:
m = int(sys.argv[3])
b = parseBlock(sys.argv[2])

replace(playerPos.x, playerPos.y, playerPos.z, R, b, m)
replace(playerPos.x, playerPos.y, playerPos.z, R, b)

mc.postToChat("Explosify done")
2 changes: 1 addition & 1 deletion python3-scripts/mcpipy/grenade.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ def getXYZ(path, t1):
if t > path[-1][0]:
break

mc.setBlock(path[-1][1],REDSTONE_BLOCK)
mc.setBlock(path[-1][1],FIRE)
2 changes: 1 addition & 1 deletion python3-scripts/mcpipy/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,4 +851,4 @@ def selectFileAndGo():

mainloop()
else:
go("models/" + sys.argv[1] + ".txt", sys.argv[2:])
go(os.path.dirname(os.path.realpath(sys.argv[0])) + "/" + "models/" + sys.argv[1] + ".txt", sys.argv[2:])
10 changes: 9 additions & 1 deletion python3-scripts/mcpipy/sphere.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
from mcturtle import *
import sys
from ast import literal_eval

def parseBlock(s):
try:
return literal_eval(s)
except:
return globals()[s.upper()]

t = Turtle()
t.pendelay(0)
if len(sys.argv) >= 2:
radius = int(sys.argv[1])
else:
radius = 10
if len(sys.argv) >= 3:
material = eval(sys.argv[2].replace("__","(undefined)"))
material = parseBlock(sys.argv[2])
else:
material = GOLD_BLOCK
t.penwidth(2*radius)
Expand Down
19 changes: 12 additions & 7 deletions python3-scripts/mcpipy/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from math import *
from sys import maxsize
from copy import copy
from ast import literal_eval
import re

def getSavePath(directory, extension):
Expand Down Expand Up @@ -122,19 +123,23 @@ def save(self,filename):
f.write("baseAngle,highWater,baseVehicle="+repr((self.baseAngle,self.highWater,self.baseVehicle))+"\n")
f.close()

@staticmethod
def safeEval(string):
if "__" in string:
raise ValueError
return eval(string)

def load(self,filename):
with open(filename) as f:
data = ''.join(f.readlines())
result = re.search("=\\s*(.*)",data)
if result is None:
raise ValueError
self.baseAngle,self.highWater,self.baseVehicle = Vehicle.safeEval(result.group(1))
self.baseAngle,self.highWater,v = literal_eval(result.group(1).replace("Block",""))
self.baseVehicle = {}
for key,value in list(v.items()):
if isinstance(value,tuple):
if len(value) > 1:
self.baseVehicle[key] = Block(value[0], value[1])
else:
self.baseVehicle[key] = Block(value[0])
else:
self.baseVehicle[key] = Block(value)

self.curLocation = None

def safeSetBlockWithData(self,pos,block):
Expand Down

0 comments on commit 047c774

Please sign in to comment.