Author Topic: Programming Megathread  (Read 145688 times)



yfw ProjectileData::onExplode keeps gunking up the project ur working on
yfw badspot made the function so complicated it takes a lingustics major in gibberish just to understand it

yfw ProjectileData::onExplode keeps gunking up the project ur working on
yfw badspot made the function so complicated it takes a lingustics major in gibberish just to understand it
for your sake bump

A question about Windows ASLR for executables modules.

Is the base address computed at module initialisation and cached? On a reboot will a new base address be computed for the module - again at initialisation?

Or

Is the base address hashed based on module attributes found in the PE header and the filesize? So that on a reboot, the base address is constant.

My observation so far: Writing to an executable causes a new base address to be computed.

This small position-independent assembly fragment jumps to the original entry point of an exectuble and solves ASLR. I wrote this originally in C++ and inline assembly but now it's an MASM file on its own. It's a nasty hackjob that I'm in the process of replacing with a runtime assembler engine. The stack stuff and conditional jumping was done in C++. It accesses the process-entry-block (PEB) via the file segment (FS) register. The PEB contains a linked list of all the loaded modules for a given process. It iterates through the loaded modules and compares each base address with a constant written into the assembly at runtime (the original entry point offset found within the PE header). I avoided using functions calls to any API to avoid having to rebuild the PE import table.

Another terrible hack is the function pointer arithmetic I did to copy that entire procedure into an array. Using two functions pointers, you can get the size in bytes of function 'A' by subtracting the succeeding function, 'B'. Undefined/Unreliable compiler behavior at its best.

Code: [Select]

« Last Edit: September 04, 2017, 02:21:30 AM by Meldaril »


There is an address computed for the base at boot time, but it is further randomized based on the order that your module gets loaded.

There is an address computed for the base at boot time, but it is further randomized based on the order that your module gets loaded.

Ok that makes sense thanks. I wasn't aware that module order had any effect.


Switching to Sublime text after years using Notepad.

yet again i am trying to into code again and yet again i forget how classes work
note: using C++ this time

yet again i am trying to into code again and yet again i forget how classes work
note: using C++ this time
Classes are the 'formal' way of making objects in C++ (the 'informal' way is via a struct). They provide slightly more functionality than structs and are written a little more verbosely. Basically you define the class and specify all the values and methods of that object.

Code: [Select]
class thingHandler
{
   public int things;
   private bool thingsAreHandled = false;
   
   public void handleThings(); // member function
}

// Constructor method
thingHandler::thingHandler(int start)
{
   things = start;
}

void thingHandler::handleThings()
{
   thingsAreHandled = true;
}

int main()
{
   thingHandler TH = new thingHandler(20);
   
   TH.handleThings();

   TH.things += 10;
}

Thanks for the corrections, Headcrab.
« Last Edit: February 16, 2017, 09:29:39 PM by Pecon »

It's been a while since I wrote any C++ so I'm not 100% sure if the 'new' declaration is right.
It would be thingHandler TH = new thingHandler(20);

Also you want the constructor declaration either inside the class, or prepended with thingHandler::. And it doesn't have any return type (not even void):

thingHandler::thingHandler(int start)
{
   things = start;
}
« Last Edit: February 16, 2017, 09:24:44 PM by Headcrab Zombie »

They provide slightly more functionality than structs

Not really. The only difference between a structure and a class is that by default, a structures members are public and it also publicly inherits it's base class.



When creating a class using new, it will not be deleted when it goes out of scope. You must delete it some point when you're finished with it, or you will leak memory.

Code: [Select]
thingHandler TH = new thingHandler(20);
TH.handleThings();
TH.things += 10;
delete TH;

You can also create your class with automatic storage duration, which will handle cleanup automatically when it goes out of scope.

Code: [Select]
thingHandler TH(20);
TH.handleThings();
TH.things += 10;

When creating a class using new, it will not be deleted when it goes out of scope. You must delete it some point when you're finished with it, or you will leak memory.
oops