Tag Archives: python

Yara python module – part 002 .

Before we start, I have to tell you that it is the continuation of an older tutorial you find here.
As you know the YARA is tool aimed at helping malware researchers to identify and classify malware samples.
The YARA tool help you to create descriptions of malware families based on textual or binary patterns.
This patterns – rules come with description consists of a set of strings and a boolean expression which determine its logic.
The YARA tool can be found on the official website.
First you need to install the python version
I used the yara-python-3.7.0.win-amd64-py3.5 version.
You need to use Python 3.5.0 version from here.
Let’s test the yara python module:

You can see the yara python module works well.
Let’s make a rule and test with a PDF file. This rule will tell us if the PDF come with links.
The rule is one file named detectpdflinks into this path:
C:\\BackUP\\Tools\\Python35\\detectpdflinks
The source code of this rule is:

Now will make the python script to use this yara rule with one pdf file:

You can see the uri on the variable named $the_uri.

Posted in All, Programming, Python, YARA. Tagged with , , , , , .

Blender 3D – sin mesh object with python.

This is a simple example of create one object from vertrices and edges using sin function.
First you need to create the mesh with: bpy.data.meshes.new .
The n number is random, you can use any number for vertices and edges.
This number is points for the drawing sin function.
The spaces variable is the range from this points.
Using for statements we can draw the sin function.
The last step is to add all of this into one object named sin.
This object will be link to the scene.
See the source code of this tutorial:

Posted in 3D, All, Blender 3D, Programming, Python. Tagged with , , , , , , , .

Blender 3D – script to show python code under console.

To run this script yo need to select the render to Cycles Render.
Then go to Compositing from Screen layout ( in the top of the screen) and select Use Nodes from Material.
This will make a default material with a Diffuse BSDF .
The next step is to select Scripting from Screen layout.
This will allow you to make a script.
Create a new text and add this source code:

Press keys Alt+P or run the script from Text – Run Script.
When you click on tabs or select something the print function will print the python code into Console output area.
This can be used to see parts of python code from addons or Blender API.
Example with Archimesh addon :
You need to have this addon install and press the books button.
The result of this source code is show into console output and can be used with console shell to add books into your Scene:

Posted in 3D, All, Blender 3D, Programming, Python. Tagged with , , , , , , , .

Python and LibreOffice – part 001.

As you know the LibreOffice includes several applications that make it the most powerful Free and Open Source office suite on the market: Writer (word processing), Calc (spreadsheets), Impress (presentations), Draw (vector graphics and flowcharts), Base (databases), and Math (formula editing).
This tutorial is about LibreOffice and python scripts used like macros.
First you need to assign the permission for your user to write into script folder.
The main reason come from your software – the LibreOffice and your script editor for python language need to using this path: C:\Program Files (x86)\LibreOffice 5\share\Scripts.
If you using one of the linux OS then he path will be: /Applications/LibreOffice.app/Contents/Resources/Scripts/python/.
Your script can be run using the LibreOffice macro : Tools – Macros – Organize Macros – Python.
This allow you to see the python files and also can be run with Run button.
I used LibreOffice version: 5.2.3.3 to make one default python script.
I open my python script with the LibreOffice default interface ( not Writer, Calc, Base, etc.) and this allow me to run python scripts for any type of LibreOffice apllications.
Let’s see the python script:

The output of the running script will be open under new document named Untitled 1.
The content of this result is: The Python version is 3.3.5 and the executable path is C:\Program Files (x86)\LibreOffice 5\program\soffice.bin.
The size of the text is 12, Default Style and font is Liberation Serif.
The python script is simple: Is like take the interface model and put some text into that.
About hasattr part is just for reduce your possible errors and avoid confusing differences in behavior between Python 2 and 3.
Don’t use Python’s hasattr() unless you’re writing Python 3-only code and understand how it works.
The sintax under Python 3 is:
hasattr(object, name)

The arguments are an object and a string. The result is True if the string is the name of one of the object’s attributes, False if not. (This is implemented by calling getattr(object, name) and seeing whether it raises an AttributeError or not.)

Posted in All, LibreOffice, Programming, Python, Windows 8. Tagged with , , , , , , .

Using python to make authentication into GMail API.

Is simple to do with python. The script I make is simple without classes.
Let’s start with first steps:
You need to create your project and then one credential with json file.
See the next image to see how is your json file. My json file is renamed to client_secret.json and is used by python script.
python-oauth2
The json file is into same folder with my python script.
After first run the script will make one json file named: gmail-python-quickstart.json.
Is simple way to get and put credentials to solve authentification to google.
Another step is to add GMail API library to your project. This allow you to use the functions from the GMail API.
The python script is very simple to do. Follow the part of this script.
Is need to use some python modules. One reason is to deal with email format, see email python module.
Some python modules are used to make authentication to google: oauth2client and apiclient.
I used argparse python module , but is no need to add arguments to the script.
The result of this script will send a email to: your@yahoo.com.
The email is created by CreateMessage function.
About the special value “me” that come from Google API and is for user.

Posted in All, Google API, Programming, Python. Tagged with , , , , , , , .