Dynamically Calling Windows Apis With Encryption

Post date: Apr 26, 2011 9:07:12 PM

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.