procedure StartMarker;
asm
DB '
CODESTART',0
end;
procedure ProtectedCode;
begin
showmessage('
protected Code wird ausgeführt');
end;
procedure StopMarker;
asm
DB '
STOPCODE',0
end;
function StopCode: PChar;
asm
MOV EAX,OFFSET StopMarker
RET
end;
function StartCode: PChar;
asm
MOV EAX,OFFSET StartMarker
RET
end;
function CodeGroesse: Integer;
asm
mov eax,offset StopMarker
sub eax,offset StartMarker;
sub eax,10
ret
end;
function Startmarkierung:DWORD;
asm
MOV EAX,OFFSET StartMarker
ADD EAX,10
RET
end;
procedure TForm1.Button2Click(Sender: TObject);
var
ProcessId : DWORD;
ThreadId : DWORD;
Dest: TStream;
ProcessHandle: THandle;
Buffer: Pointer;
Size: DWORD;
begin
ThreadId := GetWindowThreadProcessId(
Handle,@ProcessId);
ProcessHandle := OpenProcess(PROCESS_ALL_ACCESS,False,ProcessId);
Buffer:=AllocMem(CodeGroesse);
ReadProcessMemory(ProcessHandle, ptr(StartMarkierung), Buffer, CodeGroesse, DWORD(
nil^));
//Den Buffer in eine Datei speichern zu Testzwecken
Dest := TFileStream.Create('
testpart.bin', fmCreate);
Dest.WriteBuffer(buffer^, CodeGroesse);
Dest.Free;
FreeMem(buffer);
closehandle(ProcessHandle);
end;