This works fantastic! I couldn't leave my previous solution for the next programmer to untangle so I reverted in the repo and here is what I ended up with. Again constant strings are handled via a simple en/decode function (while I'm wishing can I wish for macro support?). The last of my "mandates" was obfuscate the class field names since they were the most revealing. But as a bonus This solution also takes care of sensitive procedure names. Unit tests still run! So it seems I didn't break anything at a glance.
unit Unit4;
{$RTTI EXPLICIT METHODS([]) PROPERTIES([]) Fields([vcPublic])}
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, REST.Json, REST.Json.Types;
type
TPII = class
public
//Obfuscated
Faaaa: string;
Fbbbb: string;
Fcccc: string;
public
//Human readable
property FNAME: string read Faaaa write Faaaa;
property FAddress: string read Fbbbb write Fbbbb;
property FCity: string read Fcccc write Fcccc;
end;
type
TForm4 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure MyPIIProcedure; //Could be sensative. Needs to be hidden as well...
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
procedure TForm4.Button1Click(Sender: TObject);
begin
MyPIIProcedure;
end;
procedure TForm4.MyPIIProcedure;
var
MyPII: TPII;
PIIJSON: string;
begin
MyPII:= TPII.Create;
MyPII.FName:= 'John';
MyPII.FAddress:= 'Main Street';
MyPII.FCity:= 'New York';
PIIJSON := TJSON.ObjectToJsonString(MyPII, [joIndentCaseCamel]);
Memo1.Lines.Add('////////////// JSON DATA //////////////');
Memo1.Lines.Add(PIIJSON);
MyPII.Free;
end;
end.
To top it off I wrote a small "scrubber" that does the search and replace as mentioned above in the .pas but did it like this:
Used this to take care of the actual class names...
created an include file with the known-name and an obfuscated equivalent. Wrote a small Delphi console app to do this. Works great in the CI/CD pipeline build. This took care of the remaining 60 or so edge cases hidden in the code.
Added the scrubber to the pre-build command to parse out the .pas files needed. Before compile.
The resulting binaries are petty darn clean!
So thanks again to everyone that chimed in! All great ideas and led to the working solution. No more "plain text" identifiers.