Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Module works on windows, but not linux

 
Post new topic   Reply to topic Printable version
 View previous topic  can't attach modules Post :: Post modules  View next topic  
Author Message
Doc Flabby
Server Help Squatter


Joined: Feb 26 2006
Posts: 636
Offline

PostPosted: Thu Jan 17, 2008 5:48 am    Post subject: Module works on windows, but not linux Reply to topic Reply with quote

I've created my own "encryption" module. The code compiles on both platforms, but doesnt work properly on linux, basically is doesnt decrypt the packets on linux, but it does on windows. I don't know much about C so i'm guessing something i've done with the pointers is dangerous so linux doesn't like it but windows doesn't care. I've attached the code.

I'm probably doing something really stupid icon_smile.gif
_________________
Rediscover online gaming. Get Subspace | STF The future...prehaps




enc

enc_ss2.c - 7.69 KB
File downloaded or viewed 32 time(s)
Back to top
View users profile Send private message Add User to Ignore List
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Thu Jan 17, 2008 12:50 pm    Post subject: Reply to topic Reply with quote

Without looking at it, I would wonder if byte order perhaps had something to do with it?
_________________

Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Doc Flabby
Server Help Squatter


Joined: Feb 26 2006
Posts: 636
Offline

PostPosted: Fri Jan 18, 2008 4:49 am    Post subject: Reply to topic Reply with quote

D1st0rt wrote:
Without looking at it, I would wonder if byte order perhaps had something to do with it?

The byte order should be the same, as both systems are 32-bit Intel x86.

Also it just seems like the its doing the decryption fine, but then not passing the value back to ASSS. Instead it uses the value originally passed to it. Bizarrly on windows its works fine, with the same code icon_sad.gif
Back to top
View users profile Send private message Add User to Ignore List
Doc Flabby
Server Help Squatter


Joined: Feb 26 2006
Posts: 636
Offline

PostPosted: Sun Jan 20, 2008 9:55 am    Post subject: Reply to topic Reply with quote

Code: Show/Hide

int do_dec(EncData *ed, byte *data, int len)
{
   //packet to small
   if(len < 13) return 0; 
         
   //my key holds key
   byte *mykey = (byte*)ed->key;
   //display IV if its there
    #ifdef CFG_LOG_CONNECTION
    lm->Log(L_DRIVEL, "<enc_ss2> CLIENTKEY");
    dump_pk(mykey,16);
    lm->Log(L_DRIVEL, "<enc_ss2> END KEY"); 
    #endif
   //get IV
   byte *IV = data;   
   byte *Content = data+8;
   
   byte* moreData = amalloc(len-8);
   memcpy(moreData, Content, len-8);

   //init and clear decryption key
   byte deckey[24];
   memset(&deckey[0], 0, 24);
   byte* deckeypos = &deckey[0];

   memcpy (deckeypos, mykey, 16);
   memcpy (deckeypos+16, IV, 8);

   #ifdef CFG_LOG_CONNECTION
   lm->Log(L_DRIVEL, "<enc_ss2> IV");
   dump_pk(deckeypos,24);
   lm->Log(L_DRIVEL, "<enc_ss2> END IV"); 
   #endif

   struct MD5Context ctx;

   byte out[16];

   MD5Init(&ctx);
   MD5Update(&ctx, deckeypos, 24);
   MD5Final(out, &ctx);

    #ifdef CFG_LOG_CONNECTION
   lm->Log(L_DRIVEL, "<enc_ss2> MD5");
   dump_pk(&out[0],16);
   lm->Log(L_DRIVEL, "<enc_ss2> END MD5"); 
   #endif
   //out contains the sessionkey
   
   
    #ifdef CFG_LOG_CONNECTION
   lm->Log(L_DRIVEL, "<enc_ss2> DATA TO DECRYPT");
   dump_pk(moreData,len-8);
   lm->Log(L_DRIVEL, "<enc_ss2> END DATA TO DECRYPT"); 
   #endif

   rc4_skip((byte*)&out, 16, 1024,moreData,len-8);
   
   memcpy(data,moreData+4,len-12);
   afree(moreData);
   
    #ifdef CFG_LOG_CONNECTION
   lm->Log(L_DRIVEL, "<enc_ss2> DECRYPTED DATA");
   dump_pk(data,len-12);
   lm->Log(L_DRIVEL, "<enc_ss2> END DECRYPTED DATA"); 
   #endif
   

   
   return len-12;
}

int Decrypt(Player *p, byte *data, int len)
{
   #ifdef CFG_LOG_CONNECTION
   lm->Log(L_DRIVEL, "<enc_ss2> Decrypt %i",len);
   #endif
   EncData *ed, **p_ed = PPDATA(p, enckey);
   pthread_mutex_lock(&mtx);
   ed = *p_ed;
   pthread_mutex_unlock(&mtx);
   return ed ? do_dec(ed, data, len) : len;
}


I've narrowed down the problem. do_dec(ed, data, len) is not being called. However it should be as I have unwravelled the line into separate if statements and can confirm ed does exist so it should be called.
Back to top
View users profile Send private message Add User to Ignore List
k0zy
Server Help Squatter


Gender:Gender:Male
Joined: Jan 11 2003
Posts: 571
Location: Germany
Offline

PostPosted: Sun Jan 20, 2008 10:22 am    Post subject: Reply to topic Reply with quote

Maybe some other thread manipulates "ed" so it equals a value interpreted as false?
_________________
It's a shark! Oh my god! Unbelievable!
Back to top
View users profile Send private message Add User to Ignore List
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Sun Jan 20, 2008 10:25 am    Post subject: Reply to topic Reply with quote

Set a breakpoint in the calling function and step it through.
_________________
Hyperspace Owner

Smong> so long as 99% deaths feel lame it will always be hyperspace to me
Back to top
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Doc Flabby
Server Help Squatter


Joined: Feb 26 2006
Posts: 636
Offline

PostPosted: Sun Jan 20, 2008 10:37 am    Post subject: Reply to topic Reply with quote

I located the problem

Code: Show/Hide

int do_dec(EncData *ed, byte *data, int len)

needed to be
Code: Show/Hide

local int do_dec(EncData *ed, byte *data, int len)

works like a charm now. Still don't understand what the difference between the two is...but nevermind...
Back to top
View users profile Send private message Add User to Ignore List
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:41
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Sun Jan 20, 2008 3:40 pm    Post subject: Reply to topic Reply with quote

local is an alias for static in ASSS. When you make a function static in C, it is known only in that file, no other. It helps keep the namespace clean.

GCC compiler attempted to find the best do_dec when compiling that file, and it found correct one. Windows's compiler attempted to find the best one, and it sounds like it found the vie encryption's do_dec, which is not local. It failed the tests in there, and returned nothing.

So yes, this is a bug in ASSS where the vie encryption's file is filling the namespace with functions it shouldn't be. I'd recommend reporting it as a bug.
Back to top
View users profile Send private message Add User to Ignore List Send email
k0zy
Server Help Squatter


Gender:Gender:Male
Joined: Jan 11 2003
Posts: 571
Location: Germany
Offline

PostPosted: Sun Jan 20, 2008 3:54 pm    Post subject: Reply to topic Reply with quote

Mine GO BOOM wrote:
GCC compiler attempted to find the best do_dec when compiling that file, and it found correct one. Windows's compiler attempted to find the best one, and it sounds like it found the vie encryption's do_dec, which is not local. It failed the tests in there, and returned nothing.


I didn't understand that...
The way you explained it, it would have failed on windows and not on linux.
Back to top
View users profile Send private message Add User to Ignore List
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:41
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Sun Jan 20, 2008 8:31 pm    Post subject: Reply to topic Reply with quote

Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole.... wrote:
I didn't understand that...
The way you explained it, it would have failed on windows and not on linux.

Ok, so I got it reversed. Either way, one of the compilers found the right function, and the other one didn't. The real issue is that there are two functions of the same prototype trying to fill the same namespace. I'm pretty sure one or both of the compilers should show a warning about that.
Back to top
View users profile Send private message Add User to Ignore List Send email
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Mon Jan 21, 2008 12:07 pm    Post subject: Reply to topic Reply with quote

Actually, from my understanding, it was a linker issue, and not a compiler one.

The dynamic linker tries to resolve things a little differently between the two operating systems. So when it was loaded under linux, it used the function that already existed in memory, where as in windows it used the function that was in the .dll.
Back to top
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Animate Dreams
Gotta buy them all!
(Consumer whore)


Age:37
Gender:Gender:Male
Joined: May 01 2004
Posts: 821
Location: Middle Tennessee
Offline

PostPosted: Mon Jan 21, 2008 10:22 pm    Post subject: Re: Module works on windows, but not linux Reply to topic Reply with quote

Doc Flabby wrote:
I don't know much about C so i'm guessing something i've done with the pointers is dangerous so linux doesn't like it but windows doesn't care.


I've always heard that Linux cared much less about things like that. That Linux didn't try to protect the OS from the user. So wouldn't that go the opposite way?
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address MSN Messenger
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Mon Jan 21, 2008 11:53 pm    Post subject: Reply to topic Reply with quote

Apples and oranges. Windows generally tries to separate the internals of the OS from the user with lots of nice, easy-to-use (ahem) dialogs, while Linux typically allows the user lots of options through text config files and stuff. How the operating system deals with applications is unrelated.
_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Goldeye
Novice


Gender:Gender:Male
Joined: Dec 15 2003
Posts: 57
Offline

PostPosted: Thu Jan 31, 2008 11:21 pm    Post subject: Re: Module works on windows, but not linux Reply to topic Reply with quote

Animate Dreams wrote:
[..]



I've always heard that Linux cared much less about things like that. That Linux didn't try to protect the OS from the user. So wouldn't that go the opposite way?


This is the compiler and linker we're talking about, not the OS, anyway. (Though I guess ld is part of the os?)
Any system should report what it's doing for an undefined behavior.


Anyway, Flabby. Just add local to the do_enc in both files. Also. probably a good idea to just change the function names in your module.
Back to top
View users profile Send private message Add User to Ignore List Send email
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> ASSS Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 254 page(s) served in previous 5 minutes.

phpBB Created this page in 0.450116 seconds : 40 queries executed (91.8%): GZIP compression disabled