@@ -85,13 +85,7 @@ public IEnumerable<DisassembledInstruction> DisassembleCode(IntPtr address, int
8585 break ;
8686 }
8787
88- yield return new DisassembledInstruction
89- {
90- Address = virtualAddress ,
91- Length = instruction . Length ,
92- Data = instruction . Data ,
93- Instruction = instruction . Instruction
94- } ;
88+ yield return new DisassembledInstruction ( ref instruction ) ;
9589
9690 eip += instruction . Length ;
9791 virtualAddress += instruction . Length ;
@@ -102,8 +96,8 @@ public IEnumerable<DisassembledInstruction> DisassembleCode(IntPtr address, int
10296 /// <param name="process">The process to read from.</param>
10397 /// <param name="address">The address of the code.</param>
10498 /// <param name="maxLength">The maximum maxLength of the code.</param>
105- /// <returns>A list of <see cref="DisassembledInstruction"/>.</returns>
106- public IEnumerable < DisassembledInstruction > RemoteDisassembleFunction ( RemoteProcess process , IntPtr address , int maxLength )
99+ /// <returns>A list of <see cref="DisassembledInstruction"/> which belong to the function .</returns>
100+ public IList < DisassembledInstruction > RemoteDisassembleFunction ( RemoteProcess process , IntPtr address , int maxLength )
107101 {
108102 Contract . Requires ( process != null ) ;
109103 Contract . Ensures ( Contract . Result < IEnumerable < DisassembledInstruction > > ( ) != null ) ;
@@ -116,8 +110,8 @@ public IEnumerable<DisassembledInstruction> RemoteDisassembleFunction(RemoteProc
116110 /// <summary>Disassembles the code in the given data.</summary>
117111 /// <param name="data">The data to disassemble.</param>
118112 /// <param name="virtualAddress">The virtual address of the code. This allows to decode instructions located anywhere in memory even if they are not at their original place.</param>
119- /// <returns>A list of <see cref="DisassembledInstruction"/>.</returns>
120- public IEnumerable < DisassembledInstruction > DisassembleFunction ( byte [ ] data , IntPtr virtualAddress )
113+ /// <returns>A list of <see cref="DisassembledInstruction"/> which belong to the function .</returns>
114+ public IList < DisassembledInstruction > DisassembleFunction ( byte [ ] data , IntPtr virtualAddress )
121115 {
122116 Contract . Requires ( data != null ) ;
123117 Contract . Ensures ( Contract . Result < IEnumerable < DisassembledInstruction > > ( ) != null ) ;
@@ -140,14 +134,27 @@ public IEnumerable<DisassembledInstruction> DisassembleFunction(byte[] data, Int
140134 /// <param name="address">The address of the code.</param>
141135 /// <param name="maxLength">The maxLength of the code.</param>
142136 /// <param name="virtualAddress">The virtual address of the code. This allows to decode instructions located anywhere in memory even if they are not at their original place.</param>
143- /// <returns>A list of <see cref="DisassembledInstruction"/>.</returns>
144- public IEnumerable < DisassembledInstruction > DisassembleFunction ( IntPtr address , int maxLength , IntPtr virtualAddress )
137+ /// <returns>A list of <see cref="DisassembledInstruction"/> which belong to the function .</returns>
138+ public IList < DisassembledInstruction > DisassembleFunction ( IntPtr address , int maxLength , IntPtr virtualAddress )
145139 {
146140 Contract . Ensures ( Contract . Result < IEnumerable < DisassembledInstruction > > ( ) != null ) ;
147141
142+ var instructions = new List < DisassembledInstruction > ( ) ;
143+
148144 // Read until first CC.
149- return DisassembleCode ( address , maxLength , virtualAddress )
150- . TakeWhile ( i => ! ( i . Length == 1 && i . Data [ 0 ] == 0xCC ) ) ;
145+ coreFunctions . DisassembleCode ( address , maxLength , virtualAddress , false , ( ref InstructionData data ) =>
146+ {
147+ if ( data . Length == 1 && data . Data [ 0 ] == 0xCC )
148+ {
149+ return false ;
150+ }
151+
152+ instructions . Add ( new DisassembledInstruction ( ref data ) ) ;
153+
154+ return true ;
155+ } ) ;
156+
157+ return instructions ;
151158 }
152159
153160 /// <summary>Tries to find and disassembles the instruction prior to the given address.</summary>
@@ -201,13 +208,7 @@ private DisassembledInstruction GetPreviousInstruction(IntPtr address, IntPtr vi
201208
202209 if ( currentAddress == address )
203210 {
204- return new DisassembledInstruction
205- {
206- Address = virtualAddress - instruction . Length ,
207- Length = instruction . Length ,
208- Data = instruction . Data ,
209- Instruction = instruction . Instruction
210- } ;
211+ return new DisassembledInstruction ( ref instruction ) ;
211212 }
212213 }
213214
@@ -274,13 +275,21 @@ public IntPtr RemoteGetFunctionStartAddress(RemoteProcess process, IntPtr addres
274275
275276 public class DisassembledInstruction
276277 {
277- public IntPtr Address ;
278- public int Length ;
279- public byte [ ] Data ;
280- public string Instruction ;
278+ public IntPtr Address { get ; set ; }
279+ public int Length { get ; set ; }
280+ public byte [ ] Data { get ; set ; }
281+ public string Instruction { get ; set ; }
281282
282283 public bool IsValid => Length > 0 ;
283284
285+ public DisassembledInstruction ( ref InstructionData data )
286+ {
287+ Address = data . Address ;
288+ Length = data . Length ;
289+ Data = data . Data ;
290+ Instruction = data . Instruction ;
291+ }
292+
284293 public override string ToString ( ) => $ "{ Address . ToString ( Constants . StringHexFormat ) } - { Instruction } ";
285294 }
286295}
0 commit comments