rizinorg / rizin

UNIX-like reverse engineering framework and command-line toolset.
https://rizin.re
GNU Lesser General Public License v3.0
2.71k stars 363 forks source link

Find functions that perform temporary seek from the API and refactor to use the offset argument if possible #2906

Open XVilka opened 2 years ago

XVilka commented 2 years ago

Also my opinion that most Rizin functions which force caller to temporary change seek is bad API and indicator that those functions should probably have offset argument.

_Originally posted by @karliss in https://github.com/rizinorg/cutter/pull/3005#discussion_r943141253_

ret2libc commented 2 years ago

Please let's create actionable issues though, otherwise we just leave issues hanging around without anyone ever knowing when something is done or what needs to be done exactly.

imbillow commented 2 years ago

I recommend using an abstraction like memory view , which also includes buffer, buffer size, and offset. Maybe also include the functionality of rz_io_read_at. https://docs.python.org/3/library/stdtypes.html#memoryview

XVilka commented 2 years ago

@imbillow RzBuffer offers such an abstraction - it works with different backends:

typedef enum {
    RZ_BUFFER_FILE,
    RZ_BUFFER_IO_FD,
    RZ_BUFFER_IO,
    RZ_BUFFER_BYTES,
    RZ_BUFFER_MMAP,
    RZ_BUFFER_SPARSE,
    RZ_BUFFER_REF,
} RzBufferType;

https://github.com/rizinorg/rizin/blob/dev/librz/util/buf.c#L9

It also tracks the state of seek and has a notion of start and end.