Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Quincy379
jadx
提交
6b3e8f08
J
jadx
项目概览
Quincy379
/
jadx
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jadx
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6b3e8f08
编写于
10月 29, 2018
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(gui): override settings by cmd options
上级
bc629337
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
145 addition
and
81 deletion
+145
-81
jadx-cli/src/main/java/jadx/cli/JCommanderWrapper.java
jadx-cli/src/main/java/jadx/cli/JCommanderWrapper.java
+105
-0
jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java
jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java
+14
-79
jadx-cli/src/test/java/jadx/cli/JadxCLIArgsTest.java
jadx-cli/src/test/java/jadx/cli/JadxCLIArgsTest.java
+25
-1
jadx-gui/src/main/java/jadx/gui/JadxGUI.java
jadx-gui/src/main/java/jadx/gui/JadxGUI.java
+1
-1
未找到文件。
jadx-cli/src/main/java/jadx/cli/JCommanderWrapper.java
0 → 100644
浏览文件 @
6b3e8f08
package
jadx.cli
;
import
java.io.PrintStream
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
com.beust.jcommander.JCommander
;
import
com.beust.jcommander.ParameterDescription
;
import
com.beust.jcommander.ParameterException
;
import
com.beust.jcommander.Parameterized
;
import
jadx.api.JadxDecompiler
;
public
class
JCommanderWrapper
<
T
>
{
private
final
JCommander
jc
;
public
JCommanderWrapper
(
T
obj
)
{
this
.
jc
=
JCommander
.
newBuilder
().
addObject
(
obj
).
build
();
}
public
boolean
parse
(
String
[]
args
)
{
try
{
jc
.
parse
(
args
);
return
true
;
}
catch
(
ParameterException
e
)
{
System
.
err
.
println
(
"Arguments parse error: "
+
e
.
getMessage
());
printUsage
();
return
false
;
}
}
public
void
overrideProvided
(
T
obj
)
{
List
<
ParameterDescription
>
fieldsParams
=
jc
.
getParameters
();
List
<
ParameterDescription
>
parameters
=
new
ArrayList
<>(
1
+
fieldsParams
.
size
());
parameters
.
add
(
jc
.
getMainParameterValue
());
parameters
.
addAll
(
fieldsParams
);
for
(
ParameterDescription
parameter
:
parameters
)
{
if
(
parameter
.
isAssigned
())
{
// copy assigned field value to obj
Parameterized
parameterized
=
parameter
.
getParameterized
();
Object
val
=
parameterized
.
get
(
parameter
.
getObject
());
parameterized
.
set
(
obj
,
val
);
}
}
}
public
void
printUsage
()
{
// print usage in not sorted fields order (by default its sorted by description)
PrintStream
out
=
System
.
out
;
out
.
println
();
out
.
println
(
"jadx - dex to java decompiler, version: "
+
JadxDecompiler
.
getVersion
());
out
.
println
();
out
.
println
(
"usage: jadx [options] "
+
jc
.
getMainParameterDescription
());
out
.
println
(
"options:"
);
List
<
ParameterDescription
>
params
=
jc
.
getParameters
();
Map
<
String
,
ParameterDescription
>
paramsMap
=
new
LinkedHashMap
<>(
params
.
size
());
int
maxNamesLen
=
0
;
for
(
ParameterDescription
p
:
params
)
{
paramsMap
.
put
(
p
.
getParameterized
().
getName
(),
p
);
int
len
=
p
.
getNames
().
length
();
if
(
len
>
maxNamesLen
)
{
maxNamesLen
=
len
;
}
}
JadxCLIArgs
args
=
new
JadxCLIArgs
();
Field
[]
fields
=
args
.
getClass
().
getDeclaredFields
();
for
(
Field
f
:
fields
)
{
String
name
=
f
.
getName
();
ParameterDescription
p
=
paramsMap
.
get
(
name
);
if
(
p
==
null
)
{
continue
;
}
StringBuilder
opt
=
new
StringBuilder
();
opt
.
append
(
" "
).
append
(
p
.
getNames
());
addSpaces
(
opt
,
maxNamesLen
-
opt
.
length
()
+
3
);
opt
.
append
(
"- "
).
append
(
p
.
getDescription
());
addDefaultValue
(
args
,
f
,
opt
);
out
.
println
(
opt
);
}
out
.
println
(
"Example:"
);
out
.
println
(
" jadx -d out classes.dex"
);
}
private
void
addDefaultValue
(
JadxCLIArgs
args
,
Field
f
,
StringBuilder
opt
)
{
Class
<?>
fieldType
=
f
.
getType
();
if
(
fieldType
==
int
.
class
)
{
try
{
int
val
=
f
.
getInt
(
args
);
opt
.
append
(
" (default: "
).
append
(
val
).
append
(
")"
);
}
catch
(
Exception
e
)
{
// ignore
}
}
}
private
static
void
addSpaces
(
StringBuilder
str
,
int
count
)
{
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
str
.
append
(
' '
);
}
}
}
jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java
浏览文件 @
6b3e8f08
package
jadx.cli
;
import
java.io.PrintStream
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
ch.qos.logback.classic.spi.ILoggingEvent
;
import
ch.qos.logback.core.Appender
;
import
com.beust.jcommander.JCommander
;
import
com.beust.jcommander.Parameter
;
import
com.beust.jcommander.ParameterDescription
;
import
com.beust.jcommander.ParameterException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -94,27 +87,26 @@ public class JadxCLIArgs {
protected
boolean
printHelp
=
false
;
public
boolean
processArgs
(
String
[]
args
)
{
return
parse
(
args
)
&&
process
();
JCommanderWrapper
<
JadxCLIArgs
>
jcw
=
new
JCommanderWrapper
<>(
this
);
return
jcw
.
parse
(
args
)
&&
process
(
jcw
);
}
private
boolean
parse
(
String
[]
args
)
{
try
{
makeJCommander
().
parse
(
args
);
return
true
;
}
catch
(
ParameterException
e
)
{
System
.
err
.
println
(
"Arguments parse error: "
+
e
.
getMessage
());
printUsage
();
/**
* Set values only for options provided in cmd.
* Used to merge saved options and options passed in command line.
*/
public
boolean
overrideProvided
(
String
[]
args
)
{
JCommanderWrapper
<
JadxCLIArgs
>
jcw
=
new
JCommanderWrapper
<>(
new
JadxCLIArgs
());
if
(!
jcw
.
parse
(
args
))
{
return
false
;
}
jcw
.
overrideProvided
(
this
);
return
process
(
jcw
);
}
private
JCommander
makeJCommander
()
{
return
JCommander
.
newBuilder
().
addObject
(
this
).
build
();
}
private
boolean
process
()
{
private
boolean
process
(
JCommanderWrapper
jcw
)
{
if
(
printHelp
)
{
printUsage
();
jcw
.
printUsage
();
return
false
;
}
if
(
printVersion
)
{
...
...
@@ -136,69 +128,12 @@ public class JadxCLIArgs {
}
}
catch
(
JadxException
e
)
{
System
.
err
.
println
(
"ERROR: "
+
e
.
getMessage
());
printUsage
();
jcw
.
printUsage
();
return
false
;
}
return
true
;
}
public
void
printUsage
()
{
JCommander
jc
=
makeJCommander
();
// print usage in not sorted fields order (by default its sorted by description)
PrintStream
out
=
System
.
out
;
out
.
println
();
out
.
println
(
"jadx - dex to java decompiler, version: "
+
JadxDecompiler
.
getVersion
());
out
.
println
();
out
.
println
(
"usage: jadx [options] "
+
jc
.
getMainParameterDescription
());
out
.
println
(
"options:"
);
List
<
ParameterDescription
>
params
=
jc
.
getParameters
();
Map
<
String
,
ParameterDescription
>
paramsMap
=
new
LinkedHashMap
<>(
params
.
size
());
int
maxNamesLen
=
0
;
for
(
ParameterDescription
p
:
params
)
{
paramsMap
.
put
(
p
.
getParameterized
().
getName
(),
p
);
int
len
=
p
.
getNames
().
length
();
if
(
len
>
maxNamesLen
)
{
maxNamesLen
=
len
;
}
}
JadxCLIArgs
args
=
new
JadxCLIArgs
();
Field
[]
fields
=
args
.
getClass
().
getDeclaredFields
();
for
(
Field
f
:
fields
)
{
String
name
=
f
.
getName
();
ParameterDescription
p
=
paramsMap
.
get
(
name
);
if
(
p
==
null
)
{
continue
;
}
StringBuilder
opt
=
new
StringBuilder
();
opt
.
append
(
" "
).
append
(
p
.
getNames
());
addSpaces
(
opt
,
maxNamesLen
-
opt
.
length
()
+
3
);
opt
.
append
(
"- "
).
append
(
p
.
getDescription
());
addDefaultValue
(
args
,
f
,
opt
);
out
.
println
(
opt
);
}
out
.
println
(
"Example:"
);
out
.
println
(
" jadx -d out classes.dex"
);
}
private
void
addDefaultValue
(
JadxCLIArgs
args
,
Field
f
,
StringBuilder
opt
)
{
Class
<?>
fieldType
=
f
.
getType
();
if
(
fieldType
==
int
.
class
)
{
try
{
int
val
=
f
.
getInt
(
args
);
opt
.
append
(
" (default: "
).
append
(
val
).
append
(
")"
);
}
catch
(
Exception
e
)
{
// ignore
}
}
}
private
static
void
addSpaces
(
StringBuilder
str
,
int
count
)
{
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
str
.
append
(
' '
);
}
}
public
JadxArgs
toJadxArgs
()
{
JadxArgs
args
=
new
JadxArgs
();
args
.
setInputFiles
(
files
.
stream
().
map
(
FileUtils:
:
toFile
).
collect
(
Collectors
.
toList
()));
...
...
jadx-cli/src/test/java/jadx/cli/JadxCLIArgsTest.java
浏览文件 @
6b3e8f08
...
...
@@ -30,11 +30,35 @@ public class JadxCLIArgsTest {
assertThat
(
parse
(
""
).
isSkipSources
(),
is
(
false
));
}
@Test
public
void
testOptionsOverride
()
{
assertThat
(
override
(
new
JadxCLIArgs
(),
"--no-imports"
).
isUseImports
(),
is
(
false
));
assertThat
(
override
(
new
JadxCLIArgs
(),
""
).
isUseImports
(),
is
(
true
));
JadxCLIArgs
args
=
new
JadxCLIArgs
();
args
.
useImports
=
false
;
assertThat
(
override
(
args
,
"--no-imports"
).
isUseImports
(),
is
(
false
));
args
=
new
JadxCLIArgs
();
args
.
useImports
=
false
;
assertThat
(
override
(
args
,
""
).
isUseImports
(),
is
(
false
));
}
private
JadxCLIArgs
parse
(
String
...
args
)
{
JadxCLIArgs
jadxArgs
=
new
JadxCLIArgs
();
return
parse
(
new
JadxCLIArgs
(),
args
);
}
private
JadxCLIArgs
parse
(
JadxCLIArgs
jadxArgs
,
String
...
args
)
{
boolean
res
=
jadxArgs
.
processArgs
(
args
);
assertThat
(
res
,
is
(
true
));
LOG
.
info
(
"Jadx args: {}"
,
jadxArgs
.
toJadxArgs
());
return
jadxArgs
;
}
private
JadxCLIArgs
override
(
JadxCLIArgs
jadxArgs
,
String
...
args
)
{
boolean
res
=
jadxArgs
.
overrideProvided
(
args
);
assertThat
(
res
,
is
(
true
));
LOG
.
info
(
"Jadx args: {}"
,
jadxArgs
.
toJadxArgs
());
return
jadxArgs
;
}
}
jadx-gui/src/main/java/jadx/gui/JadxGUI.java
浏览文件 @
6b3e8f08
...
...
@@ -19,7 +19,7 @@ public class JadxGUI {
LogCollector
.
register
();
final
JadxSettings
settings
=
JadxSettingsAdapter
.
load
();
// overwrite loaded settings by command line arguments
if
(!
settings
.
processArgs
(
args
))
{
if
(!
settings
.
overrideProvided
(
args
))
{
return
;
}
if
(!
tryDefaultLookAndFeel
())
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录