Advertisement
Ecoste

Untitled

Nov 26th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. import binascii
  2. import time
  3.  
  4.  
  5. def change(s, i): #Fucntion for changing 0s to 1s, and 1s to 0s.
  6. if s == "1":
  7. a[i] = "0"
  8. return
  9.  
  10. if s == "0":
  11. a[i] = "1"
  12. return
  13.  
  14.  
  15. b = open("C:/Users/pol/Desktop/test.exe", "rb") #Open up file.
  16. a = b.read(-1) #Read its data, which is given to us in hex.
  17. b.close()
  18. b = open("C:/Users/pol/Desktop/testCloneReversed.exe", "wb") #Open up another file where we'll be writing
  19.  
  20. a = bin(int(binascii.hexlify(a), 16))[2:]#From hex to a raw binary string.
  21. a = list(a)
  22.  
  23. print(a[:8]) #['1', '0', '0', '1', '1', '0', '1', '0']
  24. print("Len of a before reverse: " + str(len(a)))
  25.  
  26. i = 0
  27. for s in a: #Change all 0s to 1s, and all 1s to 0s.
  28. change(s, i)
  29. i = i + 1
  30.  
  31. print(a[:8]) #['0', '1', '1', '0', '0', '1', '0', '1']This works nicely.
  32. print("Len of a after reverse: " + str(len(a)))
  33.  
  34. a = ''.join(a) #From list to str.
  35.  
  36. a = hex(int(a, 2))[2:] #From raw binary to hex.
  37. print("Number or bytes * 4 = " + str(len(a) * 4)) #We gain a bit.
  38.  
  39.  
  40. print(a[:3]) #0x32, which is 00110010, as you can see it's wrong.
  41. a = binascii.unhexlify(a) #From hexlified to unhexlfied.
  42. b.write(a)
  43.  
  44. type(a) #Bytes
  45. print(a[:2]) #b'2\xa5'
  46. #2a = 00101010
  47. #2a5 = 001010100101
  48. #a5 = 10100101
  49. print(a[:4]) #b'2\xa5o\xff' Not sure how to read this.
  50.  
  51. b.close()
  52.  
  53. ####TEST
  54. print("TEST")
  55. a = bin(128) #0x80 in hex.
  56. print(a) #0b10000000, or 0x80 in hex or 128 in decimal.
  57. a = hex(int(a, 2))[2:]
  58. print(a) #Prints 0x80, which is 10000000 in binary and is right.
  59.  
  60.  
  61. ######################## OUTPUT
  62.  
  63. ['1', '0', '0', '1', '1', '0', '1', '0']
  64. Len of a before reverse: 428767
  65. ['0', '1', '1', '0', '0', '1', '0', '1']
  66. Len of a after reverse: 428767
  67. Number or bytes * 4 = 428768
  68. 32a
  69. b'2\xa5'
  70. b'2\xa5o\xff'
  71. TEST
  72. 0b10000000
  73. 80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement