Skip to content

Releases

GameGuardian 101.4 - open source, fix release 5

Choose a tag to compare

@sdars sdars released this 07 Nov 00:42

GameGuardian 101.4 - open source reconstruction, fix release 5

Clean-room Java reconstruction of GameGuardian 101.4
(catch_.me_.if_.you_.can_, versionCode 16155).

This release removes the reason for the three symptoms that the release 4
still had:

  • the value search of the panel found nothing (the list was empty),
  • the speed hack of the panel changed nothing (the app did not even show the
    error any more),
  • the freeze of the panel killed the target process after a while.

All three had one cause: the 32 bit words of the command stream between the
app and its daemon were masked with 0xf, and the daemon reads them
unmasked.

asset GameGuardian-101.4-open.apk
sha256 49e05361f38c3af15f7d9af277c10292f1f6bc87e05633347424d69350f42885
size 17 896 103 bytes
dex sha256 6928120df9b2aac06a545d907927371953a2d07a4e6086d992a1c029f6a17d16
dex md5 7b7c606d43cb745f9f80e93d69b36bd1
tag v101.4-open-source.5
repository sdars/GameGuardian-Open-Source - independent repository, not a fork
based on v101.4-open-source.4

1. The root cause

app/src/main/java/android/ext/InOut.java is the serializer of the command
stream of the app. It writes the 32 bit words of the commands masked:

public void u(int i) {
    this.f179f.putInt(0, i ^ byteOrderMask);
    t(this.f178e, 4);
}

byteOrderMask is a static volatile int whose value in the original dex is
0xf:

.field public static volatile byteOrderMask:I = 0xf

Nothing in the app writes that field - the whole dex has not a single sput
for it - so the mask was 0xf during every run of the app.

The daemon does not unmask the words:

  • the app reads the answers of the daemon without a mask
    (app/src/main/java/android/ext/w.java: this.f1287a.getInt()),
  • the daemon reads the questions of the app without a mask - a scan of the
    whole code part of the daemon (tools/eorscan.py) finds 1390 eor
    instructions and not one of them unmasks a 32 bit word with 0xf.

So every 32 bit word of every command arrived corrupted:

command the app sends the daemon received effect
34 - search the value 777 774 the search found nothing
35 - speed the factor 6/5 9/10 the target kept the speed 1.0
36 - freeze the number of the values 12 3 the stream lost its synchronisation
36 - freeze the address 0x1300cfcc 0x1300cfd3 the daemon wrote into the wrong place

The crash of the freeze is the third row: the daemon read three values out of
the stream, took the rest of the bytes for the next command and wrote the
values of the app into the heap of the target at addresses that belong to
other objects.

2. The fix

One line of one file - app/src/main/java/android/ext/InOut.java:

public static volatile int byteOrderMask = 0;

The daemon binaries are bit for bit the ones of the release 4
(md5sum app/src/main/res/raw/ydw* - 615681e53ae55bf48b2b7409a0bd0c14 for
ydw5, the other five unchanged), nothing else of the app is changed.

The full analysis is in docs/PROTOCOL_WORD_MASK.md.

3. The verification on the device

Device: MI 8, Android 10, LineageOS 17.1, APatch root, SELinux permissive
before and after the run, no reboot of the device.

3.1 The search finds the values again

tools/freeze_flow.py against the test bed of the repository
(com.gg.freezeprobe, the value 777 in the heap of the process):

the search is done / found_count is ' (2)'
result 13009860 type D
result 1300CFCC type D
1 of 2 results carry the canary -> the address of the test bed is 1300CFCC

Before the fix the same run ended with an empty list.

3.2 The speed hack works and the target stays alive

The factor is written into the clock object of the injected library inside
the target (lib6.so, the table of the clocks at lib6+0x25f80, the factor
at +0x08/+0x0c, the virtual time at +0x28, the real time at +0x20):

$ python3 tools/clockdump.py 4215
slot  1 obj=0x718d47b478 flag=1 index= 20 num=6 den=5 base=9924.924 acc=0 last=9645.766
slot  6 obj=0x718d47b4c8 flag=1 index= 24 num=6 den=5 base=9217.884 acc=4 last=9057.586

The effect, measured in the target while it is drawn:

$ python3 tools/speed_rate.py 4215 30
wall 38.7 s
slot  1 num=6/5 flag=1  virtual +36.103 s  real +30.086 s  factor 1.2000

The clock of the target advances 36.103 s while the real clock of the device
advances 30.086 s in the same interval: the target runs at 1.2x, the
factor that the panel set.

Five minutes of the speed hack on the same target
(tools/speed_e2e.py com.coquypt 4215 300):

t=  23.3  acc=4  clocks=[(1, 20, 6, 5, 0), (6, 24, 6, 5, 4)]  alive=True
t= 145.4  acc=4  clocks=[(1, 20, 6, 5, 2), (6, 24, 6, 5, 4)]  alive=True
t= 293.9  acc=4  clocks=[(1, 20, 6, 5, 0), (6, 24, 6, 5, 4)]  alive=True

alive=True in every sample, the factor stays 6/5 during the whole run and
the device wrote no new tombstone.

3.3 The freeze does not kill the target any more

Two minutes of the freeze of the value of the test bed
(tools/freeze_flow.py):

alive=18356 freeze=710 canary=0 ... status ticks=26600 freezes=709 corrupt=0
  • 720 freeze events, the target process was alive during the whole run,
  • the daemon wrote the frozen value back into the target 10 times out of 12
    samples of its memory,
  • the canary behind the frozen word stayed intact (canary=0) and the test
    bed counted no broken write (corrupt=0),
  • the device wrote no tombstone of the target during the run (the tombstone
    of the device belongs to com.dianjiqi, an unrelated application that
    crashes on its own).

4. What was not changed

  • No mock, no local stand in, no fallback: every number of this release was
    produced by the daemon of the app on the device against the real processes
    of the device.
  • The daemon of the original application was not touched - the binaries of
    this repository are the ones of the release 4.
  • SELinux was not changed: the device was Permissive before and after the
    run, the device was not rebooted (/proc/uptime only grew). See
    docs/ENVIRONMENT_IMPACT.md.

5. Build

./gradlew :app:assembleRelease      # -> app/build/outputs/apk/release/app-release.apk
bash tools/build_release.sh         # -> release/GameGuardian-101.4-open.apk (aligned + signed)
python3 tools/patch_daemon.py       # -> the daemons of every architecture are patched
bash tools/deploy_noreboot.sh       # -> install it on the device without a reboot

6. The verification of the published asset

The asset was downloaded again from the release page and checked:

$ curl -sLO https://github.com/sdars/GameGuardian-Open-Source/releases/download/v101.4-open-source.5/GameGuardian-101.4-open.apk
$ sha256sum GameGuardian-101.4-open.apk
49e05361f38c3af15f7d9af277c10292f1f6bc87e05633347424d69350f42885  GameGuardian-101.4-open.apk
$ md5sum classes.dex res/raw/ydw0 res/raw/ydw1 res/raw/ydw2 res/raw/ydw5 res/raw/ydw7 res/raw/ydw8
7b7c606d43cb745f9f80e93d69b36bd1  classes.dex
101fc1b183eb6a0859481e9c96f6de01  res/raw/ydw0
5a9264bcb3f07610cb7ddadf654a7ce6  res/raw/ydw1
b84e80d7b89283b914cee412b64b51c9  res/raw/ydw2
615681e53ae55bf48b2b7409a0bd0c14  res/raw/ydw5
579e6be38776a4ede589c4b24ea570bb  res/raw/ydw7
df263a351bb7f19ef2ef9e8261b27b4c  res/raw/ydw8

The digest that github computed for the uploaded file is the same:

GameGuardian-101.4-open.apk 17896103 uploaded sha256:49e05361f38c3af15f7d9af277c10292f1f6bc87e05633347424d69350f42885

6.1 The published asset on the device

The published asset was downloaded again, installed on the device
(tools/deploy_noreboot.sh, no reboot of the device) and verified there. The
app installs itself under a randomised package name, so the helper of this
run is com.nsvjhjasgfingxacx. The daemon that it unpacks is the one of
this repository:

615681e53ae55bf48b2b7409a0bd0c14  /data/user/0/com.nsvjhjasgfingxacx/files/GG-j5D7/lib5.so
ecb6f408a46421a159df0dd86a855e9e  /data/user/0/com.nsvjhjasgfingxacx/files/GG-j5D7/lib6.so

The search of the published asset against the test bed of the repository
(tools/freeze_flow.py com.nsvjhjasgfingxacx 18356 120):

the search is done
result 13009860 type D
result 1300CFCC type D
result 7191D4CC00 type D
found_count is ' (3)'
1 of 3 results carry the canary
the address of the test bed is 1300CFCC (type D)

The freeze of the published asset - the same run:

the daemon wrote the frozen value back 11 of 12 times
alive=12407 freeze=713 canary=0 ... status ticks=41900 freezes=1670 corrupt=0

713 freeze events during the run, the target alive, the canary behind the
frozen word intact, no broken write.

The speed hack of the published asset - the factor is in the clock object
of the target and the effect is measurable in the target
(tools/speed_e2e.py com.nsvjhjasgfingxacx 19187 150,
tools/speed_rate.py 19187 35):

the clocks of the target: [(1, 20, 6, 5, 1)]
t=  95.6  acc=3  clocks=[(1, 20, 6, 5, 3)]  alive=True

wall 42.1 s
slot  1 num=6/5 flag=1  virtual +68.749 s  real +57.291 s  factor 1.2000

The clock that the target reads advances 68.749 s while the real clock of the
device advances 57.291 s in the same interval: 1.2000x, the factor 6/5
that the panel set. The target was alive during the whole run.

The state of the device after the verification:

$ adb shell getenforce
Permissive
$ adb shell cat /proc/uptime
13458.17 98629.26

SELinux is in the state it was in before the run and the device was not
rebooted (the uptime only grew). The only tombstones of the device are of
com.dianjiqi, an unrelated application of the device that crashes on its
own.

GameGuardian 101.4 - open source, fix release 4

Choose a tag to compare

@sdars sdars released this 05 Nov 22:27

GameGuardian 101.4 - open source reconstruction, fix release 4

Clean-room Java reconstruction of GameGuardian 101.4
(catch_.me_.if_.you_.can_, versionCode 16155).

This release removes the last reason for the answer "this process does not
support the speed hack"
(the daemon code 107, the app code 1017).
The fix of release 3 removed the first reason, the release 4 the second one:
the policy of SELinux, when it is enforced, does not allow the daemon to
run its injection library inside a privileged application.

asset GameGuardian-101.4-open.apk
sha256 4ab93fcd8f18d3d5f3a6cfbc5c7f417710651c9311fc6926df4fcaa0385d1650
size 17 896 103 bytes
dex sha256 a299243bb448edd55547fb93efdf61fee7f2b2e755a524069584ded983209d36
dex md5 3eb347d94f97ace660e1c8ad55b38180
tag v101.4-open-source.4
repository sdars/GameGuardian-Open-Source - independent repository, not a fork
based on v101.4-open-source.3

1. The root cause

The daemon of GameGuardian injects a small piece of code into the target
process. That code loads the helper library lib6.so of the daemon, which
lives in the private directory of the app. While the policy is enforced the
kernel refuses that:

11-06 03:24:53.970 W/FinalizerWatchd( 3998): type=1400 audit(0.0:657):
  avc: denied { execute } for
  path="/data/data/com.lfq.hy.rhmxkypfyj/files/GG-fNsV/lib6.so" dev="sda21"
  ino=3319603 scontext=u:r:priv_app:s0:c512,c768
  tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=file permissive=0
11-06 03:24:53.989 I/android-daemon(10195): Copy lib cp: 2, No such file or
  directory; /system/priv-app/Phonesky/lib/arm64/_lib6.so;
  /data/user/0/com.lfq.hy.rhmxkypfyj/files/GG-fNsV/lib6.so
11-06 03:24:53.995 E/android-daemon(10195): Report Error: 107

The daemon has a second way for that case: it copies the helper library into
the directory of the target inside the system partition. That can not work
on a normal device:

  • the system partition is mounted read only,
  • the directory does not exist,
  • the policy of the root manager lets the daemon create a file there
    (touch works, the file gets the label system_file) but refuses to
    create a directory there (mkdir answers EACCES).

The daemon answers 107, the app turns that into the message "this process
does not support the speed hack"
(the app code 1017). Every process of a
privileged application - the Play Store, the launcher, the system user
interface - is affected, so the speed panel looked broken on most of the
processes of the device.

The daemon of the original application has two modes for that, the app picks
one of them with the setting "work with SELinux" / "work without
SELinux"
(bit 4 of the flag word that Config.r() hands over to the
daemon):

  • work with SELinux - the daemon stays inside the rules of the policy,
    it uses the copy above, it fails on a device that enforces the policy,

  • work without SELinux - the daemon turns the enforcement off while it
    works, the kernel reports it:

    11-06 05:43:54.516 I/SELinux (  550): avc:  received setenforce notice
      (enforcing=0)
    

    and the injection works for every target, of every architecture and of
    every kind of application.

The original app writes the marker sel.txt when a run failed and asks at
the next start whether it should work with SELinux. On a device that
enforces the policy that question can not change the result: the mode
"work with SELinux" fails in exactly the same way as the run that failed
before, so the question only produces the same failure again and again.

2. The fix

app/src/main/java/android/ext/f1.java, the method k() and the new
method enforcing():

  • the app reads the state of the enforcement - getenforce through the
    root shell of the app (the command has to carry an exec, the root
    wrapper of the app refuses every other form), with
    /sys/fs/selinux/enforce as the fallback for the case that the app runs
    without a root shell,
  • if the policy is enforced the app switches itself to the mode "work
    without SELinux"
    , saves the setting and restarts the daemon,
  • if the policy is not enforced the original behaviour is kept (the question
    of the original application is shown).

The switch happens on every start while the policy is enforced, not only
after a failed run: the device can be rebooted between two runs, the reboot
brings the enforcement back and the setting of the app survives it.

The mode is the mode of the original application for a device that enforces
the policy, the daemon of the original application is the daemon of this
repository - only the two instructions of its self test are patched
(docs/SPEED_HACK_EXEC_ONLY.md).

The whole change is 60 lines of one file, the daemon binaries of release 3
are unchanged.

The log of the app on the device:

E/AndroidService(12934): cmd (exec getenforce) out: Enforcing
E/AndroidService(12934): the policy is enforced: work without SELinux

3. The verification on the device

Device: MI 8, Android 10, LineageOS 17.1, APatch. The policy was enforced
at the start of the run, the build of this release is the one that was
installed and verified (com.wntyypi, root granted by APatch).

Before the fix, the same target answered with the error code 107
(build/flow/lc_rel16_3969.txt):

W/FinalizerWatchd( 3969): avc: denied { execute } for path=".../GG-GgmI/lib6.so"
I/android-daemon( 6249): Copy lib cp: 2, No such file or directory; ...
E/android-daemon( 6249): Report Error: 107

After the fix, the daemon turns the enforcement off, reads the memory of the
target with ptrace (CV: 00 instead of CV: 11) and installs the hook:

I/SELinux (  550): avc:  received setenforce notice (enforcing=0)
I/android-daemon(13837): hook 2 installed: 131
E/android-daemon(13837): Send code: 11
E/android-daemon(13837): Send code: 18
E/android-daemon(13837): Send code: 18

The matrix of the targets - every row is a real process of the device, the
hook is installed by the daemon of the app:

target arch errors codes
[16403] Google Play 商店 (vending, privileged app) 64 bit none 11, 18, 18
[2420] 系统界面 (systemui) 64 bit none 11, 18, 18
[22705] Trebuchet (launcher3, privileged app) 64 bit none 11, 18, 18
[6304] GG32Probe (com.gg.abitest) 32 bit none 18, 18
[8706] 文件 (documentsui) 64 bit none 18, 18
[9075] 软件包安装程序 (packageinstaller) 64 bit none 18, 18
[11329] 权限控制器 (permissioncontroller) 64 bit none 18, 18
[3932] com.android.smspush 64 bit none 18, 18
[3256] Google 服务框架 (com.google.android.gms) 64 bit none 18, 18

codes are the answers of the daemon (11 = the hook point was found,
18 = the speed of the target was changed), errors is the list of the
Report Error: lines of the run. There is no Report Error in any of the
runs. The log of every row is kept in build/flow/lc_rel19_<pid>.txt.

The value search of the same build, on a 64 bit target and on the 32 bit
target, the daemon reports the results and the panel lists them:

64 bit, Google Play 商店:
E/AndroidService( 1324): sendSearchNumber: 777; 0 x0 as 20000004 in 0-ffffffffffffffff, 0
I/android-daemon( 1396): searchNumber: 777; 0, 20000004 0-ffffffffffffffff
I/android-daemon( 1396): ::searchDone: 7, 7 0
   found_count is ' (7)'

32 bit, GG32Probe:
E/AndroidService( 2783): sendSearchNumber: 777; 0 x0 as 20000004 in 0-ffffffffffffffff, 0
I/android-daemon( 2860): searchNumber: 777; 0, 20000004 0-ffffffffffffffff
I/android-daemon( 2860): ::searchDone: 2, 2 0
   found_count is ' (2)'

The daemon binary that the build unpacks on the device is the patched one:

615681e53ae55bf48b2b7409a0bd0c14  /data/data/com.wntyypi/files/GG-cMjb/lib5.so

4. What was not changed

  • No mock, no local stand in, no fallback: every number of this release was
    produced by the daemon of the app on the device against the real
    processes.
  • The daemon of the original application was not touched.
  • The app does not touch the policy itself - there is no setenforce, no
    magiskpolicy and no sepolicy write in the source. The daemon does it,
    and that is the mechanism of the original application. The effect on the
    device is the enforcement mode of the kernel: it is off while the daemon
    works and it is back after a reboot of the device. docs/ENVIRONMENT_IMPACT.md
    describes the state of the device in detail.

5. Build

./gradlew :app:assembleRelease      # -> app/build/outputs/apk/release/app-release.apk
bash tools/build_release.sh         # -> release/GameGuardian-101.4-open.apk (aligned + signed)
python3 tools/patch_daemon.py       # -> the daemons of every architecture are patched
bash tools/deploy.sh                # -> install it on the device, grant the root, start the daemon

6. The verification of the published asset

The asset was downloaded again from the release page and checked:

$ curl -sLO https://github.com/sdars/GameGuardian-Open-Source/releases/download/v101.4-open-source.4/GameGuardian-101.4-open.apk
$ sha256sum GameGuardian-101.4-open.apk
4ab93fcd8f18d3d5f3a6cfbc5c7f417710651c9311fc6926df4fcaa0385d1650  GameGuardian-101.4-open.apk
$ md5sum classes.dex res/raw/ydw0 res/raw/ydw1 res/raw/ydw2 res/raw/ydw5 res/raw/ydw7 res/raw/ydw8
3eb347d94f97ace660e1c8ad55b38180  classes.dex
101fc1b183eb6a0859481e9c96f6de01  res/raw/ydw0
5a9264bcb3f07610cb7ddadf654a7ce6  res/raw/ydw1
b84e80d7b89283b914cee412b64b51c9  res/raw/ydw2
615681e53ae55bf48b2b7409a0bd0c14  res/raw/ydw5
579e6be38776a4ede589c4b24ea570bb  res/raw/ydw7
df263a351bb7f19ef2ef9e8261b27b4c  res/raw/ydw8

The digest that github computed for the uploaded file is the same:

GameGuardian-101.4-open.apk 17896103 uploaded sha256:4ab93fcd8f18d3d5f3a6cfbc5c7f417710651c9311fc6926df4fcaa0385d1650

That published...

Read more

GameGuardian 101.4 - open source, fix release 3

Choose a tag to compare

@sdars sdars released this 05 Nov 16:51

GameGuardian 101.4 - open source reconstruction, fix release 3

Clean-room Java reconstruction of GameGuardian 101.4
(catch_.me_.if_.you_.can_, versionCode 16155).

This release fixes the speed hack and the value search on the processes whose
code pages the linker maps as execute only. Before the fix the daemon
answered with {107} - "this process does not support the speed hack" -
on every process of an application with targetSdk >= 29 on Android 10 and
newer, and the value search of such a process found nothing.

asset GameGuardian-101.4-open.apk
sha256 89a6785f3e1f6656f749558ffe94184832b90bd027b270eb525b885e487af0d5
size 17 896 103 bytes
dex sha256 5e803d5e945b118c9bed8eafac46440bfc8c158681913f227f58bf398ae78819
dex md5 01a772b9275364546084145543229232
tag v101.4-open-source.3
repository sdars/GameGuardian-Open-Source - independent repository, not a fork
based on v101.4-open-source.2

1. The root cause

Since Android 10 the linker maps the system libraries of an application with
targetSdk >= 29 as --xp (execute only). process_vm_readv can not read
such a page - it fails with EFAULT - and the daemon of GameGuardian reads
the code page of the hook point that way:

I/android-daemon: VM_FAIL 2: -1 72fe125000, 16, 14, Bad address
E/android-daemon: Call point backup read failed at 72fe125000
E/android-daemon: Report Error: 107

The daemon contains a second implementation of the same read, a
PTRACE_PEEKDATA loop that works on execute only pages, but which of the two
is used is decided by one byte in the bss of the daemon. That byte is set by
the self test of the daemon, and the self test reads back a marker that the
daemon has written into its own stack - so the test always succeeds and the
daemon always ends up with the process_vm_readv implementation, even when
the target uses execute only mappings.

The full analysis, the disassembly of the daemon and the patch sites of every
architecture are in docs/SPEED_HACK_EXEC_ONLY.md.

2. The fix

tools/patch_daemon.py changes the two instructions of the self test that
set the byte, so that the daemon keeps the PTRACE_PEEKDATA implementation:

daemon arch site 1 site 2
ydw5 arm64 0x3d90e0 0x3d9100
ydw7 arm 32 bit 0x486bfc 0x486c28
ydw8 arm 32 bit 0x4863c8 0x4863f4
ydw2 x86 64 bit 0x47c2c8 0x47c2e2
ydw0 x86 32 bit 0x4a4805 0x4a481b
ydw1 x86 32 bit 0x4a4725 0x4a473b

The patch is applied to the copies of the daemon in this repository
(app/src/main/res/raw and build/ydw/res/raw), the script is idempotent
and it refuses to touch a file that does not carry the expected instruction.
The dex of the app is unchanged - the fix is in the daemon binary that the
app unpacks, so the dex hash is the one of release 2.

3. The verification on the device

The speed panel of the build with the patched daemon, on the process of the
system user interface ([26145] systemui, arm64, targetSdk 29):

I/android-daemon: hook 2 installed: 131
E/android-daemon: Send code: 11

No VM_FAIL and no Report Error in the log of the run; the same target
answered with Report Error: 107 before the patch. The matrix of the
targets reports errors=none for the Play Store, the 32 bit test process,
the launcher, the settings and the system user interface, with 88 hook
points found in the process of the Play Store and 82 in the process of the
system user interface.

The value search of the same build still works, the daemon is attached to the
target and can read it with ptrace:

E/AndroidService: sendSearchNumber: 777; 0 x0 as 20000004 in 0-ffffffffffffffff, 0
I/android-daemon: searchNumber: 777; 0, 20000004 0-ffffffffffffffff
I/android-daemon: ::searchDone: 5, 5 0

4. What was not changed

  • No mock, no local stand in, no fallback: every number of this release was
    produced by the daemon of the app on the device against the real
    processes.
  • SELinux was not changed: the device stayed in the state it was in
    (getenforce -> Permissive).
  • The daemon of the original application was not touched.

GameGuardian 101.4 - open source, fix release 2

Choose a tag to compare

@sdars sdars released this 04 Nov 22:34

GameGuardian 101.4 - open source reconstruction, fix release 2

Clean-room Java reconstruction of GameGuardian 101.4
(catch_.me_.if_.you_.can_, versionCode 16155).

This release fixes the speed hack of the floating panel. The two buttons of
the panel answered with {107} - "此进程不支持变速" ("this process does
not support the speed hack") - on every target, while the original 101.4
answers the same gesture on the same target on the same device.

asset GameGuardian-101.4-open.apk
sha256 1cd54d353e2327359b56b4c057e819b6eb0b8c612be558283b48039d1ff9de46
size 17 896 103 bytes
dex sha256 5e803d5e945b118c9bed8eafac46440bfc8c158681913f227f58bf398ae78819
dex md5 01a772b9275364546084145543229232
tag v101.4-open-source.2
repository sdars/GameGuardian-Open-Source - independent repository, not a fork
based on v101.4-open-source.1

1. The root cause: three helper libraries were never unpacked

The daemon of GameGuardian is not one file. The app unpacks a set of
helper libraries next to the daemon and the daemon copies the hook payload
out of that directory into the target before it patches it. The set depends
on the architecture of the daemon that the device uses:

daemon arch helpers that have to be unpacked
lib5.so 105 (arm64) lib5, lib08, lib6, libg, libl, lib9, libh, libn
lib7.so / lib8.so 104 lib7 / lib8, lib9, libh, libn
liba.so / libb.so 103 liba / libb, libd, libi, libo
lib0.so / lib1.so 101 lib0 / lib1, lib3, libe, libj
lib2.so 102 lib2, lib01, lib4, libf, libk, lib3, libe, libj

The unpacking is done by android.ext.e0.d(char). In the original dex the
block of the 64 bit arm daemon falls through into the block of '7'/'8',
so that the three libraries of the hook are unpacked as well:

build/verify/orig9063_smali/android/ext/e0.smali, method d(C)V
    :cond_52                          <-- c2 == '5'
    const-string p1, "08"
    ... invoke-static {p1}, Landroid/ext/e0;->b(C)V   <-- b('l')
    :cond_68                          <-- c2 == '7' or '8', reached by fall through
    const/16 p1, 0x39                 <-- b('9')
    const/16 p1, 0x68                 <-- b('h')
    sput-char p1, Landroid/ext/e0;->e:C
    const/16 p1, 0x6e                 <-- b('n')

The decompiler that the pure source tree was written from lost that fall
through: the reconstruction stopped after b('l') and unpacked
lib5.so, lib08.so, lib6.so, libg.so and libl.so - but never
lib9.so, libh.so and libn.so. The daemon then failed to copy its hook
payload into the target and answered with the error code 107, which
MainService turns into speedhack_fail:

E/android-daemon: lib chmod '/data/user/0/<package>/files/GG-xxxx/lib9.so' -1 2: No such file or directory
I/android-daemon: Copy lib cp: 2, No such file or directory; /data/app/com.gg.abitest-.../lib/arm/_lib9.so; /data/user/0/<package>/files/GG-xxxx/lib9.so
I/android-daemon: elf_hook_sections32 Find 0 '0x55a6bc4bfa': 0, 0, 0, 137, 1
E/android-daemon: Report Error: 107

app/src/main/java/android/ext/e0.java now follows the original again - the
'5' branch continues with b('9'), b('h'), e = 'h', b('n'), the
'2' branch keeps its own fall through into b('3'), b('e'), e = 'e',
b('j'), and every other branch is unchanged.

2. The verification on the device

MI 8, Android 10, APatch, target com.gg.abitest (pid 2418, a 32 bit
process), the same gesture for both applications
(tools/speed_panel_ab.py, long press on the floating icon, then the fast
forward button at 270,104):

The directory of the app is now identical to the one of the original, file
by file (only the name of the directory is random):

original 101.4 (com.utnciuwv.ldcsra, GG-mikB)   this build (com.lpj, GG-kPwZ)
lib01.so   24476   lib02.so   10408   lib05.so   10312   lib08.so   24892
lib5.so  4075552   lib6.so   147552   lib9.so   143960   libg.so    10872
libh.so     8208   libl.so    11608   libn.so     8672   sh.jar      2294
version.gg    11

The daemon log of the two runs (the searched name of the section is mixed
with a random key per run, the addresses are not):

original 101.4                                  this build
elf_hook_sections32 Find 0 '0x5ae5c94e6c':      elf_hook_sections32 Find 0 '0x6290506e6c':
    bed70638, 0, 2e638, 183, 1                      bed70638, 0, 2e638, 183, 1
elf_hook_sections32 Find 1 '0x5ae5c90177':      elf_hook_sections32 Find 1 '0x6290502177':
    bed6cbe8, 0, 2abe8, 180, 1                      bed6cbe8, 0, 2abe8, 180, 1
find all                                         find all
_reader: bed70638, _config: bed6cbe8             _reader: bed70638, _config: bed6cbe8
Send code: 18                                    Send code: 18
>>                                               >>
Send code: 18                                    Send code: 18

The hook is installed at the same addresses in the same target process, the
speed command is delivered and no Report Error is written in the whole
log of the run (before the fix: Report Error: 107).

The panel itself is pixel identical to the panel of the original - the
screenshots of the expanded panel were compared pixel by pixel, before and
after the fast forward button was pressed:

panel pixels before ours vs original: 0/31488 differ (0.000%)
panel pixels after  ours vs original: 0/31488 differ (0.000%)

(tools/speed_panel_readback.py, the region of the expanded panel,
(0, 56) - (328, 152).)

3. The tool that drives the panel

python3 tools/speed_panel_ab.py <package> <tag> <pid>

attaches the package to the target, hides the main panel, finds the floating
icon in the APPLICATION_OVERLAY windows, opens the speed panel with a long
press, presses the fast forward button and prints the screen and the log of
the app and of the daemon. tools/speed_panel_readback.py does the same and
additionally renders the text view of the speed from the screenshot, before
and after the button.

4. The published asset on the device

The asset of the release was downloaded again, installed on the device and
driven through the same gesture - the app installs itself under a randomised
package name, so the package of the run was com.fifunrftosjpvh:

$ curl -sL -o gg_release_v2.apk https://github.com/sdars/GameGuardian-Open-Source/releases/download/v101.4-open-source.2/GameGuardian-101.4-open.apk
$ sha256sum gg_release_v2.apk
1cd54d353e2327359b56b4c057e819b6eb0b8c612be558283b48039d1ff9de46  gg_release_v2.apk

$ adb shell su -c 'ls -l /data/user/0/com.fifunrftosjpvh/files/GG-LzTW/'
lib01.so   24476   lib02.so   10408   lib05.so   10312   lib08.so   24892
lib5.so  4075552   lib6.so   147552   lib9.so   143960   libg.so    10872
libh.so     8208   libl.so    11608   libn.so     8672   sh.jar      2294
version.gg    11

E/AndroidService( 2480): >>
E/android-daemon( 5359): Send code: 18

No Report Error in the log of the run.

The value search of the published asset returns the same rows as the
original - F5104A40, F51A8160, F5201EC8, each of them 999, D,
Ca - and the memory list shows the real disassembly (0D;, 0.0F;,
PS):

sendSearchNumber: 999; 0 x0 as 20000004 in 0-ffffffffffffffff, 0
searchNumber: 999; 0, 20000004 0-ffffffffffffffff
::searchDone: 5, 5 0

The number of hits changes between two runs, because the heap of the target
process changes while it runs - the original itself found 4 hits in one
run and 3 in the next one, the reconstruction found 5; the three rows
above are in every run.

5. Build

./gradlew :app:assembleRelease      # -> app/build/outputs/apk/release/app-release.apk
bash tools/build_release.sh         # -> release/GameGuardian-101.4-open.apk (aligned + signed)
bash tools/deploy.sh                # -> install it on the device, grant the root, start the daemon

Legal

GameGuardian is a commercial product of GameGuardian Ltd. This release
contains a reconstruction produced by static analysis of the APK for
educational and interoperability purposes; the original binary is not
included. The authors of GameGuardian Ltd. own the original code.

GameGuardian 101.4 - open source, fix release 1

Choose a tag to compare

@sdars sdars released this 04 Nov 21:16

GameGuardian 101.4 - open source reconstruction, fix release 1

Clean-room Java reconstruction of GameGuardian 101.4
(catch_.me_.if_.you_.can_, versionCode 16155).

This release fixes the three defects that were still visible in the published
v101.4-open-source APK:

  • every value of a value search was rendered as 0,
  • the disassembly (the opcode column) of the memory list was wrong,
  • the preferences that the app copies during its self install were shifted
    by one entry, so every copied value ended up under the name of its
    predecessor.
asset GameGuardian-101.4-open.apk
sha256 9f66496415c9804495cd696158007f5f574cb6d8775e32b6a46dbea88036a4ca
size 17 896 103 bytes
dex sha256 03e56cf565da42d60a9833e7aceabc35931667cbadd2329583eab36ecd163dd1
dex md5 43ed75b6e7337b99f044c01ec54d5fb8
tag v101.4-open-source.1
repository sdars/GameGuardian-Open-Source - independent repository, not a fork
based on v101.4-open-source

1. Why every search result was 0

The mask of the value types is built once, in the static initialiser of
android.ext.i0:

for (int i = 0; i < 3; i++) {
    long j = (1 << ((1 << i) * 8)) - 1;   // 8, 16 and 32 bit
    ...
}

Java masks the distance of an int shift to five bits, so 1 << 32 is
1 and not 0x100000000; the dword mask became 0 and every dword value
was masked to zero before it was rendered. The original dex builds the same
constant with a long shift:

build/verify/orig9063_smali/android/ext/i0.smali, <clinit>
    const-wide/16 v4, 0x1
    shl-long v6, v4, v3        <-- 64 bit shift, 1L << 32 == 0x100000000
    sub-long/2addr v6, v4

The reconstruction had been decompiled with the shift type lost, and the same
error was repeated in 16 places. All of them are fixed now:

file what it builds
android/ext/i0.java the type masks (byte / word / dword)
android/ext/n1.java the reversed hex of a value, the mask of the value column
android/ext/c.java the mask of the value formats of the memory list
android/ext/i2.java the sign bit of an unsigned search
android/ext/t1.java the sign extension of a 64 bit search value
android/ext/m.java the field mask of the ARM64 decoder
android/ext/p1.java, OffsetCalculator.java, MainService.java, ConfigListAdapter.java, ConfigListAdapter$g.java the bit masks of the settings
luaj/a.java, luaj/lib/StringLib.java, luaj/lib/StringLib$pack.java the bit masks of the Lua runtime

android.ext.m (the ARM64 decoder) had the same defect in the other
direction: (-1) >>> (64 - (i6 + 1)) was an int shift, which masked the
distance to five bits and gave a 32 bit field the mask 0xffffffff instead
of 0xffffffff00000000. The original uses ushr-long.

The disassembly was broken by the same mask

android.ext.n1 feeds the value it has read into the disassembler:

java.lang.StringBuilder sbG = android.ext.m.g(iArrD, j, (int) j2, new java.lang.StringBuilder());

With the mask broken, j was always 0, so every row of the memory list was
disassembled as the word 0x00000000 - ANDEQ R0, R0, R0; for ARM and
MOVS R0, R0; for Thumb. That is the "the opcodes are all wrong" of the
previous release; it is a consequence of the same root cause and it is gone
with it.

2. Why the copied preferences were shifted

gg_b.b.g() reads the preferences of the package that the app replaces. The
reconstruction had the arguments of the put() in the wrong order:

map.put(strArr[0], k(xmlPullParser, strArr, b_a));   // wrong

Java evaluates the arguments from left to right, so strArr[0] was read
before k() had filled it with the name of the element that was just
parsed. Every entry of the copy therefore carried the value of its
predecessor. The original dex parses the value first and reads the name
afterwards:

build/verify/orig9063_smali/b/b.smali, method g(...)
    invoke-static {p0, p2, p3}, Lb/b;->k(...)   <-- the value
    move-result-object v1
    const/4 v2, 0x0
    aget-object v2, p2, v2                     <-- then the name
    invoke-virtual {v0, v2, v1}, Ljava/util/HashMap;->put(...)

The fix is the same order as the original:

java.lang.Object obj = k(xmlPullParser, strArr, b_a);
map.put(strArr[0], obj);

The effect of the bug on the device was visible in the preferences of the
self installed package - the history of the searches and the value formats of
the memory list were the values of their neighbours:

<string name="history-0">999</string>            (the value of history-1)
<string name="memory-editor-format">BAAAIA</string> (a string, not an int)
<int name="history-size" value="1" />            (the value of h-6)

3. The verification on the device

MI 8, Android 10, APatch, target com.gg.abitest (pid 2418, a 32 bit
process), the same script for both applications (tools/search_flow.py):

original 101.4 (com.utnciuwv.ldcsra)      this build (com.saweyhfbpyrcxakywsq)
E9C04A40   999   D   Ca                   E9C04A40   999   D   Ca
(1)                                         (1)

The daemon log of both runs:

sendSearchNumber: 999; 0 x0 as 20000004 in 0-ffffffffffffffff, 0
searchNumber: 999; 0, 20000004 0-ffffffffffffffff
::searchDone: 1, 1 0

Before the fix the same run showed 00000000 | 00000000 | D | Ca.

The 32 bit process is listed as [2418] GG32Probe [112 MB] - without the
[x64] tag, exactly like the original, because android.ext.z1$d.l() only
appends the tag for a 64 bit process.

4. The tool that found the shift type

tools/verify/shift_methods.py compares the shift instructions of every
method of the reconstruction with the shifts of the original dex, method by
method and in the order in which they appear:

python3 tools/verify/shift_methods.py build/verify/rel_apk_smali4 build/verify/orig9063_smali --pkg-map com/utnciuwv/ldcsra=catch_/me_/if_/you_/can_ --rename-orig

After the fix the only remaining differences are the methods that were
rewritten as state machines (android.ext.m.g, android.ext.m.l,
luaj.LuaClosure.Y2, luaj.LuaTable.*) and a handful of methods where the
order of two independent shifts differs - the result is the same.

tools/verify/smali_semdiff.py no longer folds if-eqz and if-nez into
one opcode any more: the polarity of a branch is part of the behaviour and
an inverted branch is exactly the kind of defect the comparison has to see.

5. Build

./gradlew :app:assembleRelease      # -> app/build/outputs/apk/release/app-release.apk
bash tools/build_release.sh         # -> release/GameGuardian-101.4-open.apk (aligned + signed)
bash tools/deploy.sh                # -> install it on the device, grant the root, start the daemon

Legal

GameGuardian is a commercial product of GameGuardian Ltd. This release
contains a reconstruction produced by static analysis of the APK for
educational and interoperability purposes; the original binary is not
included. The authors of GameGuardian Ltd. own the original code.

GameGuardian 101.4 - open source, full tree

Choose a tag to compare

@sdars sdars released this 03 Nov 20:14

Clean-room Java reconstruction of GameGuardian 101.4
(catch_.me_.if_.you_.can_, versionCode 16155).

Every class of the original APK is present as Java source - including the
four methods that defeat every Java decompiler. The project compiles with
Gradle and nothing else: there is no smali in the build, no baksmali, no
smali assembler. app/src/main/java is the only input of the APK.

asset GameGuardian-101.4-open.apk
sha256 bd584b9c5493e860773e80f405e4ccfef28e74ca99f898d08ee79b60a8fd4075
size 17 896 103 bytes
java sources 1139 files, 488 944 lines
certificate CN=GameGuardian, v1 signature alias CERT
tag v101.4-open-source
repository sdars/GameGuardian-Open-Source - independent repository, not a fork
commit a6b815a (main, open-source, feature/gg-101.4-opensource)

What is in this release

  • the three large methods that used to be shipped as a smali overlay are
    plain Java state machines now (android.ext.m.e, android.ext.n$a.a,
    luaj.LuaClosure.Y2); the app/src/main/smali_overlay directory is gone,
  • the type of a failure survives the translation: the call sites that wrapped
    a checked exception into a RuntimeException re-throw it unchanged, so
    the dex handlers that catch a concrete type keep matching,
    (tools/repair/fix_exception_wrappers.py),
  • the object of a new-instance reaches every register that carries the
    reference - the process list of the floating panel is complete again
    (tools/repair/scan_new_instance.py),
  • the region map of the process ends where the dex ends it: a zero flag
    leaves the loop instead of running into the end of the buffer,
  • catch_.me_.if_.you_.can_.Receiver is back. The 101.4 manifest declares
    it and android.ext.w2 sends its notification actions to it by class
    name, so without the class every action of the notification ended in a
    ClassNotFoundException.
  • the number parser (android.ext.t1.p()) follows the original smali again:
    a plain decimal value without a suffix is a plain integer, the suffix
    letters select the type (b/w/d/x/f/q/e/a), float and double
    keep their raw bit pattern and a value that does not fit into the selected
    type produces the original range message.
  • the region map of android.ext.InOut holds at most 40 entries and drops
    the oldest one instead of growing without a limit.
  • the text/hex search works again: android.ext.t1.h() has the four way
    dispatch of the original smali again (; = UTF-16LE text, H/h = hex,
    Q/q = quoted sections, everything else = UTF-8 text). Before
    this the : and h prefixes were parsed as hex, so every text
    search ended in a NumberFormatException before the request even
    reached the daemon, and the ; branch sent UTF-8 bytes while the
    daemon was told UTF-16LE.
  • the layout flag of a row is read the way the original reads it:
    Config.q & (1 << Tools.d1()) is set when the bit is set, the
    reconstruction had the test inverted (== 0 instead of != 0) in
    android.ext.AddressArrayAdapter and in android.ext.SavedListAdapter.
    Config.q is the bit mask of config_use_small_list_items: bit 0 is the
    portrait variant and bit 1 the landscape variant, and the flag decides
    whether a row is drawn in the compact or in the tall variant.

The value search on a real device

docs/SEARCH_BEHAVIOUR.md documents what the search really does:

  • the daemon is always asked for the whole address range
    (sendSearchNumber: 777; 0 x0 as 2000007e in 0-ffffffffffffffff),
    the range button reads 在全部内存中,
  • the type mask that is handed to the daemon is the bit set of the selected
    types (777 with Auto -> 0x7e -> 182 hits, 777 with Dword ->
    0x20000004 -> 29 hits, 305419896 with Dword -> 0 hits because the
    value is not in the attached process),
  • the text search reaches the daemon and comes back with hits:
    :Trebuchet (UTF-8) -> 1467 hits, ;Trebuchet (UTF-16LE, 18 bytes)
    -> 180 hits, hDEADBEEF (hex) -> the request leaves as raw bytes,
  • 32 bit values are searched with their own mask and are tagged with their
    own type letter in the result list: 777 with Dword ->
    0x20000004 -> 38 hits tagged D, 777 with Word ->
    0x20000002 -> 136 hits tagged W, 77 with Byte ->
    0x20000001 -> 33205 hits tagged B,
  • the dark input field (#0d0d0d) is the theme of the original
    (Theme.Material -> @drawable/edit_text_material), the same colour is
    measured in the original 101.4 APK, in the commercial 499.6 build and in
    this build. The whole resource tree of the original APK and of this build
    is byte identical (diff -rq of the two res directories is empty).
bash tools/test/run_t1_parse_test.sh
  -> ALL PASS (24 cases) - the parser is compared with a transcription of
     the original smali, byte for byte

The three reports of this round

1. "The input field behind address: is black"

It is black in the original as well - the field is not a bug, it is the
theme. The two builds were screenshotted on the same device with the same
search dialog open and compared pixel by pixel (tools/diff_region.py):

region                                     original        this build
the value field 195,212-580,271           identical       identical
the label "value" 44,217-95,266          identical       identical
the "=" spinner 95,194-191,290           identical       identical
the whole dialog 32,107-688,1229          1.03 % differ,
                                           difference bbox (32,107)-(428,196)

The only pixels that differ are the first two characters of the headline of
the dialog (antialiasing), not the input field. The colour of the field
itself is #0d0d0d, the colour of @drawable/edit_text_material of
Theme.Material, and it is measured in the original 101.4 APK, in the
commercial 499.6 build and in this build. Screenshots:
build/new_orig_dlg.png and build/new_ours_dlg.png.

2. "The rows of the result list are too narrow"

The pitch of the rows is 98 px, the same as in the original 101.4. Before
this release the reconstruction drew them with 66 px - the row was drawn in
the compact variant because one bit of the row was read inverted:

original 101.4      this build before the fix   this build now
row 1  top  333     row 1  top  317             row 1  top  333
row 2  top  431     row 2  top  383             row 2  top  431
row 3  top  529     row 3  top  449             row 3  top  529
row 4  top  627     row 4  top  515             row 4  top  627
row 5  top  725     row 5  top  581             row 5  top  725
row 6  top  823     row 6  top  647             row 6  top  823
row 7  top  921     row 7  top  713             row 7  top  921
                  98 px per row                66 px per row   98 px per row

The type and the area column sit on the same place as in the original:
D at [594,510][624,548] and Ca at [579,548][624,586] in both.
The fix is the test of the layout flag of the row
(Config.q & (1 << Tools.d1())), it is now != 0 as in the original smali.

3. "There is no speedhack"

There is one, and it behaves exactly like the original. Both applications
were driven through the same lua script against the same target
(com.gg.abitest, pid 2424, 32 bit) on the same device:

print("SPEED_BEFORE " .. tostring(gg.getSpeed()))
local r = gg.setSpeed(2)
print("SETSPEED_RET " .. tostring(r))
print("SPEED_AFTER " .. tostring(gg.getSpeed()))
original 101.4 this build
daemon config Sended config: 2147483647 110000010000000011 1111...1111 33000 262207 ... identical
daemon hook hook 2 installed: 132, Send code: 11, Send code: 18 elf_hook_sections32 Find 0/1, find all, Send code: 18
gg.setSpeed(2) SETSPEED_RET true SETSPEED_RET true
gg.getSpeed() SPEED_AFTER 2.0 SPEED_AFTER 2.0
long press on the icon Fake long click: 350 / Real long click: true identical

The same run against the apk that is published here (the self install of
this build created com.hdzj.yopvkq on the device):

E/AndroidService(13085): script: SPEED_BEFORE 1.0
I/android-daemon(20200): elf_hook_sections32 Find 0 '0x5d9fc6be6c': c1f3a638, 0, 2e638, 183, 1
I/android-daemon(20200): elf_hook_sections32 Find 1 '0x5d9fc67177': c1f36be8, 0, 2abe8, 180, 1
I/android-daemon(20200): find all
E/android-daemon(20200): Send code: 18
E/AndroidService(13085): script: SETSPEED_RET true
E/AndroidService(13085): script: SPEED_AFTER 2.0
E/AndroidService(13085): Sended config: 2147483647 110000010000000011 1111...1111 33000 262207 ...

(build/logs/speed_new.log, the script is
/storage/emulated/0/Notes/com.gg.abitest.lua, the target is
com.gg.abitest, pid 2424, 32 bit.)

The daemon that installs the hook is the binary of the original APK:
res/raw/ydw0 of this release and of the original APK have the same sha256
(3535a0261b749ae8ddc9fd1215527b64ac2ba9c9b14ee3602458f3c15f4e9433).
The panel of the speedhack is opened by a long press on the floating icon
(HotFrame.onLongClick -> MainService.onLongClick -> HotPoint.x() ->
HotPoint$d -> speed_inc / speed_dec / speed_text); MainService.T()
(>>) and MainService.u0() (<<) end in MainService.o1(true) ->
MainService.S0(byte, double) -> f0.F0(cmd, num, den), the same call the
lua API uses.

The gesture has to hit the icon itself: the icon is a 96 x 96 px window, the
panel of the app covers the same area while it is open, and a long press on
the panel is a long press on the panel.

The script path of the script runner

The self install copies the preferences of the package it replaces
(android.ext.x2.n()) and keeps the type of every entry. The original
stores script-path as a long, so opening the script dialog throws

java.lang.ClassCastException: java.lang.Long cannot be ...
Read more