Compare commits

...

11 Commits

Author SHA1 Message Date
40914a33b6 Remove broken unused and unfinished apps and libs
- TEAtool: A useless utility for encryption with the TEA algorithm,
  written for fun by me during my school years;
- GameHack: not a working prototype of a program like Cheat Engine;
- microtar: port of a portable library with a reduced functionality
  for working with TAR in C that is not used

Signed-off-by: Max Logaev <maxlogaev@proton.me>
2026-02-22 00:09:36 +03:00
Igor Shutrov
668fd4deeb ftpd: add ip to first message 2026-02-17 22:08:04 +05:00
dd9a7b92d8 libc.obj: Fixed build skip with TCC build enabled
Signed-off-by: Max Logaev <maxlogaev@proton.me>
2026-01-28 17:22:54 +03:00
Igor Shutrov
1173ca7b26 Cedit: Improve search panel (#313)
Улучшения для Cedit в Панели поиска:
- Добавлен поиск следующего фрагмента текста по нажатию Enter
- Добавлен обратный переход по полям ввода в Панели поиска по Shift-Tab

Co-authored-by: Igor Shutrov <igor@shutrov.ru>
Reviewed-on: KolibriOS/kolibrios#313
Reviewed-by: Burer <burer@noreply.localhost>
Co-authored-by: Igor Shutrov <kolibridev@inbox.ru>
Co-committed-by: Igor Shutrov <kolibridev@inbox.ru>
2026-01-18 16:28:46 +00:00
ccd0c183ec mtdbg: Backtrace implemented (#315)
Added support for backtrace/stacktrace output.
This is useful for high-level languages ​​like C and Oberon07.
If a debug file is provided, searches for the nearest debug symbol.

Reviewed-on: KolibriOS/kolibrios#315
Reviewed-by: Mikhail Frolov <mixa.frolov2003@gmail.com>
Reviewed-by: Burer <burer@noreply.localhost>
2026-01-18 13:08:02 +00:00
f065cc6e69 mtdbg: Fixed magic cmd flags
Signed-off-by: Max Logaev <maxlogaev@proton.me>
2026-01-11 13:35:58 +00:00
f1b99bad84 libc.obj: Added missing strpbrk() to EXPORTS (#310)
Reviewed-on: KolibriOS/kolibrios#310
Reviewed-by: Max Logaev <maxlogaev@proton.me>
Co-authored-by: Егор <velikiydolbayeb@gmail.com>
Co-committed-by: Егор <velikiydolbayeb@gmail.com>
2026-01-10 23:27:51 +00:00
igorsh
c580d4ac5b ftpd: Add XPWD and XCWD commands (#309)
Добавлены команды XPWD и XCWD, дублирующие PWD и CWD

Co-authored-by: Igor Shutrov <igor@shutrov.ru>
Co-authored-by: Burer <burer@kolibrios.org>
Reviewed-on: KolibriOS/kolibrios#309
Reviewed-by: Burer <burer@noreply.localhost>
Co-authored-by: igorsh <kolibridev@inbox.ru>
Co-committed-by: igorsh <kolibridev@inbox.ru>
2026-01-08 17:03:23 +00:00
Igor Shutrov
17c33521c3 ftpd: Fix typo 2026-01-07 19:41:28 +00:00
Igor Shutrov
f6395c9501 ftpd: Fix typo 2026-01-07 19:41:28 +00:00
Igor Shutrov
000288ce8b ftpd: Fix RETR for small and empty files 2026-01-06 18:20:39 +00:00
25 changed files with 308 additions and 1551 deletions

View File

@@ -722,6 +722,7 @@ tup.append_table(img_files, {
{"SHELL", VAR_PROGS .. "/system/shell/shell"},
{"GAMES/DINO", VAR_PROGS .. "/games/dino/dino"},
{"GAMES/FLPYBIRD", VAR_PROGS .. "/games/flpybird/flpybird"},
{"LIB/LIBC.OBJ", VAR_PROGS .. "/develop/ktcc/trunk/libc.obj/source/libc.obj"},
})
tup.append_table(extra_files, {
{"kolibrios/utils/thashview", VAR_PROGS .. "/other/TinyHashView/thashview"},
@@ -730,7 +731,6 @@ tup.append_table(extra_files, {
{"kolibrios/develop/TinyBasic/TinyBasic", VAR_PROGS .. "/develop/tinybasic-1.0.4/tinybasic"},
{"kolibrios/develop/TinyBasic/bas/", SRC_PROGS .. "/develop/tinybasic-1.0.4/bas/*"},
{"kolibrios/develop/TinyBasic/TinyBasic.man", SRC_PROGS .. "/develop/tinybasic-1.0.4/doc/tinybasic.man"},
-- {"kolibrios/utils/teatool", VAR_PROGS .. "/other/TEAtool/teatool"},
{"kolibrios/utils/passwordgen", VAR_PROGS .. "/other/PasswordGen/passwordgen"},
{"kolibrios/utils/kruler", VAR_PROGS .. "/other/kruler/kruler"},
{"kolibrios/media/qr_tool", SRC_PROGS .. "/media/qr_tool/qr_tool"},
@@ -745,9 +745,7 @@ if tup.getconfig('NO_GCC') ~= 'full' then
tup.append_table(img_files, {
{"GAMES/REVERSI", VAR_PROGS .. "/games/reversi/reversi"},
{"LIB/BASE64.OBJ", VAR_PROGS .. "/develop/libraries/base64/base64.obj"},
{"LIB/LIBC.OBJ", VAR_PROGS .. "/develop/ktcc/trunk/libc.obj/source/libc.obj"},
{"LIB/ICONV.OBJ", VAR_PROGS .. "/develop/libraries/iconv/iconv.obj"},
-- {"LIB/MTAR.OBJ", VAR_PROGS .. "/develop/libraries/microtar/mtar.obj"},
})
tup.append_table(extra_files, {
-- {"kolibrios/3D/cubeline", VAR_PROGS .. "/demos/cubeline/trunk/cubeline"},

View File

@@ -47,3 +47,9 @@
перемещение по тексту:
(ctrl+)Home, (ctrl+)End, (ctrl+)PageUp, (ctrl+)PageDown
ctrl+Left, ctrl+Right
перемещение в панели поиска:
Tab к следующему полю ввода
Shift-Tab к предыдущему полю ввода
Enter поиск следующего вхождения

View File

@@ -28,7 +28,7 @@ IMPORT
RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar;
CONST
HEADER = "CEdit (30-apr-2025)";
HEADER = "CEdit (11-jan-2026)";
ShellFilter = "";
EditFilter = "sh|inc|txt|asm|ob07|c|cpp|h|pas|pp|lua|ini|json";
@@ -1750,7 +1750,15 @@ BEGIN
ELSE
IF EditBox_Focus(FindEdit) THEN
IF keyCode = 15 THEN (* Tab *)
SetFocus(ReplaceEdit, TRUE)
IF shift THEN
SetFocus(GotoEdit, TRUE)
ELSE
SetFocus(ReplaceEdit, TRUE)
END
ELSIF keyCode = 28 THEN (* Enter *)
IF searchOpened & (searchText # "") THEN
notFound := ~T.findNext(text, BKW.value)
END
ELSE
EB.key(FindEdit, key);
EditBox_Get(FindEdit, new_searchText);
@@ -1761,14 +1769,26 @@ BEGIN
END
ELSIF EditBox_Focus(ReplaceEdit) THEN
IF keyCode = 15 THEN (* Tab *)
SetFocus(GotoEdit, TRUE)
IF shift THEN
SetFocus(FindEdit, TRUE)
ELSE
SetFocus(GotoEdit, TRUE)
END
ELSIF keyCode = 28 THEN (* Enter *)
IF searchOpened & (searchText # "") THEN
notFound := ~T.findNext(text, BKW.value)
END
ELSE
EB.key(ReplaceEdit, key);
EditBox_Get(ReplaceEdit, replaceText)
END
ELSIF EditBox_Focus(GotoEdit) THEN
IF keyCode = 15 THEN (* Tab *)
SetFocus(FindEdit, TRUE)
IF shift THEN
SetFocus(ReplaceEdit, TRUE)
ELSE
SetFocus(FindEdit, TRUE)
END
ELSE
IF (key DIV 256) MOD 256 = 13 THEN
goto

View File

@@ -204,6 +204,7 @@ ksys_dll_t EXPORTS[] = {
{ "strstr", &strstr },
{ "strtok", &strtok },
{ "strxfrm", &strxfrm },
{ "strpbrk", &strpbrk },
{ "__errno", &__errno },
{ "closedir", &closedir },
{ "opendir", &opendir },

View File

@@ -1,19 +0,0 @@
Copyright (c) 2017 rxi
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,99 +0,0 @@
# microtar
A lightweight tar library written in ANSI C
## Basic Usage
The library consists of `microtar.c` and `microtar.h`. These two files can be
dropped into an existing project and compiled along with it.
#### Reading
```c
mtar_t tar;
mtar_header_t h;
char *p;
/* Open archive for reading */
mtar_open(&tar, "test.tar", "r");
/* Print all file names and sizes */
while ( (mtar_read_header(&tar, &h)) != MTAR_ENULLRECORD ) {
printf("%s (%d bytes)\n", h.name, h.size);
mtar_next(&tar);
}
/* Load and print contents of file "test.txt" */
mtar_find(&tar, "test.txt", &h);
p = calloc(1, h.size + 1);
mtar_read_data(&tar, p, h.size);
printf("%s", p);
free(p);
/* Close archive */
mtar_close(&tar);
```
#### Writing
```c
mtar_t tar;
const char *str1 = "Hello world";
const char *str2 = "Goodbye world";
/* Open archive for writing */
mtar_open(&tar, "test.tar", "w");
/* Write strings to files `test1.txt` and `test2.txt` */
mtar_write_file_header(&tar, "test1.txt", strlen(str1));
mtar_write_data(&tar, str1, strlen(str1));
mtar_write_file_header(&tar, "test2.txt", strlen(str2));
mtar_write_data(&tar, str2, strlen(str2));
/* Finalize -- this needs to be the last thing done before closing */
mtar_finalize(&tar);
/* Close archive */
mtar_close(&tar);
```
## Error handling
All functions which return an `int` will return `MTAR_ESUCCESS` if the operation
is successful. If an error occurs an error value less-than-zero will be
returned; this value can be passed to the function `mtar_strerror()` to get its
corresponding error string.
## Wrapping a stream
If you want to read or write from something other than a file, the `mtar_t`
struct can be manually initialized with your own callback functions and a
`stream` pointer.
All callback functions are passed a pointer to the `mtar_t` struct as their
first argument. They should return `MTAR_ESUCCESS` if the operation succeeds
without an error, or an integer below zero if an error occurs.
After the `stream` field has been set, all required callbacks have been set and
all unused fields have been zeroset the `mtar_t` struct can be safely used with
the microtar functions. `mtar_open` *should not* be called if the `mtar_t`
struct was initialized manually.
#### Reading
The following callbacks should be set for reading an archive from a stream:
Name | Arguments | Description
--------|------------------------------------------|---------------------------
`read` | `mtar_t *tar, void *data, unsigned size` | Read data from the stream
`seek` | `mtar_t *tar, unsigned pos` | Set the position indicator
`close` | `mtar_t *tar` | Close the stream
#### Writing
The following callbacks should be set for writing an archive to a stream:
Name | Arguments | Description
--------|------------------------------------------------|---------------------
`write` | `mtar_t *tar, const void *data, unsigned size` | Write data to the stream
## License
This library is free software; you can redistribute it and/or modify it under
the terms of the MIT license. See [LICENSE](LICENSE) for details.

View File

@@ -1,8 +0,0 @@
if tup.getconfig("NO_GCC") ~= "" then return end
HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../../" or tup.getconfig("HELPERDIR")
tup.include(HELPERDIR .. "/use_gcc.lua")
CFLAGS = " -c -w -nostdinc -DGNUC -DMTAR_OBJ -Os -fno-common -fno-builtin -fno-leading-underscore -fno-pie"
INCLUDES = " -I../include -I../../ktcc/trunk/libc.obj/include"
tup.rule("microtar.c", "kos32-gcc" .. CFLAGS .. INCLUDES .. " -o %o %f " .. tup.getconfig("KPACK_CMD"), "mtar.obj")

View File

@@ -1,78 +0,0 @@
format binary as "kex"
use32
org 0x0
db 'MENUET01'
dd 0x01
dd START
dd IM_END
dd MEM
dd MEM
dd 0
dd 0
include '../../../../macros.inc'
include '../../../../proc32.inc'
include '../../../../KOSfuncs.inc'
include '../../../../dll.inc'
include '../mtar.inc'
;include '../../../../debug-fdo.inc'
;__DEBUG__ = 1
;__DEBUG_LEVEL__ = 2
START:
stdcall dll.Load, @IMPORT ; Имортироуем функции из mtar.obj
test eax, eax
jnz exit
ccall [mtar_init] ; Инициализируем библиотеку (на самом деле подгружается libc.obj
ccall [mtar_open], tar, tar_fname, tar_fmode ; Открываем для чтения файл 'test.tar'
; DEBUGF 2, "%d", eax
print_next:
ccall [mtar_read_header], tar, header ; Читаем заголовок
cmp eax, MTAR_ENULLRECORD ; Если заголовок не был прочитан (return -7) выходим из цикла
je exit
ccall [printf], format_str, header+mtar_header_t.name, dword[header+mtar_header_t.size] ; Выводим в консоль имя файла и размер в байтах
ccall [mtar_next], tar ; Переходим к следующему заголовку
jmp print_next ; прыгаем в начало цикла
exit:
ccall [mtar_close], tar ; Закрываем 'test.tar'
mcall SF_TERMINATE_PROCESS ; Выходим из программы
; data
tar_fname db 'test.tar', 0
tar_fmode db 'r', 0
tar rb sizeof.mtar_t
header rb sizeof.mtar_header_t
format_str db '%-10s (%-4d bytes)', 0x0A,0
align 4
@IMPORT:
library mtar, 'mtar.obj', libc , 'libc.obj'
import mtar, \
mtar_init, 'mtar_init', \
mtar_open, 'mtar_open', \
mtar_next, 'mtar_next', \
mtar_strerror, 'mtar_strerror', \
mtar_read_header, 'mtar_read_header', \
mtar_write_data, 'mtar_write_data', \
mtar_finalize, 'mtar_finalize', \
mtar_close, 'mtar_close'
import libc, \
printf, 'printf'
IM_END:
align 4
rb 4096 ; stack
MEM:

View File

@@ -1,70 +0,0 @@
format binary as "kex"
use32
org 0x0
db 'MENUET01'
dd 0x01
dd START
dd IM_END
dd MEM
dd MEM
dd 0
dd 0
include '../../../../macros.inc'
include '../../../../proc32.inc'
include '../../../../KOSfuncs.inc'
include '../../../../dll.inc'
include '../mtar.inc'
;include '../../../../debug-fdo.inc'
;__DEBUG__ = 1
;__DEBUG_LEVEL__ = 2
START:
stdcall dll.Load, @IMPORT ; Имортироуем функции из mtar.obj
test eax, eax
jnz exit
ccall [mtar_init] ; Инициализируем библиотеку (на самом деле подгружается libc.obj
ccall [mtar_open], tar, tar_fname, tar_fmode ; Создаём новый файл 'test.tar'
ccall [mtar_write_file_header], tar, test1_txt , str1_len ; Создаём внутри 'test.tar' пустрой файл 'test1.txt'
ccall [mtar_write_data], tar, str1, str1_len ; Записываем данныев в этот файл
ccall [mtar_finalize], tar ; Указываем что больше с tar работать не будем
ccall [mtar_close], tar ; Закрываем 'test.tar'
exit:
mcall SF_TERMINATE_PROCESS ; Выходим из программы
; data
str1 db 'Hello world!', 0
str1_len = $ - str1
str2 db 'Goodbye world!', 0
tar_fname db 'test.tar', 0
tar_fmode db 'w', 0
test1_txt db 'test1.txt', 0
tar rb 32
align 4
@IMPORT:
library mtar, 'mtar.obj'
import mtar, \
mtar_init, 'mtar_init', \
mtar_open, 'mtar_open', \
mtar_write_file_header, 'mtar_write_file_header', \
mtar_write_data, 'mtar_write_data', \
mtar_finalize, 'mtar_finalize', \
mtar_close, 'mtar_close'
IM_END:
align 4
rb 4096 ; stack
MEM:

View File

@@ -1,450 +0,0 @@
/*
* Copyright (c) 2017 rxi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <sys/ksys.h>
#include "microtar.h"
typedef struct {
char name[100];
char mode[8];
char owner[8];
char group[8];
char size[12];
char mtime[12];
char checksum[8];
char type;
char linkname[100];
char _padding[255];
} mtar_raw_header_t;
static void * mtar_memset( void * s, int c, size_t n ){
unsigned char * p = ( unsigned char * ) s;
while ( n-- ){
*p++ = ( unsigned char ) c;
}
return s;
}
#ifdef MTAR_OBJ
// All pointers was changed for compatible to latest version tcc and the libc.obj headers
size_t (*_fread)(void *restrict, size_t size, size_t count, FILE *restrict)=NULL;
size_t (*_fwrite)(const void *restrict, size_t size, size_t count, FILE *restrict)=NULL;
int (*_fclose)(FILE *)=NULL;
FILE* (*_fopen)(const char *restrict, const char *restrict)=NULL;
int (*_fseek)(FILE *, long, int)=NULL;
long (*_ftell)(FILE *)=NULL;
int (*_sprintf)(char* buffer, const char* format, ...)=NULL;
int (*_sscanf)(const char*, const char *restrict, ...)=NULL;
int (*_strcmp)(const char * s1, const char* s2)=NULL;
char* (*_strchr)(const char* s, int c)=NULL;
char* (*_strcpy)(char* s1, const char* s2)=NULL;
#endif
static unsigned round_up(unsigned n, unsigned incr) {
return n + (incr - n % incr) % incr;
}
static unsigned checksum(const mtar_raw_header_t* rh) {
unsigned i;
unsigned char *p = (unsigned char*) rh;
unsigned res = 256;
for (i = 0; i < offsetof(mtar_raw_header_t, checksum); i++) {
res += p[i];
}
for (i = offsetof(mtar_raw_header_t, type); i < sizeof(*rh); i++) {
res += p[i];
}
return res;
}
static int tread(mtar_t *tar, void *data, unsigned size) {
int err = tar->read(tar, data, size);
tar->pos += size;
return err;
}
static int twrite(mtar_t *tar, const void *data, unsigned size) {
int err = tar->write(tar, data, size);
tar->pos += size;
return err;
}
static int write_null_bytes(mtar_t *tar, int n) {
int i, err;
char nul = '\0';
for (i = 0; i < n; i++) {
err = twrite(tar, &nul, 1);
if (err) {
return err;
}
}
return MTAR_ESUCCESS;
}
static int raw_to_header(mtar_header_t *h, const mtar_raw_header_t *rh) {
unsigned chksum1, chksum2;
/* If the checksum starts with a null byte we assume the record is NULL */
if (*rh->checksum == '\0') {
return MTAR_ENULLRECORD;
}
/* Build and compare checksum */
chksum1 = checksum(rh);
_sscanf(rh->checksum, "%o", &chksum2);
if (chksum1 != chksum2) {
return MTAR_EBADCHKSUM;
}
/* Load raw header into header */
_sscanf(rh->mode, "%o", &h->mode);
_sscanf(rh->owner, "%o", &h->owner);
_sscanf(rh->size, "%o", &h->size);
_sscanf(rh->mtime, "%o", &h->mtime);
h->type = rh->type;
_strcpy(h->name, rh->name);
_strcpy(h->linkname, rh->linkname);
return MTAR_ESUCCESS;
}
static int header_to_raw(mtar_raw_header_t *rh, const mtar_header_t *h) {
unsigned chksum;
/* Load header into raw header */
mtar_memset(rh, 0, sizeof(*rh));
_sprintf(rh->mode, "%o", h->mode);
_sprintf(rh->owner, "%o", h->owner);
_sprintf(rh->size, "%o", h->size);
_sprintf(rh->mtime, "%o", h->mtime);
rh->type = h->type ? h->type : MTAR_TREG;
_strcpy(rh->name, h->name);
_strcpy(rh->linkname, h->linkname);
/* Calculate and write checksum */
chksum = checksum(rh);
_sprintf(rh->checksum, "%06o", chksum);
rh->checksum[7] = ' ';
return MTAR_ESUCCESS;
}
const char* mtar_strerror(int err) {
switch (err) {
case MTAR_ESUCCESS : return "success";
case MTAR_EFAILURE : return "failure";
case MTAR_EOPENFAIL : return "could not open";
case MTAR_EREADFAIL : return "could not read";
case MTAR_EWRITEFAIL : return "could not write";
case MTAR_ESEEKFAIL : return "could not seek";
case MTAR_EBADCHKSUM : return "bad checksum";
case MTAR_ENULLRECORD : return "null record";
case MTAR_ENOTFOUND : return "file not found";
}
return "unknown error";
}
static int file_write(mtar_t *tar, const void *data, unsigned size) {
unsigned res = _fwrite(data, 1, size, tar->stream);
return (res == size) ? MTAR_ESUCCESS : MTAR_EWRITEFAIL;
}
static int file_read(mtar_t *tar, void *data, unsigned size) {
unsigned res = _fread(data, 1, size, tar->stream);
return (res == size) ? MTAR_ESUCCESS : MTAR_EREADFAIL;
}
static int file_seek(mtar_t *tar, unsigned offset) {
int res = _fseek(tar->stream, offset, SEEK_SET);
return (res == 0) ? MTAR_ESUCCESS : MTAR_ESEEKFAIL;
}
static int file_close(mtar_t *tar) {
_fclose(tar->stream);
return MTAR_ESUCCESS;
}
int mtar_open(mtar_t *tar, const char *filename, const char *mode) {
int err;
mtar_header_t h;
/* Init tar struct and functions */
mtar_memset(tar, 0, sizeof(*tar));
tar->write = file_write;
tar->read = file_read;
tar->seek = file_seek;
tar->close = file_close;
/* Assure mode is always binary */
if ( _strchr(mode, 'r') ) mode = "rb";
if ( _strchr(mode, 'w') ) mode = "wb";
if ( _strchr(mode, 'a') ) mode = "ab";
/* Open file */
tar->stream = _fopen(filename, mode);
if (!tar->stream) {
return MTAR_EOPENFAIL;
}
/* Read first header to check it is valid if mode is `r` */
if (*mode == 'r') {
err = mtar_read_header(tar, &h);
if (err != MTAR_ESUCCESS) {
mtar_close(tar);
return err;
}
}
/* Return ok */
return MTAR_ESUCCESS;
}
int mtar_close(mtar_t *tar) {
return tar->close(tar);
}
int mtar_seek(mtar_t *tar, unsigned pos) {
int err = tar->seek(tar, pos);
tar->pos = pos;
return err;
}
int mtar_rewind(mtar_t *tar) {
tar->remaining_data = 0;
tar->last_header = 0;
return mtar_seek(tar, 0);
}
int mtar_next(mtar_t *tar) {
int err, n;
mtar_header_t h;
/* Load header */
err = mtar_read_header(tar, &h);
if (err) {
return err;
}
/* Seek to next record */
n = round_up(h.size, 512) + sizeof(mtar_raw_header_t);
return mtar_seek(tar, tar->pos + n);
}
int mtar_find(mtar_t *tar, const char *name, mtar_header_t *h) {
int err;
mtar_header_t header;
/* Start at beginning */
err = mtar_rewind(tar);
if (err) {
return err;
}
/* Iterate all files until we hit an error or find the file */
while ( (err = mtar_read_header(tar, &header)) == MTAR_ESUCCESS ) {
if ( !_strcmp(header.name, name) ) {
if (h) {
*h = header;
}
return MTAR_ESUCCESS;
}
mtar_next(tar);
}
/* Return error */
if (err == MTAR_ENULLRECORD) {
err = MTAR_ENOTFOUND;
}
return err;
}
int mtar_read_header(mtar_t *tar, mtar_header_t *h) {
int err;
mtar_raw_header_t rh;
/* Save header position */
tar->last_header = tar->pos;
/* Read raw header */
err = tread(tar, &rh, sizeof(rh));
if (err) {
return err;
}
/* Seek back to start of header */
err = mtar_seek(tar, tar->last_header);
if (err) {
return err;
}
/* Load raw header into header struct and return */
return raw_to_header(h, &rh);
}
int mtar_read_data(mtar_t *tar, void *ptr, unsigned size) {
int err;
/* If we have no remaining data then this is the first read, we get the size,
* set the remaining data and seek to the beginning of the data */
if (tar->remaining_data == 0) {
mtar_header_t h;
/* Read header */
err = mtar_read_header(tar, &h);
if (err) {
return err;
}
/* Seek past header and init remaining data */
err = mtar_seek(tar, tar->pos + sizeof(mtar_raw_header_t));
if (err) {
return err;
}
tar->remaining_data = h.size;
}
/* Read data */
err = tread(tar, ptr, size);
if (err) {
return err;
}
tar->remaining_data -= size;
/* If there is no remaining data we've finished reading and seek back to the
* header */
if (tar->remaining_data == 0) {
return mtar_seek(tar, tar->last_header);
}
return MTAR_ESUCCESS;
}
int mtar_write_header(mtar_t *tar, const mtar_header_t *h) {
mtar_raw_header_t rh;
/* Build raw header and write */
header_to_raw(&rh, h);
tar->remaining_data = h->size;
return twrite(tar, &rh, sizeof(rh));
}
int mtar_write_file_header(mtar_t *tar, const char *name, unsigned size) {
mtar_header_t h;
/* Build header */
mtar_memset(&h, 0, sizeof(h));
_strcpy(h.name, name);
h.size = size;
h.type = MTAR_TREG;
h.mode = 0664;
/* Write header */
return mtar_write_header(tar, &h);
}
int mtar_write_dir_header(mtar_t *tar, const char *name) {
mtar_header_t h;
/* Build header */
mtar_memset(&h, 0, sizeof(h));
_strcpy(h.name, name);
h.type = MTAR_TDIR;
h.mode = 0775;
/* Write header */
return mtar_write_header(tar, &h);
}
int mtar_write_data(mtar_t *tar, const void *data, unsigned size) {
int err;
/* Write data */
err = twrite(tar, data, size);
if (err) {
return err;
}
tar->remaining_data -= size;
/* Write padding if we've written all the data for this file */
if (tar->remaining_data == 0) {
return write_null_bytes(tar, round_up(tar->pos, 512) - tar->pos);
}
return MTAR_ESUCCESS;
}
int mtar_finalize(mtar_t *tar) {
/* Write two NULL records */
return write_null_bytes(tar, sizeof(mtar_raw_header_t) * 2);
}
/* Load libc.obj */
#ifdef MTAR_OBJ
#include <sys/ksys.h>
int mtar_init(){
ksys_dll_t *libc = _ksys_dlopen("/sys/lib/libc.obj");
if(!libc){
_ksys_debug_puts("mtar.obj: libc.obj not loaded!");
return 1;
}
_fread = _ksys_dlsym(libc, "fread");
_fwrite = _ksys_dlsym(libc, "fwrite");
_fclose = _ksys_dlsym(libc, "fclose");
_fopen = _ksys_dlsym(libc, "fopen");
_fseek = _ksys_dlsym(libc, "fseek");
_ftell = _ksys_dlsym(libc, "ftell");
_sprintf= _ksys_dlsym(libc, "sprintf");
_sscanf = _ksys_dlsym(libc, "sscanf");
_strcmp = _ksys_dlsym(libc, "strcmp");
_strchr = _ksys_dlsym(libc, "strchr");
_strcpy = _ksys_dlsym(libc, "strcpy");
return 0;
}
ksys_dll_t EXPORTS[] = {
{"mtar_init", mtar_init},
{"mtar_open", mtar_open},
{"mtar_close", mtar_close},
{"mtar_seek", mtar_seek},
{"mtar_rewind", mtar_rewind},
{"mtar_next", mtar_next},
{"mtar_find", mtar_find},
{"mtar_read_header", mtar_read_header},
{"mtar_read_data", mtar_read_data},
{"mtar_write_header", mtar_write_header},
{"mtar_write_file_header", mtar_write_file_header},
{"mtar_write_dir_header", mtar_write_dir_header},
{"mtar_write_data",mtar_write_data},
{"mtar_finalize", mtar_finalize},
{"mtar_strerror", mtar_strerror},
NULL
};
#endif

View File

@@ -1,91 +0,0 @@
/**
* Copyright (c) 2017 rxi
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MIT license. See `microtar.c` for details.
*/
#ifndef MICROTAR_H
#define MICROTAR_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdio.h>
#include <stdlib.h>
#define MTAR_VERSION "0.1.0"
enum {
MTAR_ESUCCESS = 0,
MTAR_EFAILURE = -1,
MTAR_EOPENFAIL = -2,
MTAR_EREADFAIL = -3,
MTAR_EWRITEFAIL = -4,
MTAR_ESEEKFAIL = -5,
MTAR_EBADCHKSUM = -6,
MTAR_ENULLRECORD = -7,
MTAR_ENOTFOUND = -8
};
enum {
MTAR_TREG = '0',
MTAR_TLNK = '1',
MTAR_TSYM = '2',
MTAR_TCHR = '3',
MTAR_TBLK = '4',
MTAR_TDIR = '5',
MTAR_TFIFO = '6'
};
typedef struct {
unsigned mode;
unsigned owner;
unsigned size;
unsigned mtime;
unsigned type;
char name[100];
char linkname[100];
} mtar_header_t;
typedef struct mtar_t mtar_t;
#pragma pack(push,1)
struct mtar_t {
int (*read)(mtar_t *tar, void *data, unsigned size);
int (*write)(mtar_t *tar, const void *data, unsigned size);
int (*seek)(mtar_t *tar, unsigned pos);
int (*close)(mtar_t *tar);
void *stream;
unsigned pos;
unsigned remaining_data;
unsigned last_header;
};
#pragma pack(pop)
const char* mtar_strerror(int err);
int mtar_open(mtar_t *tar, const char *filename, const char *mode);
int mtar_close(mtar_t *tar);
int mtar_seek(mtar_t *tar, unsigned pos);
int mtar_rewind(mtar_t *tar);
int mtar_next(mtar_t *tar);
int mtar_find(mtar_t *tar, const char *name, mtar_header_t *h);
int mtar_read_header(mtar_t *tar, mtar_header_t *h);
int mtar_read_data(mtar_t *tar, void *ptr, unsigned size);
int mtar_write_header(mtar_t *tar, const mtar_header_t *h);
int mtar_write_file_header(mtar_t *tar, const char *name, unsigned size);
int mtar_write_dir_header(mtar_t *tar, const char *name);
int mtar_write_data(mtar_t *tar, const void *data, unsigned size);
int mtar_finalize(mtar_t *tar);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,38 +0,0 @@
MTAR_ESUCCESS = 0
MTAR_EFAILURE = -1
MTAR_EOPENFAIL = -2
MTAR_EREADFAIL = -3
MTAR_EWRITEFAIL = -4
MTAR_ESEEKFAIL = -5
MTAR_EBADCHKSUM = -6
MTAR_ENULLRECORD = -7
MTAR_ENOTFOUND = -8
MTAR_TREG = '0'
MTAR_TLNK = '1'
MTAR_TSYM = '2'
MTAR_TCHR = '3'
MTAR_TBLK = '4'
MTAR_TDIR = '5'
MTAR_TFIFO = '6'
struct mtar_header_t
mode dd ?
owner dd ?
size dd ?
mtime dd ?
type dd ?
name rb 100
linkname rb 100
ends
struct mtar_t
read_func dd ?
write_func dd ?
seek_func dd ?
close_func dd ?
stream dd ?
pos dd ?
remaining_data dd ?
last_header dd ?
ends

View File

@@ -122,7 +122,13 @@ struc fpcvt
.sizeof:
}
;-----------------------------------------------------------------------------
; Command flags
CMD_WITHOUT_PARAM = 1b ; command may be called without parameters
CMD_WITH_PARAM = 10b ; command may be called with parameters
CMD_WITHOUT_LOADED_APP = 100b ; command may be called without loaded program
CMD_WITH_LOADED_APP = 1000b ; command may be called with loaded program
;-----------------------------------------------------------------------------
; Entry point
@@ -449,63 +455,56 @@ z1:
mov esi, commands
call find_cmd
mov eax, aUnknownCommand
jc .x11
; check command requirements
; flags field:
; &1: command may be called without parameters
; &2: command may be called with parameters
; &4: command may be called without loaded program
; &8: command may be called with loaded program
jc .cmd_procg
mov eax, [esi+8]
mov ecx, [curarg]
cmp byte [ecx], 0
jz .noargs
test byte [esi+16], 2
jz .x11
test byte [esi+16], CMD_WITH_PARAM
jz .cmd_procg
jmp @f
.noargs:
test byte [esi+16], 1
jz .x11
test byte [esi+16], CMD_WITHOUT_PARAM
jz .cmd_procg
@@:
cmp [debuggee_pid], 0
jz .nodebuggee
mov eax, aAlreadyLoaded
test byte [esi+16], 8
jz .x11
jmp .x9
test byte [esi+16], CMD_WITH_LOADED_APP
jz .cmd_procg
jmp .run_cmd
.nodebuggee:
mov eax, need_debuggee
test byte [esi+16], 4
jnz .x9
test byte [esi+16], CMD_WITHOUT_LOADED_APP
jnz .run_cmd
.x11:
.cmd_procg:
xchg esi, eax
call put_message
; store cmdline for repeating
.x10:
.cmd_procg_no_put_msg:
mov esi, cmdline
mov ecx, [cmdline_len]
@@:
cmp ecx, 0
jle .we
jle .wait_event
mov al, [esi + ecx]
mov [cmdline_prev + ecx], al
dec ecx
jmp @b
.we:
.wait_event:
mov [cmdline_len], 0
jmp waitevent
.x9:
.run_cmd:
call dword [esi+4]
jmp .x10
jmp .cmd_procg_no_put_msg
;-----------------------------------------------------------------------------
; Cmdline handling

View File

@@ -2,7 +2,10 @@
COLOR_THEME fix MOVIEOS
format binary as ""
include '../../macros.inc'
include '../../KOSfuncs.inc'
use32
db 'MENUET01'
dd 1
@@ -1145,6 +1148,105 @@ OnDump:
.ret:
ret
;-----------------------------------------------------------------------------
; Print Backtrace
struct STACK_FRAME
prev_frame rd 1
ret_addr rd 1
ends
OnBacktrace:
push ebp
; Set max depth counter
xor eax, eax
dec eax
mov esi, [curarg]
cmp byte [esi], 0
jz .save_depth
call get_hex_number
mov esi, aParseError
jc .exit
; If depth 0
test eax, eax
jz .done
.save_depth:
mov [bt_depth], eax
; Get start frame addres
mov ebp, [_ebp]
test ebp, ebp
jz .done
mov edi, stack_frame_dump
.next:
mcall SF_DEBUG, SSF_READ_MEMORY, [debuggee_pid], sizeof.STACK_FRAME, ebp
cmp eax, -1
mov esi, read_mem_err
jz .exit
; The address of the previous frame must be less than the current one
mov eax, [edi + STACK_FRAME.prev_frame]
test eax, eax
jz .done
; Save stack_frame_dump
push edi
; Save previous frame
push ebp
; Save return address
mov eax, [edi + STACK_FRAME.ret_addr]
push eax
; Print frame address and return address
push eax ; pop in put_message_nodraw
push ebp ; pop in put_message_nodraw
mov esi, aBacktraceFmt
call put_message_nodraw
; Restore return address
pop eax
; Find symbol by return address
call find_near_symbol
test esi, esi
jnz .print_sym
mov esi, aBacktraceSymStub
.print_sym:
call put_message_nodraw
mov esi, newline
call put_message_nodraw
; Restore previous frame
pop ebp
; Restore stack_frame_dump
pop edi
; The address of the previous frame must be greater than the current one.
cmp [edi + STACK_FRAME.prev_frame], ebp
jna .done
; Set previous frame
mov ebp, [edi + STACK_FRAME.prev_frame]
dec [bt_depth]
jnz .next
.done:
mov esi, newline
.exit:
call put_message
pop ebp
ret
;-----------------------------------------------------------------------------
; Dissassemble block of executable event
@@ -1864,7 +1966,7 @@ include 'disasm.inc'
caption_str db 'Kolibri Debugger',0
begin_str db 'Kolibri Debugger, version 0.35',10
begin_str db 'Kolibri Debugger, version 0.36',10
db 'Hint: type "help" for help, "quit" to quit'
newline db 10,0
prompt db '> ',0
@@ -1880,66 +1982,88 @@ help_groups:
;-----------------------------------------------------------------------------
; Commands format definitions
; TODO: make it with macros
; flags field:
; &1: command may be called without parameters
; &2: command may be called with parameters
; &4: command may be called without loaded program
; &8: command may be called with loaded program
commands:
dd _aH, OnHelp, HelpSyntax, HelpHelp
db 0Fh
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITHOUT_LOADED_APP or CMD_WITH_LOADED_APP
dd aHelp, OnHelp, HelpSyntax, HelpHelp
db 0Fh
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITHOUT_LOADED_APP or CMD_WITH_LOADED_APP
dd aQuit, OnQuit, QuitSyntax, QuitHelp
db 0Dh
db CMD_WITHOUT_PARAM or CMD_WITHOUT_LOADED_APP or CMD_WITH_LOADED_APP
dd aLoad, OnLoad, LoadSyntax, LoadHelp
db 6
db CMD_WITH_PARAM or CMD_WITHOUT_LOADED_APP
dd aReload, OnReload, ReloadSyntax, ReloadHelp
db 0Dh
db CMD_WITHOUT_PARAM or CMD_WITHOUT_LOADED_APP or CMD_WITH_LOADED_APP
dd aTerminate, OnTerminate, TerminateSyntax, TerminateHelp
db 9
db CMD_WITHOUT_PARAM or CMD_WITH_LOADED_APP
dd aDetach, OnDetach, DetachSyntax, DetachHelp
db 9
db CMD_WITHOUT_PARAM or CMD_WITH_LOADED_APP
dd aSuspend, OnSuspend, SuspendSyntax, SuspendHelp
db 9
db CMD_WITHOUT_PARAM or CMD_WITH_LOADED_APP
dd aResume, OnResume, ResumeSyntax, ResumeHelp
db 0Bh
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aStep, OnStepMultiple, StepSyntax, StepHelp
db 0Bh
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aProceed, OnProceedMultiple, ProceedSyntax, ProceedHelp
db 0Bh
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aCalc, OnCalc, CalcSyntax, CalcHelp
db 0Eh
db CMD_WITH_PARAM or CMD_WITHOUT_LOADED_APP or CMD_WITH_LOADED_APP
dd aDump, OnDump, DumpSyntax, DumpHelp
db 0Bh
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBacktrace, OnBacktrace, BacktraceSyntax, BacktraceHelp
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aUnassemble, OnUnassemble, UnassembleSyntax, UnassembleHelp
db 0Bh
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBp, OnBp, BpSyntax, BpHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBpm, OnBpmb, BpmSyntax, BpmHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBpmb, OnBpmb, BpmSyntax, BpmHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBpmw, OnBpmw, BpmSyntax, BpmHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBpmd, OnBpmd, BpmSyntax, BpmHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBl, OnBl, BlSyntax, BlHelp
db 0Bh
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBc, OnBc, BcSyntax, BcHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBd, OnBd, BdSyntax, BdHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBe, OnBe, BeSyntax, BeHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aReg, OnReg, RSyntax, RHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aUnpack, OnUnpack, UnpackSyntax, UnpackHelp
db 9
db CMD_WITHOUT_PARAM or CMD_WITH_LOADED_APP
dd aLoadSymbols, OnLoadSymbols, LoadSymbolsSyntax, LoadSymbolsHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd 0
;-----------------------------------------------------------------------------
@@ -1980,7 +2104,8 @@ help_data_msg db 'List of data commands:',10
db 'd [<expression>] - dump data at given address',10
db 'u [<expression>] - unassemble instructions at given address',10
db 'r <register> <expression> or',10
db 'r <register>=<expression> - set register value',10,0
db 'r <register>=<expression> - set register value',10
db 'bt [<number>] - display backtrace / stacktrace',10,0
; Breakpoints commands group
@@ -2038,6 +2163,11 @@ DumpHelp db 'Dump data of debugged program',10
DumpSyntax db 'Usage: d <expression> - dump data at specified address',10
db ' or: d - continue current dump',10,0
aBacktrace db 3,'bt',0
BacktraceHelp db 'Display backtrace / stacktrace',10
BacktraceSyntax db 'Usage: bt <number> - display backtrace with depth',10
db ' or: bt display all backtrace',10,0
aCalc db 2,'?',0
CalcHelp db 'Calculate value of expression',10
CalcSyntax db 'Usage: ? <expression>',10,0
@@ -2102,6 +2232,11 @@ LoadSymbolsSyntax db 'Usage: load-symbols <symbols-file-name>',10,0
aUnknownCommand db 'Unknown command',10,0
;-----------------------------------------------------------------------------
; Info messages
aBacktraceSymStub db '??',0
aBacktraceFmt db '[0x%8X] 0x%8X in ',0
;-----------------------------------------------------------------------------
; Error messages
@@ -2474,11 +2609,13 @@ disasm_cur_pos dd ?
disasm_cur_str dd ?
disasm_string rb 256
thread_info process_information
stack_frame_dump rb sizeof.STACK_FRAME
bt_depth rd 1
;-----------------------------------------------------------------------------
; Coordinates and sizes for GUI
thread_info process_information
data_x_size_dd dd ?, ?
messages_x_size_dd dd ?, ?
registers_x_pos_dd dd ?, ?

View File

@@ -4,6 +4,11 @@
include 'sort.inc'
struct DEBUG_SYMBOL
addr rd 1
string rd 0
ends
; compare proc for sorter
compare:
cmpsd
@@ -459,4 +464,69 @@ find_symbol_name:
@@:
pop esi
ret
ret
;-----------------------------------------------------------------------------
;
; Find the nearest symol using binary search
;
; in: eax - target addres
; out: esi - symbol name
; destroys: ebx, ecx, edx, edi, ebp
;
find_near_symbol:
mov edi, [symbols]
xor esi, esi ; Result
mov ecx, esi ; Left
mov edx, [num_symbols] ; Right
dec edx
js .end
; If the first address is already greater than the target
mov ebp, [edi + ecx * sizeof.DEBUG_SYMBOL]
cmp [ebp + DEBUG_SYMBOL.addr], eax
ja .end
; If the last address is less than or equal to the target
mov ebp, [edi + edx * sizeof.DEBUG_SYMBOL]
cmp [ebp + DEBUG_SYMBOL.addr], eax
jbe .found
.loop:
cmp ecx, edx
ja .end
; Calc middle:
mov ebx, edx ; Middle
sub ebx, ecx ; (right - left)
shr ebx, 1 ; / 2
add ebx, ecx ; + left
; Equal
mov ebp, [edi + ebx * sizeof.DEBUG_SYMBOL]
cmp [ebp + DEBUG_SYMBOL.addr], eax
jz .found
jb .update_left
; Update right
mov edx, ebx
dec edx
jmp .loop
.update_left:
; Save potential result
mov esi, ebp
add esi, DEBUG_SYMBOL.string
; Update left
mov ecx, ebx
inc ecx
jmp .loop
.found:
mov esi, ebp
add esi, DEBUG_SYMBOL.string
.end:
ret

View File

@@ -84,6 +84,7 @@ commands: ; all commands must be in uppercase
; dd 'APPE', login_first, login_first, login_first, cmd_APPE
dd 'CDUP', login_first, login_first, login_first, cmdCDUP
dd 'CWD', login_first, login_first, login_first, cmdCWD
dd 'XCWD', login_first, login_first, login_first, cmdCWD
dd 'DELE', login_first, login_first, login_first, cmdDELE
; dd 'HELP', login_first, login_first, login_first, cmd_HELP
dd 'LIST', login_first, login_first, login_first, cmdLIST
@@ -96,6 +97,7 @@ commands: ; all commands must be in uppercase
dd 'PASV', login_first, login_first, login_first, cmdPASV
dd 'PORT', login_first, login_first, login_first, cmdPORT
dd 'PWD', login_first, login_first, login_first, cmdPWD
dd 'XPWD', login_first, login_first, login_first, cmdPWD
dd 'QUIT', cmdQUIT, cmdQUIT, cmdQUIT, cmdQUIT
; dd 'REIN', login_first, login_first, login_first, cmd_REIN
; dd 'REST', login_first, login_first, login_first, cmd_REST
@@ -342,7 +344,7 @@ align 4
cmdABOR:
or [ebp + thread_data.permissions], ABORT
sendFTP "250 Command succesul"
sendFTP "250 Command successful"
ret
;------------------------------------------------
@@ -383,7 +385,7 @@ cmdCDUP:
invoke con_write_asciiz, eax
invoke con_write_asciiz, str_newline
sendFTP "250 Command succesul"
sendFTP "250 Command successful"
ret
;------------------------------------------------
@@ -448,7 +450,7 @@ cmdCWD:
invoke con_write_asciiz, eax
invoke con_write_asciiz, str_newline
sendFTP "250 Command succesful"
sendFTP "250 Command successful"
ret
.err:
@@ -510,7 +512,7 @@ cmdDELE:
test eax, eax
jnz .err
sendFTP "250 Command succesful"
sendFTP "250 Command successful"
ret
.err:
sendFTP "550 No such file"
@@ -998,7 +1000,9 @@ cmdRETR:
cmp eax, -1
je .cannot_open ; FIXME: this is not the correct error
push eax
invoke con_write_asciiz, str2
pop eax
push eax ebx
mov esi, eax

View File

@@ -135,7 +135,7 @@ start:
mov [sockaddr1.port], ax
xchg al, ah
invoke con_printf, str1, eax
invoke con_printf, str1, ini_buf, eax
add esp, 8
; open listening socket
@@ -341,7 +341,7 @@ thread_exit:
; initialized data
title db 'FTP daemon', 0
str1 db 'Starting FTP daemon on port %u.', 0
str1 db 'Starting FTP daemon on %s:%u', 0
str2 db '.', 0
str2b db ' OK!',10,0
str3 db 'Listen error',10,0

View File

@@ -1,16 +0,0 @@
KTCC_DIR=../../develop/ktcc/trunk
NAME=gamehack
KTCC=$(KTCC_DIR)/bin/kos32-tcc
KPACK=kpack
SRC=gh_shell.c
CFLAGS=-I $(KTCC_DIR)/libc/include
LIBS = -lck
all:
$(KTCC) $(CFLAGS) $(SRC) $(LIBS) -o $(NAME)
$(KPACK) $(NAME)
clean:
rm $(NAME)

View File

@@ -1,72 +0,0 @@
int PID=-1;
int kdebugger_write(unsigned ID, unsigned n, unsigned addr, unsigned* buff)
{
int num;
__asm__ __volatile__(
"int $0x40"
:"=a"(num)
:"a"(69), "b"(7), "c"(ID), "d"(n),"S"(addr),"D"(buff)
);
return num;
}
int kdebugger_read(unsigned ID, unsigned n, unsigned addr, unsigned* buff)
{
int num;
__asm__ __volatile__(
"int $0x40"
:"=a"(num)
:"a"(69), "b"(6), "c"(ID), "d"(n),"S"(addr),"D"(buff)
);
return num;
}
void kdebugger_pause(unsigned ID)
{
__asm__ __volatile__(
"int $0x40"
::"a"(69), "b"(4), "c"(ID)
);
}
void kdebugger_play(unsigned ID)
{
__asm__ __volatile__(
"int $0x40"
::"a"(69), "b"(5), "c"(ID)
);
}
void kdebugger_disconnect(unsigned ID)
{
__asm__ __volatile__(
"int $0x40"
::"a"(69), "b"(3), "c"(ID)
);
}
int load_game(char *app_name, char *args)
{
#pragma pack(push, 1)
struct file_op_t
{
unsigned fn;
unsigned flags;
char* args;
unsigned res1, res2;
char zero;
char* app_name __attribute__((packed));
} file_op;
#pragma pack(pop)
memset(&file_op, 0, sizeof(file_op));
file_op.fn = 7;
file_op.flags = 1;
file_op.args = args;
file_op.app_name = app_name;
register int val;
asm volatile ("int $0x40":"=a"(val):"a"(70), "b"(&file_op));
return val;
}

View File

@@ -1,96 +0,0 @@
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <kos32sys1.h>
#include "gh_core.c"
#define CMD_LEN 255
#define TITLE "GameHack 1.0 ALPHA "
char cmd_line[CMD_LEN];
char cmd_line_tmp[CMD_LEN];
void notify_show(char *text)
{
start_app("/sys/@notify", text);
}
void cmd_processing()
{
strcpy(cmd_line_tmp, cmd_line);
char *cmd = strtok(cmd_line_tmp, " \n");
if(!strcmp(cmd, "pause")){
kdebugger_pause(PID);
}
else if(!strcmp(cmd, "play")){
kdebugger_play(PID);
}
else if(!strcmp(cmd, "exit")){
exit(0);
}
else if(!strcmp(cmd, "write")){
unsigned addr=0;
int val =0;
if(sscanf(cmd_line, "%s %x %d %d",cmd_line, &addr, &val, &val)==3){
if(kdebugger_write(PID, sizeof(int), addr, &val)==-1){
puts("Memory write error!");
}
}else{
puts("Invalid arguments!");
}
}
else if(!strcmp(cmd, "read")){
unsigned addr=0;
int val =0;
if(sscanf(cmd_line, "%s %x %x",cmd_line, &addr, &addr)==2){
if(kdebugger_read(PID, sizeof(int), addr, &val)==-1){
puts("Memory read error!");
}
printf("0x%.8X: %d\n", addr, val);
}else{
puts("Invalid arguments!");
}
}
else if(!strcmp(cmd, "help"))
{
puts("Commands:");
puts(" write [addres] [value] - Write DWORD value by address.");
puts(" read [addres] [value] - Read DWORD value by address.");
puts(" pause - Suspend the game (process)." );
puts(" play - Resume running the game(process).");
puts(" find [value] - Search for DWORD value in memory(VIP).");
}
else if(!strcmp(cmd, "find"))
{
puts("Not yet implemented ...");
}
else if(cmd != NULL){
puts("Unknown command!");
}
}
int main(int argc, char* argv[])
{
if (argc!=2 ){
notify_show("'No game selected!' -E");
exit(0);
}
con_init_console_dll();
con_set_title(TITLE);
PID = load_game(argv[1], NULL);
PID = 2;
if(PID<0){
notify_show("'Game not loaded!' -E");
exit(0);
}
kdebugger_play(PID);
while (1){
printf("GameHack> ");
con_gets(cmd_line, CMD_LEN);
cmd_processing();
memset(cmd_line, '\n', CMD_LEN);
}
}

View File

@@ -1,18 +0,0 @@
KTCC_DIR=../../develop/ktcc/trunk
NAME=teatool
KTCC=$(KTCC_DIR)/bin/kos32-tcc
KPACK=kpack
SRC=teatool.c
CFLAGS=-nostdinc -I $(KTCC_DIR)/libc/include
LFLAGS=-nostdlib -L $(KTCC_DIR)/bin/lib $(KTCC_DIR)/bin/lib/start.o
LIBS = -lck
all:
$(KTCC) $(CFLAGS) $(LFLAGS) $(SRC) $(LIBS) -o $(NAME)
$(KPACK) $(NAME)
clean:
rm $(NAME)

View File

@@ -1,49 +0,0 @@
#include <stdio.h>
#define INVALID_ARG "Invalid arguments! Use the help: -h!\n"
#define KEY_RECORD_IN_FILE "The key is recorded in file: %s\n"
#define INCORRECT_FILE "Error! Incorrect file:'%s'\n"
#define NO_KEY_OR_KEYFILE "No key or key file!\n"
#define INVALID_KEY_FORMAT "Invalid key format!\n"
#define FILE_NOT_FOUND "File '%s' not found!\n"
#define DATA_DECRYPT "Data from file: %s successfully DECRYPTED to file: %s\n"
#define DATA_ENCRYPT "Data from file: %s successfully ENCRYPTED to file: %s\n"
#define FILE_DECRYPTION "File decryption...\n"
#define FILE_ENCRYPTION "File encryption...\n"
#define RECORD_DECRYPT_DATA "Record decryped data...\n"
#define LOAD_IN_RAM "Loading a '%s' file in RAM...\n"
#define RECORD_ENCRYPT_DATA "Record encryped data...\n"
#define MEMORY_ERROR "To big file, not enough memory! Use normal mode."
void show_help()
{
puts("Usage: \nTEAtool [infile] [outfile] [arguments]\n");
puts("Arguments:");
puts("-e [mode] Encrypt file in 'speed' or 'normal' mode.");
puts("-d [mode] Decrypt file in 'speed' or 'normal' mode.");
puts(" In 'speed' mode, file is entirely loaded into RAM.");
puts(" In 'normal' mode, file is loaded with parts in RAM.");
puts("-k [key] 128bit-key in hex format.");
puts("-K [keyfile] Use key from file.");
puts("-r [key] [keyfile].key Key entry to key file.");
puts("-h This reference");
puts("-a About the program \n");
}
void show_about()
{
puts("\n");
puts("-----------TEAtool-ENG-----------\n");
printf(" ) ( Version: \n");
printf(" ( ) ) 1.8-stable \n");
printf(" ) ( ( \n");
printf(" _______)_ Author: \n");
printf(" .-'---------| turbocat2001 \n");
printf("( C|/////////| \n");
printf(" '-./////////| Tester: rgimad \n");
printf(" '_________' \n");
printf(" '-------'' License: GPLv3 \n\n");
printf(" Powered by: \n");
printf(" Tiny Encryption Algorithm. \n\n");
}

View File

@@ -1,9 +0,0 @@
Encrypting the "in.file" file with the "FFAB1100C176001F1ADDB8E792001EA5" key in normal mode:
# teatool in.file out.file -k FFAB1100C176001F1ADDB8E792001EA5 -e normal
Encrypting the "in.file" file with the key-file "my.key" in speed mode:*
# teatool in.file out.file -K my.key -e speed
Writing the "FFAB1100C176001F1ADDB8E792001EA5" key to the key-file "my.key"*
# teatool -r FFAB1100C176001F1ADDB8E792001EA5 my

View File

@@ -1,62 +0,0 @@
#include <stdint.h>
void TEA_encrypt (uint32_t block[2], uint32_t key[4])
{
/* set up */
uint32_t v0 = block[0];
uint32_t v1 = block[1];
uint32_t sum = 0;
uint32_t i;
/* a key schedule constant */
uint32_t delta = 0x9e3779b9;
/* cache key */
uint32_t k0 = key[0];
uint32_t k1 = key[1];
uint32_t k2 = key[2];
uint32_t k3 = key[3];
/* basic cycle start */
for (i = 0; i < 32; i++)
{
sum += delta;
v0 += ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1);
v1 += ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3);
}
/* end cycle */
block[0] = v0;
block[1] = v1;
}
void TEA_decrypt (uint32_t* block, uint32_t* key)
{
/* set up */
uint32_t v0 = block[0];
uint32_t v1 = block[1];
uint32_t sum = 0xC6EF3720;
uint32_t i;
/* a key schedule constant */
uint32_t delta = 0x9e3779b9;
/* cache key */
uint32_t k0 = key[0];
uint32_t k1 = key[1];
uint32_t k2 = key[2];
uint32_t k3 = key[3];
/* basic cycle start */
for (i = 0; i < 32; i++)
{
v1 -= ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3);
v0 -= ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1);
sum -= delta;
}
/* end cycle */
block[0] = v0;
block[1] = v1;
}

View File

@@ -1,303 +0,0 @@
/* Copyright (C) 2019-2021 Logaev Maxim (turbocat2001), GPLv2 */
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <conio.h>
#include "lang_en.c"
#include "tea.c"
#define ENCRYPT 1
#define DECRYPT 2
typedef unsigned char flag;
uint32_t key[4];
long size_orig_file(FILE* file)
{
fseek(file, 0, SEEK_END);
long size = ftell(file);
fseek(file, 0, SEEK_SET);
return size;
}
long size_xcrypt_file(FILE* file)
{
fseek(file, 0, SEEK_END);
long size = ftell(file);
fseek(file, 0, SEEK_SET);
if(size%8==0) {
return size;
}else{
return (size/8+1)*8;
}
}
void xcrypt_file_speed(char *in_file, char* out_file, char arg)
{
FILE *input, *output;
if((input = fopen(in_file,"rb"))==NULL){
printf(FILE_NOT_FOUND, in_file);
exit(1);
}
output = fopen(out_file,"wb");
long size_f=size_xcrypt_file(input);
uint8_t size_diff;
size_diff=(uint8_t)(size_f-size_orig_file(input));
uint32_t *buff;
buff=malloc(size_f);
if(!buff) {
puts(MEMORY_ERROR);
exit(-1);
}
if(arg==ENCRYPT){
printf(LOAD_IN_RAM,in_file);
fread(buff, 1,size_f, input);
printf(FILE_ENCRYPTION);
for(long i=0; i<(size_f/4); i=i+2)
{
TEA_encrypt(buff+i,key);
}
printf(RECORD_ENCRYPT_DATA);
fwrite(&size_diff,1, 1, output);
fwrite(buff,1,size_f, output);
fclose(input);
fclose(output);
printf(DATA_ENCRYPT,in_file,out_file);
exit(0);
}
else if(arg==DECRYPT){
long size_f=size_orig_file(input);
printf(LOAD_IN_RAM,in_file);
fread(&size_diff,1,1,input);
fread(buff,1,size_f-1, input);
printf(FILE_DECRYPTION);
for(long i=0; i<size_f/4; i=i+2)
{
TEA_decrypt(buff+i,key);
}
printf(RECORD_DECRYPT_DATA);
fwrite(buff,1,size_f-size_diff-1, output);
fclose(input);
fclose(output);
printf(DATA_DECRYPT,in_file,out_file);
exit(0);
}
}
void xcrypt_file(char *in_file, char* out_file, char arg)
{
uint32_t temp_block[2];
FILE *input, *output;
if((input = fopen(in_file,"rb"))==NULL){
printf(FILE_NOT_FOUND, in_file);
exit(1);
}
output = fopen(out_file,"wb");
register long size_f=size_xcrypt_file(input);
uint8_t size_diff=(uint8_t)(size_f-size_orig_file(input));
if(arg==ENCRYPT){
fwrite(&size_diff,1,1,output);
printf(FILE_ENCRYPTION);
while(!feof(input))
{
memset(temp_block, 0x00, 2);
fread(temp_block, sizeof(uint32_t), 2, input) ;
TEA_encrypt(temp_block,key);
fwrite(temp_block, sizeof(uint32_t),2, output);
}
fclose(input);
fclose(output);
printf(DATA_ENCRYPT,in_file,out_file);
exit(0);
}
else if(arg==DECRYPT){
size_f = size_orig_file(input);
fread(&size_diff,1,1,input);
size_f=size_f-size_diff-1;
printf(FILE_DECRYPTION);
while(!feof(input))
{
fread(temp_block, sizeof(uint32_t), 2, input);
TEA_decrypt(temp_block,key);
if(size_f>=8){
fwrite(temp_block,sizeof(uint32_t),2,output);
}else{
fwrite(temp_block,1,size_f,output);
}
size_f=size_f-8;
if(size_f<0){
size_f=0;
}
}
fclose(input);
fclose(output);
printf(DATA_DECRYPT,in_file,out_file);
exit(0);
}
}
void str_to_strkey(char *str, char str_key[4][9])
{
int count=0;
for(int i=0; i<4; i++)
{
int j=0;
while (j<8)
{
str_key[i][j]=str[count];
count++;
j++;
}
}
}
int valid_key(char *str)
{
int count=0;
char hex[]={"abcdefABCDEF0123456789"};
for(int i=0; i<32; i++)
{
if(strchr(hex,str[i])!=NULL){
count++;
}
}
if(count==32){return 1;}
else{ return 0;}
}
void key_con_read(char *str)
{
char str_key[4][9];
if(valid_key(str)&&(strlen(str)==32))
{
for(int i=0; i<4; i++){
str_to_strkey(str, str_key);
key[i]=(uint32_t)strtol(str_key[i],NULL,16);
}
}else{
printf(INVALID_KEY_FORMAT);
exit(-1);
}
}
void key_file_read(char *key_file)
{
FILE *keyfile;
if((keyfile = fopen(key_file,"rb"))==NULL){
printf(FILE_NOT_FOUND, key_file);
exit(-1);
}
if(size_orig_file(keyfile)==16) {
fread(key,sizeof(uint32_t),4, keyfile);
}else{
printf(INVALID_KEY_FORMAT);
exit(-1);
}
fclose(keyfile);
}
void findopt(int argc, char *argv[],char *in_file, char *out_file)
{
char found=0;
for(int j=3; j<argc; j++)
{
if(!strcmp(argv[j],"-k")){
found=1;
key_con_read(argv[j+1]);
break;
}
else if(!strcmp(argv[j],"-K")){
found=1;
key_file_read(argv[j+1]);
break;
}
}
if(!found){
printf(NO_KEY_OR_KEYFILE);
exit(-1);
}
for(int i=3;i<argc; i++){
if(!strcmp(argv[i],"-e"))
{
if(!strcmp(argv[i+1],"normal")){xcrypt_file(in_file, out_file, ENCRYPT);}
if(!strcmp(argv[i+1],"speed")){xcrypt_file_speed(in_file, out_file, ENCRYPT);}
}
if(!strcmp(argv[i],"-d"))
{
if(!strcmp(argv[i+1],"normal")){xcrypt_file(in_file, out_file, DECRYPT);}
if(!strcmp(argv[i+1],"speed")){xcrypt_file_speed(in_file, out_file, DECRYPT);}
}
}
printf(INVALID_ARG);
exit(0);
}
void key_write_in_file(char *keyfilename)
{
FILE *keyfile;
if((keyfile = fopen(strcat(keyfilename, ".key"), "wb"))==NULL){
printf(INCORRECT_FILE, keyfilename);
exit(-1);
}
fwrite(key,sizeof(uint8_t), 16, keyfile);
printf(KEY_RECORD_IN_FILE, keyfilename);
fclose(keyfile);
exit(0);
}
int main(int argc, char **argv)
{
con_init_console_dll();
con_set_title("TEAtool\0");
if(argc==7){
findopt(argc,argv, argv[1],argv[2]);
}
else if(argc==2 && !strcmp(argv[1],"-a")){
show_about();
exit(0);
}
else if(argc==2 && !strcmp(argv[1],"-h")){
show_help();
exit(0);
}
else if(argc==4 && !strcmp(argv[1],"-r")){
key_con_read(argv[2]);
key_write_in_file(argv[3]);
}
else{
printf(INVALID_ARG);
exit(0);
}
return 0;
}