//! //! Sets and opens the log file //! //! @param[in] file the file name of the log file. A NULL value unset the file //! //! @return EUCA_OK on success or EUCA_ERROR on failure //! int log_file_set(const char *file, const char *req_track_file) { if (file == NULL) { // NULL means standard output log_file_path[0] = '\0'; log_file_path_req_track[0] = '\0'; return (EUCA_OK); } if (strcmp(log_file_path, file) == 0) { ; } else { euca_strncpy(log_file_path, file, EUCA_MAX_PATH); if (get_file(log_file_path, TRUE) == NULL) { return (EUCA_ERROR); } release_file(log_file_path); } if (req_track_file == NULL || strlen(req_track_file) == 0) { log_file_path_req_track[0] = '\0'; return (EUCA_OK); } if (strcmp(log_file_path_req_track, req_track_file) == 0) { return (EUCA_OK); } else { euca_strncpy(log_file_path_req_track, req_track_file, EUCA_MAX_PATH); if (get_file(log_file_path_req_track, TRUE) == NULL) { return (EUCA_ERROR); } release_file(log_file_path_req_track); } return (EUCA_OK); }
//! //! This is the function that ultimately dumps a buffer into a log. //! //! @param[in] line the string buffer to log //! //! @return EUCA_OK on success or EUCA_ERROR on failure //! //! @pre The given line pointer must not be NULL. //! //! @post The given line is written into the log file //! static int log_line(const char *line) { int rc = EUCA_ERROR; FILE *pFh = NULL; if (log_sem) { sem_prolaag(log_sem, FALSE); if ((pFh = get_file(FALSE)) != NULL) { fprintf(pFh, "%s", line); fflush(pFh); release_file(); rc = EUCA_OK; } sem_verhogen(log_sem, FALSE); } else { if ((pFh = get_file(FALSE)) != NULL) { fprintf(pFh, "%s", line); fflush(pFh); release_file(); rc = EUCA_OK; } } return (rc); }
void Restore::restore_lcp_conf(Signal* signal, FilePtr file_ptr) { RestoreLcpConf* rep= (RestoreLcpConf*)signal->getDataPtrSend(); rep->senderData= file_ptr.p->m_sender_data; if(file_ptr.p->is_lcp()) { /** * Temporary reset DBTUP's #disk attributes on table * * TUP will send RESTORE_LCP_CONF */ c_tup->complete_restore_lcp(signal, file_ptr.p->m_sender_ref, file_ptr.p->m_sender_data, file_ptr.p->m_table_id, file_ptr.p->m_fragment_id); } else { sendSignal(file_ptr.p->m_sender_ref, GSN_RESTORE_LCP_CONF, signal, RestoreLcpConf::SignalLength, JBB); } signal->theData[0] = NDB_LE_ReadLCPComplete; signal->theData[1] = file_ptr.p->m_table_id; signal->theData[2] = file_ptr.p->m_fragment_id; signal->theData[3] = Uint32(file_ptr.p->m_rows_restored >> 32); signal->theData[4] = Uint32(file_ptr.p->m_rows_restored); sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 5, JBB); release_file(file_ptr); }
// setter for logging parameters except file path void log_params_set(int log_level_in, int log_roll_number_in, long log_max_size_bytes_in) { // update the log level if (log_level_in >= EUCAALL && log_level_in <= EUCAOFF) { log_level = log_level_in; } else { log_level = DEFAULT_LOG_LEVEL; } // update the roll number limit if (log_roll_number_in >= 0 && // sanity check log_roll_number_in < 1000 && // sanity check log_roll_number != log_roll_number_in) { log_roll_number = log_roll_number_in; } // update the max size for any file if (log_max_size_bytes_in > 0 && log_max_size_bytes != log_max_size_bytes_in) { log_max_size_bytes = log_max_size_bytes_in; if (get_file(FALSE)) // that will rotate log files if needed release_file(); } }
unsigned char get_byte() { if (index >= file_size) { fprintf(stderr,"Read past end of file. Die.\n"); release_file(); exit(1); } return file_mem[index++]; }
unsigned int get_int() { if (index+3 >= file_size) { fprintf(stderr,"Read past end of file on int read. Die.\n"); release_file(); exit(1); } index += 4; return *((unsigned int *)(file_mem + index-4)); }
int main(int argc, char** argv) { get_args(argc, argv); if(argc < 1) { puts("Usage: ez executable.exe [-i -d -t] \n" "-i : destroy import address table\n" "-d : add anti debug traps\n" "-t : add execution time trace traps\n\n"); } _PE target = load_file(argv[1]); if(target->load_error != NULL) { printf(target->load_error); return -1; } // TODO after testing: not this ;) _PE lib_ez = load_file("C:\\Users\\Darius\\Documents\\GitHub\\EZEE_cryptor-x64\\ezpak\\dist\\Debug\\MinGW64-Windows\\libezpak.dll"); if(lib_ez->load_error != NULL) { printf(lib_ez->load_error); return -2; } if(!crush_sections(target, lib_ez)) { release_file(target); puts("There was a problem combining the section headers of this PE file.\n\n"); return -3; } create_stub_space(target); inject_stub(target, lib_ez); pe_fixup(target); //apply_crypt(target); save_file(target, argv[1]); release_file(target); release_file(lib_ez); return (EXIT_SUCCESS); }
//! //! setter for logging parameters except file path //! //! @param[in] log_level_in the log level to set //! @param[in] log_roll_number_in the log roll number to set //! @param[in] log_max_size_bytes_in the maximum file size in bytes to set //! //! @pre \li The log_level_in field must be within the EUCA_LOG_ALL and EUCA_LOG_OFF range //! \li The log_roll_number_in field must be withing the [0..999] range //! \li The log_max_size_bytes_in field must be greater than 0. //! //! @post \li if log_level_in field is valid, our global log_level field is updated with this value //! where if its outside the valid range, it will be set to DEFAULT_LOG_LEVEL explicitedly. //! \li If the log_roll_number_in field is valid, the log_roll_number global field will be updated //! with the given value. //! \li If the log_max_size_bytes_in field is valid, our global log_max_size_bytes field will be //! updated with the new value and get_file() will be called in order to rotate the log file //! if necessary based on the new number. //! void log_params_set(int log_level_in, int log_roll_number_in, long log_max_size_bytes_in) { // update the log level if ((log_level_in >= EUCA_LOG_ALL) && (log_level_in <= EUCA_LOG_OFF)) { log_level = log_level_in; } else { log_level = DEFAULT_LOG_LEVEL; } // update the roll number limit if ((log_roll_number_in >= 0) && (log_roll_number_in < 1000) && (log_roll_number != log_roll_number_in)) { log_roll_number = log_roll_number_in; } // update the max size for any file if (log_max_size_bytes_in >= 0 && log_max_size_bytes != log_max_size_bytes_in) { log_max_size_bytes = log_max_size_bytes_in; if (get_file(log_file_path, FALSE)) // that will rotate log files if needed release_file(log_file_path); if (get_file(log_file_path_req_track, FALSE)) // that will rotate log files if needed release_file(log_file_path_req_track); } }
int main(int argc,char *argv[]) { if (argc != 2) { fprintf(stderr,"Usage: blakdeco filename.bof\n"); exit(1); } if (memmap_file(argv[1])) { dump_bof(); release_file(); } }
static void release_file(struct iso9660 *iso9660, struct file_info *file) { struct file_info *parent; if (file->refcount == 0) { parent = file->parent; if (file->name) free(file->name); archive_string_free(&file->symlink); free(file); if (parent != NULL) { parent->refcount--; release_file(iso9660, parent); } } }
static int archive_read_format_iso9660_cleanup(struct archive_read *a) { struct iso9660 *iso9660; struct file_info *file; iso9660 = (struct iso9660 *)(a->format->data); while ((file = next_entry(iso9660)) != NULL) release_file(iso9660, file); archive_string_free(&iso9660->pathname); archive_string_free(&iso9660->previous_pathname); if (iso9660->pending_files) free(iso9660->pending_files); free(iso9660); (a->format->data) = NULL; return (ARCHIVE_OK); }
int log_file_set(const char * file) { if (file==NULL) { // NULL means standard output log_file_path [0] = '\0'; return 0; } if (strcmp (log_file_path, file) == 0) // hasn't changed return 0; strncpy (log_file_path, file, EUCA_MAX_PATH); if (get_file (TRUE) == NULL) { return 1; } release_file(); return 0; }
void get_string(char *str, int max_chars) { int i; for (i=0; i < max_chars; i++) { if (index > file_size) { fprintf(stderr,"Read past end of file on string read. Die.\n"); release_file(); exit(1); } /* Copy byte of string and look for null termination */ str[i] = *(file_mem + index); index++; if (str[i] == 0) return; } }
void Restore::execFSOPENREF(Signal* signal) { FsRef* ref= (FsRef*)signal->getDataPtr(); FilePtr file_ptr; jamEntry(); m_file_pool.getPtr(file_ptr, ref->userPointer); Uint32 errCode= ref->errorCode; Uint32 osError= ref->osErrorCode; RestoreLcpRef* rep= (RestoreLcpRef*)signal->getDataPtrSend(); rep->senderData= file_ptr.p->m_sender_data; rep->errorCode = errCode; rep->extra[0] = osError; sendSignal(file_ptr.p->m_sender_ref, GSN_RESTORE_LCP_REF, signal, RestoreLcpRef::SignalLength+1, JBB); release_file(file_ptr); }
//! //! This is the function that ultimately dumps a buffer into a log. //! //! @param[in] line the string buffer to log //! //! @return EUCA_OK on success or EUCA_ERROR on failure //! static int log_line(const char *line) { int rc = EUCA_ERROR; if (log_sem) sem_prolaag(log_sem, FALSE); FILE *file = get_file(FALSE); if (file != NULL) { fprintf(file, "%s", line); fflush(file); release_file(); rc = EUCA_OK; } if (log_sem) sem_verhogen(log_sem, FALSE); return rc; }
static int archive_read_format_iso9660_read_header(struct archive_read *a, struct archive_entry *entry) { struct iso9660 *iso9660; struct file_info *file; ssize_t bytes_read; int r; iso9660 = (struct iso9660 *)(a->format->data); if (!a->archive.archive_format) { a->archive.archive_format = ARCHIVE_FORMAT_ISO9660; a->archive.archive_format_name = "ISO9660"; } /* Get the next entry that appears after the current offset. */ r = next_entry_seek(a, iso9660, &file); if (r != ARCHIVE_OK) return (r); iso9660->entry_bytes_remaining = file->size; iso9660->entry_sparse_offset = 0; /* Offset for sparse-file-aware clients. */ /* Set up the entry structure with information about this entry. */ archive_entry_set_mode(entry, file->mode); archive_entry_set_uid(entry, file->uid); archive_entry_set_gid(entry, file->gid); archive_entry_set_nlink(entry, file->nlinks); archive_entry_set_ino(entry, file->inode); archive_entry_set_mtime(entry, file->mtime, 0); archive_entry_set_ctime(entry, file->ctime, 0); archive_entry_set_atime(entry, file->atime, 0); archive_entry_set_size(entry, iso9660->entry_bytes_remaining); archive_string_empty(&iso9660->pathname); archive_entry_set_pathname(entry, build_pathname(&iso9660->pathname, file)); if (file->symlink.s != NULL) archive_entry_copy_symlink(entry, file->symlink.s); /* If this entry points to the same data as the previous * entry, convert this into a hardlink to that entry. * But don't bother for zero-length files. */ if (file->offset == iso9660->previous_offset && file->size == iso9660->previous_size && file->size > 0) { archive_entry_set_hardlink(entry, iso9660->previous_pathname.s); iso9660->entry_bytes_remaining = 0; iso9660->entry_sparse_offset = 0; release_file(iso9660, file); return (ARCHIVE_OK); } /* If the offset is before our current position, we can't * seek backwards to extract it, so issue a warning. */ if (file->offset < iso9660->current_position) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Ignoring out-of-order file"); iso9660->entry_bytes_remaining = 0; iso9660->entry_sparse_offset = 0; release_file(iso9660, file); return (ARCHIVE_WARN); } iso9660->previous_size = file->size; iso9660->previous_offset = file->offset; archive_strcpy(&iso9660->previous_pathname, iso9660->pathname.s); /* If this is a directory, read in all of the entries right now. */ if (archive_entry_filetype(entry) == AE_IFDIR) { while (iso9660->entry_bytes_remaining > 0) { const void *block; const unsigned char *p; ssize_t step = iso9660->logical_block_size; if (step > iso9660->entry_bytes_remaining) step = iso9660->entry_bytes_remaining; bytes_read = (a->decompressor->read_ahead)(a, &block, step); if (bytes_read < step) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Failed to read full block when scanning ISO9660 directory list"); release_file(iso9660, file); return (ARCHIVE_FATAL); } if (bytes_read > step) bytes_read = step; (a->decompressor->consume)(a, bytes_read); iso9660->current_position += bytes_read; iso9660->entry_bytes_remaining -= bytes_read; for (p = (const unsigned char *)block; *p != 0 && p < (const unsigned char *)block + bytes_read; p += *p) { struct file_info *child; /* Skip '.' entry. */ if (*(p + DR_name_len_offset) == 1 && *(p + DR_name_offset) == '\0') continue; /* Skip '..' entry. */ if (*(p + DR_name_len_offset) == 1 && *(p + DR_name_offset) == '\001') continue; child = parse_file_info(iso9660, file, p); add_entry(iso9660, child); if (iso9660->seenRockridge) { a->archive.archive_format = ARCHIVE_FORMAT_ISO9660_ROCKRIDGE; a->archive.archive_format_name = "ISO9660 with Rockridge extensions"; } } } } release_file(iso9660, file); return (ARCHIVE_OK); }
void dump_bof() { unsigned int c,i,j,superclass_id; unsigned int num_properties, prop_num,prop_defaults; unsigned int num_cvars, cvar_num,cvar_defaults; unsigned int handler[MAX_HANDLERS],num_messages; unsigned int classes[MAX_CLASSES],num_classes; unsigned int strtable_offset, fname_offset; unsigned int num_strings; int classes_id[MAX_CLASSES]; char *default_str, str[500]; index = 0; for (i=0; i < 4; i++) { BYTE b = get_byte(); if (b != bof_magic[i]) printf("Bad magic number--this is not a BOF file\n"); } printf(".bof version: %i\n",get_int()); fname_offset = get_int(); if (fname_offset >= (unsigned int) file_size) { fprintf(stderr,"Read past end of file on kod filename. Die.\n"); release_file(); exit(1); } printf("Source file = %s\n", file_mem + fname_offset); strtable_offset = get_int(); printf("String table at offset %08X\n", strtable_offset); debug_offset = get_int(); if (debug_offset == 0) printf("No line number debugging information\n"); else printf("Debugging information at offset %08X\n", debug_offset); num_classes = get_int(); printf("Classes: %i\n",num_classes); if (num_classes > MAX_CLASSES-1) { printf("Can only handle %i classes\n",MAX_CLASSES-1); num_classes = MAX_CLASSES-1; } for (i=0;i<num_classes;i++) { classes_id[i] = get_int(); classes[i] = get_int(); printf("class id %i at offset %08X\n",classes_id[i],classes[i]); } classes[i] = -1; for (c=0;c<num_classes;c++) { printf("Class id %i:\n",classes_id[c]); superclass_id = get_int(); printf("Superclass %i\n",superclass_id); printf("Property table offset: %08X\n", get_int()); printf("Message handler offset: %08X\n", get_int()); num_cvars = get_int(); printf("Classvars: %i\n", num_cvars); cvar_defaults = get_int(); printf("Classvar default values: %i\n",cvar_defaults); for (i=0;i<cvar_defaults;i++) { cvar_num = get_int(); default_str = strdup(str_constant(get_int())); printf(" classvar %2i init value: %s\n",cvar_num,default_str); } num_properties = get_int(); printf("Properties: %i\n",num_properties); prop_defaults = get_int(); printf("Property default values: %i\n",prop_defaults); for (i=0;i<prop_defaults;i++) { prop_num = get_int(); default_str = strdup(str_constant(get_int())); printf(" property %2i init value: %s\n",prop_num,default_str); } num_messages = get_int(); printf("Message handlers: %i\n",num_messages); if (num_messages > MAX_HANDLERS-1) { printf("Can only handle %i handlers\n",MAX_HANDLERS-1); num_messages = MAX_HANDLERS-1; } for (i=0;i<num_messages;i++) { int id, comment; id = get_int(); handler[i] = get_int(); comment = get_int(); printf(" message %5i at offset %08X\n",id,handler[i]); if (comment != -1) printf(" Comment string #%5i\n", comment); } handler[i] = -1; printf("BKOD data:\n"); for (i=0;i<num_messages;i++) { unsigned char locals,num_parms; int parm_id,parm_default; locals = get_byte(); num_parms = get_byte(); printf("\nMessage handler, %i local vars\n",locals); for (j=0;j<(unsigned int) num_parms;j++) { parm_id = get_int(); parm_default = get_int(); default_str = strdup(str_constant(parm_default)); printf(" parm id %i = %s\n",parm_id,default_str); } // printf("at ofs %08X, next handler %08X, next class %08X\n", // index,handler[i+1],classes[c+1]); while ((unsigned int) index < handler[i+1] && (unsigned int) index < classes[c+1] && index < file_size) { dump_bkod(); if (index == strtable_offset) break; } } printf("--------------------------------------------\n"); num_strings = get_int(); printf("Strings: %d\n", num_strings); for (i=0; i < num_strings; i++) printf("String %d at offset %08X\n", i, get_int()); for (i=0; i < num_strings; i++) { get_string(str, 500); printf("String %d = %s\n", i, str); } printf("\n"); } }
void *check_db_thread ( void *arg ) { int timerfd = timerfd_create (CLOCK_REALTIME, 0); int check_db_fd = timerfd_create (CLOCK_REALTIME, 0); if ( timerfd == - 1 || check_db_fd == - 1 ) { return ( void * ) NULL; } struct itimerspec tv, check_tv; memset (&tv, 0, sizeof (tv )); memset (&check_tv, 0, sizeof (check_tv )); tv.it_value.tv_sec = 1; tv.it_interval.tv_sec = release_interval; check_tv.it_value.tv_sec = 1; check_tv.it_interval.tv_sec = checkdb_interval; if ( timerfd_settime (timerfd, 0, &tv, NULL) == - 1 || timerfd_settime (check_db_fd, 0, &check_tv, NULL) == - 1 ) { return ( void * ) NULL; } struct pollfd *pfd; pfd = ( struct pollfd * ) calloc ( 3, sizeof ( struct pollfd ) ); if ( pfd == NULL ) { return ( void * ) NULL; } pfd[0].fd = timerfd; pfd[0].events = POLLIN; pfd[1].fd = check_db_fd; pfd[1].events = POLLIN; pfd[2].fd = stop_pipe[0]; pfd[2].events = POLLIN; int ret; uint64_t val; while ( is_running ) { ret = poll ( pfd, 3, - 1 ); if ( ret == - 1 ) { if ( errno == EINTR ) { continue; } continue; } if ( pfd[0].revents & POLLIN ) { read ( timerfd, &val, sizeof ( val ) ); release_file (); } if ( pfd[1].revents & POLLIN ) { read ( check_db_fd, &val, sizeof ( val ) ); check_db ( hosts ); } if ( pfd[2].revents & POLLIN ) { char buf; read ( stop_pipe[0], &buf, 1 ); } } close ( timerfd ); close ( check_db_fd ); delete client; return ( void * ) NULL; }
static struct elf_file *grab_module(const char *name, const char *kernel, const char *basedir) { char *data; unsigned long size; struct utsname buf; char *depname, *p, *moddir; struct elf_file *module; if (strchr(name, '.') || strchr(name, '/')) { module = grab_elf_file(name); if (!module) error("modinfo: could not open %s: %s\n", name, strerror(errno)); return module; } if (!kernel) { uname(&buf); kernel = buf.release; } if (strlen(basedir)) nofail_asprintf(&moddir, "%s/%s/%s", basedir, MODULE_DIR, kernel); else nofail_asprintf(&moddir, "%s/%s", MODULE_DIR, kernel); /* Search for it in modules.dep. */ nofail_asprintf(&depname, "%s/%s", moddir, "modules.dep"); data = grab_file(depname, &size); if (!data) { error("modinfo: could not open %s\n", depname); free(depname); return NULL; } free(depname); for (p = data; p < data + size; p = next_line(p, data + size)) { if (name_matches(p, data + size, name)) { int namelen = strcspn(p, ":"); const char *dir; char *filename; if ('/' == p[0]) dir = basedir; /* old style deps - abs. path */ else dir = moddir; /* new style - relative path */ if (strlen(dir)) { nofail_asprintf(&filename, "%s/%s", dir, p); filename[namelen + strlen(dir) + 1] = '\0'; } else { filename = strndup(p, namelen); } release_file(data, size); module = grab_elf_file(filename); if (!module) error("modinfo: could not open %s: %s\n", filename, strerror(errno)); free(filename); return module; } } release_file(data, size); error("modinfo: could not find module %s\n", name); return NULL; }