toolbox.c -- struct - define toolname - tool.h <==== please help me learn this! - Android Software Development

Updated with answer: (not sure how much of this is actually needed but it gets you playing with your own custom Android 6.01 Toolbox!)
Trying to compile toolbox.c for some odd reason? Or bionic? Or the libc libraries, all this section of code is super easy.
1. I downloaded the AOSP that matched the build number of the sources for my device
2. I download the sources for my device and merged them in as described in the text file. (basically replace don't merge)
3. I copied in my device specific hardware I found from the AP file of my firmware.
4. I follow instructions both on the AOSP site and on this forum to prepare my platform for building. (stole some settings from cyanogenmod real quick)
5. make modules <==== list of modules
6. make toolbox
words
https://android.googlesource.com/platform/system/core/+/master/toolbox
Here's the code that's stumping me (compiler can't find tools.h and neither can I) It seems to be created on the fly but how does it do it?
Code:
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define TOOL(name) int name##_main(int, char**);
#include "tools.h"
#undef TOOL
static struct {
const char* name;
int (*func)(int, char**);
} tools[] = {
#define TOOL(name) { #name, name##_main },
#include "tools.h"
#undef TOOL
{ 0, 0 },
};
Here's toolbox.c Google Source
https://android.googlesource.com/platform/system/core/+/master/toolbox/toolbox.c

Related

Problem with DLL

Hello!
Please, can you show me a sample code of the simple DLL for PDA? I don't realy sure that I write function implementation in correct place...
Here is my code, can you tell me were is my mistake?
myHeader.h
Code:
#ifdef MYDLL_IMPLEMENTATION
#define DLLEXPORT _declspec(dllexport)
#else
#define DLLEXPORT _declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C" {
#endif
DLLEXPORT int _cdecl Get54();
#ifdef __cplusplus
}
#endif
cppDll.cpp
Code:
// CppDll.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "CppDll.h"
#include "myHeader.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define MYDLL_IMPLEMENTATION
//
// Note!
// .......
//
/////////////////////////////////////////////////////////////////////////////
// CCppDllApp
BEGIN_MESSAGE_MAP(CCppDllApp, CWinApp)
//{{AFX_MSG_MAP(CCppDllApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCppDllApp construction
CCppDllApp::CCppDllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CCppDllApp object
CCppDllApp theApp;
int _cdecl Get54()
{
return 54;
}

How to execute arbitrary code...

Dear all,
I want to publish here one very very simple method how you can execute arbitrary code in your applications.
This method can be used to protect your software with runtime decryption\encryption mechanisms.
For example, your license checking function can be stored in the exe-file somehow encrypted and you'll be able to decrypt it in runtime end execute.
Using this method you can even encrypt all your application and decrypt only necessary functions just before you want to execute them.
Of course you should understand that any security mechanisms sooner or later will be cracked, but our goal is not to create non-breakable security, but to make cracking process more expensive then buying a license.
So, the idea is simple: we can prepare some buffer in the application and in the runtime copy there code we want to execute.
Here is source code:
Code:
/*
After compilation it is necessary to change flags of .mysec
from 60000020 (Code Execute Read) на E0000020 (Code Execute Read Write)
Just open exe-file, search for 0x20 0x00 0x00 0x60 after text ".mysec"
and change it to 0x20 0x00 0x00 0xE0
*/
#include <windows.h>
// turn off optimiztions
#pragma optimize("", off)
// define our code segment
#pragma code_seg(".mysec")
// let's allocate some place in our new segment
__declspec(allocate(".mysec")) BYTE pBUF[100];
// put functions to the new segment (not necessary!)
int func1(int i)
{
return i*2;
}
int func2(void) // just fake function. we'll need it to find size of func1
{
return 5;
}
// turn on optimizations
#pragma optimize("", on)
// switch back to .text segment
#pragma code_seg()
// define pointer to function
typedef int (*pfn_t)(int i);
int _tmain(int argc, TCHAR* argv[])
{
func2(); // not so necessary, but linker might remove unused functions... :-\
// here we're copying code of func1 into the buffer :)
// in fact, here should be some procedure decrypting necessary
// code into our buffer, but to simplify the example, I'll
// just copy one of existing functions int the buffer
// and then execute it
memcpy(pBUF, &func1, (int)&func2 - (int)&func1);
int a = ((pfn_t)(void*)pBUF)(4); // execute
// show result
wchar_t pBuf[20] = {0};
wsprintf(pBuf, L"a = %d", a);
::MessageBoxW(0, pBuf, L"tst1", MB_OK);
return 0;
}
I'll also attach the compiled application for those who think it won't work.
Thank you!
Best regards,
efrost

Sample of Nokia.c found in cyanogenmod-sony-kernel-msm8960 for USB driver.

Was searching for Qualcomm drivers to throw at my Lumia. Same cpu and looks like it was written for PC Suite Mode. Actually there's Nokia stuff all over in the folder I downloaded. Found here http://searchcode.com/codesearch/view/42236209.
Code:
/* nokia.c -- Nokia Composite Gadget Driver
*
* Copyright (C) 2008-2010 Nokia Corporation
* Contact: Felipe Balbi <[email protected]>
*
* This gadget driver borrows from serial.c which is:
*
* Copyright (C) 2003 Al Borchers ([email protected])
* Copyright (C) 2008 by David Brownell
* Copyright (C) 2008 by Nokia Corporation
*
* This software is distributed under the terms of the GNU General
* Public License ("GPL") as published by the Free Software Foundation,
* version 2 of that License.
*/
#include <linux/kernel.h>
#include <linux/utsname.h>
#include <linux/device.h>
#include "u_serial.h"
#include "u_ether.h"
#include "u_phonet.h"
#include "gadget_chips.h"
/* Defines */
#define NOKIA_VERSION_NUM 0x0211
#define NOKIA_LONG_NAME "N900 (PC-Suite Mode)"
/*-------------------------------------------------------------------------*/
/*
* Kbuild is not very cooperative with respect to linking separately
* compiled library objects into one module. So for now we won't use
* separate compilation ... ensuring init/exit sections work to shrink
* the runtime footprint, and giving us at least some parts of what
* a "gcc --combine ... part1.c part2.c part3.c ... " build would.
*/
#include "composite.c"
#include "usbstring.c"
#include "config.c"
#include "epautoconf.c"
#include "u_serial.c"
#include "f_acm.c"
#include "f_ecm.c"
#include "f_obex.c"
#include "f_serial.c"
#include "f_phonet.c"
#include "u_ether.c"
/*-------------------------------------------------------------------------*/
#define NOKIA_VENDOR_ID 0x0421 /* Nokia */
#define NOKIA_PRODUCT_ID 0x01c8 /* Nokia Gadget */
/* string IDs are assigned dynamically */
#define STRING_MANUFACTURER_IDX 0
#define STRING_PRODUCT_IDX 1
#define STRING_DESCRIPTION_IDX 2
static char manufacturer_nokia[] = "Nokia";
static const char product_nokia[] = NOKIA_LONG_NAME;
static const char description_nokia[] = "PC-Suite Configuration";
static struct usb_string strings_dev[] = {
[STRING_MANUFACTURER_IDX].s = manufacturer_nokia,
[STRING_PRODUCT_IDX].s = NOKIA_LONG_NAME,
[STRING_DESCRIPTION_IDX].s = description_nokia,
{ } /* end of list */
};
static struct usb_gadget_strings stringtab_dev = {
.language = 0x0409, /* en-us */
.strings = strings_dev,
};
static struct usb_gadget_strings *dev_strings[] = {
&stringtab_dev,
NULL,
};
static struct usb_device_descriptor device_desc = {
.bLength = USB_DT_DEVICE_SIZE,
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = __constant_cpu_to_le16(0x0200),
.bDeviceClass = USB_CLASS_COMM,
.idVendor = __constant_cpu_to_le16(NOKIA_VENDOR_ID),
.idProduct = __constant_cpu_to_le16(NOKIA_PRODUCT_ID),
/* .iManufacturer = DYNAMIC */
/* .iProduct = DYNAMIC */
.bNumConfigurations = 1,
};
/*-------------------------------------------------------------------------*/
/* Module */
MODULE_DESCRIPTION("Nokia composite gadget driver for N900");
MODULE_AUTHOR("Felipe Balbi");
MODULE_LICENSE("GPL");
Wow. Looks interesting. Will look through it tommorow.
Don't really know whether it's useful, as I'm not a developer, but this smells like possibility of ANDROID (lol) for Lumia.
Well, N900...
"Nokia composite gadget driver for N900"
ice8lue said:
Well, N900...
"Nokia composite gadget driver for N900"
Click to expand...
Click to collapse
Yes N900 driver in the kernel for a Sony Experia running Android on the same chip used in most Lumias if I am not mistaken. In the right hands maybe useful, maybe not, but thought it interesting....
Hmmm maybe a little closer to a way to flashing unsigned firmware updates?

How do I call the device driver functions from JNI folder

I have a Java Native Interface project that works. It is the helloJNI prototype. Now I want to use it to call the functions in the header file of a Device Driver. This DD is already in my image, and I see it in /dev folder. What I want to know if how do I call the device driver functions? Here is what I have in my JNI folder:
Code:
#include "com_example_sansari_usedevicedriver_MainActivity.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
/*
* Class: com_example_sansari_usedevicedriver_MainActivity
* Method: useqseecom
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_com_example_sansari_usedevicedriver_MainActivity_UseQUALCOM
(JNIEnv *env, jobject obj)
{
(*env)->NewStringUTF(env,"Hi From UseDeviceDriver");
}
Below is the executable I created to interface with the device driver from the user space. It works. I am trying to see how do I add the code below to the JNI handle I have above. Where does the main function of my executable below fit in the above file?
[/CODE]
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char **argv)
{
/* Our file descriptor */
int fd;
int rc = 0;
char *rd_buf[16];
printf("<1>%s: entered\n", argv[0]);
/* Open the device */
fd = open("/dev/hello1", O_RDWR);
if ( fd == -1 ) {
perror("<1>open failed");
rc = fd;
exit(-1);
}
printf("<1>%s: open: successful\n", argv[0]);
/* Issue a read */
rc = read(fd, rd_buf, 0);
if ( rc == -1 ) {
perror("<1>read failed");
close(fd);
exit(-1);
}
printf("<1>%s: read: returning %d bytes!\n", argv[0], rc);
close(fd);
return 0;
}
[/CODE]

port BlueLightFilter at kernel?

amazing kernel port-er or mode-er are from this section so I post the question at here. I had tried for the past 2 weeks but no luck, so my last resort is to question the genius of xda.
A brief introduction: Samsung stock BlueLightFilter is not using overlay like 3rd part apps, the benefit is it will not get blur when you increase the intensity.
I see no reason why I shouldn't share the thing I already knew to everyone, sharing is caring:
I got some clue to get it working, you have to edit the kernel. I get more specific clue you have to edit the mdnie file
https://forum.xda-developers.com/showpost.php?p=74542731&postcount=327 @BlackMesa123
Which is correct when I check https://forum.xda-developers.com/samsung-a-series/development/advanced-seven-t3509237
https://github.com/jjhitel/ASKernel by @jjhitel it is indeed the mdnie.h, mdnie_lite.c and mdnie_lite_table_A7xe.h that are modified
The code are from G920FXXU5EQAC kernel code, just lucky they spot the same screen size. Not sure how these values are generated:
static unsigned char coordinate_data_2[] = {
0xff, 0xff, 0xff, /* dummy */
0xff, 0xf6, 0xec, /* Tune_1 */
0xff, 0xf7, 0xf0, /* Tune_2 */
0xff, 0xf8, 0xf4, /* Tune_3 */
0xff, 0xf9, 0xed, /* Tune_4 */
0xff, 0xfa, 0xf1, /* Tune_5 */
0xff, 0xfb, 0xf4, /* Tune_6 */
0xff, 0xfc, 0xee, /* Tune_7 */
0xff, 0xfd, 0xf0, /* Tune_8 */
0xff, 0xfe, 0xf4, /* Tune_9 */
};
Advanced Seven rom is the example that someone port it to the rom without blf. But I have no idea what is/are the framework file(s) needed to be modified
I even tried directly take Note 5's mdnie.h, mdnie_lite.c and mdnie_lite_table_ compile and boot with no error but not working.
Then I tried match mdnie_lite_table_noble to my mdnie_lite_table_j7xe.h still boot with no error but not working.
I already added BlueLightFilter apk back but when turn on and off nothing happen.
Here is my device kernel source code
https://github.com/doulcXDA/Nougat-...kernel/drivers/video/exynos/decon_7580/panels
video\exynos\decon_7580\panels\mdnie.h
video\exynos\decon_7580\panels\mdnie_lite.c
video\exynos\decon_7580\panels\mdnie_lite_table_j7xe.h
To sum the question what I want to ask, how to get BlueLightFilter working?
Question is, do both aod and blf need to mod framework.jar to get it working?
I am targeting framework.jar or services.jar but I didn't get anything when compare both jar's smali
Can those godlike experienced master take a look at this for always on display and bluelight filter please?
I have both services.jar and framework.jar from my phone(no blf and aod) and targeting phone(with blf and aod)
services.jar
https://mega.nz/#!LUUVjbxZ!KqP5W7M23PKDt5jhkAiYXjwj1h2IwvGl-cW42u4T6nE
framework.jar
https://mega.nz/#!eU8DWaIb!HEjloERDK91VpNXvYupIdEb4X-7ii-oPKXcp9huf__o
I don't mind alternative approach actually as long as it can filter blue light out like kcal but kcal only support snapdragon not exynos.

Categories

Resources