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

Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...FIDO Alliance
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfFIDO Alliance
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Skynet Technologies
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...FIDO Alliance
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideStefan Dietze
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data SciencePaolo Missier
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTopCSSGallery
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctBrainSell Technologies
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxFIDO Alliance
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...ScyllaDB
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGDSC PJATK
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!Memoori
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxFIDO Alliance
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxjbellis
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?Mark Billinghurst
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераMark Opanasiuk
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfFIDO Alliance
 

Recently uploaded (20)

Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 

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