Skip to content

Commit

Permalink
v0.2.2 Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bvernoux committed Jun 3, 2023
1 parent 7886bc5 commit 1cc4075
Showing 2 changed files with 10 additions and 16 deletions.
18 changes: 6 additions & 12 deletions Find_DLL_Dependencies.c
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
#include <string.h>

#define APP_NAME "Find_DLL_Dependencies"
#define VERSION "v0.1.0 29/05/2023 B.VERNOUX"
#define VERSION "v0.1.1 03/06/2023 B.VERNOUX"

#define BANNER1 APP_NAME " " VERSION "\n"
#define USAGE "usage: " APP_NAME " <win32_64_exe_or_dll>\n"
@@ -69,8 +69,8 @@ typedef struct _IMAGE_FILE_HEADER {
} IMAGE_FILE_HEADER;

typedef struct _IMAGE_DATA_DIRECTORY {
uint32_t VirtualAddress;
uint32_t Size;
uint32_t VirtualAddress;
uint32_t Size;
} IMAGE_DATA_DIRECTORY;

#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
@@ -280,9 +280,9 @@ int Find_DLL_Dependencies(const char* filename, char* dependencies[], size_t num
return 0; /* No dependencies found / Error import_directory invalid data */
}

IMAGE_IMPORT_DESCRIPTOR import_descriptor;
long fileoffset_import_descriptor = section_header.PointerToRawData + (import_directory.VirtualAddress - section_header.VirtualAddress);
while (1) {
IMAGE_IMPORT_DESCRIPTOR import_descriptor;
if(fseek(file, fileoffset_import_descriptor, SEEK_SET) != 0) {
Find_DLL_Dependencies_file_error_exit(file);
}
@@ -299,17 +299,11 @@ int Find_DLL_Dependencies(const char* filename, char* dependencies[], size_t num
if(fseek(file, section_header.PointerToRawData + (import_descriptor.Name - section_header.VirtualAddress), SEEK_SET) != 0) {
Find_DLL_Dependencies_file_error_exit(file);
}
char dll_name[DLL_NAME_MAX_SIZE];
char dll_name[DLL_NAME_MAX_SIZE + 1] = { 0 };
fread_nb = fread(dll_name, 1, DLL_NAME_MAX_SIZE, file);
if(fread_nb != DLL_NAME_MAX_SIZE) {
Find_DLL_Dependencies_file_error_exit(file);
}
size_t j;
for (j = 0; j < DLL_NAME_MAX_SIZE; j++) {
if (dll_name[j] == '\0') {
break;
}
}
dependencies[nb_dependencies++] = strdup(dll_name);
} else {
fclose(file);
@@ -340,7 +334,7 @@ int main(int argc, char* argv[]) {
}
const char* filename = argv[1];
char* dependencies[MAX_DEPS]; // Adjust the array size as per your requirements
char* dependencies[MAX_DEPS] = { 0 }; // Adjust the array size as per your requirements
size_t num_dependencies = ARRAY_LENGTH(dependencies);
int num_deps = Find_DLL_Dependencies(filename, dependencies, num_dependencies);
8 changes: 4 additions & 4 deletions mingw-bundledlls.c
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ extern int Find_DLL_Dependencies(const char* filename, char* dependencies[], siz
extern void Free_DLL_Dependencies(char* dependencies[], size_t num_dependencies);

#define APP_NAME "mingw-bundledlls"
#define VERSION "v0.2.1 30/05/2023 B.VERNOUX"
#define VERSION "v0.2.2 03/06/2023 B.VERNOUX"

#define BANNER1 APP_NAME " " VERSION "\n"
#define USAGE "usage: " APP_NAME " <exe_file> [--copy] [--verbose]\n"
@@ -286,12 +286,12 @@ void copyFile(const char* source, const char* destination) {
}

void copyDeps(const char* exe_file, char* deps[], int num_deps) {
char exe_dir[MAX_PATH_LENGTH + 1];
char exe_dir[MAX_PATH_LENGTH + 1] = { 0 };
strncpy(exe_dir, exe_file, MAX_PATH_LENGTH);

for (int i = 0; i < num_deps; i++) {
char* dep = deps[i];
char target[MAX_PATH_LENGTH + 1];
char target[MAX_PATH_LENGTH + 1] = { 0 };
/* Detect path separator */
char* PATH_SEPARATOR;
if(strstr(exe_dir, PATH_SEPARATOR_WINDOWS) != NULL) {
@@ -394,7 +394,7 @@ int main(int argc, char* argv[]) {
if (num_deps > 0) {
printf("Dependencies(%d):\n", num_deps);
if (copy_files) { // Copy all dependencies
char destination[MAX_PATH_LENGTH + 1];
char destination[MAX_PATH_LENGTH + 1] = { 0 };
snprintf(destination, MAX_PATH_LENGTH, "%s", dirname(exe_file));
copyDeps(destination, deps, num_deps);
} else { // Display all dependencies

0 comments on commit 1cc4075

Please sign in to comment.