I'm trying to figure out how the compiler / RTS / HugoR does this, and I'm stumped

This is a discussion / support forum for the Hugo programming language by Kent Tessman. Hugo is a powerful programming language for making text games / interactive fiction with multimedia support.

Hugo download links: https://www.generalcoffee.com/hugo
Roody Yogurt's Hugo Blog: https://notdeadhugo.blogspot.com
The Hugor interpreter by RealNC: http://ifwiki.org/index.php/Hugor

Moderators: Ice Cream Jonsey, joltcountry

User avatar
Tdarcos
Posts: 9556
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

I'm trying to figure out how the compiler / RTS / HugoR does this, and I'm stumped

Post by Tdarcos »

I have the feeling the source code of all of these - Hugo Compiler, Hugo Execution (Run Time System or RTS) are either trying to hide what they are doing, or, they're trying for first prize in the obfuscated C code contest.

The book explains how the start of the executable carries certain information about the tables. So I wrote a program, using QB64 Phoenix Edition, to load a Hugo Executable and display this information. When I saw that I had correctly read the table to get the number of entries in the dictionary, and I match what the compiler said when I compiled it, I felt pretty good.

Until I got to the dictionary. I'm doing something wrong, and I'm not sure what. Okay, the dictionary is located at bytes 0x15 and 0x16 (21 and 22) in the file. The number is retrieved by taking the second byte, multiplying it by 256, and adding the first byte. Hugo uses a "segmented" address, and to get around handling files as big as 1 meg, or in any case, bigger than 32,767 or 65,536 bytes, the number is indexed to the next 16-byte segment by dividing by 16. So the prior number has to be multiplied by 16,

Okay, so far, so good. Loading the entire file into a byte array, variable Dictionary = Bytes (0x16*256)+Bytes(0x15) * 16. Going to tha address, Byte(Dictionary+1)*256 + Byte(Dictionary), I get the dictionary size. Immediately following this is a null string, a byte of 0. Now, there are 2-byte addresses for each of the dictionary entries. So I look at the first one. I tried using that as a specific byte in the file. I processed the string by using the magic constant of -0x14 applied to each byte. I know the first byte is length, but in any case, it's garbage both raw and decrypted. So I tried as a byte in the file, offset by the start of the dictionary table. Same thing, no soap. So I thought maybe the dictionary table addresses are indexed, but multiplying the address by 16 exceeds the size of the file.

So I'm not sure what I'm doing wrong. But I'll keep trying.
"When I die, I want it easy and peaceful in my sleep, like my uncle.
Not screaming and crying like his passengers."

User avatar
Tdarcos
Posts: 9556
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Re: I'm trying to figure out how the compiler / RTS / HugoR does this, and I'm stumped

Post by Tdarcos »

I even thought maybe I was supposed to add the magic constant 0x14, only that caused overflow, so that's not it. I mean, I looked at the source of the Hugo Compiler. I looked at the source of the run-time system, can't figure it out. And when I tried to read Nico's code, and I can't even begin to follow how the Hugo opcodes get executed, let alone how to decode the strings.

I'll keep looking around.
"When I die, I want it easy and peaceful in my sleep, like my uncle.
Not screaming and crying like his passengers."

User avatar
Ice Cream Jonsey
Posts: 30175
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Re: I'm trying to figure out how the compiler / RTS / HugoR does this, and I'm stumped

Post by Ice Cream Jonsey »

So I wrote a program, using QB64 Phoenix Edition, to load a Hugo Executable and display this information.
When you get a chance - no rush and no pressure - I shall gladly send you $20 if you are able to put it on Github. Or mail me the source and I'll do it and pay you. This sounds cool!
the dark and gritty...Ice Cream Jonsey!

User avatar
Tdarcos
Posts: 9556
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Re: I'm trying to figure out how the compiler / RTS / HugoR does this, and I'm stumped

Post by Tdarcos »

Ice Cream Jonsey wrote: Thu Apr 25, 2024 7:39 pm
So I wrote a program, using QB64 Phoenix Edition, to load a Hugo Executable and display this information.
When you get a chance - no rush and no pressure - I shall gladly send you $20 if you are able to put it on Github.
Ice Cream Jonsey wrote: Thu Apr 25, 2024 7:39 pmOr mail me the source and I'll do it and pay you. This sounds cool!
Done. I even cleaned up the program a little (it uses the open dialog instead of asking you to type in a file name).

https://github.com/electric-socket/HugoDecompiler

That's why I put it up now, rather than wait to fix it and turd polish it, etc. I can always use the money.

As noted in the readme, it requires QB64 Phoenix Edition to recompile it (if you want to try making changes, or play around with what it does.)

The version is 0.1.16, and SHA-256 checksums for all related files are listed.
"When I die, I want it easy and peaceful in my sleep, like my uncle.
Not screaming and crying like his passengers."

User avatar
Tdarcos
Posts: 9556
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Re: I'm trying to figure out how the compiler / RTS / HugoR does this, and I'm stumped

Post by Tdarcos »

I am calling this my "warts and all" edition. If you look at the code you'll find false starts, and tries that didn't work, pushed down in the code to try something else, lather, rinse, repeat.
"When I die, I want it easy and peaceful in my sleep, like my uncle.
Not screaming and crying like his passengers."

User avatar
Ice Cream Jonsey
Posts: 30175
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Re: I'm trying to figure out how the compiler / RTS / HugoR does this, and I'm stumped

Post by Ice Cream Jonsey »

Can you remind me again of the best address to use to PayPal you?
the dark and gritty...Ice Cream Jonsey!

User avatar
Tdarcos
Posts: 9556
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Re: I'm trying to figure out how the compiler / RTS / HugoR does this, and I'm stumped

Post by Tdarcos »

Ice Cream Jonsey wrote: Fri Apr 26, 2024 7:12 am Can you remind me again of the best address to use to PayPal you?
paul@paul-robinson.us

Thank you.

I'll let you know when the next update is released.
"When I die, I want it easy and peaceful in my sleep, like my uncle.
Not screaming and crying like his passengers."

User avatar
Ice Cream Jonsey
Posts: 30175
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Re: I'm trying to figure out how the compiler / RTS / HugoR does this, and I'm stumped

Post by Ice Cream Jonsey »

Thanks bro! Sent! I will try to try it out next week! Let me know if the payment did not reach you.
the dark and gritty...Ice Cream Jonsey!

User avatar
Ice Cream Jonsey
Posts: 30175
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Re: I'm trying to figure out how the compiler / RTS / HugoR does this, and I'm stumped

Post by Ice Cream Jonsey »

Paul -let us know if this Hugo hex dumper works for you:

the dark and gritty...Ice Cream Jonsey!

Post Reply