mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-13 16:18:33 +00:00
Add client and server rap examples in python
This commit is contained in:
parent
9e0ebe9def
commit
c402674b5d
10
r2-bindings/python/test-rap-client.py
Normal file
10
r2-bindings/python/test-rap-client.py
Normal file
@ -0,0 +1,10 @@
|
||||
from remote import RapClient
|
||||
|
||||
rs = RapClient("localhost", 9999)
|
||||
rs.open ("/bin/ls", 0)
|
||||
print (rs.read (10))
|
||||
print (rs.read (10))
|
||||
print (rs.read (10))
|
||||
print (rs.cmd ("x"))
|
||||
print (rs.cmd ("x"))
|
||||
print (rs.cmd ("pd 3"))
|
43
r2-bindings/python/test-rap-server.py
Normal file
43
r2-bindings/python/test-rap-server.py
Normal file
@ -0,0 +1,43 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# python example using the radapy (remote radare API for python)
|
||||
#
|
||||
# -- pancake // nopcode .org
|
||||
#
|
||||
|
||||
from remote import RapServer
|
||||
from string import *
|
||||
|
||||
PORT = 9999
|
||||
|
||||
def fun_system(str):
|
||||
print "CURRENT SEEK IS %d"%radapy.offset
|
||||
return str
|
||||
|
||||
def fun_open(file,flags):
|
||||
return str
|
||||
|
||||
def fun_seek(off,type):
|
||||
return str
|
||||
|
||||
def fun_write(buf):
|
||||
print "WRITING %d bytes (%s)"%(len(buf),buf)
|
||||
return 6
|
||||
|
||||
def fun_read(len):
|
||||
global rs
|
||||
print "READ %d bytes from %d\n"% (len, rs.offset)
|
||||
str = "patata"
|
||||
str = str[rs.offset:]
|
||||
return str
|
||||
|
||||
# main
|
||||
|
||||
#radapy.handle_cmd_open = fun_open
|
||||
#radapy.handle_cmd_close = fun_close
|
||||
rs = RapServer()
|
||||
rs.handle_cmd_system = fun_system
|
||||
rs.handle_cmd_read = fun_read
|
||||
rs.handle_cmd_write = fun_write
|
||||
rs.size = 10
|
||||
rs.listen_tcp (PORT)
|
Loading…
Reference in New Issue
Block a user