Here are the examples of the csharp api System.Array.CopyTo(System.Array, int) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1533 Examples
19
View Source File : HeifIccColorProfile.cs
License : GNU Lesser General Public License v3.0
Project Creator : 0xC0000054
License : GNU Lesser General Public License v3.0
Project Creator : 0xC0000054
public byte[] GetIccProfileBytes()
{
byte[] clone = new byte[this.iccProfileBytes.Length];
this.iccProfileBytes.CopyTo(clone, 0);
return clone;
}
19
View Source File : Inline_Hook.cs
License : Apache License 2.0
Project Creator : 1694439208
License : Apache License 2.0
Project Creator : 1694439208
public static byte[] Add(byte[] byteABytes,byte[] bytes)
{
byte[] bytes_ = new byte[byteABytes.Length + bytes.Length];
byteABytes.CopyTo(bytes_, 0);
bytes.CopyTo(bytes_, byteABytes.Length);
return bytes_;
}
19
View Source File : Globals.cs
License : MIT License
Project Creator : 1ZouLTReX1
License : MIT License
Project Creator : 1ZouLTReX1
public static byte[] SerializeLenPrefix(byte[] data)
{
// Get the length prefix for the message
byte[] lengthPrefix = BitConverter.GetBytes(data.Length);
// Concatenate the length prefix and the message
byte[] ret = new byte[lengthPrefix.Length + data.Length];
lengthPrefix.CopyTo(ret, 0);
data.CopyTo(ret, lengthPrefix.Length);
return ret;
}
19
View Source File : ArrayDecorator.cs
License : MIT License
Project Creator : 404Lcc
License : MIT License
Project Creator : 404Lcc
public override object Read(object value, ProtoReader source)
{
int field = source.FieldNumber;
BasicList list = new BasicList();
if (packedWireType != WireType.None && source.WireType == WireType.String)
{
SubItemToken token = ProtoReader.StartSubItem(source);
while (ProtoReader.HreplacedubValue(packedWireType, source))
{
list.Add(Tail.Read(null, source));
}
ProtoReader.EndSubItem(token, source);
}
else
{
do
{
list.Add(Tail.Read(null, source));
} while (source.TryReadFieldHeader(field));
}
int oldLen = AppendToCollection ? ((value == null ? 0 : ((Array)value).Length)) : 0;
Array result = Array.CreateInstance(itemType, oldLen + list.Count);
if (oldLen != 0) ((Array)value).CopyTo(result, 0);
list.CopyTo(result, oldLen);
return result;
}
19
View Source File : Helpers.cs
License : MIT License
Project Creator : 404Lcc
License : MIT License
Project Creator : 404Lcc
internal static MemberInfo[] GetInstanceFieldsAndProperties(Type type, bool publicOnly)
{
#if WINRT || PROFILE259
System.Collections.Generic.List<MemberInfo> members = new System.Collections.Generic.List<MemberInfo>();
foreach(FieldInfo field in type.GetRuntimeFields())
{
if(field.IsStatic) continue;
if(field.IsPublic || !publicOnly) members.Add(field);
}
foreach(PropertyInfo prop in type.GetRuntimeProperties())
{
MethodInfo getter = Helpers.GetGetMethod(prop, true, true);
if(getter == null || getter.IsStatic) continue;
if(getter.IsPublic || !publicOnly) members.Add(prop);
}
return members.ToArray();
#else
BindingFlags flags = publicOnly ? BindingFlags.Public | BindingFlags.Instance : BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic;
PropertyInfo[] props = type.GetProperties(flags);
FieldInfo[] fields = type.GetFields(flags);
MemberInfo[] members = new MemberInfo[fields.Length + props.Length];
props.CopyTo(members, 0);
fields.CopyTo(members, props.Length);
return members;
#endif
}
19
View Source File : TeaCrypter.cs
License : MIT License
Project Creator : 499116344
License : MIT License
Project Creator : 499116344
private void Encrypt8Bytes()
{
for (_pos = 0L; _pos < 8; _pos++)
{
if (_header)
{
_plain[_pos] = (byte) (_plain[_pos] ^ _prePlain[_pos]);
}
else
{
_plain[_pos] = (byte) (_plain[_pos] ^ _out[_preCrypt + _pos]);
}
}
var array = Encipher(_plain, _key);
for (var i = 0; i <= 7; i++)
{
_out[_crypt + i] = array[i];
}
for (_pos = 0L; _pos <= 7; _pos++)
{
_out[_crypt + _pos] = (byte) (_out[_crypt + _pos] ^ _prePlain[_pos]);
}
_plain.CopyTo(_prePlain, 0);
_preCrypt = _crypt;
_crypt += 8L;
_pos = 0L;
_header = false;
}
19
View Source File : TeaCrypter.cs
License : MIT License
Project Creator : 499116344
License : MIT License
Project Creator : 499116344
public byte[] Decrypt(byte[] arrayIn, byte[] arrayKey, long offset)
{
var result = new byte[0];
if (arrayIn.Length < 16 || arrayIn.Length % 8 != 0)
{
return result;
}
var array = new byte[offset + 8];
arrayKey.CopyTo(_key, 0);
_crypt = _preCrypt = 0L;
_prePlain = Decipher(arrayIn, arrayKey, offset);
_pos = _prePlain[0] & 7;
var num = arrayIn.Length - _pos - 10;
if (num <= 0)
{
return result;
}
_out = new byte[num];
_preCrypt = 0L;
_crypt = 8L;
_contextStart = 8L;
_pos++;
_padding = 1L;
while (_padding < 3)
{
if (_pos < 8)
{
_pos++;
_padding++;
}
else if (_pos == 8)
{
for (var i = 0; i < array.Length; i++)
{
array[i] = arrayIn[i];
}
if (!Decrypt8Bytes(arrayIn, offset))
{
return result;
}
}
}
var num2 = 0L;
while (num != 0)
{
if (_pos < 8)
{
_out[num2] = (byte) (array[offset + _preCrypt + _pos] ^ _prePlain[_pos]);
num2++;
num--;
_pos++;
}
else if (_pos == 8)
{
array = arrayIn;
_preCrypt = _crypt - 8;
if (!Decrypt8Bytes(arrayIn, offset))
{
return result;
}
}
}
for (_padding = 1L; _padding <= 7; _padding++)
{
if (_pos < 8)
{
if ((array[offset + _preCrypt + _pos] ^ _prePlain[_pos]) != 0)
{
return result;
}
_pos++;
}
else if (_pos == 8)
{
for (var i = 0; i < array.Length; i++)
{
array[i] = arrayIn[i];
}
_preCrypt = _crypt;
if (!Decrypt8Bytes(arrayIn, offset))
{
return result;
}
}
}
return _out;
}
19
View Source File : XXTeaCrypter.cs
License : MIT License
Project Creator : 499116344
License : MIT License
Project Creator : 499116344
public static uint[] Decrypt(uint[] v, uint[] k)
{
var num = v.Length - 1;
if (num < 1)
{
return v;
}
if (k.Length < 4)
{
var array = new uint[4];
k.CopyTo(array, 0);
k = array;
}
var num9 = v[num];
var num2 = v[0];
var num3 = 2654435769u;
var num4 = 6 + 52 / (num + 1);
for (var num5 = (uint) (num4 * num3); num5 != 0; num5 -= num3)
{
var num6 = (num5 >> 2) & 3;
int num7;
uint num8;
for (num7 = num; num7 > 0; num7--)
{
num8 = v[num7 - 1];
num2 = v[num7] -= (((num8 >> 5) ^ (num2 << 2)) + ((num2 >> 3) ^ (num8 << 4))) ^
((num5 ^ num2) + (k[(num7 & 3) ^ num6] ^ num8));
}
num8 = v[num];
num2 = v[0] -= (((num8 >> 5) ^ (num2 << 2)) + ((num2 >> 3) ^ (num8 << 4))) ^
((num5 ^ num2) + (k[(num7 & 3) ^ num6] ^ num8));
}
return v;
}
19
View Source File : XXTeaCrypter.cs
License : MIT License
Project Creator : 499116344
License : MIT License
Project Creator : 499116344
public static uint[] Encrypt(uint[] v, uint[] k)
{
var num = v.Length - 1;
if (num < 1)
{
return v;
}
if (k.Length < 4)
{
var array = new uint[4];
k.CopyTo(array, 0);
k = array;
}
var num2 = v[num];
var num9 = v[0];
var num3 = 2654435769u;
var num4 = 0u;
var num5 = 6 + 52 / (num + 1);
while (num5-- > 0)
{
num4 += num3;
var num7 = (num4 >> 2) & 3;
int i;
uint num8;
for (i = 0; i < num; i++)
{
num8 = v[i + 1];
num2 = v[i] += (((num2 >> 5) ^ (num8 << 2)) + ((num8 >> 3) ^ (num2 << 4))) ^
((num4 ^ num8) + (k[(i & 3) ^ num7] ^ num2));
}
num8 = v[0];
num2 = v[num] += (((num2 >> 5) ^ (num8 << 2)) + ((num8 >> 3) ^ (num2 << 4))) ^
((num4 ^ num8) + (k[(i & 3) ^ num7] ^ num2));
}
return v;
}
19
View Source File : LightList.cs
License : MIT License
Project Creator : 71
License : MIT License
Project Creator : 71
public void CopyTo(T[] array, int arrayIndex) => underlyingArray.CopyTo(array, arrayIndex);
19
View Source File : ExpressionVisitor`1.cs
License : MIT License
Project Creator : 71
License : MIT License
Project Creator : 71
private void EnsureCapacity(int capacity)
{
if (_scope.Length != capacity - 1)
return;
Expression[] tmp = new Expression[capacity];
_scope.CopyTo(tmp, 0);
_scope = tmp;
}
19
View Source File : Helpers.cs
License : MIT License
Project Creator : 71
License : MIT License
Project Creator : 71
public static byte[] GetJmpBytes(IntPtr destination)
{
switch (RuntimeInformation.ProcessArchitecture)
{
case Architecture.Arm:
{
// LDR PC, [PC, #-4]
// $addr
byte[] result = new byte[8];
result[0] = 0x04;
result[1] = 0xF0;
result[2] = 0x1F;
result[3] = 0xE5;
BitConverter.GetBytes(destination.ToInt32()).CopyTo(result, 4);
return result;
}
case Architecture.Arm64:
{
// LDR PC, [PC, #-4]
// $addr
byte[] result = new byte[12];
result[0] = 0x04;
result[1] = 0xF0;
result[2] = 0x1F;
result[3] = 0xE5;
BitConverter.GetBytes(destination.ToInt64()).CopyTo(result, 4);
return result;
}
case Architecture.X64:
{
// movabs rax,$addr
// jmp rax
byte[] result = new byte[12];
result[0] = 0x48;
result[1] = 0xB8;
result[10] = 0xFF;
result[11] = 0xE0;
BitConverter.GetBytes(destination.ToInt64()).CopyTo(result, 2);
return result;
}
case Architecture.X86:
{
// push $addr
// ret
byte[] result = new byte[6];
result[0] = 0x68;
result[5] = 0xC3;
BitConverter.GetBytes(destination.ToInt32()).CopyTo(result, 1);
return result;
}
default:
throw UnsupportedArchitecture;
}
}
19
View Source File : Ryder.Lightweight.cs
License : MIT License
Project Creator : 71
License : MIT License
Project Creator : 71
public static byte[] GetJmpBytes(IntPtr destination)
{
switch (RuntimeInformation.ProcessArchitecture)
{
case Architecture.Arm:
{
// LDR PC, [PC, #-4]
// $addr
byte[] result = new byte[8];
result[0] = 0x04;
result[1] = 0xF0;
result[2] = 0x1F;
result[3] = 0xE5;
BitConverter.GetBytes(destination.ToInt32()).CopyTo(result, 4);
return result;
}
case Architecture.Arm64:
{
// LDR PC, [PC, #-4]
// $addr
byte[] result = new byte[12];
result[0] = 0x04;
result[1] = 0xF0;
result[2] = 0x1F;
result[3] = 0xE5;
BitConverter.GetBytes(destination.ToInt64()).CopyTo(result, 4);
return result;
}
case Architecture.X64:
{
// movabs rax,$addr
// jmp rax
byte[] result = new byte[12];
result[0] = 0x48;
result[1] = 0xB8;
result[10] = 0xFF;
result[11] = 0xE0;
BitConverter.GetBytes(destination.ToInt64()).CopyTo(result, 2);
return result;
}
case Architecture.X86:
{
// push $addr
// ret
byte[] result = new byte[6];
result[0] = 0x68;
result[5] = 0xC3;
BitConverter.GetBytes(destination.ToInt32()).CopyTo(result, 1);
return result;
}
default:
throw UnsupportedArchitecture;
}
}
19
View Source File : ExternalCommunicator.cs
License : Apache License 2.0
Project Creator : A7ocin
License : Apache License 2.0
Project Creator : A7ocin
private byte[] AppendLength(byte[] input){
byte[] newArray = new byte[input.Length + 4];
input.CopyTo(newArray, 4);
System.BitConverter.GetBytes(input.Length).CopyTo(newArray, 0);
return newArray;
}
19
View Source File : RopeNode.cs
License : MIT License
Project Creator : Abdesol
License : MIT License
Project Creator : Abdesol
internal RopeNode<T> Clone()
{
if (height == 0) {
// If a function node needs cloning, we'll evaluate it.
if (contents == null)
return GetContentNode().Clone();
T[] newContents = new T[NodeSize];
contents.CopyTo(newContents, 0);
return new RopeNode<T> {
length = this.length,
contents = newContents
};
} else {
return new RopeNode<T> {
left = this.left,
right = this.right,
length = this.length,
height = this.height
};
}
}
19
View Source File : FastList.cs
License : MIT License
Project Creator : absurd-joy
License : MIT License
Project Creator : absurd-joy
void Allocate() {
T[] newArray;
if (array == null) {
newArray = new T[32];
}
else {
newArray = new T[Mathf.Max(array.Length << 1, 32)];
}
if (array != null && size > 0) {
array.CopyTo(newArray, 0);
}
array = newArray;
}
19
View Source File : OVRLipSync.cs
License : MIT License
Project Creator : absurd-joy
License : MIT License
Project Creator : absurd-joy
public void CopyInput(Frame input)
{
frameNumber = input.frameNumber;
frameDelay = input.frameDelay;
input.Visemes.CopyTo(Visemes, 0);
laughterScore = input.laughterScore;
}
19
View Source File : OVRNetwork.cs
License : MIT License
Project Creator : absurd-joy
License : MIT License
Project Creator : absurd-joy
public void Broadcast(int payloadType, byte[] payload)
{
if (payload.Length > OVRNetwork.MaxPayloadLength)
{
Debug.LogWarningFormat("[OVRNetworkTcpServer] drop payload because it's too long: {0} bytes", payload.Length);
}
FrameHeader header = new FrameHeader();
header.protocolIdentifier = FrameHeaderMagicIdentifier;
header.payloadType = payloadType;
header.payloadLength = payload.Length;
byte[] headerBuffer = header.ToBytes();
byte[] dataBuffer = new byte[headerBuffer.Length + payload.Length];
headerBuffer.CopyTo(dataBuffer, 0);
payload.CopyTo(dataBuffer, headerBuffer.Length);
lock (clientsLock)
{
foreach (TcpClient client in clients)
{
if (client.Connected)
{
try
{
client.GetStream().BeginWrite(dataBuffer, 0, dataBuffer.Length, new AsyncCallback(DoWriteDataCallback), client.GetStream());
}
catch (SocketException e)
{
Debug.LogWarningFormat("[OVRNetworkTcpServer] close client because of socket error: {0}", e.Message);
client.GetStream().Close();
client.Close();
}
}
}
}
}
19
View Source File : EnumerableExtraExtensions.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
private static T[] ConcatArray<T>(T extraElement, T[] source, bool insertAtStart)
{
if (source == null)
{
source = new T[0];
}
T[] result = new T[source.Length + 1];
source.CopyTo(result, insertAtStart ? 1 : 0);
result[insertAtStart ? 0 : source.Length] = extraElement;
return result;
}
19
View Source File : EnumerableExtraExtensions.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
private static T[] ConcatArrays<T>(T[] extraElements, T[] source, bool insertAtStart)
{
if (source == null)
{
source = new T[0];
}
T[] result = new T[source.Length + extraElements.Length];
source.CopyTo(result, insertAtStart ? extraElements.Length : 0);
extraElements.CopyTo(result, insertAtStart ? 0 : source.Length);
return result;
}
19
View Source File : ArrayExtensions.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public static T[] InsertAt<T>(this T[] array, int position, T[] items)
{
T[] newArray = new T[array.Length + items.Length];
if (position > 0)
{
Array.Copy(array, newArray, position);
}
if (position < array.Length)
{
Array.Copy(array, position, newArray, position + items.Length, array.Length - position);
}
items.CopyTo(newArray, position);
return newArray;
}
19
View Source File : Extensions.cs
License : MIT License
Project Creator : adrenak
License : MIT License
Project Creator : adrenak
public static T[] Concat<T>(this T[] arr1, T[] arr2) {
var result = new T[arr1.Length + arr2.Length];
arr1.CopyTo(result, 0);
arr2.CopyTo(result, arr1.Length);
return result;
}
19
View Source File : ModEntry.cs
License : GNU General Public License v3.0
Project Creator : aedenthorn
License : GNU General Public License v3.0
Project Creator : aedenthorn
private void LoadNames()
{
string filePath = $"{Helper.DirectoryPath}/replacedets/names_female_{Config.LocaleString}.txt";
if (File.Exists(filePath))
{
femaleNames = File.ReadAllLines(filePath);
Monitor.Log($"Female names found at {filePath}.", LogLevel.Debug);
}
else
{
Monitor.Log($"Female names file not found at {filePath}.", LogLevel.Warn);
femaleNames = new string[0];
}
filePath = $"{Helper.DirectoryPath}/replacedets/names_male_{Config.LocaleString}.txt";
if (File.Exists(filePath))
{
maleNames = File.ReadAllLines(filePath);
Monitor.Log($"Male names file found at {filePath}.", LogLevel.Debug);
}
else
{
Monitor.Log($"Male names file not found at {filePath}.", LogLevel.Warn);
maleNames = new string[0];
}
if(Config.NeutralNameGender == "female")
{
neuterNames = femaleNames;
}
else if(Config.NeutralNameGender == "male")
{
neuterNames = maleNames;
}
else
{
filePath = $"{Helper.DirectoryPath}/replacedets/names_{Config.LocaleString}.txt";
if (File.Exists(filePath))
{
neuterNames = File.ReadAllLines(filePath);
}
else
{
Monitor.Log($"Gender-neutral names file not found at {filePath}. Using combined male/female strings.", LogLevel.Debug);
neuterNames = new string[femaleNames.Length + maleNames.Length];
femaleNames.CopyTo(neuterNames, 0);
maleNames.CopyTo(neuterNames, femaleNames.Length);
}
}
}
19
View Source File : EventRPC.cs
License : GNU General Public License v3.0
Project Creator : aelariane
License : GNU General Public License v3.0
Project Creator : aelariane
public bool Handle()
{
PhotonView photonView = PhotonView.Find(viewID);
if (photonView == null)
{
return true;
}
if ((photonView.Group != 0) && !PhotonNetwork.networkingPeer.allowedReceivingGroups.Contains(photonView.Group))
{
return true;
}
System.Type[] callParameterTypes = new System.Type[0];
if (parameters.Length > 0)
{
callParameterTypes = new System.Type[parameters.Length];
int index = 0;
for (int i = 0; i < parameters.Length; i++)
{
object obj2 = parameters[i];
if (obj2 == null)
{
callParameterTypes[index] = null;
}
else
{
callParameterTypes[index] = obj2.GetType();
}
index++;
}
}
int num7 = 0;
int num8 = 0;
foreach (MonoBehaviour behaviour in photonView.GetComponents<MonoBehaviour>())
{
if (behaviour == null)
{
Debug.LogError("ERROR You have missing MonoBehaviours on your gameobjects!");
}
else
{
System.Type key = behaviour.GetType();
List<MethodInfo> list = null;
if (PhotonNetwork.networkingPeer.monoRPCMethodsCache.ContainsKey(key))
{
list = PhotonNetwork.networkingPeer.monoRPCMethodsCache[key];
}
if (list == null)
{
List<MethodInfo> methods = SupportClreplaced.GetMethods(key, typeof(UnityEngine.RPC));
PhotonNetwork.networkingPeer.monoRPCMethodsCache[key] = methods;
list = methods;
}
if (list != null)
{
for (int j = 0; j < list.Count; j++)
{
MethodInfo info = list[j];
if (info.Name == name)
{
num8++;
ParameterInfo[] methodParameters = info.GetParameters();
if (methodParameters.Length == callParameterTypes.Length)
{
if (PhotonNetwork.networkingPeer.CheckTypeMatch(methodParameters, callParameterTypes))
{
num7++;
object obj3 = info.Invoke(behaviour, parameters);
if (info.ReturnType == typeof(IEnumerator))
{
behaviour.StartCoroutine((IEnumerator)obj3);
}
}
return true;
}
else if ((methodParameters.Length - 1) == callParameterTypes.Length)
{
if (PhotonNetwork.networkingPeer.CheckTypeMatch(methodParameters, callParameterTypes) && (methodParameters[methodParameters.Length - 1].ParameterType == typeof(PhotonMessageInfo)))
{
num7++;
object[] array = new object[parameters.Length + 1];
parameters.CopyTo(array, 0);
array[array.Length - 1] = new PhotonMessageInfo(sender, sTime, photonView);
object obj4 = info.Invoke(behaviour, array);
if (info.ReturnType == typeof(IEnumerator))
{
behaviour.StartCoroutine((IEnumerator)obj4);
}
}
return true;
}
else if ((methodParameters.Length == 1) && methodParameters[0].ParameterType.IsArray)
{
num7++;
object[] objArray5 = new object[] { parameters };
object obj5 = info.Invoke(behaviour, objArray5);
if (info.ReturnType == typeof(IEnumerator))
{
behaviour.StartCoroutine((IEnumerator)obj5);
}
return true;
}
return false;
}
//Log.AddLineRaw("Unknown RPC: " + name + " by ID " + sender.ID);
}
}
}
}
return true;
}
19
View Source File : BetterList.cs
License : GNU General Public License v3.0
Project Creator : aelariane
License : GNU General Public License v3.0
Project Creator : aelariane
private void AllocateMore()
{
T[] array = (this.buffer == null) ? new T[32] : new T[Mathf.Max(this.buffer.Length << 1, 32)];
if (this.buffer != null && this.size > 0)
{
this.buffer.CopyTo(array, 0);
}
this.buffer = array;
}
19
View Source File : ColorAffector.cs
License : GNU General Public License v3.0
Project Creator : aelariane
License : GNU General Public License v3.0
Project Creator : aelariane
public override void Update()
{
this.ElapsedTime += Time.deltaTime;
if (this.IsNodeLife)
{
this.GradualLen = this.Node.GetLifeTime();
}
if (this.GradualLen <= 0f)
{
return;
}
if (this.ElapsedTime <= this.GradualLen)
{
int num = (int)((float)(this.ColorArr.Length - 1) * (this.ElapsedTime / this.GradualLen));
if (num == this.ColorArr.Length - 1)
{
num--;
}
int num2 = num + 1;
float num3 = this.GradualLen / (float)(this.ColorArr.Length - 1);
float t = (this.ElapsedTime - num3 * (float)num) / num3;
this.Node.Color = Color.Lerp(this.ColorArr[num], this.ColorArr[num2], t);
return;
}
if (this.Type == COLOR_GRADUAL_TYPE.CLAMP)
{
return;
}
if (this.Type == COLOR_GRADUAL_TYPE.LOOP)
{
this.ElapsedTime = 0f;
return;
}
Color[] array = new Color[this.ColorArr.Length];
this.ColorArr.CopyTo(array, 0);
for (int i = 0; i < array.Length / 2; i++)
{
this.ColorArr[array.Length - i - 1] = array[i];
this.ColorArr[i] = array[array.Length - i - 1];
}
this.ElapsedTime = 0f;
}
19
View Source File : VertexPool.cs
License : GNU General Public License v3.0
Project Creator : aelariane
License : GNU General Public License v3.0
Project Creator : aelariane
public void EnlargeArrays(int count, int icount)
{
Vector3[] vertices = this.Vertices;
this.Vertices = new Vector3[this.Vertices.Length + count];
vertices.CopyTo(this.Vertices, 0);
Vector2[] uvs = this.UVs;
this.UVs = new Vector2[this.UVs.Length + count];
uvs.CopyTo(this.UVs, 0);
Color[] colors = this.Colors;
this.Colors = new Color[this.Colors.Length + count];
colors.CopyTo(this.Colors, 0);
int[] indices = this.Indices;
this.Indices = new int[this.Indices.Length + icount];
indices.CopyTo(this.Indices, 0);
this.VertCountChanged = true;
this.IndiceChanged = true;
this.ColorChanged = true;
this.UVChanged = true;
this.VertChanged = true;
}
19
View Source File : Form1.cs
License : GNU General Public License v3.0
Project Creator : Aemony
License : GNU General Public License v3.0
Project Creator : Aemony
private void buttonSave_Click(object sender, EventArgs e)
{
DialogResult dialogResult;
if (_byteInventoryImportedActive != null || _byteInventoryImportedCorpse != null)
{
dialogResult = MessageBox.Show("You currently have an imported inventory list active that have overwritten the original inventory list of the opened slot file. Saving will make the change permanent.\n\nAre you sure you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
} else {
dialogResult = MessageBox.Show("Are you sure you want to save your changes to the slot file?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
}
if(dialogResult == DialogResult.Yes)
{
byte[] byteInventoryChanged = new byte[_intBlockLength];
for (int i = 0; i < 256; i++)
{
BitConverter.GetBytes(_itemInventoryActive[i].ID).CopyTo(byteInventoryChanged, i * 12);
BitConverter.GetBytes(_itemInventoryActive[i].Status).CopyTo(byteInventoryChanged, i * 12 + 4);
BitConverter.GetBytes(_itemInventoryActive[i].Amount).CopyTo(byteInventoryChanged, i * 12 + 8);
}
for (int i = 256; i < 512; i++)
{
BitConverter.GetBytes(_itemInventoryCorpse[i - 256].ID).CopyTo(byteInventoryChanged, i * 12);
BitConverter.GetBytes(_itemInventoryCorpse[i - 256].Status).CopyTo(byteInventoryChanged, i * 12 + 4);
BitConverter.GetBytes(_itemInventoryCorpse[i - 256].Amount).CopyTo(byteInventoryChanged, i * 12 + 8);
}
#if DEBUG
Console.WriteLine("Wrote:");
Console.WriteLine(BitConverter.ToString(byteInventoryChanged));
#endif
// Create a backup first
File.Copy(_filePath, _filePath + DateTime.Now.ToString("_yyyy-MM-dd_HH-mm-ss.bak"));
// Now overwrite the data
using (Stream stream = File.Open(_filePath, FileMode.Open, FileAccess.Write))
{
stream.Position = _intBlockOffset;
stream.Write(byteInventoryChanged, 0, _intBlockLength);
}
// Finally update the background stuff to reflect the new file
_byteInventory = byteInventoryChanged;
_byteInventoryImportedActive = null;
_byteInventoryImportedCorpse = null;
textBoxInventoryPath.Text = "No inventory list imported...";
MessageBox.Show("Changes were saved!", "Save complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
19
View Source File : Form1.cs
License : GNU General Public License v3.0
Project Creator : Aemony
License : GNU General Public License v3.0
Project Creator : Aemony
private void buttonExport_Click(object sender, EventArgs e)
{
byte[] byteInventoryExport = new byte[_intBlockLength];
for (int i = 0; i < 256; i++)
{
BitConverter.GetBytes(_itemInventoryActive[i].ID).CopyTo(byteInventoryExport, i * 12);
BitConverter.GetBytes(_itemInventoryActive[i].Status).CopyTo(byteInventoryExport, i * 12 + 4);
BitConverter.GetBytes(_itemInventoryActive[i].Amount).CopyTo(byteInventoryExport, i * 12 + 8);
}
for (int i = 256; i < 512; i++)
{
BitConverter.GetBytes(_itemInventoryCorpse[i - 256].ID).CopyTo(byteInventoryExport, i * 12);
BitConverter.GetBytes(_itemInventoryCorpse[i - 256].Status).CopyTo(byteInventoryExport, i * 12 + 4);
BitConverter.GetBytes(_itemInventoryCorpse[i - 256].Amount).CopyTo(byteInventoryExport, i * 12 + 8);
}
SaveFileDialog saveFileDialog = new SaveFileDialog
{
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDoreplacedents) + "\\My Games\\NieR_Automata",
replacedle = "Export inventory to file",
Filter = "Binary Data (*.bin)|*.bin|All Files|*",
FileName = "inventory.bin"
};
if(saveFileDialog.ShowDialog() == DialogResult.OK)
{
// Now export the data
using (Stream stream = saveFileDialog.OpenFile())
{
stream.Position = 0;
stream.Write(byteInventoryExport, 0, _intBlockLength);
}
#if DEBUG
Console.WriteLine("Wrote:");
Console.WriteLine(BitConverter.ToString(byteInventoryExport));
#endif
MessageBox.Show("Inventory was exported!", "Export complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
19
View Source File : ManualMap.cs
License : Apache License 2.0
Project Creator : aequabit
License : Apache License 2.0
Project Creator : aequabit
private static bool LoadDependencies(JLibrary.PortableExecutable.PortableExecutable image, IntPtr hProcess, int processId)
{
List<string> list = new List<string>();
string lpBuffer = string.Empty;
bool flag = false;
foreach (IMAGE_IMPORT_DESCRIPTOR image_import_descriptor in image.EnumImports())
{
if ((image.ReadString((long) image.GetPtrFromRVA(image_import_descriptor.Name), SeekOrigin.Begin, out lpBuffer, -1, null) && !string.IsNullOrEmpty(lpBuffer)) && GetRemoteModuleHandle(lpBuffer, processId).IsNull())
{
list.Add(lpBuffer);
}
}
if (list.Count > 0)
{
byte[] data = ExtractManifest(image);
string str2 = string.Empty;
if (data == null)
{
if (string.IsNullOrEmpty(image.FileLocation) || !File.Exists(Path.Combine(Path.GetDirectoryName(image.FileLocation), Path.GetFileName(image.FileLocation) + ".manifest")))
{
IntPtr[] ptrArray = InjectionMethod.Create(InjectionMethodType.Standard).InjectAll(list.ToArray(), hProcess);
foreach (IntPtr ptr in ptrArray)
{
if (ptr.IsNull())
{
return false;
}
}
return true;
}
str2 = Path.Combine(Path.GetDirectoryName(image.FileLocation), Path.GetFileName(image.FileLocation) + ".manifest");
}
else
{
str2 = Utils.WriteTempData(data);
}
if (string.IsNullOrEmpty(str2))
{
return false;
}
IntPtr ptr2 = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, (uint) RESOLVER_STUB.Length, 0x3000, 0x40);
IntPtr lpAddress = WinAPI.CreateRemotePointer(hProcess, Encoding.ASCII.GetBytes(str2 + "\0"), 4);
IntPtr ptr4 = WinAPI.CreateRemotePointer(hProcess, Encoding.ASCII.GetBytes(string.Join("\0", list.ToArray()) + "\0"), 4);
if (!ptr2.IsNull())
{
byte[] array = (byte[]) RESOLVER_STUB.Clone();
uint lpNumberOfBytesRead = 0;
BitConverter.GetBytes(FN_CREATEACTCTXA.Subtract(ptr2.Add(((long) 0x3fL))).ToInt32()).CopyTo(array, 0x3b);
BitConverter.GetBytes(FN_ACTIVATEACTCTX.Subtract(ptr2.Add(((long) 0x58L))).ToInt32()).CopyTo(array, 0x54);
BitConverter.GetBytes(FN_GETMODULEHANDLEA.Subtract(ptr2.Add(((long) 0x84L))).ToInt32()).CopyTo(array, 0x80);
BitConverter.GetBytes(FN_LOADLIBRARYA.Subtract(ptr2.Add(((long) 0x92L))).ToInt32()).CopyTo(array, 0x8e);
BitConverter.GetBytes(FN_DEACTIVATEACTCTX.Subtract(ptr2.Add(((long) 200L))).ToInt32()).CopyTo(array, 0xc4);
BitConverter.GetBytes(FN_RELEASEACTCTX.Subtract(ptr2.Add(((long) 0xd1L))).ToInt32()).CopyTo(array, 0xcd);
BitConverter.GetBytes(lpAddress.ToInt32()).CopyTo(array, 0x1f);
BitConverter.GetBytes(list.Count).CopyTo(array, 40);
BitConverter.GetBytes(ptr4.ToInt32()).CopyTo(array, 0x31);
if (WinAPI.WriteProcessMemory(hProcess, ptr2, array, array.Length, out lpNumberOfBytesRead) && (lpNumberOfBytesRead == array.Length))
{
uint num2 = WinAPI.RunThread(hProcess, ptr2, 0, 0x1388);
flag = (num2 != uint.MaxValue) && (num2 != 0);
}
WinAPI.VirtualFreeEx(hProcess, ptr4, 0, 0x8000);
WinAPI.VirtualFreeEx(hProcess, lpAddress, 0, 0x8000);
WinAPI.VirtualFreeEx(hProcess, ptr2, 0, 0x8000);
}
}
return flag;
}
19
View Source File : StandardInjectionMethod.cs
License : Apache License 2.0
Project Creator : aequabit
License : Apache License 2.0
Project Creator : aequabit
protected virtual IntPtr CreateMultiLoadStub(string[] paths, IntPtr hProcess, out IntPtr pModuleBuffer, uint nullmodule = 0)
{
IntPtr ptr6;
pModuleBuffer = IntPtr.Zero;
IntPtr zero = IntPtr.Zero;
try
{
IntPtr moduleHandleA = WinAPI.GetModuleHandleA("kernel32.dll");
IntPtr procAddress = WinAPI.GetProcAddress(moduleHandleA, "LoadLibraryA");
IntPtr ptr = WinAPI.GetProcAddress(moduleHandleA, "GetModuleHandleA");
if (procAddress.IsNull() || ptr.IsNull())
{
throw new Exception("Unable to find necessary function entry points in the remote process");
}
pModuleBuffer = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, ((uint) paths.Length) << 2, 0x3000, 4);
IntPtr ptr5 = WinAPI.CreateRemotePointer(hProcess, Encoding.ASCII.GetBytes(string.Join("\0", paths) + "\0"), 4);
if (pModuleBuffer.IsNull() || ptr5.IsNull())
{
throw new InvalidOperationException("Unable to allocate memory in the remote process");
}
try
{
uint lpNumberOfBytesRead = 0;
byte[] array = new byte[paths.Length << 2];
for (int i = 0; i < (array.Length >> 2); i++)
{
BitConverter.GetBytes(nullmodule).CopyTo(array, (int) (i << 2));
}
WinAPI.WriteProcessMemory(hProcess, pModuleBuffer, array, array.Length, out lpNumberOfBytesRead);
byte[] buffer2 = (byte[]) MULTILOAD_STUB.Clone();
zero = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, (uint) buffer2.Length, 0x3000, 0x40);
if (zero.IsNull())
{
throw new InvalidOperationException("Unable to allocate memory in the remote process");
}
BitConverter.GetBytes(ptr5.ToInt32()).CopyTo(buffer2, 7);
BitConverter.GetBytes(paths.Length).CopyTo(buffer2, 15);
BitConverter.GetBytes(pModuleBuffer.ToInt32()).CopyTo(buffer2, 0x18);
BitConverter.GetBytes(ptr.Subtract(zero.Add(((long) 0x38L))).ToInt32()).CopyTo(buffer2, 0x34);
BitConverter.GetBytes(procAddress.Subtract(zero.Add(((long) 0x45L))).ToInt32()).CopyTo(buffer2, 0x41);
if (!(WinAPI.WriteProcessMemory(hProcess, zero, buffer2, buffer2.Length, out lpNumberOfBytesRead) && (lpNumberOfBytesRead == buffer2.Length)))
{
throw new Exception("Error creating the remote function stub.");
}
ptr6 = zero;
}
finally
{
WinAPI.VirtualFreeEx(hProcess, pModuleBuffer, 0, 0x8000);
WinAPI.VirtualFreeEx(hProcess, ptr5, 0, 0x8000);
if (!zero.IsNull())
{
WinAPI.VirtualFreeEx(hProcess, zero, 0, 0x8000);
}
pModuleBuffer = IntPtr.Zero;
}
}
catch (Exception exception)
{
this.SetLastError(exception);
ptr6 = IntPtr.Zero;
}
return ptr6;
}
19
View Source File : StandardInjectionMethod.cs
License : Apache License 2.0
Project Creator : aequabit
License : Apache License 2.0
Project Creator : aequabit
public override bool[] UnloadAll(IntPtr[] hModules, IntPtr hProcess)
{
bool[] flagArray2;
this.ClearErrors();
IntPtr zero = IntPtr.Zero;
IntPtr ptr = IntPtr.Zero;
IntPtr ptr3 = IntPtr.Zero;
try
{
int num2;
uint lpNumberOfBytesRead = 0;
IntPtr procAddress = WinAPI.GetProcAddress(WinAPI.GetModuleHandleA("kernel32.dll"), "FreeLibrary");
if (procAddress.IsNull())
{
throw new Exception("Unable to find necessary function entry points in the remote process");
}
zero = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, ((uint) hModules.Length) << 2, 0x3000, 4);
ptr = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, (uint) ((hModules.Length + 1) << 2), 0x3000, 4);
ptr3 = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, (uint) MULTIUNLOAD_STUB.Length, 0x3000, 0x40);
if ((zero.IsNull() || ptr.IsNull()) || ptr3.IsNull())
{
throw new InvalidOperationException("Unable to allocate memory in the remote process");
}
byte[] array = new byte[(hModules.Length + 1) << 2];
for (num2 = 0; num2 < hModules.Length; num2++)
{
BitConverter.GetBytes(hModules[num2].ToInt32()).CopyTo(array, (int) (num2 << 2));
}
WinAPI.WriteProcessMemory(hProcess, ptr, array, array.Length, out lpNumberOfBytesRead);
byte[] buffer2 = (byte[]) MULTIUNLOAD_STUB.Clone();
BitConverter.GetBytes(ptr.ToInt32()).CopyTo(buffer2, 7);
BitConverter.GetBytes(zero.ToInt32()).CopyTo(buffer2, 15);
BitConverter.GetBytes(procAddress.Subtract(ptr3.Add(((long) 0x38L))).ToInt32()).CopyTo(buffer2, 0x34);
if (!(WinAPI.WriteProcessMemory(hProcess, ptr3, buffer2, buffer2.Length, out lpNumberOfBytesRead) && (lpNumberOfBytesRead == buffer2.Length)))
{
throw new InvalidOperationException("Unable to write the function stub to the remote process.");
}
if (WinAPI.RunThread(hProcess, ptr3, 0, 0x3e8) == uint.MaxValue)
{
throw new InvalidOperationException("Error occurred when running remote function stub.");
}
byte[] buffer3 = WinAPI.ReadRemoteMemory(hProcess, zero, ((uint) hModules.Length) << 2);
if (buffer3 == null)
{
throw new Exception("Unable to read results from the remote process.");
}
bool[] flagArray = new bool[hModules.Length];
for (num2 = 0; num2 < flagArray.Length; num2++)
{
flagArray[num2] = BitConverter.ToInt32(buffer3, num2 << 2) != 0;
}
flagArray2 = flagArray;
}
catch (Exception exception)
{
this.SetLastError(exception);
flagArray2 = null;
}
finally
{
WinAPI.VirtualFreeEx(hProcess, ptr3, 0, 0x8000);
WinAPI.VirtualFreeEx(hProcess, zero, 0, 0x8000);
WinAPI.VirtualFreeEx(hProcess, ptr, 0, 0x8000);
}
return flagArray2;
}
19
View Source File : ThreadHijack.cs
License : Apache License 2.0
Project Creator : aequabit
License : Apache License 2.0
Project Creator : aequabit
public override IntPtr[] InjectAll(string[] dllPaths, IntPtr hProcess)
{
Exception exception;
this.ClearErrors();
try
{
if (hProcess.IsNull() || hProcess.Compare(-1L))
{
throw new ArgumentException("Invalid process handle.", "hProcess");
}
int processId = WinAPI.GetProcessId(hProcess);
if (processId == 0)
{
throw new ArgumentException("Provided handle doesn't have sufficient permissions to inject", "hProcess");
}
Process processById = Process.GetProcessById(processId);
if (processById.Threads.Count == 0)
{
throw new Exception("Target process has no targetable threads to hijack.");
}
ProcessThread thread = SelectOptimalThread(processById);
IntPtr ptr = WinAPI.OpenThread(0x1a, false, thread.Id);
if (ptr.IsNull() || ptr.Compare(-1L))
{
throw new Exception("Unable to obtain a handle for the remote thread.");
}
IntPtr zero = IntPtr.Zero;
IntPtr lpAddress = IntPtr.Zero;
IntPtr ptr4 = this.CreateMultiLoadStub(dllPaths, hProcess, out zero, 1);
IntPtr[] ptrArray = null;
if (!ptr4.IsNull())
{
if (WinAPI.SuspendThread(ptr) == uint.MaxValue)
{
throw new Exception("Unable to suspend the remote thread");
}
try
{
uint lpNumberOfBytesRead = 0;
WinAPI.CONTEXT pContext = new WinAPI.CONTEXT {
ContextFlags = 0x10001
};
if (!WinAPI.GetThreadContext(ptr, ref pContext))
{
throw new InvalidOperationException("Cannot get the remote thread's context");
}
byte[] array = REDIRECT_STUB;
IntPtr ptr5 = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, (uint) array.Length, 0x3000, 0x40);
if (ptr5.IsNull())
{
throw new InvalidOperationException("Unable to allocate memory in the remote process.");
}
BitConverter.GetBytes(ptr4.Subtract(ptr5.Add(((long) 7L))).ToInt32()).CopyTo(array, 3);
BitConverter.GetBytes((uint) (pContext.Eip - ((uint) ptr5.Add(((long) array.Length)).ToInt32()))).CopyTo(array, (int) (array.Length - 4));
if (!(WinAPI.WriteProcessMemory(hProcess, ptr5, array, array.Length, out lpNumberOfBytesRead) && (lpNumberOfBytesRead == array.Length)))
{
throw new InvalidOperationException("Unable to write stub to the remote process.");
}
pContext.Eip = (uint) ptr5.ToInt32();
WinAPI.SetThreadContext(ptr, ref pContext);
}
catch (Exception exception1)
{
exception = exception1;
this.SetLastError(exception);
ptrArray = null;
WinAPI.VirtualFreeEx(hProcess, zero, 0, 0x8000);
WinAPI.VirtualFreeEx(hProcess, ptr4, 0, 0x8000);
WinAPI.VirtualFreeEx(hProcess, lpAddress, 0, 0x8000);
}
WinAPI.ResumeThread(ptr);
if (this.GetLastError() == null)
{
Thread.Sleep(100);
ptrArray = new IntPtr[dllPaths.Length];
byte[] buffer2 = WinAPI.ReadRemoteMemory(hProcess, zero, ((uint) dllPaths.Length) << 2);
if (buffer2 != null)
{
for (int i = 0; i < ptrArray.Length; i++)
{
ptrArray[i] = Win32Ptr.Create((long) BitConverter.ToInt32(buffer2, i << 2));
}
}
}
WinAPI.CloseHandle(ptr);
}
return ptrArray;
}
catch (Exception exception2)
{
exception = exception2;
this.SetLastError(exception);
return null;
}
}
19
View Source File : Decompress.cs
License : GNU General Public License v3.0
Project Creator : Aeroblast
License : GNU General Public License v3.0
Project Creator : Aeroblast
public byte[] Decode(byte[] _data)
{
byte[] data = new byte[_data.Length + 8]; _data.CopyTo(data, 0);
long bitsleft = _data.Length * 8;
ulong pos = 0;
ulong x = Util.GetUInt64(data, pos);
int n = 32;
List<byte> s = new List<byte>();
while (true)
{
if (n <= 0)
{
pos += 4;
x = Util.GetUInt64(data, pos);
n += 32;
}
ulong code = (x >> n) & (((ulong)1 << 32) - 1);
ulong dict1_i = code >> 24;
uint _codelen = codelen[dict1_i];
ulong _maxcode = maxcode1[dict1_i];
if (!term[dict1_i])
{
while (code < mincode[_codelen]) _codelen++;
_maxcode = maxcode[_codelen];
}
n -= (int)_codelen;
bitsleft -= _codelen;
if (bitsleft < 0) break;
ulong r = (_maxcode - code) >> (int)(32 - _codelen);
byte[] slice = cdic.slice[(int)r];
bool flag = cdic.slice_flag[(int)r];
if (!flag)
{
cdic.slice[(int)r] = new byte[0];
slice = Decode(slice);
cdic.slice[(int)r] = slice; cdic.slice_flag[(int)r] = true;//self.dictionary[r] = (slice, 1)
}
s.AddRange(slice);
}
return s.ToArray();
}
19
View Source File : ManualMap.cs
License : Apache License 2.0
Project Creator : aequabit
License : Apache License 2.0
Project Creator : aequabit
private static IntPtr MapModule(JLibrary.PortableExecutable.PortableExecutable image, IntPtr hProcess, bool preserveHeaders = false)
{
if (hProcess.IsNull() || hProcess.Compare(-1L))
{
throw new ArgumentException("Invalid process handle.", "hProcess");
}
if (image == null)
{
throw new ArgumentException("Cannot map a non-existant PE Image.", "image");
}
int processId = WinAPI.GetProcessId(hProcess);
if (processId == 0)
{
throw new ArgumentException("Provided handle doesn't have sufficient permissions to inject", "hProcess");
}
IntPtr zero = IntPtr.Zero;
IntPtr ptr = IntPtr.Zero;
uint lpNumberOfBytesRead = 0;
try
{
zero = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, image.NTHeader.OptionalHeader.SizeOfImage, 0x3000, 4);
if (zero.IsNull())
{
throw new InvalidOperationException("Unable to allocate memory in the remote process.");
}
PatchRelocations(image, zero);
LoadDependencies(image, hProcess, processId);
PatchImports(image, hProcess, processId);
if (preserveHeaders)
{
long num3 = (long) (((image.DOSHeader.e_lfanew + Marshal.SizeOf(typeof(IMAGE_FILE_HEADER))) + ((long) 4L)) + image.NTHeader.FileHeader.SizeOfOptionalHeader);
byte[] buffer = new byte[num3];
if (image.Read(0L, SeekOrigin.Begin, buffer))
{
WinAPI.WriteProcessMemory(hProcess, zero, buffer, buffer.Length, out lpNumberOfBytesRead);
}
}
MapSections(image, hProcess, zero);
if (image.NTHeader.OptionalHeader.AddressOfEntryPoint <= 0)
{
return zero;
}
byte[] array = (byte[]) DLLMAIN_STUB.Clone();
BitConverter.GetBytes(zero.ToInt32()).CopyTo(array, 11);
ptr = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, (uint) DLLMAIN_STUB.Length, 0x3000, 0x40);
if (ptr.IsNull() || (!WinAPI.WriteProcessMemory(hProcess, ptr, array, array.Length, out lpNumberOfBytesRead) || (lpNumberOfBytesRead != array.Length)))
{
throw new InvalidOperationException("Unable to write stub to the remote process.");
}
IntPtr hObject = WinAPI.CreateRemoteThread(hProcess, 0, 0, ptr, (uint) zero.Add(((long) image.NTHeader.OptionalHeader.AddressOfEntryPoint)).ToInt32(), 0, 0);
if (WinAPI.WaitForSingleObject(hObject, 0x1388) != 0L)
{
return zero;
}
WinAPI.GetExitCodeThread(hObject, out lpNumberOfBytesRead);
if (lpNumberOfBytesRead == 0)
{
WinAPI.VirtualFreeEx(hProcess, zero, 0, 0x8000);
throw new Exception("Entry method of module reported a failure " + Marshal.GetLastWin32Error().ToString());
}
WinAPI.VirtualFreeEx(hProcess, ptr, 0, 0x8000);
WinAPI.CloseHandle(hObject);
}
catch (Exception exception)
{
if (!zero.IsNull())
{
WinAPI.VirtualFreeEx(hProcess, zero, 0, 0x8000);
}
if (!ptr.IsNull())
{
WinAPI.VirtualFreeEx(hProcess, zero, 0, 0x8000);
}
zero = IntPtr.Zero;
throw exception;
}
return zero;
}
19
View Source File : ManualMap.cs
License : Apache License 2.0
Project Creator : aequabit
License : Apache License 2.0
Project Creator : aequabit
public override bool Unload(IntPtr hModule, IntPtr hProcess)
{
this.ClearErrors();
if (hModule.IsNull())
{
throw new ArgumentNullException("hModule", "Invalid module handle");
}
if (hProcess.IsNull() || hProcess.Compare(-1L))
{
throw new ArgumentException("Invalid process handle.", "hProcess");
}
IntPtr zero = IntPtr.Zero;
uint lpNumberOfBytesRead = 0;
try
{
uint num2 = FindEntryPoint(hProcess, hModule);
if (num2 != 0)
{
byte[] array = (byte[]) DLLMAIN_STUB.Clone();
BitConverter.GetBytes(hModule.ToInt32()).CopyTo(array, 11);
BitConverter.GetBytes((uint) 0).CopyTo(array, 6);
BitConverter.GetBytes((uint) 0x3e8).CopyTo(array, 1);
zero = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, (uint) DLLMAIN_STUB.Length, 0x3000, 0x40);
if (zero.IsNull() || (!WinAPI.WriteProcessMemory(hProcess, zero, array, array.Length, out lpNumberOfBytesRead) || (lpNumberOfBytesRead != array.Length)))
{
throw new InvalidOperationException("Unable to write stub to the remote process.");
}
IntPtr hObject = WinAPI.CreateRemoteThread(hProcess, 0, 0, zero, (uint) hModule.Add(((long) num2)).ToInt32(), 0, 0);
if (WinAPI.WaitForSingleObject(hObject, 0x1388) == 0L)
{
WinAPI.VirtualFreeEx(hProcess, zero, 0, 0x8000);
WinAPI.CloseHandle(hObject);
return WinAPI.VirtualFreeEx(hProcess, hModule, 0, 0x8000);
}
return false;
}
return WinAPI.VirtualFreeEx(hProcess, hModule, 0, 0x8000);
}
catch (Exception exception)
{
this.SetLastError(exception);
return false;
}
}
19
View Source File : EntityStateReadBuffers.cs
License : The Unlicense
Project Creator : aeroson
License : The Unlicense
Project Creator : aeroson
internal void Add(Enreplacedy e)
{
//Don't need to lock since the parent manager handles it.
if (frontBuffer.Length <= e.BufferedStates.motionStateIndex)
{
var newStates = new MotionState[frontBuffer.Length * 2]; //TODO: shifty
frontBuffer.CopyTo(newStates, 0);
frontBuffer = newStates;
}
frontBuffer[e.BufferedStates.motionStateIndex].Position = e.position;
frontBuffer[e.BufferedStates.motionStateIndex].Orientation = e.orientation;
if (backBuffer.Length <= e.BufferedStates.motionStateIndex)
{
var newStates = new MotionState[backBuffer.Length * 2]; //TODO: shifty
backBuffer.CopyTo(newStates, 0);
backBuffer = newStates;
}
backBuffer[e.BufferedStates.motionStateIndex].Position = e.position;
backBuffer[e.BufferedStates.motionStateIndex].Orientation = e.orientation;
}
19
View Source File : InterpolatedStatesManager.cs
License : The Unlicense
Project Creator : aeroson
License : The Unlicense
Project Creator : aeroson
internal void Add(Enreplacedy e)
{
//Don't need to lock since the parent manager handles it.
if (states.Length <= e.BufferedStates.motionStateIndex)
{
var newStates = new RigidTransform[states.Length * 2];
states.CopyTo(newStates, 0);
states = newStates;
}
states[e.BufferedStates.motionStateIndex].Position = e.position;
states[e.BufferedStates.motionStateIndex].Orientation = e.orientation;
if (backBuffer.Length <= e.BufferedStates.motionStateIndex)
{
var newStates = new RigidTransform[backBuffer.Length * 2];
backBuffer.CopyTo(newStates, 0);
backBuffer = newStates;
}
backBuffer[e.BufferedStates.motionStateIndex].Position = e.position;
backBuffer[e.BufferedStates.motionStateIndex].Orientation = e.orientation;
}
19
View Source File : SimpleBuffer.cs
License : GNU General Public License v2.0
Project Creator : afrantzis
License : GNU General Public License v2.0
Project Creator : afrantzis
public override void Append(byte[] d, long index, long length)
{
if (length == 0)
return;
if (data.Length > 0) {
byte[] tmp = new byte[data.LongLength + length];
data.CopyTo(tmp, 0);
Array.Copy(d, index, tmp, data.LongLength, length);
data = tmp;
}
else {
data = new byte[length];
Array.Copy(d, index, data, 0, length);
}
}
19
View Source File : SimpleBuffer.cs
License : GNU General Public License v2.0
Project Creator : afrantzis
License : GNU General Public License v2.0
Project Creator : afrantzis
public override void AppendBuffer(IBuffer buf, long index, long length)
{
if (length == 0)
return;
if (data.Length > 0) {
byte[] tmp = new byte[data.LongLength + length];
data.CopyTo(tmp, 0);
buf.Read(tmp, data.LongLength, index, length);
data = tmp;
}
else {
data = new byte[length];
buf.Read(data, 0, index, length);
}
}
19
View Source File : ListInput.cs
License : MIT License
Project Creator : afucher
License : MIT License
Project Creator : afucher
public override string[] GetQuestion()
{
var question = new string[options.Length+1];
question[0] = message;
options.CopyTo(question, 1);
question[selectedOption + 1] = "> " + question[selectedOption + 1];
return question;
}
19
View Source File : MainForm.cs
License : GNU General Public License v3.0
Project Creator : AgentRev
License : GNU General Public License v3.0
Project Creator : AgentRev
bool isRunning(bool init)
{
Process[] spProcs = Process.GetProcessesByName(Singleplayer.c_exe);
Process[] mpProcs = Process.GetProcessesByName(Multiplayer.c_exe);
Process[] procs = new Process[mpProcs.Length + spProcs.Length];
try
{
spProcs.CopyTo(procs, 0);
mpProcs.CopyTo(procs, spProcs.Length);
}
catch { }
if (procs.Length > 0)
{
if (proc == null && init)
{
proc = procs[0];
if (proc.ProcessName == Singleplayer.c_exe && !rbSingleplayer.Checked)
rbSingleplayer.Checked = true;
else if (proc.ProcessName == Multiplayer.c_exe && !rbMultiplayer.Checked)
rbMultiplayer.Checked = true;
try
{
mem = new Memory((string)gameMode.GetValue("c_cVar"), proc.Id, (dword_ptr)gameMode.GetValue("c_baseAddr"), (byte)gameMode.GetValue("c_checkRange"), c_pOffset);
}
catch (Exception ex)
{
ErrMessage(ex);
Application.Exit();
}
TimerVerif.Start();
}
/*if (proc != null)
{
proc.Refresh();
return !proc.HasExited;
}*/
return true;
}
else
{
if (proc != null && init)
{
TimerVerif.Stop();
mem = null;
progStop();
}
return false;
}
}
19
View Source File : MainForm.cs
License : GNU General Public License v3.0
Project Creator : AgentRev
License : GNU General Public License v3.0
Project Creator : AgentRev
bool isRunning(bool init)
{
Process[] spProcs = Process.GetProcessesByName(Singleplayer.c_exe);
Process[] mpProcs = Process.GetProcessesByName(Multiplayer.c_exe);
Process[] procs = new Process[mpProcs.Length + spProcs.Length];
try
{
spProcs.CopyTo(procs, 0);
mpProcs.CopyTo(procs, spProcs.Length);
}
catch { }
if (procs.Length > 0)
{
if (proc == null && init)
{
proc = procs[0];
if (proc.ProcessName == Singleplayer.c_exe && !rbSingleplayer.Checked)
rbSingleplayer.Checked = true;
else if (proc.ProcessName == Multiplayer.c_exe && !rbMultiplayer.Checked)
rbMultiplayer.Checked = true;
try
{
mem = new Memory((string)gameMode.GetValue("c_cVar"), proc.Id, (int)gameMode.GetValue("c_baseAddr"), (byte)gameMode.GetValue("c_checkRange"), c_pOffset);
}
catch (Exception ex)
{
ErrMessage(ex);
Application.Exit();
}
TimerVerif.Start();
}
return true;
}
else
{
if (proc != null && init)
{
TimerVerif.Stop();
mem = null;
progStop();
}
return false;
}
}
19
View Source File : MemoryManager.cs
License : GNU General Public License v3.0
Project Creator : aglab2
License : GNU General Public License v3.0
Project Creator : aglab2
public void WriteToFile(int offset, int bit, int maxShown)
{
byte[] stars = new byte[FileLength];
Stars.CopyTo(stars, 0);
stars[offset] = (byte) (stars[offset] ^ (byte)(1 << bit));
FixStarCount(stars, maxShown);
for (int i = 0; i < FileLength; i += 4)
Array.Reverse(stars, i, 4);
Process.WriteBytes(filePtr, stars);
for (int i = 0; i < FileLength; i += 4)
Array.Reverse(stars, i, 4);
stars.CopyTo(Stars, 0);
isStarsInvalidated = true;
isInvalidated = true;
}
19
View Source File : DataUtil.cs
License : GNU General Public License v3.0
Project Creator : ahmed605
License : GNU General Public License v3.0
Project Creator : ahmed605
public static byte[] Decrypt(byte[] dataIn)
{
byte[] data = new byte[dataIn.Length];
dataIn.CopyTo(data, 0);
// Create our Rijndael clreplaced
Rijndael rj = Rijndael.Create();
rj.BlockSize = 128;
rj.KeySize = 256;
rj.Mode = CipherMode.ECB;
rj.Key = KeyStore.AESKey;
rj.IV = new byte[16];
rj.Padding = PaddingMode.None;
ICryptoTransform transform = rj.CreateDecryptor();
int dataLen = data.Length & ~0x0F;
// Decrypt!
// R* was nice enough to do it 16 times...
// AES is just as effective doing it 1 time because it has multiple internal rounds
if (dataLen > 0)
{
for (int i = 0; i < 16; i++)
{
transform.TransformBlock(data, 0, dataLen, data, 0);
}
}
return data;
}
19
View Source File : TOCEntry.cs
License : GNU General Public License v3.0
Project Creator : ahmed605
License : GNU General Public License v3.0
Project Creator : ahmed605
public void SetCustomData(byte[] data)
{
if (data == null)
{
CustomData = null;
}
else
{
Size = data.Length;
if ((data.Length % BlockSize) != 0)
{
int padding = (BlockSize - data.Length%BlockSize);
int fullDataLength = data.Length + padding;
var newData = new byte[fullDataLength];
data.CopyTo(newData, 0);
data = newData;
PaddingCount = padding;
}
else
{
PaddingCount = 0;
}
CustomData = data;
if (IsResourceFile)
{
var ms = new MemoryStream(data, false);
uint flags;
ResourceType resType;
ResourceUtil.GetResourceData(ms, out flags, out resType);
RSCFlags = flags;
ResourceType = resType;
ms.Close();
}
}
}
19
View Source File : FileEntry.cs
License : GNU General Public License v3.0
Project Creator : ahmed605
License : GNU General Public License v3.0
Project Creator : ahmed605
public void SetCustomData(byte[] data)
{
if (data == null)
{
CustomData = null;
}
else
{
Size = data.Length;
SizeInArchive = data.Length;
IsCompressed = false;
if ((data.Length % BlockSize) != 0)
{
int fullDataLength = data.Length + (BlockSize - data.Length % BlockSize);
var newData = new byte[fullDataLength];
data.CopyTo(newData, 0);
data = newData;
}
CustomData = data;
if (IsResourceFile)
{
var ms = new MemoryStream(data, false);
uint flags;
ResourceType resType;
ResourceUtil.GetResourceData(ms, out flags, out resType);
RSCFlags = flags;
ResourceType = resType;
ms.Close();
}
}
}
19
View Source File : MonthlyBoldedDates.cs
License : Mozilla Public License 2.0
Project Creator : ahyahy
License : Mozilla Public License 2.0
Project Creator : ahyahy
[ContextMethod("Добавить", "Add")]
public IValue Add(IValue p1)
{
DateTime[] DateTime2 = new DateTime[M_Object.Length + 1];
M_Object.CopyTo(DateTime2, 0);
System.DateTime p2 = p1.AsDate();
DateTime2[M_Object.Length] = new System.DateTime(p2.Year, p2.Month, p2.Day, p2.Hour, p2.Minute, p2.Second);
M_Object = DateTime2;
return p1;
}
19
View Source File : Utils.cs
License : Apache License 2.0
Project Creator : ajuna-network
License : Apache License 2.0
Project Creator : ajuna-network
public static string GetAddressFrom(byte[] bytes)
{
var SR25519_PUBLIC_SIZE = 32;
var PUBLIC_KEY_LENGTH = 32;
var plainAddr = Enumerable
.Repeat((byte) 0x2A, 35)
.ToArray();
bytes.CopyTo(plainAddr.AsMemory(1));
var ssPrefixed = new byte[SR25519_PUBLIC_SIZE + 8];
var ssPrefixed1 = new byte[] {0x53, 0x53, 0x35, 0x38, 0x50, 0x52, 0x45};
ssPrefixed1.CopyTo(ssPrefixed, 0);
plainAddr.replacedpan(0, SR25519_PUBLIC_SIZE + 1).CopyTo(ssPrefixed.replacedpan(7));
var blake2bHashed = HashExtension.Blake2(ssPrefixed, 0, SR25519_PUBLIC_SIZE + 8);
plainAddr[1 + PUBLIC_KEY_LENGTH] = blake2bHashed[0];
plainAddr[2 + PUBLIC_KEY_LENGTH] = blake2bHashed[1];
var addrCh = Base58.Bitcoin.Encode(plainAddr).ToArray();
return new string(addrCh);
}
19
View Source File : U16.cs
License : Apache License 2.0
Project Creator : ajuna-network
License : Apache License 2.0
Project Creator : ajuna-network
public override void Create(byte[] byteArray)
{
if (byteArray.Length < Size())
{
var newByteArray = new byte[Size()];
byteArray.CopyTo(newByteArray, 0);
byteArray = newByteArray;
}
Bytes = byteArray;
Value = BitConverter.ToUInt16(byteArray, 0);
}
See More Examples