Skip to content

Instantly share code, notes, and snippets.

template <typename T, typename P>
void ZGSearchWithFunctionHelperDirect(T *searchValue, bool (*comparisonFunction)(ZGSearchData *, T *, T *), ZGSearchData * __unsafe_unretained searchData, ZGMemorySize dataIndex, ZGMemorySize dataSize, ZGMemorySize dataAlignment, ZGMemorySize endLimit, P pointerSize, NSMutableData * __unsafe_unretained resultSet, ZGMemoryAddress address, void *bytes)
{
//dataIndex is 'position' in the data, endLimit is (region_size) - (datatype_size)
//dataAlignment is amount to advance dataIndex for each iteration
while (dataIndex <= endLimit)
{
if (comparisonFunction(searchData, (T *)((int8_t *)bytes + dataIndex), searchValue))
{
P memoryAddress = (P)(address + dataIndex);
template <typename T, typename P>
void ZGSearchWithFunctionHelperDirect(T *searchValue, bool (*comparisonFunction)(ZGSearchData *, T *, T *), ZGSearchData * __unsafe_unretained searchData, ZGMemorySize dataIndex, ZGMemorySize dataSize, ZGMemorySize dataAlignment, ZGMemorySize endLimit, P pointerSize, NSMutableData * __unsafe_unretained resultSet, ZGMemoryAddress address, void *bytes)
{
ZGMemorySize maxSteps = 4096;
while (dataIndex <= endLimit)
{
ZGMemorySize numberOfVariablesFound = 0;
P memoryAddresses[maxSteps];
for (ZGMemorySize stepIndex = 0; stepIndex < maxSteps && dataIndex <= endLimit; stepIndex++)
{
template <typename T, typename P>
void ZGSearchWithFunctionHelperRegular(T *searchValue, bool (*comparisonFunction)(ZGSearchData *, T *, T *), ZGSearchData * __unsafe_unretained searchData, ZGMemorySize dataIndex, ZGMemorySize dataAlignment, ZGMemorySize endLimit, P pointerSize, NSMutableData * __unsafe_unretained resultSet, ZGMemoryAddress address, void *bytes)
{
const ZGMemorySize maxSteps = 4096;
while (dataIndex <= endLimit)
{
ZGMemorySize numberOfVariablesFound = 0;
P memoryAddresses[maxSteps];
ZGMemorySize numberOfStepsToTake = MIN(maxSteps, (endLimit + dataAlignment - dataIndex) / dataAlignment);
@zorgiepoo
zorgiepoo / gist:7405858
Created November 11, 2013 00:24
Spinning progress indicator troubles, ugh
#import "ZGAppDelegate.h"
@interface ZGAppDelegate ()
@property (nonatomic) NSTimer *timer;
@property (assign) IBOutlet NSProgressIndicator *progressIndicator;
@end
@implementation ZGAppDelegate
@zorgiepoo
zorgiepoo / leaksucks.c
Created March 5, 2014 02:21
task_for_pid() leak when dev ID signed
// task_for_pid leak
// **IMPORTANT** To reproduce this bug, you have to sign this program with a developer ID -- do not use a self-signed certificate or run as root!
// This code will cause taskgated's memory usage to grow (see activity monitor)
// Link to Xcode project with included info.plist: http://tinyurl.com/kps28av
// Radar 16230826
#include <mach/mach_init.h>
#include <mach/task.h>
#include <mach/mach_port.h>
@zorgiepoo
zorgiepoo / osx_being_debugged.c
Created April 12, 2014 20:40
Detect if you're being debugged on OS X. Apple's AmIBeingDebugged() won't handle a debugger not using ptrace and is insufficient.
#include <mach/task.h>
#include <mach/mach_init.h>
#include <stdbool.h>
static bool amIAnInferior(void)
{
mach_msg_type_number_t count = 0;
exception_mask_t masks[EXC_TYPES_COUNT];
mach_port_t ports[EXC_TYPES_COUNT];
exception_behavior_t behaviors[EXC_TYPES_COUNT];
@zorgiepoo
zorgiepoo / gist:d751cba19a0167a589a2
Last active October 21, 2023 07:54
Example program for retrieving active URLs from Safari webkit processes.
#import <Foundation/Foundation.h>
// Useful references:
// -[SMProcess webKitActiveURLs] implementation used in Activity Monitor on 10.9 (search for it using Hopper)
// http://opensource.apple.com/source/WebKit2/WebKit2-7537.71/WebProcess/mac/WebProcessMac.mm
// https://github.com/rodionovd/RDProcess/blob/master/RDProcess.m
const CFStringRef kLSActivePageUserVisibleOriginsKey = CFSTR("LSActivePageUserVisibleOriginsKey");
const int kLSMagicConstant = -1;
@zorgiepoo
zorgiepoo / gist:34b9e787100572dd83c7
Created September 7, 2014 02:39
C++ destructors and ARC
#import "ZZGAppDelegate.h"
@interface Foo : NSObject
@end
@implementation Foo
- (void)dealloc
{
function xman
set lookup_name "$argv[-1]"
set lookup_section "$argv[1]"
set open_string ""
set grep_string ""
set beginning_pattern "(^|[ \t\r\n\f])"
if [ $lookup_name = $lookup_section ]; set open_string "x-man-page://$lookup_name"; set grep_string "$beginning_pattern$lookup_name\\("; end;
if [ $lookup_name != $lookup_section ]; set open_string "x-man-page://$lookup_section/$lookup_name"; set grep_string "$beginning_pattern$lookup_name\\($lookup_section\\)"; end;
@zorgiepoo
zorgiepoo / gist:5f769893ad2a7f58a747
Last active February 11, 2018 16:12
Game speed hack prototype; still WIP
#Game Speed Hack
#Increase x86-64 game by 2x by overriding mach_absolute_time
#May not work on games that call gettimeofday or something else instead
#May not work on games that don't call a time function at all (these areee badddd)
#May also not work if the function is referenced in more than one executable image (eg, local library)
#This is not very robust
from bitslicer import VirtualMemoryError, DebuggerError
import vmprot
SPEED_MULTIPLIER = 2.0