Files
2026-06-04 11:42:34 +02:00

243 lines
7.4 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine.Internal;
namespace UnityEngine
{
// Token: 0x0200028F RID: 655
public class WWWForm
{
// Token: 0x06002CEE RID: 11502 RVA: 0x0003EEC4 File Offset: 0x0003D0C4
public WWWForm()
{
this.formData = new List<byte[]>();
this.fieldNames = new List<string>();
this.fileNames = new List<string>();
this.types = new List<string>();
this.boundary = new byte[40];
for (int i = 0; i < 40; i++)
{
int num = Random.Range(48, 110);
if (num > 57)
{
num += 7;
}
if (num > 90)
{
num += 6;
}
this.boundary[i] = (byte)num;
}
}
// Token: 0x17000A3B RID: 2619
// (get) Token: 0x06002CEF RID: 11503 RVA: 0x0003EF5C File Offset: 0x0003D15C
internal static Encoding DefaultEncoding
{
get
{
return Encoding.ASCII;
}
}
// Token: 0x06002CF0 RID: 11504 RVA: 0x0003EF78 File Offset: 0x0003D178
public void AddField(string fieldName, string value)
{
this.AddField(fieldName, value, Encoding.UTF8);
}
// Token: 0x06002CF1 RID: 11505 RVA: 0x0003EF88 File Offset: 0x0003D188
public void AddField(string fieldName, string value, Encoding e)
{
this.fieldNames.Add(fieldName);
this.fileNames.Add(null);
this.formData.Add(e.GetBytes(value));
this.types.Add("text/plain; charset=\"" + e.WebName + "\"");
}
// Token: 0x06002CF2 RID: 11506 RVA: 0x0003EFE0 File Offset: 0x0003D1E0
public void AddField(string fieldName, int i)
{
this.AddField(fieldName, i.ToString());
}
// Token: 0x06002CF3 RID: 11507 RVA: 0x0003EFF8 File Offset: 0x0003D1F8
[ExcludeFromDocs]
public void AddBinaryData(string fieldName, byte[] contents)
{
this.AddBinaryData(fieldName, contents, null, null);
}
// Token: 0x06002CF4 RID: 11508 RVA: 0x0003F008 File Offset: 0x0003D208
[ExcludeFromDocs]
public void AddBinaryData(string fieldName, byte[] contents, string fileName)
{
this.AddBinaryData(fieldName, contents, fileName, null);
}
// Token: 0x06002CF5 RID: 11509 RVA: 0x0003F018 File Offset: 0x0003D218
public void AddBinaryData(string fieldName, byte[] contents, [DefaultValue("null")] string fileName, [DefaultValue("null")] string mimeType)
{
this.containsFiles = true;
bool flag = contents.Length > 8 && contents[0] == 137 && contents[1] == 80 && contents[2] == 78 && contents[3] == 71 && contents[4] == 13 && contents[5] == 10 && contents[6] == 26 && contents[7] == 10;
if (fileName == null)
{
fileName = fieldName + ((!flag) ? ".dat" : ".png");
}
if (mimeType == null)
{
if (flag)
{
mimeType = "image/png";
}
else
{
mimeType = "application/octet-stream";
}
}
this.fieldNames.Add(fieldName);
this.fileNames.Add(fileName);
this.formData.Add(contents);
this.types.Add(mimeType);
}
// Token: 0x17000A3C RID: 2620
// (get) Token: 0x06002CF6 RID: 11510 RVA: 0x0003F104 File Offset: 0x0003D304
public Dictionary<string, string> headers
{
get
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
if (this.containsFiles)
{
dictionary["Content-Type"] = "multipart/form-data; boundary=\"" + Encoding.UTF8.GetString(this.boundary, 0, this.boundary.Length) + "\"";
}
else
{
dictionary["Content-Type"] = "application/x-www-form-urlencoded";
}
return dictionary;
}
}
// Token: 0x17000A3D RID: 2621
// (get) Token: 0x06002CF7 RID: 11511 RVA: 0x0003F174 File Offset: 0x0003D374
public byte[] data
{
get
{
if (this.containsFiles)
{
byte[] bytes = WWWForm.DefaultEncoding.GetBytes("--");
byte[] bytes2 = WWWForm.DefaultEncoding.GetBytes("\r\n");
byte[] bytes3 = WWWForm.DefaultEncoding.GetBytes("Content-Type: ");
byte[] bytes4 = WWWForm.DefaultEncoding.GetBytes("Content-disposition: form-data; name=\"");
byte[] bytes5 = WWWForm.DefaultEncoding.GetBytes("\"");
byte[] bytes6 = WWWForm.DefaultEncoding.GetBytes("; filename=\"");
using (MemoryStream memoryStream = new MemoryStream(1024))
{
for (int i = 0; i < this.formData.Count; i++)
{
memoryStream.Write(bytes2, 0, bytes2.Length);
memoryStream.Write(bytes, 0, bytes.Length);
memoryStream.Write(this.boundary, 0, this.boundary.Length);
memoryStream.Write(bytes2, 0, bytes2.Length);
memoryStream.Write(bytes3, 0, bytes3.Length);
byte[] bytes7 = Encoding.UTF8.GetBytes(this.types[i]);
memoryStream.Write(bytes7, 0, bytes7.Length);
memoryStream.Write(bytes2, 0, bytes2.Length);
memoryStream.Write(bytes4, 0, bytes4.Length);
string headerName = Encoding.UTF8.HeaderName;
string text = this.fieldNames[i];
if (!WWWTranscoder.SevenBitClean(text, Encoding.UTF8) || text.IndexOf("=?") > -1)
{
text = string.Concat(new string[]
{
"=?",
headerName,
"?Q?",
WWWTranscoder.QPEncode(text, Encoding.UTF8),
"?="
});
}
byte[] bytes8 = Encoding.UTF8.GetBytes(text);
memoryStream.Write(bytes8, 0, bytes8.Length);
memoryStream.Write(bytes5, 0, bytes5.Length);
if (this.fileNames[i] != null)
{
string text2 = this.fileNames[i];
if (!WWWTranscoder.SevenBitClean(text2, Encoding.UTF8) || text2.IndexOf("=?") > -1)
{
text2 = string.Concat(new string[]
{
"=?",
headerName,
"?Q?",
WWWTranscoder.QPEncode(text2, Encoding.UTF8),
"?="
});
}
byte[] bytes9 = Encoding.UTF8.GetBytes(text2);
memoryStream.Write(bytes6, 0, bytes6.Length);
memoryStream.Write(bytes9, 0, bytes9.Length);
memoryStream.Write(bytes5, 0, bytes5.Length);
}
memoryStream.Write(bytes2, 0, bytes2.Length);
memoryStream.Write(bytes2, 0, bytes2.Length);
byte[] array = this.formData[i];
memoryStream.Write(array, 0, array.Length);
}
memoryStream.Write(bytes2, 0, bytes2.Length);
memoryStream.Write(bytes, 0, bytes.Length);
memoryStream.Write(this.boundary, 0, this.boundary.Length);
memoryStream.Write(bytes, 0, bytes.Length);
memoryStream.Write(bytes2, 0, bytes2.Length);
return memoryStream.ToArray();
}
}
byte[] bytes10 = WWWForm.DefaultEncoding.GetBytes("&");
byte[] bytes11 = WWWForm.DefaultEncoding.GetBytes("=");
byte[] array5;
using (MemoryStream memoryStream2 = new MemoryStream(1024))
{
for (int j = 0; j < this.formData.Count; j++)
{
byte[] array2 = WWWTranscoder.URLEncode(Encoding.UTF8.GetBytes(this.fieldNames[j]));
byte[] array3 = this.formData[j];
byte[] array4 = WWWTranscoder.URLEncode(array3);
if (j > 0)
{
memoryStream2.Write(bytes10, 0, bytes10.Length);
}
memoryStream2.Write(array2, 0, array2.Length);
memoryStream2.Write(bytes11, 0, bytes11.Length);
memoryStream2.Write(array4, 0, array4.Length);
}
array5 = memoryStream2.ToArray();
}
return array5;
}
}
// Token: 0x04000893 RID: 2195
private List<byte[]> formData;
// Token: 0x04000894 RID: 2196
private List<string> fieldNames;
// Token: 0x04000895 RID: 2197
private List<string> fileNames;
// Token: 0x04000896 RID: 2198
private List<string> types;
// Token: 0x04000897 RID: 2199
private byte[] boundary;
// Token: 0x04000898 RID: 2200
private bool containsFiles = false;
}
}