11import de .labystudio .spotifyapi .platform .windows .api .WinProcess ;
22import de .labystudio .spotifyapi .platform .windows .api .jna .Psapi ;
33import de .labystudio .spotifyapi .platform .windows .api .playback .PlaybackAccessor ;
4+ import de .labystudio .spotifyapi .platform .windows .api .spotify .SpotifyTitle ;
5+
6+ import java .util .ArrayList ;
7+ import java .util .Comparator ;
8+ import java .util .List ;
9+ import java .util .Map ;
410
511public class SpotifyProcessTest {
612
@@ -14,16 +20,72 @@ public static void main(String[] args) {
1420 long addressTrackId = process .findAddressOfText (moduleInfo .getBaseOfDll (), "spotify:track:" , 0 );
1521 System .out .println ("Track Id Address: 0x" + Long .toHexString (addressTrackId ));
1622
23+ boolean isPlaying = process .getWindowTitle ().contains (SpotifyTitle .DELIMITER );
1724 long addressPlayBack = process .findInMemory (
1825 0 ,
1926 addressTrackId ,
2027 PREFIX_CONTEXT ,
2128 (address , index ) -> {
2229 PlaybackAccessor accessor = new PlaybackAccessor (process , address );
23- return accessor .isValid ();
30+ boolean valid = accessor .isValid () && accessor .isPlaying () == isPlaying ; // Check if address is valid
31+
32+ // If valid then pull the data again and check if it is still valid
33+ if (valid ) {
34+ accessor .update ();
35+ return accessor .isValid ();
36+ }
37+
38+ return false ;
2439 }
2540 );
41+ if (addressPlayBack == -1 ) {
42+ System .out .println ("Could not find playback address" );
43+ return ;
44+ }
2645 System .out .println ("Playback Address: 0x" + Long .toHexString (addressPlayBack ));
46+
47+ printModules (process , addressPlayBack );
48+ }
49+
50+ public static void printModules (WinProcess process , long addressPlayBack ) {
51+ List <Module > modules = new ArrayList <>();
52+ for (Map .Entry <String , Psapi .ModuleInfo > entry : process .getModules ().entrySet ()) {
53+ modules .add (new Module (entry .getKey (), entry .getValue ().getBaseOfDll ()));
54+ }
55+ modules .sort (Comparator .comparingLong (o -> o .address ));
56+
57+ int passed = 0 ;
58+ for (Module entry : modules ) {
59+ long entryPoint = entry .address ;
60+ if (entryPoint > addressPlayBack ) {
61+ if (passed == 0 ) {
62+ System .out .println (Long .toHexString (addressPlayBack ) + " CONTEXT ------------------------" );
63+ }
64+ passed ++;
65+ if (passed > 1 ) {
66+ break ;
67+ }
68+ }
69+ System .out .println (Long .toHexString (entryPoint ) + " " + entry .name );
70+ }
71+ }
72+
73+ private static class Module {
74+ private final String name ;
75+ private final long address ;
76+
77+ public Module (String name , long address ) {
78+ this .name = name ;
79+ this .address = address ;
80+ }
81+
82+ public String getName () {
83+ return this .name ;
84+ }
85+
86+ public long getAddress () {
87+ return this .address ;
88+ }
2789 }
2890
2991}
0 commit comments