Compare commits

...

3 Commits

Author SHA1 Message Date
Yourtion
575c4ffce8 保护应用程序(2) 2016-05-17 12:39:47 +08:00
Yourtion
f3f9a6c178 保护应用程序(1) 2016-05-17 12:30:15 +08:00
Yourtion
01bbd98aa8 应用程序运行时关闭命令行窗口 2016-05-17 12:24:03 +08:00
6 changed files with 82 additions and 23 deletions

View File

@@ -164,10 +164,17 @@ color2.bim : color2.obj a_nask.obj Makefile
color2.hrb : color2.bim Makefile
$(BIM2HRB) color2.bim color2.hrb 56k
crack7.bim : crack7.obj Makefile
$(OBJ2BIM) @$(RULEFILE) out:crack7.bim stack:1k map:crack7.map crack7.obj
crack7.hrb : crack7.bim Makefile
$(BIM2HRB) crack7.bim crack7.hrb 0k
haribote.img : ipl10.bin haribote.sys Makefile \
hello.hrb hello2.hrb a.hrb hello3.hrb hello4.hrb hello5.hrb \
winhelo.hrb winhelo2.hrb winhelo3.hrb star1.hrb stars.hrb stars2.hrb \
lines.hrb walk.hrb noodle.hrb beepdown.hrb color.hrb color2.hrb
lines.hrb walk.hrb noodle.hrb beepdown.hrb color.hrb color2.hrb \
crack7.hrb
$(EDIMG) imgin:../z_tools/fdimg0at.tek \
wbinimg src:ipl10.bin len:512 from:0 to:0 \
copy from:haribote.sys to:@: \
@@ -191,6 +198,7 @@ haribote.img : ipl10.bin haribote.sys Makefile \
copy from:beepdown.hrb to:@: \
copy from:color.hrb to:@: \
copy from:color2.hrb to:@: \
copy from:crack7.hrb to:@: \
imgout:haribote.img
# 其他指令

View File

@@ -46,7 +46,7 @@ void HariMain(void)
};
int key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1;
int j, x, y, mmx = -1, mmy = -1, mmx2 = 0;
struct SHEET *sht = 0, *key_win;
struct SHEET *sht = 0, *key_win, *sht2;
init_gdtidt();
init_pic();
@@ -195,8 +195,8 @@ void HariMain(void)
io_cli(); /*强制结束处理时禁止任务切换*/
task->tss.eax = (int) &(task->tss.esp0);
task->tss.eip = (int) asm_end_app;
task_run(task, -1, 0); /*为了确实执行结束处理,如果处于休眠状态则唤醒*/
io_sti();
task_run(task, -1, 0); /*为了确实执行结束处理,如果处于休眠状态则唤醒*/
}
}
if (i == 256 + 0x3c && key_shift != 0) { /* Shift+F2 */
@@ -267,10 +267,14 @@ void HariMain(void)
io_cli(); /*强制结束处理时禁止任务切换*/
task->tss.eax = (int) &(task->tss.esp0);
task->tss.eip = (int) asm_end_app;
task_run(task, -1, 0);
io_sti();
task_run(task, -1, 0);
} else { /*命令行窗口*/
task = sht->task;
sheet_updown(sht, -1); /*暂且隐藏该图层*/
keywin_off(key_win);
key_win = shtctl->sheets[shtctl->top - 1];
keywin_on(key_win);
io_cli();
fifo32_put(&task->fifo, 4);
io_sti();
@@ -301,6 +305,10 @@ void HariMain(void)
close_console(shtctl->sheets0 + (i - 768));
} else if (1024 <= i && i <= 2023) {
close_constask(taskctl->tasks0 + (i - 1024));
} else if (2024 <= i && i <= 2279) { /*只关闭命令行窗口*/
sht2 = shtctl->sheets0 + (i - 2024);
memman_free_4k(memman, (int) sht2->buf, 256 * 165);
sheet_free(sht2);
}
}
}

View File

@@ -88,15 +88,16 @@ struct GATE_DESCRIPTOR {
void init_gdtidt(void);
void set_segmdesc(struct SEGMENT_DESCRIPTOR *sd, unsigned int limit, int base, int ar);
void set_gatedesc(struct GATE_DESCRIPTOR *gd, int offset, int selector, int ar);
#define ADR_IDT 0x0026f800
#define LIMIT_IDT 0x000007ff
#define ADR_GDT 0x00270000
#define LIMIT_GDT 0x0000ffff
#define ADR_IDT 0x0026f800
#define LIMIT_IDT 0x000007ff
#define ADR_GDT 0x00270000
#define LIMIT_GDT 0x0000ffff
#define ADR_BOTPAK 0x00280000
#define LIMIT_BOTPAK 0x0007ffff
#define AR_DATA32_RW 0x4092
#define AR_CODE32_ER 0x409a
#define AR_TSS32 0x0089
#define AR_LDT 0x0082
#define AR_TSS32 0x0089
#define AR_INTGATE32 0x008e
/* int.c */
@@ -210,6 +211,7 @@ struct TASK {
int level, priority; /* 优先级 */
struct FIFO32 fifo;
struct TSS32 tss;
struct SEGMENT_DESCRIPTOR ldt[2];
struct CONSOLE *cons;
int ds_base, cons_stack;
};

View File

@@ -17,7 +17,7 @@ void console_task(struct SHEET *sheet, int memtotal)
cons.cur_c = -1;
task->cons = &cons;
if (sheet != 0) {
if (cons.sht != 0) {
cons.timer = timer_alloc();
timer_init(cons.timer, &task->fifo, 1);
timer_settime(cons.timer, 50);
@@ -35,7 +35,7 @@ void console_task(struct SHEET *sheet, int memtotal)
} else {
i = fifo32_get(&task->fifo);
io_sti();
if (i <= 1) { /*光标用定时器*/
if (i <= 1 && cons.sht != 0) { /*光标用定时器*/
if (i != 0) {
timer_init(cons.timer, &task->fifo, 0); /*下次置0 */
if (cons.cur_c >= 0) {
@@ -53,7 +53,10 @@ void console_task(struct SHEET *sheet, int memtotal)
cons.cur_c = COL8_FFFFFF;
}
if (i == 3) { /*光标OFF */
boxfill8(sheet->buf, sheet->bxsize, COL8_000000, cons.cur_x, cons.cur_y, cons.cur_x + 7, cons.cur_y + 15);
if (cons.sht != 0) {
boxfill8(cons.sht->buf, cons.sht->bxsize, COL8_000000,
cons.cur_x, cons.cur_y, cons.cur_x + 7, cons.cur_y + 15);
}
cons.cur_c = -1;
}
if (i == 4) { /*点击命令行窗口的“×”按钮*/
@@ -74,7 +77,7 @@ void console_task(struct SHEET *sheet, int memtotal)
cmdline[cons.cur_x / 8 - 2] = 0;
cons_newline(&cons);
cons_runcmd(cmdline, &cons, fat, memtotal); /*运行命令*/
if (sheet == 0) {
if (cons.sht == 0) {
cmd_exit(&cons, fat);
}
/*显示提示符*/
@@ -89,11 +92,12 @@ void console_task(struct SHEET *sheet, int memtotal)
}
}
/*重新显示光标*/
if (sheet != 0) {
if (cons.sht != 0) {
if (cons.cur_c >= 0) {
boxfill8(sheet->buf, sheet->bxsize, cons.cur_c, cons.cur_x, cons.cur_y, cons.cur_x + 7, cons.cur_y + 15);
boxfill8(cons.sht->buf, cons.sht->bxsize, cons.cur_c,
cons.cur_x, cons.cur_y, cons.cur_x + 7, cons.cur_y + 15);
}
sheet_refresh(sheet, cons.cur_x, cons.cur_y, cons.cur_x + 8, cons.cur_y + 16);
sheet_refresh(cons.sht, cons.cur_x, cons.cur_y, cons.cur_x + 8, cons.cur_y + 16);
}
}
}
@@ -108,8 +112,8 @@ void cons_putchar(struct CONSOLE *cons, int chr, char move)
for (;;) {
if (cons->sht != 0) {
putfonts8_asc_sht(cons->sht, cons->cur_x, cons->cur_y, COL8_FFFFFF, COL8_000000, " ", 1);
cons->cur_x += 8;
}
cons->cur_x += 8;
if (cons->cur_x == 8 + 240) {
cons_newline(cons);
}
@@ -194,8 +198,8 @@ void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal)
} else if (strncmp(cmdline, "start ", 6) == 0) {
cmd_start(cons, cmdline, memtotal);
} else if (strncmp(cmdline, "ncst ", 5) == 0) {
cmd_ncst(cons, cmdline, memtotal);
}else if (cmdline[0] != 0) {
cmd_ncst(cons, cmdline, memtotal);
} else if (cmdline[0] != 0) {
if (cmd_app(cons, fat, cmdline) == 0) {
/*不是命令,不是应用程序,也不是空行*/
cons_putstr0(cons, "Bad command.\n\n");
@@ -369,12 +373,12 @@ int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
dathrb = *((int *) (p + 0x0014));
q = (char *) memman_alloc_4k(memman, segsiz);
task->ds_base = (int) q;
set_segmdesc(gdt + task->sel / 8 + 1000, finfo->size - 1, (int) p, AR_CODE32_ER + 0x60);
set_segmdesc(gdt + task->sel / 8 + 2000, segsiz - 1, (int) q, AR_DATA32_RW + 0x60);
set_segmdesc(task->ldt + 0, finfo->size - 1, (int) p, AR_CODE32_ER + 0x60);
set_segmdesc(task->ldt + 1, segsiz - 1, (int) q, AR_DATA32_RW + 0x60);
for (i = 0; i < datsiz; i++) {
q[esp + i] = p[dathrb + i];
}
start_app(0x1b, task->sel + 1000 * 8, esp, task->sel + 2000 * 8, &(task->tss.esp0));
start_app(0x1b, 0 * 8 + 4, esp, 1 * 8 + 4, &(task->tss.esp0));
shtctl = (struct SHTCTL *) *((int *) 0x0fe4);
for (i = 0; i < MAX_SHEETS; i++) {
sht = &(shtctl->sheets0[i]);
@@ -403,6 +407,7 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int
struct CONSOLE *cons = task->cons;
struct SHTCTL *shtctl = (struct SHTCTL *) *((int *) 0x0fe4);
struct SHEET *sht;
struct FIFO32 *sys_fifo = (struct FIFO32 *) *((int *) 0x0fec);
int *reg = &eax + 1; /* eax后面的地址*/
/*强行改写通过PUSHAD保存的值*/
/* reg[0] : EDI, reg[1] : ESI, reg[2] : EBP, reg[3] : ESP */
@@ -490,6 +495,13 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int
if (i == 3) { /*光标OFF */
cons->cur_c = -1;
}
if (i == 4) { /*只关闭命令行窗口*/
timer_cancel(cons->timer);
io_cli();
fifo32_put(sys_fifo, cons->sht - shtctl->sheets0 + 2024); /*20242279*/
cons->sht = 0;
io_sti();
}
if (i >= 256) { /*键盘数据通过任务A等*/
reg[7] = i - 256;
return 0;

28
27_day/crack7.nas Normal file
View File

@@ -0,0 +1,28 @@
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "crack7.nas"]
GLOBAL _HariMain
[SECTION .text]
_HariMain:
MOV AX,1005*8
MOV DS,AX
CMP DWORD [DS:0x0004],'Hari'
JNE fin ; 不是应用程序,因此不执行任何操作
MOV ECX,[DS:0x0000] ; 读取该应用程序数据段的大小
MOV AX,2005*8
MOV DS,AX
crackloop: ; 整个用123填充
ADD ECX,-1
MOV BYTE [DS:ECX],123
CMP ECX,0
JNE crackloop
fin: ; 结束
MOV EDX,4
INT 0x40

View File

@@ -82,7 +82,9 @@ struct TASK *task_init(struct MEMMAN *memman)
for (i = 0; i < MAX_TASKS; i++) {
taskctl->tasks0[i].flags = 0;
taskctl->tasks0[i].sel = (TASK_GDT0 + i) * 8;
taskctl->tasks0[i].tss.ldtr = (TASK_GDT0 + MAX_TASKS + i) * 8;
set_segmdesc(gdt + TASK_GDT0 + i, 103, (int) &taskctl->tasks0[i].tss, AR_TSS32);
set_segmdesc(gdt + TASK_GDT0 + MAX_TASKS + i, 15, (int) taskctl->tasks0[i].ldt, AR_LDT);
}
for (i = 0; i < MAX_TASKLEVELS; i++) {
taskctl->level[i].running = 0;
@@ -133,7 +135,6 @@ struct TASK *task_alloc(void)
task->tss.ds = 0;
task->tss.fs = 0;
task->tss.gs = 0;
task->tss.ldtr = 0;
task->tss.iomap = 0x40000000;
task->tss.ss0 = 0;
return task;