Malloc geiger is a hook for malloc that plays geiger counter blips in proportion to the amount of calls to malloc as a way of knowing what an application does

Overview

Malloc Geiger

Malloc geiger is a hook for malloc that plays geiger counter blips in proportion to the amount of calls to malloc as a way of knowing what an application does. It's largely meant as a joke so don't expect it to work properly in every situation. It only looks at malloc at this point so it won't react to any other way an application may allocate memory.

A video of malloc_geiger in action can be found here

API

The API is minimal:

// Installs the geiger clicking malloc handler
// saturation_rate, the amount of mallocs required in a cycle to max out the clicking
//
// interval the time in microseconds between each check for whether a click should be played or not.
// lower values allows more extreme rates of clicking. A good start value tends to be 10000 meaning
// a maximum of 100 clicks per second when saturating the amount of allocations
//
// The probability of a click happening in each interval is 
// min(number_of_mallocs_in_interval/saturation_rate, 1.0)
MALLOC_GEIGER_API MG_Status install_malloc_geiger(size_t saturation_rate, size_t interval);

// Uninstalls the geiger clicking malloc handler
MALLOC_GEIGER_API MG_Status uninstall_malloc_geiger();

A typical initialization looks something like this:

if(install_malloc_geiger(1000, 10000) != MG_STATUS_SUCCESS) {
    // error handling
}

This call should ideally before the application has started any other threads to make sure the patching doesn't happen while another thread is doing a call to malloc or free.

Compatiblity

malloc_geiger only works on Windows at this point. It has been tested on Win64 using visual studio 2017

Installing and Building

When you have cloned the repository you need to sync the submodules. Enter the directory you synced and run

git submodule update --init

Create and go to a directory for the build

md build
cd build

Run the cmake configuration, there is a script for doing that provided for Ninja and Release Builds installing in build/installed

../scripts/createproj.bat

Now you should be ready to build

ninja --j4 install

If everything worked you can run the test application

installed/bin/test_app.exe

Python injection

Since the library is built as a dll and does dynamic patching of the malloc functions it can be installed in a running application. If the application has a python interpreter it's an excellent vector to do the installation.

Note that this only works if the runtime libraries matches between geiger_malloc and the host application. Here is a sample script for installing it in an application

/malloc_geiger.dll") res = mg.install_malloc_geiger(1000, 10000) if res != 0: raise BaseException('Failed to install malloc geiger')">
import ctypes
mg = ctypes.windll.LoadLibrary("
    
     /malloc_geiger.dll"
    ) 
res = mg.install_malloc_geiger(1000, 10000)
if res != 0:
    raise BaseException('Failed to install malloc geiger')

Caveats

Too many to mention all. Here are some:

  • With the current setup where malloc_geiger is built as a dll it requires the application using it to use the dynamic runtime library. If using it in an application with static runtime library it needs to be linked statically.
  • It only overrides malloc, any allocation not passing through malloc is going to be missed.
  • There is a potential deadlock in the malloc functions since there is a lock in the sound code too. Have not invested time in figuring out whether it can happen and properly avoided.
  • It overrides the malloc the dll uses. If the host application uses a different runtime library you need to configure the build settings to match for it to work.
  • The replacement malloc has an additional lock and does some extra work so it affects performance negatively.
  • Probably a million other things

Credits

The application works thanks to two external libraries

gperftools

A small part of gperftools is used to override the malloc/free functions at runtime

https://github.com/gperftools/gperftools

cute_headers

The cute_sound library is used to play sounds.

https://github.com/RandyGaul/cute_headers/

Geiger sound

Cut out from a sound found at wikipedia, here are the credits for it https://upload.wikimedia.org/wikipedia/commons/5/58/Geiger_calm.ogg Snaily [CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)]

Issues
  • VS2019 missing include <memory>

    VS2019 missing include

    Compile error in Visual Studio 2019 because #include<memory> is missing in malloc_geiger.cpp.

    malloc_geiger.cpp(71,10): error C2039: 'shared_ptr': is not a member of 'std'

    opened by jamesmagnus 2
  • Video example?

    Video example?

    This is a great idea :) Would you mind creating a video example for those who don't have Windows but want to see it in action?

    Edit: Not a general solution, but I managed to use Python's tracing functionality and the mido library to output MIDI when a function is entered or exited: https://github.com/void4/tonetrace :) tracemalloc may be another library that could be used.

    opened by void4 2
Owner
David Larsson
David Larsson
Assembly HellGate implementation that directly calls Windows System Calls and displays the PPID of the explorer.exe process

Custom HellsGate Implementation Assembly HellGate implementation that directly calls Windows System Calls and displays the PPID of the explorer.exe pr

Bobby Cooke 88 Jun 20, 2022
Take Damage hook hook made to increase weapon damage, the game I made is Free Fire in version 1.65

Take-Damage Simple Take Damage hook hook made to increase weapon damage, the game I made is Free Fire in version 1.65 Bool bool isTakeDemageBool = fal

Master Games 3 Jan 1, 2022
android analysis tools, jni trace by native hook, libc hook, write log with caller's addr in file or AndroidLog

编译方法 unix like mkdir "build" cd build cmake .. -DNDK=your_ndk_path/Android/sdk/ndk/22.0.7026061 -DANDROID_ABI=armeabi-v7a make -j8 或者使用andriod studio编

pony 49 May 18, 2022
TETRIS-OS: An operating system that only plays Tetris.

TETRIS-OS: An operating system that only plays Tetris.

null 3.5k Jul 14, 2021
Plays native alert sound and shows native dialogs/alerts in your Flutter app.

flutter_platform_alert 2021 © Weizhong Yang a.k.a zonble. A simple plugin to present native alerts, including playing alert sounds and showing alert d

Weizhong Yang a.k.a zonble 52 Jun 18, 2022
VEX v5 Pro program that records driver movements and plays them back during the autonomous period.

Autonomous Recorder This code was written for team 5588R, but it can be easily modified to work with your team's robot. Notes Code isn't fully finishe

brett 2 Jun 21, 2022
AVR-based frequency counter module with I2C interface.

AVR-based Frequency Counter The AVR-based frequency counter is partly based on the project developed by Herbert Dingfelder with some extensions and mo

DoWiD 1 Feb 26, 2022
YouTube subscriber counter widget

YouTube subscriber counter My version of AlexGyver's project. My improvements Fix work with new youtube API Change subscribers displaying from 42000 t

null 1 Oct 26, 2021
Counter-Strike 1.6 Pickup Game Play for ReGameDLL_CS

CS Pick Up Game Counter-Strike 1.6 Pickup Game Play for Metamod Description This mod allows the server to run a full match without any admin to contro

Cleverson 9 Jun 26, 2022
A way to visualize your multithreaded Mbed OS application like never before!

MbedSysview Library A way to visualize your multithreaded Mbed OS application like never before! MbedSysview is a library that connects the Mbed OS ta

Jamie Smith 3 Dec 27, 2021
This was the first ever Computer Science project that I made back in Class XII (2016). I thought I should upload it on GitHub so that it does not get lost. :)

First Ever Project This was the first ever Computer Science project that I made back in Class XII (2016). I thought I should upload it on github so th

Kshitiz Srivastava 3 Jun 7, 2021
GlueGD is a mod loader for Geometry Dash that does not require a modification to any existing Geometry Dash files or an external injector or launcher.

GlueGD is a mod loader for Geometry Dash that does not require a modification to any existing Geometry Dash files or an external injector or la

Aly Cerruti 9 Apr 10, 2022
This repo does not contain any skins that work by themselves, but rather addons to already existing skins like CakeOS and Polybar

Rainmeter-addons ⚠ This repo does not contain any skins that work by themselves, but rather addons to already existing skins like CakeOS and Polybar E

null 4 Oct 17, 2021
A simple CHIP-8 emulator made for the purpose of studying computer organization, mainly how emulation does work.

CHIP8EMU A simple CHIP-8 emulator made for the purpose of studying computer organization, mainly how emulation does work. It was written in just a few

Patrick Cardoso 1 Nov 9, 2021
Filter driver which support changing DPI of mouse that does not support hardware dpi changing.

Custom Mouse DPI Driver 하드웨어 DPI 변경이 불가능한 마우스들의 DPI 변경을 가능하게 하는 필터 드라이버 경고: 해당 드라이버는 완전히 테스트 되지 않았습니다 Install 해당 드라이버는 서명이 되어있지않습니다. 드라이버를 사용하려면 tests

storycraft 3 Jun 9, 2022
Operating system project - implementing scheduling algorithms and some system calls for XV6 OS

About XV6 xv6 is a modern reimplementation of Sixth Edition Unix in ANSI C for multiprocessor x86 and RISC-V systems.

Amirhossein Rajabpour 20 May 19, 2022
A refactored Proof-of-concept originally developed in 2017 to print all function calls with their arguments data types and values using Ptrace during program execution.

print-function-args-debugger A refactored Proof-of-concept originally developed in 2017 to print all function calls with their arguments data types an

*finixbit 15 Jun 17, 2022
Obfuscate calls to imports by patching in stubs. ICO works on both X86 and X64 binaries.

ICO adds a new section into the image, then begins building stubs for each import that uses a extremely basic routine to decrypt an RVA and places them into the section.

null 34 Jun 4, 2022
Shell program written in C to implement various system calls, with support of executing commands, output redirection and signals.

Use ./shell command to start the shell. $<space>path/executable to run the executable(please specify the path without beginning it with "/"). Eg. type

Ayuj Panchal 1 Nov 15, 2021