I am trying this MFC code:
CString strURL = _T("https://www.website-to-use.co.uk/file.php?");
strURL.AppendFormat(_T("mwblang=%d"), theApp.GetForeignLanguageGroupCachedLanguageID());
strURL.AppendFormat(_T("&guilang=%d"), theApp.GetProgramLanguage());
strURL.AppendFormat(_T("&flg=%d"), theApp.GetForeignLanguageGroupMenuID() != ID_OPTIONS_GROUP_LANGUAGE_NONE);
InternetGoOnline((LPTSTR)(LPCTSTR)strURL, GetSafeHwnd(), 0);
It is not working. If I go to the same link using a browser (correct details ofcourse) then it updates my database. But trying to run this from my MFC application, nothing happens
This seems to work:
CString strURL = _T("https://website-to-use.co.uk/file.php?");
strURL.AppendFormat(_T("mwblang=%d"), theApp.GetForeignLanguageGroupCachedLanguageID());
strURL.AppendFormat(_T("&guilang=%d"), theApp.GetProgramLanguage());
strURL.AppendFormat(_T("&flg=%d"), theApp.GetForeignLanguageGroupMenuID() != ID_OPTIONS_GROUP_LANGUAGE_NONE);
if (InternetGoOnline(strURL.GetString(), GetSafeHwnd(), 0))
{
CInternetSession iSession;
CHttpFile* pWebFile = nullptr;
pWebFile = (CHttpFile*)iSession.OpenURL(strURL, 1,
INTERNET_FLAG_SECURE | INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD);
if (pWebFile != nullptr)
{
pWebFile->Close();
delete pWebFile;
}
iSession.Close();
}
Related
I've tried a lot to finally get this working, but it still doesn't work yet.
Im trying to change some variables in the __TEXT section, which is read-only by default, like changing the cryptid (and other stuff)
It kind of worked a while ago, back on 32 bit devices. But somehow, it always fails after I used the 64bit commands.
It currently crashes if I hit the following lines:
tseg->maxprot = tseg->initprot = VM_PROT_READ | VM_PROT_EXECUTE
or
crypt->cryptid = 1.
struct mach_header_64* mach = (struct mach_header_64*) _dyld_get_image_header(0);
uint64_t header_size = 0;
struct encryption_info_command_64 *crypt;
struct segment_command_64 *tseg;
struct dylib_command *protector_cmd;
// clean up some commands
void *curloc = (void *)mach + sizeof(struct mach_header);
for (int i=0;i<mach->ncmds;i++) {
struct load_command *lcmd = curloc;
if (lcmd->cmd == LC_ENCRYPTION_INFO_64) {
// save crypt cmd
crypt = curloc;
} else if (lcmd->cmd == LC_SEGMENT_64) {
struct segment_command_64 *seg = curloc;
if (seg->fileoff == 0 && seg->filesize != 0) {
header_size = seg->vmsize;
tseg = curloc;
}
}
if(i == mach->ncmds-1){
protector_cmd = curloc;
}
curloc += lcmd->cmdsize;
}
kern_return_t err;
// make __TEXT temporarily writable
err = vm_protect(mach_task_self(), (vm_address_t)mach, (vm_size_t)header_size, false, VM_PROT_ALL);
if (err != KERN_SUCCESS) exit(1);
// modify the load commands
// change protection of __TEXT segment
tseg->maxprot = tseg->initprot = VM_PROT_READ | VM_PROT_EXECUTE;
// change cryptid
crypt->cryptid = 1;
There's no point in changing the load command. The load commands were already processed when the program was loaded (which must be before this code of yours can run). They have no further effect on the protection of pages.
You're apparently already aware of the vm_protect() function. So why aren't you using that to make the text segment itself writable rather than trying to make the load commands writable?
And it's surely simpler to use getsegmentdata() to locate the segment in memory than looking at the load commands (to which you'd have to add the slide).
Beyond that, I would be surprised if iOS lets you do that. There's a general prohibition against run-time modifiable code (with very narrow exceptions).
I try to use require('electron').clipboard.readText() and just get an empty string, although I have some text in the clipboard.
I see this in Console.app (not sure if this is related):
Failed to set up CFPasteboardRef 'Apple CFPasteboard general'. Error: <error: 0x7fffa6d6fda0> { count = 1, transaction: 0, voucher = 0x0, contents =
"XPCErrorDescription" => <string: 0x7fffa6d70048> { length = 18, contents = "Connection invalid" }
}
How can I fix this?
I think this is because the Electron app was started via execve() in a forked process (fork() +daemon()` actually).
One workaround is to execute /usr/bin/open as a wrapper, like so (pseudo code):
open -a argv[0] --args args[1...]
Or basically this code:
char** args = parse_args(cmd);
char* arg0 = find_in_path(args[0]);
pid_t pid = fork();
if (pid == 0) {
daemon(1, 0);
#ifdef __APPLE__
{
// We cannot directly use `execv` for a GUI app on MacOSX
// in a forked process
// (e.g. issues like https://stackoverflow.com/questions/53958926/).
// But using `open` will work around this.
int argc = 0;
for(; args[argc]; ++argc);
char** args_ext = malloc(sizeof(char*) * (argc + 5));
arg0 = "/usr/bin/open";
args_ext[0] = arg0;
args_ext[1] = "-a";
args_ext[2] = args[0];
args_ext[3] = "--args";
for(int i = 0; ; ++i) {
args_ext[i + 4] = args[i + 1];
if(!args[i + 1])
break;
}
args = args_ext;
}
#endif
execv(arg0, args);
exit(-1);
} else if (pid > 0) { // master
// go on ...
free(args);
} else {
// error handling...
}
(Basically via this commit.)
I'm using dlsym to load private APIs (required on iOS 9.3) :
handle = dlopen(CORETELPATH, RTLD_LAZY);
_CTServerConnectionCreate = dlsym(handle, "_CTServerConnectionCreate");
When I kill the app (swipe from bottom on multitask mode) and restart app, it crashes on the second line.
The handle is equal to NULL and I didn't succeed in loading the lib twice.
I tried to get the error with dlerror(), but it returns also NULL.
Does anybody got this issue ? How to resolve it ?
Edit :
Here is the full code ; with the if (handle != NULL) the app doesn't crashes, but private frameworks won't load also
#define CORETELPATH "/System/Library/PrivateFrameworks/CoreTelephony.framework/CoreTelephony"
handle = dlopen(CORETELPATH, RTLD_LAZY);
NSLog(#"DL Error : %s", dlerror());
if (handle != NULL) {
_CTServerConnectionCreate = dlsym(handle, "_CTServerConnectionCreate");
CTResultConnection = _CTServerConnectionCreate(NULL, simMonitorCallback, NULL);
_CTServerConnectionAddToRunLoop = dlsym(handle, "_CTServerConnectionAddToRunLoop");
_CTServerConnectionAddToRunLoop(CTResultConnection, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
_CTServerConnectionRegisterForNotification = dlsym(handle, "_CTServerConnectionRegisterForNotification");
_CTServerConnectionUnregisterForNotification = dlsym(handle, "_CTServerConnectionUnregisterForNotification");
_CTServerConnectionRegisterForNotification(CTResultConnection, kCTSIMSupportSIMStatusChangeNotification);
_CTServerConnectionGetSIMStatus = dlsym(handle, "_CTServerConnectionGetSIMStatus");
_CTServerConnectionCopyMobileEquipmentInfo = dlsym(handle, "_CTServerConnectionCopyMobileEquipmentInfo");
}
It seems that changing Private API path to public fix the issue ; and the call to private APIs still works :
#define CORETELPATH "/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony"
I was trying to implement a function to stretch the sound speed, without changing it's pitch and time scale.
I try the method to set the frequency of channel to slow of fast the speed.
Then use FMOD_DSP_PITCHSHIFT to correct the pitch sounds as default.
I was using wav format sound file for test and build function.
I'm trying to intergrate product resource which sound file was encoded as MP3.
PITCHSHIFT DSP doesn't work at MP3 sound channel. console log looks fine with no exception & error.
Same project and setting everything works fine in iOS Simulator.
After some research and experiments, results indicates even m4a works fine at iOS.
I wonder is this some kind of bug? or I missed something at configuration.
sample code was based on FMOD Sample project Play stream.
`/*==============================================================================
Play Stream Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2015.
This example shows how to simply play a stream such as an MP3 or WAV. The stream
behaviour is achieved by specifying FMOD_CREATESTREAM in the call to
System::createSound. This makes FMOD decode the file in realtime as it plays,
instead of loading it all at once which uses far less memory in exchange for a
small runtime CPU hit.
==============================================================================*/
#include "fmod.hpp"
#include "common.h"
int FMOD_Main()
{
FMOD::System *system;
FMOD::Sound *sound, *sound_to_play;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
FMOD::DSP * pitch_shift;
unsigned int version;
void *extradriverdata = 0;
int numsubsounds;
Common_Init(&extradriverdata);
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
Common_Fatal("FMOD lib version %08x doesn't match header version %08x", version, FMOD_VERSION);
}
result = system->init(32, FMOD_INIT_NORMAL, extradriverdata);
ERRCHECK(result);
result = system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT, &pitch_shift);
ERRCHECK(result);
/*
This example uses an FSB file, which is a preferred pack format for fmod containing multiple sounds.
This could just as easily be exchanged with a wav/mp3/ogg file for example, but in this case you wouldnt need to call getSubSound.
Because getNumSubSounds is called here the example would work with both types of sound file (packed vs single).
*/
result = system->createSound(Common_MediaPath("aaa.m4a"), FMOD_LOOP_NORMAL | FMOD_2D, 0, &sound);
ERRCHECK(result);
result = sound->getNumSubSounds(&numsubsounds);
ERRCHECK(result);
if (numsubsounds)
{
sound->getSubSound(0, &sound_to_play);
ERRCHECK(result);
}
else
{
sound_to_play = sound;
}
/*
Play the sound.
*/
result = system->playSound(sound_to_play, 0, false, &channel);
ERRCHECK(result);
result = channel->addDSP(0, pitch_shift);
ERRCHECK(result);
float pitch = 1.f;
result = pitch_shift->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, pitch);
ERRCHECK(result);
pitch_shift->setActive(true);
ERRCHECK(result);
float defaultFrequency;
result = channel->getFrequency(&defaultFrequency);
ERRCHECK(result);
/*
Main loop.
*/
do
{
Common_Update();
if (Common_BtnPress(BTN_ACTION1))
{
bool paused;
result = channel->getPaused(&paused);
ERRCHECK(result);
result = channel->setPaused(!paused);
ERRCHECK(result);
}
if (Common_BtnPress(BTN_DOWN)) {
char valuestr;
int valuestrlen;
pitch_shift->getParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, &pitch, &valuestr, valuestrlen);
pitch+=0.1f;
pitch = pitch>2.0f?2.0f:pitch;
pitch_shift->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, pitch);
channel->setFrequency(defaultFrequency/pitch);
}
if (Common_BtnPress(BTN_UP)) {
char valuestr;
int valuestrlen;
pitch_shift->getParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, &pitch, &valuestr, valuestrlen);
pitch-=0.1f;
pitch = pitch<0.5f?0.5f:pitch;
pitch_shift->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, pitch);
channel->setFrequency(defaultFrequency/pitch);
}
result = system->update();
ERRCHECK(result);
{
unsigned int ms = 0;
unsigned int lenms = 0;
bool playing = false;
bool paused = false;
if (channel)
{
result = channel->isPlaying(&playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = channel->getPaused(&paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = sound_to_play->getLength(&lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
}
Common_Draw("==================================================");
Common_Draw("Play Stream Example.");
Common_Draw("Copyright (c) Firelight Technologies 2004-2015.");
Common_Draw("==================================================");
Common_Draw("");
Common_Draw("Press %s to toggle pause", Common_BtnStr(BTN_ACTION1));
Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT));
Common_Draw("");
Common_Draw("Time %02d:%02d:%02d/%02d:%02d:%02d : %s", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
Common_Draw("Pitch %02f",pitch);
}
Common_Sleep(50);
} while (!Common_BtnPress(BTN_QUIT));
/*
Shut down
*/
result = sound->release(); /* Release the parent, not the sound that was retrieved with getSubSound. */
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
Common_Close();
return 0;
}
`
After some more experiments , i can approach the destination through switch sound file format to m4a on iOS Device.
MP3 still not working .
There is a strange problem I've run in using RIM compression API, I can't make it work as it's described in documentation.
If I gzip plain text file using win gzip tool, add gz to resources of blackberry project and in app try to decompress it, there will be infinite loop, gzis.read() never return -1...
try
{
InputStream inputStream = getClass().getResourceAsStream("test.gz");
GZIPInputStream gzis = new GZIPInputStream(inputStream);
StringBuffer sb = new StringBuffer();
char c;
while ((c = (char)gzis.read()) != -1)
{
sb.append(c);
}
String data = sb.toString();
add(new RichTextField(data));
gzis.close();
}
catch(IOException ioe)
{
}
After the compressed content there is repetition of 65535 value in gzis.read(). The only workaround I've found is dumb
while ((c = (char)gzis.read()) != -1 && c != 65535)
But I'm curious what is the reason, what I'm doing wrong, and why 65535?
char is an unsigned, 16-bit data type. -1 cast to a char is 65535.
Change to:
int i;
while ((i = gzis.read()) != -1)
{
sb.append((char)i);
}
And it should work. The example on RIM's API can't possibly work, as no char will ever equal -1.