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

0 Members and 1 Guest are viewing this topic.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
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

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Editing EXE file to swap values
« Reply #1 on: February 17, 2021, 08:54:52 pm »
Look at OpenProcess on the MSDN
Shuwatch!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • 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

  • Forum Resident
  • Posts: 509
    • View Profile
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 »