public static unsafe void Decode(CodeInfo nci, DecodedResult dr) { _CodeInfo * ci = null; _DecodedInst *insts = null; var gch = new GCHandle(); uint usedInstructionsCount = 0; try { if ((ci = AcquireCodeInfoStruct(nci, out gch)) == null) { throw new OutOfMemoryException(); } var maxInstructions = dr.MaxInstructions; if ((insts = (_DecodedInst *)Malloc(maxInstructions * sizeof(_DecodedInst))) == null) { throw new OutOfMemoryException(); } distorm_decode64(ci->codeOffset, ci->code, ci->codeLen, ci->dt, insts, (uint)maxInstructions, &usedInstructionsCount); var dinsts = new DecodedInst[usedInstructionsCount]; for (var i = 0; i < usedInstructionsCount; i++) { dinsts[i] = CreateDecodedInstObj(&insts[i]); } dr.Instructions = dinsts; } finally { /* In case of an error, jInsts will get cleaned automatically. */ if (gch.IsAllocated) { gch.Free(); } if (ci != null) { Free(ci); } if (insts != null) { Free(insts); } } }
public static unsafe void Decode(CodeInfo nci, DecodedResult dr) { _CodeInfo* ci = null; _DecodedInst* insts = null; var gch = new GCHandle(); uint usedInstructionsCount = 0; try { if ((ci = AcquireCodeInfoStruct(nci, out gch)) == null) throw new OutOfMemoryException(); var maxInstructions = dr.MaxInstructions; if ((insts = (_DecodedInst*) Malloc(maxInstructions*sizeof (_DecodedInst))) == null) throw new OutOfMemoryException(); distorm_decode64(ci->codeOffset, ci->code, ci->codeLen, ci->dt, insts, (uint) maxInstructions, &usedInstructionsCount); var dinsts = new DecodedInst[usedInstructionsCount]; for (var i = 0; i < usedInstructionsCount; i++) dinsts[i] = CreateDecodedInstObj(&insts[i]); dr.Instructions = dinsts; } finally { /* In case of an error, jInsts will get cleaned automatically. */ if (gch.IsAllocated) gch.Free(); if (ci != null) Free(ci); if (insts != null) Free(insts); } }