Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https://github.com/JPaulMora/FileHider/blob/master/FileHidder.py
- # Comments For Ptt Old-Games
- #!/usr/bin/env python
- import binascii
- import sys
- #import PyQt4 some time in the future..
- from os.path import expanduser, splitext
- args = sys.argv
- home = expanduser("~")
- # 設定「以 hex 讀取檔案」的功能,讓 36 行下面的程式碼可以使用
- def hexstr(fn): # This function makes use of binascii to read file in hex mode
- with open(fn, 'rb') as f:
- content = f.read()
- Payload = (binascii.hexlify(content))
- return Payload
- # 設定「寫入檔案」的功能,讓 36 行下面的程式碼可以使用
- def merger(cov,pld,ext):
- Final = binascii.unhexlify(str(cov)) + "overherelolz" + ext + "extafter"+ binascii.unhexlify(str(pld))
- return Final
- # 設定指令,需要時出現以下文字
- # Usage: args[0] < hide|get > /file/to/unhide.png
- #
- # Example: args[0] hide /path/to/MySecretMessage.txt /some/funny.gif
- # 此行顯示指令錯誤原因
- def usage(reason, ecode):
- print " Usage: " + str(args[0]) + " < hide|get > /file/to/unhide.png\n\n Example: " + str(args[0]) + " hide /path/to/MySecretMessage.txt /some/funny.gif\n"
- print reason + "\n"
- sys.exit(ecode)
- # 如果輸入的參數數量正確
- if len(args) >= 3 and len(args) <= 4:
- if args[1] == "hide":
- # 設定 Cover 為被更改的檔案(以 hex 讀取檔案)
- Cover = hexstr(args[3])
- # 設定 ExtCov 為被更改的檔案的副檔名
- ExtCov = splitext(args[3])[1]
- # 設定 ExtPay 為加入的檔案的副檔名
- ExtPay = splitext(args[2])[1]
- # 設定 Payload 為加入的檔案(以 hex 讀取檔案)
- Payload = hexstr(args[2])
- # 設定 destfile(輸出的檔案位置)為桌面的 Changedfile.XXX,XXX 為被更改的檔案的副檔名
- destfile = home +"/Desktop/Changedfile" + ExtCov
- # 在視窗中顯示 writting .../Desktop/Changedfile.XXX
- print "writting" + destfile
- # 打開 .../Desktop/Changedfile.XXX
- file = open(destfile, 'w')
- # 寫入資訊到 .../Desktop/Changedfile.XXX
- file.write(merger(Cover,Payload,ExtPay))
- # 關閉 .../Desktop/Changedfile.XXX
- file.close()
- elif args[1] == "get":
- # 設定 filetodec 為要開啟的檔案
- filetodec = args[2]
- # 設定 raw 為要開啟的檔案的 hex
- raw = hexstr(filetodec)
- # 6f766572686572656c6f6c7a 是 overherelolz 的 hex,設定 extract 為「要開啟的檔案」以 overherelolz 分成的前後兩段字串
- extract = raw.split("6f766572686572656c6f6c7a")
- # 6578746166746572 是 extafter 的 hex,設定 Ext 為「上述後半段(同 extract[1])」以 extafter 分成的前後兩段字串
- Ext = extract[1].split("6578746166746572")
- # 設定 destfile(輸出的檔案位置)為桌面的 Embeded.XXX,XXX 為之前隱藏的檔案的副檔名
- destfile = home +"/Desktop/Embeded" + binascii.unhexlify(Ext[0])
- # 設定 Message(隱藏的檔案)為「上述 Ext 的後半段(同 Ext[1])」的原始樣貌(unhexlify)
- Message = binascii.unhexlify(Ext[1])
- file = open(destfile, 'w')
- file.write(Message)
- file.close()
- else:
- # 如果參數少於 3
- if len(args) < 3:
- usage(" Error: not enough arguments.",1)
- else:
- usage(" Error: too many arguments.",1)
Advertisement
Add Comment
Please, Sign In to add comment