public bool MonoTypeGetIsByRef(TargetMemoryAccess memory, TargetAddress type) { uint flags = (uint)memory.ReadInteger( type + memory.TargetMemoryInfo.TargetAddressSize); return((int)((flags & 0x40000000) >> 30) != 0); }
// // MonoType // public MonoTypeEnum MonoTypeGetType(TargetMemoryAccess memory, TargetAddress type) { uint flags = (uint)memory.ReadInteger( type + memory.TargetMemoryInfo.TargetAddressSize); return((MonoTypeEnum)((flags & 0x00ff0000) >> 16)); }
public MonoMethodSignature GetMethodSignature(MonoLanguageBackend mono, TargetMemoryAccess memory, TargetAddress signature) { int count = memory.ReadInteger(signature + 4) & 0x0000ffff; int offset = memory.TargetAddressSize == 8 ? 16 : 12; TargetAddress ret = memory.ReadAddress(signature + offset); TargetType ret_type = mono.ReadType(memory, ret); if (count == 0) { return(new MonoMethodSignature(ret_type, new TargetType [0])); } offset += memory.TargetAddressSize; TargetReader reader = new TargetReader( memory.ReadMemory(signature + offset, count * memory.TargetAddressSize)); TargetType[] param_types = new TargetType [count]; for (int i = 0; i < count; i++) { param_types [i] = mono.ReadType(memory, reader.ReadAddress()); } return(new MonoMethodSignature(ret_type, param_types)); }
// // The following API is new in `terrania'. // public GenericClassInfo GetGenericClass(TargetMemoryAccess memory, TargetAddress address) { int addr_size = memory.TargetMemoryInfo.TargetAddressSize; TargetReader reader = new TargetReader(memory.ReadMemory(address, 5 * addr_size)); TargetAddress container = reader.ReadAddress(); TargetAddress class_inst = reader.ReadAddress(); reader.ReadAddress(); /* method_inst */ reader.ReadAddress(); TargetAddress cached_class = reader.ReadAddress(); int inst_id = memory.ReadInteger(class_inst); int inst_data = memory.ReadInteger(class_inst + 4); TargetAddress inst_argv; if (MonoDebuggerInfo.MajorVersion == 80) { inst_argv = memory.ReadAddress(class_inst + 8); } else { inst_argv = class_inst + 8; } int type_argc = inst_data & 0x3fffff; TargetReader argv_reader = new TargetReader( memory.ReadMemory(inst_argv, type_argc * addr_size)); TargetAddress[] type_args = new TargetAddress [type_argc]; for (int i = 0; i < type_argc; i++) { type_args [i] = argv_reader.ReadAddress(); } TargetAddress cached_class_ptr = address + 4 * addr_size; return(new GenericClassInfo(container, type_args, cached_class_ptr, cached_class)); }
public int MonoClassGetInstanceSize(TargetMemoryAccess memory, TargetAddress klass) { int flags = memory.ReadInteger(klass + 4 * memory.TargetAddressSize); bool size_inited = (flags & 4) != 0; bool valuetype = (flags & 8) != 0; if (!size_inited) { throw new TargetException(TargetError.ClassNotInitialized); } int size = memory.ReadInteger(klass + 4 + 3 * memory.TargetAddressSize); if (valuetype) { size -= 2 * memory.TargetAddressSize; } return(size); }
public int MonoClassGetFieldOffset(TargetMemoryAccess memory, TargetAddress klass, int index) { int offset = index * MonoMetadataInfo.FieldInfoSize + MonoMetadataInfo.FieldInfoOffsetOffset; TargetAddress fields = memory.ReadAddress( klass + MonoMetadataInfo.KlassFieldOffset); if (fields.IsNull) { throw new TargetException(TargetError.ClassNotInitialized); } return(memory.ReadInteger(fields + offset)); }
public int MonoClassGetInstanceSize(TargetMemoryAccess memory, TargetAddress klass) { int flags = memory.ReadInteger (klass + 4 * memory.TargetAddressSize); bool size_inited = (flags & 4) != 0; bool valuetype = (flags & 8) != 0; if (!size_inited) throw new TargetException (TargetError.ClassNotInitialized); int size = memory.ReadInteger (klass + 4 + 3 * memory.TargetAddressSize); if (valuetype) size -= 2 * memory.TargetAddressSize; return size; }
// // MonoMethod // public int MonoMethodGetToken(TargetMemoryAccess memory, TargetAddress method) { return(memory.ReadInteger(method + MonoMetadataInfo.MonoMethodTokenOffset)); }
public int MonoClassGetFieldCount(TargetMemoryAccess memory, TargetAddress klass) { return(memory.ReadInteger(klass + MonoMetadataInfo.KlassFieldCountOffset)); }
// // MonoMethod // public int MonoMethodGetToken(TargetMemoryAccess memory, TargetAddress method) { return memory.ReadInteger (method + MonoMetadataInfo.MonoMethodTokenOffset); }
public MethodSource GetTrampoline(TargetMemoryAccess memory, TargetAddress address) { #if FIXME int insn_size; TargetAddress target; CallTargetType type = memory.Architecture.GetCallTarget ( memory, address, out target, out insn_size); if (type != CallTargetType.MonoTrampoline) return null; int token = memory.ReadInteger (target + 4); TargetAddress klass = memory.ReadAddress (target + 8); TargetAddress image = memory.ReadAddress (klass); foreach (MonoSymbolFile file in symfile_by_index.Values) { if (file.MonoImage != image) continue; return file.GetMethodByToken (token); } #endif return null; }
public int MonoClassGetToken(TargetMemoryAccess memory, TargetAddress klass) { return(memory.ReadInteger(klass + MonoMetadataInfo.KlassTokenOffset)); }
public MetadataInfo(TargetMemoryAccess memory, TargetAddress address) { int size = memory.ReadInteger(address); TargetBinaryReader reader = memory.ReadMemory(address, size).GetReader(); reader.ReadInt32(); MonoDefaultsSize = reader.ReadInt32(); MonoDefaultsAddress = new TargetAddress( memory.AddressDomain, reader.ReadAddress()); TypeSize = reader.ReadInt32(); ArrayTypeSize = reader.ReadInt32(); KlassSize = reader.ReadInt32(); ThreadSize = reader.ReadInt32(); ThreadTidOffset = reader.ReadInt32(); ThreadStackPtrOffset = reader.ReadInt32(); ThreadEndStackOffset = reader.ReadInt32(); KlassImageOffset = reader.ReadInt32(); KlassInstanceSizeOffset = reader.ReadInt32(); KlassParentOffset = reader.ReadInt32(); KlassTokenOffset = reader.ReadInt32(); KlassFieldOffset = reader.ReadInt32(); KlassMethodsOffset = reader.ReadInt32(); KlassMethodCountOffset = reader.ReadInt32(); KlassThisArgOffset = reader.ReadInt32(); KlassByValArgOffset = reader.ReadInt32(); KlassGenericClassOffset = reader.ReadInt32(); KlassGenericContainerOffset = reader.ReadInt32(); KlassVTableOffset = reader.ReadInt32(); FieldInfoSize = reader.ReadInt32(); FieldInfoTypeOffset = reader.ReadInt32(); FieldInfoOffsetOffset = reader.ReadInt32(); KlassFieldCountOffset = KlassMethodCountOffset - 8; MonoDefaultsCorlibOffset = reader.ReadInt32(); MonoDefaultsObjectOffset = reader.ReadInt32(); MonoDefaultsByteOffset = reader.ReadInt32(); MonoDefaultsVoidOffset = reader.ReadInt32(); MonoDefaultsBooleanOffset = reader.ReadInt32(); MonoDefaultsSByteOffset = reader.ReadInt32(); MonoDefaultsInt16Offset = reader.ReadInt32(); MonoDefaultsUInt16Offset = reader.ReadInt32(); MonoDefaultsInt32Offset = reader.ReadInt32(); MonoDefaultsUInt32Offset = reader.ReadInt32(); MonoDefaultsIntOffset = reader.ReadInt32(); MonoDefaultsUIntOffset = reader.ReadInt32(); MonoDefaultsInt64Offset = reader.ReadInt32(); MonoDefaultsUInt64Offset = reader.ReadInt32(); MonoDefaultsSingleOffset = reader.ReadInt32(); MonoDefaultsDoubleOffset = reader.ReadInt32(); MonoDefaultsCharOffset = reader.ReadInt32(); MonoDefaultsStringOffset = reader.ReadInt32(); MonoDefaultsEnumOffset = reader.ReadInt32(); MonoDefaultsArrayOffset = reader.ReadInt32(); MonoDefaultsDelegateOffset = reader.ReadInt32(); MonoDefaultsExceptionOffset = reader.ReadInt32(); MonoMethodKlassOffset = reader.ReadInt32(); MonoMethodTokenOffset = reader.ReadInt32(); MonoMethodFlagsOffset = reader.ReadInt32(); MonoMethodInflatedOffset = reader.ReadInt32(); MonoVTableKlassOffset = reader.ReadInt32(); MonoVTableVTableOffset = reader.ReadInt32(); }
StackFrame try_pthread_cond_timedwait(StackFrame frame, TargetMemoryAccess memory) { Symbol name = frame.Name; /* * This is a hack for pthread_cond_timedwait() on Red Hat 9. */ if ((name == null) || (name.Name != "pthread_cond_timedwait") || (name.Offset != 0xe5)) return null; /* * Disassemble some bytes of the method to find out whether * it's the "correct" one. */ uint data = (uint) memory.ReadInteger (name.Address); if (data != 0x53565755) return null; data = (uint) memory.ReadInteger (name.Address + 4); if (data != 0x14245c8b) return null; data = (uint) memory.ReadInteger (name.Address + 8); if (data != 0x1c246c8b) return null; data = (uint) memory.ReadInteger (frame.TargetAddress); if (data != 0x8910eb83) return null; data = (uint) memory.ReadInteger (frame.TargetAddress + 0x7b); if (data != 0x852cc483) return null; data = (uint) memory.ReadInteger (frame.TargetAddress + 0x7f); if (data != 0xc6440fc0) return null; TargetAddress esp = frame.StackPointer; Registers regs = new Registers (this); TargetAddress ebx = memory.ReadAddress (esp + 0x2c); TargetAddress esi = memory.ReadAddress (esp + 0x30); TargetAddress edi = memory.ReadAddress (esp + 0x34); TargetAddress ebp = memory.ReadAddress (esp + 0x38); TargetAddress eip = memory.ReadAddress (esp + 0x3c); regs [(int)X86_Register.RBX].SetValue (esp + 0x2c, ebx); regs [(int)X86_Register.RSI].SetValue (esp + 0x30, esi); regs [(int)X86_Register.RDI].SetValue (esp + 0x34, edi); regs [(int)X86_Register.RBP].SetValue (esp + 0x38, ebp); regs [(int)X86_Register.RIP].SetValue (esp + 0x3c, eip); esp += 0x40; regs [(int)X86_Register.RSP].SetValue (esp.Address); return CreateFrame (frame.Thread, FrameType.Normal, memory, eip, esp, ebp, regs); }
StackFrame unwind_method(StackFrame frame, TargetMemoryAccess memory, byte[] code, int pos, int offset) { Registers old_regs = frame.Registers; Registers regs = new Registers (old_regs); TargetAddress ebp = new TargetAddress ( memory.AddressDomain, old_regs [(int) X86_Register.RBP].GetValue ()); int addr_size = TargetAddressSize; TargetAddress new_ebp = memory.ReadAddress (ebp); regs [(int) X86_Register.RBP].SetValue (ebp, new_ebp); TargetAddress new_eip = memory.ReadAddress (ebp + addr_size); regs [(int) X86_Register.RIP].SetValue (ebp + addr_size, new_eip); TargetAddress new_esp = ebp + 2 * addr_size; regs [(int) X86_Register.RSP].SetValue (ebp, new_esp); regs [(int) X86_Register.RSI].Valid = true; regs [(int) X86_Register.RDI].Valid = true; ebp -= addr_size; int length = System.Math.Min (code.Length, offset); while (pos < length) { byte opcode = code [pos++]; if ((opcode < 0x50) || (opcode > 0x57)) break; long value; switch (opcode) { case 0x50: /* eax */ value = (long) (uint) memory.ReadInteger (ebp); regs [(int) X86_Register.RAX].SetValue (ebp, value); break; case 0x51: /* ecx */ value = (long) (uint) memory.ReadInteger (ebp); regs [(int) X86_Register.RCX].SetValue (ebp, value); break; case 0x52: /* edx */ value = (long) (uint) memory.ReadInteger (ebp); regs [(int) X86_Register.RDX].SetValue (ebp, value); break; case 0x53: /* ebx */ value = (long) (uint) memory.ReadInteger (ebp); regs [(int) X86_Register.RBX].SetValue (ebp, value); break; case 0x56: /* esi */ value = (long) (uint) memory.ReadInteger (ebp); regs [(int) X86_Register.RSI].SetValue (ebp, value); break; case 0x57: /* edi */ value = (long) (uint) memory.ReadInteger (ebp); regs [(int) X86_Register.RDI].SetValue (ebp, value); break; } ebp -= addr_size; } return CreateFrame (frame.Thread, FrameType.Normal, memory, new_eip, new_esp, new_ebp, regs); }
public MetadataInfo(TargetMemoryAccess memory, TargetAddress address) { int size = memory.ReadInteger (address); TargetBinaryReader reader = memory.ReadMemory (address, size).GetReader (); reader.ReadInt32 (); MonoDefaultsSize = reader.ReadInt32 (); MonoDefaultsAddress = new TargetAddress ( memory.AddressDomain, reader.ReadAddress ()); TypeSize = reader.ReadInt32 (); ArrayTypeSize = reader.ReadInt32 (); KlassSize = reader.ReadInt32 (); ThreadSize = reader.ReadInt32 (); ThreadTidOffset = reader.ReadInt32 (); ThreadStackPtrOffset = reader.ReadInt32 (); ThreadEndStackOffset = reader.ReadInt32 (); KlassImageOffset = reader.ReadInt32 (); KlassInstanceSizeOffset = reader.ReadInt32 (); KlassParentOffset = reader.ReadInt32 (); KlassTokenOffset = reader.ReadInt32 (); KlassFieldOffset = reader.ReadInt32 (); KlassMethodsOffset = reader.ReadInt32 (); KlassMethodCountOffset = reader.ReadInt32 (); KlassThisArgOffset = reader.ReadInt32 (); KlassByValArgOffset = reader.ReadInt32 (); KlassGenericClassOffset = reader.ReadInt32 (); KlassGenericContainerOffset = reader.ReadInt32 (); KlassVTableOffset = reader.ReadInt32 (); FieldInfoSize = reader.ReadInt32 (); FieldInfoTypeOffset = reader.ReadInt32 (); FieldInfoOffsetOffset = reader.ReadInt32 (); KlassFieldCountOffset = KlassMethodCountOffset - 8; MonoDefaultsCorlibOffset = reader.ReadInt32 (); MonoDefaultsObjectOffset = reader.ReadInt32 (); MonoDefaultsByteOffset = reader.ReadInt32 (); MonoDefaultsVoidOffset = reader.ReadInt32 (); MonoDefaultsBooleanOffset = reader.ReadInt32 (); MonoDefaultsSByteOffset = reader.ReadInt32 (); MonoDefaultsInt16Offset = reader.ReadInt32 (); MonoDefaultsUInt16Offset = reader.ReadInt32 (); MonoDefaultsInt32Offset = reader.ReadInt32 (); MonoDefaultsUInt32Offset = reader.ReadInt32 (); MonoDefaultsIntOffset = reader.ReadInt32 (); MonoDefaultsUIntOffset = reader.ReadInt32 (); MonoDefaultsInt64Offset = reader.ReadInt32 (); MonoDefaultsUInt64Offset = reader.ReadInt32 (); MonoDefaultsSingleOffset = reader.ReadInt32 (); MonoDefaultsDoubleOffset = reader.ReadInt32 (); MonoDefaultsCharOffset = reader.ReadInt32 (); MonoDefaultsStringOffset = reader.ReadInt32 (); MonoDefaultsEnumOffset = reader.ReadInt32 (); MonoDefaultsArrayOffset = reader.ReadInt32 (); MonoDefaultsDelegateOffset = reader.ReadInt32 (); MonoDefaultsExceptionOffset = reader.ReadInt32 (); MonoMethodKlassOffset = reader.ReadInt32 (); MonoMethodTokenOffset = reader.ReadInt32 (); MonoMethodFlagsOffset = reader.ReadInt32 (); MonoMethodInflatedOffset = reader.ReadInt32 (); MonoVTableKlassOffset = reader.ReadInt32 (); MonoVTableVTableOffset = reader.ReadInt32 (); }
// // MonoType // public MonoTypeEnum MonoTypeGetType(TargetMemoryAccess memory, TargetAddress type) { uint flags = (uint) memory.ReadInteger ( type + memory.TargetMemoryInfo.TargetAddressSize); return (MonoTypeEnum) ((flags & 0x00ff0000) >> 16); }
public bool MonoTypeGetIsByRef(TargetMemoryAccess memory, TargetAddress type) { uint flags = (uint) memory.ReadInteger ( type + memory.TargetMemoryInfo.TargetAddressSize); return (int) ((flags & 0x40000000) >> 30) != 0; }
public int MonoClassGetFieldOffset(TargetMemoryAccess memory, TargetAddress klass, int index) { int offset = index * MonoMetadataInfo.FieldInfoSize + MonoMetadataInfo.FieldInfoOffsetOffset; TargetAddress fields = memory.ReadAddress ( klass + MonoMetadataInfo.KlassFieldOffset); if (fields.IsNull) throw new TargetException (TargetError.ClassNotInitialized); return memory.ReadInteger (fields + offset); }
public MonoMethodSignature GetMethodSignature(MonoLanguageBackend mono, TargetMemoryAccess memory, TargetAddress signature) { int count = memory.ReadInteger (signature + 4) & 0x0000ffff; int offset = memory.TargetAddressSize == 8 ? 16 : 12; TargetAddress ret = memory.ReadAddress (signature + offset); TargetType ret_type = mono.ReadType (memory, ret); if (count == 0) return new MonoMethodSignature (ret_type, new TargetType [0]); offset += memory.TargetAddressSize; TargetReader reader = new TargetReader ( memory.ReadMemory (signature + offset, count * memory.TargetAddressSize)); TargetType[] param_types = new TargetType [count]; for (int i = 0; i < count; i++) param_types [i] = mono.ReadType (memory, reader.ReadAddress ()); return new MonoMethodSignature (ret_type, param_types); }
public int MonoClassGetFieldCount(TargetMemoryAccess memory, TargetAddress klass) { return memory.ReadInteger (klass + MonoMetadataInfo.KlassFieldCountOffset); }
Method read_range_entry(TargetMemoryAccess target, TargetAddress address) { int size = target.ReadInteger (address); TargetReader reader = new TargetReader (target.ReadMemory (address, size)); byte[] contents = reader.BinaryReader.PeekBuffer (size); reader.BinaryReader.ReadInt32 (); int file_idx = reader.BinaryReader.ReadInt32 (); MonoSymbolFile file = (MonoSymbolFile) symfile_by_index [file_idx]; return file.ReadRangeEntry (target, reader, contents); }
StackFrame unwind_method(StackFrame frame, TargetMemoryAccess memory, byte[] code, int pos, int offset) { Registers old_regs = frame.Registers; Registers regs = new Registers(old_regs); TargetAddress ebp = new TargetAddress( memory.AddressDomain, old_regs [(int)X86_Register.RBP].GetValue()); int addr_size = TargetAddressSize; TargetAddress new_ebp = memory.ReadAddress(ebp); regs [(int)X86_Register.RBP].SetValue(ebp, new_ebp); TargetAddress new_eip = memory.ReadAddress(ebp + addr_size); regs [(int)X86_Register.RIP].SetValue(ebp + addr_size, new_eip); TargetAddress new_esp = ebp + 2 * addr_size; regs [(int)X86_Register.RSP].SetValue(ebp, new_esp); regs [(int)X86_Register.RSI].Valid = true; regs [(int)X86_Register.RDI].Valid = true; ebp -= addr_size; int length = System.Math.Min(code.Length, offset); while (pos < length) { byte opcode = code [pos++]; if ((opcode < 0x50) || (opcode > 0x57)) { break; } long value; switch (opcode) { case 0x50: /* eax */ value = (long)(uint)memory.ReadInteger(ebp); regs [(int)X86_Register.RAX].SetValue(ebp, value); break; case 0x51: /* ecx */ value = (long)(uint)memory.ReadInteger(ebp); regs [(int)X86_Register.RCX].SetValue(ebp, value); break; case 0x52: /* edx */ value = (long)(uint)memory.ReadInteger(ebp); regs [(int)X86_Register.RDX].SetValue(ebp, value); break; case 0x53: /* ebx */ value = (long)(uint)memory.ReadInteger(ebp); regs [(int)X86_Register.RBX].SetValue(ebp, value); break; case 0x56: /* esi */ value = (long)(uint)memory.ReadInteger(ebp); regs [(int)X86_Register.RSI].SetValue(ebp, value); break; case 0x57: /* edi */ value = (long)(uint)memory.ReadInteger(ebp); regs [(int)X86_Register.RDI].SetValue(ebp, value); break; } ebp -= addr_size; } return(CreateFrame(frame.Thread, FrameType.Normal, memory, new_eip, new_esp, new_ebp, regs)); }
public int MonoClassGetToken(TargetMemoryAccess memory, TargetAddress klass) { return memory.ReadInteger (klass + MonoMetadataInfo.KlassTokenOffset); }
StackFrame try_pthread_cond_timedwait(StackFrame frame, TargetMemoryAccess memory) { Symbol name = frame.Name; /* * This is a hack for pthread_cond_timedwait() on Red Hat 9. */ if ((name == null) || (name.Name != "pthread_cond_timedwait") || (name.Offset != 0xe5)) { return(null); } /* * Disassemble some bytes of the method to find out whether * it's the "correct" one. */ uint data = (uint)memory.ReadInteger(name.Address); if (data != 0x53565755) { return(null); } data = (uint)memory.ReadInteger(name.Address + 4); if (data != 0x14245c8b) { return(null); } data = (uint)memory.ReadInteger(name.Address + 8); if (data != 0x1c246c8b) { return(null); } data = (uint)memory.ReadInteger(frame.TargetAddress); if (data != 0x8910eb83) { return(null); } data = (uint)memory.ReadInteger(frame.TargetAddress + 0x7b); if (data != 0x852cc483) { return(null); } data = (uint)memory.ReadInteger(frame.TargetAddress + 0x7f); if (data != 0xc6440fc0) { return(null); } TargetAddress esp = frame.StackPointer; Registers regs = new Registers(this); TargetAddress ebx = memory.ReadAddress(esp + 0x2c); TargetAddress esi = memory.ReadAddress(esp + 0x30); TargetAddress edi = memory.ReadAddress(esp + 0x34); TargetAddress ebp = memory.ReadAddress(esp + 0x38); TargetAddress eip = memory.ReadAddress(esp + 0x3c); regs [(int)X86_Register.RBX].SetValue(esp + 0x2c, ebx); regs [(int)X86_Register.RSI].SetValue(esp + 0x30, esi); regs [(int)X86_Register.RDI].SetValue(esp + 0x34, edi); regs [(int)X86_Register.RBP].SetValue(esp + 0x38, ebp); regs [(int)X86_Register.RIP].SetValue(esp + 0x3c, eip); esp += 0x40; regs [(int)X86_Register.RSP].SetValue(esp.Address); return(CreateFrame(frame.Thread, FrameType.Normal, memory, eip, esp, ebp, regs)); }
// // The following API is new in `terrania'. // public GenericClassInfo GetGenericClass(TargetMemoryAccess memory, TargetAddress address) { int addr_size = memory.TargetMemoryInfo.TargetAddressSize; TargetReader reader = new TargetReader (memory.ReadMemory (address, 5 * addr_size)); TargetAddress container = reader.ReadAddress (); TargetAddress class_inst = reader.ReadAddress (); reader.ReadAddress (); /* method_inst */ reader.ReadAddress (); TargetAddress cached_class = reader.ReadAddress (); int inst_id = memory.ReadInteger (class_inst); int inst_data = memory.ReadInteger (class_inst + 4); TargetAddress inst_argv; if (MonoDebuggerInfo.MajorVersion == 80) inst_argv = memory.ReadAddress (class_inst + 8); else inst_argv = class_inst + 8; int type_argc = inst_data & 0x3fffff; TargetReader argv_reader = new TargetReader ( memory.ReadMemory (inst_argv, type_argc * addr_size)); TargetAddress[] type_args = new TargetAddress [type_argc]; for (int i = 0; i < type_argc; i++) type_args [i] = argv_reader.ReadAddress (); TargetAddress cached_class_ptr = address + 4 * addr_size; return new GenericClassInfo (container, type_args, cached_class_ptr, cached_class); }