Dynamically Calling Windows Apis With Encryption

posted 26 Apr 2011, 14:07 by Delphi Basics
This short delphi snippet details dynamically calling windows apis with encryption.

program DynamiqueAPI;
//cswi
//www.delphibasics.info
uses
  Windows;

type
  TMessageBoxA = function(Handle : Cardinal;
                          lpText : PAnsiChar;
                          lpCaption : PAnsiChar;
                          uType : Cardinal) : Cardinal; stdcall;

function EnDeCrypt(const Value : String) : String;
var
  CharIndex : integer;
begin
  Result := Value;
  for CharIndex := 1 to Length(Value) do
    Result[CharIndex] := chr(not(ord(Value[CharIndex])));
end;

var
  hUser32 : Cardinal;
  xMessageBoxA : TMessageBoxA;
  sMessageBoxA : PAnsiChar;
begin
  sMessageBoxA := PAnsiChar(EnDeCrypt('²šŒŒž˜š½‡¾'));
  hUser32 := LoadLibraryA('user32.dll');
  @xMessageBoxA := GetProcAddress(hUser32, sMessageBoxA);
  if Assigned(xMessageBoxA) then
    xMessageBoxA(0, 'Hello World', '', 0);
end.
Comments