diff --git a/_sources/mc.md.txt b/_sources/mc.md.txt index 665d67364..af3a3f493 100644 --- a/_sources/mc.md.txt +++ b/_sources/mc.md.txt @@ -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/_sources/redefine.md.txt b/_sources/redefine.md.txt index 6935e7121..b64c71e9b 100644 --- a/_sources/redefine.md.txt +++ b/_sources/redefine.md.txt @@ -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 diff --git a/en/_sources/mc.md.txt b/en/_sources/mc.md.txt index 195418056..3cac0b960 100644 --- a/en/_sources/mc.md.txt +++ b/en/_sources/mc.md.txt @@ -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/en/_sources/redefine.md.txt b/en/_sources/redefine.md.txt index c6f2b364b..1a1f89411 100644 --- a/en/_sources/redefine.md.txt +++ b/en/_sources/redefine.md.txt @@ -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/en/mc.html b/en/mc.html index 821c79e23..0d9efec67 100644 --- a/en/mc.html +++ b/en/mc.html @@ -210,6 +210,8 @@

After compiling the .class file, you can use the redefine 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 command description for details.
diff --git a/en/redefine.html b/en/redefine.html index 5fb36db3a..1191df8cf 100644 --- a/en/redefine.html +++ b/en/redefine.html @@ -112,6 +112,7 @@
  • Options
  • Usage
  • Use with the jad/mc command
  • +
  • Tips for uploading .class files to the server
  • Restrictions of the redefine command
  • @@ -249,6 +250,25 @@ redefine /tmp/com/example/demo/arthas/user/UserController.class
  • 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

      +
      Base64 < Test.class > result.txt
      +
      +
      +
    2. +
    3. Login the server, create and edit result.txt, copy the local content, paste and save

      +
    4. +
    5. Restore result.txt on the server to .class

      +
      Base64 -d < result.txt > Test.class
      +
      +
    6. +
    7. Use the md5 command to verify that the .class files are consistent.

      +
    8. +
    +

    Restrictions of the redefine command

    编译生成.class文件之后,可以结合redefine命令实现热更新代码。

    +
    +
    注意,mc命令有可能失败。如果编译失败可以在本地编译好.class文件,再上传到服务器。具体参考redefine命令说明。
    diff --git a/redefine.html b/redefine.html index b9c81f7fb..789481137 100644 --- a/redefine.html +++ b/redefine.html @@ -113,6 +113,7 @@
  • 参数说明
  • 使用参考
  • 结合 jad/mc 命令使用
  • +
  • 上传 .class 文件到服务器的技巧
  • redefine的限制
  • @@ -251,6 +252,25 @@ redefine /tmp/com/example/demo/arthas/user/UserController.class
  • 用redefine命令加载新的字节码
  • +
    +

    上传 .class 文件到服务器的技巧

    +

    使用mc命令来编译jad的反编译的代码有可能失败。可以在本地修改代码,编译好后再上传到服务器上。有的服务器不允许直接上传文件,可以使用base64命令来绕过。

    +
      +
    1. 在本地先转换.class文件为base64,再保存为result.txt

      +
      base64 < Test.class > result.txt
      +
      +
      +
    2. +
    3. 到服务器上,新建并编辑result.txt,复制本地的内容,粘贴再保存

      +
    4. +
    5. 把服务器上的 result.txt还原为.class

      +
      base64 -d < result.txt > Test.class
      +
      +
    6. +
    7. 用md5命令计算哈希值,校验是否一致

      +
    8. +
    +

    redefine的限制