Xreferat.com » Рефераты по информатике и программированию » Семантический анализ структуры EXE файла и дисассемблер (с примерами и исходниками), вирусология

Семантический анализ структуры EXE файла и дисассемблер (с примерами и исходниками), вирусология

( 0, $98, $96, $80),

( 5, $F5, $E1, 0),

($3B, $9A, $CA, 0) );

var

i, j : INTEGER;

CharOffset,

Digit : BYTE;

Rep : ARRAY [0..9] OF CHAR;

Number : LongInt absolute Low;

OldNumber : LongInt;

stop : BOOLEAN;

begin

CharOffset := Ord(' ');

OldNumber := Number;

Rep := ' ';

for i:=9 downto 0 do begin

Digit := 0;

Number := OldNumber;

stop := false;

repeat

(* subtract Divisor from TestNumber *)

for j:=0 to 3 do begin

Number[j] := Number[j] - Divisors[i][3-j];

if (Number[j] > OldNumber[j]) AND (j<>3) then

Number[j+1] := number[j+1] - 1;

end;

if (Number[3] <= OldNumber[3]) then begin

Digit := succ(Digit);

CharOffset := Ord('0');

OldNumber := Number

end

else stop := true;

until stop;

Rep[9-i] := Chr(CharOffset+Digit);

end;

Write(Rep)

end;


procedure ComOut(var par);

const

WriteCommand = 1;

var

regs: RECORD

AX, BX, CX, DX, BP, SI, DI, DS, ES, Flags: INTEGER

END;

B : BYTE absolute par;

begin

with Regs do begin

AX := (WriteCommand shl 8) + B;

DX := 0;

Intr($14, Regs);

end

end;


procedure BlockRead (var f: file; var buffer; var n: integer);

const

readfunction = $3F;


var

regs: RECORD

AX, BX, CX, DX, BP, SI, DI, DS, ES, Flags: INTEGER

END;


begin

with Regs do begin

AX := (readfunction shl 8);

BX := MemW[Seg(f):Ofs(f)];

CX := n;

DX := Ofs(buffer);

DS := Seg(buffer);

Intr($21, Regs);

if (Flags and $0001) = 1 then begin

write('I/O Error ');

writeHex(AX shr 8);

writeln (' during BlockRead');

end

else

n := AX

end;

end;


function FileSize (var f: file): INTEGER;

const

seekfunction = $42;

from_begin = 0;

from_current = 1;

from_end = 2;


var

regs: RECORD

AX, BX, CX, DX, BP, SI, DI, DS, ES, Flags: INTEGER

END;

CurrentFilePointer_low,

CurrentFilePointer_high : INTEGER;


begin

with Regs do begin

AX := (seekfunction shl 8) + from_current;

BX := MemW[Seg(f):Ofs(f)]; (* handle ! *)

CX := 0; (* offset-high *)

DX := 0; (* offset-low *)

Intr($21, Regs);

if (Flags and $0001) = 1 then begin

write('I/O Error ');

writeHex(AX shr 8);

writeln (' during FileSize');

end;

CurrentFilePointer_low := AX;

CurrentFilePointer_high := DX;

(* determine file size *)

AX := (seekfunction shl 8) + from_end;

BX := MemW[Seg(f):Ofs(f)]; (* handle ! *)

CX := 0; (* offset-high *)

DX := 0; (* offset-low *)

Intr($21, Regs);

if (Flags and $0001) = 1 then begin

write('I/O Error ');

writeHex(AX shr 8);

writeln (' during FileSize');

end;

FileSize := AX;

(* restore FilePointer *)

AX := (seekfunction shl 8) + from_begin;

BX := MemW[Seg(f):Ofs(f)]; (* handle ! *)

CX := CurrentFilePointer_high;

DX := CurrentFilePointer_low;

Intr($21, Regs);

if (Flags and $0001) = 1 then begin

write('I/O Error ');

writeHex(AX shr 8);

writeln (' during FileSize');

end;

end

end;


procedure BlockWrite (var f: file; var b; var n: integer);

const

writefunction = $40;


var

regs: RECORD

AX, BX, CX, DX, BP, SI, DI, DS, ES, Flags: INTEGER

END;


begin

with Regs do begin

AX := (writefunction shl 8);

BX := MemW[Seg(f):Ofs(f)];

CX := n;

DX := Ofs(b);

DS := Seg(b);

Intr($21, Regs);

if (Flags and $0001) = 1 then begin

write('I/O Error ');

writeHex(AX shr 8);

writeln (' during BlockWrite');

end

end;

end;


procedure Open(var f: file; VAR Name);

const

OpenFunction = $3D;

OpenMode = 128; (* read only *)


var

FName: STRING [255] ABSOLUTE Name;

regs: RECORD

AX, BX, CX, DX, BP, SI, DI, DS, ES, Flags: INTEGER

END;


begin

FName := FName + chr (0);

with Regs do begin

AX := (OpenFunction shl 8) + OpenMode;

DX := Ofs (FName) + 1;

DS := Seg (FName);

Intr($21, Regs);

MemW [Seg (f) : Ofs (f)] := AX;

if (Flags and $0001) = 1 then begin

write('I/O Error ');

writeHex(AX shr 8);

writeln (' during Reset');

end

end

end;


----------- start of source ---- CUT HERE FOR DEB2ASM.PAS -------------


const

blank = ' ';

tab = #9;

comma = ',';

colon = ':';

semicolon = ';';


type

STR4 = STRING[4];

STR5 = STRING[5];

STR6 = STRING[6];

STR12 = STRING[12];

STR18 = STRING[18];

STR80 = STRING[80];

ReferenceTypes = (None, B, W, D, N, F);

ParseTypes = RECORD

Offset : STR4;

HexCode : STR12;

OpCode : STR6;

Operand1,

Operand2 : STR12;

Comment : BYTE; (* position where comment starts *)

TypeOverride : ReferenceTypes

END;


var

f_in, f_out : text[$2000];

Line : STR80;

LineCount,

CharPos : INTEGER;

FileName : STR80;

FileExt : BOOLEAN;

Rep : ARRAY [ReferenceTypes] OF STR5;

ParsedLine : ParseTypes;


(*$I

io.inc *)

(*$I

sort.box *)


const

SymbolTableSize = 2000;


type

TableEntry = RECORD

offset,

reference : INTEGER;

reftype : ReferenceTypes;

position : BYTE

END;


var

SymbolTable,

AuxTable : ARRAY [0 .. SymbolTableSize] OF TableEntry;


Current_SymbolTable_Index,

Symbol_Table_Length,

SortInputIndex,

SortOutputIndex,

SortStatus : INTEGER;


(* TOOLBOX SORT interface *)


procedure Inp;

begin

while SortInputIndex < Symbol_Table_Length do begin

SortRelease(SymbolTable[SortInputIndex]);

SortInputIndex := succ(SortInputIndex)

end;

end;


procedure Outp;

begin

while (NOT SortEOS) AND (SortOutputIndex <= Symbol_Table_Length) do begin

SortReturn(AuxTable[SortOutputIndex]);

SortOutputIndex := succ(SortOutputIndex) ;

end;

end;


function Less;

var

Entry1 : TableEntry absolute X;

Entry2 : TableEntry absolute Y;

begin

if Entry1.reference = Entry2.reference then

Less := Ord(Entry1.reftype) < Ord(Entry2.reftype)

else (* compare the Entries as unsigned integers *)

if ((Entry1.reference XOR Entry2.reference) AND $8000) = 0 then

Less := Entry1.reference < Entry2.reference

else if (Entry1.reference AND $8000)= $8000 then Less := false

else Less := true;

end;


procedure StoreReference(_Offset, _Label: INTEGER; _RefType: ReferenceTypes;

_position: BYTE);


(* This procedure keeps a table of locations referenced *)

(* including the type of reference

Если Вам нужна помощь с академической работой (курсовая, контрольная, диплом, реферат и т.д.), обратитесь к нашим специалистам. Более 90000 специалистов готовы Вам помочь.
Бесплатные корректировки и доработки. Бесплатная оценка стоимости работы.

Поможем написать работу на аналогичную тему

Получить выполненную работу или консультацию специалиста по вашему учебному проекту
Нужна помощь в написании работы?
Мы - биржа профессиональных авторов (преподавателей и доцентов вузов). Пишем статьи РИНЦ, ВАК, Scopus. Помогаем в публикации. Правки вносим бесплатно.

Похожие рефераты: