static int lookup_functions() { lib_handle = LoadLibraryA("hid.dll"); if (lib_handle) { #define RESOLVE(x) x = (x##_)GetProcAddress(lib_handle, #x); if (!x) return -1; RESOLVE(HidD_GetAttributes); RESOLVE(HidD_GetSerialNumberString); RESOLVE(HidD_GetManufacturerString); RESOLVE(HidD_GetProductString); RESOLVE(HidD_SetFeature); RESOLVE(HidD_GetFeature); RESOLVE(HidD_GetIndexedString); RESOLVE(HidD_GetPreparsedData); RESOLVE(HidD_FreePreparsedData); RESOLVE(HidP_GetCaps); #undef RESOLVE } else return -1; return 0; }
void initKernel(void) { int libkernel; loadModule("libkernel.sprx", &libkernel); RESOLVE(libkernel, sceKernelLoadStartModule); RESOLVE(libkernel, sceKernelAllocateDirectMemory); RESOLVE(libkernel, sceKernelMapDirectMemory); RESOLVE(libkernel, sceKernelSleep); RESOLVE(libkernel, sceKernelUsleep); RESOLVE(libkernel, sceKernelGettimeofday); RESOLVE(libkernel, sceKernelGetProcessTime); RESOLVE(libkernel, sceKernelGetCurrentCpu); }
int fclose(FILE *stream) { int fd = fileno(stream); if (intercept[fd]) { DEBUGF("fd=%d\n", fd); return _intercept_close(fd); } RESOLVE(fclose); return o_fclose(stream); }
__off64_t ftello64 (FILE *stream) { int fd = fileno(stream); if (intercept[fd]) { DEBUGF("fd=%d\n", fd); return intercept[fd]->offset; } RESOLVE(ftello64); return o_ftello64(stream); }
void pdf_array_push_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *item) { RESOLVE(obj); if (obj >= PDF_OBJ__LIMIT) { fz_try(ctx) pdf_array_push(ctx, obj, item); fz_always(ctx) pdf_drop_obj(ctx, item); fz_catch(ctx) fz_rethrow(ctx); } }
void pdf_array_insert_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *item, int i) { RESOLVE(obj); if (obj) { fz_try(ctx) pdf_array_insert(ctx, obj, item, i); fz_always(ctx) pdf_drop_obj(ctx, item); fz_catch(ctx) fz_rethrow(ctx); } }
int __fxstat64(int version, int fd, struct stat64 *buf) { if (intercept[fd]) { DEBUGF("version=%d, fd=%d\n", version, fd); _intercept_stat(fd, buf); return 0; } RESOLVE(__fxstat64); return o___fxstat64(version, fd, buf); }
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) { int fd = fileno(stream); if (intercept[fd]) { DEBUGF("ptr=%p, size=%zu, nmemb=%zu, fd=%d", ptr, size, nmemb, fd); return _intercept_read(fd, ptr, size * nmemb); } RESOLVE(fread); return o_fread(ptr, size, nmemb, stream); }
void pdf_array_delete(fz_context *ctx, pdf_obj *obj, int i) { RESOLVE(obj); if (!OBJ_IS_ARRAY(obj)) fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj)); if (i < 0 || i >= ARRAY(obj)->len) fz_throw(ctx, FZ_ERROR_GENERIC, "index out of bounds"); prepare_object_for_alteration(ctx, obj, NULL); pdf_drop_obj(ctx, ARRAY(obj)->items[i]); ARRAY(obj)->items[i] = 0; ARRAY(obj)->len--; memmove(ARRAY(obj)->items + i, ARRAY(obj)->items + i + 1, (ARRAY(obj)->len - i) * sizeof(pdf_obj*)); }
void pdf_array_insert(fz_context *ctx, pdf_obj *obj, pdf_obj *item, int i) { RESOLVE(obj); if (!OBJ_IS_ARRAY(obj)) fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj)); if (i < 0 || i > ARRAY(obj)->len) fz_throw(ctx, FZ_ERROR_GENERIC, "index out of bounds"); prepare_object_for_alteration(ctx, obj, item); if (ARRAY(obj)->len + 1 > ARRAY(obj)->cap) pdf_array_grow(ctx, ARRAY(obj)); memmove(ARRAY(obj)->items + i + 1, ARRAY(obj)->items + i, (ARRAY(obj)->len - i) * sizeof(pdf_obj*)); ARRAY(obj)->items[i] = pdf_keep_obj(ctx, item); ARRAY(obj)->len++; }
CONFUGA_API int confuga_truncate(confuga *C, const char *path, confuga_off_t length) { static const confuga_fid_t empty = {CONFUGA_FID_EMPTY}; int rc; RESOLVE(path) debug(D_CONFUGA, "truncate(`%s', %" PRIuCONFUGA_OFF_T ")", unresolved_path, length); confuga_fid_t fid; confuga_off_t size; enum CONFUGA_FILE_TYPE type; CATCH(lookup(C, path, &fid, &size, &type)); if (length > 0) CATCH(EINVAL); CATCH(update(C, path, empty, 0, 0)); PROLOGUE }
void pdf_array_push(fz_context *ctx, pdf_obj *obj, pdf_obj *item) { RESOLVE(obj); if (!OBJ_IS_ARRAY(obj)) fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj)); if (!item) item = PDF_OBJ_NULL; prepare_object_for_alteration(ctx, obj, item); if (ARRAY(obj)->len + 1 > ARRAY(obj)->cap) pdf_array_grow(ctx, ARRAY(obj)); ARRAY(obj)->items[ARRAY(obj)->len] = pdf_keep_obj(ctx, item); ARRAY(obj)->len++; }
CONFUGA_API int confuga_link(confuga *C, const char *target, const char *path) { /* This deserves some explanation: * * Since the NM manages both the Confuga NS and the file metadata, the * inode on the local file system contains all the file metadata and a * pointer to file contents. So, when we create a link, we really want to * have both entries point to the local file system inode. * * The inode also points to file data which includes the Confuga file ID. * This would be an identifier for the content, not the metadata. */ int rc; RESOLVE(target); SIMPLE_WRAP_UNIX(link(target, path), "link(`%s', `%s')", unresolved_target, unresolved_path); }
static INT64_T chirp_fs_local_open(const char *path, INT64_T flags, INT64_T mode) { const char *unresolved = path; RESOLVE(path) INT64_T fd = getfd(); if (fd == -1) return -1; mode &= S_IXUSR|S_IRWXG|S_IRWXO; mode |= S_IRUSR|S_IWUSR; INT64_T lfd = open64(path, flags, mode); if (lfd >= 0) { open_files[fd].fd = lfd; strcpy(open_files[fd].path, unresolved); return fd; } else { return -1; } }
static INT64_T chirp_fs_local_open(const char *path, INT64_T flags, INT64_T mode) { PREAMBLE("open(`%s', 0x%" PRIx64 ", 0o%" PRIo64 ")", path, flags, mode); const char *unresolved = path; RESOLVE(path) INT64_T fd = getfd(); if (fd == -1) return -1; mode &= S_IXUSR|S_IRWXG|S_IRWXO; mode |= S_IRUSR|S_IWUSR; rc = open64(path, flags, (int) mode); if (rc >= 0) { open_files[fd].fd = rc; strcpy(open_files[fd].path, unresolved); rc = fd; } PROLOGUE }
int fseeko64 (FILE *stream, __off64_t offset, int whence) { int fd = fileno(stream); if (intercept[fd]) { DEBUGF("fd=%d, offset=%s, whence=%d\n", fd, str_off_t(offset), whence); if (_intercept_seek(fd, offset, whence) < 0) return EINVAL; return 0; } RESOLVE(fseeko64); return o_fseeko64(stream, offset, whence); }
fz_obj * fz_copy_dict(fz_context *ctx, fz_obj *obj) { fz_obj *dict; int i, n; RESOLVE(obj); if (obj && obj->kind != FZ_DICT) fz_warn(ctx, "assert: not a dict (%s)", fz_objkindstr(obj)); n = fz_dict_len(obj); dict = fz_new_dict(ctx, n); for (i = 0; i < n; i++) fz_dict_put(dict, fz_dict_get_key(obj, i), fz_dict_get_val(obj, i)); return dict; }
void pdf_array_push(pdf_obj *obj, pdf_obj *item) { RESOLVE(obj); if (!obj) return; /* Can't warn :( */ if (obj->kind != PDF_ARRAY) fz_warn(obj->ctx, "assert: not an array (%s)", pdf_objkindstr(obj)); else { if (obj->u.a.len + 1 > obj->u.a.cap) pdf_array_grow(obj); obj->u.a.items[obj->u.a.len] = pdf_keep_obj(item); obj->u.a.len++; } }
void pdf_array_put(fz_context *ctx, pdf_obj *obj, int i, pdf_obj *item) { RESOLVE(obj); if (!OBJ_IS_ARRAY(obj)) fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj)); if (i == ARRAY(obj)->len) { pdf_array_push(ctx, obj, item); return; } if (i < 0 || i > ARRAY(obj)->len) fz_throw(ctx, FZ_ERROR_GENERIC, "index out of bounds"); prepare_object_for_alteration(ctx, obj, item); pdf_drop_obj(ctx, ARRAY(obj)->items[i]); ARRAY(obj)->items[i] = pdf_keep_obj(ctx, item); }
void pdf_dict_put_val_drop(fz_context *ctx, pdf_obj *obj, int i, pdf_obj *new_obj) { RESOLVE(obj); if (!obj || obj->kind != PDF_DICT) { pdf_drop_obj(ctx, new_obj); return; } if (i < 0 || i >= obj->u.d.len) { /* FIXME: Should probably extend the dict here */ pdf_drop_obj(ctx, new_obj); return; } pdf_drop_obj(ctx, obj->u.d.items[i].v); obj->u.d.items[i].v = new_obj; }
void pdf_array_delete(fz_context *ctx, pdf_obj *obj, int i) { RESOLVE(obj); if (obj) { if (obj->kind != PDF_ARRAY) fz_warn(ctx, "assert: not an array (%s)", pdf_objkindstr(obj)); else { pdf_drop_obj(ctx, obj->u.a.items[i]); obj->u.a.items[i] = 0; obj->u.a.len--; memmove(obj->u.a.items + i, obj->u.a.items + i + 1, (obj->u.a.len - i) * sizeof(pdf_obj*)); } } return; /* Can't warn :( */ }
fz_obj * fz_copy_array(fz_context *ctx, fz_obj *obj) { fz_obj *arr; int i; int n; RESOLVE(obj); if (!obj || obj->kind != FZ_ARRAY) fz_warn(ctx, "assert: not an array (%s)", fz_objkindstr(obj)); arr = fz_new_array(ctx, fz_array_len(obj)); n = fz_array_len(obj); for (i = 0; i < n; i++) fz_array_push(arr, fz_array_get(obj, i)); return arr; }
FILE *fopen64(const char *pathname, const char *mode) { if (IS_SUPPORTED_URL(pathname)) { int fd; FILE *ret = 0; DEBUGF("pathname=%s, mode=%s\n", pathname, mode); if ((fd = _intercept_open(pathname)) > 0) ret = fdopen(fd, mode); return ret; } RESOLVE(fopen64); return o_fopen64(pathname, mode); }
void fz_array_insert(fz_obj *obj, fz_obj *item) { RESOLVE(obj); if (!obj) return; /* Can't warn :( */ if (obj->kind != FZ_ARRAY) fz_warn(obj->ctx, "assert: not an array (%s)", fz_objkindstr(obj)); else { if (obj->u.a.len + 1 > obj->u.a.cap) fz_array_grow(obj); memmove(obj->u.a.items + 1, obj->u.a.items, obj->u.a.len * sizeof(fz_obj*)); obj->u.a.items[0] = fz_keep_obj(item); obj->u.a.len++; } }
void pdf_array_put(pdf_obj *obj, int i, pdf_obj *item) { RESOLVE(obj); if (!obj) return; /* Can't warn :( */ if (obj->kind != PDF_ARRAY) fz_warn(obj->ctx, "assert: not an array (%s)", pdf_objkindstr(obj)); else if (i < 0) fz_warn(obj->ctx, "assert: index %d < 0", i); else if (i >= obj->u.a.len) fz_warn(obj->ctx, "assert: index %d > length %d", i, obj->u.a.len); else { pdf_drop_obj(obj->u.a.items[i]); obj->u.a.items[i] = pdf_keep_obj(item); } }
pdf_obj * pdf_copy_dict(fz_context *ctx, pdf_obj *obj) { pdf_document *doc; pdf_obj *dict; int i, n; RESOLVE(obj); if (!OBJ_IS_DICT(obj)) fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj)); doc = DICT(obj)->doc; n = pdf_dict_len(ctx, obj); dict = pdf_new_dict(ctx, doc, n); for (i = 0; i < n; i++) pdf_dict_put(ctx, dict, pdf_dict_get_key(ctx, obj, i), pdf_dict_get_val(ctx, obj, i)); return dict; }
int __lxstat64(int version, const char *file_name, struct stat64 *buf) { if (IS_SUPPORTED_URL(file_name)) { int fd; DEBUGF("version=%d, file_name=%s\n", version, file_name); if ((fd = _intercept_open(file_name)) < 0) return -1; _intercept_stat(fd, buf); _intercept_close(fd); return 0; } RESOLVE(__lxstat64); return o___lxstat64(version, file_name, buf); }
pdf_obj * pdf_copy_dict(fz_context *ctx, pdf_obj *obj) { pdf_obj *dict; int i, n; RESOLVE(obj); if (!obj) return NULL; /* Can't warn :( */ if (obj->kind != PDF_DICT) fz_warn(ctx, "assert: not a dict (%s)", pdf_objkindstr(obj)); n = pdf_dict_len(obj); dict = pdf_new_dict(ctx, n); for (i = 0; i < n; i++) fz_dict_put(dict, pdf_dict_get_key(obj, i), pdf_dict_get_val(obj, i)); return dict; }
void pdf_array_push(fz_context *ctx, pdf_obj *obj, pdf_obj *item) { RESOLVE(obj); if (obj) { if (obj->kind != PDF_ARRAY) fz_warn(ctx, "assert: not an array (%s)", pdf_objkindstr(obj)); else { if (obj->u.a.len + 1 > obj->u.a.cap) pdf_array_grow(ctx, obj); obj->u.a.items[obj->u.a.len] = pdf_keep_obj(ctx, item); obj->u.a.len++; } object_altered(ctx, obj, item); } return; /* Can't warn :( */ }
pdf_obj * pdf_copy_array(fz_context *ctx, pdf_obj *obj) { pdf_obj *arr; int i; int n; RESOLVE(obj); if (!obj) return NULL; /* Can't warn :( */ if (obj->kind != PDF_ARRAY) fz_warn(ctx, "assert: not an array (%s)", pdf_objkindstr(obj)); arr = pdf_new_array(ctx, pdf_array_len(obj)); n = pdf_array_len(obj); for (i = 0; i < n; i++) pdf_array_push(arr, pdf_array_get(obj, i)); return arr; }