Jump to content











Photo
- - - - -

[RELEASE] SectEdit.g4b hex sector editor for grub4dos


  • Please log in to reply
72 replies to this topic

#51 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 18 September 2021 - 09:52 AM

That works

So must be way that dd is copying memory?

 

I don't know, but the commands that give the error basically say:

take everything starting from offset 6 and paste it "on itself" starting from offset 12.

while the one that works says:

take everything starting from offset 6 and paste it "somewhere else", then skip 6 bytes and paste it back on the source starting at offset 12.

Maybe the (large) buffer (64 K) gets *somehow* in the way.

How small can be made the buffer?

Setting it to 1 byte :w00t: delivers the same error? (it will probably be slow as molasses).

Both approaches use anyway two dd commands, so there shouldn't be any added slowness in the second, issue might be preserving integrity of memory

All in all, since crc32 and Fn.24 are very fast, it may be "safe" to have a routine *loosely* like[1]:

crc32 (md)0x20000+2048

if %@retval%==0x6CD60AE2 echo OK, temp memory is clean && call :do_dd

call Fn.24 0x400000 0x00 1M 

 

That checks that the memory drive area is all 00's to begin with, uses it as temporary storage and then resets it to all 00's as before. :unsure:

 

The issue with this approach is what to do if the designed memory drive area is not 00's to begin with. (try with another - higher - memory address?) :dubbio:

 

:duff:

Wonko

 

 

 

[1] after having run once 

call Fn.24 0x400000 0x00 1M

crc32 (md)0x20000+2048

set /A thiscrc=%@retval%

I get

thiscrc=0x6CD60AE2



#52 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 18 September 2021 - 10:10 AM

See error report last example

https://github.com/c...4dos/issues/336

It seems the first copy works OK but the second line to copy backwards does not copy properly.

raw dd if=(md)0x3000+511 of=(md)0x3000+511 bs=1 skip=0 seek=16
raw dd if=(md)0x3000+511 of=(md)0x3000+511 bs=1 skip=16 seek=0

 

You can see the first copy must have worked because the 16 bytes were correctly copied up by 16 bytes, but then they were not overwritten at the 64K point when copying backwards.



#53 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 18 September 2021 - 12:16 PM

Yep, and since the issue happens exactly at 65536, i.e. at the 64 K buffer offset, it must mean that this latter (the buffer) is involved.

 

I checked and it seems like 64 K is the minimum size of the buffer, so a smaller size of the buffer is not a way out.

 

But what happens with a buffer greater than the whole size of the file?

 

It should work like the 0x20000 intermediate buffer. :dubbio:

 

:duff:

Wonko



#54 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 18 September 2021 - 12:52 PM

Updated script on first post.

 

Things to do:
1) remove list of variables on exit (hopefully after having found if we have too many and some can be removed/reused)

2) set the switch for skip/seek to a sensible value, 1 M or 2048 (for tests is now at 4 sectors)

 

 

Warning:

a space and some double quotes were eaten by the dog :w00t: :on the line:

if not %line24:~0,9%=="Clipboard"goto :clip_clearz

should really be:

if not "%line24:~0,9%"=="Clipboard" goto :clip_clearz

 

:duff:

Wonko



#55 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 19 September 2021 - 11:30 AM

Version 0.6 with a couple more bugs fixed and the P[R]ompt option now cleaner and allowing multiple commands in sequence.

skip/seek left at 4 sectors for the moment

 

:duff:

Wonko



#56 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 19 September 2021 - 12:01 PM

mymem not working as mymem is set to '00006000: 00'  

Latest version of grub4dos/grub4efi understands both -mem and --mem for compatibility, so suggest use...

#workaround for version of grub4dos that use -mem instead of --mem
echo -mem=0x60000=1 | set mymem=
if "%mymem:~0,4%"=="-mem" set mymem=--mem || set mymem=-mem


#57 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 19 September 2021 - 01:43 PM

 

mymem not working as mymem is set to '00006000: 00'  

Latest version of grub4dos/grub4efi understands both -mem and --mem for compatibility, so suggest use...

 

Good. :)

 

This seems "universal" though comment should be ;):





#workaround for version of grub4dos that use -mem instead of --mem AND for those versions that understand BOTH -men and --mem

Can you define exactly "Latest"?

 

BTW, as a side note, while I am far from discovering the 101 ways users will be able to break the batch, i am ahead and found the 102th ;) and 103th, in the P[R]ompt window you cannot use commands "quit" nor "exit", first one kills the batch as it wasn't started by DOS and second enters in a sort of endless loop due to pager on and debug msg=3 (needed for having the commands behave "normally".

 

Adding workaround/fixes for these two cases. 

 

:duff:

Wonko



#58 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 19 September 2021 - 01:45 PM

your original code did not work for older versions either.

Latest - latest beta grub4efi.



#59 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 19 September 2021 - 03:57 PM

your original code did not work for older versions either.

I realize it now :), actually it worked in tests until I borked it by using one less variable (and making a mess :blush:, and not re-retesting it).

 

Latest - latest beta grub4efi.

 

As always, this makes no sense whatsoever.  :frusty:

 

Is it a release?

Then it has a date.

 

and can it be found here?:

https://github.com/c...ub4dos/releases

or where?

 

How §@ç#ing difficult can it be to run:

echo -v

and post THAT info?

 

:duff:

Wonko



#60 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 19 September 2021 - 04:45 PM

Grub4efi, today's date.
It's a test version added to an issue thread on GitHub but it has other bugs, it's not a release.
But it means next release version will have same changes to echo command.

#61 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 19 September 2021 - 05:31 PM

today's date.

That is NOT anywhere in your post (that in a week will be tagged "A week ago" by our smart board software).

By quoting it the date is however "stamped" on the quote.

 

:duff:

Wonko



#62 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 20 September 2021 - 11:11 AM

New version 0.7 uploaded.

 

A few fixes, including support for the -mem/--mem and (hopefully) a "better" P[R]ompt support for commands.

 

The batch uses 37/38 variables or so.

 

I can remove some 4 of them xmin/xmax/ymin/ymax by hardcoding hex view screen limits, but I wonder if it makes sense, maybe there is one or two other ones that can be removed, but I believe that is all that can be done. 

 

:duff:

Wonko



#63 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 21 September 2021 - 05:32 PM

@Wonko,
You' re going very fast regarding new versions.

I just tested 006, generally good.

I made a typo while starting sectedit.g4b: (nd)0x19000+1. Result: reboot needed. Can be changed.

Maybe I found a typo: %%%~1 (instead %%~1). Don't know if it's a serious matter.

You're prompt is very challenging: great idea.

So far set * is not possible, but can be easily adjusted.

With some changes I can even run my text-editor in your prompt to edit your script!

If you like, I can show my changes, will cost only one sector of memory (and a few lines)

#64 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 22 September 2021 - 08:13 AM

@Wonko,
You' re going very fast regarding new versions.

I just tested 006, generally good.

I made a typo while starting sectedit.g4b: (nd)0x19000+1. Result: reboot needed. Can be changed.

Maybe I found a typo: %%%~1 (instead %%~1). Don't know if it's a serious matter.

You're prompt is very challenging: great idea.

So far set * is not possible, but can be easily adjusted.

With some changes I can even run my text-editor in your prompt to edit your script!

If you like, I can show my changes, will cost only one sector of memory (and a few lines)

Sure :).

But let's use v 0.7 as "base" for the changes.

Using set * inside the prompt (if/when made possible) is "risky" because it will reset also  the param and target variable :unsure: there would be no problems if we decide to hardcode (like now the clipboard area is) the mem drive area to (md)0x20000/0x4000000, otherwise - this is something I was thinking about in order to reduce the number of variables used - we will need to use a hardcoded sector for stroring some "invariable" variables (let's call these "constants") like the loading address.

 

:duff:

Wonko

 

P.S. OT (but not much) I tried putting together a way to check user input for dd commands (validating if= and of= values), though right now it is (intentionally) overly verbose, it seems to be working fine, but it needs some testing, attached.

 

Attached Files



#65 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 22 September 2021 - 02:31 PM

Sure :).

But let's use v 0.7 as "base" for the changes.

Using set * inside the prompt (if/when made possible) is "risky" because it will reset also  the param and target variable :unsure: there would be no problems if we decide to hardcode (like now the clipboard area is) the mem drive area to (md)0x20000/0x4000000, otherwise - this is something I was thinking about in order to reduce the number of variables used - we will need to use a hardcoded sector for stroring some "invariable" variables (let's call these "constants") like the loading address.

 

All right, I started again with version 0.7 - only this 'round' I became more 'demanding' regarding the 'Prompt'. I added some 'state of the art' features, so be warned. Of cause only suggestions from someone with a crippled mindset. :ph34r:

 

If the prompt is run in a 'setlocal/ endlocal'-sandbox, only a few changes are needed. I am using still ONE hardwired memory-sector, but very low in memory.

 

So will give following (possible) starting lines, also to rule out 'hanging' of the script after (a few) typo's.

!BAT
::clear
setlocal
debug msg=0
pager off
if "%1."=="." goto :help
set param=%1
:: Line [2] later after some additional lines. Idea: starting sector => 0x300 to have some hardwired sectors below
if not "%param:~0,6%"=="(md)0x" if not /i "%param:~0,2%"=="0x" && echo %param% is not valid && goto :eof
if "%param:~0,6%"=="(md)0x" && if not %param:~6%>=300 && echo %param% is not allowed && goto :eof
if "%param:~0,2%"=="0x" && if not %param:~2%>=60000 && echo %param% is not allowed && goto :eof
clear

BTW To make my (suggested) changes clear, I used ::-remarks, also to rem out existing lines I 'replaced'.

 

Below my lines/ changes in your call ':prompt'

:prompt
call :status 19 "Prompt command allows to quickly run one or more commands"
call :status 20 "as an example calc, blocklist or dd, but be aware that there are no checks"
call :status 21 "so possible errors produced by the command may crash the batch" 
:: Some eyes are a bit older...
call :status 22 "pressing the $[0x03][Enter]$[] key will clear the screen and allow the input of a single"
::call :status 22 "pressing the [Enter] key will clear the screen and allow the input of a single"
call :status 23 "line command that will be executed, not all commands will work or work"
call :status 24 "exactly as they do on command line but simple ones normally should."
pause --test-key
set /A ascii=%@retval%&0xFF
#Enter
if not %ascii%==0x0d goto :back_prompt
clear
:: Header hardwired
echo -n > (md)0x227+1
write (md)0x227+1 Sectedit.g4b - Current sector:$[0x03](md)$[0x03]%mdoffset%+1  $[]Memory address:$[0x03]%target%\x0D\x0A > nul
:: Start of sandbox
setlocal
pager off
:next_com
:: Optional: cleaning last output
echo -P:1900 -e \x20                                                                              $[0x00]"
echo -P:2000 -e \x20                                                                              $[0x00]"
echo -P:2100 -e \x20                                                                              $[0x00]"
:: echo -P:yyxx doesn't (seem to) update the cursor position
call Fn.5 0 21 || cat (md)0x227+1 | echo
:: Somehow 'not good': cat (md)0x227+1 | echo -P:2100 -e
::cat (md)0x227+1 | echo -P:2100 -e
::echo -e -P:2100 Sectedit.g4b - Current sector:$[0x03](md)$[0x03]%mdoffset%+1  $[]Memory address:$[0x03]%target%   
echo -P:2200 -v      
echo -P:2300 $[0x03]grub command:
call Fn.5 0 24
:: Between double-quotes more universal (and - optional: nice extra space after 'grub>')
set /p "lcmd=grub> "
::set /p lcmd=grub>
#we need to expand possible variables in command line
:: Between double-qoutes always 'good' in this case, although don't understand why expanding variables is needed
call set "lcmd=%lcmd%"
::call set lcmd=%lcmd%
:: Watch (not visible) space after 'grub> ' in next line!
echo -P:2400 -n $[0x03]grub> 
:: Problems if %lcmd% contains operators, so 'real' 'set /p'-cmd echood from History Buffer.
cat --skip=0x3EA4C2 (md)0x0+0x1F63 | echo -P:2406 -n $[0x03]
::echo -P:2400 $[0x03]grub>%lcmd%
echo
:: Inserted below..
::debug msg=3
::pager on
:: Optional
set retval=
set thiskey=
:: Optional: some 'forbidden' commands skipped
call Fn.11 "%lcmd%" "quit" && set "lcmd=%lcmd% $[]not allowed" && set forbiden=forbidden && goto :skiplcmd
call Fn.11 "%lcmd%" "exit" && set "lcmd=%lcmd% $[]not allowed" && set forbiden=forbidden && goto :skiplcmd
call Fn.11 "%lcmd%" "reboot" && set "lcmd=%lcmd% $[]not allowed" && set forbiden=forbidden && goto :skiplcmd
call Fn.11 "%lcmd%" "(md)0x227+1" && call Fn.11 "%lcmd%" "write" && set "lcmd=%lcmd% $[]not allowed" && set forbiden=forbidden && goto :skiplcmd
call Fn.11 "%lcmd%" "(md)0x227+1" && call Fn.11 "%lcmd%" "echo -n >" && set "lcmd=%lcmd% $[]not allowed" && set forbiden=forbidden && goto :skiplcmd
#we need to issue a debug msg=0 immediately after issuing the command to intercept "bad" behaviour of exit and quit (and possibly many other ones)
#I have no idea why exactly the following actually works, but as long as it works ...
:: Optional: errorcheck off ('heals' for instance crash after 'ls /file' if file not exist, but Error 30 will give unevitable a crash)
pager on
errorcheck off
debug msg=3
%lcmd% &; set retval=%@retval% && debug msg=0
errorcheck on
pager off
:: Some label needed again
:skiplcmd
#%lcmd%
:: Variable %blank% not always available anymore... Somehow last double-qoute was visible(?)
echo -e \x20                                                                              $[0x00]"
echo -e \x20                                                                              $[0x00]"
echo -e \x20                                                                              $[0x00]"
echo -e \x20                                                                              $[0x00]"
echo -e \x20                                                                              $[0x00]"
echo -e \x20                                                                              $[0x00]"
::echo -e %blank%
::echo -e %blank%
::echo -e %blank%
::echo -e %blank%
::echo -e %blank%
::echo -e %blank%
:: Some room in case of long commands...
if not exist forbiden && call Fn.5 0 19 || echo -n "Last command run: 
:: Last 'real' command echood from History Buffer
if not exist forbiden && call Fn.5 19 19 || cat --skip=0x3EA4C2 (md)0x0+0x1F63 | echo -n $[0x03]
if not exist forbiden && echo "
if exist forbiden && echo "Last command: $[0x03]%lcmd%$[]"
:: Cleaning
set forbiden=
if exist retval && echo -n "retval=%retval%"
:: Sorry for the addition, how to get a new prompt wasn't clear at first...
call Fn.5 0 24 || echo -n "Press $[0x03][End]$[] key to go back to sectedit, other key for new prompt"
::call :status 20 "retval=$[0x03]%retval%"
::call :status 19 "Last command run:$[0x03]%lcmd%"
::call :status 24 "Press $[0x03][End]$[] key to go back to sectedit"
pause --test-key > nul
set /A thiskey=%@retval%&0xFFFF > nul
#End
if not %thiskey%==0x4F00 goto :next_com
:: Leaving sandbox
endlocal
call :footer
debug msg=0
pager off
set return=:begin
:: Cleaning hardwired sector...
echo -n > (md)0x227+1
goto :eof

BTW: I didn't delete anything (hope so), but used again ::-remarks (also to rem out existing lines I 'replaced').
 

Some print-screens (first one with cleaning of last output).

 

VirtualBox_MS-DOS 7.1 small_SectEdit v0.7_mod PROMPT write (md)0x226+2 set star is allowed command, output from History Buffer XIV.png VirtualBox_MS-DOS 7.1 small_SectEdit v0.7_mod PROMPT after set with empty vars - zero logical output XVII.png VirtualBox_MS-DOS 7.1 small_SectEdit v0.7_mod PROMPT even calling sectedit by accident XVII.png VirtualBox_MS-DOS 7.1 small_SectEdit v0.7_mod PROMPT even returning from calling sectedit by accident XVIII.png VirtualBox_MS-DOS 7.1 small_SectEdit v0.6_mod PROMPT not  allowed commands XIX.png VirtualBox_MS-DOS 7.1 small_SectEdit v0.6_mod PROMPT still allowed commands XX.png

 

BTW: the print-screen with sectedit was by accident while using history - to return to 'Prompt' only Escape and one key-press was needed.

 

Thanks a lot for this (new) opportunity to play with your tremendous script. :rolleyes:

 

EDIT: typo (single-quote) at end of Header corrected (NOT in print-screens).



#66 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 22 September 2021 - 04:21 PM

Thank you :)

 

I will revise/test the modifications later, but I have a couple questions (and hopefully a couple ideas) and an explanation.

 

Question #1:

How/why did you choose (md)0x227+1?

Idea:

I mean, we have hardcoded clipboard to (md)0x1F800 (+1M) we can use (for what it costs ;)) two sectors more (2050 or 2048 is not that big an issue) and call them (md)0x1F7FE+1 the "scrap" and (md)0x1F7FF the "status" sector where we store things that need to survive.

example:

the %blank% variable is really-really a constant, it is declared at the start of the batch and never changed (unless some reckless guy runs a set * inside the prompt provision ;))

If we declare it at the beginning of the batch, then hardcode it to (md)0x1F7FF+1 at - say - offset 64, we can re-use its contents, see attached.

 

Question #2 (very little relevance if any):

Why (the heck) are you using cat --skip=0x3EA4C2 (md)0x0+0x1F63?

Idea:

I mean, isn't it easier to cat --skip=0xC2 (md)0x1F52+1?

 

Explanation:

The *need* to expand variables in lcmd is only to give a (hopefully) clearer reminder on line 19, the original idea is that when you are back on sector edit view you will see 

Last command: set myvar=36

as opposed to:

Last command: set myvar=%xpos%

Or -still say - 

Last command: echo --mem=0x400000=32

as opposed to:

Last command: echo --mem=%target%=32

but it is not at all "carved in stone" and can be changed. 

 

:duff:

Wonko

Attached Files



#67 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 22 September 2021 - 10:00 PM

@Wonko

About Question #1
Didn't really studied your hardwired clipboard, saw only it was situated below (md)0x20000. Used (md)0x227+1 as a quick solution (also indirectly ->=0x300- in the starting lines - should be modified if you want to relocate).
Studied your attachment en tested your solution in ':prompt' - possible. But such a constant will still cost you one variable.
In my text-editor I call a subroutine (:cleanline "y") for such jobs (with some extra functionality regarding y-position of cursor afterwards (everything inside setlocal / endlocal).

About Question #2
Address 0x3EA4C0 is the (documented) starting address of the History Buffer. I prefer in such cases my skip. Tested yours: good too. Length of cmd can be easily found with this address if needed. See print screen below

VirtualBox_MS-DOS 7.1 small_SectEdit v0.7_mod PROMPT echo expanded lcmd after ONE hidden doudle-quote XXII.png

About expanding variables, now I understand.
Maybe extra line? See print-screen above (extra line is preceded by ONE hidden double-quote to be sure whole content of %lcmd% is echood in case of operators - found two extra double-qoutes NOT possible somehow).

#68 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 23 September 2021 - 08:54 AM

About the blank, no, it can cost no variable, one can never define it, making it entirely hardcoded i.e. something *like* the attached. (BTW I have to review it, a space is semingly missing, it should be 80 spaces total (obviously) to cover the whole line, but 79 are enough :w00t:, the double quotes can be removed if we use \x20<-78 spaces>\x20, which is also easier to look at.

I don't know, the prompt is still only - from an interface viewpoint - "just thrown in".
We have a limited number of "status" lines, the idea is to keep them "in the same place in any case", in "sector view mode:
line 19 is reserved for expansion of hot-keys command and user input
line 20 is additional line for confirm and similar, though mostly a separator between 19 and the following 4 lines
line 21 is either 1st line of hints or empty
line 22 is either 2nd line of hints or load history
line 23 is either 3rd line of hints or save history
line 24 is either 4th line of hints hints or Clipboard status

The current use of lines 19 and 20 as "return" from P[R]ompt is only to avoid overwriting the hints/history, but of course it is only a very temporary storage as it will be overwritten at the next first command.

If I change the [H] hotkey from a two states toggle Hints/History to a three state one, Hints/History/Hic (Human issued commands ;)), we can have more space (lines 21,22,23 and 24) to hold information from the *whatever* was done in P[R]ompt.

What would be useful? Would this be "enough"? Something else that could be useful?
1) last command line issued
2) last command line with expanded variables
3) @retval
4) ?

About the param=%1 check, your approach is nice, but unfortunately not complete (not that the current solution is any good), a parameter:
/sectedit.g4b 67108864
or
/sectedit.g4b (md)131072+1
should work in theory (for those people that use decimal), currently the second works, but not the first.

Validation of user input is tough.

Douglas Adams said:
“A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.”

:duff:
Wonko
 
P.S. BTW the lines:
 
echo -e -P:2100 Sectedit.g4b - Current sector:$[0x03](md)$[0x03]%mdoffset%+1  $[]Memory address:$[0x03]%target%  
echo -P:2200 -v     
 
were put there only to make the users aware that they are inside a pseudo-prompt, maybe they can be both removed, the position of sector view can be easily seen by going back and the grub4dos version is not particularly relevant.
Is the cyano "grub command:" enough to make the screen recognizable from a "plain, direct" grub> one? :dubbio:
 
P.P.S.: about the check for dd if= and of=, at the end of the day this three liner seems to work fine (let's say good enough):
!BAT
#fileorbl2.g4b - batch to check if a parameter is a (valid) file or a device blocklist
#for dd use, i.e. full path (<device>)[/<path>/]/filename.ext or (<device>)<start>+<numblocks>
set thiswhat=%1

if "%thiswhat:~0,1%"=="/" set thiswhat=%@root%%%thiswhat%
if not "%thiswhat:~0,1%"=="(" set thiswhat=%@root%/%thiswhat%
if exist %thiswhat% echo %thiswhat%, OK. || echo %thiswhat%, NO good.

it adds device (root) if it is missing and root and the forward slash if it is missing. Of course it cannot cure stupidity but it should help avoiding some errors on load and save dialogs in sectedit.g4b.

Attached Files



#69 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 24 September 2021 - 10:14 PM

@Wonko
1) About blank hardcoded in your way, instead of %blank%: good idea.

2) About using same lines inside 'prompt' as status lines: I didn't understand this goal so far. I thought you wanted to see your cmd-history before giving a new command (in fact I first cleared the screen in my mod to have a 'normal' view. Later I returned to your 'lining'. In fact I like it now). How are the messages saved before going to 'prompt'?
In edit/ view-mode it took me a while to learn [H] is the switch between messages/ hints. So maybe highlighting status of [H], like you did for [W], or am I wrong?

3) About saving lines from 'prompt': two first seems to be enough. Sometimes commands are longer than 79 chars, so will need max four lines. 'Hic' is a nice idea. You can easily save %lcmd% while leaving the sandbox, but last 'real' command in 'prompt' must be copied with dd to a temporarily sector in memory - because of use 'set /p' too in edit/ view-mode.

4) About the param-check: not the user is the real problem, but the script. If the script hangs after a typo like mine: no good.
Maybe following is better and allows decimal numbers too (untested - sorry, not much time at the moment):

set param=
if %~d1==(md) && call Fn.11 "%~n1" "+" || if %~n1>=0x3000 && set param=%~1
if not exist param && if not %~d1==(md) && call Fn.11 "%~n1" "+" || if %~n1>=0x600000 && set /A param=%~1
if not exist param && echo 'some message' && goto :eof

EDIT: typo corrected + tested. Seems to work. 6291456 accepted, 6291455 rejected (6 * 16^5 - 1). If you want to suppress (hd (fd (rd (# in third line, some 'if not %ARG:~0,3%==(..' should be added, after setting ARG. Second line can be refined with 'set param=%~d1%~n1' instead '%~1' to simply ignore accidental path-'/'. Same in third line with '%~1n'

As you see I don't think allowing '+' is a good idea. Further I think 0x3000 is minimum (BTW choosing 0x20000 will rule out low-memory environments)

5) About header in 'prompt': I like the sector-info, grub4dos version too. Actual third line not needed, looks like 'overkill'. Colored cmd as third line is enough to realize it's not the 'normal' prompt (color is nice!).

6) About dd: I do not fully understand if in case of a block device a '+N-sectors' must be always inserted BEFORE number of sectors in second part of dialog? If yes you can use maybe the '+' too for identifying a blockdev and if not leaving %~f1 for file (needs a subroutine).

#70 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 25 September 2021 - 11:41 AM

Thanks. :)
 
I'll have a look at your ideas/suggestions.
 
I am not sure to understand your note about block devices, a block device is by definition a three-information string:
(<device>)<start offset in sectors>+<extent, length in sectors>
all three of them are needed, even if <start> can be omitted and, if it is omitted, assumed to be 0.
When you load (or save, or copy) the block device(s) involved need to be defined, particularly if the skip or seek are later used.
I mean, let's say that the batches accept "only" (hd0) as source, and that this implies a start offset of 0, then we can ask numbers of bytes to be transferred and "dimension" the blockk device accordingly, i.e. example:
User input:
Device?
(hd0)
what the batch understands:
(hd0)0+
User Input:
Number of bytes to be transferred:
245821
what the batch understands:
245821/512=480
length=480+1=481 (to take care of the rest, more properly if 245821%512>=1 set length=480+1 )
let device be (hd0)0+481
OR:
User Input:
Number of sectors to be transferred:
481
let device be (hd0)0+481
But then skip (say) comes into play:
User input:
Skip (bytes)?
815
then the device needs to be re-calculated, adding 1 or 2 sectors to it. :dubbio:
 
 

3) About saving lines from 'prompt': two first seems to be enough. Sometimes commands are longer than 79 chars, so will need max four lines. 'Hic' is a nice idea. You can easily save %lcmd% while leaving the sandbox, but last 'real' command in 'prompt' must be copied with dd to a temporarily sector in memory - because of use 'set /p' too in edit/ view-mode.

 I could use the "scrap" sector I just defined as (md)0x1F7FE+1 or mem 0x3EFFC00, it can be recovered from keyboard buffer, right? :unsure:
 
About the parameter, I thought of this (and it seems to be working, though it is probably not - yet - foolproof):

!BAT
#valparam.g4b - test batch to validate user param %1
#we want the parameter to be any of:
#1) a valid (md) device of the particular kind of (md)<start>+1
#2) a hex memory address
#3) a decimal memory address
# and nothing else

setlocal
set /a param=%1
if %param%==0 set param=%1
#here param is 0 if the %1 is *whatever* but a valid hex or decimal number
if "%param:~0,4%"=="(md)" if "%param:~-2,2%"=="+1" set /a param=%param:~4% -1 * 512
#here we can put some limits, let's say (md)0x300=0x60000=393216 and (md)0x30000=0x6000000=100663296
checkrange 0x60000:0x6000000 calc %param% && echo OK. valid number && goto :memaddress 
echo if we get here there is a problem %param% is not valid
goto :eof


:memaddress
set /A memadd=%param%
echo OK, we are at mem address %memadd%
goto :eof
:duff:
Wonko

#71 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 26 September 2021 - 08:45 PM

I am not sure to understand your note about block devices, a block device is by definition a three-information string:
(<device>)<start offset in sectors>+<extent, length in sectors>
all three of them are needed, even if <start> can be omitted and, if it is omitted, assumed to be 0.
When you load (or save, or copy) the block device(s) involved need to be defined, particularly if the skip or seek are later used.
I mean, let's say that the batches accept "only" (hd0) as source, and that this implies a start offset of 0, then we can ask numbers of bytes to be transferred and "dimension" the blockk device accordingly, i.e. example:
User input:
Device?
(hd0)
what the batch understands:
(hd0)0+
User Input:
Number of bytes to be transferred:
245821
what the batch understands:
245821/512=480
length=480+1=481 (to take care of the rest, more properly if 245821%512>=1 set length=480+1 )
let device be (hd0)0+481
OR:
User Input:
Number of sectors to be transferred:
481
let device be (hd0)0+481
But then skip (say) comes into play:
User input:
Skip (bytes)?
815
then the device needs to be re-calculated, adding 1 or 2 sectors to it. :dubbio:

 

Thnx, I understand better now. In last version I tested (hd0) or (hd0)0 was rejected, only full block-device or file-on-disk. I had only the simple-minded idea to use the '+' in that case to identify the block-device instead of not-'/'.

 

 

 
 I could use the "scrap" sector I just defined as (md)0x1F7FE+1 or mem 0x3EFFC00, it can be recovered from keyboard buffer, right? :unsure:

 

Yes, just copy the right amount of bytes from the History Buffer if you want to use not-expanded %lcmd% outside of 'prompt' (first two bytes on 0x3EA4C0 = length of cmd - see print-screen three days ago):

 

 

About the parameter, I thought of this (and it seems to be working, though it is probably not - yet - foolproof):

!BAT
#valparam.g4b - test batch to validate user param %1
#we want the parameter to be any of:
#1) a valid (md) device of the particular kind of (md)<start>+1
#2) a hex memory address
#3) a decimal memory address
# and nothing else

setlocal
set /a param=%1
if %param%==0 set param=%1
#here param is 0 if the %1 is *whatever* but a valid hex or decimal number
if "%param:~0,4%"=="(md)" if "%param:~-2,2%"=="+1" set /a param=%param:~4% -1 * 512
#here we can put some limits, let's say (md)0x300=0x60000=393216 and (md)0x30000=0x6000000=100663296
checkrange 0x60000:0x6000000 calc %param% && echo OK. valid number && goto :memaddress 
echo if we get here there is a problem %param% is not valid
goto :eof


:memaddress
set /A memadd=%param%
echo OK, we are at mem address %memadd%
goto :eof

I tested these lines. Just a number is good, for instance: 0x600000 - typo's like 0c600000 rejected. Parameter (md)0x3000+1 is accepted too, typo (nd)0x3000+1 rejected.

 

But just (md)0x3000 is now rejected. Is that what you want?



#72 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 27 September 2021 - 09:12 AM

Thnx, I understand better now. In last version I tested (hd0) or (hd0)0 was rejected, only full block-device or file-on-disk. I had only the simple-minded idea to use the '+' in that case to identify the block-device instead of not-'/'.

 

 

Yes, just copy the right amount of bytes from the History Buffer if you want to use not-expanded %lcmd% outside of 'prompt' (first two bytes on 0x3EA4C0 = length of cmd - see print-screen three days ago):

 

 

I tested these lines. Just a number is good, for instance: 0x600000 - typo's like 0c600000 rejected. Parameter (md)0x3000+1 is accepted too, typo (nd)0x3000+1 rejected.

 

But just (md)0x3000 is now rejected. Is that what you want?

Yes, in my (perverted) mind (md)0x3000 is only the incipit of a sector that is properly called (md)0x3000+1.

While when we access memory we indicate a starting address (and that's it) when we access a block device we open its first sector, i.e. (md)<start>+1, the idea was to validate parameters that are also correct in generic grub4dos "speak".

 

BUT, this said, nothing prevents us from re-adding the +1 if missing, i.e. inserting a check *like*:

call Fn.11 "%param%" "+"

if %@retval%==0 if "%param:~0,4%"=="(md)" set param=%param%+1

!BAT
#valparam.g4b - test batch to validate user param %1
#we want the parameter to be any of:
#1) a valid (md) device of the particular kind of (md)<start>+1 but we accept also (md)<start>
#2) a hex memory address
#3) a decimal memory address
# and nothing else

setlocal
set /a param=%1
if %param%==0 set param=%1
#here param is 0 if the %1 is *whatever* but a valid hex or decimal number
call Fn.11 "%param%" "+"
if %@retval%==0 if "%param:~0,4%"=="(md)" set param=%param%+1
if "%param:~0,4%"=="(md)" if "%param:~-2,2%"=="+1" set /a param=%param:~4% -1 * 512
#here we can put some limits, let's say (md)0x300=0x60000=393216 and (md)0x30000=0x6000000=100663296
checkrange 0x60000:0x6000000 calc %param% && echo OK. valid number && goto :memaddress 
echo if we get here there is a problem %param% is not valid
goto :eof


:memaddress
set /A memadd=%param%
echo OK, we are at mem address %memadd%
goto :eof

:duff:

Wonko



#73 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 04 October 2021 - 01:31 PM

New version 0.8 released.

Hopefully including most of the fixes discussed.

 

@deomsh

After a few tests, the sandbox fixes just fine "quit" and "exit", if some users want to run inside the P[R]ompt "reboot" or "halt", they are still allowed to, they should know the consequences of their choices.

 

The call Fn.11 for "reboot" and "halt" would prevent users from issuing common :dubbio: commands such as:

 

echo $[0x0F]reboot.pro rulez

 

or

 

echo The asphalt that was laid on the road the day before yesterday is unexpectedly  porous.[1]

 

More seriously, if you think it "safer", maybe "reboot[space]" and "halt[space]" can be re-added :unsure: (but still no asphalt related comments, while asphalt-related ones would still be possible ;)).

 

:duff:

Wonko

 

 

 

[1] Which I believe comes near "My postilion has been struck by a lightning" in good ol' English conversation manuals






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users