Hi, I want to share the algorithm to decrypt and encrypt the setup is a simple algorithm, but as I have not seen here sharing it with you.
The method is made in vb. Net but there is no problem to port them to other languages because of its simplicity.
if this is not correct would appreciate propose optimization and/or correction.
Also I have the structure to read the decrypted buff, but the structure is not finished, need to correct some lengths of the variables.
Code for read buff dec with structure Marshall
Sorry for my english :P
The method is made in vb. Net but there is no problem to port them to other languages because of its simplicity.
Code:
Public Function EncDecBuff2(ByVal pBuff As Byte()) As Byte()
Dim tmpBuff As Byte() = New Byte(UBound(pBuff)) {}
For i = 0 To UBound(tmpBuff)
If Int(tmpBuff(i) / 4) Mod 2 Then tmpBuff(i) -= 4 Else tmpBuff(i) += 4
Next
Return tmpBuff
End Function
if this is not correct would appreciate propose optimization and/or correction.
Also I have the structure to read the decrypted buff, but the structure is not finished, need to correct some lengths of the variables.
Code:
<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Ansi)> _ Public Structure SetupConfig
Public ServerIndex As Integer
Public ServerNumber As Integer
Public split1 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=23)> _
Public ServerName As String
Public View1100X As Byte
Public ViewAdmission As Byte
Public TestServer As Short
Public TestLevel As Short
Public Unknown1 As Short
Public TestGold As Integer
Public TestUserLimit As Integer
Public split2 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=23)> _
Public DBSrvIP As String
Public DBSRVPort As Integer 'Size 74
Public split3 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=23)> _
Public IDSRVIP As String
Public IDSRVPort As Integer
Public split4 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=23)> _
Public MSGIP As String
Public MSGPort As Integer
Public HumLimit As Integer
Public MonLimit As Integer
Public ZenLimit As Integer
Public NPCLimit As Integer
Public SocLimit As Integer
Public DecLimit As Integer
Public Unknown2 As Integer
Public Unknown3 As Integer
Public SendBlock As Integer
Public CheckBlock As Integer
Public AvailableBlock As Integer
Public GateLoad As Integer
Public UserFull As Integer
Public ZenFastStep As Integer
Public split5 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=23)> _
Public LOGSRVIP As String
Public LOGSRVPort As Integer
Public DiscountForNightTime As Integer
Public HalfFeeStart As Integer
Public HalfFeeEnd As Integer
Public split6 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=51)> _
Public EmergencyMapName As String
Public EmergencyMapX As Integer
Public EmergencyMapY As Integer
Public split7 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=11)> _
Public WarriorStartMapName As String
Public WarriorStartMapX As Integer
Public WarriorStartMapY As Integer
Public split8 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=11)> _
Public WizardStartMapName As String
Public WizardStartMapX As Integer
Public WizardStartMapY As Integer
Public split9 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=11)> _
Public TaoistStartMapName As String
Public TaoistStartMapX As Integer
Public TaoistStartMapY As Integer
Public split10 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=20)> _
Public HeroDBIP As String
Public split11 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=20)> _
Public HeroDBUsername As String
Public split12 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=20)> _
Public HeroDBPassword As String
Public split13 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=20)> _
Public HeroDBName As String
Public split14 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=20)> _
Public GameDBIP As String
Dim split15 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=20)> _
Public GameDBUsername As String
Dim split16 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=20)> _
Public GameDBPassword As String
Dim split17 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=20)> _
Public GameDBName As String
Public Unknown4 As Integer
Public ExtraExpRate As Double
Public ExtraMoneyRate As Double
Public ExtraItemRate As Double
Public ExtraMonGenRate As Double
Public Unknown5 As Integer
Public Unknown6 As Integer
Public Unknown7 As Byte
Public split18 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=100)> _
Public BaseDir As String
Public split19 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=100)> _
Public GuildDir As String
Public split20 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=100)> _
Public GuildList As String
Public split21 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=100)> _
Public VentureDir As String
Public split22 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=100)> _
Public ConLogDir As String
Public split23 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=100)> _
Public KoreaDir As String
Public split24 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=100)> _
Public EnvirDir As String
Public split25 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=100)> _
Public MapDir As String
Public split26 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=100)> _
Public LogDir As String
Public Unknown8 As Short
Public ItemNumber As Integer
Public split27 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=100)> _
Public ClientPath1 As String
Public split28 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=100)> _
Public ClientPath2 As String
Public split29 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=100)> _
Public ClientPath3 As String
Public split30 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public MaleStartArmor As String
Public split31 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public FemaleStartArmor As String
Public split32 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public StartWeapon As String
Public split33 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public StartCandle As String
Public split34 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public StartDrug As String
Public split35 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public GoldOre As String
Public split36 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public IronOre As String
Public split37 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public CopperOre As String
Public split38 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public SilverOre As String
Public split39 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public BlackIronOre As String
Public split40 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public ZumaGuardian As String
Public split41 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public ZumaStatue As String
Public split42 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public ZumaArcher As String
Public split43 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public WedgeMoth As String
Public split44 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public BugBat As String
Public split45 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public Larva As String
Public split46 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public WoomaHorn As String
Public split47 As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public ZumaRelic As String
Public split48 As Byte
Public Unknown9 As Short
Public Unknown10 As Short
Public Unknown11 As Byte
Public Unknown12 As Byte
End Structure
Code for read buff dec with structure Marshall
Code:
Public Function DecryptSetup(ByVal pPathSetup As String) As SetupConfig
If IO.File.Exists(pPathSetup) Then
Dim buff As Byte() = IO.File.ReadAllBytes(pPathSetup)
buff = EncDecBuff(buff)
Dim reader As New IO.BinaryReader(New IO.MemoryStream(buff), System.Text.Encoding.Default)
Dim handle As GCHandle = GCHandle.Alloc(reader.ReadBytes(Marshal.SizeOf(GetType(SetupConfig))), GCHandleType.Pinned)
reader.Close()
Return Marshal.PtrToStructure(handle.AddrOfPinnedObject(), GetType(SetupConfig))
Else
MsgBox("The file selected not found", MsgBoxStyle.Exclamation, "ERROR")
Return New SetupConfig
End If
End Function
Sorry for my english :P