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

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
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
 

Recently uploaded (20)

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
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
 

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