das-labor / panopticon

A libre cross-platform disassembler.
https://panopticon.re
GNU General Public License v3.0
1.43k stars 78 forks source link

add CLI component #305

Closed m4b closed 7 years ago

m4b commented 7 years ago

I made several changes based on your branch:

  1. switched to structopt, which is easier and better to use for adding more command line functionality, and very easy to read imho.
  2. switched to a main/run setup, and exit on error
  3. unfortunately, I don't see any display logic for printing a disassembled function. I hope I just missed it, but I thought the point of adding a middle layer was to reuse assembly printers, etc., otherwise it's very tedious and repetitive.

For assembly printing, I implemented a display_with function on an older branch that took the program as an argument and printed it very nicely, but it needed the display structs and display logic that was originally in the qt/qml portion; I think we should move those display structs into pipeline and have them be reusable, otherwise the cli will fork on important issues, and will make maintenance harder IMHO

@flanfly what do you think?

--- META --- Also, so I made this a branch on panopticon, can remove if you like, but I think we should consider this for development model; if your branch hadn't been from your own repo, I could in principle push commits to it directly (very nice for basic fixes, etc.), or make a PR merging commits into your branch; to do that against your own branch in your own repo is much harder, and not sure what the gain is.

anyway if you don't like having branch on panopticon, I can delete this and push to my master, but again, i strongly urge to consider other development model.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.2%) to 60.084% when pulling 4f916cc6748e3bab8a087b811e3aca77d2a9b342 on m4b/cli into 19a18e1af92ebe0383ce2e5b6d6683701fe91317 on master.

m4b commented 7 years ago

the -f function adds a function filter, and without by default disassembles and prints everything now, e.g.:

m4b@efrit ::  [ ~/git/panopticon/cli ] cargo run -- libfoo.so
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `/home/m4b/git/panopticon/target/debug/panop libfoo.so`
000006b0 <libfoo.so>:
     6b0: lea rdi, 201048
     6b7: lea rax, 20104f
     6be: push rbp
     6bf: sub rax, rdi
     6c2: mov rbp, rsp
     6c5: cmp rax, e
     6c9: jbe 6e0
     6cb: mov rax, qword ptr [0x200fd8]
     6d2: test rax, rax
     6d5: je 6e0
     6d7: pop rbp
     6d8: jmp RAX
     6e0: pop rbp
     6e1: ret 
00000628 <_init>:
     628: sub rsp, 8
     62c: mov rax, qword ptr [0x200fe0]
     633: test rax, rax
     636: je 63a
     638: call RAX
     63a: add rsp, 8
     63e: ret 
000006f0 <register_tm_clones>:
     6f0: lea rdi, 201048
     6f7: lea rsi, 201048
     6fe: push rbp
     6ff: sub rsi, rdi
     702: mov rbp, rsp
     705: sar rsi, 3
     709: mov rax, rsi
     70c: shr rax, 3f
     710: add rsi, rax
     713: sar rsi, 1
     716: je 730
     718: mov rax, qword ptr [0x200ff0]
     71f: test rax, rax
     722: je 730
     724: pop rbp
     725: jmp RAX
     730: pop rbp
     731: ret 
000007bb <internal1>:
     7bb: push rbp
     7bc: mov rbp, rsp
     7bf: mov dword ptr [rbp-0x4], edi
     7c2: mov eax, dword ptr [rbp-0x4]
     7c5: sub eax, beef
     7ca: pop rbp
     7cb: ret 
0000080d <ifoobar>:
     80d: push rbp
     80e: mov rbp, rsp
     811: sub rsp, 10
     815: mov eax, 0
     81a: call 670
     81f: mov dword ptr [rbp-0x4], eax
     822: mov eax, dword ptr [rbp-0x4]
     825: mov esi, eax
     827: lea rdi, 852
     82e: mov eax, 0
     833: call 680
     838: xchg eax, eax
     839: leave 
     83a: ret 
00000740 <__do_global_dtors_aux>:
     740: cmp byte ptr [0x201047], 0
     747: jne 770
     749: cmp qword ptr [0x200ff7], 0
     751: push rbp
     752: mov rbp, rsp
     755: je 763
     757: mov rdi, qword ptr [0x201040]
     75e: call 6a0
     763: call 6b0
     768: pop rbp
     769: mov byte ptr [0x201047], 1
     770: ret 
000006f0 <frame_dummy>:
     6f0: lea rdi, 201048
     6f7: lea rsi, 201048
     6fe: push rbp
     6ff: sub rsi, rdi
     702: mov rbp, rsp
     705: sar rsi, 3
     709: mov rax, rsi
     70c: shr rax, 3f
     710: add rsi, rax
     713: sar rsi, 1
     716: je 730
     718: mov rax, qword ptr [0x200ff0]
     71f: test rax, rax
     722: je 730
     724: pop rbp
     725: jmp RAX
     730: pop rbp
     731: ret 
     780: lea rdi, 200e10
     787: cmp rdi, 0
     78b: jne 798
     78d: jmp 6f0
     798: mov rax, qword ptr [0x200fe8]
     79f: test rax, rax
     7a2: je 78d
     7a4: push rbp
     7a5: mov rbp, rsp
     7a8: call RAX
     7aa: pop rbp
     7ab: jmp 6f0
000007cc <bar>:
     7cc: push rbp
     7cd: mov rbp, rsp
     7d0: sub rsp, 8
     7d4: mov dword ptr [rbp-0x4], edi
     7d7: mov eax, dword ptr [rbp-0x4]
     7da: mov edi, eax
     7dc: call 7bb
     7e1: leave 
     7e2: ret 
000007fa <ifoo>:
     7fa: push rbp
     7fb: mov rbp, rsp
     7fe: lea rdi, 845
     805: call 650
     80a: xchg eax, eax
     80b: pop rbp
     80c: ret 
000007e3 <foobar>:
     7e3: push rbp
     7e4: mov rbp, rsp
     7e7: mov eax, 0
     7ec: call 690
     7f1: mov edi, eax
     7f3: call 660
     7f8: pop rbp
     7f9: ret 
000007b0 <foo>:
     7b0: push rbp
     7b1: mov rbp, rsp
     7b4: mov eax, deadbeef
     7b9: pop rbp
     7ba: ret 
0000083c <_fini>:
     83c: sub rsp, 8
     840: add rsp, 8
     844: ret 
00000670 <func_0x670>:
     670: jmp QWORD PTR [0x201028]
00000660 <func_0x660>:
     660: jmp QWORD PTR [0x201020]
00000680 <func_0x680>:
     680: jmp QWORD PTR [0x201030]
000006a0 <func_0x6a0>:
     6a0: jmp QWORD PTR [0x200ff8]
00000690 <func_0x690>:
     690: jmp QWORD PTR [0x201038]
00000650 <func_0x650>:
     650: jmp QWORD PTR [0x201018]
m4b@efrit ::  [ ~/git/panopticon/cli ] cargo run -- libfoo.so -f foo
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `/home/m4b/git/panopticon/target/debug/panop libfoo.so -f foo`
000007b0 <foo>:
     7b0: push rbp
     7b1: mov rbp, rsp
     7b4: mov eax, deadbeef
     7b9: pop rbp
     7ba: ret 
coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.4%) to 59.826% when pulling 037aea2b02f3bf321bf1d30c5801ae2188e05757 on m4b/cli into 19a18e1af92ebe0383ce2e5b6d6683701fe91317 on master.

flanfly commented 7 years ago

Pretty cool. The display_with thing isn't the most elegant way to do it, but for a first iteration I'm Ok with it.

I (now) agree that using a branch on the main repo is easier when working on something collaboratively. I forgot that you can't force push into somebody else branch (after rebase for example).

m4b commented 7 years ago

So, sorting the functions has revealed that there still appear to be dup functions:

000007bb <internal1>:
     7bb: push rbp
     7bc: mov rbp, rsp
     7bf: mov dword ptr [rbp-0x4], edi
     7c2: mov eax, dword ptr [rbp-0x4]
     7c5: sub eax, beef
     7ca: pop rbp
     7cb: ret 
000007bb <func_0x7bb>:
     7bb: push rbp
     7bc: mov rbp, rsp
     7bf: mov dword ptr [rbp-0x4], edi
     7c2: mov eax, dword ptr [rbp-0x4]
     7c5: sub eax, beef
     7ca: pop rbp
     7cb: ret 
m4b commented 7 years ago

RE: ya, display with is a hack; I also wish I didn't have to pass in the whole Program reference either, but not sure of any way to get the callq, etc. resolutions done

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.7%) to 59.568% when pulling 2380117024711a3e182792bbd0cf66a8049dcdba on m4b/cli into 19a18e1af92ebe0383ce2e5b6d6683701fe91317 on master.

m4b commented 7 years ago

Dunno what's up with that appveyor CI failure ?

flanfly commented 7 years ago

Just a hiccup.