.


:




:

































 

 

 

 


VirtualAlloc .

.

2. ASCII ( 128 255).

3. , 10 - .

 

 

1. Delphi7 .

Delphi7 :

 

Form1 - Virtual Memory;

Button1 - SysInfo;

Button2 - GlobalMemorySatus;

Button3 - VirtualQuery;

Button4 - VirtualAlloc;

Button5 - VirtualFree;

Button6 - ;

Button7 - VirtualProtect;

Button8 - ;

ComboBox1 - ;

Edit1 - ;

Edit2 - ;

Label1 - ;

Label2 - ;

Label3 - ;

Label4 - ;

Memo1 - ;

Memo2 - ;

 

2. ASCII ( 128 255).

 

. asm. (AS.asm). TASM () tasm.exe. .

AS.asm : TASM.EXE /zi AS,,,. AS.obj, AS.lstlist, AS.crf. - . ..

tlink.exe tlink.exe /v AS.obj. . AS.exe. , : /m/cmd.exe, C:\Document and Settings\User>chdir C:\tasm\bin, C:\tasm\bi>AS.exe, .

 

3. 10 hello,world!

 

. asm. (hw10.asm). TASM () tasm.exe. .

hw10.asm : TASM.EXE /zi hw10,,,. HW10.obj, HW10.lstlist, HW10.crf. - . ..

tlink.exe tlink.exe /v HW10.obj. . HW10.exe. , : /m/cmd.exe, C:\Document and Settings\User>chdir C:\tasm\bin, C:\tasm\bi>HW10.exe, 10 hello,World!.

 

 


1 ( 1)

 

unit Unit1;

 

interface

 

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls;

 

type

TForm1 = class(TForm)

Button1: TButton;

Button2: TButton;

Button3: TButton;

Button4: TButton;

Button5: TButton;

Button6: TButton;

Label1: TLabel;

Edit1: TEdit;

Memo1: TMemo;

ComboBox1: TComboBox;

Label2: TLabel;

Button7: TButton;

Label3: TLabel;

Label4: TLabel;

Edit2: TEdit;

Button8: TButton;

Memo2: TMemo;

procedure FormActivate(Sender: TObject);

procedure Button1Click(Sender: TObject);

procedure Button2Click(Sender: TObject);

procedure Button3Click(Sender: TObject);

procedure Button4Click(Sender: TObject);

procedure Button5Click(Sender: TObject);

procedure Button6Click(Sender: TObject);

procedure Button7Click(Sender: TObject);

procedure Button8Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

 

var

Form1: TForm1;

p: pointer;

 

implementation

 

{$R *.dfm}

 

procedure TForm1.FormActivate(Sender: TObject);

begin

Memo1.Clear;

Memo2.Clear;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

var // SysInf: TSystemInfo;

SysInf: SYSTEM_INFO;

begin

GetSystemInfo(SysInf);

Memo1.Clear;

Memo1.Lines.Add(' : '+IntToStr(SysInf.dwPageSize)+' ');

Memo1.Lines.Add(': '+IntToStr(SysInf.wProcessorArchitecture));

Memo1.Lines.Add(': '+IntToStr(SysInf.wReserved));

Memo1.Lines.Add(' : '+IntToStr(SysInf.dwNumberOfProcessors));

Memo1.Lines.Add(' : '+IntToStr(SysInf.dwActiveProcessorMask));

Memo1.Lines.Add(' : '+IntToStr(SysInf.dwProcessorType));

Memo1.Lines.Add(' : '+IntToStr(SysInf.dwAllocationGranularity));

Memo1.Lines.Add(' : '+IntToStr(SysInf.wProcessorLevel));

Memo1.Lines.Add(' : '+IntToStr(SysInf.wProcessorRevision));

end;

 

procedure TForm1.Button2Click(Sender: TObject);

var // ms: MEMORYSTATUS;

ms: TMEMORYSTATUS;

begin

ms.dwLength:=SizeOf(MEMORYSTATUS);

GlobalMemoryStatus(ms);

Memo1.Clear;

Memo1.Lines.Add(' : '+IntToStr(ms.dwMemoryLoad));

Memo1.Lines.Add(' : '+IntToStr(ms.dwTotalPhys)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwAvailPhys)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwTotalPageFile)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwAvailPageFile)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwTotalVirtual)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwAvailVirtual)+' ');

end;

 

procedure TForm1.Button3Click(Sender: TObject);

var // mbi: MEMORY_BASIC_INFORMATION;

mbi: TMemoryBasicInformation;

dwRez: DWORD;

begin

If Edit1.GetTextLen<=0 then

ShowMessage(' ')

else

begin

dwRez:=VirtualQuery(pointer(StrToInt(Edit1.Text)),mbi,sizeof(MEMORY_BASIC_INFORMATION));

Memo1.Clear;

Memo1.Lines.Add(' : '+IntToStr(integer(mbi.BaseAddress)));

Memo1.Lines.Add(' : '+IntToStr(integer(mbi.BaseAddress)));

case mbi.AllocationProtect of

0: Memo1.Lines.Add(' ');

PAGE_NOACCESS: Memo1.Lines.Add(' : PAGE_NOACCESS');

PAGE_READONLY: Memo1.Lines.Add(' : PAGE_READONLY');

PAGE_READWRITE: Memo1.Lines.Add(' : PAGE_READWRITE');

PAGE_EXECUTE: Memo1.Lines.Add(' : PAGE_EXECUTE');

PAGE_EXECUTE_READ: Memo1.Lines.Add(' : PAGE_EXECUTE_READ');

PAGE_EXECUTE_READWRITE: Memo1.Lines.Add(' : PAGE_EXECUTE_READWRITE');

PAGE_WRITECOPY: Memo1.Lines.Add(' : PAGE_WRITECOPY');

PAGE_EXECUTE_WRITECOPY: Memo1.Lines.Add(' : PAGE_EXECUTE_WRITECOPY');

end;

Memo1.Lines.Add(' : '+IntToStr(mbi.RegionSize)+' ');

case mbi.State of

MEM_COMMIT: Memo1.Lines.Add(' : MEM_COMMIT');

MEM_RESERVE: Memo1.Lines.Add(' : MEM_RESERVE');

MEM_FREE: Memo1.Lines.Add(' : MEM_FREE');

end;

case mbi.Protect of

0: Memo1.Lines.Add('');

PAGE_NOACCESS: Memo1.Lines.Add(' .: PAGE_NOACCESS');

PAGE_READONLY: Memo1.Lines.Add(' : PAGE_READONLY');

PAGE_READWRITE: Memo1.Lines.Add(' : PAGE_READWRITE');

PAGE_EXECUTE: Memo1.Lines.Add(' : PAGE_EXECUTE');

PAGE_EXECUTE_READ: Memo1.Lines.Add(' : PAGE_EXECUTE_READ');

PAGE_EXECUTE_READWRITE: Memo1.Lines.Add(' : PAGE_EXECUTE_READWRITE');

PAGE_WRITECOPY: Memo1.Lines.Add(' : PAGE_WRITECOPY');

PAGE_EXECUTE_WRITECOPY: Memo1.Lines.Add(' : PAGE_EXECUTE_WRITECOPY');

end;

end;

end;

 

procedure TForm1.Button4Click(Sender: TObject);

var ms: MEMORYSTATUS;

Size: integer;

begin

If Edit2.GetTextLen=0 then

Size:=4096

else

Size:=StrToInt(Edit2.Text);

If Edit1.GetTextLen=0 then

p:=VirtualAlloc(nil,Size,MEM_COMMIT,PAGE_READWRITE)

else

p:=VirtualAlloc(pointer(StrToInt64(Edit1.Text)),Size,MEM_COMMIT,PAGE_READWRITE);

ms.dwLength:=sizeof(MEMORYSTATUS);

GlobalMemoryStatus(ms);

Memo1.Clear;

Memo1.Lines.Add(' : '+IntToStr(ms.dwMemoryLoad)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwTotalPhys)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwAvailPhys)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwTotalPageFile)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwAvailPageFile)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwTotalVirtual)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwAvailVirtual)+' ');

end;

 

procedure TForm1.Button5Click(Sender: TObject);

var ms: MEMORYSTATUS;

begin

VirtualFree(p,4096,MEM_DECOMMIT);

VirtualFree(p,4096,MEM_RELEASE);

ms.dwLength:=SizeOf(MEMORYSTATUS);

GlobalMemoryStatus(ms);

Memo1.Clear;

Memo1.Lines.Add(' : '+IntToStr(ms.dwMemoryLoad)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwTotalPhys)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwAvailPhys)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwTotalPageFile)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwAvailPageFile)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwTotalVirtual)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwAvailVirtual)+' ');

end;

 

procedure TForm1.Button6Click(Sender: TObject);

begin

Form1.Close;

end;

 

procedure TForm1.Button7Click(Sender: TObject);

var ms: MEMORYSTATUS;

OldProtect: pointer;

begin

If ComboBox1.Text='' then

ShowMessage(' ')

else

begin

If ComboBox1.Text='PAGE_NOACCESS' then

VirtualProtect(p,4096,PAGE_NOACCESS,OldProtect);

If ComboBox1.Text='PAGE_READONLY' then

VirtualProtect(p,4096,PAGE_READONLY,OldProtect);

If ComboBox1.Text='PAGE_EXECUTE' then

VirtualProtect(p,4096,PAGE_EXECUTE,OldProtect);

If ComboBox1.Text='PAGE_EXECUTE_READ' then

VirtualProtect(p,4096,PAGE_EXECUTE_READ,OldProtect);

If ComboBox1.Text='PAGE_EXECUTE_READWRITE' then

VirtualProtect(p,4096,PAGE_EXECUTE_READWRITE,OldProtect);

If ComboBox1.Text='PAGE_WRITECOPY' then

VirtualProtect(p,4096,PAGE_WRITECOPY,OldProtect);

If ComboBox1.Text='PAGE_EXECUTE_WRITECOPY' then

VirtualProtect(p,4096,PAGE_EXECUTE_WRITECOPY,OldProtect);

end;

ms.dwLength:=SizeOf(MEMORYSTATUS);

GlobalMemoryStatus(ms);

Memo1.Clear;

Memo1.Lines.Add(' : '+IntToStr(ms.dwMemoryLoad)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwTotalPhys)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwAvailPhys)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwTotalPageFile)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwAvailPageFile)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwTotalVirtual)+' ');

Memo1.Lines.Add(' : '+IntToStr(ms.dwAvailVirtual)+' ');

end;

 

procedure TForm1.Button8Click(Sender: TObject);

var mbi: TMemoryBasicInformation;

n, k: DWORD;

begin

Memo2.Clear;

n:=00000000;

k:=11111111;

While n<k do

begin

VirtualQuery(pointer(n),mbi,SizeOf(MEMORY_BASIC_INFORMATION));

If mbi.State=MEM_FREE then

Memo2.Lines.Add(IntToStr(n));

Inc(n,mbi.RegionSize);

end;

end;

 

end.

 

2 ( 2)

 

;

cseg segment 'code'

assume cs:cseg, ds:dseg, ss:sseg

mypr proc

mov ax,sseg; ax

; c

mov ss,ax;

;

mov sp, offset TOS;

;

mov ax,dseg;

;

mov ds,ax;

; ds

mov cx,128;

; - 128

mov al,''; al

;

mov si,0; si 0

;( mes)

f1: mov mes[si],al; al

; mes

; (

; si)

inc si; 1

inc al; 1

loop f1; cx

; 1,

; 0, f1

mov ah,40h;

;

mov bx,1;

mov cx,128;

mov dx,offset mes;

; ds:dx

int 21h; ,

;

; ah

mov ax,4c00h;

;

int 21h; ,

;

; ah

mypr endp

cseg ends

;

dseg segment

mes db 128 dup('~')

dseg ends

;

sseg segment

dw 30 dup(?)

TOS label word

sseg ends

end mypr

 

3 ( 3)

text segment 'code'

assume cs:text, ds:data

begin:

MOV AX, data

MOV DS,AX

MOV cx, 10

f1: MOV AH,09h

MOV DX, offset metka

INT 21h

LOOP f1

MOV AX,4C00h

INT 21h

text ends

 

data segment

metka db "hello,World!",0dh,0ah,"$"

data ends

end begin

 

1 ( 1)

 

 

:

 

. . .
SysInfo : 4096 : 0 : 0 : 4 : 15 : 586 : 65536 : 6 : 10759
GlobalMemorySatus : 36 : 4201725952 : 2663731200 : 4294967295 : 4294967295 : 2147352576 : 2075938816
VirtualQuery : . : 0 : 0 : 65536 : MEM_FREE .: PAGE_NOACCESS
VirtualAlloc : 36 : 4201725952 : 2648408064 : 4294967295 : 4294967295 : 2147352576 : 2075938816
VirtualFree : : 2646986752
VirtualProtect : : 2652839936
 

 

2 ( 2)

 

 

 

3 ( 3)

 

  1. Windows?

 

SYSTEM_INFO. : dwAllocationGranularity;

: . 64 Windows.

 

2. , ?

 

VirtualAlloc .

:

function VirtualAlloc(lpvAddress: Pointer; dwSize, flAllocationType, flProtect: DWORD): Pointer; stdcall;

 

.

lpvAddress , , . nil, .
dwSize
flAllocationType , ( ). MEM_RESERVE. MEM_COMMIT.
flProtect ,

 

VirtualAlloc . , nil.

 

  1. , VirtualAlloc 7000 ?

 

: 8192 .

4. ?

 

. . , , , .

 

5. ?

 

, , VirtualAlloc.

 

 

Delphi 7, , . . kernel32.dll . : ; ; ; ; .



<== | ==>
|
:


: 2017-02-25; !; : 1452 |


:

:

, , 1:10
==> ...

1656 - | 1582 -


© 2015-2024 lektsii.org - -

: 0.137 .