开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 8 Fork 3

dwing/sharecode

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
main
分支 (1)
main
main
分支 (1)
main
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
main
分支 (1)
main
sharecode
/
lua
/
classinfo.lua
sharecode
/
lua
/
classinfo.lua
classinfo.lua 7.22 KB
一键复制 编辑 原始数据 按行查看 历史
dwing 提交于 2024年09月20日 20:18 +08:00 . java,lua: add TestClassAPI.java and classinfo.lua
-- luajit classinfo.lua input.class
local error = error
local arg = arg
local string = string
local format = string.format
local concat = table.concat
local io = io
local write = io.write
local f = io.open(arg[1], "rb")
if not f then
error("can not open file:" .. arg[1])
return
end
local s = f:read "*a"
f:close()
local pos = 0
local function printinfo(...)
write(format("%06X: ", pos), format(...), "\n")
end
local function dumpbin(n)
local t = {}
for i = 1, n do
t[i] = format(i < n and "%02X " or "%02X", s:byte(pos + i))
end
return concat(t)
end
local function read1()
return s:byte(pos + 1)
end
local function read2be()
return s:byte(pos + 1) * 0x100 + s:byte(pos + 2)
end
local function read4be()
return s:byte(pos + 1) * 0x1000000 + s:byte(pos + 2) * 0x10000 + s:byte(pos + 3) * 0x100 + s:byte(pos + 4)
end
printinfo("magic[4]: %s", dumpbin(4)); pos = pos + 4 -- always CA FE BA BE
printinfo("minor_version[2]: %d", read2be()); pos = pos + 2 -- almost 0
printinfo("major_version[2]: %d", read2be()); pos = pos + 2 -- Java4/5/6/7/8: 48/49/50/51/52
local n = read2be()
printinfo("constant_pool_count[2]: %d(-1)", n); pos = pos + 2
local const = {}
local i = 1; while i < n do
-- CONSTANT_Utf8_info 1 len[2] + bytes[len](utf-8)
-- CONSTANT_Integer_info 3 v[4]
-- CONSTANT_Float_info 4 v[4]
-- CONSTANT_Long_info 5 v[8] (2 slots)
-- CONSTANT_Double_info 6 v[8] (2 slots)
-- CONSTANT_Class_info 7 index[2] 包含类或者接口全限定名的CONSTANT_Utf8_info表的索引
-- CONSTANT_String_info 8 index[2] 包含文字字符串值的CONSTANT_Utf8_info表的索引
-- CONSTANT_Fieldref_info 9 index[2] + index[2] 声明被引用字段的类或者接口的CONSTANT_Class_info入口的索引 提供了CONSTANT_NameAndType_info入口的索引,该入口提供了字段的简单名称以及描述符
-- CONSTANT_Methodref_info 10 index[2] + index[2] 声明被引用方法的类的CONSTANT_Class_info入口的索引 提供了CONSTANT_NameAndType_info入口的索引,该入口提供了方法的简单名称以及描述符
-- CONSTANT_InterfaceMethodref_info 11 index[2] + index[2] 声明被引用方法的接口的CONSTANT_Class_info入口的索引 提供了CONSTANT_NameAndType_info入口的索引,该入口提供了方法的简单名称以及描述符
-- CONSTANT_NameAndType_info 12 index[2] + index[2] 给出了CONSTANT_Utf8_info入口的索引,该入口给出了字段或者方法的名称 提供了CONSTANT_Utf8_info入口的索引,该入口提供了字段或者方法的描述符
-- CONSTANT_MethodHandle_info 15 type[1] + index[2]
-- CONSTANT_MethodType_info 16 index[2]
-- CONSTANT_Dynamic_info 17 index[2] + index[2]
-- CONSTANT_InvokeDynamic_info 18 index[2] + index[2]
-- CONSTANT_Module_info 19 index[2]
-- CONSTANT_Package_info 20 index[2]
local oldPos = pos
local t = read1(); pos = pos + 1
if t == 1 then
local len = read2be(); pos = pos + 2 + len
const[i] = s:sub(pos - len + 1, pos)
elseif t == 7 or t == 8 or t == 16 or t == 19 or t == 20 then
const[i] = read2be(); pos = pos + 2
elseif t == 15 then
local a = read1(); pos = pos + 1
local b = read2be(); pos = pos + 2
const[i] = format("%d, %d", a, b)
elseif t == 5 or t == 6 then
const[i] = dumpbin(8); pos = pos + 8
else
const[i] = read4be(); pos = pos + 4
end
local newPos = pos
pos = oldPos
printinfo(" [%5d] (%2d) %s", i, t, const[i])
pos = newPos
i = i + ((t == 5 or t == 6) and 2 or 1)
end
-- ACC_PUBLIC 0x0001 pubilc
-- ACC_PRIVATE 0x0002 private
-- ACC_PROTECTED 0x0004 protected
-- ACC_STATIC 0x0008 static
-- ACC_FINAL 0x0010 final
-- ACC_SUPER 0x0020 用于兼容早期编译器, 新编译器都设置该标记, 以在使用 invokespecial指令时对子类方法做特定处理。
-- ACC_BRIDGE 0x0040 bridge方法, 由编译器生成。
-- ACC_INTERFACE 0x0200 接口, 同时需要设置:ACC_ABSTRACT。不可同时设置:ACC_FINAL、ACC_SUPER、ACC_ENUM
-- ACC_ABSTRACT 0x0400 abstract
-- ACC_SYNTHETIC 0x1000 synthetic, 由编译器产生, 不存在于源代码中。
-- ACC_ANNOTATION 0x2000 注解类型(annotation), 需同时设置:ACC_INTERFACE、ACC_ABSTRACT
-- ACC_ENUM 0x4000 枚举类型
printinfo("access_flags[2]: 0x%04X", read2be(2)); pos = pos + 2
printinfo("this_class[2]: %d", read2be()); pos = pos + 2
printinfo("super_class[2]: %d", read2be()); pos = pos + 2
printinfo("interfaces_count[2]: %d", read2be()); pos = pos + 2
--TODO
-- u2 access_flag
-- ACC_VOLATILE 0x0040 volatile
-- ACC_TRANSIENT 0x0080 transient
-- u2 name_index 提供了给出字段简单名称(不是全限定名)的CONSTANT_Utf8_info入口的索引
-- u2 descriptor_index 提供了给出字段描述符的CONSTANT_Utf8_info入口的索引
-- u2 attributes_count
-- attribute_info attribute_info[attributes_count]
-- u2 attribute_name_index
-- u4 attribute_length
-- u1 bytes[attribute_length]
n = read2be(); pos = pos + 2
printinfo("fields_count[2]: %d", n)
for i = 1, n do
printinfo(" -access_flags[2]: 0x%04X", read2be(2)); pos = pos + 2
printinfo(" name_index[2]: %d", read2be()); pos = pos + 2
printinfo(" descriptor_index[2]: %d", read2be()); pos = pos + 2
local m = read2be(); pos = pos + 2
printinfo(" attributes_count[2]: %d", m)
if m > 0 then printinfo(" attribute_info:") end
for j = 1, m do
printinfo(" -attribute_name_index[2]: %d", read2be()); pos = pos + 2
local k = read4be(); pos = pos + 4
printinfo(" attribute_length[4]: %d", k)
printinfo(" info[%d]: %s", k, dumpbin(k)); pos = pos + k
end
end
-- u2 access_flag
-- ACC_SYNCHRONIZED0x0020 synchronized
-- ACC_VARARGS 0x0080 包含不定参数个数的方法。
-- ACC_NATIVE 0x0100 native
-- ACC_STRICT 0x0800 strictfp
-- u2 name_index 提供了给出字段简单名称(不是全限定名)的CONSTANT_Utf8_info入口的索引
-- u2 descriptor_index 提供了给出字段描述符的CONSTANT_Utf8_info入口的索引
-- u2 attributes_count
-- attribute_info attribute_info[attributes_count]
-- u2 attribute_name_index
-- u4 attribute_length
-- u1 bytes[attribute_length]
n = read2be(); pos = pos + 2
printinfo("methods_count[2]: %d", n)
for i = 1, n do
printinfo(" -access_flags[2]: 0x%04X", read2be(2)); pos = pos + 2
printinfo(" name_index[2]: %d", read2be()); pos = pos + 2
printinfo(" descriptor_index[2]: %d", read2be()); pos = pos + 2
local m = read2be(); pos = pos + 2
printinfo(" attributes_count[2]: %d", m)
if m > 0 then printinfo(" attribute_info:") end
for j = 1, m do
printinfo(" -attribute_name_index[2]: %d", read2be()); pos = pos + 2
local k = read4be(); pos = pos + 4
printinfo(" attribute_length[4]: %d", k)
printinfo(" info[%d]: %s", k, dumpbin(k)); pos = pos + k
end
end
-- u2 attribute_name_index 给出了包含属性名称的CONSTANT_Utf8入口的常量池中的索引
-- u4 attribute_length 给出了属性数据的长度(以字节计)
-- u1 info[attribute_length] 包含属性数据
n = read2be(); pos = pos + 2
printinfo("attribute_count[2]: %d", n)
if n > 0 then printinfo("attribute_info:") end
for i = 1, n do
local j = read2be(); pos = pos + 2
printinfo(" -attribute_name_index[2]: %d : %s", j, const[j])
local m = read4be(); pos = pos + 4
printinfo(" attribute_length[4]: %d", m)
printinfo(" info[%d]: %s", m, dumpbin(m)); pos = pos + m
end
printinfo("<END>")
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

分享个人编写的各种编程语言的短代码
暂无标签
MIT
使用 MIT 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
其他
1
https://gitee.com/dwing/sharecode.git
git@gitee.com:dwing/sharecode.git
dwing
sharecode
sharecode
main
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /