/programs/develop/libraries/kolibri-libc/linuxtools/src/ExportGen.c |
---|
0,0 → 1,57 |
// export_table_gen |
// Copyright (C) maxcodehack and turbocat2001, 2021 |
#include <stdio.h> |
#include <string.h> |
int main(int argc, char** argv) { |
if (argc != 3) { |
printf("Usage: %s <symbols.txt> <exports.c>\n", argv[0]); |
return 0; |
} |
FILE *input, *output; |
if ((input = fopen(argv[1], "r")) == NULL) |
{ |
printf("error: file \"%s\" not found\n", argv[1]); |
return 1; |
} |
char buf[10000]; |
// Head |
strcpy(buf, \ |
"#include <stdio.h>\n" \ |
"#include <string.h>\n" \ |
"#include <stdlib.h>\n" \ |
"#include <time.h>\n" \ |
"#include <sys/dirent.h>\n" \ |
"#include <sys/ksys.h>\n\n" \ |
"#include <math.h>\n\n" \ |
"#include <setjmp.h>\n\n" \ |
"ksys_coff_etable_t EXPORTS[] = {\n"); |
// Generate |
char symbol[256]; |
while(fscanf(input, "%s", symbol) != EOF) { |
if(symbol[0]!='!'){ |
char temp[256]; |
sprintf(temp, "{\"%s\", &%s},\n", symbol, symbol); |
strcat(buf, temp); |
} |
} |
strcat(buf, "NULL,\n};"); |
fclose(input); |
// Output generated |
output = fopen(argv[2], "w"); |
if (output == NULL) |
{ |
printf("Unable to write to file: '%s'!\n", argv[2]); |
return 1; |
} |
fputs(buf, output); |
fclose(output); |
printf("Done, check %s!\n", argv[2]); |
return 0; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/kolibri-libc/linuxtools/src/LoaderGen.c |
---|
0,0 → 1,48 |
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <limits.h> |
int main(int argc, char** argv) { |
if(argc!=3){ |
printf("Usage: LoadGen <symbols.txt> <loader_dir>\n"); |
return 0; |
} |
argv[2][strlen(argv[1])-2]='\0'; |
FILE* symbols_txt = fopen(argv[1], "r"); |
if(!symbols_txt){ |
fprintf(stderr, "File '%s' not found!\n", argv[1]); |
return -1; |
} |
char line[256]; |
while(fgets(line, 256, symbols_txt)) { |
if(line[0]!='!'){ |
if(line[strlen(line)-1]=='\n'){ |
line[strlen(line)-1]='\0'; |
} |
char asm_name[PATH_MAX]; |
sprintf(asm_name, "%s/%s.asm", argv[2], line); |
FILE *out = fopen(asm_name, "wb"); |
if(!out){ |
fprintf(stderr, "Error! File '%s' not created!\n", asm_name); |
return -1; |
}else{ |
printf("File '%s' created successfully!\n", asm_name); |
} |
fprintf(out, "format ELF\n"); |
fprintf(out, "include \"__lib__.inc\"\n"); |
fprintf(out, "fun equ __func@%s\n", line); |
fprintf(out, "fun_str equ '%s'\n", line); |
fprintf(out, "section '.text'\n"); |
fprintf(out, "fun_name db fun_str, 0\n"); |
fprintf(out, "section '.data'\n"); |
fprintf(out, "extrn lib_name\n"); |
fprintf(out, "public fun as fun_str\n"); |
fprintf(out, "fun dd fun_name\n"); |
fprintf(out, "lib dd lib_name\n"); |
fclose(out); |
} |
} |
} |
/programs/develop/libraries/kolibri-libc/linuxtools/src/Makefile |
---|
0,0 → 1,3 |
all: |
$(CC) ExportGen.c -o ../ExportGen |
$(CC) LoaderGen.c -o ../LoaderGen |