rizinorg / rz-pipe Goto Github PK
View Code? Open in Web Editor NEWAccess rizin via pipe from any programming language!
Access rizin via pipe from any programming language!
my setup:
[h4x5p4c3@int3r5t3ll4r ~]$ rizin -v
rizin 0.3.0-git @ linux-x86-64
commit: 899483566d4f25c91178b8ef6ebd72e4872a1222, build: 2021-05-01__01:14:48
[h4x5p4c3@int3r5t3ll4r ~]$ pip install rzpipe
Defaulting to user installation because normal site-packages is not writeable
Collecting rzpipe
Using cached rzpipe-0.1.0-py3-none-any.whl (11 kB)
Installing collected packages: rzpipe
Successfully installed rzpipe-0.1.0
[h4x5p4c3@int3r5t3ll4r ~]$ python
Python 3.9.4 (default, Apr 20 2021, 15:51:38)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import rzpipe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/h4x5p4c3/.local/lib/python3.9/site-packages/rzpipe/__init__.py", line 38, in <module>
from .open_sync import open
File "/home/h4x5p4c3/.local/lib/python3.9/site-packages/rzpipe/open_sync.py", line 16, in <module>
from .open_base import OpenBase
File "/home/h4x5p4c3/.local/lib/python3.9/site-packages/rzpipe/open_base.py", line 22, in <module>
from .native import RCore
File "/home/h4x5p4c3/.local/lib/python3.9/site-packages/rzpipe/native.py", line 25, in <module>
lib = CDLL(lib_name)
File "/usr/lib/python3.9/ctypes/__init__.py", line 374, in __init__
self._handle = _dlopen(self._name, mode)
OSError: librz_core.so.0.3.0-git: cannot open shared object file: No such file or directory
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
name: Upload Python Package
on:
release:
types: [created]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload --skip-existing dist/*
keep in mind that the main issue is that we can't just push on release because we might do a release for each lang.
>>> import rzpipe
>>> rzpipe.open('/usr/bin/true', flags=['-2']).cmdj('iVj')
rzpipe.cmdj.Error: Expecting value: line 2 column 1 (char 1)
/usr/bin/true is https://www.virustotal.com/gui/file/409b33a9b8702e77546c44d58362011d0634ef8dd811975e42a5ed01bd748fcb
Hi there,
I am a member of the Quark Engine project. We use rz-pipe as a dependency of our tool. And we are trying to upload our deb package to the Kali Linux distribution. However, we find that rz-pipe for python is not included in the Kali Linux repository. That results in broken dependencies in our tool on Kali Linux.
So we kindly request that you consider adding rz-pipe for python to the Kali Linux repository. This way, open-source tools in the repository can rely on rz-pipe as a dependency. Also, users can have another way to install rz-pipe easily.
The processes of adding tools to the Kali Linux repository are well documented on the official website:
And here are some examples:
Looking forward to your opinion.
Using:
dev
branch on commit 957a2997b3bda24f36187b87cf2be731c227a2fa
When disassembling this particular basic block I found that pdb
returns differently between rzpipe from Python and Rizin.
rzpipe:
In [14]: print(self._pipe.cmd('pdb'))
│ 0x00015525 mov rdi, rbp
│ 0x00015528 ~ mov esi, 0x20 ; "@"
│ ; CODE XREF from fcn.00014ab0 @ 0x14c95
│ ;-- case 48: ; from 0x14c95
│ 0x0001552a add byte [rax], al
│ 0x0001552c add al, ch
│ 0x0001552e hlt
│ 0x00015530 invalid
│ 0x00015531 dec dword [rax - 0x75]
│ 0x00015534 insb byte [rdi], dx
│ 0x00015535 and al, 0x30
│ 0x00015537 mov rcx, qword [var_20h]
Rizin:
[0x00015525]> pdb
│ 0x00015525 mov rdi, rbp
│ ; CODE XREF from fcn.00014ab0 @ 0x14c95
│ ;-- case 48: ; from 0x14c95
│ 0x00015528 ~ mov esi, 0x20 ; "@"
│ 0x0001552d call sym.imp.memset ; sym.imp.memset
│ 0x00015532 mov rbp, qword [var_38h]
│ 0x00015537 mov rcx, qword [var_20h]
I've only tested with one sample and one command (iI
), but I dont seem to get the same details when I use:
$ rz-bin -I 6a09bc6c19c4236c0bd8a01953371a29
Name Value
------------------------------------------------------------------------------
arch x86
baddr 0x400000
binsz 651424
bintype pe
bits 32
retguard false
class PE32
cmp.csum 0x000a52d4
compiled Mon Apr 24 20:38:08 2017
dbg_file C:\Builds\13810\Tools\ProcDump_master\bin\Win32\Release\procdump.pdb
endian LE
hdr.csum 0x000a52d4
guid 35DC14947AF44564BC0C59336A3D8F741
laddr 0x0
lang c
machine i386
maxopsz 16
minopsz 1
os windows
overlay true
cc cdecl
pcalign 0
signed true
subsys Windows CUI
stripped false
crypto false
havecode true
va true
sanitiz false
static false
linenum false
lsyms false
canary false
PIE true
RELROCS false
NX true
As when I do (in ptpython
):
>>> rzpipe.open('6a09bc6c19c4236c0bd8a01953371a29').cmdJ('iIj')
X(arch='x86', baddr=4194304, binsz=651424, bintype='pe', bits=32, retguard=False, _6='PE32', _7='0x000a52d4', compiled='Mon Apr 24 20:38:08 2017', dbg_file='C:\\Builds\\13810\\Tools\\ProcDump_master\\bin\\Win32\\Release\\procdump.pdb', endian='LE', _11='0x000a52d4', guid='35DC14947AF44564BC0C59336A3D8F741', intrp='', laddr=0, lang='c', machine='i386', maxopsz=16, minopsz=1, os='windows', overlay=True, cc='cdecl', pcalign=0, rpath='', signed=True, subsys='Windows CUI', stripped=False, crypto=False, havecode=True, va=True, sanitiz=False, static=False, linenum=False, lsyms=False, canary=False, PIE=True, RELROCS=False, NX=True, checksums=X()
As you can see, there are some fields which as represented as _6
,_7
, _11
. So the data is there, just with the wrong name.
@wargio looks like recent rz-pipe changes broke the CI:
[XX] C:\projects\rizin\test\db\cmd\cmd_pipe rzpipe load project
ANSICON=1 RZ_NOPLUGINS=1 C:\projects\rizin\rizin-vs2022_64-v0.6.0\bin\rizin.exe -escr.utf8=0 -escr.color=0 -escr.interactive=0 -eflirt.sigdb.load.system=false -eflirt.sigdb.load.home=false -N -Qc '%q `env~?^ASAN_LD_PRELOAD=`
%+ env LD_PRELOAD=`env ASAN_LD_PRELOAD`
!python3 -c 'import rzpipe;rz=rzpipe.open("--");rz.cmd("Po bins/other/ls.rzdb");print(rz.cmd("%v custom_main"))'
' --
-- stdout
--- expected
+++ actual
@@ -1,2 +1,0 @@
-0x4070
-
-- stderr
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python38-x64\lib\site-packages\rzpipe\open_base.py", line 266, in cmd
with timeout_callback(
File "C:\Python38-x64\lib\contextlib.py", line 113, in __enter__
return next(self.gen)
File "C:\Python38-x64\lib\site-packages\rzpipe\open_base.py", line 86, in timeout_callback
signal.signal(signal.SIGALRM, callback)
AttributeError: module 'signal' has no attribute 'SIGALRM'
[XX] C:\projects\rizin\test\db\cmd\cmd_pipe rzpipe.py - shared memory (shm://)
ANSICON=1 RZ_NOPLUGINS=1 C:\projects\rizin\rizin-vs2022_64-v0.6.0\bin\rizin.exe -escr.utf8=0 -escr.color=0 -escr.interactive=0 -eflirt.sigdb.load.system=false -eflirt.sigdb.load.home=false -N -Qc '%q `env~?^ASAN_LD_PRELOAD=`
%+ env LD_PRELOAD=`env ASAN_LD_PRELOAD`
#!pipe python3 scripts/shared_memory.py
' 'bins/elf/_Exit (42)'
-- stdout
--- expected
+++ actual
@@ -3,83 +3,3 @@
-------------
Shared buffer size 0x360c
-------------
-{'arch': 'x86', 'baddr': 134512640, 'binsz': 13073, 'bintype': 'elf', 'bits': 32, 'class': 'ELF32', 'compiler': 'GCC: (GNU) 9.2.1 20190827 (Red Hat 9.2.1-1)', 'endian': 'LE', 'intrp': '/lib/ld-linux.so.2', 'laddr': 0, 'lang': 'c++', 'machine': 'Intel 80386', 'maxopsz': 16, 'minopsz': 1, 'os': 'linux', 'pcalign': 0, 'relro': 'partial', 'rpath': 'NONE', 'subsys': 'linux', 'stripped': False, 'crypto': False, 'havecode': True, 'va': True, 'sanitiz': False, 'static': False, 'linenum': True, 'lsyms': True, 'canary': False, 'PIE': False, 'RELROCS': True, 'NX': True}
-- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
-0x08049020 5589 e583 ec08 83ec 0c6a 2ae8 e0ff ffff U........j*.....
-
-0x08049020 1 16 entry0
-0x08049010 1 6 sym.imp._Exit
-
- ;-- section..text:
- ;-- .text:
- ;-- _start():
-/ entry0 ();
-| 0x08049020 push ebp ; [09] -r-x section size 16 named .text
-| 0x08049021 mov ebp, esp
-| 0x08049023 sub esp, 8
-| 0x08049026 sub esp, 0xc
-| 0x08049029 push 0x2a ; '*' ; 42 ; int status
-\ 0x0804902b call sym.imp._Exit ; void _Exit(int status)
-
-Copying bins/pe/winver.exe...
-Copied bins/pe/winver.exe succesfully
--------------
-Shared buffer size 0x400
--------------
-{'arch': 'x86', 'baddr': 4194304, 'binsz': 1024, 'bintype': 'pe', 'bits': 32, 'retguard': False, 'class': 'PE32', 'cmp.csum': '0x00005082', 'compiled': 'Thu Jan 1 00:00:00 1970 UTC', 'endian': 'LE', 'hdr.csum': '0x00000000', 'laddr': 0, 'lang': 'c', 'machine': 'i386', 'maxopsz': 16, 'minopsz': 1, 'os': 'windows', 'overlay': False, 'cc': 'cdecl', 'pcalign': 0, 'signed': False, 'subsys': 'Windows CUI', 'stripped': False, 'crypto': False, 'havecode': True, 'va': True, 'sanitiz': False, 'static': False, 'linenum': False, 'lsyms': False, 'canary': False, 'PIE': False, 'RELROCS': False, 'NX': False}
-- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
-0x00401000 6880 1040 00ff 15b4 1140 00ff 3590 1040 h..@[email protected]..@
-
-0x00401000 1 58 entry0
-
- ;-- section.sect_0:
-/ entry0 ();
-| 0x00401000 push 0x401080 ; LPOSVERSIONINFOA lpVersionInformation ; [00] -rwx section size 4096 named sect_0
-| 0x00401005 call dword [sym.imp.kernel32.dll_GetVersionExA] ; 0x4011b4 ; BOOL GetVersionExA(LPOSVERSIONINFOA lpVersionInformation)
-| 0x0040100b push dword [0x401090]
-| 0x00401011 push dword [0x40108c]
-| 0x00401017 push dword [0x401088]
-| 0x0040101d push dword [0x401084]
-| 0x00401023 push str.a_PE_overriding_OS_values:_OS_Ver__i._i._i_PlatformID__i ; 0x40103c ; " * a PE overriding OS values: OS Ver %i.%i.%i PlatformID %i\n\n" ; const char *format
-| 0x00401028 call dword [sym.imp.msvcrt.dll_printf] ; 0x4011bc ; int printf(const char *format)
-| 0x0040102e add esp, 0x10
-| 0x00401031 nop
-| 0x00401032 push 0 ; UINT uExitCode
-\ 0x00401034 call dword [sym.imp.kernel32.dll_ExitProcess] ; 0x4011b0 ; VOID ExitProcess(UINT uExitCode)
-
-Copying bins/mach0/mach0_2-x86_64...
-Copied bins/mach0/mach0_2-x86_64 succesfully
--------------
-Shared buffer size 0x10e8
--------------
-{'arch': 'x86', 'baddr': 4294967296, 'binsz': 4328, 'bintype': 'mach0', 'bits': 64, 'class': 'MACH064', 'endian': 'LE', 'intrp': '/usr/lib/dyld', 'laddr': 0, 'lang': 'c', 'machine': 'x86 64 all', 'maxopsz': 16, 'minopsz': 1, 'os': 'macos', 'pcalign': 0, 'subsys': 'darwin', 'stripped': False, 'crypto': False, 'havecode': True, 'va': True, 'sanitiz': False, 'static': False, 'linenum': False, 'lsyms': False, 'canary': False, 'PIE': True, 'RELROCS': False, 'NX': False}
-- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
-0x100000f70 5548 89e5 4883 ec10 c745 fc00 0000 0089 UH..H....E......
-
-0x100000f70 1 36 entry0
-0x100000f40 1 45 sym._foo
-0x100000ef0 4 65 sym._bar
-0x1000001d5 1 171 fcn.1000001d5
-0x1000002e0 13 3088 -> 3110 fcn.1000002e0
-
- ;-- main:
- ;-- _main:
- ;-- func.100000f70:
-/ entry0 (int64_t arg1, int64_t arg2);
-| ; arg int64_t arg1 @ rdi
-| ; arg int64_t arg2 @ rsi
-| ; var int64_t var_18h @ stack - 0x18
-| ; var int64_t var_10h @ stack - 0x10
-| ; var int64_t var_ch @ stack - 0xc
-| 0x100000f70 push rbp
-| 0x100000f71 mov rbp, rsp
-| 0x100000f74 sub rsp, 0x10
-| 0x100000f78 mov dword [var_ch], 0
-| 0x100000f7f mov dword [var_10h], edi ; arg1
-| 0x100000f82 mov qword [var_18h], rsi ; arg2
-| 0x100000f86 mov edi, dword [var_10h] ; int64_t arg1
-| 0x100000f89 call sym._foo
-| 0x100000f8e add rsp, 0x10
-| 0x100000f92 pop rbp
-\ 0x100000f93 ret
-
-- stderr
Traceback (most recent call last):
File "scripts/shared_memory.py", line 22, in <module>
rzp.cmd("e scr.color=0")
File "C:\Python38-x64\lib\site-packages\rzpipe\open_base.py", line 266, in cmd
with timeout_callback(
File "C:\Python38-x64\lib\contextlib.py", line 113, in __enter__
return next(self.gen)
File "C:\Python38-x64\lib\site-packages\rzpipe\open_base.py", line 86, in timeout_callback
signal.signal(signal.SIGALRM, callback)
AttributeError: module 'signal' has no attribute 'SIGALRM'
[XX] C:\projects\rizin\test\db\cmd\cmd_pipe rzpipe.py
ANSICON=1 RZ_NOPLUGINS=1 C:\projects\rizin\rizin-vs2022_64-v0.6.0\bin\rizin.exe -escr.utf8=0 -escr.color=0 -escr.interactive=0 -eflirt.sigdb.load.system=false -eflirt.sigdb.load.home=false -N -Qc '%q `env~?^ASAN_LD_PRELOAD=`
%+ env LD_PRELOAD=`env ASAN_LD_PRELOAD`
#!pipe python3 scripts/get-funcs.py
' 'bins/elf/_Exit (42)'
-- stdout
--- expected
+++ actual
@@ -1,17 +1,0 @@
-
-Function names:
-entry0
-sym.imp._Exit
-
-Disassembly of entry0:
- ;-- section..text:
- ;-- .text:
- ;-- _start():
-/ entry0 ();
-| 0x08049020 push ebp ; [09] -r-x section size 16 named .text
-| 0x08049021 mov ebp, esp
-| 0x08049023 sub esp, 8
-| 0x08049026 sub esp, 0xc
-| 0x08049029 push 0x2a ; '*' ; 42
-\ 0x0804902b call sym.imp._Exit ; void _Exit(int status)
-
-- stderr
Traceback (most recent call last):
File "scripts/get-funcs.py", line 4, in <module>
rzp.cmd("aa")
File "C:\Python38-x64\lib\site-packages\rzpipe\open_base.py", line 266, in cmd
with timeout_callback(
File "C:\Python38-x64\lib\contextlib.py", line 113, in __enter__
return next(self.gen)
File "C:\Python38-x64\lib\site-packages\rzpipe\open_base.py", line 86, in timeout_callback
signal.signal(signal.SIGALRM, callback)
AttributeError: module 'signal' has no attribute 'SIGALRM'
Originally posted by @XVilka in rizinorg/rizin#3527 (comment)
When open some file with rizin, it might print a huge amount of messages like unimplemented ELF/PPC reloc type 22
, which is very annoying. Can this be disabled?
When using rzpipe to open some file, there should be params to disable some output, so my important debug message won't be messed up with huge amount of rizin messages.
See https://github.com/pypa/gh-action-pypi-publish
This can be run on each tag (or on branches, though I would opt for tags here in rz-pipe).
Create an documentation page for rz-pipe's Rust crate, just like r2pipe's one and host it when rizin.re/docs is up.
Sometimes, rizin commands may take too long. It would be good if we could set a timeout and kill rizin if it expires.
python/native.py
lacks access to the rest of the native API.
Port over the missing functions and structs..
Run go get github.com/rizinorg/rz-pipe/go
go: go.mod file not found in current directory or any parent directory.
'go get' is no longer supported outside a module.
To build and install a command, use 'go install' with a version,
like 'go install example.com/cmd@latest'
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'.
rz-pipe-go
go: downloading github.com/rizinorg/rz-pipe v0.0.0-20220325131231-15136d33df87
go: downloading github.com/rizinorg/rz-pipe/go v0.0.0-20220325131231-15136d33df87
go get: github.com/rizinorg/rz-pipe/[email protected]: parsing go.mod:
module declares its path as: github.com/rizinorg/rz-pipe
but was required as: github.com/rizinorg/rz-pipe/go
https://github.com/rizinorg/rizin/runs/6210865319?check_suite_focus=true#step:7:20
On https://pypi.org/project/rzpipe/#description, pipe.cmdj("ij").core.format
should be pipe.cmdj("ij")['core'].['format']
, as python dictionaries don't generally have their keys as attributes.
This is on macOS M1 for any usage of the Go bindings - seems the dependency used to link (https://github.com/rainycape/dl) doesn't support ARM?
# github.com/rainycape/dl
Undefined symbols for architecture arm64:
"_make_call", referenced from:
_call in _x004.o
ld: symbol(s) not found for architecture arm64
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
The open_async.py
file reads as follows:
# whole file doesn't have any profit of asyncio usage, TODO: refactor
jsdec is using javascript too.
I tested blow code to save and load project with rzpipe, but it Hangs.
import rzpipe
# project file "bin-ls" created in current directory
rz = rzpipe.open("/bin/ls")
rz.cmd('Ps bin-ls')
# Another session
rz = rzpipe.open("--")
rz.cmd('Po bin-ls') # it hangs here
Running arch linux with go version go1.17 linux/amd64.
package main
import (
"github.com/rizinorg/rz-pipe/go"
)
func main() {
r2p, err := rzpipe.NewPipe("/bin/ls")
if err != nil {
panic(err)
}
defer r2p.Close()
}
Output of trying to install
go/src/hello2
▶ go version
go version go1.17 linux/amd64
go/src/hello2
▶ go mod init
go: creating new go.mod: module hello2
go: to add module requirements and sums:
go mod tidy
go/src/hello2
▶ go mod tidy
go: finding module for package github.com/rizinorg/rz-pipe/go
go: found github.com/rizinorg/rz-pipe/go in github.com/rizinorg/rz-pipe/go v0.0.0-20210623092913-2128c46e5221
go: hello2 imports
github.com/rizinorg/rz-pipe/go: github.com/rizinorg/rz-pipe/[email protected]: parsing go.mod:
module declares its path as: github.com/rizinorg/rz-pipe
but was required as: github.com/rizinorg/rz-pipe/go
I've also tried using rz-pm with the same results. I'm not sure if this is an issue with my version of go or with go.mod:
module github.com/rizinorg/rz-pipe
go 1.15
require github.com/rainycape/dl v0.0.0-20151222075243-1b01514224a1
I can clone the repo directly and use replace to get it to work but it would be nice to be able to just go get <blah>
or rz-pm install rz-pipe-go
:
module hello
go 1.17
require github.com/rizinorg/rz-pipe/go v0.0.0-00010101000000-000000000000
require github.com/rainycape/dl v0.0.0-20151222075243-1b01514224a1 // indirect
replace github.com/rizinorg/rz-pipe/go => /home/majesticboar/go/src/github.com/rizinorg/rz-pipe/go
Also a SourceHut probably.
Hello I would like to make a change in rzpipe. Radare2 has been improving r2pipe for some time now. This project is https://github.com/radare/radare2-r2pipe-api. If possible I would like it to be implemented in rzpipe as much as in cutter so that it creates a high level API, abstracting the rizin commands with a human friendly taste.
Currently the python tests (to be implemented) in #8 are missing coverage information.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.