这段代码如何生成十六进制值?
How this code makes that hex values?
谁能给我解释一下"in details"这段代码是如何生成一个如左图所示的 .cfg 文件的?我想改变它,让它变得像正确的那样?
setLastFileInTNM(getTnmInstalledPath(), getLastPath());
private void setLastFileInTNM(String TNMConfigFilePath, String fileTobeSetInTNM) throws Exception {
//fileTobeSetInTNM += " ";
File file = new File(TNMConfigFilePath);
char[] dt = fileTobeSetInTNM.toCharArray();
char[] data = readFile(file);
int offset = 145;
int length = fileTobeSetInTNM.length();
int j = 0;
for (int i = 145; i < offset + length; i++) {
if (j == dt.length) {
break;
}
data[i] = dt[j];
j++;
}
data[offset + length] = (char) 0;//for seprating the rest
writeToFile(data, file);
readFile(file);
}
此代码在.cfg 文件中写入一个地址。下图是在 notepad++ 中比较两个 .cfg 文件。左边的是上面的代码做的,我想改一下代码,让hex类型变成右边的样子。我应该如何更改密码?
右边的文字是
" D : \ M D S 8 3 1 0 . h e x "
,而左边的文字是
" D:\MDS 8310.hex 1 0 . h e x "
。
这表明原始文件中数据的编码是每个字符 16 位,将每个第二个字符保留为 space,而在左侧,您只需将每个字符复制为一个字节,从而得到文件名过于紧凑。如果你想以这种低级风格来做,只需添加行
data[++i] = 0x20;
行后:
data[i] = dt[j];
并将for循环的上限增加到offset + length * 2
我不明白为什么你的文件也在第 29 行和第 6 行被修改,但这可能取决于你的代码的其余部分。
谁能给我解释一下"in details"这段代码是如何生成一个如左图所示的 .cfg 文件的?我想改变它,让它变得像正确的那样?
setLastFileInTNM(getTnmInstalledPath(), getLastPath());
private void setLastFileInTNM(String TNMConfigFilePath, String fileTobeSetInTNM) throws Exception {
//fileTobeSetInTNM += " ";
File file = new File(TNMConfigFilePath);
char[] dt = fileTobeSetInTNM.toCharArray();
char[] data = readFile(file);
int offset = 145;
int length = fileTobeSetInTNM.length();
int j = 0;
for (int i = 145; i < offset + length; i++) {
if (j == dt.length) {
break;
}
data[i] = dt[j];
j++;
}
data[offset + length] = (char) 0;//for seprating the rest
writeToFile(data, file);
readFile(file);
}
此代码在.cfg 文件中写入一个地址。下图是在 notepad++ 中比较两个 .cfg 文件。左边的是上面的代码做的,我想改一下代码,让hex类型变成右边的样子。我应该如何更改密码?
右边的文字是
" D : \ M D S 8 3 1 0 . h e x "
,而左边的文字是
" D:\MDS 8310.hex 1 0 . h e x "
。
这表明原始文件中数据的编码是每个字符 16 位,将每个第二个字符保留为 space,而在左侧,您只需将每个字符复制为一个字节,从而得到文件名过于紧凑。如果你想以这种低级风格来做,只需添加行
data[++i] = 0x20;
行后:
data[i] = dt[j];
并将for循环的上限增加到offset + length * 2
我不明白为什么你的文件也在第 29 行和第 6 行被修改,但这可能取决于你的代码的其余部分。