Author Topic: Read, write execute memory demo.  (Read 353 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4873
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Read, write execute memory demo.
« on: August 29, 2017, 03:56:36 PM »
The attached file is a demo of configuring VirtualAlloc() for read, write and execute attributes and it writes 2 simple algos in decimal notation to memory then executes both to show that it works correctly. I have a tool in the testing stage that converts assembler notation code into binary which is then converted to decimal notation and when I am happy with it, I will post it.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 7633
  • Assembler is fun ;-)
    • MasmBasic
Re: Read, write execute memory demo.
« Reply #1 on: August 29, 2017, 05:48:22 PM »
Mr Hutchesson, I must remind you of the forum rules, point 3, Legality of content :eusa_naughty:

Siekmanski

  • Member
  • *****
  • Posts: 1110
Re: Read, write execute memory demo.
« Reply #2 on: August 29, 2017, 06:38:32 PM »
Mr Hutchesson, I must remind you of the forum rules, point 3, Legality of content :eusa_naughty:

 :biggrin:

Using this technique you can create optimum code in memory for each cpu type using a code preprocessor.
A good example for this is the FFT routine. Instead of having +/- 16 routines in your executable, you could create the fastest code for a specific cpu type from 1 basic routine by adjusting it in memory.
Easy aligning of the code for fast 64 byte L1 loops.
Or duplicate the FFT code in memory and adjust it to an IFFT routine. Create immediate compares, static memory pointers etc.
There are many legitimate reasons to reduce code size and speed up your code by this technique.  8)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4873
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Read, write execute memory demo.
« Reply #3 on: August 29, 2017, 08:24:02 PM »
 :biggrin:

No, there is nothing naughty in it, Marinus is right, there are many useful things that can be done with dynamically produced code, the one that immediately appealed to me was the capacity to put code in the data section and write it to memory on demand, if its not needed again you can simply overwrite it. To make life more difficult for the wannabee hackers of this world, encrypting the data section data is in fact no big deal to do and it would make it a nightmare to pull apart. If you write the code sequentially in the data section and put the pointers and length after them all, the data section becomes a jumbled mess that would be no joy to separate.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Siekmanski

  • Member
  • *****
  • Posts: 1110
Re: Read, write execute memory demo.
« Reply #4 on: August 29, 2017, 08:40:23 PM »
This technique was part of one of my previous posts, if discussing SMC was allowed on the forum.
Next cool thing would be a code parser cruncher/decruncher routine.  8)

Raistlin

  • Member
  • **
  • Posts: 246
Re: Read, write execute memory demo.
« Reply #5 on: August 29, 2017, 08:48:06 PM »
This is Lovely in-fact ! No RPC issues, No DLL deployment (for network scenarios) - and the encryption idea is brilliant if not inspired !

@hutch: THANKS LOADS, I asked you about options for remote execution & message passing previously in a pm
             - this solves some niggly problems and provides alternatives to rpc, dll etc.  Great job. :t  I'am off to write a 32-bit version :biggrin:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4873
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Read, write execute memory demo.
« Reply #6 on: August 29, 2017, 11:25:32 PM »
The only thing I would ask is don't post stuff that the cockroaches want after they come out of the woodwork.  :eusa_snooty:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Siekmanski

  • Member
  • *****
  • Posts: 1110
Re: Read, write execute memory demo.
« Reply #7 on: August 30, 2017, 12:08:51 AM »
I wouldn't dare, I hate cockroaches.  :t

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4873
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Read, write execute memory demo.
« Reply #8 on: August 30, 2017, 12:44:44 AM »
 :biggrin:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin: