Colaboratory importing .py files error - python

I mounted Google drive in Colaboratory and set path to the drive/.
It seems that the path is set correctly, however when I run my code, the files can't be read. I am quite sure that proc_data_lib.py is a pythonfile instead of zip file and the first few lines of that python file is in the second picture
Error Images
File:proc_data_lib.py
ERROR INFO: File "drive/ECMLDeepAudio-Master/lib/proc_data_lib.py", line 1
PK�����rpL^�2'���'������mimetypeapplication/vnd.oasis.opendocument.textPK�����rpL/�4z���������Thumbnails/thumbnail.png�PNG
^
SyntaxError: invalid syntax

The problem here is that the file is not just a text file -- from the error message, it seems to be a custom format of type oasis.opendocument.text, which looks to be an OpenOffice file. Were you writing the file with something like OpenOffice?
Switching to a vanilla text file should fix things.

Related

Reading file in python on the Mac

I am very new on this platform and I need help reading a file in python. First, it was a docx file because I am using Mac, I converted it into a txt file ,but still have file not found error.
Here is some code:
opdoc = open('PRACT.txt')
print(opdoc.readline())
for each in opdoc :
print(each)
and this the error output: FileNotFoundError: [Errno 2] No such file or directory: 'PRACT.txt'
Unless your file is in the exact same directory as your python file, you'll get this error. Even then, it's best practice to include some sort of relative filepath, like "./PRACT.txt". In general, your issue stems from the fact that Python doesn't know where to look for your file, and where it does know to look, the file isn't there. You need to provide the full path to the file, like:
with open("path/to/file/PRACT.txt", "rb") as f:
# read file etc
Make a new folder and put the txt file in it and also the programme itself. Or just put them in the same directory.
As you have this error ( No such file or directory: 'PRACT.txt') your code couldn't find the file because they were not in the same directory. When you use open("README.txt") the programme is assuming that the text is in the same directory as your code. If you don't want them in the same directory you could also try open(f"[file_path]") and that should work.

Decoding a Payload using GitHub Decoder Script

Abstract:
I am analysing a pcap file, with live malware (for educational purposes), and using Wireshark - I managed to extract few objects from the HTTP stream and some executables.
During my Analysis, I found instances hinting Fiestka Exploit Kit used.
Having Googled a ton, I came across a GitHub Rep: https://github.com/0x3a/tools/blob/master/fiesta-payload-decrypter.py
What am I trying to achieve?
I am trying to run the python fiesta-payload-decrypter.py against the malicious executable (extracted from the pcap).
What have I done so far?
I've copied the code onto a plain text and saved it as malwaredecoder.py. - This script is saved in the same Folder (/Download/Investigation/) as the malware.exe that I want to run it against.
What's the Problem?
Traceback (most recent call last):
File "malwaredecoder.py", line 51, in <module>
sys.exit(DecryptFiestaPyload(sys.argv[1], sys.argv[2]))
File "malwaredecoder.py", line 27, in DecryptFiestaPyload
fdata = open(inputfile, "rb").read()
IOError: [Errno 2] No such file or directory: '-'
I am running this python script in Kali Linux, and any help would be much appreciated. Thank you.
The script expects two args... What are you passing it?
Looks like it expects the args to be files and it sees a -, (dash), as the input file.
https://github.com/0x3a/tools/blob/master/fiesta-payload-decrypter.py#L44 Here it looks like the first arg is the input file and second is the output file.
Try running it like this:
python malewaredecoder.py /Download/Investigation/fileImInvestigating.pcap /Download/Investigation/out.pcap
All that said, good luck, that script looks pretty old and was last modified in 2015.

Python 3.8.6 Invalid Character in identifier splittext

I'm working on a script in Python 3.8.6 to load .sql files into big query. We're adding some non .sql files into our repo and I want my python script to only look at sql files, so I added an if statement in my loop and now I get an error: Invalid Character in identifier.
for filename in os.listdir(self.script_dir):
if os.path.splitext(filename)[1] == '.sql':
self.logger.info(os.path.join(self.script_dir, filename))
sql = self.read_sql(os.path.join(self.script_dir, filename))
Any idea as to why this is happening? There is actually only one file in the directory that its running for, which does not have a .sql extension. The original file was a text file saved with no extension (we use it to check in empty folders), I added a .txt extension to it as well and still get the same error.
Maybe there is a zero width space somewhere, copied from some website or pdf. Try to delete the line and retype it.

Python calling .txt file in same folder

I'm trying to access the .txt file in my project folder (in the same folder). But I am kept getting FileNotFoundError: [Errno 2] No such file or directory: '\u200e\u2068useragents.txt' error.
Code is;
USER_AGENT_LIST = "‎⁨useragents.txt"
it seems like you have a control character in your file name value. erase and write the file name again. Check if your editor or IDE has the feature to show invisible control characters. you will be able to see it.

Search and replace in current file with Sublime Text plugin

I am trying to port a Sublime Text build system to a plugin.
The build system would receive the current file and go through it with this code:
for line in fileinput.input(inplace=1):
sys.stdout.write(makeReplacements(line))
Now, in the plugin syntax I go the fact that the way to get my current file's content is:
input = self.view.substr(
sublime.Region(0, self.view.size())
)
But now I'm not sure about what I should do about the next operation.
for line in input(inplace=1):
How could I make replacements in the file on-the-fly and then save it?
I don't think the Sublime Text plugin API can save the buffer, but you could use the file_name() method in the sublime.View class and work with the file directly.
As noted by #MattDMo, the file can be saved using view.run_command('save').
It may be easier to use the file name if your old build file worked with that.
As stated by #RazerM, the first argument has to be the file path. So for my example, this will work.
for line in fileinput.input(self.view.file_name(), inplace=1):
sys.stdout.write(self.makeReplacements(line))

Categories

Resources