cCopy codefloat unnamed_function_1(double x) {
double x2 = x * x;
return (float)(
x * x2 * x2 * x2 * (x2 * 2.718311493989822e-06 + -0.00019839334836096632) +
x * x2 * (x2 * 0.008333329385889463 + -0.) +
x
);
}
This is a polynomial approximation of a mathematical function, likely derived from aTaylor or Padé seriesexpansion. Let's break down what this resembles:
Breakdown & Recognition
This kind of structure is a hallmark offunction approximations, often used in performance-critical code (e.g., graphics shaders, embedded math libraries, etc.) where computing exact transcendental functions liketanh,sin,, etc., is too slow or unavailable.
Let’s inspect the structure:
x7⋅a+x5⋅b+xx^7 \cdot a + x^5 \cdot b + xx7⋅a+x5⋅b+x: This pattern appears in odd function approximations.
The coefficients closely matchknown polynomial approximationsof functions like:tanh(x)(hyperbolic tangent)atan(x)(arctangent)sin(x)for smallxxx
tanh(x)(hyperbolic tangent)
atan(x)(arctangent)
sin(x)for smallxxx
x7⋅a+x5⋅b+xx^7 \cdot a + x^5 \cdot b + xx7⋅a+x5⋅b+x: This pattern appears in odd function approximations.
The coefficients closely matchknown polynomial approximationsof functions like:
This complements thesin(x)approximation from the previous function — commonly used in WASM shaders for wave functions, lighting, animation curves, etc.
Let me know if you want help generating a combined fastsinf/cosfpair or analyzing further approximations (e.g.,atan,exp, etc.).
User
And a third function with the following decompilation:double unnamed_function_4(double param1,uint param2)
You're now diving into the guts of floating-point manipulation — this one isnota polynomial approximation like thesin()orcos()cases, but instead acustom implementation of a scaled power-of-two operation.
This functionmanipulatesparam2like an exponent, applying ascaling factortoparam1. It multipliesparam1by very small or very large constants depending onparam2, and finally:
cCopy codedouble fast_scalbn(double x, int exp); // like C99 scalbn()
It implements edge-case handling for:
Underflow:Overflow:whenexp > 1023
Handling denormals via scaling with magic constants ^-960and2^1023
Underflow:Overflow:whenexp > 1023
Handling denormals via scaling with magic constants ^-960and2^1023
✅ Suggested Function Names
fast_scalbn
scaled_exp2_mul
ldexp_approx
double_scale_by_pow2
mul_pow2_safe
fast_scalbn
scaled_exp2_mul
ldexp_approx
double_scale_by_pow2
mul_pow2_safe
Let me know if you want a cleaned-up C version or want to locate where/how it's used (e.g., texture LOD, exposure/gamma correction, etc. — all of which useldexp-like behavior).
User
I'm now left with this very large function. Can you explain what it does and suggest 5 names for it?int unnamed_function_5(float param1,double *param2,float8 param_3)
Return aninteger codebased on the input’s properties (possibly a quadrant or parity).
Recognizable Math
Key signs suggest this function is ahigh-precision range reduction routinefor atrigonometric function(likesin,cos, ortan):
1. ≈ π/2
0. ≈ 2/π
Large constants like6755399441055744.0are used forrounding floats via FPU tricks
Use ofABS(param1)followed by range checks
1. ≈ π/2
0. ≈ 2/π
Large constants like6755399441055744.0are used forrounding floats via FPU tricks
Use ofABS(param1)followed by range checks
Then it:
extractionusing multiples ofπ/2
Reduces the input to a "primary interval" (e.g.[-π/4, π/4])
Returns:A reduced argument through*param2Aninteger representing the quadrant or symmetry class(e.g., for adjusting the sign ofsin/coslater)
A reduced argument through*param2
Aninteger representing the quadrant or symmetry class(e.g., for adjusting the sign ofsin/coslater)
Performsquadrant extractionusing multiples ofπ/2
Reduces the input to a "primary interval" (e.g.[-π/4, π/4])
Returns:
A reduced argument through*param2
Aninteger representing the quadrant or symmetry class(e.g., for adjusting the sign ofsin/coslater)
A reduced argument through*param2
Aninteger representing the quadrant or symmetry class(e.g., for adjusting the sign ofsin/coslater)
✅ So What Is It?
This is arange reductionfunction for trigonometric evaluation. It prepares an input angle for a latersin,cos, ortanapproximation.
Its logic is consistent with what's used in:
The Cephes math library
glibc’s high-precision__kernel_sinand__rem_pio2()
User
It is used in the following WASM fragment shader:void exportapplyLiquidGlass(int inputPtr,int outputPtr,uint width,uint height)
{
byte bVar1;
byte bVar2;
byte bVar3;
byte bVar4;
byte bVar5;
bVar6;
byte bVar7;
byte bVar8;
byte bVar9;
byte bVar10;
;
byte bVar12;
uint uVar13;
uint uVar14;
int iVar15;
float fVar16;
float fVar17;
float fVar18;
float fVar19;
float fVar20;
float ;
float fVar22;
byte *pbVar23;
byte *pbVar24;
byte *pbVar25;
undefined *puVar26;
uint uVar27;
uint uVar28;
double dVar29;
double dVar30;
;
int iVar32;
int iVar33;
float ;
float ;
float8 in_stack_fffffff0;
float8 local_8;
uVar28 = 0;
if ((0 < (int)height) && (0 < (int)width)) {
code
Assistant
Yes — this fragment shader , warped distortion filterover the input image using sine and cosine waves, mixed with a bilinear interpolation and alpha blending. It'snon-invertible in the general casebecause:
The distortion usesnonlinear trigonometric warping(sin, cos, conditional approximations),
There isresampling with interpolation(bilinear mixing of 4 surrounding pixels),
It's dependent onradius from center(fVar21 = sqrt(...)) which causes radial warping,
It usesdownmixing(multiple input pixels contribute to one output),
Alpha is modified based on distance from center (also nonlinear).
The distortion usesnonlinear trigonometric warping(sin, cos, conditional approximations),
There isresampling with interpolation(bilinear mixing of 4 surrounding pixels),
It's dependent onradius from center(fVar21 = sqrt(...)) which causes radial warping,
It usesdownmixing(multiple input pixels contribute to one output),
Alpha is modified based on distance from center (also nonlinear).
That said, youcan approximate an inverse— or undo it partially — if you can:
Reproduce the warping math,
Map from theoutput image coordinatesback to approximateinput image coordinates,
Sample from the output withreverse interpolation(this can undo distortion to a point).
Reproduce the warping math,
Map from theoutput image coordinatesback to approximateinput image coordinates,
Sample from the output withreverse interpolation(this can undo distortion to a point).
✅ Step-by-step formula overview (core transformation):
The script you've provided does the same as the WASM function now. Modify it to actually reverse the transformation. Note thatxv, yvis unused.
Assistant
To reverse the transformation applied by theapplyLiquidGlassWASM shader, we need toundo the warping and samplinglogic that maps source pixels (in the input image) to target pixels (in the output image).
The shader essentially applies a nonlinear distortion to(x, y)coordinates using trigonometric functions (sin,cos) and distance-based warping. Since it's not strictly invertible analytically, we'll need tonumerically approximate the inverse mapping, i.e., for each output pixel(x, y):
Find the input coordinate(u, v)such thatapplyLiquidGlass(u, v) ≈ (x, y)
This is often done using agrid searchoriterative refinement (e.g. Newton-Raphson or gradient descent). Below is a simplifiedapproximate reversal script, using a grid search over a small neighborhood for each output pixel:
}I'm doing a CTF challenge where the flag is an image and is passed through the fragment shader. Can you come up with the formula that is applied to all pixels? I would like to create a script that reverses the operation.
cCopy codesrc_u = u + dx * r * 0.5 + 0.1 * waveX
src_v = v + dy * r * 0.5 + 0.1 * waveY
This isnot exactly reversible, but here's how you can get close:
Create a Python script that:For eachoutputpixel coordinate(x, y):Inverts the warp logic (findu, vsuch that after applying the shader warp, you'd land at(x, y)).Use numericaloptimization (e.g., gradient descent or iterative solver)to find(src_u, src_v)that map to(x, y).Sample thewarped imageat that point to recreate the original.
For eachoutputpixel coordinate(x, y):Inverts the warp logic (findu, vsuch that after applying the shader warp, you'd land at(x, y)).Use numericaloptimization (e.g., gradient descent or iterative solver)to find(src_u, src_v)that map to(x, y).Sample thewarped imageat that point to recreate the original.
Inverts the warp logic (findu, vsuch that after applying the shader warp, you'd land at(x, y)).
Use numericaloptimization (e.g., gradient descent or iterative solver)to find(src_u, src_v)that map to(x, y).
Sample thewarped imageat that point to recreate the original.
This is .
Create a Python script that:
For eachoutputpixel coordinate(x, y):Inverts the warp logic (findu, vsuch that after applying the shader warp, you'd land at(x, y)).Use numericaloptimization (e.g., gradient descent or iterative solver)to find(src_u, src_v)that map to(x, y).Sample thewarped imageat that point to recreate the original.
Inverts the warp logic (findu, vsuch that after applying the shader warp, you'd land at(x, y)).
Use numericaloptimization (e.g., gradient descent or iterative solver)to find(src_u, src_v)that map to(x, y).
Sample thewarped imageat that point to recreate the original.
For eachoutputpixel coordinate(x, y):
Inverts the warp logic (findu, vsuch that after applying the shader warp, you'd land at(x, y)).
Use numericaloptimization (e.g., gradient descent or iterative solver)to find(src_u, src_v)that map to(x, y).
Sample thewarped imageat that point to recreate the original.
Inverts the warp logic (findu, vsuch that after applying the shader warp, you'd land at(x, y)).
Use numericaloptimization (e.g., gradient descent or iterative solver)to find(src_u, src_v)that map to(x, y).
Sample thewarped imageat that point to recreate the original.
This is .
Practical Inversion Script (Approximation)
Here's aPython sketch using NumPy and OpenCVto simulate the inverse:
This assumes a known distorted image, and tries to reverse it by undoing the warp — it's approximate but might reveal enough for a CTF.
CTF-Specific Hint
If you're given the distorted image and need to extract the flag visually (e.g., QR code or readable characters), the above process shouldde-warpit enough to make it legible.