News:

Holy shit, it's 2018 2019 2020 2021 2022 2023 2024, and the US isn't a fascist country! What a time to be alive.

Main Menu

Check this please

Started by Hdx, November 02, 2008, 01:44:37 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Hdx

    System.out.format("M %08X %08X %08X %08X\n", buf[0], buf[1], buf[2], buf[3]);
    for(int x = 3; x > -1; x--){
  int y = buf[x] * 5;
  System.out.println(buf[x] * 5);
      buf[x] = decodedByte + y;
      decodedByte = y;
}
System.out.format("M %08X %08X %08X %08X\n", buf[0], buf[1], buf[2], buf[3]);

decodedByte starts at 2;
M 00000000 00000000 00000000 00000001
5
0
0
0
M 00000000 00000000 00000005 00000007

WHY THE HELL is the 3rd int being set to 5?

http://img140.exs.cx/img140/6720/hdxnew6lb.gif
09/08/05 - Clan SBs @ USEast
[19:59:04.000] <DeadHelp> We don't like customers.
[19:59:05.922] <DeadHelp> They're assholes
[19:59:08.094] <DeadHelp> And they're never right.

Sidoh

"y" is 5 on the first iteration, so decodedByte is 5 on the second iteration.  You add 5 to 0, you should get 5, no?

Hdx

#2
Ya, I noticed that, i'm trying to figure out what makes it diffrent form this:
while(rounds-- > 0){
  long param1 = bufA[posA--] & 0x00000000FFFFFFFFl;
  long param2 = mulx & 0x00000000FFFFFFFFl;
  long edxeax = param1 * param2;
      bufB[posB--] = decodedByte + (int)edxeax;
  System.out.println(decodedByte + " " + edxeax);
      decodedByte = (int)(edxeax >> 32);
    }
m 00000000 00000000 00000000 00000001
2 5
0 0
0 0
0 0
m 00000000 00000000 00000000 00000007

God damnet
32-bit ints != 64-bit ints
http://img140.exs.cx/img140/6720/hdxnew6lb.gif
09/08/05 - Clan SBs @ USEast
[19:59:04.000] <DeadHelp> We don't like customers.
[19:59:05.922] <DeadHelp> They're assholes
[19:59:08.094] <DeadHelp> And they're never right.

Sidoh

lol, yuck.  I might try to stare at it later.  I'm going to crank out some more crap for an assignment I have due in a few days and hit the sack for now, though.

Ender

Quote from: Sidoh on November 02, 2008, 01:55:46 AM
lol, yuck.  I might try to stare at it later.  I'm going to crank out some more crap [...] and hit the sack for now, though.

vivid imagery

iago

#5
btw, "int" and "long" and stuff aren't portable.

Use stdint.h and then use int32_t, uint32_t, int64_t, uint64_t, etc.


Nevermind, thought you were using C. :P

Hdx

#6
Quote from: HdxBmx27 on November 02, 2008, 01:52:54 AM
God damnet
32-bit ints != 64-bit ints
I was using a 32-bit in when I should of used a 64-bit in.
I fixed that. Now I'm on the final loop of WC3 decoding.

  uint32_t eax, ecx, edx;
  uint32_t location;
  e = 0;
  for(c = 0; c < 120; c++){
    eax = c & 0x1F;
ecx = e & 0x1F;
edx = 3 - (edi >> 5);

location = 12 - ((e >> 5) << 2);
ebp = values[location / 4];
ebp = (ebp & (1 << ecx)) >> ecx;
values[edx] = ((ebp & 1) << eax) | (~(1 << eax) & values[edx]);
printf("%08X %08X %08X %08X\n", values[0], values[1], values[2], values[3]);
e = (e + 11) % 120;
  }
Not working correctly. I'll look at it more later. But now, i'm at the mall hoping the owner of the WiFi i'm on [SSID: Uv been hAcked] will try and hack/talk to me









#ifndef CDKEYS_C
#define CDKEYS_C
#define hexvalue(n)  (((n) & 0x0F) + (((n) & 0x0F) < 10 ? 0x30 : 0x37))
#define numvalue(n)   (toupper(n) - (isdigit(n) ? 0x30 : 0x37))
#include "cdkeys.h"

uint8_t *orig_key = "246789BCDEFGHJKMNPRTVWXZ";
uint8_t *war3_key = "246789BCDEFGHJKMNPRTVWXYZ";

uint8_t star_seq[12] = {6, 0, 2, 9, 3, 11, 1, 7, 5, 4, 10, 8};
uint8_t wcd2_seq[16] = {5, 6, 0, 1, 2, 3, 4, 9, 1, 11, 12, 13, 14, 15, 7, 8};

uint8_t TranslateTable[] = {
    0x09, 0x04, 0x07, 0x0F, 0x0D, 0x0A, 0x03, 0x0B, 0x01, 0x02, 0x0C, 0x08,
    0x06, 0x0E, 0x05, 0x00, 0x09, 0x0B, 0x05, 0x04, 0x08, 0x0F, 0x01, 0x0E,
    0x07, 0x00, 0x03, 0x02, 0x0A, 0x06, 0x0D, 0x0C, 0x0C, 0x0E, 0x01, 0x04,
    0x09, 0x0F, 0x0A, 0x0B, 0x0D, 0x06, 0x00, 0x08, 0x07, 0x02, 0x05, 0x03,
    0x0B, 0x02, 0x05, 0x0E, 0x0D, 0x03, 0x09, 0x00, 0x01, 0x0F, 0x07, 0x0C,
    0x0A, 0x06, 0x04, 0x08, 0x06, 0x02, 0x04, 0x05, 0x0B, 0x08, 0x0C, 0x0E,
    0x0D, 0x0F, 0x07, 0x01, 0x0A, 0x00, 0x03, 0x09, 0x05, 0x04, 0x0E, 0x0C,
    0x07, 0x06, 0x0D, 0x0A, 0x0F, 0x02, 0x09, 0x01, 0x00, 0x0B, 0x08, 0x03,
    0x0C, 0x07, 0x08, 0x0F, 0x0B, 0x00, 0x05, 0x09, 0x0D, 0x0A, 0x06, 0x0E,
    0x02, 0x04, 0x03, 0x01, 0x03, 0x0A, 0x0E, 0x08, 0x01, 0x0B, 0x05, 0x04,
    0x02, 0x0F, 0x0D, 0x0C, 0x06, 0x07, 0x09, 0x00, 0x0C, 0x0D, 0x01, 0x0F,
    0x08, 0x0E, 0x05, 0x0B, 0x03, 0x0A, 0x09, 0x00, 0x07, 0x02, 0x04, 0x06,
    0x0D, 0x0A, 0x07, 0x0E, 0x01, 0x06, 0x0B, 0x08, 0x0F, 0x0C, 0x05, 0x02,
    0x03, 0x00, 0x04, 0x09, 0x03, 0x0E, 0x07, 0x05, 0x0B, 0x0F, 0x08, 0x0C,
    0x01, 0x0A, 0x04, 0x0D, 0x00, 0x06, 0x09, 0x02, 0x0B, 0x06, 0x09, 0x04,
    0x01, 0x08, 0x0A, 0x0D, 0x07, 0x0E, 0x00, 0x0C, 0x0F, 0x02, 0x03, 0x05,
    0x0C, 0x07, 0x08, 0x0D, 0x03, 0x0B, 0x00, 0x0E, 0x06, 0x0F, 0x09, 0x04,
    0x0A, 0x01, 0x05, 0x02, 0x0C, 0x06, 0x0D, 0x09, 0x0B, 0x00, 0x01, 0x02,
    0x0F, 0x07, 0x03, 0x04, 0x0A, 0x0E, 0x08, 0x05, 0x03, 0x06, 0x01, 0x05,
    0x0B, 0x0C, 0x08, 0x00, 0x0F, 0x0E, 0x09, 0x04, 0x07, 0x0A, 0x0D, 0x02,
    0x0A, 0x07, 0x0B, 0x0F, 0x02, 0x08, 0x00, 0x0D, 0x0E, 0x0C, 0x01, 0x06,
    0x09, 0x03, 0x05, 0x04, 0x0A, 0x0B, 0x0D, 0x04, 0x03, 0x08, 0x05, 0x09,
    0x01, 0x00, 0x0F, 0x0C, 0x07, 0x0E, 0x02, 0x06, 0x0B, 0x04, 0x0D, 0x0F,
    0x01, 0x06, 0x03, 0x0E, 0x07, 0x0A, 0x0C, 0x08, 0x09, 0x02, 0x05, 0x00,
    0x09, 0x06, 0x07, 0x00, 0x01, 0x0A, 0x0D, 0x02, 0x03, 0x0E, 0x0F, 0x0C,
    0x05, 0x0B, 0x04, 0x08, 0x0D, 0x0E, 0x05, 0x06, 0x01, 0x09, 0x08, 0x0C,
    0x02, 0x0F, 0x03, 0x07, 0x0B, 0x04, 0x00, 0x0A, 0x09, 0x0F, 0x04, 0x00,
    0x01, 0x06, 0x0A, 0x0E, 0x02, 0x03, 0x07, 0x0D, 0x05, 0x0B, 0x08, 0x0C,
    0x03, 0x0E, 0x01, 0x0A, 0x02, 0x0C, 0x08, 0x04, 0x0B, 0x07, 0x0D, 0x00,
    0x0F, 0x06, 0x09, 0x05, 0x07, 0x02, 0x0C, 0x06, 0x0A, 0x08, 0x0B, 0x00,
    0x0F, 0x04, 0x03, 0x0E, 0x09, 0x01, 0x0D, 0x05, 0x0C, 0x04, 0x05, 0x09,
    0x0A, 0x02, 0x08, 0x0D, 0x03, 0x0F, 0x01, 0x0E, 0x06, 0x07, 0x0B, 0x00,
    0x0A, 0x08, 0x0E, 0x0D, 0x09, 0x0F, 0x03, 0x00, 0x04, 0x06, 0x01, 0x0C,
    0x07, 0x0B, 0x02, 0x05, 0x03, 0x0C, 0x04, 0x0A, 0x02, 0x0F, 0x0D, 0x0E,
    0x07, 0x00, 0x05, 0x08, 0x01, 0x06, 0x0B, 0x09, 0x0A, 0x0C, 0x01, 0x00,
    0x09, 0x0E, 0x0D, 0x0B, 0x03, 0x07, 0x0F, 0x08, 0x05, 0x02, 0x04, 0x06,
    0x0E, 0x0A, 0x01, 0x08, 0x07, 0x06, 0x05, 0x0C, 0x02, 0x0F, 0x00, 0x0D,
    0x03, 0x0B, 0x04, 0x09, 0x03, 0x08, 0x0E, 0x00, 0x07, 0x09, 0x0F, 0x0C,
    0x01, 0x06, 0x0D, 0x02, 0x05, 0x0A, 0x0B, 0x04, 0x03, 0x0A, 0x0C, 0x04,
    0x0D, 0x0B, 0x09, 0x0E, 0x0F, 0x06, 0x01, 0x07, 0x02, 0x00, 0x05, 0x08
};

uint32_t cdkeys_instr(uint8_t *string, uint8_t find){
  uint8_t *location = strchr(string, toupper(find));
  return (location == NULL ? -1 : location - string);
}

/*******************************************************
*Converts and ASCII strign of number into a long.
*Used in Starcraft Key decoding.
*******************************************************/
uint32_t cdkeys_strtol(uint8_t *number, uint32_t length, uint32_t base){
  uint8_t *temp = safe_malloc(length);
  memcpy(temp, number, length);
  temp[length] = 0;
  uint32_t ret = strtol(temp, NULL, base);
  free(temp);
  return ret;
}

BOOLEAN cdkeys_verifystarcraft(uint8_t *key){
  uint32_t sum = 3;
  uint32_t i = 0;
  if(strlen(key) != 13) return FALSE;
  for(i = 0; i < 12; i++)
    sum += (key[i] - '0') ^ (sum << 1);
  return (sum % 10 == key[12] - '0');
}
/*****************************************************************************
*Reterives the Public, Private, and Product values from an 'old style'
*Starcraft cdkey, AE: the 13-digit numerical key.
*****************************************************************************/
BOOLEAN cdkeys_getstarcraftvalues(uint8_t *key, uint32_t *public_key, uint32_t *private_key, uint32_t *product){
  if(cdkeys_verifystarcraft(key) == FALSE) return FALSE;
  uint32_t hashkey = 0x13AC9741;
  uint8_t sequance[12] = {6, 0, 2, 9, 3, 11, 1, 7, 5, 4, 10, 8};
  uint8_t *temp_key = safe_malloc(13);
  int32_t c;
  for(c = 11; c >= 0; c--){
    if(key[sequance[c]] <= '7'){
  temp_key[c] = key[sequance[c]] ^ (uint8_t)(hashkey & 7);
  hashkey >>= 3;
}else
  temp_key[c] = key[sequance[c]] ^ (uint8_t)(c & 1);
  }
 
  *product     = cdkeys_strtol(temp_key,   2, 10);
  *public_key  = cdkeys_strtol(temp_key+2, 7, 10);
  *private_key = cdkeys_strtol(temp_key+9, 3, 10);
  free(temp_key);
  return (product != 0 && public_key != 0 && private_key != 0 ? TRUE : FALSE);
}

BOOLEAN cdkeys_verifydiablo(uint8_t *key, uint8_t **decoded){
  if(strlen(key) != 16) return FALSE;
  uint8_t *temp_key = safe_malloc(16);
  uint8_t i;
  uint32_t n = 0;
  uint32_t checksum = 0;
  uint32_t r = 1;

  for(i = 0; i < 16; i +=2){
    n = (cdkeys_instr(orig_key, key[i + 1]) + (cdkeys_instr(orig_key, key[i])  * 24));
if(n >= 0x100){
  n -= 0x100;
  checksum |= r;
}
r <<= 1;
temp_key[i] = hexvalue(n >> 4);
temp_key[i + 1] = hexvalue(n);
  } 
  n = 3;
  for(i = 0; i < 16; i++)
    n += numvalue(temp_key[i]) ^ n * 2;
 
  if((n & 0xFF) != checksum){
    free(temp_key);
    return FALSE;
  }
 
  if(decoded != NULL) *decoded = temp_key;
  else free(temp_key);
 
  return TRUE;
}

BOOLEAN cdkeys_getdiablovalues(uint8_t *key, uint32_t *public_key, uint32_t *private_key, uint32_t *product){
  uint8_t *temp_key = safe_malloc(16);
  if(cdkeys_verifydiablo(key, &temp_key) == FALSE){
    free(temp_key);
    return FALSE;
  }
  uint32_t hashkey = 0x13AC9741;
  uint16_t i;
  uint8_t n;
  uint8_t c;
 
  for(i = 15; i < 16; i--){
    n = (i > 8 ? i - 9 : 7 + i);
c = temp_key[n];
temp_key[n] = temp_key[i];
temp_key[i] = c;
  }
 
  for(i = 15; i < 16; i--){
    if(temp_key[i] <= '7'){
  temp_key[i] ^= (hashkey & 7);
  hashkey >>= 3;
}else if(temp_key[i] < 'A')
  temp_key[i] ^= (i & 1);
  }
 
  *product     = cdkeys_strtol(temp_key,   2, 16);
  *public_key  = cdkeys_strtol(temp_key+2, 6, 16);
  *private_key = cdkeys_strtol(temp_key+8, 8, 16);
 
  free(temp_key);
  return ((product != 0) && (public_key != 0) && (private_key != 0));
}

BOOLEAN cdkeys_getwarcraftvalues(uint8_t *key, uint32_t *public_key, uint32_t *private_key, uint32_t *product){
  uint8_t *table = safe_malloc(52);
  uint32_t *values = safe_malloc(16);
  uint32_t c = 0;
  uint8_t d = 0;
  uint64_t e;
  uint32_t f = 30;
  uint32_t g;
  uint32_t h;
 
  for(c = 0; c < 26; c++){
d = cdkeys_instr(war3_key, toupper(key[c]));
table[f] = (d / 5);
f = (f + 49) % 52;
table[f] = (d % 5);
f = (f + 49) % 52;
  }
 
  for(c = 51; c < 52; c--){
    for(d = 3; d < 4; d--){
  e = (uint64_t)values[d] * 5;
  values[d] = table[c] + (uint32_t)e;
  table[c] = (uint8_t)(e >> 32);
}
  }

  f = 24;
  d = 2;
  for(c = 0x1D0; c < 0x1D1; c -= 0x10){
f = (f + 28) % 32;
g = (values[d / 8] & (0x0F << f)) >> f;
h = 24;
for(e = 29; e < 30; e--){
  h = (h + 28) % 32;
  if(e != (c / 0x10))
    g = TranslateTable[((values[3 - (e >> 3)] & (0x0F << h)) >> h) ^ TranslateTable[g + c] + c];
}
values[d / 8] = ((TranslateTable[g + c] & 0x0F) << f) | ~(0x0F << f) & values[d / 8];
d++;
  }
  uint32_t eax, ecx, edx;
  uint32_t location;
  e = 0;
  for(c = 0; c < 120; c++){
    eax = c & 0x1F;
ecx = e & 0x1F;
edx = 3 - (edi >> 5);

location = 12 - ((e >> 5) << 2);
ebp = values[location / 4];
ebp = (ebp & (1 << ecx)) >> ecx;
values[edx] = ((ebp & 1) << eax) | (~(1 << eax) & values[edx]);
printf("%08X %08X %08X %08X\n", values[0], values[1], values[2], values[3]);
e = (e + 11) % 120;
  }
  /*for(edi = 0; edi < 120; edi++)
    {
      eax = edi & 0x1F;
      ecx = esi & 0x1F;
      edx = 3 - (edi >>> 5);
     
      int location = 12 - ((esi >>> 5) << 2);
      ebp = IntFromByteArray.LITTLEENDIAN.getInteger(Copy, location);
     
      ebp = (ebp & (1 << ecx)) >>> ecx;
      keyTable[edx] = ((ebp & 1) << eax) | (~(1 << eax) & keyTable[edx]);
  esi = (esi + 11) % 120;
  System.out.format("%03d %d %08X %08X %08X %08X %08X\n", location, edx, ebp, keyTable[0], keyTable[1], keyTable[2], keyTable[3]);
    }
*/


 
  for(c = 0; c < 4; c++){
    printf("%08X ", values[c]);
  }
}

#endif
once I get it finished I will clean it up, I'm going to clean code, and willing to sacrifice a bit of effiancy to do it. So please don't complain to me about it.
http://img140.exs.cx/img140/6720/hdxnew6lb.gif
09/08/05 - Clan SBs @ USEast
[19:59:04.000] <DeadHelp> We don't like customers.
[19:59:05.922] <DeadHelp> They're assholes
[19:59:08.094] <DeadHelp> And they're never right.

warz

why would we complain to you about it? not like your code is the first and only option. youre months behind, imo. have fun :P
http://www.chyea.org/ - web based markup debugger

Joe

Quote from: HdxBmx27 on November 02, 2008, 08:24:35 PM
But now, i'm at the mall hoping the owner of the WiFi i'm on [SSID: Uv been hAcked] will try and hack/talk to me

lolwut
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


Camel


<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Camel

#10
Quote
    System.out.format("M %08X %08X %08X %08X\n", buf[0], buf[1], buf[2], buf[3]);
    for(int x = 3; x > -1; x--){
  int y = buf[x] * 5;
  System.out.println(buf[x] * 5);
      buf[x] = decodedByte + y;
      decodedByte = y;
}
System.out.format("M %08X %08X %08X %08X\n", buf[0], buf[1], buf[2], buf[3]);

Ya, I noticed that, i'm trying to figure out what makes it diffrent form this:
while(rounds-- > 0){
  long param1 = bufA[posA--] & 0x00000000FFFFFFFFl;
  long param2 = mulx & 0x00000000FFFFFFFFl;
  long edxeax = param1 * param2;
      bufB[posB--] = decodedByte + (int)edxeax;
  System.out.println(decodedByte + " " + edxeax);
      decodedByte = (int)(edxeax >> 32);
    }


Just a guess, but I'm pretty sure that decodedByte = y; and decodedByte = (int)(edxeax >> 32); do radically different things :)

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Hdx

Well dua i'm years behind. I haven't gotten it working 100% yet.  [Who knew a 7 month old could erase 1/2 a file and save it?]
But I just did a comparison, and it runs ~27 times faster in C then it does in Java. [No surprise there] Its helping me learn a bit more about the cdkey system/C. So its worth it.
http://img140.exs.cx/img140/6720/hdxnew6lb.gif
09/08/05 - Clan SBs @ USEast
[19:59:04.000] <DeadHelp> We don't like customers.
[19:59:05.922] <DeadHelp> They're assholes
[19:59:08.094] <DeadHelp> And they're never right.

Lead

Quote from: HdxBmx27 on November 04, 2008, 09:52:39 PM
Well dua i'm years behind. I haven't gotten it working 100% yet.  [Who knew a 7 month old could erase 1/2 a file and save it?]
But I just did a comparison, and it runs ~27 times faster in C then it does in Java. [No surprise there] Its helping me learn a bit more about the cdkey system/C. So its worth it.

In a year or two this knowledge is going to be all outdated, even more so than it is now.


QuoteSon, if you really want something in this life, you have to work for it. Now quiet! They're about to announce the lottery numbers. - Homer Simpson

Camel

#13
Quote from: Hdx on November 04, 2008, 09:52:39 PM
But I just did a comparison, and it runs ~27 times faster in C then it does in Java.

I'd be willing to bet money that one or all of the following is true:
* You have hotspot disabled (or have a debugger attached) during the Java sample
* You are compiling the C code to 64-bit machine code, and comparing it to a 32-bit JVM
* You are not logging in your C code, or if you are, you are using stdout instead of cout

If none of these are the case, then you have something seriously wrong with your Java configuration. Hotspot transforms the Java bytecode to machine code that should run similarly to the machine code generated by the c compiler - since you're not allocating any objects in either case (all your variables are primitives on the stack), the gc vs malloc argument doesn't apply.

That said, hotspot is not as good at optimization as GCC is (which I'm assuming you're using; correct me if I'm wrong), so you'll still find that the C code will run marginally faster, by not by an order of magnitude. In my preliminary tests, it's somewhere between 5% and 30% slower than GCC-generated machine code.

This will have no bearing if you're not logging, but System.out is a stream, so it's not fair to compare it to stdout; use cout in your C code for a fair comparison.

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Hdx

Ya, I had a few problems with the code when i first tested it. As I didn't feel like verifying the results, I jsut let them both run 0x1000000 times with no logging or anything.
Turns out I had a bug that made the C code not compute 1/2 the crap.
Now i've finished it and Java runs about 70% faster then the C.
Both are still < 1/2 ms per decode, but still.
http://img140.exs.cx/img140/6720/hdxnew6lb.gif
09/08/05 - Clan SBs @ USEast
[19:59:04.000] <DeadHelp> We don't like customers.
[19:59:05.922] <DeadHelp> They're assholes
[19:59:08.094] <DeadHelp> And they're never right.