Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save PIPIPIG233666/84757b63c7b75c7f450bc91ce5b58d1d to your computer and use it in GitHub Desktop.
Save PIPIPIG233666/84757b63c7b75c7f450bc91ce5b58d1d to your computer and use it in GitHub Desktop.
enable_snd_device reversing
__int64 __fastcall enable_snd_device(__int64 a1, unsigned int a2)
{
unsigned __int64 v2; // x22
unsigned int v3; // w20
__int64 result; // x0
__int64 v5; // x19
__int64 v6; // x21
__int64 v7; // x0
const char *v8; // x2
signed __int64 v9; // x21
signed int v10; // w8
__int64 *v11; // x8
__int64 v12; // x10
int v13; // [xsp+Ch] [xbp-284h]
__int128 v14; // [xsp+10h] [xbp-280h]
__int128 v15; // [xsp+20h] [xbp-270h]
__int128 v16; // [xsp+30h] [xbp-260h]
__int128 v17; // [xsp+40h] [xbp-250h]
__int128 v18; // [xsp+50h] [xbp-240h]
__int128 v19; // [xsp+60h] [xbp-230h]
__int128 v20; // [xsp+70h] [xbp-220h]
__int128 v21; // [xsp+80h] [xbp-210h]
char v22[440]; // [xsp+90h] [xbp-200h]
__int64 v23; // [xsp+248h] [xbp-48h]
v2 = _ReadStatusReg(ARM64_SYSREG(3, 3, 13, 0, 2));
v3 = a2;
v23 = *(_QWORD *)(v2 + 40);
v13 = 0;
v20 = 0u;
v21 = 0u;
v18 = 0u;
v19 = 0u;
v16 = 0u;
v17 = 0u;
v14 = 0u;
v15 = 0u;
if ( a2 - 1 < 0x106 )
{
v5 = a1;
LODWORD(v6) = platform_get_ref_cnt_snd_device(a2);
++*(_DWORD *)(*(_QWORD *)(v5 + 584) + ((signed __int64)((unsigned __int64)(unsigned int)v6 << 32) >> 30));
if ( platform_get_snd_device_name_extn(*(_QWORD *)(v5 + 976), v3, &v14) & 0x80000000 )
{
__android_log_print(6LL, "audio_hw_primary", "%s: Invalid sound device returned", "enable_snd_device");
result = 4294967274LL;
goto LABEL_62;
}
v6 = (signed int)v6;
if ( *(_DWORD *)(*(_QWORD *)(v5 + 584) + 4LL * (signed int)v6) >= 2
&& (unsigned int)platform_split_snd_device(*(_QWORD *)(v5 + 976), (unsigned int)v6, &v13, v22) )
{
if ( hal_log_mask )
__android_log_print(
3LL,
"audio_hw_primary",
"%s: snd_device(%d: %s) is already active",
"enable_snd_device",
v3,
&v14);
goto LABEL_59;
}
if ( audio_extn_spkr_prot_is_enabled() & 1 )
audio_extn_spkr_prot_calib_cancel(v5);
audio_extn_dsm_feedback_enable(v5, v3, 1LL);
if ( platform_can_enable_spkr_prot_on_device(v3) & 1 && audio_extn_spkr_prot_is_enabled() & 1 )
{
if ( !(platform_get_spkr_prot_acdb_id(v3) & 0x80000000) )
{
result = audio_extn_spkr_prot_start_processing(v3);
if ( !(_DWORD)result )
goto LABEL_62;
__android_log_print(6LL, "audio_hw_primary", "%s: spkr_start_processing failed", "enable_snd_device");
}
LABEL_61:
result = 4294967274LL;
--*(_DWORD *)(*(_QWORD *)(v5 + 584) + 4 * v6);
goto LABEL_62;
}
if ( !(unsigned int)platform_split_snd_device(*(_QWORD *)(v5 + 976), v3, &v13, v22) )
{
if ( v13 >= 1 )
{
v9 = 0LL;
do
enable_snd_device(v5, *(unsigned int *)&v22[4 * v9++]);
while ( v9 < v13 );
}
platform_set_speaker_gain_in_combo(v5, v3, 1LL);
goto LABEL_59;
}
v7 = __android_log_print(
3LL,
"audio_hw_primary",
"%s: snd_device(%d: %s)[%s]",
"enable_snd_device",
v3,
&v14,
qword_A7560[v3]);
if ( (signed int)v3 <= 156 )
{
if ( v3 != 39 )
{
if ( v3 == 40 && audio_extn_a2dp_start_playback(v7) & 0x80000000 )
{
v8 = " fail to configure A2dp Source control path ";
goto LABEL_41;
}
LABEL_31:
audio_extn_sound_trigger_update_device_status(v3, 1LL);
if ( platform_get_snd_device_acdb_id(v3) & 0x80000000 )
{
if ( v3 != 103 && v3 != 246 )
{
audio_extn_sound_trigger_update_device_status(v3, 0LL);
goto LABEL_61;
}
}
else
{
v10 = v3;
switch ( v3 )
{
case 1u:
LABEL_43:
dword_AB0B8 |= v10;
LABEL_44:
property_set("vendor.audio.voice.receiver.status", "on");
LABEL_45:
audio_route_apply_and_update_path(*(_QWORD *)(v5 + 640), &v14);
audio_extn_tfa98xx_start_feedback(v5, v3);
if ( v3 == 235 || v3 == 205 )
{
v11 = *(__int64 **)(v5 + 592);
if ( v11 == (__int64 *)(v5 + 592) )
goto LABEL_65;
v12 = 0LL;
do
{
if ( *((_DWORD *)v11 + 5) == 1 && v11[10] )
v12 = v11[10];
v11 = (__int64 *)*v11;
}
while ( v11 != (__int64 *)(v5 + 592) );
if ( !v12 )
LABEL_65:
__android_log_print(3LL, "audio_hw_primary", "%s: init ec ref loopback", "enable_snd_device");
}
else if ( v3 == 10 && !*(_BYTE *)(v5 + 1276) && audio_is_true_native_stream_active(v5) & 1 )
{
__android_log_print(
3LL,
"audio_hw_primary",
"%s: %d: napb: enabling native mode in hardware",
"enable_snd_device",
1496LL);
audio_route_apply_and_update_path(*(_QWORD *)(v5 + 640), "true-native-mode");
result = 0LL;
*(_BYTE *)(v5 + 1276) = 1;
goto LABEL_62;
}
LABEL_59:
result = 0LL;
goto LABEL_62;
case 0x39u:
v10 = 4;
goto LABEL_43;
case 0x18u:
v10 = 2;
goto LABEL_43;
}
}
if ( !dword_AB0B8 )
goto LABEL_45;
goto LABEL_44;
}
}
else if ( v3 - 157 >= 2 )
{
if ( v3 == 159 && audio_extn_a2dp_start_capture(v7) & 0x80000000 )
{
v8 = " fail to configure A2dp Sink control path ";
LABEL_41:
__android_log_print(6LL, "audio_hw_primary", v8);
goto LABEL_61;
}
goto LABEL_31;
}
if ( audio_extn_sco_start_configuration(v7) & 0x80000000 )
{
v8 = " fail to configure sco control path ";
goto LABEL_41;
}
goto LABEL_31;
}
__android_log_print(6LL, "audio_hw_primary", "%s: Invalid sound device %d", "enable_snd_device", a2);
result = 4294967274LL;
LABEL_62:
*(_QWORD *)(v2 + 40);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment