|
| 17 Nov 2013 03:55 PM |
I want to make it so it can take math problems from strings This works
Problem = "2 + 2" -- This will come from a text box, so it must be a string Math = "Answer = " .. Problem loadstring(Math)() print(Answer) |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2013 03:56 PM |
Fail
This works Problem = "2 + 2" -- This will come from a text box, so it must be a string Math = "Answer = " .. Problem loadstring(Math)() print(Answer)
But will also let people insert code
Problem = "print('HACKED')" -- This will come from a text box, so it must be a string Math = "Answer = " .. Problem loadstring(Math)() print(Answer)
Now imagine if instead of printing something they put a script |
|
|
| Report Abuse |
|
|
Zachiah
|
  |
| Joined: 27 Oct 2013 |
| Total Posts: 1401 |
|
|
| 17 Nov 2013 03:57 PM |
What's your question?
local SolveProblem = function(Expression) return loadstring('return ' ..Expression); end
print(SolveProblem('5 - 2 + 5')) -- > 8 |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2013 03:59 PM |
Problem = "2 + 2" Math = false pcall(function() Math = "Answer = "..loadstring(Problem)() end)
if Math ~= false then print(Math) else print(Invalid syntax, error) end |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2013 03:59 PM |
Whoops, lol, forgot quotes on the else print:
Problem = "2 + 2" Math = false pcall(function() Math = "Answer = "..loadstring(Problem)() end)
if Math ~= false then print(Math) else print("Invalid syntax, error") end |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2013 03:59 PM |
local SolveProblem = function(Expression) return loadstring('return ' ..Expression)(); end
print(SolveProblem("print('hacked')")) |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2013 04:00 PM |
@The Pcall will try and run the script though, so unless their script has a error in it, it'll still run |
|
|
| Report Abuse |
|
|
Bebee2
|
  |
| Joined: 17 May 2009 |
| Total Posts: 3985 |
|
|
| 17 Nov 2013 04:01 PM |
So why are you using the loadstring method o.o?
What exactly do you want? |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2013 04:01 PM |
Exactly.
That's why I check if math is not false, so I know their script ran correctly. |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2013 04:02 PM |
@Bee To turn string into a solved math problem @The It doesn't work qq |
|
|
| Report Abuse |
|
|
Zachiah
|
  |
| Joined: 27 Oct 2013 |
| Total Posts: 1401 |
|
|
| 17 Nov 2013 04:04 PM |
Oh, I only saw your first post.
Alright, easy fix:
local SolveProblem = function(Expression) if string.find(Expression,'%a') then print 'Invalid syntax' else return loadstring('return ' ..Expression)(); end end
print(SolveProblem('a + b')) -- > Invalid syntax print(SolveProblem('2 + 5')) -- > 7 |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2013 04:04 PM |
| Also if their code did run correctly, then it doesn't really matter anymore because it run :P |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2013 04:06 PM |
@Zach It works, what does %a do in string.find |
|
|
| Report Abuse |
|
|
Zachiah
|
  |
| Joined: 27 Oct 2013 |
| Total Posts: 1401 |
|
|
| 17 Nov 2013 04:07 PM |
It checks if there is an uppercase or lowercase letter is in the string.
http://wiki.roblox.com/index.php/String_patterns |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2013 04:08 PM |
| They could get around that with byte'd code qq |
|
|
| Report Abuse |
|
|
Bebee2
|
  |
| Joined: 17 May 2009 |
| Total Posts: 3985 |
|
|
| 17 Nov 2013 04:09 PM |
loadstring('\112\114\105\110\116\034\108\111\108\034')()
is the same as
loadstring('print"lol"')()
Hue hue.
+1 problem you have |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2013 04:10 PM |
@Bebee I said that first :3 |
|
|
| Report Abuse |
|
|
FoggedOut
|
  |
| Joined: 09 Dec 2011 |
| Total Posts: 3021 |
|
| |
|
|
| 17 Nov 2013 04:10 PM |
How would I check if it has a \ in it?
Just string.find(string, "\")
? |
|
|
| Report Abuse |
|
|
Zachiah
|
  |
| Joined: 27 Oct 2013 |
| Total Posts: 1401 |
|
|
| 17 Nov 2013 04:13 PM |
A forward slash is a way to put a string in a string, which wouldn't work using string.find.
When I run my function with bytecode it still prints 'Invalid syntax' |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2013 04:16 PM |
if string.find(StringProblem, "%a") or string.find(StringProblem, "\\") then This works, \ isn't part of math is it? |
|
|
| Report Abuse |
|
|
Bebee2
|
  |
| Joined: 17 May 2009 |
| Total Posts: 3985 |
|
| |
|
| |
|
|
| 17 Nov 2013 04:24 PM |
blah new problem now it can't use math.pi, ceil, or other things Guess I kinda just have to deal with that :c |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 17 Nov 2013 04:29 PM |
local swagFrag = loadstring("return math.pi")() print(swagFrag) >3.1415... |
|
|
| Report Abuse |
|
|