Skip to content

Commit

Permalink
Merge pull request #5 from daniel752/daniel752-patch-2
Browse files Browse the repository at this point in the history
Took off debugging prints
  • Loading branch information
daniel752 authored Jun 7, 2023
2 parents 49493e6 + 7f88acd commit 49a07fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
19 changes: 7 additions & 12 deletions bbis_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,10 @@ def extract_binary_data(buffer,offsets):
# Current offset
offset = offsets[i]
opcode = f"{buffer[offset]} {buffer[offset+1]}"
print(f"Offset:{offset}; opcode:{opcode}")
# print(f"Offset:{offset}; opcode:{opcode}")
if opcode in extraction_opcode_map:
# # If opcode in map
# if len(start) < 16:
# # If start isn't 16 bits yet append bit to start
# start += get_byte_conversion(opcode)
# If start is 16 bits already then append bit to end
end += get_byte_conversion(opcode)
used_offsets.append(offset)
# used_offsets.append(offset)
# Increase 'i' to next offset in 'offsets'
i += 1

Expand All @@ -51,17 +46,17 @@ def extract_binary_data(buffer,offsets):
offset = offsets[i]
while offset <= end:
opcode = f"{buffer[offset]} {buffer[offset+1]}"
print(f"Offset:{offset}; opcode:{opcode}")
# print(f"Offset:{offset}; opcode:{opcode}")
if opcode in extraction_opcode_map:
binary_data += get_byte_conversion(opcode)
used_offsets.append(offset)
# used_offsets.append(offset)

i += 1
offset = offsets[i]

with open("extraction-offsets.txt","w") as file:
for offset in offsets:
file.write(f"{offset}\n")
# with open("extraction-offsets.txt","w") as file:
# for offset in offsets:
# file.write(f"{offset}\n")

return binary_data

Expand Down
12 changes: 6 additions & 6 deletions bbis_hide.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def calculate_offsets(target_list, virtual_offset, code_offset):
offsets = [(int(x[0][:-1],16) - int(virtual_offset,16) + int(code_offset,16), x[1]) for x in target_list]

# For debugging purposes
with open("offsets-list.txt","w") as file:
for offset in offsets:
file.write(f"{offset}\n")
# with open("offsets-list.txt","w") as file:
# for offset in offsets:
# file.write(f"{offset}\n")

return offsets
# return [(int(hex((int(x[0][:-1], 16) - int(virtual_offset, 16)) + int(code_offset, 16)), 16), x[1]) for x in target_list]
Expand Down Expand Up @@ -115,19 +115,19 @@ def decode_data_within_executable(buffer, binary_data, offsets):
offset = offsets[i]
# Current opcode (all targeted mnemonics are 2 bytes)
opcode = f'{buffer[offset]} {buffer[offset + 1]}'
print(f"Offset:{offset}; opcode:{opcode}; bit:{bit}; index:{i}")
# print(f"Offset:{offset}; opcode:{opcode}; bit:{bit}; index:{i}")
if bit == '1':
# If current bit is 1 check whether current opcode gives value of 0 in map
if opcode in decode_opcode_map_0_to_1:
# Substitute opcode with another one that equals 1 in map
buffer[offset], buffer[offset + 1] = get_opcode_conversion(opcode, 1)
print(f"Converted to: {buffer[offset]} {buffer[offset+1]} => 1")
# print(f"Converted to: {buffer[offset]} {buffer[offset+1]} => 1")
elif bit == '0':
# If current bit is 0 check whether current opcode gives value of 1 in map
if opcode in decode_opcode_map_1_to_0:
# Substitute opcode with another one that equals 0 in map
buffer[offset], buffer[offset + 1] = get_opcode_conversion(opcode, 0)
print(f"Converted to: {buffer[offset]} {buffer[offset + 1]} => 0")
# print(f"Converted to: {buffer[offset]} {buffer[offset + 1]} => 0")
i += 1
except IndexError:
print('The code section in this executable is not enough to hide this message.')
Expand Down

0 comments on commit 49a07fe

Please sign in to comment.