(Translation) Win32ASM tutorial -10

zhaozj2021-02-16  54

11.0 Assembly Foundation in Windows

Now you have some basic knowledge of assembly language, you will learn how to learn compilation in Windows.

10.1API

Windows programming is based on Windows API, the application interface. This is a set of functions provided by the operating system. Each Windows programmer must use these functions. These functions are in system DLL like Kernel, User, GDI, Shell, Advapi, and so on. There are two types of functions: ANSI and Unicode. This is related to the storage method of the string. In an ANSI, each byte represents a symbol (ASCI code) and represents a null-terminated) with byte 0. Unicode uses a wide character format. Each byte is 2 bytes. This allows us to use like many characters such as Chinese. The wide string is over two 0 bytes. Windows supports ANSI and Unicode by using different function names.

E.g:

MessageBoxa (suffix a means ansi) MessageBoxw (suffix w is a wide character - UNICODE)

We only use the ANSI type

11.2 Import DLL

To use functions from WindowsAPI, you need to import DLL. This is done by the import library (.lib). These libraries are required. Because they enable the system (Windows) to load DLLs at the Dynamic foundation address of the memory. Most standard DLL libraries are available in Win32ASM.cjb.net. You can load a library with MASM's INCLUDELIB statement.

Translator Note: Note that Win32asm.cjb.net seizes IP by China Telecom. Access Please use the agent.

IncludeLib C: /masm32/lib/kernel32.lib

This will load the library kernel32.lib. In the example, in this format:

INCLUDELIB /MASM32/LIB/kernel32.lib

Now you can see why the assembly source file is to be in the same area of ​​MASM. You can compile your program on other computers without changing the path to the correct area.

But you don't just need to contain libraries. The included file (.inc) is also necessary. These can be automatically generated by the L2INC tool by the library file. Contains files to load:

INCLUDE /MASM32/INCLUDE / WANEL32.INC

In included files, define prototypes in DLL, so you can use Invoke.

Kernel32.inc:...MessageBoxa Proto Stdcall: DWORD,: DWORD,: DWORD,: DWORDMESSAGEBOX TEXTEQU ...

You can see functions with for Ansi in the file and no 'a' 'function name is defined as with the real function name: you can use MessageBox to use MessageBoxa. After you contain libraries and contain files, you can use the function:

Invoke Messagebox, Null, Addr Msgtext, Addr Msgtitle, NULL

11.3 Windows contains files

Here has a special containment file. Most of the time is collectively referred to as Windows.inc, which includes all constants and structures for Windows APIs. For example, the message box has different styles. The fourth parameter of the function is the style. NULL refers to MB_OK, it has only one OK button. Windows contains files with definitions of these styles:

MB_OK EQU 0MB_OKCANCANCEL EQU ... MB_YESNO EQU ... so you can use these names as constants:

Invoke Messagebox, Null, Addr Msgtext, Addr Msgtitle, MB_YESNO

Example will use the included file in the MASM package:

INCLUDE /MASM32/INCLUDE/Windows.inc

11.4 framework

.486.Model flat, stdcalloption casemap: noneincludelib /masm32/lib/kernel32.libincluder32.libincludelib /masm32/lib/gdi32.lib

Include /masm32/include/kernel32.incinclude /masm32/include/user32.include /masm32/include/gdi32.incinclude /masm32/include/windows.inc

.DATA

Blahblah

.code

Start:

Blahblah

End Start

This is the basic framework of Windows assembly source file (.asm)

.486

Tell whites should generate 486 processors (or higher) pseudo code. You can use .386, but most cases .486

.Model flat, stdcall

Use flat memory mode (discussed in the previous chapter) and use STDCALL call habits. It means that the parameters of the function are pressed from right left (the last parameter first press) and the function is clear at the end. This is a standard for almost all Windows API functions and DLLs.

Option CaseMAP: NONE

The mapping of the control character is uppercase. For the Windows.inc file, it will work normally, this should be "none"

Includelib

Previous discussion

Include

The previous discussion

.DATA

Start Data section (see the previous chapter)

.code

Start the Code section (see the previous chapter)

START: End Start represents the start of a program. It is not a "start". You can use any and "end" statements after the same tag: startofprog: End Startofprog

转载请注明原文地址:https://www.9cbs.com/read-26626.html

New Post(0)