├── .gitattributes ├── .gitignore ├── EnableTouchServer .Net Core ├── EnableTouchServer(.Net Core).csproj ├── FiddlerTool.cs ├── FileMod.cs ├── Program.cs ├── RsaExtention.cs ├── ToolManager.cs └── config.cs ├── FileDecryptTool ├── App.config ├── DecryptTool.cs ├── FileDecryptTool.csproj ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── RSA_Encrypted-AESkey └── rsakey.xml ├── LICENSE ├── NetPackageTool ├── App.config ├── CmdidList.cs ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── NetPackageTool.csproj ├── NetPacket.cs ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── packages.config └── protoReader │ ├── ProtoReader.cs │ └── WireType.cs ├── README.md ├── bh3toolR.sln └── lib └── UnityAssetBundleTool.dll /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | bld/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | [Ll]og/ 27 | 28 | # Visual Studio 2015/2017 cache/options directory 29 | .vs/ 30 | # Uncomment if you have tasks that create the project's static files in wwwroot 31 | #wwwroot/ 32 | 33 | # Visual Studio 2017 auto generated files 34 | Generated\ Files/ 35 | 36 | # MSTest test Results 37 | [Tt]est[Rr]esult*/ 38 | [Bb]uild[Ll]og.* 39 | 40 | # NUNIT 41 | *.VisualState.xml 42 | TestResult.xml 43 | 44 | # Build Results of an ATL Project 45 | [Dd]ebugPS/ 46 | [Rr]eleasePS/ 47 | dlldata.c 48 | 49 | # Benchmark Results 50 | BenchmarkDotNet.Artifacts/ 51 | 52 | # .NET Core 53 | project.lock.json 54 | project.fragment.lock.json 55 | artifacts/ 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_h.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *_wpftmp.csproj 81 | *.log 82 | *.vspscc 83 | *.vssscc 84 | .builds 85 | *.pidb 86 | *.svclog 87 | *.scc 88 | 89 | # Chutzpah Test files 90 | _Chutzpah* 91 | 92 | # Visual C++ cache files 93 | ipch/ 94 | *.aps 95 | *.ncb 96 | *.opendb 97 | *.opensdf 98 | *.sdf 99 | *.cachefile 100 | *.VC.db 101 | *.VC.VC.opendb 102 | 103 | # Visual Studio profiler 104 | *.psess 105 | *.vsp 106 | *.vspx 107 | *.sap 108 | 109 | # Visual Studio Trace Files 110 | *.e2e 111 | 112 | # TFS 2012 Local Workspace 113 | $tf/ 114 | 115 | # Guidance Automation Toolkit 116 | *.gpState 117 | 118 | # ReSharper is a .NET coding add-in 119 | _ReSharper*/ 120 | *.[Rr]e[Ss]harper 121 | *.DotSettings.user 122 | 123 | # JustCode is a .NET coding add-in 124 | .JustCode 125 | 126 | # TeamCity is a build add-in 127 | _TeamCity* 128 | 129 | # DotCover is a Code Coverage Tool 130 | *.dotCover 131 | 132 | # AxoCover is a Code Coverage Tool 133 | .axoCover/* 134 | !.axoCover/settings.json 135 | 136 | # Visual Studio code coverage results 137 | *.coverage 138 | *.coveragexml 139 | 140 | # NCrunch 141 | _NCrunch_* 142 | .*crunch*.local.xml 143 | nCrunchTemp_* 144 | 145 | # MightyMoose 146 | *.mm.* 147 | AutoTest.Net/ 148 | 149 | # Web workbench (sass) 150 | .sass-cache/ 151 | 152 | # Installshield output folder 153 | [Ee]xpress/ 154 | 155 | # DocProject is a documentation generator add-in 156 | DocProject/buildhelp/ 157 | DocProject/Help/*.HxT 158 | DocProject/Help/*.HxC 159 | DocProject/Help/*.hhc 160 | DocProject/Help/*.hhk 161 | DocProject/Help/*.hhp 162 | DocProject/Help/Html2 163 | DocProject/Help/html 164 | 165 | # Click-Once directory 166 | publish/ 167 | 168 | # Publish Web Output 169 | *.[Pp]ublish.xml 170 | *.azurePubxml 171 | # Note: Comment the next line if you want to checkin your web deploy settings, 172 | # but database connection strings (with potential passwords) will be unencrypted 173 | *.pubxml 174 | *.publishproj 175 | 176 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 177 | # checkin your Azure Web App publish settings, but sensitive information contained 178 | # in these scripts will be unencrypted 179 | PublishScripts/ 180 | 181 | # NuGet Packages 182 | *.nupkg 183 | # The packages folder can be ignored because of Package Restore 184 | **/[Pp]ackages/* 185 | # except build/, which is used as an MSBuild target. 186 | !**/[Pp]ackages/build/ 187 | # Uncomment if necessary however generally it will be regenerated when needed 188 | #!**/[Pp]ackages/repositories.config 189 | # NuGet v3's project.json files produces more ignorable files 190 | *.nuget.props 191 | *.nuget.targets 192 | 193 | # Microsoft Azure Build Output 194 | csx/ 195 | *.build.csdef 196 | 197 | # Microsoft Azure Emulator 198 | ecf/ 199 | rcf/ 200 | 201 | # Windows Store app package directories and files 202 | AppPackages/ 203 | BundleArtifacts/ 204 | Package.StoreAssociation.xml 205 | _pkginfo.txt 206 | *.appx 207 | 208 | # Visual Studio cache files 209 | # files ending in .cache can be ignored 210 | *.[Cc]ache 211 | # but keep track of directories ending in .cache 212 | !*.[Cc]ache/ 213 | 214 | # Others 215 | ClientBin/ 216 | ~$* 217 | *~ 218 | *.dbmdl 219 | *.dbproj.schemaview 220 | *.jfm 221 | *.pfx 222 | *.publishsettings 223 | orleans.codegen.cs 224 | 225 | # Including strong name files can present a security risk 226 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 227 | #*.snk 228 | 229 | # Since there are multiple workflows, uncomment next line to ignore bower_components 230 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 231 | #bower_components/ 232 | 233 | # RIA/Silverlight projects 234 | Generated_Code/ 235 | 236 | # Backup & report files from converting an old project file 237 | # to a newer Visual Studio version. Backup files are not needed, 238 | # because we have git ;-) 239 | _UpgradeReport_Files/ 240 | Backup*/ 241 | UpgradeLog*.XML 242 | UpgradeLog*.htm 243 | ServiceFabricBackup/ 244 | *.rptproj.bak 245 | 246 | # SQL Server files 247 | *.mdf 248 | *.ldf 249 | *.ndf 250 | 251 | # Business Intelligence projects 252 | *.rdl.data 253 | *.bim.layout 254 | *.bim_*.settings 255 | *.rptproj.rsuser 256 | 257 | # Microsoft Fakes 258 | FakesAssemblies/ 259 | 260 | # GhostDoc plugin setting file 261 | *.GhostDoc.xml 262 | 263 | # Node.js Tools for Visual Studio 264 | .ntvs_analysis.dat 265 | node_modules/ 266 | 267 | # Visual Studio 6 build log 268 | *.plg 269 | 270 | # Visual Studio 6 workspace options file 271 | *.opt 272 | 273 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 274 | *.vbw 275 | 276 | # Visual Studio LightSwitch build output 277 | **/*.HTMLClient/GeneratedArtifacts 278 | **/*.DesktopClient/GeneratedArtifacts 279 | **/*.DesktopClient/ModelManifest.xml 280 | **/*.Server/GeneratedArtifacts 281 | **/*.Server/ModelManifest.xml 282 | _Pvt_Extensions 283 | 284 | # Paket dependency manager 285 | .paket/paket.exe 286 | paket-files/ 287 | 288 | # FAKE - F# Make 289 | .fake/ 290 | 291 | # JetBrains Rider 292 | .idea/ 293 | *.sln.iml 294 | 295 | # CodeRush personal settings 296 | .cr/personal 297 | 298 | # Python Tools for Visual Studio (PTVS) 299 | __pycache__/ 300 | *.pyc 301 | 302 | # Cake - Uncomment if you are using it 303 | # tools/** 304 | # !tools/packages.config 305 | 306 | # Tabs Studio 307 | *.tss 308 | 309 | # Telerik's JustMock configuration file 310 | *.jmconfig 311 | 312 | # BizTalk build output 313 | *.btp.cs 314 | *.btm.cs 315 | *.odx.cs 316 | *.xsd.cs 317 | 318 | # OpenCover UI analysis results 319 | OpenCover/ 320 | 321 | # Azure Stream Analytics local run output 322 | ASALocalRun/ 323 | 324 | # MSBuild Binary and Structured Log 325 | *.binlog 326 | 327 | # NVidia Nsight GPU debugger configuration file 328 | *.nvuser 329 | 330 | # MFractors (Xamarin productivity tool) working folder 331 | .mfractor/ 332 | 333 | # Local History for Visual Studio 334 | .localhistory/ 335 | -------------------------------------------------------------------------------- /EnableTouchServer .Net Core/EnableTouchServer(.Net Core).csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | EnableTouchServer_.Net_Core 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | ..\lib\UnityAssetBundleTool.dll 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /EnableTouchServer .Net Core/FiddlerTool.cs: -------------------------------------------------------------------------------- 1 | using Fiddler; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace bh3tool 7 | { 8 | class FiddlerTool 9 | { 10 | public static List modinfos = new List(); 11 | 12 | public static bool bh3only = false; 13 | 14 | private const string sSecureEndpointHostname = "localhost"; 15 | private const int iSecureEndpointPort = 7777; 16 | private readonly ICollection oAllSessions = new List(); 17 | 18 | public void Start(int port, ToolManager manager) 19 | { 20 | int requestcount = 0; 21 | int responsecount = 0; 22 | 23 | FiddlerApplication.BeforeRequest += (Session oS) => 24 | { 25 | requestcount++; 26 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " [request] request:" + requestcount + " response:" + responsecount); 27 | bool isbh3url = false; 28 | foreach (var info in modinfos) 29 | { 30 | if (info.Enabletouch && oS.fullUrl.Contains(info.gameserver_url)) 31 | { 32 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " [request] response server info:" + info.server.ToString()); 33 | oS.utilCreateResponseAndBypassServer(); 34 | oS.oResponse.headers.SetStatus(200, "OK"); 35 | oS.utilSetResponseBody(info.mod_gameserver_rsp); 36 | isbh3url = true; 37 | break; 38 | } 39 | } 40 | 41 | 42 | 43 | if (oS.fullUrl.Contains("_compressed/DataVersion.unity3d")) 44 | { 45 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " [request] response dataversion"); 46 | oS.utilCreateResponseAndBypassServer(); 47 | oS.oResponse.headers.SetStatus(200, "OK"); 48 | if (oS.fullUrl.Contains("android_compressed")) 49 | oS.ResponseBody = manager.a_dataversion; 50 | if (oS.fullUrl.Contains("iphone_compressed")) 51 | oS.ResponseBody = manager.i_dataversion; 52 | } 53 | 54 | if (oS.fullUrl.Contains("_compressed/data/excel_output_")) 55 | { 56 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " [request] response excel_output.unity3d"); 57 | oS.utilCreateResponseAndBypassServer(); 58 | oS.oResponse.headers.SetStatus(200, "OK"); 59 | if (oS.fullUrl.Contains("android_compressed")) 60 | oS.ResponseBody = manager.a_excel_output; 61 | if (oS.fullUrl.Contains("iphone_compressed")) 62 | oS.ResponseBody = manager.i_excel_output; 63 | } 64 | 65 | if (oS.fullUrl.Contains("_compressed/data/setting_")) 66 | { 67 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " [request] response setting.unity3d"); 68 | oS.utilCreateResponseAndBypassServer(); 69 | oS.oResponse.headers.SetStatus(200, "OK"); 70 | if (oS.fullUrl.Contains("android_compressed")) 71 | oS.ResponseBody = manager.a_setting; 72 | if (oS.fullUrl.Contains("iphone_compressed")) 73 | oS.ResponseBody = manager.i_setting; 74 | } 75 | 76 | if (bh3only && !isbh3url) 77 | if (!oS.uriContains("bh3.com") && !oS.uriContains("mihoyo")) 78 | oS.Abort(); 79 | 80 | }; 81 | 82 | FiddlerApplication.BeforeResponse += (Session oS) => 83 | { 84 | responsecount++; 85 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " [response] request:" + requestcount + " response:" + responsecount); 86 | }; 87 | 88 | CONFIG.IgnoreServerCertErrors = true; 89 | 90 | FiddlerApplication.Prefs.SetBoolPref("fiddler.network.streaming.abortifclientaborts", true); 91 | 92 | FiddlerCoreStartupSettings startupSettings = 93 | new FiddlerCoreStartupSettingsBuilder() 94 | .ListenOnPort((ushort)port) 95 | .OptimizeThreadPool() 96 | .AllowRemoteClients() 97 | .Build(); 98 | 99 | FiddlerApplication.Startup(startupSettings); 100 | 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /EnableTouchServer .Net Core/FileMod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Security.Cryptography; 7 | using System.Text; 8 | using System.Text.RegularExpressions; 9 | using UABT; 10 | using unluac.decompile; 11 | using unluac.parse; 12 | using unluacNet; 13 | 14 | namespace bh3tool 15 | { 16 | class FileMod 17 | { 18 | public byte[] _data; 19 | public byte[] _setting; 20 | public byte[] _excel; 21 | public DateTime time; 22 | 23 | /// 24 | /// download and modify file 25 | /// 26 | /// Is ios Server 27 | /// Local File Last Modified Time 28 | /// 29 | public bool ModFile(bool isIOS, DateTime oldtime) 30 | { 31 | if (isIOS) 32 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "[FileUpdate] Check update :IOS"); 33 | else 34 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "[FileUpdate] Check update :Android"); 35 | //file url 36 | string baseurl = isIOS ? "https://bundle.bh3.com/asset_bundle/ios01/1.0" : "https://bundle.bh3.com/asset_bundle/android01/1.0"; 37 | string settingurl = isIOS ? "/data/iphone_compressed/data/setting_" : "/data/android_compressed/data/setting_"; 38 | string excelurl = isIOS ? "/data/iphone_compressed/data/excel_output_" : "/data/android_compressed/data/excel_output_"; 39 | string dataurl = isIOS ? "/data/iphone_compressed/DataVersion.unity3d" : "/data/android_compressed/DataVersion.unity3d"; 40 | 41 | string RSAkey = @"rXoKWm82JSX4UYihkt2FSjrp3pZqTxt6AyJ0ZexHssStYesCFuUOmDBrk0nxPTY2r7oB4ZC9tDhHzmA66Me56wkD47Z3fCEBfLFxmEVdUCvM1RIFdQxQCB7CMaFWXHoVfBhNcD60OtXD71vFusBLioa6HDHbKk8LdgWdV10OWaE=EQ==

16GiwrgCGvcYbgSZOBJRx4G9kioGgexLSyW62iK4EuT0Xu9xyflBDaC4yooFkxrflqEAIiEfTqNGlYeJks+5qw==

zfQY4dWi/Dlo38y6xvX4pUEAj1hbeFo/Qiy7H00P089W0KC6Mdi+GY4UuRGJtgX7UZfGQdHRj8mBjijFyhUl4w==cihlOejyDkaUdnrntEXvD0Svp7vlU9dzJ8iuNz+OoJdUMkKHiQt8yvq8Lv3Gt0p2Xs20xsY9wDhSi2Xfa9diSw==GDrVwDdAWeii7SclCFksT61LXCiDO1XpUxRSP+ryzZ/sGIthMwpwt7ZcynqIrAC0J7eAvHMJmHIPPeat24oEdQ==P4/vgq1XF77N8K/OxTbcjWFCC1d+v3W5xWQJbmU3KfVF2wOStZeILT2X12s7AHD+uUfN9O/xdEBIeqcSLVxWjw==o0WvZCxvMgWeatrybBvIvlWQ0X6CLFYYe2u42GXpILkbp3PFuzHvnkuwip/yG35RllS2efGjfHE0hgA3cazrNgM6gBDcFa7iznviIiQTySxFuzy3mXpjSQFaGgdvmuUQLgg5qahcdGgT455Fzo5GSu+IyTpD+dNoKy79NLTbvjE=
"; 42 | 43 | WebClient client = new WebClient(); 44 | //Download DataVersion.unity3d. 45 | byte[] dataversion = client.DownloadData(baseurl + dataurl); 46 | string[] key = client.ResponseHeaders.AllKeys; 47 | //Check Last-Modified time. 48 | for (int i = 0; i < key.Length; i++) 49 | { 50 | if (key[i] == "Last-Modified") 51 | { 52 | time = DateTime.Parse(client.ResponseHeaders.Get(i)); 53 | } 54 | } 55 | 56 | if (DateTime.Compare(oldtime, time) >= 0) 57 | { 58 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "[FileUpdate] No update"); 59 | return false; 60 | } 61 | 62 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "[FileUpdate] Start update"); 63 | 64 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "[FileUpdate] edit dataversion.unity3d"); 65 | 66 | //Decrypt DataVersion.unity3d 67 | for (int i = 0; i < dataversion.Length; i++) dataversion[i] = (byte)(dataversion[i] ^ 0xA5); 68 | //load bundle asset 69 | BundleFile dataversionBundle = new BundleFile(dataversion); 70 | SerializedFile dataversionFile = new SerializedFile("dataversion", new EndianBinaryReader(dataversionBundle.fileList[0].stream)); 71 | //get textasset bytes 72 | long Pid = dataversionFile.GetPathIDByName("packageversion.txt"); 73 | var packageversion = dataversionFile.m_Objects.Find(x => x.m_PathID == Pid); 74 | //load textasset 75 | Textasset textasset = new Textasset(packageversion.data); 76 | 77 | string[] versiontext = textasset.text.Split('\n'); 78 | //Get AES key IV and HMACSHA1 key 79 | var rsa = RSA.Create(); 80 | rsa.FromXmlStringA(RSAkey); 81 | byte[] AES_SHA = rsa.Decrypt(Hex2bytes(versiontext[0]), RSAEncryptionPadding.Pkcs1); 82 | //AES_SHA 56 bytes, AES key 32 bytes|AES IV 16 bytes|HMACSHA1 8 bytes 83 | byte[] AESkey = AES_SHA.Take(32).ToArray(); 84 | byte[] AESIV = AES_SHA.Skip(32).Take(16).ToArray(); 85 | byte[] SHA = AES_SHA.Skip(48).Take(8).ToArray(); 86 | 87 | Regex regexCS = new Regex("(CS\":\")([1-9]\\d*)"); 88 | Regex regexCRC = new Regex("(CRC\":\")([0-9A-Z]*)"); 89 | 90 | string settingCRC; 91 | string excelCRC; 92 | int settingindex; 93 | int excelindex; 94 | //Get File CRC 95 | if (versiontext[1].Contains("excel_output")) 96 | { 97 | excelindex = 1; 98 | settingindex = 2; 99 | } 100 | else 101 | { 102 | excelindex = 2; 103 | settingindex = 1; 104 | } 105 | excelCRC = regexCRC.Match(versiontext[excelindex]).Groups[2].Value; 106 | settingCRC = regexCRC.Match(versiontext[settingindex]).Groups[2].Value; 107 | 108 | 109 | //Download setting.unity3d and excel_output.unity3d 110 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "[FileUpdate] download setting"); 111 | byte[] settingbytes = client.DownloadData(baseurl + settingurl + settingCRC); 112 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "[FileUpdate] download excel_output"); 113 | byte[] excelbytes = client.DownloadData(baseurl + excelurl + excelCRC); 114 | client.Dispose(); 115 | 116 | //Decrypt File 117 | Aes Aes = Aes.Create(); 118 | var AES_Encryptor = Aes.CreateEncryptor(AESkey, AESIV); 119 | 120 | var AES_Decryptor = Aes.CreateDecryptor(AESkey, AESIV); 121 | settingbytes = AES_Decryptor.TransformFinalBlock(settingbytes, 0, settingbytes.Length); 122 | 123 | AES_Decryptor = Aes.CreateDecryptor(AESkey, AESIV); 124 | excelbytes = AES_Decryptor.TransformFinalBlock(excelbytes, 0, excelbytes.Length); 125 | 126 | #region Modify setting.unity3d 127 | 128 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "[FileUpdate] edit setting"); 129 | 130 | BundleFile settingBundle = new BundleFile(settingbytes); 131 | SerializedFile setting = new SerializedFile("setting", new EndianBinaryReader(settingBundle.fileList[0].stream)); 132 | 133 | #region Edit miscdata.txt 134 | //Get miscdata.txt from bundle 135 | long miscid = setting.GetPathIDByName("miscdata.txt"); 136 | var misc = setting.m_Objects.Find(x => x.m_PathID == miscid); 137 | Textasset miscasset = new Textasset(misc.data); 138 | //Enable All BodyPort Touch 139 | Regex regexMISC = new Regex("(Face|Chest|Private|Arm|Leg)(\" *\t*: )(false)"); 140 | miscasset.text = regexMISC.Replace(miscasset.text, "$1$2true"); 141 | misc.data = miscasset.GetBytes(); 142 | #endregion 143 | 144 | #region Edit uiluadesign_x_x.lua.txt/.bytes 145 | bool isLuac = false; 146 | //version number 147 | long uiluaid = setting.GetPathIDByName("uiluadesign_3_4.lua.txt"); 148 | if (uiluaid == -1) 149 | { 150 | isLuac = true; 151 | uiluaid = setting.GetPathIDByName("uiluadesign_3_4.lua.bytes"); 152 | } 153 | var uilua = setting.m_Objects.Find(x => x.m_PathID == uiluaid); 154 | Textasset uiluaasset = new Textasset(uilua.data); 155 | List list; 156 | if (isLuac) 157 | //Decompile luac to lua string 158 | list = DecompileLuac(uiluaasset.bytes); 159 | else 160 | list = new List(uiluaasset.text.Split('\n')); 161 | 162 | //insert Lua code to function UITable.ModuleEndHandlePacket 163 | int index = list.FindIndex(x => x.Contains("UITable.ModuleEndHandlePacket")); 164 | //Handle NetPacketV1 for GalTouchModule,and set GalTouchModule._canGalTouch to true 165 | string insertStr = "\tif moduleName == \"GalTouchModule\" and packet:getCmdId() == 111 then\n\t\tlocal gal = __singletonManagerType.GetSingletonInstance(\"MoleMole.GalTouchModule\")\n\t\tif gal == nil then\n\t\t\treturn\n\t\tend\n\t\tgal._canGalTouch = true\n\tend\n"; 166 | list.Insert(index + 1, insertStr); 167 | uiluaasset.text = String.Join('\n', list); 168 | uilua.data = uiluaasset.GetBytes(); 169 | #endregion 170 | 171 | #region Edit Assetbundle 172 | if (isLuac) 173 | { 174 | var ab = setting.m_Objects.Find(x => x.m_PathID == 1); 175 | AssetBundle bundle = new AssetBundle(ab.data); 176 | bundle.Rename("uiluadesign_3_4.lua.bytes", "uiluadesign_3_4.lua.txt"); 177 | ab.data = bundle.GetBytes(); 178 | } 179 | #endregion 180 | 181 | #region Edit luahackconfig.txt 182 | //Add "GalTouchModule" to "UILuaPatchModuleList" 183 | long luahackpid = setting.GetPathIDByName("luahackconfig.txt"); 184 | var luahack = setting.m_Objects.Find(x => x.m_PathID == luahackpid); 185 | Textasset hack = new Textasset(luahack.data); 186 | string inserthack = " \"GalTouchModule\","; 187 | list = new List(hack.text.Split('\n')); 188 | index = list.FindIndex(x => x.Contains("UILuaPatchModuleList")); 189 | if (list[index].Contains('[')) 190 | list[index] = list[index].Insert(list[index].IndexOf('[') + 1, inserthack); 191 | else 192 | list.Insert(index + 2, inserthack); 193 | hack.text = string.Join('\n', list); 194 | luahack.data = hack.GetBytes(); 195 | #endregion 196 | 197 | //pack to assetbundle 198 | misc.data = miscasset.GetBytes(); 199 | settingBundle.fileList[0].stream = new MemoryStream(setting.Pack()); 200 | settingbytes = settingBundle.RePack(); 201 | //ENCRYPT 202 | settingbytes = AES_Encryptor.TransformFinalBlock(settingbytes, 0, settingbytes.Length); 203 | //save file 204 | _setting = settingbytes; 205 | #endregion 206 | 207 | #region Edit excel_output.unity3d 208 | // 209 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "[FileUpdate] edit excel"); 210 | 211 | BundleFile excelBundle = new BundleFile(excelbytes); 212 | SerializedFile excel = new SerializedFile("excel", new EndianBinaryReader(excelBundle.fileList[0].stream)); 213 | //Edit touch buff 214 | long touchbuffid = excel.GetPathIDByName("touchbuffdata.asset"); 215 | var bf = excel.m_Objects.Find(x => x.m_PathID == touchbuffid); 216 | bf.data = TouchBuff.GetNew(bf.data); 217 | excelBundle.fileList[0].stream = new MemoryStream(excel.Pack()); 218 | excelbytes = excelBundle.RePack(); 219 | //Encrypt excel_output.unity3d 220 | AES_Encryptor = Aes.CreateEncryptor(AESkey, AESIV); 221 | excelbytes = AES_Encryptor.TransformFinalBlock(excelbytes, 0, excelbytes.Length); 222 | _excel = excelbytes; 223 | #endregion 224 | 225 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "[FileUpdate] edit dataversion"); 226 | 227 | //compute new CRC(hmac-SHA1) 228 | HMACSHA1 hMACSHA1 = new HMACSHA1(SHA); 229 | settingCRC = BitConverter.ToString(hMACSHA1.ComputeHash(settingbytes)).Replace("-", ""); 230 | excelCRC = BitConverter.ToString(hMACSHA1.ComputeHash(excelbytes)).Replace("-", ""); 231 | 232 | //Replace fileSize("CS") and SHA1("CRC") 233 | versiontext[excelindex] = regexCRC.Replace(versiontext[1], "CRC\":\"" + excelCRC); 234 | versiontext[excelindex] = regexCS.Replace(versiontext[1], "CS\":\"" + excelbytes.Length.ToString()); 235 | versiontext[settingindex] = regexCRC.Replace(versiontext[2], "CRC\":\"" + settingCRC); 236 | versiontext[settingindex] = regexCS.Replace(versiontext[2], "CS\":\"" + settingbytes.Length.ToString()); 237 | 238 | //string[] to string 239 | textasset.text = string.Join("\n", versiontext); 240 | //get textasset bytes 241 | packageversion.data = textasset.GetBytes(); 242 | //pack 243 | dataversionBundle.fileList[0].stream = new MemoryStream(dataversionFile.Pack()); 244 | byte[] dz = dataversionBundle.RePack(); 245 | //encrypt dataversion.unity3d 246 | for (int i = 0; i < dz.Length; i++) dz[i] = (byte)(dz[i] ^ 0xA5); 247 | //save file 248 | _data = dz; 249 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "[FileUpdate] Update file success"); 250 | return true; 251 | } 252 | 253 | /// 254 | /// HEX string to byte[] 255 | /// 256 | /// 257 | /// 258 | private static byte[] Hex2bytes(string hex) 259 | { 260 | int ver = hex.Length / 2; 261 | byte[] data = new byte[ver]; 262 | for (int i = 0; i < ver; i++) 263 | { 264 | data[i] = (byte)Convert.ToInt32(hex.Substring(i * 2, 2), 16); 265 | } 266 | return data; 267 | } 268 | static int[] Opindex = { 0x09,0x22,0x02,0x1a,0x12,0x00,0x21,0x24, 269 | 0x1e,0x11,0x08,0x0f,0x0c,0x17,0x03,0x23, 270 | 0x0e,0x0a,0x1c,0x16,0x13,0x0b,0x04,0x0d, 271 | 0x06,0x14,0x01,0x18,0x20,0x10,0x05,0x25, 272 | 0x15,0x1d,0x1b,0x19,0x07,0x1f 273 | }; 274 | private List DecompileLuac(byte[] data) 275 | { 276 | data[5] = 0x00; 277 | ByteBuffer buffer = new ByteBuffer(data); 278 | var header = new BHeader(buffer); 279 | LFunction lmain = header.function.parse(buffer, header); 280 | decryptcode(lmain); 281 | Decompiler d = new Decompiler(lmain); 282 | d.decompile(); 283 | MemoryStream outs = new MemoryStream(); 284 | StreamWriter writer = new StreamWriter(outs); 285 | d.print(new Output(writer.Write, writer.WriteLine)); 286 | var text = Encoding.UTF8.GetString(outs.ToArray()); 287 | return new List(text.Split('\n')); 288 | } 289 | 290 | static void decryptcode(LFunction function) 291 | { 292 | int[] code = function.code; 293 | for (int i = 0; i < code.Length; i++) 294 | { 295 | var opcode = code[i] & 0x3f; 296 | code[i] &= ~0x3f; 297 | code[i] |= Opindex[opcode]; 298 | } 299 | foreach (var f in function.functions) 300 | decryptcode(f); 301 | } 302 | 303 | } 304 | } 305 | -------------------------------------------------------------------------------- /EnableTouchServer .Net Core/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Threading; 4 | 5 | namespace ConsoleApp1 6 | { 7 | class Program 8 | { 9 | static Timer Timer; 10 | 11 | static void Main(string[] args) 12 | { 13 | Console.WriteLine("bh3tool test start"); 14 | try 15 | { 16 | //Get bh3tool.dll path. 17 | string path = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); 18 | path = Path.Combine(path, "Config.ini"); 19 | Console.WriteLine("Read Config.ini"); 20 | //default comfig 21 | string[] config = { "Port = 8877\n", "Bh3UrlOnly = false\n", "EnableIos = true\n", "EnableAndroid = true\n" }; 22 | 23 | if (File.Exists(path)) 24 | config = File.ReadAllLines(path); 25 | else 26 | File.WriteAllLines(path, config); 27 | 28 | var cfg = new bh3tool.config(config); 29 | foreach (var a in config) 30 | Console.WriteLine(a); 31 | 32 | bh3tool.ToolManager manager = new bh3tool.ToolManager(); 33 | //start 34 | manager.Start(cfg.port, cfg.Bh3Only, cfg.EnableAndroid, cfg.EnableIos); 35 | //start timer for checkupdate 36 | Timer = new Timer(new TimerCallback(CheckUpdate), manager, 10 * 1000, 60 * 1000); 37 | } 38 | catch (Exception ex) 39 | { 40 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " " + ex.Message + "\n" + ex.StackTrace); 41 | } 42 | Console.WriteLine("bh3tool is running"); 43 | while (true) 44 | { 45 | string s = Console.ReadLine(); 46 | if (s == "exit") 47 | { 48 | return; 49 | } 50 | 51 | } 52 | 53 | } 54 | 55 | static void CheckUpdate(object s) 56 | { 57 | var manager = (bh3tool.ToolManager)s; 58 | manager.UpdateFile(); 59 | } 60 | 61 | 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /EnableTouchServer .Net Core/RsaExtention.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Security.Cryptography; 4 | using System.Xml; 5 | 6 | namespace bh3tool 7 | { 8 | public static class RsaExtention 9 | { 10 | 11 | public static void FromXmlStringA(this RSA rsa, string xmlString) 12 | { 13 | RSAParameters parameters = new RSAParameters(); 14 | XmlDocument xmlDoc = new XmlDocument(); 15 | xmlDoc.LoadXml(xmlString); 16 | if (xmlDoc.DocumentElement.Name.Equals("RSAKeyValue")) 17 | { 18 | foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) 19 | { 20 | switch (node.Name) 21 | { 22 | case "Modulus": parameters.Modulus = Convert.FromBase64String(node.InnerText); break; 23 | case "Exponent": parameters.Exponent = Convert.FromBase64String(node.InnerText); break; 24 | case "P": parameters.P = Convert.FromBase64String(node.InnerText); break; 25 | case "Q": parameters.Q = Convert.FromBase64String(node.InnerText); break; 26 | case "DP": parameters.DP = Convert.FromBase64String(node.InnerText); break; 27 | case "DQ": parameters.DQ = Convert.FromBase64String(node.InnerText); break; 28 | case "InverseQ": parameters.InverseQ = Convert.FromBase64String(node.InnerText); break; 29 | case "D": parameters.D = Convert.FromBase64String(node.InnerText); break; 30 | } 31 | } 32 | } 33 | else 34 | { 35 | throw new Exception("Invalid XML RSA key."); 36 | } 37 | 38 | rsa.ImportParameters(parameters); 39 | } 40 | 41 | public static string ToXmlString(this RSA rsa, bool includePrivateParameters) 42 | { 43 | RSAParameters parameters = rsa.ExportParameters(includePrivateParameters); 44 | 45 | if (includePrivateParameters) 46 | { 47 | return string.Format("{0}{1}

{2}

{3}{4}{5}{6}{7}
", 48 | Convert.ToBase64String(parameters.Modulus), 49 | Convert.ToBase64String(parameters.Exponent), 50 | Convert.ToBase64String(parameters.P), 51 | Convert.ToBase64String(parameters.Q), 52 | Convert.ToBase64String(parameters.DP), 53 | Convert.ToBase64String(parameters.DQ), 54 | Convert.ToBase64String(parameters.InverseQ), 55 | Convert.ToBase64String(parameters.D)); 56 | } 57 | return string.Format("{0}{1}", 58 | Convert.ToBase64String(parameters.Modulus), 59 | Convert.ToBase64String(parameters.Exponent)); 60 | } 61 | 62 | } 63 | } -------------------------------------------------------------------------------- /EnableTouchServer .Net Core/ToolManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | using UABT; 9 | 10 | namespace bh3tool 11 | { 12 | class ToolManager 13 | { 14 | //server list 15 | Dictionary mod_servers = new Dictionary 16 | { 17 | { "android01", new Server_modinfo(Gameserver.android01) }, 18 | { "bb01", new Server_modinfo(Gameserver.bb01) }, 19 | { "hun01", new Server_modinfo(Gameserver.hun01) }, 20 | { "hun02", new Server_modinfo(Gameserver.hun02) }, 21 | { "ios01", new Server_modinfo(Gameserver.ios01) }, 22 | { "yyb01", new Server_modinfo(Gameserver.yyb01) } 23 | }; 24 | private FiddlerTool Fiddlertool = new FiddlerTool(); 25 | 26 | public int port = 8877; 27 | //ios data 28 | public byte[] i_dataversion; 29 | public byte[] i_setting; 30 | public byte[] i_excel_output; 31 | public DateTime i_time = new DateTime(0); 32 | //android data 33 | public byte[] a_dataversion; 34 | public byte[] a_setting; 35 | public byte[] a_excel_output; 36 | public DateTime a_time = new DateTime(0); 37 | 38 | bool Enableandroid = true; 39 | bool Enableios = true; 40 | /// 41 | /// start 42 | /// 43 | /// proxy port 44 | /// is only response *.bh3.com and *.mihoyo.com 45 | /// Enable android 46 | /// Enable IOS 47 | public void Start(int iport, bool Bh3Only, bool Enableandroid, bool Enableios) 48 | { 49 | this.Enableandroid = Enableandroid; 50 | this.Enableios = Enableios; 51 | Console.WriteLine("init server info"); 52 | 53 | Console.WriteLine("start Fiddler,port:" + iport); 54 | FiddlerTool.bh3only = Bh3Only; 55 | 56 | port = iport; 57 | Fiddlertool.Start(port, this); 58 | 59 | Console.WriteLine("Get server info"); 60 | string[] severlist = mod_servers.Keys.ToArray(); 61 | 62 | foreach (string se in severlist) 63 | mod_servers[se].Enabletouch = Enableandroid; 64 | 65 | mod_servers["ios01"].Enabletouch = Enableios; 66 | //get all server info 67 | foreach (var se in severlist) 68 | { 69 | if (mod_servers[se].Enabletouch) 70 | { 71 | if (!Getseverinfo(se)) 72 | { 73 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " Get " + se + " info fail"); 74 | return; 75 | } 76 | 77 | if (string.IsNullOrEmpty(mod_servers[se].mod_gameserver_rsp)) 78 | Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " Get " + se + " info fail"); 79 | else 80 | Console.WriteLine(se + " " + mod_servers[se].server_ip + " " + mod_servers[se].oa_ip); 81 | } 82 | } 83 | 84 | var ios = mod_servers["ios01"]; 85 | var android = mod_servers["android01"]; 86 | Console.WriteLine("process file"); 87 | //Get File 88 | try 89 | { 90 | if (Enableios) 91 | { 92 | var m = new FileMod(); 93 | if (m.ModFile(true, i_time)) 94 | { 95 | i_dataversion = m._data; 96 | i_excel_output = m._excel; 97 | i_setting = m._setting; 98 | i_time = m.time; 99 | } 100 | m = null; 101 | } 102 | if (Enableandroid) 103 | { 104 | var c = new FileMod(); 105 | if (c.ModFile(false, a_time)) 106 | { 107 | a_dataversion = c._data; 108 | a_excel_output = c._excel; 109 | a_setting = c._setting; 110 | a_time = c.time; 111 | } 112 | c = null; 113 | } 114 | } 115 | catch (Exception e) 116 | { 117 | Console.WriteLine(e.Message + "\n" + e.StackTrace); 118 | } 119 | //start fiddler 120 | if (!Fiddler.FiddlerApplication.IsStarted()) 121 | { 122 | 123 | port = iport; 124 | Fiddlertool.Start(port, this); 125 | } 126 | FiddlerTool.modinfos = mod_servers.Values.ToList(); 127 | } 128 | 129 | /// 130 | /// Update File 131 | /// 132 | public void UpdateFile() 133 | { 134 | try 135 | { 136 | if (Enableios) 137 | { 138 | var m = new FileMod(); 139 | if (m.ModFile(true, i_time)) 140 | { 141 | i_dataversion = m._data; 142 | i_excel_output = m._excel; 143 | i_setting = m._setting; 144 | i_time = m.time; 145 | } 146 | m = null; 147 | } 148 | if (Enableandroid) 149 | { 150 | var c = new FileMod(); 151 | if (c.ModFile(false, a_time)) 152 | { 153 | a_dataversion = c._data; 154 | a_excel_output = c._excel; 155 | a_setting = c._setting; 156 | a_time = c.time; 157 | } 158 | c = null; 159 | } 160 | GC.Collect(); 161 | } 162 | catch (Exception e) 163 | { 164 | Console.WriteLine(e.Message + "\n" + e.StackTrace); 165 | } 166 | } 167 | 168 | 169 | /// 170 | /// Get Server Info 171 | /// 172 | /// 173 | /// 174 | bool Getseverinfo(string se) 175 | { 176 | //用于匹配数据的正则 177 | Regex reg_serverurl = new Regex("(dispatch_url\":\")(.*?)\""); 178 | Regex reg_gameserver = new Regex("(gameserver\":)(\\{.*?\\})"); 179 | Regex reg_geteway = new Regex("(gateway\":)(\\{.*?\\})"); 180 | Regex reg_oaserver = new Regex("(oaserver_url\":)(\".*?\")"); 181 | 182 | WebClient client = new WebClient(); 183 | try 184 | { 185 | //note version number 186 | string version = "?version=3.4.0_" + GetserverStr(mod_servers[se].server); 187 | string globaleDispatchUrl = "http://global1.bh3.com/query_dispatch" + version; 188 | 189 | string rsp = client.DownloadString(globaleDispatchUrl); 190 | //get dispatch_url 191 | string dispatch_url = reg_serverurl.Match(rsp).Groups[2].Value; 192 | 193 | string qserverurl = dispatch_url + version; 194 | //get server rsponse 195 | string qrsp = client.DownloadString(qserverurl); 196 | //match server ip 197 | string gameserver = reg_gameserver.Match(qrsp).Groups[2].Value; 198 | string getway = reg_geteway.Match(qrsp).Groups[2].Value; 199 | string oa = reg_oaserver.Match(qrsp).Groups[2].Value; 200 | 201 | mod_servers[se].gameserver_url = dispatch_url; 202 | mod_servers[se].gameserver_rsp = qrsp; 203 | mod_servers[se].server_ip = gameserver; 204 | mod_servers[se].getway_ip = getway; 205 | mod_servers[se].oa_ip = oa; 206 | //Replace "https" with "http" 207 | mod_servers[se].mod_gameserver_rsp = qrsp.Replace("https://bundle.bh3.com", "http://bundle.bh3.com"); 208 | } 209 | catch 210 | { 211 | return false; 212 | } 213 | return true; 214 | } 215 | 216 | /// 217 | /// get a server name 218 | /// 219 | /// 220 | /// 221 | private string GetserverStr(Gameserver server) 222 | { 223 | switch (server) 224 | { 225 | case Gameserver.android01: return "gf_android"; 226 | case Gameserver.bb01: return "bilibili"; 227 | case Gameserver.hun01: return "oppo"; 228 | case Gameserver.hun02: return "xiaomi"; 229 | case Gameserver.ios01: return "gf_ios"; 230 | case Gameserver.yyb01: return "tencent"; 231 | default: return "gf_android"; 232 | } 233 | 234 | } 235 | 236 | } 237 | 238 | /// 239 | /// edit touch buff 240 | /// 241 | class TouchBuff 242 | { 243 | static readonly int buffId = 6; 244 | static string effect = "EmotionBuff_01"; 245 | static string buffDetail = "TouchBuff_SKL_CHG"; 246 | static float param1 = 0.0299999993f; 247 | static float param1Add = 0.00999999978f; 248 | 249 | static public byte[] GetNew(byte[] data) 250 | { 251 | MemoryStream stream = new MemoryStream(data); 252 | BinaryReader reader = new BinaryReader(stream); 253 | reader.BaseStream.Position = 0x30; 254 | int count = reader.ReadInt32(); 255 | EndianBinaryWriter writer = new EndianBinaryWriter(new MemoryStream(), EndianType.LittleEndian); 256 | reader.BaseStream.Position = 0; 257 | byte[] header = new byte[0x34]; 258 | reader.BaseStream.Read(header, 0, header.Length); 259 | writer.Write(header); 260 | for (int i = 0; i < count; i++) 261 | { 262 | writer.Write(buffId); 263 | writer.WriteAlignedString(effect); 264 | writer.WriteAlignedString(buffDetail); 265 | writer.Write(param1); 266 | writer.Write(0); 267 | writer.Write(0); 268 | writer.Write(param1Add); 269 | writer.Write(0); 270 | writer.Write(0); 271 | } 272 | byte[] output = new byte[writer.BaseStream.Length]; 273 | writer.BaseStream.Position = 0; 274 | writer.BaseStream.Read(output, 0, output.Length); 275 | return output; 276 | } 277 | } 278 | 279 | /// 280 | /// unity TextAsset 281 | /// 282 | class Textasset 283 | { 284 | public string name; 285 | public string text; 286 | public byte[] bytes; 287 | public string m_pathname; 288 | /// 289 | /// TextAsset 290 | /// 291 | /// 292 | public Textasset(byte[] data) 293 | { 294 | EndianBinaryReader reader = new EndianBinaryReader(new MemoryStream(data), EndianType.LittleEndian); 295 | name = reader.ReadAlignedString(); 296 | var length = reader.ReadInt32(); 297 | bytes = reader.ReadBytes(length); 298 | text = Encoding.UTF8.GetString(bytes); 299 | reader.AlignStream(4); 300 | // m_pathname = reader.ReadAlignedString(); 301 | } 302 | /// 303 | /// TextAsset to byte[] 304 | /// 305 | /// 306 | public byte[] GetBytes() 307 | { 308 | EndianBinaryWriter writer = new EndianBinaryWriter(new MemoryStream(), EndianType.LittleEndian); 309 | writer.WriteAlignedString(name); 310 | writer.WriteAlignedString(text); 311 | //writer.WriteAlignedString(m_pathname); 312 | writer.Position = 0; 313 | byte[] data = new byte[writer.BaseStream.Length]; 314 | writer.BaseStream.Read(data, 0, data.Length); 315 | return data; 316 | } 317 | } 318 | 319 | class AssetBundle 320 | { 321 | string name; 322 | int count; 323 | byte[] data1; 324 | int assetcount; 325 | List assetname = new List(); 326 | List assetinfo = new List(); 327 | byte[] data2; 328 | 329 | 330 | public AssetBundle(byte[] data) 331 | { 332 | EndianBinaryReader reader = new EndianBinaryReader(new MemoryStream(data), EndianType.LittleEndian); 333 | name = reader.ReadAlignedString(); 334 | count = reader.ReadInt32(); 335 | data1 = reader.ReadBytes(count * 12); 336 | assetcount = reader.ReadInt32(); 337 | for (int i = 0; i < assetcount; i++) 338 | { 339 | assetname.Add(reader.ReadAlignedString()); 340 | assetinfo.Add(reader.ReadBytes(20)); 341 | } 342 | data2 = reader.ReadBytes((int)(reader.BaseStream.Length - reader.Position)); 343 | } 344 | public void Rename(string oldname, string newname) 345 | { 346 | for (int i = 0; i < assetname.Count; i++) 347 | { 348 | if (assetname[i].EndsWith(oldname)) 349 | { 350 | assetname[i] = assetname[i].Replace(oldname, newname); 351 | } 352 | } 353 | 354 | } 355 | public byte[] GetBytes() 356 | { 357 | EndianBinaryWriter writer = new EndianBinaryWriter(new MemoryStream(), EndianType.LittleEndian); 358 | writer.WriteAlignedString(name); 359 | writer.Write(count); 360 | writer.Write(data1); 361 | writer.Write(assetcount); 362 | for (int i = 0; i < assetcount; i++) 363 | { 364 | writer.WriteAlignedString(assetname[i]); 365 | writer.Write(assetinfo[i]); 366 | } 367 | writer.Write(data2); 368 | byte[] data = new byte[writer.BaseStream.Length]; 369 | writer.BaseStream.Read(data, 0, data.Length); 370 | return data; 371 | } 372 | 373 | } 374 | /// 375 | /// serverinfo 376 | /// 377 | public class Server_modinfo 378 | { 379 | /// 380 | /// Server 381 | /// 382 | public Gameserver server; 383 | /// 384 | /// Enable? 385 | /// 386 | public bool Enabletouch; 387 | public string gameserver_url; 388 | public string gameserver_rsp; 389 | public string server_ip; 390 | public string getway_ip; 391 | public string oa_ip; 392 | /// 393 | /// modified response 394 | /// 395 | public string mod_gameserver_rsp; 396 | 397 | public Server_modinfo(Gameserver sser) 398 | { 399 | server = sser; 400 | } 401 | } 402 | 403 | /// 404 | /// Server 405 | /// 406 | public enum Gameserver 407 | { 408 | android01, 409 | ios01, 410 | hun01, 411 | hun02, 412 | bb01, 413 | yyb01 414 | } 415 | 416 | 417 | } 418 | -------------------------------------------------------------------------------- /EnableTouchServer .Net Core/config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.RegularExpressions; 3 | 4 | namespace bh3tool 5 | { 6 | public class config 7 | { 8 | public int port; 9 | public bool Bh3Only; 10 | public bool EnableIos; 11 | public bool EnableAndroid ; 12 | 13 | public config(string[] str) 14 | { 15 | foreach (string s in str) 16 | { 17 | if (s.StartsWith('#')) 18 | continue; 19 | if (s.Contains("Port") || s.Contains("port")) 20 | { 21 | var ss = Regex.Match(s, @"[0-9]+"); 22 | port = Convert.ToInt32(ss.Value); 23 | } 24 | if (s.Contains("Bh3UrlOnly")) 25 | { 26 | if (s.Contains("true")) 27 | Bh3Only = true; 28 | if (s.Contains("false")) 29 | Bh3Only = false; 30 | } 31 | if (s.Contains("EnableIos")) 32 | { 33 | if (s.Contains("true")) 34 | EnableIos = true; 35 | if (s.Contains("false")) 36 | EnableIos = false; 37 | } 38 | if (s.Contains("EnableAndroid")) 39 | { 40 | if (s.Contains("true")) 41 | EnableAndroid = true; 42 | if (s.Contains("false")) 43 | EnableAndroid = false; 44 | } 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /FileDecryptTool/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /FileDecryptTool/DecryptTool.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Linq; 3 | using System.Security.Cryptography; 4 | using System.Text; 5 | using System.Windows.Forms; 6 | 7 | namespace FileDecryptTool 8 | { 9 | class FileDecryptTool 10 | { 11 | static public void AB_Decrypt(string path) 12 | { 13 | byte[] AESkey = GetAESkey(); 14 | if (AESkey == null) return; 15 | 16 | byte[] AES_Key = AESkey.Take(32).ToArray(); 17 | byte[] AES_IV = AESkey.Skip(32).Take(16).ToArray(); 18 | 19 | byte[] data = File.ReadAllBytes(path); 20 | 21 | byte[] Decrypt = AESDecrypt(data, AES_Key, AES_IV); 22 | if (Decrypt == null) return; 23 | 24 | SaveFileDialog saveFile = new SaveFileDialog(); 25 | saveFile.RestoreDirectory = true; 26 | saveFile.Filter = "AssetBundle(*.unity3d)|*.unity3d"; 27 | if (saveFile.ShowDialog() == DialogResult.OK) 28 | File.WriteAllBytes(saveFile.FileName, Decrypt); 29 | } 30 | 31 | static public string Hash(byte[] data, byte[] key) 32 | { 33 | var hmac = new HMACSHA1(key); 34 | byte[] hash = hmac.ComputeHash(data); 35 | 36 | StringBuilder sb = new StringBuilder(); 37 | foreach (byte b in hash) 38 | { 39 | sb.AppendFormat("{0:X2}", b); 40 | } 41 | var hex = sb.ToString(); 42 | return hex; 43 | } 44 | 45 | static public void AB_Encrypt(string path) 46 | { 47 | byte[] AESkey = GetAESkey(); 48 | 49 | byte[] AES_Key = AESkey.Take(32).ToArray(); 50 | byte[] AES_IV = AESkey.Skip(32).Take(16).ToArray(); 51 | byte[] HMACkey = AESkey.Skip(48).ToArray(); 52 | 53 | byte[] data = File.ReadAllBytes(path); 54 | 55 | byte[] Encrypt = AESEncrypt(data, AES_Key, AES_IV); 56 | if (Encrypt == null) return; 57 | 58 | SaveFileDialog saveFile = new SaveFileDialog(); 59 | saveFile.RestoreDirectory = true; 60 | saveFile.Filter = "AssetBundle(*.unity3d)|*.unity3d"; 61 | 62 | if (saveFile.ShowDialog() == DialogResult.OK) 63 | { 64 | string outpath = Path.GetDirectoryName(saveFile.FileName) + @"\\" + Path.GetFileNameWithoutExtension(saveFile.FileName) + "_" + Hash(Encrypt, HMACkey) + @".unity3d"; 65 | File.WriteAllBytes(outpath, Encrypt); 66 | } 67 | 68 | } 69 | 70 | static byte[] GetAESkey() 71 | { 72 | string RSAKey = File.ReadAllText(Application.StartupPath + @"\rsakey.xml"); 73 | byte[] AESkey = File.ReadAllBytes(Application.StartupPath + @"\RSA_Encrypted-AESkey"); 74 | try 75 | { 76 | RSACryptoServiceProvider rSACrypto = new RSACryptoServiceProvider(); 77 | rSACrypto.FromXmlString(RSAKey); 78 | byte[] DecryptAESKey = rSACrypto.Decrypt(AESkey, false); 79 | return DecryptAESKey; 80 | } 81 | catch 82 | { 83 | MessageBox.Show("RSA解密时出错!"); 84 | return null; 85 | } 86 | } 87 | 88 | static byte[] AESDecrypt(byte[] data, byte[] AES_key, byte[] AES_IV) 89 | { 90 | Aes AES = Aes.Create(); 91 | try 92 | { 93 | var Decryptor = AES.CreateDecryptor(AES_key, AES_IV); 94 | return Decryptor.TransformFinalBlock(data, 0, data.Length); 95 | } 96 | catch 97 | { 98 | MessageBox.Show("AES解密时出错!"); 99 | return null; 100 | } 101 | } 102 | 103 | static byte[] AESEncrypt(byte[] data, byte[] AES_key, byte[] AES_IV) 104 | { 105 | Aes AES = Aes.Create(); 106 | try 107 | { 108 | var Encryptor = AES.CreateEncryptor(AES_key, AES_IV); 109 | return Encryptor.TransformFinalBlock(data, 0, data.Length); 110 | } 111 | catch 112 | { 113 | MessageBox.Show("AES加密时出错!"); 114 | return null; 115 | } 116 | } 117 | 118 | static public void Data_xor(string path) 119 | { 120 | byte[] file = File.ReadAllBytes(path); 121 | 122 | for (int i = 0; i < file.Length; i++) file[i] ^= 0xA5; 123 | 124 | path = path + "_xor"; 125 | 126 | File.WriteAllBytes(path, file); 127 | } 128 | 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /FileDecryptTool/FileDecryptTool.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {00CE9685-6F08-4275-825A-435EFC3774A1} 8 | WinExe 9 | FileDecryptTool 10 | FileDecryptTool 11 | v4.6.1 12 | 512 13 | true 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | Form 51 | 52 | 53 | Form1.cs 54 | 55 | 56 | 57 | 58 | Form1.cs 59 | 60 | 61 | 62 | Always 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | Always 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /FileDecryptTool/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace FileDecryptTool 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// 必需的设计器变量。 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// 清理所有正在使用的资源。 12 | /// 13 | /// 如果应释放托管资源,为 true;否则为 false。 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows 窗体设计器生成的代码 24 | 25 | /// 26 | /// 设计器支持所需的方法 - 不要修改 27 | /// 使用代码编辑器修改此方法的内容。 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.label1 = new System.Windows.Forms.Label(); 32 | this.label2 = new System.Windows.Forms.Label(); 33 | this.label3 = new System.Windows.Forms.Label(); 34 | this.TB_Apath = new System.Windows.Forms.TextBox(); 35 | this.btn_decrypt = new System.Windows.Forms.Button(); 36 | this.btn_Encrypt = new System.Windows.Forms.Button(); 37 | this.btn_open1 = new System.Windows.Forms.Button(); 38 | this.label4 = new System.Windows.Forms.Label(); 39 | this.TB_pathX = new System.Windows.Forms.TextBox(); 40 | this.btn_open2 = new System.Windows.Forms.Button(); 41 | this.btn_xor = new System.Windows.Forms.Button(); 42 | this.SuspendLayout(); 43 | // 44 | // label1 45 | // 46 | this.label1.AutoSize = true; 47 | this.label1.Location = new System.Drawing.Point(12, 9); 48 | this.label1.Name = "label1"; 49 | this.label1.Size = new System.Drawing.Size(221, 12); 50 | this.label1.TabIndex = 0; 51 | this.label1.Text = "excel_output.unity3d setting.unity3d"; 52 | // 53 | // label2 54 | // 55 | this.label2.AutoSize = true; 56 | this.label2.Location = new System.Drawing.Point(12, 85); 57 | this.label2.Name = "label2"; 58 | this.label2.Size = new System.Drawing.Size(119, 12); 59 | this.label2.TabIndex = 1; 60 | this.label2.Text = "DataVersion.unity3d"; 61 | // 62 | // label3 63 | // 64 | this.label3.AutoSize = true; 65 | this.label3.Location = new System.Drawing.Point(12, 39); 66 | this.label3.Name = "label3"; 67 | this.label3.Size = new System.Drawing.Size(35, 12); 68 | this.label3.TabIndex = 2; 69 | this.label3.Text = "File:"; 70 | // 71 | // TB_Apath 72 | // 73 | this.TB_Apath.AllowDrop = true; 74 | this.TB_Apath.Location = new System.Drawing.Point(53, 34); 75 | this.TB_Apath.Name = "TB_Apath"; 76 | this.TB_Apath.Size = new System.Drawing.Size(225, 21); 77 | this.TB_Apath.TabIndex = 3; 78 | this.TB_Apath.DragDrop += new System.Windows.Forms.DragEventHandler(this.TB_Apath_DragDrop); 79 | this.TB_Apath.DragEnter += new System.Windows.Forms.DragEventHandler(this.TB_Apath_DragEnter); 80 | // 81 | // btn_decrypt 82 | // 83 | this.btn_decrypt.Location = new System.Drawing.Point(339, 22); 84 | this.btn_decrypt.Name = "btn_decrypt"; 85 | this.btn_decrypt.Size = new System.Drawing.Size(75, 23); 86 | this.btn_decrypt.TabIndex = 4; 87 | this.btn_decrypt.Text = "Decrypt"; 88 | this.btn_decrypt.UseVisualStyleBackColor = true; 89 | this.btn_decrypt.Click += new System.EventHandler(this.btn_decrypt_Click); 90 | // 91 | // btn_Encrypt 92 | // 93 | this.btn_Encrypt.Location = new System.Drawing.Point(339, 51); 94 | this.btn_Encrypt.Name = "btn_Encrypt"; 95 | this.btn_Encrypt.Size = new System.Drawing.Size(75, 23); 96 | this.btn_Encrypt.TabIndex = 5; 97 | this.btn_Encrypt.Text = "Encrypt"; 98 | this.btn_Encrypt.UseVisualStyleBackColor = true; 99 | this.btn_Encrypt.Click += new System.EventHandler(this.btn_Encrypt_Click); 100 | // 101 | // btn_open1 102 | // 103 | this.btn_open1.Location = new System.Drawing.Point(284, 34); 104 | this.btn_open1.Name = "btn_open1"; 105 | this.btn_open1.Size = new System.Drawing.Size(37, 23); 106 | this.btn_open1.TabIndex = 6; 107 | this.btn_open1.Text = "..."; 108 | this.btn_open1.UseVisualStyleBackColor = true; 109 | this.btn_open1.Click += new System.EventHandler(this.btn_open1_Click); 110 | // 111 | // label4 112 | // 113 | this.label4.AutoSize = true; 114 | this.label4.Location = new System.Drawing.Point(12, 122); 115 | this.label4.Name = "label4"; 116 | this.label4.Size = new System.Drawing.Size(35, 12); 117 | this.label4.TabIndex = 7; 118 | this.label4.Text = "File:"; 119 | // 120 | // TB_pathX 121 | // 122 | this.TB_pathX.AllowDrop = true; 123 | this.TB_pathX.Location = new System.Drawing.Point(53, 119); 124 | this.TB_pathX.Name = "TB_pathX"; 125 | this.TB_pathX.Size = new System.Drawing.Size(225, 21); 126 | this.TB_pathX.TabIndex = 8; 127 | this.TB_pathX.DragDrop += new System.Windows.Forms.DragEventHandler(this.TB_pathX_DragDrop); 128 | this.TB_pathX.DragEnter += new System.Windows.Forms.DragEventHandler(this.TB_pathX_DragEnter); 129 | // 130 | // btn_open2 131 | // 132 | this.btn_open2.Location = new System.Drawing.Point(284, 117); 133 | this.btn_open2.Name = "btn_open2"; 134 | this.btn_open2.Size = new System.Drawing.Size(37, 23); 135 | this.btn_open2.TabIndex = 6; 136 | this.btn_open2.Text = "..."; 137 | this.btn_open2.UseVisualStyleBackColor = true; 138 | this.btn_open2.Click += new System.EventHandler(this.btn_open2_Click); 139 | // 140 | // btn_xor 141 | // 142 | this.btn_xor.Location = new System.Drawing.Point(339, 117); 143 | this.btn_xor.Name = "btn_xor"; 144 | this.btn_xor.Size = new System.Drawing.Size(75, 23); 145 | this.btn_xor.TabIndex = 9; 146 | this.btn_xor.Text = "Xor"; 147 | this.btn_xor.UseVisualStyleBackColor = true; 148 | this.btn_xor.Click += new System.EventHandler(this.btn_xor_Click); 149 | // 150 | // Form1 151 | // 152 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 153 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 154 | this.ClientSize = new System.Drawing.Size(432, 157); 155 | this.Controls.Add(this.btn_xor); 156 | this.Controls.Add(this.TB_pathX); 157 | this.Controls.Add(this.label4); 158 | this.Controls.Add(this.btn_open2); 159 | this.Controls.Add(this.btn_open1); 160 | this.Controls.Add(this.btn_Encrypt); 161 | this.Controls.Add(this.btn_decrypt); 162 | this.Controls.Add(this.TB_Apath); 163 | this.Controls.Add(this.label3); 164 | this.Controls.Add(this.label2); 165 | this.Controls.Add(this.label1); 166 | this.Name = "Form1"; 167 | this.Text = "BH3Decrypt"; 168 | this.ResumeLayout(false); 169 | this.PerformLayout(); 170 | 171 | } 172 | 173 | #endregion 174 | 175 | private System.Windows.Forms.Label label1; 176 | private System.Windows.Forms.Label label2; 177 | private System.Windows.Forms.Label label3; 178 | private System.Windows.Forms.TextBox TB_Apath; 179 | private System.Windows.Forms.Button btn_decrypt; 180 | private System.Windows.Forms.Button btn_Encrypt; 181 | private System.Windows.Forms.Button btn_open1; 182 | private System.Windows.Forms.Label label4; 183 | private System.Windows.Forms.TextBox TB_pathX; 184 | private System.Windows.Forms.Button btn_open2; 185 | private System.Windows.Forms.Button btn_xor; 186 | } 187 | } 188 | 189 | -------------------------------------------------------------------------------- /FileDecryptTool/Form1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace FileDecryptTool 5 | { 6 | public partial class Form1 : Form 7 | { 8 | public Form1() 9 | { 10 | InitializeComponent(); 11 | } 12 | 13 | private void btn_decrypt_Click(object sender, EventArgs e) 14 | { 15 | FileDecryptTool.AB_Decrypt(TB_Apath.Text); 16 | } 17 | 18 | private void btn_Encrypt_Click(object sender, EventArgs e) 19 | { 20 | FileDecryptTool.AB_Encrypt(TB_Apath.Text); 21 | } 22 | 23 | private void btn_xor_Click(object sender, EventArgs e) 24 | { 25 | FileDecryptTool.Data_xor(TB_pathX.Text); 26 | } 27 | 28 | private void btn_open1_Click(object sender, EventArgs e) 29 | { 30 | FileDialog fileDialog = new OpenFileDialog(); 31 | if (fileDialog.ShowDialog() == DialogResult.OK) 32 | { 33 | TB_Apath.Text = fileDialog.FileName; 34 | } 35 | 36 | } 37 | 38 | private void btn_open2_Click(object sender, EventArgs e) 39 | { 40 | FileDialog fileDialog = new OpenFileDialog(); 41 | if (fileDialog.ShowDialog() == DialogResult.OK) 42 | { 43 | TB_pathX.Text = fileDialog.FileName; 44 | } 45 | } 46 | 47 | private void TB_Apath_DragEnter(object sender, DragEventArgs e) 48 | { 49 | if (e.Data.GetDataPresent(DataFormats.FileDrop)) 50 | e.Effect = DragDropEffects.All; 51 | else 52 | e.Effect = DragDropEffects.None; 53 | } 54 | 55 | private void TB_Apath_DragDrop(object sender, DragEventArgs e) 56 | { 57 | string path = ((Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); 58 | TB_Apath.Text = path; 59 | } 60 | 61 | private void TB_pathX_DragEnter(object sender, DragEventArgs e) 62 | { 63 | if (e.Data.GetDataPresent(DataFormats.FileDrop)) 64 | e.Effect = DragDropEffects.All; 65 | else 66 | e.Effect = DragDropEffects.None; 67 | } 68 | 69 | private void TB_pathX_DragDrop(object sender, DragEventArgs e) 70 | { 71 | string path = ((Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); 72 | TB_pathX.Text = path; 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /FileDecryptTool/Form1.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /FileDecryptTool/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace FileDecryptTool 5 | { 6 | static class Program 7 | { 8 | /// 9 | /// 应用程序的主入口点。 10 | /// 11 | [STAThread] 12 | static void Main() 13 | { 14 | Application.EnableVisualStyles(); 15 | Application.SetCompatibleTextRenderingDefault(false); 16 | Application.Run(new Form1()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /FileDecryptTool/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("FileDecryptTool")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("FileDecryptTool")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("00ce9685-6f08-4275-825a-435efc3774a1")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /FileDecryptTool/RSA_Encrypted-AESkey: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wzy96/bh3tool/9ea2a16b81a4b3173db1169d99dd34b2736fa241/FileDecryptTool/RSA_Encrypted-AESkey -------------------------------------------------------------------------------- /FileDecryptTool/rsakey.xml: -------------------------------------------------------------------------------- 1 | rXoKWm82JSX4UYihkt2FSjrp3pZqTxt6AyJ0ZexHssStYesCFuUOmDBrk0nxPTY2r7oB4ZC9tDhHzmA66Me56wkD47Z3fCEBfLFxmEVdUCvM1RIFdQxQCB7CMaFWXHoVfBhNcD60OtXD71vFusBLioa6HDHbKk8LdgWdV10OWaE=EQ==

16GiwrgCGvcYbgSZOBJRx4G9kioGgexLSyW62iK4EuT0Xu9xyflBDaC4yooFkxrflqEAIiEfTqNGlYeJks+5qw==

zfQY4dWi/Dlo38y6xvX4pUEAj1hbeFo/Qiy7H00P089W0KC6Mdi+GY4UuRGJtgX7UZfGQdHRj8mBjijFyhUl4w==cihlOejyDkaUdnrntEXvD0Svp7vlU9dzJ8iuNz+OoJdUMkKHiQt8yvq8Lv3Gt0p2Xs20xsY9wDhSi2Xfa9diSw==GDrVwDdAWeii7SclCFksT61LXCiDO1XpUxRSP+ryzZ/sGIthMwpwt7ZcynqIrAC0J7eAvHMJmHIPPeat24oEdQ==P4/vgq1XF77N8K/OxTbcjWFCC1d+v3W5xWQJbmU3KfVF2wOStZeILT2X12s7AHD+uUfN9O/xdEBIeqcSLVxWjw==o0WvZCxvMgWeatrybBvIvlWQ0X6CLFYYe2u42GXpILkbp3PFuzHvnkuwip/yG35RllS2efGjfHE0hgA3cazrNgM6gBDcFa7iznviIiQTySxFuzy3mXpjSQFaGgdvmuUQLgg5qahcdGgT455Fzo5GSu+IyTpD+dNoKy79NLTbvjE=
-------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 www 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /NetPackageTool/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /NetPackageTool/CmdidList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.RegularExpressions; 7 | using System.Threading.Tasks; 8 | using System.Windows.Forms; 9 | 10 | namespace NetPackageTool 11 | { 12 | class CmdidList 13 | { 14 | public static void SaveListToFile(string srcFilePath) 15 | { 16 | List> list = GetList(srcFilePath); 17 | 18 | StringBuilder @string = new StringBuilder(); 19 | 20 | list.Sort((x, y) => x.Key.CompareTo(y.Key)); 21 | @string = new StringBuilder(); 22 | foreach (var a in list) 23 | { 24 | @string.AppendLine(a.Key + " " + a.Value); 25 | } 26 | 27 | FileDialog fileDialog = new SaveFileDialog(); 28 | if (fileDialog.ShowDialog() == DialogResult.OK) 29 | File.WriteAllText(fileDialog.FileName, @string.ToString()); 30 | 31 | } 32 | 33 | public static List> GetList(string srcFilePath) 34 | { 35 | FileStream fileStream = new FileStream(srcFilePath, FileMode.Open); 36 | StreamReader reader = new StreamReader(fileStream); 37 | List> list = new List>(); 38 | 39 | string classname = ""; 40 | int cmdid; 41 | string line; 42 | Regex rege_cmdid = new Regex(" public const ([a-zA-Z]+)\\.CmdId CMD_ID = (\\d+)"); 43 | while ((line = reader.ReadLine()) != null) 44 | { 45 | if (line.StartsWith(" public const ") && rege_cmdid.IsMatch(line)) 46 | { 47 | 48 | classname = rege_cmdid.Match(line).Groups[1].Value; 49 | cmdid = Convert.ToInt32(rege_cmdid.Match(line).Groups[2].Value); 50 | list.Add(new KeyValuePair(cmdid, classname)); 51 | } 52 | } 53 | return list; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /NetPackageTool/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace NetPackageTool 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// 必需的设计器变量。 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// 清理所有正在使用的资源。 12 | /// 13 | /// 如果应释放托管资源,为 true;否则为 false。 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows 窗体设计器生成的代码 24 | 25 | /// 26 | /// 设计器支持所需的方法 - 不要修改 27 | /// 使用代码编辑器修改此方法的内容。 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.label1 = new System.Windows.Forms.Label(); 32 | this.label2 = new System.Windows.Forms.Label(); 33 | this.label3 = new System.Windows.Forms.Label(); 34 | this.label4 = new System.Windows.Forms.Label(); 35 | this.TB_dumppath = new System.Windows.Forms.TextBox(); 36 | this.TB_hexdumppath = new System.Windows.Forms.TextBox(); 37 | this.btn_dodump = new System.Windows.Forms.Button(); 38 | this.btn_dohexdump = new System.Windows.Forms.Button(); 39 | this.btn_opendump = new System.Windows.Forms.Button(); 40 | this.btn_openhexdump = new System.Windows.Forms.Button(); 41 | this.TB_cmdidpath = new System.Windows.Forms.TextBox(); 42 | this.btn_cmdidopen = new System.Windows.Forms.Button(); 43 | this.label5 = new System.Windows.Forms.Label(); 44 | this.SuspendLayout(); 45 | // 46 | // label1 47 | // 48 | this.label1.AutoSize = true; 49 | this.label1.Location = new System.Drawing.Point(13, 13); 50 | this.label1.Name = "label1"; 51 | this.label1.Size = new System.Drawing.Size(203, 12); 52 | this.label1.TabIndex = 0; 53 | this.label1.Text = "Generate cmd_id list from dump.cs"; 54 | // 55 | // label2 56 | // 57 | this.label2.AutoSize = true; 58 | this.label2.Location = new System.Drawing.Point(12, 42); 59 | this.label2.Name = "label2"; 60 | this.label2.Size = new System.Drawing.Size(83, 12); 61 | this.label2.TabIndex = 0; 62 | this.label2.Text = "dump.cs Path:"; 63 | // 64 | // label3 65 | // 66 | this.label3.AutoSize = true; 67 | this.label3.Location = new System.Drawing.Point(12, 67); 68 | this.label3.Name = "label3"; 69 | this.label3.Size = new System.Drawing.Size(215, 12); 70 | this.label3.TabIndex = 0; 71 | this.label3.Text = "Export NetPackage from HexDump file"; 72 | // 73 | // label4 74 | // 75 | this.label4.AutoSize = true; 76 | this.label4.Location = new System.Drawing.Point(12, 98); 77 | this.label4.Name = "label4"; 78 | this.label4.Size = new System.Drawing.Size(83, 12); 79 | this.label4.TabIndex = 0; 80 | this.label4.Text = "HexDump Path:"; 81 | // 82 | // TB_dumppath 83 | // 84 | this.TB_dumppath.AllowDrop = true; 85 | this.TB_dumppath.Location = new System.Drawing.Point(101, 38); 86 | this.TB_dumppath.Name = "TB_dumppath"; 87 | this.TB_dumppath.Size = new System.Drawing.Size(162, 21); 88 | this.TB_dumppath.TabIndex = 1; 89 | this.TB_dumppath.DragDrop += new System.Windows.Forms.DragEventHandler(this.TB_dumppath_DragDrop); 90 | this.TB_dumppath.DragEnter += new System.Windows.Forms.DragEventHandler(this.TB_dumppath_DragEnter); 91 | // 92 | // TB_hexdumppath 93 | // 94 | this.TB_hexdumppath.AllowDrop = true; 95 | this.TB_hexdumppath.Location = new System.Drawing.Point(101, 94); 96 | this.TB_hexdumppath.Name = "TB_hexdumppath"; 97 | this.TB_hexdumppath.Size = new System.Drawing.Size(162, 21); 98 | this.TB_hexdumppath.TabIndex = 2; 99 | this.TB_hexdumppath.DragDrop += new System.Windows.Forms.DragEventHandler(this.TB_pcappath_DragDrop); 100 | this.TB_hexdumppath.DragEnter += new System.Windows.Forms.DragEventHandler(this.TB_pcappath_DragEnter); 101 | // 102 | // btn_dodump 103 | // 104 | this.btn_dodump.Location = new System.Drawing.Point(309, 36); 105 | this.btn_dodump.Name = "btn_dodump"; 106 | this.btn_dodump.Size = new System.Drawing.Size(75, 23); 107 | this.btn_dodump.TabIndex = 3; 108 | this.btn_dodump.Text = "Generate"; 109 | this.btn_dodump.UseVisualStyleBackColor = true; 110 | this.btn_dodump.Click += new System.EventHandler(this.btn_dodump_Click); 111 | // 112 | // btn_dohexdump 113 | // 114 | this.btn_dohexdump.Location = new System.Drawing.Point(309, 109); 115 | this.btn_dohexdump.Name = "btn_dohexdump"; 116 | this.btn_dohexdump.Size = new System.Drawing.Size(75, 23); 117 | this.btn_dohexdump.TabIndex = 4; 118 | this.btn_dohexdump.Text = "Export"; 119 | this.btn_dohexdump.UseVisualStyleBackColor = true; 120 | this.btn_dohexdump.Click += new System.EventHandler(this.btn_dohexdump_Click); 121 | // 122 | // btn_opendump 123 | // 124 | this.btn_opendump.Location = new System.Drawing.Point(268, 38); 125 | this.btn_opendump.Name = "btn_opendump"; 126 | this.btn_opendump.Size = new System.Drawing.Size(33, 21); 127 | this.btn_opendump.TabIndex = 5; 128 | this.btn_opendump.Text = "..."; 129 | this.btn_opendump.UseVisualStyleBackColor = true; 130 | this.btn_opendump.Click += new System.EventHandler(this.btn_opendump_Click); 131 | // 132 | // btn_openhexdump 133 | // 134 | this.btn_openhexdump.Location = new System.Drawing.Point(269, 94); 135 | this.btn_openhexdump.Name = "btn_openhexdump"; 136 | this.btn_openhexdump.Size = new System.Drawing.Size(32, 21); 137 | this.btn_openhexdump.TabIndex = 6; 138 | this.btn_openhexdump.Text = "..."; 139 | this.btn_openhexdump.UseVisualStyleBackColor = true; 140 | this.btn_openhexdump.Click += new System.EventHandler(this.btn_openhexdump_Click); 141 | // 142 | // TB_cmdidpath 143 | // 144 | this.TB_cmdidpath.AllowDrop = true; 145 | this.TB_cmdidpath.Location = new System.Drawing.Point(101, 128); 146 | this.TB_cmdidpath.Name = "TB_cmdidpath"; 147 | this.TB_cmdidpath.Size = new System.Drawing.Size(162, 21); 148 | this.TB_cmdidpath.TabIndex = 2; 149 | this.TB_cmdidpath.DragDrop += new System.Windows.Forms.DragEventHandler(this.TB_cmdidpath_DragDrop); 150 | this.TB_cmdidpath.DragEnter += new System.Windows.Forms.DragEventHandler(this.TB_cmdidpath_DragEnter); 151 | // 152 | // btn_cmdidopen 153 | // 154 | this.btn_cmdidopen.Location = new System.Drawing.Point(269, 128); 155 | this.btn_cmdidopen.Name = "btn_cmdidopen"; 156 | this.btn_cmdidopen.Size = new System.Drawing.Size(32, 21); 157 | this.btn_cmdidopen.TabIndex = 6; 158 | this.btn_cmdidopen.Text = "..."; 159 | this.btn_cmdidopen.UseVisualStyleBackColor = true; 160 | this.btn_cmdidopen.Click += new System.EventHandler(this.btn_cmdidopen_Click); 161 | // 162 | // label5 163 | // 164 | this.label5.AutoSize = true; 165 | this.label5.Location = new System.Drawing.Point(24, 131); 166 | this.label5.Name = "label5"; 167 | this.label5.Size = new System.Drawing.Size(71, 12); 168 | this.label5.TabIndex = 0; 169 | this.label5.Text = "Cmdid Path:"; 170 | // 171 | // Form1 172 | // 173 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 174 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 175 | this.ClientSize = new System.Drawing.Size(396, 161); 176 | this.Controls.Add(this.btn_cmdidopen); 177 | this.Controls.Add(this.btn_openhexdump); 178 | this.Controls.Add(this.btn_opendump); 179 | this.Controls.Add(this.btn_dohexdump); 180 | this.Controls.Add(this.btn_dodump); 181 | this.Controls.Add(this.TB_cmdidpath); 182 | this.Controls.Add(this.TB_hexdumppath); 183 | this.Controls.Add(this.TB_dumppath); 184 | this.Controls.Add(this.label5); 185 | this.Controls.Add(this.label4); 186 | this.Controls.Add(this.label3); 187 | this.Controls.Add(this.label2); 188 | this.Controls.Add(this.label1); 189 | this.Name = "Form1"; 190 | this.Text = "BH3NetPackageTool"; 191 | this.ResumeLayout(false); 192 | this.PerformLayout(); 193 | 194 | } 195 | 196 | #endregion 197 | 198 | private System.Windows.Forms.Label label1; 199 | private System.Windows.Forms.Label label2; 200 | private System.Windows.Forms.Label label3; 201 | private System.Windows.Forms.Label label4; 202 | private System.Windows.Forms.TextBox TB_dumppath; 203 | private System.Windows.Forms.TextBox TB_hexdumppath; 204 | private System.Windows.Forms.Button btn_dodump; 205 | private System.Windows.Forms.Button btn_dohexdump; 206 | private System.Windows.Forms.Button btn_opendump; 207 | private System.Windows.Forms.Button btn_openhexdump; 208 | private System.Windows.Forms.TextBox TB_cmdidpath; 209 | private System.Windows.Forms.Button btn_cmdidopen; 210 | private System.Windows.Forms.Label label5; 211 | } 212 | } 213 | 214 | -------------------------------------------------------------------------------- /NetPackageTool/Form1.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Linq; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.ComponentModel; 6 | using System.Data; 7 | using System.Drawing; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using System.Windows.Forms; 12 | 13 | namespace NetPackageTool 14 | { 15 | public partial class Form1 : Form 16 | { 17 | public Form1() 18 | { 19 | InitializeComponent(); 20 | } 21 | 22 | private void btn_opendump_Click(object sender, EventArgs e) 23 | { 24 | FileDialog fileDialog = new OpenFileDialog(); 25 | if (fileDialog.ShowDialog() == DialogResult.OK) 26 | { 27 | TB_dumppath.Text = fileDialog.FileName; 28 | } 29 | } 30 | 31 | private void btn_openhexdump_Click(object sender, EventArgs e) 32 | { 33 | FileDialog fileDialog = new OpenFileDialog(); 34 | if (fileDialog.ShowDialog() == DialogResult.OK) 35 | { 36 | TB_hexdumppath.Text = fileDialog.FileName; 37 | } 38 | } 39 | 40 | private void btn_cmdidopen_Click(object sender, EventArgs e) 41 | { 42 | FileDialog fileDialog = new OpenFileDialog(); 43 | if (fileDialog.ShowDialog() == DialogResult.OK) 44 | { 45 | TB_cmdidpath.Text = fileDialog.FileName; 46 | } 47 | } 48 | 49 | private void TB_dumppath_DragEnter(object sender, DragEventArgs e) 50 | { 51 | if (e.Data.GetDataPresent(DataFormats.FileDrop)) 52 | e.Effect = DragDropEffects.All; 53 | else 54 | e.Effect = DragDropEffects.None; 55 | } 56 | 57 | private void TB_dumppath_DragDrop(object sender, DragEventArgs e) 58 | { 59 | string path = ((Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); 60 | TB_dumppath.Text = path; 61 | } 62 | 63 | private void TB_pcappath_DragEnter(object sender, DragEventArgs e) 64 | { 65 | if (e.Data.GetDataPresent(DataFormats.FileDrop)) 66 | e.Effect = DragDropEffects.All; 67 | else 68 | e.Effect = DragDropEffects.None; 69 | } 70 | 71 | private void TB_pcappath_DragDrop(object sender, DragEventArgs e) 72 | { 73 | string path = ((Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); 74 | TB_hexdumppath.Text = path; 75 | } 76 | 77 | private void TB_cmdidpath_DragEnter(object sender, DragEventArgs e) 78 | { 79 | if (e.Data.GetDataPresent(DataFormats.FileDrop)) 80 | e.Effect = DragDropEffects.All; 81 | else 82 | e.Effect = DragDropEffects.None; 83 | } 84 | 85 | private void TB_cmdidpath_DragDrop(object sender, DragEventArgs e) 86 | { 87 | string path = ((Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); 88 | TB_cmdidpath.Text = path; 89 | } 90 | 91 | private void btn_dodump_Click(object sender, EventArgs e) 92 | { 93 | CmdidList.SaveListToFile(TB_dumppath.Text); 94 | } 95 | 96 | private void btn_dohexdump_Click(object sender, EventArgs e) 97 | { 98 | NetPacket.ExportFromHexDump(TB_hexdumppath.Text, TB_cmdidpath.Text); 99 | } 100 | 101 | 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /NetPackageTool/Form1.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /NetPackageTool/NetPackageTool.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {23AF6847-0E1E-401B-AA52-BB06A8AF80D0} 8 | WinExe 9 | NetPackageTool 10 | NetPackageTool 11 | v4.6.1 12 | 512 13 | true 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | true 26 | 27 | 28 | AnyCPU 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | Form 56 | 57 | 58 | Form1.cs 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | Form1.cs 67 | 68 | 69 | ResXFileCodeGenerator 70 | Resources.Designer.cs 71 | Designer 72 | 73 | 74 | True 75 | Resources.resx 76 | 77 | 78 | 79 | SettingsSingleFileGenerator 80 | Settings.Designer.cs 81 | 82 | 83 | True 84 | Settings.settings 85 | True 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /NetPackageTool/NetPacket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.IO; 7 | using Newtonsoft.Json; 8 | using ProtoBuf; 9 | using System.Text.RegularExpressions; 10 | using Newtonsoft.Json.Linq; 11 | using System.Windows.Forms; 12 | 13 | namespace NetPackageTool 14 | { 15 | static class NetPacket 16 | { 17 | static public void ExportFromHexDump(string hexdumpPath, string cmdidPath) 18 | { 19 | Dictionary cmdid = new Dictionary(); 20 | if (File.Exists(cmdidPath)) 21 | { 22 | string[] cmdidstr = File.ReadAllLines(cmdidPath); 23 | foreach (string cmdidline in cmdidstr) 24 | { 25 | string[] s = cmdidline.Split(' '); 26 | cmdid.Add(Convert.ToInt32(s[0]), s[1]); 27 | } 28 | } 29 | 30 | List block = new List(); 31 | 32 | FileStream file = new FileStream(hexdumpPath, FileMode.Open); 33 | StreamReader reader = new StreamReader(file); 34 | 35 | string line; 36 | bool firstCharIsSpace = false; 37 | MemoryStream ms = new MemoryStream(); 38 | 39 | while ((line = reader.ReadLine()) != null) 40 | { 41 | if ((line.First() == ' ') != firstCharIsSpace) 42 | { 43 | if (ms.Length > 0) block.Add(ms); 44 | 45 | firstCharIsSpace = (line.First() == ' '); 46 | ms = new MemoryStream(); 47 | } 48 | 49 | byte[] bytes = HexDump2bytes(line); 50 | ms.Write(bytes, 0, bytes.Length); 51 | } 52 | block[0].Position = 0; 53 | block[1].Position = 0; 54 | //combine block 55 | for (int i = block.Count - 1; i > 1; i--) 56 | { 57 | var stream = block[i]; 58 | if (stream == null) continue; 59 | stream.Position = 0; 60 | byte[] buffer = stream.GetBuffer(); 61 | if (buffer[0] == 0x01 && buffer[1] == 0x23 && buffer[2] == 0x45 & buffer[3] == 0x67) continue; 62 | stream.WriteTo(block[i - 2]); 63 | block[i] = null; 64 | } 65 | 66 | StringBuilder strb = new StringBuilder(); 67 | int packetcont = 0; 68 | for (int i = 0; i < block.Count; i++) 69 | { 70 | if (block[i] == null) continue; 71 | BinaryReader breader = new BinaryReader(block[i]); 72 | //read NetPacketV1 data 73 | while (breader.BaseStream.Position < breader.BaseStream.Length) 74 | { 75 | 76 | uint head_magic_ = breader.ReadUIntBig(); 77 | ushort packet_version_ = breader.ReadUshortBig(); 78 | ushort client_version_ = breader.ReadUshortBig(); 79 | uint time_ = breader.ReadUIntBig(); 80 | uint user_id_ = breader.ReadUIntBig(); 81 | uint user_ip_ = breader.ReadUIntBig(); 82 | uint user_session_id_ = breader.ReadUIntBig(); 83 | uint gateway_ip_ = breader.ReadUIntBig(); 84 | ushort cmd_id_ = breader.ReadUshortBig(); 85 | uint body_len_ = breader.ReadUIntBig(); 86 | ushort sign_type_ = breader.ReadUshortBig(); 87 | uint sign_ = breader.ReadUIntBig(); 88 | byte[] body_ = breader.ReadBytes(body_len_); 89 | uint tail_magic_ = breader.ReadUIntBig(); 90 | 91 | //to string 92 | string cmdclass = cmdid.ContainsKey(cmd_id_) ? cmdid[cmd_id_] : "ERROR!"; 93 | strb.AppendLine("[packet] " + packetcont + " cmd_id = " + cmd_id_ + " " + cmdclass); 94 | 95 | string jsonStr = ProtoToJson(body_).ToString(Formatting.Indented); 96 | strb.AppendLine(jsonStr); 97 | 98 | packetcont++; 99 | } 100 | } 101 | 102 | FileDialog fileDialog = new SaveFileDialog(); 103 | if (fileDialog.ShowDialog() == DialogResult.OK) 104 | File.WriteAllText(fileDialog.FileName, strb.ToString()); 105 | 106 | } 107 | 108 | private static byte[] HexDump2bytes(string hex) 109 | { 110 | int offset = hex.StartsWith(" ") ? 4 : 0; 111 | string byteStr = hex.Substring(offset + 10, 48).Replace(" ", string.Empty); 112 | 113 | int len = byteStr.Length / 2; 114 | byte[] data = new byte[len]; 115 | for (int i = 0; i < len; i++) 116 | { 117 | data[i] = (byte)Convert.ToInt32(byteStr.Substring(i * 2, 2), 16); 118 | } 119 | return data; 120 | } 121 | 122 | static public JObject ProtoToJson(byte[] protodata) 123 | { 124 | Stream stream = new MemoryStream(protodata); 125 | ProtoReader s = ProtoReader.Create(stream, stream.Length); 126 | Regex regex = new Regex("[\u0000-\u0009\u000e-\u001f]"); 127 | JObject jObject = new JObject(); 128 | 129 | for (; s.Position < protodata.Length;) 130 | { 131 | int fieldNumber = s.ReadFieldHeader(); 132 | string name = "field_" + fieldNumber; 133 | 134 | switch (s.WireType) 135 | { 136 | case WireType.Variant: 137 | case WireType.Fixed32: 138 | case WireType.Fixed64: 139 | case WireType.SignedVariant: 140 | { 141 | string data = "0x" + s.ReadInt64().ToString("X"); 142 | jObject.AddEx(name, data); 143 | break; 144 | } 145 | case WireType.String: 146 | { 147 | byte[] b = s.ReadStringBytes(); 148 | string readstr = ""; 149 | if (b != null) readstr = Encoding.UTF8.GetString(b); 150 | 151 | if (b != null && regex.IsMatch(readstr)) 152 | { 153 | try 154 | { 155 | jObject.AddEx(name, ProtoToJson(b)); 156 | } 157 | catch 158 | { 159 | jObject.AddEx(name, readstr); 160 | } 161 | } 162 | else 163 | { 164 | jObject.AddEx(name, readstr); 165 | } 166 | break; 167 | } 168 | case WireType.StartGroup: 169 | //@string.Append('\t', depth + 1); @string.Append("Start Group\n"); break; 170 | case WireType.EndGroup: 171 | //@string.Append('\t', depth + 1); @string.Append("End Group\n"); break; 172 | default: break; 173 | } 174 | } 175 | return jObject; 176 | } 177 | 178 | } 179 | static public class JObjectExtention 180 | { 181 | public static void AddEx(this JObject jObject, string name, string data) 182 | { 183 | if (jObject.ContainsKey(name)) 184 | { 185 | if (jObject[name].Type != JTokenType.Array) 186 | { 187 | JArray jArray = new JArray(); 188 | jArray.Add(jObject[name]); 189 | jArray.Add(data); 190 | jObject[name] = jArray; 191 | } 192 | else 193 | { 194 | ((JArray)jObject[name]).Add(data); 195 | } 196 | } 197 | else 198 | { 199 | jObject.Add(name, data); 200 | } 201 | } 202 | public static void AddEx(this JObject jObject, string name, JObject data) 203 | { 204 | if (jObject.ContainsKey(name)) 205 | { 206 | if (jObject[name].Type != JTokenType.Array) 207 | { 208 | JArray jArray = new JArray(); 209 | jArray.Add(jObject[name]); 210 | jArray.Add(data); 211 | jObject[name] = jArray; 212 | } 213 | else 214 | { 215 | ((JArray)jObject[name]).Add(data); 216 | } 217 | } 218 | else 219 | { 220 | jObject.Add(name, data); 221 | } 222 | } 223 | } 224 | static class FileStreamExtention 225 | { 226 | public static uint ReadUIntBig(this BinaryReader file) 227 | { 228 | byte[] t = new byte[4]; 229 | if (file.Read(t, 0, 4) != 4) 230 | return 0; 231 | Array.Reverse(t); 232 | return BitConverter.ToUInt32(t, 0); 233 | } 234 | 235 | public static ushort ReadUshortBig(this BinaryReader file) 236 | { 237 | byte[] t = new byte[2]; 238 | if (file.Read(t, 0, 2) != 2) 239 | return 0; 240 | Array.Reverse(t); 241 | return BitConverter.ToUInt16(t, 0); 242 | } 243 | 244 | public static byte[] ReadBytes(this BinaryReader file, uint length) 245 | { 246 | byte[] data = new byte[length]; 247 | file.Read(data, 0, data.Length); 248 | return data; 249 | } 250 | } 251 | } 252 | -------------------------------------------------------------------------------- /NetPackageTool/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace NetPackageTool 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// 应用程序的主入口点。 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NetPackageTool/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("NetPackageTool")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("NetPackageTool")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("23af6847-0e1e-401b-aa52-bb06a8af80d0")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /NetPackageTool/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本: 4.0.30319.42000 5 | // 6 | // 对此文件的更改可能导致不正确的行为,如果 7 | // 重新生成代码,则所做更改将丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace NetPackageTool.Properties 12 | { 13 | 14 | 15 | /// 16 | /// 强类型资源类,用于查找本地化字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// 返回此类使用的缓存 ResourceManager 实例。 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NetPackageTool.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// 覆盖当前线程的 CurrentUICulture 属性 56 | /// 使用此强类型的资源类的资源查找。 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /NetPackageTool/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /NetPackageTool/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace NetPackageTool.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /NetPackageTool/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /NetPackageTool/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /NetPackageTool/protoReader/ProtoReader.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Text; 6 | 7 | namespace ProtoBuf 8 | { 9 | /// 10 | /// A stateful reader, used to read a protobuf stream. Typical usage would be (sequentially) to call 11 | /// ReadFieldHeader and (after matching the field) an appropriate Read* method. 12 | /// 13 | public sealed class ProtoReader : IDisposable 14 | { 15 | Stream source; 16 | byte[] ioBuffer = new byte[4096]; 17 | int depth, ioIndex, available; 18 | long blockEnd64, dataRemaining64; 19 | bool isFixedLength; 20 | 21 | // this is how many outstanding objects do not currently have 22 | // values for the purposes of reference tracking; we'll default 23 | // to just trapping the root object 24 | // note: objects are trapped (the ref and key mapped) via NoteObject 25 | uint trapCount; // uint is so we can use beq/bne more efficiently than bgt 26 | 27 | /// 28 | /// Gets the number of the field being processed. 29 | /// 30 | public int FieldNumber { get; private set; } 31 | 32 | /// 33 | /// Indicates the underlying proto serialization format on the wire. 34 | /// 35 | public WireType WireType { get; private set; } 36 | 37 | 38 | internal const long TO_EOF = -1; 39 | 40 | 41 | 42 | private static void Init(ProtoReader reader, Stream source, long length) 43 | { 44 | if (source == null) throw new ArgumentNullException(nameof(source)); 45 | if (!source.CanRead) throw new ArgumentException("Cannot read from stream", nameof(source)); 46 | reader.source = source; 47 | reader.ioBuffer = new byte[source.Length]; 48 | bool isFixedLength = length >= 0; 49 | reader.isFixedLength = isFixedLength; 50 | reader.dataRemaining64 = isFixedLength ? length : 0; 51 | 52 | reader.LongPosition = 0; 53 | reader.available = reader.depth = reader.FieldNumber = reader.ioIndex = 0; 54 | reader.blockEnd64 = long.MaxValue; 55 | reader.WireType = WireType.None; 56 | reader.trapCount = 1; 57 | } 58 | 59 | /// 60 | /// Releases resources used by the reader, but importantly does not Dispose the 61 | /// underlying stream; in many typical use-cases the stream is used for different 62 | /// processes, so it is assumed that the consumer will Dispose their stream separately. 63 | /// 64 | public void Dispose() 65 | { 66 | // importantly, this does **not** own the stream, and does not dispose it 67 | source = null; 68 | } 69 | 70 | internal int TryReadUInt32VariantWithoutMoving(bool trimNegative, out uint value) 71 | { 72 | if (available < 10) Ensure(10, false); 73 | if (available == 0) 74 | { 75 | value = 0; 76 | return 0; 77 | } 78 | int readPos = ioIndex; 79 | value = ioBuffer[readPos++]; 80 | if ((value & 0x80) == 0) return 1; 81 | value &= 0x7F; 82 | if (available == 1) throw EoF(this); 83 | 84 | uint chunk = ioBuffer[readPos++]; 85 | value |= (chunk & 0x7F) << 7; 86 | if ((chunk & 0x80) == 0) return 2; 87 | if (available == 2) throw EoF(this); 88 | 89 | chunk = ioBuffer[readPos++]; 90 | value |= (chunk & 0x7F) << 14; 91 | if ((chunk & 0x80) == 0) return 3; 92 | if (available == 3) throw EoF(this); 93 | 94 | chunk = ioBuffer[readPos++]; 95 | value |= (chunk & 0x7F) << 21; 96 | if ((chunk & 0x80) == 0) return 4; 97 | if (available == 4) throw EoF(this); 98 | 99 | chunk = ioBuffer[readPos]; 100 | value |= chunk << 28; // can only use 4 bits from this chunk 101 | if ((chunk & 0xF0) == 0) return 5; 102 | 103 | if (trimNegative // allow for -ve values 104 | && (chunk & 0xF0) == 0xF0 105 | && available >= 10 106 | && ioBuffer[++readPos] == 0xFF 107 | && ioBuffer[++readPos] == 0xFF 108 | && ioBuffer[++readPos] == 0xFF 109 | && ioBuffer[++readPos] == 0xFF 110 | && ioBuffer[++readPos] == 0x01) 111 | { 112 | return 10; 113 | } 114 | throw AddErrorData(new OverflowException(), this); 115 | } 116 | 117 | private uint ReadUInt32Variant(bool trimNegative) 118 | { 119 | int read = TryReadUInt32VariantWithoutMoving(trimNegative, out uint value); 120 | if (read > 0) 121 | { 122 | ioIndex += read; 123 | available -= read; 124 | LongPosition += read; 125 | return value; 126 | } 127 | throw EoF(this); 128 | } 129 | 130 | private bool TryReadUInt32Variant(out uint value) 131 | { 132 | int read = TryReadUInt32VariantWithoutMoving(false, out value); 133 | if (read > 0) 134 | { 135 | ioIndex += read; 136 | available -= read; 137 | LongPosition += read; 138 | return true; 139 | } 140 | return false; 141 | } 142 | 143 | /// 144 | /// Reads an unsigned 32-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64 145 | /// 146 | public uint ReadUInt32() 147 | { 148 | switch (WireType) 149 | { 150 | case WireType.Variant: 151 | return ReadUInt32Variant(false); 152 | case WireType.Fixed32: 153 | if (available < 4) Ensure(4, true); 154 | LongPosition += 4; 155 | available -= 4; 156 | return ((uint)ioBuffer[ioIndex++]) 157 | | (((uint)ioBuffer[ioIndex++]) << 8) 158 | | (((uint)ioBuffer[ioIndex++]) << 16) 159 | | (((uint)ioBuffer[ioIndex++]) << 24); 160 | case WireType.Fixed64: 161 | ulong val = ReadUInt64(); 162 | checked { return (uint)val; } 163 | default: 164 | throw CreateWireTypeException(); 165 | } 166 | } 167 | 168 | /// 169 | /// Returns the position of the current reader (note that this is not necessarily the same as the position 170 | /// in the underlying stream, if multiple readers are used on the same stream) 171 | /// 172 | public int Position { get { return checked((int)LongPosition); } } 173 | 174 | /// 175 | /// Returns the position of the current reader (note that this is not necessarily the same as the position 176 | /// in the underlying stream, if multiple readers are used on the same stream) 177 | /// 178 | public long LongPosition { get; private set; } 179 | internal void Ensure(int count, bool strict) 180 | { 181 | if (ioIndex + count >= ioBuffer.Length) 182 | { 183 | // need to shift the buffer data to the left to make space 184 | Buffer.BlockCopy(ioBuffer, ioIndex, ioBuffer, 0, available); 185 | ioIndex = 0; 186 | } 187 | count -= available; 188 | int writePos = ioIndex + available, bytesRead; 189 | int canRead = ioBuffer.Length - writePos; 190 | if (isFixedLength) 191 | { // throttle it if needed 192 | if (dataRemaining64 < canRead) canRead = (int)dataRemaining64; 193 | } 194 | while (count > 0 && canRead > 0 && (bytesRead = source.Read(ioBuffer, writePos, canRead)) > 0) 195 | { 196 | available += bytesRead; 197 | count -= bytesRead; 198 | canRead -= bytesRead; 199 | writePos += bytesRead; 200 | if (isFixedLength) { dataRemaining64 -= bytesRead; } 201 | } 202 | if (strict && count > 0) 203 | { 204 | throw EoF(this); 205 | } 206 | 207 | } 208 | /// 209 | /// Reads a signed 16-bit integer from the stream: Variant, Fixed32, Fixed64, SignedVariant 210 | /// 211 | public short ReadInt16() 212 | { 213 | checked { return (short)ReadInt32(); } 214 | } 215 | /// 216 | /// Reads an unsigned 16-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64 217 | /// 218 | public ushort ReadUInt16() 219 | { 220 | checked { return (ushort)ReadUInt32(); } 221 | } 222 | 223 | /// 224 | /// Reads an unsigned 8-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64 225 | /// 226 | public byte ReadByte() 227 | { 228 | checked { return (byte)ReadUInt32(); } 229 | } 230 | 231 | /// 232 | /// Reads a signed 8-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64, SignedVariant 233 | /// 234 | public sbyte ReadSByte() 235 | { 236 | checked { return (sbyte)ReadInt32(); } 237 | } 238 | 239 | /// 240 | /// Reads a signed 32-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64, SignedVariant 241 | /// 242 | public int ReadInt32() 243 | { 244 | switch (WireType) 245 | { 246 | case WireType.Variant: 247 | return (int)ReadUInt32Variant(true); 248 | case WireType.Fixed32: 249 | if (available < 4) Ensure(4, true); 250 | LongPosition += 4; 251 | available -= 4; 252 | return ((int)ioBuffer[ioIndex++]) 253 | | (((int)ioBuffer[ioIndex++]) << 8) 254 | | (((int)ioBuffer[ioIndex++]) << 16) 255 | | (((int)ioBuffer[ioIndex++]) << 24); 256 | case WireType.Fixed64: 257 | long l = ReadInt64(); 258 | checked { return (int)l; } 259 | case WireType.SignedVariant: 260 | return Zag(ReadUInt32Variant(true)); 261 | default: 262 | throw CreateWireTypeException(); 263 | } 264 | } 265 | private const long Int64Msb = ((long)1) << 63; 266 | private const int Int32Msb = ((int)1) << 31; 267 | private static int Zag(uint ziggedValue) 268 | { 269 | int value = (int)ziggedValue; 270 | return (-(value & 0x01)) ^ ((value >> 1) & ~ProtoReader.Int32Msb); 271 | } 272 | 273 | private static long Zag(ulong ziggedValue) 274 | { 275 | long value = (long)ziggedValue; 276 | return (-(value & 0x01L)) ^ ((value >> 1) & ~ProtoReader.Int64Msb); 277 | } 278 | /// 279 | /// Reads a signed 64-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64, SignedVariant 280 | /// 281 | public long ReadInt64() 282 | { 283 | switch (WireType) 284 | { 285 | case WireType.Variant: 286 | return (long)ReadUInt64Variant(); 287 | case WireType.Fixed32: 288 | return ReadInt32(); 289 | case WireType.Fixed64: 290 | if (available < 8) Ensure(8, true); 291 | LongPosition += 8; 292 | available -= 8; 293 | 294 | #if NETCOREAPP2_1 295 | var result = System.Buffers.Binary.BinaryPrimitives.ReadInt64LittleEndian(ioBuffer.AsSpan(ioIndex, 8)); 296 | 297 | ioIndex+= 8; 298 | 299 | return result; 300 | #else 301 | return ((long)ioBuffer[ioIndex++]) 302 | | (((long)ioBuffer[ioIndex++]) << 8) 303 | | (((long)ioBuffer[ioIndex++]) << 16) 304 | | (((long)ioBuffer[ioIndex++]) << 24) 305 | | (((long)ioBuffer[ioIndex++]) << 32) 306 | | (((long)ioBuffer[ioIndex++]) << 40) 307 | | (((long)ioBuffer[ioIndex++]) << 48) 308 | | (((long)ioBuffer[ioIndex++]) << 56); 309 | #endif 310 | case WireType.SignedVariant: 311 | return Zag(ReadUInt64Variant()); 312 | default: 313 | throw CreateWireTypeException(); 314 | } 315 | } 316 | 317 | private int TryReadUInt64VariantWithoutMoving(out ulong value) 318 | { 319 | if (available < 10) Ensure(10, false); 320 | if (available == 0) 321 | { 322 | value = 0; 323 | return 0; 324 | } 325 | int readPos = ioIndex; 326 | value = ioBuffer[readPos++]; 327 | if ((value & 0x80) == 0) return 1; 328 | value &= 0x7F; 329 | if (available == 1) throw EoF(this); 330 | 331 | ulong chunk = ioBuffer[readPos++]; 332 | value |= (chunk & 0x7F) << 7; 333 | if ((chunk & 0x80) == 0) return 2; 334 | if (available == 2) throw EoF(this); 335 | 336 | chunk = ioBuffer[readPos++]; 337 | value |= (chunk & 0x7F) << 14; 338 | if ((chunk & 0x80) == 0) return 3; 339 | if (available == 3) throw EoF(this); 340 | 341 | chunk = ioBuffer[readPos++]; 342 | value |= (chunk & 0x7F) << 21; 343 | if ((chunk & 0x80) == 0) return 4; 344 | if (available == 4) throw EoF(this); 345 | 346 | chunk = ioBuffer[readPos++]; 347 | value |= (chunk & 0x7F) << 28; 348 | if ((chunk & 0x80) == 0) return 5; 349 | if (available == 5) throw EoF(this); 350 | 351 | chunk = ioBuffer[readPos++]; 352 | value |= (chunk & 0x7F) << 35; 353 | if ((chunk & 0x80) == 0) return 6; 354 | if (available == 6) throw EoF(this); 355 | 356 | chunk = ioBuffer[readPos++]; 357 | value |= (chunk & 0x7F) << 42; 358 | if ((chunk & 0x80) == 0) return 7; 359 | if (available == 7) throw EoF(this); 360 | 361 | 362 | chunk = ioBuffer[readPos++]; 363 | value |= (chunk & 0x7F) << 49; 364 | if ((chunk & 0x80) == 0) return 8; 365 | if (available == 8) throw EoF(this); 366 | 367 | chunk = ioBuffer[readPos++]; 368 | value |= (chunk & 0x7F) << 56; 369 | if ((chunk & 0x80) == 0) return 9; 370 | if (available == 9) throw EoF(this); 371 | 372 | chunk = ioBuffer[readPos]; 373 | value |= chunk << 63; // can only use 1 bit from this chunk 374 | 375 | if ((chunk & ~(ulong)0x01) != 0) throw AddErrorData(new OverflowException(), this); 376 | return 10; 377 | } 378 | 379 | private ulong ReadUInt64Variant() 380 | { 381 | int read = TryReadUInt64VariantWithoutMoving(out ulong value); 382 | if (read > 0) 383 | { 384 | ioIndex += read; 385 | available -= read; 386 | LongPosition += read; 387 | return value; 388 | } 389 | throw EoF(this); 390 | } 391 | 392 | 393 | #if COREFX 394 | static readonly Encoding encoding = Encoding.UTF8; 395 | #else 396 | static readonly UTF8Encoding encoding = new UTF8Encoding(); 397 | #endif 398 | /// 399 | /// Reads a string from the stream (using UTF8); supported wire-types: String 400 | /// 401 | public string ReadString() 402 | { 403 | if (WireType == WireType.String) 404 | { 405 | int bytes = (int)ReadUInt32Variant(false); 406 | if (bytes == 0) return ""; 407 | if (available < bytes) Ensure(bytes, true); 408 | 409 | string s = encoding.GetString(ioBuffer, ioIndex, bytes); 410 | available -= bytes; 411 | LongPosition += bytes; 412 | ioIndex += bytes; 413 | 414 | return s; 415 | } 416 | throw CreateWireTypeException(); 417 | } 418 | /// 419 | /// Reads bytes from the stream (using UTF8); supported wire-types: String 420 | /// 421 | public byte[] ReadStringBytes() 422 | { 423 | if(WireType==WireType.String) 424 | { 425 | int bytes = (int)ReadUInt32Variant(false); 426 | if (bytes == 0) return null; 427 | if (available < bytes) Ensure(bytes, true); 428 | 429 | byte[] b = new byte[bytes]; 430 | Array.Copy(ioBuffer, ioIndex, b, 0, bytes); 431 | available -= bytes; 432 | LongPosition += bytes; 433 | ioIndex += bytes; 434 | 435 | return b; 436 | } 437 | throw CreateWireTypeException(); 438 | } 439 | /// 440 | /// Throws an exception indication that the given value cannot be mapped to an enum. 441 | /// 442 | 443 | private Exception CreateWireTypeException() 444 | { 445 | return CreateException("Invalid wire-type; this usually means you have over-written a file without truncating or setting the length; see https://stackoverflow.com/q/2152978/23354"); 446 | } 447 | 448 | private Exception CreateException(string message) 449 | { 450 | return new Exception(); 451 | } 452 | /// 453 | /// Reads a double-precision number from the stream; supported wire-types: Fixed32, Fixed64 454 | /// 455 | public 456 | #if !FEAT_SAFE 457 | unsafe 458 | #endif 459 | double ReadDouble() 460 | { 461 | switch (WireType) 462 | { 463 | case WireType.Fixed32: 464 | return ReadSingle(); 465 | case WireType.Fixed64: 466 | long value = ReadInt64(); 467 | #if FEAT_SAFE 468 | return BitConverter.ToDouble(BitConverter.GetBytes(value), 0); 469 | #else 470 | return *(double*)&value; 471 | #endif 472 | default: 473 | throw CreateWireTypeException(); 474 | } 475 | } 476 | /// 477 | /// Reads a field header from the stream, setting the wire-type and retuning the field number. If no 478 | /// more fields are available, then 0 is returned. This methods respects sub-messages. 479 | /// 480 | public int ReadFieldHeader() 481 | { 482 | // at the end of a group the caller must call EndSubItem to release the 483 | // reader (which moves the status to Error, since ReadFieldHeader must 484 | // then be called) 485 | if (blockEnd64 <= LongPosition || WireType == WireType.EndGroup) { return 0; } 486 | 487 | if (TryReadUInt32Variant(out uint tag) && tag != 0) 488 | { 489 | WireType = (WireType)(tag & 7); 490 | FieldNumber = (int)(tag >> 3); 491 | if (FieldNumber < 1) 492 | throw new Exception(); 493 | } 494 | else 495 | { 496 | WireType = WireType.None; 497 | FieldNumber = 0; 498 | } 499 | if (WireType == ProtoBuf.WireType.EndGroup) 500 | { 501 | if (depth > 0) return 0; // spoof an end, but note we still set the field-number 502 | throw new Exception("Unexpected end-group in source data; this usually means the source data is corrupt"); 503 | } 504 | return FieldNumber; 505 | } 506 | /// 507 | /// Looks ahead to see whether the next field in the stream is what we expect 508 | /// (typically; what we've just finished reading - for example ot read successive list items) 509 | /// 510 | public bool TryReadFieldHeader(int field) 511 | { 512 | // check for virtual end of stream 513 | if (blockEnd64 <= LongPosition || WireType == WireType.EndGroup) { return false; } 514 | 515 | int read = TryReadUInt32VariantWithoutMoving(false, out uint tag); 516 | WireType tmpWireType; // need to catch this to exclude (early) any "end group" tokens 517 | if (read > 0 && ((int)tag >> 3) == field 518 | && (tmpWireType = (WireType)(tag & 7)) != WireType.EndGroup) 519 | { 520 | WireType = tmpWireType; 521 | FieldNumber = field; 522 | LongPosition += read; 523 | ioIndex += read; 524 | available -= read; 525 | return true; 526 | } 527 | return false; 528 | } 529 | 530 | /// 531 | /// Compares the streams current wire-type to the hinted wire-type, updating the reader if necessary; for example, 532 | /// a Variant may be updated to SignedVariant. If the hinted wire-type is unrelated then no change is made. 533 | /// 534 | public void Hint(WireType wireType) 535 | { 536 | if (this.WireType == wireType) { } // fine; everything as we expect 537 | else if (((int)wireType & 7) == (int)this.WireType) 538 | { // the underling type is a match; we're customising it with an extension 539 | this.WireType = wireType; 540 | } 541 | // note no error here; we're OK about using alternative data 542 | } 543 | 544 | /// 545 | /// Verifies that the stream's current wire-type is as expected, or a specialized sub-type (for example, 546 | /// SignedVariant) - in which case the current wire-type is updated. Otherwise an exception is thrown. 547 | /// 548 | public void Assert(WireType wireType) 549 | { 550 | if (this.WireType == wireType) { } // fine; everything as we expect 551 | else if (((int)wireType & 7) == (int)this.WireType) 552 | { // the underling type is a match; we're customising it with an extension 553 | this.WireType = wireType; 554 | } 555 | else 556 | { // nope; that is *not* what we were expecting! 557 | throw CreateWireTypeException(); 558 | } 559 | } 560 | 561 | /// 562 | /// Discards the data for the current field. 563 | /// 564 | public void SkipField() 565 | { 566 | switch (WireType) 567 | { 568 | case WireType.Fixed32: 569 | if (available < 4) Ensure(4, true); 570 | available -= 4; 571 | ioIndex += 4; 572 | LongPosition += 4; 573 | return; 574 | case WireType.Fixed64: 575 | if (available < 8) Ensure(8, true); 576 | available -= 8; 577 | ioIndex += 8; 578 | LongPosition += 8; 579 | return; 580 | case WireType.String: 581 | long len = (long)ReadUInt64Variant(); 582 | if (len <= available) 583 | { // just jump it! 584 | available -= (int)len; 585 | ioIndex += (int)len; 586 | LongPosition += len; 587 | return; 588 | } 589 | // everything remaining in the buffer is garbage 590 | LongPosition += len; // assumes success, but if it fails we're screwed anyway 591 | len -= available; // discount anything we've got to-hand 592 | ioIndex = available = 0; // note that we have no data in the buffer 593 | if (isFixedLength) 594 | { 595 | if (len > dataRemaining64) throw EoF(this); 596 | // else assume we're going to be OK 597 | dataRemaining64 -= len; 598 | } 599 | ProtoReader.Seek(source, len, ioBuffer); 600 | return; 601 | case WireType.Variant: 602 | case WireType.SignedVariant: 603 | ReadUInt64Variant(); // and drop it 604 | return; 605 | case WireType.StartGroup: 606 | int originalFieldNumber = this.FieldNumber; 607 | depth++; // need to satisfy the sanity-checks in ReadFieldHeader 608 | while (ReadFieldHeader() > 0) { SkipField(); } 609 | depth--; 610 | if (WireType == WireType.EndGroup && FieldNumber == originalFieldNumber) 611 | { // we expect to exit in a similar state to how we entered 612 | WireType = ProtoBuf.WireType.None; 613 | return; 614 | } 615 | throw CreateWireTypeException(); 616 | case WireType.None: // treat as explicit errorr 617 | case WireType.EndGroup: // treat as explicit error 618 | default: // treat as implicit error 619 | throw CreateWireTypeException(); 620 | } 621 | } 622 | 623 | /// 624 | /// Reads an unsigned 64-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64 625 | /// 626 | public ulong ReadUInt64() 627 | { 628 | switch (WireType) 629 | { 630 | case WireType.Variant: 631 | return ReadUInt64Variant(); 632 | case WireType.Fixed32: 633 | return ReadUInt32(); 634 | case WireType.Fixed64: 635 | if (available < 8) Ensure(8, true); 636 | LongPosition += 8; 637 | available -= 8; 638 | 639 | return ((ulong)ioBuffer[ioIndex++]) 640 | | (((ulong)ioBuffer[ioIndex++]) << 8) 641 | | (((ulong)ioBuffer[ioIndex++]) << 16) 642 | | (((ulong)ioBuffer[ioIndex++]) << 24) 643 | | (((ulong)ioBuffer[ioIndex++]) << 32) 644 | | (((ulong)ioBuffer[ioIndex++]) << 40) 645 | | (((ulong)ioBuffer[ioIndex++]) << 48) 646 | | (((ulong)ioBuffer[ioIndex++]) << 56); 647 | default: 648 | throw CreateWireTypeException(); 649 | } 650 | } 651 | /// 652 | /// Reads a single-precision number from the stream; supported wire-types: Fixed32, Fixed64 653 | /// 654 | public 655 | #if !FEAT_SAFE 656 | unsafe 657 | #endif 658 | float ReadSingle() 659 | { 660 | switch (WireType) 661 | { 662 | case WireType.Fixed32: 663 | { 664 | int value = ReadInt32(); 665 | #if FEAT_SAFE 666 | return BitConverter.ToSingle(BitConverter.GetBytes(value), 0); 667 | #else 668 | return *(float*)&value; 669 | #endif 670 | } 671 | case WireType.Fixed64: 672 | { 673 | double value = ReadDouble(); 674 | float f = (float)value; 675 | if (float.IsInfinity(f) && !double.IsInfinity(value)) 676 | { 677 | throw AddErrorData(new OverflowException(), this); 678 | } 679 | return f; 680 | } 681 | default: 682 | throw CreateWireTypeException(); 683 | } 684 | } 685 | 686 | /// 687 | /// Reads a boolean value from the stream; supported wire-types: Variant, Fixed32, Fixed64 688 | /// 689 | /// 690 | public bool ReadBoolean() 691 | { 692 | return ReadUInt32() != 0; 693 | } 694 | 695 | private static readonly byte[] EmptyBlob = new byte[0]; 696 | /// 697 | /// Reads a byte-sequence from the stream, appending them to an existing byte-sequence (which can be null); supported wire-types: String 698 | /// 699 | public static byte[] AppendBytes(byte[] value, ProtoReader reader) 700 | { 701 | if (reader == null) throw new ArgumentNullException(nameof(reader)); 702 | switch (reader.WireType) 703 | { 704 | case WireType.String: 705 | int len = (int)reader.ReadUInt32Variant(false); 706 | reader.WireType = WireType.None; 707 | if (len == 0) return value ?? EmptyBlob; 708 | int offset; 709 | if (value == null || value.Length == 0) 710 | { 711 | offset = 0; 712 | value = new byte[len]; 713 | } 714 | else 715 | { 716 | offset = value.Length; 717 | byte[] tmp = new byte[value.Length + len]; 718 | Buffer.BlockCopy(value, 0, tmp, 0, value.Length); 719 | value = tmp; 720 | } 721 | // value is now sized with the final length, and (if necessary) 722 | // contains the old data up to "offset" 723 | reader.LongPosition += len; // assume success 724 | while (len > reader.available) 725 | { 726 | if (reader.available > 0) 727 | { 728 | // copy what we *do* have 729 | Buffer.BlockCopy(reader.ioBuffer, reader.ioIndex, value, offset, reader.available); 730 | len -= reader.available; 731 | offset += reader.available; 732 | reader.ioIndex = reader.available = 0; // we've drained the buffer 733 | } 734 | // now refill the buffer (without overflowing it) 735 | int count = len > reader.ioBuffer.Length ? reader.ioBuffer.Length : len; 736 | if (count > 0) reader.Ensure(count, true); 737 | } 738 | // at this point, we know that len <= available 739 | if (len > 0) 740 | { // still need data, but we have enough buffered 741 | Buffer.BlockCopy(reader.ioBuffer, reader.ioIndex, value, offset, len); 742 | reader.ioIndex += len; 743 | reader.available -= len; 744 | } 745 | return value; 746 | case WireType.Variant: 747 | return new byte[0]; 748 | default: 749 | throw reader.CreateWireTypeException(); 750 | } 751 | } 752 | 753 | //static byte[] ReadBytes(Stream stream, int length) 754 | //{ 755 | // if (stream == null) throw new ArgumentNullException("stream"); 756 | // if (length < 0) throw new ArgumentOutOfRangeException("length"); 757 | // byte[] buffer = new byte[length]; 758 | // int offset = 0, read; 759 | // while (length > 0 && (read = stream.Read(buffer, offset, length)) > 0) 760 | // { 761 | // length -= read; 762 | // } 763 | // if (length > 0) throw EoF(null); 764 | // return buffer; 765 | //} 766 | private static int ReadByteOrThrow(Stream source) 767 | { 768 | int val = source.ReadByte(); 769 | if (val < 0) throw EoF(null); 770 | return val; 771 | } 772 | 773 | /// 774 | /// Reads a little-endian encoded integer. An exception is thrown if the data is not all available. 775 | /// 776 | public static int DirectReadLittleEndianInt32(Stream source) 777 | { 778 | return ReadByteOrThrow(source) 779 | | (ReadByteOrThrow(source) << 8) 780 | | (ReadByteOrThrow(source) << 16) 781 | | (ReadByteOrThrow(source) << 24); 782 | } 783 | 784 | /// 785 | /// Reads a big-endian encoded integer. An exception is thrown if the data is not all available. 786 | /// 787 | public static int DirectReadBigEndianInt32(Stream source) 788 | { 789 | return (ReadByteOrThrow(source) << 24) 790 | | (ReadByteOrThrow(source) << 16) 791 | | (ReadByteOrThrow(source) << 8) 792 | | ReadByteOrThrow(source); 793 | } 794 | 795 | /// 796 | /// Reads a varint encoded integer. An exception is thrown if the data is not all available. 797 | /// 798 | public static int DirectReadVarintInt32(Stream source) 799 | { 800 | int bytes = TryReadUInt64Variant(source, out ulong val); 801 | if (bytes <= 0) throw EoF(null); 802 | return checked((int)val); 803 | } 804 | 805 | /// 806 | /// Reads a string (of a given lenth, in bytes) directly from the source into a pre-existing buffer. An exception is thrown if the data is not all available. 807 | /// 808 | public static void DirectReadBytes(Stream source, byte[] buffer, int offset, int count) 809 | { 810 | int read; 811 | if (source == null) throw new ArgumentNullException("source"); 812 | while (count > 0 && (read = source.Read(buffer, offset, count)) > 0) 813 | { 814 | count -= read; 815 | offset += read; 816 | } 817 | if (count > 0) throw EoF(null); 818 | } 819 | 820 | /// 821 | /// Reads a given number of bytes directly from the source. An exception is thrown if the data is not all available. 822 | /// 823 | public static byte[] DirectReadBytes(Stream source, int count) 824 | { 825 | byte[] buffer = new byte[count]; 826 | DirectReadBytes(source, buffer, 0, count); 827 | return buffer; 828 | } 829 | 830 | /// 831 | /// Reads a string (of a given lenth, in bytes) directly from the source. An exception is thrown if the data is not all available. 832 | /// 833 | public static string DirectReadString(Stream source, int length) 834 | { 835 | byte[] buffer = new byte[length]; 836 | DirectReadBytes(source, buffer, 0, length); 837 | return Encoding.UTF8.GetString(buffer, 0, length); 838 | } 839 | 840 | 841 | /// The number of bytes consumed; 0 if no data available 842 | private static int TryReadUInt64Variant(Stream source, out ulong value) 843 | { 844 | value = 0; 845 | int b = source.ReadByte(); 846 | if (b < 0) { return 0; } 847 | value = (uint)b; 848 | if ((value & 0x80) == 0) { return 1; } 849 | value &= 0x7F; 850 | int bytesRead = 1, shift = 7; 851 | while (bytesRead < 9) 852 | { 853 | b = source.ReadByte(); 854 | if (b < 0) throw EoF(null); 855 | value |= ((ulong)b & 0x7F) << shift; 856 | shift += 7; 857 | bytesRead++; 858 | 859 | if ((b & 0x80) == 0) return bytesRead; 860 | } 861 | b = source.ReadByte(); 862 | if (b < 0) throw EoF(null); 863 | if ((b & 1) == 0) // only use 1 bit from the last byte 864 | { 865 | value |= ((ulong)b & 0x7F) << shift; 866 | return ++bytesRead; 867 | } 868 | throw new OverflowException(); 869 | } 870 | 871 | internal static void Seek(Stream source, long count, byte[] buffer) 872 | { 873 | if (source.CanSeek) 874 | { 875 | source.Seek(count, SeekOrigin.Current); 876 | count = 0; 877 | } 878 | else if (buffer != null) 879 | { 880 | int bytesRead; 881 | while (count > buffer.Length && (bytesRead = source.Read(buffer, 0, buffer.Length)) > 0) 882 | { 883 | count -= bytesRead; 884 | } 885 | while (count > 0 && (bytesRead = source.Read(buffer, 0, (int)count)) > 0) 886 | { 887 | count -= bytesRead; 888 | } 889 | } 890 | else // borrow a buffer 891 | { 892 | throw new Exception(); 893 | } 894 | if (count > 0) throw EoF(null); 895 | } 896 | internal static Exception AddErrorData(Exception exception, ProtoReader source) 897 | { 898 | #if !CF && !PORTABLE 899 | if (exception != null && source != null && !exception.Data.Contains("protoSource")) 900 | { 901 | exception.Data.Add("protoSource", string.Format("tag={0}; wire-type={1}; offset={2}; depth={3}", 902 | source.FieldNumber, source.WireType, source.LongPosition, source.depth)); 903 | } 904 | #endif 905 | return exception; 906 | } 907 | 908 | private static Exception EoF(ProtoReader source) 909 | { 910 | return AddErrorData(new EndOfStreamException(), source); 911 | } 912 | 913 | 914 | 915 | 916 | 917 | /// 918 | /// Indicates whether the reader still has data remaining in the current sub-item, 919 | /// additionally setting the wire-type for the next field if there is more data. 920 | /// This is used when decoding packed data. 921 | /// 922 | public static bool HasSubValue(WireType wireType, ProtoReader source) 923 | { 924 | if (source == null) throw new ArgumentNullException("source"); 925 | // check for virtual end of stream 926 | if (source.blockEnd64 <= source.LongPosition || wireType == WireType.EndGroup) { return false; } 927 | source.WireType = wireType; 928 | return true; 929 | } 930 | 931 | public ProtoReader(Stream source, long length) 932 | { 933 | Init(this, source, length); 934 | } 935 | 936 | #region RECYCLER 937 | 938 | internal static ProtoReader Create(Stream source, int len) 939 | => Create(source, (long)len); 940 | /// 941 | /// Creates a new reader against a stream 942 | /// 943 | /// The source stream 944 | /// The model to use for serialization; this can be null, but this will impair the ability to deserialize sub-objects 945 | /// Additional context about this serialization operation 946 | /// The number of bytes to read, or -1 to read until the end of the stream 947 | public static ProtoReader Create(Stream source, long length = TO_EOF) 948 | { 949 | ProtoReader reader = GetRecycled(); 950 | if (reader == null) 951 | { 952 | return new ProtoReader(source, length); 953 | } 954 | Init(reader, source, length); 955 | return reader; 956 | } 957 | 958 | [ThreadStatic] 959 | private static ProtoReader lastReader; 960 | 961 | private static ProtoReader GetRecycled() 962 | { 963 | ProtoReader tmp = lastReader; 964 | lastReader = null; 965 | return tmp; 966 | } 967 | 968 | 969 | #endregion 970 | } 971 | } 972 | -------------------------------------------------------------------------------- /NetPackageTool/protoReader/WireType.cs: -------------------------------------------------------------------------------- 1 | namespace ProtoBuf 2 | { 3 | /// 4 | /// Indicates the encoding used to represent an individual value in a protobuf stream 5 | /// 6 | public enum WireType 7 | { 8 | /// 9 | /// Represents an error condition 10 | /// 11 | None = -1, 12 | 13 | /// 14 | /// Base-128 variant-length encoding 15 | /// 16 | Variant = 0, 17 | 18 | /// 19 | /// Fixed-length 8-byte encoding 20 | /// 21 | Fixed64 = 1, 22 | 23 | /// 24 | /// Length-variant-prefixed encoding 25 | /// 26 | String = 2, 27 | 28 | /// 29 | /// Indicates the start of a group 30 | /// 31 | StartGroup = 3, 32 | 33 | /// 34 | /// Indicates the end of a group 35 | /// 36 | EndGroup = 4, 37 | 38 | /// 39 | /// Fixed-length 4-byte encoding 40 | /// 10 41 | Fixed32 = 5, 42 | 43 | /// 44 | /// This is not a formal wire-type in the "protocol buffers" spec, but 45 | /// denotes a variant integer that should be interpreted using 46 | /// zig-zag semantics (so -ve numbers aren't a significant overhead) 47 | /// 48 | SignedVariant = WireType.Variant | (1 << 3), 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bh3tool 2 | 3 | 用于从网络修改崩坏三的一些工具。 4 | 5 | [游戏3.4]虽然不知道还能不能用,总之更新一下。游戏用了改过Opcode顺序的luac编译了lua脚本,但是依然支持字符串格式的lua,所以用UnluacNET反编译了一下,然后把lua的后缀.bytes改为.txt就可以了。 6 | 7 | ### EnableTouchServer .Net Core 8 | .Net Core平台的代理服务端,可以拦截http并修改开启触摸,引用了FiddlerCore拦截http和我自己的UnityAssetBundleTool.dll修改AssetBundle。 9 | 10 | ### FileDecryptTool 11 | 单独的加解密的工具。包括AES和异或加解密,用于DataVersion.unity3d、Excel_output.unity3d和Setting.unity3d的加解密。 12 | 13 | ### NetPackageTool 14 | 用于分析NetPacketV1的内容,可以从[il2cppdumper](https://github.com/Perfare/Il2CppDumper)生成的dump.cs提取出cmd_id与类的对应关系,可以从WireShark导出的文件(tcp流导出的HexDump格式)提取出protobuf序列化后的数据并转换为json格式。 15 | 16 | 17 | 18 | 19 | ###### ***UnityAssetBundleTool.dll是基于[AssetStudio](https://github.com/Perfare/AssetStudio)部分代码写的AssetBundle编辑工具,性能差但是勉强能用。*** 20 | -------------------------------------------------------------------------------- /bh3toolR.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EnableTouchServer(.Net Core)", "EnableTouchServer .Net Core\EnableTouchServer(.Net Core).csproj", "{6ABD12EF-B052-49A9-85D0-636868EB457D}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileDecryptTool", "FileDecryptTool\FileDecryptTool.csproj", "{00CE9685-6F08-4275-825A-435EFC3774A1}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetPackageTool", "NetPackageTool\NetPackageTool.csproj", "{23AF6847-0E1E-401B-AA52-BB06A8AF80D0}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {6ABD12EF-B052-49A9-85D0-636868EB457D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {6ABD12EF-B052-49A9-85D0-636868EB457D}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {6ABD12EF-B052-49A9-85D0-636868EB457D}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {6ABD12EF-B052-49A9-85D0-636868EB457D}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {00CE9685-6F08-4275-825A-435EFC3774A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {00CE9685-6F08-4275-825A-435EFC3774A1}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {00CE9685-6F08-4275-825A-435EFC3774A1}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {00CE9685-6F08-4275-825A-435EFC3774A1}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {23AF6847-0E1E-401B-AA52-BB06A8AF80D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {23AF6847-0E1E-401B-AA52-BB06A8AF80D0}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {23AF6847-0E1E-401B-AA52-BB06A8AF80D0}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {23AF6847-0E1E-401B-AA52-BB06A8AF80D0}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {3A74E5C8-F54A-4600-887C-14BA41A83919} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /lib/UnityAssetBundleTool.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wzy96/bh3tool/9ea2a16b81a4b3173db1169d99dd34b2736fa241/lib/UnityAssetBundleTool.dll --------------------------------------------------------------------------------