Skip to content

Commit

Permalink
Merge pull request #9 from daniel752/benchmark
Browse files Browse the repository at this point in the history
Added optional chosen output path for hide and extract.
  • Loading branch information
daniel752 authored Jun 11, 2023
2 parents 1e390c3 + 8b81340 commit abae6cd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
14 changes: 8 additions & 6 deletions bbis_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def get_arguments_cli():
"""Gets user input from CLI."""
parser = argparse.ArgumentParser(prog='bbis_extract.py',description='Extract a file hidden with bbis_hide.py within executable.')
parser.add_argument('-e','--executable',type=str,required=True,help='Path to executable for extraction.')
parser.add_argument('-o','--output',type=str,required=False,help='Name of output file after extraction.')
parser.add_argument('-o','--output',type=str,required=False,help='Output path for output file after extraction.')
return parser.parse_args()


Expand Down Expand Up @@ -72,10 +72,12 @@ def get_file_type(file_binary):
return file_type


def write_file(file_binary,file_name,file_type):
def write_file(file_binary,file_path,file_type):
name = f"output-file.{file_type}"
if file_name:
name = f"{file_name}.{file_type}"
if file_path:
if file_path[-1] == '/':
file_path = file_path[0:-1]
name = f"{file_path}/output-file.{file_type}"
with open(name,"wb") as file:
file.write(file_binary)

Expand All @@ -94,6 +96,6 @@ def write_file(file_binary,file_name,file_type):
# print(f"Extracted binary data:{binary_data}")
file_binary = convert_binary_to_file(binary_data)
file_type = get_file_type(file_binary)
file_name = args.output
write_file(file_binary,file_name,file_type)
output_path = args.output
write_file(file_binary,output_path,file_type)
clear_logs(os.path.basename(executable))
47 changes: 25 additions & 22 deletions bbis_hide.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_arguments_cli():
# parser.add_argument('-a', '--action', type=str, required=True, help='-a or --action [=decode,=extract] (choose whether you want to decode or extract data)')
parser.add_argument('-d', '--data', type=str, required=True, help='Path to data (file) to hide in executable')
parser.add_argument('-e', '--executable', type=str, required=True, help='Path to executable to hide file within')
parser.add_argument('-p', '--path', type=str, required=False, help='Path of where to put te modified executable')
parser.add_argument('-o', '--output_path', type=str, required=False, help='Output path for modified executable')
return parser.parse_args()


Expand All @@ -40,21 +40,27 @@ def get_executable_binary(executable):


def get_executable_object_data(executable):
# Get executable name from path
exe_name = os.path.basename(executable).split('.')[0]
# Disassemble .EXE file's code section with intel x8086 mnemonics and save output
os.system(f'objdump -d -M intel {executable} > {exe_name}_dump.txt')
# Get info about object code - code section's offset,size,virtual address
os.system(f'objdump -h {executable} > {exe_name}_code_offset.txt')
# Read object code's disassembly to 'dump'
dump = open(f'{exe_name}_dump.txt', 'r').readlines()[7:]
# Read object code's information to 'info'
info = open(f'{exe_name}_code_offset.txt', 'r').readlines()[5:6]
# Converting 'info' from list to str
info = str(info[0])
virtual_offset = info[28:36]
code_offset = info[48:56]
dump = [x.split('\t') for x in dump]
try:
# Get executable name from path
exe_name = os.path.basename(executable).split('.')[0]
# Disassemble .EXE file's code section with intel x8086 mnemonics and save output
os.system(f'objdump -d -M intel {executable} > {exe_name}_dump.txt')
# Get info about object code - code section's offset,size,virtual address
os.system(f'objdump -h {executable} > {exe_name}_code_offset.txt')
# Read object code's disassembly to 'dump'
dump = open(f'{exe_name}_dump.txt', 'r').readlines()[7:]
# Read object code's information to 'info'
info = open(f'{exe_name}_code_offset.txt', 'r').readlines()[5:6]
# Converting 'info' from list to str
info = str(info[0])
virtual_offset = info[28:36]
code_offset = info[48:56]
dump = [x.split('\t') for x in dump]
except Exception:
print(f"Objdump unable to disassemble {executable}")
print("Program exits")
clear_logs(executable)
exit(1)
return (dump, virtual_offset, code_offset)


Expand Down Expand Up @@ -145,8 +151,7 @@ def write_buffer(buffer, executable, path):
if path:
if path[-1] == '/':
path = path[0:-1]
executable = f"{path}/{executable}"
with open(f"{executable}", "wb") as file:
with open(f"{path}/{executable}", "wb") as file:
file.write(buffer)


Expand Down Expand Up @@ -185,14 +190,12 @@ def clear_logs(exe_name):
if __name__ == '__main__':
# Get arguments from CLI
args = get_arguments_cli()
# # Action to perform (to hide or extract data)
# action = args.action
# Path to file for hiding or extracting
data = args.data
# Path to executable file
executable = args.executable
# Path of modified executable
path = args.path
output_path = args.output_path
# Get targeted mnemonics offsets from executable's object data
offsets_list = get_executable_offsets(executable)
# Get file's binary data
Expand All @@ -204,6 +207,6 @@ def clear_logs(exe_name):
# Modify buffer according to 'binary_data'
buffer = modify_buffer(buffer, binary_data, offsets_list, exe_name)
# Write modified buffer back to hard-disk (looks exactly like original)
write_buffer(buffer, exe_name, path)
write_buffer(buffer, exe_name, output_path)
# Delete executable's object data logs
clear_logs(exe_name)
2 changes: 1 addition & 1 deletion testing/test.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

0 comments on commit abae6cd

Please sign in to comment.