PDA

View Full Version : module1 01-08-09


Little Kenobe
01-09-2009, 05:52 AM
thanks to noone at ET

{ // module 1 for NA (20080502 [1,2,3,4,5,6,7,8,9,10,11,12,13,14])
BIGNUM *A=BN_new(); BIGNUM *B=BN_new(); BIGNUM *C=BN_new(); BIGNUM *D=BN_new();
BIGNUM *J=BN_new(); BIGNUM *Z=BN_new(); BN_CTX *ctx=BN_CTX_new();
unsigned char *_a=hw,*_b=&hw[0x10],*_c=&hw[0x20],*_d=&hw[0x30],*_j=&hw[0x40],*_z=hw;
unsigned int m=0x27+0x72+(A00[4]&0x3F)-0x79;
unsigned char xr=((A00[2]-1)&3)+0x0A;
A00[0]|=A00[9];
memset(hw,0,sizeof(hw));
memcpy(hw,A00,0x05);
ExpandInput(hw);
RotateBytes(_a,0x10); BN_bin2bn(_a,0x10,A); RotateBytes(_a,0x10);
RotateBytes(_b,0x10); BN_bin2bn(_b,0x10,B);
RotateBytes(_c,0x10); BN_bin2bn(_c,0x10,C);
RotateBytes(_d,0x10); BN_bin2bn(_d,0x10,D);
RotateBytes(_j,0x08); BN_bin2bn(_j,0x08,J);
switch ((m<<8)|A00[3]) {
case 0x3AC9:
{
BIGNUM *tmp1 = BN_new();
BIGNUM *tmp2 = BN_new();
BIGNUM *tmp3 = BN_new();
BN_rshift(tmp1,D,64);
BN_mask_bits(tmp1,64);
BN_lshift(tmp1,tmp1,64);
BN_copy(tmp2,D);
BN_mask_bits(tmp2,64);
BN_rshift(tmp2,tmp2,16);
BN_copy(tmp3,D);
BN_mask_bits(tmp3,16);
BN_lshift(tmp3,tmp3,48);
BN_copy(D,tmp1);
BN_add(D,D,tmp2);
BN_add(D,D,tmp3);
BN_copy(Z,D);
memset(_z,0,8);
}
break;
case 0x4692:
{
BIGNUM *s = BN_new();
BIGNUM *x = BN_new();
BIGNUM *y = BN_new();
BIGNUM *v = BN_new();
BN_zero(v);
BN_sub(J,v,D);
BN_set_bit(J,0);
BN_set_bit(v,64);
BN_mod_inverse(J,J,v,ctx);
BN_mask_bits(J,64);
BN_zero(v);
BN_set_bit(v,136);
BN_mod(B,v,D,ctx);
for(int j=0;j<2;j++) {
int Boctets=(BN_num_bytes(B)+7)>>3;
BN_zero(s);
for(int i=0; i<Boctets; i++) {
BN_rshift(x,B,i<<6);
BN_mask_bits(x,64);
BN_mul(x,x,B,ctx);
BN_add(s,s,x);
BN_copy(x,s);
BN_mask_bits(x,64);
BN_mul(x,x,J,ctx);
BN_lshift(C,x,64);
BN_add(C,C,x);
BN_rshift(C,C,2);
BN_add(C,C,s);
BN_rshift(C,C,52);
BN_mask_bits(C,12);
BN_mask_bits(x,64);
BN_mul(x,x,D,ctx);
BN_add(s,s,x);
BN_lshift(y,s,12);
BN_add(C,C,y);
BN_mask_bits(C,128);
BN_rshift(s,s,64);
BN_copy(Z,s);
BN_mod(s,s,D,ctx);
}
BN_copy(B,s);
}
if (xr==0x0C) BN_copy(Z,C);
BN_mask_bits(Z,128);
memset(_z,0,0x10);
}
break;
case 0x3D6D:
{
BIGNUM *x=BN_new();
BIGNUM *i1=BN_new();
BIGNUM *i2=BN_new();
BIGNUM *o=BN_new();
BIGNUM *s=BN_new();
RotateBytes(&hw[0x50],0x10);
BN_bin2bn(&hw[0x50],0x10,D);
BN_copy(i1,B);
BN_copy(i2,B);
BN_zero(x);
BN_sub(J,x,D);
BN_set_bit(J,0);
BN_set_bit(x,64);
BN_mod_inverse(J,J,x,ctx);
BN_mask_bits(J,64);
BN_zero(s);
for (int i=0; i<2; i++)
{
BN_rshift(x,i1,i<<6);
BN_mask_bits(x,64);
BN_mul(x,x,i2,ctx);
BN_add(s,s,x);
BN_copy(x,s);
BN_mask_bits(x,64);
BN_mul(x,x,J,ctx);
BN_mask_bits(x,64);
BN_mul(x,x,D,ctx);
BN_add(s,s,x);
BN_rshift(s,s,64);
BN_copy(o,s);
if (BN_cmp(s,D)==1)
{
BN_copy(x,s);
BN_sub(s,x,D);
}
}
BN_mask_bits(o,128);
BN_copy(Z,o);
memset(_z,0,0x10);
}
break;
case 0x3963: //
case 0x3967:
BN_rshift(Z,C,64);
BN_lshift(Z,Z,64);
memset(_z,0,0x10);
break;
case 0x3B6A:
case 0x3B89:
{
BIGNUM *v=BN_new();
BN_zero(v);
BN_set_bit(v,128);
BN_mod(Z,v,D,ctx);
memset(_z,0,0x10);
}
break;
case 0x3E8C:
{
BIGNUM *v=BN_new();
BN_zero(v);
BN_set_bit(v,136);
BN_mod(Z,v,D,ctx);
memset(_z,0,0x10);
}
break;
case 0x3986:
case 0x3A58:
case 0x3E68:
{
BIGNUM *v=BN_new();
BN_zero(v);
BN_set_bit(v,136);
BN_mod(Z,v,D,ctx);
memset(_z,0,0x10);
}
break;
case 0x2100 ... 0x21FF:
case 0x39B0:
case 0x3BB0:
case 0x3EAE:
{
BIGNUM *v=BN_new();
BN_zero(v);
BN_sub(J,v,D);
BN_set_bit(J,0);
BN_set_bit(v,64);
BN_mod_inverse(J,J,v,ctx);
BN_mask_bits(J,64);
BN_mod(D,D,v,ctx);
BN_mul(C,J,D,ctx);
BN_rshift(C,C,64);
BN_mask_bits(C,64);
BN_copy(Z,C);
memset(_z,0,8);
}
break;
case 0x25AB:
{
BIGNUM *v=BN_new();
BN_zero(v);
BN_sub(B,v,D);
BN_set_bit(B,0);
BN_set_bit(v,128);
BN_mod_inverse(B,B,v,ctx);
BN_mask_bits(B,128);
BN_mod(D,D,v,ctx);
BN_mul(C,B,D,ctx);
BN_rshift(C,C,128);
BN_mask_bits(C,128);
BN_copy(Z,C);
memset(_z,0,0x10);
}
break;
case 0x3A75:
BN_mask_bits(B,64);
BN_copy(Z,B);
memset(_z,0,8);
break;
case 0x3846:
{
BIGNUM *s = BN_new();
BIGNUM *x = BN_new();
int Boctets=(BN_num_bytes(B)+7)>>3;
BN_zero(s);
for(int i=0; i<Boctets; i++) {
BN_rshift(x,B,i<<6);
BN_mask_bits(x,64);
BN_mul(x,x,B,ctx);
BN_add(s,s,x);
BN_copy(x,s);
BN_mask_bits(x,64);
BN_mul(x,x,J,ctx);
BN_mask_bits(x,64);
BN_mul(x,x,D,ctx);
BN_add(s,s,x);
BN_rshift(s,s,64);
BN_copy(Z,s);
if(BN_cmp(s,D)==1) BN_sub(s,s,D);
}
BN_mask_bits(Z,128);
memset(_z,0,0x10);
}
break;
case 0x3E92:
BN_copy(Z,A);
memset(_z,0,0x10);
break;
case 0x3E95:
case 0x3E90:
case 0x3C9F:
case 0x3CA0:
case 0x3CA5:
{
BIGNUM *s = BN_new();
BIGNUM *x = BN_new();
BIGNUM *y = BN_new();
BIGNUM *v = BN_new();
BN_zero(v);
BN_sub(J,v,D);
BN_set_bit(J,0);
BN_set_bit(v,64);
BN_mod_inverse(J,J,v,ctx);
BN_mask_bits(J,64);
BN_zero(v);
BN_set_bit(v,136);
BN_mod(B,v,D,ctx);
for(int j=0;j<((A00[3]-0x85)>>3);j++) {
int Boctets=(BN_num_bytes(B)+7)>>3;
BN_zero(s);
for(int i=0; i<Boctets; i++) {
BN_rshift(x,B,i<<6);
BN_mask_bits(x,64);
BN_mul(x,x,B,ctx);
BN_add(s,s,x);
BN_copy(x,s);
BN_mask_bits(x,64);
BN_mul(x,x,J,ctx);
BN_lshift(C,x,64);
BN_add(C,C,x);
BN_rshift(C,C,2);
BN_add(C,C,s);
BN_rshift(C,C,52);
BN_mask_bits(C,12);
BN_mask_bits(x,64);
BN_mul(x,x,D,ctx);
BN_add(s,s,x);
BN_lshift(y,s,12);
BN_add(C,C,y);
BN_mask_bits(C,128);
BN_rshift(s,s,64);
BN_copy(Z,s);
BN_mod(s,s,D,ctx);
}
BN_copy(B,s);
}
if (xr==0x0C) BN_copy(Z,C);
BN_mask_bits(Z,128);
memset(_z,0,0x10);
}
break;
}
BN_bn2bin(Z,_z); RotateBytes(_z,BN_num_bytes(Z));
for (int i=11;i>-1;i--) hw[i]^=hw[i+4]; memset(&hw[4],0,0x7C);
}

JT
01-09-2009, 07:17 AM
Thanks for bringing it over LK. I'm sticking the thread even though I haven't tested it yet. Anyone else verify this module is working?

dssnerd
01-09-2009, 07:37 AM
Working for me...

Thanks LK!!!

scottie
01-09-2009, 02:21 PM
Yeah - works great! Thanks LK.

noone
01-09-2009, 05:09 PM
aren't you duplicating the same exact code of case 0x3E95: case 0x3E90: case 0x3C9F: case 0x3CA0: case 0x3CA5: in the the case of 0x4692 ? is there a reason not to just add the case 0x4692 to the other cases? just wondering.

sirdrinks
01-09-2009, 07:28 PM
I think it just died...

Little Kenobe
01-09-2009, 08:50 PM
aren't you duplicating the same exact code of case 0x3E95: case 0x3E90: case 0x3C9F: case 0x3CA0: case 0x3CA5: in the the case of 0x4692 ? is there a reason not to just add the case 0x4692 to the other cases? just wondering.

noone its almost the same but with one difference

case 0x46
for(int j=0;j<2;j++) {

case 0x3C,etc..
for(int j=0;j<((A00[3]-0x85)>>3);j++) {

i seen some modules that had 0x46 coded with 0x3C but it would freeze
whenever map3C was used .. prolly a way to make it work with a little editing

nice catch noone but all this was done from your work .. hehe

LK

sirdrinks
01-10-2009, 01:32 AM
This might be considered off topic, if so, I apologize...do the most recent module releases address/incorporate all previous MAP calls? I noticed the date on the above code (May 08), it's my understanding that they're cycling the MAP calls? Are they mutating the existing map calls to screw us up?

Little Kenobe
01-10-2009, 01:45 AM
dont worry about the date on the module .. seems nobody ever updates it
all known maps are in the module or in the cemu source files

ex: case 0x4692 is map46 and its interrupt (92) in hex

noone
01-10-2009, 02:46 AM
I remember I explained it to one of the members there, but I don't remember if it was in a pm or in a thread, but both evaluates to the same thing: ((A00[3]-0x85)>>3) in the case of 0x46 evaluates to 2, and in 0x3c evaluates to 3 the form of J< ((A00[3]-0x85)>>3) is a general form, while J < 2 is a special case, I don't remember that I posted it as a special case, but everything is possible :)

day_tona2
01-10-2009, 04:22 AM
can someone zip all the source up so i can compile it haven't used cemu in a while so don't know what all to add where before complying...

thanks