Exemple #1
0
 private void DecorateDebugInfo(Instruction instr, DebugInfoHelper debugRecords, ulong baseInstrIP)
 {
     if (debugRecords != null)
     {
         InstructionInfoFactory factory = new InstructionInfoFactory();
         InstructionInfo        info    = factory.GetInfo(instr);
         ulong codeOffset = instr.IP - baseInstrIP;
         debugRecords.Update(codeOffset);
         Variable variable = null;
         foreach (UsedMemory usedMemInfo in info.GetUsedMemory())
         {
             string baseRegister = usedMemInfo.Base.ToString();
             int    displacement;
             unchecked
             { displacement = (int)usedMemInfo.Displacement; }
             Dictionary <int, Variable> offsetToVariableMap;
             if (debugRecords.registerRelativeVariables.TryGetValue(usedMemInfo.Base.ToString(), out offsetToVariableMap))
             {
                 if (offsetToVariableMap.TryGetValue(displacement, out variable))
                 {
                     output.Write($"; [{usedMemInfo.Base.ToString().ToLower()}{(displacement < 0 ? '-' : '+')}{Math.Abs(displacement):X}h] = {variable.Type} {variable.Index}");
                 }
             }
         }
         foreach (UsedRegister usedMemInfo in info.GetUsedRegisters())
         {
             if (debugRecords.registerVariables.TryGetValue(usedMemInfo.Register.ToString(), out variable))
             {
                 output.Write($"; {usedMemInfo.Register.ToString().ToLower()} = {variable.Type} {variable.Index}");
             }
         }
     }
 }
Exemple #2
0
 private void DecorateDebugInfo(Instruction instr, DebugInfoHelper debugRecords, ulong baseInstrIP)
 {
     if (debugRecords != null)
     {
         HashSet <Variable>     variables;
         InstructionInfoFactory factory = new InstructionInfoFactory();
         InstructionInfo        info    = factory.GetInfo(instr);
         ulong codeOffset = instr.IP - baseInstrIP;
         debugRecords.Update(codeOffset);
         foreach (UsedMemory usedMemInfo in info.GetUsedMemory())
         {
             string baseRegister = usedMemInfo.Base.ToString();
             int    displacement;
             unchecked
             { displacement = (int)usedMemInfo.Displacement; }
             Dictionary <int, HashSet <Variable> > offsetToVariableMap;
             if (debugRecords.registerRelativeVariables.TryGetValue(usedMemInfo.Base.ToString(), out offsetToVariableMap))
             {
                 if (offsetToVariableMap.TryGetValue(displacement, out variables))
                 {
                     output.Write($";");
                     foreach (Variable variable in variables)
                     {
                         output.Write($" [{usedMemInfo.Base.ToString().ToLower()}{(displacement < 0 ? '-' : '+')}{Math.Abs(displacement):X}h] = {variable.Type} {variable.Index}");
                     }
                 }
             }
         }
         foreach (UsedRegister usedMemInfo in info.GetUsedRegisters())
         {
             // TODO, if the code is accessing EAX but the debug info maps to RAX, then this match is going to fail.
             if (debugRecords.registerVariables.TryGetValue(usedMemInfo.Register.ToString(), out variables))
             {
                 output.Write($";");
                 foreach (Variable variable in variables)
                 {
                     output.Write($" {usedMemInfo.Register.ToString().ToLower()} = {variable.Type} {variable.Index}");
                 }
             }
         }
     }
 }