@@ -130,26 +130,76 @@ CMDRESULT cbInstrMov(int argc, char* argv[])
130
130
dputs (" not enough arguments" );
131
131
return STATUS_ERROR;
132
132
}
133
- uint set_value = 0 ;
134
- if (!valfromstring (argv[2 ], &set_value))
133
+
134
+ String srcText = argv[2 ];
135
+ if (srcText[0 ] == ' #' && srcText[srcText.length () - 1 ] == ' #' ) // handle mov addr, #DATA#
135
136
{
136
- dprintf (" invalid src \" %s\"\n " , argv[2 ]);
137
- return STATUS_ERROR;
137
+ // do some checks on the data
138
+ String dataText = srcText.substr (1 , srcText.length () - 2 );
139
+ int len = (int )dataText.length ();
140
+ if (len % 2 )
141
+ {
142
+ dprintf (" invalid hex string \" %s\" (length not divisible by 2)\n " );
143
+ return STATUS_ERROR;
144
+ }
145
+ for (int i = 0 ; i < len; i++)
146
+ {
147
+ if (!isxdigit (dataText[i]))
148
+ {
149
+ dprintf (" invalid hex string \" %s\" (contains invalid characters)\n " , dataText.c_str ());
150
+ return STATUS_ERROR;
151
+ }
152
+ }
153
+ // Check the destination
154
+ uint dest;
155
+ if (!valfromstring (argv[1 ], &dest) || !memisvalidreadptr (fdProcessInfo->hProcess , dest))
156
+ {
157
+ dprintf (" invalid destination \" %s\"\n " , argv[1 ]);
158
+ return STATUS_ERROR;
159
+ }
160
+ // Convert text to byte array (very ugly)
161
+ Memory<unsigned char *> data (len / 2 );
162
+ for (int i = 0 , j = 0 ; i < len; i += 2 , j++)
163
+ {
164
+ char b[3 ] = " " ;
165
+ b[0 ] = dataText[i];
166
+ b[1 ] = dataText[i + 1 ];
167
+ int res = 0 ;
168
+ sscanf_s (b, " %X" , &res);
169
+ data[j] = res;
170
+ }
171
+ // Move data to destination
172
+ if (!memwrite (fdProcessInfo->hProcess , (void *)dest, data, data.size (), 0 ))
173
+ {
174
+ dprintf (" failed to write to " fhex" \n " , dest);
175
+ return STATUS_ERROR;
176
+ }
177
+ GuiUpdateAllViews (); // refresh disassembly/dump/etc
178
+ return STATUS_CONTINUE;
138
179
}
139
- bool isvar = false ;
140
- uint temp = 0 ;
141
- valfromstring (argv[1 ], &temp, true , false , 0 , &isvar, 0 );
142
- if (!isvar)
143
- isvar = vargettype (argv[1 ], 0 );
144
- if (!isvar or !valtostring (argv[1 ], &set_value, true ))
145
- {
146
- uint value;
147
- if (valfromstring (argv[1 ], &value)) // if the var is a value already it's an invalid destination
180
+ else
181
+ {
182
+ uint set_value = 0 ;
183
+ if (!valfromstring (srcText.c_str (), &set_value))
148
184
{
149
- dprintf (" invalid dest \" %s\"\n " , argv[1 ]);
185
+ dprintf (" invalid src \" %s\"\n " , argv[2 ]);
150
186
return STATUS_ERROR;
151
187
}
152
- varnew (argv[1 ], set_value, VAR_USER);
188
+ bool isvar = false ;
189
+ uint temp = 0 ;
190
+ valfromstring (argv[1 ], &temp, true , false , 0 , &isvar, 0 );
191
+ if (!isvar)
192
+ isvar = vargettype (argv[1 ], 0 );
193
+ if (!isvar or !valtostring (argv[1 ], &set_value, true ))
194
+ {
195
+ uint value;
196
+ if (valfromstring (argv[1 ], &value)) // if the var is a value already it's an invalid destination
197
+ {
198
+ dprintf (" invalid dest \" %s\"\n " , argv[1 ]);
199
+ return STATUS_ERROR;
200
+ }
201
+ varnew (argv[1 ], set_value, VAR_USER);
202
+ }
153
203
}
154
204
return STATUS_CONTINUE;
155
205
}
0 commit comments