/** * @internal * @brief get_boot_exec_list helper. */ NTSTATUS NTAPI query_routine(PWSTR ValueName, ULONG ValueType,PVOID ValueData,ULONG ValueLength, PVOID Context,PVOID EntryContext) { struct cmd **list = (struct cmd **)Context; struct cmd *command, *prev_command = NULL; wchar_t *cmd; if(list == NULL){ etrace("list is equal to NULL"); return STATUS_UNSUCCESSFUL; } if(ValueType != REG_SZ){ etrace("invalid %ws value type: 0x%x", ValueName, (UINT)ValueType); return STATUS_UNSUCCESSFUL; } cmd = winx_tmalloc(ValueLength + sizeof(wchar_t)); if(cmd == NULL){ mtrace(); return STATUS_NO_MEMORY; } memset(cmd,0,ValueLength + sizeof(wchar_t)); memcpy(cmd,ValueData,ValueLength); if(*list) prev_command = (*list)->prev; command = (struct cmd *)winx_list_insert( (list_entry **)(void *)list, (list_entry *)prev_command, sizeof(struct cmd)); command->cmd = cmd; return STATUS_SUCCESS; }
/** * @brief Gets the fully quallified path of the current module. * @details This routine is the native equivalent of GetModuleFileName. * @note The returned string should be freed by the winx_free call after its use. */ wchar_t *winx_get_module_filename(void) { PROCESS_BASIC_INFORMATION pi; NTSTATUS status; UNICODE_STRING *us; wchar_t *path; int size; RtlZeroMemory(&pi,sizeof(pi)); status = NtQueryInformationProcess(NtCurrentProcess(), ProcessBasicInformation,&pi, sizeof(pi),NULL); if(!NT_SUCCESS(status)){ strace(status,"cannot query basic process information"); return NULL; } us = &pi.PebBaseAddress->ProcessParameters->ImagePathName; size = us->MaximumLength + sizeof(wchar_t); path = winx_tmalloc(size); if(path == NULL){ mtrace(); return NULL; } memset(path,0,size); memcpy(path,us->Buffer,us->Length); return path; }
/** * @internal * @brief Creates global memory heap. * @return Zero for success, negative value otherwise. */ int winx_create_global_heap(void) { /* create growable heap with initial size of 100 KB */ if(hGlobalHeap == NULL){ hGlobalHeap = RtlCreateHeap(HEAP_GROWABLE,NULL,0,100 * 1024,NULL,NULL); } if(hGlobalHeap == NULL){ /* trace macro cannot be used here */ /* winx_printf cannot be used here */ winx_print("\nCannot create global memory heap!\n"); return (-1); } /* reserve 1 MB of memory for the out of memory condition handling */ reserved_memory = (char *)winx_tmalloc(1024 * 1024); return 0; }
static int save_lua_report(udefrag_job_parameters *jp) { wchar_t *path = NULL; WINX_FILE *f; wchar_t *cn; wchar_t compname[MAX_COMPUTERNAME_LENGTH + 1]; char utf8_compname[(MAX_COMPUTERNAME_LENGTH + 1) * 4]; char buffer[512]; struct prb_traverser t; winx_file_info *file; char *comment; char *status; int length; winx_time tm; /* should be enough for any path in UTF-8 encoding */ #define MAX_UTF8_PATH_LENGTH (256 * 1024) char *utf8_path; utf8_path = winx_tmalloc(MAX_UTF8_PATH_LENGTH); if(utf8_path == NULL){ mtrace(); return (-1); } path = get_report_path(jp); if(path == NULL) return UDEFRAG_NO_MEM; f = winx_fbopen(path,"w",RSB_SIZE); if(f == NULL){ f = winx_fopen(path,"w"); if(f == NULL){ winx_free(path); winx_free(utf8_path); return (-1); } } /* print header */ cn = winx_getenv(L"COMPUTERNAME"); if(cn){ wcsncpy(compname,cn,MAX_COMPUTERNAME_LENGTH + 1); compname[MAX_COMPUTERNAME_LENGTH] = 0; winx_free(cn); } else { wcscpy(compname,L"nil"); } winx_to_utf8(utf8_compname,sizeof(utf8_compname),compname); memset(&tm,0,sizeof(winx_time)); (void)winx_get_local_time(&tm); (void)_snprintf(buffer,sizeof(buffer), "-- UltraDefrag report for disk %c:\r\n\r\n" "format_version = 7\r\n\r\n" "volume_letter = \"%c\"\r\n" "computer_name = \"%hs\"\r\n\r\n" "current_time = {\r\n" "\tyear = %04i,\r\n" "\tmonth = %02i,\r\n" "\tday = %02i,\r\n" "\thour = %02i,\r\n" "\tmin = %02i,\r\n" "\tsec = %02i,\r\n" "\tisdst = false\r\n" "}\r\n\r\n" "files = {\r\n", jp->volume_letter, jp->volume_letter,utf8_compname, (int)tm.year,(int)tm.month,(int)tm.day, (int)tm.hour,(int)tm.minute,(int)tm.second ); buffer[sizeof(buffer) - 1] = 0; (void)winx_fwrite(buffer,1,strlen(buffer),f); /* print body */ prb_t_init(&t,jp->fragmented_files); file = prb_t_first(&t,jp->fragmented_files); while(file){ if(is_directory(file)) comment = "[DIR]"; else if(is_compressed(file)) comment = "[CMP]"; else comment = " - "; /* * On change of status strings don't forget * also to adjust write_file_status routine * in udreportcnv.lua file. */ if(is_locked(file)) status = "locked"; else if(is_moving_failed(file)) status = "move failed"; else if(is_in_improper_state(file)) status = "invalid"; else status = " - "; (void)_snprintf(buffer, sizeof(buffer), "\t{fragments = %u," "size = %I64u," "comment = \"%s\"," "status = \"%s\"," "path = \"", (UINT)file->disp.fragments, file->disp.clusters * jp->v_info.bytes_per_cluster, comment, status ); buffer[sizeof(buffer) - 1] = 0; (void)winx_fwrite(buffer,1,strlen(buffer),f); if(file->path != NULL){ /* skip \??\ sequence in the beginning of the path */ length = (int)wcslen(file->path); if(length > 4){ convert_to_utf8_path(utf8_path,MAX_UTF8_PATH_LENGTH,file->path + 4); } else { convert_to_utf8_path(utf8_path,MAX_UTF8_PATH_LENGTH,file->path); } (void)winx_fwrite(utf8_path,1,strlen(utf8_path),f); } (void)strcpy(buffer,"\"},\r\n"); (void)winx_fwrite(buffer,1,strlen(buffer),f); file = prb_t_next(&t); } /* print footer */ (void)strcpy(buffer,"}\r\n"); (void)winx_fwrite(buffer,1,strlen(buffer),f); itrace("report saved to %ws",path); winx_fclose(f); winx_free(path); winx_free(utf8_path); return 0; }