Author Topic: Need help hacking DP832 for multicolour option.  (Read 152467 times)

0 Members and 1 Guest are viewing this topic.

Offline tossu

  • Contributor
  • Posts: 21
  • Country: 00
Re: Need help hacking DP832 for multicolour option.
« Reply #250 on: June 10, 2019, 05:56:44 pm »
Preparing the USB drive is, indeed, quite a persnickety process. The file won't end up in the right sector if the partition is too large.

To make that easier, I made a disk image that can be written directly to any USB drive with a dd-like utility. On Windows I like to use Win32 Disk Imager.
 
The following users thanked this post: thm_w, electr_peter, natman69, RoGeorge, Chris56000, bd139, joeyjoejoe, nicolasg

Offline bson

  • Supporter
  • ****
  • Posts: 2265
  • Country: us
Re: Need help hacking DP832 for multicolour option.
« Reply #251 on: June 11, 2019, 03:57:03 am »
Neat hack, and the fonts are a huge improvement over the faux 7-segment ones!  :-+
 

Offline 1anX

  • Regular Contributor
  • *
  • Posts: 195
  • Country: au
Re: Need help hacking DP832 for multicolour option.
« Reply #252 on: June 11, 2019, 05:50:13 am »
Thank you all so much!
My DG1022Z now running full speed as a DG1062Z.
Simply sent the command :PROJ:STAT MODEL,DG1062Z through Rigol's, Ultra Sigma software, connected thru USB.
Used USB and Ultra Sigma to hack my DP832 to DP832A without a hitch! Dont really know if the colour display is a step forward or backward  :)
Its certainly made the display more customisable and thats gotta be a good thing.

Probably pushing my luck but has anyone had success unlocking the 16Mb ARB memory?
« Last Edit: June 11, 2019, 06:48:31 am by 1anX »
 

Offline Gandalf_Sr

  • Super Contributor
  • ***
  • Posts: 1729
  • Country: us
Re: Need help hacking DP832 for multicolour option.
« Reply #253 on: June 12, 2019, 12:28:27 am »
I didn't think I'd like it but the 'Pie chart' screen is my favorite now.
If at first you don't succeed, get a bigger hammer
 

Offline tossu

  • Contributor
  • Posts: 21
  • Country: 00
Re: Need help hacking DP832 for multicolour option.
« Reply #254 on: June 14, 2019, 12:10:35 am »
Probably pushing my luck but has anyone had success unlocking the 16Mb ARB memory?

Yes. There are two ways to do it, both of which are described in this thread. I think changing the serial is the easier one.
 
The following users thanked this post: blubillcanada

Offline 1anX

  • Regular Contributor
  • *
  • Posts: 195
  • Country: au
Re: Need help hacking DP832 for multicolour option.
« Reply #255 on: June 14, 2019, 03:24:10 am »
Probably pushing my luck but has anyone had success unlocking the 16Mb ARB memory?

Yes. There are two ways to do it, both of which are described in this thread. I think changing the serial is the easier one.
I had help from an advanced forum member and now have the 16Mb arb enabled.
Its amazing what is possible when a group of EEV members put their collective minds together!
There is no way I could have ever hacked my Rigol instruments without the hard work being done by this community, thank you!
 
The following users thanked this post: blubillcanada

Offline HDR

  • Newbie
  • Posts: 4
  • Country: de
Re: Need help hacking DP832 for multicolour option.
« Reply #256 on: June 25, 2019, 01:55:44 pm »
Does anyone know if you can upgrade a DSA815-TG to a DSA832-TG?
 

Offline TurboTom

  • Super Contributor
  • ***
  • Posts: 1388
  • Country: de
Re: Need help hacking DP832 for multicolour option.
« Reply #257 on: June 25, 2019, 10:42:13 pm »
Does anyone know if you can upgrade a DSA815-TG to a DSA832-TG?

No way, different hardware! Compare the weights of the instruments in the specs, this already tells everything. The higher-spec'd DSA8XX units feature a much more modular design, like the Siglent SSA3000 series.

Cheers,
Thomas
 

Offline HDR

  • Newbie
  • Posts: 4
  • Country: de
Re: Need help hacking DP832 for multicolour option.
« Reply #258 on: June 26, 2019, 10:37:55 am »
Thank you!
 

Offline aristarchus

  • Regular Contributor
  • *
  • Posts: 107
  • Country: 00
Re: Need help hacking DP832 for multicolour option.
« Reply #259 on: June 27, 2019, 05:46:03 pm »
Probably pushing my luck but has anyone had success unlocking the 16Mb ARB memory?

Yes. There are two ways to do it, both of which are described in this thread. I think changing the serial is the easier one.
I had help from an advanced forum member and now have the 16Mb arb enabled.
Its amazing what is possible when a group of EEV members put their collective minds together!
There is no way I could have ever hacked my Rigol instruments without the hard work being done by this community, thank you!


Any chance to have this? It would be awsome!

A
 

Offline 1anX

  • Regular Contributor
  • *
  • Posts: 195
  • Country: au
Re: Need help hacking DP832 for multicolour option.
« Reply #260 on: June 28, 2019, 06:49:28 am »
To unlock/enable the 16Mb arb memory you need to use a license key along with this text file file as shown on the Rigol website https://rigol.desk.com/customer/en/portal/articles/2283691-how-do-i-activate-the-dg1000z-memory-upgrade-
Perhaps someone can offer a method of creating a license key from your serial number?
 

Offline Gandalf_Sr

  • Super Contributor
  • ***
  • Posts: 1729
  • Country: us
Re: Need help hacking DP832 for multicolour option.
« Reply #261 on: June 28, 2019, 08:43:47 am »
To unlock/enable the 16Mb arb memory you need to use a license key along with this text file file as shown on the Rigol website https://rigol.desk.com/customer/en/portal/articles/2283691-how-do-i-activate-the-dg1000z-memory-upgrade-
Perhaps someone can offer a method of creating a license key from your serial number?
Page 151 of the Rigol User Guide also offers this method of applying option license strings to the DG1000Z series...

2) Install the option by sending SCPI commands
Open the remote control window and send the following option installation commands by referring to “Remote Control”. :LICense:SET <license> or :LICense:INSTall <license> Wherein, <license> is the option license (note that the hyphens should be omitted).
For example,

:LICense:INSTall SM9KD3YPMWNP2AQMST8J5H592EQT (that license string is shown in the manual, you will need the right one for your AWG)

If the option is successfully installed, the prompt message informing you that the option installation succeeds will be displayed; otherwise, the corresponding error message will be displayed.
If at first you don't succeed, get a bigger hammer
 

Offline aristarchus

  • Regular Contributor
  • *
  • Posts: 107
  • Country: 00
Re: Need help hacking DP832 for multicolour option.
« Reply #262 on: June 28, 2019, 11:13:36 am »
Thanks for any help.

What I actually did is tried to modify according to starec's findings and hints.
Now I need the 4 digit option code that should be used.
Anyone knows?


A
 

Offline 1anX

  • Regular Contributor
  • *
  • Posts: 195
  • Country: au
Re: Need help hacking DP832 for multicolour option.
« Reply #263 on: June 28, 2019, 11:59:14 pm »
Thanks for any help.

What I actually did is tried to modify according to starec's findings and hints.
Now I need the 4 digit option code that should be used.
Anyone knows?

A

If you read thru the thread you will find it listed!
options:          JBNE  (0x6D422)
 

Offline starec

  • Newbie
  • Posts: 5
  • Country: sk
Re: Need help hacking DP832 for multicolour option.
« Reply #264 on: June 29, 2019, 07:34:32 am »
I've sent the PM for you - anyway
there are two options:
JBNE - for permanent license
JNNE - for temporary(timed) license
 
The following users thanked this post: aristarchus

Offline ted572

  • Frequent Contributor
  • **
  • Posts: 399
  • Country: us
  • Radio Communications Equipment/System Design Engr.
Re: Need help hacking DP832 for multicolour option.
« Reply #265 on: July 07, 2019, 06:45:06 pm »
When I first got a Rigol DM3058E (Bench-Top DMM) several years ago I would get 6 1/2 digit voltage measurement data when I queried it via USB from my PC using MS Excel.  The PC's 6 1/2 dgits went away later with a firmware change and hasn't been seen since.

I Understand that the DM3058 and DM3058E both have a LCD Display capable of displaying the 6 1/2 digits. And if this is valid, could a DM3058E/DM3058 possibly be hacked into a DM3068 'close enough' to also display 6 1/2 digits?

I asking on this thread because this seems to be where you real sharp software/firmware guys are hanging out.

PS  Thank you so very much for putting color into my DP832.
By the way I sent the SCPI command via USB using EEVbloger 'PeDre' Messinstrumente (Measuring instruments - program for data transfer and control) which is very easy and fast.  Here is a English link to 'Messinstrumente' (Measuring instruments - program for data transfer and control) ->  https://translate.google.com/translate?hl=en&sl=de&u=http://peter.dreisiebner.at/messinstrumente/index.htm

Edit: Added that I used 'Messinstrumente' to send SCPI command for DP832/A
« Last Edit: July 16, 2019, 12:09:22 am by ted572 »
 

Offline Macbeth

  • Super Contributor
  • ***
  • Posts: 2571
  • Country: gb
Re: Need help hacking DP832 for multicolour option.
« Reply #266 on: July 09, 2019, 12:15:24 am »
When I first got a Rigol DM3058E (Bench-Top DMM) several years ago I would get 6 1/2 digit voltage measurement data when I queried it via USB from my PC using MS Excel.  The PC's 6 1/2 dgits went away later with a firmware change and hasn't been seen since.

In your Excel VBA code you can change the reading mode to CMDSET AGILENT instead of CMDSET RIGOL. This will even give you 8 1/2 digits for free!  :-+ With two caveats... The first of which is you will have to filter out some garbage from the SCPI READ? results, a bug I reported nearly half a decade ago to RIGOL, and still not fixed. The second is most of those extra digits are just noise anyway.

Quote
I Understand that the DM3058 and DM3058E both have a LCD Display capable of displaying the 6 1/2 digits. And if this is valid, could a DM3058E/DM3058 possibly be hacked into a DM3068 'close enough' to also display 6 1/2 digits?

The DM3068 is an entirely different beast to the DM3058 despite the outward appearances. The least of which it uses an LM399 for 7V ref instead of the MAX6325 2.5V ref used in the DM3058.

There is no software hack to switch a 3058 to a 3068, they are completely different hardware and firmware.

(However the firmware for the 3058 is unencrypted and quite hackable for those so inclined.)
 
The following users thanked this post: ted572

Offline ted572

  • Frequent Contributor
  • **
  • Posts: 399
  • Country: us
  • Radio Communications Equipment/System Design Engr.
Re: Need help hacking DP832 for multicolour option.
« Reply #267 on: July 09, 2019, 06:09:06 pm »
When I first got a Rigol DM3058E (Bench-Top DMM) several years ago I would get 6 1/2 digit voltage measurement data when I queried it via USB from my PC using MS Excel.  The PC's 6 1/2 dgits went away later with a firmware change and hasn't been seen since.

I Understand that the DM3058 and DM3058E both have a LCD Display capable of displaying the 6 1/2 digits. And if this is valid, could a DM3058E/DM3058 possibly be hacked into a DM3068 'close enough' to also display 6 1/2 digits?

The DM3068 is an entirely different beast to the DM3058 despite the outward appearances. The least of which it uses an LM399 for 7V ref instead of the MAX6325 2.5V ref used in the DM3058.

There is no software hack to switch a 3058 to a 3068, they are completely different hardware and firmware.

(However the firmware for the 3058 is unencrypted and quite hackable for those so inclined.)

When Rigol NA was located in Ohio one of the Support Specialist there told me that the DM3058 and DM3058E DMMs were calibrated on the same Test Fixture as the DM3068, and the he understood that the sixth digit I saw on  the MS Excel work sheet was indeed valid.  Although of course that I couldn't expect the same accuracy as the DM3068. No problem with this, although if the DM3058/E firmware isn't encrypted, that gives me hope that we may be possibly able to get a another digit to be displayed (for 6 1/2 digits).  That indeed would in it-self be very nice.

Do you have any thoughts on the possibility of at least being able to get a 6 1/2 Display capability on the DM3058/3058E?  I'm only asking for your opinion.  And thank you for your initial reply to me, as I certainly understand the difference between  the DM5058/E and DM3068 much better now.    Cheers, Ted
« Last Edit: July 09, 2019, 07:11:52 pm by ted572 »
 

Online tv84

  • Super Contributor
  • ***
  • Posts: 3212
  • Country: pt
Re: Need help hacking DP832 for multicolour option.
« Reply #268 on: July 09, 2019, 07:11:18 pm »
I included here the list of DM3058 / DM3068 SCPI commands based on the latest .LDR.  The FW has 3 separate SCPI command blocks.

https://www.eevblog.com/forum/testgear/lists-of-rigol-scpi-commands/msg2460030/#msg2460030

I think there are commands that allow a model change.

What's the output of?

:SYSTem:TYPE?
« Last Edit: July 09, 2019, 07:28:33 pm by tv84 »
 
The following users thanked this post: thm_w, ted572

Offline ted572

  • Frequent Contributor
  • **
  • Posts: 399
  • Country: us
  • Radio Communications Equipment/System Design Engr.
Re: Need help hacking DP832 for multicolour option.
« Reply #269 on: July 09, 2019, 07:30:42 pm »
I included here the list of DM3058 / DM3068 SCPI commands based on the latest .LDR.  The FW has 3 separate SCPI command blocks.

https://www.eevblog.com/forum/testgear/lists-of-rigol-scpi-commands/msg2460030/#msg2460030

I think there are commands that allow a model change.

What's the output of?

:SYSTem:TYPE?
Hello TV84:  The output is -> DM3058E        Thanks, Ted
 

Online tv84

  • Super Contributor
  • ***
  • Posts: 3212
  • Country: pt
Re: Need help hacking DP832 for multicolour option.
« Reply #270 on: July 09, 2019, 07:34:25 pm »
Hello TV84:  The output is -> DM3058E        Thanks, Ted

Hi Ted, what's the difference between the E and non-E versions?
 

Offline ted572

  • Frequent Contributor
  • **
  • Posts: 399
  • Country: us
  • Radio Communications Equipment/System Design Engr.
Re: Need help hacking DP832 for multicolour option.
« Reply #271 on: July 09, 2019, 07:52:25 pm »
TV84:

RE: Hi Ted, what's the difference between the E and non-E versions?
DM3058 and DM3058E are both 5 1/5 digit Bench-Top DMMs, but he DM308E does not have GPIB or Ethernet (10/100Mbit LAN) that the DM3058 does have.  That is the only difference that I know of.

I was hoping that the DM3058 and DM3068 were similar other than the 5 1/2 vs. 6 1/2 digits, but    Macbeth pointed out that they are not similar.    Thanks for your help, Ted
 

Offline ted572

  • Frequent Contributor
  • **
  • Posts: 399
  • Country: us
  • Radio Communications Equipment/System Design Engr.
Re: Need help hacking DP832 for multicolour option.
« Reply #272 on: July 10, 2019, 01:25:04 am »
I included here the list of DM3058 / DM3068 SCPI commands based on the latest .LDR.  The FW has 3 separate SCPI command blocks.

https://www.eevblog.com/forum/testgear/lists-of-rigol-scpi-commands/msg2460030/#msg2460030

I think there are commands that allow a model change.
Hello TV84:  I couldn't find anything for changing the model type/name.  Although thank you for the suggestion to look in your SCPI command list.  I scanned the files manually, and performed automatic file searches.   Ted

Edit: Of course I could try using :SYSTem:TYPE DM3068    As this would be the natural command, and we know :SYSTem:TYPE? works to find the Model Type.  It seems like it may be low risk? ?   But I don't want to brick my unit.

Edit 2: I used  :SYSTem:TYPE DM3068 plus various combinations of the command structure and nothing worked to do anything.  The plus side is that all is still OK with my DM3058E. So no 6 1/2 digits for it, but its not bricked either.
« Last Edit: July 10, 2019, 04:51:42 pm by ted572 »
 

Offline mike47203

  • Newbie
  • Posts: 7
  • Country: us
Re: Need help hacking DP832 for multicolour option.
« Reply #273 on: July 10, 2019, 01:56:48 am »
So, I am trying to enable the 16m option on my newly upgraded DG1022Z using what starec and tv84 mentioned here, but I am not having any luck. It seems I haven't successfully modified riglol1.03d to make it work. I changed the private key and the character maps, but generated key is still incorrect. I am sure I am missing something. Any help would be appreciated.

I attached a diff file of how I changed riglol.
« Last Edit: July 10, 2019, 02:47:48 am by mike47203 »
 

Offline starec

  • Newbie
  • Posts: 5
  • Country: sk
Re: Need help hacking DP832 for multicolour option.
« Reply #274 on: July 10, 2019, 11:09:14 am »
Ok, 1-2 weeks ago i've modified riglol 1.03d for DG1000Z generation/calculation

here is a full source code:
Code: [Select]
char version[]             = "Riglol 1.03d";
char DP832_private_key[]   = "5C393C30FACCF4"; //publ: 0x5EC2D25AE85124
char DS2000_private_key[]  = "8EEBD4D04C3771"; //publ: 0x8445B2BE29E5C7
char DSA815_private_key[]  = "80444DFECE903E"; //publ: 0x691213692D18FA
char DS1000Z_private_key[] = "6F1106DDA994DA"; //publ: 0x58E9F183B924BB
char DG1000Z_private_key[] = "7412E98108CAB0"; //publ: 0x586E719859AF6C

static char* ascii_map;
static const char ascii_map_dg[] = "MNBVCXZASDFGHJKLPUYTREWQ23456789";
static const char ascii_map_[] = "23456789ASDFGHJKLPUYTREWQMNBVCXZ";

char no_private_key[]      = "";

/*
** sign the secret message (serial + opts) with the private key
*/
void ecssign(char *serial, char *options, char *privk, char *lic1, char *lic2) {
    char prime1[]  = "AEBF94CEE3E707";
    char prime2[]  = "AEBF94D5C6AA71";
    char curve_a[] = "2982";
    char curve_b[] = "3408";
    char point1[]  = "7A3E808599A525";
    char point2[]  = "28BE7FAFD2A052";
    int k_offset = 0; // optionally change ecssign starting offset (changes lic1; makes different licenses)
    mirsys(800, 16)->IOBASE = 16;

    sha sha1;
    shs_init(&sha1);

    char *ptr = serial;
    while(*ptr) shs_process(&sha1, *ptr++);
    ptr = options;
    while(*ptr) shs_process(&sha1, *ptr++);

    char h[20];
    shs_hash(&sha1, h);
    big hash = mirvar(0);
    bytes_to_big(20, h, hash);

    big a = mirvar(0);
    instr(a, curve_a);
    big b = mirvar(0);
    instr(b, curve_b);
    big p = mirvar(0);
    instr(p, prime1);
    big q = mirvar(0);
    instr(q, prime2);
    big Gx = mirvar(0);
    instr(Gx, point1);
    big Gy = mirvar(0);
    instr(Gy, point2);
    big d = mirvar(0);
    instr(d, privk);
    big k = mirvar(0);
    big r = mirvar(0);
    big s = mirvar(0);
    big k1 = mirvar(0);
    big zero = mirvar(0);

    big f1 = mirvar(17);
    big f2 = mirvar(53);
    big f3 = mirvar(905461);
    big f4 = mirvar(60291817);

    incr(k, k_offset, k);
    epoint *G = epoint_init();
    epoint *kG = epoint_init();
    ecurve_init(a, b, p, MR_PROJECTIVE);
    epoint_set(Gx, Gy, 0, G);

    for(;;) {
        incr(k, 1, k);

        if(divisible(k, f1) || divisible(k, f2) || divisible(k, f3) || divisible(k, f4))
            continue;

        ecurve_mult(k, G, kG);
        epoint_get(kG, r, r);
        divide(r, q, q);

        if(mr_compare(r, zero) == 0)
            continue;

        xgcd(k, q, k1, k1, k1);
        mad(d, r, hash, q, q, s);
        mad(s, k1, k1, q, q, s);

        if(!divisible(s, f1) && !divisible(s, f2) && !divisible(s, f3) && !divisible(s, f4))
            break;
    }

    cotstr(r, lic1);
    cotstr(s, lic2);
}

/*
** convert string to uppercase chars
*/
char *strtoupper(char *str) {
    char *p;
    for (p=str; *p; p++)
        *p = toupper(*p);
    return str;
}

/*
** prepend a char to a string
*/
char *prepend(char *c, char *str) {
    int i;

    for (i = strlen(str); i >= 0; i--) {
        str[i + 1] = str[i];
    }

    str[0] = *c;
    return c;
}

/*
** convert hex-ascii-string to rigol license format
*/
void map_hex_to_rigol(char *io) {
    unsigned long long b = 0;
    int i = 0;
    char map[] = {
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
        'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R',
        'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
        '2', '3', '4', '5', '6', '7', '8', '9'
    };

    /* hex2dez */
    while (io[i] != '\0') {
        if (io[i] >= '0' && io[i] <= '9') {
            b = b * 16 + io[i] - '0';
        } else if (io[i] >= 'A' && io[i] <= 'F') {
            b = b * 16 + io[i] - 'A' + 10;
        } else if (io[i] >= 'a' && io[i] <= 'f') {
            b = b * 16 + io[i] - 'a' + 10;
        }
        i++;
    }

    for (i = 3; ; i--) {
        io[i] = map[b & 0x1F];
        if (i == 0) break;
        b >>= 5;
    }

    io[4] = '\0';
}

char *get_version() {
  char *v;

  v=version;
  return v;
}

void show_help(char *cmd) {
    printf("%s\n", get_version());
    printf("\n");
    printf("Usage: %s <sn> <opts> <privkey>\n", cmd);
    printf("  <sn>       serial number of device (D............)\n");
    printf("  <opts>     device options, 4 characters, see below\n");
    printf("  <privkey>  private key (optional)\n");
    printf("\n");
    printf("DP832 starting from v1.09 device options:\n");
    printf("  first character:  F = official, B = trial\n");
    printf("  F3PT - Accuracy\n");
    printf("  F6PT - Analyzer and Monitor\n");
    printf("  F6LT - LAN\n");
    printf("  FALT - RS232\n");
    printf("  FLLT - Trigger\n");
    printf("\n");
    printf("DP832 up to v1.06 device options:\n");
    printf("  first character:  M = official, 5 = trial\n");
    printf("  MWSS - Trigger\n");
    printf("  MWTB - Accuracy\n");
    printf("  MWTC - LAN and RS232\n");
    printf("  MWTE - Analyzer and Monitor\n");
    printf("\n");
    printf("DS1000z device options:\n");
    printf("  DSAB - Advanced Triggers\n");
    printf("  DSAC - Decoders\n");
    printf("  DSAE - 24M Memory\n");
    printf("  DSAJ - Recorder\n");
    printf("  DSBA - 500uV Vertical\n");
    printf("\n");
    printf("DG1000z device options:\n");
    printf("  JBNE - 16M Memory\n");
    printf("\n");
    printf("DS2000 device options:\n");
    printf("  first character:  D = official, V = trial\n");
    printf("  DSAB - Advanced Triggers\n");
    printf("  DSAC - Decoders\n");
    printf("  DSAE - 56M Memory\n");
    printf("  DSAJ - 100MHz\n");
    printf("  DSAS - 200MHz\n");
    printf("  DSAZ - all options\n");
    printf("\n");
    printf("DS4000 device options:\n");
    printf("  first character:  D = official, V = trial\n");
    printf("  DSHB - RS232 Decoder\n");
    printf("  DSHC - SPI Decoder\n");
    printf("  DSHE - I2C Decoder\n");
    printf("  DSHJ - CAN Decode\n");
    printf("  DSHS - FlexRay Decoder\n");
    printf("  DSH9 - all options\n");
    printf("\n");
    printf("DSA815 device options:\n");
    printf("  first character:  A = official, S = trial\n");
    printf("  AAAB - Tracking Generator\n");
    printf("  AAAC - Advnced Measurement Kit\n");
    printf("  AAAD - 10Hz RBW\n");
    printf("  AAAE - EMI/Quasi Peak\n");
    printf("  AAAF - VSWR\n");
    printf("\n");
    printf("MAKE SURE YOUR FIRMWARE IS UP TO DATE BEFORE APPLYING ANY KEYS\n");
}

static int ascii_to_bin(char c)
{
    int i;

    for (i = 0; i < 0x20; i++)
        if (ascii_map[i] == c)
            break;
    return i;
}

static char *options_4to5(const char *opt4, char *opt5)
{
    int map[] = { 0, 3, 2, 1 };
    int i, opt = 0;

    for (i = 0; i < 4; i++)
        opt = (opt << 5) | ascii_to_bin(opt4[map[i]]);
    for (i = 0; i < 5; i++) {
        opt5[i] = ascii_map[opt & 0x0F];
        opt >>= 4;
    }
    opt5[i] = 0;
    return opt5;
}

static void format_license_dp832_109(char *lic1_code, char *lic2_code,
                                     char *options, char *licence, int isDG)
{
    const int map1dp[] = { 4, 11, 16, 23, 0, 24, 6, 22, 8, 20, 18, 25 };
    const int map2dp[] = { 3, 14, 19, 9, 26, 5, 1, 10, 12, 13, 15, 21 };
    const int map3dp[] = { 2, 7, 17, 27 };

    const int map1dg[] = {3, 0xE, 0x13, 9, 0x1A, 5, 7, 0x11, 0xC, 0x18, 6, 0x16};
    const int map2dg[] = {4, 0xB, 0x10, 0x17, 0, 8, 0x14, 0x1B, 2, 0xD, 0xF, 0x15};
    const int map3dg[] = {1, 0xA, 0x12, 0x19};

    const int *map1 = isDG?map1dg:map1dp;
    const int *map2 = isDG?map2dg:map2dp;
    const int *map3 = isDG?map3dg:map3dp;
    unsigned long long k;
    int i;

    k = strtoll(lic1_code, NULL, 16);
    for (i = 0; k < (1ULL << 51); i++)
        k = (k << 4) | 0;
    k = (k << 4) | i;
    for (i = 0; i < 12; i++) {
        licence[map1[i]] = ascii_map[k & 0x1F];
        k >>= 5;
    }

    k = strtoll(lic2_code, NULL, 16);
    for (i = 0; k < (1ULL << 51); i++)
        k = (k << 4) | 5;
    k = (k << 4) | i;
    for (i = 0; i < 12; i++) {
        licence[map2[i]] = ascii_map[k & 0x1F];
        k >>= 5;
    }

    if (isDG) {
        int map[] = { 0, 3, 2, 1 };
char *opt = strdup(options);
for (i = 0; i < 4; i++)
    opt[i] = options[map[i]];
for (i = 0; i < 4; i++)
    licence[map3[i]] = opt[3 - i];
        free(opt);
    }
    else
for (i = 0; i < 4; i++)
    licence[map3[i]] = options[i];

    licence[28] = 0;
}

static void format_license_classic(char *lic1_code, char *lic2_code,
                                   char *options, char *licence)
{
    char *lic_all, *chunk, *temp;
    int i, j;

    /* fix missing zeroes */
    while (strlen(lic1_code) < 14) {
        prepend("0", lic1_code);
    }
    while (strlen(lic2_code) < 14) {
        prepend("0", lic2_code);
    }

    /* combine lic1 and lic2 */
    lic_all = (char*)calloc(128, 1);
    temp = (char*)calloc(128, 1);
    chunk = (char*)calloc(6, 1);
    strcpy(lic_all, lic1_code);
    strcat(lic_all, "0");
    strcat(lic_all, lic2_code);
    strcat(lic_all, "0");

    /* generate serial */
    i=0;
    while (i < strlen(lic_all)) {
        memcpy(chunk, lic_all + i, 5);
        map_hex_to_rigol(chunk);
        strcat(temp, chunk);
        i = i + 5;
    }

    /* add options and "-" */
    j = 0;
    for(i = 0; i <= strlen(temp); ) {
       switch(j) {
         case 1:  licence[j] = options[0];  break;
         case 7:  licence[j] = '-';         break;
         case 10: licence[j] = options[1];  break;
         case 15: licence[j] = '-';         break;
         case 19: licence[j] = options[2];  break;
         case 23: licence[j] = '-';         break;
         case 28: licence[j] = options[3];  break;
         default: licence[j] = temp[i];
                  i++;
       }
       j++;
    }
    licence[j] = '\0';

    /* cleen up */
    free(lic_all);
    free(chunk);
    free(temp);
}

char *make_licence(char *serial, char *options, char* priv_key)
{
    char options_buffer[8], *opts = options;
    char *lic1_code, *lic2_code, *lic_all;
    char *chunk, *temp, *licence;
    int i, j;

    /* convert string to uppercase chars */
    strtoupper(serial);
    strtoupper(options);
    strtoupper(priv_key);

    int isDG = strncmp(serial, "DG1", 3)?0:1;
    /* convert options string format for DP832 with firmware >= 1.09 or for DG1000Z*/
    if ((!strncmp(serial, "DP8", 3) && options[0] != 'M' && options[0] != '5') || isDG)
        opts = options_4to5(options, options_buffer);

    /* sign the message */
    lic1_code = (char*)calloc(64, 1);
    lic2_code = (char*)calloc(64, 1);
    ecssign(serial, opts, priv_key, lic1_code, lic2_code);

    /* format licence string */
    licence = (char*)calloc(128, 1);
if ((!strncmp(serial, "DP8", 3) && *options != 'M' && *options != '5') || isDG)
        format_license_dp832_109(lic1_code, lic2_code, options, licence, isDG);
    else
        format_license_classic(lic1_code, lic2_code, options, licence);

    /* cleen up */
    free(lic1_code);
    free(lic2_code);

    return licence;
}

char *select_priv_key(char *serial) {
    char *priv_key;

    strtoupper(serial);
    if      (!strncmp(serial, "DS1", 3)) priv_key = DS1000Z_private_key;
    else if (!strncmp(serial, "DS2", 3)) priv_key = DS2000_private_key;
    else if (!strncmp(serial, "DS4", 3)) priv_key = DS2000_private_key;
    else if (!strncmp(serial, "DSA", 3)) priv_key = DSA815_private_key;
    else if (!strncmp(serial, "DP8", 3)) priv_key = DP832_private_key;
    else if (!strncmp(serial, "DG1", 3)) priv_key = DG1000Z_private_key;
    else                                 priv_key = no_private_key;

    return priv_key;
}

int main(int argc, char *argv[0]) {
    char *serial, *options, *priv_key, *licence;

    /* parse input */
    if (!((argc == 3 || argc == 4))) {
        show_help(argv[0]);
        exit(1);
    }
    serial = argv[1];
    options = argv[2];

    ascii_map = strncmp(serial, "DG1", 3)?(char*)ascii_map_:(char*)ascii_map_dg;

    if (argc == 4) priv_key = argv[3];
    else {
        priv_key = select_priv_key(serial);
        if (strlen(priv_key) == 0) {
            show_help(argv[0]);
            printf("\nERROR: UNKNOW DEVICE WITHOUT PRIVATKEY\n");
            exit(1);
        }
    }

    if (strlen(priv_key) != 14) {
        show_help(argv[0]);
        printf("\nERROR: INVALID PRIVATE KEY LENGTH\n");
        exit(1);
    }
    if (strlen(serial) < 13) {
        show_help(argv[0]);
        printf("\nERROR: INVALID SERIAL LENGTH\n");
        exit(1);
    }
    if (strlen(options) != 4) {
        show_help(argv[0]);
        printf("\nERROR: INVALID OPTIONS LENGTH\n");
        exit(1);
    }

    licence = make_licence(serial, options, priv_key);
    printf("%s\n", licence);
    free(licence);
}

Edit: I've added missing line to the function ecssign
« Last Edit: July 13, 2019, 08:16:16 am by starec »
 
The following users thanked this post: thm_w, RoGeorge, Houseman, 1anX, thierer, WhichEnt2, bd139, mike47203, ppsilva, blubillcanada


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf