SlideShare a Scribd company logo
1 of 15
Android OpenGL ES Game
ImageGrabber Final Report
Jungsoo Nam
2015/03/26
namjungsoo@gmail.com
Agenda
• Development environment setup
• Development tools setup
• Build guide
• Source code review
• Java classes/methods
• C functions
• ELF architecture with flow chart
• Linux hooking mechanism
Development environment setup (1/2)
• Development tools setup
• Eclipse with ADT(Android Developer Tools) for Mac
• http://dl.google.com/android/adt/adt-bundle-mac-x86_64-20140702.zip
• SDK updates
• Requires android-18(4.4)
• NDK setup
• android-ndk-r10d-darwin-x86_64.bin
• Bash Profile setup
• vi .bash_profile
• export PATH=$PATH:/Users/yegam400/Downloads/android-ndk-r10d
Development environment setup (2/2)
• Build guide
• Download source codes(link to download)
• AngryBots.zip
• MediaWebEncoder.zip
• Import projects
• File – Import – Android – Existing Android Code into workspace
• NDK build
• Open terminal
• cd MediaWebEncoder
• ndk-build => libmediaweb.so
• In Eclipse, Right click at MediaWebEncoder project, click “Refresh (F5)”
• Run Unity3D app(UnityPlayerNativeActivity(=AngryBots))
• In Eclipse, Check project reference with MediaWebEncoder
Source code review – Java (1/3)
• com.medaweb.Grabber.VideoGrabber
• public
• startEncoder() – starts video recording
• stopEncoder() – stops video recording
• getRecordingEnabled() – gets recording enabled
• initialize() – initialize grabber
• private
• begin/endClear() – called when glClear() -> deprecated
• begin/endSwapBuffers() – called when eglSwapBuffer()
• prepareFrameBuffer() – called when glBindFrameBuffer()
Source code review – Java (2/3)
• com.android.grafika.gles – Reuse Grafika sources
• Texture2dProgram (modified for our implementation)
• draw2() – similar to draw()
• backupStates() – backup GLSL, arraybuffer and texture stage states
• setupStates() – same as draw()’s one
• restoreStates() – restore GLSL, arraybuffer and texture stage states
• To backup rendering states are the states which are changed by
setupState():
• 1. active texture unit
• 2. multi texture binding
• 3. current program binding
• 4. array buffer binding
• 5. vertex shader attributes
• 6. blend enabled
• 7. vertex shader attributes' pointer arrays
Source code review – Java (3/3)
• Library copy(not needed when using project reference linking)
• mediawebencoder.jar -> libs
• libmediaweb.so -> libs/armeabi-v7a
• User code
• initialize()
• startEncoder()
• stopEncoder()
Source code review – C (1/5)
• Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := mediaweb
LOCAL_LDLIBS:= -llog -landroid -lEGL -lGLESv2
LOCAL_SRC_FILES := mediaweb.c hook.c
LOCAL_CFLAGS := -w
include $(BUILD_SHARED_LIBRARY)
• Application.mk
APP_ABI := armeabi-v7a
APP_PLATFORM := android-14
Source code review – C (2/5)
• mediaweb.c
• Called by VideoGrabber
• Called by Texture2dProgram
public class VideoGrabber {
static {
System.loadLibrary("mediaweb");
}
public static native void setInputSurface(long surfaceNativeHandle);
public static native int getWidth();
public static native int getHeight();
public static native void makeCurrent();
public static native void startNativeEncoder(int captureFbo);
public static native void stopNativeEncoder();
public static native void backupVertexAttribPointer(int index);
public static native void restoreVertexAttribPointer(int index, int size, int
type, int normalized, int stride);
Source code review – C (3/5)
• mediaweb.c
• public
• setInputSurface() - set MediaCodec input surface handle
• makeCurrent() – call eglMakeCurrent() with original surfaces
• backupVertexAttribPointer() - backup by glGetVertexAttribPointerv()
• restoreVertexAttribPointer() - restore by glVertexAttribPointer()
• startNativeEncoder() – start native side encoder with custom fbo handle
• stopNativeEncoder() – stop native side encoder
• private
• setupViewport() - calls prepareFramebuffer()
• do_hook2() - do_hook() wrapper. Hook a function
• so_entry() - hooks OpenGL ES functions
• JNI_OnLoad() - called when JNI initializing
These are not
supported by Java
OpenGL ES Wrapper
Source code review – C (4/5)
• mediaweb.c
• private
• hooked_glViewport()
• when first called, calls setupViewport() -> prepareFramebuffer()
• hooked_glClear()
• hooked glClear() function. rendering entry point -> deprecated.
• hooked_glBindFramebuffer()
• rendering entry point.
• If framebuffer == 0, then this is main fbo, so it changes mainfbo to capturefbo for capture when stateRecording
== 1.
• hooked_eglSwapBuffers()
• rendering end point.
• If stateRecording == 1, then calls beginSwapBuffers() -> orig_eglSwapBuffers() -> endSwapBuffers()
• hooked_eglMakeCurrent()
• when first called, remember main surfaces
• Unity3D callstack
• glClear()
• glBindFramebuffer()
• eglSwapBuffers()
4 times
Source code review – C (5/5)
• hook.c
• private
• get_module_base() – get certain module(*.so) base memory address from
/proc/self/maps
• find_got_entry_address_() – load certain module and find functions address
offset.(according to ELF file format)
• public
• do_hook() – entry of function hooking
• Replace entry_addr to hook_func
• Entry address = base address + offset address
ELF architecture with flow chart
• Document
• http://www.cs.bgu.ac.il/~caspl142/wiki.files/lab7/elf.pdf
Linux hooking mechanism
• dlsym() vs Elf32_Ehdr
Thank you

More Related Content

What's hot

What's hot (20)

What is OpenGL ?
What is OpenGL ?What is OpenGL ?
What is OpenGL ?
 
OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.
 
SIGGRAPH Asia 2008 Modern OpenGL
SIGGRAPH Asia 2008 Modern OpenGLSIGGRAPH Asia 2008 Modern OpenGL
SIGGRAPH Asia 2008 Modern OpenGL
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
 
Open Graphics Library
Open Graphics  Library Open Graphics  Library
Open Graphics Library
 
OpenGL for 2015
OpenGL for 2015OpenGL for 2015
OpenGL for 2015
 
Open gl
Open glOpen gl
Open gl
 
Opengl basics
Opengl basicsOpengl basics
Opengl basics
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programming
 
NVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityNVIDIA's OpenGL Functionality
NVIDIA's OpenGL Functionality
 
Baiscs of OpenGL
Baiscs of OpenGLBaiscs of OpenGL
Baiscs of OpenGL
 
Opengl (1)
Opengl (1)Opengl (1)
Opengl (1)
 
Android native gl
Android native glAndroid native gl
Android native gl
 
OpenGL Basics
OpenGL BasicsOpenGL Basics
OpenGL Basics
 
Angular Weekend
Angular WeekendAngular Weekend
Angular Weekend
 
Daggerate your code - Write your own annotation processor
Daggerate your code - Write your own annotation processorDaggerate your code - Write your own annotation processor
Daggerate your code - Write your own annotation processor
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
 
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
 
OpenGL Transformation
OpenGL TransformationOpenGL Transformation
OpenGL Transformation
 
IOS debugging
IOS debuggingIOS debugging
IOS debugging
 

Similar to Android OpenGL ES Game ImageGrabber Final Report

2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)JiandSon
 
Kandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalKandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalNAVER D2
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Opersys inc.
 
From Android NDK To AOSP
From Android NDK To AOSPFrom Android NDK To AOSP
From Android NDK To AOSPMin-Yih Hsu
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux DevelopersOpersys inc.
 
Native code in Android applications
Native code in Android applicationsNative code in Android applications
Native code in Android applicationsDmitry Matyukhin
 
把鐵路開進視窗裡
把鐵路開進視窗裡把鐵路開進視窗裡
把鐵路開進視窗裡Wei Jen Lu
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineChun-Yu Wang
 
20150317 firefox os_studymtg_engver
20150317 firefox os_studymtg_engver20150317 firefox os_studymtg_engver
20150317 firefox os_studymtg_engverNaoki Sekiguchi
 
Improving app performance with Kotlin Coroutines
Improving app performance with Kotlin CoroutinesImproving app performance with Kotlin Coroutines
Improving app performance with Kotlin CoroutinesHassan Abid
 
stackconf 2022: Cluster Management: Heterogeneous, Lightweight, Safe. Pick Three
stackconf 2022: Cluster Management: Heterogeneous, Lightweight, Safe. Pick Threestackconf 2022: Cluster Management: Heterogeneous, Lightweight, Safe. Pick Three
stackconf 2022: Cluster Management: Heterogeneous, Lightweight, Safe. Pick ThreeNETWAYS
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overviewKevin He
 
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit,
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit, Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit,
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit, Farshid Pirahansiah
 
An Introduction to Play 2 Framework
An Introduction to Play 2 FrameworkAn Introduction to Play 2 Framework
An Introduction to Play 2 FrameworkPT.JUG
 
Digging for Android Kernel Bugs
Digging for Android Kernel BugsDigging for Android Kernel Bugs
Digging for Android Kernel BugsJiahong Fang
 

Similar to Android OpenGL ES Game ImageGrabber Final Report (20)

2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
 
React inter3
React inter3React inter3
React inter3
 
Kandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalKandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_final
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013
 
From Android NDK To AOSP
From Android NDK To AOSPFrom Android NDK To AOSP
From Android NDK To AOSP
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
 
Native code in Android applications
Native code in Android applicationsNative code in Android applications
Native code in Android applications
 
Core Android
Core AndroidCore Android
Core Android
 
把鐵路開進視窗裡
把鐵路開進視窗裡把鐵路開進視窗裡
把鐵路開進視窗裡
 
AMIS Oracle OpenWorld 2013 Review Part 3 - Fusion Middleware
AMIS Oracle OpenWorld 2013 Review Part 3 - Fusion MiddlewareAMIS Oracle OpenWorld 2013 Review Part 3 - Fusion Middleware
AMIS Oracle OpenWorld 2013 Review Part 3 - Fusion Middleware
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machine
 
Introduction to CQ5
Introduction to CQ5Introduction to CQ5
Introduction to CQ5
 
20150317 firefox os_studymtg_engver
20150317 firefox os_studymtg_engver20150317 firefox os_studymtg_engver
20150317 firefox os_studymtg_engver
 
Improving app performance with Kotlin Coroutines
Improving app performance with Kotlin CoroutinesImproving app performance with Kotlin Coroutines
Improving app performance with Kotlin Coroutines
 
stackconf 2022: Cluster Management: Heterogeneous, Lightweight, Safe. Pick Three
stackconf 2022: Cluster Management: Heterogeneous, Lightweight, Safe. Pick Threestackconf 2022: Cluster Management: Heterogeneous, Lightweight, Safe. Pick Three
stackconf 2022: Cluster Management: Heterogeneous, Lightweight, Safe. Pick Three
 
React nativebeginner1
React nativebeginner1React nativebeginner1
React nativebeginner1
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overview
 
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit,
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit, Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit,
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit,
 
An Introduction to Play 2 Framework
An Introduction to Play 2 FrameworkAn Introduction to Play 2 Framework
An Introduction to Play 2 Framework
 
Digging for Android Kernel Bugs
Digging for Android Kernel BugsDigging for Android Kernel Bugs
Digging for Android Kernel Bugs
 

Recently uploaded

Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 

Android OpenGL ES Game ImageGrabber Final Report

  • 1. Android OpenGL ES Game ImageGrabber Final Report Jungsoo Nam 2015/03/26 namjungsoo@gmail.com
  • 2. Agenda • Development environment setup • Development tools setup • Build guide • Source code review • Java classes/methods • C functions • ELF architecture with flow chart • Linux hooking mechanism
  • 3. Development environment setup (1/2) • Development tools setup • Eclipse with ADT(Android Developer Tools) for Mac • http://dl.google.com/android/adt/adt-bundle-mac-x86_64-20140702.zip • SDK updates • Requires android-18(4.4) • NDK setup • android-ndk-r10d-darwin-x86_64.bin • Bash Profile setup • vi .bash_profile • export PATH=$PATH:/Users/yegam400/Downloads/android-ndk-r10d
  • 4. Development environment setup (2/2) • Build guide • Download source codes(link to download) • AngryBots.zip • MediaWebEncoder.zip • Import projects • File – Import – Android – Existing Android Code into workspace • NDK build • Open terminal • cd MediaWebEncoder • ndk-build => libmediaweb.so • In Eclipse, Right click at MediaWebEncoder project, click “Refresh (F5)” • Run Unity3D app(UnityPlayerNativeActivity(=AngryBots)) • In Eclipse, Check project reference with MediaWebEncoder
  • 5. Source code review – Java (1/3) • com.medaweb.Grabber.VideoGrabber • public • startEncoder() – starts video recording • stopEncoder() – stops video recording • getRecordingEnabled() – gets recording enabled • initialize() – initialize grabber • private • begin/endClear() – called when glClear() -> deprecated • begin/endSwapBuffers() – called when eglSwapBuffer() • prepareFrameBuffer() – called when glBindFrameBuffer()
  • 6. Source code review – Java (2/3) • com.android.grafika.gles – Reuse Grafika sources • Texture2dProgram (modified for our implementation) • draw2() – similar to draw() • backupStates() – backup GLSL, arraybuffer and texture stage states • setupStates() – same as draw()’s one • restoreStates() – restore GLSL, arraybuffer and texture stage states • To backup rendering states are the states which are changed by setupState(): • 1. active texture unit • 2. multi texture binding • 3. current program binding • 4. array buffer binding • 5. vertex shader attributes • 6. blend enabled • 7. vertex shader attributes' pointer arrays
  • 7. Source code review – Java (3/3) • Library copy(not needed when using project reference linking) • mediawebencoder.jar -> libs • libmediaweb.so -> libs/armeabi-v7a • User code • initialize() • startEncoder() • stopEncoder()
  • 8. Source code review – C (1/5) • Android.mk LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := mediaweb LOCAL_LDLIBS:= -llog -landroid -lEGL -lGLESv2 LOCAL_SRC_FILES := mediaweb.c hook.c LOCAL_CFLAGS := -w include $(BUILD_SHARED_LIBRARY) • Application.mk APP_ABI := armeabi-v7a APP_PLATFORM := android-14
  • 9. Source code review – C (2/5) • mediaweb.c • Called by VideoGrabber • Called by Texture2dProgram public class VideoGrabber { static { System.loadLibrary("mediaweb"); } public static native void setInputSurface(long surfaceNativeHandle); public static native int getWidth(); public static native int getHeight(); public static native void makeCurrent(); public static native void startNativeEncoder(int captureFbo); public static native void stopNativeEncoder(); public static native void backupVertexAttribPointer(int index); public static native void restoreVertexAttribPointer(int index, int size, int type, int normalized, int stride);
  • 10. Source code review – C (3/5) • mediaweb.c • public • setInputSurface() - set MediaCodec input surface handle • makeCurrent() – call eglMakeCurrent() with original surfaces • backupVertexAttribPointer() - backup by glGetVertexAttribPointerv() • restoreVertexAttribPointer() - restore by glVertexAttribPointer() • startNativeEncoder() – start native side encoder with custom fbo handle • stopNativeEncoder() – stop native side encoder • private • setupViewport() - calls prepareFramebuffer() • do_hook2() - do_hook() wrapper. Hook a function • so_entry() - hooks OpenGL ES functions • JNI_OnLoad() - called when JNI initializing These are not supported by Java OpenGL ES Wrapper
  • 11. Source code review – C (4/5) • mediaweb.c • private • hooked_glViewport() • when first called, calls setupViewport() -> prepareFramebuffer() • hooked_glClear() • hooked glClear() function. rendering entry point -> deprecated. • hooked_glBindFramebuffer() • rendering entry point. • If framebuffer == 0, then this is main fbo, so it changes mainfbo to capturefbo for capture when stateRecording == 1. • hooked_eglSwapBuffers() • rendering end point. • If stateRecording == 1, then calls beginSwapBuffers() -> orig_eglSwapBuffers() -> endSwapBuffers() • hooked_eglMakeCurrent() • when first called, remember main surfaces • Unity3D callstack • glClear() • glBindFramebuffer() • eglSwapBuffers() 4 times
  • 12. Source code review – C (5/5) • hook.c • private • get_module_base() – get certain module(*.so) base memory address from /proc/self/maps • find_got_entry_address_() – load certain module and find functions address offset.(according to ELF file format) • public • do_hook() – entry of function hooking • Replace entry_addr to hook_func • Entry address = base address + offset address
  • 13. ELF architecture with flow chart • Document • http://www.cs.bgu.ac.il/~caspl142/wiki.files/lab7/elf.pdf
  • 14. Linux hooking mechanism • dlsym() vs Elf32_Ehdr