Arthas之实例操作

1. 静态类属性操作

获取public静态属性

ognl -c 7cd84586 '@com.system.framework.ArtahsDemoClassLoader@pubTestPrex'
ognl -c 7cd84586 "@com.system.framework.ArtahsDemoClassLoader@pubfinalTestPrex"

输出各式 @Type[属性值],内容如下

@String[static public]
...
@String[final static public]

获取private静态属性

ognl -c 7cd84586 '@com.system.framework.ArtahsDemoClassLoader@privTestPrex'
ognl -c 7cd84586 '@com.system.framework.ArtahsDemoClassLoader@privFnalTestPrex'
@String[static private]
...
@String[final static private]

修改public静态属性,被final修饰,不能被修改

// author:herbert qq:464884492 date:20220331 测试代码想修改FINAL修饰符,结果没有成功
@Test
public void testModifyFinal() throws Exception {
Field finalField = this.getClass().getDeclaredField("privFnalTestPrex");
finalField.setAccessible(true);
System.out.println("==========初始值==========");
System.out.println(finalField.get(null));
Field modiField = Field.class.getDeclaredField("modifiers");
modiField.setAccessible(true);
modiField.setInt(finalField, finalField.getModifiers() & ~Modifier.FINAL);
finalField.set(null, "修改后FInal");
System.out.println("==========修改值==========");
System.out.println(privFnalTestPrex);
}

静态变量赋值,不能通过=直接赋值,需要采用反射的方式设置值

ognl '#c=@com.system.framework.ArtahsDemoClassLoader@class,#f=#c.getDeclaredField("pubTestPrex"),#f.set(#c,"modify static public ")'

修改private静态属性,需要在反射时调用方法setAccessible,使private特殊转化为public

ognl '#c=@com.system.framework.ArtahsDemoClassLoader@class,#f=#c.getDeclaredField("privTestPrex"),#f.setAccessible(true),#f.set(#c,"modify static private ")'

2. 静态类方法调用

静态方法调用和静态属性一样,格式为@class@method(args)

无参数调用

ognl -c 7cd84586 '@com.system.framework.ArtahsDemoClassLoader@setPublicStaticMethod()'
ognl -c 7cd84586 '@com.system.framework.ArtahsDemoClassLoader@modfiyPrivateStaticFiled()'
...
======第5次输出======
源文件初始输出==>static public/static private/testRefect--1/final static public/final static private
源文件初始输出==>static public/static private/testRefect--2/final static public/final static private
======第6次输出======
源文件初始输出==>modify by method static public/static private/testRefect--1/final static public/final static private
源文件初始输出==>modify by method static public/static private/testRefect--2/final static public/final static private
...
======第11次输出======
源文件初始输出==>modify by method static public/static private/testRefect--1/final static public/final static private
源文件初始输出==>modify by method static public/static private/testRefect--2/final static public/final static private
======第12次输出======
源文件初始输出==>modify by method static public/modify by method static private/testRefect--1/final static public/final static private
源文件初始输出==>modify by method static public/modify by method static private/testRefect--2/final static public/final static private
...
// author:herbert qq:464884492 date:20220331

有参数调用

ognl -c 7cd84586 '@com.system.framework.ArtahsDemoClassLoader@getPublicStaticMethod("input params")'
...
ognl -c 7cd84586 '@com.system.framework.ArtahsDemoClassLoader@getStaticPrivateMethod("input params")'
@String[input params <==> public static method return string]
...
@String[input params <==> private static method return string]

从以上的测试结果来说,静态方法不管是public还是private都可以直接调用。

3. 获取非静态类实例

查看某个类实例,无 --limit 参数默认10个

vmtool -c 3e2e18f2 -a getInstances --className *EncryptClass
vmtool -c 3e2e18f2 -a getInstances --className *EncryptClass --express 'instances.length'
vmtool -c 3e2e18f2 -a getInstances --className *EncryptClass --express 'instances[0]'
@EncryptClass[][
@EncryptClass[com.system.framework.EncryptClass@3c573d32],
@EncryptClass[com.system.framework.EncryptClass@68390fae],
]
...
@Integer[2]
...
@EncryptClass[
note=@String[testRefect--1],
]

经过上边测试发现,一个类存在多个classloader加载时,需要指定classloader。但从返回结果看,返回了所有classloader加载的实例

4. 实例方法调用

调用实例 getNotesetNote 方法

vmtool -c 3e2e18f2 -a getInstances --className *EncryptClass --express '#val=instances[0],#val.getNote()'
vmtool -c 3e2e18f2 -a getInstances --className *EncryptClass --express '#val=instances[0],#val.setNote("modify by instance"+#val.getNote())'
@String[testRefect--1]

======第7次输出======
源文件初始输出==>static public/static private/testRefect--1/final static public/final static private
源文件初始输出==>static public/static private/testRefect--2/final static public/final static private
======第8次输出======
源文件初始输出==>static public/static private/modify by instancetestRefect--1/final static public/final static private
源文件初始输出==>static public/static private/testRefect--2/final static public/final static private

从控制台输出结果,对比第7次和8次输出,我们可以发现第一个loader加载的class实例已经成功修改了

5. 实例属性操作

获取或者修改第一个实例 note 属性

vmtool -c 3e2e18f2 -a getInstances --className *EncryptClass --express '#val=instances[1].note'
vmtool -c 3e2e18f2 -a getInstances --className *EncryptClass --express '#val=instances[1],#val.note="modify by instance"+#val.note'
@String[testRefect--2]
...
======第121次输出======
源文件初始输出==>static public/static private/modify by instancetestRefect--1/final static public/final static private
源文件初始输出==>static public/static private/testRefect--2/final static public/final static private
======第122次输出======
源文件初始输出==>static public/static private/modify by instancetestRefect--1/final static public/final static private
源文件初始输出==>static public/static private/modify by instancetestRefect--2/final static public/final static private

从控制台输出结果,对比第121次和122次输出,我们可以发现第二个loader加载的class实例已经成功修改了

6. 条件操作

返回的对象集合,可以做二次筛选投影操作,也可以带条件查询符合的数据

vmtool -c 3e2e18f2 -a getInstances --className *EncryptClass --express '#val=instances'
vmtool -c 3e2e18f2 -a getInstances --className *EncryptClass --express '#val=instances.{note}'
vmtool -c 3e2e18f2 -a getInstances --className *EncryptClass --express '#val=instances.{#this.note}'
vmtool -c 3e2e18f2 -a getInstances --className *EncryptClass --express '#val=instances.{? #this.note.indexOf("1")>0}.{note}'
@EncryptClass[][
@EncryptClass[com.system.framework.EncryptClass@52790e67],
@EncryptClass[com.system.framework.EncryptClass@822cf83],
]
...
@ArrayList[
@String[modify by instancetestRefect--1],
@String[modify by instancetestRefect--2],
]
...
@ArrayList[
@String[modify by instancetestRefect--1],
@String[modify by instancetestRefect--2],
]
...
@ArrayList[
@String[modify by instancetestRefect--1],
]

7. 总结

欢迎感兴趣的朋友关注我的订阅号“小院不小”,或点击下方二维码关注。我将多年开发中遇到的难点,以及一些有意思的功能,体会都会一一发布到我的订阅号中

Arthas之实例操作的更多相关文章

  1. [转]使用Xcode 4发布App 实例操作

    使用xcode 4发布app 实例操作是本文介绍的内容,不多说,我们直接进入话题. 1.iOS Provisioning Portal 和iTunes Connect 没有变,下载与安装.mobile ...

  2. Flashback Drop实例操作

    1.Flashback DropFlashback Drop 是从Oracle 10g 开始出现的,用于恢复用户误删除的对象(包括表,索引等), 这个技术依赖于Tablespace Recycle B ...

  3. 058——VUE中vue-router之实例操作新闻列表单页面应用与路由别名的使用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. 040——VUE中组件之组件间的数据参props的使用实例操作

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 034——VUE中表单控件处理之使用vue控制radio表单的实例操作

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. php5.4以上 mysqli 实例操作mysql 增,删,改,查

    <?php //php5.4以上 mysqli 实例操作mysql header("Content-type:text/html;charset=utf8"); $conn ...

  7. [Sqlite]--&gt;嵌入式数据库事务理解以及实例操作

    引子: 1. Sqlite在Windows.Linux 和 Mac OS X 上的安装过程 2,嵌入式数据库的安装.建库.建表.更新表结构以及数据导入导出等等具体过程记录 SQLite 事务(Tran ...

  8. 每天一个JavaScript实例-操作元素定位元素

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  9. Qt数据库 QSqlTableModel实例操作(转)

    本文介绍的是Qt数据库 QSqlTableModel实例操作,详细操作请先来看内容.与上篇内容衔接着,不顾本文也有关于上篇内容的链接. Qt数据库 QSqlTableModel实例操作是本文所介绍的内 ...

随机推荐

  1. HP 电脑 - Windows 10 如何设置虚拟内存

    HP 电脑 - Windows 10 如何设置虚拟内存(新)   适用于安装 Windows 10 系统的 HP 电脑 Windows 中运用了虚拟内存技术,即分出一部分硬盘空间来充当内存使用.当内存 ...

  2. Oracle数据库巡检

    转至:https://blog.51cto.com/sf1314/2123068 select inst_id,status,count(*) from gv$session group by ins ...

  3. 「BUAA OO Unit 1 HW1」面向测试小白的简易评测机

    「BUAA OO Unit 1 HW1」面向测试小白的简易评测机 声明:本评测机所使用数据生成来自郭鸿宇同学,这对本评测机非常重要 目录 「BUAA OO Unit 1 HW1」面向测试小白的简易评测 ...

  4. Pycharm:安装anaconda中没有的第三方库

    Pycharm需要用到的pyKriging第三方库库,但是下载了Anaconda后无法在Pycharm中搜到,之前还能搜到的,所以一定是因为Anaconda的原因,后来经过摸索,终于找到了解决问题的办 ...

  5. Azure KeyVault(四)另类在 .NET Core 上操作 Secrets 的类库方法-----Azure.Security.KeyVault.Secrets

    一,引言 上一篇文章我们在 .Net Core Web 项目中添加了 "Microsoft.Azure.KeyVault" 的 Nuget 包操作 Azure KeyVault 的 ...

  6. 《手把手教你》系列基础篇(七十三)-java+ selenium自动化测试-框架设计基础-TestNG实现启动不同浏览器(详解教程)

    1.简介 上一篇文章中,从TestNg的特点我们知道支持变量,那么我们这一篇就通过变量参数来启动不同的浏览器进行自动化测试.那么如何实现同时启动不同的浏览器对脚本进行测试,且听宏哥娓娓道来. 2.项目 ...

  7. 清华大学ucore操作系统课笔记

    操作系统 清华大学ucore操作系统课笔记 全文思维导图 1. 操作系统概述 1.1 什么是操作系统? 操作系统的定义 没有公认的精确定义 一个控制程序 一个系统软件 控制程序执行过程,防止错误和计算 ...

  8. 【AIA】培训感悟

    最主要一个感悟,有钱了一定要买香港的保险.存个100万,年薪30就行,先把这个做目标.

  9. BBS 项目(四)

    目录 BBS 项目(四) 首页布局 个人头像显示 个人站点路由设计 个人站点页面设计 base.html site.html 左侧过滤功能 404.html BBS 项目(四) 首页布局 <!D ...

  10. CVE-2017-7269(IIS远程代码执行)

    利用CVE-2017-7269让IIS向自己的msf反弹一个shell 漏洞编号:CVE2017-7269 服务器版本:Windows server 2003 中间件:IIS6.0 攻击工具:meta ...