PDA

View Full Version : No Memory Hacking?



LiquidIce
02-02-2003, 07:02 PM
I am creating a game and I am wondering if anyone knows any ways to prevent memory hacking, or to at least make it difficult to do so.

I could make everything server sided, but it would waste precious bandwith and I would like to make only the things I need to server sided (ie: weapons, items, ..).

Sly
03-02-2003, 12:07 AM
I've seen a component for C++ Builder that randomly encrypts a memory buffer. Not only does it encrypt it once, it re-encrypts the buffer once a second. This is about the most secure I think you will get from memory hacking. This component is part of a commercial package so you cannot get the source code freely.

cairnswm
03-02-2003, 07:41 AM
Why not write your own component to do it for you?


Type
TEncryptedMem = Class
Private
IntTimer : TTimer;
FOnReEncrypt: TNotiFyEvent;
procedure SetOnReEncrypt(const Value: TNotiFyEvent);
Protected
procedure SetAsInteger(const Value: Integer); Virtual;
procedure SetAsString(const Value: String); Virtual;
procedure SetEncryptInterval(const Value: Integer); Virtual;
Procedure ReEncrypt(Sender : TObject); Virtual;
function GetAsInteger: Integer; Virtual;
function GetAsString: String; Virtual;
function GetEncryptInterval: Integer; Virtual;
Published
Property AsInteger : Integer read GetAsInteger write SetAsInteger;
Property AsString : String read GetAsString write SetAsString;
Property EncryptInterval : Integer read GetEncryptInterval write SetEncryptInterval;
Property OnReEncrypt : TNotiFyEvent read FOnReEncrypt write SetOnReEncrypt;
Constructor Create;
Destructor Destroy; Override;
Public
DataStr : String;
End;


Obviously the Datastr should be private but for testing you need it visible.


constructor TEncryptedMem.Create;
begin
inherited;
IntTimer := TTimer.Create(Nil);
IntTimer.Interval := 1000;
IntTimer.OnTimer := ReEncrypt;
end;

destructor TEncryptedMem.Destroy;
begin
IntTimer.Free;
inherited;
end;

function TEncryptedMem.GetAsInteger: Integer;
begin
Result := StrToInt(Decrypt(DataStr));
end;

function TEncryptedMem.GetAsString: String;
begin
Result := Decrypt(DataStr);
end;

function TEncryptedMem.GetEncryptInterval: Integer;
begin
Result := IntTimer.Interval;
end;

procedure TEncryptedMem.ReEncrypt(Sender: TObject);
begin
DataStr := Encrypt(Decrypt(DataStr));
If Assigned(OnReEncrypt) then
OnReEncrypt(Self);
end;

procedure TEncryptedMem.SetAsInteger(const Value: Integer);
begin
DataStr := Encrypt(IntToStr(Value));
end;

procedure TEncryptedMem.SetAsString(const Value: String);
begin
DataStr := Encrypt(Value);
end;

procedure TEncryptedMem.SetEncryptInterval(const Value: Integer);
begin
IntTimer.Interval := Value;
end;


procedure TEncryptedMem.SetOnReEncrypt(const Value: TNotiFyEvent);
begin
FOnReEncrypt := Value;
end;


Write your own encryption Algorithms or use a secure system. I have my own little system that I use - not highly secure as the encrypted portion always remains the same but in my environment it does ok - I use it to encrypt password and IDs in the Registry etc.


function Encrypt(Str: String): String;
Var
I : Integer;
S : String;
begin
S := Char(Trunc(Random*26)+Ord('A'));
For I := 1 to Length(Str) do
Begin
S := S+Char(Ord(Str[I])-I)+Char(Trunc(Random*26)+Ord('A'));
end;
Result := S;
end;

function Decrypt(Str: String): String;
Var
S : String;
I : Integer;
begin
S := '';
I := 1;
While I * 2 < Length(Str) do
Begin
S := S + Char(Ord(Str[I*2])+I);
I := I + 1;
End;
Result := S;
end;



To use this just create a unit with it all in. (or send me an email william.cairns@arivia.co.za and I'll send you the unit and the test form.)

Create a TEncryptedMem object in your program.

To set a value
Mem.AsString := 'This is my secret memory program';
To read the value
MyVar := Mem.AsString;
To see what it looks like in memory
MyEncrypt := Mem.DataStr; // For Debug Purposes Only.

You can use the OnReEncrypt event to be notified whenever the timer reencrypts the value. - Nive for debugging purposes :)

Cheers

EDIT (BlueCat) - [ pascal ] tags look so much nicer than [ code ] :pirate: