Jump to content

Recommended Posts

Posted (edited)

Hey guys, long time lurker, first time poster here. Recently I've been delving into building an Online version of the popular Pokesav, and It's going fairly well so far, reading and writing data is a cinch, however I'm having a lot of trouble with the PRNG. I've browsed Codemonkey85's open source libraries and ported his VB PRNG class to PHP, and it seems to work just fine, but the values I'm getting after decrypting don't line up with the values in Pokesav.

I've been bending my brain for about 2 or 3 hours trying to get this decryption to work. I've tried my own solutions, then I tried porting Codemonkey85's solution, but nothing seems to hit the nail on the head. Can someone please hold my hand with this one and explain to me exactly what I should be doing? I'm fairly certain I've got the basics down flat, but my implementation is probably out of whack.

I have the PV, which matches the Pokesav PV. Using that, I use the code (($PV >> 0xD) & 0x1F) % 24; to get the Shift Value (which in this case is ADCB). I get the 2-Byte Checksum as an integer, which in this case is 63432. Using this Checksum I seed the PRNG ($m_seed in the ported class). Then I do a loop to loop from the 8th byte through to the 135th, during which I get 2 bytes at a time stored in $Before, and then calculate $After using this formula: $After = ($Before ^ ($PRNG->NextNum() >> 0x10));. Then I modify the data from bytes 8 to 135 using $Data[$i+1] = ($After >> 0x08); and $Data[$i] = ($After & 0xFF);.

Afterwards I use a switch to determine which block I'm supposed to be analyzing and I begin reading out data from there. However, as I stated before, the data doesn't match what it should be. Does anyone have any idea what I'm doing wrong? This is really making me scratch my brain.

Thanks,

Jeff

EDIT:

I just thought about how some people reading this might not understand or recognize PHP bitwise operators, so to clarify ^ is XOR, & is AND, >> is Right Shift and << is Left Shift.

EDIT 2:

Well I worked through it this morning with a clear head and got it working fine. Turns out I made a simple mistake (by doing a for loop that increased $i by 1 instead of 2, to account for the fact that I'm working with 2 bytes) and I am happy I didn't actually rely on the assistance of others to solve it.

Edited by Jeff

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...