generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Loadstring()()

Previous Thread :: Next Thread 
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
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
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
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 is not online. 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
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
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
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
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
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
17 Nov 2013 03:59 PM
local SolveProblem = function(Expression)
return loadstring('return ' ..Expression)();
end

print(SolveProblem("print('hacked')"))
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
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 is not online. 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
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
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
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
17 Nov 2013 04:02 PM
@Bee
To turn string into a solved math problem
@The
It doesn't work qq
Report Abuse
Zachiah is not online. 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
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
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
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
17 Nov 2013 04:06 PM
@Zach
It works, what does %a do in string.find
Report Abuse
Zachiah is not online. 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
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
17 Nov 2013 04:08 PM
They could get around that with byte'd code qq
Report Abuse
Bebee2 is not online. 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
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
17 Nov 2013 04:10 PM
@Bebee
I said that first :3
Report Abuse
FoggedOut is not online. FoggedOut
Joined: 09 Dec 2011
Total Posts: 3021
17 Nov 2013 04:10 PM
xD

ℱoggedOut ~
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
17 Nov 2013 04:10 PM
How would I check if it has a \ in it?

Just string.find(string, "\")

?
Report Abuse
Zachiah is not online. 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
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
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 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
17 Nov 2013 04:17 PM
It isn't.
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
17 Nov 2013 04:20 PM
Alright thanks everyone
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image