diff --git a/site/src/site/sphinx/en/mc.md b/site/src/site/sphinx/en/mc.md index 195418056..3cac0b960 100644 --- a/site/src/site/sphinx/en/mc.md +++ b/site/src/site/sphinx/en/mc.md @@ -20,3 +20,5 @@ mc -d /tmp/output /tmp/ClassA.java /tmp/ClassB.java ``` After compiling the `.class` file, you can use the [redefine](redefine.md) command to re-define the loaded classes in JVM. + +> Note that the mc command may fail. If the compilation fails, the `.class` file can be compiled locally and uploaded to the server. Refer to the [redefine](redefine.md) command description for details. \ No newline at end of file diff --git a/site/src/site/sphinx/en/redefine.md b/site/src/site/sphinx/en/redefine.md index c6f2b364b..1a1f89411 100644 --- a/site/src/site/sphinx/en/redefine.md +++ b/site/src/site/sphinx/en/redefine.md @@ -36,6 +36,26 @@ redefine /tmp/com/example/demo/arthas/user/UserController.class * `mc` command to compile the modified code * Load new bytecode with `redefine` command +### Tips for uploading .class files to the server + +The `mc` command may fail. You can modify the code locally, compile it, and upload it to the server. Some servers do not allow direct uploading files, you can use the `base64` command to bypass. + +1. Convert the `.class` file to base64 first, then save it as result.txt + + ```bash + Base64 < Test.class > result.txt + ``` + +2. Login the server, create and edit `result.txt`, copy the local content, paste and save + +3. Restore `result.txt` on the server to `.class` + + ``` + Base64 -d < result.txt > Test.class + ``` + +4. Use the md5 command to verify that the `.class` files are consistent. + ### Restrictions of the redefine command diff --git a/site/src/site/sphinx/mc.md b/site/src/site/sphinx/mc.md index 665d67364..af3a3f493 100644 --- a/site/src/site/sphinx/mc.md +++ b/site/src/site/sphinx/mc.md @@ -20,3 +20,5 @@ mc -d /tmp/output /tmp/ClassA.java /tmp/ClassB.java ``` 编译生成`.class`文件之后,可以结合[redefine](redefine.md)命令实现热更新代码。 + +> 注意,mc命令有可能失败。如果编译失败可以在本地编译好`.class`文件,再上传到服务器。具体参考[redefine](redefine.md)命令说明。 \ No newline at end of file diff --git a/site/src/site/sphinx/redefine.md b/site/src/site/sphinx/redefine.md index 6935e7121..b64c71e9b 100644 --- a/site/src/site/sphinx/redefine.md +++ b/site/src/site/sphinx/redefine.md @@ -37,6 +37,26 @@ redefine /tmp/com/example/demo/arthas/user/UserController.class * mc命令来内存编译修改过的代码 * 用redefine命令加载新的字节码 +### 上传 .class 文件到服务器的技巧 + +使用`mc`命令来编译`jad`的反编译的代码有可能失败。可以在本地修改代码,编译好后再上传到服务器上。有的服务器不允许直接上传文件,可以使用`base64`命令来绕过。 + +1. 在本地先转换`.class`文件为base64,再保存为result.txt + + ```bash + base64 < Test.class > result.txt + ``` + +2. 到服务器上,新建并编辑`result.txt`,复制本地的内容,粘贴再保存 + +3. 把服务器上的 `result.txt`还原为`.class` + + ``` + base64 -d < result.txt > Test.class + ``` + +4. 用md5命令计算哈希值,校验是否一致 + ### redefine的限制 * 不允许新增加field/method