Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cwe_checker
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-gitdep
cwe_checker
Commits
45ececd2
Commit
45ececd2
authored
4 years ago
by
Melvin Klimke
Committed by
Enkelmann
4 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parse Calling Convention Register from Ghidra (#87)
parent
945cbf90
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
123 additions
and
1 deletions
+123
-1
PcodeExtractor.java
ghidra/p_code_extractor/PcodeExtractor.java
+29
-0
ParseCspecContent.java
ghidra/p_code_extractor/internal/ParseCspecContent.java
+0
-0
PcodeBlockData.java
ghidra/p_code_extractor/internal/PcodeBlockData.java
+3
-0
RegisterConvention.java
ghidra/p_code_extractor/internal/RegisterConvention.java
+75
-0
Project.java
ghidra/p_code_extractor/term/Project.java
+16
-1
No files found.
ghidra/p_code_extractor/PcodeExtractor.java
View file @
45ececd2
import
java.io.FileNotFoundException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.regex.Matcher
;
...
...
@@ -10,6 +12,7 @@ import org.apache.commons.lang3.EnumUtils;
import
bil.*
;
import
term.*
;
import
internal.*
;
import
symbol.ExternSymbol
;
import
serializer.Serializer
;
import
ghidra.app.script.GhidraScript
;
...
...
@@ -20,6 +23,7 @@ import ghidra.program.model.block.CodeBlockIterator;
import
ghidra.program.model.block.CodeBlockReferenceIterator
;
import
ghidra.program.model.block.SimpleBlockModel
;
import
ghidra.program.model.lang.CompilerSpec
;
import
ghidra.program.model.lang.PrototypeModel
;
import
ghidra.program.model.lang.Register
;
import
ghidra.program.model.listing.Function
;
import
ghidra.program.model.listing.FunctionIterator
;
...
...
@@ -28,6 +32,7 @@ import ghidra.program.model.listing.Instruction;
import
ghidra.program.model.listing.InstructionIterator
;
import
ghidra.program.model.listing.Listing
;
import
ghidra.program.model.listing.Parameter
;
import
ghidra.program.model.listing.VariableStorage
;
import
ghidra.program.model.pcode.PcodeOp
;
import
ghidra.program.model.pcode.Varnode
;
import
ghidra.program.model.symbol.Symbol
;
...
...
@@ -574,6 +579,14 @@ public class PcodeExtractor extends GhidraScript {
project
.
setProgram
(
program
);
project
.
setStackPointerRegister
(
stackPointerVar
);
project
.
setCpuArch
(
cpuArch
);
try
{
HashMap
<
String
,
RegisterConvention
>
conventions
=
new
HashMap
<
String
,
RegisterConvention
>();
ParseCspecContent
.
parseSpecs
(
ghidraProgram
,
conventions
);
addParameterRegister
(
conventions
);
project
.
setRegisterConvention
(
new
ArrayList
<
RegisterConvention
>(
conventions
.
values
()));
}
catch
(
FileNotFoundException
e
)
{
System
.
out
.
println
(
e
);
}
return
project
;
}
...
...
@@ -1066,4 +1079,20 @@ public class PcodeExtractor extends GhidraScript {
return
""
;
}
/**
* Adds parameter register to the RegisterCallingConvention object
*/
protected
void
addParameterRegister
(
HashMap
<
String
,
RegisterConvention
>
conventions
)
{
PrototypeModel
[]
models
=
ghidraProgram
.
getCompilerSpec
().
getCallingConventions
();
for
(
PrototypeModel
model
:
models
)
{
String
cconv
=
model
.
getName
();
if
(
conventions
.
get
(
cconv
)
!=
null
)
{
ArrayList
<
String
>
parameters
=
conventions
.
get
(
cconv
).
getParameter
();
for
(
VariableStorage
storage
:
model
.
getPotentialInputRegisterStorage
(
ghidraProgram
))
{
parameters
.
add
(
storage
.
getRegister
().
getName
());
}
}
}
}
}
This diff is collapsed.
Click to expand it.
ghidra/p_code_extractor/internal/ParseCspecContent.java
0 → 100644
View file @
45ececd2
This diff is collapsed.
Click to expand it.
ghidra/p_code_extractor/PcodeBlockData.java
→
ghidra/p_code_extractor/
internal/
PcodeBlockData.java
View file @
45ececd2
package
internal
;
import
java.util.ArrayList
;
import
ghidra.program.model.listing.Instruction
;
...
...
This diff is collapsed.
Click to expand it.
ghidra/p_code_extractor/internal/RegisterConvention.java
0 → 100644
View file @
45ececd2
package
internal
;
import
java.util.ArrayList
;
import
com.google.gson.annotations.SerializedName
;
public
class
RegisterConvention
{
@SerializedName
(
"calling_convention"
)
private
String
cconv
;
@SerializedName
(
"parameter_register"
)
private
ArrayList
<
String
>
parameter
;
@SerializedName
(
"return_register"
)
private
ArrayList
<
String
>
return_
;
@SerializedName
(
"unaffected_register"
)
private
ArrayList
<
String
>
unaffected
;
@SerializedName
(
"killed_by_call_register"
)
private
ArrayList
<
String
>
killedByCall
;
public
RegisterConvention
()
{
this
.
setParameter
(
new
ArrayList
<
String
>());
this
.
setReturn
(
new
ArrayList
<
String
>());
this
.
setUnaffected
(
new
ArrayList
<
String
>());
this
.
setKilledByCall
(
new
ArrayList
<
String
>());
}
public
RegisterConvention
(
String
cconv
,
ArrayList
<
String
>
parameter
,
ArrayList
<
String
>
return_
,
ArrayList
<
String
>
unaffected
,
ArrayList
<
String
>
killedByCall
)
{
this
.
setCconv
(
cconv
);
this
.
setParameter
(
parameter
);
this
.
setReturn
(
return_
);
this
.
setUnaffected
(
unaffected
);
this
.
setKilledByCall
(
killedByCall
);
}
public
String
getCconv
()
{
return
cconv
;
}
public
void
setCconv
(
String
cconv
)
{
this
.
cconv
=
cconv
;
}
public
ArrayList
<
String
>
getParameter
()
{
return
parameter
;
}
public
void
setParameter
(
ArrayList
<
String
>
parameter
)
{
this
.
parameter
=
parameter
;
}
public
ArrayList
<
String
>
getReturn
()
{
return
return_
;
}
public
void
setReturn
(
ArrayList
<
String
>
return_
)
{
this
.
return_
=
return_
;
}
public
ArrayList
<
String
>
getUnaffected
()
{
return
unaffected
;
}
public
void
setUnaffected
(
ArrayList
<
String
>
unaffected
)
{
this
.
unaffected
=
unaffected
;
}
public
ArrayList
<
String
>
getKilledByCall
()
{
return
killedByCall
;
}
public
void
setKilledByCall
(
ArrayList
<
String
>
killedByCall
)
{
this
.
killedByCall
=
killedByCall
;
}
}
This diff is collapsed.
Click to expand it.
ghidra/p_code_extractor/term/Project.java
View file @
45ececd2
package
term
;
import
bil.Variable
;
import
internal.RegisterConvention
;
import
java.util.ArrayList
;
import
com.google.gson.annotations.SerializedName
;
public
class
Project
{
...
...
@@ -10,14 +14,17 @@ public class Project {
private
Variable
stackPointerRegister
;
@SerializedName
(
"cpu_architecture"
)
private
String
cpuArch
;
@SerializedName
(
"register_calling_convention"
)
private
ArrayList
<
RegisterConvention
>
conventions
;
public
Project
()
{
}
public
Project
(
Term
<
Program
>
program
,
String
cpuArch
,
Variable
stackPointerRegister
)
{
public
Project
(
Term
<
Program
>
program
,
String
cpuArch
,
Variable
stackPointerRegister
,
ArrayList
<
RegisterConvention
>
conventions
)
{
this
.
setProgram
(
program
);
this
.
setCpuArch
(
cpuArch
);
this
.
setStackPointerRegister
(
stackPointerRegister
);
this
.
setRegisterConvention
(
conventions
);
}
public
Term
<
Program
>
getProgram
()
{
...
...
@@ -43,4 +50,12 @@ public class Project {
public
void
setCpuArch
(
String
cpuArch
)
{
this
.
cpuArch
=
cpuArch
;
}
public
ArrayList
<
RegisterConvention
>
getRegisterConvention
()
{
return
conventions
;
}
public
void
setRegisterConvention
(
ArrayList
<
RegisterConvention
>
conventions
)
{
this
.
conventions
=
conventions
;
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment