/programs/emulator/kwine/bin/lib/msvcrt.dll |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/programs/emulator/kwine/bin/samples.zip |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/programs/emulator/kwine/kwine.asm |
---|
1,6 → 1,6 |
; ------------------------------------------------------------- ; |
; KWINE is a fork of program PELoad written by 0CodErr |
; author - rgimad |
; author of fork - rgimad |
; ------------------------------------------------------------- ; |
ORG 0 |
BITS 32 |
/programs/emulator/kwine/lib/conio.c |
---|
0,0 → 1,159 |
char* con_caption = "Console app"; |
//extern int __argc; |
//extern char** __argv; |
//extern char* __path; |
uint32_t *con_dll_ver; |
int __console_initdll_status = 0; |
char* con_dllname = "/sys/lib/console.obj"; |
typedef int (stdcall * con_gets2_callback)(int keycode, char** pstr, int* pn, int* ppos); |
void stdcall (*con_init)(uint32_t wnd_width, uint32_t wnd_height, uint32_t scr_width, uint32_t scr_height, const char* title) = 0; |
void stdcall (*con_exit)(int bCloseWindow) = 0; |
void stdcall (*con_set_title)(const char* title) = 0; |
void stdcall (*con_write_asciiz)(const char* str) = 0; |
void stdcall (*con_write_string)(const char* str, uint32_t length) = 0; |
int cdecl (*con_printf)(const char* format, ...) = 0; |
uint32_t stdcall (*con_get_flags)(void) = 0; |
uint32_t stdcall (*con_set_flags)(uint32_t new_flags) = 0; |
int stdcall (*con_get_font_height)(void) = 0; |
int stdcall (*con_get_cursor_height)(void) = 0; |
int stdcall (*con_set_cursor_height)(int new_height) = 0; |
int stdcall (*con_getch)(void) = 0; |
uint16_t stdcall (*con_getch2)(void) = 0; |
int stdcall (*con_kbhit)(void) = 0; |
char* stdcall (*con_gets)(char* str, int n) = 0; |
char* stdcall (*con_gets2)(con_gets2_callback callback, char* str, int n) = 0; |
void stdcall (*con_cls)() = 0; |
void stdcall (*con_get_cursor_pos)(int* px, int* py) = 0; |
void stdcall (*con_set_cursor_pos)(int x, int y) = 0; |
void *load_library(char *name) { |
void *exports; |
asm volatile ("int $0x40":"=a"(exports):"a"(68), "b"(19), "c"(name)); |
return exports; |
} |
void *getprocaddress(void *exports, char *name) |
{ |
if (exports == NULL) { return 0; } |
while (*(uint32_t*)exports != NULL) |
{ |
char *str1 = (char*)(*(uint32_t*)exports); |
if (strcmp(str1, name) == 0) |
{ |
void *ptr = *(uint32_t*)(exports + 4); |
// important for debug |
/*debug_board_write_string(name); |
char otv[16]; |
itoa(ptr, otv); |
debug_board_write_string(otv); |
debug_board_write_byte('\n');*/ |
return ptr; |
} |
exports += 8; |
} |
return 0; |
} |
// don't change order in this! linked by index |
char* con_imports[] = { |
"START", "version", "con_init", "con_write_asciiz", "con_write_string", |
"con_printf", "con_exit", "con_get_flags", "con_set_flags", "con_kbhit", |
"con_getch", "con_getch2", "con_gets", "con_gets2", "con_get_font_height", |
"con_get_cursor_height", "con_set_cursor_height", "con_cls", |
"con_get_cursor_pos", "con_set_cursor_pos", "con_set_title", |
(char*)0 |
}; |
void con_lib_link(void *exp, char** imports) |
{ |
con_dll_ver = getprocaddress(exp, imports[1]); |
con_init = getprocaddress(exp, imports[2]); |
con_write_asciiz = getprocaddress(exp, imports[3]); |
con_write_string = getprocaddress(exp, imports[4]); |
con_printf = getprocaddress(exp, imports[5]); |
con_exit = getprocaddress(exp, imports[6]); |
con_get_flags = getprocaddress(exp, imports[7]); |
con_set_flags = getprocaddress(exp, imports[8]); |
con_kbhit = getprocaddress(exp, imports[9]); |
con_getch = getprocaddress(exp, imports[10]); |
con_getch2 = getprocaddress(exp, imports[11]); |
con_gets = getprocaddress(exp, imports[12]); |
con_gets2 = getprocaddress(exp, imports[13]); |
con_get_font_height = getprocaddress(exp, imports[14]); |
con_get_cursor_height = getprocaddress(exp, imports[15]); |
con_set_cursor_height = getprocaddress(exp, imports[16]); |
con_cls = getprocaddress(exp, imports[17]); |
con_get_cursor_pos = getprocaddress(exp, imports[18]); |
con_set_cursor_pos = getprocaddress(exp, imports[19]); |
con_set_title = getprocaddress(exp, imports[20]); |
} |
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) |
/*works as con_init_console_dll, but call con_init with params*/ |
{ |
void *hDll; |
if (__console_initdll_status == 1) return 0; |
if((hDll = load_library(con_dllname)) == 0) |
{ |
debug_out_str("can't load lib\n"); |
return 1; |
} |
//debug_board_write_byte('I'); |
con_lib_link(hDll, con_imports); |
/*if (con_dll_ver != (uint32_t*)0x00020008) |
{ |
//debug_board_write_byte(48 + sizeof(KosExp)); |
//char otv[16]; |
//itoa(con_init, otv); |
//debug_board_write_string(otv); |
debug_board_write_string("con_dll_ver="); |
char otv[16]; |
itoa(con_dll_ver, otv); |
debug_board_write_string(otv); |
debug_board_write_byte('\n'); |
debug_board_write_string("con_init="); |
//char otv[16]; |
itoa(con_init, otv); |
debug_board_write_string(otv); |
debug_board_write_byte('\n'); |
debug_board_write_string("(wtf)"); |
}*/ |
con_init(wnd_width, wnd_height, scr_width, scr_height, title); |
__console_initdll_status = 1; |
return 0; |
} |
int con_init_console_dll(void) |
{ |
return con_init_console_dll_param(-1, -1, -1, -1, con_caption); |
} |
// -------------------------------------------------------------------- |
int cdecl _getch() |
{ |
con_init_console_dll(); |
return con_getch(); |
} |
int cdecl _kbhit() |
{ |
con_init_console_dll(); |
return con_kbhit(); |
} |
/programs/emulator/kwine/lib/msvcrt.dll.asm |
---|
1,6 → 1,6 |
; ------------------------------------------------------------- ; |
; KWINE is a fork of program PELoad written by 0CodErr |
; author - rgimad |
; author of fork - rgimad |
; ------------------------------------------------------------- ; |
GLOBAL EXPORTS |
section '.exprt' align 16 |
/programs/emulator/kwine/lib/msvcrt.dll.c |
---|
0,0 → 1,67 |
// ------------------------------------------------------------- |
// KWINE is a fork of program PELoad written by 0CodErr |
// author of fork - rgimad |
//------------------------------------------------------------- |
#include "stddef.h" |
#include <stdarg.h> |
#include "msvcrt.dll.h" |
#include "string.c" |
//#include "dlfcn.c" |
#include "conio.c" |
#include "stdio.c" |
#include "stdlib.c" |
typedef struct |
{ |
char *name; |
void *f; |
} export_t; |
// conio |
const char sz__getch[] = "_getch"; |
const char sz__kbhit[] = "_kbhit"; |
// stdio |
const char sz_printf[] = "printf"; |
const char sz_puts[] = "puts"; |
const char sz_gets[] = "gets"; |
//string |
const char sz_strlen[] = "strlen"; |
const char sz_strcmp[] = "strcmp"; |
const char sz_strcat[] = "strcat"; |
// stdlib |
const char sz_malloc[] = "malloc"; |
const char sz_free[] = "free"; |
const char sz_realloc[] = "realloc"; |
//const char sz_[] = ""; |
//uint32_t EXPORTS[] __asm__("EXPORTS") = |
export_t EXPORTS[] = |
{ |
{sz__getch, (void*)_getch}, |
{sz__kbhit, (void*)_kbhit}, |
{sz_printf, (void*)printf}, |
{sz_puts, (void*)puts}, |
{sz_gets, (void*)gets}, |
{sz_strlen, (void*)strlen}, |
{sz_strcmp, (void*)strcmp}, |
{sz_strcat, (void*)strcat}, |
{sz_malloc, (void*)malloc}, |
{sz_free, (void*)free}, |
{sz_realloc, (void*)realloc}, |
{NULL, NULL}, |
}; |
int lib_init() |
{ |
con_init_console_dll(); |
} |
/programs/emulator/kwine/lib/msvcrt.dll.h |
---|
0,0 → 1,36 |
// ------------------------------------------------------------- |
// KWINE is a fork of program PELoad written by 0CodErr |
// author of fork - rgimad |
//------------------------------------------------------------- |
#ifndef MSVCRT_DLL_H |
#define MSVCRT_DLL_H |
#define NULL ((void*)0) |
#define cdecl __attribute__ ((cdecl)) |
#define stdcall __attribute__ ((stdcall)) |
//#define cdecl __cdecl |
//#define stdcall __stdcall |
static inline void debug_board_write_byte(const char ch){ |
__asm__ __volatile__( |
"int $0x40" |
: |
:"a"(63), "b"(1), "c"(ch)); |
} |
static inline void debug_board_write_string(char *str){ |
char ch; |
while (ch = *(str++)) |
{ |
__asm__ __volatile__( |
"int $0x40" |
: |
:"a"(63), "b"(1), "c"(ch)); |
} |
} |
// |
#endif |
/programs/emulator/kwine/lib/stddef.h |
---|
0,0 → 1,27 |
#ifndef _STDDEF_H |
#define _STDDEF_H |
typedef __SIZE_TYPE__ size_t; |
typedef __PTRDIFF_TYPE__ ssize_t; |
typedef __WCHAR_TYPE__ wchar_t; |
typedef __PTRDIFF_TYPE__ ptrdiff_t; |
typedef __PTRDIFF_TYPE__ intptr_t; |
typedef __SIZE_TYPE__ uintptr_t; |
#ifndef __int8_t_defined |
#define __int8_t_defined |
typedef signed char int8_t; |
typedef signed short int int16_t; |
typedef signed int int32_t; |
typedef signed long long int int64_t; |
typedef unsigned char uint8_t; |
typedef unsigned short int uint16_t; |
typedef unsigned int uint32_t; |
typedef unsigned long long int uint64_t; |
#endif |
#ifndef NULL |
#define NULL ((void*)0) |
#endif |
#endif // |
/programs/emulator/kwine/lib/stdio.c |
---|
0,0 → 1,124 |
int putchar(int ch) |
{ |
con_init_console_dll(); |
char str[2]; |
str[0] = ch; |
str[1] = 0; |
con_write_asciiz(str); |
return ch; |
} |
void cdecl puts(const char *str) |
{ |
con_init_console_dll(); |
con_write_asciiz(str); |
} |
char* cdecl gets(char* str) |
{ |
con_init_console_dll(); |
return con_gets(str, 256); |
} |
void putuint(int i) |
{ |
unsigned int n, d = 1000000000; |
char str[255]; |
unsigned int dec_index = 0; |
while( ( i/d == 0 ) && ( d >= 10 ) ) d /= 10; |
n = i; |
while(d >= 10) |
{ |
str[dec_index++] = ((char)((int)'0' + n/d)); |
n = n % d; |
d /= 10; |
} |
str[dec_index++] = ((char)((int)'0' + n)); |
str[dec_index] = 0; |
puts(str); |
} |
void putint(int i) |
{ |
if(i >= 0) |
{ |
putuint(i); |
} else { |
putchar('-'); |
putuint(-i); |
} |
} |
void puthex(uint32_t i) |
{ |
const unsigned char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; |
unsigned int n, d = 0x10000000; |
puts("0x"); |
while((i / d == 0) && (d >= 0x10)) d /= 0x10; |
n = i; |
while( d >= 0xF ) |
{ |
putchar(hex[n/d]); |
n = n % d; |
d /= 0x10; |
} |
putchar(hex[n]); |
} |
void print(char *format, va_list args) |
{ |
int i = 0; |
char *string; |
while (format[i]) |
{ |
if (format[i] == '%') |
{ |
i++; |
switch (format[i]) |
{ |
case 's': |
string = va_arg(args, char*); |
puts(string); |
break; |
case 'c': |
// To-Do: fix this! "warning: cast to pointer from integer of different size" |
putchar(va_arg(args, int)); |
break; |
case 'd': |
putint(va_arg(args, int)); |
break; |
case 'i': |
putint(va_arg(args, int)); |
break; |
case 'u': |
putuint(va_arg(args, unsigned int)); |
break; |
case 'x': |
puthex(va_arg(args, uint32_t)); |
break; |
default: |
putchar(format[i]); |
} |
} else { |
putchar(format[i]); |
} |
i++; |
}//endwhile |
} |
void printf(char *text, ... ) |
{ |
va_list args; |
// find the first argument |
va_start(args, text); |
// pass print the output handle the format text and the first argument |
print(text, args); |
} |
/programs/emulator/kwine/lib/stdlib.c |
---|
0,0 → 1,32 |
void *malloc(size_t size) |
{ |
void *val; |
__asm__ __volatile__( |
"int $0x40" |
:"=a"(val) |
:"a"(68),"b"(12),"c"(size)); |
return val; |
} |
int free(void *mem) |
{ |
int val; |
__asm__ __volatile__( |
"int $0x40" |
:"=a"(val) |
:"a"(68),"b"(13),"c"(mem)); |
return val; |
} |
void* realloc(void *mem, size_t size) |
{ |
void *val; |
__asm__ __volatile__( |
"int $0x40" |
:"=a"(val) |
:"a"(68),"b"(20),"c"(size),"d"(mem) |
:"memory"); |
return val; |
}; |
/programs/emulator/kwine/lib/string.c |
---|
0,0 → 1,194 |
#ifndef NULL |
#define NULL ((void*)0) |
#endif |
void* memset(void *mem, int c, unsigned size) |
{ |
unsigned i; |
for ( i = 0; i < size; i++ ) |
*((char *)mem+i) = (char) c; |
return NULL; |
} |
void* memcpy(void *dst, const void *src, unsigned size) |
{ |
unsigned i; |
for ( i = 0; i < size; i++) |
*(char *)(dst+i) = *(char *)(src+i); |
return NULL; |
} |
int memcmp(const void* buf1, const void* buf2, int count) |
{ |
int i; |
for (i=0;i<count;i++) |
{ |
if (*(unsigned char*)buf1<*(unsigned char*)buf2) |
return -1; |
if (*(unsigned char*)buf1>*(unsigned char*)buf2) |
return 1; |
} |
return 0; |
} |
char *strcat(char strDest[], char strSource[]) |
{ |
int i, j; |
i = j = 0; |
while (strDest[i] != '\0') i++; |
while ((strDest[i++] = strSource[j++]) != '\0'); |
return strDest; |
} |
/*int strcmp(char* string1,char* string2) |
{ |
while (1) |
{ |
if (*string1<*string2) |
return -1; |
if (*string1>*string2) |
return 1; |
if (*string1=='\0') |
return 0; |
string1++; |
string2++; |
} |
}*/ |
int strcmp(const char* s1, const char* s2) |
{ |
while(*s1 && (*s1==*s2)) |
s1++,s2++; |
return *(const unsigned char*)s1-*(const unsigned char*)s2; |
} |
char *strcpy(char strDest[], const char strSource[]) |
{ |
unsigned i; |
i = 0; |
while ((strDest[i] = strSource[i]) != '\0') i++; |
return strDest; |
} |
char* strncpy(char *strDest, const char *strSource, unsigned n) |
{ |
unsigned i; |
if (! n ) |
return strDest; |
i = 0; |
while ((strDest[i] = strSource[i]) != '\0') |
if ( (n-1) == i ) |
break; |
else |
i++; |
return strDest; |
} |
int strlen(const char* string) |
{ |
int i; |
i=0; |
while (*string++) i++; |
return i; |
} |
char* strchr(const char* string, int c) |
{ |
while (*string) |
{ |
if (*string==c) |
return (char*)string; |
string++; |
} |
return (char*)0; |
} |
char* strrchr(const char* string, int c) |
{ |
char* last_found; |
while (*string) |
{ |
if (*string==c) |
{ |
last_found = (char*)string; |
} |
string++; |
} |
return last_found; |
} |
void _itoa(int i, char *s) |
{ |
int a, b, c, d; |
a = (i - i%1000)/1000; |
b = (i - i%100)/100 - a*10; |
c = (i - i%10)/10 - a*100 - b*10; |
d = i%10; |
s[0] = a + '0'; |
s[1] = b + '0'; |
s[2] = c + '0'; |
s[3] = d + '0'; |
s[4] = 0; |
} |
/* reverse: ïåðåâîðà÷èâàåì ñòðîêó s íà ìåñòå */ |
void reverse(char s[]) |
{ |
int i, j; |
char c; |
for (i = 0, j = strlen(s)-1; i<j; i++, j--) { |
c = s[i]; |
s[i] = s[j]; |
s[j] = c; |
} |
} |
/* itoa: êîíâåðòèðóåì n â ñèìâîëû â s */ |
void itoa(int n, char s[]) |
{ |
int i, sign; |
if ((sign = n) < 0) |
n = -n; |
i = 0; |
do { |
s[i++] = n % 10 + '0'; |
} while ((n /= 10) > 0); |
if (sign < 0) |
s[i++] = '-'; |
s[i] = '\0'; |
reverse(s); |
} |
int atoi ( char *s ) |
{ |
int i, n; |
n = 0; |
for ( i = 0; s[i]!= '\0'; ++i) |
if ((s[i]<'0') || (s[i]>'9')) |
return 0; |
else |
n = 10 * n + s[i] - '0'; |
return n; |
} |
/programs/emulator/kwine/make.bat |
---|
1,8 → 1,14 |
@echo off |
set NASM="nasm\nasm.exe" |
%NASM% -f coff "lib\msvcrt.dll.asm" -o "..\lib\msvcrt.dll" |
strip --strip-debug "../lib/msvcrt.dll" |
rem set GCC="D:\MinGW_32_bit\bin\gcc.exe" |
set GCC="C:\MinGW\msys\1.0\home\autobuild\tools\win32\bin\kos32-gcc.exe" |
rem %NASM% -f coff "lib\msvcrt.dll.asm" -o "..\lib\msvcrt.dll" |
rem strip --strip-debug "../lib/msvcrt.dll" |
rem %GCC% -fno-ident -nostdlib -fno-builtin -c -std=gnu99 -o ..\lib\msvcrt.dll lib\msvcrt.dll.c |
%GCC% -fno-ident -fno-builtin -O0 -c -o ..\lib\msvcrt.dll lib\msvcrt.dll.c |
%NASM% -f coff "lib/kernel32.dll.asm" -o "../lib/kernel32.dll" |
strip --strip-debug "../lib/kernel32.dll" |
/programs/emulator/kwine/readme.txt |
---|
1,8 → 1,15 |
kwine - kolibri wine. |
KWINE v0.0.2 |
Developers: |
- 0CodErr founder of project (PEload) |
- rgimad some improvements |
- 0CodErr founder of project PEload |
- rgimad author of KWINE - fork of PEload |
Topic: |
http://board.kolibrios.org/viewtopic.php?f=9&t=2318&p=74314#p74308 |
How to use: |
- in bin folder there is all neccesary files: |
kwine, lib/kernel32.dll, lib/msvcrt.dll |
- usage: |
kwine mysuperexefile.exe |
Changelog: |
- msvcrt.dll rewritten in c |
- added malloc, free, realloc, strcmp, strcat, strlen, printf to msvcrt.dll |