27 #define StructStat struct _stat64
29 #define StructStat struct stat
35 wchar_t *wfile = rz_utf8_to_utf16(
file);
39 int ret = _wstati64(wfile, pStat);
65 int r = _chsize(
fd, newsize);
125 if (ptr == newpath) {
134 if (ptr && ptr == newpath && *ptr ==
'.') {
152 if (!strcmp(
ext,
"cparse") || !strcmp(
ext,
"c") || !strcmp(
ext,
"h")) {
164 return ((S_IFREG &
buf.st_mode) == S_IFREG);
174 if ((S_IFBLK &
buf.st_mode) == S_IFBLK) {
178 return S_IFDIR == (S_IFDIR &
buf.st_mode);
186 vsnprintf(
string,
sizeof(
string), fmt, ap);
202 return S_IFREG == (S_IFREG &
buf.st_mode);
224 if (strstr(
file,
"://")) {
229 if (
cwd && *ret !=
'/') {
240 if (!strncmp(ret,
"\\\\", 2)) {
243 if (!strchr(ret,
':')) {
254 char rp[PATH_MAX] = { 0 };
255 char *abspath = realpath(ret,
rp);
257 abspath =
strdup(abspath);
280 while (*base && *
path) {
288 if (*base != *
path) {
317 size_t suff_len = strlen(
path);
318 char *
r =
malloc(ups * 3 + suff_len + 1);
323 for (
i = 0;
i < ups;
i++) {
359 const char *extension =
"";
360 if (!strncmp(
bin,
"./", 2)) {
404 bin_sh =
strdup(
"/bin/sh");
409 #if __UNIX__ || __WINDOWS__
411 if ((newfd =
dup(0)) < 0) {
419 for (
i = 0;
i >= 0;
i += ret) {
449 #warning TODO rz_stdin_slurp
511 char *ret = (
char *)
malloc(sz + 1);
516 size_t rsz = fread(ret, 1, sz,
fd);
518 eprintf(
"Warning: rz_file_slurp: fread: truncated read\n");
540 if (!
out && origonfail) {
573 if (fscanf(
fd,
" #%*[^\n]") == 1) {
576 if (fscanf(
fd,
"%02x", &
c) == 1) {
607 ret = (
char *)
malloc(sz + 1);
610 *osz = (
int)(
size_t)fread(ret, 1, sz,
fd);
612 read_items = fread(ret, 1, sz,
fd);
634 size_t i,
lines, selection = -1;
638 for (
i = 0;
str[
i];
i++) {
639 if (
str[
i] ==
'\n') {
643 selection = (*
line - 1);
647 if ((selection <
start) || (selection == -1)) {
655 if (
str[
i] ==
'\n') {
660 for (
i = 0; ptr[
i];
i++) {
661 if (ptr[
i] ==
'\n') {
680 for (
i = 0;
str[
i];
i++) {
681 if (
str[
i] ==
'\n') {
691 if (
str[
i] ==
'\n') {
696 for (
i = 0; ptr[
i];
i++) {
697 if (ptr[
i] ==
'\n') {
715 for (
i = 0;
str[
i];
i++) {
716 if (
str[
i] ==
'\n') {
725 if (
str[
i] ==
'\n') {
743 for (
i = 0;
str[
i];
i++) {
744 if (
str[
i] ==
'\n') {
754 if (
str[
i] ==
'\n') {
759 for (
i = 0; ptr[
i];
i++) {
760 if (ptr[
i] ==
'\n') {
779 while (strstr(
s,
"..")) {
782 while (strstr(
s,
"./")) {
785 while (strstr(
s,
"//")) {
811 for (
i = 0;
i <
len;
i += 16) {
814 for (j = 0; j + 2 <= l; j += 2) {
815 fprintf(
fd,
"%02x%02x ",
buf[
i + j],
buf[
i + j + 1]);
818 fprintf(
fd,
"%02x ",
buf[
i + j]);
822 fprintf(
fd,
"%*s ", (16 - j) / 2 * 5,
"");
824 for (j = 0; j < 16; j++) {
853 len = strlen((
const char *)
buf);
872 bool ret = RemoveDirectoryW(wfile);
882 bool ret = DeleteFileW(wfile);
896 char pathbuf[4096] = { 0 };
897 strncpy(pathbuf,
path,
sizeof(pathbuf) - 1);
914 m->len = (
DWORD)GetFileSize(
fh, (LPDWORD)((
char *)&
m->len +
sizeof(
DWORD)));
915 if (
m->len == INVALID_FILE_SIZE) {
920 m->fm = CreateFileMappingW(
fh,
922 is_write ? PAGE_READWRITE : PAGE_READONLY,
928 m->buf = MapViewOfFileEx(
m->fm,
929 is_write ? (FILE_MAP_READ | FILE_MAP_WRITE) : FILE_MAP_READ,
930 0, 0, 0, (
void *)
m->base);
946 m->buf =
mmap((
void *)(
size_t)
m->base,
950 if (
m->buf == MAP_FAILED) {
1001 UnmapViewOfFile(
m->buf);
1020 UnmapViewOfFile(
m->buf);
1029 if (
m->buf &&
munmap(
m->buf,
m->len) != 0) {
1069 if (!(wname && wpath && wprefix)) {
1070 goto err_r_file_mkstemp;
1073 if (GetTempFileNameW(wpath, wprefix, 0, wname)) {
1074 char *
name = rz_utf16_to_utf8(wname);
1106 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__) && 2 <= __GLIBC__ && 19 <= __GLIBC__MINOR__
1109 char *
const xpos = strrchr(
name,
'X');
1110 const char c = (char)(
NULL != xpos ? *(xpos + 1) : 0);
1137 LPWSTR tmpdir =
calloc(1,
sizeof(WCHAR) * (MAX_PATH + 1));
1141 if ((
len = GetTempPathW(MAX_PATH + 1, tmpdir)) == 0) {
1149 GetLongPathNameW(tmpdir, tmpdir, MAX_PATH + 1);
1150 path = rz_utf16_to_utf8(tmpdir);
1155 size_t path_len = strlen(
path);
1156 if (path_len > 0 &&
path[path_len - 1] ==
'\\') {
1157 path[path_len - 1] =
'\0';
1167 path =
strdup(
"/data/data/org.rizin.rizininstaller/rizin/tmp");
1174 eprintf(
"Cannot find temporary directory '%s'\n",
path);
1183 return copyfile(
src,
dst, 0, COPYFILE_DATA | COPYFILE_XATTR) != -1;
1184 #elif HAVE_COPY_FILE_RANGE
1190 int mask = (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
1207 PWCHAR
s = rz_utf8_to_utf16(
src);
1208 PWCHAR
d = rz_utf8_to_utf16(
dst);
1210 RZ_LOG_ERROR(
"rz_file_copy: Failed to allocate memory\n");
1215 bool ret = CopyFileW(
s,
d, 0);
1225 int rc =
rz_sys_cmdf(
"cp -f '%s' '%s'", src2, dst2);
1239 rz_list_foreach (dir,
iter,
file) {
1240 if (!strcmp(
file,
".") || !strcmp(
file,
"..")) {
1264 char *globbed_path =
strdup(_globbed_path);
1266 char *glob = strchr(globbed_path,
'*');
1273 char *
path, *glob_ptr;
1275 glob_ptr = last_slash + 1;
1276 if (globbed_path[0] ==
'~') {
1277 char *rpath =
rz_str_newlen(globbed_path + 2, last_slash - globbed_path - 1);
1284 glob_ptr = globbed_path;
1294 if (*(glob + 1) ==
'*') {
1319 const char *sep = ends_with_dir ?
"" :
RZ_SYS_DIR;
1337 if (!(src_buf && dst_buf)) {
1341 ut64 block_size = 1 << 18;
1369 if (!(src_buf && dst_buf)) {
1373 ut64 block_size = 1 << 13;
static RzBinSourceLineInfo * lines(RzBinFile *bf)
const lzma_allocator const uint8_t * in
const lzma_allocator const uint8_t size_t uint8_t * out
static static fork const void static count static fd const char const char static newpath const char static path const char path
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence ftruncate
static static fork const void static count close
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen rmdir
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
static static sync static getppid static getegid const char static filename char static len readlink
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz umask
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep lseek
RZ_API const char * rz_file_basename(const char *path)
RZ_API char * rz_file_tmpdir(void)
RZ_API const char * rz_file_dos_basename(RZ_BORROW RZ_NONNULL const char *path)
RZ_API char * rz_file_temp(const char *prefix)
RZ_API ut8 * rz_file_slurp_hexpairs(const char *str, int *usz)
RZ_API char * rz_file_binsh(void)
RZ_API bool rz_file_is_c(const char *file)
RZ_API bool rz_file_is_directory(const char *str)
RZ_API char * rz_file_readlink(const char *path)
RZ_API bool rz_file_exists(const char *str)
RZ_API RZ_OWN char * rz_file_slurp_lines_from_bottom(const char *file, int line)
RZ_API char * rz_file_relpath(const char *base, const char *path)
RZ_API RzMmap * rz_file_mmap(const char *file, int perm, int mode, ut64 base)
RZ_API bool rz_file_touch(const char *file)
RZ_API bool rz_file_is_deflated(RZ_NONNULL const char *src)
check whether a file is a deflated (gzip) file
RZ_API bool rz_file_is_abspath(const char *file)
RZ_API bool rz_file_fexists(const char *fmt,...)
RZ_API bool rz_file_inflate(RZ_NONNULL const char *src, RZ_NONNULL const char *dst)
unzip the contents of src and store in dst
static RzMmap * file_mmap(RzMmap *m)
RZ_API bool rz_file_is_regular(const char *str)
RZ_API char * rz_file_path_local_to_unix(const char *path)
RZ_API char * rz_stdin_slurp(int *sz)
RZ_API ut8 * rz_file_gzslurp(const char *str, int *outlen, int origonfail)
RZ_API bool rz_file_deflate(RZ_NONNULL const char *src, RZ_NONNULL const char *dst)
zip the contents of src and store in dst
RZ_API char * rz_file_abspath(const char *file)
RZ_API bool rz_file_copy(const char *src, const char *dst)
RZ_API int rz_file_mkstemp(RZ_NULLABLE const char *prefix, char **oname)
RZ_API char * rz_file_dirname(const char *path)
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
RZ_API char * rz_file_slurp_random_line_count(const char *file, int *line)
RZ_API char * rz_file_root(const char *root, const char *path)
RZ_API bool rz_file_dump(const char *file, const ut8 *buf, int len, bool append)
RZ_API bool rz_file_rm(const char *file)
RZ_API char * rz_file_path(const char *bin)
RZ_API RZ_OWN char * rz_file_path_join(RZ_NONNULL const char *s1, RZ_NULLABLE const char *s2)
Concatenate two paths to create a new one with s1+s2 with the correct path separator.
RZ_API ut64 rz_file_size(const char *str)
RZ_API char * rz_file_slurp_range(const char *str, ut64 off, int sz, int *osz)
RZ_API char * rz_file_slurp_line(const char *file, int line, int context)
RZ_API bool rz_file_hexdump(const char *file, const ut8 *buf, int len, int append)
RZ_API char * rz_file_abspath_rel(const char *cwd, const char *file)
RZ_API RzList * rz_file_globsearch(const char *_globbed_path, int maxdepth)
RZ_API char * rz_file_path_unix_to_local(const char *path)
RZ_API void * rz_file_mmap_resize(RzMmap *m, ut64 newsize)
RZ_API char * rz_file_slurp_random_line(const char *file)
RZ_API void rz_file_mmap_free(RzMmap *m)
static void recursive_search_glob(const char *path, const char *glob, RzList *list, int depth)
static int file_stat(const char *file, StructStat *pStat)
RZ_API bool rz_file_truncate(const char *filename, ut64 newsize)
RZ_API char * rz_file_slurp_lines(const char *file, int line, int count)
checking print the parsed form of the magic use in n conjunction with m to debug a new magic file n before installing it n output MIME type special files
unsigned char suffix[65536]
unsigned short prefix[65536]
RZ_API void Ht_() free(HtName_(Ht) *ht)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static void list(RzEgg *egg)
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
void * realloc(void *ptr, size_t size)
void * malloc(size_t size)
void * calloc(size_t number, size_t size)
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode dup
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags mmap
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path dup2
static static fork const void static count static fd const char static mode unlink
static const void static count static fd struct stat static buf struct pollfd unsigned static timeout void static offset munmap
#define header(is_bt, len_min, ret_op)
static void repeat(struct parse *, sopno, int, int)
#define rz_return_val_if_fail(expr, val)
RZ_API bool rz_inflate_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed)
inflate compressed data in RzBbuffer, use MAX_WBITS as the window size logarithm.
RZ_API bool rz_deflate_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed)
deflate uncompressed data in RzBbuffer to zlib or gzipped, use MAX_WBITS as the window size logarithm...
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
RZ_API RZ_OWN RzBuffer * rz_buf_new_file(const char *file, int perm, int mode)
Creates a new buffer from a file.
RZ_API ut8 * rz_inflate(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen)
inflate zlib compressed or gzipped, automatically accepts either the zlib or gzip format,...
#define RZ_LOG_ERROR(fmtstr,...)
RZ_API int rz_num_rand(int max)
RZ_API void rz_num_irand(void)
RZ_API RZ_OWN char * rz_path_home_expand(RZ_NULLABLE const char *path)
Return a new path with the ~ char expanded to the home directory.
#define RZ_STR_ISNOTEMPTY(x)
RZ_API const char * rz_str_lchr(const char *str, char chr)
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_append(char *ptr, const char *string)
RZ_API char RZ_API char * rz_str_newlen(const char *str, int len)
RZ_API const char * rz_str_rchr(const char *base, const char *p, int ch)
RZ_API size_t rz_str_ncpy(char *dst, const char *src, size_t n)
Secure string copy with null terminator.
RZ_API char * rz_str_home(const char *str)
RZ_API bool rz_str_glob(const char *str, const char *glob)
RZ_API const char * rz_str_last(const char *in, const char *ch)
#define RZ_STR_ISEMPTY(x)
RZ_API size_t rz_str_nlen(const char *s, size_t n)
RZ_API char * rz_str_replace(char *str, const char *key, const char *val, int g)
RZ_API bool rz_str_endswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string ends with a specifc sequence of characters (case sensitive)
RZ_API int rz_sys_cmdf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_sys_getenv(const char *key)
Get the value of an environment variable named key or NULL if none exists.
RZ_API int rz_sys_open(const char *path, int perm, int mode)
RZ_API RzList * rz_sys_dir(const char *path)
RZ_API int rz_sys_truncate(const char *file, int sz)
RZ_API FILE * rz_sys_fopen(const char *path, const char *mode)
RZ_API char * rz_sys_getdir(void)
Get current working directory.
RZ_API ut64 rz_time_now(void)
Returns the current time in microseconds.
#define rz_xread(fd, buf, count)
#define RZ_JOIN_2_PATHS(p1, p2)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode fd[]
int read(izstream &zs, T *x, Items items)