unity学习(13)——逆向服务器

学习参考教程从始至终没有讲解和提供服务器代码,但是有exe文件,随着学习的深入,发现必须获取服务器代码。

dotpeek的下载链接Download dotPeek: Free .NET Decompiler by JetBrains

dotpeek教学dotpeek 反编译修改代码 - 百度文库 (baidu.com)

file->open,选择exe程序所在的文件夹, 在assembly explorer中右键点击加载进来的项目,然后选择export to project,在输出的文件中无法通过sln打开项目,只能用vs2022打开文件夹

在ServerStart.cs中增加主函数,原来服务器是有图形界面的,功能就是启动和关闭服务器,这个暂时pass。

主函数写在ServerStart.cs中

// Decompiled with JetBrains decompiler
// Type: GameServer.Hnalder.ServerStart
// Assembly: GameServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 25EF85C6-A373-4517-96D9-28BC268C5DA9
// Assembly location: E:\BaiduNetdiskDownload\ARPG源代码\源代码\GameServer.exe

using GameServer.logic;
using GameServer.NetModel;
using System;
using System.Net;
using System.Net.Sockets;

#nullable disable
namespace GameServer.Hnalder
{
  internal class ServerStart
  {
    private static Socket server;

    public static void start(int port)
    {
      ServerStart.server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
      ServerStart.server.Bind((EndPoint) new IPEndPoint(IPAddress.Any, port));
      ServerStart.server.Listen(20);
      ServerStart.server.BeginAccept(new AsyncCallback(ServerStart.AcceptCallBack), (object) ServerStart.server);
    }

    public static void stop()
    {
      ServerStart.server.Dispose();
      ServerStart.server.Close();
    }

    private static void AcceptCallBack(IAsyncResult ar)
    {
      MyLog.form.textAdd("有客户端连接");
      try
      {
        Socket asyncState = (Socket) ar.AsyncState;
        Socket socket = asyncState.EndAccept(ar);
        Session session = new Session();
        session.socket = socket;
        LogicHandler.getInstance().sessionOpen(session);
        socket.BeginReceive(session.message, 0, session.message.Length, SocketFlags.None, new AsyncCallback(ServerStart.ReceiveCallBack), (object) session);
        asyncState.BeginAccept(new AsyncCallback(ServerStart.AcceptCallBack), (object) asyncState);
      }
      catch
      {
      }
    }

    private static void ReceiveCallBack(IAsyncResult ar)
    {
      Session asyncState = (Session) ar.AsyncState;
      try
      {
        int count = asyncState.socket.EndReceive(ar);
        if (count == 0)
        {
          MyLog.form.textAdd("有客户端断开连接");
          LogicHandler.getInstance().sessionClose(asyncState);
          return;
        }
        byte[] numArray = new byte[count];
        Buffer.BlockCopy((Array) asyncState.message, 0, (Array) numArray, 0, count);
        ServerStart.readMessage(asyncState, numArray);
      }
      catch (SocketException ex)
      {
        LogicHandler.getInstance().sessionClose(asyncState);
        asyncState.socket.Close();
        return;
      }
      asyncState.socket.BeginReceive(asyncState.message, 0, asyncState.message.Length, SocketFlags.None, new AsyncCallback(ServerStart.ReceiveCallBack), (object) asyncState);
    }

    public static void readMessage(Session session, byte[] bytes)
    {
      try
      {
        ByteArray byteArray = new ByteArray(bytes);
        int num1 = byteArray.ReadInt();
        int num2 = byteArray.ReadInt();
        int num3 = byteArray.ReadInt();
        int length = byteArray.ReadInt();
        string str = (string) null;
        if (length > 0)
          str = byteArray.ReadUTFBytes((uint) length);
        LogicHandler.getInstance().process(session, new SocketModel()
        {
          Type = num1,
          Area = num2,
          Command = num3,
          Message = str
        });
      }
      catch
      {
      }
    }
  }
  public static void Main()
  {
        ServerStart m = new ServerStart();
        m.start();

   }
}

运行报错:

C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(1241,5): error MSB3644: 找不到 .NETFramework,Version=v4.0 的引用程序集。要解决此问题,请为此框架版本安装开发人员工具包(SDK/目标包)或者重新定向应用程序。可在 https://aka.ms/msbuild/developerpacks 处下载 .NET Framework 开发人员工具包
========== 生成: 0 成功,1 失败,0 更新,0 跳过 ==========

  • 11
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值