Part 3: Creating Modules for Juliar in Python

September 13, 2016 | Views: 1637

Begin Learning Cyber Security for FREE Now!

FREE REGISTRATIONAlready a Member Login Here

In the last tutorial, we learned how to use optionals correctly: https://www.cybrary.it/0p3n/part-2-creating-modules-juliar-python/

In this tutorial we will learn how to make modules and have juliar only load certain commands.

We do this by creating a def commands():

Please NOTE that we are not doing def commands(content,optionals);

This is a special exception, since it’s technically not a command, but rather used as a description. For the sake of the tutorial we will call it descriptor. This descriptor should only do the following: return the list of usable commands.

This is very useful for two reasons:

  1. If you want to create def that you wish not to be a command.
  2. You and other people editing your module can clearly see what commands the module provides for use in Juliar.

If you do not create def commands, all commands will be exported, which is fine; however, we want to stay away from this behavior if we are developing an advanced module.

If you have a command:

  • def copy(obj1):
  • return obj1+obj1
  • def repeat(content,optionals):
  • return copy(content)

You obviously don’t want to export copy (if you are not sure why, read part 1 & 2 of this tutorial again), but command copy will be exported automatically. We do not want to export copy. Copy is just a helper def for repeat def.

Also, if your module contains 20 commands, you may not know which commands the module contains. Placing the descriptor def commands(): at the top so that it provides a convenient way to see what are the commands called that are being exported to Juliar.

Let’s make a sample script and test it in Juliar def commands():

  • return “repeat repeatmore”
  • def copy(obj1):
  • return obj1+obj1
  • def repeat(content,optionals):
  • return copy(content)
  • def copy2x(obj1):
  • return copy(obj1)+copy(obj1)
  • def repeatmore(content,optionals):
  • return copy2x(content)
  • Save the file as test.py

Let’s test it in Juliar. Import a module in juliar via *import=py test.py*

Juliar should output the following commands: repeat repeatmore. Take a note that copy2x, commands, and copy have not been exported. You can freely use repeat and repeatmore.

Now let’s try removing def commands():

return “repeat repeatmore” and reimporting the module to juliar via *import=py test.py*

You will notice that copy, repeat, copy2x, repeatmore have been imported.

Let’s try to execute copy…We will get an error… Aaah. So remember to use def commands(): to your advantage!:)

Congratulations, you’ve gotten an orange belt in creating a module in Juliar.
Hope you enjoyed the tutorial! If you have any other questions, please check out the official website of Juliar at www.juliar.org or post the questions here.

Share with Friends
FacebookTwitterLinkedInEmail
Use Cybytes and
Tip the Author!
Join
Share with Friends
FacebookTwitterLinkedInEmail
Ready to share your knowledge and expertise?
Comment on This

You must be logged in to post a comment.

Our Revolution

We believe Cyber Security training should be free, for everyone, FOREVER. Everyone, everywhere, deserves the OPPORTUNITY to learn, begin and grow a career in this fascinating field. Therefore, Cybrary is a free community where people, companies and training come together to give everyone the ability to collaborate in an open source way that is revolutionizing the cyber security educational experience.

Cybrary On The Go

Get the Cybrary app for Android for online and offline viewing of our lessons.

Get it on Google Play
 

Support Cybrary

Donate Here to Get This Month's Donor Badge

 
Skip to toolbar

We recommend always using caution when following any link

Are you sure you want to continue?

Continue
Cancel