COM Object compiled in Delphi 2006: How to DEP enable it? [duplicate] - delphi

Delphi 2007 (and newer) supports enabling DEP and ASLR via any of these three techniques:
add the command-line switch –dynamicbase when compiling with dcc32
add the preprocessor command {$DYNAMICBASE ON} to the source code
manually OR in the bit in the header, with {$SETPEOPTFLAGS $40} in the source code
I'd like to be able to do the same thing with Delphi 2006 and C++ Builder 2006 (aka BDS 2006). Does anyone know how to do this?

Set PE flags
You can use {$SetPEOptFlags $40} to set the DEP flag, and {$SetPEOptFlags $100} to set the ASLR flag. To set both use {$SetPEOptFlags $140}.
If you have a version of Delphi with the necessary definitions in the Windows.pas unit you can use the much more readable:
{$SetPEOptFlags IMAGE_DLLCHARACTERISTICS_NX_COMPAT or
IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE }
Typically you include the $SetPEOptFlags setting in the .dpr file. And so you need to make sure that Windows is in the .dpr file uses clause for these IMAGE_XXX constants to be available.
Set DEP policy at runtime
For versions that don't support PE flag based approaches you can call this function early in your app's initialization:
procedure EnableDEP;
const
PROCESS_DEP_ENABLE: DWORD=$00000001;
var
SetProcessDEPPolicy: function(dwFlags: DWORD): BOOL; stdcall;
begin
SetProcessDEPPolicy := GetProcAddress(GetModuleHandle(kernel32),
'SetProcessDEPPolicy');
if Assigned(SetProcessDEPPolicy) then begin
//don't bother checking for errors since we don't need to know if it fails
SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
end;
end;
This will work for any version of Delphi.
You cannot set the ASLR flag at runtime since it influences how the module is loaded. So ASLR can only be set using PE flags.
Modifying PE flags for very old versions of Delphi
Older versions of Delphi do not support $SetPEFlags and $SetPEOptFlags. For such versions you need to use an external tool to modify the executable post-build. When I originally wrote this answer I assumed that EDITBIN from the MS toolchain would do the job. For DEP it will suffice, using the /NXCOMPAT option. For ASLR you will need to use a different PE flag editor. My websearch revealed peflags from cygwin.
peflags --dynamicbase=true --nxcompat=true MyApp.exe
I'm sure there are other PE flag editing options available.

‘{$DYNAMICBASE ON}’ is new in Delphi2007, ‘{$SETPEOPTFLAGS $40}' was an existing directive: info
{$SetPEOptFlags $40} works in Delphi2006

Related

CreateOleObject in a 64-bit Delphi program?

In a Delphi XE7 64-bit VCL program, the unit Vcl.OleAutocannot be found:
[dcc64 Fatal Error] Unit1.pas(33): F1026 File not found: 'Vcl.OleAuto.dcu'
While it works without problems in a 32-bit program:
uses
Vcl.OleAuto;
...
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
So how can I use CreateOleObject in a 64-bit program?
Although the source code for Vcl.OleAuto is still supplied, the 64 bit lib directory does not include Vcl.OleAuto.dcu. Instead you are expected to use System.Win.ComObj and/or System.Win.ComServ. Note that the source for Vcl.OleAuto marks that unit as being deprecated, and tells you what to use instead.
If we look through the source for Vcl.OleAuto we can find some 32 bit asm code that has not been ported. Presumably Embarcadero decided not to port this to 64 bit because the unit is deprecated.

Lockbox 3 for Android with XE7 not working

I just found that lockbox 3.6.0 should support Android. However when i look in my palette i see that the codec only supports win32 and win64.
How can i make it work for my android apps also?
Im using Delphi XE7 and have already followed the installation instructions supplied in the package. For a windows app it works just fine.
You have two options:
(1) Run-time
You can always create the components at run-time. There is an example on the website on how to do it, and I copy a fragment of this example below. Just replace the ShowMessage() functions with whatever is appropriate ...
procedure EncryptAStream( Plaintext, Ciphertext: TStream);
var
Codec1: TCodec;
CryptographicLibrary1: TCryptographicLibrary;
begin
ShowMessage( 'Demonstration of How to Encrypt a Stream with TurboPower LockBox 3.');
Codec1 := TCodec.Create( nil);
CryptographicLibrary1 := TCryptographicLibrary.Create( nil);
Codec1.CryptoLibrary := CryptographicLibrary1;
Codec1.StreamCipherId := uTPLb_Constants.BlockCipher_ProgId;
Codec1.BlockCipherId := 'native.AES-256';
Codec1.ChainModeId := uTPLb_Constants.CBC_ProgId;
Codec1.Password := 'my utf-16le password';
// Codec1.Reset; Reset if you are continuing from a previous encryption operation.
Codec1.EncryptStream( Plaintext, Ciphertext);
// Codec1.Burn; Burn if you need to purge memory of sensitive data.
Ciphertext.Position := 0;
ShowMessageFmt(
'The ciphertext for AES-256 with CBC chaining'#13#10 +
' of plaintext ''banana'' (UTF-8 encoding),'#13#10 +
' and password ''my utf-16le password'' (UTF-16LE encoding),'#13#10 +
' prepended by 64 bit nonce, (being the IV),'#13#10 +
' and rendered for display in base64 is ...'#13#10 +
'%s', [Stream_to_Base64( Ciphertext)]);
Codec1.Free;
CryptographicLibrary1.Free;
end;
(2) Design-time
A little bit of tweaking is required to get the components onto the palette for Android. This will be done for you in the next version of TPLockbox 3 to be released, but for now, here is the procedure ...
Remove vcl, vclimg and dbrtl from the TPLB3 run-time requirements.
For the run-time package, add the Android target platform, and make it the active one. But of course, don't add this platform to the design-time package.
The binary product for the run-time should be named libTP_LockBox3_XE7.so, where XE7 is a place-marker for your compiler version.
Preface the declarations for the two components (TCodec and TCryptographicLibrary) with
[ComponentPlatformsAttribute( pidWin32 or pidWin64 or pidOSX32 or pidiOSSimulator or pidiOSDevice or pidAndroid)]
TCodec = class( TTPLb_BaseNonVisualComponent, ICryptographicLibraryWatcher,
{ etc. }
This is the key to the whole thing. The ComponentPlatformsAttribute attribute declares what platforms should the component be displayed for, on the palette. If not declared, I believe that the default is pidWin32 or pidWin64, but I cannot point to any official documentation to support this.
Recompile the run-time package. Remember that if your are compiling with MS-BUILD, on certain compiler versions, you need to save-all before you can successfully compile.
Go to the IDE Tools | Options and open the Library Path for the Android platform. Make sure that this path include the location of where you put the dcu files for the Android case. For example, on my installation it is ...
C:\Dev\TPLB\work-products\ephemeral\dcu\XE6\Android
You should physically check this directory. It should have a file named TPLB3.AES.dcu and another named TPLB3.AES.so for example.
Recompile and re-install the design-time package
Open your mobile project. Slap design-time components for TCodec and TCryptographicLibrary on your Android forms. Proceed as you would for a windows application.

List of Delphi language features and version in which they were introduced/deprecated

Before I begin, I would like to point out that I have honestly and genuinely searched repeatedly and exhaustively via Google for such a thing, and been unable to find one.
I require (for a project I'm developing) a list of all Delphi (2007 to the very latest released version, I no longer support any version older than 2007) "Language Features", and the versions in which they were introduced and (where applicable) deprecated, improved or removed.
I have noted similar questions to this on Stack Overflow before, though most of those were phrased in the form of "which feature is best", and closed as deemed unsuitable.
If anyone knows of such a list (or has enough spare time to compile one), I would be very grateful.
The accepted answer will either contain a link to such a list, or the list itself.
Note that this answer only lists new language features
not new VCL/FMX features.
Here are the links to the RAD Studio docwiki:
What's new in RAD Studio 11 Alexandria
What's new in Rad Studio 10.4 Sydney
What's new in Rad Studio 10.3 Rio
What's new in Delphi and C++Builder 10.2 Tokyo
What's new in Delphi and C++Builder 10.1 Berlin
What's new in Delphi and C++Builder 10 Seattle
What's new in Delphi and C++Builder XE8
What's New in Delphi and C++Builder XE7
What's New in Delphi and C++Builder XE6
What's New in Delphi and C++Builder XE5
What's New in Delphi and C++Builder XE4
What's New in Delphi and C++Builder XE3
What's New in Delphi and C++Builder XE2
What's New in Delphi and C++Builder XE
What's New in Delphi and C++Builder 2010
What's New in Delphi and C++Builder 2009
What's New in RAD Studio (Delphi for Win32 2007)
What's New in RAD Studio (C++Builder 2007)
What’s New in Delphi 2006
What’s New in Delphi 2005
What’s New in Delphi 7
What’s New in Delphi 6
What’s New in Delphi 5
What's New in Delphi 4
What's New in Delphi 3
What's New in Delphi 2
Delphi 1 Features
The full list from Embarcadero: What's New
See also: David I's list
See also: Delphi Master Release List wiki
To summarize:
Delphi 11
Binary Literals and Digit Separators
Inline assembler support for AVX instructions (AVX-512)
New record helpers: TDateTimeHelper and TCurrencyHelper
macOS ARM 64-bit target platform
Delphi 10.4
Unified memory management on all platforms - full ARC compiler has been removed and all compilers now use manual (classic) memory management for objects
Custom managed records
Support for macOS 64-bit
Support for Android 64-bit
Delphi 10.3
The 64-bit Linux compiler no longer uses ARC, it instead uses the default manual managed, which is the same as in the Windows compiler. This makes porting code from Windows or OSX to Linux much easier.
Inline variables with automatic type inference
8 bit AnsiChar/AnsiString support in enabled on Linux.
C++Builder and Delphi now use the same ABI for all calls.
Delphi 10.2 Tokyo
Support for Linux server apps (Intel 64-bit using LLVM and ARC).
Assigning a dynamic arrays to a pointer using the # operator is only allowed when hard-casting the array.
More flexible namespace resolution of unit names
Delphi 10.1 Berlin
Native support for Utf8String and RawByteString type on all platforms
The [weak], [unsafe] and [volatile] attributes are supported on all compilers.
The size of extended on OSX is now 16 bytes.
class and record helpers cannot access private members of the classes or records they extend.
Support for Android up to 6.01.
Delphi 10 Seattle
Support for Android 5.1.1 and iOS 8.4
Improved OSX exception handling
Delphi XE8
Support for 64-bit iOS;
New integer types: FixedInt, FixedUInt 32-bit integer types on all platforms;
New platform dependent integer types: LongInt, LongWord (64-bits on iOS-64, 32-bits on all other platforms);
Delphi XE7
String-Like Operations Supported on Dynamic Arrays
Parallel Library added to the RTL
New compiler intrinsic routines (undocumented):
function IsManagedType(T: TypeIdentifier): Boolean; function HasWeakRef(T: TypeIdentifier): Boolean; function GetTypeKind(T: TypeIdentifier): TTypeKind; function IsConstValue(Value): boolean;
Delphi XE6
Delphi XE5
Android Support;
needs device with ArmV6 + Neon or ArmV7 for deployment
introduces conditional define ANDROID
Operator overloading for classes (but only for the NextGen compiler {Android/iOS})
Delphi XE4
The following new conditionals are introduced/enabled in XE4:
AUTOREFCOUNT
CPUARM
EXTERNAL_LINKER
IOS
NEXTGEN
UNDERSCOREIMPORTNAME
WEAKREF
WEAKINSTREF
WEAKINTREF
Reintroduced support for iOS.
New dependency directive for specifying the dependencies of an external library (undocumented until XE8).
ARC support in NextGen compilers (including TObject.DisposeOf).
Note that much of the groundwork for ARC was already in XE3, but much of it was disabled
Before the XE4 release, $IF statements could only be terminated with $IFEND, and the $IFDEF, $IFNDEF, $IFOPT directives could only be terminated with $ENDIF.
At XE4, this changed so that $ENDIF became an accepted terminator for $IF, $IFDEF, $IFNDEF, and $IFOPT.
Delphi XE3
Record helpers for built-in types
Removed support for iOS.
Atomic intrinsic functions:
AtomicExchange(), AtomicIncrement(), AtomicCmpExchange(), AtomicDecrement()
Introduction of the [ref] attribute.
Delphi XE2
Cross platform support for Mac OSX (32-bit) and iOS;
Support for Win64;
Modified RTL to support cross platform;
Packed Now Forces Byte Alignment of Records (Pre XE2 it did not necessarily do this)
Eight new DEFINEs have been added:
ALIGN_STACK
CPUX86
CPUX64
MACOS (Mac operating system)
MACOS32
PC_MAPPED_EXCEPTIONS
PIC
WIN64
Full unit scope names are now required in your uses clause.
{$ExcessPrecision on/off} compiler directive (x64 only)
The build-in types differ depending on the target platform (32/64-bit)
Extended Data Type Is 10 bytes on Win32, but 8 (!) bytes on Win64
Delphi XE
The {$STRINGCHECKS} compiler directive is ignored in XE;
New 16-byte value for the {$ALIGN} directive:
The acceptable values for the {$ALIGN} directive now include 1, 2, 4, 8, and 16.
new {$CODEALIGN} directive, this sets the starting address for a procedure or function.
The {$STRONGLINKTYPES ON} directive
Support for regular expressions.
Delphi 2010
Enhanced Delphi RTTI (Run Time Type Information).
Attributes
The as operator can be used to cast an interface reference back to the object from which it was extracted.
The is operator can be used to verify whether an interface reference was extracted from a certain class.
Normal unsafe casting can be performed on an interface: TObject(SomeInterface).
new delayed directive indicates that an external library such as a DLL is not to be loaded at declaration time but is to wait until the first call to the method
Class Constructor/Destructor
Delphi 2009
Intrinsic type string now maps to UnicodeString;
{$HighCharUnicode on|off} compiler directive
Generics;
function Default(T): T intrinsic function (Undocumented)
Smart pointers;
Anonymous methods;
Support for nested exceptions and exception tracing;
support for pointermath and a new compiler directive: {$PointerMath on|off};
Four new compiler warnings:
W1057 Implicit string cast from '%s' to '%s',
W1058 Implicit string cast with potential data loss from '%s' to '%s',
W1059 Explicit string cast from '%s' to '%s',
W1060 Explicit string cast with potential data loss from '%s' to '%s';
The Exit function can take a parameter specifying a result;
resourcestrings as Widestrings;
TObject has a extra hidden pointer to TMonitor in addition to its VMT pointer;
the deprecated keyword can now have additional text
Delphi 2007
No language changes that I know of;
Note that Delphi 2007 is a non-breaking release, DCU's from D2006 will work unchanged in D2007;
(The .NET 'personality' of 2007 introduced generics)
Delphi 2006
Enhanced records;
operator overloading;
static methods and properties;
FastMM is the default memory manager;
strict private/protected visibility keyword;
final keyword for virtual methods;
{$METHODINFO} directive;
Delphi 2005
for ... in loops,
inline keyword
Wildcard in uses statement allowed
nested types
nested constants
{$REGION}/{$ENDREGION} directives
class helpers (added in Delphi 8 for .net);
Delphi 7
three additional compiler warnings:
Unsafe_Type,
Unsafe_Code, and
Unsafe_Cast. These warnings are disabled by default, but can be enabled
new compiler directive {$WARN UNSAFE_CODE ON}
Overloads of routines that format and parse numbers, date-time values, and currency using a TFormatSettings structure.
Delphi 6
[TCustomVariantType][68] provides operator overloading for custom variant types
New compiler directives:
{$IFDEF MSWINDOWS}
{$IFDEF LINUX}
{$LIBPREFIX}
{$LIBSUFFIX}
{$LIBVERSION}
{$MESSAGE 'message'}
{$SetPEFlags}
Support for {$IF}{$ELSE} compiler directives
Compiler hinting directives: experimental, deprecated, library, platform (but without additional text for deprecated)
Variant is no longer based on COM but changed to be CLX compatible, COM based variant renamed to OLEVariant
Typed constants cannot be assigned to (Override with {$J+})
Enumerated types can be assigned an explicit value (cf C++);
Interface properties
Support for calling varargs external functions (but only for the cdecl calling convention)
custom variants
Delphi 5
No new language features, but:
Support added for Frames
Delphi 4
Dynamic arrays
LongWord and Int64; Cardinal is an UINT32 (before it was unsigned 31-bit value)
Real takes 8 bytes and is the same as double (previously it was 6 bytes);
Override with the new {$REALCOMPATIBILITY ON} compiler directive;
REAL48 replaces the old 6-byte real;
Support for resourcestrings
Method overloading
Default parameters
{$EXTERNALSYM} and {$NODEFINE} directives
implements keyword for properties
Delphi 3
Wordbool, longbool and bytebool store true as -1 instead of 1 (Boolean is unchanged)
Components must be installed using packages.
Assertions.
out parameters.
Widestring
interface and dispinterface keyword and COM (dispid) support.
Delphi 2
Support for 32-bit;
Ansistring replaces shortstring as the default string type
Currency
Variant (for interop with OLE automation).
Threading support and ThreadVar keyword.
4 byte data is 4 byte aligned new packed keyword overrides this behavior;
TDateTime starts at 1899/12/30 under D1 it started at 0000/00/00
new finalization keyword
register and stdcall calling conventions added.
packed keyword.
Just for complement the answer of Johan check this entry on my blog List of changes between versions of Delphi (Since Delphi 5) and the excellent page The TIndex which list most of the new features since delphi 2005 and resources about each one.
The jedi.inc file used by the Dephi JEDI project exposes a series of feature defines. If your project is MPL-compatible, you could even use it for feature detection and save yourself the trouble of reinventing that particular wheel.
For example, it defines SUPPORTS_FOR_IN if the compiler supports enumerators. One could wrap your enumerator code in an IFDEF checking for that define rather than checking for a particular compiler version.

Delphi Xe2 Package x64

Let's admit, I create new package in Delphi Xe2. I keep under a name "My". I add a simple component "MyComponent". I compile, I receive file Bpl in C:\Users\Public\Documents\RAD Studio\9.0\Bpl\My.bpl.
I add a platform "Win x64".
I compile, I receive C:\Users\Public\Documents\RAD Studio\9.0\Bpl\Win64\My.bpl.
...\Bpl\Win64\My.bpl to establish as new package does not give, writes "is not windows x32 applications".
The first is established normally and on a palette the component appears "MyComponent".
If to bring to are mute the index of a mouse will appear hint where it will be written, that it x32-compatible.
And at native component Delphi - at all x32-64 compatible.
Together with a disk to Xe2 there is a free disk with Free and Tral components if to put therefrom for example OverByteIcs or Ip*Works, that at them at all components will be 32-64х compatibility.
Questions:
1. How to establish the x64 the version package?
2. How to achieve, that the component had a compatibility 32-64, and not just 32?
P.S. Bad English language: ON
The Delphi IDE is 32 bit and so can only load 32 bit designtime packages. You can of course create 64 bit runtime packages.
Has earned, has understood!
We create empty package
We add the component, for example Button and it is specified what platforms for a component (the key moment are necessary!)
Example
unit GuButton;
interface
uses
System. SysUtils, System. Classes, Vcl. Controls, Vcl. StdCtrls;
type
[ComponentPlatformsAttribute (pidWin32 or pidWin64)] // !!!!!!!!!!!!!!!
TButtonGu = class (TButton)
private
{Private declarations}
protected
{Protected declarations}
public
{Public declarations}
published
{Published declarations}
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents (' Gu ', [TButtonGu]);
end;
We keep, we compile under x32. We add a platform x64 (in options should be registered, that directories under platforms different).
We compile under x64. We receive 2 BPL (as in the first question). We establish x32. We look - new component ButtonGu - 32-64 compatible was added.
Here I that wanted, all thanks.
In addition http://docwiki.embarcadero.com/RADStudio/en/64-bit_Cross-Platform_Application_Development_for_Windows

Delphi warning - W1002 Symbol 'FileSetDate' is specific to a platform

When I compile my application under Delphi 2006 I get the following warning
[Pascal Warning]- W1002 Symbol 'FileSetDate' is specific to a platform
What must I do to suppress this warning?
The code
MyLastError:= FileSetDate( Files[ i ].Handle, DateTimeToFileDate( arcDate ) );
1) In the project options you can choose the compiler messages you want to see.
If you don't care about platform independency you can just switch off the platform warning there.
2) Another way is disabling the warning for a certain part of the code:
{$WARN SYMBOL_PLATFORM OFF}
// Your code
{$WARN SYMBOL_PLATFORM ON}
For a complete list of options look at the Delphi help file at the topic '$WARN'
3) A last way would be adding
{$WARNINGS OFF}
// Your code
{$WARNINGS ON}
but that is dangerous, because all warnings will be suppressed.
4) Additionally, as the other answers have already suggested, you could just switch to the platform independant variant of FileSetDate which works on file names (i.e. Strings), but as far as I understand that was not your question.
Although the answer of DR solves the warning, it is not the correct solution.
You should use the platform independent version of FileSetDate:
function FileSetDate(const FileName: string; Age: Integer): Integer; overload;
Also in SysUtils.
You can turn off the platform unit and platform symbol compiler warnings. They are obsolete (and disabled in Delphi 2009 by default). They were introduced when there was a Delphi for Linux (Kylix). They do not have a meaning anymore. Especially with the replacement of Delphi.NET with Delphi Prism.
You can turn them off for the whole project in the Project Options dialog (Compiler Messages).

Resources