Guest User

Untitled

a guest
Dec 30th, 2017
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.24 KB | None | 0 0
  1. # https://github.com/JPaulMora/FileHider/blob/master/FileHidder.py
  2. # Comments For Ptt Old-Games
  3.  
  4. #!/usr/bin/env python
  5.  
  6. import binascii
  7. import sys
  8. #import PyQt4 some time in the future..
  9. from os.path import expanduser, splitext
  10.  
  11. args = sys.argv  
  12. home = expanduser("~")
  13.  
  14. # 設定「以 hex 讀取檔案」的功能,讓 36 行下面的程式碼可以使用
  15. def hexstr(fn):                # This function makes use of binascii to read file in hex mode
  16.     with open(fn, 'rb') as f:
  17.             content = f.read()
  18.     Payload = (binascii.hexlify(content))
  19.     return Payload
  20.    
  21. # 設定「寫入檔案」的功能,讓 36 行下面的程式碼可以使用
  22. def merger(cov,pld,ext):
  23.     Final = binascii.unhexlify(str(cov)) + "overherelolz" + ext + "extafter"+ binascii.unhexlify(str(pld))
  24.     return Final
  25.    
  26. # 設定指令,需要時出現以下文字
  27. # Usage: args[0] < hide|get > /file/to/unhide.png
  28. #
  29. # Example: args[0] hide /path/to/MySecretMessage.txt /some/funny.gif
  30. # 此行顯示指令錯誤原因
  31. def usage(reason, ecode):
  32.     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"
  33.     print reason + "\n"
  34.     sys.exit(ecode)
  35.    
  36.    
  37. # 如果輸入的參數數量正確
  38. if len(args) >= 3 and len(args) <= 4:
  39.    
  40.     if args[1] == "hide":
  41.         # 設定 Cover 為被更改的檔案(以 hex 讀取檔案)
  42.         Cover = hexstr(args[3])
  43.  
  44.         # 設定 ExtCov 為被更改的檔案的副檔名
  45.         ExtCov = splitext(args[3])[1]
  46.  
  47.         # 設定 ExtPay 為加入的檔案的副檔名
  48.         ExtPay = splitext(args[2])[1]
  49.  
  50.         # 設定 Payload 為加入的檔案(以 hex 讀取檔案)
  51.         Payload = hexstr(args[2])
  52.  
  53.         # 設定 destfile(輸出的檔案位置)為桌面的 Changedfile.XXX,XXX 為被更改的檔案的副檔名
  54.         destfile = home +"/Desktop/Changedfile" + ExtCov
  55.  
  56.         # 在視窗中顯示 writting .../Desktop/Changedfile.XXX
  57.         print "writting" + destfile
  58.  
  59.         # 打開 .../Desktop/Changedfile.XXX
  60.         file = open(destfile, 'w')
  61.  
  62.         # 寫入資訊到 .../Desktop/Changedfile.XXX
  63.         file.write(merger(Cover,Payload,ExtPay))
  64.  
  65.         # 關閉 .../Desktop/Changedfile.XXX
  66.         file.close()
  67.  
  68.     elif args[1] == "get":
  69.    
  70.         # 設定 filetodec 為要開啟的檔案
  71.         filetodec = args[2]
  72.  
  73.         # 設定 raw 為要開啟的檔案的 hex
  74.         raw = hexstr(filetodec)
  75.  
  76.         # 6f766572686572656c6f6c7a 是 overherelolz 的 hex,設定 extract 為「要開啟的檔案」以 overherelolz 分成的前後兩段字串
  77.         extract = raw.split("6f766572686572656c6f6c7a")
  78.  
  79.         # 6578746166746572 是 extafter 的 hex,設定 Ext 為「上述後半段(同 extract[1])」以 extafter 分成的前後兩段字串
  80.         Ext = extract[1].split("6578746166746572")
  81.  
  82.         # 設定 destfile(輸出的檔案位置)為桌面的 Embeded.XXX,XXX 為之前隱藏的檔案的副檔名
  83.         destfile = home +"/Desktop/Embeded" + binascii.unhexlify(Ext[0])
  84.        
  85.         # 設定 Message(隱藏的檔案)為「上述 Ext 的後半段(同 Ext[1])」的原始樣貌(unhexlify)
  86.         Message = binascii.unhexlify(Ext[1])
  87.        
  88.         file = open(destfile, 'w')
  89.         file.write(Message)
  90.         file.close()
  91. else:
  92.     # 如果參數少於 3
  93.     if len(args) < 3:
  94.         usage(" Error: not enough arguments.",1)
  95.     else:
  96. usage(" Error: too many arguments.",1)
Advertisement
Add Comment
Please, Sign In to add comment