Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by YoungDeveloper · Sep 20, 2013 at 07:50 AM · changeaccesssecurityhack

Security and access specifiers

I somewhat knew that public variables can be changed by memory editor software, I wanted to be sure, so I made a little test using "Cheat engine", by using this code.

 public int a =101;

 void Start(){
         StartCoroutine(Count ());
 }
 
 void OnGUI(){
         GUILayout.Button(""+a);
 }
 
 IEnumerator Count(){
         for(;;){
             yield return new WaitForSeconds(2f);
             a ++;
         }
     }

Result: http://gyazo.com/0010223afdcfb943904f4190d8298e0b

Test Two, private and protected:

 private int a = 5;
 protected int b = 100;
     
 void Start(){
     StartCoroutine(Count());    
 }
     
 void OnGUI(){
     GUI.TextArea(new Rect(10,Screen.height/2,120,30),"Private int a: "+a);
     GUI.TextArea(new Rect(10,Screen.height/2+40,120,30),"Protected int b: "+b);
 }
     
 IEnumerator Count(){
     for(;;){
         yield return new WaitForSeconds(2f);
         a++;
         b++;
     }
 }

Result: http://gyazo.com/0517f5b8f0d4f580552e54b8ac067916

Private and protected types can be found and edited same as public.

Public variable can be easily found an changed to any integer. So my question is: Only way to keep variables safe is by only using private and protected access specifiers? If so, that means most variable accessing should rewritten, which is a pain.

Or are there other method for keeping run-time data safe, thanks!

Any experience and hints very appreciated.

Comment
Add comment · Show 10
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ShadoX · Sep 20, 2013 at 10:11 AM 0
Share

I guess you could either add sanity checks or just rewrite all/most of the code to change it to private/protected while using setters/getters assu$$anonymous$$g that there is any need for those. But I have no idea if using setters would change much, never really touched this subject.

avatar image ArkaneX · Sep 20, 2013 at 10:35 AM 0
Share

Is it really that bad that 5% of kids will try to edit your variables? $$anonymous$$aybe it's just better to spend your time on actually polishing your game, than to worry about cheat engine or other similar software.

avatar image DannyB · Sep 20, 2013 at 10:39 AM 0
Share

I tend to agree with @ArkaneX - I mean, you must have your reasons for wanting to protect everything, but even so, you probably need to protect only the things that can cause actual damage to you (financially, ot to public leaderboards etc.).

avatar image YoungDeveloper · Sep 20, 2013 at 10:47 AM 0
Share

Of course, if we are talking about single player type of game- project, I'm sure, i wouldn't care. But completely different case is if It's multiplayer, letting player change sensitive stats would be critical.

avatar image ArkaneX · Sep 20, 2013 at 11:02 AM 0
Share

I'm not an expert of multiplayer games development, but I'm sure that security here must be based on comparing data stored on server and client.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Jamora · Sep 20, 2013 at 12:32 PM

There is no universal way to keep run-time data safe.

One way you can keep your run-time data safe is to break value-types into multiple variables and use a getter to combine those. This method is still only effective against memory editors, as the code (at least C# code) can easily be decompiled from the assemblies. Native code can of course be decompiled into assembly and anyone with sufficient knowledge can figure out what you're doing.

The key to preventing this decompilation (from being fruitful) is obfuscation.

Let's consider your example. You have variable a, which you proved can easily be found with at least one memory editor. The way you could secure this data is to use variables a1 and a2, which split the responsibility of describing a value. In other words, you could have half of a in a1, and the other half in a2. Alternatively (possibly more secure) is to randomly add to either value). Then in a public int GetA() function sum the variables and return it. You would also need setters to determine which variable is being added to etc.

Same as above in code:

     private int a1;
     private int a2;
     
     public int A{
         get{ return a1+a2; }
         set{ 
             int temp = value/2;
             a1 += temp;
             a2 += value-temp;
         }
     }

And so many people complain how useless getters/setters (properties are the same thing) are...

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity remote security vulnerablity risk identified. Is there a patch for beta versions? 2 Answers

Players can decompile my game and find out the login and password to my sql server.... WHAT DO I DO?? 5 Answers

Changing variable of another object (C#) 1 Answer

How to get Scripts attached GameObject from within a Struct declared in the Class 1 Answer

Strange issue of MacBook,access Denied to Internet,when required by any Package/Plugin 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges