Changeset 3232
- Timestamp:
- 01/21/10 23:13:51 (7 weeks ago)
- Location:
- trunk/lua
- Files:
-
- 2 modified
-
lib.protocol.lua (modified) (1 diff)
-
lib.proxy.lua (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lua/lib.protocol.lua
r3212 r3232 63 63 local sPacketTypeName = gPacketTypeId2Name[iId] -- get packet-type-name 64 64 local packet_debuginfo = sprintf("typeid=0x%02x,size=%d,typename=%s",iId,iPacketSize,sPacketTypeName or "") 65 local iBFSubCmd = (iId == kPacket_Generic_Command) and input:PeekNetUint16(3) 66 if (iBFSubCmd) then 67 local genname = gGenericSubCommandNamesByID[iBFSubCmd] or "???" 68 packet_debuginfo = packet_debuginfo .. sprintf(",subcmd=%s[0x%02x]",genname,iBFSubCmd) 69 end 65 70 if (not gNoLogPackets_ByPacket[iId]) then -- log on 66 71 printdebug("net",sprintf("NET: ProtocolPacketRecvHandler "..packet_debuginfo)) 67 if (gEnablePacketDebug_Short) then print("packet",packet_debuginfo) end 72 if (gEnablePacketDebug_Short) then 73 if (iBFSubCmd and gNoLogPackets_BySubCmd and gNoLogPackets_BySubCmd[iBFSubCmd]) then 74 -- skip 75 else 76 print("packet",packet_debuginfo) 77 end 78 end 68 79 if (gbPacketLogToFadeLines) then GuiAddChatLine("recv "..packet_debuginfo) end 69 80 end -
trunk/lua/lib.proxy.lua
r2986 r3232 1 1 -- uoproxy for debugging 2 2 3 function UOProxyOpenListener (port) 4 local timeout = Client_GetTicks() + 5*1000 5 local listener 6 repeat 7 listener = NetListen(port) 8 if (not listener) then print("port listen bind fail, retrying...") Client_USleep(1 * 1000) end 9 until listener or Client_GetTicks() > timeout 10 assert(listener,"failed to bind to local port "..(port or 0)) 11 return listener 12 end 3 13 function UOProxyMode (host,port) 4 14 print("starting proxy mode") … … 7 17 gProxyHost = host 8 18 gProxyPort = port 9 10 local timeout = Client_GetTicks() + 5*1000 11 repeat 12 gServerListenerTCP = NetListen(port) 13 if (not gServerListenerTCP) then print("port listen bind fail, retrying...") Client_USleep(1 * 1000) end 14 until gServerListenerTCP or Client_GetTicks() > timeout 15 assert(gServerListenerTCP,"failed to bind to local port "..(port or 0)) 19 gProxyPort2 = port+1 20 21 gServerListenerTCP = UOProxyOpenListener(gProxyPort) 22 gServerListenerTCP2 = UOProxyOpenListener(gProxyPort2) 16 23 17 24 print("listen port opened....") 18 25 19 26 while true do 27 local listener = gServerListenerTCP 20 28 while true do 21 local newcon = gServerListenerTCP:PopAccepted()29 local newcon = listener:PopAccepted() 22 30 if (not newcon) then break end 31 print("###############################") 32 print("#### PROXY : connection started, listener=",(listener == gServerListenerTCP) and "A" or "B") 33 print("###############################") 23 34 UOProxyOneConnection(newcon) 35 print("###############################") 36 print("#### PROXY : connection ended") 37 print("###############################") 38 listener = gServerListenerTCP2 24 39 --~ print("proxy end") return 25 40 end … … 106 121 --~ if (bIsFromServer and gProxyServerHuffmanStarted) then bInterpret = false end -- huffman comp&decomp active now 107 122 --~ if (bIsFromClient and gProxyServerHuffmanStarted) then bInterpret = false end -- not really needed but something seems bugged 108 123 if (gDisableProxyInterpretation) then bInterpret = false end 109 124 local bScrambleTest = false 110 125 local bClientBlockTest = true 111 126 112 if (bIsFromClient and gProxyServerHuffmanStarted and (not gProxySecondPartHeaderStarted)) then 113 gProxySecondPartHeaderStarted = true 114 local iPacketSize = 4 115 print("recv:",fromname,"4byte header before protocol start") 116 print(FIFOHexDump(fifo_in,0,iPacketSize)) 117 fifo_out:PushFIFOPartRaw(fifo_in,0,iPacketSize) 118 fifo_in:PopRaw(iPacketSize) 119 return true 120 end 121 122 -- scramble kPacket_Generic_SubCommand_Screensize (0xBF subcmd 0x05) last 5 bytes (unknown) 123 --~ bf 00 0d 00 05 00 00 03 20 3f d0 11 00 |........ ?...| 124 if (bScrambleTest and bIsFromClient and fifo_in:Size() >= 13) then 125 if (fifo_in:PeekNetUint8(0) == 0xBF and 126 fifo_in:PeekNetUint8(1) == 0x00 and 127 fifo_in:PeekNetUint8(2) == 0x0d and 128 fifo_in:PeekNetUint8(3) == 0x00 and 129 fifo_in:PeekNetUint8(4) == 0x05) then 130 fifo_in:PokeNetUint8(9,0xff) 131 fifo_in:PokeNetUint8(10,0xff) 132 fifo_in:PokeNetUint8(11,0xff) 133 fifo_in:PokeNetUint8(12,0xff) 134 print("SCRAMBLED kPacket_Generic_SubCommand_Screensize") 135 end 136 end 137 138 139 140 -- modify the unknown se packets 141 if (bIsFromClient and fifo_in:Size() >= 6) then 142 --~ bf 00 06 00 24 5e 143 if (fifo_in:PeekNetUint8(0) == 0xBF and 144 fifo_in:PeekNetUint8(1) == 0x00 and 145 fifo_in:PeekNetUint8(2) == 0x06 and 146 fifo_in:PeekNetUint8(3) == 0x00 and 147 fifo_in:PeekNetUint8(4) == 0x24) then 148 --~ fifo_in:PokeNetUint8(5,math.random(0,255)) 149 print("detected unknownSE") 150 if (bScrambleTest) then 151 fifo_in:PokeNetUint8(5,16) 152 print("SCRAMBLED unknownSE") 127 if (bInterpret) then 128 -- 4-byte-head con1 129 if (bIsFromClient and (not gProxyFirstPartHeaderStarted)) then 130 gProxyFirstPartHeaderStarted = true 131 local iPacketSize = 4 132 print("recv:",fromname,"4byte header before protocol start con1") 133 print(FIFOHexDump(fifo_in,0,iPacketSize)) 134 fifo_out:PushFIFOPartRaw(fifo_in,0,iPacketSize) 135 fifo_in:PopRaw(iPacketSize) 136 return true 137 end 138 139 -- 4-byte-head con2 140 if (bIsFromClient and gProxyServerHuffmanStarted and (not gProxySecondPartHeaderStarted)) then 141 gProxySecondPartHeaderStarted = true 142 local iPacketSize = 4 143 print("recv:",fromname,"4byte header before protocol start con2") 144 print(FIFOHexDump(fifo_in,0,iPacketSize)) 145 fifo_out:PushFIFOPartRaw(fifo_in,0,iPacketSize) 146 fifo_in:PopRaw(iPacketSize) 147 return true 148 end 149 150 -- scramble kPacket_Generic_SubCommand_Screensize (0xBF subcmd 0x05) last 5 bytes (unknown) 151 --~ bf 00 0d 00 05 00 00 03 20 3f d0 11 00 |........ ?...| 152 if (bScrambleTest and bIsFromClient and fifo_in:Size() >= 13) then 153 if (fifo_in:PeekNetUint8(0) == 0xBF and 154 fifo_in:PeekNetUint8(1) == 0x00 and 155 fifo_in:PeekNetUint8(2) == 0x0d and 156 fifo_in:PeekNetUint8(3) == 0x00 and 157 fifo_in:PeekNetUint8(4) == 0x05) then 158 fifo_in:PokeNetUint8(9,0xff) 159 fifo_in:PokeNetUint8(10,0xff) 160 fifo_in:PokeNetUint8(11,0xff) 161 fifo_in:PokeNetUint8(12,0xff) 162 print("+++++++++++++++++++++++++++++++++++++++++++++++") 163 print("SCRAMBLED kPacket_Generic_SubCommand_Screensize") 164 print("+++++++++++++++++++++++++++++++++++++++++++++++") 153 165 end 154 if (bClientBlockTest) then gProxyBlockingClient = true end 155 end 156 end 157 158 159 -- modify kPacket_Pre_Login 0x5D packet data 160 if (bScrambleTest and bIsFromClient and fifo_in:Size() >= 49) then 161 if (fifo_in:PeekNetUint8(0) == 0x5D and 162 fifo_in:PeekNetUint8(1) == 0xED and 163 fifo_in:PeekNetUint8(2) == 0xED and 164 fifo_in:PeekNetUint8(3) == 0xED and 165 fifo_in:PeekNetUint8(4) == 0xED) then 166 --~ fifo_in:PokeNetUint8(5,math.random(0,255)) 167 fifo_in:PokeNetUint8(48,0x11) 168 print("SCRAMBLED kPacket_Pre_Login") 166 end 167 168 169 170 -- modify the unknown se packets 171 if (bIsFromClient and fifo_in:Size() >= 6) then 172 --~ bf 00 06 00 24 5e 173 if (fifo_in:PeekNetUint8(0) == 0xBF and 174 fifo_in:PeekNetUint8(1) == 0x00 and 175 fifo_in:PeekNetUint8(2) == 0x06 and 176 fifo_in:PeekNetUint8(3) == 0x00 and 177 fifo_in:PeekNetUint8(4) == 0x24) then 178 --~ fifo_in:PokeNetUint8(5,math.random(0,255)) 179 print("+++++++++++++++++++++++++++++++++++++++++++++++") 180 print("detected unknownSE") 181 print("+++++++++++++++++++++++++++++++++++++++++++++++") 182 if (bScrambleTest) then 183 fifo_in:PokeNetUint8(5,16) 184 print("SCRAMBLED unknownSE") 185 end 186 if (bClientBlockTest) then gProxyBlockingClient = true end 187 end 188 end 189 190 191 -- modify kPacket_Pre_Login 0x5D packet data 192 if (bScrambleTest and bIsFromClient and fifo_in:Size() >= 49) then 193 if (fifo_in:PeekNetUint8(0) == 0x5D and 194 fifo_in:PeekNetUint8(1) == 0xED and 195 fifo_in:PeekNetUint8(2) == 0xED and 196 fifo_in:PeekNetUint8(3) == 0xED and 197 fifo_in:PeekNetUint8(4) == 0xED) then 198 --~ fifo_in:PokeNetUint8(5,math.random(0,255)) 199 fifo_in:PokeNetUint8(48,0x11) 200 print("+++++++++++++++++++++++++++++++++++++++++++++++") 201 print("SCRAMBLED kPacket_Pre_Login") 202 print("+++++++++++++++++++++++++++++++++++++++++++++++") 203 end 169 204 end 170 205 end … … 173 208 local iId = fifo_in:PeekNetUint8(0) 174 209 local iPacketSize = gPacketSizeByID[iId] 175 print("UOProxyHandlePacket",fromname,sprintf("0x%02x",iId),gPacketTypeId2Name[iId], 176 iPacketSize,"t="..t_since_start) 210 print("UOProxyHandlePacket",fromname,sprintf("0x%02x",iId),gPacketTypeId2Name[iId],iPacketSize,"t="..t_since_start) 177 211 assert(iPacketSize) 178 if (iPacketSize == 0 and fifo_in:Size() < 3) then return end -- packet incomplete212 if (iPacketSize == 0 and fifo_in:Size() < 3) then print("incomplete packet dynsize? <3") return end -- packet incomplete 179 213 if (iPacketSize == 0) then iPacketSize = fifo_in:PeekNetUint16(1) end 180 if (fifo_in:Size() < iPacketSize) then return end -- packet incomplete214 if (fifo_in:Size() < iPacketSize) then print("incomplete packet ",fifo_in:Size(),iPacketSize) return end -- packet incomplete 181 215 182 216 … … 186 220 fifo_in:PokeNetUint8(16*3-5,0) 187 221 fifo_in:PokeNetUint8(16*3-6,1) 222 print("adjusted kPacket_Server_List") -- TODO : more than one server ? 223 print("+++++++++++++++++++++++++++++++++++++++++++++++") 224 print("+++++ adjusted kPacket_Server_List") 225 print("+++++++++++++++++++++++++++++++++++++++++++++++") 188 226 end 189 227 -- login.uogamers.com (209=0xD1.173=0xAD.139=0x8B.110=0x6E) … … 199 237 fifo_in:PokeNetUint8(3,0) 200 238 fifo_in:PokeNetUint8(4,1) 239 local iGameServerPort = gProxyPort2 240 fifo_in:PokeNetUint8(5,floor(iGameServerPort/256)) -- port 241 fifo_in:PokeNetUint8(6,math.mod(iGameServerPort,256)) -- port 242 201 243 gProxyServerHuffmanStartedNextRound = true 244 print("+++++++++++++++++++++++++++++++++++++++++++++++") 245 print("+++++ adjusted kPacket_Server_Redirect") 246 print("+++++++++++++++++++++++++++++++++++++++++++++++") 247 gDisableProxyInterpretation = true 202 248 end 203 249 204 250 -- todo : NetStartHuffman (after redirect?) 205 251 206 252 --[[ 207 253 if (bIsFromServer and iId == kPacket_Compressed_Gump) then --0xDD 208 254 local packetfifo = CreateFIFO() … … 225 271 MyPrintField(gumpdata,"textline_unicode") 226 272 end 227 228 229 230 231 232 273 233 274 … … 256 297 end 257 298 end 299 ]]-- 258 300 259 301 … … 265 307 return true 266 308 else 267 print("recv:",fromname,"(uninterpreted) t_since_start=",t_since_start )309 print("recv:",fromname,"(uninterpreted) t_since_start=",t_since_start,fifo_in:Size()) 268 310 print(FIFOHexDump(fifo_in)) 269 311 fifo_out:PushFIFOPartRaw(fifo_in) … … 322 364 while bAlive do 323 365 -- send 366 gProxyServerHuffmanStarted = false 324 367 if (gProxyServerHuffmanStarted) then 325 368 HuffmanCompress(gProxyClientSendFifo,gProxyClientSendCompFifo) -- does NOT remove data from in-fifo. compression can always be completed. … … 348 391 gProxyServerCon:Pop(gProxyServerRecvFifo) 349 392 end 393 gProxyServerHuffmanStarted = false 350 394 351 395 -- handle packets
