Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by WermHat · Sep 17, 2015 at 10:29 PM · editor-scriptingscriptingbasicsscripting-underthehood

Does code wrapped in #if UNITY_EDITOR appear anywhere in builds?

Hi all,

Does code wrapped in '#if UNITY_EDITOR' appear anywhere in builds in a way that could be reverse engineered and discovered by malicious users?

I know that the code itself would not be executed, but I'm wondering whether it would appear anywhere at all in the final build (as plain text, for example).

Thanks!

Comment
Add comment · Show 2
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 _Gkxd · Sep 18, 2015 at 04:55 AM 1
Share

Theoretically, anything in the build can be reverse engineered. Someone with enough patience can always analyze the binary inside the file and figure out what your code is.

However, there is a difference between the build and the source. The source code contains human readable code which is easy for programmers to develop in. The build contains machine language, which the machine can run. Because the machine can't use source code, it wouldn't make sense to put it in the build, since that would be a waste of space.

When you have something like #if SO$$anonymous$$ETHING, and SO$$anonymous$$ETHING isn't defined, you can think of the enclosed text being physically removed from the file before compilation, but your source code won't be in the build either way.

A more practical use for this is to decrease file size in the final build. You don't need $$anonymous$$ac code on the Windows version or Windows code on the $$anonymous$$ac version, so using #if will help reduce the size of each build.

avatar image WermHat _Gkxd · Sep 19, 2015 at 12:48 AM 0
Share

$$anonymous$$uch appreciated!

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Pharan · Sep 18, 2015 at 05:45 AM

No, it's not included in the build. None of your C# or js code will appear in the build as plain text. Everything is compiled into Common Intermediate Language (IL for short). IL is a translation of your code that's faster for the runtime to read and execute. It's much less readable, but it can still be translated back into C#. There are tools that can make your code more difficult to read even if it is translated back. (read up on .NET obfuscators)

But regarding #if UNITY_EDITOR. The #if check happens at compile time and if the condition isn't met, whatever is inside it won't be included in the compilation. It won't be turned into IL. It won't be in the build.

So reason why "the code would not be executed" is because it won't be there at all.

@BMayne poses a good question though. What are you doing in there that's so dangerous?

Comment
Add comment · Show 2 · 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
avatar image WermHat · Sep 19, 2015 at 12:47 AM 0
Share

Thanks so much for the extremely detailed answer!

avatar image _Gkxd · Sep 19, 2015 at 04:36 AM 0
Share

I'd like to add that if you are storing passwords as string literals and they get compiled, it's easy to recover them even if the code is obfuscated. (You can't really obfuscate a string literal.)

A more secure way to include passwords in the build is to hash them beforehand. Here is a website that hashes a string: http://www.sha1-online.com/

When you type in the string "Hello" into the box, you'll get this string back: "f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0"

The idea is to implement (or find an implementation of) a hashing function and store the hash of your password. For example, if your string is "Hello", you will store "f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0" in the code.

Then in your code, ins$$anonymous$$d of checking if what the user types is equal to the password, you take what the user types, put it through your hash function, and then compare the result to the hash that you stored.

In pseudocode (if your password is "Hello"):

 bool matchesPassword(string whatThePlayerTyped) {
     return myHashFunction(whatThePlayerTyped) == "f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0";
 }
avatar image
2

Answer by BMayne · Sep 18, 2015 at 02:17 AM

Hey there,

When you say "can be discovered by malicious users" what do you mean? Do you have passwords baked into the preproc?

Cheers

Comment
Add comment · Show 1 · 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
avatar image WermHat · Sep 19, 2015 at 12:46 AM 0
Share

Thanks B$$anonymous$$ayne. I think Pharan covered the answer.

avatar image
1

Answer by Dave-Carlile · Sep 17, 2015 at 10:30 PM

This is called "conditional compilation". That symbol isn't defined when doing a build, so the code inside of it can't appear in the build because it doesn't exist.

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

6 People are following this question.

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

Related Questions

Running scripts from editor 1 Answer

How to execute a function in editor to populate an array? 1 Answer

help with 3d scroller skateboard chase script 0 Answers

beginner question: behavior of duplicated objects 1 Answer

Adding callbacks/events to an instantiated prefab 2 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