Writing some of the underlying programs that involve system features, especially shellcode, inevitably takes the form of writing assembly code directly.
In the target platform for the x86 model, you can directly use the inline assembly, which many people are more familiar with, but also very convenient.
But when the target platform is x64, Microsoft no longer allows the direct inline assembly, which has caused some inconvenience to our programming.
How to solve this problem? One option is to use the Intel compiler, which still supports inline assembly.
Another approach is to use VS, but not inline, you need to separate the assembly into an ASM file, and then reference it in other source files.
I refer to some of the online instructions, the process here to write more detailed, convenient for themselves, but also convenient for others.
Main process:
I. Writing function functions separately in ASM files
For example, to implement a 64-bit addition function, the prototype is as follows:
ULONG64 Myadd (ULONG64 u1,ulong64 U2);
Then create a new file and write the following:
. Codemyadd PROC add rcx,rdx mov rax,rcx ret Myadd Endpend
Save the above content as myadd.asm and add it to the project.
In other source files that need to reference the function, add the following declaration:
#include"stdafx.h"#include<windows.h>//declaring a reference to an external functionextern_c ULONG64 myadd (ULONG64 u1,ulong64 U2);int_tmain (intARGC, _tchar*argv[]) {ULONG64 result= Myadd (0x111111111,0x333333333); printf ("result = 0x%i64x\n", result); return 0;}
second, set the ASM file generation mode
Right-click on the ASM file and select "Properties":
Then click "General" on the left, "Exclude from Build" select "No", "Item Type" SELECT "Custom Build Tool", then click Apply.
The entry for custom build tool appears under general.
Click on it, set "command line" to ml64/fo $ (IntDir)% (filename). obj/c% (filename). asm
Set the output to $ (IntDir)% (fileName). obj, which must be configured, otherwise vs thinks that the file does not set the output and will not process it, and it also tells the linker where to find the obj file.
The above $ (INTDIR) is a macro that represents the directory of the current build configuration, such as "X64\debug".
After the above configuration, the ASM file compilation generated obj file is automatically generated to the corresponding configured directory.
Third, the generation of engineering
Once the configuration is complete, you will be able to generate the project happily. The normal output results are as follows:
1>------Started Build: Project: Testasm, configuration: Release x64------1> Build Start Time is ./4/Ten 9: $: $. 1>Initializebuildstatus:1>"X64\release\testasm.unsuccessfulbuild" is being created because "AlwaysCreate" is specified. 1>custombuild:1> performing Custom Build tools1> assembling:myadd.asm1> Microsoft (R) Macro assembler (x64) Version 10.00.40219.011> Copyright (C) Microsoft Corporation. All rights reserved.1>1>Clcompile:1>Stdafx.cpp1>Testasm.cpp1>Link:1>Generating Code1>build of completed code1> testasm.vcxprojF:\x64Program\testasm\x64\Release\testasm.exe1>Finalizebuildstatus:1>deleting file "X64\release\testasm.unsuccessfulbuild". 1>A Touch task is being performed on "X64\release\testasm.lastbuildstate". 1>1>The build succeeded. 1>1> Used Timexx:xx:01.11========== Generation: Success1One, failure0A, Latest0One, skip0A ==========
If nothing happens, it will be a success. If you write an ASM file with errors, you can also see the corresponding prompt in the output, to get rid of the error.
At this point, we can use the assembly happily again ~
Specific methods for compiling x64 compilation in VS2010