-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental code to start java class reachability.
- Loading branch information
1 parent
71e372e
commit 5e4d60b
Showing
3 changed files
with
461 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"io" | ||
"log" | ||
"os" | ||
|
||
"github.com/google/osv-scanner/experimental/javareach" | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
for _, filename := range flag.Args() { | ||
reader, err := os.Open(filename) | ||
if err != nil { | ||
log.Printf("failed to open %s: %v", filename, err) | ||
continue | ||
} | ||
err = EnumerateReachability(reader) | ||
if err != nil { | ||
log.Printf("failed to enumerate reachability for %s: %v", filename, err) | ||
} | ||
} | ||
} | ||
|
||
// TODO: | ||
// - Transitively resolve dependencies and download dependent .jar files. | ||
// - Detect uses of reflection | ||
// - See if we should do a finer grained analysis to only consider referenced | ||
// classes where a method is called/referenced. | ||
func EnumerateReachability(r io.Reader) error { | ||
cf, err := javareach.ParseClass(r) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
thisClass, err := cf.ConstantPoolClass(int(cf.ThisClass)) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("this class: %s\n", thisClass) | ||
|
||
for i, cp := range cf.ConstantPool { | ||
if int(cf.ThisClass) == i { | ||
// Don't consider the this class itself. | ||
continue | ||
} | ||
|
||
if cp.Type() == javareach.ConstantKindClass { | ||
class, err := cf.ConstantPoolClass(i) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("class: %s\n", class) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/google/osv-scanner/experimental/javareach | ||
|
||
go 1.23 |
Oops, something went wrong.