KWINE v0.0.3

into msvcrt.dll added:
 - putchar
 - strchr
 - strrchr
 - strcpy
 - strncpy
 - memset
 - memcpy
 - memcmp
 - time
 - mktime
 - localtime
 - difftime
 - srand
 - rand
new samples
 - rnd_arr1.exe
 - string2.exe

git-svn-id: svn://kolibrios.org@7894 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Rustem Gimadutdinov (rgimad) 2020-05-07 22:14:53 +00:00
parent 88a13211ae
commit bdd9a3634d
12 changed files with 115 additions and 10 deletions

Binary file not shown.

View File

@ -117,7 +117,7 @@ lib dd 0
func dd 0
func_name dd 0
; ------------------------------------------------------------- ;
sz_pe_load db "PELoad",0
sz_pe_load db "KWINE",0
; ------------------------------------------------------------- ;
con_init dd 0
con_write_asciiz dd 0

View File

@ -42,12 +42,12 @@ void *load_library(char *name) {
void *getprocaddress(void *exports, char *name)
{
if (exports == NULL) { return 0; }
while (*(uint32_t*)exports != NULL)
while (*(uint32_t*)exports != 0)
{
char *str1 = (char*)(*(uint32_t*)exports);
if (strcmp(str1, name) == 0)
{
void *ptr = *(uint32_t*)(exports + 4);
void *ptr = (void*)*(uint32_t*)(exports + 4);
// important for debug
/*debug_board_write_string(name);
@ -146,13 +146,13 @@ int con_init_console_dll(void)
// --------------------------------------------------------------------
int cdecl _getch()
int _getch()
{
con_init_console_dll();
return con_getch();
}
int cdecl _kbhit()
int _kbhit()
{
con_init_console_dll();
return con_kbhit();

View File

@ -0,0 +1,11 @@
#ifndef _CONIO_H
#define _CONIO_H
int _getch();
int _kbhit();
int con_init_console_dll(void);
int con_init_console_dll_param(uint32_t wnd_width, uint32_t wnd_height, uint32_t scr_width, uint32_t scr_height, const char* title);
void con_lib_link(void *exp, char** imports);
#endif

View File

@ -6,15 +6,19 @@
#include <stdarg.h>
#include "msvcrt.dll.h"
#include "string.h"
#include "conio.h"
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
#include "string.c"
//#include "dlfcn.c"
#include "conio.c"
#include "stdio.c"
#include "stdlib.c"
#include "time.h"
#include "time.c"
// note: by default all function in c are cdecl :D
typedef struct
{
@ -30,13 +34,23 @@ const char sz__kbhit[] = "_kbhit";
const char sz_printf[] = "printf";
const char sz_puts[] = "puts";
const char sz_gets[] = "gets";
const char sz_putchar[] = "putchar";
//string
const char sz_strlen[] = "strlen";
const char sz_strcmp[] = "strcmp";
const char sz_strcat[] = "strcat";
const char sz_strchr[] = "strchr";
const char sz_strrchr[] = "strrchr";
const char sz_strcpy[] = "strcpy";
const char sz_strncpy[] = "strncpy";
const char sz_memset[] = "memset";
const char sz_memcpy[] = "memcpy";
const char sz_memcmp[] = "memcmp";
// stdlib
const char sz_srand[] = "srand";
const char sz_rand[] = "rand";
const char sz_malloc[] = "malloc";
const char sz_free[] = "free";
const char sz_realloc[] = "realloc";
@ -44,6 +58,9 @@ const char sz_realloc[] = "realloc";
// time
const char sz_time[] = "time";
const char sz_mktime[] = "mktime";
const char sz_localtime[] = "localtime";
const char sz_difftime[] = "difftime";
//uint32_t EXPORTS[] __asm__("EXPORTS") =
@ -55,16 +72,30 @@ export_t EXPORTS[] =
{sz_printf, (void*)printf},
{sz_puts, (void*)puts},
{sz_gets, (void*)gets},
{sz_putchar, (void*)putchar},
{sz_strlen, (void*)strlen},
{sz_strcmp, (void*)strcmp},
{sz_strcat, (void*)strcat},
{sz_strchr, (void*)strchr},
{sz_strrchr, (void*)strrchr},
{sz_strcpy, (void*)strcpy},
{sz_strncpy, (void*)strncpy},
{sz_memset, (void*)memset},
{sz_memcpy, (void*)memcpy},
{sz_memcmp, (void*)memcmp},
{sz_srand, (void*)srand},
{sz_rand, (void*)rand},
{sz_malloc, (void*)malloc},
{sz_free, (void*)free},
{sz_realloc, (void*)realloc},
{sz_time, (void*)time},
{sz_mktime, (void*)mktime},
{sz_localtime, (void*)localtime},
{sz_difftime, (void*)difftime},
{NULL, NULL},
};

View File

@ -10,13 +10,13 @@ int putchar(int ch)
return ch;
}
void cdecl puts(const char *str)
void puts(const char *str)
{
con_init_console_dll();
con_write_asciiz(str);
}
char* cdecl gets(char* str)
char* gets(char* str)
{
con_init_console_dll();
return con_gets(str, 256);

View File

@ -0,0 +1,14 @@
#ifndef _STDIO_H
#define _STDIO_H
int putchar(int ch);
void puts(const char *str);
char* gets(char* str);
void putuint(int i);
void putint(int i);
void puthex(uint32_t i);
void print(char *format, va_list args);
void printf(char *text, ... );
#endif

View File

@ -1,4 +1,18 @@
unsigned long int __rnd_next = 1;
int rand(void) // RAND_MAX assumed to be 32767
{
__rnd_next = __rnd_next * 1103515245 + 12345;
return (unsigned int)(__rnd_next/65536) % 32768;
}
void srand(unsigned int seed)
{
__rnd_next = seed;
}
void *malloc(size_t size)
{
void *val;

View File

@ -0,0 +1,12 @@
#ifndef _STDLIB_H
#define _STDLIB_H
int rand(void);
void srand(unsigned int seed);
void *malloc(size_t size);
int free(void *mem);
void* realloc(void *mem, size_t size);
#endif

View File

@ -0,0 +1,23 @@
#ifndef _STRING_H
#define _STRING_H
void* memset(void *mem, int c, unsigned size);
void* memcpy(void *dst, const void *src, unsigned size);
int memcmp(const void* buf1, const void* buf2, int count);
char *strcat(char strDest[], char strSource[]);
int strcmp(const char* s1, const char* s2);
char *strcpy(char strDest[], const char strSource[]);
char* strncpy(char *strDest, const char *strSource, unsigned n);
int strlen(const char* string);
char* strchr(const char* string, int c);
char* strrchr(const char* string, int c);
void _itoa(int i, char *s);
void reverse(char s[]);
void itoa(int n, char s[]);
int atoi ( char *s );
#endif