¿ØÖÆ̨³ÌÐòCtrl +C Í˳ö
[DllImport("kernel32.dll",SetLastError=true)]
[return: MarshalAs( UnmanagedType.Bool )]
static extern bool AllocConsole();
[DllImport("kernel32.dll",SetLastError=true)]
[return: MarshalAs( UnmanagedType.Bool )]
static extern bool FreeConsole();
// Delegate type to be used as the Handler Routine for SCCH
delegate bool ConsoleCtrlDelegate(CtrlTypes CtrlType);
// Enumerated type for the control messages sent to the handler routine
enum CtrlTypes: uint
{
CTRL_C_EVENT=0,
CTRL_BREAK_EVENT,
CTRL_CLOSE_EVENT,
CTRL_LOGOFF_EVENT=5,
CTRL_SHUTDOWN_EVENT
}
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetConsoleCtrlHandler(ConsoleCtrlDelegate HandlerRoutine, bool Add);
private static bool ctrlHandler(CtrlTypes CtrlType)
{
if ((CtrlType == CtrlTypes.CTRL_C_EVENT) || (CtrlType == CtrlTypes.CTRL_BREAK_EVENT))
{
FreeConsole();
return true;
}
if (CtrlType == CtrlTypes.CTRL_CLOSE_EVENT)
return true;
return false;
}
Ïà¹ØÎĵµ£º
ÔÚCÓïÑÔÖУ¬staticµÄ×ÖÃæÒâ˼ºÜÈÝÒ×°ÑÎÒÃǵ¼ÈëÆç;£¬ÆäʵËüµÄ×÷ÓÃÓÐÈýÌõ¡£
£¨1£©ÏÈÀ´½éÉÜËüµÄµÚÒ»ÌõÒ²ÊÇ×îÖØÒªµÄÒ»Ìõ£ºÒþ²Ø¡£
µ±ÎÒÃÇͬʱ±àÒë¶à¸öÎļþʱ£¬ËùÓÐδ¼Óstaticǰ׺µÄÈ«¾Ö±äÁ¿ºÍº¯Êý¶¼¾ßÓÐÈ«¾Ö¿É¼ûÐÔ¡£ÎªÀí½âÕâ¾ä»°£¬ÎÒ¾ÙÀýÀ´ËµÃ÷¡£ÎÒÃÇҪͬʱ±àÒëÁ½¸öÔ´Îļþ£¬Ò»¸öÊÇa.c£¬ÁíÒ»¸öÊÇmain.c¡£
ÏÂÃæÊÇa.cµÄÄÚÈÝ
ch ......
ÎÊÌâÃèÊö£ºÒ»Ë³ÐòÎļþÖÐÖÁ¶à´æÔÚ10000000¸ö¼Ç¼£¬Ã¿Ìõ¼Ç¼¶¼ÊÇÒ»¸ö7λÕûÊý£¬Çë¶Ô´ËÎļþÖÐÊý¾Ý½øÐÐÅÅÐò¡£
ÒªÇó£º1.³ÌÐò¿ÉʹÓÃÄÚ´æÖ»ÓÐ1MB¡£2.³ÌÐòÔËÐÐʱ¼ä¾¡¿ÉÄܵĶ̡£
²¹³ä˵Ã÷£ºÃ¿¸ö¼Ç¼¶¼ÊÇÒ»¸ö7λÕýÕûÊý£¬²¢ÇÒûÓÐÆäËûµÄ¹ØÁªÊý¾Ý£¬Ã¿¸öÕûÊýÖÁ¶àÖ»ÄܳöÏÖÒ»´Î¡£
ʵÏÖ¸ÙÒª£º
ÔÚÏÖʵÖУ¬Î»Í¼ºÍλÏòÁ¿ºÜ³£¼û£¬ÎÒÃÇ¿ÉÒÔÊ¹Ó ......
1¡¢CºÍC++¹»±¿£¬±ÆµÄ³ÌÐòÔ±×Ô¼º×öºÜ¶àÊ¡£
CÆäʵ´ó¼Ò¶¼ÖªµÀ£¬ÊÇÒ»ÃÅÖеͼ¶ÓïÑÔ£¬±£ÁôÁËÖ¸ÕëµÈ»ã±àÌØÕ÷£¬Óëϵͳµ×²ã½áºÏÃÜÇС£C++ÄØ£¬¸ü¶àµÄÏò¸öObject C£¬¼´ÃæÏò¶ÔÏóµÄC¡£µ«ÕâЩ£¬Æäʵ²¢²»Äܹ»ÈóÌÐòÔ±ÏԵúÜÅ£¡£
ÎÒ¸öÈ˵ÄÀí½â£¬Ö®ËùÒÔCºÍC++³ÌÐòÔ±ÏԵúÜÅ££¬ÆäʵÔÒòºÍ´ó¼ÒÏëÏñµÄÕýºÃÏà·´£¬²»ÊÇÒòΪCºÍC++Ì«Ç¿´ó£¬¶øÊÇÕâ ......
int main()
{
printf(&unix["\021%six\012\0"], (unix)["have"] + "fun" - 0x60);
}
gcc -S±àÒë³É»ã±à´úÂëÈçÏÂ:
.file "test.c"
.section .rodata
.LC0:
&nbs ......