Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CLI component #305

Merged
merged 5 commits into from
Jun 25, 2017
Merged

add CLI component #305

merged 5 commits into from
Jun 25, 2017

Conversation

m4b
Copy link
Collaborator

@m4b m4b commented Jun 19, 2017

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.

@m4b m4b requested a review from flanfly June 19, 2017 04:39
@coveralls
Copy link

Coverage Status

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

…thods

* add display_with methods to Function, BasicBlock, and Mnemonic for pp
* add function filter to command line options
* default disassemble and print every found function
@m4b
Copy link
Collaborator Author

m4b commented Jun 23, 2017

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
Copy link

Coverage Status

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

@flanfly
Copy link
Member

flanfly commented Jun 24, 2017

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).

cli/src/main.rs Outdated
match filter {
Some(filter) => {
for function in pipe.wait() {
info!("derp");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wat?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing if you're awake 🤣

cli/src/main.rs Outdated
None
}
}).collect::<Vec<_>>();
// todo: sort by address
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this?

@m4b
Copy link
Collaborator Author

m4b commented Jun 24, 2017

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
Copy link
Collaborator Author

m4b commented Jun 24, 2017

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
Copy link

Coverage Status

Coverage decreased (-0.7%) to 59.568% when pulling 2380117 on m4b/cli into 19a18e1 on master.

@m4b
Copy link
Collaborator Author

m4b commented Jun 24, 2017

Dunno what's up with that appveyor CI failure ?

@flanfly
Copy link
Member

flanfly commented Jun 25, 2017

Just a hiccup.

@flanfly flanfly merged commit 6153a7f into master Jun 25, 2017
@m4b m4b deleted the m4b/cli branch June 28, 2017 05:16
@m4b m4b mentioned this pull request Jun 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants