Jump to content
igors233

Record fields with obfuscation

Recommended Posts

Once that code is obfuscated, record fields when serialized, becomes giberrish which is a bit of a problem if you store it in local storage and then update the app (field names will change).

What is a preffered way of handling this, is there some compiler flag that would prevent obfuscating certain record or anonymous records are the way to go?

Share this post


Link to post
Share on other sites

When you create a Record type structure such as

type
TMyRecord = Record
  mrMagic: Integer; //Magic word to check
  mrData: Array of String; // your string data

End; 

{"oBM":3405691582,"zA4":["first","second"]}

 

When you activate though, the record fields will get renamed randomly, and I discovered that there's a little black magic

type
TMyRecord = Record
  property mrMagic: Integer; //Magic word to check
  property mrData: Array of String; // your string data

End;

{"mrMagic":3405691582,"mrData":["first","second"]}

Share this post


Link to post
Share on other sites

> When you activate though, the record fields will get renamed randomly, and I discovered that there's a little black magic

 

This is great info, it works very well, now I can delete my custom serialization/deserialization code! Thanks a lot.

Share this post


Link to post
Share on other sites

Tip of the day: # Initialize array of records with obfuscation enabled

type
    TShopItem = record
      Name: string; 
      Price : float; 
    end;

var
    Items : array[1..3] of TShopItem =
    (
      (Name : 'Clock';  Price : 20.99),
      (Name : 'Pencil'; Price : 15.75),
      (Name : 'Board';  Price : 42.96)
    );
When obfuscation is enabled, the fields are obfuscated as well.
bzY = [{
         YoL : "Clock",
         ih : 20.99
        }, {
         YoL : "Pencil",
         ih : 15.75
       }, {
         YoL : "Board",
         ih : 42.96
       }];
 
...you can prevent obfuscating in certain record fields using the as "property", but you can't initialize the array of record.
The black magic here is to add the keyword external + fieldname
type
    TShopItem = record
      Name: string; external "Name";
      Price : float; external "Price";
    end;

var
    Items : array[1..3] of TShopItem =
    (
      (Name : 'Clock';  Price : 20.99),
      (Name : 'Pencil'; Price : 15.75),
      (Name : 'Board';  Price : 42.96)
    );
Cs6 = [{
         Name : "Clock",
         Price : 20.99
       }, {
         Name : "Pencil",
         Price : 15.75
       }, {
         Name : "Board",
         Price : 42.96
       }];
 
=====
In the latest commit, Erik Grange has added a new feature in the DWScript language (using "record external" syntax). 
Eric added record external feature now. I hope it will be available in the next release.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×