Ultimate Amiga

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2   Go Down

Author Topic: Poking AMOS string constants  (Read 7315 times)

0 Members and 2 Guests are viewing this topic.

Mequa

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 64
Poking AMOS string constants
« on: October 23, 2010, 12:58:39 AM »

AMOS did something amusing if you used =Varptr() to grab the address of string constants (such as A$="Hello") and tried to modify their contents using the Poke command. This also works under UAE.

I tried this on my friend Douglas back in the day, let's just say this little program didn't do quite as he expected:

A$="Douglas is a duck!"
Poke Varptr(A$)+13,Peek(Varptr(A$)+13)+2

(Caution: the above results may be offensive!)
Logged

BooBoo

  • Amiga Guru
  • A600
  • ****
  • Karma: 3
  • Offline Offline
  • Posts: 168
Re: Poking AMOS string constants
« Reply #1 on: October 24, 2010, 01:18:37 PM »

Ok I didnt even need to try this to figure it out ;D

But intresting that you can add to the value

Is there an easy way I can make A$ = A
E.g A$="22"
I wont A to equal the same as A$

I want to be able to HEX edit values of my compiled code thats why im using A$...
Logged

Mequa

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 64
Re: Poking AMOS string constants
« Reply #2 on: October 24, 2010, 03:12:35 PM »

Like this?

A$="22"
A=Val("$"+A$)
Print Hex$(A)
Logged

Mequa

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 64
Re: Poking AMOS string constants
« Reply #3 on: October 24, 2010, 04:13:47 PM »

If you want to dynamically modify a hex string in the AMOS source from within the program itself, you can try something like this:

Code: [Select]
' Hex string to be hacked (3 characters):     
A$="ABC"

Print "A$="+Chr$(34)+A$+Chr$(34)
I=Val("$"+A$) : If I>=0 and I<4096 Then Colour 1,I Else Colour 1,$A40

' Hex value to A replace A$ (prompted for demonstration):
A=$DEF : Print "Enter a new HEX value without $ (ABC): "
Input "";HEXINPUT$ : A=Val("$"+HEXINPUT$) : If HEXINPUT$="" Then End

' Grab the hex string version of A (without $):
B$=Hex$(A) : B$=Right$(B$,Len(B$)-1)
' Test if the string A$ is large enough:
If Len(A$)<Len(B$) Then Print "Error: String A$ too small!" : Bell : End

' Poke the contents into the string A$ and append spaces:
For X=0 To Len(A$)-1
   If X<Len(B$) Then P=Peek(Varptr(B$)+X) Else P=32
   Poke Varptr(A$)+X,P
Next X

' Finally get the new value as an integer and display in hex: 
A=Val("$"+A$) : Print "New value: "+Right$(Hex$(A),Len(Hex$(A))-1)
Print "A$="+Chr$(34)+A$+Chr$(34)
If A>=0 and A<4096 Then Colour 1,A Else Colour 1,$A40
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Poking AMOS string constants
« Reply #4 on: October 24, 2010, 06:41:13 PM »

There's lots of Amos-related optimizations at http://www.amigacoding.com/index.php/AMOS:Optimizing.
Logged

BooBoo

  • Amiga Guru
  • A600
  • ****
  • Karma: 3
  • Offline Offline
  • Posts: 168
Re: Poking AMOS string constants
« Reply #5 on: October 24, 2010, 06:43:13 PM »

Thanks Dude :)

A$="22"
A=Val(A$)
Seems to work fine - Well ill simply create a seperate program to edit the values of the compiled code
Logged

Mequa

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 64
Re: Poking AMOS string constants
« Reply #6 on: October 24, 2010, 07:11:20 PM »

A=Val("22") will return 22 in decimal, I believe AMOS requires A=Val("$22") for hexadecimal from string.

To convert back to string hex format use H$=Hex$(A). This will create a string beginning with $ followed by the hex values.

As for my original 2 line AMOS program above, at first it doesn't appear to do anything.
Then you return to the editor... :D
« Last Edit: October 24, 2010, 07:15:10 PM by Mequa »
Logged

Mequa

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 64
Re: Poking AMOS string constants
« Reply #7 on: October 24, 2010, 08:32:02 PM »

Here's a little demonstration: http://www.youtube.com/watch?v=ymPeBK7VskI (strong language, lol)
Logged

Lonewolf10

  • AMOS Extensions Developer
  • AMOS Dev
  • A2000
  • *****
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 618
    • http://www.aliensrcooluk.com
Re: Poking AMOS string constants
« Reply #8 on: November 12, 2010, 05:42:15 PM »


That is cool, but bad :(
You only want the string to be manipulated during the program and return to it's original state when you return to the editor. Thankfully I rarely use the Varptr function in my programs, but for those that did it would make developing programs interesting.
If you ran the program again, would the first line change to:

A$="Douglas is a huck!"

...???


Regards,
Lonewolf10

Logged

Mequa

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 64
Re: Poking AMOS string constants
« Reply #9 on: November 13, 2010, 01:17:37 PM »

Yes, and then "juck" and "luck" etc.

This could be fixed as follows:

A$="Bob is a duck!"
Poke Vartpr(A$)+9,102
Logged

Lonewolf10

  • AMOS Extensions Developer
  • AMOS Dev
  • A2000
  • *****
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 618
    • http://www.aliensrcooluk.com
Re: Poking AMOS string constants
« Reply #10 on: November 13, 2010, 05:43:55 PM »


Here's one for you (just found it today). Type the following into Direct Mode:

Print "S";pen$(4)

Then try using direct mode after that!!!

(You'll find all text is invisible after the "S" has been printed! The fix is to go back to the Editor and then return to Direct Mode)


Regards,
Lonewolf10

Logged

Mequa

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 64
Re: Poking AMOS string constants
« Reply #11 on: April 03, 2011, 10:05:32 AM »

Code: [Select]
A$="AMOS is cool"
P=Varptr(A$)
A$=A$+" indeed!"
Loke P+8,1936222580
Print A$

OK, that's a bit rude :)
But it does demonstrate AMOS's difference between string constants and string variables.
Logged

Hungry Horace

  • Amorphous Blue-Blob Man
  • Site Admin
  • A4000T
  • ******
  • Karma: 307
  • Offline Offline
  • Gender: Male
  • Posts: 3,364
  • Don't forget... Ameboid's need love too!
    • AUW
Re: Poking AMOS string constants
« Reply #12 on: April 03, 2011, 02:43:37 PM »


That is cool, but bad :(
You only want the string to be manipulated during the program and return to it's original state when you return to the editor. Thankfully I rarely use the Varptr function in my programs, but for those that did it would make developing programs interesting.
If you ran the program again, would the first line change to:

A$="Douglas is a huck!"


I've just realised, surely you could use this as a clever way of doing a program "version" string... I am forever forgetting to change mine manually, so i am tempted to write a re-usable/generic routine for this and stick it in my programs!  (even if it is incrementing on every run, it'd still be handy)
Logged
Quote from: KillerGorilla
because winuae is made of code and your amiga is made of stuff

Lonewolf10

  • AMOS Extensions Developer
  • AMOS Dev
  • A2000
  • *****
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 618
    • http://www.aliensrcooluk.com
Re: Poking AMOS string constants
« Reply #13 on: April 06, 2011, 06:54:32 PM »

I've just realised, surely you could use this as a clever way of doing a program "version" string... I am forever forgetting to change mine manually, so i am tempted to write a re-usable/generic routine for this and stick it in my programs!  (even if it is incrementing on every run, it'd still be handy)


Perhaps. I don't usually change the version string until after a major update or introduction of something bit (e.g my file selector routine).


Regards,
Lonewolf10
Logged

Hungry Horace

  • Amorphous Blue-Blob Man
  • Site Admin
  • A4000T
  • ******
  • Karma: 307
  • Offline Offline
  • Gender: Male
  • Posts: 3,364
  • Don't forget... Ameboid's need love too!
    • AUW
Re: Poking AMOS string constants
« Reply #14 on: April 06, 2011, 07:19:25 PM »

Perhaps. I don't usually change the version string until after a major update or introduction of something bit (e.g my file selector routine).

"build number" then ;)

My problem is i *never* remember to update it manually!
Logged
Quote from: KillerGorilla
because winuae is made of code and your amiga is made of stuff

Pages: [1] 2   Go Up
 

TinyPortal 2.2.2 © 2005-2022