Created the Thursday 29 April 2021. Updated 1 year, 7 months ago.

The function LocalSize retrieves the current size of the specified local memory object, in bytes. By setting the hMem parameters with 0 will trigger an exception in a debugger that can be used as an anti-debugging mechanism.

Technique Identifier


Technique Tag


Code Snippets

#include <iostream>
#include <windows.h>

using namespace std;

int main()
	SIZE_T s;
	printf("Starting the LocalSize()\n");
	for (int i = 0; i < 0xFFF; i++){
	    s = LocalSize(0);
	printf("Sempai! :) \n");
	return 0;

Detection Rules

rule Detect_LocalSize: AntiDebug {
        description = "Detect LocalSize as anti-debug"
        author = "Unprotect"
        comment = "Experimental rule"
        $1 = "LocalSize" fullword ascii
       uint16(0) == 0x5A4D and filesize < 1000KB and $1
    name: trap debugger with localsize
    namespace: anti-analysis/anti-debugging
    author: lordtmk@protonmail.com
    scope: basic block
      - B67E5B1985742F62785122B637EF4FBD:0x4B1F5B
    - and:
      - api: LocalSize
      - mnemonic: push 
      - number: 0

Additional Resources

External Links

Subscribe to our Newsletter

The information entered into this form is mandatory. It will be subjected to computer processing. It is processed by computer in order to support our users and readers. The recipients of the data will be : contact@unprotect.it.

According to the Data Protection Act of January 6th, 1978, you have at any time, a right of access to and rectification of all of your personal data. If you wish to exercise this right and gain access to your personal data, please write to Thomas Roccia at contact@unprotect.it.

You may also oppose, for legitimate reasons, the processing of your personal data.