Wanting to expand my horizons I decided to pick up programming and I've read that python is very beginner-friendly, knowing this I downloaded the program in addition to the PyCharm text editor and started to write some small stuff like print commands and the like. However, I wanted to start doing more and embarked on a mission to replicate a game off the internet, more specifically snake just to see how it all functions together in a cohesive manner. Every tutorial begins with "import" commands in addition to something like "math" and "random" directly after, turning red every single time. But for me, it just turns grey with the original orange "import" text also turning grey with a help icon saying to optimize my imports but just deleting my text altogether when I click it. I can find anything on the web to help me with what I'm dealing with leading me to believe that its probably an easy fix that I, for whatever reason can't seem to find. I really don't have a clue as to what to do and im increasingly becoming more and more frustrated.
That is okay, PyCharm is only signaling you that you haven't used that module yet. This can help Developers in large programs to save code and memory. Don't worry about it just ignore it and continue.
Related
I'm creating a program in python (2.7) and I want to protect it from reverse engineering.
I compiled it using cx_freeze (supplies basic security- obfuscation and anti-debugging)
How can I add more protections such as obfuscation, packing, anti-debugging, encrypt the code recognize VM.
I thought maybe to encrypt to payload and decrypt it on run time, but I have no clue how to do it.
Generally speaking, it's almost impossible for you to make your program unbreakable as long as there's enough motive for the hackers.
But still you can make it harder to be reverse engineered, try to use cython to compile your core codes into pyd or so files.
There's no way to make anything digital safe nowadays.
What you CAN do is making it hard to a point where it's frustrating to do it, but I admit I don't know python specific ways to achieve that. The amount of security of your program is not actually a function of programsecurity, but of psychology.
Yes, psychology.
Given the fact that it's an arms race between crackers and anti-crackers, where both continuously attempt to top each other, the only thing one can do is trying to make it as frustrating as possible. How do we achieve that?
By being a pain in the rear!
Every additional step you take to make sure your code is hard to decipher is a good one.
For example could you turn your program into a single compiled block of bytecode, which you call from inside your program. Use an external library to encrypt it beforehand and decrypt it afterwards. Do the same with extra steps for codeblocks of functions. Or, have functions in precompiled blocks ready, but broken. At runtime, utilizing byteplay, repair the bytecode with bytes depending on other bytes of different functions, which would then stop your program from working when modified.
There are lots of ways of messing with people's heads and while I can't tell you any python specific ways, if you think in context of "How to be difficult", you'll find the weirdest ways of making it a mess to deal with your code.
Funnily enough this is much easier in assembly, than python, so maybe you should look into executing foreign code via ctypes or whatever.
Summon your inner Troll!
Story time: I was a Python programmer for a long time. Recently I joined in a company as a Python programmer. My manager was a Java programmer for a decade I guess. He gave me a project and at the initial review, he asked me that are we obfuscating the code? and I said, we don't do that kind of thing in Python. He said we do that kind of things in Java and we want the same thing to be implemented in python. Eventually I managed to obfuscate code just removing comments and spaces and renaming local variables) but entire python debugging process got messed up.
Then he asked me, Can we use ProGuard? I didn't know what the hell it was. After some googling I said it is for Java and cannot be used in Python. I also said whatever we are building we deploy in our own servers, so we don't need to actually protect the code. But he was reluctant and said, we have a set of procedures and they must be followed before deploying.
Eventually I quit my job after a year tired of fighting to convince them Python is not Java. I also had no interest in making them to think differently at that point of time.
TLDR; Because of the open source nature of the Python, there are no viable tools available to obfuscate or encrypt your code. I also don't think it is not a problem as long as you deploy the code in your own server (providing software as a service). But if you actually provide the product to the customer, there are some tools available to wrap up your code or byte code and give it like a executable file. But it is always possible to view your code if they want to. Or you choose some other language that provides better protection if it is absolutely necessary to protect your code. Again keep in mind that it is always possible to do reverse engineering on the code.
I want to create a program with a GUI using Python. This program should show a list of nodes somewhere and allow me to insert them on a working diagram. I also need this nodes connected in some sequence. The following image is similar to what I need, it's from Orange3.
I come from a web development background and I've used Python for some Data Science but all using Terminal so right now I feel a little lost on where to get started.
I would much appreciate some help on where to look. Also I would like to use, if possible, existing tools instead of having to develop everything from scratch. Maybe there even is a project that does what I need and I could fork it from Github.
Thanks a lot for the help.
Check out Tkinter. Its great for GUI. Hard to add in images though. You could use Base64 to add in images.
There are plenty but it's best to create it yourself. There are infinite tutorials. Besides its gonna be full of bugs if you try to alter code that isn't yours.
As the title says. I'll give some background as to why I ask this question. I have just started learning a bit of python, and embarrassingly I have re-named all the files in the anaconda folder by running a script I had written in the wrong folder due to misinterpreting the code I was using as an example. This is incredibly frustrating as you can imagine and seems to be quite an easy mistake for a beginner to make. I was wondering if there are any techniques to prevent this sort of thing happening when you're learning, other than being more careful?
Thanks for your advice.
Christian
With low level languages like Assembly, it was much more common for beginners to make damaging mistakes but now adays, you cant do too much damage without really trying to do damage if that makes sense.
When it comes to scripts you don't entirely follow, you should look for things like
Does it modify/read a file?
Does it run any system commands like "rm -rf"
Does it have any infinite loops or anything that seems strange?
Of course this is just a very simple list, there is no actual check list for "bad stuff".
In your case, it sounds like you just got unlucky. Don't look at it as a failure, look at it as you learned what the script can do.
You can also set up a Virtual Machine to use as a "sandbox" for your applications.
One last thing, since you are starting on this journey, it is important to make backups of your code/workspace and your important computer files. This is because you might want to go back to a previous version of your code.
I prefere setting up a virtual machine while coding
"potential dangerous things"
VM's also have the advantage of making snapshots before running the code that afterwards easily can be reset (e.g. for testing things multiple times)
I'm using vim with ConqueTerm and ipython (--pylab if it matters) on Ubuntu 14.04. When I select multiple lines and send them using F9, everything pastes in the same line, as in this question. I could try remapping as the poster did for that question, but I don't have this issue with matlab on the same machine or with ConqueTerm+ipython on mac. Is there a way to fix this so I can continue using F9? Thanks!
The solution
It was my first experience using vimscript, but I was able to modify the plugin so it can send the selected lines properly.
I changed the send_selected function in the conque.vim(or another mirror)\autoload\conque_term.vim to this: https://gist.github.com/freencis/28e351e3bb267a8522e1dff53436fb8d
The function name is the same, just go there and replace it.
What I did
I will skip the "explaing what was wrong" part, mostly because I didn't fully grasp the original implementation.
So, after searching a bit on the internet about how I could access the file's text from a plugin, I ended up finding a way to get the text from specific lines from the file: using the getline function. Luckly there were already a Conque's function to send the line to the terminal and execute it (used by the 's send_file), so I just used it.
Then It was just a matter of knowing which lines were selected and get those. Which led me to the line function, which returns the line number in a different ways. One of these was by marker, in this case the '<, '> markers from the visual selection. Unfortunately I also don't know how to explain these, but calling line("'<") and line("'>") returned me the selection's start and end lines respectively.
And that was the vimscript programming part, the :help is really a life saver. The traditional programming was just looping through the line numbers, getting the text from those and sending them to the terminal.
Notes
It was my first ever experience with vimscript (I've only been using vim for a month), so I'm sure it might not the proper way to do it, plus I replaced a functionality, so I'm just sharing it as a quick hack. Any feedback is appreciated.
Props to http://learnvimscriptthehardway.stevelosh.com/, it helped me a lot with the language, I never expected it to be that accessible
And sorry for any bad English. peace
i have been delving into ida Pro for the last couple of weeks to get a bit of a background.
Something that has been bugging me for a long time though is the seemingly lack of support for pulling out the imported functions.
All i want is a script that can copy the entire imports window and paste into a text file, but I am having serious trouble finding anything in the API's that can help me do this. It should be very simple, yet I find it impossible. I have managed to find things to pull out the library's from this window, but nothing to pull out everything.
any help or direction would be much appreciated.
I agree with the assertion that you should use Ctrl+Ins or dumpbin.
However, what you ask has been solved already by the IDAPython project and I suggest you head over and look at their examples (here and here), especially this one.
The relevant idaapi functions are:
idaapi.get_import_module_qty
idaapi.enum_import_names
GUI Solution:
You can copy the entire contents of the imports window by placing focus on that window and hitting Ctrl+Ins.
IDAPython Solution:
This may need to be tweaked to your liking, but this should hopefully get you started:
text = ""
seg = SegByName(".idata")
for i in xrange(seg, SegEnd(seg), 4):
text += "%08x %s\r\n" % (i, Name(i))
open(r"c:\imports.txt", "wb").write(text)