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
6313165c
Commit
6313165c
authored
4 years ago
by
Melvin Klimke
Committed by
Enkelmann
4 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Indirect call flows (#96)
parent
514be103
master
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
7 deletions
+26
-7
PcodeExtractor.java
ghidra/p_code_extractor/PcodeExtractor.java
+26
-7
No files found.
ghidra/p_code_extractor/PcodeExtractor.java
View file @
6313165c
...
@@ -56,6 +56,7 @@ public class PcodeExtractor extends GhidraScript {
...
@@ -56,6 +56,7 @@ public class PcodeExtractor extends GhidraScript {
Term
<
Program
>
program
=
null
;
Term
<
Program
>
program
=
null
;
FunctionManager
funcMan
;
FunctionManager
funcMan
;
HashMap
<
String
,
Integer
>
functionEntryPoints
;
ghidra
.
program
.
model
.
listing
.
Program
ghidraProgram
;
ghidra
.
program
.
model
.
listing
.
Program
ghidraProgram
;
VarnodeContext
context
;
VarnodeContext
context
;
String
cpuArch
;
String
cpuArch
;
...
@@ -79,6 +80,8 @@ public class PcodeExtractor extends GhidraScript {
...
@@ -79,6 +80,8 @@ public class PcodeExtractor extends GhidraScript {
cpuArch
=
getCpuArchitecture
();
cpuArch
=
getCpuArchitecture
();
program
=
createProgramTerm
();
program
=
createProgramTerm
();
functionEntryPoints
=
new
HashMap
<
String
,
Integer
>();
setFunctionEntryPoints
();
Project
project
=
createProject
();
Project
project
=
createProject
();
program
=
iterateFunctions
(
simpleBM
,
listing
);
program
=
iterateFunctions
(
simpleBM
,
listing
);
...
@@ -91,6 +94,24 @@ public class PcodeExtractor extends GhidraScript {
...
@@ -91,6 +94,24 @@ public class PcodeExtractor extends GhidraScript {
/**
/**
* Adds all entry points of internal and external function to a global hash map
* This will later speed up the cast of indirect Calls.
*/
protected
void
setFunctionEntryPoints
()
{
// Add external symbols and internal function addresses to hash map
int
funcCounter
=
0
;
for
(
ExternSymbol
sym
:
program
.
getTerm
().
getExternSymbols
()){
functionEntryPoints
.
put
(
sym
.
getAddress
(),
funcCounter
);
funcCounter
++;
}
for
(
Function
func
:
funcMan
.
getFunctionsNoStubs
(
true
))
{
functionEntryPoints
.
put
(
func
.
getEntryPoint
().
toString
(),
funcCounter
);
funcCounter
++;
}
}
/**
*
*
* @return: CPU architecture as string.
* @return: CPU architecture as string.
*
*
...
@@ -998,13 +1019,11 @@ public class PcodeExtractor extends GhidraScript {
...
@@ -998,13 +1019,11 @@ public class PcodeExtractor extends GhidraScript {
* Resolves the target id for an indirect jump
* Resolves the target id for an indirect jump
*/
*/
protected
Tid
getTargetTid
(
Varnode
target
)
{
protected
Tid
getTargetTid
(
Varnode
target
)
{
if
(!
target
.
isRegister
()
&&
!
target
.
isUnique
())
{
Address
[]
flowDestinations
=
PcodeBlockData
.
instruction
.
getFlows
();
Reference
[]
referenced
=
ghidraProgram
.
getReferenceManager
().
getReferencesFrom
(
target
.
getAddress
());
if
(
flowDestinations
.
length
==
1
)
{
if
(
referenced
.
length
!=
0
)
{
for
(
Address
flow
:
flowDestinations
)
{
for
(
ExternSymbol
symbol
:
program
.
getTerm
().
getExternSymbols
())
{
if
(
functionEntryPoints
.
containsKey
(
flow
.
toString
())){
if
(
symbol
.
getAddress
().
equals
(
referenced
[
0
].
getToAddress
().
toString
()))
{
return
new
Tid
(
String
.
format
(
"sub_%s"
,
flow
.
toString
()),
flow
.
toString
());
return
symbol
.
getTid
();
}
}
}
}
}
}
}
...
...
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