<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: YAKSH BARIYA</title>
    <description>The latest articles on DEV Community by YAKSH BARIYA (@thundercoding).</description>
    <link>https://dev.to/thundercoding</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F524663%2Fc6ec0cab-f0d1-4bbf-8820-7e3189a3ad16.jpeg</url>
      <title>DEV Community: YAKSH BARIYA</title>
      <link>https://dev.to/thundercoding</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thundercoding"/>
    <language>en</language>
    <item>
      <title>Code Obfuscation: Why, How &amp; When...</title>
      <dc:creator>YAKSH BARIYA</dc:creator>
      <pubDate>Thu, 03 Dec 2020 05:20:13 +0000</pubDate>
      <link>https://dev.to/thundercoding/code-obfuscation-why-how-when-ebg</link>
      <guid>https://dev.to/thundercoding/code-obfuscation-why-how-when-ebg</guid>
      <description>&lt;p&gt;With huge number of available code decompilers out there on the internet, it is becoming more important day by day to hide our source code, so that any reverse engineer cannot decompile it.&lt;/p&gt;

&lt;p&gt;Interpreted languages like Python &amp;amp; JavaScript have made obfuscation more necessary to protect the source code. Even though you package your app as an executable, you source code can still be viewed from the memory.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is Code Obfuscation?
&lt;/h1&gt;

&lt;p&gt;Code Obfuscation is the technology for making lives of reverse engineers hard so as to keep our source code safe.&lt;/p&gt;

&lt;p&gt;It's similiar to the Oxford provided defination for &lt;strong&gt;obfuscation&lt;/strong&gt; &lt;em&gt;&lt;code&gt;the action of making something obscure, unclear, or unintelligible.&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Code Obfuscation is the process of converting the actual source code to a unreadable and un-understandable code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Here's a Javascript Obfuscated Code Example
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Real Source Code
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;hi&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="nx"&gt;hi&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;hi&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Obfuscated Code
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;_0xcd38&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;log&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s1"&gt;x20World!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_0x1499a2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;_0x273593&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;_0xcd38c1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_0x13863e&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;_0x13863e&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;&lt;span class="nx"&gt;_0x1499a2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;push&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="nx"&gt;_0x1499a2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;shift&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]());}};&lt;/span&gt;&lt;span class="nx"&gt;_0xcd38c1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="nx"&gt;_0x273593&lt;/span&gt;&lt;span class="p"&gt;);}(&lt;/span&gt;&lt;span class="nx"&gt;_0xcd38&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mh"&gt;0xd7&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;_0x1386&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_0x1499a2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;_0x273593&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;&lt;span class="nx"&gt;_0x1499a2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;_0x1499a2&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mh"&gt;0x1a2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;_0xcd38c1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;_0xcd38&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;_0x1499a2&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;_0xcd38c1&lt;/span&gt;&lt;span class="p"&gt;;};&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;_0x425006&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;_0x18303c&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;_0x1386&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;_0x18303c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0x1a3&lt;/span&gt;&lt;span class="p"&gt;)](&lt;/span&gt;&lt;span class="nx"&gt;_0x18303c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0x1a2&lt;/span&gt;&lt;span class="p"&gt;));}&lt;/span&gt;&lt;span class="nx"&gt;_0x425006&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  How does Code Obfuscation work?
&lt;/h1&gt;

&lt;p&gt;As you can see, in the obfuscated code, the variable names have been changed, function name changed into random hex.&lt;/p&gt;

&lt;p&gt;Also, unnecessary variables and loops have been added so that no reverse engineer can understand it.&lt;/p&gt;

&lt;p&gt;I would also recommend you to experiment with it yourself, &lt;a href="https://obfuscator.io/"&gt;here is the link to the online JavaScript obfuscator which I used in the above example&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  How is Code Obfuscation different from Code Uglifying
&lt;/h1&gt;

&lt;p&gt;Code Uglifying is very different from Code Obfuscation. Code Uglification only removes excess space characters and tab characters, the uglified code can be easily brought back to it's earlier state using Beautifier use as Prettier for VS Code.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why obfuscate your code?
&lt;/h1&gt;

&lt;p&gt;Let's say you and your team is working hard on a new commercial application for your company. The application is obviously paid 💰. You released the first public version (v1.0.0).&lt;/p&gt;

&lt;p&gt;Now, after 2 days you get to know that your app is available as a free download on a 3rd party torrent website. You would be too sad after hearing this news.&lt;/p&gt;

&lt;p&gt;Your months and years of hard work was stolen!!&lt;/p&gt;

&lt;h2&gt;
  
  
  This situation could be prevented.
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How?
&lt;/h3&gt;

&lt;p&gt;If you had obfuscated your Source Code before compiling it and releasing.&lt;/p&gt;

&lt;h3&gt;
  
  
  How can Obfuscation prevent that? 😏
&lt;/h3&gt;

&lt;p&gt;Obfuscation will prevent your application's real source code from being viewed by any reverse engineer.&lt;/p&gt;

&lt;h3&gt;
  
  
  But how?
&lt;/h3&gt;

&lt;p&gt;As mentioned earlier, code Obfuscation changes variable names, line numbers, adds unnecessary loops so that it would become hard to understand it.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to obfuscate your code?
&lt;/h1&gt;

&lt;p&gt;There are many obfuscaters available on the internet, most of them are free and Open Source.&lt;/p&gt;

&lt;p&gt;To obfuscate your code, first of all you need to install an obfuscater. Then just follow their documentation 😉.&lt;/p&gt;

&lt;h2&gt;
  
  
  Here is a list of different obfuscators for different languages:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Java&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://www.guardsquare.com/en/products/proguard"&gt;ProGaurd&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Certainly the most popular and widely used Java Obfuscater.&lt;br&gt;
Comes pre-installed with Android Studio.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://java-source.net/open-source/obfuscators"&gt;See a more bigger list of Java Obfuscaters here&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  &lt;a href="https://obfuscator.io/"&gt;javascript-obfuscator&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Open Source JavaScript obfuscater. &lt;/p&gt;

&lt;p&gt;Available as a npm package 📦&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install --save-dev javascript-obfuscator
$ # OR
$ yarn add --dev javascript-obfuscator
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Python&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://pypi.org/project/pyarmor/"&gt;PyArmour&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Install&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip install pyarmor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/obfuscar/obfuscar"&gt;C#&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An Open Source C# obfuscater for you&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.android.com/studio/build/shrink-code"&gt;Android Studio&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Android Studio's official guide to obfuscate your app.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;C/C++&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;C or C++ does not require obfuscation. As C++ is directly compiled to machine language, decompiling it will give us only Assembly, which is very hard to understand&lt;/p&gt;

&lt;h1&gt;
  
  
  How safe Code Obfuscation is?
&lt;/h1&gt;

&lt;p&gt;Code Obfuscation is safe. But still I would recommend you to first test your app compiled with obfuscated code before releasing it.&lt;/p&gt;

&lt;p&gt;Also, while testing before production should be done without obfuscation, as obfuscation is very time consuming many times.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Also remember&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Your obfuscated code will be safer, but not safest.&lt;/p&gt;

&lt;h1&gt;
  
  
  Advantages and disadvantages of Code Obfuscation
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Advantages
&lt;/h2&gt;

&lt;p&gt;Code Obfuscation has many advantages&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code Shrinking&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code Obfuscation often removes unused code.&lt;/p&gt;

&lt;p&gt;For example, if your code has a if statement with a empty &lt;code&gt;else{}&lt;/code&gt;, then the else will be removed during obfuscation&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Source Code protection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's too obvious 😜&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Optimisation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As a result of Code Shrinking, the obfuscated code is often more optimised&lt;/p&gt;

&lt;h2&gt;
  
  
  Disadvantages
&lt;/h2&gt;

&lt;p&gt;Well, there are a huge number of advantages, there are also much more disadvantages too.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Malicious applications are often obfuscated&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Many of the malicious app creaters obfuscate their code so as to bypass Antivirus protection.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Antivirus often goes mad&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whenever you visit a website which has obfuscated code, sometimes your antivirus becomes mad. This is because, many sites obfuscate their code to hide malicious &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Obfuscated Browser Extensions no longer on Chrome &amp;amp; Firefox&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As Obfuscation is often used to hide malicious code, this action was announced by Google and Mozilla.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Fact: 70% of extensions removed from the Chrome Web Store were obfuscated.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Many a times obfuscation is time consuming&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I would always recommend you to test your app or anything without obfuscation first, then again test it after obfuscation.&lt;/p&gt;

&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;Code Obfuscation is very important of you are working on a huge app.&lt;/p&gt;

&lt;p&gt;There are a lot of decompilers available on the internet.&lt;/p&gt;

&lt;p&gt;Code Obfuscation can protect your code to a huge extent, but remember that everything is hackable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reply in comments 👇
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Do you obfuscate your code?
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Still here?
&lt;/h2&gt;

&lt;p&gt;I have something special for you...&lt;/p&gt;

&lt;p&gt;Follow me on &lt;a href="https://twitter.com/CodingThunder"&gt;Twitter(@CodingThunder)&lt;/a&gt; to see my #100daysofcode progress. I also share some good threads sometimes. :)&lt;/p&gt;

&lt;p&gt;Have a nice day..&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>important</category>
      <category>code</category>
      <category>codeobfuscation</category>
    </item>
  </channel>
</rss>
