Monday, October 18, 2010

DLL calling convention and name of the modification in


Calling convention (Calling Convention) is the programming language in order to achieve the function call and the establishment of a protocol. This agreement provides the function of the parameters of language transmission, parameters are variable and stack who deal with such issues. Different language defines different calling convention.

In C + +, in order to allow operator overloading and function overloading, C + + compilers are in accordance with certain rules rewritten for each entry point symbol name, in order to allow the same name (with different parameter types or different scope) more a usage, but it will not break the existing C-based linker. This technique is often called the name of adaptation (Name Mangling) or the name of the modification (Name Decoration). Many C + + compiler vendors chose their name modification program.

Therefore, in order to make other language modules (such as Visual Basic applications, Pascal or Fortran applications, etc.) can call C / C + + written DLL function, you must use the correct calling convention for exported functions, and do not let the compiler on the function you want to export any names modified.

1. Calling convention (Calling Convention)
Calling convention to a decision to transfer function parameters and the stack when the stack order (by the caller or callee pop the argument stack), and the compiler used to identify the name of the function name modification agreement and other issues. In Microsoft VC + + 6.0 is defined in the following several calling conventions, we will combine the assembly language to 11 of them:

1, __cdecl

__cdecl is the C / C + + and MFC programs use the default calling convention, you can also add in the function declaration to manually specify __cdecl keyword. Use __cdecl convention, the function parameters in accordance with the order from right to left stack, and call the function are the parameters from the stack to clean up the stack pop. Therefore, the realization of a variable function of the parameter can only use the calling convention. Since each function using the __cdecl convention should clean up the stack contains the code, something the size of the executable file will be bigger. __cdecl can be written as _cdecl.

The following specific examples will be analyzed through a __cdecl convention:

In VC + +, create a new Win32 Console project, named cdecl. The code is as follows:

int __cdecl Add (int a, int b); file / / function declaration

void main ()

(

Add (1,2); file / / function call

)

int __cdecl Add (int a, int b) file / / function implementation

(

return (a + b);

)

Department disassembled code function call is as follows:

; Add (1,2);

push 2; parameter stack from right to left, first pressed into 2

push 1; pressed into a

call @ ILT +0 (Add) (00401005); call the function to achieve

add esp, 8; clear from the function call stack

2, __stdcall

__stdcall calling convention used to call the Win32 API function. Agreement with __stdcal, the function parameters in accordance with the order from right to left stack, the called function returns transport parameters of the stack before the clean-up, the number of fixed-function parameters. As the body of the function itself, the number of parameters that pass came, so the called function can return to the previous instruction with a ret n pass parameters directly to clean up the stack. __stdcall can be written as _stdcall.

Or the example of the __cdecl convention replaced __stdcall:

int __stdcall Add (int a, int b)

(

return (a + b);

)

Function call Department disassembled code:

; Add (1,2);

push 2; parameter stack from right to left, first pressed into 2

push 1; pressed into a

call @ ILT +10 (Add) (0040100f); call the function to achieve

Functions is part of the anti-assembly code:

; Int __stdcall Add (int a, int b)

push ebp

mov ebp, esp




[Next]



sub esp, 40h

push ebx

push esi

push edi

lea edi, [ebp-40h]

mov ecx, 10h

mov eax, 0CCCCCCCCh

rep stos dword ptr [edi]

; Return (a + b);

mov eax, dword ptr [ebp +8]

add eax, dword ptr [ebp +0 Ch]

pop edi

pop esi

pop ebx

mov esp, ebp

pop ebp

ret 8; clear stack

3, __fastcall

__fastcall convention used for very high performance requirements of the occasion. __fastcall convention will function from the left of the first two size not larger than 4 bytes (DWORD) of the parameters are placed in ECX and EDX registers, the rest of the parameters are still stacking transmission from right to left, the called function returns transmission parameters prior to clean up the stack. __fastcall can be written _fastcall.

Is still similar to the example, then the function calling convention for the __fastcall, increase the number of function parameters 2:

int __fastcall Add (int a, double b, int c, int d)

(

return (a + b + c + d);

)

Function call part of the assembly code:

; Add (1, 2, 3, 4);

push 4; two parameters after the stack from right to left, first pressed into 4

mov edx, 3; the int type 3 into edx

push 40000000h; pressed into double type 2

push 0

mov ecx, 1; the int type 1 into ecx

call @ ILT +0 (Add) (00401005); call the function to achieve

Functions is part of the anti-assembly code:

; Int __fastcall Add (int a, double b, int c, int d)

push ebp

mov ebp, esp

sub esp, 48h

push ebx

push esi

push edi

push ecx

lea edi, [ebp-48h]

mov ecx, 12h

mov eax, 0CCCCCCCCh

rep stos dword ptr [edi]


pop ecx

mov dword ptr [ebp-8], edx

mov dword ptr [ebp-4], ecx




[Next]



; Return (a + b + c + d);

fild dword ptr [ebp-4]

fadd qword ptr [ebp +8]

fiadd dword ptr [ebp-8]

fiadd dword ptr [ebp +10 h]

call __ftol (004011b8)

pop edi

pop esi

pop ebx

mov esp, ebp

pop ebp

ret 0Ch; clear stack

Keyword __cdecl, __stdcall, and __fastcall can be added to the output of the function before, you can also build environment Setting ...-> C / C + + -> Code Generation option. Their corresponding command-line parameters are / Gd, / Gz and / Gr. The default state / Gd, that is __cdecl. When added to the output function keyword before the build environment of choice and not at the same time, a direct increase in output before the keyword function effectively.






Recommended links:



Command LINE "" and "-" symbol represents the meaning of



hp Pavilion dv6000 notebook reviews pics specs



ASF to MPG



Picked Business Databases And TOOLS



MKV to WMV



Wave of mergers BI have a happy life



Top Registry TOOLS



GIS integration OF the western expedition geographic resources



Recommend Tools And Editors



MP4 To WMP



Beijing: refused to sign the contract is terminated will receive compensation



Five-stroke Input Method Is Not Just Pole



LIVEMOTION font production: shadow word



Ali power to help her mother five years beyond the traditional media blog



Dell's green innovation-up plastic bag recycling to say "no"



Optional U disk watch "shell" scam



Sunday, October 10, 2010

MAC and IP addresses tied to theft are no longer



In network management, IP address fraudulent usage is frequent, 涓嶄粎 normal use of the network impact, and because the address of the unauthorized use of authority is often high, thus causing a large number of users of economic loss and potential security hidden. What measures have the greatest possible to avoid such phenomena happen? In order to prevent IP address theft, you can assign the proxy server IP address, the IP address and network card address binding.

For dynamic allocation IP, do a DHCP server to bind the user network card MAC address and IP address, and then set according to different IP rights. For static IP, if using three switches, you can switch ports on each IP address so limited, if someone changes their IP address, then his network was unreasonable. We are now bound for the static IP address to explain an example.

View Network Card MAC Address

Click on "Start", select "Run" and then enter winipcfg command inside, which you can find out your network card address.

Record before the proxy server, allowing network administrators to a static IP address of your Internet records and the address of the computer's network card bundle. Specific command is:

ARP-s 192.168.0.4 00-EO-4C-6C-08-75

This will be your static IP address of the Internet (assuming that 192.168.0.4) and network card address (assuming a 00-EO-4C-6C-08-75) bound with a computer, even if your IP address stolen 192.168.0.4 can not access through a proxy server. One should note that this command only in the LAN Internet proxy server useful, but also a static IP address, like normal dial-up Modem is a dynamic IP address on does not work.

ARP function of each parameter Introduction

ARP 顨?s 顨?顨?d 顨?顨?a 顨?br />
-S - to the corresponding IP address and physical address of the bundle.

-D - delete the given IP address and physical address of the bundle.

-A - Arp protocol by querying the table to display the IP address and physical address corresponding to the situation.

As a network manager, if the MAC address and IP on the binding flexibility in the use of skilled, it will create a very safe environment conducive to security risks can be greatly reduced.







相关链接:



After the way you do business You're considering?



"Mount & Blade" combat experience



World Rally 3 cheat



Beijing-Shenyang Expressway: Breaking the "separatism," the first



Launchers AND Task Managers Wizard



Ministry Of Information Industry, Dalian Today On The AVS Will Determine The Acceptance Of IPTV Comm



avi to Mp4 converter with style



MOV to MPEG4



Premier Web Servers



AVI To MOV



DivX TO 3GP



Three invincible Dharma of the Three Kingdoms 10



VIGILANCE "Fantasy Westward Journey" Daohao Trojan havoc