Jump to content


Photo

Record fields with obfuscation


  • Please log in to reply
3 replies to this topic

#1 Igor Savkic

Igor Savkic
  • Members
  • 169 posts

Posted 27 March 2016 - 12:05 PM

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?



#2 Laksekjønn

Laksekjønn
  • Members
  • 428 posts

Posted 27 March 2016 - 04:07 PM

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"]}


  • Dany and Nico Wouterse like this

#3 Igor Savkic

Igor Savkic
  • Members
  • 169 posts

Posted 28 March 2016 - 03:41 AM

> 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.



#4 Laksekjønn

Laksekjønn
  • Members
  • 428 posts

Posted 12 April 2017 - 03:31 PM

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.

  • ielite and Nico Wouterse like this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users