Skip to content

Instantly share code, notes, and snippets.

@suidroot
Created May 16, 2020 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suidroot/094698089abf8750fcae19a99d3f73d9 to your computer and use it in GitHub Desktop.
Save suidroot/094698089abf8750fcae19a99d3f73d9 to your computer and use it in GitHub Desktop.
Bank Statement Decoder
import png
import struct
def print_list(thelist, quantity):
if (quantity == 0):
quantity = len(thelist)
#print ("Decimal: ", end="")
#for i in range(0, quantity):
# print (thelist[i], ", ", end="")
#print ("")
print ("Hex: ", end="")
for i in range(0, quantity):
print (hex(thelist[i]), ", ", end="")
print ("")
print ("ASCII: ", end="")
for i in range(0, quantity):
print (chr(thelist[i]), ", ", end="")
print ("")
############
filename = "79fb5.bmp"
# 0x0 , 0x58 , 0x0 , 0x41 , 0x0 , 0x64 , 0x0 , 0x67 , 0x0 , 0x57 , 0x0 , 0x6b , 0x0 , 0x4b
plain_key = "XAdgWkK"
key = bytearray(plain_key.encode("utf-16be"))
print_len = 50
print ("Key: ")
print_list(key, 0)
print ("Key len: ", len(key))
##
#### Load PNG
bmp_full_data = png.Reader(filename=filename).read()
bmp_img_data = list(bmp_full_data[2])
##
#### Reverse Start
data_array = []
output_array = []
print ("")
print ("Loading Image data")
print ("IMG height: ", len(bmp_img_data))
row_count = 0
#print ("Row: ", i, len(bmp_img_data[i]), end='')
while (row_count < len(bmp_img_data[0])-4):
#print (row_count, " ", end="")
for i in range(0,len(bmp_img_data)):
# AARRGGBB
R = bmp_img_data[i][row_count] # 05
G = bmp_img_data[i][row_count+1] # 16
B = bmp_img_data[i][row_count+2] # 01
A = bmp_img_data[i][row_count+3] # 00
data_array.append(B)
data_array.append(G)
data_array.append(R)
data_array.append(A)
row_count += 4
#print (".. row loaded")
print ("1st bytes")
print_list(data_array[:4], 4)
first_bytes_value = struct.unpack("<I", bytearray(data_array[0:4]))[0]
decode_data = data_array[4:]
##
#### XOR_DEC Start
key_counter = 0
print ("Data Length: ", len(data_array))
print ("")
print ("Pre XORed data")
print_list(decode_data, 50)
outfile = open ("test-prexor.bin", 'wb')
outfile.write(bytearray(decode_data))
outfile.close()
print ("")
print ("XORing Image data")
# below is either B5 or 00 ^ 112
key_modifier = 0xb5 ^ 112 # 0xc5
#key_modifier = decode_data[len(decode_data)-1] ^ 112
#key_modifier = 0
print(len(decode_data)-1, hex(decode_data[len(decode_data)-1]), key_modifier)
key_counter = 0
for xor_i in range(0,len(decode_data)):
key_value = key[key_counter]
output_array.append(decode_data[xor_i] ^ key_modifier ^ key_value)
if (key_counter < len(plain_key)-1):
key_counter += 1
else:
key_counter = 0
print ("Final Output")
print_list(output_array, print_len)
outfile = open ("test-postxor.bin", 'wb')
outfile.write(bytearray(output_array))
outfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment