1+ package burp_hotpatch .scripts ;
2+ import java .util .HashMap ;
3+
4+ public class ScriptSharedMemory {
5+
6+ private HashMap <String ,String > strings ;
7+ private HashMap <String ,Integer > integers ;
8+ private HashMap <String ,Object > objects ;
9+
10+ private static ScriptSharedMemory INSTANCE ;
11+ public ScriptSharedMemory () {
12+ }
13+
14+ public static ScriptSharedMemory getInstance () {
15+ if (INSTANCE == null ) {
16+ INSTANCE = new ScriptSharedMemory ();
17+ INSTANCE .reset ();
18+ }
19+ return INSTANCE ;
20+ }
21+
22+ public void reset () {
23+ strings = new HashMap <>();
24+ integers = new HashMap <>();
25+ objects = new HashMap <>();
26+ }
27+
28+ public synchronized void setInt ( String name , int num ) {
29+ integers .put (name ,num );
30+ }
31+
32+ public int getInt ( String name ) throws ScriptSharedMemoryException {
33+ if ( integers .get (name ) == null ) {
34+ throw new ScriptSharedMemoryException (String .format ("Key %s does not exist" , name ));
35+ }
36+ return integers .get (name );
37+ }
38+
39+ public synchronized void setString ( String name , String str ) {
40+ strings .put (name ,str );
41+ }
42+
43+ public String getString ( String name ) throws ScriptSharedMemoryException {
44+ if ( objects .get (name ) == null ) {
45+ throw new ScriptSharedMemoryException (String .format ("Key %s does not exist" , name ));
46+ }
47+ return strings .get (name );
48+ }
49+
50+ public synchronized void setObject ( String name , Object obj ) {
51+ objects .put (name ,obj );
52+ }
53+
54+ public Object getObject ( String name ) throws ScriptSharedMemoryException {
55+ if ( objects .get (name ) == null ) {
56+ throw new ScriptSharedMemoryException (String .format ("Key %s does not exist" , name ));
57+ }
58+ return objects .get (name );
59+ }
60+
61+ }
0 commit comments