OpenGL Hooking ( Mac-OSX)

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

NTvalk

Hacker
Meme Tier VIP
Jul 6, 2013
499
3,108
8
I'll post some source of a way to make a game overlay in OSX (opengl). Since i could not find anything on google.
After a while I actually managed to hook functions on OSX (https://guidedhacking.com/showthread.php?4748-MAC-OSX-Hooking-(intermediate-way)), but I didn't make it stable enough yet to release the code for it, so for now I'm using https://github.com/rentzsch/mach_override , which is an excellent library, similar to detours on windows.

The function (on OSX) that is equivalent for endscene is called CGLFlushDrawable (not really equivalent but we don't care).
To test the overlay I created a small dummy program (just a green square):

C++:
-(void) drawRect: (NSRect) bounds
{
    glClearColor(0, 20, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);

	puts("now calling real puts");
	CGLContextObj ctx = 0;
	CGLFlushDrawable(ctx); // games usually call this function once a frame.
	glFlush();
	
}
And the hook (note, we inject the dylib at start-up time with DYLD_INSERT_LIBRARIES (google it)):
hook.dylib
C++:
#include "overlay.h"
#include "mach_override.h"

#include <dlfcn.h>
#include <stdio.h>
#include <unistd.h>

#include <OpenGL/OpenGL.h>

static void drawAnObject ()
{
    glColor3f(1.0f, 0.85f, 0.35f);
    glBegin(GL_TRIANGLES);
    {
        glVertex3f(  0.0,  0.6, 0.0);
        glVertex3f( -0.2, -0.3, 0.0);
        glVertex3f(  0.2, -0.3 ,0.0);
    }
    glEnd();
}

typedef void (*CGLFlushDrawable_s)(CGLContextObj ctx);
CGLFlushDrawable_s oCGLFlushDrawable;

typedef int (*puts_s)(const char*str);
puts_s oputs;

void CGLFlushDrawableOverride(CGLContextObj ctx) {
	drawAnObject();
	oCGLFlushDrawable(ctx);
}

__attribute__ ((visibility("default")))
__attribute__((constructor))
void OverlayEntryPoint()
{
	printf("attempting to hook ogl\n");
	

	if (mach_override_ptr(dlsym(RTLD_DEFAULT, "CGLFlushDrawable"), CGLFlushDrawableOverride, (void **) &oCGLFlushDrawable) != 0) 
		printf("CGLFlushDrawable override failed.");
	 else
		printf("Up running.\n");

}
drawAnObject () just draws a triangle, this is the result:

Naamloos.png

PS: I have not tried injecting at runtime yet, but this https://github.com/tpurtell/machinject/ looks promising.
 
Last edited:

c5

Kim Kong Trasher
Dank Tier VIP
Dank Tier Donator
Jul 19, 2012
1,187
12,638
76
CGLFlushDrawable = SwapBuffers?

also dlsym = GetProcAddress?
 

c5

Kim Kong Trasher
Dank Tier VIP
Dank Tier Donator
Jul 19, 2012
1,187
12,638
76
Exactly, thanks for making this clear :D
Was just checking myself, thanks for confirming. Have never touched a mac for that matter :)
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods