Skip to content

Commit

Permalink
Merge branch 'BogdanW3-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
diegonc committed Jun 17, 2022
2 parents d2c1eca + 5539d7c commit 5486b21
Show file tree
Hide file tree
Showing 8 changed files with 363 additions and 160 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ SOURCES = \
src/api/iterator.lua \
src/api/ipv4.lua \
src/api/sockaddr.lua \
src/api/slot.lua \
src/api/bytes.lua \
src/api/version.lua \
src/valuemaps.lua \
Expand Down
Binary file added captures/war3/War3_31_Lan-(2)Harrow.pcapng
Binary file not shown.
70 changes: 70 additions & 0 deletions src/api/slot.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
--[[
-- slot([label])
--
--
-- Displays a slot struct.
-- Is equals to the sequence
--
-- uint8 {"Player Number"},
-- uint8 {"Download status"},
-- uint8 {"Slot status"},
-- uint8 {"Computer status"},
-- uint8 {"Team"},
-- uint8 {"Colour"},
-- uint8 {"Race"},
-- uint8 {"Computer type"},
-- uint8 {"Handicap"},
--
-- with some summary.
--
-- Quick call:
-- @par label Name of the field. It will be used as a label for the
-- field's node at the dissection tree.
--
--]]
do
local template = {
protofield_type = "bytes",
imp = {
uint8 {"Player Number", key="num"},
int8 {"Download status", key="dl"},
uint8 {"Slot status", key="status"},
uint8 {"Computer status", key="comp"},
uint8 {"Team", key="team"},
uint8 {"Colour", key="color"},
uint8 {"Race", key="race"},
uint8 {"Computer type", key="diff"}, -- difficulty
uint8 {"Handicap", key="handicap"},
},
}

function template:size()
return 9
end

function template:dissect(state)
local bn = state.bnet_node
if self.big_endian then
state.bnet_node = bn:add(self.pf, state:peek(self:size()))
else
state.bnet_node = bn:add_le(self.pf, state:peek(self:size()))
end
dissect_packet(state, self.imp)
local summary = string.format("Slot %d", state.packet.num)
if self.label ~= nil then
summary = self.label .. ": " .. summary
end
state.bnet_node:set_text(summary)
state.bnet_node = bn
end

function slot (...)
local args = make_args_table_with_positional_map(
{"real_label"},
...
)
args.label = "dummy string"
return create_proto_field(template, args)
end
end

6 changes: 3 additions & 3 deletions src/api/sockaddr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-- Displays sockaddr struct.
-- Is equals to the sequence
--
-- uint16("Address Family", nil, {[2]="AF_INET"}),
-- uint16("Address Family", nil, {[0]="AF_UNSPEC",[2]="AF_INET"}),
-- uint16("Port", big_endian=true},
-- ipv4("Host's IP"},
-- uint32("sin_zero"),
Expand All @@ -22,7 +22,7 @@ do
local template = {
protofield_type = "bytes",
imp = {
uint16 {"Address Family", nil, {[2]="AF_INET"}, key="af"},
uint16 {"Address Family", nil, {[0]="AF_UNSPEC",[2]="AF_INET"}, key="af"},
uint16 {"Port", big_endian=true, key="port"},
ipv4 {"Host's IP", key="ip"},
uint32 {"sin_zero", key="sz1"},
Expand All @@ -45,7 +45,7 @@ do
if state.packet.sz1 ~= 0 or state.packet.sz2 ~= 0 then
state:error("sin_zero is not zero.");
end
if state.packet.af ~= 2 then
if state.packet.af ~= 0 and state.packet.af ~= 2 then
state:error("Adress Family is not AF_INET.")
end
local summary = string.format("IP: %s, Port: %d", state.packet.ip, state.packet.port)
Expand Down
5 changes: 3 additions & 2 deletions src/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ do
#include "api/array.lua"
#include "api/flags.lua"
#include "api/sockaddr.lua"
#include "api/slot.lua"

-- Packets from server to client
SPacketDescription = {
Expand All @@ -612,8 +613,8 @@ do

-- After all the initialization is finished, register plugin
-- to default port.
--local udp_encap_table = DissectorTable.get("udp.port")
local udp_encap_table = DissectorTable.get("udp.port")
local tcp_encap_table = DissectorTable.get("tcp.port")
--udp_encap_table:add(6112,p_bnetp)
udp_encap_table:add(6112,p_bnetp)
tcp_encap_table:add(Config.server_port,p_bnetp)
end
52 changes: 35 additions & 17 deletions src/cpackets_w3gs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
(WORD) Listen Port
(DWORD) Peer Key
(STRING) Player name
(DWORD) Unknown
(WORD) Internal Port
(DWORD) Internal IP
(BYTE)[] Unknown
(SOCKADDR) Internal
Remarks: A client sends this to the host to enter the game lobby.
Expand All @@ -32,9 +31,11 @@
uint16("Listen Port"),
uint32("Peer Key"),
stringz("Player name"),
uint32("Unknown"),
uint16("Internal Port"),
uint32("Internal IP"),
uint8{"Unknown", key="length"},
iterator{alias="none", label="Unknown", refkey="length", repeated={
uint8("Unknown")
}},
sockaddr("Socket"),
},
--[[doc
Message ID: 0x21
Expand Down Expand Up @@ -119,15 +120,15 @@
Used By: Warcraft III: The Frozen Throne, Warcraft III
Format: (DWORD) Unknown
Format: (BYTE)[] Unknown
Remarks: This is sent to the host from each client.
The unknown value may be a checksum and is also used in replays.
]]
[W3GS_OUTGOING_KEEPALIVE] = { -- 0x27
uint32("Unknown"),
array("Unknown", uint8, 5),
},
--[[doc
Message ID: 0x28
Expand Down Expand Up @@ -180,14 +181,31 @@
uint8("Total"),
uint8("To player number"),
uint8("From player number"),
uint8("Flags"),
stringz("Message"),
uint8("Team"),
uint8("Color"),
uint8("Race"),
uint8("Handicap"),
uint32("Extra Flags"),
stringz("Message"),
uint8{"Flags", key="flags"},
casewhen{
{Cond.equals("flags", 0x10), {
stringz("Message"),
}},
{Cond.equals("flags", 0x11), {
uint8("Team"),
}},
{Cond.equals("flags", 0x12), {
uint8("Color"),
}},
{Cond.equals("flags", 0x13), {
uint8("Race"),
}},
{Cond.equals("flags", 0x14), {
uint8("Handicap"),
}},
{Cond.equals("flags", 0x20), {
uint32("Extra Flags"), --message scope
stringz("Message"),
}},
{Cond.always(), { --Probably never happens
stringz("Message"),
}},
},
},
--[[doc
Message ID: 0x2F
Expand All @@ -210,7 +228,7 @@
]]
[W3GS_SEARCHGAME] = { -- 0x2F
uint32("Product"),
strdw("Product", Descs.ClientTag),
uint32("Version"),
uint32("Unknown"),
},
Expand Down
Loading

0 comments on commit 5486b21

Please sign in to comment.