flat assembler
Message board for the users of flat assembler.
Index
> Windows > [Solved] Simple Shell. Need Help! Goto page 1, 2 Next |
Author |
|
revolution 07 Feb 2015, 12:42
Perhaps you can define a buffer that stores incoming keystrokes and when Enter is pressed you search your command table for a matching string.
|
|||
07 Feb 2015, 12:42 |
|
CampTheBoss 07 Feb 2015, 12:58
do you mean like using an if statement? (.if BYTE[buffer]=variableofkeyword)
I also don't know how to set a buffer up for the msvcrt function: _fgetchar, so I might need help with that. (i am new to win64/32 assembly, I came off DOS as an expert) |
|||
07 Feb 2015, 12:58 |
|
CampTheBoss 07 Feb 2015, 13:04
do you mean like using an if statement? (.if BYTE[buffer]=variableofkeyword)
I also don't know how to set a buffer up for the msvcrt function: _fgetchar, so I might need help with that. (i am new to win64/32 assembly, I came off DOS as an expert) |
|||
07 Feb 2015, 13:04 |
|
revolution 07 Feb 2015, 13:35
I mean to keep loading key presses one-by-one into a multi-byte buffer until either Enter is detected or the buffer overflows. Then in a different part of the code, after Enter has been detected, compare the contents of the buffer to a list of valid commands and act accordingly.
|
|||
07 Feb 2015, 13:35 |
|
catafest 07 Feb 2015, 14:35
I saw you put your username , I think you need to get the default user under your OS. also you can change and update your code with some specials commands like: ls , grep or awk or maybe make some default shells to your applications , like : python 2.7, 3.0 , gimp ...
This can be great. |
|||
07 Feb 2015, 14:35 |
|
CampTheBoss 07 Feb 2015, 17:51
I am adding some stuff to it using ShellExecute, so it can load web pages etc.
The only thing i want to change is the WinExec permissions file. i want to make it a configuration file (in assembly format) and the program reads it without another compile |
|||
07 Feb 2015, 17:51 |
|
CampTheBoss 07 Feb 2015, 18:35
I tried making a buffer:
Code: buff db 0,0,0,0 helpstr db 'help' looper: invoke getchar jmp makeabuff makeabuff: cmp al, 0ah je cmpstrings mov BYTE[buff],al jmp looper cmpstrings: cmp BYTE[buff], BYTE[helpstr] je good jne exit but it never compiles. why? |
|||
07 Feb 2015, 18:35 |
|
revolution 07 Feb 2015, 18:52
Your buffer is four bytes in size so your maximum command length is 4 characters.
But you need to add each keypress to the next position in the buffer. Currently you keep overwriting the first position with each incoming keypress. Also, perhaps you can review the docs for the cmps instruction (and the prefix repz) to do comparisons with memory to memory directly. You'll need the RSI, RDI and RCX registers to be properly set for that to work. |
|||
07 Feb 2015, 18:52 |
|
typedef 08 Feb 2015, 02:24
Why not just make the shell load 'cmdlets' from a folder instead of hard coding your commands?
This will give you lots of advantages because your shell will not need to load a network library when all you want to do is find a local file. Load your cmdlets when your shell loads and also have a command to reload the cmdlets on demand. Add integrity checks as well. |
|||
08 Feb 2015, 02:24 |
|
CampTheBoss 08 Feb 2015, 09:50
Do you mean like loads of includes?
And at execution time, it calls them? |
|||
08 Feb 2015, 09:50 |
|
CampTheBoss 08 Feb 2015, 13:38
How do i do it? I don't know how to load cmdlets at execution time.
|
|||
08 Feb 2015, 13:38 |
|
typedef 10 Feb 2015, 04:52
No. I mean like, take a look at CMD.EXE. It calls other console EXEs but also has few built in commands.
Now imagine if all those other system console EXEs were packaged into CMD.EXE. |
|||
10 Feb 2015, 04:52 |
|
CampTheBoss 10 Feb 2015, 07:24
typedef wrote: No. I mean like, take a look at CMD.EXE. It calls other console EXEs but also has few built in commands. Do you mean I should use ShellExecute to load other files? |
|||
10 Feb 2015, 07:24 |
|
typedef 11 Feb 2015, 13:31
I'd recommend CreateProcess so you can redirect their IO handles to the console's STDIN/OUT and wait for the processes to get their exit code and other info.
However you load them, you just gotta make sure they receive and return data to and from the console. After all, they will be console apps. |
|||
11 Feb 2015, 13:31 |
|
CampTheBoss 14 Feb 2015, 17:38
so, I should make macros and implement them into the program to test if they direct to an executable in a working directory?
|
|||
14 Feb 2015, 17:38 |
|
typedef 16 Feb 2015, 06:22
No. My point is to avoid hard coding.
Here, I just whipped up an example for you. I'd advise you to focus more on the methodology and not so much on the code. List of internal commands (hard coded): clear, time, help, exit List of external commands (EXEs in cmdlets folder): input, delete, whoami You can type all those in the shell and it will try to resolve them. You'll get the idea.
|
|||||||||||
16 Feb 2015, 06:22 |
|
typedef 16 Feb 2015, 06:51
Update
Function is_cmdlet can be optimized to this: Code: proc is_cmdlet ; if parameters, get the name part only and check if an EXE by that name exists in the 'cmdlets' folder call has_Params cmp eax, TRUE jne .no_params push szCmdletName jmp .findCmdlet .no_params: push szInput .findCmdlet: push szCmdletPathFmt push szCmdletPath call [wsprintfA] add esp, 4 * 3 ; check if cmdlet by this name exists call cmdlet_Exists .finish: ret endp |
|||
16 Feb 2015, 06:51 |
|
CampTheBoss 16 Feb 2015, 11:07
Hey, I am kind of stuck because I usually like to do all of my work in high-level code, so could I use the code you have used and optimise it?
|
|||
16 Feb 2015, 11:07 |
|
typedef 16 Feb 2015, 12:16
CampTheBoss wrote: Hey, I am kind of stuck because I usually like to do all of my work in high-level code, so could I use the code you have used and optimise it? Sure go ahead. |
|||
16 Feb 2015, 12:16 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.