From c074cca980eb94cc16735f1e568b08bb308001fc Mon Sep 17 00:00:00 2001 From: Jinquan Zhang Date: Tue, 14 Dec 2021 14:26:26 -0500 Subject: [PATCH] version 0.5 --- Docker/README.md | 6 +++--- README.md | 2 +- ...al_results_reported_in_Wang_et_al._2015.md | 2 +- src/cfg.ml | 2 +- src/extern_symbol_process64.py | 4 ++-- src/init.ml | 3 +-- src/pic_process.py | 6 +++--- src/pic_process64.py | 6 +++--- src/post_process.py | 20 +++++++++++++------ src/reassemble_symbol_get.ml | 10 +++++----- src/uroboros.py | 4 ++-- 11 files changed, 36 insertions(+), 29 deletions(-) diff --git a/Docker/README.md b/Docker/README.md index 5d9f2e0..eae7f19 100644 --- a/Docker/README.md +++ b/Docker/README.md @@ -1,4 +1,4 @@ -# Docker for Uroboros version 0.4 +# Docker for Uroboros version 0.5 ## Docker build @@ -6,7 +6,7 @@ Then use `docker build` to build the docker image from Dockerfile. ```shell -docker build -f Dockerfile -t uroboros:0.4 . +docker build -f Dockerfile -t uroboros:0.5 . ``` ## Docker usage @@ -14,5 +14,5 @@ docker build -f Dockerfile -t uroboros:0.4 . run the Docker container with `docker run`. ```shell -docker run -it uroboros:0.4 +docker run -it uroboros:0.5 ``` diff --git a/README.md b/README.md index 9e7ebbd..d69acf2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Uroboros: Infrastructure for Reassembleable Disassembling and Transformation (Version 0.4) +# Uroboros: Infrastructure for Reassembleable Disassembling and Transformation (Version 0.5) # Installation diff --git a/instruction_to_reproduce_experimenttal_results_reported_in_Wang_et_al._2015.md b/instruction_to_reproduce_experimenttal_results_reported_in_Wang_et_al._2015.md index bc1462a..9270580 100644 --- a/instruction_to_reproduce_experimenttal_results_reported_in_Wang_et_al._2015.md +++ b/instruction_to_reproduce_experimenttal_results_reported_in_Wang_et_al._2015.md @@ -1,4 +1,4 @@ -Please use Uroboros (version 0.4) for the tests below. +Please use Uroboros (version 0.5) for the tests below. # Coreutils: diff --git a/src/cfg.ml b/src/cfg.ml index 2f2b45b..a7b4c28 100644 --- a/src/cfg.ml +++ b/src/cfg.ml @@ -114,7 +114,7 @@ class cfg = begin match c with | Jump _ -> true (* jump ops *) - | CALL -> true (* call *) + (*| CALL -> true (* call *)*) | RET -> true | RETN -> true | _ -> false diff --git a/src/extern_symbol_process64.py b/src/extern_symbol_process64.py index c1e9a35..4d1ebd5 100644 --- a/src/extern_symbol_process64.py +++ b/src/extern_symbol_process64.py @@ -41,8 +41,8 @@ def check_32(): for i in range(len(lines)): l = lines[i] - if "#" in l and not "+" in l: - m_s = re.search(pat_s, l) + m_s = re.search(pat_s, l) + if "#" in l and not "+" in l and m_s: m_d = re.search(pat_d, l) try: src = m_s.group(1) # let it crash it not diff --git a/src/init.ml b/src/init.ml index 86749f7..c07b28a 100644 --- a/src/init.ml +++ b/src/init.ml @@ -22,8 +22,7 @@ object (self) print_string "1: linearly disassemble\n"; - ret := Sys.command("objdump -Dr -j \ - .text "^f^" > "^f^".temp"); + ret := Sys.command("objdump -Dr -j .text "^f^" > "^f^".temp"); self#checkret ret (f^".temp"); Sys.command("python pic_process.py "^f^" "^(string_of_bool !is_32)); diff --git a/src/pic_process.py b/src/pic_process.py index ade6033..7d52462 100644 --- a/src/pic_process.py +++ b/src/pic_process.py @@ -67,7 +67,7 @@ def text_process_unstrip(f): info_dump(f) pic_map = info_collect() - for i in xrange(1,len(ls)): + for i in range(1,len(ls)): l = ls[i] if "<__i686.get_pc_thunk.bx>" in l and "call" in l: t = ls[i+1] @@ -96,7 +96,7 @@ def text_process_unstrip(f): def thunk_identify(ls): global step - for i in xrange(step, len(ls)): + for i in range(step, len(ls)): l = ls[i] m = re.search(r'([0-9A-Fa-f]*)(.+)(mov\s+\(%esp\),)(%e\w{2})', l.strip()) if m != None: @@ -157,7 +157,7 @@ def text_process_strip(f): while True: pc_thunk_addr, register = thunk_identify(ls) if pc_thunk_addr == None: break - for i in xrange(1,len(ls)): + for i in range(1,len(ls)): l = ls[i] if re.search(r'call\s+'+pc_thunk_addr, l) != None: t = ls[i+1] diff --git a/src/pic_process64.py b/src/pic_process64.py index cd700c8..8169447 100644 --- a/src/pic_process64.py +++ b/src/pic_process64.py @@ -35,7 +35,7 @@ l = lines[i] if "#" in l: des = l.split('#')[1].split()[0] - #symbols.append(des+"\n") + if des.startswith('0x'): des = des[2:] m = re.search(pat, l) try: sub = m.group(0) # let it crash it not @@ -44,8 +44,8 @@ l = l.replace(sub, sub1) lines[i] = l+"\n" except Exception: - print "exception in pic processing of 64-bit ELF" - print l + print("exception in pic processing of 64-bit ELF") + print(l) with open(fn + '.temp', 'w') as f: f.writelines(lines) diff --git a/src/post_process.py b/src/post_process.py index d299971..2f04bbf 100644 --- a/src/post_process.py +++ b/src/post_process.py @@ -36,6 +36,20 @@ def check_32(): if m and re.search(r'add\s+%r\w{2},'+m.group(1),lines[i-1]): lines[i-1] = "nop\n" +pre_symbol = '' +pre_idx = -1 +for i in range(ll): + l = lines[i] + if l.startswith('BB_'): + if len(lines[i+1].strip()) == 0 or lines[i+1].startswith('S_0x'): + lines[i] = "" + if l.startswith('S_0x'): + if l == pre_symbol: + lines[pre_idx] = '' + pre_symbol = l + pre_idx = i + + for i in range(ll): l = lines[i] if ".text" in l: @@ -129,13 +143,7 @@ def check_exe(): def help(l): if main_symbol1 != "" and main_symbol1 in l and l.startswith(main_symbol1): - #main_s1 = "S"+main_symbol - #if main_s1 in l: - #l = l.replace(main_s1, ".globl main\nmain") l = ".globl main\nmain:\n"+l - #else: - #l = l.replace(main_symbol, ".globl main\nmain") - # l = ".globl main\nmain:\n"+l return l #print lines lines = map(lambda l : help(l), lines) diff --git a/src/reassemble_symbol_get.ml b/src/reassemble_symbol_get.ml index 183afa1..c4851cd 100644 --- a/src/reassemble_symbol_get.ml +++ b/src/reassemble_symbol_get.ml @@ -969,7 +969,7 @@ end let p = object(sp) method process lbs = let dec_hex (s:int) : string = - (Printf.sprintf "S_0x%X : " s) + (Printf.sprintf "S_0x%X:\n" s) in let rec help loc_list = match loc_list with @@ -1195,7 +1195,7 @@ class instrhandler instr_list des' = "S_0x"^(Printf.sprintf "%X" s) in let help l = let d = dec_hex l.loc_addr in - print_string (l.loc_label^" : "^d^"\n") in + print_string (l.loc_label^":\n"^d^"\n") in List.iter help locs method get_instr_list = @@ -1299,7 +1299,7 @@ class instrhandler instr_list des' = if dh = lhd then ( let lhs = dec_hex lh.loc_addr in - let label' = do_update lh.loc_label (lhs^" : ") in + let label' = do_update lh.loc_label (lhs^":\n") in let lh' = {lh with loc_label=label'} in help (lh'::acc) lt dt ) @@ -1328,7 +1328,7 @@ class instrhandler instr_list des' = method update_loc locs d = let dec_hex (s:int) : string = - "S_0x"^(Printf.sprintf "%X : " s) in + "S_0x"^(Printf.sprintf "%X:\n" s) in let identify_des addr1 addr2 = addr1.loc_addr = (int_of_string addr2) and lift_addr addr = @@ -1365,7 +1365,7 @@ class funchandler instr_list u_funcs' = "S_0x"^(Printf.sprintf "%X" s) in let help l = let d = dec_hex l.loc_addr in - print_string (l.loc_label^" : "^d^"\n") in + print_string (l.loc_label^":\n"^d^"\n") in List.iter help locs diff --git a/src/uroboros.py b/src/uroboros.py index 5da6396..cbc27f6 100644 --- a/src/uroboros.py +++ b/src/uroboros.py @@ -121,7 +121,7 @@ def process(f, i): def iterate (f, iterations): print("start to process binary: " + f) - for i in xrange(0, iterations): + for i in range(0, iterations): print ("########## iteration round "+str(i+1) + " begin ! ###########") if process(f, i): pass @@ -220,7 +220,7 @@ def set_assumption (l): (n-byte alignment) are set by default, while assumption two and three need to be configured. For example, setting assumption two and three: -a 2 -a 3''') - p.add_argument('--version', action='version', version='Uroboros v0.4') + p.add_argument('--version', action='version', version='Uroboros 0.5') args = p.parse_args() b = args.binary