Godmode9: [Feature Request] GM9 script, 'hexget' COMMAND

Created on 5 Apr 2018  路  18Comments  路  Source: d0k3/GodMode9

'hexget' COMMAND
The 'hexget' command is used to extract hex values from a file.
The second argument is a variable that temporarily stores the hex values.
The syntax is: hexget origin@x:y variable
x: origin offset (in hex)
y: origin size, starting at x (in hex)
Both x and y must be provided
-r / --reverse the order of extracted hex values
-s / --space between each of the hex values

set HEX_VALUES ""
set DUMMY "$[GM9OUT]/dummy.bin"

fill $[DUMMY]@00:01 00
fill $[DUMMY]@01:01 01
fill $[DUMMY]@02:01 02
fill $[DUMMY]@03:01 0A

hexget $[DUMMY]@00:04 HEX_VALUES
echo $[HEX_VALUES]      # 0001020A

hexget -s $[DUMMY]@00:04 HEX_VALUES
echo $[HEX_VALUES]      # 00 01 02 0A

hexget -r $[DUMMY]@00:04 HEX_VALUES
echo $[HEX_VALUES]      # 0A020100

hexget -r -s $[DUMMY]@00:04 HEX_VALUES
echo $[HEX_VALUES]      # 0A 02 01 00

As for why, see post 159 and below. I hit a limit in GM9 scripting.

Edit - Meant post 159, not 169.

feature request

All 18 comments

Do you really need -r and -s for that? Looks quite gimmicky to me.

@d0k3 While -s may not be useful, I could definitely see -r being useful.

The -s flag, probably not. That would have been used for easier read out when using echo command.

For the -r flag, almost all the hex offsets in CIA files are read from right to left. I could do with single hex copying going backwards. I don't know how complicated programming would be for this type of command.

@d0k3 Actually, we could perhaps make -r a separate command, allowing you to reverse a string or otherwise modify it according to a set of rules.

headerexefs_fbi

The script I would be using 'hexget' modifies a title's exefs.bin by swapping out for a different icon and/or logo.

_FBI's ExeFS files hex offsets for injection purposes:_
.code = 0000000 ( 00 00 00 00 )
banner = 0004E600 ( 00 04 E6 00 )
icon = 000ACE00 ( 00 0A CE 00 )
logo = 000B0600 ( 00 0B 06 00 )

@d0k3, this request can go at the back burner. I'm not in any rush because the script in question already gets by using 'shaget' and 'chk' hoopla, albeit very slowly. It's a very niche feature for the sake of optimizing injection speed.

Edit 1 - Put spaces in between the parenthesis for better legibility.

Edit 2 - The example FBI is for visualizing how those offsets look like when viewed from a hex editor. The offset values are tailored to each title, so a script wouldn't be able to know ahead of time what those offsets are for every CIA.

Edit 3 - Small correction for the picture. ANSI highlighted areas for offsets and sizes were off, shifted by one column.

We could modify inject to allow us to inject a specific amount of data starting from a specific point instead of just injecting a whole file.

Inject command already does that with how much to inject. My issue is trying to read hex values to know where to inject.

We can't modify existing commands in a way that would introduce incompatibilities. You'll get that command in one form or another, @TurdPooCharger, but you'll have to wait for a bit.

@TurdPooCharger Oh. I hadn't realized that. Though, that suggestion is a good idea.

@SirNapkin1334, sorry for the confusion. I didn't do a good job separating the different commands in my explanation. I was trying to provide the purpose behind the requested hexget while linking it back to inject.

@d0k3, take all the time you require. Do it super leisurely. In fact, I insist you leave it out until the next or 2nd next major GodMode9 release. I would like nothing to do with GM9 scripting for a while. So long as I know that hex command is out of reach, I'll have no reason to want to code. :laughing:

Okay, I'll be closing the issue. In case you're like me, I'd gets panic attacks seeing issues stay open for too long.

Reopened :P. Yeah, we actually need a command such as that, and I want to do it shortly. This is here so we have a reminder.

Okay, this commit adds fget and fsetcommands to scripting:
https://github.com/d0k3/GodMode9/commit/4f8dfc1eaf7b4d231bd2caadbdf277a5d8061b83

Please test and tell me if that works for you.

Will need script instructions on how commands are used. I'll test the next following day. Thanks!

Edit - Noticed instructions at wAay bottom.

Update: Cooking up a new script to try out fget and fset. I could easy-peasy this, but where's the fun in that?

This might a take a while, expected release and testing results later today. Here's a preview of the script.

GodMode9 script for checking selected .cia
file against a homebrew database.

This also tests for and validates two
new GM9 script COMMANDS, 'fset' and 'fget'.

@d0k3, I think I found a bug not related to this feature request. Is there a char limitation for ' - '?

echo "d0k3"
echo "TurdPooCharger"
echo " "
echo "-" # error message fail

Edit - if you do this, it'll work

echo "CTR-N-"

@d0k3, sorry you have to simultaneously deal with this command request, the possible script char bug, and H&S injector SaveData dilemma.

I'm done with writing the test script and was about to showcase it, except I might have found a bug in one of the commands.

There's something fishy about hex 00, but I haven't quite pinpointed it. Will need more time to try reproducing the phenomena with the most simplistic, secondary test script.

fset and fget are scrutinized and receive my approval. :+1:

I was not able to reproduce the supposed bug in my original test script with this second test script. Gonna chalk it up to programming error on my part. Unless noted otherwise, I have no reason to believe the commands are the cause of something funny that happens with 00. Perhaps someone else can lend a helping set of eyes (debugging 1st original script, if you feel like it)?

This is the second test script:
fget_fset_debug.zip

Can someone else check against the 'fget' and 'fset' debug test script? There's a support hex table file that contains all hex numbers from 00 to FF. The script recreates that 1st table with an exact 2nd and 3rd tables through two different methods.

The second table is recreated individually piece-wise for all 256 hex numbers.

The third table is recreated using double endian (reversing) with sets of (0xF) 16 bytes. The -e flag is used for both fget and fset.

Both 2nd and 3rd table are hash checked against the 1st table.

Edit - ... Found the derp in original test script. Here's a snippet view of where it went wrong.

.
.
.
@HEX_TO_CHAR_CONVERTER

  if chk $[HEX_INPUT] "00"
    set CHAR_ADRESS ""
elif chk $[HEX_INPUT] "41"
    set CHAR_ADDRESS "A"
elif chk $[HEX_INPUT] "42"
    set CHAR_ADDRESS "B"
.
.
.

Edit 2 - Opps. Had to pull the debug zip archive. The directory for the script was in gm9/script. Correct folder is gm9/scripts .

Alright, so I'm assuming the feature working as intended and no bugs left (except the one you opened another issue for). If anything comes up, feel free to reopen. Gotta weed out those Github issues :).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Bolt23 picture Bolt23  路  3Comments

flarn2006 picture flarn2006  路  5Comments

zoogie picture zoogie  路  4Comments

Nemris picture Nemris  路  7Comments

TurdPooCharger picture TurdPooCharger  路  12Comments