@@ -72,7 +72,7 @@ function examineMemory() {
7272 }
7373 const pickedFile = ( file ) => {
7474 vscode . window . showInputBox ( { placeHolder : "Memory Location or Range" , validateInput : range => getMemoryRange ( range ) === undefined ? "Range must either be in format 0xF00-0xF01, 0xF100+32 or 0xABC154" : "" } ) . then ( range => {
75- vscode . commands . executeCommand ( "vscode.previewHtml" , vscode . Uri . parse ( "debugmemory://" + file + "#" + getMemoryRange ( range ) ) ) ;
75+ vscode . window . showTextDocument ( vscode . Uri . parse ( "debugmemory://" + file + "#" + getMemoryRange ( range ) ) ) ;
7676 } ) ;
7777 } ;
7878 if ( files . length == 1 )
@@ -89,7 +89,7 @@ function examineMemory() {
8989class MemoryContentProvider implements vscode . TextDocumentContentProvider {
9090 provideTextDocumentContent ( uri : vscode . Uri , token : vscode . CancellationToken ) : Thenable < string > {
9191 return new Promise ( ( resolve , reject ) => {
92- const conn = net . connect ( path . join ( os . tmpdir ( ) , "code-debug-sockets" , uri . authority ) ) ;
92+ const conn = net . connect ( path . join ( os . tmpdir ( ) , "code-debug-sockets" , uri . authority . toLowerCase ( ) ) ) ;
9393 let from , to ;
9494 let highlightAt = - 1 ;
9595 const splits = uri . fragment . split ( "&" ) ;
@@ -110,24 +110,38 @@ class MemoryContentProvider implements vscode.TextDocumentContentProvider {
110110 return reject ( "Negative Range" ) ;
111111 conn . write ( "examineMemory " + JSON . stringify ( [ from , to - from + 1 ] ) ) ;
112112 conn . once ( "data" , data => {
113- let formattedCode = "" ;
113+ let formattedCode = " 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n" ;
114+ var index : number = from ;
114115 const hexString = data . toString ( ) ;
115116 let x = 0 ;
116117 let asciiLine = "" ;
117118 let byteNo = 0 ;
118119 for ( let i = 0 ; i < hexString . length ; i += 2 ) {
120+ if ( x == 0 ) {
121+ var addr = index . toString ( 16 ) ;
122+ while ( addr . length < 16 ) addr = '0' + addr ;
123+ formattedCode += addr + " " ;
124+ }
125+ index ++ ;
126+
119127 const digit = hexString . substr ( i , 2 ) ;
120128 const digitNum = parseInt ( digit , 16 ) ;
121129 if ( digitNum >= 32 && digitNum <= 126 )
122130 asciiLine += String . fromCharCode ( digitNum ) ;
123131 else
124132 asciiLine += "." ;
133+
125134 if ( highlightAt == byteNo ) {
126- formattedCode += "<b> " + digit + "</b> " ;
127- } else
135+ formattedCode = formattedCode . slice ( 0 , - 1 ) + "[ " + digit + "] " ;
136+ } else {
128137 formattedCode += digit + " " ;
129- if ( ++ x > 16 ) {
130- formattedCode += asciiLine + "\n" ;
138+ }
139+
140+ if ( x == 7 )
141+ formattedCode += " " ;
142+
143+ if ( ++ x >= 16 ) {
144+ formattedCode += " " + asciiLine + "\n" ;
131145 x = 0 ;
132146 asciiLine = "" ;
133147 }
@@ -137,11 +151,25 @@ class MemoryContentProvider implements vscode.TextDocumentContentProvider {
137151 for ( let i = 0 ; i <= 16 - x ; i ++ ) {
138152 formattedCode += " " ;
139153 }
154+ if ( x >= 8 )
155+ formattedCode = formattedCode . slice ( 0 , - 2 ) ;
156+ else
157+ formattedCode = formattedCode . slice ( 0 , - 1 ) ;
140158 formattedCode += asciiLine ;
141159 }
142- resolve ( "<h2> Memory Range from 0x" + from . toString ( 16 ) + " to 0x" + to . toString ( 16 ) + "</h2><code><pre> " + formattedCode + "</pre></code>" ) ;
160+ resolve ( center ( " Memory Range from 0x" + from . toString ( 16 ) + " to 0x" + to . toString ( 16 ) , 84 ) + "\n\n " + formattedCode ) ;
143161 conn . destroy ( ) ;
144162 } ) ;
145163 } ) ;
146164 }
147165}
166+
167+ function center ( str : string , width : number ) : string {
168+ var left = true ;
169+ while ( str . length < width ) {
170+ if ( left ) str = ' ' + str ;
171+ else str = str + ' ' ;
172+ left = ! left ;
173+ }
174+ return str ;
175+ }
0 commit comments