private static unsafe DecodedInst CreateDecodedInstObj(_DecodedInst *inst) { return(new DecodedInst { Offset = inst->offset, Size = inst->size, Mnemonic = new String(inst->mnemonic.p), Operands = new String(inst->operands.p), Hex = new string(inst->instructionHex.p) }); }
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); } } }