Having touble converting from Java -> PureBasic

Just starting out? Need help? Post your questions and find answers here.
SoFlawLess_
New User
New User
Posts: 5
Joined: Wed Jul 25, 2012 3:50 am

Having touble converting from Java -> PureBasic

Post by SoFlawLess_ »

Hi everyone, I'm attempting to copy over a game server written in Java. I'm almost through the login decoding but this is the part that is stopping me from finishing.

Java Vesion:

Code: Select all

	public int readDWord() {
		currentOffset += 4;
		return ((buffer[currentOffset - 4] & 0xff) << 24) + ((buffer[currentOffset - 3] & 0xff) << 16) + ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] & 0xff);
	}
	public long readQWord() {
		long l = (long)readDWord() & 0xffffffffL;
		long l1 = (long)readDWord() & 0xffffffffL;
		return (l << 32) + l1;
	}
My Attempt

Code: Select all

Procedure.l ReadDWord(*MemoryBuffer)
  dword = ((PeekB(*MemoryBuffer) & $FF) << 24) + ((PeekB(*MemoryBuffer + 1) & $FF) << 16) + ((PeekB(*MemoryBuffer + 2) & $FF) << 8) + (((PeekB(*MemoryBuffer + 3) & $FF)))
  ProcedureReturn dword
EndProcedure

Procedure.l ReadQWord(*MemoryBuffer)
		l = ReadDWord(*MemoryBuffer) & 4294967295;
		l1 = ReadDWord(*MemoryBuffer + 4) & 4294967295;
		l2 = (l << 2)
		ProcedureReturn (l2 << 30) + l1
EndProcedure
I've tried using PeekQ and PeekL but they aren't working. Maybe the problem is I can't use 32 left shift? PB is only allowing 31 as the maximum. Please help
User avatar
Demivec
Addict
Addict
Posts: 4282
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Having touble converting from Java -> PureBasic

Post by Demivec »

SoFlawLess_ wrote:I've tried using PeekQ and PeekL but they aren't working. Maybe the problem is I can't use 32 left shift? PB is only allowing 31 as the maximum.
When you say PeekQ and PeekL aren't working, did you try it like this?

Code: Select all

Procedure.l ReadDWord(*MemoryBuffer)
  ProcedureReturn PeekL(*MemoryBuffer)
EndProcedure

Procedure.q ReadQWord(*MemoryBuffer)
  ProcedureReturn PeekQ(*MemoryBuffer)
EndProcedure
I noticed that the return value that you had for the procedure ReadQWord() was specified as a long, it should be a quad. Perhaps that was the cause of your problems.
SoFlawLess_
New User
New User
Posts: 5
Joined: Wed Jul 25, 2012 3:50 am

Re: Having touble converting from Java -> PureBasic

Post by SoFlawLess_ »

Demivec wrote:
SoFlawLess_ wrote:I've tried using PeekQ and PeekL but they aren't working. Maybe the problem is I can't use 32 left shift? PB is only allowing 31 as the maximum.
When you say PeekQ and PeekL aren't working, did you try it like this?

Code: Select all

Procedure.l ReadDWord(*MemoryBuffer)
  ProcedureReturn PeekL(*MemoryBuffer)
EndProcedure

Procedure.q ReadQWord(*MemoryBuffer)
  ProcedureReturn PeekQ(*MemoryBuffer)
EndProcedure
I noticed that the return value that you had for the procedure ReadQWord() was specified as a long, it should be a quad. Perhaps that was the cause of your problems.
Thank you so much it's working now :D
User avatar
Demivec
Addict
Addict
Posts: 4282
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Having touble converting from Java -> PureBasic

Post by Demivec »

SoFlawLess_ wrote:Thank you so much it's working now :D
Your welcome.

I noticed the original code seem to advance the buffer pointer, you may want to add that back in.
Post Reply