QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Doubts, help and support about QuickBMS and other game research tools
Shokoniraya
Posts: 416
Joined: Sat Sep 15, 2018 5:22 am

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by Shokoniraya »

sir aluigi, i found two problem in QuickBMS


1) switching encryption key
it's a script to encrypt a MEMORY_FILE and looks like there a problem with switching encryption key

Code: Select all

set MEMORY_FILE1 binary "\x16"

set MEMORY_FILE3 binary "\x00"
for i = 0 < 255
goto 0 MEMORY_FILE3
get KEY_CODE byte MEMORY_FILE3
encryption xor KEY_CODE
goto 0 MEMORY_FILE3
math KEY_CODE + 1
put KEY_CODE byte MEMORY_FILE3
log MEMORY_FILE2 0 1 MEMORY_FILE1
encryption xor ""
goto 0 MEMORY_FILE2
get BLOCK byte MEMORY_FILE2
print "%BLOCK%"
next i




2) label and continue
a attached a zip file, in _export_table.bms, in line 18 there is a continue SECTION_PARSER
and also there is a label SECTION_PARSER in line 26 too, but not working at all
spiritovod
Posts: 719
Joined: Sat Sep 28, 2019 7:00 pm

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by spiritovod »

@Shokoniraya: It's just the parser script logic is invalid, because you can't jump into cycle, only outside of it, due to its variables may not be initialized at the moment (and other reasons as well).
Shokoniraya
Posts: 416
Joined: Sat Sep 15, 2018 5:22 am

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by Shokoniraya »

i found the real problem
continue not working under if-endif command

Code: Select all

math ALLOW_MODE = 1

if ALLOW_MODE = 1
continue PASSING
else
print "not allowed"
cleanexit
endif


label PASSING
if ALLOW_MODE = 1
print "allowed!"
endif


there is same problem with do-while

Code: Select all

math COUNT = 2

do
print "same number detected"
continue next_for
while COUNT != 2
cleanexit


for k = 0 < 4
label next_for
print "%k%"
next k




spiritovod, it's possible to jump into a cycle

Code: Select all

math COUNT = 0
for i = 0 < 4
math COUNT + 1
print "%COUNT%"
next i
continue next_for
cleanexit


for k = 0 < 4
label next_for
print "next for!"
print "%k%"
next k



problem is jumping out of a cycle, if-endif or do-while

Code: Select all

math COUNT = 0
for i = 0 < 4
math COUNT + 1
print "%COUNT%"
continue next_for
next i
cleanexit

label next_for
print "passed!"
spiritovod
Posts: 719
Joined: Sat Sep 28, 2019 7:00 pm

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by spiritovod »

@Shokoniraya: That's how quickbms is dealing with initializing unknown variables, but it doesn't work properly that way. You can run the script with -v option to understand it more clearly. Take a look at it's output - with normal approach "for k = 0 < 4" should get you "0 1 2 3", but in your case it will be "k 1 2 3". So you expect that K variable will be integer in the first iteration, but it's actually a string. The best advice would be not to use such expressions in any script.

But problem with jumping with "continue" from if-endif / do-while cycles is indeed exist in latest beta version (in 0.10.1 it works fine).
Last edited by spiritovod on Sun Dec 20, 2020 1:53 am, edited 1 time in total.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by aluigi »

@Shokoniraya
Regarding the Encryption doubt, the problem is that KEY_CODE is read as a number ("byte") but it's used as a string as key of Encryption.
The correct way should be: getdstring KEY_CODE 1 MEMORY_FILE3
Indeed if you use 'print "%KEY_CODE%"' it will show 0 which is the key "0" (0x30).

While for the problem of the label, honestly I don't know what should I do because I see various cycles with labels outside them.
That feature is experimental and worked well in my tests but that script is too messy :D
Shokoniraya
Posts: 416
Joined: Sat Sep 15, 2018 5:22 am

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by Shokoniraya »

thank you sir aluigi, so i have to use getdstring for key
but sure there is problem with label and continue (mybe just lebel)

and thanks for your answering, spiritovod


so i downloaded beta version right now (just want to make sure that i'm using latest version)
there is some problems with EXECUTE and two idea

idea 1) adding QUICKBMS_FOLDER to get QuickBMS exe folder
idea 2) adding a option for findloc to find exact string (WoRd != word), it can be done with binary, but useful in some cases like making a string VAR (string MY_STRING = "my stirng") or you want to find same string that readed with getdstring



i attached a zip file in this comment
there is a unicode execute folder in zip, just extract zip file same as-is (files must be under unicode execute folder for this test)
and put quickbms_4gb_files.exe where the run.bat is

so we have a #FOLDERS directory that contain some folders and a .txt file that has unicode charcters in file path
and a _temp folder
the plan is making a copy of txt file in _temp folder, but there is some problems


problem 1)
file path is "C:\my_folder\tests\unicode execute"
if file path have space in current dictionary address (path of run.bat), this error happens
'""C:\my_folder\tests\unicode' is not recognized as an internal or external command,
operable program or batch file.


and after renaming "unicode execute" from the "C:\my_folder\tests\unicode execute" to this: "unicode_execute", problem not happens

problem 2)
after testing problem 1, click on run.bat again. and file can't be fount because unicode names not working in EXECUTE and this error happens

@"C:\my_folder\tests\unicode_execute\copy.exe" "C:\my_folder\tests\unicode_execute\#FOLDERS\?¢‰è¦?C´E½\?‘“?•‡?€°?‡?.LSB_files\strings.txt" /s /e /f /y /q "C:\my_folder\tests\unicode_execute\_temp"
File not found - strings.txt
0 File(s) copied
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by aluigi »

I can check if I can add QUICKBMS_FOLDER since I have to check first if there is any multiplatform solution, but I suppose that the other options like CURRENT_FOLDER, FILE_FOLDER, BMS_FOLDER and INPUT_FOLDER may be already useful and better than knowing where quickbms.exe is located.

Findloc is already case sensitive.
In fact I think I should handle the "string" type as insensitive and "binary" as sensitive.
I guess that what you experience is a sort of collision between constant strings.

I gave a look at your script and it seems ok.
I removed the various \" because they are automatically handled by quickbms (at least in the beta).
This is the output of a test:

Code: Select all

- execute:
  @"Z:\unicode execute\unicode execute\mytest.exe" "z:\unicode execute\unicode execute\#FOLDERS\䢉覞Ǵ˽\䑓䕇ူᇪ.LSB_files\strings.txt" /s /e /f /y /q z:\output_folder

argument: 0 Z:\unicode execute\unicode execute\mytest.exe
argument: 1 z:\unicode execute\unicode execute\#FOLDERS\䢉覞Ǵ˽\䑓䕇ူᇪ.LSB_files\strings.txt
argument: 2 /s
argument: 3 /e
argument: 4 /f
argument: 5 /y
argument: 6 /q
argument: 7 z:\output_folder

Don't expect good results when using unicode with the console, probably you can run "chcp 65001" in the console before running quickbms but who knows.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by aluigi »

I found that quickbms already has an EXE_FOLDER but it was available only as variable quickbms_exe_folder when running with -v and -V (debugging).
In next beta I will add EXE_FOLDER as type for get.
Shokoniraya
Posts: 416
Joined: Sat Sep 15, 2018 5:22 am

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by Shokoniraya »

sir aluigi, i found out that i can use batch scripts in EXECUTE command
but isn't better to add a shell command in QuickBMS?
like this example

Code: Select all

get FILES long
get NAME string
shell "copy.exe file.bin folder"


it could be very useful to have a shell command, becuase EXECUTE working with cmd.exe and not useful for such cases
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by aluigi »

In theory the EXECUTE command should not even exist :)
It's dangerous to have something like that in scripts used by users but at least it works well.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by aluigi »

Ah and I guess that what you want is "cmd.exe /c copy arguments"
Shokoniraya
Posts: 416
Joined: Sat Sep 15, 2018 5:22 am

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by Shokoniraya »

danger? i understand

and just one more thing, can you please do something about MEMOEY_FILE names?
it's really messy for scripts that contain a lot of memory file
i know that i can use comment, but it's not make anything clearer for me
spiritovod
Posts: 719
Joined: Sat Sep 28, 2019 7:00 pm

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by spiritovod »

Took the time and tested, how exactly continue and break works with labels at the moment. Outside conditions and cycles they work as expected. In do and for cycles (where continue and break are expected) "continue/break label" works like simple "continue/break", that means something like this will create infinite loop in both 0.10.1 and latest beta:

Code: Select all

math COUNT = 2
do
print "%COUNT%"
continue NEXT1
math COUNT - 1
while COUNT > 0
label NEXT1

As for if condition (where continue and break are not expected), "continue label" works as expected in 0.10.1 and creates infinite loop in latest beta:

Code: Select all

math CHECK = 1
if CHECK = 1
   continue NEXT1
endif
print "Here"
label NEXT1
print "There"

Despite the feature is being experimental, I think it's clearly a bug somewhere and current behavior doesn't match with explained in papers when cycles are considered.

And about string operators descriptions, I can now explain, why latest one is more confusing. Let's take "& strchr" - in old version there is description for it "first occurrence" and clear example with operands and result. In the new version it's just result1, result2, result3 - that means you should scroll up to see operands - and no description, that means you should guess, what current operator is actually doing.
For example, if I put something like this in a documentation, would you understand, how # operator works:
[# - convertstr
"CD" # "FF" = "FFAB"]
Shokoniraya
Posts: 416
Joined: Sat Sep 15, 2018 5:22 am

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by Shokoniraya »

there is a weird problem, can't get any variable from inside a function

Code: Select all

math FIEL_NUMBER = 0
print "%FIEL_NUMBER%"
callfunction GET_NUMBER
print "%FIEL_NUMBER%"

startfunction GET_NUMBER
math FIEL_NUMBER = 1
endfunction GET_NUMBER
spiritovod
Posts: 719
Joined: Sat Sep 28, 2019 7:00 pm

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by spiritovod »

@Shokoniraya: You didn't preserve the variable, it should be "callfunction GET_NUMBER 1" in your case.
And also about memory files - I think aluigi already explained somewhere that you can create aliases after initializing them, since they can be addressed simply by numbers. Like this:

Code: Select all

log MEMORY_FILE2 0 SIZE
math NAME2 = -2
get BIN_SIZE long NAME2
findloc FOUND long BIN_SIZE NAME2 ""
Shokoniraya
Posts: 416
Joined: Sat Sep 15, 2018 5:22 am

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by Shokoniraya »

i know about MEMORY_FILE numbers, but it will be a mess if i use too much MEMORY_FILE since thety doesn't have any name
so negative file numbers specificed for MEMORY_FILE numbers, i didn't knew it at all!

Code: Select all

math NUMBER_BOX = -1
set MEMORY_FILE1 binary "\x01\x00\x00\x00"
get MY_NUMBER long NUMBER_BOX
print "%MY_NUMBER%"



and thank you so much about callfunction GET_NUMBER 1, thanks to sir aluigi
Shokoniraya
Posts: 416
Joined: Sat Sep 15, 2018 5:22 am

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by Shokoniraya »

putdstring works fine to putting a binary, but still there is limitation (null terminate) if we want to findout that two string or binary is same or not same

Code: Select all

set MEMORY_FILE1 binary "\x00\x00\x00\x00\x00\x00\x01"
set MEMORY_FILE2 binary "\x00\x00\x00\x00\x00\x00\x02"

getdstring BINARY_1 3 MEMORY_FILE1
getdstring BINARY_2 3 MEMORY_FILE2

if BINARY_1 = BINARY_2
print "equal!"
else
print "not equal!"
endif



maybe above example is just a childish for it, that is why we need a getbinary for such times, if we want to use it for such times

Code: Select all

set MEMORY_FILE1 binary "A\x00\x00\x00\x00\x00\x00\x01"
set MEMORY_FILE2 binary "a\x00\x00\x00\x00\x00\x00\x02"

getdstring BINARY_1 3 MEMORY_FILE1
getdstring BINARY_2 3 MEMORY_FILE2

if BINARY_1 = BINARY_2
print "equal!"
else
print "not equal!"
endif


this could be solved with below code, but good to have such thing to make the process faster and binary sensitive if var is a binary (readed as getbinary)

Code: Select all

set MEMORY_FILE1 binary "a\x00\x00\x00\x00\x00\x00\x01"
set MEMORY_FILE2 binary "A\x00\x00\x00\x00\x00\x00\x02"

get MEM_SIZE1 asize MEMORY_FILE1
get MEM_SIZE2 asize MEMORY_FILE2
math EQUAL_MODE = 1
if MEM_SIZE1 = MEM_SIZE2
for memory = 0 < MEM_SIZE1
get MEMORY_BYTE_1 byte MEMORY_FILE1
get MEMORY_BYTE_2 byte MEMORY_FILE2
if MEMORY_BYTE_1 != MEMORY_BYTE_2
math EQUAL_MODE = 0
endif
next memory
endif



if EQUAL_MODE = 1
print "equal!"
else
print "not equal!"
endif
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by aluigi »

The new beta has now full support for the labels.

The links are ever the same:
http://aluigi.org/beta/quickbms_exe.zip (exe)
http://aluigi.org/beta/quickbms_beta.zip (exe + source)

I used this script for testing the feature and it worked with all the NEXT* labels:

Code: Select all

label NEXT0

math COUNT = 1
do
    print "----------"
    print "0 %COUNT|x%"

    label NEXT1
    math COUNT + 1
    print "1 %COUNT|x%"

    label NEXT2
    math COUNT + 0x200
    print "2 %COUNT|x%"

    break NEXT2 # edit here

    math COUNT - 1
    print "SKIP_ME"

    label NEXT3
    math COUNT + 0x30000
    print "3 %COUNT|x%"

while COUNT > 0

print "END_OF_LOOP"

label NEXT4
print "NEXT4"

label NEXT5
print "NEXT5"


@Shokoniraya
I forgot about mentioning the solution of using variables as file number (with any name you desire), good that spiritovod remembered it :)

Regarding the other question about the comparison try using a 0 prefix for using the binary comparison.
It's a new feature of the beta introduced a coupld of months ago:

Code: Select all

if BINARY_1 0= BINARY_2


@spiritovod
I will check what I can do for the String examples, those in quickbms.txt are automatically generated by a script.
spiritovod
Posts: 719
Joined: Sat Sep 28, 2019 7:00 pm

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by spiritovod »

Great, thanks for the update. All labels and simple continue/break works fine in all combinations of encapsulated cycles now.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: QuickBMS errors [programming, scripting, quickbms.exe tool... NOT games]

Post by aluigi »

Please report any other issue, improvement, new feature you spot.
If you think the beta is ok I can release it publicly, my list of things to do/fix with quickbms is now empty.