Announcement

Collapse
No announcement yet.

All about how to build an old Chrome Browser for each platform

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • All about how to build an old Chrome Browser for each platform


    This article will continue to be updated if there are improved build commands.

    Code:
    =======================================================================================================================================
    1. Intro
    
    If you start studying browser hacking, Only the research preparation process consumes 70 percent.
    It is a very sad reality. I only wanted to study the core.
    These commands are not directly related to research projects. But everyone must go through this process.
    So I think that commands should be shared with each other in order to reduce duplication of unnecessary preparation work.
    We need a build environment on the specified version unless we do zero day research. Or to reproduce the results of another researcher.
    However, older build environments have more build errors. Therefore we need build commands that have already been tested.
    
    Of course, the Windows Chrome Browser must be built on Windows. Android and Linux Chrome Browsers must be built on Linux.
    From what I tested, it didn't build on Windows 10's WSL(version 1) Linux.
    It's a bug. So Microsoft changed its development direction to WSL2 and dropped the WSL1 project.
    If so, use VMware. WSL2 no longer emulates, but operates on a hypervisor-based basis.
    So it's better to use VMware.
    For Windows, there is a way to build on a cross platform. But that method is dirty. I do not recommend that way.
    And in a Windows environment, you couldn't build a Chrome Browser for Linux. I thought it would be possible.
    I was an idiot. :)
    =======================================================================================================================================
    2. Enter "chrome://version" into the URL window of the Chrome Browser and check the target version.
    
    Chrome    76.0.3809.132 (Official Builds) (32bit)  <-- Target chrome version
    commit    fd1acc410994a7a68ac25bc77513d443f3130860-refs/branch-heads/3809@{#1035}
    OS    Windows 10 OS Version 1903 (Build 19018.1)
    JavaScript    V8 7.6.303.29  <-- Target v8 version
    
    =====================================================================================================================================
    3. How to Build Windows Chrome Browser
    
    You must first get depot_tools.zip. I suppose you have registered the tool in an environment variable.
    
    C:\> mkdir C:\Google\chromium
    C:\> cd C:\Google\chromium
    C:\Google\chromium> set DEPOT_TOOLS_UPDATE=0
    C:\Google\chromium> set DEPOT_TOOLS_WIN_TOOLCHAIN=0
    C:\Google\chromium> fetch chromium
    C:\Google\chromium> cd src
    C:\Google\chromium\src> gclient sync --with_branch_heads --with_tags
    C:\Google\chromium\src> git checkout –t tags/76.0.3809.132
    C:\Google\chromium\src> gclient sync –D –j4
    C:\Google\chromium\src> gn gen --args="is_debug=false is_clang=true use_goma=false use_jumbo_build=true
                            is_component_build=false is_official_build=true proprietary_codecs=true
                            enable_widevine=true ffmpeg_branding=\"Chrome\" chrome_pgo_phase=0
                            enable_iterator_debugging=false enable_nacl=false is_win_fastlink=true
                            clang_use_chrome_plugins=false blink_symbol_level=0 visual_studio_version=\"2017\"
                            target_os=\"win\" target_cpu=\"x86\"" out/GN_CHROME_RELEASE_76.0.3809.132_x86
    
    C:\Google\chromium\src> autoninja -j4 -C out/GN_CHROME_RELEASE_76.0.3809.132_x86 chrome
    
    ----------------------------------------------------------------------------------------------
    If you are working on Windows, you can debug without building your own Windows Chrome Browser.
    The research method is to use a symbol server.
    
    You can use prebuilt Chrome Browser binaries and analyze them using a symbol server at the same time.
    You probably need to build only d8.exe. However, d8 is not a universal debugger.
    
    For reference, you can't use "addrof(window)" in d8(v8 console engine).
    Because d8 is a pure JavaScript engine, it doesn't have a browser native binding object. (Like the window object in the example)
    Therefore, you need to use "--js-flag" in Windows Chrome Browser.
    This is just a reference that is not relevant to the article. But it's good to know. Find this part yourself.
    
    You must install windbg before using this command. The following command is one line:
    
    ---------------------------------------------
    [How to set up symbol server: Example CASE-1]
    ---------------------------------------------
    C:\> "C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\symchk.exe"
         /r C:\Google\Google_Chrome_Portable_32bit_v76.0.3809.132\App\Chrome-bin\76.0.3809.132
         /s SRV*C:\Symbols*https://msdl.microsoft.com/download/symbols;
         SRV*C:\Symbols*https://chromium-browser-symsrv.commondatastorage.googleapis.com;
         SRV*C:\Symbols*https://download.amd.com/dir/bin;
         SRV*C:\Symbols*https://driver-symbols.nvidia.com/;
         SRV*C:\Symbols*https://software.intel.com/sites/downloads/symbols
    ---------------------------------------------
    [How to set up symbol server: Example CASE-2]
    ---------------------------------------------
    C:\> "c:\Program Files (x86)\Windows Kits\10\Debuggers\x64\symchk.exe" /r C:\Windows\SysWOW64 /s SRV*C:\Symbols*http://msdl.microsoft.com/download/symbols
    
    =====================================================================================================================================
    4. How to Build Android Chrome Browser
    
    If you get an error when you run autoninja, the following packages are not installed.
    You will need to install the following packages using apt-get:
    
    $ sudo apt-get install build-essential python gperf bison pkg-config openjdk-8-jdk protobuf-c-compiler protobuf-compiler
    $ export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
    $ export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib
    $ export PATH=$JAVA_HOME/bin:$PATH
    
    $ mkdir chromium && cd chromium
    $ fetch android
    $ cd src && gclient sync --with_branch_heads --with_tags
    $ git checkout -t tags/76.0.3809.132
    $ gclient sync -D -j4
    
    $ gn gen  --args="is_debug=false is_clang=true is_official_build=true target_os=\"android\" target_cpu=\"arm\"" out/GN_ARM_PACKED_CHROME_76.0.3809.132
    $ autoninja -j4 -C out/GN_ARM_PACKED_CHROME_76.0.3809.132 chrome_public_apk
    
    When the build is complete, the apks directory and the lib.unstripped directory will be created in the output directory.
    In the apks directory, apk files will be created, and in the lib.unstripped directory, a libchrome.so file will be created for debugging.
    
    -------------------------------------------------------------
    The following commands are for reference only and do not use.
    This is because it does not create a libchrome.so file.
    -------------------------------------------------------------
    $ gn gen  --args="is_debug=true is_clang=true target_os=\"android\" target_cpu=\"arm\"" out/GN_ARM_UNPACKED_CHROME_76.0.3809.132
    $ autoninja  -j4  -C  out/GN_ARM_UNPACKED_CHROME_76.0.3809.132  chrome_modern_public_apk
    
    $ gn gen  --args="is_debug=true is_clang=true target_os=\"android\" target_cpu=\"arm\"" out/GN_ARM_UNPACKED_MONOCHROME_76.0.3809.132
    $ autoninja  -j4  -C  out/GN_ARM_UNPACKED_MONOCHROME_76.0.3809.132  monochrome_public_apk
    
    =====================================================================================================================================
    5. How to Build Windows d8.exe
    
    You must first get depot_tools.zip. I suppose you have registered the tool in an environment variable.
    
    Build 32 bit Windows old d8 version (v8 debug console)
    
    C:\> SET DEPOT_TOOLS_UPDATE=0
    C:\> SET DEPOT_TOOLS_WIN_TOOLCHAIN=0
    C:\> mkdir C:\Google\chromium
    C:\> cd Google\chromium
    C:\Google\chromium> fetch chromium
    C:\Google\chromium> cd src
    C:\Google\chromium\src> gclient sync -j4
    C:\Google\chromium\src> cd v8
    C:\Google\chromium\src\v8> git checkout -t origin/7.6.303
    C:\Google\chromium\src\v8> git pull
    C:\Google\chromium\src\v8> cd ..
    C:\Google\chromium\src> gn gen --ide=vs2017 --filters=//v8/* --no-deps --args="is_debug=true v8_postmortem_support=true
                            v8_use_snapshot=true v8_enable_disassembler=true v8_enable_backtrace=true v8_enable_verify_heap=true
                            v8_enable_object_print=true v8_enable_i18n_support=false is_clang=false treat_warnings_as_errors=false
                            symbol_level=1 v8_enable_fast_mksnapshot=true is_component_build=false target_cpu=\"x86\"
                            v8_target_cpu=\"x86\"" out/GN_CHROME_D8_7.6.303_x86
    --------------------------------------------------------------------------------------
    If an error occurs after this command, you should fix the path in some BUILD.gn files.
    ---------- in the BUILD.gn file ---------
    import("//v8/gni/snapshot_toolchain.gni")
    -> import("//v8/snapshot_toolchain.gni")
    -----------------------------------------
    C:\Google\chromium\src> ninja -C out/GN_CHROME_D8_7.6.303_x86 d8
    C:\Google\chromium\src> cd out\GN_CHROME_D8_7.6.303_x86
    
    --------------------------------------
    d8 is a set of three files as follows.
    --------------------------------------
    C:\Google\chromium\src\out\GN_CHROME_D8_7.6.303_x86> dir d8.exe /w
    C:\Google\chromium\src\out\GN_CHROME_D8_7.6.303_x86> dir natives_blob.bin /w
    C:\Google\chromium\src\out\GN_CHROME_D8_7.6.303_x86> dir snapshot_blob.bin /w
    
    =====================================================================================================================================
    6. How to Build Linux d8
    
    You must first get depot_tools.zip. I suppose you have registered the tool in an environment variable.
    
    Build 32 bit Linux old d8 version (v8 debug console based on x86)
    
    If you get an error when you run autoninja, the following packages are not installed.
    You will need to install the following packages using apt-get:
    
    $ sudo apt-get install build-essential python gperf bison pkg-config openjdk-8-jdk protobuf-c-compiler protobuf-compiler
    $ export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
    $ export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib
    $ export PATH=$JAVA_HOME/bin:$PATH
    
    # mkdir -p Google/chromium
    # cd Google/chromium
    # fetch chromium
    # vi .gclient
    --------------------------------------------------------
    Add the following to the last line of the .gclient file:
    --------------------------------------------------------
    target_os=['linux'];
    --------------------------------------------------------
    # cd src
    # gclient sync -j4
    # cd v8
    # git checkout -t origin/7.6.303
    # git pull
    # cd ..
    # gn gen --filters=//v8/* --no-deps --args="use_lld=true use_gold=false is_debug=true \
      v8_postmortem_support=true v8_use_snapshot=true v8_enable_disassembler=true \
      v8_enable_backtrace=true v8_enable_object_print=true v8_enable_i18n_support=false \
      treat_warnings_as_errors=false symbol_level=1 v8_enable_fast_mksnapshot=true \
      is_component_build=false target_os=\"linux\" target_cpu=\"x86\" \
      v8_target_cpu=\"x86\"" out/GN_CHROME_D8_7.6.303_x86
    --------------------------------------------------------------------------------------
    If an error occurs after this command, you should fix the path in some BUILD.gn files.
    ---------- in the BUILD.gn file ---------
    import("//v8/gni/snapshot_toolchain.gni")
    -> import("//v8/snapshot_toolchain.gni")
    -----------------------------------------
    # ninja -C out/GN_CHROME_D8_7.6.303_x86 d8
    # cd out/GN_CHROME_D8_7.6.303_x86
    
    --------------------------------------
    d8 is a set of three files as follows.
    --------------------------------------
    # ls -al ./d8
    # ls -al ./natives_blob.bin
    # ls -al ./snapshot_blob.bin
    
    =====================================================================================================================================
    7. How to Build Android d8
    
    You must first get depot_tools.zip. I suppose you have registered the tool in an environment variable.
    
    Build 32 bit Android old d8 version (v8 debug console based on ARM)
    
    If you get an error when you run autoninja, the following packages are not installed.
    You will need to install the following packages using apt-get:
    
    $ sudo apt-get install build-essential python gperf bison pkg-config openjdk-8-jdk protobuf-c-compiler protobuf-compiler
    $ export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
    $ export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib
    $ export PATH=$JAVA_HOME/bin:$PATH
    
    # mkdir -p Google/chromium
    # cd Google/chromium
    # fetch chromium
    # vi .gclient
    --------------------------------------------------------
    Add the following to the last line of the .gclient file:
    --------------------------------------------------------
    target_os=['android'];
    --------------------------------------------------------
    # cd src
    # gclient sync -j4
    # cd v8
    # git checkout -t origin/7.6.303
    # git pull
    # cd ..
    # gn gen --filters=//v8/* --no-deps --args="use_lld=true use_gold=false is_debug=true
      v8_postmortem_support=true v8_use_snapshot=true v8_enable_disassembler=true
      v8_enable_backtrace=true v8_enable_object_print=true v8_enable_i18n_support=false
      treat_warnings_as_errors=false symbol_level=1 v8_enable_fast_mksnapshot=true
      is_component_build=false target_os=\"android\" target_cpu=\"arm\"
      v8_target_cpu=\"arm\"" out/GN_CHROME_D8_7.6.303_ARM d8
    --------------------------------------------------------------------------------------
    If an error occurs after this command, you should fix the path in some BUILD.gn files.
    ---------- in the BUILD.gn file ---------
    import("//v8/gni/snapshot_toolchain.gni")
    -> import("//v8/snapshot_toolchain.gni")
    -----------------------------------------
    # ninja -C out/GN_CHROME_D8_7.6.303_ARM d8
    # cd out/GN_CHROME_D8_7.6.303_ARM
    
    --------------------------------------
    d8 is a set of three files as follows.
    --------------------------------------
    # ls -al ./d8
    # ls -al ./natives_blob.bin
    # ls -al ./snapshot_blob.bin
    
    =====================================================================================================================================

    <Advice - 1>

    If the following problem occurs when building with autoninja, the solution is as follows.

    This is because of the following problems:
    Click image for larger version  Name:	Chrome_Build_on_WSL2.png Views:	0 Size:	81.7 KB ID:	373

    <Advice - 2>
    Ignore all of the following. It's not important.

    Nevertheless, there is a reason to write such an article.
    It is trying to show that an error occurs depending on how you give GN's build options


    The following error occurs if you build an older version of Windows Chrome Browser with the enable_print_preview option. So I removed the enable_print_preview option from the GN build option in the above article.



    Build Error - 1
    Click image for larger version  Name:	BuildBugs.png Views:	0 Size:	541.7 KB ID:	367

    Build Error - 2
    Click image for larger version  Name:	BuildBugs2.png Views:	0 Size:	595.3 KB ID:	368

    This problem occurs every time you build an older version, so be careful.
    You can patch it, but it's very cumbersome. This problem was not solved with a simple patch.
    I stopped the patch and readjusted the GN options. So this problem is all solved.

    The following is the build command verified in Windows.

    Click image for larger version  Name:	20191117_chrome_build_tested_on_windows.png Views:	0 Size:	278.7 KB ID:	369

    The following is the build command verified in Linux.


    Click image for larger version  Name:	20191117_chrome_build_tested_on_linux.png Views:	0 Size:	90.1 KB ID:	372

    I say it again, read and ignore this advice parts. It is only a reference.
Working...
X