Author Topic: Editing EXE file to swap values  (Read 180 times)

0 Members and 1 Guest are viewing this topic.

Offline NOVARSEG

  • Seasoned Forum Regular
  • Posts: 398
Editing EXE file to swap values
« on: February 17, 2021, 08:53:43 PM »
So using a hex editor :)  it is possible to find the address bytes in a QB64 EXE and swap the address of one variable with another.

This is the BAS file (complied and then edited the EXE)

It swaps A with B.  Only had to change two bytes with the editor.


DIM A AS _UNSIGNED LONG
DIM B AS _UNSIGNED LONG


GOSUB LL1
PRINT A
PRINT B


END

LL1:

A = 808530224 ' look for "0110"
B = 825373233  ' look for "1221"


RETURN

**** This is for experiment only, do not adjust your set

If anyone wants the EXE then say so
« Last Edit: February 17, 2021, 08:58:38 PM by NOVARSEG »

Offline SpriggsySpriggs

  • QB64 Developer
  • Forum Resident
  • Posts: 946
  • If you're API and you know it clap your hands
    • My GitHub
Re: Editing EXE file to swap values
« Reply #1 on: February 17, 2021, 08:54:52 PM »
Look at OpenProcess on the MSDN

Online SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3525
    • Steve’s QB64 Archive Forum
Re: Editing EXE file to swap values
« Reply #2 on: February 17, 2021, 09:00:03 PM »
Easy way is to just open your source and then: SWAP A, B
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline NOVARSEG

  • Seasoned Forum Regular
  • Posts: 398
Re: Editing EXE file to swap values
« Reply #3 on: February 17, 2021, 09:25:16 PM »
Yep that works too.


 what the unedited bytes look like in the EXE

A1 4C 2B 6B 00        'address = 6B2B4C
C7 00 30 31 31 30    '30 31 31 30 = 808530224 dec

A1 50 2B 6B 00         'address = 6B2B50
C7 00 31 32 32 31     '31 32 32 31 = 825373233 dec

****

the edited bytes

A1 50 2B 6B 00        'address = 6B2B50
C7 00 30 31 31 30    '30 31 31 30 = 808530224 dec

A1 4C 2B 6B 00         'address = 6B2B4C
C7 00 31 32 32 31     '31 32 32 31 = 825373233 dec

notice the LONGs are 4 bytes apart so there are no spaces between.
« Last Edit: February 17, 2021, 09:37:39 PM by NOVARSEG »