File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,7 +40,8 @@ namespace Il2Cpp {
4040 /**
4141 * Gets the version name of the current application, e.g. `4.12.8`.
4242 *
43- * **This information is not guaranteed to exist.**
43+ * In case the version cannot be retrieved, an hash of the IL2CPP
44+ * module is returned instead.
4445 *
4546 * ```ts
4647 * Il2Cpp.perform(() => {
@@ -49,8 +50,8 @@ namespace Il2Cpp {
4950 * });
5051 * ```
5152 */
52- get version ( ) : string | null {
53- return unityEngineCall ( "get_version" ) ;
53+ get version ( ) : string {
54+ return unityEngineCall ( "get_version" ) ?? exportsHash ( Il2Cpp . module ) . toString ( 16 ) ;
5455 }
5556 } ;
5657
Original file line number Diff line number Diff line change 22/// <reference path="./utils/console.ts">/>
33/// <reference path="./utils/decorate.ts">/>
44/// <reference path="./utils/getter.ts">/>
5+ /// <reference path="./utils/hash.ts">/>
56/// <reference path="./utils/lazy.ts">/>
67/// <reference path="./utils/native-struct.ts">/>
78/// <reference path="./utils/offset-of.ts">/>
Original file line number Diff line number Diff line change @@ -369,24 +369,4 @@ namespace Il2Cpp {
369369
370370 return new Il2Cpp . Tracer ( applier ( ) ) ;
371371 }
372-
373- /** https://stackoverflow.com/a/52171480/16885569 */
374- function cyrb53 ( str : string ) : number {
375- let h1 = 0xdeadbeef ;
376- let h2 = 0x41c6ce57 ;
377-
378- for ( let i = 0 , ch ; i < str . length ; i ++ ) {
379- ch = str . charCodeAt ( i ) ;
380- h1 = Math . imul ( h1 ^ ch , 2654435761 ) ;
381- h2 = Math . imul ( h2 ^ ch , 1597334677 ) ;
382- }
383-
384- h1 = Math . imul ( h1 ^ ( h1 >>> 16 ) , 2246822507 ) ;
385- h1 ^= Math . imul ( h2 ^ ( h2 >>> 13 ) , 3266489909 ) ;
386-
387- h2 = Math . imul ( h2 ^ ( h2 >>> 16 ) , 2246822507 ) ;
388- h2 ^= Math . imul ( h1 ^ ( h1 >>> 13 ) , 3266489909 ) ;
389-
390- return 4294967296 * ( 2097151 & h2 ) + ( h1 >>> 0 ) ;
391- }
392372}
Original file line number Diff line number Diff line change 1+ /** @internal https://stackoverflow.com/a/52171480/16885569 */
2+ function cyrb53 ( str : string ) : number {
3+ let h1 = 0xdeadbeef ;
4+ let h2 = 0x41c6ce57 ;
5+
6+ for ( let i = 0 , ch ; i < str . length ; i ++ ) {
7+ ch = str . charCodeAt ( i ) ;
8+ h1 = Math . imul ( h1 ^ ch , 2654435761 ) ;
9+ h2 = Math . imul ( h2 ^ ch , 1597334677 ) ;
10+ }
11+
12+ h1 = Math . imul ( h1 ^ ( h1 >>> 16 ) , 2246822507 ) ;
13+ h1 ^= Math . imul ( h2 ^ ( h2 >>> 13 ) , 3266489909 ) ;
14+
15+ h2 = Math . imul ( h2 ^ ( h2 >>> 16 ) , 2246822507 ) ;
16+ h2 ^= Math . imul ( h1 ^ ( h1 >>> 13 ) , 3266489909 ) ;
17+
18+ return 4294967296 * ( 2097151 & h2 ) + ( h1 >>> 0 ) ;
19+ }
20+
21+ /** @internal */
22+ function exportsHash ( module : Module ) : number {
23+ return cyrb53 (
24+ module
25+ . enumerateExports ( )
26+ . sort ( ( a , b ) => a . name . localeCompare ( b . name ) )
27+ . map ( _ => _ . name + _ . address . sub ( module . base ) )
28+ . join ( "" )
29+ ) ;
30+ }
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ class Assertion<T> {
3737 }
3838 }
3939
40- not ( unexpected : T ) {
40+ not ( unexpected : T | null ) {
4141 if ( eq ( unexpected , this . actual ) ) {
4242 throw new AssertionError ( `\x1b[1m${ unexpected } \x1b[22m was not expected` ) ;
4343 }
Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ Il2Cpp.perform(() => {
1111 assert ( Il2Cpp . application . identifier ) . is ( "host" ) ;
1212 } ) ;
1313
14+ test ( "Application version is detected" , ( ) => {
15+ assert ( Il2Cpp . application . version ) . not ( null ) ;
16+ } ) ;
17+
1418 test ( "Il2Cpp.Thread::id" , ( ) => {
1519 assert ( Il2Cpp . currentThread ?. id ) . is ( Process . getCurrentThreadId ( ) ) ;
1620 } ) ;
You can’t perform that action at this time.
0 commit comments