整理代码

This commit is contained in:
Perfare 2019-12-04 05:48:47 +08:00
parent a357705e15
commit 1b2fe8eb09
7 changed files with 80 additions and 119 deletions

View file

@ -5,7 +5,7 @@ namespace Il2CppDumper
{
static class BoyerMooreHorspool
{
public static IEnumerable<int> IndicesOf(this byte[] source, byte[] pattern)
public static IEnumerable<int> Search(this byte[] source, byte[] pattern)
{
if (source == null)
{

View file

@ -165,6 +165,10 @@ namespace Il2CppDumper
public ulong[] ReadPointers(ulong addr, long count)
{
if (addr == 0 || count == 0)
{
return new ulong[0];
}
if (is32Bit)
{
return Array.ConvertAll(MapVATR<uint>(addr, count), x => (ulong)x);

View file

@ -211,7 +211,7 @@ namespace Il2CppDumper
}
if (val is string str)
{
writer.Write($" = \"{ToEscapedString(str)}\"");
writer.Write($" = \"{str.ToEscapedString()}\"");
}
else if (val is char c)
{
@ -327,7 +327,7 @@ namespace Il2CppDumper
var value = GetDefaultValue(parameterDefault.typeIndex, parameterDefault.dataIndex);
if (value is string str)
{
parameterStr += $" = \"{ToEscapedString(str)}\"";
parameterStr += $" = \"{str.ToEscapedString()}\"";
}
else if (value is char c)
{
@ -376,7 +376,7 @@ namespace Il2CppDumper
writer.Close();
}
public string GetTypeName(Il2CppType type, bool fullName = false)
public string GetTypeName(Il2CppType type)
{
string ret;
switch (type.type)
@ -385,16 +385,7 @@ namespace Il2CppDumper
case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE:
{
var typeDef = metadata.typeDefs[type.data.klassIndex];
ret = string.Empty;
if (fullName)
{
ret = metadata.GetStringFromIndex(typeDef.namespaceIndex);
if (ret != string.Empty)
{
ret += ".";
}
}
ret += GetTypeName(typeDef);
ret = GetTypeName(typeDef);
break;
}
case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
@ -568,56 +559,5 @@ namespace Il2CppDumper
throw new ArgumentOutOfRangeException();
}
}
public string ToEscapedString(string s)
{
var re = new StringBuilder(s.Length);
foreach (var c in s)
{
switch (c)
{
case '\'':
re.Append(@"\'");
break;
case '"':
re.Append(@"\""");
break;
case '\t':
re.Append(@"\t");
break;
case '\n':
re.Append(@"\n");
break;
case '\r':
re.Append(@"\r");
break;
case '\f':
re.Append(@"\f");
break;
case '\b':
re.Append(@"\b");
break;
case '\\':
re.Append(@"\\");
break;
case '\0':
re.Append(@"\0");
break;
case '\u0085':
re.Append(@"\u0085");
break;
case '\u2028':
re.Append(@"\u2028");
break;
case '\u2029':
re.Append(@"\u2029");
break;
default:
re.Append(c);
break;
}
}
return re.ToString();
}
}
}

View file

@ -56,6 +56,7 @@
<Compile Include="NSOClass.cs" />
<Compile Include="ScriptGenerator.cs" />
<Compile Include="SearchSection.cs" />
<Compile Include="StringExtensions.cs" />
<Compile Include="VersionAttribute.cs" />
<Compile Include="Config.cs" />
<Compile Include="DummyAssemblyGenerator.cs" />

View file

@ -350,7 +350,7 @@ namespace Il2CppDumper
{
il2Cpp.Position = sec.offset;
var buff = il2Cpp.ReadBytes((int)(sec.offsetEnd - sec.offset));
foreach (var index in buff.IndicesOf(featureBytes2019))
foreach (var index in buff.Search(featureBytes2019))
{
var va = (ulong)index + sec.address;
foreach (var dataSec in data)
@ -404,7 +404,7 @@ namespace Il2CppDumper
{
il2Cpp.Position = sec.offset;
var buff = il2Cpp.ReadBytes((int)(sec.offsetEnd - sec.offset));
foreach (var index in buff.IndicesOf(featureBytes2019))
foreach (var index in buff.Search(featureBytes2019))
{
var va = (ulong)index + sec.address;
foreach (var dataSec in data)

View file

@ -125,7 +125,7 @@ namespace Il2CppDumper
File.WriteAllText("stringliteral.json", JsonConvert.SerializeObject(stringLiterals, Formatting.Indented), new UTF8Encoding(false)); //TODO
foreach (var stringLiteral in stringLiterals)
{
writer.WriteLine($"SetString({stringLiteral.address}, r'{ToEscapedString(stringLiteral.value)}')");
writer.WriteLine($"SetString({stringLiteral.address}, r'{stringLiteral.value.ToEscapedString()}')");
}
foreach (var i in metadata.metadataUsageDic[6]) //kIl2CppMetadataUsageMethodRef
{
@ -268,56 +268,5 @@ namespace Il2CppDumper
}
return $"<{string.Join(", ", typeNames)}>";
}
public string ToEscapedString(string s)
{
var re = new StringBuilder(s.Length);
foreach (var c in s)
{
switch (c)
{
case '\'':
re.Append(@"\'");
break;
case '"':
re.Append(@"\""");
break;
case '\t':
re.Append(@"\t");
break;
case '\n':
re.Append(@"\n");
break;
case '\r':
re.Append(@"\r");
break;
case '\f':
re.Append(@"\f");
break;
case '\b':
re.Append(@"\b");
break;
case '\\':
re.Append(@"\\");
break;
case '\0':
re.Append(@"\0");
break;
case '\u0085':
re.Append(@"\u0085");
break;
case '\u2028':
re.Append(@"\u2028");
break;
case '\u2029':
re.Append(@"\u2029");
break;
default:
re.Append(c);
break;
}
}
return re.ToString();
}
}
}

View file

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Il2CppDumper
{
public static class StringExtensions
{
public static string ToEscapedString(this string s)
{
var re = new StringBuilder(s.Length);
foreach (var c in s)
{
switch (c)
{
case '\'':
re.Append(@"\'");
break;
case '"':
re.Append(@"\""");
break;
case '\\':
re.Append(@"\\");
break;
case '\0':
re.Append(@"\0");
break;
case '\a':
re.Append(@"\a");
break;
case '\b':
re.Append(@"\b");
break;
case '\f':
re.Append(@"\f");
break;
case '\n':
re.Append(@"\n");
break;
case '\r':
re.Append(@"\r");
break;
case '\t':
re.Append(@"\t");
break;
case '\v':
re.Append(@"\v");
break;
case '\u0085':
re.Append(@"\u0085");
break;
case '\u2028':
re.Append(@"\u2028");
break;
case '\u2029':
re.Append(@"\u2029");
break;
default:
re.Append(c);
break;
}
}
return re.ToString();
}
}
}