Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import binascii
- import time
- def change(s, i): #Fucntion for changing 0s to 1s, and 1s to 0s.
- if s == "1":
- a[i] = "0"
- return
- if s == "0":
- a[i] = "1"
- return
- b = open("C:/Users/pol/Desktop/test.exe", "rb") #Open up file.
- a = b.read(-1) #Read its data, which is given to us in hex.
- b.close()
- b = open("C:/Users/pol/Desktop/testCloneReversed.exe", "wb") #Open up another file where we'll be writing
- a = bin(int(binascii.hexlify(a), 16))[2:]#From hex to a raw binary string.
- a = list(a)
- print(a[:8]) #['1', '0', '0', '1', '1', '0', '1', '0']
- print("Len of a before reverse: " + str(len(a)))
- i = 0
- for s in a: #Change all 0s to 1s, and all 1s to 0s.
- change(s, i)
- i = i + 1
- print(a[:8]) #['0', '1', '1', '0', '0', '1', '0', '1']This works nicely.
- print("Len of a after reverse: " + str(len(a)))
- a = ''.join(a) #From list to str.
- a = hex(int(a, 2))[2:] #From raw binary to hex.
- print("Number or bytes * 4 = " + str(len(a) * 4)) #We gain a bit.
- print(a[:3]) #0x32, which is 00110010, as you can see it's wrong.
- a = binascii.unhexlify(a) #From hexlified to unhexlfied.
- b.write(a)
- type(a) #Bytes
- print(a[:2]) #b'2\xa5'
- #2a = 00101010
- #2a5 = 001010100101
- #a5 = 10100101
- print(a[:4]) #b'2\xa5o\xff' Not sure how to read this.
- b.close()
- ####TEST
- print("TEST")
- a = bin(128) #0x80 in hex.
- print(a) #0b10000000, or 0x80 in hex or 128 in decimal.
- a = hex(int(a, 2))[2:]
- print(a) #Prints 0x80, which is 10000000 in binary and is right.
- ######################## OUTPUT
- ['1', '0', '0', '1', '1', '0', '1', '0']
- Len of a before reverse: 428767
- ['0', '1', '1', '0', '0', '1', '0', '1']
- Len of a after reverse: 428767
- Number or bytes * 4 = 428768
- 32a
- b'2\xa5'
- b'2\xa5o\xff'
- TEST
- 0b10000000
- 80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement