Obfuscate my files and push to repository

Hi, all.

Hope you are going.

is it possible to obfuscate my files when i pushed to my repository and after obfuscated it should be pushed to another repository.

Is it possible using actions or is their any way to do like that.

Hoping with a positive response.

Regards, shiva

1 Like

@shivani-designer,

Do you mean that after pushing some modified or added files to a repository, then use workflow to automatically sync the new changes to another repository?
If so, here is an example workflow as reference:

# Suppose you will manually push new commits to GitHub repository 'Repos-01'
# and want to sync code to another GitHub repository 'Repos-02'.
# You can setup this workflow in repository 'Repos-01'.

name: Sync code

on: push
jobs:
  sync_code:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code from Repos-01
        uses: actions/checkout@v2
        with:
          persist-credentials: false
          path: Repos-01

      - name: Remove remote
        working-directory: Repos-01
        run: find . -type f | grep -i "\.git" | xargs rm

      - name: Checkout code from Repos-02
        uses: actions/checkout@v2
        with:
          repository: 'owner/Repos-02'
          token: ${{ secrets.MY_GITHUB_PAT }}
          path: Repos-02

      - name: Copy files
        run: cp -r Repos-01/* Repos-02

      - name: Push to Repos-02
        working-directory: Repos-02
        run: |
          git config --global user.name "user name"
          git config --global user.email "user email"
          git add -A
          git commit -m "commit message"
          git push

Thanks for the reply @brightran .

If you don’t mind can you tell, How can i obfuscate those files which are containing .js extension.

And rather than pushing to another repository i want to push to another branch is it possible?

@shivani-designer,

How can i obfuscate those files which are containing .js extension.

What do you mean about “obfuscate files” ? Can you give an example to explain the actual behavior you want.

And rather than pushing to another repository i want to push to another branch is it possible?

You can try to use the git-merge command to merge the new commits from a branch into another branch in the same repository.

@brightran,

Their is a tool called https://obfuscator.io for obfuscate javascript files.

For example:

if you have javascript file as following code:

function hi(){
console.log('hellow world');
} hi();

The above code will be converted to the file code

var _0xb5c3=['\x5b\x5e\x20\x5d\x2b\x29\x2b\x29\x2b\x5b','\x6c\x6f\x67','\x74\x65\x73\x74','\x5e\x20\x5d\x7d','\x61\x70\x70\x6c\x79','\x72\x65\x74\x75\x72\x6e\x20\x2f\x22\x20','\x5e\x28\x5b\x5e\x20\x5d\x2b\x28\x20\x2b','\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c'];(function(_0x1cc120,_0x44291b){var _0x11419d=function(_0x5c5c23){while(--_0x5c5c23){_0x1cc120['push'](_0x1cc120['shift']());}},_0x213fd4=function(){var _0x7a6eea={'data':{'key':'cookie','value':'timeout'},'setCookie':function(_0xf55458,_0x3e7a67,_0x2a9eeb,_0x3b09ba){_0x3b09ba=_0x3b09ba||{};var _0x2c14e1=_0x3e7a67+'='+_0x2a9eeb,_0x46ff37=0x1f*0x14+-0x1*0x1dc4+0xe*0x1f4;for(var _0x35fd98=0x131a+-0x1*0x259d+0x1283,_0x5b3236=_0xf55458['length'];_0x35fd98<_0x5b3236;_0x35fd98++){var _0x38c0bc=_0xf55458[_0x35fd98];_0x2c14e1+=';\x20'+_0x38c0bc;var _0x45d46d=_0xf55458[_0x38c0bc];_0xf55458['push'](_0x45d46d),_0x5b3236=_0xf55458['length'],_0x45d46d!==!![]&&(_0x2c14e1+='='+_0x45d46d);}_0x3b09ba['cookie']=_0x2c14e1;},'removeCookie':function(){return'dev';},'getCookie':function(_0x9f40d9,_0x58eea9){_0x9f40d9=_0x9f40d9||function(_0x55c652){return _0x55c652;};var _0x320814=_0x9f40d9(new RegExp('(?:^|;\x20)'+_0x58eea9['replace'](/([.$?*|{}()[]\/+^])/g,'$1')+'=([^;]*)')),_0x145a7b=function(_0x1db3c3,_0x444fe5){_0x1db3c3(++_0x444fe5);};return _0x145a7b(_0x11419d,_0x44291b),_0x320814?decodeURIComponent(_0x320814[0x1d4d*0x1+-0x444+-0x10b*0x18]):undefined;}},_0x3e926d=function(){var _0x58bbc7=new RegExp('\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*[\x27|\x22].+[\x27|\x22];?\x20*}');return _0x58bbc7['test'](_0x7a6eea['removeCookie']['toString']());};_0x7a6eea['updateCookie']=_0x3e926d;var _0xa38c04='';var _0x2f81a1=_0x7a6eea['updateCookie']();if(!_0x2f81a1)_0x7a6eea['setCookie'](['*'],'counter',-0x1*0xf55+0x14f0+-0x3*0x1de);else _0x2f81a1?_0xa38c04=_0x7a6eea['getCookie'](null,'counter'):_0x7a6eea['removeCookie']();};_0x213fd4();}(_0xb5c3,0x59*0x67+0x549*-0x1+-0x1d4e));var _0x4841=function(_0x4700dc,_0x1c8738){_0x4700dc=_0x4700dc-(0x1f*0x14+-0x1*0x1dc4+0xe*0x1f4);var _0x9d5f3=_0xb5c3[_0x4700dc];return _0x9d5f3;};function hi(){var _0x2c789a=function(){var _0x38d1fb=!![];return function(_0x2334e5,_0x5b6484){var _0x293cc9=_0x38d1fb?function(){if(_0x5b6484){var _0x48adad=_0x5b6484[_0x4841('\x30\x78\x34')](_0x2334e5,arguments);return _0x5b6484=null,_0x48adad;}}:function(){};return _0x38d1fb=![],_0x293cc9;};}(),_0x18ffba=_0x2c789a(this,function(){var _0x41ff5c=function(){var _0x564f12=_0x41ff5c['\x63\x6f\x6e\x73\x74\x72\x75\x63\x74\x6f'+'\x72'](_0x4841('\x30\x78\x35')+'\x2b\x20\x74\x68\x69\x73\x20\x2b\x20\x22'+'\x2f')()['\x63\x6f\x6e\x73\x74\x72\x75\x63\x74\x6f'+'\x72'](_0x4841('\x30\x78\x36')+_0x4841('\x30\x78\x30')+_0x4841('\x30\x78\x33'));return!_0x564f12[_0x4841('\x30\x78\x32')](_0x18ffba);};return _0x41ff5c();});_0x18ffba(),console[_0x4841('\x30\x78\x31')](_0x4841('\x30\x78\x37')+'\x64\x21');}hi();

So that anyone can’t read it and only browser can read it and debug it.

And they (https://obfuscator.io) provided a way to obfuscate code:

  • using NPM

Iam new to actions i don’t know how it can be wrote

So want my main aim is

  • I have repo named repo1 of two branches namly 1. Master 2. code
  • I will push my code to “code” branch. So when i push to this branch.
  • Only files with .js should be obfuscate using NPM
  • And push this obfuscated file to MASTER branch.
    Using actions.

If you don’t mind can you code for my aim.

Hoping with a positive response :innocent:

Regards, shivani

@shivani-designer,

In your repository, you can try to setup a workflow on the code branch like as this:

name: Obfuscate JavaScript code

on: push
jobs:
  obfuscate_code:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code from code branch
        uses: actions/checkout@v2
        with:
          ref: code
          path: b_code

      - name: Remove remote
        working-directory: b_code
        run: find . -type f | grep -i "\.git" | xargs rm

      # In this step you generally need to run some related command lines
      # of the JavaScript Obfuscator Tool to obfuscate the JavaScript code.
      # see 'https://github.com/javascript-obfuscator/javascript-obfuscator#cli-usage'
      - name: Obfuscate JavaScript code
        working-directory: b_code
        run: |
          --- some command lines to obfuscate the JavaScript code ---

      - name: Checkout code from master branch
        uses: actions/checkout@v2
        with:
          ref: master
          path: b_master

      # Copy files from b_code into b_master, the new obfuscated JavaScript files
      # will be copied to overwrite the old obfuscated JavaScript files in b_master.
      - name: Copy files
        run: cp -r b_code/* b_master

      - name: Push to remote master branch
        working-directory: b_master
        run: |
          git config --global user.name "user name"
          git config --global user.email "user email"
          git add -A
          git commit -m "Obfuscate JavaScript code"
          git push

@brightran,

I setup workflow as you said above

name: Obfuscate JavaScript code

on: push


jobs:
  obfuscate_code:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code from code branch
        uses: actions/checkout@v2
        with:
          ref: code
          path: b_code

      - name: Remove remote
        working-directory: b_code
        run: find . -type f | grep -i "\.git" | xargs rm

      # In this step you generally need to run some related command lines
      # of the JavaScript Obfuscator Tool to obfuscate the JavaScript code.
      # see 'https://github.com/javascript-obfuscator/javascript-obfuscator#cli-usage'
      - name: Obfuscate JavaScript code
        working-directory: b_code
        run: |
      
          javascript-obfuscator undex.js --output undex.js [options]
        
          

      - name: Checkout code from master branch
        uses: actions/checkout@v2
        with:
          ref: master
          path: b_master

      # Copy files from b_code into b_master, the new obfuscated JavaScript files
      # will be copied to overwrite the old obfuscated JavaScript files in b_master.
      - name: Copy files
        run: cp -r b_code/* b_master

      - name: Push to remote master branch
        working-directory: b_master
        run: |
          git config --global user.name "the-bug-finder"
          git config --global user.email "sandupatlashiva2@gmail.com"
          git add -A
          git commit -m "Obfuscate JavaScript code"
          git push

and i got an error in it.

if you don’t mind can i contact you personally to solve my problem.

The “command not found” error occurs because there is no step in your workflow that installs the javascript-obfuscator command, and it’s not part of the software installed by default on ubuntu-latest either. :wink:

1 Like

@shivani-designer,

As @airtower-luna mentioned, the JavaScript obfuscator is not the default software installed on GitHub-hosted runners. You need to install this tool before using it.

In the README of the the JavaScript obfuscator, it has shared the main commands to install this tool (see here).
In your workflow, you can reference the installation steps in the README to set a step for installing the JavaScript obfuscator on the runner.