Использовать этот пример просто и ясно и проверено
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sairamkrishna.myapplication" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
public class MainActivity extends AppCompatActivity {
EditText ed1,ed2,ed3;
Button b1;
public static final String MyPREFERENCES = "MyPrefs" ;
public static final String Name = "nameKey";
public static final String Phone = "phoneKey";
public static final String Email = "emailKey";
SharedPreferences sharedpreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1=(EditText)findViewById(R.id.editText);
ed2=(EditText)findViewById(R.id.editText2);
ed3=(EditText)findViewById(R.id.editText3);
b1=(Button)findViewById(R.id.button);
sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String n = ed1.getText().toString();
String ph = ed2.getText().toString();
String e = ed3.getText().toString();
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Name, n);
editor.putString(Phone, ph);
editor.putString(Email, e);
editor.commit();
Toast.makeText(MainActivity.this,"Thanks",Toast.LENGTH_LONG).show();
}
});
}
}
В этот вопрос о заголовках файлов ELF есть несколько (возможно) связанных ответов. В принятом ответе упоминается использование objcopy
для добавления разделов в файл ELF, а BSD bintools утверждает, что имеет лицензированную BSD реализацию objcopy
, которая может подойти вам потребности.
Можно посмотреть на этот код:
#include "packer.h"
extern uint64_t loader_size;
extern uint64_t infos_size;
extern void entry_loader(void);
static Elf64_Shdr new_section = {
.sh_name = (uint32_t)0,
.sh_type = (uint32_t)SHT_PROGBITS,
.sh_flags = (uint64_t)SHF_EXECINSTR | SHF_ALLOC,
.sh_addr = (Elf64_Addr)0,
.sh_offset = (Elf64_Off)0,
.sh_size = (uint64_t)0,
.sh_link = (uint32_t)0,
.sh_info = (uint32_t)0,
.sh_addralign = (uint64_t)16,
.sh_entsize = (uint64_t)0,
};
uint64_t entry_addr, entry_size, key;
static int32_t create_section(t_elf *elf, uint16_t last_section, uint16_t last_ptload)
{
Elf64_Shdr *new_shdrs;
uint8_t **new_sects;
uint8_t *loader;
elf->elf_header->e_shnum += 1;
if (!(new_shdrs = realloc(elf->section_header, sizeof(Elf64_Shdr) * elf->elf_header->e_shnum))) {
perror("realloc");
return (-1);
}
if (!(new_sects = realloc(elf->section_data, sizeof(uint8_t *) * elf->elf_header->e_shnum))) {
perror("realloc");
return (-1);
}
elf->section_header = new_shdrs;
elf->section_data = new_sects;
new_section.sh_offset = elf->prog_header[last_ptload].p_offset + elf->prog_header[last_ptload].p_memsz;
new_section.sh_addr = elf->prog_header[last_ptload].p_vaddr + elf->prog_header[last_ptload].p_memsz;
new_section.sh_size = loader_size;
if (!(loader = malloc(loader_size))) {
perror("malloc");
return (-1);
}
memcpy(loader, (void *)entry_loader, loader_size);
memcpy(loader + loader_size - 24, &key, sizeof(uint64_t));
memcpy(loader + loader_size - 16, &entry_addr, sizeof(uint64_t));
memcpy(loader + loader_size - 8, &entry_size, sizeof(uint64_t));
memmove(new_shdrs + last_section + 2, new_shdrs + last_section + 1, sizeof(Elf64_Shdr) * (elf->elf_header->e_shnum - last_section - 2));
memmove(new_sects + last_section + 2, new_sects + last_section + 1, sizeof(uint8_t *) * (elf->elf_header->e_shnum - last_section - 2));
memcpy(new_shdrs + last_section + 1, &new_section, sizeof(Elf64_Shdr));
new_sects[last_section + 1] = loader;
return (0);
}
код не очень трудно понять, но если хотят знать контекст или как этот раздел вставляется в эльфа, можно посмотреть на исходную реализацию этой функции в упаковщике sebastiencs:
https://github.com/sebastiencs/Packer_ELF/blob/master/src/insert_section.c
взгляните на ELFsh, который теперь является частью проекта ERESI http://www.eresi-project.org/ У них есть много документации и отличные способы использования своих инструментов.
Я сам еще не пробовал, но Вы можете посмотреть на функцию elf_newscn в libelf
.