/gen_whitelist.py

https://github.com/halfhalo/LunaSysMgr · Python · 111 lines · 82 code · 16 blank · 13 comment · 4 complexity · 40ab93e52ccb1eb8decc75089bb21b2e MD5 · raw file

  1. #!/usr/bin/python
  2. # sudo apt-get install python-crypto
  3. import os, sys
  4. from random import randrange
  5. from Crypto.Cipher import Blowfish
  6. # This script reads in the apps-whitelist.txt file and generates
  7. # a data structure that can be pased into ApplicationManager.cpp.
  8. kApps = "\
  9. com.palm.launcher:\
  10. com.palm.systemui:\
  11. \
  12. com.palm.app.amazonstore:\
  13. com.palm.app.backup:\
  14. com.palm.app.bluetooth:\
  15. com.palm.app.browser:\
  16. com.palm.app.calculator:\
  17. com.palm.app.calendar:\
  18. com.palm.app.camera:\
  19. com.palm.app.certificate:\
  20. com.palm.app.contacts:\
  21. com.palm.app.dataimport:\
  22. com.palm.app.dateandtime:\
  23. com.palm.app.deviceinfo:\
  24. com.palm.app.devmodeswitcher:\
  25. com.palm.app.docviewer:\
  26. com.palm.app.email:\
  27. com.palm.app.facebook:\
  28. com.palm.app.firstuse:\
  29. com.palm.app.help:\
  30. com.palm.app.languagepicker:\
  31. com.palm.app.location:\
  32. com.palm.app.maps:\
  33. com.palm.app.messaging:\
  34. com.palm.app.musicplayer:\
  35. com.palm.app.notes:\
  36. com.palm.app.pdfviewer:\
  37. com.palm.app.phone:\
  38. com.palm.app.phoneprefs:\
  39. com.palm.app.photos:\
  40. com.palm.app.screenlock:\
  41. com.palm.app.soundsandalerts:\
  42. com.palm.app.sprintportal:\
  43. com.palm.app.streamingmusicplayer:\
  44. com.palm.app.tasks:\
  45. com.palm.app.updates:\
  46. com.palm.app.videoplayer:\
  47. com.palm.app.videoplayer.launcher:\
  48. com.palm.app.wifi:\
  49. com.palm.app.youtube:\
  50. \
  51. com.handson.app.nascar:\
  52. com.telenav.app.sprintnavigation:\
  53. com.mobitv.app.sprinttv:\
  54. \
  55. \x00";
  56. # Blowfish cipher needs 8 byte blocks to work with
  57. def __pad_file( file_buffer):
  58. pad_bytes = 8 - (len(file_buffer) % 8)
  59. for i in range(pad_bytes - 1): file_buffer += chr(randrange(0, 256))
  60. # final padding byte; % by 8 to get the number of padding bytes
  61. bflag = randrange(6, 248); bflag -= bflag % 8 - pad_bytes
  62. file_buffer += chr(bflag)
  63. return file_buffer
  64. def writefile(outfile_name, file_buffer):
  65. outfile = open(outfile_name, 'wb')
  66. outfile.write(file_buffer)
  67. outfile.close()
  68. # Paul says rot13 is enough for our purposes.
  69. def rot13( inStr ):
  70. outStr = ""
  71. for x in range(len(inStr)):
  72. byte = ord(inStr[x])
  73. cap = (byte & 32)
  74. byte = (byte & (~cap))
  75. if (byte >= ord('A')) and (byte <= ord('Z')):
  76. byte = ((byte - ord('A') + 13) % 26 + ord('A'))
  77. byte = (byte | cap)
  78. outStr = str( outStr + (chr(byte)) )
  79. return outStr
  80. def main():
  81. #result = "\n"
  82. #for appid in allowedApps:
  83. # result = str( result+"\""+rot13(appid)+"\", // "+appid+"\n" )
  84. #print result
  85. #Blowflish
  86. key="Copyright 2009 Palm Inc."
  87. filename = "/usr/lib/lib_id.so"
  88. __cipher = Blowfish.new(key,Blowfish.MODE_CBC)
  89. result = __cipher.encrypt(__pad_file(kApps))
  90. writefile( "/tmp/apps", result );
  91. print str( "File written to " + "/tmp/apps" )
  92. print str("Key is \"" + rot13(key)+ "\"")
  93. print str("filename is \"" + rot13(filename)+ "\" ("+filename+")")
  94. #print "// Paste this into ApplicationManager.cpp, \"ApplicationManager::checkAppAgainstWhiteList\""
  95. main()